blob: 6bef9ba8140598935c6f41bddf7c17cebdc6438d [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001
2/*
Kiran Kandi5e809b02012-01-31 00:24:33 -08003 * Copyright (c) 2010-2012, Code Aurora Forum. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004 * Author: Brian Swetland <swetland@google.com>
5 *
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16#include <linux/fs.h>
17#include <linux/mutex.h>
18#include <linux/wait.h>
19#include <linux/miscdevice.h>
20#include <linux/uaccess.h>
21#include <linux/sched.h>
22#include <linux/dma-mapping.h>
23#include <linux/miscdevice.h>
24#include <linux/delay.h>
25#include <linux/spinlock.h>
26#include <linux/slab.h>
27#include <linux/msm_audio.h>
28#include <linux/android_pmem.h>
29#include <linux/memory_alloc.h>
Ben Rombergerfce8f512011-07-18 16:46:09 -070030#include <linux/debugfs.h>
31#include <linux/time.h>
32#include <linux/atomic.h>
33
34#include <asm/ioctls.h>
35
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070036#include <mach/memory.h>
37#include <mach/debug_mm.h>
38#include <mach/peripheral-loader.h>
39#include <mach/qdsp6v2/audio_acdb.h>
40#include <mach/qdsp6v2/rtac.h>
Ben Rombergerfce8f512011-07-18 16:46:09 -070041
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070042#include <sound/apr_audio.h>
43#include <sound/q6asm.h>
Ben Rombergerfce8f512011-07-18 16:46:09 -070044
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070045
46#define TRUE 0x01
47#define FALSE 0x00
48#define READDONE_IDX_STATUS 0
49#define READDONE_IDX_BUFFER 1
50#define READDONE_IDX_SIZE 2
51#define READDONE_IDX_OFFSET 3
52#define READDONE_IDX_MSW_TS 4
53#define READDONE_IDX_LSW_TS 5
54#define READDONE_IDX_FLAGS 6
55#define READDONE_IDX_NUMFRAMES 7
56#define READDONE_IDX_ID 8
Rajesha Kini3498c932011-07-19 19:58:27 +053057#ifdef CONFIG_DEBUG_FS
58#define OUT_BUFFER_SIZE 56
59#define IN_BUFFER_SIZE 24
60#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070061static DEFINE_MUTEX(session_lock);
62
63/* session id: 0 reserved */
64static struct audio_client *session[SESSION_MAX+1];
65static int32_t q6asm_mmapcallback(struct apr_client_data *data, void *priv);
66static int32_t q6asm_callback(struct apr_client_data *data, void *priv);
67static void q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
68 uint32_t pkt_size, uint32_t cmd_flg);
69static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
70 uint32_t pkt_size, uint32_t cmd_flg);
71static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
72 uint32_t bufsz, uint32_t bufcnt);
73static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir,
74 uint32_t bufsz, uint32_t bufcnt);
75
76static void q6asm_reset_buf_state(struct audio_client *ac);
77
Rajesha Kini3498c932011-07-19 19:58:27 +053078#ifdef CONFIG_DEBUG_FS
79static struct timeval out_cold_tv;
80static struct timeval out_warm_tv;
81static struct timeval out_cont_tv;
82static struct timeval in_cont_tv;
83static long out_enable_flag;
84static long in_enable_flag;
85static struct dentry *out_dentry;
86static struct dentry *in_dentry;
87static int in_cont_index;
88/*This var is used to keep track of first write done for cold output latency */
89static int out_cold_index;
90static char *out_buffer;
91static char *in_buffer;
92static int audio_output_latency_dbgfs_open(struct inode *inode,
93 struct file *file)
94{
95 file->private_data = inode->i_private;
96 return 0;
97}
98static ssize_t audio_output_latency_dbgfs_read(struct file *file,
99 char __user *buf, size_t count, loff_t *ppos)
100{
101 snprintf(out_buffer, OUT_BUFFER_SIZE, "%ld,%ld,%ld,%ld,%ld,%ld,",\
102 out_cold_tv.tv_sec, out_cold_tv.tv_usec, out_warm_tv.tv_sec,\
103 out_warm_tv.tv_usec, out_cont_tv.tv_sec, out_cont_tv.tv_usec);
104 return simple_read_from_buffer(buf, OUT_BUFFER_SIZE, ppos,
105 out_buffer, OUT_BUFFER_SIZE);
106}
107static ssize_t audio_output_latency_dbgfs_write(struct file *file,
108 const char __user *buf, size_t count, loff_t *ppos)
109{
110 char *temp;
111
112 if (count > 2*sizeof(char))
113 return -EINVAL;
114 else
115 temp = kmalloc(2*sizeof(char), GFP_KERNEL);
116
117 out_cold_index = 0;
118
119 if (temp) {
120 if (copy_from_user(temp, buf, 2*sizeof(char))) {
121 kfree(temp);
122 return -EFAULT;
123 }
124 if (!strict_strtol(temp, 10, &out_enable_flag)) {
125 kfree(temp);
126 return count;
127 }
128 kfree(temp);
129 }
130 return -EINVAL;
131}
132static const struct file_operations audio_output_latency_debug_fops = {
133 .open = audio_output_latency_dbgfs_open,
134 .read = audio_output_latency_dbgfs_read,
135 .write = audio_output_latency_dbgfs_write
136};
137
138static int audio_input_latency_dbgfs_open(struct inode *inode,
139 struct file *file)
140{
141 file->private_data = inode->i_private;
142 return 0;
143}
144static ssize_t audio_input_latency_dbgfs_read(struct file *file,
145 char __user *buf, size_t count, loff_t *ppos)
146{
147 snprintf(in_buffer, IN_BUFFER_SIZE, "%ld,%ld,",\
148 in_cont_tv.tv_sec, in_cont_tv.tv_usec);
149 return simple_read_from_buffer(buf, IN_BUFFER_SIZE, ppos,
150 in_buffer, IN_BUFFER_SIZE);
151}
152static ssize_t audio_input_latency_dbgfs_write(struct file *file,
153 const char __user *buf, size_t count, loff_t *ppos)
154{
155 char *temp;
156
157 if (count > 2*sizeof(char))
158 return -EINVAL;
159 else
160 temp = kmalloc(2*sizeof(char), GFP_KERNEL);
161 if (temp) {
162 if (copy_from_user(temp, buf, 2*sizeof(char))) {
163 kfree(temp);
164 return -EFAULT;
165 }
166 if (!strict_strtol(temp, 10, &in_enable_flag)) {
167 kfree(temp);
168 return count;
169 }
170 kfree(temp);
171 }
172 return -EINVAL;
173}
174static const struct file_operations audio_input_latency_debug_fops = {
175 .open = audio_input_latency_dbgfs_open,
176 .read = audio_input_latency_dbgfs_read,
177 .write = audio_input_latency_dbgfs_write
178};
179#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700180struct asm_mmap {
181 atomic_t ref_cnt;
182 atomic_t cmd_state;
183 wait_queue_head_t cmd_wait;
184 void *apr;
185};
186
187static struct asm_mmap this_mmap;
188
189static int q6asm_session_alloc(struct audio_client *ac)
190{
191 int n;
192 mutex_lock(&session_lock);
193 for (n = 1; n <= SESSION_MAX; n++) {
194 if (!session[n]) {
195 session[n] = ac;
196 mutex_unlock(&session_lock);
197 return n;
198 }
199 }
200 mutex_unlock(&session_lock);
201 return -ENOMEM;
202}
203
204static void q6asm_session_free(struct audio_client *ac)
205{
206 pr_debug("%s: sessionid[%d]\n", __func__, ac->session);
Ben Romberger93d4d2d2011-10-19 23:04:02 -0700207 rtac_remove_popp_from_adm_devices(ac->session);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700208 mutex_lock(&session_lock);
209 session[ac->session] = 0;
210 mutex_unlock(&session_lock);
211 ac->session = 0;
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700212 ac->perf_mode = false;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700213 return;
214}
215
216int q6asm_audio_client_buf_free(unsigned int dir,
217 struct audio_client *ac)
218{
219 struct audio_port_data *port;
220 int cnt = 0;
221 int rc = 0;
222 pr_debug("%s: Session id %d\n", __func__, ac->session);
223 mutex_lock(&ac->cmd_lock);
224 if (ac->io_mode == SYNC_IO_MODE) {
225 port = &ac->port[dir];
226 if (!port->buf) {
227 mutex_unlock(&ac->cmd_lock);
228 return 0;
229 }
230 cnt = port->max_buf_cnt - 1;
231
232 if (cnt >= 0) {
233 rc = q6asm_memory_unmap_regions(ac, dir,
234 port->buf[0].size,
235 port->max_buf_cnt);
236 if (rc < 0)
237 pr_err("%s CMD Memory_unmap_regions failed\n",
238 __func__);
239 }
240
241 while (cnt >= 0) {
242 if (port->buf[cnt].data) {
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800243#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
244 ion_unmap_kernel(port->buf[cnt].client,
245 port->buf[cnt].handle);
246 ion_free(port->buf[cnt].client,
247 port->buf[cnt].handle);
248 ion_client_destroy(port->buf[cnt].client);
249#else
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700250 pr_debug("%s:data[%p]phys[%p][%p] cnt[%d] mem_buffer[%p]\n",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700251 __func__, (void *)port->buf[cnt].data,
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700252 (void *)port->buf[cnt].phys,
253 (void *)&port->buf[cnt].phys, cnt,
254 (void *)port->buf[cnt].mem_buffer);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700255 if (IS_ERR((void *)port->buf[cnt].mem_buffer))
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700256 pr_err("%s:mem buffer invalid, error = %ld\n",
257 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700258 PTR_ERR((void *)port->buf[cnt].mem_buffer));
259 else {
Laura Abbottea3e7b62012-04-30 15:59:21 -0700260 if (iounmap(
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700261 port->buf[cnt].mem_buffer) < 0)
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700262 pr_err("%s: unmap buffer failed\n",
263 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700264 }
265 free_contiguous_memory_by_paddr(
266 port->buf[cnt].phys);
267
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800268#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700269 port->buf[cnt].data = NULL;
270 port->buf[cnt].phys = 0;
271 --(port->max_buf_cnt);
272 }
273 --cnt;
274 }
275 kfree(port->buf);
276 port->buf = NULL;
277 }
278 mutex_unlock(&ac->cmd_lock);
279 return 0;
280}
281
282int q6asm_audio_client_buf_free_contiguous(unsigned int dir,
283 struct audio_client *ac)
284{
285 struct audio_port_data *port;
286 int cnt = 0;
287 int rc = 0;
288 pr_debug("%s: Session id %d\n", __func__, ac->session);
289 mutex_lock(&ac->cmd_lock);
290 port = &ac->port[dir];
291 if (!port->buf) {
292 mutex_unlock(&ac->cmd_lock);
293 return 0;
294 }
295 cnt = port->max_buf_cnt - 1;
296
297 if (cnt >= 0) {
Deepa Madiregama7d52a402011-07-13 20:28:36 +0530298 rc = q6asm_memory_unmap(ac, port->buf[0].phys, dir);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700299 if (rc < 0)
300 pr_err("%s CMD Memory_unmap_regions failed\n",
301 __func__);
302 }
303
304 if (port->buf[0].data) {
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800305#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
306 ion_unmap_kernel(port->buf[0].client, port->buf[0].handle);
307 ion_free(port->buf[0].client, port->buf[0].handle);
308 ion_client_destroy(port->buf[0].client);
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700309 pr_debug("%s:data[%p]phys[%p][%p], client[%p] handle[%p]\n",
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800310 __func__,
311 (void *)port->buf[0].data,
312 (void *)port->buf[0].phys,
313 (void *)&port->buf[0].phys,
314 (void *)port->buf[0].client,
315 (void *)port->buf[0].handle);
316#else
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700317 pr_debug("%s:data[%p]phys[%p][%p] mem_buffer[%p]\n",
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700318 __func__,
319 (void *)port->buf[0].data,
320 (void *)port->buf[0].phys,
321 (void *)&port->buf[0].phys,
322 (void *)port->buf[0].mem_buffer);
323 if (IS_ERR((void *)port->buf[0].mem_buffer))
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700324 pr_err("%s:mem buffer invalid, error = %ld\n",
325 __func__,
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700326 PTR_ERR((void *)port->buf[0].mem_buffer));
327 else {
Laura Abbottea3e7b62012-04-30 15:59:21 -0700328 if (iounmap(
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700329 port->buf[0].mem_buffer) < 0)
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700330 pr_err("%s: unmap buffer failed\n", __func__);
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700331 }
332 free_contiguous_memory_by_paddr(port->buf[0].phys);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800333#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700334 }
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700335
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700336 while (cnt >= 0) {
337 port->buf[cnt].data = NULL;
338 port->buf[cnt].phys = 0;
339 cnt--;
340 }
341 port->max_buf_cnt = 0;
342 kfree(port->buf);
343 port->buf = NULL;
344 mutex_unlock(&ac->cmd_lock);
345 return 0;
346}
347
348void q6asm_audio_client_free(struct audio_client *ac)
349{
350 int loopcnt;
351 struct audio_port_data *port;
352 if (!ac || !ac->session)
353 return;
354 pr_debug("%s: Session id %d\n", __func__, ac->session);
355 if (ac->io_mode == SYNC_IO_MODE) {
356 for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
357 port = &ac->port[loopcnt];
358 if (!port->buf)
359 continue;
360 pr_debug("%s:loopcnt = %d\n", __func__, loopcnt);
361 q6asm_audio_client_buf_free(loopcnt, ac);
362 }
363 }
364
365 apr_deregister(ac->apr);
366 q6asm_session_free(ac);
367
368 pr_debug("%s: APR De-Register\n", __func__);
369 if (atomic_read(&this_mmap.ref_cnt) <= 0) {
370 pr_err("%s: APR Common Port Already Closed\n", __func__);
371 goto done;
372 }
373
374 atomic_dec(&this_mmap.ref_cnt);
375 if (atomic_read(&this_mmap.ref_cnt) == 0) {
376 apr_deregister(this_mmap.apr);
377 pr_debug("%s:APR De-Register common port\n", __func__);
378 }
379done:
380 kfree(ac);
381 return;
382}
383
384int q6asm_set_io_mode(struct audio_client *ac, uint32_t mode)
385{
386 if (ac == NULL) {
387 pr_err("%s APR handle NULL\n", __func__);
388 return -EINVAL;
389 }
390 if ((mode == ASYNC_IO_MODE) || (mode == SYNC_IO_MODE)) {
391 ac->io_mode = mode;
392 pr_debug("%s:Set Mode to %d\n", __func__, ac->io_mode);
393 return 0;
394 } else {
395 pr_err("%s:Not an valid IO Mode:%d\n", __func__, ac->io_mode);
396 return -EINVAL;
397 }
398}
399
400struct audio_client *q6asm_audio_client_alloc(app_cb cb, void *priv)
401{
402 struct audio_client *ac;
403 int n;
404 int lcnt = 0;
405
406 ac = kzalloc(sizeof(struct audio_client), GFP_KERNEL);
407 if (!ac)
408 return NULL;
409 n = q6asm_session_alloc(ac);
410 if (n <= 0)
411 goto fail_session;
412 ac->session = n;
413 ac->cb = cb;
414 ac->priv = priv;
415 ac->io_mode = SYNC_IO_MODE;
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700416 ac->perf_mode = false;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700417 ac->apr = apr_register("ADSP", "ASM", \
418 (apr_fn)q6asm_callback,\
419 ((ac->session) << 8 | 0x0001),\
420 ac);
421
422 if (ac->apr == NULL) {
423 pr_err("%s Registration with APR failed\n", __func__);
424 goto fail;
425 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700426 rtac_set_asm_handle(n, ac->apr);
Ben Rombergerfce8f512011-07-18 16:46:09 -0700427
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700428 pr_debug("%s Registering the common port with APR\n", __func__);
429 if (atomic_read(&this_mmap.ref_cnt) == 0) {
430 this_mmap.apr = apr_register("ADSP", "ASM", \
431 (apr_fn)q6asm_mmapcallback,\
432 0x0FFFFFFFF, &this_mmap);
433 if (this_mmap.apr == NULL) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700434 pr_debug("%s Unable to register APR ASM common port\n",
435 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700436 goto fail;
437 }
438 }
439
440 atomic_inc(&this_mmap.ref_cnt);
441 init_waitqueue_head(&ac->cmd_wait);
442 init_waitqueue_head(&ac->time_wait);
443 atomic_set(&ac->time_flag, 1);
444 mutex_init(&ac->cmd_lock);
445 for (lcnt = 0; lcnt <= OUT; lcnt++) {
446 mutex_init(&ac->port[lcnt].lock);
447 spin_lock_init(&ac->port[lcnt].dsp_lock);
448 }
449 atomic_set(&ac->cmd_state, 0);
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +0530450 atomic_set(&ac->cmd_response, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700451
452 pr_debug("%s: session[%d]\n", __func__, ac->session);
453
454 return ac;
455fail:
456 q6asm_audio_client_free(ac);
457 return NULL;
458fail_session:
459 kfree(ac);
460 return NULL;
461}
462
Ben Romberger61754dc2011-10-31 18:25:41 -0700463struct audio_client *q6asm_get_audio_client(int session_id)
464{
465 if ((session_id <= 0) || (session_id > SESSION_MAX)) {
466 pr_err("%s: invalid session: %d\n", __func__, session_id);
467 goto err;
468 }
469
470 if (!session[session_id]) {
471 pr_err("%s: session not active: %d\n", __func__, session_id);
472 goto err;
473 }
474
475 return session[session_id];
476err:
477 return NULL;
478}
479
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700480int q6asm_audio_client_buf_alloc(unsigned int dir,
481 struct audio_client *ac,
482 unsigned int bufsz,
483 unsigned int bufcnt)
484{
485 int cnt = 0;
486 int rc = 0;
487 struct audio_buffer *buf;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800488#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
489 int len;
490#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700491
492 if (!(ac) || ((dir != IN) && (dir != OUT)))
493 return -EINVAL;
494
495 pr_debug("%s: session[%d]bufsz[%d]bufcnt[%d]\n", __func__, ac->session,
496 bufsz, bufcnt);
497
498 if (ac->session <= 0 || ac->session > 8)
499 goto fail;
500
501 if (ac->io_mode == SYNC_IO_MODE) {
502 if (ac->port[dir].buf) {
503 pr_debug("%s: buffer already allocated\n", __func__);
504 return 0;
505 }
506 mutex_lock(&ac->cmd_lock);
507 buf = kzalloc(((sizeof(struct audio_buffer))*bufcnt),
508 GFP_KERNEL);
509
510 if (!buf) {
511 mutex_unlock(&ac->cmd_lock);
512 goto fail;
513 }
514
515 ac->port[dir].buf = buf;
516
517 while (cnt < bufcnt) {
518 if (bufsz > 0) {
519 if (!buf[cnt].data) {
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800520#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
521 buf[cnt].client = msm_ion_client_create
522 (UINT_MAX, "audio_client");
523 if (IS_ERR_OR_NULL((void *)
524 buf[cnt].client)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700525 pr_err("%s: ION create client for AUDIO failed\n",
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800526 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700527 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800528 goto fail;
529 }
530 buf[cnt].handle = ion_alloc
531 (buf[cnt].client, bufsz, SZ_4K,
Hanumant Singh2ac41c92012-08-29 18:39:44 -0700532 (0x1 << ION_AUDIO_HEAP_ID), 0);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800533 if (IS_ERR_OR_NULL((void *)
534 buf[cnt].handle)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700535 pr_err("%s: ION memory allocation for AUDIO failed\n",
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800536 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700537 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800538 goto fail;
539 }
540
541 rc = ion_phys(buf[cnt].client,
542 buf[cnt].handle,
543 (ion_phys_addr_t *)
544 &buf[cnt].phys,
545 (size_t *)&len);
546 if (rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700547 pr_err("%s: ION Get Physical for AUDIO failed, rc = %d\n",
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800548 __func__, rc);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700549 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800550 goto fail;
551 }
552
553 buf[cnt].data = ion_map_kernel
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;
1629 case FORMAT_V13K:
1630 open.write_format = V13K_FS;
1631 break;
1632 case FORMAT_EVRC:
1633 open.write_format = EVRC_FS;
1634 break;
1635 case FORMAT_EVRCB:
1636 open.write_format = EVRCB_FS;
1637 break;
1638 case FORMAT_EVRCWB:
1639 open.write_format = EVRCWB_FS;
1640 break;
1641 case FORMAT_MP3:
1642 open.write_format = MP3;
1643 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001644 default:
1645 pr_err("Invalid format[%d]\n", wr_format);
1646 goto fail_cmd;
1647 }
1648
1649 switch (rd_format) {
1650 case FORMAT_LINEAR_PCM:
1651 open.read_format = LINEAR_PCM;
1652 break;
1653 case FORMAT_MPEG4_AAC:
1654 open.read_format = MPEG4_AAC;
1655 break;
1656 case FORMAT_V13K:
1657 open.read_format = V13K_FS;
1658 break;
1659 case FORMAT_EVRC:
1660 open.read_format = EVRC_FS;
1661 break;
1662 case FORMAT_AMRNB:
1663 open.read_format = AMRNB_FS;
1664 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301665 case FORMAT_AMRWB:
1666 open.read_format = AMRWB_FS;
1667 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001668 default:
1669 pr_err("Invalid format[%d]\n", rd_format);
1670 goto fail_cmd;
1671 }
1672 pr_debug("%s:rdformat[0x%x]wrformat[0x%x]\n", __func__,
1673 open.read_format, open.write_format);
1674
1675 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1676 if (rc < 0) {
1677 pr_err("open failed op[0x%x]rc[%d]\n", \
1678 open.hdr.opcode, rc);
1679 goto fail_cmd;
1680 }
1681 rc = wait_event_timeout(ac->cmd_wait,
1682 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1683 if (!rc) {
1684 pr_err("timeout. waited for OPEN_WRITE rc[%d]\n", rc);
1685 goto fail_cmd;
1686 }
1687 return 0;
1688fail_cmd:
1689 return -EINVAL;
1690}
1691
1692int q6asm_run(struct audio_client *ac, uint32_t flags,
1693 uint32_t msw_ts, uint32_t lsw_ts)
1694{
1695 struct asm_stream_cmd_run run;
1696 int rc;
1697 if (!ac || ac->apr == NULL) {
1698 pr_err("APR handle NULL\n");
1699 return -EINVAL;
1700 }
1701 pr_debug("%s session[%d]", __func__, ac->session);
1702 q6asm_add_hdr(ac, &run.hdr, sizeof(run), TRUE);
1703
1704 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1705 run.flags = flags;
1706 run.msw_ts = msw_ts;
1707 run.lsw_ts = lsw_ts;
Rajesha Kini3498c932011-07-19 19:58:27 +05301708#ifdef CONFIG_DEBUG_FS
1709 if (out_enable_flag) {
1710 do_gettimeofday(&out_cold_tv);
1711 pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",\
1712 out_cold_tv.tv_sec, out_cold_tv.tv_usec);
1713 }
1714#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001715 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1716 if (rc < 0) {
1717 pr_err("Commmand run failed[%d]", rc);
1718 goto fail_cmd;
1719 }
1720
1721 rc = wait_event_timeout(ac->cmd_wait,
1722 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1723 if (!rc) {
1724 pr_err("timeout. waited for run success rc[%d]", rc);
1725 goto fail_cmd;
1726 }
1727
1728 return 0;
1729fail_cmd:
1730 return -EINVAL;
1731}
1732
1733int q6asm_run_nowait(struct audio_client *ac, uint32_t flags,
1734 uint32_t msw_ts, uint32_t lsw_ts)
1735{
1736 struct asm_stream_cmd_run run;
1737 int rc;
1738 if (!ac || ac->apr == NULL) {
1739 pr_err("%s:APR handle NULL\n", __func__);
1740 return -EINVAL;
1741 }
1742 pr_debug("session[%d]", ac->session);
1743 q6asm_add_hdr_async(ac, &run.hdr, sizeof(run), TRUE);
1744
1745 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1746 run.flags = flags;
1747 run.msw_ts = msw_ts;
1748 run.lsw_ts = lsw_ts;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001749 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1750 if (rc < 0) {
1751 pr_err("%s:Commmand run failed[%d]", __func__, rc);
1752 return -EINVAL;
1753 }
Jay Wang0668d1062012-07-11 18:53:21 -07001754 atomic_inc(&ac->nowait_cmd_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001755 return 0;
1756}
1757
1758
1759int q6asm_enc_cfg_blk_aac(struct audio_client *ac,
1760 uint32_t frames_per_buf,
1761 uint32_t sample_rate, uint32_t channels,
1762 uint32_t bit_rate, uint32_t mode, uint32_t format)
1763{
1764 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1765 int rc = 0;
1766
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001767 pr_debug("%s:session[%d]frames[%d]SR[%d]ch[%d]bitrate[%d]mode[%d] format[%d]",
1768 __func__, ac->session, frames_per_buf,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001769 sample_rate, channels, bit_rate, mode, format);
1770
1771 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1772
1773 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1774 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1775 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1776 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1777 enc_cfg.enc_blk.format_id = MPEG4_AAC;
1778 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_aac_read_cfg);
1779 enc_cfg.enc_blk.cfg.aac.bitrate = bit_rate;
1780 enc_cfg.enc_blk.cfg.aac.enc_mode = mode;
1781 enc_cfg.enc_blk.cfg.aac.format = format;
1782 enc_cfg.enc_blk.cfg.aac.ch_cfg = channels;
1783 enc_cfg.enc_blk.cfg.aac.sample_rate = sample_rate;
1784
1785 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1786 if (rc < 0) {
1787 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1788 rc = -EINVAL;
1789 goto fail_cmd;
1790 }
1791 rc = wait_event_timeout(ac->cmd_wait,
1792 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1793 if (!rc) {
1794 pr_err("timeout. waited for FORMAT_UPDATE\n");
1795 goto fail_cmd;
1796 }
1797 return 0;
1798fail_cmd:
1799 return -EINVAL;
1800}
1801
1802int q6asm_enc_cfg_blk_pcm(struct audio_client *ac,
1803 uint32_t rate, uint32_t channels)
1804{
1805 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1806
1807 int rc = 0;
1808
1809 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1810 ac->session, rate, channels);
1811
1812 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1813
1814 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1815 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1816 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1817 enc_cfg.enc_blk.frames_per_buf = 1;
1818 enc_cfg.enc_blk.format_id = LINEAR_PCM;
1819 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg);
1820 enc_cfg.enc_blk.cfg.pcm.ch_cfg = channels;
1821 enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16;
1822 enc_cfg.enc_blk.cfg.pcm.sample_rate = rate;
1823 enc_cfg.enc_blk.cfg.pcm.is_signed = 1;
1824 enc_cfg.enc_blk.cfg.pcm.interleaved = 1;
1825
1826 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1827 if (rc < 0) {
1828 pr_err("Comamnd open failed\n");
1829 rc = -EINVAL;
1830 goto fail_cmd;
1831 }
1832 rc = wait_event_timeout(ac->cmd_wait,
1833 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1834 if (!rc) {
1835 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1836 goto fail_cmd;
1837 }
1838 return 0;
1839fail_cmd:
1840 return -EINVAL;
1841}
1842
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001843int q6asm_enc_cfg_blk_pcm_native(struct audio_client *ac,
1844 uint32_t rate, uint32_t channels)
1845{
1846 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1847
1848 int rc = 0;
1849
1850 pr_debug("%s: Session %d, rate = %d, channels = %d, setting the rate and channels to 0 for native\n",
1851 __func__, ac->session, rate, channels);
1852
1853 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1854
1855 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1856 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1857 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1858 enc_cfg.enc_blk.frames_per_buf = 1;
1859 enc_cfg.enc_blk.format_id = LINEAR_PCM;
1860 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg);
1861 enc_cfg.enc_blk.cfg.pcm.ch_cfg = 0;/*channels;*/
1862 enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16;
1863 enc_cfg.enc_blk.cfg.pcm.sample_rate = 0;/*rate;*/
1864 enc_cfg.enc_blk.cfg.pcm.is_signed = 1;
1865 enc_cfg.enc_blk.cfg.pcm.interleaved = 1;
1866
1867 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1868 if (rc < 0) {
1869 pr_err("Comamnd open failed\n");
1870 rc = -EINVAL;
1871 goto fail_cmd;
1872 }
1873 rc = wait_event_timeout(ac->cmd_wait,
1874 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1875 if (!rc) {
1876 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1877 goto fail_cmd;
1878 }
1879 return 0;
1880fail_cmd:
1881 return -EINVAL;
1882}
1883
Mingming Yin647e9ea2012-03-17 19:56:10 -07001884int q6asm_enc_cfg_blk_multi_ch_pcm(struct audio_client *ac,
1885 uint32_t rate, uint32_t channels)
1886{
1887 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1888
1889 int rc = 0;
1890
1891 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1892 ac->session, rate, channels);
1893
1894 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1895
1896 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1897 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1898 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1899 enc_cfg.enc_blk.frames_per_buf = 1;
1900 enc_cfg.enc_blk.format_id = MULTI_CHANNEL_PCM;
1901 enc_cfg.enc_blk.cfg_size =
1902 sizeof(struct asm_multi_channel_pcm_fmt_blk);
1903 enc_cfg.enc_blk.cfg.mpcm.num_channels = channels;
1904 enc_cfg.enc_blk.cfg.mpcm.bits_per_sample = 16;
1905 enc_cfg.enc_blk.cfg.mpcm.sample_rate = rate;
1906 enc_cfg.enc_blk.cfg.mpcm.is_signed = 1;
1907 enc_cfg.enc_blk.cfg.mpcm.is_interleaved = 1;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07001908 if (channels == 1) {
1909 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1910 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = 0;
1911 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = 0;
1912 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = 0;
1913 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1914 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1915 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1916 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1917 } else if (channels == 2) {
Subhash Chandra Bose Naripeddy8477d222012-06-12 00:30:54 -07001918 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1919 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1920 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = 0;
1921 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = 0;
1922 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1923 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1924 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1925 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1926 } else if (channels == 4) {
1927 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1928 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1929 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_RB;
1930 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_LB;
1931 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1932 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1933 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1934 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1935 } else if (channels == 6) {
1936 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1937 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1938 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_LFE;
1939 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_FC;
1940 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = PCM_CHANNEL_LB;
1941 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = PCM_CHANNEL_RB;
1942 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1943 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1944 } else if (channels == 8) {
1945 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1946 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1947 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_LFE;
1948 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_FC;
1949 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = PCM_CHANNEL_LB;
1950 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = PCM_CHANNEL_RB;
1951 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = PCM_CHANNEL_FLC;
1952 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = PCM_CHANNEL_FRC;
1953 }
Mingming Yin647e9ea2012-03-17 19:56:10 -07001954
1955 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1956 if (rc < 0) {
1957 pr_err("Comamnd open failed\n");
1958 rc = -EINVAL;
1959 goto fail_cmd;
1960 }
1961 rc = wait_event_timeout(ac->cmd_wait,
1962 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1963 if (!rc) {
1964 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1965 goto fail_cmd;
1966 }
1967 return 0;
1968fail_cmd:
1969 return -EINVAL;
1970}
1971
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001972int q6asm_enable_sbrps(struct audio_client *ac,
1973 uint32_t sbr_ps_enable)
1974{
1975 struct asm_stream_cmd_encdec_sbr sbrps;
1976
1977 int rc = 0;
1978
1979 pr_debug("%s: Session %d\n", __func__, ac->session);
1980
1981 q6asm_add_hdr(ac, &sbrps.hdr, sizeof(sbrps), TRUE);
1982
1983 sbrps.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1984 sbrps.param_id = ASM_ENABLE_SBR_PS;
1985 sbrps.param_size = sizeof(struct asm_sbr_ps);
1986 sbrps.sbr_ps.enable = sbr_ps_enable;
1987
1988 rc = apr_send_pkt(ac->apr, (uint32_t *) &sbrps);
1989 if (rc < 0) {
1990 pr_err("Command opcode[0x%x]paramid[0x%x] failed\n",
1991 ASM_STREAM_CMD_SET_ENCDEC_PARAM,
1992 ASM_ENABLE_SBR_PS);
1993 rc = -EINVAL;
1994 goto fail_cmd;
1995 }
1996 rc = wait_event_timeout(ac->cmd_wait,
1997 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1998 if (!rc) {
1999 pr_err("timeout opcode[0x%x] ", sbrps.hdr.opcode);
2000 goto fail_cmd;
2001 }
2002 return 0;
2003fail_cmd:
2004 return -EINVAL;
2005}
2006
Swaminathan Sathappan70765cd2011-07-19 18:42:47 -07002007int q6asm_cfg_dual_mono_aac(struct audio_client *ac,
2008 uint16_t sce_left, uint16_t sce_right)
2009{
2010 struct asm_stream_cmd_encdec_dualmono dual_mono;
2011
2012 int rc = 0;
2013
2014 pr_debug("%s: Session %d, sce_left = %d, sce_right = %d\n",
2015 __func__, ac->session, sce_left, sce_right);
2016
2017 q6asm_add_hdr(ac, &dual_mono.hdr, sizeof(dual_mono), TRUE);
2018
2019 dual_mono.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2020 dual_mono.param_id = ASM_CONFIGURE_DUAL_MONO;
2021 dual_mono.param_size = sizeof(struct asm_dual_mono);
2022 dual_mono.channel_map.sce_left = sce_left;
2023 dual_mono.channel_map.sce_right = sce_right;
2024
2025 rc = apr_send_pkt(ac->apr, (uint32_t *) &dual_mono);
2026 if (rc < 0) {
2027 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
2028 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
2029 ASM_CONFIGURE_DUAL_MONO);
2030 rc = -EINVAL;
2031 goto fail_cmd;
2032 }
2033 rc = wait_event_timeout(ac->cmd_wait,
2034 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2035 if (!rc) {
2036 pr_err("%s:timeout opcode[0x%x]\n", __func__,
2037 dual_mono.hdr.opcode);
2038 goto fail_cmd;
2039 }
2040 return 0;
2041fail_cmd:
2042 return -EINVAL;
2043}
2044
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07002045int q6asm_set_encdec_chan_map(struct audio_client *ac,
2046 uint32_t num_channels)
2047{
2048 struct asm_stream_cmd_encdec_channelmap chan_map;
2049 u8 *channel_mapping;
2050
2051 int rc = 0;
2052
2053 pr_debug("%s: Session %d, num_channels = %d\n",
2054 __func__, ac->session, num_channels);
2055
2056 q6asm_add_hdr(ac, &chan_map.hdr, sizeof(chan_map), TRUE);
2057
2058 chan_map.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2059 chan_map.param_id = ASM_ENCDEC_DEC_CHAN_MAP;
2060 chan_map.param_size = sizeof(struct asm_dec_chan_map);
2061 chan_map.chan_map.num_channels = num_channels;
2062
2063 channel_mapping =
2064 chan_map.chan_map.channel_mapping;
2065
2066 memset(channel_mapping, PCM_CHANNEL_NULL, MAX_CHAN_MAP_CHANNELS);
2067 if (num_channels == 1) {
2068 channel_mapping[0] = PCM_CHANNEL_FL;
2069 } else if (num_channels == 2) {
2070 channel_mapping[0] = PCM_CHANNEL_FL;
2071 channel_mapping[1] = PCM_CHANNEL_FR;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002072 } else if (num_channels == 4) {
2073 channel_mapping[0] = PCM_CHANNEL_FL;
2074 channel_mapping[1] = PCM_CHANNEL_FR;
2075 channel_mapping[1] = PCM_CHANNEL_LB;
2076 channel_mapping[1] = PCM_CHANNEL_RB;
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07002077 } else if (num_channels == 6) {
2078 channel_mapping[0] = PCM_CHANNEL_FC;
2079 channel_mapping[1] = PCM_CHANNEL_FL;
2080 channel_mapping[2] = PCM_CHANNEL_FR;
2081 channel_mapping[3] = PCM_CHANNEL_LB;
2082 channel_mapping[4] = PCM_CHANNEL_RB;
2083 channel_mapping[5] = PCM_CHANNEL_LFE;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002084 } else if (num_channels == 8) {
2085 channel_mapping[0] = PCM_CHANNEL_FC;
2086 channel_mapping[1] = PCM_CHANNEL_FL;
2087 channel_mapping[2] = PCM_CHANNEL_FR;
2088 channel_mapping[3] = PCM_CHANNEL_LB;
2089 channel_mapping[4] = PCM_CHANNEL_RB;
2090 channel_mapping[5] = PCM_CHANNEL_LFE;
2091 channel_mapping[6] = PCM_CHANNEL_FLC;
2092 channel_mapping[7] = PCM_CHANNEL_FRC;
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07002093 } else {
2094 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
2095 num_channels);
2096 rc = -EINVAL;
2097 goto fail_cmd;
2098 }
2099
2100 rc = apr_send_pkt(ac->apr, (uint32_t *) &chan_map);
2101 if (rc < 0) {
2102 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
2103 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
2104 ASM_ENCDEC_DEC_CHAN_MAP);
2105 goto fail_cmd;
2106 }
2107 rc = wait_event_timeout(ac->cmd_wait,
2108 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2109 if (!rc) {
2110 pr_err("%s:timeout opcode[0x%x]\n", __func__,
2111 chan_map.hdr.opcode);
2112 rc = -ETIMEDOUT;
2113 goto fail_cmd;
2114 }
2115 return 0;
2116fail_cmd:
2117 return rc;
2118}
2119
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002120int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf,
2121 uint16_t min_rate, uint16_t max_rate,
2122 uint16_t reduced_rate_level, uint16_t rate_modulation_cmd)
2123{
2124 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2125 int rc = 0;
2126
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002127 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]",
2128 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002129 ac->session, frames_per_buf, min_rate, max_rate,
2130 reduced_rate_level, rate_modulation_cmd);
2131
2132 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2133
2134 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2135
2136 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2137 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2138
2139 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2140 enc_cfg.enc_blk.format_id = V13K_FS;
2141 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_qcelp13_read_cfg);
2142 enc_cfg.enc_blk.cfg.qcelp13.min_rate = min_rate;
2143 enc_cfg.enc_blk.cfg.qcelp13.max_rate = max_rate;
2144 enc_cfg.enc_blk.cfg.qcelp13.reduced_rate_level = reduced_rate_level;
2145 enc_cfg.enc_blk.cfg.qcelp13.rate_modulation_cmd = rate_modulation_cmd;
2146
2147 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2148 if (rc < 0) {
2149 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2150 goto fail_cmd;
2151 }
2152 rc = wait_event_timeout(ac->cmd_wait,
2153 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2154 if (!rc) {
2155 pr_err("timeout. waited for FORMAT_UPDATE\n");
2156 goto fail_cmd;
2157 }
2158 return 0;
2159fail_cmd:
2160 return -EINVAL;
2161}
2162
2163int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf,
2164 uint16_t min_rate, uint16_t max_rate,
2165 uint16_t rate_modulation_cmd)
2166{
2167 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2168 int rc = 0;
2169
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002170 pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] rate_modulation_cmd[0x%4x]",
2171 __func__, ac->session,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002172 frames_per_buf, min_rate, max_rate, rate_modulation_cmd);
2173
2174 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2175
2176 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2177
2178 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2179 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2180
2181 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2182 enc_cfg.enc_blk.format_id = EVRC_FS;
2183 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_evrc_read_cfg);
2184 enc_cfg.enc_blk.cfg.evrc.min_rate = min_rate;
2185 enc_cfg.enc_blk.cfg.evrc.max_rate = max_rate;
2186 enc_cfg.enc_blk.cfg.evrc.rate_modulation_cmd = rate_modulation_cmd;
2187 enc_cfg.enc_blk.cfg.evrc.reserved = 0;
2188
2189 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2190 if (rc < 0) {
2191 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2192 goto fail_cmd;
2193 }
2194 rc = wait_event_timeout(ac->cmd_wait,
2195 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2196 if (!rc) {
2197 pr_err("timeout. waited for FORMAT_UPDATE\n");
2198 goto fail_cmd;
2199 }
2200 return 0;
2201fail_cmd:
2202 return -EINVAL;
2203}
2204
2205int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf,
2206 uint16_t band_mode, uint16_t dtx_enable)
2207{
2208 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2209 int rc = 0;
2210
2211 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
2212 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
2213
2214 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2215
2216 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2217
2218 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2219 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2220
2221 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2222 enc_cfg.enc_blk.format_id = AMRNB_FS;
2223 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrnb_read_cfg);
2224 enc_cfg.enc_blk.cfg.amrnb.mode = band_mode;
2225 enc_cfg.enc_blk.cfg.amrnb.dtx_mode = dtx_enable;
2226
2227 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2228 if (rc < 0) {
2229 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2230 goto fail_cmd;
2231 }
2232 rc = wait_event_timeout(ac->cmd_wait,
2233 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2234 if (!rc) {
2235 pr_err("timeout. waited for FORMAT_UPDATE\n");
2236 goto fail_cmd;
2237 }
2238 return 0;
2239fail_cmd:
2240 return -EINVAL;
2241}
2242
Alex Wong2caeecc2011-10-28 10:52:15 +05302243int q6asm_enc_cfg_blk_amrwb(struct audio_client *ac, uint32_t frames_per_buf,
2244 uint16_t band_mode, uint16_t dtx_enable)
2245{
2246 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2247 int rc = 0;
2248
2249 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
2250 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
2251
2252 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2253
2254 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2255
2256 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2257 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2258
2259 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2260 enc_cfg.enc_blk.format_id = AMRWB_FS;
2261 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrwb_read_cfg);
2262 enc_cfg.enc_blk.cfg.amrwb.mode = band_mode;
2263 enc_cfg.enc_blk.cfg.amrwb.dtx_mode = dtx_enable;
2264
2265 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2266 if (rc < 0) {
2267 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2268 goto fail_cmd;
2269 }
2270 rc = wait_event_timeout(ac->cmd_wait,
2271 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2272 if (!rc) {
2273 pr_err("timeout. waited for FORMAT_UPDATE\n");
2274 goto fail_cmd;
2275 }
2276 return 0;
2277fail_cmd:
2278 return -EINVAL;
2279}
2280
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002281int q6asm_media_format_block_pcm(struct audio_client *ac,
2282 uint32_t rate, uint32_t channels)
2283{
2284 struct asm_stream_media_format_update fmt;
2285 int rc = 0;
2286
2287 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
2288 channels);
2289
2290 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2291
2292 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2293
2294 fmt.format = LINEAR_PCM;
2295 fmt.cfg_size = sizeof(struct asm_pcm_cfg);
2296 fmt.write_cfg.pcm_cfg.ch_cfg = channels;
2297 fmt.write_cfg.pcm_cfg.bits_per_sample = 16;
2298 fmt.write_cfg.pcm_cfg.sample_rate = rate;
2299 fmt.write_cfg.pcm_cfg.is_signed = 1;
2300 fmt.write_cfg.pcm_cfg.interleaved = 1;
2301
2302 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2303 if (rc < 0) {
2304 pr_err("%s:Comamnd open failed\n", __func__);
2305 goto fail_cmd;
2306 }
2307 rc = wait_event_timeout(ac->cmd_wait,
2308 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2309 if (!rc) {
2310 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2311 goto fail_cmd;
2312 }
2313 return 0;
2314fail_cmd:
2315 return -EINVAL;
2316}
2317
Kiran Kandi5e809b02012-01-31 00:24:33 -08002318int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
2319 uint32_t rate, uint32_t channels)
2320{
2321 struct asm_stream_media_format_update fmt;
2322 u8 *channel_mapping;
2323 int rc = 0;
2324
2325 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
2326 channels);
2327
2328 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2329
2330 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2331
2332 fmt.format = MULTI_CHANNEL_PCM;
2333 fmt.cfg_size = sizeof(struct asm_multi_channel_pcm_fmt_blk);
2334 fmt.write_cfg.multi_ch_pcm_cfg.num_channels = channels;
2335 fmt.write_cfg.multi_ch_pcm_cfg.bits_per_sample = 16;
2336 fmt.write_cfg.multi_ch_pcm_cfg.sample_rate = rate;
2337 fmt.write_cfg.multi_ch_pcm_cfg.is_signed = 1;
2338 fmt.write_cfg.multi_ch_pcm_cfg.is_interleaved = 1;
2339 channel_mapping =
2340 fmt.write_cfg.multi_ch_pcm_cfg.channel_mapping;
2341
2342 memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
2343
2344 if (channels == 1) {
2345 channel_mapping[0] = PCM_CHANNEL_FL;
2346 } else if (channels == 2) {
2347 channel_mapping[0] = PCM_CHANNEL_FL;
2348 channel_mapping[1] = PCM_CHANNEL_FR;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002349 } else if (channels == 4) {
2350 channel_mapping[0] = PCM_CHANNEL_FL;
2351 channel_mapping[1] = PCM_CHANNEL_FR;
2352 channel_mapping[1] = PCM_CHANNEL_LB;
2353 channel_mapping[1] = PCM_CHANNEL_RB;
Kiran Kandi5e809b02012-01-31 00:24:33 -08002354 } else if (channels == 6) {
SathishKumar Mani6074b772012-09-26 13:49:49 -07002355 channel_mapping[0] = PCM_CHANNEL_FL;
2356 channel_mapping[1] = PCM_CHANNEL_FR;
2357 channel_mapping[2] = PCM_CHANNEL_FC;
2358 channel_mapping[3] = PCM_CHANNEL_LFE;
2359 channel_mapping[4] = PCM_CHANNEL_LB;
2360 channel_mapping[5] = PCM_CHANNEL_RB;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002361 } else if (channels == 8) {
2362 channel_mapping[0] = PCM_CHANNEL_FC;
2363 channel_mapping[1] = PCM_CHANNEL_FL;
2364 channel_mapping[2] = PCM_CHANNEL_FR;
2365 channel_mapping[3] = PCM_CHANNEL_LB;
2366 channel_mapping[4] = PCM_CHANNEL_RB;
2367 channel_mapping[5] = PCM_CHANNEL_LFE;
2368 channel_mapping[6] = PCM_CHANNEL_FLC;
2369 channel_mapping[7] = PCM_CHANNEL_FRC;
Kiran Kandi5e809b02012-01-31 00:24:33 -08002370 } else {
2371 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
2372 channels);
2373 return -EINVAL;
2374 }
2375
2376 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2377 if (rc < 0) {
2378 pr_err("%s:Comamnd open failed\n", __func__);
2379 goto fail_cmd;
2380 }
2381 rc = wait_event_timeout(ac->cmd_wait,
2382 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2383 if (!rc) {
2384 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2385 goto fail_cmd;
2386 }
2387 return 0;
2388fail_cmd:
2389 return -EINVAL;
2390}
2391
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002392int q6asm_media_format_block_aac(struct audio_client *ac,
2393 struct asm_aac_cfg *cfg)
2394{
2395 struct asm_stream_media_format_update fmt;
2396 int rc = 0;
2397
2398 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2399 cfg->sample_rate, cfg->ch_cfg);
2400
2401 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2402
2403 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2404
2405 fmt.format = MPEG4_AAC;
2406 fmt.cfg_size = sizeof(struct asm_aac_cfg);
2407 fmt.write_cfg.aac_cfg.format = cfg->format;
2408 fmt.write_cfg.aac_cfg.aot = cfg->aot;
2409 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
2410 fmt.write_cfg.aac_cfg.section_data_resilience =
2411 cfg->section_data_resilience;
2412 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2413 cfg->scalefactor_data_resilience;
2414 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2415 cfg->spectral_data_resilience;
2416 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2417 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2418 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2419 __func__, fmt.format, fmt.cfg_size,
2420 fmt.write_cfg.aac_cfg.format,
2421 fmt.write_cfg.aac_cfg.aot,
2422 fmt.write_cfg.aac_cfg.ch_cfg,
2423 fmt.write_cfg.aac_cfg.sample_rate);
2424 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2425 if (rc < 0) {
2426 pr_err("%s:Comamnd open failed\n", __func__);
2427 goto fail_cmd;
2428 }
2429 rc = wait_event_timeout(ac->cmd_wait,
2430 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2431 if (!rc) {
2432 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2433 goto fail_cmd;
2434 }
2435 return 0;
2436fail_cmd:
2437 return -EINVAL;
2438}
2439
Ajit Khare43fd8832012-08-07 13:19:44 -07002440int q6asm_media_format_block_amrwbplus(struct audio_client *ac,
2441 struct asm_amrwbplus_cfg *cfg)
2442{
2443 struct asm_stream_media_format_update fmt;
2444 int rc = 0;
2445 pr_debug("q6asm_media_format_block_amrwbplus");
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07002446
Ajit Khare43fd8832012-08-07 13:19:44 -07002447 pr_debug("%s:session[%d]band-mode[%d]frame-fmt[%d]ch[%d]\n",
2448 __func__,
2449 ac->session,
2450 cfg->amr_band_mode,
2451 cfg->amr_frame_fmt,
2452 cfg->num_channels);
2453
2454 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2455
2456 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2457
2458 fmt.format = AMR_WB_PLUS;
2459 fmt.cfg_size = cfg->size_bytes;
2460
2461 fmt.write_cfg.amrwbplus_cfg.size_bytes = cfg->size_bytes;
2462 fmt.write_cfg.amrwbplus_cfg.version = cfg->version;
2463 fmt.write_cfg.amrwbplus_cfg.num_channels = cfg->num_channels;
2464 fmt.write_cfg.amrwbplus_cfg.amr_band_mode = cfg->amr_band_mode;
2465 fmt.write_cfg.amrwbplus_cfg.amr_dtx_mode = cfg->amr_dtx_mode;
2466 fmt.write_cfg.amrwbplus_cfg.amr_frame_fmt = cfg->amr_frame_fmt;
2467 fmt.write_cfg.amrwbplus_cfg.amr_lsf_idx = cfg->amr_lsf_idx;
2468
2469 pr_debug("%s: num_channels=%x amr_band_mode=%d amr_frame_fmt=%d\n",
2470 __func__,
2471 cfg->num_channels,
2472 cfg->amr_band_mode,
2473 cfg->amr_frame_fmt);
2474
2475 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2476 if (rc < 0) {
2477 pr_err("%s:Comamnd media format update failed..\n", __func__);
2478 goto fail_cmd;
2479 }
2480 rc = wait_event_timeout(ac->cmd_wait,
2481 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2482 if (!rc) {
2483 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2484 goto fail_cmd;
2485 }
2486 return 0;
2487fail_cmd:
2488 return -EINVAL;
2489}
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07002490int q6asm_media_format_block_multi_aac(struct audio_client *ac,
2491 struct asm_aac_cfg *cfg)
2492{
2493 struct asm_stream_media_format_update fmt;
2494 int rc = 0;
2495
2496 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2497 cfg->sample_rate, cfg->ch_cfg);
2498
2499 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2500
2501 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2502
2503 fmt.format = MPEG4_MULTI_AAC;
2504 fmt.cfg_size = sizeof(struct asm_aac_cfg);
2505 fmt.write_cfg.aac_cfg.format = cfg->format;
2506 fmt.write_cfg.aac_cfg.aot = cfg->aot;
2507 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
2508 fmt.write_cfg.aac_cfg.section_data_resilience =
2509 cfg->section_data_resilience;
2510 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2511 cfg->scalefactor_data_resilience;
2512 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2513 cfg->spectral_data_resilience;
2514 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2515 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2516 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2517 __func__, fmt.format, fmt.cfg_size,
2518 fmt.write_cfg.aac_cfg.format,
2519 fmt.write_cfg.aac_cfg.aot,
2520 fmt.write_cfg.aac_cfg.ch_cfg,
2521 fmt.write_cfg.aac_cfg.sample_rate);
2522 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2523 if (rc < 0) {
2524 pr_err("%s:Comamnd open failed\n", __func__);
2525 goto fail_cmd;
2526 }
2527 rc = wait_event_timeout(ac->cmd_wait,
2528 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2529 if (!rc) {
2530 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2531 goto fail_cmd;
2532 }
2533 return 0;
2534fail_cmd:
2535 return -EINVAL;
2536}
2537
2538
Alex Wong2caeecc2011-10-28 10:52:15 +05302539
2540int q6asm_media_format_block(struct audio_client *ac, uint32_t format)
2541{
2542
2543 struct asm_stream_media_format_update fmt;
2544 int rc = 0;
2545
2546 pr_debug("%s:session[%d] format[0x%x]\n", __func__,
2547 ac->session, format);
2548
2549 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2550 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302551 switch (format) {
2552 case FORMAT_V13K:
2553 fmt.format = V13K_FS;
2554 break;
2555 case FORMAT_EVRC:
2556 fmt.format = EVRC_FS;
2557 break;
2558 case FORMAT_AMRWB:
2559 fmt.format = AMRWB_FS;
2560 break;
Ajit Khare43fd8832012-08-07 13:19:44 -07002561 case FORMAT_AMR_WB_PLUS:
2562 fmt.format = AMR_WB_PLUS;
2563 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302564 case FORMAT_AMRNB:
2565 fmt.format = AMRNB_FS;
2566 break;
2567 case FORMAT_MP3:
2568 fmt.format = MP3;
2569 break;
Srikanth Uyyala66f781a2012-06-13 23:23:25 +05302570 case FORMAT_DTS:
2571 fmt.format = DTS;
2572 break;
2573 case FORMAT_DTS_LBR:
2574 fmt.format = DTS_LBR;
2575 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302576 default:
2577 pr_err("Invalid format[%d]\n", format);
2578 goto fail_cmd;
2579 }
Alex Wong2caeecc2011-10-28 10:52:15 +05302580 fmt.cfg_size = 0;
2581
2582 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2583 if (rc < 0) {
2584 pr_err("%s:Comamnd open failed\n", __func__);
2585 goto fail_cmd;
2586 }
2587 rc = wait_event_timeout(ac->cmd_wait,
2588 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2589 if (!rc) {
2590 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2591 goto fail_cmd;
2592 }
2593 return 0;
2594fail_cmd:
2595 return -EINVAL;
2596}
2597
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002598int q6asm_media_format_block_wma(struct audio_client *ac,
2599 void *cfg)
2600{
2601 struct asm_stream_media_format_update fmt;
2602 struct asm_wma_cfg *wma_cfg = (struct asm_wma_cfg *)cfg;
2603 int rc = 0;
2604
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002605 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 -07002606 ac->session, wma_cfg->format_tag, wma_cfg->sample_rate,
2607 wma_cfg->ch_cfg, wma_cfg->avg_bytes_per_sec,
2608 wma_cfg->block_align, wma_cfg->valid_bits_per_sample,
2609 wma_cfg->ch_mask, wma_cfg->encode_opt);
2610
2611 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2612
2613 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2614
2615 fmt.format = WMA_V9;
2616 fmt.cfg_size = sizeof(struct asm_wma_cfg);
2617 fmt.write_cfg.wma_cfg.format_tag = wma_cfg->format_tag;
2618 fmt.write_cfg.wma_cfg.ch_cfg = wma_cfg->ch_cfg;
2619 fmt.write_cfg.wma_cfg.sample_rate = wma_cfg->sample_rate;
2620 fmt.write_cfg.wma_cfg.avg_bytes_per_sec = wma_cfg->avg_bytes_per_sec;
2621 fmt.write_cfg.wma_cfg.block_align = wma_cfg->block_align;
2622 fmt.write_cfg.wma_cfg.valid_bits_per_sample =
2623 wma_cfg->valid_bits_per_sample;
2624 fmt.write_cfg.wma_cfg.ch_mask = wma_cfg->ch_mask;
2625 fmt.write_cfg.wma_cfg.encode_opt = wma_cfg->encode_opt;
2626 fmt.write_cfg.wma_cfg.adv_encode_opt = 0;
2627 fmt.write_cfg.wma_cfg.adv_encode_opt2 = 0;
2628 fmt.write_cfg.wma_cfg.drc_peak_ref = 0;
2629 fmt.write_cfg.wma_cfg.drc_peak_target = 0;
2630 fmt.write_cfg.wma_cfg.drc_ave_ref = 0;
2631 fmt.write_cfg.wma_cfg.drc_ave_target = 0;
2632
2633 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2634 if (rc < 0) {
2635 pr_err("%s:Comamnd open failed\n", __func__);
2636 goto fail_cmd;
2637 }
2638 rc = wait_event_timeout(ac->cmd_wait,
2639 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2640 if (!rc) {
2641 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2642 goto fail_cmd;
2643 }
2644 return 0;
2645fail_cmd:
2646 return -EINVAL;
2647}
2648
2649int q6asm_media_format_block_wmapro(struct audio_client *ac,
2650 void *cfg)
2651{
2652 struct asm_stream_media_format_update fmt;
2653 struct asm_wmapro_cfg *wmapro_cfg = (struct asm_wmapro_cfg *)cfg;
2654 int rc = 0;
2655
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002656 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 -07002657 ac->session, wmapro_cfg->format_tag, wmapro_cfg->sample_rate,
2658 wmapro_cfg->ch_cfg, wmapro_cfg->avg_bytes_per_sec,
2659 wmapro_cfg->block_align, wmapro_cfg->valid_bits_per_sample,
2660 wmapro_cfg->ch_mask, wmapro_cfg->encode_opt,
2661 wmapro_cfg->adv_encode_opt, wmapro_cfg->adv_encode_opt2);
2662
2663 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2664
2665 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2666
2667 fmt.format = WMA_V10PRO;
2668 fmt.cfg_size = sizeof(struct asm_wmapro_cfg);
2669 fmt.write_cfg.wmapro_cfg.format_tag = wmapro_cfg->format_tag;
2670 fmt.write_cfg.wmapro_cfg.ch_cfg = wmapro_cfg->ch_cfg;
2671 fmt.write_cfg.wmapro_cfg.sample_rate = wmapro_cfg->sample_rate;
2672 fmt.write_cfg.wmapro_cfg.avg_bytes_per_sec =
2673 wmapro_cfg->avg_bytes_per_sec;
2674 fmt.write_cfg.wmapro_cfg.block_align = wmapro_cfg->block_align;
2675 fmt.write_cfg.wmapro_cfg.valid_bits_per_sample =
2676 wmapro_cfg->valid_bits_per_sample;
2677 fmt.write_cfg.wmapro_cfg.ch_mask = wmapro_cfg->ch_mask;
2678 fmt.write_cfg.wmapro_cfg.encode_opt = wmapro_cfg->encode_opt;
2679 fmt.write_cfg.wmapro_cfg.adv_encode_opt = wmapro_cfg->adv_encode_opt;
2680 fmt.write_cfg.wmapro_cfg.adv_encode_opt2 = wmapro_cfg->adv_encode_opt2;
2681 fmt.write_cfg.wmapro_cfg.drc_peak_ref = 0;
2682 fmt.write_cfg.wmapro_cfg.drc_peak_target = 0;
2683 fmt.write_cfg.wmapro_cfg.drc_ave_ref = 0;
2684 fmt.write_cfg.wmapro_cfg.drc_ave_target = 0;
2685
2686 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2687 if (rc < 0) {
2688 pr_err("%s:Comamnd open failed\n", __func__);
2689 goto fail_cmd;
2690 }
2691 rc = wait_event_timeout(ac->cmd_wait,
2692 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2693 if (!rc) {
2694 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2695 goto fail_cmd;
2696 }
2697 return 0;
2698fail_cmd:
2699 return -EINVAL;
2700}
2701
2702int q6asm_memory_map(struct audio_client *ac, uint32_t buf_add, int dir,
2703 uint32_t bufsz, uint32_t bufcnt)
2704{
2705 struct asm_stream_cmd_memory_map mem_map;
2706 int rc = 0;
2707
2708 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2709 pr_err("APR handle NULL\n");
2710 return -EINVAL;
2711 }
2712
2713 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2714
2715 mem_map.hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP;
2716
2717 mem_map.buf_add = buf_add;
2718 mem_map.buf_size = bufsz * bufcnt;
2719 mem_map.mempool_id = 0; /* EBI */
2720 mem_map.reserved = 0;
2721
2722 q6asm_add_mmaphdr(&mem_map.hdr,
2723 sizeof(struct asm_stream_cmd_memory_map), TRUE);
2724
2725 pr_debug("buf add[%x] buf_add_parameter[%x]\n",
2726 mem_map.buf_add, buf_add);
2727
2728 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_map);
2729 if (rc < 0) {
2730 pr_err("mem_map op[0x%x]rc[%d]\n",
2731 mem_map.hdr.opcode, rc);
2732 rc = -EINVAL;
2733 goto fail_cmd;
2734 }
2735
2736 rc = wait_event_timeout(this_mmap.cmd_wait,
2737 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2738 if (!rc) {
2739 pr_err("timeout. waited for memory_map\n");
2740 rc = -EINVAL;
2741 goto fail_cmd;
2742 }
2743 rc = 0;
2744fail_cmd:
2745 return rc;
2746}
2747
2748int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add, int dir)
2749{
2750 struct asm_stream_cmd_memory_unmap mem_unmap;
2751 int rc = 0;
2752
2753 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2754 pr_err("APR handle NULL\n");
2755 return -EINVAL;
2756 }
2757 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2758
2759 q6asm_add_mmaphdr(&mem_unmap.hdr,
2760 sizeof(struct asm_stream_cmd_memory_unmap), TRUE);
2761 mem_unmap.hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP;
2762 mem_unmap.buf_add = buf_add;
2763
2764 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_unmap);
2765 if (rc < 0) {
2766 pr_err("mem_unmap op[0x%x]rc[%d]\n",
2767 mem_unmap.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_set_lrgain(struct audio_client *ac, int left_gain, int right_gain)
2785{
2786 void *vol_cmd = NULL;
2787 void *payload = NULL;
2788 struct asm_pp_params_command *cmd = NULL;
2789 struct asm_lrchannel_gain_params *lrgain = NULL;
2790 int sz = 0;
2791 int rc = 0;
2792
2793 sz = sizeof(struct asm_pp_params_command) +
2794 + sizeof(struct asm_lrchannel_gain_params);
2795 vol_cmd = kzalloc(sz, GFP_KERNEL);
2796 if (vol_cmd == NULL) {
2797 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2798 rc = -EINVAL;
2799 return rc;
2800 }
2801 cmd = (struct asm_pp_params_command *)vol_cmd;
2802 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2803 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2804 cmd->payload = NULL;
2805 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2806 sizeof(struct asm_lrchannel_gain_params);
2807 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2808 cmd->params.param_id = L_R_CHANNEL_GAIN_PARAM_ID;
2809 cmd->params.param_size = sizeof(struct asm_lrchannel_gain_params);
2810 cmd->params.reserved = 0;
2811
2812 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2813 lrgain = (struct asm_lrchannel_gain_params *)payload;
2814
2815 lrgain->left_gain = left_gain;
2816 lrgain->right_gain = right_gain;
2817 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2818 if (rc < 0) {
2819 pr_err("%s: Volume Command failed\n", __func__);
2820 rc = -EINVAL;
2821 goto fail_cmd;
2822 }
2823
2824 rc = wait_event_timeout(ac->cmd_wait,
2825 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2826 if (!rc) {
2827 pr_err("%s: timeout in sending volume command to apr\n",
2828 __func__);
2829 rc = -EINVAL;
2830 goto fail_cmd;
2831 }
2832 rc = 0;
2833fail_cmd:
2834 kfree(vol_cmd);
2835 return rc;
2836}
2837
2838static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
2839 uint32_t bufsz, uint32_t bufcnt)
2840{
2841 struct asm_stream_cmd_memory_map_regions *mmap_regions = NULL;
2842 struct asm_memory_map_regions *mregions = NULL;
2843 struct audio_port_data *port = NULL;
2844 struct audio_buffer *ab = NULL;
2845 void *mmap_region_cmd = NULL;
2846 void *payload = NULL;
2847 int rc = 0;
2848 int i = 0;
2849 int cmd_size = 0;
2850
2851 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2852 pr_err("APR handle NULL\n");
2853 return -EINVAL;
2854 }
2855 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2856
2857 cmd_size = sizeof(struct asm_stream_cmd_memory_map_regions)
2858 + sizeof(struct asm_memory_map_regions) * bufcnt;
2859
2860 mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302861 if (mmap_region_cmd == NULL) {
2862 pr_err("%s: Mem alloc failed\n", __func__);
2863 rc = -EINVAL;
2864 return rc;
2865 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002866 mmap_regions = (struct asm_stream_cmd_memory_map_regions *)
2867 mmap_region_cmd;
2868 q6asm_add_mmaphdr(&mmap_regions->hdr, cmd_size, TRUE);
2869 mmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP_REGIONS;
2870 mmap_regions->mempool_id = 0;
2871 mmap_regions->nregions = bufcnt & 0x00ff;
2872 pr_debug("map_regions->nregions = %d\n", mmap_regions->nregions);
2873 payload = ((u8 *) mmap_region_cmd +
2874 sizeof(struct asm_stream_cmd_memory_map_regions));
2875 mregions = (struct asm_memory_map_regions *)payload;
2876
2877 port = &ac->port[dir];
2878 for (i = 0; i < bufcnt; i++) {
2879 ab = &port->buf[i];
2880 mregions->phys = ab->phys;
2881 mregions->buf_size = ab->size;
2882 ++mregions;
2883 }
2884
2885 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) mmap_region_cmd);
2886 if (rc < 0) {
2887 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2888 mmap_regions->hdr.opcode, rc);
2889 rc = -EINVAL;
2890 goto fail_cmd;
2891 }
2892
2893 rc = wait_event_timeout(this_mmap.cmd_wait,
2894 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2895 if (!rc) {
2896 pr_err("timeout. waited for memory_map\n");
2897 rc = -EINVAL;
2898 goto fail_cmd;
2899 }
2900 rc = 0;
2901fail_cmd:
2902 kfree(mmap_region_cmd);
2903 return rc;
2904}
2905
2906static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir,
2907 uint32_t bufsz, uint32_t bufcnt)
2908{
2909 struct asm_stream_cmd_memory_unmap_regions *unmap_regions = NULL;
2910 struct asm_memory_unmap_regions *mregions = NULL;
2911 struct audio_port_data *port = NULL;
2912 struct audio_buffer *ab = NULL;
2913 void *unmap_region_cmd = NULL;
2914 void *payload = NULL;
2915 int rc = 0;
2916 int i = 0;
2917 int cmd_size = 0;
2918
2919 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2920 pr_err("APR handle NULL\n");
2921 return -EINVAL;
2922 }
2923 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2924
2925 cmd_size = sizeof(struct asm_stream_cmd_memory_unmap_regions) +
2926 sizeof(struct asm_memory_unmap_regions) * bufcnt;
2927
2928 unmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302929 if (unmap_region_cmd == NULL) {
2930 pr_err("%s: Mem alloc failed\n", __func__);
2931 rc = -EINVAL;
2932 return rc;
2933 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002934 unmap_regions = (struct asm_stream_cmd_memory_unmap_regions *)
2935 unmap_region_cmd;
2936 q6asm_add_mmaphdr(&unmap_regions->hdr, cmd_size, TRUE);
2937 unmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS;
2938 unmap_regions->nregions = bufcnt & 0x00ff;
2939 pr_debug("unmap_regions->nregions = %d\n", unmap_regions->nregions);
2940 payload = ((u8 *) unmap_region_cmd +
2941 sizeof(struct asm_stream_cmd_memory_unmap_regions));
2942 mregions = (struct asm_memory_unmap_regions *)payload;
2943 port = &ac->port[dir];
2944 for (i = 0; i < bufcnt; i++) {
2945 ab = &port->buf[i];
2946 mregions->phys = ab->phys;
2947 ++mregions;
2948 }
2949
2950 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) unmap_region_cmd);
2951 if (rc < 0) {
2952 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2953 unmap_regions->hdr.opcode, rc);
2954 goto fail_cmd;
2955 }
2956
2957 rc = wait_event_timeout(this_mmap.cmd_wait,
2958 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2959 if (!rc) {
2960 pr_err("timeout. waited for memory_unmap\n");
2961 goto fail_cmd;
2962 }
2963 rc = 0;
2964
2965fail_cmd:
2966 kfree(unmap_region_cmd);
2967 return rc;
2968}
2969
2970int q6asm_set_mute(struct audio_client *ac, int muteflag)
2971{
2972 void *vol_cmd = NULL;
2973 void *payload = NULL;
2974 struct asm_pp_params_command *cmd = NULL;
2975 struct asm_mute_params *mute = NULL;
2976 int sz = 0;
2977 int rc = 0;
2978
2979 sz = sizeof(struct asm_pp_params_command) +
2980 + sizeof(struct asm_mute_params);
2981 vol_cmd = kzalloc(sz, GFP_KERNEL);
2982 if (vol_cmd == NULL) {
2983 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2984 rc = -EINVAL;
2985 return rc;
2986 }
2987 cmd = (struct asm_pp_params_command *)vol_cmd;
2988 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2989 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2990 cmd->payload = NULL;
2991 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2992 sizeof(struct asm_mute_params);
2993 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2994 cmd->params.param_id = MUTE_CONFIG_PARAM_ID;
2995 cmd->params.param_size = sizeof(struct asm_mute_params);
2996 cmd->params.reserved = 0;
2997
2998 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2999 mute = (struct asm_mute_params *)payload;
3000
3001 mute->muteflag = muteflag;
3002 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3003 if (rc < 0) {
3004 pr_err("%s: Mute Command failed\n", __func__);
3005 rc = -EINVAL;
3006 goto fail_cmd;
3007 }
3008
3009 rc = wait_event_timeout(ac->cmd_wait,
3010 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3011 if (!rc) {
3012 pr_err("%s: timeout in sending mute command to apr\n",
3013 __func__);
3014 rc = -EINVAL;
3015 goto fail_cmd;
3016 }
3017 rc = 0;
3018fail_cmd:
3019 kfree(vol_cmd);
3020 return rc;
3021}
3022
3023int q6asm_set_volume(struct audio_client *ac, int volume)
3024{
3025 void *vol_cmd = NULL;
3026 void *payload = NULL;
3027 struct asm_pp_params_command *cmd = NULL;
3028 struct asm_master_gain_params *mgain = NULL;
3029 int sz = 0;
3030 int rc = 0;
3031
3032 sz = sizeof(struct asm_pp_params_command) +
3033 + sizeof(struct asm_master_gain_params);
3034 vol_cmd = kzalloc(sz, GFP_KERNEL);
3035 if (vol_cmd == NULL) {
3036 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3037 rc = -EINVAL;
3038 return rc;
3039 }
3040 cmd = (struct asm_pp_params_command *)vol_cmd;
3041 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3042 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3043 cmd->payload = NULL;
3044 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3045 sizeof(struct asm_master_gain_params);
3046 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3047 cmd->params.param_id = MASTER_GAIN_PARAM_ID;
3048 cmd->params.param_size = sizeof(struct asm_master_gain_params);
3049 cmd->params.reserved = 0;
3050
3051 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3052 mgain = (struct asm_master_gain_params *)payload;
3053
3054 mgain->master_gain = volume;
3055 mgain->padding = 0x00;
3056 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3057 if (rc < 0) {
3058 pr_err("%s: Volume Command failed\n", __func__);
3059 rc = -EINVAL;
3060 goto fail_cmd;
3061 }
3062
3063 rc = wait_event_timeout(ac->cmd_wait,
3064 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3065 if (!rc) {
3066 pr_err("%s: timeout in sending volume command to apr\n",
3067 __func__);
3068 rc = -EINVAL;
3069 goto fail_cmd;
3070 }
3071 rc = 0;
3072fail_cmd:
3073 kfree(vol_cmd);
3074 return rc;
3075}
3076
3077int q6asm_set_softpause(struct audio_client *ac,
3078 struct asm_softpause_params *pause_param)
3079{
3080 void *vol_cmd = NULL;
3081 void *payload = NULL;
3082 struct asm_pp_params_command *cmd = NULL;
3083 struct asm_softpause_params *params = NULL;
3084 int sz = 0;
3085 int rc = 0;
3086
3087 sz = sizeof(struct asm_pp_params_command) +
3088 + sizeof(struct asm_softpause_params);
3089 vol_cmd = kzalloc(sz, GFP_KERNEL);
3090 if (vol_cmd == NULL) {
3091 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3092 rc = -EINVAL;
3093 return rc;
3094 }
3095 cmd = (struct asm_pp_params_command *)vol_cmd;
3096 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3097 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3098 cmd->payload = NULL;
3099 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3100 sizeof(struct asm_softpause_params);
3101 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3102 cmd->params.param_id = SOFT_PAUSE_PARAM_ID;
3103 cmd->params.param_size = sizeof(struct asm_softpause_params);
3104 cmd->params.reserved = 0;
3105
3106 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3107 params = (struct asm_softpause_params *)payload;
3108
3109 params->enable = pause_param->enable;
3110 params->period = pause_param->period;
3111 params->step = pause_param->step;
3112 params->rampingcurve = pause_param->rampingcurve;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003113 pr_debug("%s: soft Pause Command: enable = %d, period = %d, step = %d, curve = %d\n",
3114 __func__, params->enable,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003115 params->period, params->step, params->rampingcurve);
3116 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3117 if (rc < 0) {
3118 pr_err("%s: Volume Command(soft_pause) failed\n", __func__);
3119 rc = -EINVAL;
3120 goto fail_cmd;
3121 }
3122
3123 rc = wait_event_timeout(ac->cmd_wait,
3124 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3125 if (!rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003126 pr_err("%s: timeout in sending volume command(soft_pause) to apr\n",
3127 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003128 rc = -EINVAL;
3129 goto fail_cmd;
3130 }
3131 rc = 0;
3132fail_cmd:
3133 kfree(vol_cmd);
3134 return rc;
3135}
3136
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003137int q6asm_set_softvolume(struct audio_client *ac,
3138 struct asm_softvolume_params *softvol_param)
3139{
3140 void *vol_cmd = NULL;
3141 void *payload = NULL;
3142 struct asm_pp_params_command *cmd = NULL;
3143 struct asm_softvolume_params *params = NULL;
3144 int sz = 0;
3145 int rc = 0;
3146
3147 sz = sizeof(struct asm_pp_params_command) +
3148 + sizeof(struct asm_softvolume_params);
3149 vol_cmd = kzalloc(sz, GFP_KERNEL);
3150 if (vol_cmd == NULL) {
3151 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3152 rc = -EINVAL;
3153 return rc;
3154 }
3155 cmd = (struct asm_pp_params_command *)vol_cmd;
3156 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3157 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3158 cmd->payload = NULL;
3159 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3160 sizeof(struct asm_softvolume_params);
3161 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3162 cmd->params.param_id = SOFT_VOLUME_PARAM_ID;
3163 cmd->params.param_size = sizeof(struct asm_softvolume_params);
3164 cmd->params.reserved = 0;
3165
3166 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3167 params = (struct asm_softvolume_params *)payload;
3168
3169 params->period = softvol_param->period;
3170 params->step = softvol_param->step;
3171 params->rampingcurve = softvol_param->rampingcurve;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003172 pr_debug("%s: soft Volume:opcode = %d,payload_sz =%d,module_id =%d, param_id = %d, param_sz = %d\n",
3173 __func__,
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003174 cmd->hdr.opcode, cmd->payload_size,
3175 cmd->params.module_id, cmd->params.param_id,
3176 cmd->params.param_size);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003177 pr_debug("%s: soft Volume Command: period = %d, step = %d, curve = %d\n",
3178 __func__, params->period,
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003179 params->step, params->rampingcurve);
3180 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3181 if (rc < 0) {
3182 pr_err("%s: Volume Command(soft_volume) failed\n", __func__);
3183 rc = -EINVAL;
3184 goto fail_cmd;
3185 }
3186
3187 rc = wait_event_timeout(ac->cmd_wait,
3188 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3189 if (!rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003190 pr_err("%s: timeout in sending volume command(soft_volume) to apr\n",
3191 __func__);
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003192 rc = -EINVAL;
3193 goto fail_cmd;
3194 }
3195 rc = 0;
3196fail_cmd:
3197 kfree(vol_cmd);
3198 return rc;
3199}
3200
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003201int q6asm_equalizer(struct audio_client *ac, void *eq)
3202{
3203 void *eq_cmd = NULL;
3204 void *payload = NULL;
3205 struct asm_pp_params_command *cmd = NULL;
3206 struct asm_equalizer_params *equalizer = NULL;
3207 struct msm_audio_eq_stream_config *eq_params = NULL;
3208 int i = 0;
3209 int sz = 0;
3210 int rc = 0;
3211
3212 sz = sizeof(struct asm_pp_params_command) +
3213 + sizeof(struct asm_equalizer_params);
3214 eq_cmd = kzalloc(sz, GFP_KERNEL);
3215 if (eq_cmd == NULL) {
3216 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3217 rc = -EINVAL;
3218 goto fail_cmd;
3219 }
3220 eq_params = (struct msm_audio_eq_stream_config *) eq;
3221 cmd = (struct asm_pp_params_command *)eq_cmd;
3222 q6asm_add_hdr(ac, &cmd->hdr, sz, TRUE);
3223 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3224 cmd->payload = NULL;
3225 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3226 sizeof(struct asm_equalizer_params);
3227 cmd->params.module_id = EQUALIZER_MODULE_ID;
3228 cmd->params.param_id = EQUALIZER_PARAM_ID;
3229 cmd->params.param_size = sizeof(struct asm_equalizer_params);
3230 cmd->params.reserved = 0;
3231 payload = (u8 *)(eq_cmd + sizeof(struct asm_pp_params_command));
3232 equalizer = (struct asm_equalizer_params *)payload;
3233
3234 equalizer->enable = eq_params->enable;
3235 equalizer->num_bands = eq_params->num_bands;
3236 pr_debug("%s: enable:%d numbands:%d\n", __func__, eq_params->enable,
3237 eq_params->num_bands);
3238 for (i = 0; i < eq_params->num_bands; i++) {
3239 equalizer->eq_bands[i].band_idx =
3240 eq_params->eq_bands[i].band_idx;
3241 equalizer->eq_bands[i].filter_type =
3242 eq_params->eq_bands[i].filter_type;
3243 equalizer->eq_bands[i].center_freq_hz =
3244 eq_params->eq_bands[i].center_freq_hz;
3245 equalizer->eq_bands[i].filter_gain =
3246 eq_params->eq_bands[i].filter_gain;
3247 equalizer->eq_bands[i].q_factor =
3248 eq_params->eq_bands[i].q_factor;
3249 pr_debug("%s: filter_type:%u bandnum:%d\n", __func__,
3250 eq_params->eq_bands[i].filter_type, i);
3251 pr_debug("%s: center_freq_hz:%u bandnum:%d\n", __func__,
3252 eq_params->eq_bands[i].center_freq_hz, i);
3253 pr_debug("%s: filter_gain:%d bandnum:%d\n", __func__,
3254 eq_params->eq_bands[i].filter_gain, i);
3255 pr_debug("%s: q_factor:%d bandnum:%d\n", __func__,
3256 eq_params->eq_bands[i].q_factor, i);
3257 }
3258 rc = apr_send_pkt(ac->apr, (uint32_t *) eq_cmd);
3259 if (rc < 0) {
3260 pr_err("%s: Equalizer Command failed\n", __func__);
3261 rc = -EINVAL;
3262 goto fail_cmd;
3263 }
3264
3265 rc = wait_event_timeout(ac->cmd_wait,
3266 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3267 if (!rc) {
3268 pr_err("%s: timeout in sending equalizer command to apr\n",
3269 __func__);
3270 rc = -EINVAL;
3271 goto fail_cmd;
3272 }
3273 rc = 0;
3274fail_cmd:
3275 kfree(eq_cmd);
3276 return rc;
3277}
3278
3279int q6asm_read(struct audio_client *ac)
3280{
3281 struct asm_stream_cmd_read read;
3282 struct audio_buffer *ab;
3283 int dsp_buf;
3284 struct audio_port_data *port;
3285 int rc;
3286 if (!ac || ac->apr == NULL) {
3287 pr_err("APR handle NULL\n");
3288 return -EINVAL;
3289 }
3290 if (ac->io_mode == SYNC_IO_MODE) {
3291 port = &ac->port[OUT];
3292
3293 q6asm_add_hdr(ac, &read.hdr, sizeof(read), FALSE);
3294
3295 mutex_lock(&port->lock);
3296
3297 dsp_buf = port->dsp_buf;
3298 ab = &port->buf[dsp_buf];
3299
3300 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
3301 __func__,
3302 ac->session,
3303 dsp_buf,
3304 (void *)port->buf[dsp_buf].data,
3305 port->cpu_buf,
3306 (void *)port->buf[port->cpu_buf].phys);
3307
3308 read.hdr.opcode = ASM_DATA_CMD_READ;
3309 read.buf_add = ab->phys;
3310 read.buf_size = ab->size;
3311 read.uid = port->dsp_buf;
3312 read.hdr.token = port->dsp_buf;
3313
3314 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3315 mutex_unlock(&port->lock);
3316 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
3317 read.buf_add,
3318 read.hdr.token,
3319 read.uid);
3320 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3321 if (rc < 0) {
3322 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
3323 goto fail_cmd;
3324 }
3325 return 0;
3326 }
3327fail_cmd:
3328 return -EINVAL;
3329}
3330
3331int q6asm_read_nolock(struct audio_client *ac)
3332{
3333 struct asm_stream_cmd_read read;
3334 struct audio_buffer *ab;
3335 int dsp_buf;
3336 struct audio_port_data *port;
3337 int rc;
3338 if (!ac || ac->apr == NULL) {
3339 pr_err("APR handle NULL\n");
3340 return -EINVAL;
3341 }
3342 if (ac->io_mode == SYNC_IO_MODE) {
3343 port = &ac->port[OUT];
3344
3345 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3346
3347
3348 dsp_buf = port->dsp_buf;
3349 ab = &port->buf[dsp_buf];
3350
3351 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
3352 __func__,
3353 ac->session,
3354 dsp_buf,
3355 (void *)port->buf[dsp_buf].data,
3356 port->cpu_buf,
3357 (void *)port->buf[port->cpu_buf].phys);
3358
3359 read.hdr.opcode = ASM_DATA_CMD_READ;
3360 read.buf_add = ab->phys;
3361 read.buf_size = ab->size;
3362 read.uid = port->dsp_buf;
3363 read.hdr.token = port->dsp_buf;
3364
3365 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3366 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
3367 read.buf_add,
3368 read.hdr.token,
3369 read.uid);
3370 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3371 if (rc < 0) {
3372 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
3373 goto fail_cmd;
3374 }
3375 return 0;
3376 }
3377fail_cmd:
3378 return -EINVAL;
3379}
3380
3381
3382static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
3383 uint32_t pkt_size, uint32_t cmd_flg)
3384{
3385 pr_debug("session=%d pkt size=%d cmd_flg=%d\n", pkt_size, cmd_flg,
3386 ac->session);
3387 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
3388 APR_HDR_LEN(sizeof(struct apr_hdr)),\
3389 APR_PKT_VER);
3390 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
3391 hdr->src_domain = APR_DOMAIN_APPS;
3392 hdr->dest_svc = APR_SVC_ASM;
3393 hdr->dest_domain = APR_DOMAIN_ADSP;
3394 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
3395 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
3396 if (cmd_flg) {
3397 hdr->token = ac->session;
3398 atomic_set(&ac->cmd_state, 1);
3399 }
3400 hdr->pkt_size = pkt_size;
3401 return;
3402}
3403
3404int q6asm_async_write(struct audio_client *ac,
3405 struct audio_aio_write_param *param)
3406{
3407 int rc = 0;
3408 struct asm_stream_cmd_write write;
3409
3410 if (!ac || ac->apr == NULL) {
3411 pr_err("%s: APR handle NULL\n", __func__);
3412 return -EINVAL;
3413 }
3414
3415 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write), FALSE);
3416
3417 /* Pass physical address as token for AIO scheme */
3418 write.hdr.token = param->uid;
3419 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3420 write.buf_add = param->paddr;
3421 write.avail_bytes = param->len;
3422 write.uid = param->uid;
3423 write.msw_ts = param->msw_ts;
3424 write.lsw_ts = param->lsw_ts;
3425 /* Use 0xFF00 for disabling timestamps */
3426 if (param->flags == 0xFF00)
3427 write.uflags = (0x00000000 | (param->flags & 0x800000FF));
3428 else
3429 write.uflags = (0x80000000 | param->flags);
3430
3431 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3432 write.buf_add, write.avail_bytes);
3433
3434 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3435 if (rc < 0) {
3436 pr_debug("[%s] write op[0x%x]rc[%d]\n", __func__,
3437 write.hdr.opcode, rc);
3438 goto fail_cmd;
3439 }
3440 return 0;
3441fail_cmd:
3442 return -EINVAL;
3443}
3444
3445int q6asm_async_read(struct audio_client *ac,
3446 struct audio_aio_read_param *param)
3447{
3448 int rc = 0;
3449 struct asm_stream_cmd_read read;
3450
3451 if (!ac || ac->apr == NULL) {
3452 pr_err("%s: APR handle NULL\n", __func__);
3453 return -EINVAL;
3454 }
3455
3456 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3457
3458 /* Pass physical address as token for AIO scheme */
3459 read.hdr.token = param->paddr;
3460 read.hdr.opcode = ASM_DATA_CMD_READ;
3461 read.buf_add = param->paddr;
3462 read.buf_size = param->len;
3463 read.uid = param->uid;
3464
3465 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3466 read.buf_add, read.buf_size);
3467
3468 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3469 if (rc < 0) {
3470 pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
3471 read.hdr.opcode, rc);
3472 goto fail_cmd;
3473 }
3474 return 0;
3475fail_cmd:
3476 return -EINVAL;
3477}
3478
Subhash Chandra Bose Naripeddy694b7d92012-06-20 20:46:13 -07003479int q6asm_async_read_compressed(struct audio_client *ac,
3480 struct audio_aio_read_param *param)
3481{
3482 int rc = 0;
3483 struct asm_stream_cmd_read read;
3484
3485 if (!ac || ac->apr == NULL) {
3486 pr_err("%s: APR handle NULL\n", __func__);
3487 return -EINVAL;
3488 }
3489
3490 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3491
3492 /* Pass physical address as token for AIO scheme */
3493 read.hdr.token = param->paddr;
3494 read.hdr.opcode = ASM_DATA_CMD_READ_COMPRESSED;
3495 read.buf_add = param->paddr;
3496 read.buf_size = param->len;
3497 read.uid = param->uid;
3498
3499 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3500 read.buf_add, read.buf_size);
3501
3502 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3503 if (rc < 0) {
3504 pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
3505 read.hdr.opcode, rc);
3506 goto fail_cmd;
3507 }
3508 return 0;
3509fail_cmd:
3510 return -EINVAL;
3511}
3512
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003513int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3514 uint32_t lsw_ts, uint32_t flags)
3515{
3516 int rc = 0;
3517 struct asm_stream_cmd_write write;
3518 struct audio_port_data *port;
3519 struct audio_buffer *ab;
3520 int dsp_buf = 0;
3521
3522 if (!ac || ac->apr == NULL) {
3523 pr_err("APR handle NULL\n");
3524 return -EINVAL;
3525 }
3526 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3527 if (ac->io_mode == SYNC_IO_MODE) {
3528 port = &ac->port[IN];
3529
3530 q6asm_add_hdr(ac, &write.hdr, sizeof(write),
3531 FALSE);
3532 mutex_lock(&port->lock);
3533
3534 dsp_buf = port->dsp_buf;
3535 ab = &port->buf[dsp_buf];
3536
3537 write.hdr.token = port->dsp_buf;
3538 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3539 write.buf_add = ab->phys;
3540 write.avail_bytes = len;
3541 write.uid = port->dsp_buf;
3542 write.msw_ts = msw_ts;
3543 write.lsw_ts = lsw_ts;
3544 /* Use 0xFF00 for disabling timestamps */
3545 if (flags == 0xFF00)
3546 write.uflags = (0x00000000 | (flags & 0x800000FF));
3547 else
3548 write.uflags = (0x80000000 | flags);
3549 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3550
3551 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3552 , __func__,
3553 ab->phys,
3554 write.buf_add,
3555 write.hdr.token,
3556 write.uid);
3557 mutex_unlock(&port->lock);
Rajesha Kini3498c932011-07-19 19:58:27 +05303558#ifdef CONFIG_DEBUG_FS
3559 if (out_enable_flag) {
3560 char zero_pattern[2] = {0x00, 0x00};
3561 /* If First two byte is non zero and last two byte
3562 is zero then it is warm output pattern */
3563 if ((strncmp(((char *)ab->data), zero_pattern, 2)) &&
3564 (!strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3565 do_gettimeofday(&out_warm_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003566 pr_debug("WARM:apr_send_pkt at %ld sec %ld microsec\n",
3567 out_warm_tv.tv_sec,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303568 out_warm_tv.tv_usec);
3569 pr_debug("Warm Pattern Matched");
3570 }
3571 /* If First two byte is zero and last two byte is
3572 non zero then it is cont ouput pattern */
3573 else if ((!strncmp(((char *)ab->data), zero_pattern, 2))
3574 && (strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3575 do_gettimeofday(&out_cont_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003576 pr_debug("CONT:apr_send_pkt at %ld sec %ld microsec\n",
3577 out_cont_tv.tv_sec,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303578 out_cont_tv.tv_usec);
3579 pr_debug("Cont Pattern Matched");
3580 }
3581 }
3582#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003583 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3584 if (rc < 0) {
3585 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3586 goto fail_cmd;
3587 }
3588 pr_debug("%s: WRITE SUCCESS\n", __func__);
3589 return 0;
3590 }
3591fail_cmd:
3592 return -EINVAL;
3593}
3594
3595int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3596 uint32_t lsw_ts, uint32_t flags)
3597{
3598 int rc = 0;
3599 struct asm_stream_cmd_write write;
3600 struct audio_port_data *port;
3601 struct audio_buffer *ab;
3602 int dsp_buf = 0;
3603
3604 if (!ac || ac->apr == NULL) {
3605 pr_err("APR handle NULL\n");
3606 return -EINVAL;
3607 }
3608 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3609 if (ac->io_mode == SYNC_IO_MODE) {
3610 port = &ac->port[IN];
3611
3612 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write),
3613 FALSE);
3614
3615 dsp_buf = port->dsp_buf;
3616 ab = &port->buf[dsp_buf];
3617
3618 write.hdr.token = port->dsp_buf;
3619 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3620 write.buf_add = ab->phys;
3621 write.avail_bytes = len;
3622 write.uid = port->dsp_buf;
3623 write.msw_ts = msw_ts;
3624 write.lsw_ts = lsw_ts;
3625 /* Use 0xFF00 for disabling timestamps */
3626 if (flags == 0xFF00)
3627 write.uflags = (0x00000000 | (flags & 0x800000FF));
3628 else
3629 write.uflags = (0x80000000 | flags);
3630 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3631
3632 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3633 , __func__,
3634 ab->phys,
3635 write.buf_add,
3636 write.hdr.token,
3637 write.uid);
3638
3639 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3640 if (rc < 0) {
3641 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3642 goto fail_cmd;
3643 }
3644 pr_debug("%s: WRITE SUCCESS\n", __func__);
3645 return 0;
3646 }
3647fail_cmd:
3648 return -EINVAL;
3649}
3650
3651uint64_t q6asm_get_session_time(struct audio_client *ac)
3652{
3653 struct apr_hdr hdr;
3654 int rc;
3655
3656 if (!ac || ac->apr == NULL) {
3657 pr_err("APR handle NULL\n");
3658 return -EINVAL;
3659 }
Swaminathan Sathappanc7f98992012-07-09 11:07:12 -07003660 q6asm_add_hdr(ac, &hdr, sizeof(hdr), FALSE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003661 hdr.opcode = ASM_SESSION_CMD_GET_SESSION_TIME;
3662 atomic_set(&ac->time_flag, 1);
3663
3664 pr_debug("%s: session[%d]opcode[0x%x]\n", __func__,
3665 ac->session,
3666 hdr.opcode);
3667 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3668 if (rc < 0) {
3669 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3670 goto fail_cmd;
3671 }
3672 rc = wait_event_timeout(ac->time_wait,
3673 (atomic_read(&ac->time_flag) == 0), 5*HZ);
3674 if (!rc) {
3675 pr_err("%s: timeout in getting session time from DSP\n",
3676 __func__);
3677 goto fail_cmd;
3678 }
3679 return ac->time_stamp;
3680
3681fail_cmd:
3682 return -EINVAL;
3683}
3684
3685int q6asm_cmd(struct audio_client *ac, int cmd)
3686{
3687 struct apr_hdr hdr;
3688 int rc;
3689 atomic_t *state;
3690 int cnt = 0;
3691
3692 if (!ac || ac->apr == NULL) {
3693 pr_err("APR handle NULL\n");
3694 return -EINVAL;
3695 }
3696 q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
3697 switch (cmd) {
3698 case CMD_PAUSE:
3699 pr_debug("%s:CMD_PAUSE\n", __func__);
3700 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3701 state = &ac->cmd_state;
3702 break;
3703 case CMD_FLUSH:
3704 pr_debug("%s:CMD_FLUSH\n", __func__);
3705 hdr.opcode = ASM_STREAM_CMD_FLUSH;
3706 state = &ac->cmd_state;
3707 break;
3708 case CMD_OUT_FLUSH:
3709 pr_debug("%s:CMD_OUT_FLUSH\n", __func__);
3710 hdr.opcode = ASM_STREAM_CMD_FLUSH_READBUFS;
3711 state = &ac->cmd_state;
3712 break;
3713 case CMD_EOS:
3714 pr_debug("%s:CMD_EOS\n", __func__);
3715 hdr.opcode = ASM_DATA_CMD_EOS;
3716 atomic_set(&ac->cmd_state, 0);
3717 state = &ac->cmd_state;
3718 break;
3719 case CMD_CLOSE:
3720 pr_debug("%s:CMD_CLOSE\n", __func__);
3721 hdr.opcode = ASM_STREAM_CMD_CLOSE;
3722 state = &ac->cmd_state;
3723 break;
3724 default:
3725 pr_err("Invalid format[%d]\n", cmd);
3726 goto fail_cmd;
3727 }
3728 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3729 ac->session,
3730 hdr.opcode);
3731 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3732 if (rc < 0) {
3733 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3734 goto fail_cmd;
3735 }
3736 rc = wait_event_timeout(ac->cmd_wait, (atomic_read(state) == 0), 5*HZ);
3737 if (!rc) {
3738 pr_err("timeout. waited for response opcode[0x%x]\n",
3739 hdr.opcode);
3740 goto fail_cmd;
3741 }
3742 if (cmd == CMD_FLUSH)
3743 q6asm_reset_buf_state(ac);
3744 if (cmd == CMD_CLOSE) {
3745 /* check if DSP return all buffers */
3746 if (ac->port[IN].buf) {
3747 for (cnt = 0; cnt < ac->port[IN].max_buf_cnt;
3748 cnt++) {
3749 if (ac->port[IN].buf[cnt].used == IN) {
3750 pr_debug("Write Buf[%d] not returned\n",
3751 cnt);
3752 }
3753 }
3754 }
3755 if (ac->port[OUT].buf) {
3756 for (cnt = 0; cnt < ac->port[OUT].max_buf_cnt; cnt++) {
3757 if (ac->port[OUT].buf[cnt].used == OUT) {
3758 pr_debug("Read Buf[%d] not returned\n",
3759 cnt);
3760 }
3761 }
3762 }
3763 }
3764 return 0;
3765fail_cmd:
3766 return -EINVAL;
3767}
3768
3769int q6asm_cmd_nowait(struct audio_client *ac, int cmd)
3770{
3771 struct apr_hdr hdr;
3772 int rc;
3773
3774 if (!ac || ac->apr == NULL) {
3775 pr_err("%s:APR handle NULL\n", __func__);
3776 return -EINVAL;
3777 }
3778 q6asm_add_hdr_async(ac, &hdr, sizeof(hdr), TRUE);
3779 switch (cmd) {
3780 case CMD_PAUSE:
3781 pr_debug("%s:CMD_PAUSE\n", __func__);
3782 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3783 break;
3784 case CMD_EOS:
3785 pr_debug("%s:CMD_EOS\n", __func__);
3786 hdr.opcode = ASM_DATA_CMD_EOS;
3787 break;
3788 default:
3789 pr_err("%s:Invalid format[%d]\n", __func__, cmd);
3790 goto fail_cmd;
3791 }
3792 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3793 ac->session,
3794 hdr.opcode);
Jay Wang0668d1062012-07-11 18:53:21 -07003795
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003796 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3797 if (rc < 0) {
3798 pr_err("%s:Commmand 0x%x failed\n", __func__, hdr.opcode);
3799 goto fail_cmd;
3800 }
Jay Wang0668d1062012-07-11 18:53:21 -07003801 atomic_inc(&ac->nowait_cmd_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003802 return 0;
3803fail_cmd:
3804 return -EINVAL;
3805}
3806
3807static void q6asm_reset_buf_state(struct audio_client *ac)
3808{
3809 int cnt = 0;
3810 int loopcnt = 0;
3811 struct audio_port_data *port = NULL;
3812
3813 if (ac->io_mode == SYNC_IO_MODE) {
3814 mutex_lock(&ac->cmd_lock);
3815 for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
3816 port = &ac->port[loopcnt];
3817 cnt = port->max_buf_cnt - 1;
3818 port->dsp_buf = 0;
3819 port->cpu_buf = 0;
3820 while (cnt >= 0) {
3821 if (!port->buf)
3822 continue;
3823 port->buf[cnt].used = 1;
3824 cnt--;
3825 }
3826 }
3827 mutex_unlock(&ac->cmd_lock);
3828 }
3829}
3830
3831int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable)
3832{
3833 struct asm_stream_cmd_reg_tx_overflow_event tx_overflow;
3834 int rc;
3835
3836 if (!ac || ac->apr == NULL) {
3837 pr_err("APR handle NULL\n");
3838 return -EINVAL;
3839 }
3840 pr_debug("%s:session[%d]enable[%d]\n", __func__,
3841 ac->session, enable);
3842 q6asm_add_hdr(ac, &tx_overflow.hdr, sizeof(tx_overflow), TRUE);
3843
3844 tx_overflow.hdr.opcode = \
3845 ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS;
3846 /* tx overflow event: enable */
3847 tx_overflow.enable = enable;
3848
3849 rc = apr_send_pkt(ac->apr, (uint32_t *) &tx_overflow);
3850 if (rc < 0) {
3851 pr_err("tx overflow op[0x%x]rc[%d]\n", \
3852 tx_overflow.hdr.opcode, rc);
3853 goto fail_cmd;
3854 }
3855 rc = wait_event_timeout(ac->cmd_wait,
3856 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3857 if (!rc) {
3858 pr_err("timeout. waited for tx overflow\n");
3859 goto fail_cmd;
3860 }
3861 return 0;
3862fail_cmd:
3863 return -EINVAL;
3864}
3865
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003866int q6asm_get_apr_service_id(int session_id)
3867{
3868 pr_debug("%s\n", __func__);
3869
Shiv Maliyappanahallia84982a2012-01-19 15:25:04 -08003870 if (session_id < 0 || session_id > SESSION_MAX) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003871 pr_err("%s: invalid session_id = %d\n", __func__, session_id);
3872 return -EINVAL;
3873 }
3874
3875 return ((struct apr_svc *)session[session_id]->apr)->id;
3876}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003877
3878
3879static int __init q6asm_init(void)
3880{
3881 pr_debug("%s\n", __func__);
3882 init_waitqueue_head(&this_mmap.cmd_wait);
3883 memset(session, 0, sizeof(session));
Rajesha Kini3498c932011-07-19 19:58:27 +05303884#ifdef CONFIG_DEBUG_FS
3885 out_buffer = kmalloc(OUT_BUFFER_SIZE, GFP_KERNEL);
3886 out_dentry = debugfs_create_file("audio_out_latency_measurement_node",\
Glenn Kasten5dfda802012-10-04 16:40:27 -07003887 0664,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303888 NULL, NULL, &audio_output_latency_debug_fops);
3889 if (IS_ERR(out_dentry))
3890 pr_err("debugfs_create_file failed\n");
3891 in_buffer = kmalloc(IN_BUFFER_SIZE, GFP_KERNEL);
3892 in_dentry = debugfs_create_file("audio_in_latency_measurement_node",\
Glenn Kasten5dfda802012-10-04 16:40:27 -07003893 0664,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303894 NULL, NULL, &audio_input_latency_debug_fops);
3895 if (IS_ERR(in_dentry))
3896 pr_err("debugfs_create_file failed\n");
3897#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003898 return 0;
3899}
3900
3901device_initcall(q6asm_init);