blob: 82b21886293d61d63ddb370261e0c45556d82f34 [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:
Jay Wang0668d1062012-07-11 18:53:21 -0700896 if (atomic_read(&ac->cmd_state) && wakeup_flag) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700897 atomic_set(&ac->cmd_state, 0);
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700898 if (payload[1] == ADSP_EUNSUPPORTED) {
899 pr_debug("paload[1]:%d unsupported",
900 payload[1]);
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +0530901 atomic_set(&ac->cmd_response, 1);
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700902 }
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +0530903 else
904 atomic_set(&ac->cmd_response, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700905 wake_up(&ac->cmd_wait);
906 }
907 if (ac->cb)
908 ac->cb(data->opcode, data->token,
909 (uint32_t *)data->payload, ac->priv);
910 break;
911 default:
912 pr_debug("%s:command[0x%x] not expecting rsp\n",
913 __func__, payload[0]);
914 break;
915 }
916 return 0;
917 }
918
919 switch (data->opcode) {
920 case ASM_DATA_EVENT_WRITE_DONE:{
921 struct audio_port_data *port = &ac->port[IN];
922 pr_debug("%s: Rxed opcode[0x%x] status[0x%x] token[%d]",
923 __func__, payload[0], payload[1],
924 data->token);
925 if (ac->io_mode == SYNC_IO_MODE) {
926 if (port->buf == NULL) {
927 pr_err("%s: Unexpected Write Done\n",
928 __func__);
929 return -EINVAL;
930 }
931 spin_lock_irqsave(&port->dsp_lock, dsp_flags);
932 if (port->buf[data->token].phys !=
933 payload[0]) {
934 pr_err("Buf expected[%p]rxed[%p]\n",\
935 (void *)port->buf[data->token].phys,\
936 (void *)payload[0]);
937 spin_unlock_irqrestore(&port->dsp_lock,
938 dsp_flags);
939 return -EINVAL;
940 }
941 token = data->token;
942 port->buf[token].used = 1;
943 spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
Rajesha Kini3498c932011-07-19 19:58:27 +0530944#ifdef CONFIG_DEBUG_FS
945 if (out_enable_flag) {
946 /* For first Write done log the time and reset
947 out_cold_index*/
948 if (out_cold_index != 1) {
949 do_gettimeofday(&out_cold_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700950 pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",
951 out_cold_tv.tv_sec,
Rajesha Kini3498c932011-07-19 19:58:27 +0530952 out_cold_tv.tv_usec);
953 out_cold_index = 1;
954 }
955 pr_debug("out_enable_flag %ld",\
956 out_enable_flag);
957 }
958#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700959 for (i = 0; i < port->max_buf_cnt; i++)
960 pr_debug("%d ", port->buf[i].used);
961
962 }
963 break;
964 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700965 case ASM_STREAM_CMDRSP_GET_PP_PARAMS:
966 rtac_make_asm_callback(ac->session, payload,
967 data->payload_size);
968 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700969 case ASM_DATA_EVENT_READ_DONE:{
970
971 struct audio_port_data *port = &ac->port[OUT];
Rajesha Kini3498c932011-07-19 19:58:27 +0530972#ifdef CONFIG_DEBUG_FS
973 if (in_enable_flag) {
974 /* when in_cont_index == 7, DSP would be
975 * writing into the 8th 512 byte buffer and this
976 * timestamp is tapped here.Once done it then writes
977 * to 9th 512 byte buffer.These two buffers(8th, 9th)
978 * reach the test application in 5th iteration and that
979 * timestamp is tapped at user level. The difference
980 * of these two timestamps gives us the time between
981 * the time at which dsp started filling the sample
982 * required and when it reached the test application.
983 * Hence continuous input latency
984 */
985 if (in_cont_index == 7) {
986 do_gettimeofday(&in_cont_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700987 pr_err("In_CONT:previous read buffer done at %ld sec %ld microsec\n",
Sriranjan Srikantam74753532011-10-03 14:48:37 -0700988 in_cont_tv.tv_sec, in_cont_tv.tv_usec);
Rajesha Kini3498c932011-07-19 19:58:27 +0530989 }
990 }
991#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700992 pr_debug("%s:R-D: status=%d buff_add=%x act_size=%d offset=%d\n",
993 __func__, payload[READDONE_IDX_STATUS],
994 payload[READDONE_IDX_BUFFER],
995 payload[READDONE_IDX_SIZE],
996 payload[READDONE_IDX_OFFSET]);
997 pr_debug("%s:R-D:msw_ts=%d lsw_ts=%d flags=%d id=%d num=%d\n",
998 __func__, payload[READDONE_IDX_MSW_TS],
999 payload[READDONE_IDX_LSW_TS],
1000 payload[READDONE_IDX_FLAGS],
1001 payload[READDONE_IDX_ID],
1002 payload[READDONE_IDX_NUMFRAMES]);
Rajesha Kini3498c932011-07-19 19:58:27 +05301003#ifdef CONFIG_DEBUG_FS
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001004 if (in_enable_flag)
Rajesha Kini3498c932011-07-19 19:58:27 +05301005 in_cont_index++;
Rajesha Kini3498c932011-07-19 19:58:27 +05301006#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001007 if (ac->io_mode == SYNC_IO_MODE) {
1008 if (port->buf == NULL) {
1009 pr_err("%s: Unexpected Write Done\n", __func__);
1010 return -EINVAL;
1011 }
1012 spin_lock_irqsave(&port->dsp_lock, dsp_flags);
1013 token = data->token;
1014 port->buf[token].used = 0;
1015 if (port->buf[token].phys !=
1016 payload[READDONE_IDX_BUFFER]) {
1017 pr_err("Buf expected[%p]rxed[%p]\n",\
1018 (void *)port->buf[token].phys,\
1019 (void *)payload[READDONE_IDX_BUFFER]);
1020 spin_unlock_irqrestore(&port->dsp_lock,
1021 dsp_flags);
1022 break;
1023 }
1024 port->buf[token].actual_size =
1025 payload[READDONE_IDX_SIZE];
1026 spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
1027 }
1028 break;
1029 }
1030 case ASM_DATA_EVENT_EOS:
1031 case ASM_DATA_CMDRSP_EOS:
1032 pr_debug("%s:EOS ACK received: rxed opcode[0x%x]\n",
1033 __func__, data->opcode);
1034 break;
1035 case ASM_STREAM_CMDRSP_GET_ENCDEC_PARAM:
1036 break;
1037 case ASM_SESSION_EVENT_TX_OVERFLOW:
1038 pr_err("ASM_SESSION_EVENT_TX_OVERFLOW\n");
1039 break;
1040 case ASM_SESSION_CMDRSP_GET_SESSION_TIME:
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001041 pr_debug("%s: ASM_SESSION_CMDRSP_GET_SESSION_TIME, payload[0] = %d, payload[1] = %d, payload[2] = %d\n",
1042 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001043 payload[0], payload[1], payload[2]);
1044 ac->time_stamp = (uint64_t)(((uint64_t)payload[1] << 32) |
1045 payload[2]);
1046 if (atomic_read(&ac->time_flag)) {
1047 atomic_set(&ac->time_flag, 0);
1048 wake_up(&ac->time_wait);
1049 }
1050 break;
1051 case ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY:
Deepa Madiregama55cbf782011-09-10 05:44:39 +05301052 case ASM_DATA_EVENT_ENC_SR_CM_NOTIFY:
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001053 pr_debug("%s: ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY, payload[0] = %d, payload[1] = %d, payload[2] = %d, payload[3] = %d\n",
1054 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001055 payload[0], payload[1], payload[2],
1056 payload[3]);
1057 break;
1058 }
1059 if (ac->cb)
1060 ac->cb(data->opcode, data->token,
1061 data->payload, ac->priv);
1062
1063 return 0;
1064}
1065
1066void *q6asm_is_cpu_buf_avail(int dir, struct audio_client *ac, uint32_t *size,
1067 uint32_t *index)
1068{
1069 void *data;
1070 unsigned char idx;
1071 struct audio_port_data *port;
1072
1073 if (!ac || ((dir != IN) && (dir != OUT)))
1074 return NULL;
1075
1076 if (ac->io_mode == SYNC_IO_MODE) {
1077 port = &ac->port[dir];
1078
1079 mutex_lock(&port->lock);
1080 idx = port->cpu_buf;
1081 if (port->buf == NULL) {
1082 pr_debug("%s:Buffer pointer null\n", __func__);
Jayasena Sangaraboina466e6b92012-01-17 21:10:55 -08001083 mutex_unlock(&port->lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001084 return NULL;
1085 }
1086 /* dir 0: used = 0 means buf in use
1087 dir 1: used = 1 means buf in use */
1088 if (port->buf[idx].used == dir) {
1089 /* To make it more robust, we could loop and get the
1090 next avail buf, its risky though */
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001091 pr_debug("%s:Next buf idx[0x%x] not available,dir[%d]\n",
1092 __func__, idx, dir);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001093 mutex_unlock(&port->lock);
1094 return NULL;
1095 }
1096 *size = port->buf[idx].actual_size;
1097 *index = port->cpu_buf;
1098 data = port->buf[idx].data;
1099 pr_debug("%s:session[%d]index[%d] data[%p]size[%d]\n",
1100 __func__,
1101 ac->session,
1102 port->cpu_buf,
1103 data, *size);
1104 /* By default increase the cpu_buf cnt
1105 user accesses this function,increase cpu
1106 buf(to avoid another api)*/
1107 port->buf[idx].used = dir;
1108 port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1));
1109 mutex_unlock(&port->lock);
1110 return data;
1111 }
1112 return NULL;
1113}
1114
Jay Wang9cf59a02011-08-10 16:58:40 -07001115void *q6asm_is_cpu_buf_avail_nolock(int dir, struct audio_client *ac,
1116 uint32_t *size, uint32_t *index)
1117{
1118 void *data;
1119 unsigned char idx;
1120 struct audio_port_data *port;
1121
1122 if (!ac || ((dir != IN) && (dir != OUT)))
1123 return NULL;
1124
1125 port = &ac->port[dir];
1126
1127 idx = port->cpu_buf;
1128 if (port->buf == NULL) {
1129 pr_debug("%s:Buffer pointer null\n", __func__);
1130 return NULL;
1131 }
1132 /*
1133 * dir 0: used = 0 means buf in use
1134 * dir 1: used = 1 means buf in use
1135 */
1136 if (port->buf[idx].used == dir) {
1137 /*
1138 * To make it more robust, we could loop and get the
1139 * next avail buf, its risky though
1140 */
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001141 pr_debug("%s:Next buf idx[0x%x] not available, dir[%d]\n",
1142 __func__, idx, dir);
Jay Wang9cf59a02011-08-10 16:58:40 -07001143 return NULL;
1144 }
1145 *size = port->buf[idx].actual_size;
1146 *index = port->cpu_buf;
1147 data = port->buf[idx].data;
1148 pr_debug("%s:session[%d]index[%d] data[%p]size[%d]\n",
1149 __func__, ac->session, port->cpu_buf,
1150 data, *size);
1151 /*
1152 * By default increase the cpu_buf cnt
1153 * user accesses this function,increase cpu
1154 * buf(to avoid another api)
1155 */
1156 port->buf[idx].used = dir;
1157 port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1));
1158 return data;
1159}
1160
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001161int q6asm_is_dsp_buf_avail(int dir, struct audio_client *ac)
1162{
1163 int ret = -1;
1164 struct audio_port_data *port;
1165 uint32_t idx;
1166
1167 if (!ac || (dir != OUT))
1168 return ret;
1169
1170 if (ac->io_mode == SYNC_IO_MODE) {
1171 port = &ac->port[dir];
1172
1173 mutex_lock(&port->lock);
1174 idx = port->dsp_buf;
1175
1176 if (port->buf[idx].used == (dir ^ 1)) {
1177 /* To make it more robust, we could loop and get the
1178 next avail buf, its risky though */
1179 pr_err("Next buf idx[0x%x] not available, dir[%d]\n",
1180 idx, dir);
1181 mutex_unlock(&port->lock);
1182 return ret;
1183 }
1184 pr_debug("%s: session[%d]dsp_buf=%d cpu_buf=%d\n", __func__,
1185 ac->session, port->dsp_buf, port->cpu_buf);
1186 ret = ((port->dsp_buf != port->cpu_buf) ? 0 : -1);
1187 mutex_unlock(&port->lock);
1188 }
1189 return ret;
1190}
1191
1192static void q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
1193 uint32_t pkt_size, uint32_t cmd_flg)
1194{
1195 pr_debug("%s:session=%d pkt size=%d cmd_flg=%d\n", __func__, pkt_size,
1196 cmd_flg, ac->session);
1197 mutex_lock(&ac->cmd_lock);
1198 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
1199 APR_HDR_LEN(sizeof(struct apr_hdr)),\
1200 APR_PKT_VER);
1201 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
1202 hdr->src_domain = APR_DOMAIN_APPS;
1203 hdr->dest_svc = APR_SVC_ASM;
1204 hdr->dest_domain = APR_DOMAIN_ADSP;
1205 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
1206 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
1207 if (cmd_flg) {
1208 hdr->token = ac->session;
1209 atomic_set(&ac->cmd_state, 1);
1210 }
1211 hdr->pkt_size = pkt_size;
1212 mutex_unlock(&ac->cmd_lock);
1213 return;
1214}
1215
1216static void q6asm_add_mmaphdr(struct apr_hdr *hdr, uint32_t pkt_size,
1217 uint32_t cmd_flg)
1218{
1219 pr_debug("%s:pkt size=%d cmd_flg=%d\n", __func__, pkt_size, cmd_flg);
1220 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
1221 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1222 hdr->src_port = 0;
1223 hdr->dest_port = 0;
1224 if (cmd_flg) {
1225 hdr->token = 0;
1226 atomic_set(&this_mmap.cmd_state, 1);
1227 }
1228 hdr->pkt_size = pkt_size;
1229 return;
1230}
1231
1232int q6asm_open_read(struct audio_client *ac,
1233 uint32_t format)
1234{
1235 int rc = 0x00;
1236 struct asm_stream_cmd_open_read open;
Rajesha Kini3498c932011-07-19 19:58:27 +05301237#ifdef CONFIG_DEBUG_FS
1238 in_cont_index = 0;
1239#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001240 if ((ac == NULL) || (ac->apr == NULL)) {
1241 pr_err("%s: APR handle NULL\n", __func__);
1242 return -EINVAL;
1243 }
1244 pr_debug("%s:session[%d]", __func__, ac->session);
1245
1246 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1247 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ;
1248 /* Stream prio : High, provide meta info with encoded frames */
1249 open.src_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1250
1251 open.pre_proc_top = get_asm_topology();
1252 if (open.pre_proc_top == 0)
1253 open.pre_proc_top = DEFAULT_POPP_TOPOLOGY;
1254
1255 switch (format) {
1256 case FORMAT_LINEAR_PCM:
1257 open.uMode = STREAM_PRIORITY_HIGH;
1258 open.format = LINEAR_PCM;
1259 break;
Mingming Yin647e9ea2012-03-17 19:56:10 -07001260 case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
1261 open.uMode = STREAM_PRIORITY_HIGH;
1262 open.format = MULTI_CHANNEL_PCM;
1263 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001264 case FORMAT_MPEG4_AAC:
1265 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1266 open.format = MPEG4_AAC;
1267 break;
1268 case FORMAT_V13K:
1269 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1270 open.format = V13K_FS;
1271 break;
1272 case FORMAT_EVRC:
1273 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1274 open.format = EVRC_FS;
1275 break;
1276 case FORMAT_AMRNB:
1277 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1278 open.format = AMRNB_FS;
1279 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301280 case FORMAT_AMRWB:
1281 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1282 open.format = AMRWB_FS;
1283 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001284 default:
1285 pr_err("Invalid format[%d]\n", format);
1286 goto fail_cmd;
1287 }
1288 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1289 if (rc < 0) {
1290 pr_err("open failed op[0x%x]rc[%d]\n", \
1291 open.hdr.opcode, rc);
1292 goto fail_cmd;
1293 }
1294 rc = wait_event_timeout(ac->cmd_wait,
1295 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1296 if (!rc) {
1297 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1298 rc);
1299 goto fail_cmd;
1300 }
1301 return 0;
1302fail_cmd:
1303 return -EINVAL;
1304}
1305
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -07001306int q6asm_open_read_v2_1(struct audio_client *ac,
1307 uint32_t format)
1308{
1309 int rc = 0x00;
1310 struct asm_stream_cmd_open_read_v2_1 open;
1311#ifdef CONFIG_DEBUG_FS
1312 in_cont_index = 0;
1313#endif
1314 if ((ac == NULL) || (ac->apr == NULL)) {
1315 pr_err("%s: APR handle NULL\n", __func__);
1316 return -EINVAL;
1317 }
1318 pr_debug("%s:session[%d]", __func__, ac->session);
1319
1320 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1321 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ_V2_1;
1322 open.src_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1323 open.pre_proc_top = get_asm_topology();
1324 if (open.pre_proc_top == 0)
1325 open.pre_proc_top = DEFAULT_POPP_TOPOLOGY;
1326
1327 switch (format) {
1328 case FORMAT_LINEAR_PCM:
1329 open.uMode = STREAM_PRIORITY_HIGH;
1330 open.format = LINEAR_PCM;
1331 break;
1332 case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
1333 open.uMode = STREAM_PRIORITY_HIGH;
1334 open.format = MULTI_CHANNEL_PCM;
1335 break;
1336 case FORMAT_MPEG4_AAC:
1337 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1338 open.format = MPEG4_AAC;
1339 break;
1340 case FORMAT_V13K:
1341 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1342 open.format = V13K_FS;
1343 break;
1344 case FORMAT_EVRC:
1345 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1346 open.format = EVRC_FS;
1347 break;
1348 case FORMAT_AMRNB:
1349 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1350 open.format = AMRNB_FS;
1351 break;
1352 case FORMAT_AMRWB:
1353 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1354 open.format = AMRWB_FS;
1355 break;
1356 default:
1357 pr_err("Invalid format[%d]\n", format);
1358 goto fail_cmd;
1359 }
1360 open.uMode = ASM_OPEN_READ_PERF_MODE_BIT;
1361 open.bits_per_sample = PCM_BITS_PER_SAMPLE;
1362 open.reserved = 0;
1363 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1364 if (rc < 0) {
1365 pr_err("open failed op[0x%x]rc[%d]\n", \
1366 open.hdr.opcode, rc);
1367 goto fail_cmd;
1368 }
1369 rc = wait_event_timeout(ac->cmd_wait,
1370 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1371 if (!rc) {
1372 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1373 rc);
1374 goto fail_cmd;
1375 }
1376 return 0;
1377fail_cmd:
1378 return -EINVAL;
1379}
1380
1381
Subhash Chandra Bose Naripeddy694b7d92012-06-20 20:46:13 -07001382int q6asm_open_read_compressed(struct audio_client *ac,
1383 uint32_t frames_per_buffer, uint32_t meta_data_mode)
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -07001384{
1385 int rc = 0x00;
1386 struct asm_stream_cmd_open_read_compressed open;
1387#ifdef CONFIG_DEBUG_FS
1388 in_cont_index = 0;
1389#endif
1390 if ((ac == NULL) || (ac->apr == NULL)) {
1391 pr_err("%s: APR handle NULL\n", __func__);
1392 return -EINVAL;
1393 }
1394 pr_debug("%s:session[%d]", __func__, ac->session);
1395
1396 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1397 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ_COMPRESSED;
1398 /* hardcoded as following*/
Subhash Chandra Bose Naripeddy694b7d92012-06-20 20:46:13 -07001399 open.frame_per_buf = frames_per_buffer;
1400 open.uMode = meta_data_mode;
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -07001401
1402 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1403 if (rc < 0) {
1404 pr_err("open failed op[0x%x]rc[%d]\n", open.hdr.opcode, rc);
1405 goto fail_cmd;
1406 }
1407 rc = wait_event_timeout(ac->cmd_wait,
1408 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1409 if (!rc) {
1410 pr_err("%s: timeout. waited for OPEN_READ_COMPRESSED rc[%d]\n",
1411 __func__, rc);
1412 goto fail_cmd;
1413 }
1414 return 0;
1415fail_cmd:
1416 return -EINVAL;
1417}
1418
Santosh Mardi23321202012-03-22 04:33:25 +05301419int q6asm_open_write_compressed(struct audio_client *ac, uint32_t format)
1420{
1421 int rc = 0x00;
1422 struct asm_stream_cmd_open_write_compressed open;
1423
1424 if ((ac == NULL) || (ac->apr == NULL)) {
1425 pr_err("%s: APR handle NULL\n", __func__);
1426 return -EINVAL;
1427 }
1428 pr_debug("%s: session[%d] wr_format[0x%x]", __func__, ac->session,
1429 format);
1430
1431 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1432
1433 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_COMPRESSED;
1434
1435 switch (format) {
1436 case FORMAT_AC3:
1437 open.format = AC3_DECODER;
1438 break;
1439 case FORMAT_EAC3:
1440 open.format = EAC3_DECODER;
1441 break;
1442 case FORMAT_MP3:
1443 open.format = MP3;
1444 break;
1445 case FORMAT_DTS:
1446 open.format = DTS;
1447 break;
Srikanth Uyyala66f781a2012-06-13 23:23:25 +05301448 case FORMAT_DTS_LBR:
1449 open.format = DTS_LBR;
1450 break;
Santosh Mardi23321202012-03-22 04:33:25 +05301451 case FORMAT_AAC:
1452 open.format = MPEG4_AAC;
1453 break;
1454 case FORMAT_ATRAC:
1455 open.format = ATRAC;
1456 break;
1457 case FORMAT_WMA_V10PRO:
1458 open.format = WMA_V10PRO;
1459 break;
1460 case FORMAT_MAT:
1461 open.format = MAT;
1462 break;
1463 default:
1464 pr_err("%s: Invalid format[%d]\n", __func__, format);
1465 goto fail_cmd;
1466 }
1467 /*Below flag indicates the DSP that Compressed audio input
1468 stream is not IEC 61937 or IEC 60958 packetizied*/
1469 open.flags = 0x00000000;
1470 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1471 if (rc < 0) {
1472 pr_err("%s: open failed op[0x%x]rc[%d]\n", \
1473 __func__, open.hdr.opcode, rc);
1474 goto fail_cmd;
1475 }
1476 rc = wait_event_timeout(ac->cmd_wait,
1477 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1478 if (!rc) {
1479 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1480 rc);
1481 goto fail_cmd;
1482 }
1483 return 0;
1484fail_cmd:
1485 return -EINVAL;
1486}
1487
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001488int q6asm_open_write(struct audio_client *ac, uint32_t format)
1489{
1490 int rc = 0x00;
1491 struct asm_stream_cmd_open_write open;
1492
1493 if ((ac == NULL) || (ac->apr == NULL)) {
1494 pr_err("%s: APR handle NULL\n", __func__);
1495 return -EINVAL;
1496 }
1497 pr_debug("%s: session[%d] wr_format[0x%x]", __func__, ac->session,
1498 format);
1499
1500 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1501
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -07001502 if (ac->perf_mode) {
1503 pr_debug("%s In Performance/lowlatency mode", __func__);
1504 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_V2_1;
1505 open.uMode = ASM_OPEN_WRITE_PERF_MODE_BIT;
1506 /* source endpoint : matrix */
1507 open.sink_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1508 open.stream_handle = PCM_BITS_PER_SAMPLE;
1509 } else {
1510 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE;
1511 open.uMode = STREAM_PRIORITY_HIGH;
1512 /* source endpoint : matrix */
1513 open.sink_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1514 open.stream_handle = 0x00;
1515 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001516 open.post_proc_top = get_asm_topology();
1517 if (open.post_proc_top == 0)
1518 open.post_proc_top = DEFAULT_POPP_TOPOLOGY;
1519
1520 switch (format) {
1521 case FORMAT_LINEAR_PCM:
1522 open.format = LINEAR_PCM;
1523 break;
Kiran Kandi5e809b02012-01-31 00:24:33 -08001524 case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
1525 open.format = MULTI_CHANNEL_PCM;
1526 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001527 case FORMAT_MPEG4_AAC:
1528 open.format = MPEG4_AAC;
1529 break;
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07001530 case FORMAT_MPEG4_MULTI_AAC:
1531 open.format = MPEG4_MULTI_AAC;
1532 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001533 case FORMAT_WMA_V9:
1534 open.format = WMA_V9;
1535 break;
1536 case FORMAT_WMA_V10PRO:
1537 open.format = WMA_V10PRO;
1538 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05301539 case FORMAT_MP3:
1540 open.format = MP3;
1541 break;
Srikanth Uyyala66f781a2012-06-13 23:23:25 +05301542 case FORMAT_DTS:
1543 open.format = DTS;
1544 break;
1545 case FORMAT_DTS_LBR:
1546 open.format = DTS_LBR;
1547 break;
Ajit Khare43fd8832012-08-07 13:19:44 -07001548 case FORMAT_AMRWB:
1549 open.format = AMRWB_FS;
1550 pr_debug("q6asm_open_write FORMAT_AMRWB");
1551 break;
1552 case FORMAT_AMR_WB_PLUS:
1553 open.format = AMR_WB_PLUS;
1554 pr_debug("q6asm_open_write FORMAT_AMR_WB_PLUS");
1555 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001556 default:
1557 pr_err("%s: Invalid format[%d]\n", __func__, format);
1558 goto fail_cmd;
1559 }
1560 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1561 if (rc < 0) {
1562 pr_err("%s: open failed op[0x%x]rc[%d]\n", \
1563 __func__, open.hdr.opcode, rc);
1564 goto fail_cmd;
1565 }
1566 rc = wait_event_timeout(ac->cmd_wait,
1567 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1568 if (!rc) {
1569 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1570 rc);
1571 goto fail_cmd;
1572 }
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +05301573 if (atomic_read(&ac->cmd_response)) {
1574 pr_err("%s: format = %x not supported\n", __func__, format);
1575 goto fail_cmd;
1576 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001577 return 0;
1578fail_cmd:
1579 return -EINVAL;
1580}
1581
1582int q6asm_open_read_write(struct audio_client *ac,
1583 uint32_t rd_format,
1584 uint32_t wr_format)
1585{
1586 int rc = 0x00;
1587 struct asm_stream_cmd_open_read_write open;
1588
1589 if ((ac == NULL) || (ac->apr == NULL)) {
1590 pr_err("APR handle NULL\n");
1591 return -EINVAL;
1592 }
1593 pr_debug("%s: session[%d]", __func__, ac->session);
1594 pr_debug("wr_format[0x%x]rd_format[0x%x]",
1595 wr_format, rd_format);
1596
1597 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1598 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READWRITE;
1599
Deepa Madiregama55cbf782011-09-10 05:44:39 +05301600 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_NORMAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001601 /* source endpoint : matrix */
1602 open.post_proc_top = get_asm_topology();
1603 if (open.post_proc_top == 0)
1604 open.post_proc_top = DEFAULT_POPP_TOPOLOGY;
1605
1606 switch (wr_format) {
1607 case FORMAT_LINEAR_PCM:
1608 open.write_format = LINEAR_PCM;
1609 break;
1610 case FORMAT_MPEG4_AAC:
1611 open.write_format = MPEG4_AAC;
1612 break;
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07001613 case FORMAT_MPEG4_MULTI_AAC:
1614 open.write_format = MPEG4_MULTI_AAC;
1615 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001616 case FORMAT_WMA_V9:
1617 open.write_format = WMA_V9;
1618 break;
1619 case FORMAT_WMA_V10PRO:
1620 open.write_format = WMA_V10PRO;
1621 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301622 case FORMAT_AMRNB:
1623 open.write_format = AMRNB_FS;
1624 break;
1625 case FORMAT_AMRWB:
1626 open.write_format = AMRWB_FS;
1627 break;
Ajit Khare7277bb72012-10-31 16:34:22 -07001628 case FORMAT_AMR_WB_PLUS:
1629 open.write_format = AMR_WB_PLUS;
1630 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301631 case FORMAT_V13K:
1632 open.write_format = V13K_FS;
1633 break;
1634 case FORMAT_EVRC:
1635 open.write_format = EVRC_FS;
1636 break;
1637 case FORMAT_EVRCB:
1638 open.write_format = EVRCB_FS;
1639 break;
1640 case FORMAT_EVRCWB:
1641 open.write_format = EVRCWB_FS;
1642 break;
1643 case FORMAT_MP3:
1644 open.write_format = MP3;
1645 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001646 default:
1647 pr_err("Invalid format[%d]\n", wr_format);
1648 goto fail_cmd;
1649 }
1650
1651 switch (rd_format) {
1652 case FORMAT_LINEAR_PCM:
1653 open.read_format = LINEAR_PCM;
1654 break;
1655 case FORMAT_MPEG4_AAC:
1656 open.read_format = MPEG4_AAC;
1657 break;
1658 case FORMAT_V13K:
1659 open.read_format = V13K_FS;
1660 break;
1661 case FORMAT_EVRC:
1662 open.read_format = EVRC_FS;
1663 break;
1664 case FORMAT_AMRNB:
1665 open.read_format = AMRNB_FS;
1666 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301667 case FORMAT_AMRWB:
1668 open.read_format = AMRWB_FS;
1669 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001670 default:
1671 pr_err("Invalid format[%d]\n", rd_format);
1672 goto fail_cmd;
1673 }
1674 pr_debug("%s:rdformat[0x%x]wrformat[0x%x]\n", __func__,
1675 open.read_format, open.write_format);
1676
1677 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1678 if (rc < 0) {
1679 pr_err("open failed op[0x%x]rc[%d]\n", \
1680 open.hdr.opcode, rc);
1681 goto fail_cmd;
1682 }
1683 rc = wait_event_timeout(ac->cmd_wait,
1684 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1685 if (!rc) {
1686 pr_err("timeout. waited for OPEN_WRITE rc[%d]\n", rc);
1687 goto fail_cmd;
1688 }
1689 return 0;
1690fail_cmd:
1691 return -EINVAL;
1692}
1693
1694int q6asm_run(struct audio_client *ac, uint32_t flags,
1695 uint32_t msw_ts, uint32_t lsw_ts)
1696{
1697 struct asm_stream_cmd_run run;
1698 int rc;
1699 if (!ac || ac->apr == NULL) {
1700 pr_err("APR handle NULL\n");
1701 return -EINVAL;
1702 }
1703 pr_debug("%s session[%d]", __func__, ac->session);
1704 q6asm_add_hdr(ac, &run.hdr, sizeof(run), TRUE);
1705
1706 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1707 run.flags = flags;
1708 run.msw_ts = msw_ts;
1709 run.lsw_ts = lsw_ts;
Rajesha Kini3498c932011-07-19 19:58:27 +05301710#ifdef CONFIG_DEBUG_FS
1711 if (out_enable_flag) {
1712 do_gettimeofday(&out_cold_tv);
1713 pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",\
1714 out_cold_tv.tv_sec, out_cold_tv.tv_usec);
1715 }
1716#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001717 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1718 if (rc < 0) {
1719 pr_err("Commmand run failed[%d]", rc);
1720 goto fail_cmd;
1721 }
1722
1723 rc = wait_event_timeout(ac->cmd_wait,
1724 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1725 if (!rc) {
1726 pr_err("timeout. waited for run success rc[%d]", rc);
1727 goto fail_cmd;
1728 }
1729
1730 return 0;
1731fail_cmd:
1732 return -EINVAL;
1733}
1734
1735int q6asm_run_nowait(struct audio_client *ac, uint32_t flags,
1736 uint32_t msw_ts, uint32_t lsw_ts)
1737{
1738 struct asm_stream_cmd_run run;
1739 int rc;
1740 if (!ac || ac->apr == NULL) {
1741 pr_err("%s:APR handle NULL\n", __func__);
1742 return -EINVAL;
1743 }
1744 pr_debug("session[%d]", ac->session);
1745 q6asm_add_hdr_async(ac, &run.hdr, sizeof(run), TRUE);
1746
1747 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1748 run.flags = flags;
1749 run.msw_ts = msw_ts;
1750 run.lsw_ts = lsw_ts;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001751 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1752 if (rc < 0) {
1753 pr_err("%s:Commmand run failed[%d]", __func__, rc);
1754 return -EINVAL;
1755 }
Jay Wang0668d1062012-07-11 18:53:21 -07001756 atomic_inc(&ac->nowait_cmd_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001757 return 0;
1758}
1759
1760
1761int q6asm_enc_cfg_blk_aac(struct audio_client *ac,
1762 uint32_t frames_per_buf,
1763 uint32_t sample_rate, uint32_t channels,
1764 uint32_t bit_rate, uint32_t mode, uint32_t format)
1765{
1766 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1767 int rc = 0;
1768
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001769 pr_debug("%s:session[%d]frames[%d]SR[%d]ch[%d]bitrate[%d]mode[%d] format[%d]",
1770 __func__, ac->session, frames_per_buf,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001771 sample_rate, channels, bit_rate, mode, format);
1772
1773 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1774
1775 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1776 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1777 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1778 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1779 enc_cfg.enc_blk.format_id = MPEG4_AAC;
1780 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_aac_read_cfg);
1781 enc_cfg.enc_blk.cfg.aac.bitrate = bit_rate;
1782 enc_cfg.enc_blk.cfg.aac.enc_mode = mode;
1783 enc_cfg.enc_blk.cfg.aac.format = format;
1784 enc_cfg.enc_blk.cfg.aac.ch_cfg = channels;
1785 enc_cfg.enc_blk.cfg.aac.sample_rate = sample_rate;
1786
1787 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1788 if (rc < 0) {
1789 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1790 rc = -EINVAL;
1791 goto fail_cmd;
1792 }
1793 rc = wait_event_timeout(ac->cmd_wait,
1794 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1795 if (!rc) {
1796 pr_err("timeout. waited for FORMAT_UPDATE\n");
1797 goto fail_cmd;
1798 }
1799 return 0;
1800fail_cmd:
1801 return -EINVAL;
1802}
1803
1804int q6asm_enc_cfg_blk_pcm(struct audio_client *ac,
1805 uint32_t rate, uint32_t channels)
1806{
1807 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1808
1809 int rc = 0;
1810
1811 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1812 ac->session, rate, channels);
1813
1814 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1815
1816 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1817 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1818 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1819 enc_cfg.enc_blk.frames_per_buf = 1;
1820 enc_cfg.enc_blk.format_id = LINEAR_PCM;
1821 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg);
1822 enc_cfg.enc_blk.cfg.pcm.ch_cfg = channels;
1823 enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16;
1824 enc_cfg.enc_blk.cfg.pcm.sample_rate = rate;
1825 enc_cfg.enc_blk.cfg.pcm.is_signed = 1;
1826 enc_cfg.enc_blk.cfg.pcm.interleaved = 1;
1827
1828 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1829 if (rc < 0) {
1830 pr_err("Comamnd open failed\n");
1831 rc = -EINVAL;
1832 goto fail_cmd;
1833 }
1834 rc = wait_event_timeout(ac->cmd_wait,
1835 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1836 if (!rc) {
1837 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1838 goto fail_cmd;
1839 }
1840 return 0;
1841fail_cmd:
1842 return -EINVAL;
1843}
1844
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001845int q6asm_enc_cfg_blk_pcm_native(struct audio_client *ac,
1846 uint32_t rate, uint32_t channels)
1847{
1848 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1849
1850 int rc = 0;
1851
1852 pr_debug("%s: Session %d, rate = %d, channels = %d, setting the rate and channels to 0 for native\n",
1853 __func__, ac->session, rate, channels);
1854
1855 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1856
1857 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1858 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1859 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1860 enc_cfg.enc_blk.frames_per_buf = 1;
1861 enc_cfg.enc_blk.format_id = LINEAR_PCM;
1862 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg);
1863 enc_cfg.enc_blk.cfg.pcm.ch_cfg = 0;/*channels;*/
1864 enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16;
1865 enc_cfg.enc_blk.cfg.pcm.sample_rate = 0;/*rate;*/
1866 enc_cfg.enc_blk.cfg.pcm.is_signed = 1;
1867 enc_cfg.enc_blk.cfg.pcm.interleaved = 1;
1868
1869 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1870 if (rc < 0) {
1871 pr_err("Comamnd open failed\n");
1872 rc = -EINVAL;
1873 goto fail_cmd;
1874 }
1875 rc = wait_event_timeout(ac->cmd_wait,
1876 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1877 if (!rc) {
1878 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1879 goto fail_cmd;
1880 }
1881 return 0;
1882fail_cmd:
1883 return -EINVAL;
1884}
1885
Mingming Yin647e9ea2012-03-17 19:56:10 -07001886int q6asm_enc_cfg_blk_multi_ch_pcm(struct audio_client *ac,
1887 uint32_t rate, uint32_t channels)
1888{
1889 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1890
1891 int rc = 0;
1892
1893 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1894 ac->session, rate, channels);
1895
1896 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1897
1898 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1899 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1900 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1901 enc_cfg.enc_blk.frames_per_buf = 1;
1902 enc_cfg.enc_blk.format_id = MULTI_CHANNEL_PCM;
1903 enc_cfg.enc_blk.cfg_size =
1904 sizeof(struct asm_multi_channel_pcm_fmt_blk);
1905 enc_cfg.enc_blk.cfg.mpcm.num_channels = channels;
1906 enc_cfg.enc_blk.cfg.mpcm.bits_per_sample = 16;
1907 enc_cfg.enc_blk.cfg.mpcm.sample_rate = rate;
1908 enc_cfg.enc_blk.cfg.mpcm.is_signed = 1;
1909 enc_cfg.enc_blk.cfg.mpcm.is_interleaved = 1;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07001910 if (channels == 1) {
1911 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1912 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = 0;
1913 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = 0;
1914 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = 0;
1915 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1916 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1917 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1918 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1919 } else if (channels == 2) {
Subhash Chandra Bose Naripeddy8477d222012-06-12 00:30:54 -07001920 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1921 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1922 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = 0;
1923 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = 0;
1924 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1925 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1926 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1927 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1928 } else if (channels == 4) {
1929 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1930 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1931 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_RB;
1932 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_LB;
1933 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1934 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1935 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1936 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1937 } else if (channels == 6) {
1938 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1939 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1940 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_LFE;
1941 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_FC;
1942 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = PCM_CHANNEL_LB;
1943 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = PCM_CHANNEL_RB;
1944 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1945 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1946 } else if (channels == 8) {
1947 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1948 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1949 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_LFE;
1950 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_FC;
1951 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = PCM_CHANNEL_LB;
1952 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = PCM_CHANNEL_RB;
1953 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = PCM_CHANNEL_FLC;
1954 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = PCM_CHANNEL_FRC;
1955 }
Mingming Yin647e9ea2012-03-17 19:56:10 -07001956
1957 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1958 if (rc < 0) {
1959 pr_err("Comamnd open failed\n");
1960 rc = -EINVAL;
1961 goto fail_cmd;
1962 }
1963 rc = wait_event_timeout(ac->cmd_wait,
1964 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1965 if (!rc) {
1966 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1967 goto fail_cmd;
1968 }
1969 return 0;
1970fail_cmd:
1971 return -EINVAL;
1972}
1973
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001974int q6asm_enable_sbrps(struct audio_client *ac,
1975 uint32_t sbr_ps_enable)
1976{
1977 struct asm_stream_cmd_encdec_sbr sbrps;
1978
1979 int rc = 0;
1980
1981 pr_debug("%s: Session %d\n", __func__, ac->session);
1982
1983 q6asm_add_hdr(ac, &sbrps.hdr, sizeof(sbrps), TRUE);
1984
1985 sbrps.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1986 sbrps.param_id = ASM_ENABLE_SBR_PS;
1987 sbrps.param_size = sizeof(struct asm_sbr_ps);
1988 sbrps.sbr_ps.enable = sbr_ps_enable;
1989
1990 rc = apr_send_pkt(ac->apr, (uint32_t *) &sbrps);
1991 if (rc < 0) {
1992 pr_err("Command opcode[0x%x]paramid[0x%x] failed\n",
1993 ASM_STREAM_CMD_SET_ENCDEC_PARAM,
1994 ASM_ENABLE_SBR_PS);
1995 rc = -EINVAL;
1996 goto fail_cmd;
1997 }
1998 rc = wait_event_timeout(ac->cmd_wait,
1999 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2000 if (!rc) {
2001 pr_err("timeout opcode[0x%x] ", sbrps.hdr.opcode);
2002 goto fail_cmd;
2003 }
2004 return 0;
2005fail_cmd:
2006 return -EINVAL;
2007}
2008
Swaminathan Sathappan70765cd2011-07-19 18:42:47 -07002009int q6asm_cfg_dual_mono_aac(struct audio_client *ac,
2010 uint16_t sce_left, uint16_t sce_right)
2011{
2012 struct asm_stream_cmd_encdec_dualmono dual_mono;
2013
2014 int rc = 0;
2015
2016 pr_debug("%s: Session %d, sce_left = %d, sce_right = %d\n",
2017 __func__, ac->session, sce_left, sce_right);
2018
2019 q6asm_add_hdr(ac, &dual_mono.hdr, sizeof(dual_mono), TRUE);
2020
2021 dual_mono.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2022 dual_mono.param_id = ASM_CONFIGURE_DUAL_MONO;
2023 dual_mono.param_size = sizeof(struct asm_dual_mono);
2024 dual_mono.channel_map.sce_left = sce_left;
2025 dual_mono.channel_map.sce_right = sce_right;
2026
2027 rc = apr_send_pkt(ac->apr, (uint32_t *) &dual_mono);
2028 if (rc < 0) {
2029 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
2030 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
2031 ASM_CONFIGURE_DUAL_MONO);
2032 rc = -EINVAL;
2033 goto fail_cmd;
2034 }
2035 rc = wait_event_timeout(ac->cmd_wait,
2036 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2037 if (!rc) {
2038 pr_err("%s:timeout opcode[0x%x]\n", __func__,
2039 dual_mono.hdr.opcode);
2040 goto fail_cmd;
2041 }
2042 return 0;
2043fail_cmd:
2044 return -EINVAL;
2045}
2046
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07002047int q6asm_set_encdec_chan_map(struct audio_client *ac,
2048 uint32_t num_channels)
2049{
2050 struct asm_stream_cmd_encdec_channelmap chan_map;
2051 u8 *channel_mapping;
2052
2053 int rc = 0;
2054
2055 pr_debug("%s: Session %d, num_channels = %d\n",
2056 __func__, ac->session, num_channels);
2057
2058 q6asm_add_hdr(ac, &chan_map.hdr, sizeof(chan_map), TRUE);
2059
2060 chan_map.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2061 chan_map.param_id = ASM_ENCDEC_DEC_CHAN_MAP;
2062 chan_map.param_size = sizeof(struct asm_dec_chan_map);
2063 chan_map.chan_map.num_channels = num_channels;
2064
2065 channel_mapping =
2066 chan_map.chan_map.channel_mapping;
2067
2068 memset(channel_mapping, PCM_CHANNEL_NULL, MAX_CHAN_MAP_CHANNELS);
2069 if (num_channels == 1) {
2070 channel_mapping[0] = PCM_CHANNEL_FL;
2071 } else if (num_channels == 2) {
2072 channel_mapping[0] = PCM_CHANNEL_FL;
2073 channel_mapping[1] = PCM_CHANNEL_FR;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002074 } else if (num_channels == 4) {
2075 channel_mapping[0] = PCM_CHANNEL_FL;
2076 channel_mapping[1] = PCM_CHANNEL_FR;
2077 channel_mapping[1] = PCM_CHANNEL_LB;
2078 channel_mapping[1] = PCM_CHANNEL_RB;
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07002079 } else if (num_channels == 6) {
2080 channel_mapping[0] = PCM_CHANNEL_FC;
2081 channel_mapping[1] = PCM_CHANNEL_FL;
2082 channel_mapping[2] = PCM_CHANNEL_FR;
2083 channel_mapping[3] = PCM_CHANNEL_LB;
2084 channel_mapping[4] = PCM_CHANNEL_RB;
2085 channel_mapping[5] = PCM_CHANNEL_LFE;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002086 } else if (num_channels == 8) {
2087 channel_mapping[0] = PCM_CHANNEL_FC;
2088 channel_mapping[1] = PCM_CHANNEL_FL;
2089 channel_mapping[2] = PCM_CHANNEL_FR;
2090 channel_mapping[3] = PCM_CHANNEL_LB;
2091 channel_mapping[4] = PCM_CHANNEL_RB;
2092 channel_mapping[5] = PCM_CHANNEL_LFE;
2093 channel_mapping[6] = PCM_CHANNEL_FLC;
2094 channel_mapping[7] = PCM_CHANNEL_FRC;
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07002095 } else {
2096 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
2097 num_channels);
2098 rc = -EINVAL;
2099 goto fail_cmd;
2100 }
2101
2102 rc = apr_send_pkt(ac->apr, (uint32_t *) &chan_map);
2103 if (rc < 0) {
2104 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
2105 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
2106 ASM_ENCDEC_DEC_CHAN_MAP);
2107 goto fail_cmd;
2108 }
2109 rc = wait_event_timeout(ac->cmd_wait,
2110 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2111 if (!rc) {
2112 pr_err("%s:timeout opcode[0x%x]\n", __func__,
2113 chan_map.hdr.opcode);
2114 rc = -ETIMEDOUT;
2115 goto fail_cmd;
2116 }
2117 return 0;
2118fail_cmd:
2119 return rc;
2120}
2121
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002122int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf,
2123 uint16_t min_rate, uint16_t max_rate,
2124 uint16_t reduced_rate_level, uint16_t rate_modulation_cmd)
2125{
2126 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2127 int rc = 0;
2128
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002129 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]",
2130 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002131 ac->session, frames_per_buf, min_rate, max_rate,
2132 reduced_rate_level, rate_modulation_cmd);
2133
2134 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2135
2136 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2137
2138 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2139 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2140
2141 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2142 enc_cfg.enc_blk.format_id = V13K_FS;
2143 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_qcelp13_read_cfg);
2144 enc_cfg.enc_blk.cfg.qcelp13.min_rate = min_rate;
2145 enc_cfg.enc_blk.cfg.qcelp13.max_rate = max_rate;
2146 enc_cfg.enc_blk.cfg.qcelp13.reduced_rate_level = reduced_rate_level;
2147 enc_cfg.enc_blk.cfg.qcelp13.rate_modulation_cmd = rate_modulation_cmd;
2148
2149 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2150 if (rc < 0) {
2151 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2152 goto fail_cmd;
2153 }
2154 rc = wait_event_timeout(ac->cmd_wait,
2155 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2156 if (!rc) {
2157 pr_err("timeout. waited for FORMAT_UPDATE\n");
2158 goto fail_cmd;
2159 }
2160 return 0;
2161fail_cmd:
2162 return -EINVAL;
2163}
2164
2165int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf,
2166 uint16_t min_rate, uint16_t max_rate,
2167 uint16_t rate_modulation_cmd)
2168{
2169 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2170 int rc = 0;
2171
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002172 pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] rate_modulation_cmd[0x%4x]",
2173 __func__, ac->session,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002174 frames_per_buf, min_rate, max_rate, rate_modulation_cmd);
2175
2176 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2177
2178 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2179
2180 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2181 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2182
2183 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2184 enc_cfg.enc_blk.format_id = EVRC_FS;
2185 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_evrc_read_cfg);
2186 enc_cfg.enc_blk.cfg.evrc.min_rate = min_rate;
2187 enc_cfg.enc_blk.cfg.evrc.max_rate = max_rate;
2188 enc_cfg.enc_blk.cfg.evrc.rate_modulation_cmd = rate_modulation_cmd;
2189 enc_cfg.enc_blk.cfg.evrc.reserved = 0;
2190
2191 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2192 if (rc < 0) {
2193 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2194 goto fail_cmd;
2195 }
2196 rc = wait_event_timeout(ac->cmd_wait,
2197 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2198 if (!rc) {
2199 pr_err("timeout. waited for FORMAT_UPDATE\n");
2200 goto fail_cmd;
2201 }
2202 return 0;
2203fail_cmd:
2204 return -EINVAL;
2205}
2206
2207int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf,
2208 uint16_t band_mode, uint16_t dtx_enable)
2209{
2210 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2211 int rc = 0;
2212
2213 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
2214 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
2215
2216 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2217
2218 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2219
2220 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2221 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2222
2223 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2224 enc_cfg.enc_blk.format_id = AMRNB_FS;
2225 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrnb_read_cfg);
2226 enc_cfg.enc_blk.cfg.amrnb.mode = band_mode;
2227 enc_cfg.enc_blk.cfg.amrnb.dtx_mode = dtx_enable;
2228
2229 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2230 if (rc < 0) {
2231 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2232 goto fail_cmd;
2233 }
2234 rc = wait_event_timeout(ac->cmd_wait,
2235 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2236 if (!rc) {
2237 pr_err("timeout. waited for FORMAT_UPDATE\n");
2238 goto fail_cmd;
2239 }
2240 return 0;
2241fail_cmd:
2242 return -EINVAL;
2243}
2244
Alex Wong2caeecc2011-10-28 10:52:15 +05302245int q6asm_enc_cfg_blk_amrwb(struct audio_client *ac, uint32_t frames_per_buf,
2246 uint16_t band_mode, uint16_t dtx_enable)
2247{
2248 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2249 int rc = 0;
2250
2251 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
2252 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
2253
2254 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2255
2256 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2257
2258 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2259 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2260
2261 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2262 enc_cfg.enc_blk.format_id = AMRWB_FS;
2263 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrwb_read_cfg);
2264 enc_cfg.enc_blk.cfg.amrwb.mode = band_mode;
2265 enc_cfg.enc_blk.cfg.amrwb.dtx_mode = dtx_enable;
2266
2267 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2268 if (rc < 0) {
2269 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2270 goto fail_cmd;
2271 }
2272 rc = wait_event_timeout(ac->cmd_wait,
2273 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2274 if (!rc) {
2275 pr_err("timeout. waited for FORMAT_UPDATE\n");
2276 goto fail_cmd;
2277 }
2278 return 0;
2279fail_cmd:
2280 return -EINVAL;
2281}
2282
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002283int q6asm_media_format_block_pcm(struct audio_client *ac,
2284 uint32_t rate, uint32_t channels)
2285{
2286 struct asm_stream_media_format_update fmt;
2287 int rc = 0;
2288
2289 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
2290 channels);
2291
2292 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2293
2294 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2295
2296 fmt.format = LINEAR_PCM;
2297 fmt.cfg_size = sizeof(struct asm_pcm_cfg);
2298 fmt.write_cfg.pcm_cfg.ch_cfg = channels;
2299 fmt.write_cfg.pcm_cfg.bits_per_sample = 16;
2300 fmt.write_cfg.pcm_cfg.sample_rate = rate;
2301 fmt.write_cfg.pcm_cfg.is_signed = 1;
2302 fmt.write_cfg.pcm_cfg.interleaved = 1;
2303
2304 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2305 if (rc < 0) {
2306 pr_err("%s:Comamnd open failed\n", __func__);
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("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2313 goto fail_cmd;
2314 }
2315 return 0;
2316fail_cmd:
2317 return -EINVAL;
2318}
2319
Kiran Kandi5e809b02012-01-31 00:24:33 -08002320int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
2321 uint32_t rate, uint32_t channels)
2322{
2323 struct asm_stream_media_format_update fmt;
2324 u8 *channel_mapping;
2325 int rc = 0;
2326
2327 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
2328 channels);
2329
2330 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2331
2332 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2333
2334 fmt.format = MULTI_CHANNEL_PCM;
2335 fmt.cfg_size = sizeof(struct asm_multi_channel_pcm_fmt_blk);
2336 fmt.write_cfg.multi_ch_pcm_cfg.num_channels = channels;
2337 fmt.write_cfg.multi_ch_pcm_cfg.bits_per_sample = 16;
2338 fmt.write_cfg.multi_ch_pcm_cfg.sample_rate = rate;
2339 fmt.write_cfg.multi_ch_pcm_cfg.is_signed = 1;
2340 fmt.write_cfg.multi_ch_pcm_cfg.is_interleaved = 1;
2341 channel_mapping =
2342 fmt.write_cfg.multi_ch_pcm_cfg.channel_mapping;
2343
2344 memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
2345
2346 if (channels == 1) {
2347 channel_mapping[0] = PCM_CHANNEL_FL;
2348 } else if (channels == 2) {
2349 channel_mapping[0] = PCM_CHANNEL_FL;
2350 channel_mapping[1] = PCM_CHANNEL_FR;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002351 } else if (channels == 4) {
2352 channel_mapping[0] = PCM_CHANNEL_FL;
2353 channel_mapping[1] = PCM_CHANNEL_FR;
2354 channel_mapping[1] = PCM_CHANNEL_LB;
2355 channel_mapping[1] = PCM_CHANNEL_RB;
Kiran Kandi5e809b02012-01-31 00:24:33 -08002356 } else if (channels == 6) {
SathishKumar Mani6074b772012-09-26 13:49:49 -07002357 channel_mapping[0] = PCM_CHANNEL_FL;
2358 channel_mapping[1] = PCM_CHANNEL_FR;
2359 channel_mapping[2] = PCM_CHANNEL_FC;
2360 channel_mapping[3] = PCM_CHANNEL_LFE;
2361 channel_mapping[4] = PCM_CHANNEL_LB;
2362 channel_mapping[5] = PCM_CHANNEL_RB;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002363 } else if (channels == 8) {
2364 channel_mapping[0] = PCM_CHANNEL_FC;
2365 channel_mapping[1] = PCM_CHANNEL_FL;
2366 channel_mapping[2] = PCM_CHANNEL_FR;
2367 channel_mapping[3] = PCM_CHANNEL_LB;
2368 channel_mapping[4] = PCM_CHANNEL_RB;
2369 channel_mapping[5] = PCM_CHANNEL_LFE;
2370 channel_mapping[6] = PCM_CHANNEL_FLC;
2371 channel_mapping[7] = PCM_CHANNEL_FRC;
Kiran Kandi5e809b02012-01-31 00:24:33 -08002372 } else {
2373 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
2374 channels);
2375 return -EINVAL;
2376 }
2377
2378 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2379 if (rc < 0) {
2380 pr_err("%s:Comamnd open failed\n", __func__);
2381 goto fail_cmd;
2382 }
2383 rc = wait_event_timeout(ac->cmd_wait,
2384 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2385 if (!rc) {
2386 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2387 goto fail_cmd;
2388 }
2389 return 0;
2390fail_cmd:
2391 return -EINVAL;
2392}
2393
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002394int q6asm_media_format_block_aac(struct audio_client *ac,
2395 struct asm_aac_cfg *cfg)
2396{
2397 struct asm_stream_media_format_update fmt;
2398 int rc = 0;
2399
2400 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2401 cfg->sample_rate, cfg->ch_cfg);
2402
2403 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2404
2405 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2406
2407 fmt.format = MPEG4_AAC;
2408 fmt.cfg_size = sizeof(struct asm_aac_cfg);
2409 fmt.write_cfg.aac_cfg.format = cfg->format;
2410 fmt.write_cfg.aac_cfg.aot = cfg->aot;
2411 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
2412 fmt.write_cfg.aac_cfg.section_data_resilience =
2413 cfg->section_data_resilience;
2414 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2415 cfg->scalefactor_data_resilience;
2416 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2417 cfg->spectral_data_resilience;
2418 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2419 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2420 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2421 __func__, fmt.format, fmt.cfg_size,
2422 fmt.write_cfg.aac_cfg.format,
2423 fmt.write_cfg.aac_cfg.aot,
2424 fmt.write_cfg.aac_cfg.ch_cfg,
2425 fmt.write_cfg.aac_cfg.sample_rate);
2426 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2427 if (rc < 0) {
2428 pr_err("%s:Comamnd open failed\n", __func__);
2429 goto fail_cmd;
2430 }
2431 rc = wait_event_timeout(ac->cmd_wait,
2432 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2433 if (!rc) {
2434 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2435 goto fail_cmd;
2436 }
2437 return 0;
2438fail_cmd:
2439 return -EINVAL;
2440}
2441
Ajit Khare43fd8832012-08-07 13:19:44 -07002442int q6asm_media_format_block_amrwbplus(struct audio_client *ac,
2443 struct asm_amrwbplus_cfg *cfg)
2444{
2445 struct asm_stream_media_format_update fmt;
2446 int rc = 0;
2447 pr_debug("q6asm_media_format_block_amrwbplus");
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07002448
Ajit Khare43fd8832012-08-07 13:19:44 -07002449 pr_debug("%s:session[%d]band-mode[%d]frame-fmt[%d]ch[%d]\n",
2450 __func__,
2451 ac->session,
2452 cfg->amr_band_mode,
2453 cfg->amr_frame_fmt,
2454 cfg->num_channels);
2455
2456 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2457
2458 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2459
2460 fmt.format = AMR_WB_PLUS;
2461 fmt.cfg_size = cfg->size_bytes;
2462
2463 fmt.write_cfg.amrwbplus_cfg.size_bytes = cfg->size_bytes;
2464 fmt.write_cfg.amrwbplus_cfg.version = cfg->version;
2465 fmt.write_cfg.amrwbplus_cfg.num_channels = cfg->num_channels;
2466 fmt.write_cfg.amrwbplus_cfg.amr_band_mode = cfg->amr_band_mode;
2467 fmt.write_cfg.amrwbplus_cfg.amr_dtx_mode = cfg->amr_dtx_mode;
2468 fmt.write_cfg.amrwbplus_cfg.amr_frame_fmt = cfg->amr_frame_fmt;
2469 fmt.write_cfg.amrwbplus_cfg.amr_lsf_idx = cfg->amr_lsf_idx;
2470
2471 pr_debug("%s: num_channels=%x amr_band_mode=%d amr_frame_fmt=%d\n",
2472 __func__,
2473 cfg->num_channels,
2474 cfg->amr_band_mode,
2475 cfg->amr_frame_fmt);
2476
2477 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2478 if (rc < 0) {
2479 pr_err("%s:Comamnd media format update failed..\n", __func__);
2480 goto fail_cmd;
2481 }
2482 rc = wait_event_timeout(ac->cmd_wait,
2483 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2484 if (!rc) {
2485 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2486 goto fail_cmd;
2487 }
2488 return 0;
2489fail_cmd:
2490 return -EINVAL;
2491}
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07002492int q6asm_media_format_block_multi_aac(struct audio_client *ac,
2493 struct asm_aac_cfg *cfg)
2494{
2495 struct asm_stream_media_format_update fmt;
2496 int rc = 0;
2497
2498 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2499 cfg->sample_rate, cfg->ch_cfg);
2500
2501 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2502
2503 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2504
2505 fmt.format = MPEG4_MULTI_AAC;
2506 fmt.cfg_size = sizeof(struct asm_aac_cfg);
2507 fmt.write_cfg.aac_cfg.format = cfg->format;
2508 fmt.write_cfg.aac_cfg.aot = cfg->aot;
2509 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
2510 fmt.write_cfg.aac_cfg.section_data_resilience =
2511 cfg->section_data_resilience;
2512 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2513 cfg->scalefactor_data_resilience;
2514 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2515 cfg->spectral_data_resilience;
2516 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2517 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2518 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2519 __func__, fmt.format, fmt.cfg_size,
2520 fmt.write_cfg.aac_cfg.format,
2521 fmt.write_cfg.aac_cfg.aot,
2522 fmt.write_cfg.aac_cfg.ch_cfg,
2523 fmt.write_cfg.aac_cfg.sample_rate);
2524 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2525 if (rc < 0) {
2526 pr_err("%s:Comamnd open failed\n", __func__);
2527 goto fail_cmd;
2528 }
2529 rc = wait_event_timeout(ac->cmd_wait,
2530 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2531 if (!rc) {
2532 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2533 goto fail_cmd;
2534 }
2535 return 0;
2536fail_cmd:
2537 return -EINVAL;
2538}
2539
2540
Alex Wong2caeecc2011-10-28 10:52:15 +05302541
2542int q6asm_media_format_block(struct audio_client *ac, uint32_t format)
2543{
2544
2545 struct asm_stream_media_format_update fmt;
2546 int rc = 0;
2547
2548 pr_debug("%s:session[%d] format[0x%x]\n", __func__,
2549 ac->session, format);
2550
2551 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2552 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302553 switch (format) {
2554 case FORMAT_V13K:
2555 fmt.format = V13K_FS;
2556 break;
2557 case FORMAT_EVRC:
2558 fmt.format = EVRC_FS;
2559 break;
2560 case FORMAT_AMRWB:
2561 fmt.format = AMRWB_FS;
2562 break;
Ajit Khare43fd8832012-08-07 13:19:44 -07002563 case FORMAT_AMR_WB_PLUS:
2564 fmt.format = AMR_WB_PLUS;
2565 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302566 case FORMAT_AMRNB:
2567 fmt.format = AMRNB_FS;
2568 break;
2569 case FORMAT_MP3:
2570 fmt.format = MP3;
2571 break;
Srikanth Uyyala66f781a2012-06-13 23:23:25 +05302572 case FORMAT_DTS:
2573 fmt.format = DTS;
2574 break;
2575 case FORMAT_DTS_LBR:
2576 fmt.format = DTS_LBR;
2577 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302578 default:
2579 pr_err("Invalid format[%d]\n", format);
2580 goto fail_cmd;
2581 }
Alex Wong2caeecc2011-10-28 10:52:15 +05302582 fmt.cfg_size = 0;
2583
2584 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2585 if (rc < 0) {
2586 pr_err("%s:Comamnd open failed\n", __func__);
2587 goto fail_cmd;
2588 }
2589 rc = wait_event_timeout(ac->cmd_wait,
2590 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2591 if (!rc) {
2592 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2593 goto fail_cmd;
2594 }
2595 return 0;
2596fail_cmd:
2597 return -EINVAL;
2598}
2599
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002600int q6asm_media_format_block_wma(struct audio_client *ac,
2601 void *cfg)
2602{
2603 struct asm_stream_media_format_update fmt;
2604 struct asm_wma_cfg *wma_cfg = (struct asm_wma_cfg *)cfg;
2605 int rc = 0;
2606
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002607 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 -07002608 ac->session, wma_cfg->format_tag, wma_cfg->sample_rate,
2609 wma_cfg->ch_cfg, wma_cfg->avg_bytes_per_sec,
2610 wma_cfg->block_align, wma_cfg->valid_bits_per_sample,
2611 wma_cfg->ch_mask, wma_cfg->encode_opt);
2612
2613 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2614
2615 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2616
2617 fmt.format = WMA_V9;
2618 fmt.cfg_size = sizeof(struct asm_wma_cfg);
2619 fmt.write_cfg.wma_cfg.format_tag = wma_cfg->format_tag;
2620 fmt.write_cfg.wma_cfg.ch_cfg = wma_cfg->ch_cfg;
2621 fmt.write_cfg.wma_cfg.sample_rate = wma_cfg->sample_rate;
2622 fmt.write_cfg.wma_cfg.avg_bytes_per_sec = wma_cfg->avg_bytes_per_sec;
2623 fmt.write_cfg.wma_cfg.block_align = wma_cfg->block_align;
2624 fmt.write_cfg.wma_cfg.valid_bits_per_sample =
2625 wma_cfg->valid_bits_per_sample;
2626 fmt.write_cfg.wma_cfg.ch_mask = wma_cfg->ch_mask;
2627 fmt.write_cfg.wma_cfg.encode_opt = wma_cfg->encode_opt;
2628 fmt.write_cfg.wma_cfg.adv_encode_opt = 0;
2629 fmt.write_cfg.wma_cfg.adv_encode_opt2 = 0;
2630 fmt.write_cfg.wma_cfg.drc_peak_ref = 0;
2631 fmt.write_cfg.wma_cfg.drc_peak_target = 0;
2632 fmt.write_cfg.wma_cfg.drc_ave_ref = 0;
2633 fmt.write_cfg.wma_cfg.drc_ave_target = 0;
2634
2635 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2636 if (rc < 0) {
2637 pr_err("%s:Comamnd open failed\n", __func__);
2638 goto fail_cmd;
2639 }
2640 rc = wait_event_timeout(ac->cmd_wait,
2641 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2642 if (!rc) {
2643 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2644 goto fail_cmd;
2645 }
2646 return 0;
2647fail_cmd:
2648 return -EINVAL;
2649}
2650
2651int q6asm_media_format_block_wmapro(struct audio_client *ac,
2652 void *cfg)
2653{
2654 struct asm_stream_media_format_update fmt;
2655 struct asm_wmapro_cfg *wmapro_cfg = (struct asm_wmapro_cfg *)cfg;
2656 int rc = 0;
2657
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002658 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 -07002659 ac->session, wmapro_cfg->format_tag, wmapro_cfg->sample_rate,
2660 wmapro_cfg->ch_cfg, wmapro_cfg->avg_bytes_per_sec,
2661 wmapro_cfg->block_align, wmapro_cfg->valid_bits_per_sample,
2662 wmapro_cfg->ch_mask, wmapro_cfg->encode_opt,
2663 wmapro_cfg->adv_encode_opt, wmapro_cfg->adv_encode_opt2);
2664
2665 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2666
2667 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2668
2669 fmt.format = WMA_V10PRO;
2670 fmt.cfg_size = sizeof(struct asm_wmapro_cfg);
2671 fmt.write_cfg.wmapro_cfg.format_tag = wmapro_cfg->format_tag;
2672 fmt.write_cfg.wmapro_cfg.ch_cfg = wmapro_cfg->ch_cfg;
2673 fmt.write_cfg.wmapro_cfg.sample_rate = wmapro_cfg->sample_rate;
2674 fmt.write_cfg.wmapro_cfg.avg_bytes_per_sec =
2675 wmapro_cfg->avg_bytes_per_sec;
2676 fmt.write_cfg.wmapro_cfg.block_align = wmapro_cfg->block_align;
2677 fmt.write_cfg.wmapro_cfg.valid_bits_per_sample =
2678 wmapro_cfg->valid_bits_per_sample;
2679 fmt.write_cfg.wmapro_cfg.ch_mask = wmapro_cfg->ch_mask;
2680 fmt.write_cfg.wmapro_cfg.encode_opt = wmapro_cfg->encode_opt;
2681 fmt.write_cfg.wmapro_cfg.adv_encode_opt = wmapro_cfg->adv_encode_opt;
2682 fmt.write_cfg.wmapro_cfg.adv_encode_opt2 = wmapro_cfg->adv_encode_opt2;
2683 fmt.write_cfg.wmapro_cfg.drc_peak_ref = 0;
2684 fmt.write_cfg.wmapro_cfg.drc_peak_target = 0;
2685 fmt.write_cfg.wmapro_cfg.drc_ave_ref = 0;
2686 fmt.write_cfg.wmapro_cfg.drc_ave_target = 0;
2687
2688 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2689 if (rc < 0) {
2690 pr_err("%s:Comamnd open failed\n", __func__);
2691 goto fail_cmd;
2692 }
2693 rc = wait_event_timeout(ac->cmd_wait,
2694 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2695 if (!rc) {
2696 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2697 goto fail_cmd;
2698 }
2699 return 0;
2700fail_cmd:
2701 return -EINVAL;
2702}
2703
2704int q6asm_memory_map(struct audio_client *ac, uint32_t buf_add, int dir,
2705 uint32_t bufsz, uint32_t bufcnt)
2706{
2707 struct asm_stream_cmd_memory_map mem_map;
2708 int rc = 0;
2709
2710 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2711 pr_err("APR handle NULL\n");
2712 return -EINVAL;
2713 }
2714
2715 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2716
2717 mem_map.hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP;
2718
2719 mem_map.buf_add = buf_add;
2720 mem_map.buf_size = bufsz * bufcnt;
2721 mem_map.mempool_id = 0; /* EBI */
2722 mem_map.reserved = 0;
2723
2724 q6asm_add_mmaphdr(&mem_map.hdr,
2725 sizeof(struct asm_stream_cmd_memory_map), TRUE);
2726
2727 pr_debug("buf add[%x] buf_add_parameter[%x]\n",
2728 mem_map.buf_add, buf_add);
2729
2730 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_map);
2731 if (rc < 0) {
2732 pr_err("mem_map op[0x%x]rc[%d]\n",
2733 mem_map.hdr.opcode, rc);
2734 rc = -EINVAL;
2735 goto fail_cmd;
2736 }
2737
2738 rc = wait_event_timeout(this_mmap.cmd_wait,
2739 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2740 if (!rc) {
2741 pr_err("timeout. waited for memory_map\n");
2742 rc = -EINVAL;
2743 goto fail_cmd;
2744 }
2745 rc = 0;
2746fail_cmd:
2747 return rc;
2748}
2749
2750int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add, int dir)
2751{
2752 struct asm_stream_cmd_memory_unmap mem_unmap;
2753 int rc = 0;
2754
2755 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2756 pr_err("APR handle NULL\n");
2757 return -EINVAL;
2758 }
2759 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2760
2761 q6asm_add_mmaphdr(&mem_unmap.hdr,
2762 sizeof(struct asm_stream_cmd_memory_unmap), TRUE);
2763 mem_unmap.hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP;
2764 mem_unmap.buf_add = buf_add;
2765
2766 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_unmap);
2767 if (rc < 0) {
2768 pr_err("mem_unmap op[0x%x]rc[%d]\n",
2769 mem_unmap.hdr.opcode, rc);
2770 rc = -EINVAL;
2771 goto fail_cmd;
2772 }
2773
2774 rc = wait_event_timeout(this_mmap.cmd_wait,
2775 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2776 if (!rc) {
2777 pr_err("timeout. waited for memory_map\n");
2778 rc = -EINVAL;
2779 goto fail_cmd;
2780 }
2781 rc = 0;
2782fail_cmd:
2783 return rc;
2784}
2785
2786int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain)
2787{
2788 void *vol_cmd = NULL;
2789 void *payload = NULL;
2790 struct asm_pp_params_command *cmd = NULL;
2791 struct asm_lrchannel_gain_params *lrgain = NULL;
2792 int sz = 0;
2793 int rc = 0;
2794
2795 sz = sizeof(struct asm_pp_params_command) +
2796 + sizeof(struct asm_lrchannel_gain_params);
2797 vol_cmd = kzalloc(sz, GFP_KERNEL);
2798 if (vol_cmd == NULL) {
2799 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2800 rc = -EINVAL;
2801 return rc;
2802 }
2803 cmd = (struct asm_pp_params_command *)vol_cmd;
2804 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2805 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2806 cmd->payload = NULL;
2807 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2808 sizeof(struct asm_lrchannel_gain_params);
2809 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2810 cmd->params.param_id = L_R_CHANNEL_GAIN_PARAM_ID;
2811 cmd->params.param_size = sizeof(struct asm_lrchannel_gain_params);
2812 cmd->params.reserved = 0;
2813
2814 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2815 lrgain = (struct asm_lrchannel_gain_params *)payload;
2816
2817 lrgain->left_gain = left_gain;
2818 lrgain->right_gain = right_gain;
2819 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2820 if (rc < 0) {
2821 pr_err("%s: Volume Command failed\n", __func__);
2822 rc = -EINVAL;
2823 goto fail_cmd;
2824 }
2825
2826 rc = wait_event_timeout(ac->cmd_wait,
2827 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2828 if (!rc) {
2829 pr_err("%s: timeout in sending volume command to apr\n",
2830 __func__);
2831 rc = -EINVAL;
2832 goto fail_cmd;
2833 }
2834 rc = 0;
2835fail_cmd:
2836 kfree(vol_cmd);
2837 return rc;
2838}
2839
2840static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
2841 uint32_t bufsz, uint32_t bufcnt)
2842{
2843 struct asm_stream_cmd_memory_map_regions *mmap_regions = NULL;
2844 struct asm_memory_map_regions *mregions = NULL;
2845 struct audio_port_data *port = NULL;
2846 struct audio_buffer *ab = NULL;
2847 void *mmap_region_cmd = NULL;
2848 void *payload = NULL;
2849 int rc = 0;
2850 int i = 0;
2851 int cmd_size = 0;
2852
2853 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2854 pr_err("APR handle NULL\n");
2855 return -EINVAL;
2856 }
2857 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2858
2859 cmd_size = sizeof(struct asm_stream_cmd_memory_map_regions)
2860 + sizeof(struct asm_memory_map_regions) * bufcnt;
2861
2862 mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302863 if (mmap_region_cmd == NULL) {
2864 pr_err("%s: Mem alloc failed\n", __func__);
2865 rc = -EINVAL;
2866 return rc;
2867 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002868 mmap_regions = (struct asm_stream_cmd_memory_map_regions *)
2869 mmap_region_cmd;
2870 q6asm_add_mmaphdr(&mmap_regions->hdr, cmd_size, TRUE);
2871 mmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP_REGIONS;
2872 mmap_regions->mempool_id = 0;
2873 mmap_regions->nregions = bufcnt & 0x00ff;
2874 pr_debug("map_regions->nregions = %d\n", mmap_regions->nregions);
2875 payload = ((u8 *) mmap_region_cmd +
2876 sizeof(struct asm_stream_cmd_memory_map_regions));
2877 mregions = (struct asm_memory_map_regions *)payload;
2878
2879 port = &ac->port[dir];
2880 for (i = 0; i < bufcnt; i++) {
2881 ab = &port->buf[i];
2882 mregions->phys = ab->phys;
2883 mregions->buf_size = ab->size;
2884 ++mregions;
2885 }
2886
2887 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) mmap_region_cmd);
2888 if (rc < 0) {
2889 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2890 mmap_regions->hdr.opcode, rc);
2891 rc = -EINVAL;
2892 goto fail_cmd;
2893 }
2894
2895 rc = wait_event_timeout(this_mmap.cmd_wait,
2896 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2897 if (!rc) {
2898 pr_err("timeout. waited for memory_map\n");
2899 rc = -EINVAL;
2900 goto fail_cmd;
2901 }
2902 rc = 0;
2903fail_cmd:
2904 kfree(mmap_region_cmd);
2905 return rc;
2906}
2907
2908static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir,
2909 uint32_t bufsz, uint32_t bufcnt)
2910{
2911 struct asm_stream_cmd_memory_unmap_regions *unmap_regions = NULL;
2912 struct asm_memory_unmap_regions *mregions = NULL;
2913 struct audio_port_data *port = NULL;
2914 struct audio_buffer *ab = NULL;
2915 void *unmap_region_cmd = NULL;
2916 void *payload = NULL;
2917 int rc = 0;
2918 int i = 0;
2919 int cmd_size = 0;
2920
2921 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2922 pr_err("APR handle NULL\n");
2923 return -EINVAL;
2924 }
2925 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2926
2927 cmd_size = sizeof(struct asm_stream_cmd_memory_unmap_regions) +
2928 sizeof(struct asm_memory_unmap_regions) * bufcnt;
2929
2930 unmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302931 if (unmap_region_cmd == NULL) {
2932 pr_err("%s: Mem alloc failed\n", __func__);
2933 rc = -EINVAL;
2934 return rc;
2935 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002936 unmap_regions = (struct asm_stream_cmd_memory_unmap_regions *)
2937 unmap_region_cmd;
2938 q6asm_add_mmaphdr(&unmap_regions->hdr, cmd_size, TRUE);
2939 unmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS;
2940 unmap_regions->nregions = bufcnt & 0x00ff;
2941 pr_debug("unmap_regions->nregions = %d\n", unmap_regions->nregions);
2942 payload = ((u8 *) unmap_region_cmd +
2943 sizeof(struct asm_stream_cmd_memory_unmap_regions));
2944 mregions = (struct asm_memory_unmap_regions *)payload;
2945 port = &ac->port[dir];
2946 for (i = 0; i < bufcnt; i++) {
2947 ab = &port->buf[i];
2948 mregions->phys = ab->phys;
2949 ++mregions;
2950 }
2951
2952 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) unmap_region_cmd);
2953 if (rc < 0) {
2954 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2955 unmap_regions->hdr.opcode, rc);
2956 goto fail_cmd;
2957 }
2958
2959 rc = wait_event_timeout(this_mmap.cmd_wait,
2960 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2961 if (!rc) {
2962 pr_err("timeout. waited for memory_unmap\n");
2963 goto fail_cmd;
2964 }
2965 rc = 0;
2966
2967fail_cmd:
2968 kfree(unmap_region_cmd);
2969 return rc;
2970}
2971
2972int q6asm_set_mute(struct audio_client *ac, int muteflag)
2973{
2974 void *vol_cmd = NULL;
2975 void *payload = NULL;
2976 struct asm_pp_params_command *cmd = NULL;
2977 struct asm_mute_params *mute = NULL;
2978 int sz = 0;
2979 int rc = 0;
2980
2981 sz = sizeof(struct asm_pp_params_command) +
2982 + sizeof(struct asm_mute_params);
2983 vol_cmd = kzalloc(sz, GFP_KERNEL);
2984 if (vol_cmd == NULL) {
2985 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2986 rc = -EINVAL;
2987 return rc;
2988 }
2989 cmd = (struct asm_pp_params_command *)vol_cmd;
2990 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2991 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2992 cmd->payload = NULL;
2993 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2994 sizeof(struct asm_mute_params);
2995 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2996 cmd->params.param_id = MUTE_CONFIG_PARAM_ID;
2997 cmd->params.param_size = sizeof(struct asm_mute_params);
2998 cmd->params.reserved = 0;
2999
3000 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3001 mute = (struct asm_mute_params *)payload;
3002
3003 mute->muteflag = muteflag;
3004 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3005 if (rc < 0) {
3006 pr_err("%s: Mute Command failed\n", __func__);
3007 rc = -EINVAL;
3008 goto fail_cmd;
3009 }
3010
3011 rc = wait_event_timeout(ac->cmd_wait,
3012 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3013 if (!rc) {
3014 pr_err("%s: timeout in sending mute command to apr\n",
3015 __func__);
3016 rc = -EINVAL;
3017 goto fail_cmd;
3018 }
3019 rc = 0;
3020fail_cmd:
3021 kfree(vol_cmd);
3022 return rc;
3023}
3024
3025int q6asm_set_volume(struct audio_client *ac, int volume)
3026{
3027 void *vol_cmd = NULL;
3028 void *payload = NULL;
3029 struct asm_pp_params_command *cmd = NULL;
3030 struct asm_master_gain_params *mgain = NULL;
3031 int sz = 0;
3032 int rc = 0;
3033
3034 sz = sizeof(struct asm_pp_params_command) +
3035 + sizeof(struct asm_master_gain_params);
3036 vol_cmd = kzalloc(sz, GFP_KERNEL);
3037 if (vol_cmd == NULL) {
3038 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3039 rc = -EINVAL;
3040 return rc;
3041 }
3042 cmd = (struct asm_pp_params_command *)vol_cmd;
3043 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3044 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3045 cmd->payload = NULL;
3046 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3047 sizeof(struct asm_master_gain_params);
3048 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3049 cmd->params.param_id = MASTER_GAIN_PARAM_ID;
3050 cmd->params.param_size = sizeof(struct asm_master_gain_params);
3051 cmd->params.reserved = 0;
3052
3053 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3054 mgain = (struct asm_master_gain_params *)payload;
3055
3056 mgain->master_gain = volume;
3057 mgain->padding = 0x00;
3058 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3059 if (rc < 0) {
3060 pr_err("%s: Volume Command failed\n", __func__);
3061 rc = -EINVAL;
3062 goto fail_cmd;
3063 }
3064
3065 rc = wait_event_timeout(ac->cmd_wait,
3066 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3067 if (!rc) {
3068 pr_err("%s: timeout in sending volume command to apr\n",
3069 __func__);
3070 rc = -EINVAL;
3071 goto fail_cmd;
3072 }
3073 rc = 0;
3074fail_cmd:
3075 kfree(vol_cmd);
3076 return rc;
3077}
3078
3079int q6asm_set_softpause(struct audio_client *ac,
3080 struct asm_softpause_params *pause_param)
3081{
3082 void *vol_cmd = NULL;
3083 void *payload = NULL;
3084 struct asm_pp_params_command *cmd = NULL;
3085 struct asm_softpause_params *params = NULL;
3086 int sz = 0;
3087 int rc = 0;
3088
3089 sz = sizeof(struct asm_pp_params_command) +
3090 + sizeof(struct asm_softpause_params);
3091 vol_cmd = kzalloc(sz, GFP_KERNEL);
3092 if (vol_cmd == NULL) {
3093 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3094 rc = -EINVAL;
3095 return rc;
3096 }
3097 cmd = (struct asm_pp_params_command *)vol_cmd;
3098 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3099 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3100 cmd->payload = NULL;
3101 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3102 sizeof(struct asm_softpause_params);
3103 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3104 cmd->params.param_id = SOFT_PAUSE_PARAM_ID;
3105 cmd->params.param_size = sizeof(struct asm_softpause_params);
3106 cmd->params.reserved = 0;
3107
3108 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3109 params = (struct asm_softpause_params *)payload;
3110
3111 params->enable = pause_param->enable;
3112 params->period = pause_param->period;
3113 params->step = pause_param->step;
3114 params->rampingcurve = pause_param->rampingcurve;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003115 pr_debug("%s: soft Pause Command: enable = %d, period = %d, step = %d, curve = %d\n",
3116 __func__, params->enable,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003117 params->period, params->step, params->rampingcurve);
3118 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3119 if (rc < 0) {
3120 pr_err("%s: Volume Command(soft_pause) failed\n", __func__);
3121 rc = -EINVAL;
3122 goto fail_cmd;
3123 }
3124
3125 rc = wait_event_timeout(ac->cmd_wait,
3126 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3127 if (!rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003128 pr_err("%s: timeout in sending volume command(soft_pause) to apr\n",
3129 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003130 rc = -EINVAL;
3131 goto fail_cmd;
3132 }
3133 rc = 0;
3134fail_cmd:
3135 kfree(vol_cmd);
3136 return rc;
3137}
3138
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003139int q6asm_set_softvolume(struct audio_client *ac,
3140 struct asm_softvolume_params *softvol_param)
3141{
3142 void *vol_cmd = NULL;
3143 void *payload = NULL;
3144 struct asm_pp_params_command *cmd = NULL;
3145 struct asm_softvolume_params *params = NULL;
3146 int sz = 0;
3147 int rc = 0;
3148
3149 sz = sizeof(struct asm_pp_params_command) +
3150 + sizeof(struct asm_softvolume_params);
3151 vol_cmd = kzalloc(sz, GFP_KERNEL);
3152 if (vol_cmd == NULL) {
3153 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3154 rc = -EINVAL;
3155 return rc;
3156 }
3157 cmd = (struct asm_pp_params_command *)vol_cmd;
3158 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3159 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3160 cmd->payload = NULL;
3161 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3162 sizeof(struct asm_softvolume_params);
3163 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3164 cmd->params.param_id = SOFT_VOLUME_PARAM_ID;
3165 cmd->params.param_size = sizeof(struct asm_softvolume_params);
3166 cmd->params.reserved = 0;
3167
3168 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3169 params = (struct asm_softvolume_params *)payload;
3170
3171 params->period = softvol_param->period;
3172 params->step = softvol_param->step;
3173 params->rampingcurve = softvol_param->rampingcurve;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003174 pr_debug("%s: soft Volume:opcode = %d,payload_sz =%d,module_id =%d, param_id = %d, param_sz = %d\n",
3175 __func__,
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003176 cmd->hdr.opcode, cmd->payload_size,
3177 cmd->params.module_id, cmd->params.param_id,
3178 cmd->params.param_size);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003179 pr_debug("%s: soft Volume Command: period = %d, step = %d, curve = %d\n",
3180 __func__, params->period,
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003181 params->step, params->rampingcurve);
3182 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3183 if (rc < 0) {
3184 pr_err("%s: Volume Command(soft_volume) failed\n", __func__);
3185 rc = -EINVAL;
3186 goto fail_cmd;
3187 }
3188
3189 rc = wait_event_timeout(ac->cmd_wait,
3190 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3191 if (!rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003192 pr_err("%s: timeout in sending volume command(soft_volume) to apr\n",
3193 __func__);
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003194 rc = -EINVAL;
3195 goto fail_cmd;
3196 }
3197 rc = 0;
3198fail_cmd:
3199 kfree(vol_cmd);
3200 return rc;
3201}
3202
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003203int q6asm_equalizer(struct audio_client *ac, void *eq)
3204{
3205 void *eq_cmd = NULL;
3206 void *payload = NULL;
3207 struct asm_pp_params_command *cmd = NULL;
3208 struct asm_equalizer_params *equalizer = NULL;
3209 struct msm_audio_eq_stream_config *eq_params = NULL;
3210 int i = 0;
3211 int sz = 0;
3212 int rc = 0;
3213
3214 sz = sizeof(struct asm_pp_params_command) +
3215 + sizeof(struct asm_equalizer_params);
3216 eq_cmd = kzalloc(sz, GFP_KERNEL);
3217 if (eq_cmd == NULL) {
3218 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3219 rc = -EINVAL;
3220 goto fail_cmd;
3221 }
3222 eq_params = (struct msm_audio_eq_stream_config *) eq;
3223 cmd = (struct asm_pp_params_command *)eq_cmd;
3224 q6asm_add_hdr(ac, &cmd->hdr, sz, TRUE);
3225 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3226 cmd->payload = NULL;
3227 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3228 sizeof(struct asm_equalizer_params);
3229 cmd->params.module_id = EQUALIZER_MODULE_ID;
3230 cmd->params.param_id = EQUALIZER_PARAM_ID;
3231 cmd->params.param_size = sizeof(struct asm_equalizer_params);
3232 cmd->params.reserved = 0;
3233 payload = (u8 *)(eq_cmd + sizeof(struct asm_pp_params_command));
3234 equalizer = (struct asm_equalizer_params *)payload;
3235
3236 equalizer->enable = eq_params->enable;
3237 equalizer->num_bands = eq_params->num_bands;
3238 pr_debug("%s: enable:%d numbands:%d\n", __func__, eq_params->enable,
3239 eq_params->num_bands);
3240 for (i = 0; i < eq_params->num_bands; i++) {
3241 equalizer->eq_bands[i].band_idx =
3242 eq_params->eq_bands[i].band_idx;
3243 equalizer->eq_bands[i].filter_type =
3244 eq_params->eq_bands[i].filter_type;
3245 equalizer->eq_bands[i].center_freq_hz =
3246 eq_params->eq_bands[i].center_freq_hz;
3247 equalizer->eq_bands[i].filter_gain =
3248 eq_params->eq_bands[i].filter_gain;
3249 equalizer->eq_bands[i].q_factor =
3250 eq_params->eq_bands[i].q_factor;
3251 pr_debug("%s: filter_type:%u bandnum:%d\n", __func__,
3252 eq_params->eq_bands[i].filter_type, i);
3253 pr_debug("%s: center_freq_hz:%u bandnum:%d\n", __func__,
3254 eq_params->eq_bands[i].center_freq_hz, i);
3255 pr_debug("%s: filter_gain:%d bandnum:%d\n", __func__,
3256 eq_params->eq_bands[i].filter_gain, i);
3257 pr_debug("%s: q_factor:%d bandnum:%d\n", __func__,
3258 eq_params->eq_bands[i].q_factor, i);
3259 }
3260 rc = apr_send_pkt(ac->apr, (uint32_t *) eq_cmd);
3261 if (rc < 0) {
3262 pr_err("%s: Equalizer Command failed\n", __func__);
3263 rc = -EINVAL;
3264 goto fail_cmd;
3265 }
3266
3267 rc = wait_event_timeout(ac->cmd_wait,
3268 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3269 if (!rc) {
3270 pr_err("%s: timeout in sending equalizer command to apr\n",
3271 __func__);
3272 rc = -EINVAL;
3273 goto fail_cmd;
3274 }
3275 rc = 0;
3276fail_cmd:
3277 kfree(eq_cmd);
3278 return rc;
3279}
3280
3281int q6asm_read(struct audio_client *ac)
3282{
3283 struct asm_stream_cmd_read read;
3284 struct audio_buffer *ab;
3285 int dsp_buf;
3286 struct audio_port_data *port;
3287 int rc;
3288 if (!ac || ac->apr == NULL) {
3289 pr_err("APR handle NULL\n");
3290 return -EINVAL;
3291 }
3292 if (ac->io_mode == SYNC_IO_MODE) {
3293 port = &ac->port[OUT];
3294
3295 q6asm_add_hdr(ac, &read.hdr, sizeof(read), FALSE);
3296
3297 mutex_lock(&port->lock);
3298
3299 dsp_buf = port->dsp_buf;
3300 ab = &port->buf[dsp_buf];
3301
3302 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
3303 __func__,
3304 ac->session,
3305 dsp_buf,
3306 (void *)port->buf[dsp_buf].data,
3307 port->cpu_buf,
3308 (void *)port->buf[port->cpu_buf].phys);
3309
3310 read.hdr.opcode = ASM_DATA_CMD_READ;
3311 read.buf_add = ab->phys;
3312 read.buf_size = ab->size;
3313 read.uid = port->dsp_buf;
3314 read.hdr.token = port->dsp_buf;
3315
3316 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3317 mutex_unlock(&port->lock);
3318 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
3319 read.buf_add,
3320 read.hdr.token,
3321 read.uid);
3322 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3323 if (rc < 0) {
3324 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
3325 goto fail_cmd;
3326 }
3327 return 0;
3328 }
3329fail_cmd:
3330 return -EINVAL;
3331}
3332
3333int q6asm_read_nolock(struct audio_client *ac)
3334{
3335 struct asm_stream_cmd_read read;
3336 struct audio_buffer *ab;
3337 int dsp_buf;
3338 struct audio_port_data *port;
3339 int rc;
3340 if (!ac || ac->apr == NULL) {
3341 pr_err("APR handle NULL\n");
3342 return -EINVAL;
3343 }
3344 if (ac->io_mode == SYNC_IO_MODE) {
3345 port = &ac->port[OUT];
3346
3347 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3348
3349
3350 dsp_buf = port->dsp_buf;
3351 ab = &port->buf[dsp_buf];
3352
3353 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
3354 __func__,
3355 ac->session,
3356 dsp_buf,
3357 (void *)port->buf[dsp_buf].data,
3358 port->cpu_buf,
3359 (void *)port->buf[port->cpu_buf].phys);
3360
3361 read.hdr.opcode = ASM_DATA_CMD_READ;
3362 read.buf_add = ab->phys;
3363 read.buf_size = ab->size;
3364 read.uid = port->dsp_buf;
3365 read.hdr.token = port->dsp_buf;
3366
3367 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3368 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
3369 read.buf_add,
3370 read.hdr.token,
3371 read.uid);
3372 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3373 if (rc < 0) {
3374 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
3375 goto fail_cmd;
3376 }
3377 return 0;
3378 }
3379fail_cmd:
3380 return -EINVAL;
3381}
3382
3383
3384static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
3385 uint32_t pkt_size, uint32_t cmd_flg)
3386{
3387 pr_debug("session=%d pkt size=%d cmd_flg=%d\n", pkt_size, cmd_flg,
3388 ac->session);
3389 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
3390 APR_HDR_LEN(sizeof(struct apr_hdr)),\
3391 APR_PKT_VER);
3392 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
3393 hdr->src_domain = APR_DOMAIN_APPS;
3394 hdr->dest_svc = APR_SVC_ASM;
3395 hdr->dest_domain = APR_DOMAIN_ADSP;
3396 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
3397 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
3398 if (cmd_flg) {
3399 hdr->token = ac->session;
3400 atomic_set(&ac->cmd_state, 1);
3401 }
3402 hdr->pkt_size = pkt_size;
3403 return;
3404}
3405
3406int q6asm_async_write(struct audio_client *ac,
3407 struct audio_aio_write_param *param)
3408{
3409 int rc = 0;
3410 struct asm_stream_cmd_write write;
3411
3412 if (!ac || ac->apr == NULL) {
3413 pr_err("%s: APR handle NULL\n", __func__);
3414 return -EINVAL;
3415 }
3416
3417 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write), FALSE);
3418
3419 /* Pass physical address as token for AIO scheme */
3420 write.hdr.token = param->uid;
3421 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3422 write.buf_add = param->paddr;
3423 write.avail_bytes = param->len;
3424 write.uid = param->uid;
3425 write.msw_ts = param->msw_ts;
3426 write.lsw_ts = param->lsw_ts;
3427 /* Use 0xFF00 for disabling timestamps */
3428 if (param->flags == 0xFF00)
3429 write.uflags = (0x00000000 | (param->flags & 0x800000FF));
3430 else
3431 write.uflags = (0x80000000 | param->flags);
3432
3433 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3434 write.buf_add, write.avail_bytes);
3435
3436 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3437 if (rc < 0) {
3438 pr_debug("[%s] write op[0x%x]rc[%d]\n", __func__,
3439 write.hdr.opcode, rc);
3440 goto fail_cmd;
3441 }
3442 return 0;
3443fail_cmd:
3444 return -EINVAL;
3445}
3446
3447int q6asm_async_read(struct audio_client *ac,
3448 struct audio_aio_read_param *param)
3449{
3450 int rc = 0;
3451 struct asm_stream_cmd_read read;
3452
3453 if (!ac || ac->apr == NULL) {
3454 pr_err("%s: APR handle NULL\n", __func__);
3455 return -EINVAL;
3456 }
3457
3458 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3459
3460 /* Pass physical address as token for AIO scheme */
3461 read.hdr.token = param->paddr;
3462 read.hdr.opcode = ASM_DATA_CMD_READ;
3463 read.buf_add = param->paddr;
3464 read.buf_size = param->len;
3465 read.uid = param->uid;
3466
3467 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3468 read.buf_add, read.buf_size);
3469
3470 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3471 if (rc < 0) {
3472 pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
3473 read.hdr.opcode, rc);
3474 goto fail_cmd;
3475 }
3476 return 0;
3477fail_cmd:
3478 return -EINVAL;
3479}
3480
Subhash Chandra Bose Naripeddy694b7d92012-06-20 20:46:13 -07003481int q6asm_async_read_compressed(struct audio_client *ac,
3482 struct audio_aio_read_param *param)
3483{
3484 int rc = 0;
3485 struct asm_stream_cmd_read read;
3486
3487 if (!ac || ac->apr == NULL) {
3488 pr_err("%s: APR handle NULL\n", __func__);
3489 return -EINVAL;
3490 }
3491
3492 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3493
3494 /* Pass physical address as token for AIO scheme */
3495 read.hdr.token = param->paddr;
3496 read.hdr.opcode = ASM_DATA_CMD_READ_COMPRESSED;
3497 read.buf_add = param->paddr;
3498 read.buf_size = param->len;
3499 read.uid = param->uid;
3500
3501 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3502 read.buf_add, read.buf_size);
3503
3504 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3505 if (rc < 0) {
3506 pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
3507 read.hdr.opcode, rc);
3508 goto fail_cmd;
3509 }
3510 return 0;
3511fail_cmd:
3512 return -EINVAL;
3513}
3514
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003515int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3516 uint32_t lsw_ts, uint32_t flags)
3517{
3518 int rc = 0;
3519 struct asm_stream_cmd_write write;
3520 struct audio_port_data *port;
3521 struct audio_buffer *ab;
3522 int dsp_buf = 0;
3523
3524 if (!ac || ac->apr == NULL) {
3525 pr_err("APR handle NULL\n");
3526 return -EINVAL;
3527 }
3528 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3529 if (ac->io_mode == SYNC_IO_MODE) {
3530 port = &ac->port[IN];
3531
3532 q6asm_add_hdr(ac, &write.hdr, sizeof(write),
3533 FALSE);
3534 mutex_lock(&port->lock);
3535
3536 dsp_buf = port->dsp_buf;
3537 ab = &port->buf[dsp_buf];
3538
3539 write.hdr.token = port->dsp_buf;
3540 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3541 write.buf_add = ab->phys;
3542 write.avail_bytes = len;
3543 write.uid = port->dsp_buf;
3544 write.msw_ts = msw_ts;
3545 write.lsw_ts = lsw_ts;
3546 /* Use 0xFF00 for disabling timestamps */
3547 if (flags == 0xFF00)
3548 write.uflags = (0x00000000 | (flags & 0x800000FF));
3549 else
3550 write.uflags = (0x80000000 | flags);
3551 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3552
3553 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3554 , __func__,
3555 ab->phys,
3556 write.buf_add,
3557 write.hdr.token,
3558 write.uid);
3559 mutex_unlock(&port->lock);
Rajesha Kini3498c932011-07-19 19:58:27 +05303560#ifdef CONFIG_DEBUG_FS
3561 if (out_enable_flag) {
3562 char zero_pattern[2] = {0x00, 0x00};
3563 /* If First two byte is non zero and last two byte
3564 is zero then it is warm output pattern */
3565 if ((strncmp(((char *)ab->data), zero_pattern, 2)) &&
3566 (!strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3567 do_gettimeofday(&out_warm_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003568 pr_debug("WARM:apr_send_pkt at %ld sec %ld microsec\n",
3569 out_warm_tv.tv_sec,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303570 out_warm_tv.tv_usec);
3571 pr_debug("Warm Pattern Matched");
3572 }
3573 /* If First two byte is zero and last two byte is
3574 non zero then it is cont ouput pattern */
3575 else if ((!strncmp(((char *)ab->data), zero_pattern, 2))
3576 && (strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3577 do_gettimeofday(&out_cont_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003578 pr_debug("CONT:apr_send_pkt at %ld sec %ld microsec\n",
3579 out_cont_tv.tv_sec,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303580 out_cont_tv.tv_usec);
3581 pr_debug("Cont Pattern Matched");
3582 }
3583 }
3584#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003585 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3586 if (rc < 0) {
3587 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3588 goto fail_cmd;
3589 }
3590 pr_debug("%s: WRITE SUCCESS\n", __func__);
3591 return 0;
3592 }
3593fail_cmd:
3594 return -EINVAL;
3595}
3596
3597int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3598 uint32_t lsw_ts, uint32_t flags)
3599{
3600 int rc = 0;
3601 struct asm_stream_cmd_write write;
3602 struct audio_port_data *port;
3603 struct audio_buffer *ab;
3604 int dsp_buf = 0;
3605
3606 if (!ac || ac->apr == NULL) {
3607 pr_err("APR handle NULL\n");
3608 return -EINVAL;
3609 }
3610 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3611 if (ac->io_mode == SYNC_IO_MODE) {
3612 port = &ac->port[IN];
3613
3614 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write),
3615 FALSE);
3616
3617 dsp_buf = port->dsp_buf;
3618 ab = &port->buf[dsp_buf];
3619
3620 write.hdr.token = port->dsp_buf;
3621 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3622 write.buf_add = ab->phys;
3623 write.avail_bytes = len;
3624 write.uid = port->dsp_buf;
3625 write.msw_ts = msw_ts;
3626 write.lsw_ts = lsw_ts;
3627 /* Use 0xFF00 for disabling timestamps */
3628 if (flags == 0xFF00)
3629 write.uflags = (0x00000000 | (flags & 0x800000FF));
3630 else
3631 write.uflags = (0x80000000 | flags);
3632 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3633
3634 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3635 , __func__,
3636 ab->phys,
3637 write.buf_add,
3638 write.hdr.token,
3639 write.uid);
3640
3641 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3642 if (rc < 0) {
3643 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3644 goto fail_cmd;
3645 }
3646 pr_debug("%s: WRITE SUCCESS\n", __func__);
3647 return 0;
3648 }
3649fail_cmd:
3650 return -EINVAL;
3651}
3652
Patrick Lai3aabeae2013-01-06 00:52:34 -08003653int q6asm_get_session_time(struct audio_client *ac, uint64_t *tstamp)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003654{
3655 struct apr_hdr hdr;
3656 int rc;
3657
Patrick Lai3aabeae2013-01-06 00:52:34 -08003658 if (!ac || ac->apr == NULL || tstamp == NULL) {
3659 pr_err("APR handle or tstamp NULL\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003660 return -EINVAL;
3661 }
Swaminathan Sathappanc7f98992012-07-09 11:07:12 -07003662 q6asm_add_hdr(ac, &hdr, sizeof(hdr), FALSE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003663 hdr.opcode = ASM_SESSION_CMD_GET_SESSION_TIME;
3664 atomic_set(&ac->time_flag, 1);
3665
3666 pr_debug("%s: session[%d]opcode[0x%x]\n", __func__,
3667 ac->session,
3668 hdr.opcode);
3669 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3670 if (rc < 0) {
3671 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3672 goto fail_cmd;
3673 }
3674 rc = wait_event_timeout(ac->time_wait,
3675 (atomic_read(&ac->time_flag) == 0), 5*HZ);
3676 if (!rc) {
3677 pr_err("%s: timeout in getting session time from DSP\n",
3678 __func__);
3679 goto fail_cmd;
3680 }
Patrick Lai3aabeae2013-01-06 00:52:34 -08003681
3682 *tstamp = ac->time_stamp;
3683 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003684
3685fail_cmd:
3686 return -EINVAL;
3687}
3688
3689int q6asm_cmd(struct audio_client *ac, int cmd)
3690{
3691 struct apr_hdr hdr;
3692 int rc;
3693 atomic_t *state;
3694 int cnt = 0;
3695
3696 if (!ac || ac->apr == NULL) {
3697 pr_err("APR handle NULL\n");
3698 return -EINVAL;
3699 }
3700 q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
3701 switch (cmd) {
3702 case CMD_PAUSE:
3703 pr_debug("%s:CMD_PAUSE\n", __func__);
3704 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3705 state = &ac->cmd_state;
3706 break;
3707 case CMD_FLUSH:
3708 pr_debug("%s:CMD_FLUSH\n", __func__);
3709 hdr.opcode = ASM_STREAM_CMD_FLUSH;
3710 state = &ac->cmd_state;
3711 break;
3712 case CMD_OUT_FLUSH:
3713 pr_debug("%s:CMD_OUT_FLUSH\n", __func__);
3714 hdr.opcode = ASM_STREAM_CMD_FLUSH_READBUFS;
3715 state = &ac->cmd_state;
3716 break;
3717 case CMD_EOS:
3718 pr_debug("%s:CMD_EOS\n", __func__);
3719 hdr.opcode = ASM_DATA_CMD_EOS;
3720 atomic_set(&ac->cmd_state, 0);
3721 state = &ac->cmd_state;
3722 break;
3723 case CMD_CLOSE:
3724 pr_debug("%s:CMD_CLOSE\n", __func__);
3725 hdr.opcode = ASM_STREAM_CMD_CLOSE;
3726 state = &ac->cmd_state;
3727 break;
3728 default:
3729 pr_err("Invalid format[%d]\n", cmd);
3730 goto fail_cmd;
3731 }
3732 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3733 ac->session,
3734 hdr.opcode);
3735 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3736 if (rc < 0) {
3737 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3738 goto fail_cmd;
3739 }
3740 rc = wait_event_timeout(ac->cmd_wait, (atomic_read(state) == 0), 5*HZ);
3741 if (!rc) {
3742 pr_err("timeout. waited for response opcode[0x%x]\n",
3743 hdr.opcode);
3744 goto fail_cmd;
3745 }
3746 if (cmd == CMD_FLUSH)
3747 q6asm_reset_buf_state(ac);
3748 if (cmd == CMD_CLOSE) {
3749 /* check if DSP return all buffers */
3750 if (ac->port[IN].buf) {
3751 for (cnt = 0; cnt < ac->port[IN].max_buf_cnt;
3752 cnt++) {
3753 if (ac->port[IN].buf[cnt].used == IN) {
3754 pr_debug("Write Buf[%d] not returned\n",
3755 cnt);
3756 }
3757 }
3758 }
3759 if (ac->port[OUT].buf) {
3760 for (cnt = 0; cnt < ac->port[OUT].max_buf_cnt; cnt++) {
3761 if (ac->port[OUT].buf[cnt].used == OUT) {
3762 pr_debug("Read Buf[%d] not returned\n",
3763 cnt);
3764 }
3765 }
3766 }
3767 }
3768 return 0;
3769fail_cmd:
3770 return -EINVAL;
3771}
3772
3773int q6asm_cmd_nowait(struct audio_client *ac, int cmd)
3774{
3775 struct apr_hdr hdr;
3776 int rc;
3777
3778 if (!ac || ac->apr == NULL) {
3779 pr_err("%s:APR handle NULL\n", __func__);
3780 return -EINVAL;
3781 }
3782 q6asm_add_hdr_async(ac, &hdr, sizeof(hdr), TRUE);
3783 switch (cmd) {
3784 case CMD_PAUSE:
3785 pr_debug("%s:CMD_PAUSE\n", __func__);
3786 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3787 break;
3788 case CMD_EOS:
3789 pr_debug("%s:CMD_EOS\n", __func__);
3790 hdr.opcode = ASM_DATA_CMD_EOS;
3791 break;
3792 default:
3793 pr_err("%s:Invalid format[%d]\n", __func__, cmd);
3794 goto fail_cmd;
3795 }
3796 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3797 ac->session,
3798 hdr.opcode);
Jay Wang0668d1062012-07-11 18:53:21 -07003799
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003800 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3801 if (rc < 0) {
3802 pr_err("%s:Commmand 0x%x failed\n", __func__, hdr.opcode);
3803 goto fail_cmd;
3804 }
Jay Wang0668d1062012-07-11 18:53:21 -07003805 atomic_inc(&ac->nowait_cmd_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003806 return 0;
3807fail_cmd:
3808 return -EINVAL;
3809}
3810
3811static void q6asm_reset_buf_state(struct audio_client *ac)
3812{
3813 int cnt = 0;
3814 int loopcnt = 0;
3815 struct audio_port_data *port = NULL;
3816
3817 if (ac->io_mode == SYNC_IO_MODE) {
3818 mutex_lock(&ac->cmd_lock);
3819 for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
3820 port = &ac->port[loopcnt];
3821 cnt = port->max_buf_cnt - 1;
3822 port->dsp_buf = 0;
3823 port->cpu_buf = 0;
3824 while (cnt >= 0) {
3825 if (!port->buf)
3826 continue;
3827 port->buf[cnt].used = 1;
3828 cnt--;
3829 }
3830 }
3831 mutex_unlock(&ac->cmd_lock);
3832 }
3833}
3834
3835int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable)
3836{
3837 struct asm_stream_cmd_reg_tx_overflow_event tx_overflow;
3838 int rc;
3839
3840 if (!ac || ac->apr == NULL) {
3841 pr_err("APR handle NULL\n");
3842 return -EINVAL;
3843 }
3844 pr_debug("%s:session[%d]enable[%d]\n", __func__,
3845 ac->session, enable);
3846 q6asm_add_hdr(ac, &tx_overflow.hdr, sizeof(tx_overflow), TRUE);
3847
3848 tx_overflow.hdr.opcode = \
3849 ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS;
3850 /* tx overflow event: enable */
3851 tx_overflow.enable = enable;
3852
3853 rc = apr_send_pkt(ac->apr, (uint32_t *) &tx_overflow);
3854 if (rc < 0) {
3855 pr_err("tx overflow op[0x%x]rc[%d]\n", \
3856 tx_overflow.hdr.opcode, rc);
3857 goto fail_cmd;
3858 }
3859 rc = wait_event_timeout(ac->cmd_wait,
3860 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3861 if (!rc) {
3862 pr_err("timeout. waited for tx overflow\n");
3863 goto fail_cmd;
3864 }
3865 return 0;
3866fail_cmd:
3867 return -EINVAL;
3868}
3869
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003870int q6asm_get_apr_service_id(int session_id)
3871{
3872 pr_debug("%s\n", __func__);
3873
Shiv Maliyappanahallia84982a2012-01-19 15:25:04 -08003874 if (session_id < 0 || session_id > SESSION_MAX) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003875 pr_err("%s: invalid session_id = %d\n", __func__, session_id);
3876 return -EINVAL;
3877 }
3878
3879 return ((struct apr_svc *)session[session_id]->apr)->id;
3880}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003881
3882
3883static int __init q6asm_init(void)
3884{
3885 pr_debug("%s\n", __func__);
3886 init_waitqueue_head(&this_mmap.cmd_wait);
3887 memset(session, 0, sizeof(session));
Rajesha Kini3498c932011-07-19 19:58:27 +05303888#ifdef CONFIG_DEBUG_FS
3889 out_buffer = kmalloc(OUT_BUFFER_SIZE, GFP_KERNEL);
3890 out_dentry = debugfs_create_file("audio_out_latency_measurement_node",\
Glenn Kasten5dfda802012-10-04 16:40:27 -07003891 0664,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303892 NULL, NULL, &audio_output_latency_debug_fops);
3893 if (IS_ERR(out_dentry))
3894 pr_err("debugfs_create_file failed\n");
3895 in_buffer = kmalloc(IN_BUFFER_SIZE, GFP_KERNEL);
3896 in_dentry = debugfs_create_file("audio_in_latency_measurement_node",\
Glenn Kasten5dfda802012-10-04 16:40:27 -07003897 0664,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303898 NULL, NULL, &audio_input_latency_debug_fops);
3899 if (IS_ERR(in_dentry))
3900 pr_err("debugfs_create_file failed\n");
3901#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003902 return 0;
3903}
3904
3905device_initcall(q6asm_init);