blob: 9b8a4bdaf3e29ac982780b407986454bc9de82c6 [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 Naripeddy68d103a2012-08-17 21:03:19 -07001901 if (channels == 1) {
1902 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1903 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = 0;
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 == 2) {
Subhash Chandra Bose Naripeddy8477d222012-06-12 00:30:54 -07001911 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] = 0;
1914 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = 0;
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 == 4) {
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_RB;
1923 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_LB;
1924 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1925 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
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 == 6) {
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] = 0;
1936 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1937 } else if (channels == 8) {
1938 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1939 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1940 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_LFE;
1941 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_FC;
1942 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = PCM_CHANNEL_LB;
1943 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = PCM_CHANNEL_RB;
1944 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = PCM_CHANNEL_FLC;
1945 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = PCM_CHANNEL_FRC;
1946 }
Mingming Yin647e9ea2012-03-17 19:56:10 -07001947
1948 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1949 if (rc < 0) {
1950 pr_err("Comamnd open failed\n");
1951 rc = -EINVAL;
1952 goto fail_cmd;
1953 }
1954 rc = wait_event_timeout(ac->cmd_wait,
1955 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1956 if (!rc) {
1957 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1958 goto fail_cmd;
1959 }
1960 return 0;
1961fail_cmd:
1962 return -EINVAL;
1963}
1964
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001965int q6asm_enable_sbrps(struct audio_client *ac,
1966 uint32_t sbr_ps_enable)
1967{
1968 struct asm_stream_cmd_encdec_sbr sbrps;
1969
1970 int rc = 0;
1971
1972 pr_debug("%s: Session %d\n", __func__, ac->session);
1973
1974 q6asm_add_hdr(ac, &sbrps.hdr, sizeof(sbrps), TRUE);
1975
1976 sbrps.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1977 sbrps.param_id = ASM_ENABLE_SBR_PS;
1978 sbrps.param_size = sizeof(struct asm_sbr_ps);
1979 sbrps.sbr_ps.enable = sbr_ps_enable;
1980
1981 rc = apr_send_pkt(ac->apr, (uint32_t *) &sbrps);
1982 if (rc < 0) {
1983 pr_err("Command opcode[0x%x]paramid[0x%x] failed\n",
1984 ASM_STREAM_CMD_SET_ENCDEC_PARAM,
1985 ASM_ENABLE_SBR_PS);
1986 rc = -EINVAL;
1987 goto fail_cmd;
1988 }
1989 rc = wait_event_timeout(ac->cmd_wait,
1990 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1991 if (!rc) {
1992 pr_err("timeout opcode[0x%x] ", sbrps.hdr.opcode);
1993 goto fail_cmd;
1994 }
1995 return 0;
1996fail_cmd:
1997 return -EINVAL;
1998}
1999
Swaminathan Sathappan70765cd2011-07-19 18:42:47 -07002000int q6asm_cfg_dual_mono_aac(struct audio_client *ac,
2001 uint16_t sce_left, uint16_t sce_right)
2002{
2003 struct asm_stream_cmd_encdec_dualmono dual_mono;
2004
2005 int rc = 0;
2006
2007 pr_debug("%s: Session %d, sce_left = %d, sce_right = %d\n",
2008 __func__, ac->session, sce_left, sce_right);
2009
2010 q6asm_add_hdr(ac, &dual_mono.hdr, sizeof(dual_mono), TRUE);
2011
2012 dual_mono.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2013 dual_mono.param_id = ASM_CONFIGURE_DUAL_MONO;
2014 dual_mono.param_size = sizeof(struct asm_dual_mono);
2015 dual_mono.channel_map.sce_left = sce_left;
2016 dual_mono.channel_map.sce_right = sce_right;
2017
2018 rc = apr_send_pkt(ac->apr, (uint32_t *) &dual_mono);
2019 if (rc < 0) {
2020 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
2021 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
2022 ASM_CONFIGURE_DUAL_MONO);
2023 rc = -EINVAL;
2024 goto fail_cmd;
2025 }
2026 rc = wait_event_timeout(ac->cmd_wait,
2027 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2028 if (!rc) {
2029 pr_err("%s:timeout opcode[0x%x]\n", __func__,
2030 dual_mono.hdr.opcode);
2031 goto fail_cmd;
2032 }
2033 return 0;
2034fail_cmd:
2035 return -EINVAL;
2036}
2037
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07002038int q6asm_set_encdec_chan_map(struct audio_client *ac,
2039 uint32_t num_channels)
2040{
2041 struct asm_stream_cmd_encdec_channelmap chan_map;
2042 u8 *channel_mapping;
2043
2044 int rc = 0;
2045
2046 pr_debug("%s: Session %d, num_channels = %d\n",
2047 __func__, ac->session, num_channels);
2048
2049 q6asm_add_hdr(ac, &chan_map.hdr, sizeof(chan_map), TRUE);
2050
2051 chan_map.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2052 chan_map.param_id = ASM_ENCDEC_DEC_CHAN_MAP;
2053 chan_map.param_size = sizeof(struct asm_dec_chan_map);
2054 chan_map.chan_map.num_channels = num_channels;
2055
2056 channel_mapping =
2057 chan_map.chan_map.channel_mapping;
2058
2059 memset(channel_mapping, PCM_CHANNEL_NULL, MAX_CHAN_MAP_CHANNELS);
2060 if (num_channels == 1) {
2061 channel_mapping[0] = PCM_CHANNEL_FL;
2062 } else if (num_channels == 2) {
2063 channel_mapping[0] = PCM_CHANNEL_FL;
2064 channel_mapping[1] = PCM_CHANNEL_FR;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002065 } else if (num_channels == 4) {
2066 channel_mapping[0] = PCM_CHANNEL_FL;
2067 channel_mapping[1] = PCM_CHANNEL_FR;
2068 channel_mapping[1] = PCM_CHANNEL_LB;
2069 channel_mapping[1] = PCM_CHANNEL_RB;
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07002070 } else if (num_channels == 6) {
2071 channel_mapping[0] = PCM_CHANNEL_FC;
2072 channel_mapping[1] = PCM_CHANNEL_FL;
2073 channel_mapping[2] = PCM_CHANNEL_FR;
2074 channel_mapping[3] = PCM_CHANNEL_LB;
2075 channel_mapping[4] = PCM_CHANNEL_RB;
2076 channel_mapping[5] = PCM_CHANNEL_LFE;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002077 } else if (num_channels == 8) {
2078 channel_mapping[0] = PCM_CHANNEL_FC;
2079 channel_mapping[1] = PCM_CHANNEL_FL;
2080 channel_mapping[2] = PCM_CHANNEL_FR;
2081 channel_mapping[3] = PCM_CHANNEL_LB;
2082 channel_mapping[4] = PCM_CHANNEL_RB;
2083 channel_mapping[5] = PCM_CHANNEL_LFE;
2084 channel_mapping[6] = PCM_CHANNEL_FLC;
2085 channel_mapping[7] = PCM_CHANNEL_FRC;
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07002086 } else {
2087 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
2088 num_channels);
2089 rc = -EINVAL;
2090 goto fail_cmd;
2091 }
2092
2093 rc = apr_send_pkt(ac->apr, (uint32_t *) &chan_map);
2094 if (rc < 0) {
2095 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
2096 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
2097 ASM_ENCDEC_DEC_CHAN_MAP);
2098 goto fail_cmd;
2099 }
2100 rc = wait_event_timeout(ac->cmd_wait,
2101 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2102 if (!rc) {
2103 pr_err("%s:timeout opcode[0x%x]\n", __func__,
2104 chan_map.hdr.opcode);
2105 rc = -ETIMEDOUT;
2106 goto fail_cmd;
2107 }
2108 return 0;
2109fail_cmd:
2110 return rc;
2111}
2112
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002113int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf,
2114 uint16_t min_rate, uint16_t max_rate,
2115 uint16_t reduced_rate_level, uint16_t rate_modulation_cmd)
2116{
2117 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2118 int rc = 0;
2119
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002120 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]",
2121 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002122 ac->session, frames_per_buf, min_rate, max_rate,
2123 reduced_rate_level, rate_modulation_cmd);
2124
2125 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2126
2127 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2128
2129 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2130 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2131
2132 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2133 enc_cfg.enc_blk.format_id = V13K_FS;
2134 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_qcelp13_read_cfg);
2135 enc_cfg.enc_blk.cfg.qcelp13.min_rate = min_rate;
2136 enc_cfg.enc_blk.cfg.qcelp13.max_rate = max_rate;
2137 enc_cfg.enc_blk.cfg.qcelp13.reduced_rate_level = reduced_rate_level;
2138 enc_cfg.enc_blk.cfg.qcelp13.rate_modulation_cmd = rate_modulation_cmd;
2139
2140 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2141 if (rc < 0) {
2142 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2143 goto fail_cmd;
2144 }
2145 rc = wait_event_timeout(ac->cmd_wait,
2146 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2147 if (!rc) {
2148 pr_err("timeout. waited for FORMAT_UPDATE\n");
2149 goto fail_cmd;
2150 }
2151 return 0;
2152fail_cmd:
2153 return -EINVAL;
2154}
2155
2156int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf,
2157 uint16_t min_rate, uint16_t max_rate,
2158 uint16_t rate_modulation_cmd)
2159{
2160 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2161 int rc = 0;
2162
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002163 pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] rate_modulation_cmd[0x%4x]",
2164 __func__, ac->session,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002165 frames_per_buf, min_rate, max_rate, rate_modulation_cmd);
2166
2167 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2168
2169 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2170
2171 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2172 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2173
2174 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2175 enc_cfg.enc_blk.format_id = EVRC_FS;
2176 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_evrc_read_cfg);
2177 enc_cfg.enc_blk.cfg.evrc.min_rate = min_rate;
2178 enc_cfg.enc_blk.cfg.evrc.max_rate = max_rate;
2179 enc_cfg.enc_blk.cfg.evrc.rate_modulation_cmd = rate_modulation_cmd;
2180 enc_cfg.enc_blk.cfg.evrc.reserved = 0;
2181
2182 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2183 if (rc < 0) {
2184 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2185 goto fail_cmd;
2186 }
2187 rc = wait_event_timeout(ac->cmd_wait,
2188 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2189 if (!rc) {
2190 pr_err("timeout. waited for FORMAT_UPDATE\n");
2191 goto fail_cmd;
2192 }
2193 return 0;
2194fail_cmd:
2195 return -EINVAL;
2196}
2197
2198int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf,
2199 uint16_t band_mode, uint16_t dtx_enable)
2200{
2201 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2202 int rc = 0;
2203
2204 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
2205 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
2206
2207 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2208
2209 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2210
2211 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2212 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2213
2214 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2215 enc_cfg.enc_blk.format_id = AMRNB_FS;
2216 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrnb_read_cfg);
2217 enc_cfg.enc_blk.cfg.amrnb.mode = band_mode;
2218 enc_cfg.enc_blk.cfg.amrnb.dtx_mode = dtx_enable;
2219
2220 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2221 if (rc < 0) {
2222 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2223 goto fail_cmd;
2224 }
2225 rc = wait_event_timeout(ac->cmd_wait,
2226 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2227 if (!rc) {
2228 pr_err("timeout. waited for FORMAT_UPDATE\n");
2229 goto fail_cmd;
2230 }
2231 return 0;
2232fail_cmd:
2233 return -EINVAL;
2234}
2235
Alex Wong2caeecc2011-10-28 10:52:15 +05302236int q6asm_enc_cfg_blk_amrwb(struct audio_client *ac, uint32_t frames_per_buf,
2237 uint16_t band_mode, uint16_t dtx_enable)
2238{
2239 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2240 int rc = 0;
2241
2242 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
2243 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
2244
2245 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2246
2247 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2248
2249 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2250 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2251
2252 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2253 enc_cfg.enc_blk.format_id = AMRWB_FS;
2254 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrwb_read_cfg);
2255 enc_cfg.enc_blk.cfg.amrwb.mode = band_mode;
2256 enc_cfg.enc_blk.cfg.amrwb.dtx_mode = dtx_enable;
2257
2258 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2259 if (rc < 0) {
2260 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2261 goto fail_cmd;
2262 }
2263 rc = wait_event_timeout(ac->cmd_wait,
2264 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2265 if (!rc) {
2266 pr_err("timeout. waited for FORMAT_UPDATE\n");
2267 goto fail_cmd;
2268 }
2269 return 0;
2270fail_cmd:
2271 return -EINVAL;
2272}
2273
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002274int q6asm_media_format_block_pcm(struct audio_client *ac,
2275 uint32_t rate, uint32_t channels)
2276{
2277 struct asm_stream_media_format_update fmt;
2278 int rc = 0;
2279
2280 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
2281 channels);
2282
2283 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2284
2285 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2286
2287 fmt.format = LINEAR_PCM;
2288 fmt.cfg_size = sizeof(struct asm_pcm_cfg);
2289 fmt.write_cfg.pcm_cfg.ch_cfg = channels;
2290 fmt.write_cfg.pcm_cfg.bits_per_sample = 16;
2291 fmt.write_cfg.pcm_cfg.sample_rate = rate;
2292 fmt.write_cfg.pcm_cfg.is_signed = 1;
2293 fmt.write_cfg.pcm_cfg.interleaved = 1;
2294
2295 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2296 if (rc < 0) {
2297 pr_err("%s:Comamnd open failed\n", __func__);
2298 goto fail_cmd;
2299 }
2300 rc = wait_event_timeout(ac->cmd_wait,
2301 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2302 if (!rc) {
2303 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2304 goto fail_cmd;
2305 }
2306 return 0;
2307fail_cmd:
2308 return -EINVAL;
2309}
2310
Kiran Kandi5e809b02012-01-31 00:24:33 -08002311int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
2312 uint32_t rate, uint32_t channels)
2313{
2314 struct asm_stream_media_format_update fmt;
2315 u8 *channel_mapping;
2316 int rc = 0;
2317
2318 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
2319 channels);
2320
2321 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2322
2323 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2324
2325 fmt.format = MULTI_CHANNEL_PCM;
2326 fmt.cfg_size = sizeof(struct asm_multi_channel_pcm_fmt_blk);
2327 fmt.write_cfg.multi_ch_pcm_cfg.num_channels = channels;
2328 fmt.write_cfg.multi_ch_pcm_cfg.bits_per_sample = 16;
2329 fmt.write_cfg.multi_ch_pcm_cfg.sample_rate = rate;
2330 fmt.write_cfg.multi_ch_pcm_cfg.is_signed = 1;
2331 fmt.write_cfg.multi_ch_pcm_cfg.is_interleaved = 1;
2332 channel_mapping =
2333 fmt.write_cfg.multi_ch_pcm_cfg.channel_mapping;
2334
2335 memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
2336
2337 if (channels == 1) {
2338 channel_mapping[0] = PCM_CHANNEL_FL;
2339 } else if (channels == 2) {
2340 channel_mapping[0] = PCM_CHANNEL_FL;
2341 channel_mapping[1] = PCM_CHANNEL_FR;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002342 } else if (channels == 4) {
2343 channel_mapping[0] = PCM_CHANNEL_FL;
2344 channel_mapping[1] = PCM_CHANNEL_FR;
2345 channel_mapping[1] = PCM_CHANNEL_LB;
2346 channel_mapping[1] = PCM_CHANNEL_RB;
Kiran Kandi5e809b02012-01-31 00:24:33 -08002347 } else if (channels == 6) {
SathishKumar Mani6074b772012-09-26 13:49:49 -07002348 channel_mapping[0] = PCM_CHANNEL_FL;
2349 channel_mapping[1] = PCM_CHANNEL_FR;
2350 channel_mapping[2] = PCM_CHANNEL_FC;
2351 channel_mapping[3] = PCM_CHANNEL_LFE;
2352 channel_mapping[4] = PCM_CHANNEL_LB;
2353 channel_mapping[5] = PCM_CHANNEL_RB;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002354 } else if (channels == 8) {
2355 channel_mapping[0] = PCM_CHANNEL_FC;
2356 channel_mapping[1] = PCM_CHANNEL_FL;
2357 channel_mapping[2] = PCM_CHANNEL_FR;
2358 channel_mapping[3] = PCM_CHANNEL_LB;
2359 channel_mapping[4] = PCM_CHANNEL_RB;
2360 channel_mapping[5] = PCM_CHANNEL_LFE;
2361 channel_mapping[6] = PCM_CHANNEL_FLC;
2362 channel_mapping[7] = PCM_CHANNEL_FRC;
Kiran Kandi5e809b02012-01-31 00:24:33 -08002363 } else {
2364 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
2365 channels);
2366 return -EINVAL;
2367 }
2368
2369 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2370 if (rc < 0) {
2371 pr_err("%s:Comamnd open failed\n", __func__);
2372 goto fail_cmd;
2373 }
2374 rc = wait_event_timeout(ac->cmd_wait,
2375 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2376 if (!rc) {
2377 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2378 goto fail_cmd;
2379 }
2380 return 0;
2381fail_cmd:
2382 return -EINVAL;
2383}
2384
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002385int q6asm_media_format_block_aac(struct audio_client *ac,
2386 struct asm_aac_cfg *cfg)
2387{
2388 struct asm_stream_media_format_update fmt;
2389 int rc = 0;
2390
2391 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2392 cfg->sample_rate, cfg->ch_cfg);
2393
2394 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2395
2396 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2397
2398 fmt.format = MPEG4_AAC;
2399 fmt.cfg_size = sizeof(struct asm_aac_cfg);
2400 fmt.write_cfg.aac_cfg.format = cfg->format;
2401 fmt.write_cfg.aac_cfg.aot = cfg->aot;
2402 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
2403 fmt.write_cfg.aac_cfg.section_data_resilience =
2404 cfg->section_data_resilience;
2405 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2406 cfg->scalefactor_data_resilience;
2407 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2408 cfg->spectral_data_resilience;
2409 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2410 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2411 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2412 __func__, fmt.format, fmt.cfg_size,
2413 fmt.write_cfg.aac_cfg.format,
2414 fmt.write_cfg.aac_cfg.aot,
2415 fmt.write_cfg.aac_cfg.ch_cfg,
2416 fmt.write_cfg.aac_cfg.sample_rate);
2417 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2418 if (rc < 0) {
2419 pr_err("%s:Comamnd open failed\n", __func__);
2420 goto fail_cmd;
2421 }
2422 rc = wait_event_timeout(ac->cmd_wait,
2423 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2424 if (!rc) {
2425 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2426 goto fail_cmd;
2427 }
2428 return 0;
2429fail_cmd:
2430 return -EINVAL;
2431}
2432
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07002433
2434int q6asm_media_format_block_multi_aac(struct audio_client *ac,
2435 struct asm_aac_cfg *cfg)
2436{
2437 struct asm_stream_media_format_update fmt;
2438 int rc = 0;
2439
2440 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2441 cfg->sample_rate, cfg->ch_cfg);
2442
2443 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2444
2445 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2446
2447 fmt.format = MPEG4_MULTI_AAC;
2448 fmt.cfg_size = sizeof(struct asm_aac_cfg);
2449 fmt.write_cfg.aac_cfg.format = cfg->format;
2450 fmt.write_cfg.aac_cfg.aot = cfg->aot;
2451 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
2452 fmt.write_cfg.aac_cfg.section_data_resilience =
2453 cfg->section_data_resilience;
2454 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2455 cfg->scalefactor_data_resilience;
2456 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2457 cfg->spectral_data_resilience;
2458 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2459 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2460 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2461 __func__, fmt.format, fmt.cfg_size,
2462 fmt.write_cfg.aac_cfg.format,
2463 fmt.write_cfg.aac_cfg.aot,
2464 fmt.write_cfg.aac_cfg.ch_cfg,
2465 fmt.write_cfg.aac_cfg.sample_rate);
2466 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2467 if (rc < 0) {
2468 pr_err("%s:Comamnd open failed\n", __func__);
2469 goto fail_cmd;
2470 }
2471 rc = wait_event_timeout(ac->cmd_wait,
2472 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2473 if (!rc) {
2474 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2475 goto fail_cmd;
2476 }
2477 return 0;
2478fail_cmd:
2479 return -EINVAL;
2480}
2481
2482
Alex Wong2caeecc2011-10-28 10:52:15 +05302483
2484int q6asm_media_format_block(struct audio_client *ac, uint32_t format)
2485{
2486
2487 struct asm_stream_media_format_update fmt;
2488 int rc = 0;
2489
2490 pr_debug("%s:session[%d] format[0x%x]\n", __func__,
2491 ac->session, format);
2492
2493 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2494 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302495 switch (format) {
2496 case FORMAT_V13K:
2497 fmt.format = V13K_FS;
2498 break;
2499 case FORMAT_EVRC:
2500 fmt.format = EVRC_FS;
2501 break;
2502 case FORMAT_AMRWB:
2503 fmt.format = AMRWB_FS;
2504 break;
2505 case FORMAT_AMRNB:
2506 fmt.format = AMRNB_FS;
2507 break;
2508 case FORMAT_MP3:
2509 fmt.format = MP3;
2510 break;
Srikanth Uyyala66f781a2012-06-13 23:23:25 +05302511 case FORMAT_DTS:
2512 fmt.format = DTS;
2513 break;
2514 case FORMAT_DTS_LBR:
2515 fmt.format = DTS_LBR;
2516 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302517 default:
2518 pr_err("Invalid format[%d]\n", format);
2519 goto fail_cmd;
2520 }
Alex Wong2caeecc2011-10-28 10:52:15 +05302521 fmt.cfg_size = 0;
2522
2523 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2524 if (rc < 0) {
2525 pr_err("%s:Comamnd open failed\n", __func__);
2526 goto fail_cmd;
2527 }
2528 rc = wait_event_timeout(ac->cmd_wait,
2529 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2530 if (!rc) {
2531 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2532 goto fail_cmd;
2533 }
2534 return 0;
2535fail_cmd:
2536 return -EINVAL;
2537}
2538
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002539int q6asm_media_format_block_wma(struct audio_client *ac,
2540 void *cfg)
2541{
2542 struct asm_stream_media_format_update fmt;
2543 struct asm_wma_cfg *wma_cfg = (struct asm_wma_cfg *)cfg;
2544 int rc = 0;
2545
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002546 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 -07002547 ac->session, wma_cfg->format_tag, wma_cfg->sample_rate,
2548 wma_cfg->ch_cfg, wma_cfg->avg_bytes_per_sec,
2549 wma_cfg->block_align, wma_cfg->valid_bits_per_sample,
2550 wma_cfg->ch_mask, wma_cfg->encode_opt);
2551
2552 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2553
2554 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2555
2556 fmt.format = WMA_V9;
2557 fmt.cfg_size = sizeof(struct asm_wma_cfg);
2558 fmt.write_cfg.wma_cfg.format_tag = wma_cfg->format_tag;
2559 fmt.write_cfg.wma_cfg.ch_cfg = wma_cfg->ch_cfg;
2560 fmt.write_cfg.wma_cfg.sample_rate = wma_cfg->sample_rate;
2561 fmt.write_cfg.wma_cfg.avg_bytes_per_sec = wma_cfg->avg_bytes_per_sec;
2562 fmt.write_cfg.wma_cfg.block_align = wma_cfg->block_align;
2563 fmt.write_cfg.wma_cfg.valid_bits_per_sample =
2564 wma_cfg->valid_bits_per_sample;
2565 fmt.write_cfg.wma_cfg.ch_mask = wma_cfg->ch_mask;
2566 fmt.write_cfg.wma_cfg.encode_opt = wma_cfg->encode_opt;
2567 fmt.write_cfg.wma_cfg.adv_encode_opt = 0;
2568 fmt.write_cfg.wma_cfg.adv_encode_opt2 = 0;
2569 fmt.write_cfg.wma_cfg.drc_peak_ref = 0;
2570 fmt.write_cfg.wma_cfg.drc_peak_target = 0;
2571 fmt.write_cfg.wma_cfg.drc_ave_ref = 0;
2572 fmt.write_cfg.wma_cfg.drc_ave_target = 0;
2573
2574 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2575 if (rc < 0) {
2576 pr_err("%s:Comamnd open failed\n", __func__);
2577 goto fail_cmd;
2578 }
2579 rc = wait_event_timeout(ac->cmd_wait,
2580 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2581 if (!rc) {
2582 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2583 goto fail_cmd;
2584 }
2585 return 0;
2586fail_cmd:
2587 return -EINVAL;
2588}
2589
2590int q6asm_media_format_block_wmapro(struct audio_client *ac,
2591 void *cfg)
2592{
2593 struct asm_stream_media_format_update fmt;
2594 struct asm_wmapro_cfg *wmapro_cfg = (struct asm_wmapro_cfg *)cfg;
2595 int rc = 0;
2596
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002597 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 -07002598 ac->session, wmapro_cfg->format_tag, wmapro_cfg->sample_rate,
2599 wmapro_cfg->ch_cfg, wmapro_cfg->avg_bytes_per_sec,
2600 wmapro_cfg->block_align, wmapro_cfg->valid_bits_per_sample,
2601 wmapro_cfg->ch_mask, wmapro_cfg->encode_opt,
2602 wmapro_cfg->adv_encode_opt, wmapro_cfg->adv_encode_opt2);
2603
2604 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2605
2606 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2607
2608 fmt.format = WMA_V10PRO;
2609 fmt.cfg_size = sizeof(struct asm_wmapro_cfg);
2610 fmt.write_cfg.wmapro_cfg.format_tag = wmapro_cfg->format_tag;
2611 fmt.write_cfg.wmapro_cfg.ch_cfg = wmapro_cfg->ch_cfg;
2612 fmt.write_cfg.wmapro_cfg.sample_rate = wmapro_cfg->sample_rate;
2613 fmt.write_cfg.wmapro_cfg.avg_bytes_per_sec =
2614 wmapro_cfg->avg_bytes_per_sec;
2615 fmt.write_cfg.wmapro_cfg.block_align = wmapro_cfg->block_align;
2616 fmt.write_cfg.wmapro_cfg.valid_bits_per_sample =
2617 wmapro_cfg->valid_bits_per_sample;
2618 fmt.write_cfg.wmapro_cfg.ch_mask = wmapro_cfg->ch_mask;
2619 fmt.write_cfg.wmapro_cfg.encode_opt = wmapro_cfg->encode_opt;
2620 fmt.write_cfg.wmapro_cfg.adv_encode_opt = wmapro_cfg->adv_encode_opt;
2621 fmt.write_cfg.wmapro_cfg.adv_encode_opt2 = wmapro_cfg->adv_encode_opt2;
2622 fmt.write_cfg.wmapro_cfg.drc_peak_ref = 0;
2623 fmt.write_cfg.wmapro_cfg.drc_peak_target = 0;
2624 fmt.write_cfg.wmapro_cfg.drc_ave_ref = 0;
2625 fmt.write_cfg.wmapro_cfg.drc_ave_target = 0;
2626
2627 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2628 if (rc < 0) {
2629 pr_err("%s:Comamnd open failed\n", __func__);
2630 goto fail_cmd;
2631 }
2632 rc = wait_event_timeout(ac->cmd_wait,
2633 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2634 if (!rc) {
2635 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2636 goto fail_cmd;
2637 }
2638 return 0;
2639fail_cmd:
2640 return -EINVAL;
2641}
2642
2643int q6asm_memory_map(struct audio_client *ac, uint32_t buf_add, int dir,
2644 uint32_t bufsz, uint32_t bufcnt)
2645{
2646 struct asm_stream_cmd_memory_map mem_map;
2647 int rc = 0;
2648
2649 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2650 pr_err("APR handle NULL\n");
2651 return -EINVAL;
2652 }
2653
2654 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2655
2656 mem_map.hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP;
2657
2658 mem_map.buf_add = buf_add;
2659 mem_map.buf_size = bufsz * bufcnt;
2660 mem_map.mempool_id = 0; /* EBI */
2661 mem_map.reserved = 0;
2662
2663 q6asm_add_mmaphdr(&mem_map.hdr,
2664 sizeof(struct asm_stream_cmd_memory_map), TRUE);
2665
2666 pr_debug("buf add[%x] buf_add_parameter[%x]\n",
2667 mem_map.buf_add, buf_add);
2668
2669 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_map);
2670 if (rc < 0) {
2671 pr_err("mem_map op[0x%x]rc[%d]\n",
2672 mem_map.hdr.opcode, rc);
2673 rc = -EINVAL;
2674 goto fail_cmd;
2675 }
2676
2677 rc = wait_event_timeout(this_mmap.cmd_wait,
2678 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2679 if (!rc) {
2680 pr_err("timeout. waited for memory_map\n");
2681 rc = -EINVAL;
2682 goto fail_cmd;
2683 }
2684 rc = 0;
2685fail_cmd:
2686 return rc;
2687}
2688
2689int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add, int dir)
2690{
2691 struct asm_stream_cmd_memory_unmap mem_unmap;
2692 int rc = 0;
2693
2694 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2695 pr_err("APR handle NULL\n");
2696 return -EINVAL;
2697 }
2698 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2699
2700 q6asm_add_mmaphdr(&mem_unmap.hdr,
2701 sizeof(struct asm_stream_cmd_memory_unmap), TRUE);
2702 mem_unmap.hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP;
2703 mem_unmap.buf_add = buf_add;
2704
2705 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_unmap);
2706 if (rc < 0) {
2707 pr_err("mem_unmap op[0x%x]rc[%d]\n",
2708 mem_unmap.hdr.opcode, rc);
2709 rc = -EINVAL;
2710 goto fail_cmd;
2711 }
2712
2713 rc = wait_event_timeout(this_mmap.cmd_wait,
2714 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2715 if (!rc) {
2716 pr_err("timeout. waited for memory_map\n");
2717 rc = -EINVAL;
2718 goto fail_cmd;
2719 }
2720 rc = 0;
2721fail_cmd:
2722 return rc;
2723}
2724
2725int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain)
2726{
2727 void *vol_cmd = NULL;
2728 void *payload = NULL;
2729 struct asm_pp_params_command *cmd = NULL;
2730 struct asm_lrchannel_gain_params *lrgain = NULL;
2731 int sz = 0;
2732 int rc = 0;
2733
2734 sz = sizeof(struct asm_pp_params_command) +
2735 + sizeof(struct asm_lrchannel_gain_params);
2736 vol_cmd = kzalloc(sz, GFP_KERNEL);
2737 if (vol_cmd == NULL) {
2738 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2739 rc = -EINVAL;
2740 return rc;
2741 }
2742 cmd = (struct asm_pp_params_command *)vol_cmd;
2743 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2744 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2745 cmd->payload = NULL;
2746 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2747 sizeof(struct asm_lrchannel_gain_params);
2748 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2749 cmd->params.param_id = L_R_CHANNEL_GAIN_PARAM_ID;
2750 cmd->params.param_size = sizeof(struct asm_lrchannel_gain_params);
2751 cmd->params.reserved = 0;
2752
2753 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2754 lrgain = (struct asm_lrchannel_gain_params *)payload;
2755
2756 lrgain->left_gain = left_gain;
2757 lrgain->right_gain = right_gain;
2758 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2759 if (rc < 0) {
2760 pr_err("%s: Volume Command failed\n", __func__);
2761 rc = -EINVAL;
2762 goto fail_cmd;
2763 }
2764
2765 rc = wait_event_timeout(ac->cmd_wait,
2766 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2767 if (!rc) {
2768 pr_err("%s: timeout in sending volume command to apr\n",
2769 __func__);
2770 rc = -EINVAL;
2771 goto fail_cmd;
2772 }
2773 rc = 0;
2774fail_cmd:
2775 kfree(vol_cmd);
2776 return rc;
2777}
2778
2779static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
2780 uint32_t bufsz, uint32_t bufcnt)
2781{
2782 struct asm_stream_cmd_memory_map_regions *mmap_regions = NULL;
2783 struct asm_memory_map_regions *mregions = NULL;
2784 struct audio_port_data *port = NULL;
2785 struct audio_buffer *ab = NULL;
2786 void *mmap_region_cmd = NULL;
2787 void *payload = NULL;
2788 int rc = 0;
2789 int i = 0;
2790 int cmd_size = 0;
2791
2792 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2793 pr_err("APR handle NULL\n");
2794 return -EINVAL;
2795 }
2796 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2797
2798 cmd_size = sizeof(struct asm_stream_cmd_memory_map_regions)
2799 + sizeof(struct asm_memory_map_regions) * bufcnt;
2800
2801 mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302802 if (mmap_region_cmd == NULL) {
2803 pr_err("%s: Mem alloc failed\n", __func__);
2804 rc = -EINVAL;
2805 return rc;
2806 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002807 mmap_regions = (struct asm_stream_cmd_memory_map_regions *)
2808 mmap_region_cmd;
2809 q6asm_add_mmaphdr(&mmap_regions->hdr, cmd_size, TRUE);
2810 mmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP_REGIONS;
2811 mmap_regions->mempool_id = 0;
2812 mmap_regions->nregions = bufcnt & 0x00ff;
2813 pr_debug("map_regions->nregions = %d\n", mmap_regions->nregions);
2814 payload = ((u8 *) mmap_region_cmd +
2815 sizeof(struct asm_stream_cmd_memory_map_regions));
2816 mregions = (struct asm_memory_map_regions *)payload;
2817
2818 port = &ac->port[dir];
2819 for (i = 0; i < bufcnt; i++) {
2820 ab = &port->buf[i];
2821 mregions->phys = ab->phys;
2822 mregions->buf_size = ab->size;
2823 ++mregions;
2824 }
2825
2826 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) mmap_region_cmd);
2827 if (rc < 0) {
2828 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2829 mmap_regions->hdr.opcode, rc);
2830 rc = -EINVAL;
2831 goto fail_cmd;
2832 }
2833
2834 rc = wait_event_timeout(this_mmap.cmd_wait,
2835 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2836 if (!rc) {
2837 pr_err("timeout. waited for memory_map\n");
2838 rc = -EINVAL;
2839 goto fail_cmd;
2840 }
2841 rc = 0;
2842fail_cmd:
2843 kfree(mmap_region_cmd);
2844 return rc;
2845}
2846
2847static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir,
2848 uint32_t bufsz, uint32_t bufcnt)
2849{
2850 struct asm_stream_cmd_memory_unmap_regions *unmap_regions = NULL;
2851 struct asm_memory_unmap_regions *mregions = NULL;
2852 struct audio_port_data *port = NULL;
2853 struct audio_buffer *ab = NULL;
2854 void *unmap_region_cmd = NULL;
2855 void *payload = NULL;
2856 int rc = 0;
2857 int i = 0;
2858 int cmd_size = 0;
2859
2860 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2861 pr_err("APR handle NULL\n");
2862 return -EINVAL;
2863 }
2864 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2865
2866 cmd_size = sizeof(struct asm_stream_cmd_memory_unmap_regions) +
2867 sizeof(struct asm_memory_unmap_regions) * bufcnt;
2868
2869 unmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302870 if (unmap_region_cmd == NULL) {
2871 pr_err("%s: Mem alloc failed\n", __func__);
2872 rc = -EINVAL;
2873 return rc;
2874 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002875 unmap_regions = (struct asm_stream_cmd_memory_unmap_regions *)
2876 unmap_region_cmd;
2877 q6asm_add_mmaphdr(&unmap_regions->hdr, cmd_size, TRUE);
2878 unmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS;
2879 unmap_regions->nregions = bufcnt & 0x00ff;
2880 pr_debug("unmap_regions->nregions = %d\n", unmap_regions->nregions);
2881 payload = ((u8 *) unmap_region_cmd +
2882 sizeof(struct asm_stream_cmd_memory_unmap_regions));
2883 mregions = (struct asm_memory_unmap_regions *)payload;
2884 port = &ac->port[dir];
2885 for (i = 0; i < bufcnt; i++) {
2886 ab = &port->buf[i];
2887 mregions->phys = ab->phys;
2888 ++mregions;
2889 }
2890
2891 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) unmap_region_cmd);
2892 if (rc < 0) {
2893 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2894 unmap_regions->hdr.opcode, rc);
2895 goto fail_cmd;
2896 }
2897
2898 rc = wait_event_timeout(this_mmap.cmd_wait,
2899 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2900 if (!rc) {
2901 pr_err("timeout. waited for memory_unmap\n");
2902 goto fail_cmd;
2903 }
2904 rc = 0;
2905
2906fail_cmd:
2907 kfree(unmap_region_cmd);
2908 return rc;
2909}
2910
2911int q6asm_set_mute(struct audio_client *ac, int muteflag)
2912{
2913 void *vol_cmd = NULL;
2914 void *payload = NULL;
2915 struct asm_pp_params_command *cmd = NULL;
2916 struct asm_mute_params *mute = NULL;
2917 int sz = 0;
2918 int rc = 0;
2919
2920 sz = sizeof(struct asm_pp_params_command) +
2921 + sizeof(struct asm_mute_params);
2922 vol_cmd = kzalloc(sz, GFP_KERNEL);
2923 if (vol_cmd == NULL) {
2924 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2925 rc = -EINVAL;
2926 return rc;
2927 }
2928 cmd = (struct asm_pp_params_command *)vol_cmd;
2929 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2930 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2931 cmd->payload = NULL;
2932 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2933 sizeof(struct asm_mute_params);
2934 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2935 cmd->params.param_id = MUTE_CONFIG_PARAM_ID;
2936 cmd->params.param_size = sizeof(struct asm_mute_params);
2937 cmd->params.reserved = 0;
2938
2939 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2940 mute = (struct asm_mute_params *)payload;
2941
2942 mute->muteflag = muteflag;
2943 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2944 if (rc < 0) {
2945 pr_err("%s: Mute Command failed\n", __func__);
2946 rc = -EINVAL;
2947 goto fail_cmd;
2948 }
2949
2950 rc = wait_event_timeout(ac->cmd_wait,
2951 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2952 if (!rc) {
2953 pr_err("%s: timeout in sending mute command to apr\n",
2954 __func__);
2955 rc = -EINVAL;
2956 goto fail_cmd;
2957 }
2958 rc = 0;
2959fail_cmd:
2960 kfree(vol_cmd);
2961 return rc;
2962}
2963
2964int q6asm_set_volume(struct audio_client *ac, int volume)
2965{
2966 void *vol_cmd = NULL;
2967 void *payload = NULL;
2968 struct asm_pp_params_command *cmd = NULL;
2969 struct asm_master_gain_params *mgain = NULL;
2970 int sz = 0;
2971 int rc = 0;
2972
2973 sz = sizeof(struct asm_pp_params_command) +
2974 + sizeof(struct asm_master_gain_params);
2975 vol_cmd = kzalloc(sz, GFP_KERNEL);
2976 if (vol_cmd == NULL) {
2977 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2978 rc = -EINVAL;
2979 return rc;
2980 }
2981 cmd = (struct asm_pp_params_command *)vol_cmd;
2982 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2983 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2984 cmd->payload = NULL;
2985 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2986 sizeof(struct asm_master_gain_params);
2987 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2988 cmd->params.param_id = MASTER_GAIN_PARAM_ID;
2989 cmd->params.param_size = sizeof(struct asm_master_gain_params);
2990 cmd->params.reserved = 0;
2991
2992 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2993 mgain = (struct asm_master_gain_params *)payload;
2994
2995 mgain->master_gain = volume;
2996 mgain->padding = 0x00;
2997 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2998 if (rc < 0) {
2999 pr_err("%s: Volume Command failed\n", __func__);
3000 rc = -EINVAL;
3001 goto fail_cmd;
3002 }
3003
3004 rc = wait_event_timeout(ac->cmd_wait,
3005 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3006 if (!rc) {
3007 pr_err("%s: timeout in sending volume command to apr\n",
3008 __func__);
3009 rc = -EINVAL;
3010 goto fail_cmd;
3011 }
3012 rc = 0;
3013fail_cmd:
3014 kfree(vol_cmd);
3015 return rc;
3016}
3017
3018int q6asm_set_softpause(struct audio_client *ac,
3019 struct asm_softpause_params *pause_param)
3020{
3021 void *vol_cmd = NULL;
3022 void *payload = NULL;
3023 struct asm_pp_params_command *cmd = NULL;
3024 struct asm_softpause_params *params = NULL;
3025 int sz = 0;
3026 int rc = 0;
3027
3028 sz = sizeof(struct asm_pp_params_command) +
3029 + sizeof(struct asm_softpause_params);
3030 vol_cmd = kzalloc(sz, GFP_KERNEL);
3031 if (vol_cmd == NULL) {
3032 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3033 rc = -EINVAL;
3034 return rc;
3035 }
3036 cmd = (struct asm_pp_params_command *)vol_cmd;
3037 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3038 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3039 cmd->payload = NULL;
3040 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3041 sizeof(struct asm_softpause_params);
3042 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3043 cmd->params.param_id = SOFT_PAUSE_PARAM_ID;
3044 cmd->params.param_size = sizeof(struct asm_softpause_params);
3045 cmd->params.reserved = 0;
3046
3047 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3048 params = (struct asm_softpause_params *)payload;
3049
3050 params->enable = pause_param->enable;
3051 params->period = pause_param->period;
3052 params->step = pause_param->step;
3053 params->rampingcurve = pause_param->rampingcurve;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003054 pr_debug("%s: soft Pause Command: enable = %d, period = %d, step = %d, curve = %d\n",
3055 __func__, params->enable,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003056 params->period, params->step, params->rampingcurve);
3057 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3058 if (rc < 0) {
3059 pr_err("%s: Volume Command(soft_pause) failed\n", __func__);
3060 rc = -EINVAL;
3061 goto fail_cmd;
3062 }
3063
3064 rc = wait_event_timeout(ac->cmd_wait,
3065 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3066 if (!rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003067 pr_err("%s: timeout in sending volume command(soft_pause) to apr\n",
3068 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003069 rc = -EINVAL;
3070 goto fail_cmd;
3071 }
3072 rc = 0;
3073fail_cmd:
3074 kfree(vol_cmd);
3075 return rc;
3076}
3077
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003078int q6asm_set_softvolume(struct audio_client *ac,
3079 struct asm_softvolume_params *softvol_param)
3080{
3081 void *vol_cmd = NULL;
3082 void *payload = NULL;
3083 struct asm_pp_params_command *cmd = NULL;
3084 struct asm_softvolume_params *params = NULL;
3085 int sz = 0;
3086 int rc = 0;
3087
3088 sz = sizeof(struct asm_pp_params_command) +
3089 + sizeof(struct asm_softvolume_params);
3090 vol_cmd = kzalloc(sz, GFP_KERNEL);
3091 if (vol_cmd == NULL) {
3092 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3093 rc = -EINVAL;
3094 return rc;
3095 }
3096 cmd = (struct asm_pp_params_command *)vol_cmd;
3097 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3098 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3099 cmd->payload = NULL;
3100 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3101 sizeof(struct asm_softvolume_params);
3102 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3103 cmd->params.param_id = SOFT_VOLUME_PARAM_ID;
3104 cmd->params.param_size = sizeof(struct asm_softvolume_params);
3105 cmd->params.reserved = 0;
3106
3107 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3108 params = (struct asm_softvolume_params *)payload;
3109
3110 params->period = softvol_param->period;
3111 params->step = softvol_param->step;
3112 params->rampingcurve = softvol_param->rampingcurve;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003113 pr_debug("%s: soft Volume:opcode = %d,payload_sz =%d,module_id =%d, param_id = %d, param_sz = %d\n",
3114 __func__,
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003115 cmd->hdr.opcode, cmd->payload_size,
3116 cmd->params.module_id, cmd->params.param_id,
3117 cmd->params.param_size);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003118 pr_debug("%s: soft Volume Command: period = %d, step = %d, curve = %d\n",
3119 __func__, params->period,
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003120 params->step, params->rampingcurve);
3121 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3122 if (rc < 0) {
3123 pr_err("%s: Volume Command(soft_volume) failed\n", __func__);
3124 rc = -EINVAL;
3125 goto fail_cmd;
3126 }
3127
3128 rc = wait_event_timeout(ac->cmd_wait,
3129 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3130 if (!rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003131 pr_err("%s: timeout in sending volume command(soft_volume) to apr\n",
3132 __func__);
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003133 rc = -EINVAL;
3134 goto fail_cmd;
3135 }
3136 rc = 0;
3137fail_cmd:
3138 kfree(vol_cmd);
3139 return rc;
3140}
3141
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003142int q6asm_equalizer(struct audio_client *ac, void *eq)
3143{
3144 void *eq_cmd = NULL;
3145 void *payload = NULL;
3146 struct asm_pp_params_command *cmd = NULL;
3147 struct asm_equalizer_params *equalizer = NULL;
3148 struct msm_audio_eq_stream_config *eq_params = NULL;
3149 int i = 0;
3150 int sz = 0;
3151 int rc = 0;
3152
3153 sz = sizeof(struct asm_pp_params_command) +
3154 + sizeof(struct asm_equalizer_params);
3155 eq_cmd = kzalloc(sz, GFP_KERNEL);
3156 if (eq_cmd == NULL) {
3157 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3158 rc = -EINVAL;
3159 goto fail_cmd;
3160 }
3161 eq_params = (struct msm_audio_eq_stream_config *) eq;
3162 cmd = (struct asm_pp_params_command *)eq_cmd;
3163 q6asm_add_hdr(ac, &cmd->hdr, sz, TRUE);
3164 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3165 cmd->payload = NULL;
3166 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3167 sizeof(struct asm_equalizer_params);
3168 cmd->params.module_id = EQUALIZER_MODULE_ID;
3169 cmd->params.param_id = EQUALIZER_PARAM_ID;
3170 cmd->params.param_size = sizeof(struct asm_equalizer_params);
3171 cmd->params.reserved = 0;
3172 payload = (u8 *)(eq_cmd + sizeof(struct asm_pp_params_command));
3173 equalizer = (struct asm_equalizer_params *)payload;
3174
3175 equalizer->enable = eq_params->enable;
3176 equalizer->num_bands = eq_params->num_bands;
3177 pr_debug("%s: enable:%d numbands:%d\n", __func__, eq_params->enable,
3178 eq_params->num_bands);
3179 for (i = 0; i < eq_params->num_bands; i++) {
3180 equalizer->eq_bands[i].band_idx =
3181 eq_params->eq_bands[i].band_idx;
3182 equalizer->eq_bands[i].filter_type =
3183 eq_params->eq_bands[i].filter_type;
3184 equalizer->eq_bands[i].center_freq_hz =
3185 eq_params->eq_bands[i].center_freq_hz;
3186 equalizer->eq_bands[i].filter_gain =
3187 eq_params->eq_bands[i].filter_gain;
3188 equalizer->eq_bands[i].q_factor =
3189 eq_params->eq_bands[i].q_factor;
3190 pr_debug("%s: filter_type:%u bandnum:%d\n", __func__,
3191 eq_params->eq_bands[i].filter_type, i);
3192 pr_debug("%s: center_freq_hz:%u bandnum:%d\n", __func__,
3193 eq_params->eq_bands[i].center_freq_hz, i);
3194 pr_debug("%s: filter_gain:%d bandnum:%d\n", __func__,
3195 eq_params->eq_bands[i].filter_gain, i);
3196 pr_debug("%s: q_factor:%d bandnum:%d\n", __func__,
3197 eq_params->eq_bands[i].q_factor, i);
3198 }
3199 rc = apr_send_pkt(ac->apr, (uint32_t *) eq_cmd);
3200 if (rc < 0) {
3201 pr_err("%s: Equalizer Command failed\n", __func__);
3202 rc = -EINVAL;
3203 goto fail_cmd;
3204 }
3205
3206 rc = wait_event_timeout(ac->cmd_wait,
3207 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3208 if (!rc) {
3209 pr_err("%s: timeout in sending equalizer command to apr\n",
3210 __func__);
3211 rc = -EINVAL;
3212 goto fail_cmd;
3213 }
3214 rc = 0;
3215fail_cmd:
3216 kfree(eq_cmd);
3217 return rc;
3218}
3219
3220int q6asm_read(struct audio_client *ac)
3221{
3222 struct asm_stream_cmd_read read;
3223 struct audio_buffer *ab;
3224 int dsp_buf;
3225 struct audio_port_data *port;
3226 int rc;
3227 if (!ac || ac->apr == NULL) {
3228 pr_err("APR handle NULL\n");
3229 return -EINVAL;
3230 }
3231 if (ac->io_mode == SYNC_IO_MODE) {
3232 port = &ac->port[OUT];
3233
3234 q6asm_add_hdr(ac, &read.hdr, sizeof(read), FALSE);
3235
3236 mutex_lock(&port->lock);
3237
3238 dsp_buf = port->dsp_buf;
3239 ab = &port->buf[dsp_buf];
3240
3241 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
3242 __func__,
3243 ac->session,
3244 dsp_buf,
3245 (void *)port->buf[dsp_buf].data,
3246 port->cpu_buf,
3247 (void *)port->buf[port->cpu_buf].phys);
3248
3249 read.hdr.opcode = ASM_DATA_CMD_READ;
3250 read.buf_add = ab->phys;
3251 read.buf_size = ab->size;
3252 read.uid = port->dsp_buf;
3253 read.hdr.token = port->dsp_buf;
3254
3255 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3256 mutex_unlock(&port->lock);
3257 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
3258 read.buf_add,
3259 read.hdr.token,
3260 read.uid);
3261 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3262 if (rc < 0) {
3263 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
3264 goto fail_cmd;
3265 }
3266 return 0;
3267 }
3268fail_cmd:
3269 return -EINVAL;
3270}
3271
3272int q6asm_read_nolock(struct audio_client *ac)
3273{
3274 struct asm_stream_cmd_read read;
3275 struct audio_buffer *ab;
3276 int dsp_buf;
3277 struct audio_port_data *port;
3278 int rc;
3279 if (!ac || ac->apr == NULL) {
3280 pr_err("APR handle NULL\n");
3281 return -EINVAL;
3282 }
3283 if (ac->io_mode == SYNC_IO_MODE) {
3284 port = &ac->port[OUT];
3285
3286 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3287
3288
3289 dsp_buf = port->dsp_buf;
3290 ab = &port->buf[dsp_buf];
3291
3292 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
3293 __func__,
3294 ac->session,
3295 dsp_buf,
3296 (void *)port->buf[dsp_buf].data,
3297 port->cpu_buf,
3298 (void *)port->buf[port->cpu_buf].phys);
3299
3300 read.hdr.opcode = ASM_DATA_CMD_READ;
3301 read.buf_add = ab->phys;
3302 read.buf_size = ab->size;
3303 read.uid = port->dsp_buf;
3304 read.hdr.token = port->dsp_buf;
3305
3306 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3307 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
3308 read.buf_add,
3309 read.hdr.token,
3310 read.uid);
3311 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3312 if (rc < 0) {
3313 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
3314 goto fail_cmd;
3315 }
3316 return 0;
3317 }
3318fail_cmd:
3319 return -EINVAL;
3320}
3321
3322
3323static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
3324 uint32_t pkt_size, uint32_t cmd_flg)
3325{
3326 pr_debug("session=%d pkt size=%d cmd_flg=%d\n", pkt_size, cmd_flg,
3327 ac->session);
3328 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
3329 APR_HDR_LEN(sizeof(struct apr_hdr)),\
3330 APR_PKT_VER);
3331 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
3332 hdr->src_domain = APR_DOMAIN_APPS;
3333 hdr->dest_svc = APR_SVC_ASM;
3334 hdr->dest_domain = APR_DOMAIN_ADSP;
3335 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
3336 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
3337 if (cmd_flg) {
3338 hdr->token = ac->session;
3339 atomic_set(&ac->cmd_state, 1);
3340 }
3341 hdr->pkt_size = pkt_size;
3342 return;
3343}
3344
3345int q6asm_async_write(struct audio_client *ac,
3346 struct audio_aio_write_param *param)
3347{
3348 int rc = 0;
3349 struct asm_stream_cmd_write write;
3350
3351 if (!ac || ac->apr == NULL) {
3352 pr_err("%s: APR handle NULL\n", __func__);
3353 return -EINVAL;
3354 }
3355
3356 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write), FALSE);
3357
3358 /* Pass physical address as token for AIO scheme */
3359 write.hdr.token = param->uid;
3360 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3361 write.buf_add = param->paddr;
3362 write.avail_bytes = param->len;
3363 write.uid = param->uid;
3364 write.msw_ts = param->msw_ts;
3365 write.lsw_ts = param->lsw_ts;
3366 /* Use 0xFF00 for disabling timestamps */
3367 if (param->flags == 0xFF00)
3368 write.uflags = (0x00000000 | (param->flags & 0x800000FF));
3369 else
3370 write.uflags = (0x80000000 | param->flags);
3371
3372 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3373 write.buf_add, write.avail_bytes);
3374
3375 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3376 if (rc < 0) {
3377 pr_debug("[%s] write op[0x%x]rc[%d]\n", __func__,
3378 write.hdr.opcode, rc);
3379 goto fail_cmd;
3380 }
3381 return 0;
3382fail_cmd:
3383 return -EINVAL;
3384}
3385
3386int q6asm_async_read(struct audio_client *ac,
3387 struct audio_aio_read_param *param)
3388{
3389 int rc = 0;
3390 struct asm_stream_cmd_read read;
3391
3392 if (!ac || ac->apr == NULL) {
3393 pr_err("%s: APR handle NULL\n", __func__);
3394 return -EINVAL;
3395 }
3396
3397 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3398
3399 /* Pass physical address as token for AIO scheme */
3400 read.hdr.token = param->paddr;
3401 read.hdr.opcode = ASM_DATA_CMD_READ;
3402 read.buf_add = param->paddr;
3403 read.buf_size = param->len;
3404 read.uid = param->uid;
3405
3406 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3407 read.buf_add, read.buf_size);
3408
3409 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3410 if (rc < 0) {
3411 pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
3412 read.hdr.opcode, rc);
3413 goto fail_cmd;
3414 }
3415 return 0;
3416fail_cmd:
3417 return -EINVAL;
3418}
3419
Subhash Chandra Bose Naripeddy694b7d92012-06-20 20:46:13 -07003420int q6asm_async_read_compressed(struct audio_client *ac,
3421 struct audio_aio_read_param *param)
3422{
3423 int rc = 0;
3424 struct asm_stream_cmd_read read;
3425
3426 if (!ac || ac->apr == NULL) {
3427 pr_err("%s: APR handle NULL\n", __func__);
3428 return -EINVAL;
3429 }
3430
3431 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3432
3433 /* Pass physical address as token for AIO scheme */
3434 read.hdr.token = param->paddr;
3435 read.hdr.opcode = ASM_DATA_CMD_READ_COMPRESSED;
3436 read.buf_add = param->paddr;
3437 read.buf_size = param->len;
3438 read.uid = param->uid;
3439
3440 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3441 read.buf_add, read.buf_size);
3442
3443 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3444 if (rc < 0) {
3445 pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
3446 read.hdr.opcode, rc);
3447 goto fail_cmd;
3448 }
3449 return 0;
3450fail_cmd:
3451 return -EINVAL;
3452}
3453
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003454int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3455 uint32_t lsw_ts, uint32_t flags)
3456{
3457 int rc = 0;
3458 struct asm_stream_cmd_write write;
3459 struct audio_port_data *port;
3460 struct audio_buffer *ab;
3461 int dsp_buf = 0;
3462
3463 if (!ac || ac->apr == NULL) {
3464 pr_err("APR handle NULL\n");
3465 return -EINVAL;
3466 }
3467 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3468 if (ac->io_mode == SYNC_IO_MODE) {
3469 port = &ac->port[IN];
3470
3471 q6asm_add_hdr(ac, &write.hdr, sizeof(write),
3472 FALSE);
3473 mutex_lock(&port->lock);
3474
3475 dsp_buf = port->dsp_buf;
3476 ab = &port->buf[dsp_buf];
3477
3478 write.hdr.token = port->dsp_buf;
3479 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3480 write.buf_add = ab->phys;
3481 write.avail_bytes = len;
3482 write.uid = port->dsp_buf;
3483 write.msw_ts = msw_ts;
3484 write.lsw_ts = lsw_ts;
3485 /* Use 0xFF00 for disabling timestamps */
3486 if (flags == 0xFF00)
3487 write.uflags = (0x00000000 | (flags & 0x800000FF));
3488 else
3489 write.uflags = (0x80000000 | flags);
3490 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3491
3492 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3493 , __func__,
3494 ab->phys,
3495 write.buf_add,
3496 write.hdr.token,
3497 write.uid);
3498 mutex_unlock(&port->lock);
Rajesha Kini3498c932011-07-19 19:58:27 +05303499#ifdef CONFIG_DEBUG_FS
3500 if (out_enable_flag) {
3501 char zero_pattern[2] = {0x00, 0x00};
3502 /* If First two byte is non zero and last two byte
3503 is zero then it is warm output pattern */
3504 if ((strncmp(((char *)ab->data), zero_pattern, 2)) &&
3505 (!strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3506 do_gettimeofday(&out_warm_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003507 pr_debug("WARM:apr_send_pkt at %ld sec %ld microsec\n",
3508 out_warm_tv.tv_sec,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303509 out_warm_tv.tv_usec);
3510 pr_debug("Warm Pattern Matched");
3511 }
3512 /* If First two byte is zero and last two byte is
3513 non zero then it is cont ouput pattern */
3514 else if ((!strncmp(((char *)ab->data), zero_pattern, 2))
3515 && (strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3516 do_gettimeofday(&out_cont_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003517 pr_debug("CONT:apr_send_pkt at %ld sec %ld microsec\n",
3518 out_cont_tv.tv_sec,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303519 out_cont_tv.tv_usec);
3520 pr_debug("Cont Pattern Matched");
3521 }
3522 }
3523#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003524 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3525 if (rc < 0) {
3526 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3527 goto fail_cmd;
3528 }
3529 pr_debug("%s: WRITE SUCCESS\n", __func__);
3530 return 0;
3531 }
3532fail_cmd:
3533 return -EINVAL;
3534}
3535
3536int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3537 uint32_t lsw_ts, uint32_t flags)
3538{
3539 int rc = 0;
3540 struct asm_stream_cmd_write write;
3541 struct audio_port_data *port;
3542 struct audio_buffer *ab;
3543 int dsp_buf = 0;
3544
3545 if (!ac || ac->apr == NULL) {
3546 pr_err("APR handle NULL\n");
3547 return -EINVAL;
3548 }
3549 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3550 if (ac->io_mode == SYNC_IO_MODE) {
3551 port = &ac->port[IN];
3552
3553 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write),
3554 FALSE);
3555
3556 dsp_buf = port->dsp_buf;
3557 ab = &port->buf[dsp_buf];
3558
3559 write.hdr.token = port->dsp_buf;
3560 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3561 write.buf_add = ab->phys;
3562 write.avail_bytes = len;
3563 write.uid = port->dsp_buf;
3564 write.msw_ts = msw_ts;
3565 write.lsw_ts = lsw_ts;
3566 /* Use 0xFF00 for disabling timestamps */
3567 if (flags == 0xFF00)
3568 write.uflags = (0x00000000 | (flags & 0x800000FF));
3569 else
3570 write.uflags = (0x80000000 | flags);
3571 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3572
3573 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3574 , __func__,
3575 ab->phys,
3576 write.buf_add,
3577 write.hdr.token,
3578 write.uid);
3579
3580 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3581 if (rc < 0) {
3582 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3583 goto fail_cmd;
3584 }
3585 pr_debug("%s: WRITE SUCCESS\n", __func__);
3586 return 0;
3587 }
3588fail_cmd:
3589 return -EINVAL;
3590}
3591
3592uint64_t q6asm_get_session_time(struct audio_client *ac)
3593{
3594 struct apr_hdr hdr;
3595 int rc;
3596
3597 if (!ac || ac->apr == NULL) {
3598 pr_err("APR handle NULL\n");
3599 return -EINVAL;
3600 }
Swaminathan Sathappanc7f98992012-07-09 11:07:12 -07003601 q6asm_add_hdr(ac, &hdr, sizeof(hdr), FALSE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003602 hdr.opcode = ASM_SESSION_CMD_GET_SESSION_TIME;
3603 atomic_set(&ac->time_flag, 1);
3604
3605 pr_debug("%s: session[%d]opcode[0x%x]\n", __func__,
3606 ac->session,
3607 hdr.opcode);
3608 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3609 if (rc < 0) {
3610 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3611 goto fail_cmd;
3612 }
3613 rc = wait_event_timeout(ac->time_wait,
3614 (atomic_read(&ac->time_flag) == 0), 5*HZ);
3615 if (!rc) {
3616 pr_err("%s: timeout in getting session time from DSP\n",
3617 __func__);
3618 goto fail_cmd;
3619 }
3620 return ac->time_stamp;
3621
3622fail_cmd:
3623 return -EINVAL;
3624}
3625
3626int q6asm_cmd(struct audio_client *ac, int cmd)
3627{
3628 struct apr_hdr hdr;
3629 int rc;
3630 atomic_t *state;
3631 int cnt = 0;
3632
3633 if (!ac || ac->apr == NULL) {
3634 pr_err("APR handle NULL\n");
3635 return -EINVAL;
3636 }
3637 q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
3638 switch (cmd) {
3639 case CMD_PAUSE:
3640 pr_debug("%s:CMD_PAUSE\n", __func__);
3641 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3642 state = &ac->cmd_state;
3643 break;
3644 case CMD_FLUSH:
3645 pr_debug("%s:CMD_FLUSH\n", __func__);
3646 hdr.opcode = ASM_STREAM_CMD_FLUSH;
3647 state = &ac->cmd_state;
3648 break;
3649 case CMD_OUT_FLUSH:
3650 pr_debug("%s:CMD_OUT_FLUSH\n", __func__);
3651 hdr.opcode = ASM_STREAM_CMD_FLUSH_READBUFS;
3652 state = &ac->cmd_state;
3653 break;
3654 case CMD_EOS:
3655 pr_debug("%s:CMD_EOS\n", __func__);
3656 hdr.opcode = ASM_DATA_CMD_EOS;
3657 atomic_set(&ac->cmd_state, 0);
3658 state = &ac->cmd_state;
3659 break;
3660 case CMD_CLOSE:
3661 pr_debug("%s:CMD_CLOSE\n", __func__);
3662 hdr.opcode = ASM_STREAM_CMD_CLOSE;
3663 state = &ac->cmd_state;
3664 break;
3665 default:
3666 pr_err("Invalid format[%d]\n", cmd);
3667 goto fail_cmd;
3668 }
3669 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3670 ac->session,
3671 hdr.opcode);
3672 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3673 if (rc < 0) {
3674 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3675 goto fail_cmd;
3676 }
3677 rc = wait_event_timeout(ac->cmd_wait, (atomic_read(state) == 0), 5*HZ);
3678 if (!rc) {
3679 pr_err("timeout. waited for response opcode[0x%x]\n",
3680 hdr.opcode);
3681 goto fail_cmd;
3682 }
3683 if (cmd == CMD_FLUSH)
3684 q6asm_reset_buf_state(ac);
3685 if (cmd == CMD_CLOSE) {
3686 /* check if DSP return all buffers */
3687 if (ac->port[IN].buf) {
3688 for (cnt = 0; cnt < ac->port[IN].max_buf_cnt;
3689 cnt++) {
3690 if (ac->port[IN].buf[cnt].used == IN) {
3691 pr_debug("Write Buf[%d] not returned\n",
3692 cnt);
3693 }
3694 }
3695 }
3696 if (ac->port[OUT].buf) {
3697 for (cnt = 0; cnt < ac->port[OUT].max_buf_cnt; cnt++) {
3698 if (ac->port[OUT].buf[cnt].used == OUT) {
3699 pr_debug("Read Buf[%d] not returned\n",
3700 cnt);
3701 }
3702 }
3703 }
3704 }
3705 return 0;
3706fail_cmd:
3707 return -EINVAL;
3708}
3709
3710int q6asm_cmd_nowait(struct audio_client *ac, int cmd)
3711{
3712 struct apr_hdr hdr;
3713 int rc;
3714
3715 if (!ac || ac->apr == NULL) {
3716 pr_err("%s:APR handle NULL\n", __func__);
3717 return -EINVAL;
3718 }
3719 q6asm_add_hdr_async(ac, &hdr, sizeof(hdr), TRUE);
3720 switch (cmd) {
3721 case CMD_PAUSE:
3722 pr_debug("%s:CMD_PAUSE\n", __func__);
3723 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3724 break;
3725 case CMD_EOS:
3726 pr_debug("%s:CMD_EOS\n", __func__);
3727 hdr.opcode = ASM_DATA_CMD_EOS;
3728 break;
3729 default:
3730 pr_err("%s:Invalid format[%d]\n", __func__, cmd);
3731 goto fail_cmd;
3732 }
3733 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3734 ac->session,
3735 hdr.opcode);
Jay Wang0668d1062012-07-11 18:53:21 -07003736
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003737 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3738 if (rc < 0) {
3739 pr_err("%s:Commmand 0x%x failed\n", __func__, hdr.opcode);
3740 goto fail_cmd;
3741 }
Jay Wang0668d1062012-07-11 18:53:21 -07003742 atomic_inc(&ac->nowait_cmd_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003743 return 0;
3744fail_cmd:
3745 return -EINVAL;
3746}
3747
3748static void q6asm_reset_buf_state(struct audio_client *ac)
3749{
3750 int cnt = 0;
3751 int loopcnt = 0;
3752 struct audio_port_data *port = NULL;
3753
3754 if (ac->io_mode == SYNC_IO_MODE) {
3755 mutex_lock(&ac->cmd_lock);
3756 for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
3757 port = &ac->port[loopcnt];
3758 cnt = port->max_buf_cnt - 1;
3759 port->dsp_buf = 0;
3760 port->cpu_buf = 0;
3761 while (cnt >= 0) {
3762 if (!port->buf)
3763 continue;
3764 port->buf[cnt].used = 1;
3765 cnt--;
3766 }
3767 }
3768 mutex_unlock(&ac->cmd_lock);
3769 }
3770}
3771
3772int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable)
3773{
3774 struct asm_stream_cmd_reg_tx_overflow_event tx_overflow;
3775 int rc;
3776
3777 if (!ac || ac->apr == NULL) {
3778 pr_err("APR handle NULL\n");
3779 return -EINVAL;
3780 }
3781 pr_debug("%s:session[%d]enable[%d]\n", __func__,
3782 ac->session, enable);
3783 q6asm_add_hdr(ac, &tx_overflow.hdr, sizeof(tx_overflow), TRUE);
3784
3785 tx_overflow.hdr.opcode = \
3786 ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS;
3787 /* tx overflow event: enable */
3788 tx_overflow.enable = enable;
3789
3790 rc = apr_send_pkt(ac->apr, (uint32_t *) &tx_overflow);
3791 if (rc < 0) {
3792 pr_err("tx overflow op[0x%x]rc[%d]\n", \
3793 tx_overflow.hdr.opcode, rc);
3794 goto fail_cmd;
3795 }
3796 rc = wait_event_timeout(ac->cmd_wait,
3797 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3798 if (!rc) {
3799 pr_err("timeout. waited for tx overflow\n");
3800 goto fail_cmd;
3801 }
3802 return 0;
3803fail_cmd:
3804 return -EINVAL;
3805}
3806
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003807int q6asm_get_apr_service_id(int session_id)
3808{
3809 pr_debug("%s\n", __func__);
3810
Shiv Maliyappanahallia84982a2012-01-19 15:25:04 -08003811 if (session_id < 0 || session_id > SESSION_MAX) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003812 pr_err("%s: invalid session_id = %d\n", __func__, session_id);
3813 return -EINVAL;
3814 }
3815
3816 return ((struct apr_svc *)session[session_id]->apr)->id;
3817}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003818
3819
3820static int __init q6asm_init(void)
3821{
3822 pr_debug("%s\n", __func__);
3823 init_waitqueue_head(&this_mmap.cmd_wait);
3824 memset(session, 0, sizeof(session));
Rajesha Kini3498c932011-07-19 19:58:27 +05303825#ifdef CONFIG_DEBUG_FS
3826 out_buffer = kmalloc(OUT_BUFFER_SIZE, GFP_KERNEL);
3827 out_dentry = debugfs_create_file("audio_out_latency_measurement_node",\
Glenn Kasten5dfda802012-10-04 16:40:27 -07003828 0664,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303829 NULL, NULL, &audio_output_latency_debug_fops);
3830 if (IS_ERR(out_dentry))
3831 pr_err("debugfs_create_file failed\n");
3832 in_buffer = kmalloc(IN_BUFFER_SIZE, GFP_KERNEL);
3833 in_dentry = debugfs_create_file("audio_in_latency_measurement_node",\
Glenn Kasten5dfda802012-10-04 16:40:27 -07003834 0664,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303835 NULL, NULL, &audio_input_latency_debug_fops);
3836 if (IS_ERR(in_dentry))
3837 pr_err("debugfs_create_file failed\n");
3838#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003839 return 0;
3840}
3841
3842device_initcall(q6asm_init);