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