blob: f39a227954ae7cefb0f6d592d28cbeae2517f669 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001
2/*
Kiran Kandi5e809b02012-01-31 00:24:33 -08003 * Copyright (c) 2010-2012, Code Aurora Forum. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004 * Author: Brian Swetland <swetland@google.com>
5 *
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16#include <linux/fs.h>
17#include <linux/mutex.h>
18#include <linux/wait.h>
19#include <linux/miscdevice.h>
20#include <linux/uaccess.h>
21#include <linux/sched.h>
22#include <linux/dma-mapping.h>
23#include <linux/miscdevice.h>
24#include <linux/delay.h>
25#include <linux/spinlock.h>
26#include <linux/slab.h>
27#include <linux/msm_audio.h>
28#include <linux/android_pmem.h>
29#include <linux/memory_alloc.h>
Ben Rombergerfce8f512011-07-18 16:46:09 -070030#include <linux/debugfs.h>
31#include <linux/time.h>
32#include <linux/atomic.h>
33
34#include <asm/ioctls.h>
35
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070036#include <mach/memory.h>
37#include <mach/debug_mm.h>
38#include <mach/peripheral-loader.h>
39#include <mach/qdsp6v2/audio_acdb.h>
40#include <mach/qdsp6v2/rtac.h>
Ben Rombergerfce8f512011-07-18 16:46:09 -070041
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070042#include <sound/apr_audio.h>
43#include <sound/q6asm.h>
Ben Rombergerfce8f512011-07-18 16:46:09 -070044
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070045
46#define TRUE 0x01
47#define FALSE 0x00
48#define READDONE_IDX_STATUS 0
49#define READDONE_IDX_BUFFER 1
50#define READDONE_IDX_SIZE 2
51#define READDONE_IDX_OFFSET 3
52#define READDONE_IDX_MSW_TS 4
53#define READDONE_IDX_LSW_TS 5
54#define READDONE_IDX_FLAGS 6
55#define READDONE_IDX_NUMFRAMES 7
56#define READDONE_IDX_ID 8
Rajesha Kini3498c932011-07-19 19:58:27 +053057#ifdef CONFIG_DEBUG_FS
58#define OUT_BUFFER_SIZE 56
59#define IN_BUFFER_SIZE 24
60#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070061static DEFINE_MUTEX(session_lock);
62
63/* session id: 0 reserved */
64static struct audio_client *session[SESSION_MAX+1];
65static int32_t q6asm_mmapcallback(struct apr_client_data *data, void *priv);
66static int32_t q6asm_callback(struct apr_client_data *data, void *priv);
67static void q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
68 uint32_t pkt_size, uint32_t cmd_flg);
69static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
70 uint32_t pkt_size, uint32_t cmd_flg);
71static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
72 uint32_t bufsz, uint32_t bufcnt);
73static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir,
74 uint32_t bufsz, uint32_t bufcnt);
75
76static void q6asm_reset_buf_state(struct audio_client *ac);
77
Rajesha Kini3498c932011-07-19 19:58:27 +053078#ifdef CONFIG_DEBUG_FS
79static struct timeval out_cold_tv;
80static struct timeval out_warm_tv;
81static struct timeval out_cont_tv;
82static struct timeval in_cont_tv;
83static long out_enable_flag;
84static long in_enable_flag;
85static struct dentry *out_dentry;
86static struct dentry *in_dentry;
87static int in_cont_index;
88/*This var is used to keep track of first write done for cold output latency */
89static int out_cold_index;
90static char *out_buffer;
91static char *in_buffer;
92static int audio_output_latency_dbgfs_open(struct inode *inode,
93 struct file *file)
94{
95 file->private_data = inode->i_private;
96 return 0;
97}
98static ssize_t audio_output_latency_dbgfs_read(struct file *file,
99 char __user *buf, size_t count, loff_t *ppos)
100{
101 snprintf(out_buffer, OUT_BUFFER_SIZE, "%ld,%ld,%ld,%ld,%ld,%ld,",\
102 out_cold_tv.tv_sec, out_cold_tv.tv_usec, out_warm_tv.tv_sec,\
103 out_warm_tv.tv_usec, out_cont_tv.tv_sec, out_cont_tv.tv_usec);
104 return simple_read_from_buffer(buf, OUT_BUFFER_SIZE, ppos,
105 out_buffer, OUT_BUFFER_SIZE);
106}
107static ssize_t audio_output_latency_dbgfs_write(struct file *file,
108 const char __user *buf, size_t count, loff_t *ppos)
109{
110 char *temp;
111
112 if (count > 2*sizeof(char))
113 return -EINVAL;
114 else
115 temp = kmalloc(2*sizeof(char), GFP_KERNEL);
116
117 out_cold_index = 0;
118
119 if (temp) {
120 if (copy_from_user(temp, buf, 2*sizeof(char))) {
121 kfree(temp);
122 return -EFAULT;
123 }
124 if (!strict_strtol(temp, 10, &out_enable_flag)) {
125 kfree(temp);
126 return count;
127 }
128 kfree(temp);
129 }
130 return -EINVAL;
131}
132static const struct file_operations audio_output_latency_debug_fops = {
133 .open = audio_output_latency_dbgfs_open,
134 .read = audio_output_latency_dbgfs_read,
135 .write = audio_output_latency_dbgfs_write
136};
137
138static int audio_input_latency_dbgfs_open(struct inode *inode,
139 struct file *file)
140{
141 file->private_data = inode->i_private;
142 return 0;
143}
144static ssize_t audio_input_latency_dbgfs_read(struct file *file,
145 char __user *buf, size_t count, loff_t *ppos)
146{
147 snprintf(in_buffer, IN_BUFFER_SIZE, "%ld,%ld,",\
148 in_cont_tv.tv_sec, in_cont_tv.tv_usec);
149 return simple_read_from_buffer(buf, IN_BUFFER_SIZE, ppos,
150 in_buffer, IN_BUFFER_SIZE);
151}
152static ssize_t audio_input_latency_dbgfs_write(struct file *file,
153 const char __user *buf, size_t count, loff_t *ppos)
154{
155 char *temp;
156
157 if (count > 2*sizeof(char))
158 return -EINVAL;
159 else
160 temp = kmalloc(2*sizeof(char), GFP_KERNEL);
161 if (temp) {
162 if (copy_from_user(temp, buf, 2*sizeof(char))) {
163 kfree(temp);
164 return -EFAULT;
165 }
166 if (!strict_strtol(temp, 10, &in_enable_flag)) {
167 kfree(temp);
168 return count;
169 }
170 kfree(temp);
171 }
172 return -EINVAL;
173}
174static const struct file_operations audio_input_latency_debug_fops = {
175 .open = audio_input_latency_dbgfs_open,
176 .read = audio_input_latency_dbgfs_read,
177 .write = audio_input_latency_dbgfs_write
178};
179#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700180struct asm_mmap {
181 atomic_t ref_cnt;
182 atomic_t cmd_state;
183 wait_queue_head_t cmd_wait;
184 void *apr;
185};
186
187static struct asm_mmap this_mmap;
188
189static int q6asm_session_alloc(struct audio_client *ac)
190{
191 int n;
192 mutex_lock(&session_lock);
193 for (n = 1; n <= SESSION_MAX; n++) {
194 if (!session[n]) {
195 session[n] = ac;
196 mutex_unlock(&session_lock);
197 return n;
198 }
199 }
200 mutex_unlock(&session_lock);
201 return -ENOMEM;
202}
203
204static void q6asm_session_free(struct audio_client *ac)
205{
206 pr_debug("%s: sessionid[%d]\n", __func__, ac->session);
Ben Romberger93d4d2d2011-10-19 23:04:02 -0700207 rtac_remove_popp_from_adm_devices(ac->session);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700208 mutex_lock(&session_lock);
209 session[ac->session] = 0;
210 mutex_unlock(&session_lock);
211 ac->session = 0;
212 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;
415 ac->apr = apr_register("ADSP", "ASM", \
416 (apr_fn)q6asm_callback,\
417 ((ac->session) << 8 | 0x0001),\
418 ac);
419
420 if (ac->apr == NULL) {
421 pr_err("%s Registration with APR failed\n", __func__);
422 goto fail;
423 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700424 rtac_set_asm_handle(n, ac->apr);
Ben Rombergerfce8f512011-07-18 16:46:09 -0700425
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700426 pr_debug("%s Registering the common port with APR\n", __func__);
427 if (atomic_read(&this_mmap.ref_cnt) == 0) {
428 this_mmap.apr = apr_register("ADSP", "ASM", \
429 (apr_fn)q6asm_mmapcallback,\
430 0x0FFFFFFFF, &this_mmap);
431 if (this_mmap.apr == NULL) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700432 pr_debug("%s Unable to register APR ASM common port\n",
433 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700434 goto fail;
435 }
436 }
437
438 atomic_inc(&this_mmap.ref_cnt);
439 init_waitqueue_head(&ac->cmd_wait);
440 init_waitqueue_head(&ac->time_wait);
441 atomic_set(&ac->time_flag, 1);
442 mutex_init(&ac->cmd_lock);
443 for (lcnt = 0; lcnt <= OUT; lcnt++) {
444 mutex_init(&ac->port[lcnt].lock);
445 spin_lock_init(&ac->port[lcnt].dsp_lock);
446 }
447 atomic_set(&ac->cmd_state, 0);
448
449 pr_debug("%s: session[%d]\n", __func__, ac->session);
450
451 return ac;
452fail:
453 q6asm_audio_client_free(ac);
454 return NULL;
455fail_session:
456 kfree(ac);
457 return NULL;
458}
459
Ben Romberger61754dc2011-10-31 18:25:41 -0700460struct audio_client *q6asm_get_audio_client(int session_id)
461{
462 if ((session_id <= 0) || (session_id > SESSION_MAX)) {
463 pr_err("%s: invalid session: %d\n", __func__, session_id);
464 goto err;
465 }
466
467 if (!session[session_id]) {
468 pr_err("%s: session not active: %d\n", __func__, session_id);
469 goto err;
470 }
471
472 return session[session_id];
473err:
474 return NULL;
475}
476
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700477int q6asm_audio_client_buf_alloc(unsigned int dir,
478 struct audio_client *ac,
479 unsigned int bufsz,
480 unsigned int bufcnt)
481{
482 int cnt = 0;
483 int rc = 0;
484 struct audio_buffer *buf;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800485#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
486 int len;
487#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700488
489 if (!(ac) || ((dir != IN) && (dir != OUT)))
490 return -EINVAL;
491
492 pr_debug("%s: session[%d]bufsz[%d]bufcnt[%d]\n", __func__, ac->session,
493 bufsz, bufcnt);
494
495 if (ac->session <= 0 || ac->session > 8)
496 goto fail;
497
498 if (ac->io_mode == SYNC_IO_MODE) {
499 if (ac->port[dir].buf) {
500 pr_debug("%s: buffer already allocated\n", __func__);
501 return 0;
502 }
503 mutex_lock(&ac->cmd_lock);
504 buf = kzalloc(((sizeof(struct audio_buffer))*bufcnt),
505 GFP_KERNEL);
506
507 if (!buf) {
508 mutex_unlock(&ac->cmd_lock);
509 goto fail;
510 }
511
512 ac->port[dir].buf = buf;
513
514 while (cnt < bufcnt) {
515 if (bufsz > 0) {
516 if (!buf[cnt].data) {
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800517#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
518 buf[cnt].client = msm_ion_client_create
519 (UINT_MAX, "audio_client");
520 if (IS_ERR_OR_NULL((void *)
521 buf[cnt].client)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700522 pr_err("%s: ION create client for AUDIO failed\n",
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800523 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700524 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800525 goto fail;
526 }
527 buf[cnt].handle = ion_alloc
528 (buf[cnt].client, bufsz, SZ_4K,
529 (0x1 << ION_AUDIO_HEAP_ID));
530 if (IS_ERR_OR_NULL((void *)
531 buf[cnt].handle)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700532 pr_err("%s: ION memory allocation for AUDIO failed\n",
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800533 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700534 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800535 goto fail;
536 }
537
538 rc = ion_phys(buf[cnt].client,
539 buf[cnt].handle,
540 (ion_phys_addr_t *)
541 &buf[cnt].phys,
542 (size_t *)&len);
543 if (rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700544 pr_err("%s: ION Get Physical for AUDIO failed, rc = %d\n",
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800545 __func__, rc);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700546 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800547 goto fail;
548 }
549
550 buf[cnt].data = ion_map_kernel
551 (buf[cnt].client, buf[cnt].handle,
552 0);
553 if (IS_ERR_OR_NULL((void *)
554 buf[cnt].data)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700555 pr_err("%s: ION memory mapping for AUDIO failed\n",
556 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700557 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800558 goto fail;
559 }
560 memset((void *)buf[cnt].data, 0, bufsz);
561#else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700562 unsigned int flags = 0;
563 buf[cnt].phys =
564 allocate_contiguous_ebi_nomap(bufsz,
565 SZ_4K);
566 if (!buf[cnt].phys) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700567 pr_err("%s:Buf alloc failed size=%d\n",
568 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700569 bufsz);
570 mutex_unlock(&ac->cmd_lock);
571 goto fail;
572 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700573 buf[cnt].mem_buffer =
Laura Abbottea3e7b62012-04-30 15:59:21 -0700574 ioremap(buf[cnt].phys, bufsz);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700575 if (IS_ERR(
576 (void *)buf[cnt].mem_buffer)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700577 pr_err("%s:map_buffer failed, error = %ld\n",
578 __func__,
579 PTR_ERR((void *)buf[cnt].mem_buffer));
Jayasena Sangaraboina466e6b92012-01-17 21:10:55 -0800580 mutex_unlock(&ac->cmd_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700581 goto fail;
582 }
583 buf[cnt].data =
Laura Abbottea3e7b62012-04-30 15:59:21 -0700584 buf[cnt].mem_buffer;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700585 if (!buf[cnt].data) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700586 pr_err("%s:invalid vaddr, iomap failed\n",
587 __func__);
Jayasena Sangaraboina466e6b92012-01-17 21:10:55 -0800588 mutex_unlock(&ac->cmd_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700589 goto fail;
590 }
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800591#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700592 buf[cnt].used = 1;
593 buf[cnt].size = bufsz;
594 buf[cnt].actual_size = bufsz;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800595 pr_debug("%s data[%p]phys[%p][%p]\n",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700596 __func__,
597 (void *)buf[cnt].data,
598 (void *)buf[cnt].phys,
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800599 (void *)&buf[cnt].phys);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700600 cnt++;
601 }
602 }
603 }
604 ac->port[dir].max_buf_cnt = cnt;
605
606 mutex_unlock(&ac->cmd_lock);
607 rc = q6asm_memory_map_regions(ac, dir, bufsz, cnt);
608 if (rc < 0) {
609 pr_err("%s:CMD Memory_map_regions failed\n", __func__);
610 goto fail;
611 }
612 }
613 return 0;
614fail:
615 q6asm_audio_client_buf_free(dir, ac);
616 return -EINVAL;
617}
618
619int q6asm_audio_client_buf_alloc_contiguous(unsigned int dir,
620 struct audio_client *ac,
621 unsigned int bufsz,
622 unsigned int bufcnt)
623{
624 int cnt = 0;
625 int rc = 0;
626 struct audio_buffer *buf;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800627#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
628 int len;
629#else
630 int flags = 0;
631#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700632 if (!(ac) || ((dir != IN) && (dir != OUT)))
633 return -EINVAL;
634
635 pr_debug("%s: session[%d]bufsz[%d]bufcnt[%d]\n",
636 __func__, ac->session,
637 bufsz, bufcnt);
638
639 if (ac->session <= 0 || ac->session > 8)
640 goto fail;
641
642 if (ac->port[dir].buf) {
643 pr_debug("%s: buffer already allocated\n", __func__);
644 return 0;
645 }
646 mutex_lock(&ac->cmd_lock);
647 buf = kzalloc(((sizeof(struct audio_buffer))*bufcnt),
648 GFP_KERNEL);
649
650 if (!buf) {
651 mutex_unlock(&ac->cmd_lock);
652 goto fail;
653 }
654
655 ac->port[dir].buf = buf;
656
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800657#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
658 buf[0].client = msm_ion_client_create(UINT_MAX, "audio_client");
659 if (IS_ERR_OR_NULL((void *)buf[0].client)) {
660 pr_err("%s: ION create client for AUDIO failed\n", __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700661 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800662 goto fail;
663 }
664 buf[0].handle = ion_alloc(buf[0].client, bufsz * bufcnt, SZ_4K,
665 (0x1 << ION_AUDIO_HEAP_ID));
666 if (IS_ERR_OR_NULL((void *) buf[0].handle)) {
667 pr_err("%s: ION memory allocation for AUDIO failed\n",
668 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700669 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800670 goto fail;
671 }
672
673 rc = ion_phys(buf[0].client, buf[0].handle,
674 (ion_phys_addr_t *)&buf[0].phys, (size_t *)&len);
675 if (rc) {
676 pr_err("%s: ION Get Physical for AUDIO failed, rc = %d\n",
677 __func__, rc);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700678 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800679 goto fail;
680 }
681
682 buf[0].data = ion_map_kernel(buf[0].client, buf[0].handle, 0);
683 if (IS_ERR_OR_NULL((void *) buf[0].data)) {
684 pr_err("%s: ION memory mapping for AUDIO failed\n", __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700685 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800686 goto fail;
687 }
688 memset((void *)buf[0].data, 0, (bufsz * bufcnt));
689#else
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700690 buf[0].phys = allocate_contiguous_ebi_nomap(bufsz * bufcnt,
691 SZ_4K);
692 if (!buf[0].phys) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700693 pr_err("%s:Buf alloc failed size=%d, bufcnt=%d\n",
694 __func__, bufsz, bufcnt);
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700695 mutex_unlock(&ac->cmd_lock);
696 goto fail;
697 }
698
Laura Abbottea3e7b62012-04-30 15:59:21 -0700699 buf[0].mem_buffer = ioremap(buf[0].phys, bufsz * bufcnt);
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700700 if (IS_ERR((void *)buf[cnt].mem_buffer)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700701 pr_err("%s:map_buffer failed, error = %ld\n",
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700702 __func__, PTR_ERR((void *)buf[0].mem_buffer));
703
704 mutex_unlock(&ac->cmd_lock);
705 goto fail;
706 }
Laura Abbottea3e7b62012-04-30 15:59:21 -0700707 buf[0].data = buf[0].mem_buffer;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800708#endif
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700709 if (!buf[0].data) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700710 pr_err("%s:invalid vaddr, iomap failed\n", __func__);
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700711 mutex_unlock(&ac->cmd_lock);
712 goto fail;
713 }
714
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700715 buf[0].used = dir ^ 1;
716 buf[0].size = bufsz;
717 buf[0].actual_size = bufsz;
718 cnt = 1;
719 while (cnt < bufcnt) {
720 if (bufsz > 0) {
721 buf[cnt].data = buf[0].data + (cnt * bufsz);
722 buf[cnt].phys = buf[0].phys + (cnt * bufsz);
723 if (!buf[cnt].data) {
724 pr_err("%s Buf alloc failed\n",
725 __func__);
726 mutex_unlock(&ac->cmd_lock);
727 goto fail;
728 }
729 buf[cnt].used = dir ^ 1;
730 buf[cnt].size = bufsz;
731 buf[cnt].actual_size = bufsz;
732 pr_debug("%s data[%p]phys[%p][%p]\n", __func__,
733 (void *)buf[cnt].data,
734 (void *)buf[cnt].phys,
735 (void *)&buf[cnt].phys);
736 }
737 cnt++;
738 }
739 ac->port[dir].max_buf_cnt = cnt;
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -0700740
741 pr_debug("%s ac->port[%d].max_buf_cnt[%d]\n", __func__, dir,
742 ac->port[dir].max_buf_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700743 mutex_unlock(&ac->cmd_lock);
744 rc = q6asm_memory_map(ac, buf[0].phys, dir, bufsz, cnt);
745 if (rc < 0) {
746 pr_err("%s:CMD Memory_map_regions failed\n", __func__);
747 goto fail;
748 }
749 return 0;
750fail:
751 q6asm_audio_client_buf_free_contiguous(dir, ac);
752 return -EINVAL;
753}
754
755static int32_t q6asm_mmapcallback(struct apr_client_data *data, void *priv)
756{
757 uint32_t token;
758 uint32_t *payload = data->payload;
759
760 if (data->opcode == RESET_EVENTS) {
761 pr_debug("%s: Reset event is received: %d %d apr[%p]\n",
762 __func__,
763 data->reset_event,
764 data->reset_proc,
765 this_mmap.apr);
766 apr_reset(this_mmap.apr);
767 this_mmap.apr = NULL;
768 atomic_set(&this_mmap.cmd_state, 0);
769 return 0;
770 }
771
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700772 pr_debug("%s:ptr0[0x%x]ptr1[0x%x]opcode[0x%x] token[0x%x]payload_s[%d] src[%d] dest[%d]\n",
773 __func__, payload[0], payload[1], data->opcode, data->token,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700774 data->payload_size, data->src_port, data->dest_port);
775
776 if (data->opcode == APR_BASIC_RSP_RESULT) {
777 token = data->token;
778 switch (payload[0]) {
779 case ASM_SESSION_CMD_MEMORY_MAP:
780 case ASM_SESSION_CMD_MEMORY_UNMAP:
781 case ASM_SESSION_CMD_MEMORY_MAP_REGIONS:
782 case ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS:
783 pr_debug("%s:command[0x%x]success [0x%x]\n",
784 __func__, payload[0], payload[1]);
785 if (atomic_read(&this_mmap.cmd_state)) {
786 atomic_set(&this_mmap.cmd_state, 0);
787 wake_up(&this_mmap.cmd_wait);
788 }
789 break;
790 default:
791 pr_debug("%s:command[0x%x] not expecting rsp\n",
792 __func__, payload[0]);
793 break;
794 }
795 }
796 return 0;
797}
798
799
800static int32_t q6asm_callback(struct apr_client_data *data, void *priv)
801{
802 int i = 0;
803 struct audio_client *ac = (struct audio_client *)priv;
804 uint32_t token;
805 unsigned long dsp_flags;
806 uint32_t *payload;
807
808
809 if ((ac == NULL) || (data == NULL)) {
810 pr_err("ac or priv NULL\n");
811 return -EINVAL;
812 }
813 if (ac->session <= 0 || ac->session > 8) {
814 pr_err("%s:Session ID is invalid, session = %d\n", __func__,
815 ac->session);
816 return -EINVAL;
817 }
818
819 payload = data->payload;
820
821 if (data->opcode == RESET_EVENTS) {
822 pr_debug("q6asm_callback: Reset event is received: %d %d apr[%p]\n",
823 data->reset_event, data->reset_proc, ac->apr);
Laxminath Kasam692c6542012-02-21 11:17:47 +0530824 if (ac->cb)
825 ac->cb(data->opcode, data->token,
826 (uint32_t *)data->payload, ac->priv);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700827 apr_reset(ac->apr);
828 return 0;
829 }
830
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700831 pr_debug("%s: session[%d]opcode[0x%x] token[0x%x]payload_s[%d] src[%d] dest[%d]\n",
832 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700833 ac->session, data->opcode,
834 data->token, data->payload_size, data->src_port,
835 data->dest_port);
836
837 if (data->opcode == APR_BASIC_RSP_RESULT) {
838 token = data->token;
839 switch (payload[0]) {
840 case ASM_STREAM_CMD_SET_PP_PARAMS:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700841 if (rtac_make_asm_callback(ac->session, payload,
842 data->payload_size))
843 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700844 case ASM_SESSION_CMD_PAUSE:
845 case ASM_DATA_CMD_EOS:
846 case ASM_STREAM_CMD_CLOSE:
847 case ASM_STREAM_CMD_FLUSH:
848 case ASM_SESSION_CMD_RUN:
849 case ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS:
850 case ASM_STREAM_CMD_FLUSH_READBUFS:
851 pr_debug("%s:Payload = [0x%x]\n", __func__, payload[0]);
852 if (token != ac->session) {
853 pr_err("%s:Invalid session[%d] rxed expected[%d]",
854 __func__, token, ac->session);
855 return -EINVAL;
856 }
857 case ASM_STREAM_CMD_OPEN_READ:
858 case ASM_STREAM_CMD_OPEN_WRITE:
859 case ASM_STREAM_CMD_OPEN_READWRITE:
860 case ASM_DATA_CMD_MEDIA_FORMAT_UPDATE:
861 case ASM_STREAM_CMD_SET_ENCDEC_PARAM:
Santosh Mardi23321202012-03-22 04:33:25 +0530862 case ASM_STREAM_CMD_OPEN_WRITE_COMPRESSED:
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -0700863 case ASM_STREAM_CMD_OPEN_READ_COMPRESSED:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700864 if (atomic_read(&ac->cmd_state)) {
865 atomic_set(&ac->cmd_state, 0);
866 wake_up(&ac->cmd_wait);
867 }
868 if (ac->cb)
869 ac->cb(data->opcode, data->token,
870 (uint32_t *)data->payload, ac->priv);
871 break;
872 default:
873 pr_debug("%s:command[0x%x] not expecting rsp\n",
874 __func__, payload[0]);
875 break;
876 }
877 return 0;
878 }
879
880 switch (data->opcode) {
881 case ASM_DATA_EVENT_WRITE_DONE:{
882 struct audio_port_data *port = &ac->port[IN];
883 pr_debug("%s: Rxed opcode[0x%x] status[0x%x] token[%d]",
884 __func__, payload[0], payload[1],
885 data->token);
886 if (ac->io_mode == SYNC_IO_MODE) {
887 if (port->buf == NULL) {
888 pr_err("%s: Unexpected Write Done\n",
889 __func__);
890 return -EINVAL;
891 }
892 spin_lock_irqsave(&port->dsp_lock, dsp_flags);
893 if (port->buf[data->token].phys !=
894 payload[0]) {
895 pr_err("Buf expected[%p]rxed[%p]\n",\
896 (void *)port->buf[data->token].phys,\
897 (void *)payload[0]);
898 spin_unlock_irqrestore(&port->dsp_lock,
899 dsp_flags);
900 return -EINVAL;
901 }
902 token = data->token;
903 port->buf[token].used = 1;
904 spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
Rajesha Kini3498c932011-07-19 19:58:27 +0530905#ifdef CONFIG_DEBUG_FS
906 if (out_enable_flag) {
907 /* For first Write done log the time and reset
908 out_cold_index*/
909 if (out_cold_index != 1) {
910 do_gettimeofday(&out_cold_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700911 pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",
912 out_cold_tv.tv_sec,
Rajesha Kini3498c932011-07-19 19:58:27 +0530913 out_cold_tv.tv_usec);
914 out_cold_index = 1;
915 }
916 pr_debug("out_enable_flag %ld",\
917 out_enable_flag);
918 }
919#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700920 for (i = 0; i < port->max_buf_cnt; i++)
921 pr_debug("%d ", port->buf[i].used);
922
923 }
924 break;
925 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700926 case ASM_STREAM_CMDRSP_GET_PP_PARAMS:
927 rtac_make_asm_callback(ac->session, payload,
928 data->payload_size);
929 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700930 case ASM_DATA_EVENT_READ_DONE:{
931
932 struct audio_port_data *port = &ac->port[OUT];
Rajesha Kini3498c932011-07-19 19:58:27 +0530933#ifdef CONFIG_DEBUG_FS
934 if (in_enable_flag) {
935 /* when in_cont_index == 7, DSP would be
936 * writing into the 8th 512 byte buffer and this
937 * timestamp is tapped here.Once done it then writes
938 * to 9th 512 byte buffer.These two buffers(8th, 9th)
939 * reach the test application in 5th iteration and that
940 * timestamp is tapped at user level. The difference
941 * of these two timestamps gives us the time between
942 * the time at which dsp started filling the sample
943 * required and when it reached the test application.
944 * Hence continuous input latency
945 */
946 if (in_cont_index == 7) {
947 do_gettimeofday(&in_cont_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700948 pr_err("In_CONT:previous read buffer done at %ld sec %ld microsec\n",
Sriranjan Srikantam74753532011-10-03 14:48:37 -0700949 in_cont_tv.tv_sec, in_cont_tv.tv_usec);
Rajesha Kini3498c932011-07-19 19:58:27 +0530950 }
951 }
952#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700953 pr_debug("%s:R-D: status=%d buff_add=%x act_size=%d offset=%d\n",
954 __func__, payload[READDONE_IDX_STATUS],
955 payload[READDONE_IDX_BUFFER],
956 payload[READDONE_IDX_SIZE],
957 payload[READDONE_IDX_OFFSET]);
958 pr_debug("%s:R-D:msw_ts=%d lsw_ts=%d flags=%d id=%d num=%d\n",
959 __func__, payload[READDONE_IDX_MSW_TS],
960 payload[READDONE_IDX_LSW_TS],
961 payload[READDONE_IDX_FLAGS],
962 payload[READDONE_IDX_ID],
963 payload[READDONE_IDX_NUMFRAMES]);
Rajesha Kini3498c932011-07-19 19:58:27 +0530964#ifdef CONFIG_DEBUG_FS
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700965 if (in_enable_flag)
Rajesha Kini3498c932011-07-19 19:58:27 +0530966 in_cont_index++;
Rajesha Kini3498c932011-07-19 19:58:27 +0530967#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700968 if (ac->io_mode == SYNC_IO_MODE) {
969 if (port->buf == NULL) {
970 pr_err("%s: Unexpected Write Done\n", __func__);
971 return -EINVAL;
972 }
973 spin_lock_irqsave(&port->dsp_lock, dsp_flags);
974 token = data->token;
975 port->buf[token].used = 0;
976 if (port->buf[token].phys !=
977 payload[READDONE_IDX_BUFFER]) {
978 pr_err("Buf expected[%p]rxed[%p]\n",\
979 (void *)port->buf[token].phys,\
980 (void *)payload[READDONE_IDX_BUFFER]);
981 spin_unlock_irqrestore(&port->dsp_lock,
982 dsp_flags);
983 break;
984 }
985 port->buf[token].actual_size =
986 payload[READDONE_IDX_SIZE];
987 spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
988 }
989 break;
990 }
991 case ASM_DATA_EVENT_EOS:
992 case ASM_DATA_CMDRSP_EOS:
993 pr_debug("%s:EOS ACK received: rxed opcode[0x%x]\n",
994 __func__, data->opcode);
995 break;
996 case ASM_STREAM_CMDRSP_GET_ENCDEC_PARAM:
997 break;
998 case ASM_SESSION_EVENT_TX_OVERFLOW:
999 pr_err("ASM_SESSION_EVENT_TX_OVERFLOW\n");
1000 break;
1001 case ASM_SESSION_CMDRSP_GET_SESSION_TIME:
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001002 pr_debug("%s: ASM_SESSION_CMDRSP_GET_SESSION_TIME, payload[0] = %d, payload[1] = %d, payload[2] = %d\n",
1003 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001004 payload[0], payload[1], payload[2]);
1005 ac->time_stamp = (uint64_t)(((uint64_t)payload[1] << 32) |
1006 payload[2]);
1007 if (atomic_read(&ac->time_flag)) {
1008 atomic_set(&ac->time_flag, 0);
1009 wake_up(&ac->time_wait);
1010 }
1011 break;
1012 case ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY:
Deepa Madiregama55cbf782011-09-10 05:44:39 +05301013 case ASM_DATA_EVENT_ENC_SR_CM_NOTIFY:
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001014 pr_debug("%s: ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY, payload[0] = %d, payload[1] = %d, payload[2] = %d, payload[3] = %d\n",
1015 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001016 payload[0], payload[1], payload[2],
1017 payload[3]);
1018 break;
1019 }
1020 if (ac->cb)
1021 ac->cb(data->opcode, data->token,
1022 data->payload, ac->priv);
1023
1024 return 0;
1025}
1026
1027void *q6asm_is_cpu_buf_avail(int dir, struct audio_client *ac, uint32_t *size,
1028 uint32_t *index)
1029{
1030 void *data;
1031 unsigned char idx;
1032 struct audio_port_data *port;
1033
1034 if (!ac || ((dir != IN) && (dir != OUT)))
1035 return NULL;
1036
1037 if (ac->io_mode == SYNC_IO_MODE) {
1038 port = &ac->port[dir];
1039
1040 mutex_lock(&port->lock);
1041 idx = port->cpu_buf;
1042 if (port->buf == NULL) {
1043 pr_debug("%s:Buffer pointer null\n", __func__);
Jayasena Sangaraboina466e6b92012-01-17 21:10:55 -08001044 mutex_unlock(&port->lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001045 return NULL;
1046 }
1047 /* dir 0: used = 0 means buf in use
1048 dir 1: used = 1 means buf in use */
1049 if (port->buf[idx].used == dir) {
1050 /* To make it more robust, we could loop and get the
1051 next avail buf, its risky though */
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001052 pr_debug("%s:Next buf idx[0x%x] not available,dir[%d]\n",
1053 __func__, idx, dir);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001054 mutex_unlock(&port->lock);
1055 return NULL;
1056 }
1057 *size = port->buf[idx].actual_size;
1058 *index = port->cpu_buf;
1059 data = port->buf[idx].data;
1060 pr_debug("%s:session[%d]index[%d] data[%p]size[%d]\n",
1061 __func__,
1062 ac->session,
1063 port->cpu_buf,
1064 data, *size);
1065 /* By default increase the cpu_buf cnt
1066 user accesses this function,increase cpu
1067 buf(to avoid another api)*/
1068 port->buf[idx].used = dir;
1069 port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1));
1070 mutex_unlock(&port->lock);
1071 return data;
1072 }
1073 return NULL;
1074}
1075
Jay Wang9cf59a02011-08-10 16:58:40 -07001076void *q6asm_is_cpu_buf_avail_nolock(int dir, struct audio_client *ac,
1077 uint32_t *size, uint32_t *index)
1078{
1079 void *data;
1080 unsigned char idx;
1081 struct audio_port_data *port;
1082
1083 if (!ac || ((dir != IN) && (dir != OUT)))
1084 return NULL;
1085
1086 port = &ac->port[dir];
1087
1088 idx = port->cpu_buf;
1089 if (port->buf == NULL) {
1090 pr_debug("%s:Buffer pointer null\n", __func__);
1091 return NULL;
1092 }
1093 /*
1094 * dir 0: used = 0 means buf in use
1095 * dir 1: used = 1 means buf in use
1096 */
1097 if (port->buf[idx].used == dir) {
1098 /*
1099 * To make it more robust, we could loop and get the
1100 * next avail buf, its risky though
1101 */
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001102 pr_debug("%s:Next buf idx[0x%x] not available, dir[%d]\n",
1103 __func__, idx, dir);
Jay Wang9cf59a02011-08-10 16:58:40 -07001104 return NULL;
1105 }
1106 *size = port->buf[idx].actual_size;
1107 *index = port->cpu_buf;
1108 data = port->buf[idx].data;
1109 pr_debug("%s:session[%d]index[%d] data[%p]size[%d]\n",
1110 __func__, ac->session, port->cpu_buf,
1111 data, *size);
1112 /*
1113 * By default increase the cpu_buf cnt
1114 * user accesses this function,increase cpu
1115 * buf(to avoid another api)
1116 */
1117 port->buf[idx].used = dir;
1118 port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1));
1119 return data;
1120}
1121
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001122int q6asm_is_dsp_buf_avail(int dir, struct audio_client *ac)
1123{
1124 int ret = -1;
1125 struct audio_port_data *port;
1126 uint32_t idx;
1127
1128 if (!ac || (dir != OUT))
1129 return ret;
1130
1131 if (ac->io_mode == SYNC_IO_MODE) {
1132 port = &ac->port[dir];
1133
1134 mutex_lock(&port->lock);
1135 idx = port->dsp_buf;
1136
1137 if (port->buf[idx].used == (dir ^ 1)) {
1138 /* To make it more robust, we could loop and get the
1139 next avail buf, its risky though */
1140 pr_err("Next buf idx[0x%x] not available, dir[%d]\n",
1141 idx, dir);
1142 mutex_unlock(&port->lock);
1143 return ret;
1144 }
1145 pr_debug("%s: session[%d]dsp_buf=%d cpu_buf=%d\n", __func__,
1146 ac->session, port->dsp_buf, port->cpu_buf);
1147 ret = ((port->dsp_buf != port->cpu_buf) ? 0 : -1);
1148 mutex_unlock(&port->lock);
1149 }
1150 return ret;
1151}
1152
1153static void q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
1154 uint32_t pkt_size, uint32_t cmd_flg)
1155{
1156 pr_debug("%s:session=%d pkt size=%d cmd_flg=%d\n", __func__, pkt_size,
1157 cmd_flg, ac->session);
1158 mutex_lock(&ac->cmd_lock);
1159 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
1160 APR_HDR_LEN(sizeof(struct apr_hdr)),\
1161 APR_PKT_VER);
1162 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
1163 hdr->src_domain = APR_DOMAIN_APPS;
1164 hdr->dest_svc = APR_SVC_ASM;
1165 hdr->dest_domain = APR_DOMAIN_ADSP;
1166 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
1167 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
1168 if (cmd_flg) {
1169 hdr->token = ac->session;
1170 atomic_set(&ac->cmd_state, 1);
1171 }
1172 hdr->pkt_size = pkt_size;
1173 mutex_unlock(&ac->cmd_lock);
1174 return;
1175}
1176
1177static void q6asm_add_mmaphdr(struct apr_hdr *hdr, uint32_t pkt_size,
1178 uint32_t cmd_flg)
1179{
1180 pr_debug("%s:pkt size=%d cmd_flg=%d\n", __func__, pkt_size, cmd_flg);
1181 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
1182 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1183 hdr->src_port = 0;
1184 hdr->dest_port = 0;
1185 if (cmd_flg) {
1186 hdr->token = 0;
1187 atomic_set(&this_mmap.cmd_state, 1);
1188 }
1189 hdr->pkt_size = pkt_size;
1190 return;
1191}
1192
1193int q6asm_open_read(struct audio_client *ac,
1194 uint32_t format)
1195{
1196 int rc = 0x00;
1197 struct asm_stream_cmd_open_read open;
Rajesha Kini3498c932011-07-19 19:58:27 +05301198#ifdef CONFIG_DEBUG_FS
1199 in_cont_index = 0;
1200#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001201 if ((ac == NULL) || (ac->apr == NULL)) {
1202 pr_err("%s: APR handle NULL\n", __func__);
1203 return -EINVAL;
1204 }
1205 pr_debug("%s:session[%d]", __func__, ac->session);
1206
1207 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1208 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ;
1209 /* Stream prio : High, provide meta info with encoded frames */
1210 open.src_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1211
1212 open.pre_proc_top = get_asm_topology();
1213 if (open.pre_proc_top == 0)
1214 open.pre_proc_top = DEFAULT_POPP_TOPOLOGY;
1215
1216 switch (format) {
1217 case FORMAT_LINEAR_PCM:
1218 open.uMode = STREAM_PRIORITY_HIGH;
1219 open.format = LINEAR_PCM;
1220 break;
Mingming Yin647e9ea2012-03-17 19:56:10 -07001221 case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
1222 open.uMode = STREAM_PRIORITY_HIGH;
1223 open.format = MULTI_CHANNEL_PCM;
1224 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001225 case FORMAT_MPEG4_AAC:
1226 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1227 open.format = MPEG4_AAC;
1228 break;
1229 case FORMAT_V13K:
1230 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1231 open.format = V13K_FS;
1232 break;
1233 case FORMAT_EVRC:
1234 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1235 open.format = EVRC_FS;
1236 break;
1237 case FORMAT_AMRNB:
1238 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1239 open.format = AMRNB_FS;
1240 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301241 case FORMAT_AMRWB:
1242 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1243 open.format = AMRWB_FS;
1244 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001245 default:
1246 pr_err("Invalid format[%d]\n", format);
1247 goto fail_cmd;
1248 }
1249 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1250 if (rc < 0) {
1251 pr_err("open failed op[0x%x]rc[%d]\n", \
1252 open.hdr.opcode, rc);
1253 goto fail_cmd;
1254 }
1255 rc = wait_event_timeout(ac->cmd_wait,
1256 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1257 if (!rc) {
1258 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1259 rc);
1260 goto fail_cmd;
1261 }
1262 return 0;
1263fail_cmd:
1264 return -EINVAL;
1265}
1266
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -07001267int q6asm_open_read_compressed(struct audio_client *ac, uint32_t format)
1268{
1269 int rc = 0x00;
1270 struct asm_stream_cmd_open_read_compressed open;
1271#ifdef CONFIG_DEBUG_FS
1272 in_cont_index = 0;
1273#endif
1274 if ((ac == NULL) || (ac->apr == NULL)) {
1275 pr_err("%s: APR handle NULL\n", __func__);
1276 return -EINVAL;
1277 }
1278 pr_debug("%s:session[%d]", __func__, ac->session);
1279
1280 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1281 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ_COMPRESSED;
1282 /* hardcoded as following*/
1283 open.frame_per_buf = 1;
1284 open.uMode = 0;
1285
1286 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1287 if (rc < 0) {
1288 pr_err("open failed op[0x%x]rc[%d]\n", open.hdr.opcode, rc);
1289 goto fail_cmd;
1290 }
1291 rc = wait_event_timeout(ac->cmd_wait,
1292 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1293 if (!rc) {
1294 pr_err("%s: timeout. waited for OPEN_READ_COMPRESSED rc[%d]\n",
1295 __func__, rc);
1296 goto fail_cmd;
1297 }
1298 return 0;
1299fail_cmd:
1300 return -EINVAL;
1301}
1302
Santosh Mardi23321202012-03-22 04:33:25 +05301303int q6asm_open_write_compressed(struct audio_client *ac, uint32_t format)
1304{
1305 int rc = 0x00;
1306 struct asm_stream_cmd_open_write_compressed open;
1307
1308 if ((ac == NULL) || (ac->apr == NULL)) {
1309 pr_err("%s: APR handle NULL\n", __func__);
1310 return -EINVAL;
1311 }
1312 pr_debug("%s: session[%d] wr_format[0x%x]", __func__, ac->session,
1313 format);
1314
1315 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1316
1317 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_COMPRESSED;
1318
1319 switch (format) {
1320 case FORMAT_AC3:
1321 open.format = AC3_DECODER;
1322 break;
1323 case FORMAT_EAC3:
1324 open.format = EAC3_DECODER;
1325 break;
1326 case FORMAT_MP3:
1327 open.format = MP3;
1328 break;
1329 case FORMAT_DTS:
1330 open.format = DTS;
1331 break;
Srikanth Uyyala66f781a2012-06-13 23:23:25 +05301332 case FORMAT_DTS_LBR:
1333 open.format = DTS_LBR;
1334 break;
Santosh Mardi23321202012-03-22 04:33:25 +05301335 case FORMAT_AAC:
1336 open.format = MPEG4_AAC;
1337 break;
1338 case FORMAT_ATRAC:
1339 open.format = ATRAC;
1340 break;
1341 case FORMAT_WMA_V10PRO:
1342 open.format = WMA_V10PRO;
1343 break;
1344 case FORMAT_MAT:
1345 open.format = MAT;
1346 break;
1347 default:
1348 pr_err("%s: Invalid format[%d]\n", __func__, format);
1349 goto fail_cmd;
1350 }
1351 /*Below flag indicates the DSP that Compressed audio input
1352 stream is not IEC 61937 or IEC 60958 packetizied*/
1353 open.flags = 0x00000000;
1354 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1355 if (rc < 0) {
1356 pr_err("%s: open failed op[0x%x]rc[%d]\n", \
1357 __func__, open.hdr.opcode, rc);
1358 goto fail_cmd;
1359 }
1360 rc = wait_event_timeout(ac->cmd_wait,
1361 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1362 if (!rc) {
1363 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1364 rc);
1365 goto fail_cmd;
1366 }
1367 return 0;
1368fail_cmd:
1369 return -EINVAL;
1370}
1371
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001372int q6asm_open_write(struct audio_client *ac, uint32_t format)
1373{
1374 int rc = 0x00;
1375 struct asm_stream_cmd_open_write open;
1376
1377 if ((ac == NULL) || (ac->apr == NULL)) {
1378 pr_err("%s: APR handle NULL\n", __func__);
1379 return -EINVAL;
1380 }
1381 pr_debug("%s: session[%d] wr_format[0x%x]", __func__, ac->session,
1382 format);
1383
1384 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1385
1386 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE;
1387 open.uMode = STREAM_PRIORITY_HIGH;
1388 /* source endpoint : matrix */
1389 open.sink_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1390 open.stream_handle = 0x00;
1391
1392 open.post_proc_top = get_asm_topology();
1393 if (open.post_proc_top == 0)
1394 open.post_proc_top = DEFAULT_POPP_TOPOLOGY;
1395
1396 switch (format) {
1397 case FORMAT_LINEAR_PCM:
1398 open.format = LINEAR_PCM;
1399 break;
Kiran Kandi5e809b02012-01-31 00:24:33 -08001400 case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
1401 open.format = MULTI_CHANNEL_PCM;
1402 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001403 case FORMAT_MPEG4_AAC:
1404 open.format = MPEG4_AAC;
1405 break;
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07001406 case FORMAT_MPEG4_MULTI_AAC:
1407 open.format = MPEG4_MULTI_AAC;
1408 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001409 case FORMAT_WMA_V9:
1410 open.format = WMA_V9;
1411 break;
1412 case FORMAT_WMA_V10PRO:
1413 open.format = WMA_V10PRO;
1414 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05301415 case FORMAT_MP3:
1416 open.format = MP3;
1417 break;
Srikanth Uyyala66f781a2012-06-13 23:23:25 +05301418 case FORMAT_DTS:
1419 open.format = DTS;
1420 break;
1421 case FORMAT_DTS_LBR:
1422 open.format = DTS_LBR;
1423 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001424 default:
1425 pr_err("%s: Invalid format[%d]\n", __func__, format);
1426 goto fail_cmd;
1427 }
1428 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1429 if (rc < 0) {
1430 pr_err("%s: open failed op[0x%x]rc[%d]\n", \
1431 __func__, open.hdr.opcode, rc);
1432 goto fail_cmd;
1433 }
1434 rc = wait_event_timeout(ac->cmd_wait,
1435 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1436 if (!rc) {
1437 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1438 rc);
1439 goto fail_cmd;
1440 }
1441 return 0;
1442fail_cmd:
1443 return -EINVAL;
1444}
1445
1446int q6asm_open_read_write(struct audio_client *ac,
1447 uint32_t rd_format,
1448 uint32_t wr_format)
1449{
1450 int rc = 0x00;
1451 struct asm_stream_cmd_open_read_write open;
1452
1453 if ((ac == NULL) || (ac->apr == NULL)) {
1454 pr_err("APR handle NULL\n");
1455 return -EINVAL;
1456 }
1457 pr_debug("%s: session[%d]", __func__, ac->session);
1458 pr_debug("wr_format[0x%x]rd_format[0x%x]",
1459 wr_format, rd_format);
1460
1461 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1462 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READWRITE;
1463
Deepa Madiregama55cbf782011-09-10 05:44:39 +05301464 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_NORMAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001465 /* source endpoint : matrix */
1466 open.post_proc_top = get_asm_topology();
1467 if (open.post_proc_top == 0)
1468 open.post_proc_top = DEFAULT_POPP_TOPOLOGY;
1469
1470 switch (wr_format) {
1471 case FORMAT_LINEAR_PCM:
1472 open.write_format = LINEAR_PCM;
1473 break;
1474 case FORMAT_MPEG4_AAC:
1475 open.write_format = MPEG4_AAC;
1476 break;
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07001477 case FORMAT_MPEG4_MULTI_AAC:
1478 open.write_format = MPEG4_MULTI_AAC;
1479 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001480 case FORMAT_WMA_V9:
1481 open.write_format = WMA_V9;
1482 break;
1483 case FORMAT_WMA_V10PRO:
1484 open.write_format = WMA_V10PRO;
1485 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301486 case FORMAT_AMRNB:
1487 open.write_format = AMRNB_FS;
1488 break;
1489 case FORMAT_AMRWB:
1490 open.write_format = AMRWB_FS;
1491 break;
1492 case FORMAT_V13K:
1493 open.write_format = V13K_FS;
1494 break;
1495 case FORMAT_EVRC:
1496 open.write_format = EVRC_FS;
1497 break;
1498 case FORMAT_EVRCB:
1499 open.write_format = EVRCB_FS;
1500 break;
1501 case FORMAT_EVRCWB:
1502 open.write_format = EVRCWB_FS;
1503 break;
1504 case FORMAT_MP3:
1505 open.write_format = MP3;
1506 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001507 default:
1508 pr_err("Invalid format[%d]\n", wr_format);
1509 goto fail_cmd;
1510 }
1511
1512 switch (rd_format) {
1513 case FORMAT_LINEAR_PCM:
1514 open.read_format = LINEAR_PCM;
1515 break;
1516 case FORMAT_MPEG4_AAC:
1517 open.read_format = MPEG4_AAC;
1518 break;
1519 case FORMAT_V13K:
1520 open.read_format = V13K_FS;
1521 break;
1522 case FORMAT_EVRC:
1523 open.read_format = EVRC_FS;
1524 break;
1525 case FORMAT_AMRNB:
1526 open.read_format = AMRNB_FS;
1527 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301528 case FORMAT_AMRWB:
1529 open.read_format = AMRWB_FS;
1530 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001531 default:
1532 pr_err("Invalid format[%d]\n", rd_format);
1533 goto fail_cmd;
1534 }
1535 pr_debug("%s:rdformat[0x%x]wrformat[0x%x]\n", __func__,
1536 open.read_format, open.write_format);
1537
1538 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1539 if (rc < 0) {
1540 pr_err("open failed op[0x%x]rc[%d]\n", \
1541 open.hdr.opcode, rc);
1542 goto fail_cmd;
1543 }
1544 rc = wait_event_timeout(ac->cmd_wait,
1545 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1546 if (!rc) {
1547 pr_err("timeout. waited for OPEN_WRITE rc[%d]\n", rc);
1548 goto fail_cmd;
1549 }
1550 return 0;
1551fail_cmd:
1552 return -EINVAL;
1553}
1554
1555int q6asm_run(struct audio_client *ac, uint32_t flags,
1556 uint32_t msw_ts, uint32_t lsw_ts)
1557{
1558 struct asm_stream_cmd_run run;
1559 int rc;
1560 if (!ac || ac->apr == NULL) {
1561 pr_err("APR handle NULL\n");
1562 return -EINVAL;
1563 }
1564 pr_debug("%s session[%d]", __func__, ac->session);
1565 q6asm_add_hdr(ac, &run.hdr, sizeof(run), TRUE);
1566
1567 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1568 run.flags = flags;
1569 run.msw_ts = msw_ts;
1570 run.lsw_ts = lsw_ts;
Rajesha Kini3498c932011-07-19 19:58:27 +05301571#ifdef CONFIG_DEBUG_FS
1572 if (out_enable_flag) {
1573 do_gettimeofday(&out_cold_tv);
1574 pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",\
1575 out_cold_tv.tv_sec, out_cold_tv.tv_usec);
1576 }
1577#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001578 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1579 if (rc < 0) {
1580 pr_err("Commmand run failed[%d]", rc);
1581 goto fail_cmd;
1582 }
1583
1584 rc = wait_event_timeout(ac->cmd_wait,
1585 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1586 if (!rc) {
1587 pr_err("timeout. waited for run success rc[%d]", rc);
1588 goto fail_cmd;
1589 }
1590
1591 return 0;
1592fail_cmd:
1593 return -EINVAL;
1594}
1595
1596int q6asm_run_nowait(struct audio_client *ac, uint32_t flags,
1597 uint32_t msw_ts, uint32_t lsw_ts)
1598{
1599 struct asm_stream_cmd_run run;
1600 int rc;
1601 if (!ac || ac->apr == NULL) {
1602 pr_err("%s:APR handle NULL\n", __func__);
1603 return -EINVAL;
1604 }
1605 pr_debug("session[%d]", ac->session);
1606 q6asm_add_hdr_async(ac, &run.hdr, sizeof(run), TRUE);
1607
1608 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1609 run.flags = flags;
1610 run.msw_ts = msw_ts;
1611 run.lsw_ts = lsw_ts;
1612
1613 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1614 if (rc < 0) {
1615 pr_err("%s:Commmand run failed[%d]", __func__, rc);
1616 return -EINVAL;
1617 }
1618 return 0;
1619}
1620
1621
1622int q6asm_enc_cfg_blk_aac(struct audio_client *ac,
1623 uint32_t frames_per_buf,
1624 uint32_t sample_rate, uint32_t channels,
1625 uint32_t bit_rate, uint32_t mode, uint32_t format)
1626{
1627 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1628 int rc = 0;
1629
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001630 pr_debug("%s:session[%d]frames[%d]SR[%d]ch[%d]bitrate[%d]mode[%d] format[%d]",
1631 __func__, ac->session, frames_per_buf,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001632 sample_rate, channels, bit_rate, mode, format);
1633
1634 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1635
1636 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1637 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1638 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1639 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1640 enc_cfg.enc_blk.format_id = MPEG4_AAC;
1641 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_aac_read_cfg);
1642 enc_cfg.enc_blk.cfg.aac.bitrate = bit_rate;
1643 enc_cfg.enc_blk.cfg.aac.enc_mode = mode;
1644 enc_cfg.enc_blk.cfg.aac.format = format;
1645 enc_cfg.enc_blk.cfg.aac.ch_cfg = channels;
1646 enc_cfg.enc_blk.cfg.aac.sample_rate = sample_rate;
1647
1648 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1649 if (rc < 0) {
1650 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1651 rc = -EINVAL;
1652 goto fail_cmd;
1653 }
1654 rc = wait_event_timeout(ac->cmd_wait,
1655 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1656 if (!rc) {
1657 pr_err("timeout. waited for FORMAT_UPDATE\n");
1658 goto fail_cmd;
1659 }
1660 return 0;
1661fail_cmd:
1662 return -EINVAL;
1663}
1664
1665int q6asm_enc_cfg_blk_pcm(struct audio_client *ac,
1666 uint32_t rate, uint32_t channels)
1667{
1668 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1669
1670 int rc = 0;
1671
1672 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1673 ac->session, rate, channels);
1674
1675 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1676
1677 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1678 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1679 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1680 enc_cfg.enc_blk.frames_per_buf = 1;
1681 enc_cfg.enc_blk.format_id = LINEAR_PCM;
1682 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg);
1683 enc_cfg.enc_blk.cfg.pcm.ch_cfg = channels;
1684 enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16;
1685 enc_cfg.enc_blk.cfg.pcm.sample_rate = rate;
1686 enc_cfg.enc_blk.cfg.pcm.is_signed = 1;
1687 enc_cfg.enc_blk.cfg.pcm.interleaved = 1;
1688
1689 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1690 if (rc < 0) {
1691 pr_err("Comamnd open failed\n");
1692 rc = -EINVAL;
1693 goto fail_cmd;
1694 }
1695 rc = wait_event_timeout(ac->cmd_wait,
1696 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1697 if (!rc) {
1698 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1699 goto fail_cmd;
1700 }
1701 return 0;
1702fail_cmd:
1703 return -EINVAL;
1704}
1705
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001706int q6asm_enc_cfg_blk_pcm_native(struct audio_client *ac,
1707 uint32_t rate, uint32_t channels)
1708{
1709 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1710
1711 int rc = 0;
1712
1713 pr_debug("%s: Session %d, rate = %d, channels = %d, setting the rate and channels to 0 for native\n",
1714 __func__, ac->session, rate, channels);
1715
1716 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1717
1718 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1719 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1720 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1721 enc_cfg.enc_blk.frames_per_buf = 1;
1722 enc_cfg.enc_blk.format_id = LINEAR_PCM;
1723 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg);
1724 enc_cfg.enc_blk.cfg.pcm.ch_cfg = 0;/*channels;*/
1725 enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16;
1726 enc_cfg.enc_blk.cfg.pcm.sample_rate = 0;/*rate;*/
1727 enc_cfg.enc_blk.cfg.pcm.is_signed = 1;
1728 enc_cfg.enc_blk.cfg.pcm.interleaved = 1;
1729
1730 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1731 if (rc < 0) {
1732 pr_err("Comamnd open failed\n");
1733 rc = -EINVAL;
1734 goto fail_cmd;
1735 }
1736 rc = wait_event_timeout(ac->cmd_wait,
1737 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1738 if (!rc) {
1739 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1740 goto fail_cmd;
1741 }
1742 return 0;
1743fail_cmd:
1744 return -EINVAL;
1745}
1746
Mingming Yin647e9ea2012-03-17 19:56:10 -07001747int q6asm_enc_cfg_blk_multi_ch_pcm(struct audio_client *ac,
1748 uint32_t rate, uint32_t channels)
1749{
1750 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1751
1752 int rc = 0;
1753
1754 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1755 ac->session, rate, channels);
1756
1757 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1758
1759 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1760 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1761 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1762 enc_cfg.enc_blk.frames_per_buf = 1;
1763 enc_cfg.enc_blk.format_id = MULTI_CHANNEL_PCM;
1764 enc_cfg.enc_blk.cfg_size =
1765 sizeof(struct asm_multi_channel_pcm_fmt_blk);
1766 enc_cfg.enc_blk.cfg.mpcm.num_channels = channels;
1767 enc_cfg.enc_blk.cfg.mpcm.bits_per_sample = 16;
1768 enc_cfg.enc_blk.cfg.mpcm.sample_rate = rate;
1769 enc_cfg.enc_blk.cfg.mpcm.is_signed = 1;
1770 enc_cfg.enc_blk.cfg.mpcm.is_interleaved = 1;
1771 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1772 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1773 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_RB;
1774 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_LB;
1775 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1776 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1777 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1778 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1779
1780 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1781 if (rc < 0) {
1782 pr_err("Comamnd open failed\n");
1783 rc = -EINVAL;
1784 goto fail_cmd;
1785 }
1786 rc = wait_event_timeout(ac->cmd_wait,
1787 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1788 if (!rc) {
1789 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1790 goto fail_cmd;
1791 }
1792 return 0;
1793fail_cmd:
1794 return -EINVAL;
1795}
1796
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001797int q6asm_enable_sbrps(struct audio_client *ac,
1798 uint32_t sbr_ps_enable)
1799{
1800 struct asm_stream_cmd_encdec_sbr sbrps;
1801
1802 int rc = 0;
1803
1804 pr_debug("%s: Session %d\n", __func__, ac->session);
1805
1806 q6asm_add_hdr(ac, &sbrps.hdr, sizeof(sbrps), TRUE);
1807
1808 sbrps.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1809 sbrps.param_id = ASM_ENABLE_SBR_PS;
1810 sbrps.param_size = sizeof(struct asm_sbr_ps);
1811 sbrps.sbr_ps.enable = sbr_ps_enable;
1812
1813 rc = apr_send_pkt(ac->apr, (uint32_t *) &sbrps);
1814 if (rc < 0) {
1815 pr_err("Command opcode[0x%x]paramid[0x%x] failed\n",
1816 ASM_STREAM_CMD_SET_ENCDEC_PARAM,
1817 ASM_ENABLE_SBR_PS);
1818 rc = -EINVAL;
1819 goto fail_cmd;
1820 }
1821 rc = wait_event_timeout(ac->cmd_wait,
1822 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1823 if (!rc) {
1824 pr_err("timeout opcode[0x%x] ", sbrps.hdr.opcode);
1825 goto fail_cmd;
1826 }
1827 return 0;
1828fail_cmd:
1829 return -EINVAL;
1830}
1831
Swaminathan Sathappan70765cd2011-07-19 18:42:47 -07001832int q6asm_cfg_dual_mono_aac(struct audio_client *ac,
1833 uint16_t sce_left, uint16_t sce_right)
1834{
1835 struct asm_stream_cmd_encdec_dualmono dual_mono;
1836
1837 int rc = 0;
1838
1839 pr_debug("%s: Session %d, sce_left = %d, sce_right = %d\n",
1840 __func__, ac->session, sce_left, sce_right);
1841
1842 q6asm_add_hdr(ac, &dual_mono.hdr, sizeof(dual_mono), TRUE);
1843
1844 dual_mono.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1845 dual_mono.param_id = ASM_CONFIGURE_DUAL_MONO;
1846 dual_mono.param_size = sizeof(struct asm_dual_mono);
1847 dual_mono.channel_map.sce_left = sce_left;
1848 dual_mono.channel_map.sce_right = sce_right;
1849
1850 rc = apr_send_pkt(ac->apr, (uint32_t *) &dual_mono);
1851 if (rc < 0) {
1852 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
1853 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
1854 ASM_CONFIGURE_DUAL_MONO);
1855 rc = -EINVAL;
1856 goto fail_cmd;
1857 }
1858 rc = wait_event_timeout(ac->cmd_wait,
1859 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1860 if (!rc) {
1861 pr_err("%s:timeout opcode[0x%x]\n", __func__,
1862 dual_mono.hdr.opcode);
1863 goto fail_cmd;
1864 }
1865 return 0;
1866fail_cmd:
1867 return -EINVAL;
1868}
1869
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07001870int q6asm_set_encdec_chan_map(struct audio_client *ac,
1871 uint32_t num_channels)
1872{
1873 struct asm_stream_cmd_encdec_channelmap chan_map;
1874 u8 *channel_mapping;
1875
1876 int rc = 0;
1877
1878 pr_debug("%s: Session %d, num_channels = %d\n",
1879 __func__, ac->session, num_channels);
1880
1881 q6asm_add_hdr(ac, &chan_map.hdr, sizeof(chan_map), TRUE);
1882
1883 chan_map.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1884 chan_map.param_id = ASM_ENCDEC_DEC_CHAN_MAP;
1885 chan_map.param_size = sizeof(struct asm_dec_chan_map);
1886 chan_map.chan_map.num_channels = num_channels;
1887
1888 channel_mapping =
1889 chan_map.chan_map.channel_mapping;
1890
1891 memset(channel_mapping, PCM_CHANNEL_NULL, MAX_CHAN_MAP_CHANNELS);
1892 if (num_channels == 1) {
1893 channel_mapping[0] = PCM_CHANNEL_FL;
1894 } else if (num_channels == 2) {
1895 channel_mapping[0] = PCM_CHANNEL_FL;
1896 channel_mapping[1] = PCM_CHANNEL_FR;
1897 } else if (num_channels == 6) {
1898 channel_mapping[0] = PCM_CHANNEL_FC;
1899 channel_mapping[1] = PCM_CHANNEL_FL;
1900 channel_mapping[2] = PCM_CHANNEL_FR;
1901 channel_mapping[3] = PCM_CHANNEL_LB;
1902 channel_mapping[4] = PCM_CHANNEL_RB;
1903 channel_mapping[5] = PCM_CHANNEL_LFE;
1904 } else {
1905 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
1906 num_channels);
1907 rc = -EINVAL;
1908 goto fail_cmd;
1909 }
1910
1911 rc = apr_send_pkt(ac->apr, (uint32_t *) &chan_map);
1912 if (rc < 0) {
1913 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
1914 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
1915 ASM_ENCDEC_DEC_CHAN_MAP);
1916 goto fail_cmd;
1917 }
1918 rc = wait_event_timeout(ac->cmd_wait,
1919 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1920 if (!rc) {
1921 pr_err("%s:timeout opcode[0x%x]\n", __func__,
1922 chan_map.hdr.opcode);
1923 rc = -ETIMEDOUT;
1924 goto fail_cmd;
1925 }
1926 return 0;
1927fail_cmd:
1928 return rc;
1929}
1930
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001931int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf,
1932 uint16_t min_rate, uint16_t max_rate,
1933 uint16_t reduced_rate_level, uint16_t rate_modulation_cmd)
1934{
1935 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1936 int rc = 0;
1937
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001938 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]",
1939 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001940 ac->session, frames_per_buf, min_rate, max_rate,
1941 reduced_rate_level, rate_modulation_cmd);
1942
1943 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1944
1945 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1946
1947 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1948 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1949
1950 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1951 enc_cfg.enc_blk.format_id = V13K_FS;
1952 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_qcelp13_read_cfg);
1953 enc_cfg.enc_blk.cfg.qcelp13.min_rate = min_rate;
1954 enc_cfg.enc_blk.cfg.qcelp13.max_rate = max_rate;
1955 enc_cfg.enc_blk.cfg.qcelp13.reduced_rate_level = reduced_rate_level;
1956 enc_cfg.enc_blk.cfg.qcelp13.rate_modulation_cmd = rate_modulation_cmd;
1957
1958 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1959 if (rc < 0) {
1960 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
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. waited for FORMAT_UPDATE\n");
1967 goto fail_cmd;
1968 }
1969 return 0;
1970fail_cmd:
1971 return -EINVAL;
1972}
1973
1974int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf,
1975 uint16_t min_rate, uint16_t max_rate,
1976 uint16_t rate_modulation_cmd)
1977{
1978 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1979 int rc = 0;
1980
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001981 pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] rate_modulation_cmd[0x%4x]",
1982 __func__, ac->session,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001983 frames_per_buf, min_rate, max_rate, rate_modulation_cmd);
1984
1985 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1986
1987 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1988
1989 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1990 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1991
1992 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1993 enc_cfg.enc_blk.format_id = EVRC_FS;
1994 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_evrc_read_cfg);
1995 enc_cfg.enc_blk.cfg.evrc.min_rate = min_rate;
1996 enc_cfg.enc_blk.cfg.evrc.max_rate = max_rate;
1997 enc_cfg.enc_blk.cfg.evrc.rate_modulation_cmd = rate_modulation_cmd;
1998 enc_cfg.enc_blk.cfg.evrc.reserved = 0;
1999
2000 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2001 if (rc < 0) {
2002 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2003 goto fail_cmd;
2004 }
2005 rc = wait_event_timeout(ac->cmd_wait,
2006 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2007 if (!rc) {
2008 pr_err("timeout. waited for FORMAT_UPDATE\n");
2009 goto fail_cmd;
2010 }
2011 return 0;
2012fail_cmd:
2013 return -EINVAL;
2014}
2015
2016int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf,
2017 uint16_t band_mode, uint16_t dtx_enable)
2018{
2019 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2020 int rc = 0;
2021
2022 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
2023 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
2024
2025 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2026
2027 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2028
2029 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2030 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2031
2032 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2033 enc_cfg.enc_blk.format_id = AMRNB_FS;
2034 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrnb_read_cfg);
2035 enc_cfg.enc_blk.cfg.amrnb.mode = band_mode;
2036 enc_cfg.enc_blk.cfg.amrnb.dtx_mode = dtx_enable;
2037
2038 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2039 if (rc < 0) {
2040 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2041 goto fail_cmd;
2042 }
2043 rc = wait_event_timeout(ac->cmd_wait,
2044 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2045 if (!rc) {
2046 pr_err("timeout. waited for FORMAT_UPDATE\n");
2047 goto fail_cmd;
2048 }
2049 return 0;
2050fail_cmd:
2051 return -EINVAL;
2052}
2053
Alex Wong2caeecc2011-10-28 10:52:15 +05302054int q6asm_enc_cfg_blk_amrwb(struct audio_client *ac, uint32_t frames_per_buf,
2055 uint16_t band_mode, uint16_t dtx_enable)
2056{
2057 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2058 int rc = 0;
2059
2060 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
2061 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
2062
2063 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2064
2065 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2066
2067 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2068 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2069
2070 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2071 enc_cfg.enc_blk.format_id = AMRWB_FS;
2072 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrwb_read_cfg);
2073 enc_cfg.enc_blk.cfg.amrwb.mode = band_mode;
2074 enc_cfg.enc_blk.cfg.amrwb.dtx_mode = dtx_enable;
2075
2076 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2077 if (rc < 0) {
2078 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2079 goto fail_cmd;
2080 }
2081 rc = wait_event_timeout(ac->cmd_wait,
2082 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2083 if (!rc) {
2084 pr_err("timeout. waited for FORMAT_UPDATE\n");
2085 goto fail_cmd;
2086 }
2087 return 0;
2088fail_cmd:
2089 return -EINVAL;
2090}
2091
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002092int q6asm_media_format_block_pcm(struct audio_client *ac,
2093 uint32_t rate, uint32_t channels)
2094{
2095 struct asm_stream_media_format_update fmt;
2096 int rc = 0;
2097
2098 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
2099 channels);
2100
2101 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2102
2103 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2104
2105 fmt.format = LINEAR_PCM;
2106 fmt.cfg_size = sizeof(struct asm_pcm_cfg);
2107 fmt.write_cfg.pcm_cfg.ch_cfg = channels;
2108 fmt.write_cfg.pcm_cfg.bits_per_sample = 16;
2109 fmt.write_cfg.pcm_cfg.sample_rate = rate;
2110 fmt.write_cfg.pcm_cfg.is_signed = 1;
2111 fmt.write_cfg.pcm_cfg.interleaved = 1;
2112
2113 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2114 if (rc < 0) {
2115 pr_err("%s:Comamnd open failed\n", __func__);
2116 goto fail_cmd;
2117 }
2118 rc = wait_event_timeout(ac->cmd_wait,
2119 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2120 if (!rc) {
2121 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2122 goto fail_cmd;
2123 }
2124 return 0;
2125fail_cmd:
2126 return -EINVAL;
2127}
2128
Kiran Kandi5e809b02012-01-31 00:24:33 -08002129int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
2130 uint32_t rate, uint32_t channels)
2131{
2132 struct asm_stream_media_format_update fmt;
2133 u8 *channel_mapping;
2134 int rc = 0;
2135
2136 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
2137 channels);
2138
2139 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2140
2141 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2142
2143 fmt.format = MULTI_CHANNEL_PCM;
2144 fmt.cfg_size = sizeof(struct asm_multi_channel_pcm_fmt_blk);
2145 fmt.write_cfg.multi_ch_pcm_cfg.num_channels = channels;
2146 fmt.write_cfg.multi_ch_pcm_cfg.bits_per_sample = 16;
2147 fmt.write_cfg.multi_ch_pcm_cfg.sample_rate = rate;
2148 fmt.write_cfg.multi_ch_pcm_cfg.is_signed = 1;
2149 fmt.write_cfg.multi_ch_pcm_cfg.is_interleaved = 1;
2150 channel_mapping =
2151 fmt.write_cfg.multi_ch_pcm_cfg.channel_mapping;
2152
2153 memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
2154
2155 if (channels == 1) {
2156 channel_mapping[0] = PCM_CHANNEL_FL;
2157 } else if (channels == 2) {
2158 channel_mapping[0] = PCM_CHANNEL_FL;
2159 channel_mapping[1] = PCM_CHANNEL_FR;
2160 } else if (channels == 6) {
2161 channel_mapping[0] = PCM_CHANNEL_FC;
2162 channel_mapping[1] = PCM_CHANNEL_FL;
2163 channel_mapping[2] = PCM_CHANNEL_FR;
2164 channel_mapping[3] = PCM_CHANNEL_LB;
2165 channel_mapping[4] = PCM_CHANNEL_RB;
2166 channel_mapping[5] = PCM_CHANNEL_LFE;
2167 } else {
2168 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
2169 channels);
2170 return -EINVAL;
2171 }
2172
2173 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2174 if (rc < 0) {
2175 pr_err("%s:Comamnd open failed\n", __func__);
2176 goto fail_cmd;
2177 }
2178 rc = wait_event_timeout(ac->cmd_wait,
2179 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2180 if (!rc) {
2181 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2182 goto fail_cmd;
2183 }
2184 return 0;
2185fail_cmd:
2186 return -EINVAL;
2187}
2188
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002189int q6asm_media_format_block_aac(struct audio_client *ac,
2190 struct asm_aac_cfg *cfg)
2191{
2192 struct asm_stream_media_format_update fmt;
2193 int rc = 0;
2194
2195 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2196 cfg->sample_rate, cfg->ch_cfg);
2197
2198 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2199
2200 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2201
2202 fmt.format = MPEG4_AAC;
2203 fmt.cfg_size = sizeof(struct asm_aac_cfg);
2204 fmt.write_cfg.aac_cfg.format = cfg->format;
2205 fmt.write_cfg.aac_cfg.aot = cfg->aot;
2206 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
2207 fmt.write_cfg.aac_cfg.section_data_resilience =
2208 cfg->section_data_resilience;
2209 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2210 cfg->scalefactor_data_resilience;
2211 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2212 cfg->spectral_data_resilience;
2213 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2214 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2215 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2216 __func__, fmt.format, fmt.cfg_size,
2217 fmt.write_cfg.aac_cfg.format,
2218 fmt.write_cfg.aac_cfg.aot,
2219 fmt.write_cfg.aac_cfg.ch_cfg,
2220 fmt.write_cfg.aac_cfg.sample_rate);
2221 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2222 if (rc < 0) {
2223 pr_err("%s:Comamnd open failed\n", __func__);
2224 goto fail_cmd;
2225 }
2226 rc = wait_event_timeout(ac->cmd_wait,
2227 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2228 if (!rc) {
2229 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2230 goto fail_cmd;
2231 }
2232 return 0;
2233fail_cmd:
2234 return -EINVAL;
2235}
2236
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07002237
2238int q6asm_media_format_block_multi_aac(struct audio_client *ac,
2239 struct asm_aac_cfg *cfg)
2240{
2241 struct asm_stream_media_format_update fmt;
2242 int rc = 0;
2243
2244 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2245 cfg->sample_rate, cfg->ch_cfg);
2246
2247 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2248
2249 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2250
2251 fmt.format = MPEG4_MULTI_AAC;
2252 fmt.cfg_size = sizeof(struct asm_aac_cfg);
2253 fmt.write_cfg.aac_cfg.format = cfg->format;
2254 fmt.write_cfg.aac_cfg.aot = cfg->aot;
2255 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
2256 fmt.write_cfg.aac_cfg.section_data_resilience =
2257 cfg->section_data_resilience;
2258 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2259 cfg->scalefactor_data_resilience;
2260 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2261 cfg->spectral_data_resilience;
2262 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2263 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2264 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2265 __func__, fmt.format, fmt.cfg_size,
2266 fmt.write_cfg.aac_cfg.format,
2267 fmt.write_cfg.aac_cfg.aot,
2268 fmt.write_cfg.aac_cfg.ch_cfg,
2269 fmt.write_cfg.aac_cfg.sample_rate);
2270 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2271 if (rc < 0) {
2272 pr_err("%s:Comamnd open failed\n", __func__);
2273 goto fail_cmd;
2274 }
2275 rc = wait_event_timeout(ac->cmd_wait,
2276 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2277 if (!rc) {
2278 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2279 goto fail_cmd;
2280 }
2281 return 0;
2282fail_cmd:
2283 return -EINVAL;
2284}
2285
2286
Alex Wong2caeecc2011-10-28 10:52:15 +05302287
2288int q6asm_media_format_block(struct audio_client *ac, uint32_t format)
2289{
2290
2291 struct asm_stream_media_format_update fmt;
2292 int rc = 0;
2293
2294 pr_debug("%s:session[%d] format[0x%x]\n", __func__,
2295 ac->session, format);
2296
2297 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2298 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302299 switch (format) {
2300 case FORMAT_V13K:
2301 fmt.format = V13K_FS;
2302 break;
2303 case FORMAT_EVRC:
2304 fmt.format = EVRC_FS;
2305 break;
2306 case FORMAT_AMRWB:
2307 fmt.format = AMRWB_FS;
2308 break;
2309 case FORMAT_AMRNB:
2310 fmt.format = AMRNB_FS;
2311 break;
2312 case FORMAT_MP3:
2313 fmt.format = MP3;
2314 break;
Srikanth Uyyala66f781a2012-06-13 23:23:25 +05302315 case FORMAT_DTS:
2316 fmt.format = DTS;
2317 break;
2318 case FORMAT_DTS_LBR:
2319 fmt.format = DTS_LBR;
2320 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302321 default:
2322 pr_err("Invalid format[%d]\n", format);
2323 goto fail_cmd;
2324 }
Alex Wong2caeecc2011-10-28 10:52:15 +05302325 fmt.cfg_size = 0;
2326
2327 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2328 if (rc < 0) {
2329 pr_err("%s:Comamnd open failed\n", __func__);
2330 goto fail_cmd;
2331 }
2332 rc = wait_event_timeout(ac->cmd_wait,
2333 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2334 if (!rc) {
2335 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2336 goto fail_cmd;
2337 }
2338 return 0;
2339fail_cmd:
2340 return -EINVAL;
2341}
2342
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002343int q6asm_media_format_block_wma(struct audio_client *ac,
2344 void *cfg)
2345{
2346 struct asm_stream_media_format_update fmt;
2347 struct asm_wma_cfg *wma_cfg = (struct asm_wma_cfg *)cfg;
2348 int rc = 0;
2349
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002350 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 -07002351 ac->session, wma_cfg->format_tag, wma_cfg->sample_rate,
2352 wma_cfg->ch_cfg, wma_cfg->avg_bytes_per_sec,
2353 wma_cfg->block_align, wma_cfg->valid_bits_per_sample,
2354 wma_cfg->ch_mask, wma_cfg->encode_opt);
2355
2356 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2357
2358 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2359
2360 fmt.format = WMA_V9;
2361 fmt.cfg_size = sizeof(struct asm_wma_cfg);
2362 fmt.write_cfg.wma_cfg.format_tag = wma_cfg->format_tag;
2363 fmt.write_cfg.wma_cfg.ch_cfg = wma_cfg->ch_cfg;
2364 fmt.write_cfg.wma_cfg.sample_rate = wma_cfg->sample_rate;
2365 fmt.write_cfg.wma_cfg.avg_bytes_per_sec = wma_cfg->avg_bytes_per_sec;
2366 fmt.write_cfg.wma_cfg.block_align = wma_cfg->block_align;
2367 fmt.write_cfg.wma_cfg.valid_bits_per_sample =
2368 wma_cfg->valid_bits_per_sample;
2369 fmt.write_cfg.wma_cfg.ch_mask = wma_cfg->ch_mask;
2370 fmt.write_cfg.wma_cfg.encode_opt = wma_cfg->encode_opt;
2371 fmt.write_cfg.wma_cfg.adv_encode_opt = 0;
2372 fmt.write_cfg.wma_cfg.adv_encode_opt2 = 0;
2373 fmt.write_cfg.wma_cfg.drc_peak_ref = 0;
2374 fmt.write_cfg.wma_cfg.drc_peak_target = 0;
2375 fmt.write_cfg.wma_cfg.drc_ave_ref = 0;
2376 fmt.write_cfg.wma_cfg.drc_ave_target = 0;
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
2394int q6asm_media_format_block_wmapro(struct audio_client *ac,
2395 void *cfg)
2396{
2397 struct asm_stream_media_format_update fmt;
2398 struct asm_wmapro_cfg *wmapro_cfg = (struct asm_wmapro_cfg *)cfg;
2399 int rc = 0;
2400
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002401 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 -07002402 ac->session, wmapro_cfg->format_tag, wmapro_cfg->sample_rate,
2403 wmapro_cfg->ch_cfg, wmapro_cfg->avg_bytes_per_sec,
2404 wmapro_cfg->block_align, wmapro_cfg->valid_bits_per_sample,
2405 wmapro_cfg->ch_mask, wmapro_cfg->encode_opt,
2406 wmapro_cfg->adv_encode_opt, wmapro_cfg->adv_encode_opt2);
2407
2408 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2409
2410 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2411
2412 fmt.format = WMA_V10PRO;
2413 fmt.cfg_size = sizeof(struct asm_wmapro_cfg);
2414 fmt.write_cfg.wmapro_cfg.format_tag = wmapro_cfg->format_tag;
2415 fmt.write_cfg.wmapro_cfg.ch_cfg = wmapro_cfg->ch_cfg;
2416 fmt.write_cfg.wmapro_cfg.sample_rate = wmapro_cfg->sample_rate;
2417 fmt.write_cfg.wmapro_cfg.avg_bytes_per_sec =
2418 wmapro_cfg->avg_bytes_per_sec;
2419 fmt.write_cfg.wmapro_cfg.block_align = wmapro_cfg->block_align;
2420 fmt.write_cfg.wmapro_cfg.valid_bits_per_sample =
2421 wmapro_cfg->valid_bits_per_sample;
2422 fmt.write_cfg.wmapro_cfg.ch_mask = wmapro_cfg->ch_mask;
2423 fmt.write_cfg.wmapro_cfg.encode_opt = wmapro_cfg->encode_opt;
2424 fmt.write_cfg.wmapro_cfg.adv_encode_opt = wmapro_cfg->adv_encode_opt;
2425 fmt.write_cfg.wmapro_cfg.adv_encode_opt2 = wmapro_cfg->adv_encode_opt2;
2426 fmt.write_cfg.wmapro_cfg.drc_peak_ref = 0;
2427 fmt.write_cfg.wmapro_cfg.drc_peak_target = 0;
2428 fmt.write_cfg.wmapro_cfg.drc_ave_ref = 0;
2429 fmt.write_cfg.wmapro_cfg.drc_ave_target = 0;
2430
2431 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2432 if (rc < 0) {
2433 pr_err("%s:Comamnd open failed\n", __func__);
2434 goto fail_cmd;
2435 }
2436 rc = wait_event_timeout(ac->cmd_wait,
2437 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2438 if (!rc) {
2439 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2440 goto fail_cmd;
2441 }
2442 return 0;
2443fail_cmd:
2444 return -EINVAL;
2445}
2446
2447int q6asm_memory_map(struct audio_client *ac, uint32_t buf_add, int dir,
2448 uint32_t bufsz, uint32_t bufcnt)
2449{
2450 struct asm_stream_cmd_memory_map mem_map;
2451 int rc = 0;
2452
2453 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2454 pr_err("APR handle NULL\n");
2455 return -EINVAL;
2456 }
2457
2458 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2459
2460 mem_map.hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP;
2461
2462 mem_map.buf_add = buf_add;
2463 mem_map.buf_size = bufsz * bufcnt;
2464 mem_map.mempool_id = 0; /* EBI */
2465 mem_map.reserved = 0;
2466
2467 q6asm_add_mmaphdr(&mem_map.hdr,
2468 sizeof(struct asm_stream_cmd_memory_map), TRUE);
2469
2470 pr_debug("buf add[%x] buf_add_parameter[%x]\n",
2471 mem_map.buf_add, buf_add);
2472
2473 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_map);
2474 if (rc < 0) {
2475 pr_err("mem_map op[0x%x]rc[%d]\n",
2476 mem_map.hdr.opcode, rc);
2477 rc = -EINVAL;
2478 goto fail_cmd;
2479 }
2480
2481 rc = wait_event_timeout(this_mmap.cmd_wait,
2482 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2483 if (!rc) {
2484 pr_err("timeout. waited for memory_map\n");
2485 rc = -EINVAL;
2486 goto fail_cmd;
2487 }
2488 rc = 0;
2489fail_cmd:
2490 return rc;
2491}
2492
2493int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add, int dir)
2494{
2495 struct asm_stream_cmd_memory_unmap mem_unmap;
2496 int rc = 0;
2497
2498 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2499 pr_err("APR handle NULL\n");
2500 return -EINVAL;
2501 }
2502 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2503
2504 q6asm_add_mmaphdr(&mem_unmap.hdr,
2505 sizeof(struct asm_stream_cmd_memory_unmap), TRUE);
2506 mem_unmap.hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP;
2507 mem_unmap.buf_add = buf_add;
2508
2509 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_unmap);
2510 if (rc < 0) {
2511 pr_err("mem_unmap op[0x%x]rc[%d]\n",
2512 mem_unmap.hdr.opcode, rc);
2513 rc = -EINVAL;
2514 goto fail_cmd;
2515 }
2516
2517 rc = wait_event_timeout(this_mmap.cmd_wait,
2518 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2519 if (!rc) {
2520 pr_err("timeout. waited for memory_map\n");
2521 rc = -EINVAL;
2522 goto fail_cmd;
2523 }
2524 rc = 0;
2525fail_cmd:
2526 return rc;
2527}
2528
2529int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain)
2530{
2531 void *vol_cmd = NULL;
2532 void *payload = NULL;
2533 struct asm_pp_params_command *cmd = NULL;
2534 struct asm_lrchannel_gain_params *lrgain = NULL;
2535 int sz = 0;
2536 int rc = 0;
2537
2538 sz = sizeof(struct asm_pp_params_command) +
2539 + sizeof(struct asm_lrchannel_gain_params);
2540 vol_cmd = kzalloc(sz, GFP_KERNEL);
2541 if (vol_cmd == NULL) {
2542 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2543 rc = -EINVAL;
2544 return rc;
2545 }
2546 cmd = (struct asm_pp_params_command *)vol_cmd;
2547 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2548 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2549 cmd->payload = NULL;
2550 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2551 sizeof(struct asm_lrchannel_gain_params);
2552 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2553 cmd->params.param_id = L_R_CHANNEL_GAIN_PARAM_ID;
2554 cmd->params.param_size = sizeof(struct asm_lrchannel_gain_params);
2555 cmd->params.reserved = 0;
2556
2557 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2558 lrgain = (struct asm_lrchannel_gain_params *)payload;
2559
2560 lrgain->left_gain = left_gain;
2561 lrgain->right_gain = right_gain;
2562 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2563 if (rc < 0) {
2564 pr_err("%s: Volume Command failed\n", __func__);
2565 rc = -EINVAL;
2566 goto fail_cmd;
2567 }
2568
2569 rc = wait_event_timeout(ac->cmd_wait,
2570 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2571 if (!rc) {
2572 pr_err("%s: timeout in sending volume command to apr\n",
2573 __func__);
2574 rc = -EINVAL;
2575 goto fail_cmd;
2576 }
2577 rc = 0;
2578fail_cmd:
2579 kfree(vol_cmd);
2580 return rc;
2581}
2582
2583static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
2584 uint32_t bufsz, uint32_t bufcnt)
2585{
2586 struct asm_stream_cmd_memory_map_regions *mmap_regions = NULL;
2587 struct asm_memory_map_regions *mregions = NULL;
2588 struct audio_port_data *port = NULL;
2589 struct audio_buffer *ab = NULL;
2590 void *mmap_region_cmd = NULL;
2591 void *payload = NULL;
2592 int rc = 0;
2593 int i = 0;
2594 int cmd_size = 0;
2595
2596 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2597 pr_err("APR handle NULL\n");
2598 return -EINVAL;
2599 }
2600 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2601
2602 cmd_size = sizeof(struct asm_stream_cmd_memory_map_regions)
2603 + sizeof(struct asm_memory_map_regions) * bufcnt;
2604
2605 mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302606 if (mmap_region_cmd == NULL) {
2607 pr_err("%s: Mem alloc failed\n", __func__);
2608 rc = -EINVAL;
2609 return rc;
2610 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002611 mmap_regions = (struct asm_stream_cmd_memory_map_regions *)
2612 mmap_region_cmd;
2613 q6asm_add_mmaphdr(&mmap_regions->hdr, cmd_size, TRUE);
2614 mmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP_REGIONS;
2615 mmap_regions->mempool_id = 0;
2616 mmap_regions->nregions = bufcnt & 0x00ff;
2617 pr_debug("map_regions->nregions = %d\n", mmap_regions->nregions);
2618 payload = ((u8 *) mmap_region_cmd +
2619 sizeof(struct asm_stream_cmd_memory_map_regions));
2620 mregions = (struct asm_memory_map_regions *)payload;
2621
2622 port = &ac->port[dir];
2623 for (i = 0; i < bufcnt; i++) {
2624 ab = &port->buf[i];
2625 mregions->phys = ab->phys;
2626 mregions->buf_size = ab->size;
2627 ++mregions;
2628 }
2629
2630 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) mmap_region_cmd);
2631 if (rc < 0) {
2632 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2633 mmap_regions->hdr.opcode, rc);
2634 rc = -EINVAL;
2635 goto fail_cmd;
2636 }
2637
2638 rc = wait_event_timeout(this_mmap.cmd_wait,
2639 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2640 if (!rc) {
2641 pr_err("timeout. waited for memory_map\n");
2642 rc = -EINVAL;
2643 goto fail_cmd;
2644 }
2645 rc = 0;
2646fail_cmd:
2647 kfree(mmap_region_cmd);
2648 return rc;
2649}
2650
2651static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir,
2652 uint32_t bufsz, uint32_t bufcnt)
2653{
2654 struct asm_stream_cmd_memory_unmap_regions *unmap_regions = NULL;
2655 struct asm_memory_unmap_regions *mregions = NULL;
2656 struct audio_port_data *port = NULL;
2657 struct audio_buffer *ab = NULL;
2658 void *unmap_region_cmd = NULL;
2659 void *payload = NULL;
2660 int rc = 0;
2661 int i = 0;
2662 int cmd_size = 0;
2663
2664 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2665 pr_err("APR handle NULL\n");
2666 return -EINVAL;
2667 }
2668 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2669
2670 cmd_size = sizeof(struct asm_stream_cmd_memory_unmap_regions) +
2671 sizeof(struct asm_memory_unmap_regions) * bufcnt;
2672
2673 unmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302674 if (unmap_region_cmd == NULL) {
2675 pr_err("%s: Mem alloc failed\n", __func__);
2676 rc = -EINVAL;
2677 return rc;
2678 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002679 unmap_regions = (struct asm_stream_cmd_memory_unmap_regions *)
2680 unmap_region_cmd;
2681 q6asm_add_mmaphdr(&unmap_regions->hdr, cmd_size, TRUE);
2682 unmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS;
2683 unmap_regions->nregions = bufcnt & 0x00ff;
2684 pr_debug("unmap_regions->nregions = %d\n", unmap_regions->nregions);
2685 payload = ((u8 *) unmap_region_cmd +
2686 sizeof(struct asm_stream_cmd_memory_unmap_regions));
2687 mregions = (struct asm_memory_unmap_regions *)payload;
2688 port = &ac->port[dir];
2689 for (i = 0; i < bufcnt; i++) {
2690 ab = &port->buf[i];
2691 mregions->phys = ab->phys;
2692 ++mregions;
2693 }
2694
2695 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) unmap_region_cmd);
2696 if (rc < 0) {
2697 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2698 unmap_regions->hdr.opcode, rc);
2699 goto fail_cmd;
2700 }
2701
2702 rc = wait_event_timeout(this_mmap.cmd_wait,
2703 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2704 if (!rc) {
2705 pr_err("timeout. waited for memory_unmap\n");
2706 goto fail_cmd;
2707 }
2708 rc = 0;
2709
2710fail_cmd:
2711 kfree(unmap_region_cmd);
2712 return rc;
2713}
2714
2715int q6asm_set_mute(struct audio_client *ac, int muteflag)
2716{
2717 void *vol_cmd = NULL;
2718 void *payload = NULL;
2719 struct asm_pp_params_command *cmd = NULL;
2720 struct asm_mute_params *mute = NULL;
2721 int sz = 0;
2722 int rc = 0;
2723
2724 sz = sizeof(struct asm_pp_params_command) +
2725 + sizeof(struct asm_mute_params);
2726 vol_cmd = kzalloc(sz, GFP_KERNEL);
2727 if (vol_cmd == NULL) {
2728 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2729 rc = -EINVAL;
2730 return rc;
2731 }
2732 cmd = (struct asm_pp_params_command *)vol_cmd;
2733 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2734 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2735 cmd->payload = NULL;
2736 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2737 sizeof(struct asm_mute_params);
2738 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2739 cmd->params.param_id = MUTE_CONFIG_PARAM_ID;
2740 cmd->params.param_size = sizeof(struct asm_mute_params);
2741 cmd->params.reserved = 0;
2742
2743 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2744 mute = (struct asm_mute_params *)payload;
2745
2746 mute->muteflag = muteflag;
2747 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2748 if (rc < 0) {
2749 pr_err("%s: Mute Command failed\n", __func__);
2750 rc = -EINVAL;
2751 goto fail_cmd;
2752 }
2753
2754 rc = wait_event_timeout(ac->cmd_wait,
2755 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2756 if (!rc) {
2757 pr_err("%s: timeout in sending mute command to apr\n",
2758 __func__);
2759 rc = -EINVAL;
2760 goto fail_cmd;
2761 }
2762 rc = 0;
2763fail_cmd:
2764 kfree(vol_cmd);
2765 return rc;
2766}
2767
2768int q6asm_set_volume(struct audio_client *ac, int volume)
2769{
2770 void *vol_cmd = NULL;
2771 void *payload = NULL;
2772 struct asm_pp_params_command *cmd = NULL;
2773 struct asm_master_gain_params *mgain = NULL;
2774 int sz = 0;
2775 int rc = 0;
2776
2777 sz = sizeof(struct asm_pp_params_command) +
2778 + sizeof(struct asm_master_gain_params);
2779 vol_cmd = kzalloc(sz, GFP_KERNEL);
2780 if (vol_cmd == NULL) {
2781 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2782 rc = -EINVAL;
2783 return rc;
2784 }
2785 cmd = (struct asm_pp_params_command *)vol_cmd;
2786 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2787 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2788 cmd->payload = NULL;
2789 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2790 sizeof(struct asm_master_gain_params);
2791 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2792 cmd->params.param_id = MASTER_GAIN_PARAM_ID;
2793 cmd->params.param_size = sizeof(struct asm_master_gain_params);
2794 cmd->params.reserved = 0;
2795
2796 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2797 mgain = (struct asm_master_gain_params *)payload;
2798
2799 mgain->master_gain = volume;
2800 mgain->padding = 0x00;
2801 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2802 if (rc < 0) {
2803 pr_err("%s: Volume Command failed\n", __func__);
2804 rc = -EINVAL;
2805 goto fail_cmd;
2806 }
2807
2808 rc = wait_event_timeout(ac->cmd_wait,
2809 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2810 if (!rc) {
2811 pr_err("%s: timeout in sending volume command to apr\n",
2812 __func__);
2813 rc = -EINVAL;
2814 goto fail_cmd;
2815 }
2816 rc = 0;
2817fail_cmd:
2818 kfree(vol_cmd);
2819 return rc;
2820}
2821
2822int q6asm_set_softpause(struct audio_client *ac,
2823 struct asm_softpause_params *pause_param)
2824{
2825 void *vol_cmd = NULL;
2826 void *payload = NULL;
2827 struct asm_pp_params_command *cmd = NULL;
2828 struct asm_softpause_params *params = NULL;
2829 int sz = 0;
2830 int rc = 0;
2831
2832 sz = sizeof(struct asm_pp_params_command) +
2833 + sizeof(struct asm_softpause_params);
2834 vol_cmd = kzalloc(sz, GFP_KERNEL);
2835 if (vol_cmd == NULL) {
2836 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2837 rc = -EINVAL;
2838 return rc;
2839 }
2840 cmd = (struct asm_pp_params_command *)vol_cmd;
2841 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2842 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2843 cmd->payload = NULL;
2844 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2845 sizeof(struct asm_softpause_params);
2846 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2847 cmd->params.param_id = SOFT_PAUSE_PARAM_ID;
2848 cmd->params.param_size = sizeof(struct asm_softpause_params);
2849 cmd->params.reserved = 0;
2850
2851 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2852 params = (struct asm_softpause_params *)payload;
2853
2854 params->enable = pause_param->enable;
2855 params->period = pause_param->period;
2856 params->step = pause_param->step;
2857 params->rampingcurve = pause_param->rampingcurve;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002858 pr_debug("%s: soft Pause Command: enable = %d, period = %d, step = %d, curve = %d\n",
2859 __func__, params->enable,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002860 params->period, params->step, params->rampingcurve);
2861 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2862 if (rc < 0) {
2863 pr_err("%s: Volume Command(soft_pause) failed\n", __func__);
2864 rc = -EINVAL;
2865 goto fail_cmd;
2866 }
2867
2868 rc = wait_event_timeout(ac->cmd_wait,
2869 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2870 if (!rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002871 pr_err("%s: timeout in sending volume command(soft_pause) to apr\n",
2872 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002873 rc = -EINVAL;
2874 goto fail_cmd;
2875 }
2876 rc = 0;
2877fail_cmd:
2878 kfree(vol_cmd);
2879 return rc;
2880}
2881
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07002882int q6asm_set_softvolume(struct audio_client *ac,
2883 struct asm_softvolume_params *softvol_param)
2884{
2885 void *vol_cmd = NULL;
2886 void *payload = NULL;
2887 struct asm_pp_params_command *cmd = NULL;
2888 struct asm_softvolume_params *params = NULL;
2889 int sz = 0;
2890 int rc = 0;
2891
2892 sz = sizeof(struct asm_pp_params_command) +
2893 + sizeof(struct asm_softvolume_params);
2894 vol_cmd = kzalloc(sz, GFP_KERNEL);
2895 if (vol_cmd == NULL) {
2896 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2897 rc = -EINVAL;
2898 return rc;
2899 }
2900 cmd = (struct asm_pp_params_command *)vol_cmd;
2901 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2902 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2903 cmd->payload = NULL;
2904 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2905 sizeof(struct asm_softvolume_params);
2906 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2907 cmd->params.param_id = SOFT_VOLUME_PARAM_ID;
2908 cmd->params.param_size = sizeof(struct asm_softvolume_params);
2909 cmd->params.reserved = 0;
2910
2911 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2912 params = (struct asm_softvolume_params *)payload;
2913
2914 params->period = softvol_param->period;
2915 params->step = softvol_param->step;
2916 params->rampingcurve = softvol_param->rampingcurve;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002917 pr_debug("%s: soft Volume:opcode = %d,payload_sz =%d,module_id =%d, param_id = %d, param_sz = %d\n",
2918 __func__,
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07002919 cmd->hdr.opcode, cmd->payload_size,
2920 cmd->params.module_id, cmd->params.param_id,
2921 cmd->params.param_size);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002922 pr_debug("%s: soft Volume Command: period = %d, step = %d, curve = %d\n",
2923 __func__, params->period,
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07002924 params->step, params->rampingcurve);
2925 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2926 if (rc < 0) {
2927 pr_err("%s: Volume Command(soft_volume) failed\n", __func__);
2928 rc = -EINVAL;
2929 goto fail_cmd;
2930 }
2931
2932 rc = wait_event_timeout(ac->cmd_wait,
2933 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2934 if (!rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002935 pr_err("%s: timeout in sending volume command(soft_volume) to apr\n",
2936 __func__);
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07002937 rc = -EINVAL;
2938 goto fail_cmd;
2939 }
2940 rc = 0;
2941fail_cmd:
2942 kfree(vol_cmd);
2943 return rc;
2944}
2945
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002946int q6asm_equalizer(struct audio_client *ac, void *eq)
2947{
2948 void *eq_cmd = NULL;
2949 void *payload = NULL;
2950 struct asm_pp_params_command *cmd = NULL;
2951 struct asm_equalizer_params *equalizer = NULL;
2952 struct msm_audio_eq_stream_config *eq_params = NULL;
2953 int i = 0;
2954 int sz = 0;
2955 int rc = 0;
2956
2957 sz = sizeof(struct asm_pp_params_command) +
2958 + sizeof(struct asm_equalizer_params);
2959 eq_cmd = kzalloc(sz, GFP_KERNEL);
2960 if (eq_cmd == NULL) {
2961 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2962 rc = -EINVAL;
2963 goto fail_cmd;
2964 }
2965 eq_params = (struct msm_audio_eq_stream_config *) eq;
2966 cmd = (struct asm_pp_params_command *)eq_cmd;
2967 q6asm_add_hdr(ac, &cmd->hdr, sz, TRUE);
2968 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2969 cmd->payload = NULL;
2970 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2971 sizeof(struct asm_equalizer_params);
2972 cmd->params.module_id = EQUALIZER_MODULE_ID;
2973 cmd->params.param_id = EQUALIZER_PARAM_ID;
2974 cmd->params.param_size = sizeof(struct asm_equalizer_params);
2975 cmd->params.reserved = 0;
2976 payload = (u8 *)(eq_cmd + sizeof(struct asm_pp_params_command));
2977 equalizer = (struct asm_equalizer_params *)payload;
2978
2979 equalizer->enable = eq_params->enable;
2980 equalizer->num_bands = eq_params->num_bands;
2981 pr_debug("%s: enable:%d numbands:%d\n", __func__, eq_params->enable,
2982 eq_params->num_bands);
2983 for (i = 0; i < eq_params->num_bands; i++) {
2984 equalizer->eq_bands[i].band_idx =
2985 eq_params->eq_bands[i].band_idx;
2986 equalizer->eq_bands[i].filter_type =
2987 eq_params->eq_bands[i].filter_type;
2988 equalizer->eq_bands[i].center_freq_hz =
2989 eq_params->eq_bands[i].center_freq_hz;
2990 equalizer->eq_bands[i].filter_gain =
2991 eq_params->eq_bands[i].filter_gain;
2992 equalizer->eq_bands[i].q_factor =
2993 eq_params->eq_bands[i].q_factor;
2994 pr_debug("%s: filter_type:%u bandnum:%d\n", __func__,
2995 eq_params->eq_bands[i].filter_type, i);
2996 pr_debug("%s: center_freq_hz:%u bandnum:%d\n", __func__,
2997 eq_params->eq_bands[i].center_freq_hz, i);
2998 pr_debug("%s: filter_gain:%d bandnum:%d\n", __func__,
2999 eq_params->eq_bands[i].filter_gain, i);
3000 pr_debug("%s: q_factor:%d bandnum:%d\n", __func__,
3001 eq_params->eq_bands[i].q_factor, i);
3002 }
3003 rc = apr_send_pkt(ac->apr, (uint32_t *) eq_cmd);
3004 if (rc < 0) {
3005 pr_err("%s: Equalizer Command failed\n", __func__);
3006 rc = -EINVAL;
3007 goto fail_cmd;
3008 }
3009
3010 rc = wait_event_timeout(ac->cmd_wait,
3011 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3012 if (!rc) {
3013 pr_err("%s: timeout in sending equalizer command to apr\n",
3014 __func__);
3015 rc = -EINVAL;
3016 goto fail_cmd;
3017 }
3018 rc = 0;
3019fail_cmd:
3020 kfree(eq_cmd);
3021 return rc;
3022}
3023
3024int q6asm_read(struct audio_client *ac)
3025{
3026 struct asm_stream_cmd_read read;
3027 struct audio_buffer *ab;
3028 int dsp_buf;
3029 struct audio_port_data *port;
3030 int rc;
3031 if (!ac || ac->apr == NULL) {
3032 pr_err("APR handle NULL\n");
3033 return -EINVAL;
3034 }
3035 if (ac->io_mode == SYNC_IO_MODE) {
3036 port = &ac->port[OUT];
3037
3038 q6asm_add_hdr(ac, &read.hdr, sizeof(read), FALSE);
3039
3040 mutex_lock(&port->lock);
3041
3042 dsp_buf = port->dsp_buf;
3043 ab = &port->buf[dsp_buf];
3044
3045 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
3046 __func__,
3047 ac->session,
3048 dsp_buf,
3049 (void *)port->buf[dsp_buf].data,
3050 port->cpu_buf,
3051 (void *)port->buf[port->cpu_buf].phys);
3052
3053 read.hdr.opcode = ASM_DATA_CMD_READ;
3054 read.buf_add = ab->phys;
3055 read.buf_size = ab->size;
3056 read.uid = port->dsp_buf;
3057 read.hdr.token = port->dsp_buf;
3058
3059 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3060 mutex_unlock(&port->lock);
3061 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
3062 read.buf_add,
3063 read.hdr.token,
3064 read.uid);
3065 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3066 if (rc < 0) {
3067 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
3068 goto fail_cmd;
3069 }
3070 return 0;
3071 }
3072fail_cmd:
3073 return -EINVAL;
3074}
3075
3076int q6asm_read_nolock(struct audio_client *ac)
3077{
3078 struct asm_stream_cmd_read read;
3079 struct audio_buffer *ab;
3080 int dsp_buf;
3081 struct audio_port_data *port;
3082 int rc;
3083 if (!ac || ac->apr == NULL) {
3084 pr_err("APR handle NULL\n");
3085 return -EINVAL;
3086 }
3087 if (ac->io_mode == SYNC_IO_MODE) {
3088 port = &ac->port[OUT];
3089
3090 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3091
3092
3093 dsp_buf = port->dsp_buf;
3094 ab = &port->buf[dsp_buf];
3095
3096 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
3097 __func__,
3098 ac->session,
3099 dsp_buf,
3100 (void *)port->buf[dsp_buf].data,
3101 port->cpu_buf,
3102 (void *)port->buf[port->cpu_buf].phys);
3103
3104 read.hdr.opcode = ASM_DATA_CMD_READ;
3105 read.buf_add = ab->phys;
3106 read.buf_size = ab->size;
3107 read.uid = port->dsp_buf;
3108 read.hdr.token = port->dsp_buf;
3109
3110 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3111 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
3112 read.buf_add,
3113 read.hdr.token,
3114 read.uid);
3115 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3116 if (rc < 0) {
3117 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
3118 goto fail_cmd;
3119 }
3120 return 0;
3121 }
3122fail_cmd:
3123 return -EINVAL;
3124}
3125
3126
3127static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
3128 uint32_t pkt_size, uint32_t cmd_flg)
3129{
3130 pr_debug("session=%d pkt size=%d cmd_flg=%d\n", pkt_size, cmd_flg,
3131 ac->session);
3132 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
3133 APR_HDR_LEN(sizeof(struct apr_hdr)),\
3134 APR_PKT_VER);
3135 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
3136 hdr->src_domain = APR_DOMAIN_APPS;
3137 hdr->dest_svc = APR_SVC_ASM;
3138 hdr->dest_domain = APR_DOMAIN_ADSP;
3139 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
3140 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
3141 if (cmd_flg) {
3142 hdr->token = ac->session;
3143 atomic_set(&ac->cmd_state, 1);
3144 }
3145 hdr->pkt_size = pkt_size;
3146 return;
3147}
3148
3149int q6asm_async_write(struct audio_client *ac,
3150 struct audio_aio_write_param *param)
3151{
3152 int rc = 0;
3153 struct asm_stream_cmd_write write;
3154
3155 if (!ac || ac->apr == NULL) {
3156 pr_err("%s: APR handle NULL\n", __func__);
3157 return -EINVAL;
3158 }
3159
3160 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write), FALSE);
3161
3162 /* Pass physical address as token for AIO scheme */
3163 write.hdr.token = param->uid;
3164 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3165 write.buf_add = param->paddr;
3166 write.avail_bytes = param->len;
3167 write.uid = param->uid;
3168 write.msw_ts = param->msw_ts;
3169 write.lsw_ts = param->lsw_ts;
3170 /* Use 0xFF00 for disabling timestamps */
3171 if (param->flags == 0xFF00)
3172 write.uflags = (0x00000000 | (param->flags & 0x800000FF));
3173 else
3174 write.uflags = (0x80000000 | param->flags);
3175
3176 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3177 write.buf_add, write.avail_bytes);
3178
3179 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3180 if (rc < 0) {
3181 pr_debug("[%s] write op[0x%x]rc[%d]\n", __func__,
3182 write.hdr.opcode, rc);
3183 goto fail_cmd;
3184 }
3185 return 0;
3186fail_cmd:
3187 return -EINVAL;
3188}
3189
3190int q6asm_async_read(struct audio_client *ac,
3191 struct audio_aio_read_param *param)
3192{
3193 int rc = 0;
3194 struct asm_stream_cmd_read read;
3195
3196 if (!ac || ac->apr == NULL) {
3197 pr_err("%s: APR handle NULL\n", __func__);
3198 return -EINVAL;
3199 }
3200
3201 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3202
3203 /* Pass physical address as token for AIO scheme */
3204 read.hdr.token = param->paddr;
3205 read.hdr.opcode = ASM_DATA_CMD_READ;
3206 read.buf_add = param->paddr;
3207 read.buf_size = param->len;
3208 read.uid = param->uid;
3209
3210 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3211 read.buf_add, read.buf_size);
3212
3213 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3214 if (rc < 0) {
3215 pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
3216 read.hdr.opcode, rc);
3217 goto fail_cmd;
3218 }
3219 return 0;
3220fail_cmd:
3221 return -EINVAL;
3222}
3223
3224int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3225 uint32_t lsw_ts, uint32_t flags)
3226{
3227 int rc = 0;
3228 struct asm_stream_cmd_write write;
3229 struct audio_port_data *port;
3230 struct audio_buffer *ab;
3231 int dsp_buf = 0;
3232
3233 if (!ac || ac->apr == NULL) {
3234 pr_err("APR handle NULL\n");
3235 return -EINVAL;
3236 }
3237 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3238 if (ac->io_mode == SYNC_IO_MODE) {
3239 port = &ac->port[IN];
3240
3241 q6asm_add_hdr(ac, &write.hdr, sizeof(write),
3242 FALSE);
3243 mutex_lock(&port->lock);
3244
3245 dsp_buf = port->dsp_buf;
3246 ab = &port->buf[dsp_buf];
3247
3248 write.hdr.token = port->dsp_buf;
3249 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3250 write.buf_add = ab->phys;
3251 write.avail_bytes = len;
3252 write.uid = port->dsp_buf;
3253 write.msw_ts = msw_ts;
3254 write.lsw_ts = lsw_ts;
3255 /* Use 0xFF00 for disabling timestamps */
3256 if (flags == 0xFF00)
3257 write.uflags = (0x00000000 | (flags & 0x800000FF));
3258 else
3259 write.uflags = (0x80000000 | flags);
3260 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3261
3262 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3263 , __func__,
3264 ab->phys,
3265 write.buf_add,
3266 write.hdr.token,
3267 write.uid);
3268 mutex_unlock(&port->lock);
Rajesha Kini3498c932011-07-19 19:58:27 +05303269#ifdef CONFIG_DEBUG_FS
3270 if (out_enable_flag) {
3271 char zero_pattern[2] = {0x00, 0x00};
3272 /* If First two byte is non zero and last two byte
3273 is zero then it is warm output pattern */
3274 if ((strncmp(((char *)ab->data), zero_pattern, 2)) &&
3275 (!strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3276 do_gettimeofday(&out_warm_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003277 pr_debug("WARM:apr_send_pkt at %ld sec %ld microsec\n",
3278 out_warm_tv.tv_sec,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303279 out_warm_tv.tv_usec);
3280 pr_debug("Warm Pattern Matched");
3281 }
3282 /* If First two byte is zero and last two byte is
3283 non zero then it is cont ouput pattern */
3284 else if ((!strncmp(((char *)ab->data), zero_pattern, 2))
3285 && (strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3286 do_gettimeofday(&out_cont_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003287 pr_debug("CONT:apr_send_pkt at %ld sec %ld microsec\n",
3288 out_cont_tv.tv_sec,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303289 out_cont_tv.tv_usec);
3290 pr_debug("Cont Pattern Matched");
3291 }
3292 }
3293#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003294 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3295 if (rc < 0) {
3296 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3297 goto fail_cmd;
3298 }
3299 pr_debug("%s: WRITE SUCCESS\n", __func__);
3300 return 0;
3301 }
3302fail_cmd:
3303 return -EINVAL;
3304}
3305
3306int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3307 uint32_t lsw_ts, uint32_t flags)
3308{
3309 int rc = 0;
3310 struct asm_stream_cmd_write write;
3311 struct audio_port_data *port;
3312 struct audio_buffer *ab;
3313 int dsp_buf = 0;
3314
3315 if (!ac || ac->apr == NULL) {
3316 pr_err("APR handle NULL\n");
3317 return -EINVAL;
3318 }
3319 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3320 if (ac->io_mode == SYNC_IO_MODE) {
3321 port = &ac->port[IN];
3322
3323 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write),
3324 FALSE);
3325
3326 dsp_buf = port->dsp_buf;
3327 ab = &port->buf[dsp_buf];
3328
3329 write.hdr.token = port->dsp_buf;
3330 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3331 write.buf_add = ab->phys;
3332 write.avail_bytes = len;
3333 write.uid = port->dsp_buf;
3334 write.msw_ts = msw_ts;
3335 write.lsw_ts = lsw_ts;
3336 /* Use 0xFF00 for disabling timestamps */
3337 if (flags == 0xFF00)
3338 write.uflags = (0x00000000 | (flags & 0x800000FF));
3339 else
3340 write.uflags = (0x80000000 | flags);
3341 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3342
3343 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3344 , __func__,
3345 ab->phys,
3346 write.buf_add,
3347 write.hdr.token,
3348 write.uid);
3349
3350 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3351 if (rc < 0) {
3352 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3353 goto fail_cmd;
3354 }
3355 pr_debug("%s: WRITE SUCCESS\n", __func__);
3356 return 0;
3357 }
3358fail_cmd:
3359 return -EINVAL;
3360}
3361
3362uint64_t q6asm_get_session_time(struct audio_client *ac)
3363{
3364 struct apr_hdr hdr;
3365 int rc;
3366
3367 if (!ac || ac->apr == NULL) {
3368 pr_err("APR handle NULL\n");
3369 return -EINVAL;
3370 }
3371 q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
3372 hdr.opcode = ASM_SESSION_CMD_GET_SESSION_TIME;
3373 atomic_set(&ac->time_flag, 1);
3374
3375 pr_debug("%s: session[%d]opcode[0x%x]\n", __func__,
3376 ac->session,
3377 hdr.opcode);
3378 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3379 if (rc < 0) {
3380 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3381 goto fail_cmd;
3382 }
3383 rc = wait_event_timeout(ac->time_wait,
3384 (atomic_read(&ac->time_flag) == 0), 5*HZ);
3385 if (!rc) {
3386 pr_err("%s: timeout in getting session time from DSP\n",
3387 __func__);
3388 goto fail_cmd;
3389 }
3390 return ac->time_stamp;
3391
3392fail_cmd:
3393 return -EINVAL;
3394}
3395
3396int q6asm_cmd(struct audio_client *ac, int cmd)
3397{
3398 struct apr_hdr hdr;
3399 int rc;
3400 atomic_t *state;
3401 int cnt = 0;
3402
3403 if (!ac || ac->apr == NULL) {
3404 pr_err("APR handle NULL\n");
3405 return -EINVAL;
3406 }
3407 q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
3408 switch (cmd) {
3409 case CMD_PAUSE:
3410 pr_debug("%s:CMD_PAUSE\n", __func__);
3411 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3412 state = &ac->cmd_state;
3413 break;
3414 case CMD_FLUSH:
3415 pr_debug("%s:CMD_FLUSH\n", __func__);
3416 hdr.opcode = ASM_STREAM_CMD_FLUSH;
3417 state = &ac->cmd_state;
3418 break;
3419 case CMD_OUT_FLUSH:
3420 pr_debug("%s:CMD_OUT_FLUSH\n", __func__);
3421 hdr.opcode = ASM_STREAM_CMD_FLUSH_READBUFS;
3422 state = &ac->cmd_state;
3423 break;
3424 case CMD_EOS:
3425 pr_debug("%s:CMD_EOS\n", __func__);
3426 hdr.opcode = ASM_DATA_CMD_EOS;
3427 atomic_set(&ac->cmd_state, 0);
3428 state = &ac->cmd_state;
3429 break;
3430 case CMD_CLOSE:
3431 pr_debug("%s:CMD_CLOSE\n", __func__);
3432 hdr.opcode = ASM_STREAM_CMD_CLOSE;
3433 state = &ac->cmd_state;
3434 break;
3435 default:
3436 pr_err("Invalid format[%d]\n", cmd);
3437 goto fail_cmd;
3438 }
3439 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3440 ac->session,
3441 hdr.opcode);
3442 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3443 if (rc < 0) {
3444 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3445 goto fail_cmd;
3446 }
3447 rc = wait_event_timeout(ac->cmd_wait, (atomic_read(state) == 0), 5*HZ);
3448 if (!rc) {
3449 pr_err("timeout. waited for response opcode[0x%x]\n",
3450 hdr.opcode);
3451 goto fail_cmd;
3452 }
3453 if (cmd == CMD_FLUSH)
3454 q6asm_reset_buf_state(ac);
3455 if (cmd == CMD_CLOSE) {
3456 /* check if DSP return all buffers */
3457 if (ac->port[IN].buf) {
3458 for (cnt = 0; cnt < ac->port[IN].max_buf_cnt;
3459 cnt++) {
3460 if (ac->port[IN].buf[cnt].used == IN) {
3461 pr_debug("Write Buf[%d] not returned\n",
3462 cnt);
3463 }
3464 }
3465 }
3466 if (ac->port[OUT].buf) {
3467 for (cnt = 0; cnt < ac->port[OUT].max_buf_cnt; cnt++) {
3468 if (ac->port[OUT].buf[cnt].used == OUT) {
3469 pr_debug("Read Buf[%d] not returned\n",
3470 cnt);
3471 }
3472 }
3473 }
3474 }
3475 return 0;
3476fail_cmd:
3477 return -EINVAL;
3478}
3479
3480int q6asm_cmd_nowait(struct audio_client *ac, int cmd)
3481{
3482 struct apr_hdr hdr;
3483 int rc;
3484
3485 if (!ac || ac->apr == NULL) {
3486 pr_err("%s:APR handle NULL\n", __func__);
3487 return -EINVAL;
3488 }
3489 q6asm_add_hdr_async(ac, &hdr, sizeof(hdr), TRUE);
3490 switch (cmd) {
3491 case CMD_PAUSE:
3492 pr_debug("%s:CMD_PAUSE\n", __func__);
3493 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3494 break;
3495 case CMD_EOS:
3496 pr_debug("%s:CMD_EOS\n", __func__);
3497 hdr.opcode = ASM_DATA_CMD_EOS;
3498 break;
3499 default:
3500 pr_err("%s:Invalid format[%d]\n", __func__, cmd);
3501 goto fail_cmd;
3502 }
3503 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3504 ac->session,
3505 hdr.opcode);
3506 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3507 if (rc < 0) {
3508 pr_err("%s:Commmand 0x%x failed\n", __func__, hdr.opcode);
3509 goto fail_cmd;
3510 }
3511 return 0;
3512fail_cmd:
3513 return -EINVAL;
3514}
3515
3516static void q6asm_reset_buf_state(struct audio_client *ac)
3517{
3518 int cnt = 0;
3519 int loopcnt = 0;
3520 struct audio_port_data *port = NULL;
3521
3522 if (ac->io_mode == SYNC_IO_MODE) {
3523 mutex_lock(&ac->cmd_lock);
3524 for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
3525 port = &ac->port[loopcnt];
3526 cnt = port->max_buf_cnt - 1;
3527 port->dsp_buf = 0;
3528 port->cpu_buf = 0;
3529 while (cnt >= 0) {
3530 if (!port->buf)
3531 continue;
3532 port->buf[cnt].used = 1;
3533 cnt--;
3534 }
3535 }
3536 mutex_unlock(&ac->cmd_lock);
3537 }
3538}
3539
3540int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable)
3541{
3542 struct asm_stream_cmd_reg_tx_overflow_event tx_overflow;
3543 int rc;
3544
3545 if (!ac || ac->apr == NULL) {
3546 pr_err("APR handle NULL\n");
3547 return -EINVAL;
3548 }
3549 pr_debug("%s:session[%d]enable[%d]\n", __func__,
3550 ac->session, enable);
3551 q6asm_add_hdr(ac, &tx_overflow.hdr, sizeof(tx_overflow), TRUE);
3552
3553 tx_overflow.hdr.opcode = \
3554 ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS;
3555 /* tx overflow event: enable */
3556 tx_overflow.enable = enable;
3557
3558 rc = apr_send_pkt(ac->apr, (uint32_t *) &tx_overflow);
3559 if (rc < 0) {
3560 pr_err("tx overflow op[0x%x]rc[%d]\n", \
3561 tx_overflow.hdr.opcode, rc);
3562 goto fail_cmd;
3563 }
3564 rc = wait_event_timeout(ac->cmd_wait,
3565 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3566 if (!rc) {
3567 pr_err("timeout. waited for tx overflow\n");
3568 goto fail_cmd;
3569 }
3570 return 0;
3571fail_cmd:
3572 return -EINVAL;
3573}
3574
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003575int q6asm_get_apr_service_id(int session_id)
3576{
3577 pr_debug("%s\n", __func__);
3578
Shiv Maliyappanahallia84982a2012-01-19 15:25:04 -08003579 if (session_id < 0 || session_id > SESSION_MAX) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003580 pr_err("%s: invalid session_id = %d\n", __func__, session_id);
3581 return -EINVAL;
3582 }
3583
3584 return ((struct apr_svc *)session[session_id]->apr)->id;
3585}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003586
3587
3588static int __init q6asm_init(void)
3589{
3590 pr_debug("%s\n", __func__);
3591 init_waitqueue_head(&this_mmap.cmd_wait);
3592 memset(session, 0, sizeof(session));
Rajesha Kini3498c932011-07-19 19:58:27 +05303593#ifdef CONFIG_DEBUG_FS
3594 out_buffer = kmalloc(OUT_BUFFER_SIZE, GFP_KERNEL);
3595 out_dentry = debugfs_create_file("audio_out_latency_measurement_node",\
3596 S_IFREG | S_IRUGO | S_IWUGO,\
3597 NULL, NULL, &audio_output_latency_debug_fops);
3598 if (IS_ERR(out_dentry))
3599 pr_err("debugfs_create_file failed\n");
3600 in_buffer = kmalloc(IN_BUFFER_SIZE, GFP_KERNEL);
3601 in_dentry = debugfs_create_file("audio_in_latency_measurement_node",\
3602 S_IFREG | S_IRUGO | S_IWUGO,\
3603 NULL, NULL, &audio_input_latency_debug_fops);
3604 if (IS_ERR(in_dentry))
3605 pr_err("debugfs_create_file failed\n");
3606#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003607 return 0;
3608}
3609
3610device_initcall(q6asm_init);