blob: 1455dfd742438c88231235195e0d041f922e6d39 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001
2/*
Duy Truonge833aca2013-02-12 13:35:08 -08003 * Copyright (c) 2010-2012, The Linux Foundation. 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
Mitchel Humpherys456e2682012-09-12 14:42:50 -0700554 (buf[cnt].client, buf[cnt].handle);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800555 if (IS_ERR_OR_NULL((void *)
556 buf[cnt].data)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700557 pr_err("%s: ION memory mapping for AUDIO failed\n",
558 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700559 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800560 goto fail;
561 }
562 memset((void *)buf[cnt].data, 0, bufsz);
563#else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700564 unsigned int flags = 0;
565 buf[cnt].phys =
566 allocate_contiguous_ebi_nomap(bufsz,
567 SZ_4K);
568 if (!buf[cnt].phys) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700569 pr_err("%s:Buf alloc failed size=%d\n",
570 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700571 bufsz);
572 mutex_unlock(&ac->cmd_lock);
573 goto fail;
574 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700575 buf[cnt].mem_buffer =
Laura Abbottea3e7b62012-04-30 15:59:21 -0700576 ioremap(buf[cnt].phys, bufsz);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700577 if (IS_ERR(
578 (void *)buf[cnt].mem_buffer)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700579 pr_err("%s:map_buffer failed, error = %ld\n",
580 __func__,
581 PTR_ERR((void *)buf[cnt].mem_buffer));
Jayasena Sangaraboina466e6b92012-01-17 21:10:55 -0800582 mutex_unlock(&ac->cmd_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700583 goto fail;
584 }
585 buf[cnt].data =
Laura Abbottea3e7b62012-04-30 15:59:21 -0700586 buf[cnt].mem_buffer;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700587 if (!buf[cnt].data) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700588 pr_err("%s:invalid vaddr, iomap failed\n",
589 __func__);
Jayasena Sangaraboina466e6b92012-01-17 21:10:55 -0800590 mutex_unlock(&ac->cmd_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700591 goto fail;
592 }
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800593#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700594 buf[cnt].used = 1;
595 buf[cnt].size = bufsz;
596 buf[cnt].actual_size = bufsz;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800597 pr_debug("%s data[%p]phys[%p][%p]\n",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700598 __func__,
599 (void *)buf[cnt].data,
600 (void *)buf[cnt].phys,
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800601 (void *)&buf[cnt].phys);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700602 cnt++;
603 }
604 }
605 }
606 ac->port[dir].max_buf_cnt = cnt;
607
608 mutex_unlock(&ac->cmd_lock);
609 rc = q6asm_memory_map_regions(ac, dir, bufsz, cnt);
610 if (rc < 0) {
611 pr_err("%s:CMD Memory_map_regions failed\n", __func__);
612 goto fail;
613 }
614 }
615 return 0;
616fail:
617 q6asm_audio_client_buf_free(dir, ac);
618 return -EINVAL;
619}
620
621int q6asm_audio_client_buf_alloc_contiguous(unsigned int dir,
622 struct audio_client *ac,
623 unsigned int bufsz,
624 unsigned int bufcnt)
625{
626 int cnt = 0;
627 int rc = 0;
628 struct audio_buffer *buf;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800629#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
630 int len;
631#else
632 int flags = 0;
633#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700634 if (!(ac) || ((dir != IN) && (dir != OUT)))
635 return -EINVAL;
636
637 pr_debug("%s: session[%d]bufsz[%d]bufcnt[%d]\n",
638 __func__, ac->session,
639 bufsz, bufcnt);
640
641 if (ac->session <= 0 || ac->session > 8)
642 goto fail;
643
644 if (ac->port[dir].buf) {
645 pr_debug("%s: buffer already allocated\n", __func__);
646 return 0;
647 }
648 mutex_lock(&ac->cmd_lock);
649 buf = kzalloc(((sizeof(struct audio_buffer))*bufcnt),
650 GFP_KERNEL);
651
652 if (!buf) {
653 mutex_unlock(&ac->cmd_lock);
654 goto fail;
655 }
656
657 ac->port[dir].buf = buf;
658
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800659#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
660 buf[0].client = msm_ion_client_create(UINT_MAX, "audio_client");
661 if (IS_ERR_OR_NULL((void *)buf[0].client)) {
662 pr_err("%s: ION create client for AUDIO failed\n", __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700663 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800664 goto fail;
665 }
666 buf[0].handle = ion_alloc(buf[0].client, bufsz * bufcnt, SZ_4K,
Hanumant Singh2ac41c92012-08-29 18:39:44 -0700667 (0x1 << ION_AUDIO_HEAP_ID), 0);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800668 if (IS_ERR_OR_NULL((void *) buf[0].handle)) {
669 pr_err("%s: ION memory allocation for AUDIO failed\n",
670 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700671 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800672 goto fail;
673 }
674
675 rc = ion_phys(buf[0].client, buf[0].handle,
676 (ion_phys_addr_t *)&buf[0].phys, (size_t *)&len);
677 if (rc) {
678 pr_err("%s: ION Get Physical for AUDIO failed, rc = %d\n",
679 __func__, rc);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700680 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800681 goto fail;
682 }
683
Mitchel Humpherys456e2682012-09-12 14:42:50 -0700684 buf[0].data = ion_map_kernel(buf[0].client, buf[0].handle);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800685 if (IS_ERR_OR_NULL((void *) buf[0].data)) {
686 pr_err("%s: ION memory mapping for AUDIO failed\n", __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700687 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800688 goto fail;
689 }
690 memset((void *)buf[0].data, 0, (bufsz * bufcnt));
691#else
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700692 buf[0].phys = allocate_contiguous_ebi_nomap(bufsz * bufcnt,
693 SZ_4K);
694 if (!buf[0].phys) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700695 pr_err("%s:Buf alloc failed size=%d, bufcnt=%d\n",
696 __func__, bufsz, bufcnt);
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700697 mutex_unlock(&ac->cmd_lock);
698 goto fail;
699 }
700
Laura Abbottea3e7b62012-04-30 15:59:21 -0700701 buf[0].mem_buffer = ioremap(buf[0].phys, bufsz * bufcnt);
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700702 if (IS_ERR((void *)buf[cnt].mem_buffer)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700703 pr_err("%s:map_buffer failed, error = %ld\n",
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700704 __func__, PTR_ERR((void *)buf[0].mem_buffer));
705
706 mutex_unlock(&ac->cmd_lock);
707 goto fail;
708 }
Laura Abbottea3e7b62012-04-30 15:59:21 -0700709 buf[0].data = buf[0].mem_buffer;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800710#endif
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700711 if (!buf[0].data) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700712 pr_err("%s:invalid vaddr, iomap failed\n", __func__);
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700713 mutex_unlock(&ac->cmd_lock);
714 goto fail;
715 }
716
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700717 buf[0].used = dir ^ 1;
718 buf[0].size = bufsz;
719 buf[0].actual_size = bufsz;
720 cnt = 1;
721 while (cnt < bufcnt) {
722 if (bufsz > 0) {
723 buf[cnt].data = buf[0].data + (cnt * bufsz);
724 buf[cnt].phys = buf[0].phys + (cnt * bufsz);
725 if (!buf[cnt].data) {
726 pr_err("%s Buf alloc failed\n",
727 __func__);
728 mutex_unlock(&ac->cmd_lock);
729 goto fail;
730 }
731 buf[cnt].used = dir ^ 1;
732 buf[cnt].size = bufsz;
733 buf[cnt].actual_size = bufsz;
734 pr_debug("%s data[%p]phys[%p][%p]\n", __func__,
735 (void *)buf[cnt].data,
736 (void *)buf[cnt].phys,
737 (void *)&buf[cnt].phys);
738 }
739 cnt++;
740 }
741 ac->port[dir].max_buf_cnt = cnt;
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -0700742
743 pr_debug("%s ac->port[%d].max_buf_cnt[%d]\n", __func__, dir,
744 ac->port[dir].max_buf_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700745 mutex_unlock(&ac->cmd_lock);
746 rc = q6asm_memory_map(ac, buf[0].phys, dir, bufsz, cnt);
747 if (rc < 0) {
748 pr_err("%s:CMD Memory_map_regions failed\n", __func__);
749 goto fail;
750 }
751 return 0;
752fail:
753 q6asm_audio_client_buf_free_contiguous(dir, ac);
754 return -EINVAL;
755}
756
757static int32_t q6asm_mmapcallback(struct apr_client_data *data, void *priv)
758{
759 uint32_t token;
760 uint32_t *payload = data->payload;
761
762 if (data->opcode == RESET_EVENTS) {
763 pr_debug("%s: Reset event is received: %d %d apr[%p]\n",
764 __func__,
765 data->reset_event,
766 data->reset_proc,
767 this_mmap.apr);
768 apr_reset(this_mmap.apr);
769 this_mmap.apr = NULL;
770 atomic_set(&this_mmap.cmd_state, 0);
771 return 0;
772 }
773
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700774 pr_debug("%s:ptr0[0x%x]ptr1[0x%x]opcode[0x%x] token[0x%x]payload_s[%d] src[%d] dest[%d]\n",
775 __func__, payload[0], payload[1], data->opcode, data->token,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700776 data->payload_size, data->src_port, data->dest_port);
777
778 if (data->opcode == APR_BASIC_RSP_RESULT) {
779 token = data->token;
780 switch (payload[0]) {
781 case ASM_SESSION_CMD_MEMORY_MAP:
782 case ASM_SESSION_CMD_MEMORY_UNMAP:
783 case ASM_SESSION_CMD_MEMORY_MAP_REGIONS:
784 case ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS:
785 pr_debug("%s:command[0x%x]success [0x%x]\n",
786 __func__, payload[0], payload[1]);
787 if (atomic_read(&this_mmap.cmd_state)) {
788 atomic_set(&this_mmap.cmd_state, 0);
789 wake_up(&this_mmap.cmd_wait);
790 }
791 break;
792 default:
793 pr_debug("%s:command[0x%x] not expecting rsp\n",
794 __func__, payload[0]);
795 break;
796 }
797 }
798 return 0;
799}
800
Jay Wangcd1d37d2012-10-03 16:17:18 -0700801static int32_t is_no_wait_cmd_rsp(uint32_t opcode, uint32_t *cmd_type)
802{
803 if (opcode == APR_BASIC_RSP_RESULT) {
804 if (cmd_type != NULL) {
805 switch (cmd_type[0]) {
806 case ASM_SESSION_CMD_RUN:
807 case ASM_SESSION_CMD_PAUSE:
808 case ASM_DATA_CMD_EOS:
809 return 1;
810 default:
811 break;
812 }
813 } else
814 pr_err("%s: null pointer!", __func__);
815 } else if (opcode == ASM_DATA_CMDRSP_EOS)
816 return 1;
817
818 return 0;
819}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700820
821static int32_t q6asm_callback(struct apr_client_data *data, void *priv)
822{
823 int i = 0;
824 struct audio_client *ac = (struct audio_client *)priv;
825 uint32_t token;
826 unsigned long dsp_flags;
827 uint32_t *payload;
Jay Wang0668d1062012-07-11 18:53:21 -0700828 uint32_t wakeup_flag = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700829
830
831 if ((ac == NULL) || (data == NULL)) {
832 pr_err("ac or priv NULL\n");
833 return -EINVAL;
834 }
835 if (ac->session <= 0 || ac->session > 8) {
836 pr_err("%s:Session ID is invalid, session = %d\n", __func__,
837 ac->session);
838 return -EINVAL;
839 }
Jay Wangcd1d37d2012-10-03 16:17:18 -0700840
841 payload = data->payload;
842 if ((atomic_read(&ac->nowait_cmd_cnt) > 0) &&
843 is_no_wait_cmd_rsp(data->opcode, payload)) {
Jay Wang0668d1062012-07-11 18:53:21 -0700844 pr_debug("%s: nowait_cmd_cnt %d\n",
845 __func__,
846 atomic_read(&ac->nowait_cmd_cnt));
847 atomic_dec(&ac->nowait_cmd_cnt);
848 wakeup_flag = 0;
849 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700850
851 if (data->opcode == RESET_EVENTS) {
852 pr_debug("q6asm_callback: Reset event is received: %d %d apr[%p]\n",
853 data->reset_event, data->reset_proc, ac->apr);
Laxminath Kasam692c6542012-02-21 11:17:47 +0530854 if (ac->cb)
855 ac->cb(data->opcode, data->token,
856 (uint32_t *)data->payload, ac->priv);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700857 apr_reset(ac->apr);
858 return 0;
859 }
860
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700861 pr_debug("%s: session[%d]opcode[0x%x] token[0x%x]payload_s[%d] src[%d] dest[%d]\n",
862 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700863 ac->session, data->opcode,
864 data->token, data->payload_size, data->src_port,
865 data->dest_port);
866
867 if (data->opcode == APR_BASIC_RSP_RESULT) {
868 token = data->token;
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700869 pr_debug("%s payload[0]:%x", __func__, payload[0]);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700870 switch (payload[0]) {
871 case ASM_STREAM_CMD_SET_PP_PARAMS:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700872 if (rtac_make_asm_callback(ac->session, payload,
873 data->payload_size))
874 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700875 case ASM_SESSION_CMD_PAUSE:
876 case ASM_DATA_CMD_EOS:
877 case ASM_STREAM_CMD_CLOSE:
878 case ASM_STREAM_CMD_FLUSH:
879 case ASM_SESSION_CMD_RUN:
880 case ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS:
881 case ASM_STREAM_CMD_FLUSH_READBUFS:
882 pr_debug("%s:Payload = [0x%x]\n", __func__, payload[0]);
883 if (token != ac->session) {
884 pr_err("%s:Invalid session[%d] rxed expected[%d]",
885 __func__, token, ac->session);
886 return -EINVAL;
887 }
888 case ASM_STREAM_CMD_OPEN_READ:
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700889 case ASM_STREAM_CMD_OPEN_READ_V2_1:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700890 case ASM_STREAM_CMD_OPEN_WRITE:
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700891 case ASM_STREAM_CMD_OPEN_WRITE_V2_1:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700892 case ASM_STREAM_CMD_OPEN_READWRITE:
893 case ASM_DATA_CMD_MEDIA_FORMAT_UPDATE:
894 case ASM_STREAM_CMD_SET_ENCDEC_PARAM:
Santosh Mardi23321202012-03-22 04:33:25 +0530895 case ASM_STREAM_CMD_OPEN_WRITE_COMPRESSED:
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -0700896 case ASM_STREAM_CMD_OPEN_READ_COMPRESSED:
Jay Wang0668d1062012-07-11 18:53:21 -0700897 if (atomic_read(&ac->cmd_state) && wakeup_flag) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700898 atomic_set(&ac->cmd_state, 0);
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700899 if (payload[1] == ADSP_EUNSUPPORTED) {
900 pr_debug("paload[1]:%d unsupported",
901 payload[1]);
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +0530902 atomic_set(&ac->cmd_response, 1);
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700903 }
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +0530904 else
905 atomic_set(&ac->cmd_response, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700906 wake_up(&ac->cmd_wait);
907 }
908 if (ac->cb)
909 ac->cb(data->opcode, data->token,
910 (uint32_t *)data->payload, ac->priv);
911 break;
912 default:
913 pr_debug("%s:command[0x%x] not expecting rsp\n",
914 __func__, payload[0]);
915 break;
916 }
917 return 0;
918 }
919
920 switch (data->opcode) {
921 case ASM_DATA_EVENT_WRITE_DONE:{
922 struct audio_port_data *port = &ac->port[IN];
923 pr_debug("%s: Rxed opcode[0x%x] status[0x%x] token[%d]",
924 __func__, payload[0], payload[1],
925 data->token);
926 if (ac->io_mode == SYNC_IO_MODE) {
927 if (port->buf == NULL) {
928 pr_err("%s: Unexpected Write Done\n",
929 __func__);
930 return -EINVAL;
931 }
932 spin_lock_irqsave(&port->dsp_lock, dsp_flags);
933 if (port->buf[data->token].phys !=
934 payload[0]) {
935 pr_err("Buf expected[%p]rxed[%p]\n",\
936 (void *)port->buf[data->token].phys,\
937 (void *)payload[0]);
938 spin_unlock_irqrestore(&port->dsp_lock,
939 dsp_flags);
940 return -EINVAL;
941 }
942 token = data->token;
943 port->buf[token].used = 1;
944 spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
Rajesha Kini3498c932011-07-19 19:58:27 +0530945#ifdef CONFIG_DEBUG_FS
946 if (out_enable_flag) {
947 /* For first Write done log the time and reset
948 out_cold_index*/
949 if (out_cold_index != 1) {
950 do_gettimeofday(&out_cold_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700951 pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",
952 out_cold_tv.tv_sec,
Rajesha Kini3498c932011-07-19 19:58:27 +0530953 out_cold_tv.tv_usec);
954 out_cold_index = 1;
955 }
956 pr_debug("out_enable_flag %ld",\
957 out_enable_flag);
958 }
959#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700960 for (i = 0; i < port->max_buf_cnt; i++)
961 pr_debug("%d ", port->buf[i].used);
962
963 }
964 break;
965 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700966 case ASM_STREAM_CMDRSP_GET_PP_PARAMS:
967 rtac_make_asm_callback(ac->session, payload,
968 data->payload_size);
969 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700970 case ASM_DATA_EVENT_READ_DONE:{
971
972 struct audio_port_data *port = &ac->port[OUT];
Rajesha Kini3498c932011-07-19 19:58:27 +0530973#ifdef CONFIG_DEBUG_FS
974 if (in_enable_flag) {
975 /* when in_cont_index == 7, DSP would be
976 * writing into the 8th 512 byte buffer and this
977 * timestamp is tapped here.Once done it then writes
978 * to 9th 512 byte buffer.These two buffers(8th, 9th)
979 * reach the test application in 5th iteration and that
980 * timestamp is tapped at user level. The difference
981 * of these two timestamps gives us the time between
982 * the time at which dsp started filling the sample
983 * required and when it reached the test application.
984 * Hence continuous input latency
985 */
986 if (in_cont_index == 7) {
987 do_gettimeofday(&in_cont_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700988 pr_err("In_CONT:previous read buffer done at %ld sec %ld microsec\n",
Sriranjan Srikantam74753532011-10-03 14:48:37 -0700989 in_cont_tv.tv_sec, in_cont_tv.tv_usec);
Rajesha Kini3498c932011-07-19 19:58:27 +0530990 }
991 }
992#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700993 pr_debug("%s:R-D: status=%d buff_add=%x act_size=%d offset=%d\n",
994 __func__, payload[READDONE_IDX_STATUS],
995 payload[READDONE_IDX_BUFFER],
996 payload[READDONE_IDX_SIZE],
997 payload[READDONE_IDX_OFFSET]);
998 pr_debug("%s:R-D:msw_ts=%d lsw_ts=%d flags=%d id=%d num=%d\n",
999 __func__, payload[READDONE_IDX_MSW_TS],
1000 payload[READDONE_IDX_LSW_TS],
1001 payload[READDONE_IDX_FLAGS],
1002 payload[READDONE_IDX_ID],
1003 payload[READDONE_IDX_NUMFRAMES]);
Rajesha Kini3498c932011-07-19 19:58:27 +05301004#ifdef CONFIG_DEBUG_FS
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001005 if (in_enable_flag)
Rajesha Kini3498c932011-07-19 19:58:27 +05301006 in_cont_index++;
Rajesha Kini3498c932011-07-19 19:58:27 +05301007#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001008 if (ac->io_mode == SYNC_IO_MODE) {
1009 if (port->buf == NULL) {
1010 pr_err("%s: Unexpected Write Done\n", __func__);
1011 return -EINVAL;
1012 }
1013 spin_lock_irqsave(&port->dsp_lock, dsp_flags);
1014 token = data->token;
1015 port->buf[token].used = 0;
1016 if (port->buf[token].phys !=
1017 payload[READDONE_IDX_BUFFER]) {
1018 pr_err("Buf expected[%p]rxed[%p]\n",\
1019 (void *)port->buf[token].phys,\
1020 (void *)payload[READDONE_IDX_BUFFER]);
1021 spin_unlock_irqrestore(&port->dsp_lock,
1022 dsp_flags);
1023 break;
1024 }
1025 port->buf[token].actual_size =
1026 payload[READDONE_IDX_SIZE];
1027 spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
1028 }
1029 break;
1030 }
1031 case ASM_DATA_EVENT_EOS:
1032 case ASM_DATA_CMDRSP_EOS:
1033 pr_debug("%s:EOS ACK received: rxed opcode[0x%x]\n",
1034 __func__, data->opcode);
1035 break;
1036 case ASM_STREAM_CMDRSP_GET_ENCDEC_PARAM:
1037 break;
1038 case ASM_SESSION_EVENT_TX_OVERFLOW:
1039 pr_err("ASM_SESSION_EVENT_TX_OVERFLOW\n");
1040 break;
1041 case ASM_SESSION_CMDRSP_GET_SESSION_TIME:
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001042 pr_debug("%s: ASM_SESSION_CMDRSP_GET_SESSION_TIME, payload[0] = %d, payload[1] = %d, payload[2] = %d\n",
1043 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001044 payload[0], payload[1], payload[2]);
1045 ac->time_stamp = (uint64_t)(((uint64_t)payload[1] << 32) |
1046 payload[2]);
1047 if (atomic_read(&ac->time_flag)) {
1048 atomic_set(&ac->time_flag, 0);
1049 wake_up(&ac->time_wait);
1050 }
1051 break;
1052 case ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY:
Deepa Madiregama55cbf782011-09-10 05:44:39 +05301053 case ASM_DATA_EVENT_ENC_SR_CM_NOTIFY:
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001054 pr_debug("%s: ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY, payload[0] = %d, payload[1] = %d, payload[2] = %d, payload[3] = %d\n",
1055 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001056 payload[0], payload[1], payload[2],
1057 payload[3]);
1058 break;
1059 }
1060 if (ac->cb)
1061 ac->cb(data->opcode, data->token,
1062 data->payload, ac->priv);
1063
1064 return 0;
1065}
1066
1067void *q6asm_is_cpu_buf_avail(int dir, struct audio_client *ac, uint32_t *size,
1068 uint32_t *index)
1069{
1070 void *data;
1071 unsigned char idx;
1072 struct audio_port_data *port;
1073
1074 if (!ac || ((dir != IN) && (dir != OUT)))
1075 return NULL;
1076
1077 if (ac->io_mode == SYNC_IO_MODE) {
1078 port = &ac->port[dir];
1079
1080 mutex_lock(&port->lock);
1081 idx = port->cpu_buf;
1082 if (port->buf == NULL) {
1083 pr_debug("%s:Buffer pointer null\n", __func__);
Jayasena Sangaraboina466e6b92012-01-17 21:10:55 -08001084 mutex_unlock(&port->lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001085 return NULL;
1086 }
1087 /* dir 0: used = 0 means buf in use
1088 dir 1: used = 1 means buf in use */
1089 if (port->buf[idx].used == dir) {
1090 /* To make it more robust, we could loop and get the
1091 next avail buf, its risky though */
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001092 pr_debug("%s:Next buf idx[0x%x] not available,dir[%d]\n",
1093 __func__, idx, dir);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001094 mutex_unlock(&port->lock);
1095 return NULL;
1096 }
1097 *size = port->buf[idx].actual_size;
1098 *index = port->cpu_buf;
1099 data = port->buf[idx].data;
1100 pr_debug("%s:session[%d]index[%d] data[%p]size[%d]\n",
1101 __func__,
1102 ac->session,
1103 port->cpu_buf,
1104 data, *size);
1105 /* By default increase the cpu_buf cnt
1106 user accesses this function,increase cpu
1107 buf(to avoid another api)*/
1108 port->buf[idx].used = dir;
1109 port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1));
1110 mutex_unlock(&port->lock);
1111 return data;
1112 }
1113 return NULL;
1114}
1115
Jay Wang9cf59a02011-08-10 16:58:40 -07001116void *q6asm_is_cpu_buf_avail_nolock(int dir, struct audio_client *ac,
1117 uint32_t *size, uint32_t *index)
1118{
1119 void *data;
1120 unsigned char idx;
1121 struct audio_port_data *port;
1122
1123 if (!ac || ((dir != IN) && (dir != OUT)))
1124 return NULL;
1125
1126 port = &ac->port[dir];
1127
1128 idx = port->cpu_buf;
1129 if (port->buf == NULL) {
1130 pr_debug("%s:Buffer pointer null\n", __func__);
1131 return NULL;
1132 }
1133 /*
1134 * dir 0: used = 0 means buf in use
1135 * dir 1: used = 1 means buf in use
1136 */
1137 if (port->buf[idx].used == dir) {
1138 /*
1139 * To make it more robust, we could loop and get the
1140 * next avail buf, its risky though
1141 */
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001142 pr_debug("%s:Next buf idx[0x%x] not available, dir[%d]\n",
1143 __func__, idx, dir);
Jay Wang9cf59a02011-08-10 16:58:40 -07001144 return NULL;
1145 }
1146 *size = port->buf[idx].actual_size;
1147 *index = port->cpu_buf;
1148 data = port->buf[idx].data;
1149 pr_debug("%s:session[%d]index[%d] data[%p]size[%d]\n",
1150 __func__, ac->session, port->cpu_buf,
1151 data, *size);
1152 /*
1153 * By default increase the cpu_buf cnt
1154 * user accesses this function,increase cpu
1155 * buf(to avoid another api)
1156 */
1157 port->buf[idx].used = dir;
1158 port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1));
1159 return data;
1160}
1161
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001162int q6asm_is_dsp_buf_avail(int dir, struct audio_client *ac)
1163{
1164 int ret = -1;
1165 struct audio_port_data *port;
1166 uint32_t idx;
1167
1168 if (!ac || (dir != OUT))
1169 return ret;
1170
1171 if (ac->io_mode == SYNC_IO_MODE) {
1172 port = &ac->port[dir];
1173
1174 mutex_lock(&port->lock);
1175 idx = port->dsp_buf;
1176
1177 if (port->buf[idx].used == (dir ^ 1)) {
1178 /* To make it more robust, we could loop and get the
1179 next avail buf, its risky though */
1180 pr_err("Next buf idx[0x%x] not available, dir[%d]\n",
1181 idx, dir);
1182 mutex_unlock(&port->lock);
1183 return ret;
1184 }
1185 pr_debug("%s: session[%d]dsp_buf=%d cpu_buf=%d\n", __func__,
1186 ac->session, port->dsp_buf, port->cpu_buf);
1187 ret = ((port->dsp_buf != port->cpu_buf) ? 0 : -1);
1188 mutex_unlock(&port->lock);
1189 }
1190 return ret;
1191}
1192
1193static void q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
1194 uint32_t pkt_size, uint32_t cmd_flg)
1195{
1196 pr_debug("%s:session=%d pkt size=%d cmd_flg=%d\n", __func__, pkt_size,
1197 cmd_flg, ac->session);
1198 mutex_lock(&ac->cmd_lock);
1199 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
1200 APR_HDR_LEN(sizeof(struct apr_hdr)),\
1201 APR_PKT_VER);
1202 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
1203 hdr->src_domain = APR_DOMAIN_APPS;
1204 hdr->dest_svc = APR_SVC_ASM;
1205 hdr->dest_domain = APR_DOMAIN_ADSP;
1206 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
1207 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
1208 if (cmd_flg) {
1209 hdr->token = ac->session;
1210 atomic_set(&ac->cmd_state, 1);
1211 }
1212 hdr->pkt_size = pkt_size;
1213 mutex_unlock(&ac->cmd_lock);
1214 return;
1215}
1216
1217static void q6asm_add_mmaphdr(struct apr_hdr *hdr, uint32_t pkt_size,
1218 uint32_t cmd_flg)
1219{
1220 pr_debug("%s:pkt size=%d cmd_flg=%d\n", __func__, pkt_size, cmd_flg);
1221 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
1222 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1223 hdr->src_port = 0;
1224 hdr->dest_port = 0;
1225 if (cmd_flg) {
1226 hdr->token = 0;
1227 atomic_set(&this_mmap.cmd_state, 1);
1228 }
1229 hdr->pkt_size = pkt_size;
1230 return;
1231}
1232
1233int q6asm_open_read(struct audio_client *ac,
1234 uint32_t format)
1235{
1236 int rc = 0x00;
1237 struct asm_stream_cmd_open_read open;
Rajesha Kini3498c932011-07-19 19:58:27 +05301238#ifdef CONFIG_DEBUG_FS
1239 in_cont_index = 0;
1240#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001241 if ((ac == NULL) || (ac->apr == NULL)) {
1242 pr_err("%s: APR handle NULL\n", __func__);
1243 return -EINVAL;
1244 }
1245 pr_debug("%s:session[%d]", __func__, ac->session);
1246
1247 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1248 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ;
1249 /* Stream prio : High, provide meta info with encoded frames */
1250 open.src_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1251
1252 open.pre_proc_top = get_asm_topology();
1253 if (open.pre_proc_top == 0)
1254 open.pre_proc_top = DEFAULT_POPP_TOPOLOGY;
1255
1256 switch (format) {
1257 case FORMAT_LINEAR_PCM:
1258 open.uMode = STREAM_PRIORITY_HIGH;
1259 open.format = LINEAR_PCM;
1260 break;
Mingming Yin647e9ea2012-03-17 19:56:10 -07001261 case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
1262 open.uMode = STREAM_PRIORITY_HIGH;
1263 open.format = MULTI_CHANNEL_PCM;
1264 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001265 case FORMAT_MPEG4_AAC:
1266 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1267 open.format = MPEG4_AAC;
1268 break;
1269 case FORMAT_V13K:
1270 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1271 open.format = V13K_FS;
1272 break;
1273 case FORMAT_EVRC:
1274 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1275 open.format = EVRC_FS;
1276 break;
1277 case FORMAT_AMRNB:
1278 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1279 open.format = AMRNB_FS;
1280 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301281 case FORMAT_AMRWB:
1282 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1283 open.format = AMRWB_FS;
1284 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001285 default:
1286 pr_err("Invalid format[%d]\n", format);
1287 goto fail_cmd;
1288 }
1289 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1290 if (rc < 0) {
1291 pr_err("open failed op[0x%x]rc[%d]\n", \
1292 open.hdr.opcode, rc);
1293 goto fail_cmd;
1294 }
1295 rc = wait_event_timeout(ac->cmd_wait,
1296 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1297 if (!rc) {
1298 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1299 rc);
1300 goto fail_cmd;
1301 }
1302 return 0;
1303fail_cmd:
1304 return -EINVAL;
1305}
1306
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -07001307int q6asm_open_read_v2_1(struct audio_client *ac,
1308 uint32_t format)
1309{
1310 int rc = 0x00;
1311 struct asm_stream_cmd_open_read_v2_1 open;
1312#ifdef CONFIG_DEBUG_FS
1313 in_cont_index = 0;
1314#endif
1315 if ((ac == NULL) || (ac->apr == NULL)) {
1316 pr_err("%s: APR handle NULL\n", __func__);
1317 return -EINVAL;
1318 }
1319 pr_debug("%s:session[%d]", __func__, ac->session);
1320
1321 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1322 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ_V2_1;
1323 open.src_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1324 open.pre_proc_top = get_asm_topology();
1325 if (open.pre_proc_top == 0)
1326 open.pre_proc_top = DEFAULT_POPP_TOPOLOGY;
1327
1328 switch (format) {
1329 case FORMAT_LINEAR_PCM:
1330 open.uMode = STREAM_PRIORITY_HIGH;
1331 open.format = LINEAR_PCM;
1332 break;
1333 case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
1334 open.uMode = STREAM_PRIORITY_HIGH;
1335 open.format = MULTI_CHANNEL_PCM;
1336 break;
1337 case FORMAT_MPEG4_AAC:
1338 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1339 open.format = MPEG4_AAC;
1340 break;
1341 case FORMAT_V13K:
1342 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1343 open.format = V13K_FS;
1344 break;
1345 case FORMAT_EVRC:
1346 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1347 open.format = EVRC_FS;
1348 break;
1349 case FORMAT_AMRNB:
1350 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1351 open.format = AMRNB_FS;
1352 break;
1353 case FORMAT_AMRWB:
1354 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1355 open.format = AMRWB_FS;
1356 break;
1357 default:
1358 pr_err("Invalid format[%d]\n", format);
1359 goto fail_cmd;
1360 }
1361 open.uMode = ASM_OPEN_READ_PERF_MODE_BIT;
1362 open.bits_per_sample = PCM_BITS_PER_SAMPLE;
1363 open.reserved = 0;
1364 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1365 if (rc < 0) {
1366 pr_err("open failed op[0x%x]rc[%d]\n", \
1367 open.hdr.opcode, rc);
1368 goto fail_cmd;
1369 }
1370 rc = wait_event_timeout(ac->cmd_wait,
1371 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1372 if (!rc) {
1373 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1374 rc);
1375 goto fail_cmd;
1376 }
1377 return 0;
1378fail_cmd:
1379 return -EINVAL;
1380}
1381
1382
Subhash Chandra Bose Naripeddy694b7d92012-06-20 20:46:13 -07001383int q6asm_open_read_compressed(struct audio_client *ac,
1384 uint32_t frames_per_buffer, uint32_t meta_data_mode)
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -07001385{
1386 int rc = 0x00;
1387 struct asm_stream_cmd_open_read_compressed open;
1388#ifdef CONFIG_DEBUG_FS
1389 in_cont_index = 0;
1390#endif
1391 if ((ac == NULL) || (ac->apr == NULL)) {
1392 pr_err("%s: APR handle NULL\n", __func__);
1393 return -EINVAL;
1394 }
1395 pr_debug("%s:session[%d]", __func__, ac->session);
1396
1397 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1398 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ_COMPRESSED;
1399 /* hardcoded as following*/
Subhash Chandra Bose Naripeddy694b7d92012-06-20 20:46:13 -07001400 open.frame_per_buf = frames_per_buffer;
1401 open.uMode = meta_data_mode;
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -07001402
1403 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1404 if (rc < 0) {
1405 pr_err("open failed op[0x%x]rc[%d]\n", open.hdr.opcode, rc);
1406 goto fail_cmd;
1407 }
1408 rc = wait_event_timeout(ac->cmd_wait,
1409 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1410 if (!rc) {
1411 pr_err("%s: timeout. waited for OPEN_READ_COMPRESSED rc[%d]\n",
1412 __func__, rc);
1413 goto fail_cmd;
1414 }
1415 return 0;
1416fail_cmd:
1417 return -EINVAL;
1418}
1419
Santosh Mardi23321202012-03-22 04:33:25 +05301420int q6asm_open_write_compressed(struct audio_client *ac, uint32_t format)
1421{
1422 int rc = 0x00;
1423 struct asm_stream_cmd_open_write_compressed open;
1424
1425 if ((ac == NULL) || (ac->apr == NULL)) {
1426 pr_err("%s: APR handle NULL\n", __func__);
1427 return -EINVAL;
1428 }
1429 pr_debug("%s: session[%d] wr_format[0x%x]", __func__, ac->session,
1430 format);
1431
1432 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1433
1434 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_COMPRESSED;
1435
1436 switch (format) {
1437 case FORMAT_AC3:
1438 open.format = AC3_DECODER;
1439 break;
1440 case FORMAT_EAC3:
1441 open.format = EAC3_DECODER;
1442 break;
1443 case FORMAT_MP3:
1444 open.format = MP3;
1445 break;
1446 case FORMAT_DTS:
1447 open.format = DTS;
1448 break;
Srikanth Uyyala66f781a2012-06-13 23:23:25 +05301449 case FORMAT_DTS_LBR:
1450 open.format = DTS_LBR;
1451 break;
Santosh Mardi23321202012-03-22 04:33:25 +05301452 case FORMAT_AAC:
1453 open.format = MPEG4_AAC;
1454 break;
1455 case FORMAT_ATRAC:
1456 open.format = ATRAC;
1457 break;
1458 case FORMAT_WMA_V10PRO:
1459 open.format = WMA_V10PRO;
1460 break;
1461 case FORMAT_MAT:
1462 open.format = MAT;
1463 break;
1464 default:
1465 pr_err("%s: Invalid format[%d]\n", __func__, format);
1466 goto fail_cmd;
1467 }
1468 /*Below flag indicates the DSP that Compressed audio input
1469 stream is not IEC 61937 or IEC 60958 packetizied*/
1470 open.flags = 0x00000000;
1471 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1472 if (rc < 0) {
1473 pr_err("%s: open failed op[0x%x]rc[%d]\n", \
1474 __func__, open.hdr.opcode, rc);
1475 goto fail_cmd;
1476 }
1477 rc = wait_event_timeout(ac->cmd_wait,
1478 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1479 if (!rc) {
1480 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1481 rc);
1482 goto fail_cmd;
1483 }
1484 return 0;
1485fail_cmd:
1486 return -EINVAL;
1487}
1488
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001489int q6asm_open_write(struct audio_client *ac, uint32_t format)
1490{
1491 int rc = 0x00;
1492 struct asm_stream_cmd_open_write open;
1493
1494 if ((ac == NULL) || (ac->apr == NULL)) {
1495 pr_err("%s: APR handle NULL\n", __func__);
1496 return -EINVAL;
1497 }
1498 pr_debug("%s: session[%d] wr_format[0x%x]", __func__, ac->session,
1499 format);
1500
1501 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1502
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -07001503 if (ac->perf_mode) {
1504 pr_debug("%s In Performance/lowlatency mode", __func__);
1505 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_V2_1;
1506 open.uMode = ASM_OPEN_WRITE_PERF_MODE_BIT;
1507 /* source endpoint : matrix */
1508 open.sink_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1509 open.stream_handle = PCM_BITS_PER_SAMPLE;
1510 } else {
1511 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE;
1512 open.uMode = STREAM_PRIORITY_HIGH;
1513 /* source endpoint : matrix */
1514 open.sink_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1515 open.stream_handle = 0x00;
1516 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001517 open.post_proc_top = get_asm_topology();
1518 if (open.post_proc_top == 0)
1519 open.post_proc_top = DEFAULT_POPP_TOPOLOGY;
1520
1521 switch (format) {
1522 case FORMAT_LINEAR_PCM:
1523 open.format = LINEAR_PCM;
1524 break;
Kiran Kandi5e809b02012-01-31 00:24:33 -08001525 case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
1526 open.format = MULTI_CHANNEL_PCM;
1527 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001528 case FORMAT_MPEG4_AAC:
1529 open.format = MPEG4_AAC;
1530 break;
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07001531 case FORMAT_MPEG4_MULTI_AAC:
1532 open.format = MPEG4_MULTI_AAC;
1533 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001534 case FORMAT_WMA_V9:
1535 open.format = WMA_V9;
1536 break;
1537 case FORMAT_WMA_V10PRO:
1538 open.format = WMA_V10PRO;
1539 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05301540 case FORMAT_MP3:
1541 open.format = MP3;
1542 break;
Srikanth Uyyala66f781a2012-06-13 23:23:25 +05301543 case FORMAT_DTS:
1544 open.format = DTS;
1545 break;
1546 case FORMAT_DTS_LBR:
1547 open.format = DTS_LBR;
1548 break;
Ajit Khare43fd8832012-08-07 13:19:44 -07001549 case FORMAT_AMRWB:
1550 open.format = AMRWB_FS;
1551 pr_debug("q6asm_open_write FORMAT_AMRWB");
1552 break;
1553 case FORMAT_AMR_WB_PLUS:
1554 open.format = AMR_WB_PLUS;
1555 pr_debug("q6asm_open_write FORMAT_AMR_WB_PLUS");
1556 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001557 default:
1558 pr_err("%s: Invalid format[%d]\n", __func__, format);
1559 goto fail_cmd;
1560 }
1561 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1562 if (rc < 0) {
1563 pr_err("%s: open failed op[0x%x]rc[%d]\n", \
1564 __func__, open.hdr.opcode, rc);
1565 goto fail_cmd;
1566 }
1567 rc = wait_event_timeout(ac->cmd_wait,
1568 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1569 if (!rc) {
1570 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1571 rc);
1572 goto fail_cmd;
1573 }
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +05301574 if (atomic_read(&ac->cmd_response)) {
1575 pr_err("%s: format = %x not supported\n", __func__, format);
1576 goto fail_cmd;
1577 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001578 return 0;
1579fail_cmd:
1580 return -EINVAL;
1581}
1582
1583int q6asm_open_read_write(struct audio_client *ac,
1584 uint32_t rd_format,
1585 uint32_t wr_format)
1586{
1587 int rc = 0x00;
1588 struct asm_stream_cmd_open_read_write open;
1589
1590 if ((ac == NULL) || (ac->apr == NULL)) {
1591 pr_err("APR handle NULL\n");
1592 return -EINVAL;
1593 }
1594 pr_debug("%s: session[%d]", __func__, ac->session);
1595 pr_debug("wr_format[0x%x]rd_format[0x%x]",
1596 wr_format, rd_format);
1597
1598 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1599 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READWRITE;
1600
Deepa Madiregama55cbf782011-09-10 05:44:39 +05301601 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_NORMAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001602 /* source endpoint : matrix */
1603 open.post_proc_top = get_asm_topology();
1604 if (open.post_proc_top == 0)
1605 open.post_proc_top = DEFAULT_POPP_TOPOLOGY;
1606
1607 switch (wr_format) {
1608 case FORMAT_LINEAR_PCM:
1609 open.write_format = LINEAR_PCM;
1610 break;
1611 case FORMAT_MPEG4_AAC:
1612 open.write_format = MPEG4_AAC;
1613 break;
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07001614 case FORMAT_MPEG4_MULTI_AAC:
1615 open.write_format = MPEG4_MULTI_AAC;
1616 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001617 case FORMAT_WMA_V9:
1618 open.write_format = WMA_V9;
1619 break;
1620 case FORMAT_WMA_V10PRO:
1621 open.write_format = WMA_V10PRO;
1622 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301623 case FORMAT_AMRNB:
1624 open.write_format = AMRNB_FS;
1625 break;
1626 case FORMAT_AMRWB:
1627 open.write_format = AMRWB_FS;
1628 break;
Ajit Khare7277bb72012-10-31 16:34:22 -07001629 case FORMAT_AMR_WB_PLUS:
1630 open.write_format = AMR_WB_PLUS;
1631 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301632 case FORMAT_V13K:
1633 open.write_format = V13K_FS;
1634 break;
1635 case FORMAT_EVRC:
1636 open.write_format = EVRC_FS;
1637 break;
1638 case FORMAT_EVRCB:
1639 open.write_format = EVRCB_FS;
1640 break;
1641 case FORMAT_EVRCWB:
1642 open.write_format = EVRCWB_FS;
1643 break;
1644 case FORMAT_MP3:
1645 open.write_format = MP3;
1646 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001647 default:
1648 pr_err("Invalid format[%d]\n", wr_format);
1649 goto fail_cmd;
1650 }
1651
1652 switch (rd_format) {
1653 case FORMAT_LINEAR_PCM:
1654 open.read_format = LINEAR_PCM;
1655 break;
1656 case FORMAT_MPEG4_AAC:
1657 open.read_format = MPEG4_AAC;
1658 break;
1659 case FORMAT_V13K:
1660 open.read_format = V13K_FS;
1661 break;
1662 case FORMAT_EVRC:
1663 open.read_format = EVRC_FS;
1664 break;
1665 case FORMAT_AMRNB:
1666 open.read_format = AMRNB_FS;
1667 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301668 case FORMAT_AMRWB:
1669 open.read_format = AMRWB_FS;
1670 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001671 default:
1672 pr_err("Invalid format[%d]\n", rd_format);
1673 goto fail_cmd;
1674 }
1675 pr_debug("%s:rdformat[0x%x]wrformat[0x%x]\n", __func__,
1676 open.read_format, open.write_format);
1677
1678 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1679 if (rc < 0) {
1680 pr_err("open failed op[0x%x]rc[%d]\n", \
1681 open.hdr.opcode, rc);
1682 goto fail_cmd;
1683 }
1684 rc = wait_event_timeout(ac->cmd_wait,
1685 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1686 if (!rc) {
1687 pr_err("timeout. waited for OPEN_WRITE rc[%d]\n", rc);
1688 goto fail_cmd;
1689 }
1690 return 0;
1691fail_cmd:
1692 return -EINVAL;
1693}
1694
1695int q6asm_run(struct audio_client *ac, uint32_t flags,
1696 uint32_t msw_ts, uint32_t lsw_ts)
1697{
1698 struct asm_stream_cmd_run run;
1699 int rc;
1700 if (!ac || ac->apr == NULL) {
1701 pr_err("APR handle NULL\n");
1702 return -EINVAL;
1703 }
1704 pr_debug("%s session[%d]", __func__, ac->session);
1705 q6asm_add_hdr(ac, &run.hdr, sizeof(run), TRUE);
1706
1707 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1708 run.flags = flags;
1709 run.msw_ts = msw_ts;
1710 run.lsw_ts = lsw_ts;
Rajesha Kini3498c932011-07-19 19:58:27 +05301711#ifdef CONFIG_DEBUG_FS
1712 if (out_enable_flag) {
1713 do_gettimeofday(&out_cold_tv);
1714 pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",\
1715 out_cold_tv.tv_sec, out_cold_tv.tv_usec);
1716 }
1717#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001718 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1719 if (rc < 0) {
1720 pr_err("Commmand run failed[%d]", rc);
1721 goto fail_cmd;
1722 }
1723
1724 rc = wait_event_timeout(ac->cmd_wait,
1725 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1726 if (!rc) {
1727 pr_err("timeout. waited for run success rc[%d]", rc);
1728 goto fail_cmd;
1729 }
1730
1731 return 0;
1732fail_cmd:
1733 return -EINVAL;
1734}
1735
1736int q6asm_run_nowait(struct audio_client *ac, uint32_t flags,
1737 uint32_t msw_ts, uint32_t lsw_ts)
1738{
1739 struct asm_stream_cmd_run run;
1740 int rc;
1741 if (!ac || ac->apr == NULL) {
1742 pr_err("%s:APR handle NULL\n", __func__);
1743 return -EINVAL;
1744 }
1745 pr_debug("session[%d]", ac->session);
1746 q6asm_add_hdr_async(ac, &run.hdr, sizeof(run), TRUE);
1747
1748 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1749 run.flags = flags;
1750 run.msw_ts = msw_ts;
1751 run.lsw_ts = lsw_ts;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001752 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1753 if (rc < 0) {
1754 pr_err("%s:Commmand run failed[%d]", __func__, rc);
1755 return -EINVAL;
1756 }
Jay Wang0668d1062012-07-11 18:53:21 -07001757 atomic_inc(&ac->nowait_cmd_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001758 return 0;
1759}
1760
1761
1762int q6asm_enc_cfg_blk_aac(struct audio_client *ac,
1763 uint32_t frames_per_buf,
1764 uint32_t sample_rate, uint32_t channels,
1765 uint32_t bit_rate, uint32_t mode, uint32_t format)
1766{
1767 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1768 int rc = 0;
1769
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001770 pr_debug("%s:session[%d]frames[%d]SR[%d]ch[%d]bitrate[%d]mode[%d] format[%d]",
1771 __func__, ac->session, frames_per_buf,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001772 sample_rate, channels, bit_rate, mode, format);
1773
1774 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1775
1776 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1777 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1778 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1779 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1780 enc_cfg.enc_blk.format_id = MPEG4_AAC;
1781 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_aac_read_cfg);
1782 enc_cfg.enc_blk.cfg.aac.bitrate = bit_rate;
1783 enc_cfg.enc_blk.cfg.aac.enc_mode = mode;
1784 enc_cfg.enc_blk.cfg.aac.format = format;
1785 enc_cfg.enc_blk.cfg.aac.ch_cfg = channels;
1786 enc_cfg.enc_blk.cfg.aac.sample_rate = sample_rate;
1787
1788 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1789 if (rc < 0) {
1790 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1791 rc = -EINVAL;
1792 goto fail_cmd;
1793 }
1794 rc = wait_event_timeout(ac->cmd_wait,
1795 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1796 if (!rc) {
1797 pr_err("timeout. waited for FORMAT_UPDATE\n");
1798 goto fail_cmd;
1799 }
1800 return 0;
1801fail_cmd:
1802 return -EINVAL;
1803}
1804
1805int q6asm_enc_cfg_blk_pcm(struct audio_client *ac,
1806 uint32_t rate, uint32_t channels)
1807{
1808 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1809
1810 int rc = 0;
1811
1812 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1813 ac->session, rate, channels);
1814
1815 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1816
1817 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1818 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1819 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1820 enc_cfg.enc_blk.frames_per_buf = 1;
1821 enc_cfg.enc_blk.format_id = LINEAR_PCM;
1822 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg);
1823 enc_cfg.enc_blk.cfg.pcm.ch_cfg = channels;
1824 enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16;
1825 enc_cfg.enc_blk.cfg.pcm.sample_rate = rate;
1826 enc_cfg.enc_blk.cfg.pcm.is_signed = 1;
1827 enc_cfg.enc_blk.cfg.pcm.interleaved = 1;
1828
1829 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1830 if (rc < 0) {
1831 pr_err("Comamnd open failed\n");
1832 rc = -EINVAL;
1833 goto fail_cmd;
1834 }
1835 rc = wait_event_timeout(ac->cmd_wait,
1836 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1837 if (!rc) {
1838 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1839 goto fail_cmd;
1840 }
1841 return 0;
1842fail_cmd:
1843 return -EINVAL;
1844}
1845
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001846int q6asm_enc_cfg_blk_pcm_native(struct audio_client *ac,
1847 uint32_t rate, uint32_t channels)
1848{
1849 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1850
1851 int rc = 0;
1852
1853 pr_debug("%s: Session %d, rate = %d, channels = %d, setting the rate and channels to 0 for native\n",
1854 __func__, ac->session, rate, channels);
1855
1856 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1857
1858 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1859 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1860 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1861 enc_cfg.enc_blk.frames_per_buf = 1;
1862 enc_cfg.enc_blk.format_id = LINEAR_PCM;
1863 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg);
1864 enc_cfg.enc_blk.cfg.pcm.ch_cfg = 0;/*channels;*/
1865 enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16;
1866 enc_cfg.enc_blk.cfg.pcm.sample_rate = 0;/*rate;*/
1867 enc_cfg.enc_blk.cfg.pcm.is_signed = 1;
1868 enc_cfg.enc_blk.cfg.pcm.interleaved = 1;
1869
1870 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1871 if (rc < 0) {
1872 pr_err("Comamnd open failed\n");
1873 rc = -EINVAL;
1874 goto fail_cmd;
1875 }
1876 rc = wait_event_timeout(ac->cmd_wait,
1877 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1878 if (!rc) {
1879 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1880 goto fail_cmd;
1881 }
1882 return 0;
1883fail_cmd:
1884 return -EINVAL;
1885}
1886
Mingming Yin647e9ea2012-03-17 19:56:10 -07001887int q6asm_enc_cfg_blk_multi_ch_pcm(struct audio_client *ac,
1888 uint32_t rate, uint32_t channels)
1889{
1890 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1891
1892 int rc = 0;
1893
1894 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1895 ac->session, rate, channels);
1896
1897 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1898
1899 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1900 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1901 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1902 enc_cfg.enc_blk.frames_per_buf = 1;
1903 enc_cfg.enc_blk.format_id = MULTI_CHANNEL_PCM;
1904 enc_cfg.enc_blk.cfg_size =
1905 sizeof(struct asm_multi_channel_pcm_fmt_blk);
1906 enc_cfg.enc_blk.cfg.mpcm.num_channels = channels;
1907 enc_cfg.enc_blk.cfg.mpcm.bits_per_sample = 16;
1908 enc_cfg.enc_blk.cfg.mpcm.sample_rate = rate;
1909 enc_cfg.enc_blk.cfg.mpcm.is_signed = 1;
1910 enc_cfg.enc_blk.cfg.mpcm.is_interleaved = 1;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07001911 if (channels == 1) {
1912 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1913 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = 0;
1914 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = 0;
1915 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = 0;
1916 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1917 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1918 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1919 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1920 } else if (channels == 2) {
Subhash Chandra Bose Naripeddy8477d222012-06-12 00:30:54 -07001921 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1922 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1923 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = 0;
1924 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = 0;
1925 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1926 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1927 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1928 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1929 } else if (channels == 4) {
1930 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1931 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1932 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_RB;
1933 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_LB;
1934 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1935 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1936 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1937 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1938 } else if (channels == 6) {
1939 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1940 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1941 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_LFE;
1942 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_FC;
1943 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = PCM_CHANNEL_LB;
1944 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = PCM_CHANNEL_RB;
1945 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1946 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1947 } else if (channels == 8) {
1948 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1949 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1950 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_LFE;
1951 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_FC;
1952 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = PCM_CHANNEL_LB;
1953 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = PCM_CHANNEL_RB;
1954 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = PCM_CHANNEL_FLC;
1955 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = PCM_CHANNEL_FRC;
1956 }
Mingming Yin647e9ea2012-03-17 19:56:10 -07001957
1958 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1959 if (rc < 0) {
1960 pr_err("Comamnd open failed\n");
1961 rc = -EINVAL;
1962 goto fail_cmd;
1963 }
1964 rc = wait_event_timeout(ac->cmd_wait,
1965 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1966 if (!rc) {
1967 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1968 goto fail_cmd;
1969 }
1970 return 0;
1971fail_cmd:
1972 return -EINVAL;
1973}
1974
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001975int q6asm_enable_sbrps(struct audio_client *ac,
1976 uint32_t sbr_ps_enable)
1977{
1978 struct asm_stream_cmd_encdec_sbr sbrps;
1979
1980 int rc = 0;
1981
1982 pr_debug("%s: Session %d\n", __func__, ac->session);
1983
1984 q6asm_add_hdr(ac, &sbrps.hdr, sizeof(sbrps), TRUE);
1985
1986 sbrps.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1987 sbrps.param_id = ASM_ENABLE_SBR_PS;
1988 sbrps.param_size = sizeof(struct asm_sbr_ps);
1989 sbrps.sbr_ps.enable = sbr_ps_enable;
1990
1991 rc = apr_send_pkt(ac->apr, (uint32_t *) &sbrps);
1992 if (rc < 0) {
1993 pr_err("Command opcode[0x%x]paramid[0x%x] failed\n",
1994 ASM_STREAM_CMD_SET_ENCDEC_PARAM,
1995 ASM_ENABLE_SBR_PS);
1996 rc = -EINVAL;
1997 goto fail_cmd;
1998 }
1999 rc = wait_event_timeout(ac->cmd_wait,
2000 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2001 if (!rc) {
2002 pr_err("timeout opcode[0x%x] ", sbrps.hdr.opcode);
2003 goto fail_cmd;
2004 }
2005 return 0;
2006fail_cmd:
2007 return -EINVAL;
2008}
2009
Swaminathan Sathappan70765cd2011-07-19 18:42:47 -07002010int q6asm_cfg_dual_mono_aac(struct audio_client *ac,
2011 uint16_t sce_left, uint16_t sce_right)
2012{
2013 struct asm_stream_cmd_encdec_dualmono dual_mono;
2014
2015 int rc = 0;
2016
2017 pr_debug("%s: Session %d, sce_left = %d, sce_right = %d\n",
2018 __func__, ac->session, sce_left, sce_right);
2019
2020 q6asm_add_hdr(ac, &dual_mono.hdr, sizeof(dual_mono), TRUE);
2021
2022 dual_mono.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2023 dual_mono.param_id = ASM_CONFIGURE_DUAL_MONO;
2024 dual_mono.param_size = sizeof(struct asm_dual_mono);
2025 dual_mono.channel_map.sce_left = sce_left;
2026 dual_mono.channel_map.sce_right = sce_right;
2027
2028 rc = apr_send_pkt(ac->apr, (uint32_t *) &dual_mono);
2029 if (rc < 0) {
2030 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
2031 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
2032 ASM_CONFIGURE_DUAL_MONO);
2033 rc = -EINVAL;
2034 goto fail_cmd;
2035 }
2036 rc = wait_event_timeout(ac->cmd_wait,
2037 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2038 if (!rc) {
2039 pr_err("%s:timeout opcode[0x%x]\n", __func__,
2040 dual_mono.hdr.opcode);
2041 goto fail_cmd;
2042 }
2043 return 0;
2044fail_cmd:
2045 return -EINVAL;
2046}
2047
Amal Paul6e0f7982013-02-21 19:36:35 -08002048int q6asm_cfg_aac_sel_mix_coef(struct audio_client *ac, uint32_t mix_coeff)
2049{
2050 struct asm_aac_stereo_mix_coeff_selection_param aac_mix_coeff;
2051 int rc = 0;
2052 q6asm_add_hdr(ac, &aac_mix_coeff.hdr, sizeof(aac_mix_coeff), TRUE);
2053 aac_mix_coeff.hdr.opcode =
2054 ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2055 aac_mix_coeff.param_id =
2056 ASM_PARAM_ID_AAC_STEREO_MIX_COEFF_SELECTION_FLAG;
2057 aac_mix_coeff.param_size =
2058 sizeof(struct asm_aac_stereo_mix_coeff_selection_param);
2059 aac_mix_coeff.aac_stereo_mix_coeff_flag = mix_coeff;
2060 pr_debug("%s, mix_coeff = %u", __func__, mix_coeff);
2061 rc = apr_send_pkt(ac->apr, (uint32_t *) &aac_mix_coeff);
2062 if (rc < 0) {
2063 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
2064 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
2065 ASM_PARAM_ID_AAC_STEREO_MIX_COEFF_SELECTION_FLAG);
2066 rc = -EINVAL;
2067 goto fail_cmd;
2068 }
2069 rc = wait_event_timeout(ac->cmd_wait,
2070 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2071 if (!rc) {
2072 pr_err("%s:timeout opcode[0x%x]\n", __func__,
2073 aac_mix_coeff.hdr.opcode);
2074 goto fail_cmd;
2075 }
2076 return 0;
2077fail_cmd:
2078 return -EINVAL;
2079}
2080
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07002081int q6asm_set_encdec_chan_map(struct audio_client *ac,
2082 uint32_t num_channels)
2083{
2084 struct asm_stream_cmd_encdec_channelmap chan_map;
2085 u8 *channel_mapping;
2086
2087 int rc = 0;
2088
2089 pr_debug("%s: Session %d, num_channels = %d\n",
2090 __func__, ac->session, num_channels);
2091
2092 q6asm_add_hdr(ac, &chan_map.hdr, sizeof(chan_map), TRUE);
2093
2094 chan_map.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2095 chan_map.param_id = ASM_ENCDEC_DEC_CHAN_MAP;
2096 chan_map.param_size = sizeof(struct asm_dec_chan_map);
2097 chan_map.chan_map.num_channels = num_channels;
2098
2099 channel_mapping =
2100 chan_map.chan_map.channel_mapping;
2101
2102 memset(channel_mapping, PCM_CHANNEL_NULL, MAX_CHAN_MAP_CHANNELS);
2103 if (num_channels == 1) {
2104 channel_mapping[0] = PCM_CHANNEL_FL;
2105 } else if (num_channels == 2) {
2106 channel_mapping[0] = PCM_CHANNEL_FL;
2107 channel_mapping[1] = PCM_CHANNEL_FR;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002108 } else if (num_channels == 4) {
2109 channel_mapping[0] = PCM_CHANNEL_FL;
2110 channel_mapping[1] = PCM_CHANNEL_FR;
2111 channel_mapping[1] = PCM_CHANNEL_LB;
2112 channel_mapping[1] = PCM_CHANNEL_RB;
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07002113 } else if (num_channels == 6) {
2114 channel_mapping[0] = PCM_CHANNEL_FC;
2115 channel_mapping[1] = PCM_CHANNEL_FL;
2116 channel_mapping[2] = PCM_CHANNEL_FR;
2117 channel_mapping[3] = PCM_CHANNEL_LB;
2118 channel_mapping[4] = PCM_CHANNEL_RB;
2119 channel_mapping[5] = PCM_CHANNEL_LFE;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002120 } else if (num_channels == 8) {
2121 channel_mapping[0] = PCM_CHANNEL_FC;
2122 channel_mapping[1] = PCM_CHANNEL_FL;
2123 channel_mapping[2] = PCM_CHANNEL_FR;
2124 channel_mapping[3] = PCM_CHANNEL_LB;
2125 channel_mapping[4] = PCM_CHANNEL_RB;
2126 channel_mapping[5] = PCM_CHANNEL_LFE;
2127 channel_mapping[6] = PCM_CHANNEL_FLC;
2128 channel_mapping[7] = PCM_CHANNEL_FRC;
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07002129 } else {
2130 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
2131 num_channels);
2132 rc = -EINVAL;
2133 goto fail_cmd;
2134 }
2135
2136 rc = apr_send_pkt(ac->apr, (uint32_t *) &chan_map);
2137 if (rc < 0) {
2138 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
2139 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
2140 ASM_ENCDEC_DEC_CHAN_MAP);
2141 goto fail_cmd;
2142 }
2143 rc = wait_event_timeout(ac->cmd_wait,
2144 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2145 if (!rc) {
2146 pr_err("%s:timeout opcode[0x%x]\n", __func__,
2147 chan_map.hdr.opcode);
2148 rc = -ETIMEDOUT;
2149 goto fail_cmd;
2150 }
2151 return 0;
2152fail_cmd:
2153 return rc;
2154}
2155
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002156int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf,
2157 uint16_t min_rate, uint16_t max_rate,
2158 uint16_t reduced_rate_level, uint16_t rate_modulation_cmd)
2159{
2160 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2161 int rc = 0;
2162
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002163 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]",
2164 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002165 ac->session, frames_per_buf, min_rate, max_rate,
2166 reduced_rate_level, rate_modulation_cmd);
2167
2168 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2169
2170 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2171
2172 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2173 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2174
2175 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2176 enc_cfg.enc_blk.format_id = V13K_FS;
2177 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_qcelp13_read_cfg);
2178 enc_cfg.enc_blk.cfg.qcelp13.min_rate = min_rate;
2179 enc_cfg.enc_blk.cfg.qcelp13.max_rate = max_rate;
2180 enc_cfg.enc_blk.cfg.qcelp13.reduced_rate_level = reduced_rate_level;
2181 enc_cfg.enc_blk.cfg.qcelp13.rate_modulation_cmd = rate_modulation_cmd;
2182
2183 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2184 if (rc < 0) {
2185 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2186 goto fail_cmd;
2187 }
2188 rc = wait_event_timeout(ac->cmd_wait,
2189 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2190 if (!rc) {
2191 pr_err("timeout. waited for FORMAT_UPDATE\n");
2192 goto fail_cmd;
2193 }
2194 return 0;
2195fail_cmd:
2196 return -EINVAL;
2197}
2198
2199int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf,
2200 uint16_t min_rate, uint16_t max_rate,
2201 uint16_t rate_modulation_cmd)
2202{
2203 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2204 int rc = 0;
2205
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002206 pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] rate_modulation_cmd[0x%4x]",
2207 __func__, ac->session,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002208 frames_per_buf, min_rate, max_rate, rate_modulation_cmd);
2209
2210 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2211
2212 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2213
2214 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2215 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2216
2217 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2218 enc_cfg.enc_blk.format_id = EVRC_FS;
2219 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_evrc_read_cfg);
2220 enc_cfg.enc_blk.cfg.evrc.min_rate = min_rate;
2221 enc_cfg.enc_blk.cfg.evrc.max_rate = max_rate;
2222 enc_cfg.enc_blk.cfg.evrc.rate_modulation_cmd = rate_modulation_cmd;
2223 enc_cfg.enc_blk.cfg.evrc.reserved = 0;
2224
2225 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2226 if (rc < 0) {
2227 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2228 goto fail_cmd;
2229 }
2230 rc = wait_event_timeout(ac->cmd_wait,
2231 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2232 if (!rc) {
2233 pr_err("timeout. waited for FORMAT_UPDATE\n");
2234 goto fail_cmd;
2235 }
2236 return 0;
2237fail_cmd:
2238 return -EINVAL;
2239}
2240
2241int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf,
2242 uint16_t band_mode, uint16_t dtx_enable)
2243{
2244 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2245 int rc = 0;
2246
2247 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
2248 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
2249
2250 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2251
2252 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2253
2254 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2255 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2256
2257 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2258 enc_cfg.enc_blk.format_id = AMRNB_FS;
2259 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrnb_read_cfg);
2260 enc_cfg.enc_blk.cfg.amrnb.mode = band_mode;
2261 enc_cfg.enc_blk.cfg.amrnb.dtx_mode = dtx_enable;
2262
2263 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2264 if (rc < 0) {
2265 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2266 goto fail_cmd;
2267 }
2268 rc = wait_event_timeout(ac->cmd_wait,
2269 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2270 if (!rc) {
2271 pr_err("timeout. waited for FORMAT_UPDATE\n");
2272 goto fail_cmd;
2273 }
2274 return 0;
2275fail_cmd:
2276 return -EINVAL;
2277}
2278
Alex Wong2caeecc2011-10-28 10:52:15 +05302279int q6asm_enc_cfg_blk_amrwb(struct audio_client *ac, uint32_t frames_per_buf,
2280 uint16_t band_mode, uint16_t dtx_enable)
2281{
2282 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2283 int rc = 0;
2284
2285 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
2286 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
2287
2288 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2289
2290 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2291
2292 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2293 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2294
2295 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2296 enc_cfg.enc_blk.format_id = AMRWB_FS;
2297 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrwb_read_cfg);
2298 enc_cfg.enc_blk.cfg.amrwb.mode = band_mode;
2299 enc_cfg.enc_blk.cfg.amrwb.dtx_mode = dtx_enable;
2300
2301 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2302 if (rc < 0) {
2303 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2304 goto fail_cmd;
2305 }
2306 rc = wait_event_timeout(ac->cmd_wait,
2307 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2308 if (!rc) {
2309 pr_err("timeout. waited for FORMAT_UPDATE\n");
2310 goto fail_cmd;
2311 }
2312 return 0;
2313fail_cmd:
2314 return -EINVAL;
2315}
2316
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002317int q6asm_media_format_block_pcm(struct audio_client *ac,
2318 uint32_t rate, uint32_t channels)
2319{
2320 struct asm_stream_media_format_update fmt;
2321 int rc = 0;
2322
2323 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
2324 channels);
2325
2326 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2327
2328 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2329
2330 fmt.format = LINEAR_PCM;
2331 fmt.cfg_size = sizeof(struct asm_pcm_cfg);
2332 fmt.write_cfg.pcm_cfg.ch_cfg = channels;
2333 fmt.write_cfg.pcm_cfg.bits_per_sample = 16;
2334 fmt.write_cfg.pcm_cfg.sample_rate = rate;
2335 fmt.write_cfg.pcm_cfg.is_signed = 1;
2336 fmt.write_cfg.pcm_cfg.interleaved = 1;
2337
2338 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2339 if (rc < 0) {
2340 pr_err("%s:Comamnd open failed\n", __func__);
2341 goto fail_cmd;
2342 }
2343 rc = wait_event_timeout(ac->cmd_wait,
2344 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2345 if (!rc) {
2346 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2347 goto fail_cmd;
2348 }
2349 return 0;
2350fail_cmd:
2351 return -EINVAL;
2352}
2353
Kiran Kandi5e809b02012-01-31 00:24:33 -08002354int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
2355 uint32_t rate, uint32_t channels)
2356{
2357 struct asm_stream_media_format_update fmt;
2358 u8 *channel_mapping;
2359 int rc = 0;
2360
2361 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
2362 channels);
2363
2364 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2365
2366 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2367
2368 fmt.format = MULTI_CHANNEL_PCM;
2369 fmt.cfg_size = sizeof(struct asm_multi_channel_pcm_fmt_blk);
2370 fmt.write_cfg.multi_ch_pcm_cfg.num_channels = channels;
2371 fmt.write_cfg.multi_ch_pcm_cfg.bits_per_sample = 16;
2372 fmt.write_cfg.multi_ch_pcm_cfg.sample_rate = rate;
2373 fmt.write_cfg.multi_ch_pcm_cfg.is_signed = 1;
2374 fmt.write_cfg.multi_ch_pcm_cfg.is_interleaved = 1;
2375 channel_mapping =
2376 fmt.write_cfg.multi_ch_pcm_cfg.channel_mapping;
2377
2378 memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
2379
2380 if (channels == 1) {
2381 channel_mapping[0] = PCM_CHANNEL_FL;
2382 } else if (channels == 2) {
2383 channel_mapping[0] = PCM_CHANNEL_FL;
2384 channel_mapping[1] = PCM_CHANNEL_FR;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002385 } else if (channels == 4) {
2386 channel_mapping[0] = PCM_CHANNEL_FL;
2387 channel_mapping[1] = PCM_CHANNEL_FR;
2388 channel_mapping[1] = PCM_CHANNEL_LB;
2389 channel_mapping[1] = PCM_CHANNEL_RB;
Kiran Kandi5e809b02012-01-31 00:24:33 -08002390 } else if (channels == 6) {
SathishKumar Mani6074b772012-09-26 13:49:49 -07002391 channel_mapping[0] = PCM_CHANNEL_FL;
2392 channel_mapping[1] = PCM_CHANNEL_FR;
2393 channel_mapping[2] = PCM_CHANNEL_FC;
2394 channel_mapping[3] = PCM_CHANNEL_LFE;
2395 channel_mapping[4] = PCM_CHANNEL_LB;
2396 channel_mapping[5] = PCM_CHANNEL_RB;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002397 } else if (channels == 8) {
2398 channel_mapping[0] = PCM_CHANNEL_FC;
2399 channel_mapping[1] = PCM_CHANNEL_FL;
2400 channel_mapping[2] = PCM_CHANNEL_FR;
2401 channel_mapping[3] = PCM_CHANNEL_LB;
2402 channel_mapping[4] = PCM_CHANNEL_RB;
2403 channel_mapping[5] = PCM_CHANNEL_LFE;
2404 channel_mapping[6] = PCM_CHANNEL_FLC;
2405 channel_mapping[7] = PCM_CHANNEL_FRC;
Kiran Kandi5e809b02012-01-31 00:24:33 -08002406 } else {
2407 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
2408 channels);
2409 return -EINVAL;
2410 }
2411
2412 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2413 if (rc < 0) {
2414 pr_err("%s:Comamnd open failed\n", __func__);
2415 goto fail_cmd;
2416 }
2417 rc = wait_event_timeout(ac->cmd_wait,
2418 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2419 if (!rc) {
2420 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2421 goto fail_cmd;
2422 }
2423 return 0;
2424fail_cmd:
2425 return -EINVAL;
2426}
2427
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002428int q6asm_media_format_block_aac(struct audio_client *ac,
2429 struct asm_aac_cfg *cfg)
2430{
2431 struct asm_stream_media_format_update fmt;
2432 int rc = 0;
2433
2434 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2435 cfg->sample_rate, cfg->ch_cfg);
2436
2437 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2438
2439 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2440
2441 fmt.format = MPEG4_AAC;
2442 fmt.cfg_size = sizeof(struct asm_aac_cfg);
2443 fmt.write_cfg.aac_cfg.format = cfg->format;
2444 fmt.write_cfg.aac_cfg.aot = cfg->aot;
2445 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
2446 fmt.write_cfg.aac_cfg.section_data_resilience =
2447 cfg->section_data_resilience;
2448 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2449 cfg->scalefactor_data_resilience;
2450 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2451 cfg->spectral_data_resilience;
2452 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2453 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2454 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2455 __func__, fmt.format, fmt.cfg_size,
2456 fmt.write_cfg.aac_cfg.format,
2457 fmt.write_cfg.aac_cfg.aot,
2458 fmt.write_cfg.aac_cfg.ch_cfg,
2459 fmt.write_cfg.aac_cfg.sample_rate);
2460 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2461 if (rc < 0) {
2462 pr_err("%s:Comamnd open failed\n", __func__);
2463 goto fail_cmd;
2464 }
2465 rc = wait_event_timeout(ac->cmd_wait,
2466 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2467 if (!rc) {
2468 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2469 goto fail_cmd;
2470 }
2471 return 0;
2472fail_cmd:
2473 return -EINVAL;
2474}
2475
Ajit Khare43fd8832012-08-07 13:19:44 -07002476int q6asm_media_format_block_amrwbplus(struct audio_client *ac,
2477 struct asm_amrwbplus_cfg *cfg)
2478{
2479 struct asm_stream_media_format_update fmt;
2480 int rc = 0;
2481 pr_debug("q6asm_media_format_block_amrwbplus");
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07002482
Ajit Khare43fd8832012-08-07 13:19:44 -07002483 pr_debug("%s:session[%d]band-mode[%d]frame-fmt[%d]ch[%d]\n",
2484 __func__,
2485 ac->session,
2486 cfg->amr_band_mode,
2487 cfg->amr_frame_fmt,
2488 cfg->num_channels);
2489
2490 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2491
2492 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2493
2494 fmt.format = AMR_WB_PLUS;
2495 fmt.cfg_size = cfg->size_bytes;
2496
2497 fmt.write_cfg.amrwbplus_cfg.size_bytes = cfg->size_bytes;
2498 fmt.write_cfg.amrwbplus_cfg.version = cfg->version;
2499 fmt.write_cfg.amrwbplus_cfg.num_channels = cfg->num_channels;
2500 fmt.write_cfg.amrwbplus_cfg.amr_band_mode = cfg->amr_band_mode;
2501 fmt.write_cfg.amrwbplus_cfg.amr_dtx_mode = cfg->amr_dtx_mode;
2502 fmt.write_cfg.amrwbplus_cfg.amr_frame_fmt = cfg->amr_frame_fmt;
2503 fmt.write_cfg.amrwbplus_cfg.amr_lsf_idx = cfg->amr_lsf_idx;
2504
2505 pr_debug("%s: num_channels=%x amr_band_mode=%d amr_frame_fmt=%d\n",
2506 __func__,
2507 cfg->num_channels,
2508 cfg->amr_band_mode,
2509 cfg->amr_frame_fmt);
2510
2511 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2512 if (rc < 0) {
2513 pr_err("%s:Comamnd media format update failed..\n", __func__);
2514 goto fail_cmd;
2515 }
2516 rc = wait_event_timeout(ac->cmd_wait,
2517 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2518 if (!rc) {
2519 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2520 goto fail_cmd;
2521 }
2522 return 0;
2523fail_cmd:
2524 return -EINVAL;
2525}
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07002526int q6asm_media_format_block_multi_aac(struct audio_client *ac,
2527 struct asm_aac_cfg *cfg)
2528{
2529 struct asm_stream_media_format_update fmt;
2530 int rc = 0;
2531
2532 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2533 cfg->sample_rate, cfg->ch_cfg);
2534
2535 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2536
2537 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2538
2539 fmt.format = MPEG4_MULTI_AAC;
2540 fmt.cfg_size = sizeof(struct asm_aac_cfg);
2541 fmt.write_cfg.aac_cfg.format = cfg->format;
2542 fmt.write_cfg.aac_cfg.aot = cfg->aot;
2543 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
2544 fmt.write_cfg.aac_cfg.section_data_resilience =
2545 cfg->section_data_resilience;
2546 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2547 cfg->scalefactor_data_resilience;
2548 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2549 cfg->spectral_data_resilience;
2550 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2551 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2552 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2553 __func__, fmt.format, fmt.cfg_size,
2554 fmt.write_cfg.aac_cfg.format,
2555 fmt.write_cfg.aac_cfg.aot,
2556 fmt.write_cfg.aac_cfg.ch_cfg,
2557 fmt.write_cfg.aac_cfg.sample_rate);
2558 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2559 if (rc < 0) {
2560 pr_err("%s:Comamnd open failed\n", __func__);
2561 goto fail_cmd;
2562 }
2563 rc = wait_event_timeout(ac->cmd_wait,
2564 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2565 if (!rc) {
2566 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2567 goto fail_cmd;
2568 }
2569 return 0;
2570fail_cmd:
2571 return -EINVAL;
2572}
2573
2574
Alex Wong2caeecc2011-10-28 10:52:15 +05302575
2576int q6asm_media_format_block(struct audio_client *ac, uint32_t format)
2577{
2578
2579 struct asm_stream_media_format_update fmt;
2580 int rc = 0;
2581
2582 pr_debug("%s:session[%d] format[0x%x]\n", __func__,
2583 ac->session, format);
2584
2585 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2586 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302587 switch (format) {
2588 case FORMAT_V13K:
2589 fmt.format = V13K_FS;
2590 break;
2591 case FORMAT_EVRC:
2592 fmt.format = EVRC_FS;
2593 break;
2594 case FORMAT_AMRWB:
2595 fmt.format = AMRWB_FS;
2596 break;
Ajit Khare43fd8832012-08-07 13:19:44 -07002597 case FORMAT_AMR_WB_PLUS:
2598 fmt.format = AMR_WB_PLUS;
2599 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302600 case FORMAT_AMRNB:
2601 fmt.format = AMRNB_FS;
2602 break;
2603 case FORMAT_MP3:
2604 fmt.format = MP3;
2605 break;
Srikanth Uyyala66f781a2012-06-13 23:23:25 +05302606 case FORMAT_DTS:
2607 fmt.format = DTS;
2608 break;
2609 case FORMAT_DTS_LBR:
2610 fmt.format = DTS_LBR;
2611 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302612 default:
2613 pr_err("Invalid format[%d]\n", format);
2614 goto fail_cmd;
2615 }
Alex Wong2caeecc2011-10-28 10:52:15 +05302616 fmt.cfg_size = 0;
2617
2618 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2619 if (rc < 0) {
2620 pr_err("%s:Comamnd open failed\n", __func__);
2621 goto fail_cmd;
2622 }
2623 rc = wait_event_timeout(ac->cmd_wait,
2624 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2625 if (!rc) {
2626 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2627 goto fail_cmd;
2628 }
2629 return 0;
2630fail_cmd:
2631 return -EINVAL;
2632}
2633
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002634int q6asm_media_format_block_wma(struct audio_client *ac,
2635 void *cfg)
2636{
2637 struct asm_stream_media_format_update fmt;
2638 struct asm_wma_cfg *wma_cfg = (struct asm_wma_cfg *)cfg;
2639 int rc = 0;
2640
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002641 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 -07002642 ac->session, wma_cfg->format_tag, wma_cfg->sample_rate,
2643 wma_cfg->ch_cfg, wma_cfg->avg_bytes_per_sec,
2644 wma_cfg->block_align, wma_cfg->valid_bits_per_sample,
2645 wma_cfg->ch_mask, wma_cfg->encode_opt);
2646
2647 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2648
2649 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2650
2651 fmt.format = WMA_V9;
2652 fmt.cfg_size = sizeof(struct asm_wma_cfg);
2653 fmt.write_cfg.wma_cfg.format_tag = wma_cfg->format_tag;
2654 fmt.write_cfg.wma_cfg.ch_cfg = wma_cfg->ch_cfg;
2655 fmt.write_cfg.wma_cfg.sample_rate = wma_cfg->sample_rate;
2656 fmt.write_cfg.wma_cfg.avg_bytes_per_sec = wma_cfg->avg_bytes_per_sec;
2657 fmt.write_cfg.wma_cfg.block_align = wma_cfg->block_align;
2658 fmt.write_cfg.wma_cfg.valid_bits_per_sample =
2659 wma_cfg->valid_bits_per_sample;
2660 fmt.write_cfg.wma_cfg.ch_mask = wma_cfg->ch_mask;
2661 fmt.write_cfg.wma_cfg.encode_opt = wma_cfg->encode_opt;
2662 fmt.write_cfg.wma_cfg.adv_encode_opt = 0;
2663 fmt.write_cfg.wma_cfg.adv_encode_opt2 = 0;
2664 fmt.write_cfg.wma_cfg.drc_peak_ref = 0;
2665 fmt.write_cfg.wma_cfg.drc_peak_target = 0;
2666 fmt.write_cfg.wma_cfg.drc_ave_ref = 0;
2667 fmt.write_cfg.wma_cfg.drc_ave_target = 0;
2668
2669 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2670 if (rc < 0) {
2671 pr_err("%s:Comamnd open failed\n", __func__);
2672 goto fail_cmd;
2673 }
2674 rc = wait_event_timeout(ac->cmd_wait,
2675 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2676 if (!rc) {
2677 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2678 goto fail_cmd;
2679 }
2680 return 0;
2681fail_cmd:
2682 return -EINVAL;
2683}
2684
2685int q6asm_media_format_block_wmapro(struct audio_client *ac,
2686 void *cfg)
2687{
2688 struct asm_stream_media_format_update fmt;
2689 struct asm_wmapro_cfg *wmapro_cfg = (struct asm_wmapro_cfg *)cfg;
2690 int rc = 0;
2691
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002692 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 -07002693 ac->session, wmapro_cfg->format_tag, wmapro_cfg->sample_rate,
2694 wmapro_cfg->ch_cfg, wmapro_cfg->avg_bytes_per_sec,
2695 wmapro_cfg->block_align, wmapro_cfg->valid_bits_per_sample,
2696 wmapro_cfg->ch_mask, wmapro_cfg->encode_opt,
2697 wmapro_cfg->adv_encode_opt, wmapro_cfg->adv_encode_opt2);
2698
2699 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2700
2701 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2702
2703 fmt.format = WMA_V10PRO;
2704 fmt.cfg_size = sizeof(struct asm_wmapro_cfg);
2705 fmt.write_cfg.wmapro_cfg.format_tag = wmapro_cfg->format_tag;
2706 fmt.write_cfg.wmapro_cfg.ch_cfg = wmapro_cfg->ch_cfg;
2707 fmt.write_cfg.wmapro_cfg.sample_rate = wmapro_cfg->sample_rate;
2708 fmt.write_cfg.wmapro_cfg.avg_bytes_per_sec =
2709 wmapro_cfg->avg_bytes_per_sec;
2710 fmt.write_cfg.wmapro_cfg.block_align = wmapro_cfg->block_align;
2711 fmt.write_cfg.wmapro_cfg.valid_bits_per_sample =
2712 wmapro_cfg->valid_bits_per_sample;
2713 fmt.write_cfg.wmapro_cfg.ch_mask = wmapro_cfg->ch_mask;
2714 fmt.write_cfg.wmapro_cfg.encode_opt = wmapro_cfg->encode_opt;
2715 fmt.write_cfg.wmapro_cfg.adv_encode_opt = wmapro_cfg->adv_encode_opt;
2716 fmt.write_cfg.wmapro_cfg.adv_encode_opt2 = wmapro_cfg->adv_encode_opt2;
2717 fmt.write_cfg.wmapro_cfg.drc_peak_ref = 0;
2718 fmt.write_cfg.wmapro_cfg.drc_peak_target = 0;
2719 fmt.write_cfg.wmapro_cfg.drc_ave_ref = 0;
2720 fmt.write_cfg.wmapro_cfg.drc_ave_target = 0;
2721
2722 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2723 if (rc < 0) {
2724 pr_err("%s:Comamnd open failed\n", __func__);
2725 goto fail_cmd;
2726 }
2727 rc = wait_event_timeout(ac->cmd_wait,
2728 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2729 if (!rc) {
2730 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2731 goto fail_cmd;
2732 }
2733 return 0;
2734fail_cmd:
2735 return -EINVAL;
2736}
2737
2738int q6asm_memory_map(struct audio_client *ac, uint32_t buf_add, int dir,
2739 uint32_t bufsz, uint32_t bufcnt)
2740{
2741 struct asm_stream_cmd_memory_map mem_map;
2742 int rc = 0;
2743
2744 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2745 pr_err("APR handle NULL\n");
2746 return -EINVAL;
2747 }
2748
2749 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2750
2751 mem_map.hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP;
2752
2753 mem_map.buf_add = buf_add;
2754 mem_map.buf_size = bufsz * bufcnt;
2755 mem_map.mempool_id = 0; /* EBI */
2756 mem_map.reserved = 0;
2757
2758 q6asm_add_mmaphdr(&mem_map.hdr,
2759 sizeof(struct asm_stream_cmd_memory_map), TRUE);
2760
2761 pr_debug("buf add[%x] buf_add_parameter[%x]\n",
2762 mem_map.buf_add, buf_add);
2763
2764 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_map);
2765 if (rc < 0) {
2766 pr_err("mem_map op[0x%x]rc[%d]\n",
2767 mem_map.hdr.opcode, rc);
2768 rc = -EINVAL;
2769 goto fail_cmd;
2770 }
2771
2772 rc = wait_event_timeout(this_mmap.cmd_wait,
2773 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2774 if (!rc) {
2775 pr_err("timeout. waited for memory_map\n");
2776 rc = -EINVAL;
2777 goto fail_cmd;
2778 }
2779 rc = 0;
2780fail_cmd:
2781 return rc;
2782}
2783
2784int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add, int dir)
2785{
2786 struct asm_stream_cmd_memory_unmap mem_unmap;
2787 int rc = 0;
2788
2789 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2790 pr_err("APR handle NULL\n");
2791 return -EINVAL;
2792 }
2793 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2794
2795 q6asm_add_mmaphdr(&mem_unmap.hdr,
2796 sizeof(struct asm_stream_cmd_memory_unmap), TRUE);
2797 mem_unmap.hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP;
2798 mem_unmap.buf_add = buf_add;
2799
2800 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_unmap);
2801 if (rc < 0) {
2802 pr_err("mem_unmap op[0x%x]rc[%d]\n",
2803 mem_unmap.hdr.opcode, rc);
2804 rc = -EINVAL;
2805 goto fail_cmd;
2806 }
2807
2808 rc = wait_event_timeout(this_mmap.cmd_wait,
2809 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2810 if (!rc) {
2811 pr_err("timeout. waited for memory_map\n");
2812 rc = -EINVAL;
2813 goto fail_cmd;
2814 }
2815 rc = 0;
2816fail_cmd:
2817 return rc;
2818}
2819
2820int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain)
2821{
2822 void *vol_cmd = NULL;
2823 void *payload = NULL;
2824 struct asm_pp_params_command *cmd = NULL;
2825 struct asm_lrchannel_gain_params *lrgain = NULL;
2826 int sz = 0;
2827 int rc = 0;
2828
2829 sz = sizeof(struct asm_pp_params_command) +
2830 + sizeof(struct asm_lrchannel_gain_params);
2831 vol_cmd = kzalloc(sz, GFP_KERNEL);
2832 if (vol_cmd == NULL) {
2833 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2834 rc = -EINVAL;
2835 return rc;
2836 }
2837 cmd = (struct asm_pp_params_command *)vol_cmd;
2838 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2839 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2840 cmd->payload = NULL;
2841 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2842 sizeof(struct asm_lrchannel_gain_params);
2843 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2844 cmd->params.param_id = L_R_CHANNEL_GAIN_PARAM_ID;
2845 cmd->params.param_size = sizeof(struct asm_lrchannel_gain_params);
2846 cmd->params.reserved = 0;
2847
2848 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2849 lrgain = (struct asm_lrchannel_gain_params *)payload;
2850
2851 lrgain->left_gain = left_gain;
2852 lrgain->right_gain = right_gain;
2853 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2854 if (rc < 0) {
2855 pr_err("%s: Volume Command failed\n", __func__);
2856 rc = -EINVAL;
2857 goto fail_cmd;
2858 }
2859
2860 rc = wait_event_timeout(ac->cmd_wait,
2861 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2862 if (!rc) {
2863 pr_err("%s: timeout in sending volume command to apr\n",
2864 __func__);
2865 rc = -EINVAL;
2866 goto fail_cmd;
2867 }
2868 rc = 0;
2869fail_cmd:
2870 kfree(vol_cmd);
2871 return rc;
2872}
2873
2874static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
2875 uint32_t bufsz, uint32_t bufcnt)
2876{
2877 struct asm_stream_cmd_memory_map_regions *mmap_regions = NULL;
2878 struct asm_memory_map_regions *mregions = NULL;
2879 struct audio_port_data *port = NULL;
2880 struct audio_buffer *ab = NULL;
2881 void *mmap_region_cmd = NULL;
2882 void *payload = NULL;
2883 int rc = 0;
2884 int i = 0;
2885 int cmd_size = 0;
2886
2887 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2888 pr_err("APR handle NULL\n");
2889 return -EINVAL;
2890 }
2891 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2892
2893 cmd_size = sizeof(struct asm_stream_cmd_memory_map_regions)
2894 + sizeof(struct asm_memory_map_regions) * bufcnt;
2895
2896 mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302897 if (mmap_region_cmd == NULL) {
2898 pr_err("%s: Mem alloc failed\n", __func__);
2899 rc = -EINVAL;
2900 return rc;
2901 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002902 mmap_regions = (struct asm_stream_cmd_memory_map_regions *)
2903 mmap_region_cmd;
2904 q6asm_add_mmaphdr(&mmap_regions->hdr, cmd_size, TRUE);
2905 mmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP_REGIONS;
2906 mmap_regions->mempool_id = 0;
2907 mmap_regions->nregions = bufcnt & 0x00ff;
2908 pr_debug("map_regions->nregions = %d\n", mmap_regions->nregions);
2909 payload = ((u8 *) mmap_region_cmd +
2910 sizeof(struct asm_stream_cmd_memory_map_regions));
2911 mregions = (struct asm_memory_map_regions *)payload;
2912
2913 port = &ac->port[dir];
2914 for (i = 0; i < bufcnt; i++) {
2915 ab = &port->buf[i];
2916 mregions->phys = ab->phys;
2917 mregions->buf_size = ab->size;
2918 ++mregions;
2919 }
2920
2921 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) mmap_region_cmd);
2922 if (rc < 0) {
2923 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2924 mmap_regions->hdr.opcode, rc);
2925 rc = -EINVAL;
2926 goto fail_cmd;
2927 }
2928
2929 rc = wait_event_timeout(this_mmap.cmd_wait,
2930 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2931 if (!rc) {
2932 pr_err("timeout. waited for memory_map\n");
2933 rc = -EINVAL;
2934 goto fail_cmd;
2935 }
2936 rc = 0;
2937fail_cmd:
2938 kfree(mmap_region_cmd);
2939 return rc;
2940}
2941
2942static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir,
2943 uint32_t bufsz, uint32_t bufcnt)
2944{
2945 struct asm_stream_cmd_memory_unmap_regions *unmap_regions = NULL;
2946 struct asm_memory_unmap_regions *mregions = NULL;
2947 struct audio_port_data *port = NULL;
2948 struct audio_buffer *ab = NULL;
2949 void *unmap_region_cmd = NULL;
2950 void *payload = NULL;
2951 int rc = 0;
2952 int i = 0;
2953 int cmd_size = 0;
2954
2955 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2956 pr_err("APR handle NULL\n");
2957 return -EINVAL;
2958 }
2959 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2960
2961 cmd_size = sizeof(struct asm_stream_cmd_memory_unmap_regions) +
2962 sizeof(struct asm_memory_unmap_regions) * bufcnt;
2963
2964 unmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302965 if (unmap_region_cmd == NULL) {
2966 pr_err("%s: Mem alloc failed\n", __func__);
2967 rc = -EINVAL;
2968 return rc;
2969 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002970 unmap_regions = (struct asm_stream_cmd_memory_unmap_regions *)
2971 unmap_region_cmd;
2972 q6asm_add_mmaphdr(&unmap_regions->hdr, cmd_size, TRUE);
2973 unmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS;
2974 unmap_regions->nregions = bufcnt & 0x00ff;
2975 pr_debug("unmap_regions->nregions = %d\n", unmap_regions->nregions);
2976 payload = ((u8 *) unmap_region_cmd +
2977 sizeof(struct asm_stream_cmd_memory_unmap_regions));
2978 mregions = (struct asm_memory_unmap_regions *)payload;
2979 port = &ac->port[dir];
2980 for (i = 0; i < bufcnt; i++) {
2981 ab = &port->buf[i];
2982 mregions->phys = ab->phys;
2983 ++mregions;
2984 }
2985
2986 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) unmap_region_cmd);
2987 if (rc < 0) {
2988 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2989 unmap_regions->hdr.opcode, rc);
2990 goto fail_cmd;
2991 }
2992
2993 rc = wait_event_timeout(this_mmap.cmd_wait,
2994 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2995 if (!rc) {
2996 pr_err("timeout. waited for memory_unmap\n");
2997 goto fail_cmd;
2998 }
2999 rc = 0;
3000
3001fail_cmd:
3002 kfree(unmap_region_cmd);
3003 return rc;
3004}
3005
3006int q6asm_set_mute(struct audio_client *ac, int muteflag)
3007{
3008 void *vol_cmd = NULL;
3009 void *payload = NULL;
3010 struct asm_pp_params_command *cmd = NULL;
3011 struct asm_mute_params *mute = NULL;
3012 int sz = 0;
3013 int rc = 0;
3014
3015 sz = sizeof(struct asm_pp_params_command) +
3016 + sizeof(struct asm_mute_params);
3017 vol_cmd = kzalloc(sz, GFP_KERNEL);
3018 if (vol_cmd == NULL) {
3019 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3020 rc = -EINVAL;
3021 return rc;
3022 }
3023 cmd = (struct asm_pp_params_command *)vol_cmd;
3024 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3025 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3026 cmd->payload = NULL;
3027 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3028 sizeof(struct asm_mute_params);
3029 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3030 cmd->params.param_id = MUTE_CONFIG_PARAM_ID;
3031 cmd->params.param_size = sizeof(struct asm_mute_params);
3032 cmd->params.reserved = 0;
3033
3034 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3035 mute = (struct asm_mute_params *)payload;
3036
3037 mute->muteflag = muteflag;
3038 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3039 if (rc < 0) {
3040 pr_err("%s: Mute Command failed\n", __func__);
3041 rc = -EINVAL;
3042 goto fail_cmd;
3043 }
3044
3045 rc = wait_event_timeout(ac->cmd_wait,
3046 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3047 if (!rc) {
3048 pr_err("%s: timeout in sending mute command to apr\n",
3049 __func__);
3050 rc = -EINVAL;
3051 goto fail_cmd;
3052 }
3053 rc = 0;
3054fail_cmd:
3055 kfree(vol_cmd);
3056 return rc;
3057}
3058
3059int q6asm_set_volume(struct audio_client *ac, int volume)
3060{
3061 void *vol_cmd = NULL;
3062 void *payload = NULL;
3063 struct asm_pp_params_command *cmd = NULL;
3064 struct asm_master_gain_params *mgain = NULL;
3065 int sz = 0;
3066 int rc = 0;
3067
3068 sz = sizeof(struct asm_pp_params_command) +
3069 + sizeof(struct asm_master_gain_params);
3070 vol_cmd = kzalloc(sz, GFP_KERNEL);
3071 if (vol_cmd == NULL) {
3072 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3073 rc = -EINVAL;
3074 return rc;
3075 }
3076 cmd = (struct asm_pp_params_command *)vol_cmd;
3077 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3078 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3079 cmd->payload = NULL;
3080 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3081 sizeof(struct asm_master_gain_params);
3082 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3083 cmd->params.param_id = MASTER_GAIN_PARAM_ID;
3084 cmd->params.param_size = sizeof(struct asm_master_gain_params);
3085 cmd->params.reserved = 0;
3086
3087 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3088 mgain = (struct asm_master_gain_params *)payload;
3089
3090 mgain->master_gain = volume;
3091 mgain->padding = 0x00;
3092 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3093 if (rc < 0) {
3094 pr_err("%s: Volume Command failed\n", __func__);
3095 rc = -EINVAL;
3096 goto fail_cmd;
3097 }
3098
3099 rc = wait_event_timeout(ac->cmd_wait,
3100 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3101 if (!rc) {
3102 pr_err("%s: timeout in sending volume command to apr\n",
3103 __func__);
3104 rc = -EINVAL;
3105 goto fail_cmd;
3106 }
3107 rc = 0;
3108fail_cmd:
3109 kfree(vol_cmd);
3110 return rc;
3111}
3112
3113int q6asm_set_softpause(struct audio_client *ac,
3114 struct asm_softpause_params *pause_param)
3115{
3116 void *vol_cmd = NULL;
3117 void *payload = NULL;
3118 struct asm_pp_params_command *cmd = NULL;
3119 struct asm_softpause_params *params = NULL;
3120 int sz = 0;
3121 int rc = 0;
3122
3123 sz = sizeof(struct asm_pp_params_command) +
3124 + sizeof(struct asm_softpause_params);
3125 vol_cmd = kzalloc(sz, GFP_KERNEL);
3126 if (vol_cmd == NULL) {
3127 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3128 rc = -EINVAL;
3129 return rc;
3130 }
3131 cmd = (struct asm_pp_params_command *)vol_cmd;
3132 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3133 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3134 cmd->payload = NULL;
3135 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3136 sizeof(struct asm_softpause_params);
3137 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3138 cmd->params.param_id = SOFT_PAUSE_PARAM_ID;
3139 cmd->params.param_size = sizeof(struct asm_softpause_params);
3140 cmd->params.reserved = 0;
3141
3142 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3143 params = (struct asm_softpause_params *)payload;
3144
3145 params->enable = pause_param->enable;
3146 params->period = pause_param->period;
3147 params->step = pause_param->step;
3148 params->rampingcurve = pause_param->rampingcurve;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003149 pr_debug("%s: soft Pause Command: enable = %d, period = %d, step = %d, curve = %d\n",
3150 __func__, params->enable,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003151 params->period, params->step, params->rampingcurve);
3152 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3153 if (rc < 0) {
3154 pr_err("%s: Volume Command(soft_pause) failed\n", __func__);
3155 rc = -EINVAL;
3156 goto fail_cmd;
3157 }
3158
3159 rc = wait_event_timeout(ac->cmd_wait,
3160 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3161 if (!rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003162 pr_err("%s: timeout in sending volume command(soft_pause) to apr\n",
3163 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003164 rc = -EINVAL;
3165 goto fail_cmd;
3166 }
3167 rc = 0;
3168fail_cmd:
3169 kfree(vol_cmd);
3170 return rc;
3171}
3172
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003173int q6asm_set_softvolume(struct audio_client *ac,
3174 struct asm_softvolume_params *softvol_param)
3175{
3176 void *vol_cmd = NULL;
3177 void *payload = NULL;
3178 struct asm_pp_params_command *cmd = NULL;
3179 struct asm_softvolume_params *params = NULL;
3180 int sz = 0;
3181 int rc = 0;
3182
3183 sz = sizeof(struct asm_pp_params_command) +
3184 + sizeof(struct asm_softvolume_params);
3185 vol_cmd = kzalloc(sz, GFP_KERNEL);
3186 if (vol_cmd == NULL) {
3187 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3188 rc = -EINVAL;
3189 return rc;
3190 }
3191 cmd = (struct asm_pp_params_command *)vol_cmd;
3192 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3193 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3194 cmd->payload = NULL;
3195 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3196 sizeof(struct asm_softvolume_params);
3197 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3198 cmd->params.param_id = SOFT_VOLUME_PARAM_ID;
3199 cmd->params.param_size = sizeof(struct asm_softvolume_params);
3200 cmd->params.reserved = 0;
3201
3202 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3203 params = (struct asm_softvolume_params *)payload;
3204
3205 params->period = softvol_param->period;
3206 params->step = softvol_param->step;
3207 params->rampingcurve = softvol_param->rampingcurve;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003208 pr_debug("%s: soft Volume:opcode = %d,payload_sz =%d,module_id =%d, param_id = %d, param_sz = %d\n",
3209 __func__,
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003210 cmd->hdr.opcode, cmd->payload_size,
3211 cmd->params.module_id, cmd->params.param_id,
3212 cmd->params.param_size);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003213 pr_debug("%s: soft Volume Command: period = %d, step = %d, curve = %d\n",
3214 __func__, params->period,
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003215 params->step, params->rampingcurve);
3216 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3217 if (rc < 0) {
3218 pr_err("%s: Volume Command(soft_volume) failed\n", __func__);
3219 rc = -EINVAL;
3220 goto fail_cmd;
3221 }
3222
3223 rc = wait_event_timeout(ac->cmd_wait,
3224 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3225 if (!rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003226 pr_err("%s: timeout in sending volume command(soft_volume) to apr\n",
3227 __func__);
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003228 rc = -EINVAL;
3229 goto fail_cmd;
3230 }
3231 rc = 0;
3232fail_cmd:
3233 kfree(vol_cmd);
3234 return rc;
3235}
3236
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003237int q6asm_equalizer(struct audio_client *ac, void *eq)
3238{
3239 void *eq_cmd = NULL;
3240 void *payload = NULL;
3241 struct asm_pp_params_command *cmd = NULL;
3242 struct asm_equalizer_params *equalizer = NULL;
3243 struct msm_audio_eq_stream_config *eq_params = NULL;
3244 int i = 0;
3245 int sz = 0;
3246 int rc = 0;
3247
3248 sz = sizeof(struct asm_pp_params_command) +
3249 + sizeof(struct asm_equalizer_params);
3250 eq_cmd = kzalloc(sz, GFP_KERNEL);
3251 if (eq_cmd == NULL) {
3252 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3253 rc = -EINVAL;
3254 goto fail_cmd;
3255 }
3256 eq_params = (struct msm_audio_eq_stream_config *) eq;
3257 cmd = (struct asm_pp_params_command *)eq_cmd;
3258 q6asm_add_hdr(ac, &cmd->hdr, sz, TRUE);
3259 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3260 cmd->payload = NULL;
3261 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3262 sizeof(struct asm_equalizer_params);
3263 cmd->params.module_id = EQUALIZER_MODULE_ID;
3264 cmd->params.param_id = EQUALIZER_PARAM_ID;
3265 cmd->params.param_size = sizeof(struct asm_equalizer_params);
3266 cmd->params.reserved = 0;
3267 payload = (u8 *)(eq_cmd + sizeof(struct asm_pp_params_command));
3268 equalizer = (struct asm_equalizer_params *)payload;
3269
3270 equalizer->enable = eq_params->enable;
3271 equalizer->num_bands = eq_params->num_bands;
3272 pr_debug("%s: enable:%d numbands:%d\n", __func__, eq_params->enable,
3273 eq_params->num_bands);
3274 for (i = 0; i < eq_params->num_bands; i++) {
3275 equalizer->eq_bands[i].band_idx =
3276 eq_params->eq_bands[i].band_idx;
3277 equalizer->eq_bands[i].filter_type =
3278 eq_params->eq_bands[i].filter_type;
3279 equalizer->eq_bands[i].center_freq_hz =
3280 eq_params->eq_bands[i].center_freq_hz;
3281 equalizer->eq_bands[i].filter_gain =
3282 eq_params->eq_bands[i].filter_gain;
3283 equalizer->eq_bands[i].q_factor =
3284 eq_params->eq_bands[i].q_factor;
3285 pr_debug("%s: filter_type:%u bandnum:%d\n", __func__,
3286 eq_params->eq_bands[i].filter_type, i);
3287 pr_debug("%s: center_freq_hz:%u bandnum:%d\n", __func__,
3288 eq_params->eq_bands[i].center_freq_hz, i);
3289 pr_debug("%s: filter_gain:%d bandnum:%d\n", __func__,
3290 eq_params->eq_bands[i].filter_gain, i);
3291 pr_debug("%s: q_factor:%d bandnum:%d\n", __func__,
3292 eq_params->eq_bands[i].q_factor, i);
3293 }
3294 rc = apr_send_pkt(ac->apr, (uint32_t *) eq_cmd);
3295 if (rc < 0) {
3296 pr_err("%s: Equalizer Command failed\n", __func__);
3297 rc = -EINVAL;
3298 goto fail_cmd;
3299 }
3300
3301 rc = wait_event_timeout(ac->cmd_wait,
3302 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3303 if (!rc) {
3304 pr_err("%s: timeout in sending equalizer command to apr\n",
3305 __func__);
3306 rc = -EINVAL;
3307 goto fail_cmd;
3308 }
3309 rc = 0;
3310fail_cmd:
3311 kfree(eq_cmd);
3312 return rc;
3313}
3314
3315int q6asm_read(struct audio_client *ac)
3316{
3317 struct asm_stream_cmd_read read;
3318 struct audio_buffer *ab;
3319 int dsp_buf;
3320 struct audio_port_data *port;
3321 int rc;
3322 if (!ac || ac->apr == NULL) {
3323 pr_err("APR handle NULL\n");
3324 return -EINVAL;
3325 }
3326 if (ac->io_mode == SYNC_IO_MODE) {
3327 port = &ac->port[OUT];
3328
3329 q6asm_add_hdr(ac, &read.hdr, sizeof(read), FALSE);
3330
3331 mutex_lock(&port->lock);
3332
3333 dsp_buf = port->dsp_buf;
3334 ab = &port->buf[dsp_buf];
3335
3336 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
3337 __func__,
3338 ac->session,
3339 dsp_buf,
3340 (void *)port->buf[dsp_buf].data,
3341 port->cpu_buf,
3342 (void *)port->buf[port->cpu_buf].phys);
3343
3344 read.hdr.opcode = ASM_DATA_CMD_READ;
3345 read.buf_add = ab->phys;
3346 read.buf_size = ab->size;
3347 read.uid = port->dsp_buf;
3348 read.hdr.token = port->dsp_buf;
3349
3350 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3351 mutex_unlock(&port->lock);
3352 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
3353 read.buf_add,
3354 read.hdr.token,
3355 read.uid);
3356 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3357 if (rc < 0) {
3358 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
3359 goto fail_cmd;
3360 }
3361 return 0;
3362 }
3363fail_cmd:
3364 return -EINVAL;
3365}
3366
3367int q6asm_read_nolock(struct audio_client *ac)
3368{
3369 struct asm_stream_cmd_read read;
3370 struct audio_buffer *ab;
3371 int dsp_buf;
3372 struct audio_port_data *port;
3373 int rc;
3374 if (!ac || ac->apr == NULL) {
3375 pr_err("APR handle NULL\n");
3376 return -EINVAL;
3377 }
3378 if (ac->io_mode == SYNC_IO_MODE) {
3379 port = &ac->port[OUT];
3380
3381 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3382
3383
3384 dsp_buf = port->dsp_buf;
3385 ab = &port->buf[dsp_buf];
3386
3387 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
3388 __func__,
3389 ac->session,
3390 dsp_buf,
3391 (void *)port->buf[dsp_buf].data,
3392 port->cpu_buf,
3393 (void *)port->buf[port->cpu_buf].phys);
3394
3395 read.hdr.opcode = ASM_DATA_CMD_READ;
3396 read.buf_add = ab->phys;
3397 read.buf_size = ab->size;
3398 read.uid = port->dsp_buf;
3399 read.hdr.token = port->dsp_buf;
3400
3401 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3402 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
3403 read.buf_add,
3404 read.hdr.token,
3405 read.uid);
3406 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3407 if (rc < 0) {
3408 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
3409 goto fail_cmd;
3410 }
3411 return 0;
3412 }
3413fail_cmd:
3414 return -EINVAL;
3415}
3416
3417
3418static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
3419 uint32_t pkt_size, uint32_t cmd_flg)
3420{
3421 pr_debug("session=%d pkt size=%d cmd_flg=%d\n", pkt_size, cmd_flg,
3422 ac->session);
3423 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
3424 APR_HDR_LEN(sizeof(struct apr_hdr)),\
3425 APR_PKT_VER);
3426 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
3427 hdr->src_domain = APR_DOMAIN_APPS;
3428 hdr->dest_svc = APR_SVC_ASM;
3429 hdr->dest_domain = APR_DOMAIN_ADSP;
3430 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
3431 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
3432 if (cmd_flg) {
3433 hdr->token = ac->session;
3434 atomic_set(&ac->cmd_state, 1);
3435 }
3436 hdr->pkt_size = pkt_size;
3437 return;
3438}
3439
3440int q6asm_async_write(struct audio_client *ac,
3441 struct audio_aio_write_param *param)
3442{
3443 int rc = 0;
3444 struct asm_stream_cmd_write write;
3445
3446 if (!ac || ac->apr == NULL) {
3447 pr_err("%s: APR handle NULL\n", __func__);
3448 return -EINVAL;
3449 }
3450
3451 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write), FALSE);
3452
3453 /* Pass physical address as token for AIO scheme */
3454 write.hdr.token = param->uid;
3455 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3456 write.buf_add = param->paddr;
3457 write.avail_bytes = param->len;
3458 write.uid = param->uid;
3459 write.msw_ts = param->msw_ts;
3460 write.lsw_ts = param->lsw_ts;
3461 /* Use 0xFF00 for disabling timestamps */
3462 if (param->flags == 0xFF00)
3463 write.uflags = (0x00000000 | (param->flags & 0x800000FF));
3464 else
3465 write.uflags = (0x80000000 | param->flags);
3466
3467 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3468 write.buf_add, write.avail_bytes);
3469
3470 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3471 if (rc < 0) {
3472 pr_debug("[%s] write op[0x%x]rc[%d]\n", __func__,
3473 write.hdr.opcode, rc);
3474 goto fail_cmd;
3475 }
3476 return 0;
3477fail_cmd:
3478 return -EINVAL;
3479}
3480
3481int q6asm_async_read(struct audio_client *ac,
3482 struct audio_aio_read_param *param)
3483{
3484 int rc = 0;
3485 struct asm_stream_cmd_read read;
3486
3487 if (!ac || ac->apr == NULL) {
3488 pr_err("%s: APR handle NULL\n", __func__);
3489 return -EINVAL;
3490 }
3491
3492 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3493
3494 /* Pass physical address as token for AIO scheme */
3495 read.hdr.token = param->paddr;
3496 read.hdr.opcode = ASM_DATA_CMD_READ;
3497 read.buf_add = param->paddr;
3498 read.buf_size = param->len;
3499 read.uid = param->uid;
3500
3501 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3502 read.buf_add, read.buf_size);
3503
3504 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3505 if (rc < 0) {
3506 pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
3507 read.hdr.opcode, rc);
3508 goto fail_cmd;
3509 }
3510 return 0;
3511fail_cmd:
3512 return -EINVAL;
3513}
3514
Subhash Chandra Bose Naripeddy694b7d92012-06-20 20:46:13 -07003515int q6asm_async_read_compressed(struct audio_client *ac,
3516 struct audio_aio_read_param *param)
3517{
3518 int rc = 0;
3519 struct asm_stream_cmd_read read;
3520
3521 if (!ac || ac->apr == NULL) {
3522 pr_err("%s: APR handle NULL\n", __func__);
3523 return -EINVAL;
3524 }
3525
3526 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3527
3528 /* Pass physical address as token for AIO scheme */
3529 read.hdr.token = param->paddr;
3530 read.hdr.opcode = ASM_DATA_CMD_READ_COMPRESSED;
3531 read.buf_add = param->paddr;
3532 read.buf_size = param->len;
3533 read.uid = param->uid;
3534
3535 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3536 read.buf_add, read.buf_size);
3537
3538 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3539 if (rc < 0) {
3540 pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
3541 read.hdr.opcode, rc);
3542 goto fail_cmd;
3543 }
3544 return 0;
3545fail_cmd:
3546 return -EINVAL;
3547}
3548
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003549int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3550 uint32_t lsw_ts, uint32_t flags)
3551{
3552 int rc = 0;
3553 struct asm_stream_cmd_write write;
3554 struct audio_port_data *port;
3555 struct audio_buffer *ab;
3556 int dsp_buf = 0;
3557
3558 if (!ac || ac->apr == NULL) {
3559 pr_err("APR handle NULL\n");
3560 return -EINVAL;
3561 }
3562 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3563 if (ac->io_mode == SYNC_IO_MODE) {
3564 port = &ac->port[IN];
3565
3566 q6asm_add_hdr(ac, &write.hdr, sizeof(write),
3567 FALSE);
3568 mutex_lock(&port->lock);
3569
3570 dsp_buf = port->dsp_buf;
3571 ab = &port->buf[dsp_buf];
3572
3573 write.hdr.token = port->dsp_buf;
3574 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3575 write.buf_add = ab->phys;
3576 write.avail_bytes = len;
3577 write.uid = port->dsp_buf;
3578 write.msw_ts = msw_ts;
3579 write.lsw_ts = lsw_ts;
3580 /* Use 0xFF00 for disabling timestamps */
3581 if (flags == 0xFF00)
3582 write.uflags = (0x00000000 | (flags & 0x800000FF));
3583 else
3584 write.uflags = (0x80000000 | flags);
3585 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3586
3587 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3588 , __func__,
3589 ab->phys,
3590 write.buf_add,
3591 write.hdr.token,
3592 write.uid);
3593 mutex_unlock(&port->lock);
Rajesha Kini3498c932011-07-19 19:58:27 +05303594#ifdef CONFIG_DEBUG_FS
3595 if (out_enable_flag) {
3596 char zero_pattern[2] = {0x00, 0x00};
3597 /* If First two byte is non zero and last two byte
3598 is zero then it is warm output pattern */
3599 if ((strncmp(((char *)ab->data), zero_pattern, 2)) &&
3600 (!strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3601 do_gettimeofday(&out_warm_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003602 pr_debug("WARM:apr_send_pkt at %ld sec %ld microsec\n",
3603 out_warm_tv.tv_sec,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303604 out_warm_tv.tv_usec);
3605 pr_debug("Warm Pattern Matched");
3606 }
3607 /* If First two byte is zero and last two byte is
3608 non zero then it is cont ouput pattern */
3609 else if ((!strncmp(((char *)ab->data), zero_pattern, 2))
3610 && (strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3611 do_gettimeofday(&out_cont_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003612 pr_debug("CONT:apr_send_pkt at %ld sec %ld microsec\n",
3613 out_cont_tv.tv_sec,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303614 out_cont_tv.tv_usec);
3615 pr_debug("Cont Pattern Matched");
3616 }
3617 }
3618#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003619 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3620 if (rc < 0) {
3621 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3622 goto fail_cmd;
3623 }
3624 pr_debug("%s: WRITE SUCCESS\n", __func__);
3625 return 0;
3626 }
3627fail_cmd:
3628 return -EINVAL;
3629}
3630
3631int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3632 uint32_t lsw_ts, uint32_t flags)
3633{
3634 int rc = 0;
3635 struct asm_stream_cmd_write write;
3636 struct audio_port_data *port;
3637 struct audio_buffer *ab;
3638 int dsp_buf = 0;
3639
3640 if (!ac || ac->apr == NULL) {
3641 pr_err("APR handle NULL\n");
3642 return -EINVAL;
3643 }
3644 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3645 if (ac->io_mode == SYNC_IO_MODE) {
3646 port = &ac->port[IN];
3647
3648 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write),
3649 FALSE);
3650
3651 dsp_buf = port->dsp_buf;
3652 ab = &port->buf[dsp_buf];
3653
3654 write.hdr.token = port->dsp_buf;
3655 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3656 write.buf_add = ab->phys;
3657 write.avail_bytes = len;
3658 write.uid = port->dsp_buf;
3659 write.msw_ts = msw_ts;
3660 write.lsw_ts = lsw_ts;
3661 /* Use 0xFF00 for disabling timestamps */
3662 if (flags == 0xFF00)
3663 write.uflags = (0x00000000 | (flags & 0x800000FF));
3664 else
3665 write.uflags = (0x80000000 | flags);
3666 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3667
3668 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3669 , __func__,
3670 ab->phys,
3671 write.buf_add,
3672 write.hdr.token,
3673 write.uid);
3674
3675 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3676 if (rc < 0) {
3677 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3678 goto fail_cmd;
3679 }
3680 pr_debug("%s: WRITE SUCCESS\n", __func__);
3681 return 0;
3682 }
3683fail_cmd:
3684 return -EINVAL;
3685}
3686
3687uint64_t q6asm_get_session_time(struct audio_client *ac)
3688{
3689 struct apr_hdr hdr;
3690 int rc;
3691
3692 if (!ac || ac->apr == NULL) {
3693 pr_err("APR handle NULL\n");
3694 return -EINVAL;
3695 }
Swaminathan Sathappanc7f98992012-07-09 11:07:12 -07003696 q6asm_add_hdr(ac, &hdr, sizeof(hdr), FALSE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003697 hdr.opcode = ASM_SESSION_CMD_GET_SESSION_TIME;
3698 atomic_set(&ac->time_flag, 1);
3699
3700 pr_debug("%s: session[%d]opcode[0x%x]\n", __func__,
3701 ac->session,
3702 hdr.opcode);
3703 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3704 if (rc < 0) {
3705 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3706 goto fail_cmd;
3707 }
3708 rc = wait_event_timeout(ac->time_wait,
3709 (atomic_read(&ac->time_flag) == 0), 5*HZ);
3710 if (!rc) {
3711 pr_err("%s: timeout in getting session time from DSP\n",
3712 __func__);
3713 goto fail_cmd;
3714 }
3715 return ac->time_stamp;
3716
3717fail_cmd:
3718 return -EINVAL;
3719}
3720
3721int q6asm_cmd(struct audio_client *ac, int cmd)
3722{
3723 struct apr_hdr hdr;
3724 int rc;
3725 atomic_t *state;
3726 int cnt = 0;
3727
3728 if (!ac || ac->apr == NULL) {
3729 pr_err("APR handle NULL\n");
3730 return -EINVAL;
3731 }
3732 q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
3733 switch (cmd) {
3734 case CMD_PAUSE:
3735 pr_debug("%s:CMD_PAUSE\n", __func__);
3736 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3737 state = &ac->cmd_state;
3738 break;
3739 case CMD_FLUSH:
3740 pr_debug("%s:CMD_FLUSH\n", __func__);
3741 hdr.opcode = ASM_STREAM_CMD_FLUSH;
3742 state = &ac->cmd_state;
3743 break;
3744 case CMD_OUT_FLUSH:
3745 pr_debug("%s:CMD_OUT_FLUSH\n", __func__);
3746 hdr.opcode = ASM_STREAM_CMD_FLUSH_READBUFS;
3747 state = &ac->cmd_state;
3748 break;
3749 case CMD_EOS:
3750 pr_debug("%s:CMD_EOS\n", __func__);
3751 hdr.opcode = ASM_DATA_CMD_EOS;
3752 atomic_set(&ac->cmd_state, 0);
3753 state = &ac->cmd_state;
3754 break;
3755 case CMD_CLOSE:
3756 pr_debug("%s:CMD_CLOSE\n", __func__);
3757 hdr.opcode = ASM_STREAM_CMD_CLOSE;
3758 state = &ac->cmd_state;
3759 break;
3760 default:
3761 pr_err("Invalid format[%d]\n", cmd);
3762 goto fail_cmd;
3763 }
3764 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3765 ac->session,
3766 hdr.opcode);
3767 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3768 if (rc < 0) {
3769 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3770 goto fail_cmd;
3771 }
3772 rc = wait_event_timeout(ac->cmd_wait, (atomic_read(state) == 0), 5*HZ);
3773 if (!rc) {
3774 pr_err("timeout. waited for response opcode[0x%x]\n",
3775 hdr.opcode);
3776 goto fail_cmd;
3777 }
3778 if (cmd == CMD_FLUSH)
3779 q6asm_reset_buf_state(ac);
3780 if (cmd == CMD_CLOSE) {
3781 /* check if DSP return all buffers */
3782 if (ac->port[IN].buf) {
3783 for (cnt = 0; cnt < ac->port[IN].max_buf_cnt;
3784 cnt++) {
3785 if (ac->port[IN].buf[cnt].used == IN) {
3786 pr_debug("Write Buf[%d] not returned\n",
3787 cnt);
3788 }
3789 }
3790 }
3791 if (ac->port[OUT].buf) {
3792 for (cnt = 0; cnt < ac->port[OUT].max_buf_cnt; cnt++) {
3793 if (ac->port[OUT].buf[cnt].used == OUT) {
3794 pr_debug("Read Buf[%d] not returned\n",
3795 cnt);
3796 }
3797 }
3798 }
3799 }
3800 return 0;
3801fail_cmd:
3802 return -EINVAL;
3803}
3804
3805int q6asm_cmd_nowait(struct audio_client *ac, int cmd)
3806{
3807 struct apr_hdr hdr;
3808 int rc;
3809
3810 if (!ac || ac->apr == NULL) {
3811 pr_err("%s:APR handle NULL\n", __func__);
3812 return -EINVAL;
3813 }
3814 q6asm_add_hdr_async(ac, &hdr, sizeof(hdr), TRUE);
3815 switch (cmd) {
3816 case CMD_PAUSE:
3817 pr_debug("%s:CMD_PAUSE\n", __func__);
3818 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3819 break;
3820 case CMD_EOS:
3821 pr_debug("%s:CMD_EOS\n", __func__);
3822 hdr.opcode = ASM_DATA_CMD_EOS;
3823 break;
3824 default:
3825 pr_err("%s:Invalid format[%d]\n", __func__, cmd);
3826 goto fail_cmd;
3827 }
3828 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3829 ac->session,
3830 hdr.opcode);
Jay Wang0668d1062012-07-11 18:53:21 -07003831
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003832 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3833 if (rc < 0) {
3834 pr_err("%s:Commmand 0x%x failed\n", __func__, hdr.opcode);
3835 goto fail_cmd;
3836 }
Jay Wang0668d1062012-07-11 18:53:21 -07003837 atomic_inc(&ac->nowait_cmd_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003838 return 0;
3839fail_cmd:
3840 return -EINVAL;
3841}
3842
3843static void q6asm_reset_buf_state(struct audio_client *ac)
3844{
3845 int cnt = 0;
3846 int loopcnt = 0;
3847 struct audio_port_data *port = NULL;
3848
3849 if (ac->io_mode == SYNC_IO_MODE) {
3850 mutex_lock(&ac->cmd_lock);
3851 for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
3852 port = &ac->port[loopcnt];
3853 cnt = port->max_buf_cnt - 1;
3854 port->dsp_buf = 0;
3855 port->cpu_buf = 0;
3856 while (cnt >= 0) {
3857 if (!port->buf)
3858 continue;
3859 port->buf[cnt].used = 1;
3860 cnt--;
3861 }
3862 }
3863 mutex_unlock(&ac->cmd_lock);
3864 }
3865}
3866
3867int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable)
3868{
3869 struct asm_stream_cmd_reg_tx_overflow_event tx_overflow;
3870 int rc;
3871
3872 if (!ac || ac->apr == NULL) {
3873 pr_err("APR handle NULL\n");
3874 return -EINVAL;
3875 }
3876 pr_debug("%s:session[%d]enable[%d]\n", __func__,
3877 ac->session, enable);
3878 q6asm_add_hdr(ac, &tx_overflow.hdr, sizeof(tx_overflow), TRUE);
3879
3880 tx_overflow.hdr.opcode = \
3881 ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS;
3882 /* tx overflow event: enable */
3883 tx_overflow.enable = enable;
3884
3885 rc = apr_send_pkt(ac->apr, (uint32_t *) &tx_overflow);
3886 if (rc < 0) {
3887 pr_err("tx overflow op[0x%x]rc[%d]\n", \
3888 tx_overflow.hdr.opcode, rc);
3889 goto fail_cmd;
3890 }
3891 rc = wait_event_timeout(ac->cmd_wait,
3892 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3893 if (!rc) {
3894 pr_err("timeout. waited for tx overflow\n");
3895 goto fail_cmd;
3896 }
3897 return 0;
3898fail_cmd:
3899 return -EINVAL;
3900}
3901
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003902int q6asm_get_apr_service_id(int session_id)
3903{
3904 pr_debug("%s\n", __func__);
3905
Shiv Maliyappanahallia84982a2012-01-19 15:25:04 -08003906 if (session_id < 0 || session_id > SESSION_MAX) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003907 pr_err("%s: invalid session_id = %d\n", __func__, session_id);
3908 return -EINVAL;
3909 }
3910
3911 return ((struct apr_svc *)session[session_id]->apr)->id;
3912}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003913
3914
3915static int __init q6asm_init(void)
3916{
3917 pr_debug("%s\n", __func__);
3918 init_waitqueue_head(&this_mmap.cmd_wait);
3919 memset(session, 0, sizeof(session));
Rajesha Kini3498c932011-07-19 19:58:27 +05303920#ifdef CONFIG_DEBUG_FS
3921 out_buffer = kmalloc(OUT_BUFFER_SIZE, GFP_KERNEL);
3922 out_dentry = debugfs_create_file("audio_out_latency_measurement_node",\
Glenn Kasten5dfda802012-10-04 16:40:27 -07003923 0664,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303924 NULL, NULL, &audio_output_latency_debug_fops);
3925 if (IS_ERR(out_dentry))
3926 pr_err("debugfs_create_file failed\n");
3927 in_buffer = kmalloc(IN_BUFFER_SIZE, GFP_KERNEL);
3928 in_dentry = debugfs_create_file("audio_in_latency_measurement_node",\
Glenn Kasten5dfda802012-10-04 16:40:27 -07003929 0664,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303930 NULL, NULL, &audio_input_latency_debug_fops);
3931 if (IS_ERR(in_dentry))
3932 pr_err("debugfs_create_file failed\n");
3933#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003934 return 0;
3935}
3936
3937device_initcall(q6asm_init);