blob: 01f4852bc79370d4bdcb157f6e158e6af81985de [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/*
Patrick Lai3aabeae2013-01-06 00:52:34 -08002 * Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003 * Author: Brian Swetland <swetland@google.com>
4 *
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 */
15#include <linux/fs.h>
16#include <linux/mutex.h>
17#include <linux/wait.h>
18#include <linux/miscdevice.h>
19#include <linux/uaccess.h>
20#include <linux/sched.h>
21#include <linux/dma-mapping.h>
22#include <linux/miscdevice.h>
23#include <linux/delay.h>
24#include <linux/spinlock.h>
25#include <linux/slab.h>
26#include <linux/msm_audio.h>
27#include <linux/android_pmem.h>
28#include <linux/memory_alloc.h>
Ben Rombergerfce8f512011-07-18 16:46:09 -070029#include <linux/debugfs.h>
30#include <linux/time.h>
31#include <linux/atomic.h>
32
33#include <asm/ioctls.h>
34
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070035#include <mach/memory.h>
36#include <mach/debug_mm.h>
37#include <mach/peripheral-loader.h>
38#include <mach/qdsp6v2/audio_acdb.h>
39#include <mach/qdsp6v2/rtac.h>
Ben Rombergerfce8f512011-07-18 16:46:09 -070040
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070041#include <sound/apr_audio.h>
42#include <sound/q6asm.h>
Ben Rombergerfce8f512011-07-18 16:46:09 -070043
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070044
45#define TRUE 0x01
46#define FALSE 0x00
47#define READDONE_IDX_STATUS 0
48#define READDONE_IDX_BUFFER 1
49#define READDONE_IDX_SIZE 2
50#define READDONE_IDX_OFFSET 3
51#define READDONE_IDX_MSW_TS 4
52#define READDONE_IDX_LSW_TS 5
53#define READDONE_IDX_FLAGS 6
54#define READDONE_IDX_NUMFRAMES 7
55#define READDONE_IDX_ID 8
Rajesha Kini3498c932011-07-19 19:58:27 +053056#ifdef CONFIG_DEBUG_FS
57#define OUT_BUFFER_SIZE 56
58#define IN_BUFFER_SIZE 24
59#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070060static DEFINE_MUTEX(session_lock);
61
62/* session id: 0 reserved */
63static struct audio_client *session[SESSION_MAX+1];
64static int32_t q6asm_mmapcallback(struct apr_client_data *data, void *priv);
65static int32_t q6asm_callback(struct apr_client_data *data, void *priv);
66static void q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
67 uint32_t pkt_size, uint32_t cmd_flg);
68static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
69 uint32_t pkt_size, uint32_t cmd_flg);
70static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
71 uint32_t bufsz, uint32_t bufcnt);
72static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir,
73 uint32_t bufsz, uint32_t bufcnt);
74
75static void q6asm_reset_buf_state(struct audio_client *ac);
76
Rajesha Kini3498c932011-07-19 19:58:27 +053077#ifdef CONFIG_DEBUG_FS
78static struct timeval out_cold_tv;
79static struct timeval out_warm_tv;
80static struct timeval out_cont_tv;
81static struct timeval in_cont_tv;
82static long out_enable_flag;
83static long in_enable_flag;
84static struct dentry *out_dentry;
85static struct dentry *in_dentry;
86static int in_cont_index;
87/*This var is used to keep track of first write done for cold output latency */
88static int out_cold_index;
89static char *out_buffer;
90static char *in_buffer;
91static int audio_output_latency_dbgfs_open(struct inode *inode,
92 struct file *file)
93{
94 file->private_data = inode->i_private;
95 return 0;
96}
97static ssize_t audio_output_latency_dbgfs_read(struct file *file,
98 char __user *buf, size_t count, loff_t *ppos)
99{
100 snprintf(out_buffer, OUT_BUFFER_SIZE, "%ld,%ld,%ld,%ld,%ld,%ld,",\
101 out_cold_tv.tv_sec, out_cold_tv.tv_usec, out_warm_tv.tv_sec,\
102 out_warm_tv.tv_usec, out_cont_tv.tv_sec, out_cont_tv.tv_usec);
103 return simple_read_from_buffer(buf, OUT_BUFFER_SIZE, ppos,
104 out_buffer, OUT_BUFFER_SIZE);
105}
106static ssize_t audio_output_latency_dbgfs_write(struct file *file,
107 const char __user *buf, size_t count, loff_t *ppos)
108{
109 char *temp;
110
111 if (count > 2*sizeof(char))
112 return -EINVAL;
113 else
114 temp = kmalloc(2*sizeof(char), GFP_KERNEL);
115
116 out_cold_index = 0;
117
118 if (temp) {
119 if (copy_from_user(temp, buf, 2*sizeof(char))) {
120 kfree(temp);
121 return -EFAULT;
122 }
123 if (!strict_strtol(temp, 10, &out_enable_flag)) {
124 kfree(temp);
125 return count;
126 }
127 kfree(temp);
128 }
129 return -EINVAL;
130}
131static const struct file_operations audio_output_latency_debug_fops = {
132 .open = audio_output_latency_dbgfs_open,
133 .read = audio_output_latency_dbgfs_read,
134 .write = audio_output_latency_dbgfs_write
135};
136
137static int audio_input_latency_dbgfs_open(struct inode *inode,
138 struct file *file)
139{
140 file->private_data = inode->i_private;
141 return 0;
142}
143static ssize_t audio_input_latency_dbgfs_read(struct file *file,
144 char __user *buf, size_t count, loff_t *ppos)
145{
146 snprintf(in_buffer, IN_BUFFER_SIZE, "%ld,%ld,",\
147 in_cont_tv.tv_sec, in_cont_tv.tv_usec);
148 return simple_read_from_buffer(buf, IN_BUFFER_SIZE, ppos,
149 in_buffer, IN_BUFFER_SIZE);
150}
151static ssize_t audio_input_latency_dbgfs_write(struct file *file,
152 const char __user *buf, size_t count, loff_t *ppos)
153{
154 char *temp;
155
156 if (count > 2*sizeof(char))
157 return -EINVAL;
158 else
159 temp = kmalloc(2*sizeof(char), GFP_KERNEL);
160 if (temp) {
161 if (copy_from_user(temp, buf, 2*sizeof(char))) {
162 kfree(temp);
163 return -EFAULT;
164 }
165 if (!strict_strtol(temp, 10, &in_enable_flag)) {
166 kfree(temp);
167 return count;
168 }
169 kfree(temp);
170 }
171 return -EINVAL;
172}
173static const struct file_operations audio_input_latency_debug_fops = {
174 .open = audio_input_latency_dbgfs_open,
175 .read = audio_input_latency_dbgfs_read,
176 .write = audio_input_latency_dbgfs_write
177};
178#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700179struct asm_mmap {
180 atomic_t ref_cnt;
181 atomic_t cmd_state;
182 wait_queue_head_t cmd_wait;
183 void *apr;
184};
185
186static struct asm_mmap this_mmap;
187
188static int q6asm_session_alloc(struct audio_client *ac)
189{
190 int n;
191 mutex_lock(&session_lock);
192 for (n = 1; n <= SESSION_MAX; n++) {
193 if (!session[n]) {
194 session[n] = ac;
195 mutex_unlock(&session_lock);
196 return n;
197 }
198 }
199 mutex_unlock(&session_lock);
200 return -ENOMEM;
201}
202
203static void q6asm_session_free(struct audio_client *ac)
204{
205 pr_debug("%s: sessionid[%d]\n", __func__, ac->session);
Ben Romberger93d4d2d2011-10-19 23:04:02 -0700206 rtac_remove_popp_from_adm_devices(ac->session);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700207 mutex_lock(&session_lock);
208 session[ac->session] = 0;
209 mutex_unlock(&session_lock);
210 ac->session = 0;
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700211 ac->perf_mode = false;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700212 return;
213}
214
215int q6asm_audio_client_buf_free(unsigned int dir,
216 struct audio_client *ac)
217{
218 struct audio_port_data *port;
219 int cnt = 0;
220 int rc = 0;
221 pr_debug("%s: Session id %d\n", __func__, ac->session);
222 mutex_lock(&ac->cmd_lock);
223 if (ac->io_mode == SYNC_IO_MODE) {
224 port = &ac->port[dir];
225 if (!port->buf) {
226 mutex_unlock(&ac->cmd_lock);
227 return 0;
228 }
229 cnt = port->max_buf_cnt - 1;
230
231 if (cnt >= 0) {
232 rc = q6asm_memory_unmap_regions(ac, dir,
233 port->buf[0].size,
234 port->max_buf_cnt);
235 if (rc < 0)
236 pr_err("%s CMD Memory_unmap_regions failed\n",
237 __func__);
238 }
239
240 while (cnt >= 0) {
241 if (port->buf[cnt].data) {
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800242#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
243 ion_unmap_kernel(port->buf[cnt].client,
244 port->buf[cnt].handle);
245 ion_free(port->buf[cnt].client,
246 port->buf[cnt].handle);
247 ion_client_destroy(port->buf[cnt].client);
248#else
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700249 pr_debug("%s:data[%p]phys[%p][%p] cnt[%d] mem_buffer[%p]\n",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700250 __func__, (void *)port->buf[cnt].data,
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700251 (void *)port->buf[cnt].phys,
252 (void *)&port->buf[cnt].phys, cnt,
253 (void *)port->buf[cnt].mem_buffer);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700254 if (IS_ERR((void *)port->buf[cnt].mem_buffer))
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700255 pr_err("%s:mem buffer invalid, error = %ld\n",
256 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700257 PTR_ERR((void *)port->buf[cnt].mem_buffer));
258 else {
Laura Abbottea3e7b62012-04-30 15:59:21 -0700259 if (iounmap(
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700260 port->buf[cnt].mem_buffer) < 0)
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700261 pr_err("%s: unmap buffer failed\n",
262 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700263 }
264 free_contiguous_memory_by_paddr(
265 port->buf[cnt].phys);
266
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800267#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700268 port->buf[cnt].data = NULL;
269 port->buf[cnt].phys = 0;
270 --(port->max_buf_cnt);
271 }
272 --cnt;
273 }
274 kfree(port->buf);
275 port->buf = NULL;
276 }
277 mutex_unlock(&ac->cmd_lock);
278 return 0;
279}
280
281int q6asm_audio_client_buf_free_contiguous(unsigned int dir,
282 struct audio_client *ac)
283{
284 struct audio_port_data *port;
285 int cnt = 0;
286 int rc = 0;
287 pr_debug("%s: Session id %d\n", __func__, ac->session);
288 mutex_lock(&ac->cmd_lock);
289 port = &ac->port[dir];
290 if (!port->buf) {
291 mutex_unlock(&ac->cmd_lock);
292 return 0;
293 }
294 cnt = port->max_buf_cnt - 1;
295
296 if (cnt >= 0) {
Deepa Madiregama7d52a402011-07-13 20:28:36 +0530297 rc = q6asm_memory_unmap(ac, port->buf[0].phys, dir);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700298 if (rc < 0)
299 pr_err("%s CMD Memory_unmap_regions failed\n",
300 __func__);
301 }
302
303 if (port->buf[0].data) {
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800304#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
305 ion_unmap_kernel(port->buf[0].client, port->buf[0].handle);
306 ion_free(port->buf[0].client, port->buf[0].handle);
307 ion_client_destroy(port->buf[0].client);
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700308 pr_debug("%s:data[%p]phys[%p][%p], client[%p] handle[%p]\n",
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800309 __func__,
310 (void *)port->buf[0].data,
311 (void *)port->buf[0].phys,
312 (void *)&port->buf[0].phys,
313 (void *)port->buf[0].client,
314 (void *)port->buf[0].handle);
315#else
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700316 pr_debug("%s:data[%p]phys[%p][%p] mem_buffer[%p]\n",
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700317 __func__,
318 (void *)port->buf[0].data,
319 (void *)port->buf[0].phys,
320 (void *)&port->buf[0].phys,
321 (void *)port->buf[0].mem_buffer);
322 if (IS_ERR((void *)port->buf[0].mem_buffer))
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700323 pr_err("%s:mem buffer invalid, error = %ld\n",
324 __func__,
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700325 PTR_ERR((void *)port->buf[0].mem_buffer));
326 else {
Laura Abbottea3e7b62012-04-30 15:59:21 -0700327 if (iounmap(
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700328 port->buf[0].mem_buffer) < 0)
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700329 pr_err("%s: unmap buffer failed\n", __func__);
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700330 }
331 free_contiguous_memory_by_paddr(port->buf[0].phys);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800332#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700333 }
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700334
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700335 while (cnt >= 0) {
336 port->buf[cnt].data = NULL;
337 port->buf[cnt].phys = 0;
338 cnt--;
339 }
340 port->max_buf_cnt = 0;
341 kfree(port->buf);
342 port->buf = NULL;
343 mutex_unlock(&ac->cmd_lock);
344 return 0;
345}
346
347void q6asm_audio_client_free(struct audio_client *ac)
348{
349 int loopcnt;
350 struct audio_port_data *port;
351 if (!ac || !ac->session)
352 return;
353 pr_debug("%s: Session id %d\n", __func__, ac->session);
354 if (ac->io_mode == SYNC_IO_MODE) {
355 for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
356 port = &ac->port[loopcnt];
357 if (!port->buf)
358 continue;
359 pr_debug("%s:loopcnt = %d\n", __func__, loopcnt);
360 q6asm_audio_client_buf_free(loopcnt, ac);
361 }
362 }
363
364 apr_deregister(ac->apr);
365 q6asm_session_free(ac);
366
367 pr_debug("%s: APR De-Register\n", __func__);
368 if (atomic_read(&this_mmap.ref_cnt) <= 0) {
369 pr_err("%s: APR Common Port Already Closed\n", __func__);
370 goto done;
371 }
372
373 atomic_dec(&this_mmap.ref_cnt);
374 if (atomic_read(&this_mmap.ref_cnt) == 0) {
375 apr_deregister(this_mmap.apr);
376 pr_debug("%s:APR De-Register common port\n", __func__);
377 }
378done:
379 kfree(ac);
380 return;
381}
382
383int q6asm_set_io_mode(struct audio_client *ac, uint32_t mode)
384{
385 if (ac == NULL) {
386 pr_err("%s APR handle NULL\n", __func__);
387 return -EINVAL;
388 }
389 if ((mode == ASYNC_IO_MODE) || (mode == SYNC_IO_MODE)) {
390 ac->io_mode = mode;
391 pr_debug("%s:Set Mode to %d\n", __func__, ac->io_mode);
392 return 0;
393 } else {
394 pr_err("%s:Not an valid IO Mode:%d\n", __func__, ac->io_mode);
395 return -EINVAL;
396 }
397}
398
399struct audio_client *q6asm_audio_client_alloc(app_cb cb, void *priv)
400{
401 struct audio_client *ac;
402 int n;
403 int lcnt = 0;
404
405 ac = kzalloc(sizeof(struct audio_client), GFP_KERNEL);
406 if (!ac)
407 return NULL;
408 n = q6asm_session_alloc(ac);
409 if (n <= 0)
410 goto fail_session;
411 ac->session = n;
412 ac->cb = cb;
413 ac->priv = priv;
414 ac->io_mode = SYNC_IO_MODE;
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700415 ac->perf_mode = false;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700416 ac->apr = apr_register("ADSP", "ASM", \
417 (apr_fn)q6asm_callback,\
418 ((ac->session) << 8 | 0x0001),\
419 ac);
420
421 if (ac->apr == NULL) {
422 pr_err("%s Registration with APR failed\n", __func__);
423 goto fail;
424 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700425 rtac_set_asm_handle(n, ac->apr);
Ben Rombergerfce8f512011-07-18 16:46:09 -0700426
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700427 pr_debug("%s Registering the common port with APR\n", __func__);
428 if (atomic_read(&this_mmap.ref_cnt) == 0) {
429 this_mmap.apr = apr_register("ADSP", "ASM", \
430 (apr_fn)q6asm_mmapcallback,\
431 0x0FFFFFFFF, &this_mmap);
432 if (this_mmap.apr == NULL) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700433 pr_debug("%s Unable to register APR ASM common port\n",
434 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700435 goto fail;
436 }
437 }
438
439 atomic_inc(&this_mmap.ref_cnt);
440 init_waitqueue_head(&ac->cmd_wait);
441 init_waitqueue_head(&ac->time_wait);
442 atomic_set(&ac->time_flag, 1);
443 mutex_init(&ac->cmd_lock);
444 for (lcnt = 0; lcnt <= OUT; lcnt++) {
445 mutex_init(&ac->port[lcnt].lock);
446 spin_lock_init(&ac->port[lcnt].dsp_lock);
447 }
448 atomic_set(&ac->cmd_state, 0);
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +0530449 atomic_set(&ac->cmd_response, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700450
451 pr_debug("%s: session[%d]\n", __func__, ac->session);
452
453 return ac;
454fail:
455 q6asm_audio_client_free(ac);
456 return NULL;
457fail_session:
458 kfree(ac);
459 return NULL;
460}
461
Ben Romberger61754dc2011-10-31 18:25:41 -0700462struct audio_client *q6asm_get_audio_client(int session_id)
463{
464 if ((session_id <= 0) || (session_id > SESSION_MAX)) {
465 pr_err("%s: invalid session: %d\n", __func__, session_id);
466 goto err;
467 }
468
469 if (!session[session_id]) {
470 pr_err("%s: session not active: %d\n", __func__, session_id);
471 goto err;
472 }
473
474 return session[session_id];
475err:
476 return NULL;
477}
478
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700479int q6asm_audio_client_buf_alloc(unsigned int dir,
480 struct audio_client *ac,
481 unsigned int bufsz,
482 unsigned int bufcnt)
483{
484 int cnt = 0;
485 int rc = 0;
486 struct audio_buffer *buf;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800487#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
488 int len;
489#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700490
491 if (!(ac) || ((dir != IN) && (dir != OUT)))
492 return -EINVAL;
493
494 pr_debug("%s: session[%d]bufsz[%d]bufcnt[%d]\n", __func__, ac->session,
495 bufsz, bufcnt);
496
497 if (ac->session <= 0 || ac->session > 8)
498 goto fail;
499
500 if (ac->io_mode == SYNC_IO_MODE) {
501 if (ac->port[dir].buf) {
502 pr_debug("%s: buffer already allocated\n", __func__);
503 return 0;
504 }
505 mutex_lock(&ac->cmd_lock);
506 buf = kzalloc(((sizeof(struct audio_buffer))*bufcnt),
507 GFP_KERNEL);
508
509 if (!buf) {
510 mutex_unlock(&ac->cmd_lock);
511 goto fail;
512 }
513
514 ac->port[dir].buf = buf;
515
516 while (cnt < bufcnt) {
517 if (bufsz > 0) {
518 if (!buf[cnt].data) {
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800519#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
520 buf[cnt].client = msm_ion_client_create
521 (UINT_MAX, "audio_client");
522 if (IS_ERR_OR_NULL((void *)
523 buf[cnt].client)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700524 pr_err("%s: ION create client for AUDIO failed\n",
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800525 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700526 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800527 goto fail;
528 }
529 buf[cnt].handle = ion_alloc
530 (buf[cnt].client, bufsz, SZ_4K,
Hanumant Singh2ac41c92012-08-29 18:39:44 -0700531 (0x1 << ION_AUDIO_HEAP_ID), 0);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800532 if (IS_ERR_OR_NULL((void *)
533 buf[cnt].handle)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700534 pr_err("%s: ION memory allocation for AUDIO failed\n",
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800535 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700536 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800537 goto fail;
538 }
539
540 rc = ion_phys(buf[cnt].client,
541 buf[cnt].handle,
542 (ion_phys_addr_t *)
543 &buf[cnt].phys,
544 (size_t *)&len);
545 if (rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700546 pr_err("%s: ION Get Physical for AUDIO failed, rc = %d\n",
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800547 __func__, rc);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700548 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800549 goto fail;
550 }
551
552 buf[cnt].data = ion_map_kernel
Mitchel Humpherys456e2682012-09-12 14:42:50 -0700553 (buf[cnt].client, buf[cnt].handle);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800554 if (IS_ERR_OR_NULL((void *)
555 buf[cnt].data)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700556 pr_err("%s: ION memory mapping for AUDIO failed\n",
557 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700558 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800559 goto fail;
560 }
561 memset((void *)buf[cnt].data, 0, bufsz);
562#else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700563 unsigned int flags = 0;
564 buf[cnt].phys =
565 allocate_contiguous_ebi_nomap(bufsz,
566 SZ_4K);
567 if (!buf[cnt].phys) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700568 pr_err("%s:Buf alloc failed size=%d\n",
569 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700570 bufsz);
571 mutex_unlock(&ac->cmd_lock);
572 goto fail;
573 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700574 buf[cnt].mem_buffer =
Laura Abbottea3e7b62012-04-30 15:59:21 -0700575 ioremap(buf[cnt].phys, bufsz);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700576 if (IS_ERR(
577 (void *)buf[cnt].mem_buffer)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700578 pr_err("%s:map_buffer failed, error = %ld\n",
579 __func__,
580 PTR_ERR((void *)buf[cnt].mem_buffer));
Jayasena Sangaraboina466e6b92012-01-17 21:10:55 -0800581 mutex_unlock(&ac->cmd_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700582 goto fail;
583 }
584 buf[cnt].data =
Laura Abbottea3e7b62012-04-30 15:59:21 -0700585 buf[cnt].mem_buffer;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700586 if (!buf[cnt].data) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700587 pr_err("%s:invalid vaddr, iomap failed\n",
588 __func__);
Jayasena Sangaraboina466e6b92012-01-17 21:10:55 -0800589 mutex_unlock(&ac->cmd_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700590 goto fail;
591 }
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800592#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700593 buf[cnt].used = 1;
594 buf[cnt].size = bufsz;
595 buf[cnt].actual_size = bufsz;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800596 pr_debug("%s data[%p]phys[%p][%p]\n",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700597 __func__,
598 (void *)buf[cnt].data,
599 (void *)buf[cnt].phys,
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800600 (void *)&buf[cnt].phys);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700601 cnt++;
602 }
603 }
604 }
605 ac->port[dir].max_buf_cnt = cnt;
606
607 mutex_unlock(&ac->cmd_lock);
608 rc = q6asm_memory_map_regions(ac, dir, bufsz, cnt);
609 if (rc < 0) {
610 pr_err("%s:CMD Memory_map_regions failed\n", __func__);
611 goto fail;
612 }
613 }
614 return 0;
615fail:
616 q6asm_audio_client_buf_free(dir, ac);
617 return -EINVAL;
618}
619
620int q6asm_audio_client_buf_alloc_contiguous(unsigned int dir,
621 struct audio_client *ac,
622 unsigned int bufsz,
623 unsigned int bufcnt)
624{
625 int cnt = 0;
626 int rc = 0;
627 struct audio_buffer *buf;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800628#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
629 int len;
630#else
631 int flags = 0;
632#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700633 if (!(ac) || ((dir != IN) && (dir != OUT)))
634 return -EINVAL;
635
636 pr_debug("%s: session[%d]bufsz[%d]bufcnt[%d]\n",
637 __func__, ac->session,
638 bufsz, bufcnt);
639
640 if (ac->session <= 0 || ac->session > 8)
641 goto fail;
642
643 if (ac->port[dir].buf) {
644 pr_debug("%s: buffer already allocated\n", __func__);
645 return 0;
646 }
647 mutex_lock(&ac->cmd_lock);
648 buf = kzalloc(((sizeof(struct audio_buffer))*bufcnt),
649 GFP_KERNEL);
650
651 if (!buf) {
652 mutex_unlock(&ac->cmd_lock);
653 goto fail;
654 }
655
656 ac->port[dir].buf = buf;
657
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800658#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
659 buf[0].client = msm_ion_client_create(UINT_MAX, "audio_client");
660 if (IS_ERR_OR_NULL((void *)buf[0].client)) {
661 pr_err("%s: ION create client for AUDIO failed\n", __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700662 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800663 goto fail;
664 }
665 buf[0].handle = ion_alloc(buf[0].client, bufsz * bufcnt, SZ_4K,
Hanumant Singh2ac41c92012-08-29 18:39:44 -0700666 (0x1 << ION_AUDIO_HEAP_ID), 0);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800667 if (IS_ERR_OR_NULL((void *) buf[0].handle)) {
668 pr_err("%s: ION memory allocation for AUDIO failed\n",
669 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700670 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800671 goto fail;
672 }
673
674 rc = ion_phys(buf[0].client, buf[0].handle,
675 (ion_phys_addr_t *)&buf[0].phys, (size_t *)&len);
676 if (rc) {
677 pr_err("%s: ION Get Physical for AUDIO failed, rc = %d\n",
678 __func__, rc);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700679 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800680 goto fail;
681 }
682
Mitchel Humpherys456e2682012-09-12 14:42:50 -0700683 buf[0].data = ion_map_kernel(buf[0].client, buf[0].handle);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800684 if (IS_ERR_OR_NULL((void *) buf[0].data)) {
685 pr_err("%s: ION memory mapping for AUDIO failed\n", __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700686 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800687 goto fail;
688 }
689 memset((void *)buf[0].data, 0, (bufsz * bufcnt));
690#else
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700691 buf[0].phys = allocate_contiguous_ebi_nomap(bufsz * bufcnt,
692 SZ_4K);
693 if (!buf[0].phys) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700694 pr_err("%s:Buf alloc failed size=%d, bufcnt=%d\n",
695 __func__, bufsz, bufcnt);
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700696 mutex_unlock(&ac->cmd_lock);
697 goto fail;
698 }
699
Laura Abbottea3e7b62012-04-30 15:59:21 -0700700 buf[0].mem_buffer = ioremap(buf[0].phys, bufsz * bufcnt);
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700701 if (IS_ERR((void *)buf[cnt].mem_buffer)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700702 pr_err("%s:map_buffer failed, error = %ld\n",
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700703 __func__, PTR_ERR((void *)buf[0].mem_buffer));
704
705 mutex_unlock(&ac->cmd_lock);
706 goto fail;
707 }
Laura Abbottea3e7b62012-04-30 15:59:21 -0700708 buf[0].data = buf[0].mem_buffer;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800709#endif
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700710 if (!buf[0].data) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700711 pr_err("%s:invalid vaddr, iomap failed\n", __func__);
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700712 mutex_unlock(&ac->cmd_lock);
713 goto fail;
714 }
715
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700716 buf[0].used = dir ^ 1;
717 buf[0].size = bufsz;
718 buf[0].actual_size = bufsz;
719 cnt = 1;
720 while (cnt < bufcnt) {
721 if (bufsz > 0) {
722 buf[cnt].data = buf[0].data + (cnt * bufsz);
723 buf[cnt].phys = buf[0].phys + (cnt * bufsz);
724 if (!buf[cnt].data) {
725 pr_err("%s Buf alloc failed\n",
726 __func__);
727 mutex_unlock(&ac->cmd_lock);
728 goto fail;
729 }
730 buf[cnt].used = dir ^ 1;
731 buf[cnt].size = bufsz;
732 buf[cnt].actual_size = bufsz;
733 pr_debug("%s data[%p]phys[%p][%p]\n", __func__,
734 (void *)buf[cnt].data,
735 (void *)buf[cnt].phys,
736 (void *)&buf[cnt].phys);
737 }
738 cnt++;
739 }
740 ac->port[dir].max_buf_cnt = cnt;
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -0700741
742 pr_debug("%s ac->port[%d].max_buf_cnt[%d]\n", __func__, dir,
743 ac->port[dir].max_buf_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700744 mutex_unlock(&ac->cmd_lock);
745 rc = q6asm_memory_map(ac, buf[0].phys, dir, bufsz, cnt);
746 if (rc < 0) {
747 pr_err("%s:CMD Memory_map_regions failed\n", __func__);
748 goto fail;
749 }
750 return 0;
751fail:
752 q6asm_audio_client_buf_free_contiguous(dir, ac);
753 return -EINVAL;
754}
755
756static int32_t q6asm_mmapcallback(struct apr_client_data *data, void *priv)
757{
758 uint32_t token;
759 uint32_t *payload = data->payload;
760
761 if (data->opcode == RESET_EVENTS) {
762 pr_debug("%s: Reset event is received: %d %d apr[%p]\n",
763 __func__,
764 data->reset_event,
765 data->reset_proc,
766 this_mmap.apr);
767 apr_reset(this_mmap.apr);
768 this_mmap.apr = NULL;
769 atomic_set(&this_mmap.cmd_state, 0);
770 return 0;
771 }
772
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700773 pr_debug("%s:ptr0[0x%x]ptr1[0x%x]opcode[0x%x] token[0x%x]payload_s[%d] src[%d] dest[%d]\n",
774 __func__, payload[0], payload[1], data->opcode, data->token,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700775 data->payload_size, data->src_port, data->dest_port);
776
777 if (data->opcode == APR_BASIC_RSP_RESULT) {
778 token = data->token;
779 switch (payload[0]) {
780 case ASM_SESSION_CMD_MEMORY_MAP:
781 case ASM_SESSION_CMD_MEMORY_UNMAP:
782 case ASM_SESSION_CMD_MEMORY_MAP_REGIONS:
783 case ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS:
784 pr_debug("%s:command[0x%x]success [0x%x]\n",
785 __func__, payload[0], payload[1]);
786 if (atomic_read(&this_mmap.cmd_state)) {
787 atomic_set(&this_mmap.cmd_state, 0);
788 wake_up(&this_mmap.cmd_wait);
789 }
790 break;
791 default:
792 pr_debug("%s:command[0x%x] not expecting rsp\n",
793 __func__, payload[0]);
794 break;
795 }
796 }
797 return 0;
798}
799
Jay Wangcd1d37d2012-10-03 16:17:18 -0700800static int32_t is_no_wait_cmd_rsp(uint32_t opcode, uint32_t *cmd_type)
801{
802 if (opcode == APR_BASIC_RSP_RESULT) {
803 if (cmd_type != NULL) {
804 switch (cmd_type[0]) {
805 case ASM_SESSION_CMD_RUN:
806 case ASM_SESSION_CMD_PAUSE:
807 case ASM_DATA_CMD_EOS:
808 return 1;
809 default:
810 break;
811 }
812 } else
813 pr_err("%s: null pointer!", __func__);
814 } else if (opcode == ASM_DATA_CMDRSP_EOS)
815 return 1;
816
817 return 0;
818}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700819
820static int32_t q6asm_callback(struct apr_client_data *data, void *priv)
821{
822 int i = 0;
823 struct audio_client *ac = (struct audio_client *)priv;
824 uint32_t token;
825 unsigned long dsp_flags;
826 uint32_t *payload;
Jay Wang0668d1062012-07-11 18:53:21 -0700827 uint32_t wakeup_flag = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700828
829
830 if ((ac == NULL) || (data == NULL)) {
831 pr_err("ac or priv NULL\n");
832 return -EINVAL;
833 }
834 if (ac->session <= 0 || ac->session > 8) {
835 pr_err("%s:Session ID is invalid, session = %d\n", __func__,
836 ac->session);
837 return -EINVAL;
838 }
Jay Wangcd1d37d2012-10-03 16:17:18 -0700839
840 payload = data->payload;
841 if ((atomic_read(&ac->nowait_cmd_cnt) > 0) &&
842 is_no_wait_cmd_rsp(data->opcode, payload)) {
Jay Wang0668d1062012-07-11 18:53:21 -0700843 pr_debug("%s: nowait_cmd_cnt %d\n",
844 __func__,
845 atomic_read(&ac->nowait_cmd_cnt));
846 atomic_dec(&ac->nowait_cmd_cnt);
847 wakeup_flag = 0;
848 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700849
850 if (data->opcode == RESET_EVENTS) {
851 pr_debug("q6asm_callback: Reset event is received: %d %d apr[%p]\n",
852 data->reset_event, data->reset_proc, ac->apr);
Laxminath Kasam692c6542012-02-21 11:17:47 +0530853 if (ac->cb)
854 ac->cb(data->opcode, data->token,
855 (uint32_t *)data->payload, ac->priv);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700856 apr_reset(ac->apr);
857 return 0;
858 }
859
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700860 pr_debug("%s: session[%d]opcode[0x%x] token[0x%x]payload_s[%d] src[%d] dest[%d]\n",
861 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700862 ac->session, data->opcode,
863 data->token, data->payload_size, data->src_port,
864 data->dest_port);
865
866 if (data->opcode == APR_BASIC_RSP_RESULT) {
867 token = data->token;
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700868 pr_debug("%s payload[0]:%x", __func__, payload[0]);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700869 switch (payload[0]) {
870 case ASM_STREAM_CMD_SET_PP_PARAMS:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700871 if (rtac_make_asm_callback(ac->session, payload,
872 data->payload_size))
873 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700874 case ASM_SESSION_CMD_PAUSE:
875 case ASM_DATA_CMD_EOS:
876 case ASM_STREAM_CMD_CLOSE:
877 case ASM_STREAM_CMD_FLUSH:
878 case ASM_SESSION_CMD_RUN:
879 case ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS:
880 case ASM_STREAM_CMD_FLUSH_READBUFS:
881 pr_debug("%s:Payload = [0x%x]\n", __func__, payload[0]);
882 if (token != ac->session) {
883 pr_err("%s:Invalid session[%d] rxed expected[%d]",
884 __func__, token, ac->session);
885 return -EINVAL;
886 }
887 case ASM_STREAM_CMD_OPEN_READ:
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700888 case ASM_STREAM_CMD_OPEN_READ_V2_1:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700889 case ASM_STREAM_CMD_OPEN_WRITE:
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700890 case ASM_STREAM_CMD_OPEN_WRITE_V2_1:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700891 case ASM_STREAM_CMD_OPEN_READWRITE:
892 case ASM_DATA_CMD_MEDIA_FORMAT_UPDATE:
893 case ASM_STREAM_CMD_SET_ENCDEC_PARAM:
Santosh Mardi23321202012-03-22 04:33:25 +0530894 case ASM_STREAM_CMD_OPEN_WRITE_COMPRESSED:
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -0700895 case ASM_STREAM_CMD_OPEN_READ_COMPRESSED:
Laxminath Kasamf16d3fd2012-12-19 14:54:14 +0530896 if (payload[0] == ASM_STREAM_CMD_CLOSE) {
897 atomic_set(&ac->cmd_close_state, 0);
898 wake_up(&ac->cmd_wait);
899 } else if (atomic_read(&ac->cmd_state) &&
900 wakeup_flag) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700901 atomic_set(&ac->cmd_state, 0);
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700902 if (payload[1] == ADSP_EUNSUPPORTED) {
903 pr_debug("paload[1]:%d unsupported",
904 payload[1]);
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +0530905 atomic_set(&ac->cmd_response, 1);
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700906 }
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +0530907 else
908 atomic_set(&ac->cmd_response, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700909 wake_up(&ac->cmd_wait);
910 }
911 if (ac->cb)
912 ac->cb(data->opcode, data->token,
913 (uint32_t *)data->payload, ac->priv);
914 break;
915 default:
916 pr_debug("%s:command[0x%x] not expecting rsp\n",
917 __func__, payload[0]);
918 break;
919 }
920 return 0;
921 }
922
923 switch (data->opcode) {
924 case ASM_DATA_EVENT_WRITE_DONE:{
925 struct audio_port_data *port = &ac->port[IN];
926 pr_debug("%s: Rxed opcode[0x%x] status[0x%x] token[%d]",
927 __func__, payload[0], payload[1],
928 data->token);
929 if (ac->io_mode == SYNC_IO_MODE) {
930 if (port->buf == NULL) {
931 pr_err("%s: Unexpected Write Done\n",
932 __func__);
933 return -EINVAL;
934 }
935 spin_lock_irqsave(&port->dsp_lock, dsp_flags);
936 if (port->buf[data->token].phys !=
937 payload[0]) {
938 pr_err("Buf expected[%p]rxed[%p]\n",\
939 (void *)port->buf[data->token].phys,\
940 (void *)payload[0]);
941 spin_unlock_irqrestore(&port->dsp_lock,
942 dsp_flags);
943 return -EINVAL;
944 }
945 token = data->token;
946 port->buf[token].used = 1;
947 spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
Rajesha Kini3498c932011-07-19 19:58:27 +0530948#ifdef CONFIG_DEBUG_FS
949 if (out_enable_flag) {
950 /* For first Write done log the time and reset
951 out_cold_index*/
952 if (out_cold_index != 1) {
953 do_gettimeofday(&out_cold_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700954 pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",
955 out_cold_tv.tv_sec,
Rajesha Kini3498c932011-07-19 19:58:27 +0530956 out_cold_tv.tv_usec);
957 out_cold_index = 1;
958 }
959 pr_debug("out_enable_flag %ld",\
960 out_enable_flag);
961 }
962#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700963 for (i = 0; i < port->max_buf_cnt; i++)
964 pr_debug("%d ", port->buf[i].used);
965
966 }
967 break;
968 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700969 case ASM_STREAM_CMDRSP_GET_PP_PARAMS:
970 rtac_make_asm_callback(ac->session, payload,
971 data->payload_size);
972 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700973 case ASM_DATA_EVENT_READ_DONE:{
974
975 struct audio_port_data *port = &ac->port[OUT];
Rajesha Kini3498c932011-07-19 19:58:27 +0530976#ifdef CONFIG_DEBUG_FS
977 if (in_enable_flag) {
978 /* when in_cont_index == 7, DSP would be
979 * writing into the 8th 512 byte buffer and this
980 * timestamp is tapped here.Once done it then writes
981 * to 9th 512 byte buffer.These two buffers(8th, 9th)
982 * reach the test application in 5th iteration and that
983 * timestamp is tapped at user level. The difference
984 * of these two timestamps gives us the time between
985 * the time at which dsp started filling the sample
986 * required and when it reached the test application.
987 * Hence continuous input latency
988 */
989 if (in_cont_index == 7) {
990 do_gettimeofday(&in_cont_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700991 pr_err("In_CONT:previous read buffer done at %ld sec %ld microsec\n",
Sriranjan Srikantam74753532011-10-03 14:48:37 -0700992 in_cont_tv.tv_sec, in_cont_tv.tv_usec);
Rajesha Kini3498c932011-07-19 19:58:27 +0530993 }
994 }
995#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700996 pr_debug("%s:R-D: status=%d buff_add=%x act_size=%d offset=%d\n",
997 __func__, payload[READDONE_IDX_STATUS],
998 payload[READDONE_IDX_BUFFER],
999 payload[READDONE_IDX_SIZE],
1000 payload[READDONE_IDX_OFFSET]);
1001 pr_debug("%s:R-D:msw_ts=%d lsw_ts=%d flags=%d id=%d num=%d\n",
1002 __func__, payload[READDONE_IDX_MSW_TS],
1003 payload[READDONE_IDX_LSW_TS],
1004 payload[READDONE_IDX_FLAGS],
1005 payload[READDONE_IDX_ID],
1006 payload[READDONE_IDX_NUMFRAMES]);
Rajesha Kini3498c932011-07-19 19:58:27 +05301007#ifdef CONFIG_DEBUG_FS
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001008 if (in_enable_flag)
Rajesha Kini3498c932011-07-19 19:58:27 +05301009 in_cont_index++;
Rajesha Kini3498c932011-07-19 19:58:27 +05301010#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001011 if (ac->io_mode == SYNC_IO_MODE) {
1012 if (port->buf == NULL) {
1013 pr_err("%s: Unexpected Write Done\n", __func__);
1014 return -EINVAL;
1015 }
1016 spin_lock_irqsave(&port->dsp_lock, dsp_flags);
1017 token = data->token;
1018 port->buf[token].used = 0;
1019 if (port->buf[token].phys !=
1020 payload[READDONE_IDX_BUFFER]) {
1021 pr_err("Buf expected[%p]rxed[%p]\n",\
1022 (void *)port->buf[token].phys,\
1023 (void *)payload[READDONE_IDX_BUFFER]);
1024 spin_unlock_irqrestore(&port->dsp_lock,
1025 dsp_flags);
1026 break;
1027 }
1028 port->buf[token].actual_size =
1029 payload[READDONE_IDX_SIZE];
1030 spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
1031 }
1032 break;
1033 }
1034 case ASM_DATA_EVENT_EOS:
1035 case ASM_DATA_CMDRSP_EOS:
1036 pr_debug("%s:EOS ACK received: rxed opcode[0x%x]\n",
1037 __func__, data->opcode);
1038 break;
1039 case ASM_STREAM_CMDRSP_GET_ENCDEC_PARAM:
1040 break;
1041 case ASM_SESSION_EVENT_TX_OVERFLOW:
1042 pr_err("ASM_SESSION_EVENT_TX_OVERFLOW\n");
1043 break;
1044 case ASM_SESSION_CMDRSP_GET_SESSION_TIME:
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001045 pr_debug("%s: ASM_SESSION_CMDRSP_GET_SESSION_TIME, payload[0] = %d, payload[1] = %d, payload[2] = %d\n",
1046 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001047 payload[0], payload[1], payload[2]);
1048 ac->time_stamp = (uint64_t)(((uint64_t)payload[1] << 32) |
1049 payload[2]);
1050 if (atomic_read(&ac->time_flag)) {
1051 atomic_set(&ac->time_flag, 0);
1052 wake_up(&ac->time_wait);
1053 }
1054 break;
1055 case ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY:
Deepa Madiregama55cbf782011-09-10 05:44:39 +05301056 case ASM_DATA_EVENT_ENC_SR_CM_NOTIFY:
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001057 pr_debug("%s: ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY, payload[0] = %d, payload[1] = %d, payload[2] = %d, payload[3] = %d\n",
1058 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001059 payload[0], payload[1], payload[2],
1060 payload[3]);
1061 break;
1062 }
1063 if (ac->cb)
1064 ac->cb(data->opcode, data->token,
1065 data->payload, ac->priv);
1066
1067 return 0;
1068}
1069
1070void *q6asm_is_cpu_buf_avail(int dir, struct audio_client *ac, uint32_t *size,
1071 uint32_t *index)
1072{
1073 void *data;
1074 unsigned char idx;
1075 struct audio_port_data *port;
1076
1077 if (!ac || ((dir != IN) && (dir != OUT)))
1078 return NULL;
1079
1080 if (ac->io_mode == SYNC_IO_MODE) {
1081 port = &ac->port[dir];
1082
1083 mutex_lock(&port->lock);
1084 idx = port->cpu_buf;
1085 if (port->buf == NULL) {
1086 pr_debug("%s:Buffer pointer null\n", __func__);
Jayasena Sangaraboina466e6b92012-01-17 21:10:55 -08001087 mutex_unlock(&port->lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001088 return NULL;
1089 }
1090 /* dir 0: used = 0 means buf in use
1091 dir 1: used = 1 means buf in use */
1092 if (port->buf[idx].used == dir) {
1093 /* To make it more robust, we could loop and get the
1094 next avail buf, its risky though */
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001095 pr_debug("%s:Next buf idx[0x%x] not available,dir[%d]\n",
1096 __func__, idx, dir);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001097 mutex_unlock(&port->lock);
1098 return NULL;
1099 }
1100 *size = port->buf[idx].actual_size;
1101 *index = port->cpu_buf;
1102 data = port->buf[idx].data;
1103 pr_debug("%s:session[%d]index[%d] data[%p]size[%d]\n",
1104 __func__,
1105 ac->session,
1106 port->cpu_buf,
1107 data, *size);
1108 /* By default increase the cpu_buf cnt
1109 user accesses this function,increase cpu
1110 buf(to avoid another api)*/
1111 port->buf[idx].used = dir;
1112 port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1));
1113 mutex_unlock(&port->lock);
1114 return data;
1115 }
1116 return NULL;
1117}
1118
Jay Wang9cf59a02011-08-10 16:58:40 -07001119void *q6asm_is_cpu_buf_avail_nolock(int dir, struct audio_client *ac,
1120 uint32_t *size, uint32_t *index)
1121{
1122 void *data;
1123 unsigned char idx;
1124 struct audio_port_data *port;
1125
1126 if (!ac || ((dir != IN) && (dir != OUT)))
1127 return NULL;
1128
1129 port = &ac->port[dir];
1130
1131 idx = port->cpu_buf;
1132 if (port->buf == NULL) {
1133 pr_debug("%s:Buffer pointer null\n", __func__);
1134 return NULL;
1135 }
1136 /*
1137 * dir 0: used = 0 means buf in use
1138 * dir 1: used = 1 means buf in use
1139 */
1140 if (port->buf[idx].used == dir) {
1141 /*
1142 * To make it more robust, we could loop and get the
1143 * next avail buf, its risky though
1144 */
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001145 pr_debug("%s:Next buf idx[0x%x] not available, dir[%d]\n",
1146 __func__, idx, dir);
Jay Wang9cf59a02011-08-10 16:58:40 -07001147 return NULL;
1148 }
1149 *size = port->buf[idx].actual_size;
1150 *index = port->cpu_buf;
1151 data = port->buf[idx].data;
1152 pr_debug("%s:session[%d]index[%d] data[%p]size[%d]\n",
1153 __func__, ac->session, port->cpu_buf,
1154 data, *size);
1155 /*
1156 * By default increase the cpu_buf cnt
1157 * user accesses this function,increase cpu
1158 * buf(to avoid another api)
1159 */
1160 port->buf[idx].used = dir;
1161 port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1));
1162 return data;
1163}
1164
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001165int q6asm_is_dsp_buf_avail(int dir, struct audio_client *ac)
1166{
1167 int ret = -1;
1168 struct audio_port_data *port;
1169 uint32_t idx;
1170
1171 if (!ac || (dir != OUT))
1172 return ret;
1173
1174 if (ac->io_mode == SYNC_IO_MODE) {
1175 port = &ac->port[dir];
1176
1177 mutex_lock(&port->lock);
1178 idx = port->dsp_buf;
1179
1180 if (port->buf[idx].used == (dir ^ 1)) {
1181 /* To make it more robust, we could loop and get the
1182 next avail buf, its risky though */
1183 pr_err("Next buf idx[0x%x] not available, dir[%d]\n",
1184 idx, dir);
1185 mutex_unlock(&port->lock);
1186 return ret;
1187 }
1188 pr_debug("%s: session[%d]dsp_buf=%d cpu_buf=%d\n", __func__,
1189 ac->session, port->dsp_buf, port->cpu_buf);
1190 ret = ((port->dsp_buf != port->cpu_buf) ? 0 : -1);
1191 mutex_unlock(&port->lock);
1192 }
1193 return ret;
1194}
1195
1196static void q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
1197 uint32_t pkt_size, uint32_t cmd_flg)
1198{
1199 pr_debug("%s:session=%d pkt size=%d cmd_flg=%d\n", __func__, pkt_size,
1200 cmd_flg, ac->session);
1201 mutex_lock(&ac->cmd_lock);
1202 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
1203 APR_HDR_LEN(sizeof(struct apr_hdr)),\
1204 APR_PKT_VER);
1205 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
1206 hdr->src_domain = APR_DOMAIN_APPS;
1207 hdr->dest_svc = APR_SVC_ASM;
1208 hdr->dest_domain = APR_DOMAIN_ADSP;
1209 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
1210 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
1211 if (cmd_flg) {
1212 hdr->token = ac->session;
1213 atomic_set(&ac->cmd_state, 1);
1214 }
1215 hdr->pkt_size = pkt_size;
1216 mutex_unlock(&ac->cmd_lock);
1217 return;
1218}
1219
1220static void q6asm_add_mmaphdr(struct apr_hdr *hdr, uint32_t pkt_size,
1221 uint32_t cmd_flg)
1222{
1223 pr_debug("%s:pkt size=%d cmd_flg=%d\n", __func__, pkt_size, cmd_flg);
1224 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
1225 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1226 hdr->src_port = 0;
1227 hdr->dest_port = 0;
1228 if (cmd_flg) {
1229 hdr->token = 0;
1230 atomic_set(&this_mmap.cmd_state, 1);
1231 }
1232 hdr->pkt_size = pkt_size;
1233 return;
1234}
1235
1236int q6asm_open_read(struct audio_client *ac,
1237 uint32_t format)
1238{
1239 int rc = 0x00;
1240 struct asm_stream_cmd_open_read open;
Rajesha Kini3498c932011-07-19 19:58:27 +05301241#ifdef CONFIG_DEBUG_FS
1242 in_cont_index = 0;
1243#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001244 if ((ac == NULL) || (ac->apr == NULL)) {
1245 pr_err("%s: APR handle NULL\n", __func__);
1246 return -EINVAL;
1247 }
1248 pr_debug("%s:session[%d]", __func__, ac->session);
1249
1250 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1251 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ;
1252 /* Stream prio : High, provide meta info with encoded frames */
1253 open.src_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1254
1255 open.pre_proc_top = get_asm_topology();
1256 if (open.pre_proc_top == 0)
1257 open.pre_proc_top = DEFAULT_POPP_TOPOLOGY;
1258
1259 switch (format) {
1260 case FORMAT_LINEAR_PCM:
1261 open.uMode = STREAM_PRIORITY_HIGH;
1262 open.format = LINEAR_PCM;
1263 break;
Mingming Yin647e9ea2012-03-17 19:56:10 -07001264 case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
1265 open.uMode = STREAM_PRIORITY_HIGH;
1266 open.format = MULTI_CHANNEL_PCM;
1267 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001268 case FORMAT_MPEG4_AAC:
1269 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1270 open.format = MPEG4_AAC;
1271 break;
1272 case FORMAT_V13K:
1273 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1274 open.format = V13K_FS;
1275 break;
1276 case FORMAT_EVRC:
1277 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1278 open.format = EVRC_FS;
1279 break;
1280 case FORMAT_AMRNB:
1281 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1282 open.format = AMRNB_FS;
1283 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301284 case FORMAT_AMRWB:
1285 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1286 open.format = AMRWB_FS;
1287 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001288 default:
1289 pr_err("Invalid format[%d]\n", format);
1290 goto fail_cmd;
1291 }
1292 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1293 if (rc < 0) {
1294 pr_err("open failed op[0x%x]rc[%d]\n", \
1295 open.hdr.opcode, rc);
1296 goto fail_cmd;
1297 }
1298 rc = wait_event_timeout(ac->cmd_wait,
1299 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1300 if (!rc) {
1301 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1302 rc);
1303 goto fail_cmd;
1304 }
1305 return 0;
1306fail_cmd:
1307 return -EINVAL;
1308}
1309
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -07001310int q6asm_open_read_v2_1(struct audio_client *ac,
1311 uint32_t format)
1312{
1313 int rc = 0x00;
1314 struct asm_stream_cmd_open_read_v2_1 open;
1315#ifdef CONFIG_DEBUG_FS
1316 in_cont_index = 0;
1317#endif
1318 if ((ac == NULL) || (ac->apr == NULL)) {
1319 pr_err("%s: APR handle NULL\n", __func__);
1320 return -EINVAL;
1321 }
1322 pr_debug("%s:session[%d]", __func__, ac->session);
1323
1324 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1325 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ_V2_1;
1326 open.src_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1327 open.pre_proc_top = get_asm_topology();
1328 if (open.pre_proc_top == 0)
1329 open.pre_proc_top = DEFAULT_POPP_TOPOLOGY;
1330
1331 switch (format) {
1332 case FORMAT_LINEAR_PCM:
1333 open.uMode = STREAM_PRIORITY_HIGH;
1334 open.format = LINEAR_PCM;
1335 break;
1336 case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
1337 open.uMode = STREAM_PRIORITY_HIGH;
1338 open.format = MULTI_CHANNEL_PCM;
1339 break;
1340 case FORMAT_MPEG4_AAC:
1341 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1342 open.format = MPEG4_AAC;
1343 break;
1344 case FORMAT_V13K:
1345 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1346 open.format = V13K_FS;
1347 break;
1348 case FORMAT_EVRC:
1349 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1350 open.format = EVRC_FS;
1351 break;
1352 case FORMAT_AMRNB:
1353 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1354 open.format = AMRNB_FS;
1355 break;
1356 case FORMAT_AMRWB:
1357 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1358 open.format = AMRWB_FS;
1359 break;
1360 default:
1361 pr_err("Invalid format[%d]\n", format);
1362 goto fail_cmd;
1363 }
1364 open.uMode = ASM_OPEN_READ_PERF_MODE_BIT;
1365 open.bits_per_sample = PCM_BITS_PER_SAMPLE;
1366 open.reserved = 0;
1367 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1368 if (rc < 0) {
1369 pr_err("open failed op[0x%x]rc[%d]\n", \
1370 open.hdr.opcode, rc);
1371 goto fail_cmd;
1372 }
1373 rc = wait_event_timeout(ac->cmd_wait,
1374 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1375 if (!rc) {
1376 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1377 rc);
1378 goto fail_cmd;
1379 }
1380 return 0;
1381fail_cmd:
1382 return -EINVAL;
1383}
1384
1385
Subhash Chandra Bose Naripeddy694b7d92012-06-20 20:46:13 -07001386int q6asm_open_read_compressed(struct audio_client *ac,
1387 uint32_t frames_per_buffer, uint32_t meta_data_mode)
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -07001388{
1389 int rc = 0x00;
1390 struct asm_stream_cmd_open_read_compressed open;
1391#ifdef CONFIG_DEBUG_FS
1392 in_cont_index = 0;
1393#endif
1394 if ((ac == NULL) || (ac->apr == NULL)) {
1395 pr_err("%s: APR handle NULL\n", __func__);
1396 return -EINVAL;
1397 }
1398 pr_debug("%s:session[%d]", __func__, ac->session);
1399
1400 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1401 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ_COMPRESSED;
1402 /* hardcoded as following*/
Subhash Chandra Bose Naripeddy694b7d92012-06-20 20:46:13 -07001403 open.frame_per_buf = frames_per_buffer;
1404 open.uMode = meta_data_mode;
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -07001405
1406 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1407 if (rc < 0) {
1408 pr_err("open failed op[0x%x]rc[%d]\n", open.hdr.opcode, rc);
1409 goto fail_cmd;
1410 }
1411 rc = wait_event_timeout(ac->cmd_wait,
1412 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1413 if (!rc) {
1414 pr_err("%s: timeout. waited for OPEN_READ_COMPRESSED rc[%d]\n",
1415 __func__, rc);
1416 goto fail_cmd;
1417 }
1418 return 0;
1419fail_cmd:
1420 return -EINVAL;
1421}
1422
Santosh Mardi23321202012-03-22 04:33:25 +05301423int q6asm_open_write_compressed(struct audio_client *ac, uint32_t format)
1424{
1425 int rc = 0x00;
1426 struct asm_stream_cmd_open_write_compressed open;
1427
1428 if ((ac == NULL) || (ac->apr == NULL)) {
1429 pr_err("%s: APR handle NULL\n", __func__);
1430 return -EINVAL;
1431 }
1432 pr_debug("%s: session[%d] wr_format[0x%x]", __func__, ac->session,
1433 format);
1434
1435 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1436
1437 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_COMPRESSED;
1438
1439 switch (format) {
1440 case FORMAT_AC3:
1441 open.format = AC3_DECODER;
1442 break;
1443 case FORMAT_EAC3:
1444 open.format = EAC3_DECODER;
1445 break;
1446 case FORMAT_MP3:
1447 open.format = MP3;
1448 break;
1449 case FORMAT_DTS:
1450 open.format = DTS;
1451 break;
Srikanth Uyyala66f781a2012-06-13 23:23:25 +05301452 case FORMAT_DTS_LBR:
1453 open.format = DTS_LBR;
1454 break;
Santosh Mardi23321202012-03-22 04:33:25 +05301455 case FORMAT_AAC:
1456 open.format = MPEG4_AAC;
1457 break;
1458 case FORMAT_ATRAC:
1459 open.format = ATRAC;
1460 break;
1461 case FORMAT_WMA_V10PRO:
1462 open.format = WMA_V10PRO;
1463 break;
1464 case FORMAT_MAT:
1465 open.format = MAT;
1466 break;
1467 default:
1468 pr_err("%s: Invalid format[%d]\n", __func__, format);
1469 goto fail_cmd;
1470 }
1471 /*Below flag indicates the DSP that Compressed audio input
1472 stream is not IEC 61937 or IEC 60958 packetizied*/
1473 open.flags = 0x00000000;
1474 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1475 if (rc < 0) {
1476 pr_err("%s: open failed op[0x%x]rc[%d]\n", \
1477 __func__, open.hdr.opcode, rc);
1478 goto fail_cmd;
1479 }
1480 rc = wait_event_timeout(ac->cmd_wait,
1481 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1482 if (!rc) {
1483 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1484 rc);
1485 goto fail_cmd;
1486 }
1487 return 0;
1488fail_cmd:
1489 return -EINVAL;
1490}
1491
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001492int q6asm_open_write(struct audio_client *ac, uint32_t format)
1493{
1494 int rc = 0x00;
1495 struct asm_stream_cmd_open_write open;
1496
1497 if ((ac == NULL) || (ac->apr == NULL)) {
1498 pr_err("%s: APR handle NULL\n", __func__);
1499 return -EINVAL;
1500 }
1501 pr_debug("%s: session[%d] wr_format[0x%x]", __func__, ac->session,
1502 format);
1503
1504 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1505
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -07001506 if (ac->perf_mode) {
1507 pr_debug("%s In Performance/lowlatency mode", __func__);
1508 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_V2_1;
1509 open.uMode = ASM_OPEN_WRITE_PERF_MODE_BIT;
1510 /* source endpoint : matrix */
1511 open.sink_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1512 open.stream_handle = PCM_BITS_PER_SAMPLE;
1513 } else {
1514 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE;
1515 open.uMode = STREAM_PRIORITY_HIGH;
1516 /* source endpoint : matrix */
1517 open.sink_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1518 open.stream_handle = 0x00;
1519 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001520 open.post_proc_top = get_asm_topology();
1521 if (open.post_proc_top == 0)
1522 open.post_proc_top = DEFAULT_POPP_TOPOLOGY;
1523
1524 switch (format) {
1525 case FORMAT_LINEAR_PCM:
1526 open.format = LINEAR_PCM;
1527 break;
Kiran Kandi5e809b02012-01-31 00:24:33 -08001528 case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
1529 open.format = MULTI_CHANNEL_PCM;
1530 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001531 case FORMAT_MPEG4_AAC:
1532 open.format = MPEG4_AAC;
1533 break;
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07001534 case FORMAT_MPEG4_MULTI_AAC:
1535 open.format = MPEG4_MULTI_AAC;
1536 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001537 case FORMAT_WMA_V9:
1538 open.format = WMA_V9;
1539 break;
1540 case FORMAT_WMA_V10PRO:
1541 open.format = WMA_V10PRO;
1542 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05301543 case FORMAT_MP3:
1544 open.format = MP3;
1545 break;
Srikanth Uyyala66f781a2012-06-13 23:23:25 +05301546 case FORMAT_DTS:
1547 open.format = DTS;
1548 break;
1549 case FORMAT_DTS_LBR:
1550 open.format = DTS_LBR;
1551 break;
Ajit Khare43fd8832012-08-07 13:19:44 -07001552 case FORMAT_AMRWB:
1553 open.format = AMRWB_FS;
1554 pr_debug("q6asm_open_write FORMAT_AMRWB");
1555 break;
1556 case FORMAT_AMR_WB_PLUS:
1557 open.format = AMR_WB_PLUS;
1558 pr_debug("q6asm_open_write FORMAT_AMR_WB_PLUS");
1559 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001560 default:
1561 pr_err("%s: Invalid format[%d]\n", __func__, format);
1562 goto fail_cmd;
1563 }
1564 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1565 if (rc < 0) {
1566 pr_err("%s: open failed op[0x%x]rc[%d]\n", \
1567 __func__, open.hdr.opcode, rc);
1568 goto fail_cmd;
1569 }
1570 rc = wait_event_timeout(ac->cmd_wait,
1571 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1572 if (!rc) {
1573 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1574 rc);
1575 goto fail_cmd;
1576 }
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +05301577 if (atomic_read(&ac->cmd_response)) {
1578 pr_err("%s: format = %x not supported\n", __func__, format);
1579 goto fail_cmd;
1580 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001581 return 0;
1582fail_cmd:
1583 return -EINVAL;
1584}
1585
1586int q6asm_open_read_write(struct audio_client *ac,
1587 uint32_t rd_format,
1588 uint32_t wr_format)
1589{
1590 int rc = 0x00;
1591 struct asm_stream_cmd_open_read_write open;
1592
1593 if ((ac == NULL) || (ac->apr == NULL)) {
1594 pr_err("APR handle NULL\n");
1595 return -EINVAL;
1596 }
1597 pr_debug("%s: session[%d]", __func__, ac->session);
1598 pr_debug("wr_format[0x%x]rd_format[0x%x]",
1599 wr_format, rd_format);
1600
1601 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1602 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READWRITE;
1603
Deepa Madiregama55cbf782011-09-10 05:44:39 +05301604 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_NORMAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001605 /* source endpoint : matrix */
1606 open.post_proc_top = get_asm_topology();
1607 if (open.post_proc_top == 0)
1608 open.post_proc_top = DEFAULT_POPP_TOPOLOGY;
1609
1610 switch (wr_format) {
1611 case FORMAT_LINEAR_PCM:
1612 open.write_format = LINEAR_PCM;
1613 break;
1614 case FORMAT_MPEG4_AAC:
1615 open.write_format = MPEG4_AAC;
1616 break;
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07001617 case FORMAT_MPEG4_MULTI_AAC:
1618 open.write_format = MPEG4_MULTI_AAC;
1619 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001620 case FORMAT_WMA_V9:
1621 open.write_format = WMA_V9;
1622 break;
1623 case FORMAT_WMA_V10PRO:
1624 open.write_format = WMA_V10PRO;
1625 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301626 case FORMAT_AMRNB:
1627 open.write_format = AMRNB_FS;
1628 break;
1629 case FORMAT_AMRWB:
1630 open.write_format = AMRWB_FS;
1631 break;
Ajit Khare7277bb72012-10-31 16:34:22 -07001632 case FORMAT_AMR_WB_PLUS:
1633 open.write_format = AMR_WB_PLUS;
1634 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301635 case FORMAT_V13K:
1636 open.write_format = V13K_FS;
1637 break;
1638 case FORMAT_EVRC:
1639 open.write_format = EVRC_FS;
1640 break;
1641 case FORMAT_EVRCB:
1642 open.write_format = EVRCB_FS;
1643 break;
1644 case FORMAT_EVRCWB:
1645 open.write_format = EVRCWB_FS;
1646 break;
1647 case FORMAT_MP3:
1648 open.write_format = MP3;
1649 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001650 default:
1651 pr_err("Invalid format[%d]\n", wr_format);
1652 goto fail_cmd;
1653 }
1654
1655 switch (rd_format) {
1656 case FORMAT_LINEAR_PCM:
1657 open.read_format = LINEAR_PCM;
1658 break;
1659 case FORMAT_MPEG4_AAC:
1660 open.read_format = MPEG4_AAC;
1661 break;
1662 case FORMAT_V13K:
1663 open.read_format = V13K_FS;
1664 break;
1665 case FORMAT_EVRC:
1666 open.read_format = EVRC_FS;
1667 break;
1668 case FORMAT_AMRNB:
1669 open.read_format = AMRNB_FS;
1670 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301671 case FORMAT_AMRWB:
1672 open.read_format = AMRWB_FS;
1673 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001674 default:
1675 pr_err("Invalid format[%d]\n", rd_format);
1676 goto fail_cmd;
1677 }
1678 pr_debug("%s:rdformat[0x%x]wrformat[0x%x]\n", __func__,
1679 open.read_format, open.write_format);
1680
1681 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1682 if (rc < 0) {
1683 pr_err("open failed op[0x%x]rc[%d]\n", \
1684 open.hdr.opcode, rc);
1685 goto fail_cmd;
1686 }
1687 rc = wait_event_timeout(ac->cmd_wait,
1688 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1689 if (!rc) {
1690 pr_err("timeout. waited for OPEN_WRITE rc[%d]\n", rc);
1691 goto fail_cmd;
1692 }
1693 return 0;
1694fail_cmd:
1695 return -EINVAL;
1696}
1697
1698int q6asm_run(struct audio_client *ac, uint32_t flags,
1699 uint32_t msw_ts, uint32_t lsw_ts)
1700{
1701 struct asm_stream_cmd_run run;
1702 int rc;
1703 if (!ac || ac->apr == NULL) {
1704 pr_err("APR handle NULL\n");
1705 return -EINVAL;
1706 }
1707 pr_debug("%s session[%d]", __func__, ac->session);
1708 q6asm_add_hdr(ac, &run.hdr, sizeof(run), TRUE);
1709
1710 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1711 run.flags = flags;
1712 run.msw_ts = msw_ts;
1713 run.lsw_ts = lsw_ts;
Rajesha Kini3498c932011-07-19 19:58:27 +05301714#ifdef CONFIG_DEBUG_FS
1715 if (out_enable_flag) {
1716 do_gettimeofday(&out_cold_tv);
1717 pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",\
1718 out_cold_tv.tv_sec, out_cold_tv.tv_usec);
1719 }
1720#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001721 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1722 if (rc < 0) {
1723 pr_err("Commmand run failed[%d]", rc);
1724 goto fail_cmd;
1725 }
1726
1727 rc = wait_event_timeout(ac->cmd_wait,
1728 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1729 if (!rc) {
1730 pr_err("timeout. waited for run success rc[%d]", rc);
1731 goto fail_cmd;
1732 }
1733
1734 return 0;
1735fail_cmd:
1736 return -EINVAL;
1737}
1738
1739int q6asm_run_nowait(struct audio_client *ac, uint32_t flags,
1740 uint32_t msw_ts, uint32_t lsw_ts)
1741{
1742 struct asm_stream_cmd_run run;
1743 int rc;
1744 if (!ac || ac->apr == NULL) {
1745 pr_err("%s:APR handle NULL\n", __func__);
1746 return -EINVAL;
1747 }
1748 pr_debug("session[%d]", ac->session);
1749 q6asm_add_hdr_async(ac, &run.hdr, sizeof(run), TRUE);
1750
1751 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1752 run.flags = flags;
1753 run.msw_ts = msw_ts;
1754 run.lsw_ts = lsw_ts;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001755 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1756 if (rc < 0) {
1757 pr_err("%s:Commmand run failed[%d]", __func__, rc);
1758 return -EINVAL;
1759 }
Jay Wang0668d1062012-07-11 18:53:21 -07001760 atomic_inc(&ac->nowait_cmd_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001761 return 0;
1762}
1763
1764
1765int q6asm_enc_cfg_blk_aac(struct audio_client *ac,
1766 uint32_t frames_per_buf,
1767 uint32_t sample_rate, uint32_t channels,
1768 uint32_t bit_rate, uint32_t mode, uint32_t format)
1769{
1770 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1771 int rc = 0;
1772
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001773 pr_debug("%s:session[%d]frames[%d]SR[%d]ch[%d]bitrate[%d]mode[%d] format[%d]",
1774 __func__, ac->session, frames_per_buf,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001775 sample_rate, channels, bit_rate, mode, format);
1776
1777 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1778
1779 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1780 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1781 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1782 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1783 enc_cfg.enc_blk.format_id = MPEG4_AAC;
1784 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_aac_read_cfg);
1785 enc_cfg.enc_blk.cfg.aac.bitrate = bit_rate;
1786 enc_cfg.enc_blk.cfg.aac.enc_mode = mode;
1787 enc_cfg.enc_blk.cfg.aac.format = format;
1788 enc_cfg.enc_blk.cfg.aac.ch_cfg = channels;
1789 enc_cfg.enc_blk.cfg.aac.sample_rate = sample_rate;
1790
1791 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1792 if (rc < 0) {
1793 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1794 rc = -EINVAL;
1795 goto fail_cmd;
1796 }
1797 rc = wait_event_timeout(ac->cmd_wait,
1798 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1799 if (!rc) {
1800 pr_err("timeout. waited for FORMAT_UPDATE\n");
1801 goto fail_cmd;
1802 }
1803 return 0;
1804fail_cmd:
1805 return -EINVAL;
1806}
1807
1808int q6asm_enc_cfg_blk_pcm(struct audio_client *ac,
1809 uint32_t rate, uint32_t channels)
1810{
1811 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1812
1813 int rc = 0;
1814
1815 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1816 ac->session, rate, channels);
1817
1818 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1819
1820 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1821 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1822 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1823 enc_cfg.enc_blk.frames_per_buf = 1;
1824 enc_cfg.enc_blk.format_id = LINEAR_PCM;
1825 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg);
1826 enc_cfg.enc_blk.cfg.pcm.ch_cfg = channels;
1827 enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16;
1828 enc_cfg.enc_blk.cfg.pcm.sample_rate = rate;
1829 enc_cfg.enc_blk.cfg.pcm.is_signed = 1;
1830 enc_cfg.enc_blk.cfg.pcm.interleaved = 1;
1831
1832 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1833 if (rc < 0) {
1834 pr_err("Comamnd open failed\n");
1835 rc = -EINVAL;
1836 goto fail_cmd;
1837 }
1838 rc = wait_event_timeout(ac->cmd_wait,
1839 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1840 if (!rc) {
1841 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1842 goto fail_cmd;
1843 }
1844 return 0;
1845fail_cmd:
1846 return -EINVAL;
1847}
1848
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001849int q6asm_enc_cfg_blk_pcm_native(struct audio_client *ac,
1850 uint32_t rate, uint32_t channels)
1851{
1852 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1853
1854 int rc = 0;
1855
1856 pr_debug("%s: Session %d, rate = %d, channels = %d, setting the rate and channels to 0 for native\n",
1857 __func__, ac->session, rate, channels);
1858
1859 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1860
1861 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1862 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1863 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1864 enc_cfg.enc_blk.frames_per_buf = 1;
1865 enc_cfg.enc_blk.format_id = LINEAR_PCM;
1866 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg);
1867 enc_cfg.enc_blk.cfg.pcm.ch_cfg = 0;/*channels;*/
1868 enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16;
1869 enc_cfg.enc_blk.cfg.pcm.sample_rate = 0;/*rate;*/
1870 enc_cfg.enc_blk.cfg.pcm.is_signed = 1;
1871 enc_cfg.enc_blk.cfg.pcm.interleaved = 1;
1872
1873 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1874 if (rc < 0) {
1875 pr_err("Comamnd open failed\n");
1876 rc = -EINVAL;
1877 goto fail_cmd;
1878 }
1879 rc = wait_event_timeout(ac->cmd_wait,
1880 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1881 if (!rc) {
1882 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1883 goto fail_cmd;
1884 }
1885 return 0;
1886fail_cmd:
1887 return -EINVAL;
1888}
1889
Mingming Yin647e9ea2012-03-17 19:56:10 -07001890int q6asm_enc_cfg_blk_multi_ch_pcm(struct audio_client *ac,
1891 uint32_t rate, uint32_t channels)
1892{
1893 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1894
1895 int rc = 0;
1896
1897 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1898 ac->session, rate, channels);
1899
1900 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1901
1902 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1903 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1904 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1905 enc_cfg.enc_blk.frames_per_buf = 1;
1906 enc_cfg.enc_blk.format_id = MULTI_CHANNEL_PCM;
1907 enc_cfg.enc_blk.cfg_size =
1908 sizeof(struct asm_multi_channel_pcm_fmt_blk);
1909 enc_cfg.enc_blk.cfg.mpcm.num_channels = channels;
1910 enc_cfg.enc_blk.cfg.mpcm.bits_per_sample = 16;
1911 enc_cfg.enc_blk.cfg.mpcm.sample_rate = rate;
1912 enc_cfg.enc_blk.cfg.mpcm.is_signed = 1;
1913 enc_cfg.enc_blk.cfg.mpcm.is_interleaved = 1;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07001914 if (channels == 1) {
1915 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1916 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = 0;
1917 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = 0;
1918 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = 0;
1919 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1920 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1921 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1922 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1923 } else if (channels == 2) {
Subhash Chandra Bose Naripeddy8477d222012-06-12 00:30:54 -07001924 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1925 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1926 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = 0;
1927 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = 0;
1928 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1929 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1930 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1931 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1932 } else if (channels == 4) {
1933 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1934 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1935 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_RB;
1936 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_LB;
1937 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1938 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1939 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1940 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1941 } else if (channels == 6) {
1942 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1943 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1944 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_LFE;
1945 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_FC;
1946 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = PCM_CHANNEL_LB;
1947 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = PCM_CHANNEL_RB;
1948 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1949 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1950 } else if (channels == 8) {
1951 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1952 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1953 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_LFE;
1954 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_FC;
1955 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = PCM_CHANNEL_LB;
1956 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = PCM_CHANNEL_RB;
1957 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = PCM_CHANNEL_FLC;
1958 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = PCM_CHANNEL_FRC;
1959 }
Mingming Yin647e9ea2012-03-17 19:56:10 -07001960
1961 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1962 if (rc < 0) {
1963 pr_err("Comamnd open failed\n");
1964 rc = -EINVAL;
1965 goto fail_cmd;
1966 }
1967 rc = wait_event_timeout(ac->cmd_wait,
1968 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1969 if (!rc) {
1970 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1971 goto fail_cmd;
1972 }
1973 return 0;
1974fail_cmd:
1975 return -EINVAL;
1976}
1977
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001978int q6asm_enable_sbrps(struct audio_client *ac,
1979 uint32_t sbr_ps_enable)
1980{
1981 struct asm_stream_cmd_encdec_sbr sbrps;
1982
1983 int rc = 0;
1984
1985 pr_debug("%s: Session %d\n", __func__, ac->session);
1986
1987 q6asm_add_hdr(ac, &sbrps.hdr, sizeof(sbrps), TRUE);
1988
1989 sbrps.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1990 sbrps.param_id = ASM_ENABLE_SBR_PS;
1991 sbrps.param_size = sizeof(struct asm_sbr_ps);
1992 sbrps.sbr_ps.enable = sbr_ps_enable;
1993
1994 rc = apr_send_pkt(ac->apr, (uint32_t *) &sbrps);
1995 if (rc < 0) {
1996 pr_err("Command opcode[0x%x]paramid[0x%x] failed\n",
1997 ASM_STREAM_CMD_SET_ENCDEC_PARAM,
1998 ASM_ENABLE_SBR_PS);
1999 rc = -EINVAL;
2000 goto fail_cmd;
2001 }
2002 rc = wait_event_timeout(ac->cmd_wait,
2003 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2004 if (!rc) {
2005 pr_err("timeout opcode[0x%x] ", sbrps.hdr.opcode);
2006 goto fail_cmd;
2007 }
2008 return 0;
2009fail_cmd:
2010 return -EINVAL;
2011}
2012
Swaminathan Sathappan70765cd2011-07-19 18:42:47 -07002013int q6asm_cfg_dual_mono_aac(struct audio_client *ac,
2014 uint16_t sce_left, uint16_t sce_right)
2015{
2016 struct asm_stream_cmd_encdec_dualmono dual_mono;
2017
2018 int rc = 0;
2019
2020 pr_debug("%s: Session %d, sce_left = %d, sce_right = %d\n",
2021 __func__, ac->session, sce_left, sce_right);
2022
2023 q6asm_add_hdr(ac, &dual_mono.hdr, sizeof(dual_mono), TRUE);
2024
2025 dual_mono.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2026 dual_mono.param_id = ASM_CONFIGURE_DUAL_MONO;
2027 dual_mono.param_size = sizeof(struct asm_dual_mono);
2028 dual_mono.channel_map.sce_left = sce_left;
2029 dual_mono.channel_map.sce_right = sce_right;
2030
2031 rc = apr_send_pkt(ac->apr, (uint32_t *) &dual_mono);
2032 if (rc < 0) {
2033 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
2034 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
2035 ASM_CONFIGURE_DUAL_MONO);
2036 rc = -EINVAL;
2037 goto fail_cmd;
2038 }
2039 rc = wait_event_timeout(ac->cmd_wait,
2040 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2041 if (!rc) {
2042 pr_err("%s:timeout opcode[0x%x]\n", __func__,
2043 dual_mono.hdr.opcode);
2044 goto fail_cmd;
2045 }
2046 return 0;
2047fail_cmd:
2048 return -EINVAL;
2049}
2050
Amal Paul6e0f7982013-02-21 19:36:35 -08002051int q6asm_cfg_aac_sel_mix_coef(struct audio_client *ac, uint32_t mix_coeff)
2052{
2053 struct asm_aac_stereo_mix_coeff_selection_param aac_mix_coeff;
2054 int rc = 0;
2055 q6asm_add_hdr(ac, &aac_mix_coeff.hdr, sizeof(aac_mix_coeff), TRUE);
2056 aac_mix_coeff.hdr.opcode =
2057 ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2058 aac_mix_coeff.param_id =
2059 ASM_PARAM_ID_AAC_STEREO_MIX_COEFF_SELECTION_FLAG;
2060 aac_mix_coeff.param_size =
2061 sizeof(struct asm_aac_stereo_mix_coeff_selection_param);
2062 aac_mix_coeff.aac_stereo_mix_coeff_flag = mix_coeff;
2063 pr_debug("%s, mix_coeff = %u", __func__, mix_coeff);
2064 rc = apr_send_pkt(ac->apr, (uint32_t *) &aac_mix_coeff);
2065 if (rc < 0) {
2066 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
2067 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
2068 ASM_PARAM_ID_AAC_STEREO_MIX_COEFF_SELECTION_FLAG);
2069 rc = -EINVAL;
2070 goto fail_cmd;
2071 }
2072 rc = wait_event_timeout(ac->cmd_wait,
2073 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2074 if (!rc) {
2075 pr_err("%s:timeout opcode[0x%x]\n", __func__,
2076 aac_mix_coeff.hdr.opcode);
2077 goto fail_cmd;
2078 }
2079 return 0;
2080fail_cmd:
2081 return -EINVAL;
2082}
2083
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07002084int q6asm_set_encdec_chan_map(struct audio_client *ac,
2085 uint32_t num_channels)
2086{
2087 struct asm_stream_cmd_encdec_channelmap chan_map;
2088 u8 *channel_mapping;
2089
2090 int rc = 0;
2091
2092 pr_debug("%s: Session %d, num_channels = %d\n",
2093 __func__, ac->session, num_channels);
2094
2095 q6asm_add_hdr(ac, &chan_map.hdr, sizeof(chan_map), TRUE);
2096
2097 chan_map.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2098 chan_map.param_id = ASM_ENCDEC_DEC_CHAN_MAP;
2099 chan_map.param_size = sizeof(struct asm_dec_chan_map);
2100 chan_map.chan_map.num_channels = num_channels;
2101
2102 channel_mapping =
2103 chan_map.chan_map.channel_mapping;
2104
2105 memset(channel_mapping, PCM_CHANNEL_NULL, MAX_CHAN_MAP_CHANNELS);
2106 if (num_channels == 1) {
2107 channel_mapping[0] = PCM_CHANNEL_FL;
2108 } else if (num_channels == 2) {
2109 channel_mapping[0] = PCM_CHANNEL_FL;
2110 channel_mapping[1] = PCM_CHANNEL_FR;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002111 } else if (num_channels == 4) {
2112 channel_mapping[0] = PCM_CHANNEL_FL;
2113 channel_mapping[1] = PCM_CHANNEL_FR;
2114 channel_mapping[1] = PCM_CHANNEL_LB;
2115 channel_mapping[1] = PCM_CHANNEL_RB;
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07002116 } else if (num_channels == 6) {
2117 channel_mapping[0] = PCM_CHANNEL_FC;
2118 channel_mapping[1] = PCM_CHANNEL_FL;
2119 channel_mapping[2] = PCM_CHANNEL_FR;
2120 channel_mapping[3] = PCM_CHANNEL_LB;
2121 channel_mapping[4] = PCM_CHANNEL_RB;
2122 channel_mapping[5] = PCM_CHANNEL_LFE;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002123 } else if (num_channels == 8) {
2124 channel_mapping[0] = PCM_CHANNEL_FC;
2125 channel_mapping[1] = PCM_CHANNEL_FL;
2126 channel_mapping[2] = PCM_CHANNEL_FR;
2127 channel_mapping[3] = PCM_CHANNEL_LB;
2128 channel_mapping[4] = PCM_CHANNEL_RB;
2129 channel_mapping[5] = PCM_CHANNEL_LFE;
2130 channel_mapping[6] = PCM_CHANNEL_FLC;
2131 channel_mapping[7] = PCM_CHANNEL_FRC;
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07002132 } else {
2133 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
2134 num_channels);
2135 rc = -EINVAL;
2136 goto fail_cmd;
2137 }
2138
2139 rc = apr_send_pkt(ac->apr, (uint32_t *) &chan_map);
2140 if (rc < 0) {
2141 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
2142 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
2143 ASM_ENCDEC_DEC_CHAN_MAP);
2144 goto fail_cmd;
2145 }
2146 rc = wait_event_timeout(ac->cmd_wait,
2147 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2148 if (!rc) {
2149 pr_err("%s:timeout opcode[0x%x]\n", __func__,
2150 chan_map.hdr.opcode);
2151 rc = -ETIMEDOUT;
2152 goto fail_cmd;
2153 }
2154 return 0;
2155fail_cmd:
2156 return rc;
2157}
2158
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002159int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf,
2160 uint16_t min_rate, uint16_t max_rate,
2161 uint16_t reduced_rate_level, uint16_t rate_modulation_cmd)
2162{
2163 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2164 int rc = 0;
2165
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002166 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]",
2167 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002168 ac->session, frames_per_buf, min_rate, max_rate,
2169 reduced_rate_level, rate_modulation_cmd);
2170
2171 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2172
2173 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2174
2175 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2176 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2177
2178 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2179 enc_cfg.enc_blk.format_id = V13K_FS;
2180 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_qcelp13_read_cfg);
2181 enc_cfg.enc_blk.cfg.qcelp13.min_rate = min_rate;
2182 enc_cfg.enc_blk.cfg.qcelp13.max_rate = max_rate;
2183 enc_cfg.enc_blk.cfg.qcelp13.reduced_rate_level = reduced_rate_level;
2184 enc_cfg.enc_blk.cfg.qcelp13.rate_modulation_cmd = rate_modulation_cmd;
2185
2186 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2187 if (rc < 0) {
2188 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2189 goto fail_cmd;
2190 }
2191 rc = wait_event_timeout(ac->cmd_wait,
2192 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2193 if (!rc) {
2194 pr_err("timeout. waited for FORMAT_UPDATE\n");
2195 goto fail_cmd;
2196 }
2197 return 0;
2198fail_cmd:
2199 return -EINVAL;
2200}
2201
2202int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf,
2203 uint16_t min_rate, uint16_t max_rate,
2204 uint16_t rate_modulation_cmd)
2205{
2206 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2207 int rc = 0;
2208
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002209 pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] rate_modulation_cmd[0x%4x]",
2210 __func__, ac->session,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002211 frames_per_buf, min_rate, max_rate, rate_modulation_cmd);
2212
2213 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2214
2215 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2216
2217 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2218 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2219
2220 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2221 enc_cfg.enc_blk.format_id = EVRC_FS;
2222 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_evrc_read_cfg);
2223 enc_cfg.enc_blk.cfg.evrc.min_rate = min_rate;
2224 enc_cfg.enc_blk.cfg.evrc.max_rate = max_rate;
2225 enc_cfg.enc_blk.cfg.evrc.rate_modulation_cmd = rate_modulation_cmd;
2226 enc_cfg.enc_blk.cfg.evrc.reserved = 0;
2227
2228 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2229 if (rc < 0) {
2230 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2231 goto fail_cmd;
2232 }
2233 rc = wait_event_timeout(ac->cmd_wait,
2234 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2235 if (!rc) {
2236 pr_err("timeout. waited for FORMAT_UPDATE\n");
2237 goto fail_cmd;
2238 }
2239 return 0;
2240fail_cmd:
2241 return -EINVAL;
2242}
2243
2244int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf,
2245 uint16_t band_mode, uint16_t dtx_enable)
2246{
2247 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2248 int rc = 0;
2249
2250 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
2251 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
2252
2253 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2254
2255 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2256
2257 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2258 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2259
2260 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2261 enc_cfg.enc_blk.format_id = AMRNB_FS;
2262 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrnb_read_cfg);
2263 enc_cfg.enc_blk.cfg.amrnb.mode = band_mode;
2264 enc_cfg.enc_blk.cfg.amrnb.dtx_mode = dtx_enable;
2265
2266 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2267 if (rc < 0) {
2268 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2269 goto fail_cmd;
2270 }
2271 rc = wait_event_timeout(ac->cmd_wait,
2272 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2273 if (!rc) {
2274 pr_err("timeout. waited for FORMAT_UPDATE\n");
2275 goto fail_cmd;
2276 }
2277 return 0;
2278fail_cmd:
2279 return -EINVAL;
2280}
2281
Alex Wong2caeecc2011-10-28 10:52:15 +05302282int q6asm_enc_cfg_blk_amrwb(struct audio_client *ac, uint32_t frames_per_buf,
2283 uint16_t band_mode, uint16_t dtx_enable)
2284{
2285 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2286 int rc = 0;
2287
2288 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
2289 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
2290
2291 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2292
2293 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2294
2295 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2296 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2297
2298 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2299 enc_cfg.enc_blk.format_id = AMRWB_FS;
2300 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrwb_read_cfg);
2301 enc_cfg.enc_blk.cfg.amrwb.mode = band_mode;
2302 enc_cfg.enc_blk.cfg.amrwb.dtx_mode = dtx_enable;
2303
2304 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2305 if (rc < 0) {
2306 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2307 goto fail_cmd;
2308 }
2309 rc = wait_event_timeout(ac->cmd_wait,
2310 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2311 if (!rc) {
2312 pr_err("timeout. waited for FORMAT_UPDATE\n");
2313 goto fail_cmd;
2314 }
2315 return 0;
2316fail_cmd:
2317 return -EINVAL;
2318}
2319
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002320int q6asm_media_format_block_pcm(struct audio_client *ac,
2321 uint32_t rate, uint32_t channels)
2322{
2323 struct asm_stream_media_format_update fmt;
2324 int rc = 0;
2325
2326 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
2327 channels);
2328
2329 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2330
2331 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2332
2333 fmt.format = LINEAR_PCM;
2334 fmt.cfg_size = sizeof(struct asm_pcm_cfg);
2335 fmt.write_cfg.pcm_cfg.ch_cfg = channels;
2336 fmt.write_cfg.pcm_cfg.bits_per_sample = 16;
2337 fmt.write_cfg.pcm_cfg.sample_rate = rate;
2338 fmt.write_cfg.pcm_cfg.is_signed = 1;
2339 fmt.write_cfg.pcm_cfg.interleaved = 1;
2340
2341 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2342 if (rc < 0) {
2343 pr_err("%s:Comamnd open failed\n", __func__);
2344 goto fail_cmd;
2345 }
2346 rc = wait_event_timeout(ac->cmd_wait,
2347 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2348 if (!rc) {
2349 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2350 goto fail_cmd;
2351 }
2352 return 0;
2353fail_cmd:
2354 return -EINVAL;
2355}
2356
Kiran Kandi5e809b02012-01-31 00:24:33 -08002357int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
2358 uint32_t rate, uint32_t channels)
2359{
2360 struct asm_stream_media_format_update fmt;
2361 u8 *channel_mapping;
2362 int rc = 0;
2363
2364 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
2365 channels);
2366
2367 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2368
2369 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2370
2371 fmt.format = MULTI_CHANNEL_PCM;
2372 fmt.cfg_size = sizeof(struct asm_multi_channel_pcm_fmt_blk);
2373 fmt.write_cfg.multi_ch_pcm_cfg.num_channels = channels;
2374 fmt.write_cfg.multi_ch_pcm_cfg.bits_per_sample = 16;
2375 fmt.write_cfg.multi_ch_pcm_cfg.sample_rate = rate;
2376 fmt.write_cfg.multi_ch_pcm_cfg.is_signed = 1;
2377 fmt.write_cfg.multi_ch_pcm_cfg.is_interleaved = 1;
2378 channel_mapping =
2379 fmt.write_cfg.multi_ch_pcm_cfg.channel_mapping;
2380
2381 memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
2382
2383 if (channels == 1) {
2384 channel_mapping[0] = PCM_CHANNEL_FL;
2385 } else if (channels == 2) {
2386 channel_mapping[0] = PCM_CHANNEL_FL;
2387 channel_mapping[1] = PCM_CHANNEL_FR;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002388 } else if (channels == 4) {
2389 channel_mapping[0] = PCM_CHANNEL_FL;
2390 channel_mapping[1] = PCM_CHANNEL_FR;
2391 channel_mapping[1] = PCM_CHANNEL_LB;
2392 channel_mapping[1] = PCM_CHANNEL_RB;
Kiran Kandi5e809b02012-01-31 00:24:33 -08002393 } else if (channels == 6) {
SathishKumar Mani6074b772012-09-26 13:49:49 -07002394 channel_mapping[0] = PCM_CHANNEL_FL;
2395 channel_mapping[1] = PCM_CHANNEL_FR;
2396 channel_mapping[2] = PCM_CHANNEL_FC;
2397 channel_mapping[3] = PCM_CHANNEL_LFE;
2398 channel_mapping[4] = PCM_CHANNEL_LB;
2399 channel_mapping[5] = PCM_CHANNEL_RB;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002400 } else if (channels == 8) {
2401 channel_mapping[0] = PCM_CHANNEL_FC;
2402 channel_mapping[1] = PCM_CHANNEL_FL;
2403 channel_mapping[2] = PCM_CHANNEL_FR;
2404 channel_mapping[3] = PCM_CHANNEL_LB;
2405 channel_mapping[4] = PCM_CHANNEL_RB;
2406 channel_mapping[5] = PCM_CHANNEL_LFE;
2407 channel_mapping[6] = PCM_CHANNEL_FLC;
2408 channel_mapping[7] = PCM_CHANNEL_FRC;
Kiran Kandi5e809b02012-01-31 00:24:33 -08002409 } else {
2410 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
2411 channels);
2412 return -EINVAL;
2413 }
2414
2415 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2416 if (rc < 0) {
2417 pr_err("%s:Comamnd open failed\n", __func__);
2418 goto fail_cmd;
2419 }
2420 rc = wait_event_timeout(ac->cmd_wait,
2421 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2422 if (!rc) {
2423 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2424 goto fail_cmd;
2425 }
2426 return 0;
2427fail_cmd:
2428 return -EINVAL;
2429}
2430
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002431int q6asm_media_format_block_aac(struct audio_client *ac,
2432 struct asm_aac_cfg *cfg)
2433{
2434 struct asm_stream_media_format_update fmt;
2435 int rc = 0;
2436
2437 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2438 cfg->sample_rate, cfg->ch_cfg);
2439
2440 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2441
2442 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2443
2444 fmt.format = MPEG4_AAC;
2445 fmt.cfg_size = sizeof(struct asm_aac_cfg);
2446 fmt.write_cfg.aac_cfg.format = cfg->format;
2447 fmt.write_cfg.aac_cfg.aot = cfg->aot;
2448 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
2449 fmt.write_cfg.aac_cfg.section_data_resilience =
2450 cfg->section_data_resilience;
2451 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2452 cfg->scalefactor_data_resilience;
2453 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2454 cfg->spectral_data_resilience;
2455 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2456 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2457 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2458 __func__, fmt.format, fmt.cfg_size,
2459 fmt.write_cfg.aac_cfg.format,
2460 fmt.write_cfg.aac_cfg.aot,
2461 fmt.write_cfg.aac_cfg.ch_cfg,
2462 fmt.write_cfg.aac_cfg.sample_rate);
2463 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2464 if (rc < 0) {
2465 pr_err("%s:Comamnd open failed\n", __func__);
2466 goto fail_cmd;
2467 }
2468 rc = wait_event_timeout(ac->cmd_wait,
2469 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2470 if (!rc) {
2471 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2472 goto fail_cmd;
2473 }
2474 return 0;
2475fail_cmd:
2476 return -EINVAL;
2477}
2478
Ajit Khare43fd8832012-08-07 13:19:44 -07002479int q6asm_media_format_block_amrwbplus(struct audio_client *ac,
2480 struct asm_amrwbplus_cfg *cfg)
2481{
2482 struct asm_stream_media_format_update fmt;
2483 int rc = 0;
2484 pr_debug("q6asm_media_format_block_amrwbplus");
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07002485
Ajit Khare43fd8832012-08-07 13:19:44 -07002486 pr_debug("%s:session[%d]band-mode[%d]frame-fmt[%d]ch[%d]\n",
2487 __func__,
2488 ac->session,
2489 cfg->amr_band_mode,
2490 cfg->amr_frame_fmt,
2491 cfg->num_channels);
2492
2493 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2494
2495 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2496
2497 fmt.format = AMR_WB_PLUS;
2498 fmt.cfg_size = cfg->size_bytes;
2499
2500 fmt.write_cfg.amrwbplus_cfg.size_bytes = cfg->size_bytes;
2501 fmt.write_cfg.amrwbplus_cfg.version = cfg->version;
2502 fmt.write_cfg.amrwbplus_cfg.num_channels = cfg->num_channels;
2503 fmt.write_cfg.amrwbplus_cfg.amr_band_mode = cfg->amr_band_mode;
2504 fmt.write_cfg.amrwbplus_cfg.amr_dtx_mode = cfg->amr_dtx_mode;
2505 fmt.write_cfg.amrwbplus_cfg.amr_frame_fmt = cfg->amr_frame_fmt;
2506 fmt.write_cfg.amrwbplus_cfg.amr_lsf_idx = cfg->amr_lsf_idx;
2507
2508 pr_debug("%s: num_channels=%x amr_band_mode=%d amr_frame_fmt=%d\n",
2509 __func__,
2510 cfg->num_channels,
2511 cfg->amr_band_mode,
2512 cfg->amr_frame_fmt);
2513
2514 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2515 if (rc < 0) {
2516 pr_err("%s:Comamnd media format update failed..\n", __func__);
2517 goto fail_cmd;
2518 }
2519 rc = wait_event_timeout(ac->cmd_wait,
2520 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2521 if (!rc) {
2522 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2523 goto fail_cmd;
2524 }
2525 return 0;
2526fail_cmd:
2527 return -EINVAL;
2528}
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07002529int q6asm_media_format_block_multi_aac(struct audio_client *ac,
2530 struct asm_aac_cfg *cfg)
2531{
2532 struct asm_stream_media_format_update fmt;
2533 int rc = 0;
2534
2535 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2536 cfg->sample_rate, cfg->ch_cfg);
2537
2538 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2539
2540 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2541
2542 fmt.format = MPEG4_MULTI_AAC;
2543 fmt.cfg_size = sizeof(struct asm_aac_cfg);
2544 fmt.write_cfg.aac_cfg.format = cfg->format;
2545 fmt.write_cfg.aac_cfg.aot = cfg->aot;
2546 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
2547 fmt.write_cfg.aac_cfg.section_data_resilience =
2548 cfg->section_data_resilience;
2549 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2550 cfg->scalefactor_data_resilience;
2551 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2552 cfg->spectral_data_resilience;
2553 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2554 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2555 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2556 __func__, fmt.format, fmt.cfg_size,
2557 fmt.write_cfg.aac_cfg.format,
2558 fmt.write_cfg.aac_cfg.aot,
2559 fmt.write_cfg.aac_cfg.ch_cfg,
2560 fmt.write_cfg.aac_cfg.sample_rate);
2561 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2562 if (rc < 0) {
2563 pr_err("%s:Comamnd open failed\n", __func__);
2564 goto fail_cmd;
2565 }
2566 rc = wait_event_timeout(ac->cmd_wait,
2567 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2568 if (!rc) {
2569 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2570 goto fail_cmd;
2571 }
2572 return 0;
2573fail_cmd:
2574 return -EINVAL;
2575}
2576
2577
Alex Wong2caeecc2011-10-28 10:52:15 +05302578
2579int q6asm_media_format_block(struct audio_client *ac, uint32_t format)
2580{
2581
2582 struct asm_stream_media_format_update fmt;
2583 int rc = 0;
2584
2585 pr_debug("%s:session[%d] format[0x%x]\n", __func__,
2586 ac->session, format);
2587
2588 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2589 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302590 switch (format) {
2591 case FORMAT_V13K:
2592 fmt.format = V13K_FS;
2593 break;
2594 case FORMAT_EVRC:
2595 fmt.format = EVRC_FS;
2596 break;
2597 case FORMAT_AMRWB:
2598 fmt.format = AMRWB_FS;
2599 break;
Ajit Khare43fd8832012-08-07 13:19:44 -07002600 case FORMAT_AMR_WB_PLUS:
2601 fmt.format = AMR_WB_PLUS;
2602 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302603 case FORMAT_AMRNB:
2604 fmt.format = AMRNB_FS;
2605 break;
2606 case FORMAT_MP3:
2607 fmt.format = MP3;
2608 break;
Srikanth Uyyala66f781a2012-06-13 23:23:25 +05302609 case FORMAT_DTS:
2610 fmt.format = DTS;
2611 break;
2612 case FORMAT_DTS_LBR:
2613 fmt.format = DTS_LBR;
2614 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302615 default:
2616 pr_err("Invalid format[%d]\n", format);
2617 goto fail_cmd;
2618 }
Alex Wong2caeecc2011-10-28 10:52:15 +05302619 fmt.cfg_size = 0;
2620
2621 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2622 if (rc < 0) {
2623 pr_err("%s:Comamnd open failed\n", __func__);
2624 goto fail_cmd;
2625 }
2626 rc = wait_event_timeout(ac->cmd_wait,
2627 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2628 if (!rc) {
2629 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2630 goto fail_cmd;
2631 }
2632 return 0;
2633fail_cmd:
2634 return -EINVAL;
2635}
2636
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002637int q6asm_media_format_block_wma(struct audio_client *ac,
2638 void *cfg)
2639{
2640 struct asm_stream_media_format_update fmt;
2641 struct asm_wma_cfg *wma_cfg = (struct asm_wma_cfg *)cfg;
2642 int rc = 0;
2643
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002644 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 -07002645 ac->session, wma_cfg->format_tag, wma_cfg->sample_rate,
2646 wma_cfg->ch_cfg, wma_cfg->avg_bytes_per_sec,
2647 wma_cfg->block_align, wma_cfg->valid_bits_per_sample,
2648 wma_cfg->ch_mask, wma_cfg->encode_opt);
2649
2650 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2651
2652 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2653
2654 fmt.format = WMA_V9;
2655 fmt.cfg_size = sizeof(struct asm_wma_cfg);
2656 fmt.write_cfg.wma_cfg.format_tag = wma_cfg->format_tag;
2657 fmt.write_cfg.wma_cfg.ch_cfg = wma_cfg->ch_cfg;
2658 fmt.write_cfg.wma_cfg.sample_rate = wma_cfg->sample_rate;
2659 fmt.write_cfg.wma_cfg.avg_bytes_per_sec = wma_cfg->avg_bytes_per_sec;
2660 fmt.write_cfg.wma_cfg.block_align = wma_cfg->block_align;
2661 fmt.write_cfg.wma_cfg.valid_bits_per_sample =
2662 wma_cfg->valid_bits_per_sample;
2663 fmt.write_cfg.wma_cfg.ch_mask = wma_cfg->ch_mask;
2664 fmt.write_cfg.wma_cfg.encode_opt = wma_cfg->encode_opt;
2665 fmt.write_cfg.wma_cfg.adv_encode_opt = 0;
2666 fmt.write_cfg.wma_cfg.adv_encode_opt2 = 0;
2667 fmt.write_cfg.wma_cfg.drc_peak_ref = 0;
2668 fmt.write_cfg.wma_cfg.drc_peak_target = 0;
2669 fmt.write_cfg.wma_cfg.drc_ave_ref = 0;
2670 fmt.write_cfg.wma_cfg.drc_ave_target = 0;
2671
2672 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2673 if (rc < 0) {
2674 pr_err("%s:Comamnd open failed\n", __func__);
2675 goto fail_cmd;
2676 }
2677 rc = wait_event_timeout(ac->cmd_wait,
2678 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2679 if (!rc) {
2680 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2681 goto fail_cmd;
2682 }
2683 return 0;
2684fail_cmd:
2685 return -EINVAL;
2686}
2687
2688int q6asm_media_format_block_wmapro(struct audio_client *ac,
2689 void *cfg)
2690{
2691 struct asm_stream_media_format_update fmt;
2692 struct asm_wmapro_cfg *wmapro_cfg = (struct asm_wmapro_cfg *)cfg;
2693 int rc = 0;
2694
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002695 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 -07002696 ac->session, wmapro_cfg->format_tag, wmapro_cfg->sample_rate,
2697 wmapro_cfg->ch_cfg, wmapro_cfg->avg_bytes_per_sec,
2698 wmapro_cfg->block_align, wmapro_cfg->valid_bits_per_sample,
2699 wmapro_cfg->ch_mask, wmapro_cfg->encode_opt,
2700 wmapro_cfg->adv_encode_opt, wmapro_cfg->adv_encode_opt2);
2701
2702 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2703
2704 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2705
2706 fmt.format = WMA_V10PRO;
2707 fmt.cfg_size = sizeof(struct asm_wmapro_cfg);
2708 fmt.write_cfg.wmapro_cfg.format_tag = wmapro_cfg->format_tag;
2709 fmt.write_cfg.wmapro_cfg.ch_cfg = wmapro_cfg->ch_cfg;
2710 fmt.write_cfg.wmapro_cfg.sample_rate = wmapro_cfg->sample_rate;
2711 fmt.write_cfg.wmapro_cfg.avg_bytes_per_sec =
2712 wmapro_cfg->avg_bytes_per_sec;
2713 fmt.write_cfg.wmapro_cfg.block_align = wmapro_cfg->block_align;
2714 fmt.write_cfg.wmapro_cfg.valid_bits_per_sample =
2715 wmapro_cfg->valid_bits_per_sample;
2716 fmt.write_cfg.wmapro_cfg.ch_mask = wmapro_cfg->ch_mask;
2717 fmt.write_cfg.wmapro_cfg.encode_opt = wmapro_cfg->encode_opt;
2718 fmt.write_cfg.wmapro_cfg.adv_encode_opt = wmapro_cfg->adv_encode_opt;
2719 fmt.write_cfg.wmapro_cfg.adv_encode_opt2 = wmapro_cfg->adv_encode_opt2;
2720 fmt.write_cfg.wmapro_cfg.drc_peak_ref = 0;
2721 fmt.write_cfg.wmapro_cfg.drc_peak_target = 0;
2722 fmt.write_cfg.wmapro_cfg.drc_ave_ref = 0;
2723 fmt.write_cfg.wmapro_cfg.drc_ave_target = 0;
2724
2725 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2726 if (rc < 0) {
2727 pr_err("%s:Comamnd open failed\n", __func__);
2728 goto fail_cmd;
2729 }
2730 rc = wait_event_timeout(ac->cmd_wait,
2731 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2732 if (!rc) {
2733 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2734 goto fail_cmd;
2735 }
2736 return 0;
2737fail_cmd:
2738 return -EINVAL;
2739}
2740
2741int q6asm_memory_map(struct audio_client *ac, uint32_t buf_add, int dir,
2742 uint32_t bufsz, uint32_t bufcnt)
2743{
2744 struct asm_stream_cmd_memory_map mem_map;
2745 int rc = 0;
2746
2747 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2748 pr_err("APR handle NULL\n");
2749 return -EINVAL;
2750 }
2751
2752 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2753
2754 mem_map.hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP;
2755
2756 mem_map.buf_add = buf_add;
2757 mem_map.buf_size = bufsz * bufcnt;
2758 mem_map.mempool_id = 0; /* EBI */
2759 mem_map.reserved = 0;
2760
2761 q6asm_add_mmaphdr(&mem_map.hdr,
2762 sizeof(struct asm_stream_cmd_memory_map), TRUE);
2763
2764 pr_debug("buf add[%x] buf_add_parameter[%x]\n",
2765 mem_map.buf_add, buf_add);
2766
2767 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_map);
2768 if (rc < 0) {
2769 pr_err("mem_map op[0x%x]rc[%d]\n",
2770 mem_map.hdr.opcode, rc);
2771 rc = -EINVAL;
2772 goto fail_cmd;
2773 }
2774
2775 rc = wait_event_timeout(this_mmap.cmd_wait,
2776 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2777 if (!rc) {
2778 pr_err("timeout. waited for memory_map\n");
2779 rc = -EINVAL;
2780 goto fail_cmd;
2781 }
2782 rc = 0;
2783fail_cmd:
2784 return rc;
2785}
2786
2787int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add, int dir)
2788{
2789 struct asm_stream_cmd_memory_unmap mem_unmap;
2790 int rc = 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 q6asm_add_mmaphdr(&mem_unmap.hdr,
2799 sizeof(struct asm_stream_cmd_memory_unmap), TRUE);
2800 mem_unmap.hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP;
2801 mem_unmap.buf_add = buf_add;
2802
2803 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_unmap);
2804 if (rc < 0) {
2805 pr_err("mem_unmap op[0x%x]rc[%d]\n",
2806 mem_unmap.hdr.opcode, rc);
2807 rc = -EINVAL;
2808 goto fail_cmd;
2809 }
2810
2811 rc = wait_event_timeout(this_mmap.cmd_wait,
2812 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2813 if (!rc) {
2814 pr_err("timeout. waited for memory_map\n");
2815 rc = -EINVAL;
2816 goto fail_cmd;
2817 }
2818 rc = 0;
2819fail_cmd:
2820 return rc;
2821}
2822
2823int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain)
2824{
2825 void *vol_cmd = NULL;
2826 void *payload = NULL;
2827 struct asm_pp_params_command *cmd = NULL;
2828 struct asm_lrchannel_gain_params *lrgain = NULL;
2829 int sz = 0;
2830 int rc = 0;
2831
2832 sz = sizeof(struct asm_pp_params_command) +
2833 + sizeof(struct asm_lrchannel_gain_params);
2834 vol_cmd = kzalloc(sz, GFP_KERNEL);
2835 if (vol_cmd == NULL) {
2836 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2837 rc = -EINVAL;
2838 return rc;
2839 }
2840 cmd = (struct asm_pp_params_command *)vol_cmd;
2841 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2842 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2843 cmd->payload = NULL;
2844 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2845 sizeof(struct asm_lrchannel_gain_params);
2846 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2847 cmd->params.param_id = L_R_CHANNEL_GAIN_PARAM_ID;
2848 cmd->params.param_size = sizeof(struct asm_lrchannel_gain_params);
2849 cmd->params.reserved = 0;
2850
2851 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2852 lrgain = (struct asm_lrchannel_gain_params *)payload;
2853
2854 lrgain->left_gain = left_gain;
2855 lrgain->right_gain = right_gain;
2856 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2857 if (rc < 0) {
2858 pr_err("%s: Volume Command failed\n", __func__);
2859 rc = -EINVAL;
2860 goto fail_cmd;
2861 }
2862
2863 rc = wait_event_timeout(ac->cmd_wait,
2864 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2865 if (!rc) {
2866 pr_err("%s: timeout in sending volume command to apr\n",
2867 __func__);
2868 rc = -EINVAL;
2869 goto fail_cmd;
2870 }
2871 rc = 0;
2872fail_cmd:
2873 kfree(vol_cmd);
2874 return rc;
2875}
2876
2877static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
2878 uint32_t bufsz, uint32_t bufcnt)
2879{
2880 struct asm_stream_cmd_memory_map_regions *mmap_regions = NULL;
2881 struct asm_memory_map_regions *mregions = NULL;
2882 struct audio_port_data *port = NULL;
2883 struct audio_buffer *ab = NULL;
2884 void *mmap_region_cmd = NULL;
2885 void *payload = NULL;
2886 int rc = 0;
2887 int i = 0;
2888 int cmd_size = 0;
2889
2890 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2891 pr_err("APR handle NULL\n");
2892 return -EINVAL;
2893 }
2894 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2895
2896 cmd_size = sizeof(struct asm_stream_cmd_memory_map_regions)
2897 + sizeof(struct asm_memory_map_regions) * bufcnt;
2898
2899 mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302900 if (mmap_region_cmd == NULL) {
2901 pr_err("%s: Mem alloc failed\n", __func__);
2902 rc = -EINVAL;
2903 return rc;
2904 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002905 mmap_regions = (struct asm_stream_cmd_memory_map_regions *)
2906 mmap_region_cmd;
2907 q6asm_add_mmaphdr(&mmap_regions->hdr, cmd_size, TRUE);
2908 mmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP_REGIONS;
2909 mmap_regions->mempool_id = 0;
2910 mmap_regions->nregions = bufcnt & 0x00ff;
2911 pr_debug("map_regions->nregions = %d\n", mmap_regions->nregions);
2912 payload = ((u8 *) mmap_region_cmd +
2913 sizeof(struct asm_stream_cmd_memory_map_regions));
2914 mregions = (struct asm_memory_map_regions *)payload;
2915
2916 port = &ac->port[dir];
2917 for (i = 0; i < bufcnt; i++) {
2918 ab = &port->buf[i];
2919 mregions->phys = ab->phys;
2920 mregions->buf_size = ab->size;
2921 ++mregions;
2922 }
2923
2924 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) mmap_region_cmd);
2925 if (rc < 0) {
2926 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2927 mmap_regions->hdr.opcode, rc);
2928 rc = -EINVAL;
2929 goto fail_cmd;
2930 }
2931
2932 rc = wait_event_timeout(this_mmap.cmd_wait,
2933 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2934 if (!rc) {
2935 pr_err("timeout. waited for memory_map\n");
2936 rc = -EINVAL;
2937 goto fail_cmd;
2938 }
2939 rc = 0;
2940fail_cmd:
2941 kfree(mmap_region_cmd);
2942 return rc;
2943}
2944
2945static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir,
2946 uint32_t bufsz, uint32_t bufcnt)
2947{
2948 struct asm_stream_cmd_memory_unmap_regions *unmap_regions = NULL;
2949 struct asm_memory_unmap_regions *mregions = NULL;
2950 struct audio_port_data *port = NULL;
2951 struct audio_buffer *ab = NULL;
2952 void *unmap_region_cmd = NULL;
2953 void *payload = NULL;
2954 int rc = 0;
2955 int i = 0;
2956 int cmd_size = 0;
2957
2958 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2959 pr_err("APR handle NULL\n");
2960 return -EINVAL;
2961 }
2962 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2963
2964 cmd_size = sizeof(struct asm_stream_cmd_memory_unmap_regions) +
2965 sizeof(struct asm_memory_unmap_regions) * bufcnt;
2966
2967 unmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302968 if (unmap_region_cmd == NULL) {
2969 pr_err("%s: Mem alloc failed\n", __func__);
2970 rc = -EINVAL;
2971 return rc;
2972 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002973 unmap_regions = (struct asm_stream_cmd_memory_unmap_regions *)
2974 unmap_region_cmd;
2975 q6asm_add_mmaphdr(&unmap_regions->hdr, cmd_size, TRUE);
2976 unmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS;
2977 unmap_regions->nregions = bufcnt & 0x00ff;
2978 pr_debug("unmap_regions->nregions = %d\n", unmap_regions->nregions);
2979 payload = ((u8 *) unmap_region_cmd +
2980 sizeof(struct asm_stream_cmd_memory_unmap_regions));
2981 mregions = (struct asm_memory_unmap_regions *)payload;
2982 port = &ac->port[dir];
2983 for (i = 0; i < bufcnt; i++) {
2984 ab = &port->buf[i];
2985 mregions->phys = ab->phys;
2986 ++mregions;
2987 }
2988
2989 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) unmap_region_cmd);
2990 if (rc < 0) {
2991 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2992 unmap_regions->hdr.opcode, rc);
2993 goto fail_cmd;
2994 }
2995
2996 rc = wait_event_timeout(this_mmap.cmd_wait,
2997 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2998 if (!rc) {
2999 pr_err("timeout. waited for memory_unmap\n");
3000 goto fail_cmd;
3001 }
3002 rc = 0;
3003
3004fail_cmd:
3005 kfree(unmap_region_cmd);
3006 return rc;
3007}
3008
3009int q6asm_set_mute(struct audio_client *ac, int muteflag)
3010{
3011 void *vol_cmd = NULL;
3012 void *payload = NULL;
3013 struct asm_pp_params_command *cmd = NULL;
3014 struct asm_mute_params *mute = NULL;
3015 int sz = 0;
3016 int rc = 0;
3017
3018 sz = sizeof(struct asm_pp_params_command) +
3019 + sizeof(struct asm_mute_params);
3020 vol_cmd = kzalloc(sz, GFP_KERNEL);
3021 if (vol_cmd == NULL) {
3022 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3023 rc = -EINVAL;
3024 return rc;
3025 }
3026 cmd = (struct asm_pp_params_command *)vol_cmd;
3027 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3028 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3029 cmd->payload = NULL;
3030 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3031 sizeof(struct asm_mute_params);
3032 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3033 cmd->params.param_id = MUTE_CONFIG_PARAM_ID;
3034 cmd->params.param_size = sizeof(struct asm_mute_params);
3035 cmd->params.reserved = 0;
3036
3037 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3038 mute = (struct asm_mute_params *)payload;
3039
3040 mute->muteflag = muteflag;
3041 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3042 if (rc < 0) {
3043 pr_err("%s: Mute Command failed\n", __func__);
3044 rc = -EINVAL;
3045 goto fail_cmd;
3046 }
3047
3048 rc = wait_event_timeout(ac->cmd_wait,
3049 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3050 if (!rc) {
3051 pr_err("%s: timeout in sending mute command to apr\n",
3052 __func__);
3053 rc = -EINVAL;
3054 goto fail_cmd;
3055 }
3056 rc = 0;
3057fail_cmd:
3058 kfree(vol_cmd);
3059 return rc;
3060}
3061
3062int q6asm_set_volume(struct audio_client *ac, int volume)
3063{
3064 void *vol_cmd = NULL;
3065 void *payload = NULL;
3066 struct asm_pp_params_command *cmd = NULL;
3067 struct asm_master_gain_params *mgain = NULL;
3068 int sz = 0;
3069 int rc = 0;
3070
3071 sz = sizeof(struct asm_pp_params_command) +
3072 + sizeof(struct asm_master_gain_params);
3073 vol_cmd = kzalloc(sz, GFP_KERNEL);
3074 if (vol_cmd == NULL) {
3075 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3076 rc = -EINVAL;
3077 return rc;
3078 }
3079 cmd = (struct asm_pp_params_command *)vol_cmd;
3080 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3081 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3082 cmd->payload = NULL;
3083 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3084 sizeof(struct asm_master_gain_params);
3085 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3086 cmd->params.param_id = MASTER_GAIN_PARAM_ID;
3087 cmd->params.param_size = sizeof(struct asm_master_gain_params);
3088 cmd->params.reserved = 0;
3089
3090 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3091 mgain = (struct asm_master_gain_params *)payload;
3092
3093 mgain->master_gain = volume;
3094 mgain->padding = 0x00;
3095 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3096 if (rc < 0) {
3097 pr_err("%s: Volume Command failed\n", __func__);
3098 rc = -EINVAL;
3099 goto fail_cmd;
3100 }
3101
3102 rc = wait_event_timeout(ac->cmd_wait,
3103 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3104 if (!rc) {
3105 pr_err("%s: timeout in sending volume command to apr\n",
3106 __func__);
3107 rc = -EINVAL;
3108 goto fail_cmd;
3109 }
3110 rc = 0;
3111fail_cmd:
3112 kfree(vol_cmd);
3113 return rc;
3114}
3115
3116int q6asm_set_softpause(struct audio_client *ac,
3117 struct asm_softpause_params *pause_param)
3118{
3119 void *vol_cmd = NULL;
3120 void *payload = NULL;
3121 struct asm_pp_params_command *cmd = NULL;
3122 struct asm_softpause_params *params = NULL;
3123 int sz = 0;
3124 int rc = 0;
3125
3126 sz = sizeof(struct asm_pp_params_command) +
3127 + sizeof(struct asm_softpause_params);
3128 vol_cmd = kzalloc(sz, GFP_KERNEL);
3129 if (vol_cmd == NULL) {
3130 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3131 rc = -EINVAL;
3132 return rc;
3133 }
3134 cmd = (struct asm_pp_params_command *)vol_cmd;
3135 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3136 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3137 cmd->payload = NULL;
3138 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3139 sizeof(struct asm_softpause_params);
3140 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3141 cmd->params.param_id = SOFT_PAUSE_PARAM_ID;
3142 cmd->params.param_size = sizeof(struct asm_softpause_params);
3143 cmd->params.reserved = 0;
3144
3145 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3146 params = (struct asm_softpause_params *)payload;
3147
3148 params->enable = pause_param->enable;
3149 params->period = pause_param->period;
3150 params->step = pause_param->step;
3151 params->rampingcurve = pause_param->rampingcurve;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003152 pr_debug("%s: soft Pause Command: enable = %d, period = %d, step = %d, curve = %d\n",
3153 __func__, params->enable,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003154 params->period, params->step, params->rampingcurve);
3155 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3156 if (rc < 0) {
3157 pr_err("%s: Volume Command(soft_pause) failed\n", __func__);
3158 rc = -EINVAL;
3159 goto fail_cmd;
3160 }
3161
3162 rc = wait_event_timeout(ac->cmd_wait,
3163 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3164 if (!rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003165 pr_err("%s: timeout in sending volume command(soft_pause) to apr\n",
3166 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003167 rc = -EINVAL;
3168 goto fail_cmd;
3169 }
3170 rc = 0;
3171fail_cmd:
3172 kfree(vol_cmd);
3173 return rc;
3174}
3175
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003176int q6asm_set_softvolume(struct audio_client *ac,
3177 struct asm_softvolume_params *softvol_param)
3178{
3179 void *vol_cmd = NULL;
3180 void *payload = NULL;
3181 struct asm_pp_params_command *cmd = NULL;
3182 struct asm_softvolume_params *params = NULL;
3183 int sz = 0;
3184 int rc = 0;
3185
3186 sz = sizeof(struct asm_pp_params_command) +
3187 + sizeof(struct asm_softvolume_params);
3188 vol_cmd = kzalloc(sz, GFP_KERNEL);
3189 if (vol_cmd == NULL) {
3190 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3191 rc = -EINVAL;
3192 return rc;
3193 }
3194 cmd = (struct asm_pp_params_command *)vol_cmd;
3195 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3196 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3197 cmd->payload = NULL;
3198 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3199 sizeof(struct asm_softvolume_params);
3200 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3201 cmd->params.param_id = SOFT_VOLUME_PARAM_ID;
3202 cmd->params.param_size = sizeof(struct asm_softvolume_params);
3203 cmd->params.reserved = 0;
3204
3205 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3206 params = (struct asm_softvolume_params *)payload;
3207
3208 params->period = softvol_param->period;
3209 params->step = softvol_param->step;
3210 params->rampingcurve = softvol_param->rampingcurve;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003211 pr_debug("%s: soft Volume:opcode = %d,payload_sz =%d,module_id =%d, param_id = %d, param_sz = %d\n",
3212 __func__,
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003213 cmd->hdr.opcode, cmd->payload_size,
3214 cmd->params.module_id, cmd->params.param_id,
3215 cmd->params.param_size);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003216 pr_debug("%s: soft Volume Command: period = %d, step = %d, curve = %d\n",
3217 __func__, params->period,
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003218 params->step, params->rampingcurve);
3219 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3220 if (rc < 0) {
3221 pr_err("%s: Volume Command(soft_volume) failed\n", __func__);
3222 rc = -EINVAL;
3223 goto fail_cmd;
3224 }
3225
3226 rc = wait_event_timeout(ac->cmd_wait,
3227 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3228 if (!rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003229 pr_err("%s: timeout in sending volume command(soft_volume) to apr\n",
3230 __func__);
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003231 rc = -EINVAL;
3232 goto fail_cmd;
3233 }
3234 rc = 0;
3235fail_cmd:
3236 kfree(vol_cmd);
3237 return rc;
3238}
3239
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003240int q6asm_equalizer(struct audio_client *ac, void *eq)
3241{
3242 void *eq_cmd = NULL;
3243 void *payload = NULL;
3244 struct asm_pp_params_command *cmd = NULL;
3245 struct asm_equalizer_params *equalizer = NULL;
3246 struct msm_audio_eq_stream_config *eq_params = NULL;
3247 int i = 0;
3248 int sz = 0;
3249 int rc = 0;
3250
3251 sz = sizeof(struct asm_pp_params_command) +
3252 + sizeof(struct asm_equalizer_params);
3253 eq_cmd = kzalloc(sz, GFP_KERNEL);
3254 if (eq_cmd == NULL) {
3255 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3256 rc = -EINVAL;
3257 goto fail_cmd;
3258 }
3259 eq_params = (struct msm_audio_eq_stream_config *) eq;
3260 cmd = (struct asm_pp_params_command *)eq_cmd;
3261 q6asm_add_hdr(ac, &cmd->hdr, sz, TRUE);
3262 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3263 cmd->payload = NULL;
3264 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3265 sizeof(struct asm_equalizer_params);
3266 cmd->params.module_id = EQUALIZER_MODULE_ID;
3267 cmd->params.param_id = EQUALIZER_PARAM_ID;
3268 cmd->params.param_size = sizeof(struct asm_equalizer_params);
3269 cmd->params.reserved = 0;
3270 payload = (u8 *)(eq_cmd + sizeof(struct asm_pp_params_command));
3271 equalizer = (struct asm_equalizer_params *)payload;
3272
3273 equalizer->enable = eq_params->enable;
3274 equalizer->num_bands = eq_params->num_bands;
3275 pr_debug("%s: enable:%d numbands:%d\n", __func__, eq_params->enable,
3276 eq_params->num_bands);
3277 for (i = 0; i < eq_params->num_bands; i++) {
3278 equalizer->eq_bands[i].band_idx =
3279 eq_params->eq_bands[i].band_idx;
3280 equalizer->eq_bands[i].filter_type =
3281 eq_params->eq_bands[i].filter_type;
3282 equalizer->eq_bands[i].center_freq_hz =
3283 eq_params->eq_bands[i].center_freq_hz;
3284 equalizer->eq_bands[i].filter_gain =
3285 eq_params->eq_bands[i].filter_gain;
3286 equalizer->eq_bands[i].q_factor =
3287 eq_params->eq_bands[i].q_factor;
3288 pr_debug("%s: filter_type:%u bandnum:%d\n", __func__,
3289 eq_params->eq_bands[i].filter_type, i);
3290 pr_debug("%s: center_freq_hz:%u bandnum:%d\n", __func__,
3291 eq_params->eq_bands[i].center_freq_hz, i);
3292 pr_debug("%s: filter_gain:%d bandnum:%d\n", __func__,
3293 eq_params->eq_bands[i].filter_gain, i);
3294 pr_debug("%s: q_factor:%d bandnum:%d\n", __func__,
3295 eq_params->eq_bands[i].q_factor, i);
3296 }
3297 rc = apr_send_pkt(ac->apr, (uint32_t *) eq_cmd);
3298 if (rc < 0) {
3299 pr_err("%s: Equalizer Command failed\n", __func__);
3300 rc = -EINVAL;
3301 goto fail_cmd;
3302 }
3303
3304 rc = wait_event_timeout(ac->cmd_wait,
3305 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3306 if (!rc) {
3307 pr_err("%s: timeout in sending equalizer command to apr\n",
3308 __func__);
3309 rc = -EINVAL;
3310 goto fail_cmd;
3311 }
3312 rc = 0;
3313fail_cmd:
3314 kfree(eq_cmd);
3315 return rc;
3316}
3317
3318int q6asm_read(struct audio_client *ac)
3319{
3320 struct asm_stream_cmd_read read;
3321 struct audio_buffer *ab;
3322 int dsp_buf;
3323 struct audio_port_data *port;
3324 int rc;
3325 if (!ac || ac->apr == NULL) {
3326 pr_err("APR handle NULL\n");
3327 return -EINVAL;
3328 }
3329 if (ac->io_mode == SYNC_IO_MODE) {
3330 port = &ac->port[OUT];
3331
3332 q6asm_add_hdr(ac, &read.hdr, sizeof(read), FALSE);
3333
3334 mutex_lock(&port->lock);
3335
3336 dsp_buf = port->dsp_buf;
3337 ab = &port->buf[dsp_buf];
3338
3339 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
3340 __func__,
3341 ac->session,
3342 dsp_buf,
3343 (void *)port->buf[dsp_buf].data,
3344 port->cpu_buf,
3345 (void *)port->buf[port->cpu_buf].phys);
3346
3347 read.hdr.opcode = ASM_DATA_CMD_READ;
3348 read.buf_add = ab->phys;
3349 read.buf_size = ab->size;
3350 read.uid = port->dsp_buf;
3351 read.hdr.token = port->dsp_buf;
3352
3353 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3354 mutex_unlock(&port->lock);
3355 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
3356 read.buf_add,
3357 read.hdr.token,
3358 read.uid);
3359 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3360 if (rc < 0) {
3361 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
3362 goto fail_cmd;
3363 }
3364 return 0;
3365 }
3366fail_cmd:
3367 return -EINVAL;
3368}
3369
3370int q6asm_read_nolock(struct audio_client *ac)
3371{
3372 struct asm_stream_cmd_read read;
3373 struct audio_buffer *ab;
3374 int dsp_buf;
3375 struct audio_port_data *port;
3376 int rc;
3377 if (!ac || ac->apr == NULL) {
3378 pr_err("APR handle NULL\n");
3379 return -EINVAL;
3380 }
3381 if (ac->io_mode == SYNC_IO_MODE) {
3382 port = &ac->port[OUT];
3383
3384 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3385
3386
3387 dsp_buf = port->dsp_buf;
3388 ab = &port->buf[dsp_buf];
3389
3390 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
3391 __func__,
3392 ac->session,
3393 dsp_buf,
3394 (void *)port->buf[dsp_buf].data,
3395 port->cpu_buf,
3396 (void *)port->buf[port->cpu_buf].phys);
3397
3398 read.hdr.opcode = ASM_DATA_CMD_READ;
3399 read.buf_add = ab->phys;
3400 read.buf_size = ab->size;
3401 read.uid = port->dsp_buf;
3402 read.hdr.token = port->dsp_buf;
3403
3404 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3405 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
3406 read.buf_add,
3407 read.hdr.token,
3408 read.uid);
3409 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3410 if (rc < 0) {
3411 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
3412 goto fail_cmd;
3413 }
3414 return 0;
3415 }
3416fail_cmd:
3417 return -EINVAL;
3418}
3419
3420
3421static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
3422 uint32_t pkt_size, uint32_t cmd_flg)
3423{
3424 pr_debug("session=%d pkt size=%d cmd_flg=%d\n", pkt_size, cmd_flg,
3425 ac->session);
3426 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
3427 APR_HDR_LEN(sizeof(struct apr_hdr)),\
3428 APR_PKT_VER);
3429 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
3430 hdr->src_domain = APR_DOMAIN_APPS;
3431 hdr->dest_svc = APR_SVC_ASM;
3432 hdr->dest_domain = APR_DOMAIN_ADSP;
3433 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
3434 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
3435 if (cmd_flg) {
3436 hdr->token = ac->session;
3437 atomic_set(&ac->cmd_state, 1);
3438 }
3439 hdr->pkt_size = pkt_size;
3440 return;
3441}
3442
3443int q6asm_async_write(struct audio_client *ac,
3444 struct audio_aio_write_param *param)
3445{
3446 int rc = 0;
3447 struct asm_stream_cmd_write write;
3448
3449 if (!ac || ac->apr == NULL) {
3450 pr_err("%s: APR handle NULL\n", __func__);
3451 return -EINVAL;
3452 }
3453
3454 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write), FALSE);
3455
3456 /* Pass physical address as token for AIO scheme */
3457 write.hdr.token = param->uid;
3458 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3459 write.buf_add = param->paddr;
3460 write.avail_bytes = param->len;
3461 write.uid = param->uid;
3462 write.msw_ts = param->msw_ts;
3463 write.lsw_ts = param->lsw_ts;
3464 /* Use 0xFF00 for disabling timestamps */
3465 if (param->flags == 0xFF00)
3466 write.uflags = (0x00000000 | (param->flags & 0x800000FF));
3467 else
3468 write.uflags = (0x80000000 | param->flags);
3469
3470 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3471 write.buf_add, write.avail_bytes);
3472
3473 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3474 if (rc < 0) {
3475 pr_debug("[%s] write op[0x%x]rc[%d]\n", __func__,
3476 write.hdr.opcode, rc);
3477 goto fail_cmd;
3478 }
3479 return 0;
3480fail_cmd:
3481 return -EINVAL;
3482}
3483
3484int q6asm_async_read(struct audio_client *ac,
3485 struct audio_aio_read_param *param)
3486{
3487 int rc = 0;
3488 struct asm_stream_cmd_read read;
3489
3490 if (!ac || ac->apr == NULL) {
3491 pr_err("%s: APR handle NULL\n", __func__);
3492 return -EINVAL;
3493 }
3494
3495 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3496
3497 /* Pass physical address as token for AIO scheme */
3498 read.hdr.token = param->paddr;
3499 read.hdr.opcode = ASM_DATA_CMD_READ;
3500 read.buf_add = param->paddr;
3501 read.buf_size = param->len;
3502 read.uid = param->uid;
3503
3504 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3505 read.buf_add, read.buf_size);
3506
3507 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3508 if (rc < 0) {
3509 pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
3510 read.hdr.opcode, rc);
3511 goto fail_cmd;
3512 }
3513 return 0;
3514fail_cmd:
3515 return -EINVAL;
3516}
3517
Subhash Chandra Bose Naripeddy694b7d92012-06-20 20:46:13 -07003518int q6asm_async_read_compressed(struct audio_client *ac,
3519 struct audio_aio_read_param *param)
3520{
3521 int rc = 0;
3522 struct asm_stream_cmd_read read;
3523
3524 if (!ac || ac->apr == NULL) {
3525 pr_err("%s: APR handle NULL\n", __func__);
3526 return -EINVAL;
3527 }
3528
3529 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3530
3531 /* Pass physical address as token for AIO scheme */
3532 read.hdr.token = param->paddr;
3533 read.hdr.opcode = ASM_DATA_CMD_READ_COMPRESSED;
3534 read.buf_add = param->paddr;
3535 read.buf_size = param->len;
3536 read.uid = param->uid;
3537
3538 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3539 read.buf_add, read.buf_size);
3540
3541 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3542 if (rc < 0) {
3543 pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
3544 read.hdr.opcode, rc);
3545 goto fail_cmd;
3546 }
3547 return 0;
3548fail_cmd:
3549 return -EINVAL;
3550}
3551
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003552int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3553 uint32_t lsw_ts, uint32_t flags)
3554{
3555 int rc = 0;
3556 struct asm_stream_cmd_write write;
3557 struct audio_port_data *port;
3558 struct audio_buffer *ab;
3559 int dsp_buf = 0;
3560
3561 if (!ac || ac->apr == NULL) {
3562 pr_err("APR handle NULL\n");
3563 return -EINVAL;
3564 }
3565 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3566 if (ac->io_mode == SYNC_IO_MODE) {
3567 port = &ac->port[IN];
3568
3569 q6asm_add_hdr(ac, &write.hdr, sizeof(write),
3570 FALSE);
3571 mutex_lock(&port->lock);
3572
3573 dsp_buf = port->dsp_buf;
3574 ab = &port->buf[dsp_buf];
3575
3576 write.hdr.token = port->dsp_buf;
3577 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3578 write.buf_add = ab->phys;
3579 write.avail_bytes = len;
3580 write.uid = port->dsp_buf;
3581 write.msw_ts = msw_ts;
3582 write.lsw_ts = lsw_ts;
3583 /* Use 0xFF00 for disabling timestamps */
3584 if (flags == 0xFF00)
3585 write.uflags = (0x00000000 | (flags & 0x800000FF));
3586 else
3587 write.uflags = (0x80000000 | flags);
3588 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3589
3590 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3591 , __func__,
3592 ab->phys,
3593 write.buf_add,
3594 write.hdr.token,
3595 write.uid);
3596 mutex_unlock(&port->lock);
Rajesha Kini3498c932011-07-19 19:58:27 +05303597#ifdef CONFIG_DEBUG_FS
3598 if (out_enable_flag) {
3599 char zero_pattern[2] = {0x00, 0x00};
3600 /* If First two byte is non zero and last two byte
3601 is zero then it is warm output pattern */
3602 if ((strncmp(((char *)ab->data), zero_pattern, 2)) &&
3603 (!strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3604 do_gettimeofday(&out_warm_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003605 pr_debug("WARM:apr_send_pkt at %ld sec %ld microsec\n",
3606 out_warm_tv.tv_sec,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303607 out_warm_tv.tv_usec);
3608 pr_debug("Warm Pattern Matched");
3609 }
3610 /* If First two byte is zero and last two byte is
3611 non zero then it is cont ouput pattern */
3612 else if ((!strncmp(((char *)ab->data), zero_pattern, 2))
3613 && (strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3614 do_gettimeofday(&out_cont_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003615 pr_debug("CONT:apr_send_pkt at %ld sec %ld microsec\n",
3616 out_cont_tv.tv_sec,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303617 out_cont_tv.tv_usec);
3618 pr_debug("Cont Pattern Matched");
3619 }
3620 }
3621#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003622 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3623 if (rc < 0) {
3624 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3625 goto fail_cmd;
3626 }
3627 pr_debug("%s: WRITE SUCCESS\n", __func__);
3628 return 0;
3629 }
3630fail_cmd:
3631 return -EINVAL;
3632}
3633
3634int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3635 uint32_t lsw_ts, uint32_t flags)
3636{
3637 int rc = 0;
3638 struct asm_stream_cmd_write write;
3639 struct audio_port_data *port;
3640 struct audio_buffer *ab;
3641 int dsp_buf = 0;
3642
3643 if (!ac || ac->apr == NULL) {
3644 pr_err("APR handle NULL\n");
3645 return -EINVAL;
3646 }
3647 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3648 if (ac->io_mode == SYNC_IO_MODE) {
3649 port = &ac->port[IN];
3650
3651 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write),
3652 FALSE);
3653
3654 dsp_buf = port->dsp_buf;
3655 ab = &port->buf[dsp_buf];
3656
3657 write.hdr.token = port->dsp_buf;
3658 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3659 write.buf_add = ab->phys;
3660 write.avail_bytes = len;
3661 write.uid = port->dsp_buf;
3662 write.msw_ts = msw_ts;
3663 write.lsw_ts = lsw_ts;
3664 /* Use 0xFF00 for disabling timestamps */
3665 if (flags == 0xFF00)
3666 write.uflags = (0x00000000 | (flags & 0x800000FF));
3667 else
3668 write.uflags = (0x80000000 | flags);
3669 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3670
3671 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3672 , __func__,
3673 ab->phys,
3674 write.buf_add,
3675 write.hdr.token,
3676 write.uid);
3677
3678 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3679 if (rc < 0) {
3680 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3681 goto fail_cmd;
3682 }
3683 pr_debug("%s: WRITE SUCCESS\n", __func__);
3684 return 0;
3685 }
3686fail_cmd:
3687 return -EINVAL;
3688}
3689
Patrick Lai3aabeae2013-01-06 00:52:34 -08003690int q6asm_get_session_time(struct audio_client *ac, uint64_t *tstamp)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003691{
3692 struct apr_hdr hdr;
3693 int rc;
3694
Patrick Lai3aabeae2013-01-06 00:52:34 -08003695 if (!ac || ac->apr == NULL || tstamp == NULL) {
3696 pr_err("APR handle or tstamp NULL\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003697 return -EINVAL;
3698 }
Swaminathan Sathappanc7f98992012-07-09 11:07:12 -07003699 q6asm_add_hdr(ac, &hdr, sizeof(hdr), FALSE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003700 hdr.opcode = ASM_SESSION_CMD_GET_SESSION_TIME;
3701 atomic_set(&ac->time_flag, 1);
3702
3703 pr_debug("%s: session[%d]opcode[0x%x]\n", __func__,
3704 ac->session,
3705 hdr.opcode);
3706 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3707 if (rc < 0) {
3708 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3709 goto fail_cmd;
3710 }
3711 rc = wait_event_timeout(ac->time_wait,
3712 (atomic_read(&ac->time_flag) == 0), 5*HZ);
3713 if (!rc) {
3714 pr_err("%s: timeout in getting session time from DSP\n",
3715 __func__);
3716 goto fail_cmd;
3717 }
Patrick Lai3aabeae2013-01-06 00:52:34 -08003718
3719 *tstamp = ac->time_stamp;
3720 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003721
3722fail_cmd:
3723 return -EINVAL;
3724}
3725
3726int q6asm_cmd(struct audio_client *ac, int cmd)
3727{
3728 struct apr_hdr hdr;
3729 int rc;
3730 atomic_t *state;
3731 int cnt = 0;
3732
3733 if (!ac || ac->apr == NULL) {
3734 pr_err("APR handle NULL\n");
3735 return -EINVAL;
3736 }
3737 q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
3738 switch (cmd) {
3739 case CMD_PAUSE:
3740 pr_debug("%s:CMD_PAUSE\n", __func__);
3741 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3742 state = &ac->cmd_state;
3743 break;
3744 case CMD_FLUSH:
3745 pr_debug("%s:CMD_FLUSH\n", __func__);
3746 hdr.opcode = ASM_STREAM_CMD_FLUSH;
3747 state = &ac->cmd_state;
3748 break;
3749 case CMD_OUT_FLUSH:
3750 pr_debug("%s:CMD_OUT_FLUSH\n", __func__);
3751 hdr.opcode = ASM_STREAM_CMD_FLUSH_READBUFS;
3752 state = &ac->cmd_state;
3753 break;
3754 case CMD_EOS:
3755 pr_debug("%s:CMD_EOS\n", __func__);
3756 hdr.opcode = ASM_DATA_CMD_EOS;
3757 atomic_set(&ac->cmd_state, 0);
3758 state = &ac->cmd_state;
3759 break;
3760 case CMD_CLOSE:
3761 pr_debug("%s:CMD_CLOSE\n", __func__);
3762 hdr.opcode = ASM_STREAM_CMD_CLOSE;
Laxminath Kasamf16d3fd2012-12-19 14:54:14 +05303763 atomic_set(&ac->cmd_close_state, 1);
3764 state = &ac->cmd_close_state;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003765 break;
3766 default:
3767 pr_err("Invalid format[%d]\n", cmd);
3768 goto fail_cmd;
3769 }
3770 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3771 ac->session,
3772 hdr.opcode);
3773 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3774 if (rc < 0) {
3775 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3776 goto fail_cmd;
3777 }
3778 rc = wait_event_timeout(ac->cmd_wait, (atomic_read(state) == 0), 5*HZ);
3779 if (!rc) {
3780 pr_err("timeout. waited for response opcode[0x%x]\n",
3781 hdr.opcode);
3782 goto fail_cmd;
3783 }
3784 if (cmd == CMD_FLUSH)
3785 q6asm_reset_buf_state(ac);
3786 if (cmd == CMD_CLOSE) {
3787 /* check if DSP return all buffers */
3788 if (ac->port[IN].buf) {
3789 for (cnt = 0; cnt < ac->port[IN].max_buf_cnt;
3790 cnt++) {
3791 if (ac->port[IN].buf[cnt].used == IN) {
3792 pr_debug("Write Buf[%d] not returned\n",
3793 cnt);
3794 }
3795 }
3796 }
3797 if (ac->port[OUT].buf) {
3798 for (cnt = 0; cnt < ac->port[OUT].max_buf_cnt; cnt++) {
3799 if (ac->port[OUT].buf[cnt].used == OUT) {
3800 pr_debug("Read Buf[%d] not returned\n",
3801 cnt);
3802 }
3803 }
3804 }
3805 }
3806 return 0;
3807fail_cmd:
3808 return -EINVAL;
3809}
3810
3811int q6asm_cmd_nowait(struct audio_client *ac, int cmd)
3812{
3813 struct apr_hdr hdr;
3814 int rc;
3815
3816 if (!ac || ac->apr == NULL) {
3817 pr_err("%s:APR handle NULL\n", __func__);
3818 return -EINVAL;
3819 }
3820 q6asm_add_hdr_async(ac, &hdr, sizeof(hdr), TRUE);
3821 switch (cmd) {
3822 case CMD_PAUSE:
3823 pr_debug("%s:CMD_PAUSE\n", __func__);
3824 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3825 break;
3826 case CMD_EOS:
3827 pr_debug("%s:CMD_EOS\n", __func__);
3828 hdr.opcode = ASM_DATA_CMD_EOS;
3829 break;
3830 default:
3831 pr_err("%s:Invalid format[%d]\n", __func__, cmd);
3832 goto fail_cmd;
3833 }
3834 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3835 ac->session,
3836 hdr.opcode);
Jay Wang0668d1062012-07-11 18:53:21 -07003837
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003838 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3839 if (rc < 0) {
3840 pr_err("%s:Commmand 0x%x failed\n", __func__, hdr.opcode);
3841 goto fail_cmd;
3842 }
Jay Wang0668d1062012-07-11 18:53:21 -07003843 atomic_inc(&ac->nowait_cmd_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003844 return 0;
3845fail_cmd:
3846 return -EINVAL;
3847}
3848
3849static void q6asm_reset_buf_state(struct audio_client *ac)
3850{
3851 int cnt = 0;
3852 int loopcnt = 0;
3853 struct audio_port_data *port = NULL;
3854
3855 if (ac->io_mode == SYNC_IO_MODE) {
3856 mutex_lock(&ac->cmd_lock);
3857 for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
3858 port = &ac->port[loopcnt];
3859 cnt = port->max_buf_cnt - 1;
3860 port->dsp_buf = 0;
3861 port->cpu_buf = 0;
3862 while (cnt >= 0) {
3863 if (!port->buf)
3864 continue;
3865 port->buf[cnt].used = 1;
3866 cnt--;
3867 }
3868 }
3869 mutex_unlock(&ac->cmd_lock);
3870 }
3871}
3872
3873int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable)
3874{
3875 struct asm_stream_cmd_reg_tx_overflow_event tx_overflow;
3876 int rc;
3877
3878 if (!ac || ac->apr == NULL) {
3879 pr_err("APR handle NULL\n");
3880 return -EINVAL;
3881 }
3882 pr_debug("%s:session[%d]enable[%d]\n", __func__,
3883 ac->session, enable);
3884 q6asm_add_hdr(ac, &tx_overflow.hdr, sizeof(tx_overflow), TRUE);
3885
3886 tx_overflow.hdr.opcode = \
3887 ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS;
3888 /* tx overflow event: enable */
3889 tx_overflow.enable = enable;
3890
3891 rc = apr_send_pkt(ac->apr, (uint32_t *) &tx_overflow);
3892 if (rc < 0) {
3893 pr_err("tx overflow op[0x%x]rc[%d]\n", \
3894 tx_overflow.hdr.opcode, rc);
3895 goto fail_cmd;
3896 }
3897 rc = wait_event_timeout(ac->cmd_wait,
3898 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3899 if (!rc) {
3900 pr_err("timeout. waited for tx overflow\n");
3901 goto fail_cmd;
3902 }
3903 return 0;
3904fail_cmd:
3905 return -EINVAL;
3906}
3907
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003908int q6asm_get_apr_service_id(int session_id)
3909{
3910 pr_debug("%s\n", __func__);
3911
Shiv Maliyappanahallia84982a2012-01-19 15:25:04 -08003912 if (session_id < 0 || session_id > SESSION_MAX) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003913 pr_err("%s: invalid session_id = %d\n", __func__, session_id);
3914 return -EINVAL;
3915 }
3916
3917 return ((struct apr_svc *)session[session_id]->apr)->id;
3918}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003919
3920
3921static int __init q6asm_init(void)
3922{
3923 pr_debug("%s\n", __func__);
3924 init_waitqueue_head(&this_mmap.cmd_wait);
3925 memset(session, 0, sizeof(session));
Rajesha Kini3498c932011-07-19 19:58:27 +05303926#ifdef CONFIG_DEBUG_FS
3927 out_buffer = kmalloc(OUT_BUFFER_SIZE, GFP_KERNEL);
3928 out_dentry = debugfs_create_file("audio_out_latency_measurement_node",\
Glenn Kasten5dfda802012-10-04 16:40:27 -07003929 0664,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303930 NULL, NULL, &audio_output_latency_debug_fops);
3931 if (IS_ERR(out_dentry))
3932 pr_err("debugfs_create_file failed\n");
3933 in_buffer = kmalloc(IN_BUFFER_SIZE, GFP_KERNEL);
3934 in_dentry = debugfs_create_file("audio_in_latency_measurement_node",\
Glenn Kasten5dfda802012-10-04 16:40:27 -07003935 0664,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303936 NULL, NULL, &audio_input_latency_debug_fops);
3937 if (IS_ERR(in_dentry))
3938 pr_err("debugfs_create_file failed\n");
3939#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003940 return 0;
3941}
3942
3943device_initcall(q6asm_init);