blob: 0575f6e9f8b52af91b25d42774933e6c37907aeb [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;
Ajit Khare7277bb72012-10-31 16:34:22 -07001629 case FORMAT_AMR_WB_PLUS:
1630 open.write_format = AMR_WB_PLUS;
1631 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301632 case FORMAT_V13K:
1633 open.write_format = V13K_FS;
1634 break;
1635 case FORMAT_EVRC:
1636 open.write_format = EVRC_FS;
1637 break;
1638 case FORMAT_EVRCB:
1639 open.write_format = EVRCB_FS;
1640 break;
1641 case FORMAT_EVRCWB:
1642 open.write_format = EVRCWB_FS;
1643 break;
1644 case FORMAT_MP3:
1645 open.write_format = MP3;
1646 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001647 default:
1648 pr_err("Invalid format[%d]\n", wr_format);
1649 goto fail_cmd;
1650 }
1651
1652 switch (rd_format) {
1653 case FORMAT_LINEAR_PCM:
1654 open.read_format = LINEAR_PCM;
1655 break;
1656 case FORMAT_MPEG4_AAC:
1657 open.read_format = MPEG4_AAC;
1658 break;
1659 case FORMAT_V13K:
1660 open.read_format = V13K_FS;
1661 break;
1662 case FORMAT_EVRC:
1663 open.read_format = EVRC_FS;
1664 break;
1665 case FORMAT_AMRNB:
1666 open.read_format = AMRNB_FS;
1667 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301668 case FORMAT_AMRWB:
1669 open.read_format = AMRWB_FS;
1670 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001671 default:
1672 pr_err("Invalid format[%d]\n", rd_format);
1673 goto fail_cmd;
1674 }
1675 pr_debug("%s:rdformat[0x%x]wrformat[0x%x]\n", __func__,
1676 open.read_format, open.write_format);
1677
1678 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1679 if (rc < 0) {
1680 pr_err("open failed op[0x%x]rc[%d]\n", \
1681 open.hdr.opcode, rc);
1682 goto fail_cmd;
1683 }
1684 rc = wait_event_timeout(ac->cmd_wait,
1685 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1686 if (!rc) {
1687 pr_err("timeout. waited for OPEN_WRITE rc[%d]\n", rc);
1688 goto fail_cmd;
1689 }
1690 return 0;
1691fail_cmd:
1692 return -EINVAL;
1693}
1694
1695int q6asm_run(struct audio_client *ac, uint32_t flags,
1696 uint32_t msw_ts, uint32_t lsw_ts)
1697{
1698 struct asm_stream_cmd_run run;
1699 int rc;
1700 if (!ac || ac->apr == NULL) {
1701 pr_err("APR handle NULL\n");
1702 return -EINVAL;
1703 }
1704 pr_debug("%s session[%d]", __func__, ac->session);
1705 q6asm_add_hdr(ac, &run.hdr, sizeof(run), TRUE);
1706
1707 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1708 run.flags = flags;
1709 run.msw_ts = msw_ts;
1710 run.lsw_ts = lsw_ts;
Rajesha Kini3498c932011-07-19 19:58:27 +05301711#ifdef CONFIG_DEBUG_FS
1712 if (out_enable_flag) {
1713 do_gettimeofday(&out_cold_tv);
1714 pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",\
1715 out_cold_tv.tv_sec, out_cold_tv.tv_usec);
1716 }
1717#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001718 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1719 if (rc < 0) {
1720 pr_err("Commmand run failed[%d]", rc);
1721 goto fail_cmd;
1722 }
1723
1724 rc = wait_event_timeout(ac->cmd_wait,
1725 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1726 if (!rc) {
1727 pr_err("timeout. waited for run success rc[%d]", rc);
1728 goto fail_cmd;
1729 }
1730
1731 return 0;
1732fail_cmd:
1733 return -EINVAL;
1734}
1735
1736int q6asm_run_nowait(struct audio_client *ac, uint32_t flags,
1737 uint32_t msw_ts, uint32_t lsw_ts)
1738{
1739 struct asm_stream_cmd_run run;
1740 int rc;
1741 if (!ac || ac->apr == NULL) {
1742 pr_err("%s:APR handle NULL\n", __func__);
1743 return -EINVAL;
1744 }
1745 pr_debug("session[%d]", ac->session);
1746 q6asm_add_hdr_async(ac, &run.hdr, sizeof(run), TRUE);
1747
1748 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1749 run.flags = flags;
1750 run.msw_ts = msw_ts;
1751 run.lsw_ts = lsw_ts;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001752 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1753 if (rc < 0) {
1754 pr_err("%s:Commmand run failed[%d]", __func__, rc);
1755 return -EINVAL;
1756 }
Jay Wang0668d1062012-07-11 18:53:21 -07001757 atomic_inc(&ac->nowait_cmd_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001758 return 0;
1759}
1760
1761
1762int q6asm_enc_cfg_blk_aac(struct audio_client *ac,
1763 uint32_t frames_per_buf,
1764 uint32_t sample_rate, uint32_t channels,
1765 uint32_t bit_rate, uint32_t mode, uint32_t format)
1766{
1767 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1768 int rc = 0;
1769
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001770 pr_debug("%s:session[%d]frames[%d]SR[%d]ch[%d]bitrate[%d]mode[%d] format[%d]",
1771 __func__, ac->session, frames_per_buf,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001772 sample_rate, channels, bit_rate, mode, format);
1773
1774 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1775
1776 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1777 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1778 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1779 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1780 enc_cfg.enc_blk.format_id = MPEG4_AAC;
1781 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_aac_read_cfg);
1782 enc_cfg.enc_blk.cfg.aac.bitrate = bit_rate;
1783 enc_cfg.enc_blk.cfg.aac.enc_mode = mode;
1784 enc_cfg.enc_blk.cfg.aac.format = format;
1785 enc_cfg.enc_blk.cfg.aac.ch_cfg = channels;
1786 enc_cfg.enc_blk.cfg.aac.sample_rate = sample_rate;
1787
1788 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1789 if (rc < 0) {
1790 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1791 rc = -EINVAL;
1792 goto fail_cmd;
1793 }
1794 rc = wait_event_timeout(ac->cmd_wait,
1795 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1796 if (!rc) {
1797 pr_err("timeout. waited for FORMAT_UPDATE\n");
1798 goto fail_cmd;
1799 }
1800 return 0;
1801fail_cmd:
1802 return -EINVAL;
1803}
1804
1805int q6asm_enc_cfg_blk_pcm(struct audio_client *ac,
1806 uint32_t rate, uint32_t channels)
1807{
1808 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1809
1810 int rc = 0;
1811
1812 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1813 ac->session, rate, channels);
1814
1815 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1816
1817 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1818 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1819 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1820 enc_cfg.enc_blk.frames_per_buf = 1;
1821 enc_cfg.enc_blk.format_id = LINEAR_PCM;
1822 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg);
1823 enc_cfg.enc_blk.cfg.pcm.ch_cfg = channels;
1824 enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16;
1825 enc_cfg.enc_blk.cfg.pcm.sample_rate = rate;
1826 enc_cfg.enc_blk.cfg.pcm.is_signed = 1;
1827 enc_cfg.enc_blk.cfg.pcm.interleaved = 1;
1828
1829 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1830 if (rc < 0) {
1831 pr_err("Comamnd open failed\n");
1832 rc = -EINVAL;
1833 goto fail_cmd;
1834 }
1835 rc = wait_event_timeout(ac->cmd_wait,
1836 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1837 if (!rc) {
1838 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1839 goto fail_cmd;
1840 }
1841 return 0;
1842fail_cmd:
1843 return -EINVAL;
1844}
1845
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001846int q6asm_enc_cfg_blk_pcm_native(struct audio_client *ac,
1847 uint32_t rate, uint32_t channels)
1848{
1849 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1850
1851 int rc = 0;
1852
1853 pr_debug("%s: Session %d, rate = %d, channels = %d, setting the rate and channels to 0 for native\n",
1854 __func__, ac->session, rate, channels);
1855
1856 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1857
1858 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1859 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1860 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1861 enc_cfg.enc_blk.frames_per_buf = 1;
1862 enc_cfg.enc_blk.format_id = LINEAR_PCM;
1863 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg);
1864 enc_cfg.enc_blk.cfg.pcm.ch_cfg = 0;/*channels;*/
1865 enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16;
1866 enc_cfg.enc_blk.cfg.pcm.sample_rate = 0;/*rate;*/
1867 enc_cfg.enc_blk.cfg.pcm.is_signed = 1;
1868 enc_cfg.enc_blk.cfg.pcm.interleaved = 1;
1869
1870 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1871 if (rc < 0) {
1872 pr_err("Comamnd open failed\n");
1873 rc = -EINVAL;
1874 goto fail_cmd;
1875 }
1876 rc = wait_event_timeout(ac->cmd_wait,
1877 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1878 if (!rc) {
1879 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1880 goto fail_cmd;
1881 }
1882 return 0;
1883fail_cmd:
1884 return -EINVAL;
1885}
1886
Mingming Yin647e9ea2012-03-17 19:56:10 -07001887int q6asm_enc_cfg_blk_multi_ch_pcm(struct audio_client *ac,
1888 uint32_t rate, uint32_t channels)
1889{
1890 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1891
1892 int rc = 0;
1893
1894 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1895 ac->session, rate, channels);
1896
1897 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1898
1899 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1900 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1901 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1902 enc_cfg.enc_blk.frames_per_buf = 1;
1903 enc_cfg.enc_blk.format_id = MULTI_CHANNEL_PCM;
1904 enc_cfg.enc_blk.cfg_size =
1905 sizeof(struct asm_multi_channel_pcm_fmt_blk);
1906 enc_cfg.enc_blk.cfg.mpcm.num_channels = channels;
1907 enc_cfg.enc_blk.cfg.mpcm.bits_per_sample = 16;
1908 enc_cfg.enc_blk.cfg.mpcm.sample_rate = rate;
1909 enc_cfg.enc_blk.cfg.mpcm.is_signed = 1;
1910 enc_cfg.enc_blk.cfg.mpcm.is_interleaved = 1;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07001911 if (channels == 1) {
1912 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1913 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = 0;
1914 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = 0;
1915 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = 0;
1916 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1917 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1918 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1919 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1920 } else if (channels == 2) {
Subhash Chandra Bose Naripeddy8477d222012-06-12 00:30:54 -07001921 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1922 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1923 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = 0;
1924 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = 0;
1925 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1926 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1927 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1928 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1929 } else if (channels == 4) {
1930 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1931 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1932 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_RB;
1933 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_LB;
1934 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1935 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1936 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1937 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1938 } else if (channels == 6) {
1939 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1940 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1941 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_LFE;
1942 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_FC;
1943 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = PCM_CHANNEL_LB;
1944 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = PCM_CHANNEL_RB;
1945 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1946 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1947 } else if (channels == 8) {
1948 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1949 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1950 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_LFE;
1951 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_FC;
1952 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = PCM_CHANNEL_LB;
1953 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = PCM_CHANNEL_RB;
1954 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = PCM_CHANNEL_FLC;
1955 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = PCM_CHANNEL_FRC;
1956 }
Mingming Yin647e9ea2012-03-17 19:56:10 -07001957
1958 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1959 if (rc < 0) {
1960 pr_err("Comamnd open failed\n");
1961 rc = -EINVAL;
1962 goto fail_cmd;
1963 }
1964 rc = wait_event_timeout(ac->cmd_wait,
1965 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1966 if (!rc) {
1967 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1968 goto fail_cmd;
1969 }
1970 return 0;
1971fail_cmd:
1972 return -EINVAL;
1973}
1974
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001975int q6asm_enable_sbrps(struct audio_client *ac,
1976 uint32_t sbr_ps_enable)
1977{
1978 struct asm_stream_cmd_encdec_sbr sbrps;
1979
1980 int rc = 0;
1981
1982 pr_debug("%s: Session %d\n", __func__, ac->session);
1983
1984 q6asm_add_hdr(ac, &sbrps.hdr, sizeof(sbrps), TRUE);
1985
1986 sbrps.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1987 sbrps.param_id = ASM_ENABLE_SBR_PS;
1988 sbrps.param_size = sizeof(struct asm_sbr_ps);
1989 sbrps.sbr_ps.enable = sbr_ps_enable;
1990
1991 rc = apr_send_pkt(ac->apr, (uint32_t *) &sbrps);
1992 if (rc < 0) {
1993 pr_err("Command opcode[0x%x]paramid[0x%x] failed\n",
1994 ASM_STREAM_CMD_SET_ENCDEC_PARAM,
1995 ASM_ENABLE_SBR_PS);
1996 rc = -EINVAL;
1997 goto fail_cmd;
1998 }
1999 rc = wait_event_timeout(ac->cmd_wait,
2000 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2001 if (!rc) {
2002 pr_err("timeout opcode[0x%x] ", sbrps.hdr.opcode);
2003 goto fail_cmd;
2004 }
2005 return 0;
2006fail_cmd:
2007 return -EINVAL;
2008}
2009
Swaminathan Sathappan70765cd2011-07-19 18:42:47 -07002010int q6asm_cfg_dual_mono_aac(struct audio_client *ac,
2011 uint16_t sce_left, uint16_t sce_right)
2012{
2013 struct asm_stream_cmd_encdec_dualmono dual_mono;
2014
2015 int rc = 0;
2016
2017 pr_debug("%s: Session %d, sce_left = %d, sce_right = %d\n",
2018 __func__, ac->session, sce_left, sce_right);
2019
2020 q6asm_add_hdr(ac, &dual_mono.hdr, sizeof(dual_mono), TRUE);
2021
2022 dual_mono.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2023 dual_mono.param_id = ASM_CONFIGURE_DUAL_MONO;
2024 dual_mono.param_size = sizeof(struct asm_dual_mono);
2025 dual_mono.channel_map.sce_left = sce_left;
2026 dual_mono.channel_map.sce_right = sce_right;
2027
2028 rc = apr_send_pkt(ac->apr, (uint32_t *) &dual_mono);
2029 if (rc < 0) {
2030 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
2031 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
2032 ASM_CONFIGURE_DUAL_MONO);
2033 rc = -EINVAL;
2034 goto fail_cmd;
2035 }
2036 rc = wait_event_timeout(ac->cmd_wait,
2037 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2038 if (!rc) {
2039 pr_err("%s:timeout opcode[0x%x]\n", __func__,
2040 dual_mono.hdr.opcode);
2041 goto fail_cmd;
2042 }
2043 return 0;
2044fail_cmd:
2045 return -EINVAL;
2046}
2047
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07002048int q6asm_set_encdec_chan_map(struct audio_client *ac,
2049 uint32_t num_channels)
2050{
2051 struct asm_stream_cmd_encdec_channelmap chan_map;
2052 u8 *channel_mapping;
2053
2054 int rc = 0;
2055
2056 pr_debug("%s: Session %d, num_channels = %d\n",
2057 __func__, ac->session, num_channels);
2058
2059 q6asm_add_hdr(ac, &chan_map.hdr, sizeof(chan_map), TRUE);
2060
2061 chan_map.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2062 chan_map.param_id = ASM_ENCDEC_DEC_CHAN_MAP;
2063 chan_map.param_size = sizeof(struct asm_dec_chan_map);
2064 chan_map.chan_map.num_channels = num_channels;
2065
2066 channel_mapping =
2067 chan_map.chan_map.channel_mapping;
2068
2069 memset(channel_mapping, PCM_CHANNEL_NULL, MAX_CHAN_MAP_CHANNELS);
2070 if (num_channels == 1) {
2071 channel_mapping[0] = PCM_CHANNEL_FL;
2072 } else if (num_channels == 2) {
2073 channel_mapping[0] = PCM_CHANNEL_FL;
2074 channel_mapping[1] = PCM_CHANNEL_FR;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002075 } else if (num_channels == 4) {
2076 channel_mapping[0] = PCM_CHANNEL_FL;
2077 channel_mapping[1] = PCM_CHANNEL_FR;
2078 channel_mapping[1] = PCM_CHANNEL_LB;
2079 channel_mapping[1] = PCM_CHANNEL_RB;
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07002080 } else if (num_channels == 6) {
2081 channel_mapping[0] = PCM_CHANNEL_FC;
2082 channel_mapping[1] = PCM_CHANNEL_FL;
2083 channel_mapping[2] = PCM_CHANNEL_FR;
2084 channel_mapping[3] = PCM_CHANNEL_LB;
2085 channel_mapping[4] = PCM_CHANNEL_RB;
2086 channel_mapping[5] = PCM_CHANNEL_LFE;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002087 } else if (num_channels == 8) {
2088 channel_mapping[0] = PCM_CHANNEL_FC;
2089 channel_mapping[1] = PCM_CHANNEL_FL;
2090 channel_mapping[2] = PCM_CHANNEL_FR;
2091 channel_mapping[3] = PCM_CHANNEL_LB;
2092 channel_mapping[4] = PCM_CHANNEL_RB;
2093 channel_mapping[5] = PCM_CHANNEL_LFE;
2094 channel_mapping[6] = PCM_CHANNEL_FLC;
2095 channel_mapping[7] = PCM_CHANNEL_FRC;
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07002096 } else {
2097 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
2098 num_channels);
2099 rc = -EINVAL;
2100 goto fail_cmd;
2101 }
2102
2103 rc = apr_send_pkt(ac->apr, (uint32_t *) &chan_map);
2104 if (rc < 0) {
2105 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
2106 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
2107 ASM_ENCDEC_DEC_CHAN_MAP);
2108 goto fail_cmd;
2109 }
2110 rc = wait_event_timeout(ac->cmd_wait,
2111 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2112 if (!rc) {
2113 pr_err("%s:timeout opcode[0x%x]\n", __func__,
2114 chan_map.hdr.opcode);
2115 rc = -ETIMEDOUT;
2116 goto fail_cmd;
2117 }
2118 return 0;
2119fail_cmd:
2120 return rc;
2121}
2122
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002123int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf,
2124 uint16_t min_rate, uint16_t max_rate,
2125 uint16_t reduced_rate_level, uint16_t rate_modulation_cmd)
2126{
2127 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2128 int rc = 0;
2129
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002130 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]",
2131 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002132 ac->session, frames_per_buf, min_rate, max_rate,
2133 reduced_rate_level, rate_modulation_cmd);
2134
2135 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2136
2137 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2138
2139 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2140 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2141
2142 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2143 enc_cfg.enc_blk.format_id = V13K_FS;
2144 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_qcelp13_read_cfg);
2145 enc_cfg.enc_blk.cfg.qcelp13.min_rate = min_rate;
2146 enc_cfg.enc_blk.cfg.qcelp13.max_rate = max_rate;
2147 enc_cfg.enc_blk.cfg.qcelp13.reduced_rate_level = reduced_rate_level;
2148 enc_cfg.enc_blk.cfg.qcelp13.rate_modulation_cmd = rate_modulation_cmd;
2149
2150 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2151 if (rc < 0) {
2152 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2153 goto fail_cmd;
2154 }
2155 rc = wait_event_timeout(ac->cmd_wait,
2156 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2157 if (!rc) {
2158 pr_err("timeout. waited for FORMAT_UPDATE\n");
2159 goto fail_cmd;
2160 }
2161 return 0;
2162fail_cmd:
2163 return -EINVAL;
2164}
2165
2166int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf,
2167 uint16_t min_rate, uint16_t max_rate,
2168 uint16_t rate_modulation_cmd)
2169{
2170 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2171 int rc = 0;
2172
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002173 pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] rate_modulation_cmd[0x%4x]",
2174 __func__, ac->session,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002175 frames_per_buf, min_rate, max_rate, rate_modulation_cmd);
2176
2177 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2178
2179 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2180
2181 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2182 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2183
2184 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2185 enc_cfg.enc_blk.format_id = EVRC_FS;
2186 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_evrc_read_cfg);
2187 enc_cfg.enc_blk.cfg.evrc.min_rate = min_rate;
2188 enc_cfg.enc_blk.cfg.evrc.max_rate = max_rate;
2189 enc_cfg.enc_blk.cfg.evrc.rate_modulation_cmd = rate_modulation_cmd;
2190 enc_cfg.enc_blk.cfg.evrc.reserved = 0;
2191
2192 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2193 if (rc < 0) {
2194 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2195 goto fail_cmd;
2196 }
2197 rc = wait_event_timeout(ac->cmd_wait,
2198 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2199 if (!rc) {
2200 pr_err("timeout. waited for FORMAT_UPDATE\n");
2201 goto fail_cmd;
2202 }
2203 return 0;
2204fail_cmd:
2205 return -EINVAL;
2206}
2207
2208int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf,
2209 uint16_t band_mode, uint16_t dtx_enable)
2210{
2211 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2212 int rc = 0;
2213
2214 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
2215 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
2216
2217 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2218
2219 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2220
2221 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2222 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2223
2224 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2225 enc_cfg.enc_blk.format_id = AMRNB_FS;
2226 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrnb_read_cfg);
2227 enc_cfg.enc_blk.cfg.amrnb.mode = band_mode;
2228 enc_cfg.enc_blk.cfg.amrnb.dtx_mode = dtx_enable;
2229
2230 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2231 if (rc < 0) {
2232 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2233 goto fail_cmd;
2234 }
2235 rc = wait_event_timeout(ac->cmd_wait,
2236 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2237 if (!rc) {
2238 pr_err("timeout. waited for FORMAT_UPDATE\n");
2239 goto fail_cmd;
2240 }
2241 return 0;
2242fail_cmd:
2243 return -EINVAL;
2244}
2245
Alex Wong2caeecc2011-10-28 10:52:15 +05302246int q6asm_enc_cfg_blk_amrwb(struct audio_client *ac, uint32_t frames_per_buf,
2247 uint16_t band_mode, uint16_t dtx_enable)
2248{
2249 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2250 int rc = 0;
2251
2252 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
2253 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
2254
2255 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2256
2257 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2258
2259 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2260 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2261
2262 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2263 enc_cfg.enc_blk.format_id = AMRWB_FS;
2264 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrwb_read_cfg);
2265 enc_cfg.enc_blk.cfg.amrwb.mode = band_mode;
2266 enc_cfg.enc_blk.cfg.amrwb.dtx_mode = dtx_enable;
2267
2268 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2269 if (rc < 0) {
2270 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2271 goto fail_cmd;
2272 }
2273 rc = wait_event_timeout(ac->cmd_wait,
2274 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2275 if (!rc) {
2276 pr_err("timeout. waited for FORMAT_UPDATE\n");
2277 goto fail_cmd;
2278 }
2279 return 0;
2280fail_cmd:
2281 return -EINVAL;
2282}
2283
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002284int q6asm_media_format_block_pcm(struct audio_client *ac,
2285 uint32_t rate, uint32_t channels)
2286{
2287 struct asm_stream_media_format_update fmt;
2288 int rc = 0;
2289
2290 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
2291 channels);
2292
2293 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2294
2295 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2296
2297 fmt.format = LINEAR_PCM;
2298 fmt.cfg_size = sizeof(struct asm_pcm_cfg);
2299 fmt.write_cfg.pcm_cfg.ch_cfg = channels;
2300 fmt.write_cfg.pcm_cfg.bits_per_sample = 16;
2301 fmt.write_cfg.pcm_cfg.sample_rate = rate;
2302 fmt.write_cfg.pcm_cfg.is_signed = 1;
2303 fmt.write_cfg.pcm_cfg.interleaved = 1;
2304
2305 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2306 if (rc < 0) {
2307 pr_err("%s:Comamnd open failed\n", __func__);
2308 goto fail_cmd;
2309 }
2310 rc = wait_event_timeout(ac->cmd_wait,
2311 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2312 if (!rc) {
2313 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2314 goto fail_cmd;
2315 }
2316 return 0;
2317fail_cmd:
2318 return -EINVAL;
2319}
2320
Kiran Kandi5e809b02012-01-31 00:24:33 -08002321int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
2322 uint32_t rate, uint32_t channels)
2323{
2324 struct asm_stream_media_format_update fmt;
2325 u8 *channel_mapping;
2326 int rc = 0;
2327
2328 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
2329 channels);
2330
2331 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2332
2333 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2334
2335 fmt.format = MULTI_CHANNEL_PCM;
2336 fmt.cfg_size = sizeof(struct asm_multi_channel_pcm_fmt_blk);
2337 fmt.write_cfg.multi_ch_pcm_cfg.num_channels = channels;
2338 fmt.write_cfg.multi_ch_pcm_cfg.bits_per_sample = 16;
2339 fmt.write_cfg.multi_ch_pcm_cfg.sample_rate = rate;
2340 fmt.write_cfg.multi_ch_pcm_cfg.is_signed = 1;
2341 fmt.write_cfg.multi_ch_pcm_cfg.is_interleaved = 1;
2342 channel_mapping =
2343 fmt.write_cfg.multi_ch_pcm_cfg.channel_mapping;
2344
2345 memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
2346
2347 if (channels == 1) {
2348 channel_mapping[0] = PCM_CHANNEL_FL;
2349 } else if (channels == 2) {
2350 channel_mapping[0] = PCM_CHANNEL_FL;
2351 channel_mapping[1] = PCM_CHANNEL_FR;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002352 } else if (channels == 4) {
2353 channel_mapping[0] = PCM_CHANNEL_FL;
2354 channel_mapping[1] = PCM_CHANNEL_FR;
2355 channel_mapping[1] = PCM_CHANNEL_LB;
2356 channel_mapping[1] = PCM_CHANNEL_RB;
Kiran Kandi5e809b02012-01-31 00:24:33 -08002357 } else if (channels == 6) {
SathishKumar Mani6074b772012-09-26 13:49:49 -07002358 channel_mapping[0] = PCM_CHANNEL_FL;
2359 channel_mapping[1] = PCM_CHANNEL_FR;
2360 channel_mapping[2] = PCM_CHANNEL_FC;
2361 channel_mapping[3] = PCM_CHANNEL_LFE;
2362 channel_mapping[4] = PCM_CHANNEL_LB;
2363 channel_mapping[5] = PCM_CHANNEL_RB;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002364 } else if (channels == 8) {
2365 channel_mapping[0] = PCM_CHANNEL_FC;
2366 channel_mapping[1] = PCM_CHANNEL_FL;
2367 channel_mapping[2] = PCM_CHANNEL_FR;
2368 channel_mapping[3] = PCM_CHANNEL_LB;
2369 channel_mapping[4] = PCM_CHANNEL_RB;
2370 channel_mapping[5] = PCM_CHANNEL_LFE;
2371 channel_mapping[6] = PCM_CHANNEL_FLC;
2372 channel_mapping[7] = PCM_CHANNEL_FRC;
Kiran Kandi5e809b02012-01-31 00:24:33 -08002373 } else {
2374 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
2375 channels);
2376 return -EINVAL;
2377 }
2378
2379 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2380 if (rc < 0) {
2381 pr_err("%s:Comamnd open failed\n", __func__);
2382 goto fail_cmd;
2383 }
2384 rc = wait_event_timeout(ac->cmd_wait,
2385 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2386 if (!rc) {
2387 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2388 goto fail_cmd;
2389 }
2390 return 0;
2391fail_cmd:
2392 return -EINVAL;
2393}
2394
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002395int q6asm_media_format_block_aac(struct audio_client *ac,
2396 struct asm_aac_cfg *cfg)
2397{
2398 struct asm_stream_media_format_update fmt;
2399 int rc = 0;
2400
2401 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2402 cfg->sample_rate, cfg->ch_cfg);
2403
2404 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2405
2406 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2407
2408 fmt.format = MPEG4_AAC;
2409 fmt.cfg_size = sizeof(struct asm_aac_cfg);
2410 fmt.write_cfg.aac_cfg.format = cfg->format;
2411 fmt.write_cfg.aac_cfg.aot = cfg->aot;
2412 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
2413 fmt.write_cfg.aac_cfg.section_data_resilience =
2414 cfg->section_data_resilience;
2415 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2416 cfg->scalefactor_data_resilience;
2417 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2418 cfg->spectral_data_resilience;
2419 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2420 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2421 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2422 __func__, fmt.format, fmt.cfg_size,
2423 fmt.write_cfg.aac_cfg.format,
2424 fmt.write_cfg.aac_cfg.aot,
2425 fmt.write_cfg.aac_cfg.ch_cfg,
2426 fmt.write_cfg.aac_cfg.sample_rate);
2427 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2428 if (rc < 0) {
2429 pr_err("%s:Comamnd open failed\n", __func__);
2430 goto fail_cmd;
2431 }
2432 rc = wait_event_timeout(ac->cmd_wait,
2433 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2434 if (!rc) {
2435 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2436 goto fail_cmd;
2437 }
2438 return 0;
2439fail_cmd:
2440 return -EINVAL;
2441}
2442
Ajit Khare43fd8832012-08-07 13:19:44 -07002443int q6asm_media_format_block_amrwbplus(struct audio_client *ac,
2444 struct asm_amrwbplus_cfg *cfg)
2445{
2446 struct asm_stream_media_format_update fmt;
2447 int rc = 0;
2448 pr_debug("q6asm_media_format_block_amrwbplus");
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07002449
Ajit Khare43fd8832012-08-07 13:19:44 -07002450 pr_debug("%s:session[%d]band-mode[%d]frame-fmt[%d]ch[%d]\n",
2451 __func__,
2452 ac->session,
2453 cfg->amr_band_mode,
2454 cfg->amr_frame_fmt,
2455 cfg->num_channels);
2456
2457 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2458
2459 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2460
2461 fmt.format = AMR_WB_PLUS;
2462 fmt.cfg_size = cfg->size_bytes;
2463
2464 fmt.write_cfg.amrwbplus_cfg.size_bytes = cfg->size_bytes;
2465 fmt.write_cfg.amrwbplus_cfg.version = cfg->version;
2466 fmt.write_cfg.amrwbplus_cfg.num_channels = cfg->num_channels;
2467 fmt.write_cfg.amrwbplus_cfg.amr_band_mode = cfg->amr_band_mode;
2468 fmt.write_cfg.amrwbplus_cfg.amr_dtx_mode = cfg->amr_dtx_mode;
2469 fmt.write_cfg.amrwbplus_cfg.amr_frame_fmt = cfg->amr_frame_fmt;
2470 fmt.write_cfg.amrwbplus_cfg.amr_lsf_idx = cfg->amr_lsf_idx;
2471
2472 pr_debug("%s: num_channels=%x amr_band_mode=%d amr_frame_fmt=%d\n",
2473 __func__,
2474 cfg->num_channels,
2475 cfg->amr_band_mode,
2476 cfg->amr_frame_fmt);
2477
2478 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2479 if (rc < 0) {
2480 pr_err("%s:Comamnd media format update failed..\n", __func__);
2481 goto fail_cmd;
2482 }
2483 rc = wait_event_timeout(ac->cmd_wait,
2484 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2485 if (!rc) {
2486 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2487 goto fail_cmd;
2488 }
2489 return 0;
2490fail_cmd:
2491 return -EINVAL;
2492}
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07002493int q6asm_media_format_block_multi_aac(struct audio_client *ac,
2494 struct asm_aac_cfg *cfg)
2495{
2496 struct asm_stream_media_format_update fmt;
2497 int rc = 0;
2498
2499 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2500 cfg->sample_rate, cfg->ch_cfg);
2501
2502 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2503
2504 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2505
2506 fmt.format = MPEG4_MULTI_AAC;
2507 fmt.cfg_size = sizeof(struct asm_aac_cfg);
2508 fmt.write_cfg.aac_cfg.format = cfg->format;
2509 fmt.write_cfg.aac_cfg.aot = cfg->aot;
2510 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
2511 fmt.write_cfg.aac_cfg.section_data_resilience =
2512 cfg->section_data_resilience;
2513 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2514 cfg->scalefactor_data_resilience;
2515 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2516 cfg->spectral_data_resilience;
2517 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2518 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2519 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2520 __func__, fmt.format, fmt.cfg_size,
2521 fmt.write_cfg.aac_cfg.format,
2522 fmt.write_cfg.aac_cfg.aot,
2523 fmt.write_cfg.aac_cfg.ch_cfg,
2524 fmt.write_cfg.aac_cfg.sample_rate);
2525 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2526 if (rc < 0) {
2527 pr_err("%s:Comamnd open failed\n", __func__);
2528 goto fail_cmd;
2529 }
2530 rc = wait_event_timeout(ac->cmd_wait,
2531 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2532 if (!rc) {
2533 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2534 goto fail_cmd;
2535 }
2536 return 0;
2537fail_cmd:
2538 return -EINVAL;
2539}
2540
2541
Alex Wong2caeecc2011-10-28 10:52:15 +05302542
2543int q6asm_media_format_block(struct audio_client *ac, uint32_t format)
2544{
2545
2546 struct asm_stream_media_format_update fmt;
2547 int rc = 0;
2548
2549 pr_debug("%s:session[%d] format[0x%x]\n", __func__,
2550 ac->session, format);
2551
2552 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2553 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302554 switch (format) {
2555 case FORMAT_V13K:
2556 fmt.format = V13K_FS;
2557 break;
2558 case FORMAT_EVRC:
2559 fmt.format = EVRC_FS;
2560 break;
2561 case FORMAT_AMRWB:
2562 fmt.format = AMRWB_FS;
2563 break;
Ajit Khare43fd8832012-08-07 13:19:44 -07002564 case FORMAT_AMR_WB_PLUS:
2565 fmt.format = AMR_WB_PLUS;
2566 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302567 case FORMAT_AMRNB:
2568 fmt.format = AMRNB_FS;
2569 break;
2570 case FORMAT_MP3:
2571 fmt.format = MP3;
2572 break;
Srikanth Uyyala66f781a2012-06-13 23:23:25 +05302573 case FORMAT_DTS:
2574 fmt.format = DTS;
2575 break;
2576 case FORMAT_DTS_LBR:
2577 fmt.format = DTS_LBR;
2578 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302579 default:
2580 pr_err("Invalid format[%d]\n", format);
2581 goto fail_cmd;
2582 }
Alex Wong2caeecc2011-10-28 10:52:15 +05302583 fmt.cfg_size = 0;
2584
2585 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2586 if (rc < 0) {
2587 pr_err("%s:Comamnd open failed\n", __func__);
2588 goto fail_cmd;
2589 }
2590 rc = wait_event_timeout(ac->cmd_wait,
2591 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2592 if (!rc) {
2593 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2594 goto fail_cmd;
2595 }
2596 return 0;
2597fail_cmd:
2598 return -EINVAL;
2599}
2600
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002601int q6asm_media_format_block_wma(struct audio_client *ac,
2602 void *cfg)
2603{
2604 struct asm_stream_media_format_update fmt;
2605 struct asm_wma_cfg *wma_cfg = (struct asm_wma_cfg *)cfg;
2606 int rc = 0;
2607
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002608 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 -07002609 ac->session, wma_cfg->format_tag, wma_cfg->sample_rate,
2610 wma_cfg->ch_cfg, wma_cfg->avg_bytes_per_sec,
2611 wma_cfg->block_align, wma_cfg->valid_bits_per_sample,
2612 wma_cfg->ch_mask, wma_cfg->encode_opt);
2613
2614 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2615
2616 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2617
2618 fmt.format = WMA_V9;
2619 fmt.cfg_size = sizeof(struct asm_wma_cfg);
2620 fmt.write_cfg.wma_cfg.format_tag = wma_cfg->format_tag;
2621 fmt.write_cfg.wma_cfg.ch_cfg = wma_cfg->ch_cfg;
2622 fmt.write_cfg.wma_cfg.sample_rate = wma_cfg->sample_rate;
2623 fmt.write_cfg.wma_cfg.avg_bytes_per_sec = wma_cfg->avg_bytes_per_sec;
2624 fmt.write_cfg.wma_cfg.block_align = wma_cfg->block_align;
2625 fmt.write_cfg.wma_cfg.valid_bits_per_sample =
2626 wma_cfg->valid_bits_per_sample;
2627 fmt.write_cfg.wma_cfg.ch_mask = wma_cfg->ch_mask;
2628 fmt.write_cfg.wma_cfg.encode_opt = wma_cfg->encode_opt;
2629 fmt.write_cfg.wma_cfg.adv_encode_opt = 0;
2630 fmt.write_cfg.wma_cfg.adv_encode_opt2 = 0;
2631 fmt.write_cfg.wma_cfg.drc_peak_ref = 0;
2632 fmt.write_cfg.wma_cfg.drc_peak_target = 0;
2633 fmt.write_cfg.wma_cfg.drc_ave_ref = 0;
2634 fmt.write_cfg.wma_cfg.drc_ave_target = 0;
2635
2636 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2637 if (rc < 0) {
2638 pr_err("%s:Comamnd open failed\n", __func__);
2639 goto fail_cmd;
2640 }
2641 rc = wait_event_timeout(ac->cmd_wait,
2642 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2643 if (!rc) {
2644 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2645 goto fail_cmd;
2646 }
2647 return 0;
2648fail_cmd:
2649 return -EINVAL;
2650}
2651
2652int q6asm_media_format_block_wmapro(struct audio_client *ac,
2653 void *cfg)
2654{
2655 struct asm_stream_media_format_update fmt;
2656 struct asm_wmapro_cfg *wmapro_cfg = (struct asm_wmapro_cfg *)cfg;
2657 int rc = 0;
2658
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002659 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 -07002660 ac->session, wmapro_cfg->format_tag, wmapro_cfg->sample_rate,
2661 wmapro_cfg->ch_cfg, wmapro_cfg->avg_bytes_per_sec,
2662 wmapro_cfg->block_align, wmapro_cfg->valid_bits_per_sample,
2663 wmapro_cfg->ch_mask, wmapro_cfg->encode_opt,
2664 wmapro_cfg->adv_encode_opt, wmapro_cfg->adv_encode_opt2);
2665
2666 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2667
2668 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2669
2670 fmt.format = WMA_V10PRO;
2671 fmt.cfg_size = sizeof(struct asm_wmapro_cfg);
2672 fmt.write_cfg.wmapro_cfg.format_tag = wmapro_cfg->format_tag;
2673 fmt.write_cfg.wmapro_cfg.ch_cfg = wmapro_cfg->ch_cfg;
2674 fmt.write_cfg.wmapro_cfg.sample_rate = wmapro_cfg->sample_rate;
2675 fmt.write_cfg.wmapro_cfg.avg_bytes_per_sec =
2676 wmapro_cfg->avg_bytes_per_sec;
2677 fmt.write_cfg.wmapro_cfg.block_align = wmapro_cfg->block_align;
2678 fmt.write_cfg.wmapro_cfg.valid_bits_per_sample =
2679 wmapro_cfg->valid_bits_per_sample;
2680 fmt.write_cfg.wmapro_cfg.ch_mask = wmapro_cfg->ch_mask;
2681 fmt.write_cfg.wmapro_cfg.encode_opt = wmapro_cfg->encode_opt;
2682 fmt.write_cfg.wmapro_cfg.adv_encode_opt = wmapro_cfg->adv_encode_opt;
2683 fmt.write_cfg.wmapro_cfg.adv_encode_opt2 = wmapro_cfg->adv_encode_opt2;
2684 fmt.write_cfg.wmapro_cfg.drc_peak_ref = 0;
2685 fmt.write_cfg.wmapro_cfg.drc_peak_target = 0;
2686 fmt.write_cfg.wmapro_cfg.drc_ave_ref = 0;
2687 fmt.write_cfg.wmapro_cfg.drc_ave_target = 0;
2688
2689 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2690 if (rc < 0) {
2691 pr_err("%s:Comamnd open failed\n", __func__);
2692 goto fail_cmd;
2693 }
2694 rc = wait_event_timeout(ac->cmd_wait,
2695 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2696 if (!rc) {
2697 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2698 goto fail_cmd;
2699 }
2700 return 0;
2701fail_cmd:
2702 return -EINVAL;
2703}
2704
2705int q6asm_memory_map(struct audio_client *ac, uint32_t buf_add, int dir,
2706 uint32_t bufsz, uint32_t bufcnt)
2707{
2708 struct asm_stream_cmd_memory_map mem_map;
2709 int rc = 0;
2710
2711 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2712 pr_err("APR handle NULL\n");
2713 return -EINVAL;
2714 }
2715
2716 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2717
2718 mem_map.hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP;
2719
2720 mem_map.buf_add = buf_add;
2721 mem_map.buf_size = bufsz * bufcnt;
2722 mem_map.mempool_id = 0; /* EBI */
2723 mem_map.reserved = 0;
2724
2725 q6asm_add_mmaphdr(&mem_map.hdr,
2726 sizeof(struct asm_stream_cmd_memory_map), TRUE);
2727
2728 pr_debug("buf add[%x] buf_add_parameter[%x]\n",
2729 mem_map.buf_add, buf_add);
2730
2731 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_map);
2732 if (rc < 0) {
2733 pr_err("mem_map op[0x%x]rc[%d]\n",
2734 mem_map.hdr.opcode, rc);
2735 rc = -EINVAL;
2736 goto fail_cmd;
2737 }
2738
2739 rc = wait_event_timeout(this_mmap.cmd_wait,
2740 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2741 if (!rc) {
2742 pr_err("timeout. waited for memory_map\n");
2743 rc = -EINVAL;
2744 goto fail_cmd;
2745 }
2746 rc = 0;
2747fail_cmd:
2748 return rc;
2749}
2750
2751int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add, int dir)
2752{
2753 struct asm_stream_cmd_memory_unmap mem_unmap;
2754 int rc = 0;
2755
2756 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2757 pr_err("APR handle NULL\n");
2758 return -EINVAL;
2759 }
2760 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2761
2762 q6asm_add_mmaphdr(&mem_unmap.hdr,
2763 sizeof(struct asm_stream_cmd_memory_unmap), TRUE);
2764 mem_unmap.hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP;
2765 mem_unmap.buf_add = buf_add;
2766
2767 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_unmap);
2768 if (rc < 0) {
2769 pr_err("mem_unmap op[0x%x]rc[%d]\n",
2770 mem_unmap.hdr.opcode, rc);
2771 rc = -EINVAL;
2772 goto fail_cmd;
2773 }
2774
2775 rc = wait_event_timeout(this_mmap.cmd_wait,
2776 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2777 if (!rc) {
2778 pr_err("timeout. waited for memory_map\n");
2779 rc = -EINVAL;
2780 goto fail_cmd;
2781 }
2782 rc = 0;
2783fail_cmd:
2784 return rc;
2785}
2786
2787int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain)
2788{
2789 void *vol_cmd = NULL;
2790 void *payload = NULL;
2791 struct asm_pp_params_command *cmd = NULL;
2792 struct asm_lrchannel_gain_params *lrgain = NULL;
2793 int sz = 0;
2794 int rc = 0;
2795
2796 sz = sizeof(struct asm_pp_params_command) +
2797 + sizeof(struct asm_lrchannel_gain_params);
2798 vol_cmd = kzalloc(sz, GFP_KERNEL);
2799 if (vol_cmd == NULL) {
2800 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2801 rc = -EINVAL;
2802 return rc;
2803 }
2804 cmd = (struct asm_pp_params_command *)vol_cmd;
2805 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2806 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2807 cmd->payload = NULL;
2808 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2809 sizeof(struct asm_lrchannel_gain_params);
2810 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2811 cmd->params.param_id = L_R_CHANNEL_GAIN_PARAM_ID;
2812 cmd->params.param_size = sizeof(struct asm_lrchannel_gain_params);
2813 cmd->params.reserved = 0;
2814
2815 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2816 lrgain = (struct asm_lrchannel_gain_params *)payload;
2817
2818 lrgain->left_gain = left_gain;
2819 lrgain->right_gain = right_gain;
2820 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2821 if (rc < 0) {
2822 pr_err("%s: Volume Command failed\n", __func__);
2823 rc = -EINVAL;
2824 goto fail_cmd;
2825 }
2826
2827 rc = wait_event_timeout(ac->cmd_wait,
2828 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2829 if (!rc) {
2830 pr_err("%s: timeout in sending volume command to apr\n",
2831 __func__);
2832 rc = -EINVAL;
2833 goto fail_cmd;
2834 }
2835 rc = 0;
2836fail_cmd:
2837 kfree(vol_cmd);
2838 return rc;
2839}
2840
2841static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
2842 uint32_t bufsz, uint32_t bufcnt)
2843{
2844 struct asm_stream_cmd_memory_map_regions *mmap_regions = NULL;
2845 struct asm_memory_map_regions *mregions = NULL;
2846 struct audio_port_data *port = NULL;
2847 struct audio_buffer *ab = NULL;
2848 void *mmap_region_cmd = NULL;
2849 void *payload = NULL;
2850 int rc = 0;
2851 int i = 0;
2852 int cmd_size = 0;
2853
2854 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2855 pr_err("APR handle NULL\n");
2856 return -EINVAL;
2857 }
2858 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2859
2860 cmd_size = sizeof(struct asm_stream_cmd_memory_map_regions)
2861 + sizeof(struct asm_memory_map_regions) * bufcnt;
2862
2863 mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302864 if (mmap_region_cmd == NULL) {
2865 pr_err("%s: Mem alloc failed\n", __func__);
2866 rc = -EINVAL;
2867 return rc;
2868 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002869 mmap_regions = (struct asm_stream_cmd_memory_map_regions *)
2870 mmap_region_cmd;
2871 q6asm_add_mmaphdr(&mmap_regions->hdr, cmd_size, TRUE);
2872 mmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP_REGIONS;
2873 mmap_regions->mempool_id = 0;
2874 mmap_regions->nregions = bufcnt & 0x00ff;
2875 pr_debug("map_regions->nregions = %d\n", mmap_regions->nregions);
2876 payload = ((u8 *) mmap_region_cmd +
2877 sizeof(struct asm_stream_cmd_memory_map_regions));
2878 mregions = (struct asm_memory_map_regions *)payload;
2879
2880 port = &ac->port[dir];
2881 for (i = 0; i < bufcnt; i++) {
2882 ab = &port->buf[i];
2883 mregions->phys = ab->phys;
2884 mregions->buf_size = ab->size;
2885 ++mregions;
2886 }
2887
2888 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) mmap_region_cmd);
2889 if (rc < 0) {
2890 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2891 mmap_regions->hdr.opcode, rc);
2892 rc = -EINVAL;
2893 goto fail_cmd;
2894 }
2895
2896 rc = wait_event_timeout(this_mmap.cmd_wait,
2897 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2898 if (!rc) {
2899 pr_err("timeout. waited for memory_map\n");
2900 rc = -EINVAL;
2901 goto fail_cmd;
2902 }
2903 rc = 0;
2904fail_cmd:
2905 kfree(mmap_region_cmd);
2906 return rc;
2907}
2908
2909static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir,
2910 uint32_t bufsz, uint32_t bufcnt)
2911{
2912 struct asm_stream_cmd_memory_unmap_regions *unmap_regions = NULL;
2913 struct asm_memory_unmap_regions *mregions = NULL;
2914 struct audio_port_data *port = NULL;
2915 struct audio_buffer *ab = NULL;
2916 void *unmap_region_cmd = NULL;
2917 void *payload = NULL;
2918 int rc = 0;
2919 int i = 0;
2920 int cmd_size = 0;
2921
2922 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2923 pr_err("APR handle NULL\n");
2924 return -EINVAL;
2925 }
2926 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2927
2928 cmd_size = sizeof(struct asm_stream_cmd_memory_unmap_regions) +
2929 sizeof(struct asm_memory_unmap_regions) * bufcnt;
2930
2931 unmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302932 if (unmap_region_cmd == NULL) {
2933 pr_err("%s: Mem alloc failed\n", __func__);
2934 rc = -EINVAL;
2935 return rc;
2936 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002937 unmap_regions = (struct asm_stream_cmd_memory_unmap_regions *)
2938 unmap_region_cmd;
2939 q6asm_add_mmaphdr(&unmap_regions->hdr, cmd_size, TRUE);
2940 unmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS;
2941 unmap_regions->nregions = bufcnt & 0x00ff;
2942 pr_debug("unmap_regions->nregions = %d\n", unmap_regions->nregions);
2943 payload = ((u8 *) unmap_region_cmd +
2944 sizeof(struct asm_stream_cmd_memory_unmap_regions));
2945 mregions = (struct asm_memory_unmap_regions *)payload;
2946 port = &ac->port[dir];
2947 for (i = 0; i < bufcnt; i++) {
2948 ab = &port->buf[i];
2949 mregions->phys = ab->phys;
2950 ++mregions;
2951 }
2952
2953 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) unmap_region_cmd);
2954 if (rc < 0) {
2955 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2956 unmap_regions->hdr.opcode, rc);
2957 goto fail_cmd;
2958 }
2959
2960 rc = wait_event_timeout(this_mmap.cmd_wait,
2961 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2962 if (!rc) {
2963 pr_err("timeout. waited for memory_unmap\n");
2964 goto fail_cmd;
2965 }
2966 rc = 0;
2967
2968fail_cmd:
2969 kfree(unmap_region_cmd);
2970 return rc;
2971}
2972
2973int q6asm_set_mute(struct audio_client *ac, int muteflag)
2974{
2975 void *vol_cmd = NULL;
2976 void *payload = NULL;
2977 struct asm_pp_params_command *cmd = NULL;
2978 struct asm_mute_params *mute = NULL;
2979 int sz = 0;
2980 int rc = 0;
2981
2982 sz = sizeof(struct asm_pp_params_command) +
2983 + sizeof(struct asm_mute_params);
2984 vol_cmd = kzalloc(sz, GFP_KERNEL);
2985 if (vol_cmd == NULL) {
2986 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2987 rc = -EINVAL;
2988 return rc;
2989 }
2990 cmd = (struct asm_pp_params_command *)vol_cmd;
2991 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2992 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2993 cmd->payload = NULL;
2994 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2995 sizeof(struct asm_mute_params);
2996 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2997 cmd->params.param_id = MUTE_CONFIG_PARAM_ID;
2998 cmd->params.param_size = sizeof(struct asm_mute_params);
2999 cmd->params.reserved = 0;
3000
3001 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3002 mute = (struct asm_mute_params *)payload;
3003
3004 mute->muteflag = muteflag;
3005 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3006 if (rc < 0) {
3007 pr_err("%s: Mute Command failed\n", __func__);
3008 rc = -EINVAL;
3009 goto fail_cmd;
3010 }
3011
3012 rc = wait_event_timeout(ac->cmd_wait,
3013 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3014 if (!rc) {
3015 pr_err("%s: timeout in sending mute command to apr\n",
3016 __func__);
3017 rc = -EINVAL;
3018 goto fail_cmd;
3019 }
3020 rc = 0;
3021fail_cmd:
3022 kfree(vol_cmd);
3023 return rc;
3024}
3025
3026int q6asm_set_volume(struct audio_client *ac, int volume)
3027{
3028 void *vol_cmd = NULL;
3029 void *payload = NULL;
3030 struct asm_pp_params_command *cmd = NULL;
3031 struct asm_master_gain_params *mgain = NULL;
3032 int sz = 0;
3033 int rc = 0;
3034
3035 sz = sizeof(struct asm_pp_params_command) +
3036 + sizeof(struct asm_master_gain_params);
3037 vol_cmd = kzalloc(sz, GFP_KERNEL);
3038 if (vol_cmd == NULL) {
3039 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3040 rc = -EINVAL;
3041 return rc;
3042 }
3043 cmd = (struct asm_pp_params_command *)vol_cmd;
3044 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3045 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3046 cmd->payload = NULL;
3047 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3048 sizeof(struct asm_master_gain_params);
3049 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3050 cmd->params.param_id = MASTER_GAIN_PARAM_ID;
3051 cmd->params.param_size = sizeof(struct asm_master_gain_params);
3052 cmd->params.reserved = 0;
3053
3054 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3055 mgain = (struct asm_master_gain_params *)payload;
3056
3057 mgain->master_gain = volume;
3058 mgain->padding = 0x00;
3059 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3060 if (rc < 0) {
3061 pr_err("%s: Volume Command failed\n", __func__);
3062 rc = -EINVAL;
3063 goto fail_cmd;
3064 }
3065
3066 rc = wait_event_timeout(ac->cmd_wait,
3067 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3068 if (!rc) {
3069 pr_err("%s: timeout in sending volume command to apr\n",
3070 __func__);
3071 rc = -EINVAL;
3072 goto fail_cmd;
3073 }
3074 rc = 0;
3075fail_cmd:
3076 kfree(vol_cmd);
3077 return rc;
3078}
3079
3080int q6asm_set_softpause(struct audio_client *ac,
3081 struct asm_softpause_params *pause_param)
3082{
3083 void *vol_cmd = NULL;
3084 void *payload = NULL;
3085 struct asm_pp_params_command *cmd = NULL;
3086 struct asm_softpause_params *params = NULL;
3087 int sz = 0;
3088 int rc = 0;
3089
3090 sz = sizeof(struct asm_pp_params_command) +
3091 + sizeof(struct asm_softpause_params);
3092 vol_cmd = kzalloc(sz, GFP_KERNEL);
3093 if (vol_cmd == NULL) {
3094 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3095 rc = -EINVAL;
3096 return rc;
3097 }
3098 cmd = (struct asm_pp_params_command *)vol_cmd;
3099 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3100 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3101 cmd->payload = NULL;
3102 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3103 sizeof(struct asm_softpause_params);
3104 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3105 cmd->params.param_id = SOFT_PAUSE_PARAM_ID;
3106 cmd->params.param_size = sizeof(struct asm_softpause_params);
3107 cmd->params.reserved = 0;
3108
3109 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3110 params = (struct asm_softpause_params *)payload;
3111
3112 params->enable = pause_param->enable;
3113 params->period = pause_param->period;
3114 params->step = pause_param->step;
3115 params->rampingcurve = pause_param->rampingcurve;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003116 pr_debug("%s: soft Pause Command: enable = %d, period = %d, step = %d, curve = %d\n",
3117 __func__, params->enable,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003118 params->period, params->step, params->rampingcurve);
3119 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3120 if (rc < 0) {
3121 pr_err("%s: Volume Command(soft_pause) failed\n", __func__);
3122 rc = -EINVAL;
3123 goto fail_cmd;
3124 }
3125
3126 rc = wait_event_timeout(ac->cmd_wait,
3127 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3128 if (!rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003129 pr_err("%s: timeout in sending volume command(soft_pause) to apr\n",
3130 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003131 rc = -EINVAL;
3132 goto fail_cmd;
3133 }
3134 rc = 0;
3135fail_cmd:
3136 kfree(vol_cmd);
3137 return rc;
3138}
3139
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003140int q6asm_set_softvolume(struct audio_client *ac,
3141 struct asm_softvolume_params *softvol_param)
3142{
3143 void *vol_cmd = NULL;
3144 void *payload = NULL;
3145 struct asm_pp_params_command *cmd = NULL;
3146 struct asm_softvolume_params *params = NULL;
3147 int sz = 0;
3148 int rc = 0;
3149
3150 sz = sizeof(struct asm_pp_params_command) +
3151 + sizeof(struct asm_softvolume_params);
3152 vol_cmd = kzalloc(sz, GFP_KERNEL);
3153 if (vol_cmd == NULL) {
3154 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3155 rc = -EINVAL;
3156 return rc;
3157 }
3158 cmd = (struct asm_pp_params_command *)vol_cmd;
3159 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3160 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3161 cmd->payload = NULL;
3162 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3163 sizeof(struct asm_softvolume_params);
3164 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3165 cmd->params.param_id = SOFT_VOLUME_PARAM_ID;
3166 cmd->params.param_size = sizeof(struct asm_softvolume_params);
3167 cmd->params.reserved = 0;
3168
3169 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3170 params = (struct asm_softvolume_params *)payload;
3171
3172 params->period = softvol_param->period;
3173 params->step = softvol_param->step;
3174 params->rampingcurve = softvol_param->rampingcurve;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003175 pr_debug("%s: soft Volume:opcode = %d,payload_sz =%d,module_id =%d, param_id = %d, param_sz = %d\n",
3176 __func__,
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003177 cmd->hdr.opcode, cmd->payload_size,
3178 cmd->params.module_id, cmd->params.param_id,
3179 cmd->params.param_size);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003180 pr_debug("%s: soft Volume Command: period = %d, step = %d, curve = %d\n",
3181 __func__, params->period,
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003182 params->step, params->rampingcurve);
3183 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3184 if (rc < 0) {
3185 pr_err("%s: Volume Command(soft_volume) failed\n", __func__);
3186 rc = -EINVAL;
3187 goto fail_cmd;
3188 }
3189
3190 rc = wait_event_timeout(ac->cmd_wait,
3191 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3192 if (!rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003193 pr_err("%s: timeout in sending volume command(soft_volume) to apr\n",
3194 __func__);
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003195 rc = -EINVAL;
3196 goto fail_cmd;
3197 }
3198 rc = 0;
3199fail_cmd:
3200 kfree(vol_cmd);
3201 return rc;
3202}
3203
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003204int q6asm_equalizer(struct audio_client *ac, void *eq)
3205{
3206 void *eq_cmd = NULL;
3207 void *payload = NULL;
3208 struct asm_pp_params_command *cmd = NULL;
3209 struct asm_equalizer_params *equalizer = NULL;
3210 struct msm_audio_eq_stream_config *eq_params = NULL;
3211 int i = 0;
3212 int sz = 0;
3213 int rc = 0;
3214
3215 sz = sizeof(struct asm_pp_params_command) +
3216 + sizeof(struct asm_equalizer_params);
3217 eq_cmd = kzalloc(sz, GFP_KERNEL);
3218 if (eq_cmd == NULL) {
3219 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3220 rc = -EINVAL;
3221 goto fail_cmd;
3222 }
3223 eq_params = (struct msm_audio_eq_stream_config *) eq;
3224 cmd = (struct asm_pp_params_command *)eq_cmd;
3225 q6asm_add_hdr(ac, &cmd->hdr, sz, TRUE);
3226 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3227 cmd->payload = NULL;
3228 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3229 sizeof(struct asm_equalizer_params);
3230 cmd->params.module_id = EQUALIZER_MODULE_ID;
3231 cmd->params.param_id = EQUALIZER_PARAM_ID;
3232 cmd->params.param_size = sizeof(struct asm_equalizer_params);
3233 cmd->params.reserved = 0;
3234 payload = (u8 *)(eq_cmd + sizeof(struct asm_pp_params_command));
3235 equalizer = (struct asm_equalizer_params *)payload;
3236
3237 equalizer->enable = eq_params->enable;
3238 equalizer->num_bands = eq_params->num_bands;
3239 pr_debug("%s: enable:%d numbands:%d\n", __func__, eq_params->enable,
3240 eq_params->num_bands);
3241 for (i = 0; i < eq_params->num_bands; i++) {
3242 equalizer->eq_bands[i].band_idx =
3243 eq_params->eq_bands[i].band_idx;
3244 equalizer->eq_bands[i].filter_type =
3245 eq_params->eq_bands[i].filter_type;
3246 equalizer->eq_bands[i].center_freq_hz =
3247 eq_params->eq_bands[i].center_freq_hz;
3248 equalizer->eq_bands[i].filter_gain =
3249 eq_params->eq_bands[i].filter_gain;
3250 equalizer->eq_bands[i].q_factor =
3251 eq_params->eq_bands[i].q_factor;
3252 pr_debug("%s: filter_type:%u bandnum:%d\n", __func__,
3253 eq_params->eq_bands[i].filter_type, i);
3254 pr_debug("%s: center_freq_hz:%u bandnum:%d\n", __func__,
3255 eq_params->eq_bands[i].center_freq_hz, i);
3256 pr_debug("%s: filter_gain:%d bandnum:%d\n", __func__,
3257 eq_params->eq_bands[i].filter_gain, i);
3258 pr_debug("%s: q_factor:%d bandnum:%d\n", __func__,
3259 eq_params->eq_bands[i].q_factor, i);
3260 }
3261 rc = apr_send_pkt(ac->apr, (uint32_t *) eq_cmd);
3262 if (rc < 0) {
3263 pr_err("%s: Equalizer Command failed\n", __func__);
3264 rc = -EINVAL;
3265 goto fail_cmd;
3266 }
3267
3268 rc = wait_event_timeout(ac->cmd_wait,
3269 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3270 if (!rc) {
3271 pr_err("%s: timeout in sending equalizer command to apr\n",
3272 __func__);
3273 rc = -EINVAL;
3274 goto fail_cmd;
3275 }
3276 rc = 0;
3277fail_cmd:
3278 kfree(eq_cmd);
3279 return rc;
3280}
3281
3282int q6asm_read(struct audio_client *ac)
3283{
3284 struct asm_stream_cmd_read read;
3285 struct audio_buffer *ab;
3286 int dsp_buf;
3287 struct audio_port_data *port;
3288 int rc;
3289 if (!ac || ac->apr == NULL) {
3290 pr_err("APR handle NULL\n");
3291 return -EINVAL;
3292 }
3293 if (ac->io_mode == SYNC_IO_MODE) {
3294 port = &ac->port[OUT];
3295
3296 q6asm_add_hdr(ac, &read.hdr, sizeof(read), FALSE);
3297
3298 mutex_lock(&port->lock);
3299
3300 dsp_buf = port->dsp_buf;
3301 ab = &port->buf[dsp_buf];
3302
3303 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
3304 __func__,
3305 ac->session,
3306 dsp_buf,
3307 (void *)port->buf[dsp_buf].data,
3308 port->cpu_buf,
3309 (void *)port->buf[port->cpu_buf].phys);
3310
3311 read.hdr.opcode = ASM_DATA_CMD_READ;
3312 read.buf_add = ab->phys;
3313 read.buf_size = ab->size;
3314 read.uid = port->dsp_buf;
3315 read.hdr.token = port->dsp_buf;
3316
3317 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3318 mutex_unlock(&port->lock);
3319 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
3320 read.buf_add,
3321 read.hdr.token,
3322 read.uid);
3323 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3324 if (rc < 0) {
3325 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
3326 goto fail_cmd;
3327 }
3328 return 0;
3329 }
3330fail_cmd:
3331 return -EINVAL;
3332}
3333
3334int q6asm_read_nolock(struct audio_client *ac)
3335{
3336 struct asm_stream_cmd_read read;
3337 struct audio_buffer *ab;
3338 int dsp_buf;
3339 struct audio_port_data *port;
3340 int rc;
3341 if (!ac || ac->apr == NULL) {
3342 pr_err("APR handle NULL\n");
3343 return -EINVAL;
3344 }
3345 if (ac->io_mode == SYNC_IO_MODE) {
3346 port = &ac->port[OUT];
3347
3348 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3349
3350
3351 dsp_buf = port->dsp_buf;
3352 ab = &port->buf[dsp_buf];
3353
3354 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
3355 __func__,
3356 ac->session,
3357 dsp_buf,
3358 (void *)port->buf[dsp_buf].data,
3359 port->cpu_buf,
3360 (void *)port->buf[port->cpu_buf].phys);
3361
3362 read.hdr.opcode = ASM_DATA_CMD_READ;
3363 read.buf_add = ab->phys;
3364 read.buf_size = ab->size;
3365 read.uid = port->dsp_buf;
3366 read.hdr.token = port->dsp_buf;
3367
3368 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3369 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
3370 read.buf_add,
3371 read.hdr.token,
3372 read.uid);
3373 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3374 if (rc < 0) {
3375 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
3376 goto fail_cmd;
3377 }
3378 return 0;
3379 }
3380fail_cmd:
3381 return -EINVAL;
3382}
3383
3384
3385static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
3386 uint32_t pkt_size, uint32_t cmd_flg)
3387{
3388 pr_debug("session=%d pkt size=%d cmd_flg=%d\n", pkt_size, cmd_flg,
3389 ac->session);
3390 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
3391 APR_HDR_LEN(sizeof(struct apr_hdr)),\
3392 APR_PKT_VER);
3393 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
3394 hdr->src_domain = APR_DOMAIN_APPS;
3395 hdr->dest_svc = APR_SVC_ASM;
3396 hdr->dest_domain = APR_DOMAIN_ADSP;
3397 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
3398 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
3399 if (cmd_flg) {
3400 hdr->token = ac->session;
3401 atomic_set(&ac->cmd_state, 1);
3402 }
3403 hdr->pkt_size = pkt_size;
3404 return;
3405}
3406
3407int q6asm_async_write(struct audio_client *ac,
3408 struct audio_aio_write_param *param)
3409{
3410 int rc = 0;
3411 struct asm_stream_cmd_write write;
3412
3413 if (!ac || ac->apr == NULL) {
3414 pr_err("%s: APR handle NULL\n", __func__);
3415 return -EINVAL;
3416 }
3417
3418 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write), FALSE);
3419
3420 /* Pass physical address as token for AIO scheme */
3421 write.hdr.token = param->uid;
3422 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3423 write.buf_add = param->paddr;
3424 write.avail_bytes = param->len;
3425 write.uid = param->uid;
3426 write.msw_ts = param->msw_ts;
3427 write.lsw_ts = param->lsw_ts;
3428 /* Use 0xFF00 for disabling timestamps */
3429 if (param->flags == 0xFF00)
3430 write.uflags = (0x00000000 | (param->flags & 0x800000FF));
3431 else
3432 write.uflags = (0x80000000 | param->flags);
3433
3434 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3435 write.buf_add, write.avail_bytes);
3436
3437 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3438 if (rc < 0) {
3439 pr_debug("[%s] write op[0x%x]rc[%d]\n", __func__,
3440 write.hdr.opcode, rc);
3441 goto fail_cmd;
3442 }
3443 return 0;
3444fail_cmd:
3445 return -EINVAL;
3446}
3447
3448int q6asm_async_read(struct audio_client *ac,
3449 struct audio_aio_read_param *param)
3450{
3451 int rc = 0;
3452 struct asm_stream_cmd_read read;
3453
3454 if (!ac || ac->apr == NULL) {
3455 pr_err("%s: APR handle NULL\n", __func__);
3456 return -EINVAL;
3457 }
3458
3459 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3460
3461 /* Pass physical address as token for AIO scheme */
3462 read.hdr.token = param->paddr;
3463 read.hdr.opcode = ASM_DATA_CMD_READ;
3464 read.buf_add = param->paddr;
3465 read.buf_size = param->len;
3466 read.uid = param->uid;
3467
3468 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3469 read.buf_add, read.buf_size);
3470
3471 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3472 if (rc < 0) {
3473 pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
3474 read.hdr.opcode, rc);
3475 goto fail_cmd;
3476 }
3477 return 0;
3478fail_cmd:
3479 return -EINVAL;
3480}
3481
Subhash Chandra Bose Naripeddy694b7d92012-06-20 20:46:13 -07003482int q6asm_async_read_compressed(struct audio_client *ac,
3483 struct audio_aio_read_param *param)
3484{
3485 int rc = 0;
3486 struct asm_stream_cmd_read read;
3487
3488 if (!ac || ac->apr == NULL) {
3489 pr_err("%s: APR handle NULL\n", __func__);
3490 return -EINVAL;
3491 }
3492
3493 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3494
3495 /* Pass physical address as token for AIO scheme */
3496 read.hdr.token = param->paddr;
3497 read.hdr.opcode = ASM_DATA_CMD_READ_COMPRESSED;
3498 read.buf_add = param->paddr;
3499 read.buf_size = param->len;
3500 read.uid = param->uid;
3501
3502 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3503 read.buf_add, read.buf_size);
3504
3505 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3506 if (rc < 0) {
3507 pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
3508 read.hdr.opcode, rc);
3509 goto fail_cmd;
3510 }
3511 return 0;
3512fail_cmd:
3513 return -EINVAL;
3514}
3515
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003516int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3517 uint32_t lsw_ts, uint32_t flags)
3518{
3519 int rc = 0;
3520 struct asm_stream_cmd_write write;
3521 struct audio_port_data *port;
3522 struct audio_buffer *ab;
3523 int dsp_buf = 0;
3524
3525 if (!ac || ac->apr == NULL) {
3526 pr_err("APR handle NULL\n");
3527 return -EINVAL;
3528 }
3529 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3530 if (ac->io_mode == SYNC_IO_MODE) {
3531 port = &ac->port[IN];
3532
3533 q6asm_add_hdr(ac, &write.hdr, sizeof(write),
3534 FALSE);
3535 mutex_lock(&port->lock);
3536
3537 dsp_buf = port->dsp_buf;
3538 ab = &port->buf[dsp_buf];
3539
3540 write.hdr.token = port->dsp_buf;
3541 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3542 write.buf_add = ab->phys;
3543 write.avail_bytes = len;
3544 write.uid = port->dsp_buf;
3545 write.msw_ts = msw_ts;
3546 write.lsw_ts = lsw_ts;
3547 /* Use 0xFF00 for disabling timestamps */
3548 if (flags == 0xFF00)
3549 write.uflags = (0x00000000 | (flags & 0x800000FF));
3550 else
3551 write.uflags = (0x80000000 | flags);
3552 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3553
3554 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3555 , __func__,
3556 ab->phys,
3557 write.buf_add,
3558 write.hdr.token,
3559 write.uid);
3560 mutex_unlock(&port->lock);
Rajesha Kini3498c932011-07-19 19:58:27 +05303561#ifdef CONFIG_DEBUG_FS
3562 if (out_enable_flag) {
3563 char zero_pattern[2] = {0x00, 0x00};
3564 /* If First two byte is non zero and last two byte
3565 is zero then it is warm output pattern */
3566 if ((strncmp(((char *)ab->data), zero_pattern, 2)) &&
3567 (!strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3568 do_gettimeofday(&out_warm_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003569 pr_debug("WARM:apr_send_pkt at %ld sec %ld microsec\n",
3570 out_warm_tv.tv_sec,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303571 out_warm_tv.tv_usec);
3572 pr_debug("Warm Pattern Matched");
3573 }
3574 /* If First two byte is zero and last two byte is
3575 non zero then it is cont ouput pattern */
3576 else if ((!strncmp(((char *)ab->data), zero_pattern, 2))
3577 && (strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3578 do_gettimeofday(&out_cont_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003579 pr_debug("CONT:apr_send_pkt at %ld sec %ld microsec\n",
3580 out_cont_tv.tv_sec,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303581 out_cont_tv.tv_usec);
3582 pr_debug("Cont Pattern Matched");
3583 }
3584 }
3585#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003586 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3587 if (rc < 0) {
3588 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3589 goto fail_cmd;
3590 }
3591 pr_debug("%s: WRITE SUCCESS\n", __func__);
3592 return 0;
3593 }
3594fail_cmd:
3595 return -EINVAL;
3596}
3597
3598int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3599 uint32_t lsw_ts, uint32_t flags)
3600{
3601 int rc = 0;
3602 struct asm_stream_cmd_write write;
3603 struct audio_port_data *port;
3604 struct audio_buffer *ab;
3605 int dsp_buf = 0;
3606
3607 if (!ac || ac->apr == NULL) {
3608 pr_err("APR handle NULL\n");
3609 return -EINVAL;
3610 }
3611 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3612 if (ac->io_mode == SYNC_IO_MODE) {
3613 port = &ac->port[IN];
3614
3615 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write),
3616 FALSE);
3617
3618 dsp_buf = port->dsp_buf;
3619 ab = &port->buf[dsp_buf];
3620
3621 write.hdr.token = port->dsp_buf;
3622 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3623 write.buf_add = ab->phys;
3624 write.avail_bytes = len;
3625 write.uid = port->dsp_buf;
3626 write.msw_ts = msw_ts;
3627 write.lsw_ts = lsw_ts;
3628 /* Use 0xFF00 for disabling timestamps */
3629 if (flags == 0xFF00)
3630 write.uflags = (0x00000000 | (flags & 0x800000FF));
3631 else
3632 write.uflags = (0x80000000 | flags);
3633 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3634
3635 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3636 , __func__,
3637 ab->phys,
3638 write.buf_add,
3639 write.hdr.token,
3640 write.uid);
3641
3642 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3643 if (rc < 0) {
3644 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3645 goto fail_cmd;
3646 }
3647 pr_debug("%s: WRITE SUCCESS\n", __func__);
3648 return 0;
3649 }
3650fail_cmd:
3651 return -EINVAL;
3652}
3653
3654uint64_t q6asm_get_session_time(struct audio_client *ac)
3655{
3656 struct apr_hdr hdr;
3657 int rc;
3658
3659 if (!ac || ac->apr == NULL) {
3660 pr_err("APR handle NULL\n");
3661 return -EINVAL;
3662 }
Swaminathan Sathappanc7f98992012-07-09 11:07:12 -07003663 q6asm_add_hdr(ac, &hdr, sizeof(hdr), FALSE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003664 hdr.opcode = ASM_SESSION_CMD_GET_SESSION_TIME;
3665 atomic_set(&ac->time_flag, 1);
3666
3667 pr_debug("%s: session[%d]opcode[0x%x]\n", __func__,
3668 ac->session,
3669 hdr.opcode);
3670 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3671 if (rc < 0) {
3672 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3673 goto fail_cmd;
3674 }
3675 rc = wait_event_timeout(ac->time_wait,
3676 (atomic_read(&ac->time_flag) == 0), 5*HZ);
3677 if (!rc) {
3678 pr_err("%s: timeout in getting session time from DSP\n",
3679 __func__);
3680 goto fail_cmd;
3681 }
3682 return ac->time_stamp;
3683
3684fail_cmd:
3685 return -EINVAL;
3686}
3687
3688int q6asm_cmd(struct audio_client *ac, int cmd)
3689{
3690 struct apr_hdr hdr;
3691 int rc;
3692 atomic_t *state;
3693 int cnt = 0;
3694
3695 if (!ac || ac->apr == NULL) {
3696 pr_err("APR handle NULL\n");
3697 return -EINVAL;
3698 }
3699 q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
3700 switch (cmd) {
3701 case CMD_PAUSE:
3702 pr_debug("%s:CMD_PAUSE\n", __func__);
3703 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3704 state = &ac->cmd_state;
3705 break;
3706 case CMD_FLUSH:
3707 pr_debug("%s:CMD_FLUSH\n", __func__);
3708 hdr.opcode = ASM_STREAM_CMD_FLUSH;
3709 state = &ac->cmd_state;
3710 break;
3711 case CMD_OUT_FLUSH:
3712 pr_debug("%s:CMD_OUT_FLUSH\n", __func__);
3713 hdr.opcode = ASM_STREAM_CMD_FLUSH_READBUFS;
3714 state = &ac->cmd_state;
3715 break;
3716 case CMD_EOS:
3717 pr_debug("%s:CMD_EOS\n", __func__);
3718 hdr.opcode = ASM_DATA_CMD_EOS;
3719 atomic_set(&ac->cmd_state, 0);
3720 state = &ac->cmd_state;
3721 break;
3722 case CMD_CLOSE:
3723 pr_debug("%s:CMD_CLOSE\n", __func__);
3724 hdr.opcode = ASM_STREAM_CMD_CLOSE;
3725 state = &ac->cmd_state;
3726 break;
3727 default:
3728 pr_err("Invalid format[%d]\n", cmd);
3729 goto fail_cmd;
3730 }
3731 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3732 ac->session,
3733 hdr.opcode);
3734 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3735 if (rc < 0) {
3736 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3737 goto fail_cmd;
3738 }
3739 rc = wait_event_timeout(ac->cmd_wait, (atomic_read(state) == 0), 5*HZ);
3740 if (!rc) {
3741 pr_err("timeout. waited for response opcode[0x%x]\n",
3742 hdr.opcode);
3743 goto fail_cmd;
3744 }
3745 if (cmd == CMD_FLUSH)
3746 q6asm_reset_buf_state(ac);
3747 if (cmd == CMD_CLOSE) {
3748 /* check if DSP return all buffers */
3749 if (ac->port[IN].buf) {
3750 for (cnt = 0; cnt < ac->port[IN].max_buf_cnt;
3751 cnt++) {
3752 if (ac->port[IN].buf[cnt].used == IN) {
3753 pr_debug("Write Buf[%d] not returned\n",
3754 cnt);
3755 }
3756 }
3757 }
3758 if (ac->port[OUT].buf) {
3759 for (cnt = 0; cnt < ac->port[OUT].max_buf_cnt; cnt++) {
3760 if (ac->port[OUT].buf[cnt].used == OUT) {
3761 pr_debug("Read Buf[%d] not returned\n",
3762 cnt);
3763 }
3764 }
3765 }
3766 }
3767 return 0;
3768fail_cmd:
3769 return -EINVAL;
3770}
3771
3772int q6asm_cmd_nowait(struct audio_client *ac, int cmd)
3773{
3774 struct apr_hdr hdr;
3775 int rc;
3776
3777 if (!ac || ac->apr == NULL) {
3778 pr_err("%s:APR handle NULL\n", __func__);
3779 return -EINVAL;
3780 }
3781 q6asm_add_hdr_async(ac, &hdr, sizeof(hdr), TRUE);
3782 switch (cmd) {
3783 case CMD_PAUSE:
3784 pr_debug("%s:CMD_PAUSE\n", __func__);
3785 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3786 break;
3787 case CMD_EOS:
3788 pr_debug("%s:CMD_EOS\n", __func__);
3789 hdr.opcode = ASM_DATA_CMD_EOS;
3790 break;
3791 default:
3792 pr_err("%s:Invalid format[%d]\n", __func__, cmd);
3793 goto fail_cmd;
3794 }
3795 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3796 ac->session,
3797 hdr.opcode);
Jay Wang0668d1062012-07-11 18:53:21 -07003798
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003799 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3800 if (rc < 0) {
3801 pr_err("%s:Commmand 0x%x failed\n", __func__, hdr.opcode);
3802 goto fail_cmd;
3803 }
Jay Wang0668d1062012-07-11 18:53:21 -07003804 atomic_inc(&ac->nowait_cmd_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003805 return 0;
3806fail_cmd:
3807 return -EINVAL;
3808}
3809
3810static void q6asm_reset_buf_state(struct audio_client *ac)
3811{
3812 int cnt = 0;
3813 int loopcnt = 0;
3814 struct audio_port_data *port = NULL;
3815
3816 if (ac->io_mode == SYNC_IO_MODE) {
3817 mutex_lock(&ac->cmd_lock);
3818 for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
3819 port = &ac->port[loopcnt];
3820 cnt = port->max_buf_cnt - 1;
3821 port->dsp_buf = 0;
3822 port->cpu_buf = 0;
3823 while (cnt >= 0) {
3824 if (!port->buf)
3825 continue;
3826 port->buf[cnt].used = 1;
3827 cnt--;
3828 }
3829 }
3830 mutex_unlock(&ac->cmd_lock);
3831 }
3832}
3833
3834int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable)
3835{
3836 struct asm_stream_cmd_reg_tx_overflow_event tx_overflow;
3837 int rc;
3838
3839 if (!ac || ac->apr == NULL) {
3840 pr_err("APR handle NULL\n");
3841 return -EINVAL;
3842 }
3843 pr_debug("%s:session[%d]enable[%d]\n", __func__,
3844 ac->session, enable);
3845 q6asm_add_hdr(ac, &tx_overflow.hdr, sizeof(tx_overflow), TRUE);
3846
3847 tx_overflow.hdr.opcode = \
3848 ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS;
3849 /* tx overflow event: enable */
3850 tx_overflow.enable = enable;
3851
3852 rc = apr_send_pkt(ac->apr, (uint32_t *) &tx_overflow);
3853 if (rc < 0) {
3854 pr_err("tx overflow op[0x%x]rc[%d]\n", \
3855 tx_overflow.hdr.opcode, rc);
3856 goto fail_cmd;
3857 }
3858 rc = wait_event_timeout(ac->cmd_wait,
3859 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3860 if (!rc) {
3861 pr_err("timeout. waited for tx overflow\n");
3862 goto fail_cmd;
3863 }
3864 return 0;
3865fail_cmd:
3866 return -EINVAL;
3867}
3868
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003869int q6asm_get_apr_service_id(int session_id)
3870{
3871 pr_debug("%s\n", __func__);
3872
Shiv Maliyappanahallia84982a2012-01-19 15:25:04 -08003873 if (session_id < 0 || session_id > SESSION_MAX) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003874 pr_err("%s: invalid session_id = %d\n", __func__, session_id);
3875 return -EINVAL;
3876 }
3877
3878 return ((struct apr_svc *)session[session_id]->apr)->id;
3879}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003880
3881
3882static int __init q6asm_init(void)
3883{
3884 pr_debug("%s\n", __func__);
3885 init_waitqueue_head(&this_mmap.cmd_wait);
3886 memset(session, 0, sizeof(session));
Rajesha Kini3498c932011-07-19 19:58:27 +05303887#ifdef CONFIG_DEBUG_FS
3888 out_buffer = kmalloc(OUT_BUFFER_SIZE, GFP_KERNEL);
3889 out_dentry = debugfs_create_file("audio_out_latency_measurement_node",\
Glenn Kasten5dfda802012-10-04 16:40:27 -07003890 0664,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303891 NULL, NULL, &audio_output_latency_debug_fops);
3892 if (IS_ERR(out_dentry))
3893 pr_err("debugfs_create_file failed\n");
3894 in_buffer = kmalloc(IN_BUFFER_SIZE, GFP_KERNEL);
3895 in_dentry = debugfs_create_file("audio_in_latency_measurement_node",\
Glenn Kasten5dfda802012-10-04 16:40:27 -07003896 0664,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303897 NULL, NULL, &audio_input_latency_debug_fops);
3898 if (IS_ERR(in_dentry))
3899 pr_err("debugfs_create_file failed\n");
3900#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003901 return 0;
3902}
3903
3904device_initcall(q6asm_init);