blob: a80ff29e355b1c0ef151d05628ea54f0eb39ab83 [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;
1332 case FORMAT_AAC:
1333 open.format = MPEG4_AAC;
1334 break;
1335 case FORMAT_ATRAC:
1336 open.format = ATRAC;
1337 break;
1338 case FORMAT_WMA_V10PRO:
1339 open.format = WMA_V10PRO;
1340 break;
1341 case FORMAT_MAT:
1342 open.format = MAT;
1343 break;
1344 default:
1345 pr_err("%s: Invalid format[%d]\n", __func__, format);
1346 goto fail_cmd;
1347 }
1348 /*Below flag indicates the DSP that Compressed audio input
1349 stream is not IEC 61937 or IEC 60958 packetizied*/
1350 open.flags = 0x00000000;
1351 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1352 if (rc < 0) {
1353 pr_err("%s: open failed op[0x%x]rc[%d]\n", \
1354 __func__, open.hdr.opcode, rc);
1355 goto fail_cmd;
1356 }
1357 rc = wait_event_timeout(ac->cmd_wait,
1358 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1359 if (!rc) {
1360 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1361 rc);
1362 goto fail_cmd;
1363 }
1364 return 0;
1365fail_cmd:
1366 return -EINVAL;
1367}
1368
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001369int q6asm_open_write(struct audio_client *ac, uint32_t format)
1370{
1371 int rc = 0x00;
1372 struct asm_stream_cmd_open_write open;
1373
1374 if ((ac == NULL) || (ac->apr == NULL)) {
1375 pr_err("%s: APR handle NULL\n", __func__);
1376 return -EINVAL;
1377 }
1378 pr_debug("%s: session[%d] wr_format[0x%x]", __func__, ac->session,
1379 format);
1380
1381 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1382
1383 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE;
1384 open.uMode = STREAM_PRIORITY_HIGH;
1385 /* source endpoint : matrix */
1386 open.sink_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1387 open.stream_handle = 0x00;
1388
1389 open.post_proc_top = get_asm_topology();
1390 if (open.post_proc_top == 0)
1391 open.post_proc_top = DEFAULT_POPP_TOPOLOGY;
1392
1393 switch (format) {
1394 case FORMAT_LINEAR_PCM:
1395 open.format = LINEAR_PCM;
1396 break;
Kiran Kandi5e809b02012-01-31 00:24:33 -08001397 case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
1398 open.format = MULTI_CHANNEL_PCM;
1399 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001400 case FORMAT_MPEG4_AAC:
1401 open.format = MPEG4_AAC;
1402 break;
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07001403 case FORMAT_MPEG4_MULTI_AAC:
1404 open.format = MPEG4_MULTI_AAC;
1405 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001406 case FORMAT_WMA_V9:
1407 open.format = WMA_V9;
1408 break;
1409 case FORMAT_WMA_V10PRO:
1410 open.format = WMA_V10PRO;
1411 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05301412 case FORMAT_MP3:
1413 open.format = MP3;
1414 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001415 default:
1416 pr_err("%s: Invalid format[%d]\n", __func__, format);
1417 goto fail_cmd;
1418 }
1419 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1420 if (rc < 0) {
1421 pr_err("%s: open failed op[0x%x]rc[%d]\n", \
1422 __func__, open.hdr.opcode, rc);
1423 goto fail_cmd;
1424 }
1425 rc = wait_event_timeout(ac->cmd_wait,
1426 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1427 if (!rc) {
1428 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1429 rc);
1430 goto fail_cmd;
1431 }
1432 return 0;
1433fail_cmd:
1434 return -EINVAL;
1435}
1436
1437int q6asm_open_read_write(struct audio_client *ac,
1438 uint32_t rd_format,
1439 uint32_t wr_format)
1440{
1441 int rc = 0x00;
1442 struct asm_stream_cmd_open_read_write open;
1443
1444 if ((ac == NULL) || (ac->apr == NULL)) {
1445 pr_err("APR handle NULL\n");
1446 return -EINVAL;
1447 }
1448 pr_debug("%s: session[%d]", __func__, ac->session);
1449 pr_debug("wr_format[0x%x]rd_format[0x%x]",
1450 wr_format, rd_format);
1451
1452 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1453 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READWRITE;
1454
Deepa Madiregama55cbf782011-09-10 05:44:39 +05301455 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_NORMAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001456 /* source endpoint : matrix */
1457 open.post_proc_top = get_asm_topology();
1458 if (open.post_proc_top == 0)
1459 open.post_proc_top = DEFAULT_POPP_TOPOLOGY;
1460
1461 switch (wr_format) {
1462 case FORMAT_LINEAR_PCM:
1463 open.write_format = LINEAR_PCM;
1464 break;
1465 case FORMAT_MPEG4_AAC:
1466 open.write_format = MPEG4_AAC;
1467 break;
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07001468 case FORMAT_MPEG4_MULTI_AAC:
1469 open.write_format = MPEG4_MULTI_AAC;
1470 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001471 case FORMAT_WMA_V9:
1472 open.write_format = WMA_V9;
1473 break;
1474 case FORMAT_WMA_V10PRO:
1475 open.write_format = WMA_V10PRO;
1476 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301477 case FORMAT_AMRNB:
1478 open.write_format = AMRNB_FS;
1479 break;
1480 case FORMAT_AMRWB:
1481 open.write_format = AMRWB_FS;
1482 break;
1483 case FORMAT_V13K:
1484 open.write_format = V13K_FS;
1485 break;
1486 case FORMAT_EVRC:
1487 open.write_format = EVRC_FS;
1488 break;
1489 case FORMAT_EVRCB:
1490 open.write_format = EVRCB_FS;
1491 break;
1492 case FORMAT_EVRCWB:
1493 open.write_format = EVRCWB_FS;
1494 break;
1495 case FORMAT_MP3:
1496 open.write_format = MP3;
1497 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001498 default:
1499 pr_err("Invalid format[%d]\n", wr_format);
1500 goto fail_cmd;
1501 }
1502
1503 switch (rd_format) {
1504 case FORMAT_LINEAR_PCM:
1505 open.read_format = LINEAR_PCM;
1506 break;
1507 case FORMAT_MPEG4_AAC:
1508 open.read_format = MPEG4_AAC;
1509 break;
1510 case FORMAT_V13K:
1511 open.read_format = V13K_FS;
1512 break;
1513 case FORMAT_EVRC:
1514 open.read_format = EVRC_FS;
1515 break;
1516 case FORMAT_AMRNB:
1517 open.read_format = AMRNB_FS;
1518 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301519 case FORMAT_AMRWB:
1520 open.read_format = AMRWB_FS;
1521 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001522 default:
1523 pr_err("Invalid format[%d]\n", rd_format);
1524 goto fail_cmd;
1525 }
1526 pr_debug("%s:rdformat[0x%x]wrformat[0x%x]\n", __func__,
1527 open.read_format, open.write_format);
1528
1529 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1530 if (rc < 0) {
1531 pr_err("open failed op[0x%x]rc[%d]\n", \
1532 open.hdr.opcode, rc);
1533 goto fail_cmd;
1534 }
1535 rc = wait_event_timeout(ac->cmd_wait,
1536 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1537 if (!rc) {
1538 pr_err("timeout. waited for OPEN_WRITE rc[%d]\n", rc);
1539 goto fail_cmd;
1540 }
1541 return 0;
1542fail_cmd:
1543 return -EINVAL;
1544}
1545
1546int q6asm_run(struct audio_client *ac, uint32_t flags,
1547 uint32_t msw_ts, uint32_t lsw_ts)
1548{
1549 struct asm_stream_cmd_run run;
1550 int rc;
1551 if (!ac || ac->apr == NULL) {
1552 pr_err("APR handle NULL\n");
1553 return -EINVAL;
1554 }
1555 pr_debug("%s session[%d]", __func__, ac->session);
1556 q6asm_add_hdr(ac, &run.hdr, sizeof(run), TRUE);
1557
1558 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1559 run.flags = flags;
1560 run.msw_ts = msw_ts;
1561 run.lsw_ts = lsw_ts;
Rajesha Kini3498c932011-07-19 19:58:27 +05301562#ifdef CONFIG_DEBUG_FS
1563 if (out_enable_flag) {
1564 do_gettimeofday(&out_cold_tv);
1565 pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",\
1566 out_cold_tv.tv_sec, out_cold_tv.tv_usec);
1567 }
1568#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001569 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1570 if (rc < 0) {
1571 pr_err("Commmand run failed[%d]", rc);
1572 goto fail_cmd;
1573 }
1574
1575 rc = wait_event_timeout(ac->cmd_wait,
1576 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1577 if (!rc) {
1578 pr_err("timeout. waited for run success rc[%d]", rc);
1579 goto fail_cmd;
1580 }
1581
1582 return 0;
1583fail_cmd:
1584 return -EINVAL;
1585}
1586
1587int q6asm_run_nowait(struct audio_client *ac, uint32_t flags,
1588 uint32_t msw_ts, uint32_t lsw_ts)
1589{
1590 struct asm_stream_cmd_run run;
1591 int rc;
1592 if (!ac || ac->apr == NULL) {
1593 pr_err("%s:APR handle NULL\n", __func__);
1594 return -EINVAL;
1595 }
1596 pr_debug("session[%d]", ac->session);
1597 q6asm_add_hdr_async(ac, &run.hdr, sizeof(run), TRUE);
1598
1599 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1600 run.flags = flags;
1601 run.msw_ts = msw_ts;
1602 run.lsw_ts = lsw_ts;
1603
1604 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1605 if (rc < 0) {
1606 pr_err("%s:Commmand run failed[%d]", __func__, rc);
1607 return -EINVAL;
1608 }
1609 return 0;
1610}
1611
1612
1613int q6asm_enc_cfg_blk_aac(struct audio_client *ac,
1614 uint32_t frames_per_buf,
1615 uint32_t sample_rate, uint32_t channels,
1616 uint32_t bit_rate, uint32_t mode, uint32_t format)
1617{
1618 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1619 int rc = 0;
1620
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001621 pr_debug("%s:session[%d]frames[%d]SR[%d]ch[%d]bitrate[%d]mode[%d] format[%d]",
1622 __func__, ac->session, frames_per_buf,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001623 sample_rate, channels, bit_rate, mode, format);
1624
1625 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1626
1627 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1628 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1629 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1630 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1631 enc_cfg.enc_blk.format_id = MPEG4_AAC;
1632 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_aac_read_cfg);
1633 enc_cfg.enc_blk.cfg.aac.bitrate = bit_rate;
1634 enc_cfg.enc_blk.cfg.aac.enc_mode = mode;
1635 enc_cfg.enc_blk.cfg.aac.format = format;
1636 enc_cfg.enc_blk.cfg.aac.ch_cfg = channels;
1637 enc_cfg.enc_blk.cfg.aac.sample_rate = sample_rate;
1638
1639 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1640 if (rc < 0) {
1641 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1642 rc = -EINVAL;
1643 goto fail_cmd;
1644 }
1645 rc = wait_event_timeout(ac->cmd_wait,
1646 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1647 if (!rc) {
1648 pr_err("timeout. waited for FORMAT_UPDATE\n");
1649 goto fail_cmd;
1650 }
1651 return 0;
1652fail_cmd:
1653 return -EINVAL;
1654}
1655
1656int q6asm_enc_cfg_blk_pcm(struct audio_client *ac,
1657 uint32_t rate, uint32_t channels)
1658{
1659 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1660
1661 int rc = 0;
1662
1663 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1664 ac->session, rate, channels);
1665
1666 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1667
1668 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1669 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1670 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1671 enc_cfg.enc_blk.frames_per_buf = 1;
1672 enc_cfg.enc_blk.format_id = LINEAR_PCM;
1673 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg);
1674 enc_cfg.enc_blk.cfg.pcm.ch_cfg = channels;
1675 enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16;
1676 enc_cfg.enc_blk.cfg.pcm.sample_rate = rate;
1677 enc_cfg.enc_blk.cfg.pcm.is_signed = 1;
1678 enc_cfg.enc_blk.cfg.pcm.interleaved = 1;
1679
1680 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1681 if (rc < 0) {
1682 pr_err("Comamnd open failed\n");
1683 rc = -EINVAL;
1684 goto fail_cmd;
1685 }
1686 rc = wait_event_timeout(ac->cmd_wait,
1687 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1688 if (!rc) {
1689 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1690 goto fail_cmd;
1691 }
1692 return 0;
1693fail_cmd:
1694 return -EINVAL;
1695}
1696
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001697int q6asm_enc_cfg_blk_pcm_native(struct audio_client *ac,
1698 uint32_t rate, uint32_t channels)
1699{
1700 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1701
1702 int rc = 0;
1703
1704 pr_debug("%s: Session %d, rate = %d, channels = %d, setting the rate and channels to 0 for native\n",
1705 __func__, ac->session, rate, channels);
1706
1707 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1708
1709 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1710 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1711 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1712 enc_cfg.enc_blk.frames_per_buf = 1;
1713 enc_cfg.enc_blk.format_id = LINEAR_PCM;
1714 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg);
1715 enc_cfg.enc_blk.cfg.pcm.ch_cfg = 0;/*channels;*/
1716 enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16;
1717 enc_cfg.enc_blk.cfg.pcm.sample_rate = 0;/*rate;*/
1718 enc_cfg.enc_blk.cfg.pcm.is_signed = 1;
1719 enc_cfg.enc_blk.cfg.pcm.interleaved = 1;
1720
1721 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1722 if (rc < 0) {
1723 pr_err("Comamnd open failed\n");
1724 rc = -EINVAL;
1725 goto fail_cmd;
1726 }
1727 rc = wait_event_timeout(ac->cmd_wait,
1728 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1729 if (!rc) {
1730 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1731 goto fail_cmd;
1732 }
1733 return 0;
1734fail_cmd:
1735 return -EINVAL;
1736}
1737
Mingming Yin647e9ea2012-03-17 19:56:10 -07001738int q6asm_enc_cfg_blk_multi_ch_pcm(struct audio_client *ac,
1739 uint32_t rate, uint32_t channels)
1740{
1741 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1742
1743 int rc = 0;
1744
1745 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1746 ac->session, rate, channels);
1747
1748 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1749
1750 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1751 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1752 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1753 enc_cfg.enc_blk.frames_per_buf = 1;
1754 enc_cfg.enc_blk.format_id = MULTI_CHANNEL_PCM;
1755 enc_cfg.enc_blk.cfg_size =
1756 sizeof(struct asm_multi_channel_pcm_fmt_blk);
1757 enc_cfg.enc_blk.cfg.mpcm.num_channels = channels;
1758 enc_cfg.enc_blk.cfg.mpcm.bits_per_sample = 16;
1759 enc_cfg.enc_blk.cfg.mpcm.sample_rate = rate;
1760 enc_cfg.enc_blk.cfg.mpcm.is_signed = 1;
1761 enc_cfg.enc_blk.cfg.mpcm.is_interleaved = 1;
1762 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1763 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1764 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_RB;
1765 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_LB;
1766 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1767 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1768 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1769 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1770
1771 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1772 if (rc < 0) {
1773 pr_err("Comamnd open failed\n");
1774 rc = -EINVAL;
1775 goto fail_cmd;
1776 }
1777 rc = wait_event_timeout(ac->cmd_wait,
1778 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1779 if (!rc) {
1780 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1781 goto fail_cmd;
1782 }
1783 return 0;
1784fail_cmd:
1785 return -EINVAL;
1786}
1787
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001788int q6asm_enable_sbrps(struct audio_client *ac,
1789 uint32_t sbr_ps_enable)
1790{
1791 struct asm_stream_cmd_encdec_sbr sbrps;
1792
1793 int rc = 0;
1794
1795 pr_debug("%s: Session %d\n", __func__, ac->session);
1796
1797 q6asm_add_hdr(ac, &sbrps.hdr, sizeof(sbrps), TRUE);
1798
1799 sbrps.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1800 sbrps.param_id = ASM_ENABLE_SBR_PS;
1801 sbrps.param_size = sizeof(struct asm_sbr_ps);
1802 sbrps.sbr_ps.enable = sbr_ps_enable;
1803
1804 rc = apr_send_pkt(ac->apr, (uint32_t *) &sbrps);
1805 if (rc < 0) {
1806 pr_err("Command opcode[0x%x]paramid[0x%x] failed\n",
1807 ASM_STREAM_CMD_SET_ENCDEC_PARAM,
1808 ASM_ENABLE_SBR_PS);
1809 rc = -EINVAL;
1810 goto fail_cmd;
1811 }
1812 rc = wait_event_timeout(ac->cmd_wait,
1813 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1814 if (!rc) {
1815 pr_err("timeout opcode[0x%x] ", sbrps.hdr.opcode);
1816 goto fail_cmd;
1817 }
1818 return 0;
1819fail_cmd:
1820 return -EINVAL;
1821}
1822
Swaminathan Sathappan70765cd2011-07-19 18:42:47 -07001823int q6asm_cfg_dual_mono_aac(struct audio_client *ac,
1824 uint16_t sce_left, uint16_t sce_right)
1825{
1826 struct asm_stream_cmd_encdec_dualmono dual_mono;
1827
1828 int rc = 0;
1829
1830 pr_debug("%s: Session %d, sce_left = %d, sce_right = %d\n",
1831 __func__, ac->session, sce_left, sce_right);
1832
1833 q6asm_add_hdr(ac, &dual_mono.hdr, sizeof(dual_mono), TRUE);
1834
1835 dual_mono.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1836 dual_mono.param_id = ASM_CONFIGURE_DUAL_MONO;
1837 dual_mono.param_size = sizeof(struct asm_dual_mono);
1838 dual_mono.channel_map.sce_left = sce_left;
1839 dual_mono.channel_map.sce_right = sce_right;
1840
1841 rc = apr_send_pkt(ac->apr, (uint32_t *) &dual_mono);
1842 if (rc < 0) {
1843 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
1844 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
1845 ASM_CONFIGURE_DUAL_MONO);
1846 rc = -EINVAL;
1847 goto fail_cmd;
1848 }
1849 rc = wait_event_timeout(ac->cmd_wait,
1850 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1851 if (!rc) {
1852 pr_err("%s:timeout opcode[0x%x]\n", __func__,
1853 dual_mono.hdr.opcode);
1854 goto fail_cmd;
1855 }
1856 return 0;
1857fail_cmd:
1858 return -EINVAL;
1859}
1860
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07001861int q6asm_set_encdec_chan_map(struct audio_client *ac,
1862 uint32_t num_channels)
1863{
1864 struct asm_stream_cmd_encdec_channelmap chan_map;
1865 u8 *channel_mapping;
1866
1867 int rc = 0;
1868
1869 pr_debug("%s: Session %d, num_channels = %d\n",
1870 __func__, ac->session, num_channels);
1871
1872 q6asm_add_hdr(ac, &chan_map.hdr, sizeof(chan_map), TRUE);
1873
1874 chan_map.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1875 chan_map.param_id = ASM_ENCDEC_DEC_CHAN_MAP;
1876 chan_map.param_size = sizeof(struct asm_dec_chan_map);
1877 chan_map.chan_map.num_channels = num_channels;
1878
1879 channel_mapping =
1880 chan_map.chan_map.channel_mapping;
1881
1882 memset(channel_mapping, PCM_CHANNEL_NULL, MAX_CHAN_MAP_CHANNELS);
1883 if (num_channels == 1) {
1884 channel_mapping[0] = PCM_CHANNEL_FL;
1885 } else if (num_channels == 2) {
1886 channel_mapping[0] = PCM_CHANNEL_FL;
1887 channel_mapping[1] = PCM_CHANNEL_FR;
1888 } else if (num_channels == 6) {
1889 channel_mapping[0] = PCM_CHANNEL_FC;
1890 channel_mapping[1] = PCM_CHANNEL_FL;
1891 channel_mapping[2] = PCM_CHANNEL_FR;
1892 channel_mapping[3] = PCM_CHANNEL_LB;
1893 channel_mapping[4] = PCM_CHANNEL_RB;
1894 channel_mapping[5] = PCM_CHANNEL_LFE;
1895 } else {
1896 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
1897 num_channels);
1898 rc = -EINVAL;
1899 goto fail_cmd;
1900 }
1901
1902 rc = apr_send_pkt(ac->apr, (uint32_t *) &chan_map);
1903 if (rc < 0) {
1904 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
1905 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
1906 ASM_ENCDEC_DEC_CHAN_MAP);
1907 goto fail_cmd;
1908 }
1909 rc = wait_event_timeout(ac->cmd_wait,
1910 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1911 if (!rc) {
1912 pr_err("%s:timeout opcode[0x%x]\n", __func__,
1913 chan_map.hdr.opcode);
1914 rc = -ETIMEDOUT;
1915 goto fail_cmd;
1916 }
1917 return 0;
1918fail_cmd:
1919 return rc;
1920}
1921
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001922int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf,
1923 uint16_t min_rate, uint16_t max_rate,
1924 uint16_t reduced_rate_level, uint16_t rate_modulation_cmd)
1925{
1926 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1927 int rc = 0;
1928
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001929 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]",
1930 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001931 ac->session, frames_per_buf, min_rate, max_rate,
1932 reduced_rate_level, rate_modulation_cmd);
1933
1934 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1935
1936 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1937
1938 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1939 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1940
1941 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1942 enc_cfg.enc_blk.format_id = V13K_FS;
1943 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_qcelp13_read_cfg);
1944 enc_cfg.enc_blk.cfg.qcelp13.min_rate = min_rate;
1945 enc_cfg.enc_blk.cfg.qcelp13.max_rate = max_rate;
1946 enc_cfg.enc_blk.cfg.qcelp13.reduced_rate_level = reduced_rate_level;
1947 enc_cfg.enc_blk.cfg.qcelp13.rate_modulation_cmd = rate_modulation_cmd;
1948
1949 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1950 if (rc < 0) {
1951 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1952 goto fail_cmd;
1953 }
1954 rc = wait_event_timeout(ac->cmd_wait,
1955 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1956 if (!rc) {
1957 pr_err("timeout. waited for FORMAT_UPDATE\n");
1958 goto fail_cmd;
1959 }
1960 return 0;
1961fail_cmd:
1962 return -EINVAL;
1963}
1964
1965int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf,
1966 uint16_t min_rate, uint16_t max_rate,
1967 uint16_t rate_modulation_cmd)
1968{
1969 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1970 int rc = 0;
1971
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001972 pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] rate_modulation_cmd[0x%4x]",
1973 __func__, ac->session,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001974 frames_per_buf, min_rate, max_rate, rate_modulation_cmd);
1975
1976 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1977
1978 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1979
1980 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1981 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1982
1983 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1984 enc_cfg.enc_blk.format_id = EVRC_FS;
1985 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_evrc_read_cfg);
1986 enc_cfg.enc_blk.cfg.evrc.min_rate = min_rate;
1987 enc_cfg.enc_blk.cfg.evrc.max_rate = max_rate;
1988 enc_cfg.enc_blk.cfg.evrc.rate_modulation_cmd = rate_modulation_cmd;
1989 enc_cfg.enc_blk.cfg.evrc.reserved = 0;
1990
1991 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1992 if (rc < 0) {
1993 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1994 goto fail_cmd;
1995 }
1996 rc = wait_event_timeout(ac->cmd_wait,
1997 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1998 if (!rc) {
1999 pr_err("timeout. waited for FORMAT_UPDATE\n");
2000 goto fail_cmd;
2001 }
2002 return 0;
2003fail_cmd:
2004 return -EINVAL;
2005}
2006
2007int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf,
2008 uint16_t band_mode, uint16_t dtx_enable)
2009{
2010 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2011 int rc = 0;
2012
2013 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
2014 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
2015
2016 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2017
2018 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2019
2020 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2021 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2022
2023 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2024 enc_cfg.enc_blk.format_id = AMRNB_FS;
2025 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrnb_read_cfg);
2026 enc_cfg.enc_blk.cfg.amrnb.mode = band_mode;
2027 enc_cfg.enc_blk.cfg.amrnb.dtx_mode = dtx_enable;
2028
2029 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2030 if (rc < 0) {
2031 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2032 goto fail_cmd;
2033 }
2034 rc = wait_event_timeout(ac->cmd_wait,
2035 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2036 if (!rc) {
2037 pr_err("timeout. waited for FORMAT_UPDATE\n");
2038 goto fail_cmd;
2039 }
2040 return 0;
2041fail_cmd:
2042 return -EINVAL;
2043}
2044
Alex Wong2caeecc2011-10-28 10:52:15 +05302045int q6asm_enc_cfg_blk_amrwb(struct audio_client *ac, uint32_t frames_per_buf,
2046 uint16_t band_mode, uint16_t dtx_enable)
2047{
2048 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2049 int rc = 0;
2050
2051 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
2052 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
2053
2054 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2055
2056 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2057
2058 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2059 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2060
2061 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2062 enc_cfg.enc_blk.format_id = AMRWB_FS;
2063 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrwb_read_cfg);
2064 enc_cfg.enc_blk.cfg.amrwb.mode = band_mode;
2065 enc_cfg.enc_blk.cfg.amrwb.dtx_mode = dtx_enable;
2066
2067 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2068 if (rc < 0) {
2069 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2070 goto fail_cmd;
2071 }
2072 rc = wait_event_timeout(ac->cmd_wait,
2073 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2074 if (!rc) {
2075 pr_err("timeout. waited for FORMAT_UPDATE\n");
2076 goto fail_cmd;
2077 }
2078 return 0;
2079fail_cmd:
2080 return -EINVAL;
2081}
2082
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002083int q6asm_media_format_block_pcm(struct audio_client *ac,
2084 uint32_t rate, uint32_t channels)
2085{
2086 struct asm_stream_media_format_update fmt;
2087 int rc = 0;
2088
2089 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
2090 channels);
2091
2092 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2093
2094 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2095
2096 fmt.format = LINEAR_PCM;
2097 fmt.cfg_size = sizeof(struct asm_pcm_cfg);
2098 fmt.write_cfg.pcm_cfg.ch_cfg = channels;
2099 fmt.write_cfg.pcm_cfg.bits_per_sample = 16;
2100 fmt.write_cfg.pcm_cfg.sample_rate = rate;
2101 fmt.write_cfg.pcm_cfg.is_signed = 1;
2102 fmt.write_cfg.pcm_cfg.interleaved = 1;
2103
2104 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2105 if (rc < 0) {
2106 pr_err("%s:Comamnd open failed\n", __func__);
2107 goto fail_cmd;
2108 }
2109 rc = wait_event_timeout(ac->cmd_wait,
2110 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2111 if (!rc) {
2112 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2113 goto fail_cmd;
2114 }
2115 return 0;
2116fail_cmd:
2117 return -EINVAL;
2118}
2119
Kiran Kandi5e809b02012-01-31 00:24:33 -08002120int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
2121 uint32_t rate, uint32_t channels)
2122{
2123 struct asm_stream_media_format_update fmt;
2124 u8 *channel_mapping;
2125 int rc = 0;
2126
2127 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
2128 channels);
2129
2130 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2131
2132 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2133
2134 fmt.format = MULTI_CHANNEL_PCM;
2135 fmt.cfg_size = sizeof(struct asm_multi_channel_pcm_fmt_blk);
2136 fmt.write_cfg.multi_ch_pcm_cfg.num_channels = channels;
2137 fmt.write_cfg.multi_ch_pcm_cfg.bits_per_sample = 16;
2138 fmt.write_cfg.multi_ch_pcm_cfg.sample_rate = rate;
2139 fmt.write_cfg.multi_ch_pcm_cfg.is_signed = 1;
2140 fmt.write_cfg.multi_ch_pcm_cfg.is_interleaved = 1;
2141 channel_mapping =
2142 fmt.write_cfg.multi_ch_pcm_cfg.channel_mapping;
2143
2144 memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
2145
2146 if (channels == 1) {
2147 channel_mapping[0] = PCM_CHANNEL_FL;
2148 } else if (channels == 2) {
2149 channel_mapping[0] = PCM_CHANNEL_FL;
2150 channel_mapping[1] = PCM_CHANNEL_FR;
2151 } else if (channels == 6) {
2152 channel_mapping[0] = PCM_CHANNEL_FC;
2153 channel_mapping[1] = PCM_CHANNEL_FL;
2154 channel_mapping[2] = PCM_CHANNEL_FR;
2155 channel_mapping[3] = PCM_CHANNEL_LB;
2156 channel_mapping[4] = PCM_CHANNEL_RB;
2157 channel_mapping[5] = PCM_CHANNEL_LFE;
2158 } else {
2159 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
2160 channels);
2161 return -EINVAL;
2162 }
2163
2164 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2165 if (rc < 0) {
2166 pr_err("%s:Comamnd open failed\n", __func__);
2167 goto fail_cmd;
2168 }
2169 rc = wait_event_timeout(ac->cmd_wait,
2170 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2171 if (!rc) {
2172 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2173 goto fail_cmd;
2174 }
2175 return 0;
2176fail_cmd:
2177 return -EINVAL;
2178}
2179
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002180int q6asm_media_format_block_aac(struct audio_client *ac,
2181 struct asm_aac_cfg *cfg)
2182{
2183 struct asm_stream_media_format_update fmt;
2184 int rc = 0;
2185
2186 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2187 cfg->sample_rate, cfg->ch_cfg);
2188
2189 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2190
2191 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2192
2193 fmt.format = MPEG4_AAC;
2194 fmt.cfg_size = sizeof(struct asm_aac_cfg);
2195 fmt.write_cfg.aac_cfg.format = cfg->format;
2196 fmt.write_cfg.aac_cfg.aot = cfg->aot;
2197 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
2198 fmt.write_cfg.aac_cfg.section_data_resilience =
2199 cfg->section_data_resilience;
2200 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2201 cfg->scalefactor_data_resilience;
2202 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2203 cfg->spectral_data_resilience;
2204 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2205 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2206 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2207 __func__, fmt.format, fmt.cfg_size,
2208 fmt.write_cfg.aac_cfg.format,
2209 fmt.write_cfg.aac_cfg.aot,
2210 fmt.write_cfg.aac_cfg.ch_cfg,
2211 fmt.write_cfg.aac_cfg.sample_rate);
2212 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2213 if (rc < 0) {
2214 pr_err("%s:Comamnd open failed\n", __func__);
2215 goto fail_cmd;
2216 }
2217 rc = wait_event_timeout(ac->cmd_wait,
2218 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2219 if (!rc) {
2220 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2221 goto fail_cmd;
2222 }
2223 return 0;
2224fail_cmd:
2225 return -EINVAL;
2226}
2227
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07002228
2229int q6asm_media_format_block_multi_aac(struct audio_client *ac,
2230 struct asm_aac_cfg *cfg)
2231{
2232 struct asm_stream_media_format_update fmt;
2233 int rc = 0;
2234
2235 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2236 cfg->sample_rate, cfg->ch_cfg);
2237
2238 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2239
2240 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2241
2242 fmt.format = MPEG4_MULTI_AAC;
2243 fmt.cfg_size = sizeof(struct asm_aac_cfg);
2244 fmt.write_cfg.aac_cfg.format = cfg->format;
2245 fmt.write_cfg.aac_cfg.aot = cfg->aot;
2246 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
2247 fmt.write_cfg.aac_cfg.section_data_resilience =
2248 cfg->section_data_resilience;
2249 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2250 cfg->scalefactor_data_resilience;
2251 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2252 cfg->spectral_data_resilience;
2253 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2254 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2255 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2256 __func__, fmt.format, fmt.cfg_size,
2257 fmt.write_cfg.aac_cfg.format,
2258 fmt.write_cfg.aac_cfg.aot,
2259 fmt.write_cfg.aac_cfg.ch_cfg,
2260 fmt.write_cfg.aac_cfg.sample_rate);
2261 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2262 if (rc < 0) {
2263 pr_err("%s:Comamnd open failed\n", __func__);
2264 goto fail_cmd;
2265 }
2266 rc = wait_event_timeout(ac->cmd_wait,
2267 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2268 if (!rc) {
2269 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2270 goto fail_cmd;
2271 }
2272 return 0;
2273fail_cmd:
2274 return -EINVAL;
2275}
2276
2277
Alex Wong2caeecc2011-10-28 10:52:15 +05302278
2279int q6asm_media_format_block(struct audio_client *ac, uint32_t format)
2280{
2281
2282 struct asm_stream_media_format_update fmt;
2283 int rc = 0;
2284
2285 pr_debug("%s:session[%d] format[0x%x]\n", __func__,
2286 ac->session, format);
2287
2288 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2289 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302290 switch (format) {
2291 case FORMAT_V13K:
2292 fmt.format = V13K_FS;
2293 break;
2294 case FORMAT_EVRC:
2295 fmt.format = EVRC_FS;
2296 break;
2297 case FORMAT_AMRWB:
2298 fmt.format = AMRWB_FS;
2299 break;
2300 case FORMAT_AMRNB:
2301 fmt.format = AMRNB_FS;
2302 break;
2303 case FORMAT_MP3:
2304 fmt.format = MP3;
2305 break;
2306 default:
2307 pr_err("Invalid format[%d]\n", format);
2308 goto fail_cmd;
2309 }
Alex Wong2caeecc2011-10-28 10:52:15 +05302310 fmt.cfg_size = 0;
2311
2312 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2313 if (rc < 0) {
2314 pr_err("%s:Comamnd open failed\n", __func__);
2315 goto fail_cmd;
2316 }
2317 rc = wait_event_timeout(ac->cmd_wait,
2318 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2319 if (!rc) {
2320 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2321 goto fail_cmd;
2322 }
2323 return 0;
2324fail_cmd:
2325 return -EINVAL;
2326}
2327
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002328int q6asm_media_format_block_wma(struct audio_client *ac,
2329 void *cfg)
2330{
2331 struct asm_stream_media_format_update fmt;
2332 struct asm_wma_cfg *wma_cfg = (struct asm_wma_cfg *)cfg;
2333 int rc = 0;
2334
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002335 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 -07002336 ac->session, wma_cfg->format_tag, wma_cfg->sample_rate,
2337 wma_cfg->ch_cfg, wma_cfg->avg_bytes_per_sec,
2338 wma_cfg->block_align, wma_cfg->valid_bits_per_sample,
2339 wma_cfg->ch_mask, wma_cfg->encode_opt);
2340
2341 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2342
2343 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2344
2345 fmt.format = WMA_V9;
2346 fmt.cfg_size = sizeof(struct asm_wma_cfg);
2347 fmt.write_cfg.wma_cfg.format_tag = wma_cfg->format_tag;
2348 fmt.write_cfg.wma_cfg.ch_cfg = wma_cfg->ch_cfg;
2349 fmt.write_cfg.wma_cfg.sample_rate = wma_cfg->sample_rate;
2350 fmt.write_cfg.wma_cfg.avg_bytes_per_sec = wma_cfg->avg_bytes_per_sec;
2351 fmt.write_cfg.wma_cfg.block_align = wma_cfg->block_align;
2352 fmt.write_cfg.wma_cfg.valid_bits_per_sample =
2353 wma_cfg->valid_bits_per_sample;
2354 fmt.write_cfg.wma_cfg.ch_mask = wma_cfg->ch_mask;
2355 fmt.write_cfg.wma_cfg.encode_opt = wma_cfg->encode_opt;
2356 fmt.write_cfg.wma_cfg.adv_encode_opt = 0;
2357 fmt.write_cfg.wma_cfg.adv_encode_opt2 = 0;
2358 fmt.write_cfg.wma_cfg.drc_peak_ref = 0;
2359 fmt.write_cfg.wma_cfg.drc_peak_target = 0;
2360 fmt.write_cfg.wma_cfg.drc_ave_ref = 0;
2361 fmt.write_cfg.wma_cfg.drc_ave_target = 0;
2362
2363 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2364 if (rc < 0) {
2365 pr_err("%s:Comamnd open failed\n", __func__);
2366 goto fail_cmd;
2367 }
2368 rc = wait_event_timeout(ac->cmd_wait,
2369 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2370 if (!rc) {
2371 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2372 goto fail_cmd;
2373 }
2374 return 0;
2375fail_cmd:
2376 return -EINVAL;
2377}
2378
2379int q6asm_media_format_block_wmapro(struct audio_client *ac,
2380 void *cfg)
2381{
2382 struct asm_stream_media_format_update fmt;
2383 struct asm_wmapro_cfg *wmapro_cfg = (struct asm_wmapro_cfg *)cfg;
2384 int rc = 0;
2385
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002386 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 -07002387 ac->session, wmapro_cfg->format_tag, wmapro_cfg->sample_rate,
2388 wmapro_cfg->ch_cfg, wmapro_cfg->avg_bytes_per_sec,
2389 wmapro_cfg->block_align, wmapro_cfg->valid_bits_per_sample,
2390 wmapro_cfg->ch_mask, wmapro_cfg->encode_opt,
2391 wmapro_cfg->adv_encode_opt, wmapro_cfg->adv_encode_opt2);
2392
2393 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2394
2395 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2396
2397 fmt.format = WMA_V10PRO;
2398 fmt.cfg_size = sizeof(struct asm_wmapro_cfg);
2399 fmt.write_cfg.wmapro_cfg.format_tag = wmapro_cfg->format_tag;
2400 fmt.write_cfg.wmapro_cfg.ch_cfg = wmapro_cfg->ch_cfg;
2401 fmt.write_cfg.wmapro_cfg.sample_rate = wmapro_cfg->sample_rate;
2402 fmt.write_cfg.wmapro_cfg.avg_bytes_per_sec =
2403 wmapro_cfg->avg_bytes_per_sec;
2404 fmt.write_cfg.wmapro_cfg.block_align = wmapro_cfg->block_align;
2405 fmt.write_cfg.wmapro_cfg.valid_bits_per_sample =
2406 wmapro_cfg->valid_bits_per_sample;
2407 fmt.write_cfg.wmapro_cfg.ch_mask = wmapro_cfg->ch_mask;
2408 fmt.write_cfg.wmapro_cfg.encode_opt = wmapro_cfg->encode_opt;
2409 fmt.write_cfg.wmapro_cfg.adv_encode_opt = wmapro_cfg->adv_encode_opt;
2410 fmt.write_cfg.wmapro_cfg.adv_encode_opt2 = wmapro_cfg->adv_encode_opt2;
2411 fmt.write_cfg.wmapro_cfg.drc_peak_ref = 0;
2412 fmt.write_cfg.wmapro_cfg.drc_peak_target = 0;
2413 fmt.write_cfg.wmapro_cfg.drc_ave_ref = 0;
2414 fmt.write_cfg.wmapro_cfg.drc_ave_target = 0;
2415
2416 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2417 if (rc < 0) {
2418 pr_err("%s:Comamnd open failed\n", __func__);
2419 goto fail_cmd;
2420 }
2421 rc = wait_event_timeout(ac->cmd_wait,
2422 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2423 if (!rc) {
2424 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2425 goto fail_cmd;
2426 }
2427 return 0;
2428fail_cmd:
2429 return -EINVAL;
2430}
2431
2432int q6asm_memory_map(struct audio_client *ac, uint32_t buf_add, int dir,
2433 uint32_t bufsz, uint32_t bufcnt)
2434{
2435 struct asm_stream_cmd_memory_map mem_map;
2436 int rc = 0;
2437
2438 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2439 pr_err("APR handle NULL\n");
2440 return -EINVAL;
2441 }
2442
2443 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2444
2445 mem_map.hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP;
2446
2447 mem_map.buf_add = buf_add;
2448 mem_map.buf_size = bufsz * bufcnt;
2449 mem_map.mempool_id = 0; /* EBI */
2450 mem_map.reserved = 0;
2451
2452 q6asm_add_mmaphdr(&mem_map.hdr,
2453 sizeof(struct asm_stream_cmd_memory_map), TRUE);
2454
2455 pr_debug("buf add[%x] buf_add_parameter[%x]\n",
2456 mem_map.buf_add, buf_add);
2457
2458 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_map);
2459 if (rc < 0) {
2460 pr_err("mem_map op[0x%x]rc[%d]\n",
2461 mem_map.hdr.opcode, rc);
2462 rc = -EINVAL;
2463 goto fail_cmd;
2464 }
2465
2466 rc = wait_event_timeout(this_mmap.cmd_wait,
2467 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2468 if (!rc) {
2469 pr_err("timeout. waited for memory_map\n");
2470 rc = -EINVAL;
2471 goto fail_cmd;
2472 }
2473 rc = 0;
2474fail_cmd:
2475 return rc;
2476}
2477
2478int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add, int dir)
2479{
2480 struct asm_stream_cmd_memory_unmap mem_unmap;
2481 int rc = 0;
2482
2483 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2484 pr_err("APR handle NULL\n");
2485 return -EINVAL;
2486 }
2487 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2488
2489 q6asm_add_mmaphdr(&mem_unmap.hdr,
2490 sizeof(struct asm_stream_cmd_memory_unmap), TRUE);
2491 mem_unmap.hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP;
2492 mem_unmap.buf_add = buf_add;
2493
2494 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_unmap);
2495 if (rc < 0) {
2496 pr_err("mem_unmap op[0x%x]rc[%d]\n",
2497 mem_unmap.hdr.opcode, rc);
2498 rc = -EINVAL;
2499 goto fail_cmd;
2500 }
2501
2502 rc = wait_event_timeout(this_mmap.cmd_wait,
2503 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2504 if (!rc) {
2505 pr_err("timeout. waited for memory_map\n");
2506 rc = -EINVAL;
2507 goto fail_cmd;
2508 }
2509 rc = 0;
2510fail_cmd:
2511 return rc;
2512}
2513
2514int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain)
2515{
2516 void *vol_cmd = NULL;
2517 void *payload = NULL;
2518 struct asm_pp_params_command *cmd = NULL;
2519 struct asm_lrchannel_gain_params *lrgain = NULL;
2520 int sz = 0;
2521 int rc = 0;
2522
2523 sz = sizeof(struct asm_pp_params_command) +
2524 + sizeof(struct asm_lrchannel_gain_params);
2525 vol_cmd = kzalloc(sz, GFP_KERNEL);
2526 if (vol_cmd == NULL) {
2527 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2528 rc = -EINVAL;
2529 return rc;
2530 }
2531 cmd = (struct asm_pp_params_command *)vol_cmd;
2532 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2533 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2534 cmd->payload = NULL;
2535 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2536 sizeof(struct asm_lrchannel_gain_params);
2537 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2538 cmd->params.param_id = L_R_CHANNEL_GAIN_PARAM_ID;
2539 cmd->params.param_size = sizeof(struct asm_lrchannel_gain_params);
2540 cmd->params.reserved = 0;
2541
2542 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2543 lrgain = (struct asm_lrchannel_gain_params *)payload;
2544
2545 lrgain->left_gain = left_gain;
2546 lrgain->right_gain = right_gain;
2547 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2548 if (rc < 0) {
2549 pr_err("%s: Volume Command failed\n", __func__);
2550 rc = -EINVAL;
2551 goto fail_cmd;
2552 }
2553
2554 rc = wait_event_timeout(ac->cmd_wait,
2555 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2556 if (!rc) {
2557 pr_err("%s: timeout in sending volume command to apr\n",
2558 __func__);
2559 rc = -EINVAL;
2560 goto fail_cmd;
2561 }
2562 rc = 0;
2563fail_cmd:
2564 kfree(vol_cmd);
2565 return rc;
2566}
2567
2568static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
2569 uint32_t bufsz, uint32_t bufcnt)
2570{
2571 struct asm_stream_cmd_memory_map_regions *mmap_regions = NULL;
2572 struct asm_memory_map_regions *mregions = NULL;
2573 struct audio_port_data *port = NULL;
2574 struct audio_buffer *ab = NULL;
2575 void *mmap_region_cmd = NULL;
2576 void *payload = NULL;
2577 int rc = 0;
2578 int i = 0;
2579 int cmd_size = 0;
2580
2581 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2582 pr_err("APR handle NULL\n");
2583 return -EINVAL;
2584 }
2585 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2586
2587 cmd_size = sizeof(struct asm_stream_cmd_memory_map_regions)
2588 + sizeof(struct asm_memory_map_regions) * bufcnt;
2589
2590 mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302591 if (mmap_region_cmd == NULL) {
2592 pr_err("%s: Mem alloc failed\n", __func__);
2593 rc = -EINVAL;
2594 return rc;
2595 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002596 mmap_regions = (struct asm_stream_cmd_memory_map_regions *)
2597 mmap_region_cmd;
2598 q6asm_add_mmaphdr(&mmap_regions->hdr, cmd_size, TRUE);
2599 mmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP_REGIONS;
2600 mmap_regions->mempool_id = 0;
2601 mmap_regions->nregions = bufcnt & 0x00ff;
2602 pr_debug("map_regions->nregions = %d\n", mmap_regions->nregions);
2603 payload = ((u8 *) mmap_region_cmd +
2604 sizeof(struct asm_stream_cmd_memory_map_regions));
2605 mregions = (struct asm_memory_map_regions *)payload;
2606
2607 port = &ac->port[dir];
2608 for (i = 0; i < bufcnt; i++) {
2609 ab = &port->buf[i];
2610 mregions->phys = ab->phys;
2611 mregions->buf_size = ab->size;
2612 ++mregions;
2613 }
2614
2615 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) mmap_region_cmd);
2616 if (rc < 0) {
2617 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2618 mmap_regions->hdr.opcode, rc);
2619 rc = -EINVAL;
2620 goto fail_cmd;
2621 }
2622
2623 rc = wait_event_timeout(this_mmap.cmd_wait,
2624 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2625 if (!rc) {
2626 pr_err("timeout. waited for memory_map\n");
2627 rc = -EINVAL;
2628 goto fail_cmd;
2629 }
2630 rc = 0;
2631fail_cmd:
2632 kfree(mmap_region_cmd);
2633 return rc;
2634}
2635
2636static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir,
2637 uint32_t bufsz, uint32_t bufcnt)
2638{
2639 struct asm_stream_cmd_memory_unmap_regions *unmap_regions = NULL;
2640 struct asm_memory_unmap_regions *mregions = NULL;
2641 struct audio_port_data *port = NULL;
2642 struct audio_buffer *ab = NULL;
2643 void *unmap_region_cmd = NULL;
2644 void *payload = NULL;
2645 int rc = 0;
2646 int i = 0;
2647 int cmd_size = 0;
2648
2649 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2650 pr_err("APR handle NULL\n");
2651 return -EINVAL;
2652 }
2653 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2654
2655 cmd_size = sizeof(struct asm_stream_cmd_memory_unmap_regions) +
2656 sizeof(struct asm_memory_unmap_regions) * bufcnt;
2657
2658 unmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302659 if (unmap_region_cmd == NULL) {
2660 pr_err("%s: Mem alloc failed\n", __func__);
2661 rc = -EINVAL;
2662 return rc;
2663 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002664 unmap_regions = (struct asm_stream_cmd_memory_unmap_regions *)
2665 unmap_region_cmd;
2666 q6asm_add_mmaphdr(&unmap_regions->hdr, cmd_size, TRUE);
2667 unmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS;
2668 unmap_regions->nregions = bufcnt & 0x00ff;
2669 pr_debug("unmap_regions->nregions = %d\n", unmap_regions->nregions);
2670 payload = ((u8 *) unmap_region_cmd +
2671 sizeof(struct asm_stream_cmd_memory_unmap_regions));
2672 mregions = (struct asm_memory_unmap_regions *)payload;
2673 port = &ac->port[dir];
2674 for (i = 0; i < bufcnt; i++) {
2675 ab = &port->buf[i];
2676 mregions->phys = ab->phys;
2677 ++mregions;
2678 }
2679
2680 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) unmap_region_cmd);
2681 if (rc < 0) {
2682 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2683 unmap_regions->hdr.opcode, rc);
2684 goto fail_cmd;
2685 }
2686
2687 rc = wait_event_timeout(this_mmap.cmd_wait,
2688 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2689 if (!rc) {
2690 pr_err("timeout. waited for memory_unmap\n");
2691 goto fail_cmd;
2692 }
2693 rc = 0;
2694
2695fail_cmd:
2696 kfree(unmap_region_cmd);
2697 return rc;
2698}
2699
2700int q6asm_set_mute(struct audio_client *ac, int muteflag)
2701{
2702 void *vol_cmd = NULL;
2703 void *payload = NULL;
2704 struct asm_pp_params_command *cmd = NULL;
2705 struct asm_mute_params *mute = NULL;
2706 int sz = 0;
2707 int rc = 0;
2708
2709 sz = sizeof(struct asm_pp_params_command) +
2710 + sizeof(struct asm_mute_params);
2711 vol_cmd = kzalloc(sz, GFP_KERNEL);
2712 if (vol_cmd == NULL) {
2713 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2714 rc = -EINVAL;
2715 return rc;
2716 }
2717 cmd = (struct asm_pp_params_command *)vol_cmd;
2718 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2719 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2720 cmd->payload = NULL;
2721 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2722 sizeof(struct asm_mute_params);
2723 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2724 cmd->params.param_id = MUTE_CONFIG_PARAM_ID;
2725 cmd->params.param_size = sizeof(struct asm_mute_params);
2726 cmd->params.reserved = 0;
2727
2728 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2729 mute = (struct asm_mute_params *)payload;
2730
2731 mute->muteflag = muteflag;
2732 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2733 if (rc < 0) {
2734 pr_err("%s: Mute Command failed\n", __func__);
2735 rc = -EINVAL;
2736 goto fail_cmd;
2737 }
2738
2739 rc = wait_event_timeout(ac->cmd_wait,
2740 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2741 if (!rc) {
2742 pr_err("%s: timeout in sending mute command to apr\n",
2743 __func__);
2744 rc = -EINVAL;
2745 goto fail_cmd;
2746 }
2747 rc = 0;
2748fail_cmd:
2749 kfree(vol_cmd);
2750 return rc;
2751}
2752
2753int q6asm_set_volume(struct audio_client *ac, int volume)
2754{
2755 void *vol_cmd = NULL;
2756 void *payload = NULL;
2757 struct asm_pp_params_command *cmd = NULL;
2758 struct asm_master_gain_params *mgain = NULL;
2759 int sz = 0;
2760 int rc = 0;
2761
2762 sz = sizeof(struct asm_pp_params_command) +
2763 + sizeof(struct asm_master_gain_params);
2764 vol_cmd = kzalloc(sz, GFP_KERNEL);
2765 if (vol_cmd == NULL) {
2766 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2767 rc = -EINVAL;
2768 return rc;
2769 }
2770 cmd = (struct asm_pp_params_command *)vol_cmd;
2771 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2772 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2773 cmd->payload = NULL;
2774 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2775 sizeof(struct asm_master_gain_params);
2776 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2777 cmd->params.param_id = MASTER_GAIN_PARAM_ID;
2778 cmd->params.param_size = sizeof(struct asm_master_gain_params);
2779 cmd->params.reserved = 0;
2780
2781 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2782 mgain = (struct asm_master_gain_params *)payload;
2783
2784 mgain->master_gain = volume;
2785 mgain->padding = 0x00;
2786 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2787 if (rc < 0) {
2788 pr_err("%s: Volume Command failed\n", __func__);
2789 rc = -EINVAL;
2790 goto fail_cmd;
2791 }
2792
2793 rc = wait_event_timeout(ac->cmd_wait,
2794 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2795 if (!rc) {
2796 pr_err("%s: timeout in sending volume command to apr\n",
2797 __func__);
2798 rc = -EINVAL;
2799 goto fail_cmd;
2800 }
2801 rc = 0;
2802fail_cmd:
2803 kfree(vol_cmd);
2804 return rc;
2805}
2806
2807int q6asm_set_softpause(struct audio_client *ac,
2808 struct asm_softpause_params *pause_param)
2809{
2810 void *vol_cmd = NULL;
2811 void *payload = NULL;
2812 struct asm_pp_params_command *cmd = NULL;
2813 struct asm_softpause_params *params = NULL;
2814 int sz = 0;
2815 int rc = 0;
2816
2817 sz = sizeof(struct asm_pp_params_command) +
2818 + sizeof(struct asm_softpause_params);
2819 vol_cmd = kzalloc(sz, GFP_KERNEL);
2820 if (vol_cmd == NULL) {
2821 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2822 rc = -EINVAL;
2823 return rc;
2824 }
2825 cmd = (struct asm_pp_params_command *)vol_cmd;
2826 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2827 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2828 cmd->payload = NULL;
2829 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2830 sizeof(struct asm_softpause_params);
2831 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2832 cmd->params.param_id = SOFT_PAUSE_PARAM_ID;
2833 cmd->params.param_size = sizeof(struct asm_softpause_params);
2834 cmd->params.reserved = 0;
2835
2836 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2837 params = (struct asm_softpause_params *)payload;
2838
2839 params->enable = pause_param->enable;
2840 params->period = pause_param->period;
2841 params->step = pause_param->step;
2842 params->rampingcurve = pause_param->rampingcurve;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002843 pr_debug("%s: soft Pause Command: enable = %d, period = %d, step = %d, curve = %d\n",
2844 __func__, params->enable,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002845 params->period, params->step, params->rampingcurve);
2846 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2847 if (rc < 0) {
2848 pr_err("%s: Volume Command(soft_pause) failed\n", __func__);
2849 rc = -EINVAL;
2850 goto fail_cmd;
2851 }
2852
2853 rc = wait_event_timeout(ac->cmd_wait,
2854 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2855 if (!rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002856 pr_err("%s: timeout in sending volume command(soft_pause) to apr\n",
2857 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002858 rc = -EINVAL;
2859 goto fail_cmd;
2860 }
2861 rc = 0;
2862fail_cmd:
2863 kfree(vol_cmd);
2864 return rc;
2865}
2866
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07002867int q6asm_set_softvolume(struct audio_client *ac,
2868 struct asm_softvolume_params *softvol_param)
2869{
2870 void *vol_cmd = NULL;
2871 void *payload = NULL;
2872 struct asm_pp_params_command *cmd = NULL;
2873 struct asm_softvolume_params *params = NULL;
2874 int sz = 0;
2875 int rc = 0;
2876
2877 sz = sizeof(struct asm_pp_params_command) +
2878 + sizeof(struct asm_softvolume_params);
2879 vol_cmd = kzalloc(sz, GFP_KERNEL);
2880 if (vol_cmd == NULL) {
2881 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2882 rc = -EINVAL;
2883 return rc;
2884 }
2885 cmd = (struct asm_pp_params_command *)vol_cmd;
2886 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2887 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2888 cmd->payload = NULL;
2889 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2890 sizeof(struct asm_softvolume_params);
2891 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2892 cmd->params.param_id = SOFT_VOLUME_PARAM_ID;
2893 cmd->params.param_size = sizeof(struct asm_softvolume_params);
2894 cmd->params.reserved = 0;
2895
2896 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2897 params = (struct asm_softvolume_params *)payload;
2898
2899 params->period = softvol_param->period;
2900 params->step = softvol_param->step;
2901 params->rampingcurve = softvol_param->rampingcurve;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002902 pr_debug("%s: soft Volume:opcode = %d,payload_sz =%d,module_id =%d, param_id = %d, param_sz = %d\n",
2903 __func__,
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07002904 cmd->hdr.opcode, cmd->payload_size,
2905 cmd->params.module_id, cmd->params.param_id,
2906 cmd->params.param_size);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002907 pr_debug("%s: soft Volume Command: period = %d, step = %d, curve = %d\n",
2908 __func__, params->period,
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07002909 params->step, params->rampingcurve);
2910 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2911 if (rc < 0) {
2912 pr_err("%s: Volume Command(soft_volume) failed\n", __func__);
2913 rc = -EINVAL;
2914 goto fail_cmd;
2915 }
2916
2917 rc = wait_event_timeout(ac->cmd_wait,
2918 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2919 if (!rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002920 pr_err("%s: timeout in sending volume command(soft_volume) to apr\n",
2921 __func__);
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07002922 rc = -EINVAL;
2923 goto fail_cmd;
2924 }
2925 rc = 0;
2926fail_cmd:
2927 kfree(vol_cmd);
2928 return rc;
2929}
2930
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002931int q6asm_equalizer(struct audio_client *ac, void *eq)
2932{
2933 void *eq_cmd = NULL;
2934 void *payload = NULL;
2935 struct asm_pp_params_command *cmd = NULL;
2936 struct asm_equalizer_params *equalizer = NULL;
2937 struct msm_audio_eq_stream_config *eq_params = NULL;
2938 int i = 0;
2939 int sz = 0;
2940 int rc = 0;
2941
2942 sz = sizeof(struct asm_pp_params_command) +
2943 + sizeof(struct asm_equalizer_params);
2944 eq_cmd = kzalloc(sz, GFP_KERNEL);
2945 if (eq_cmd == NULL) {
2946 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2947 rc = -EINVAL;
2948 goto fail_cmd;
2949 }
2950 eq_params = (struct msm_audio_eq_stream_config *) eq;
2951 cmd = (struct asm_pp_params_command *)eq_cmd;
2952 q6asm_add_hdr(ac, &cmd->hdr, sz, TRUE);
2953 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2954 cmd->payload = NULL;
2955 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2956 sizeof(struct asm_equalizer_params);
2957 cmd->params.module_id = EQUALIZER_MODULE_ID;
2958 cmd->params.param_id = EQUALIZER_PARAM_ID;
2959 cmd->params.param_size = sizeof(struct asm_equalizer_params);
2960 cmd->params.reserved = 0;
2961 payload = (u8 *)(eq_cmd + sizeof(struct asm_pp_params_command));
2962 equalizer = (struct asm_equalizer_params *)payload;
2963
2964 equalizer->enable = eq_params->enable;
2965 equalizer->num_bands = eq_params->num_bands;
2966 pr_debug("%s: enable:%d numbands:%d\n", __func__, eq_params->enable,
2967 eq_params->num_bands);
2968 for (i = 0; i < eq_params->num_bands; i++) {
2969 equalizer->eq_bands[i].band_idx =
2970 eq_params->eq_bands[i].band_idx;
2971 equalizer->eq_bands[i].filter_type =
2972 eq_params->eq_bands[i].filter_type;
2973 equalizer->eq_bands[i].center_freq_hz =
2974 eq_params->eq_bands[i].center_freq_hz;
2975 equalizer->eq_bands[i].filter_gain =
2976 eq_params->eq_bands[i].filter_gain;
2977 equalizer->eq_bands[i].q_factor =
2978 eq_params->eq_bands[i].q_factor;
2979 pr_debug("%s: filter_type:%u bandnum:%d\n", __func__,
2980 eq_params->eq_bands[i].filter_type, i);
2981 pr_debug("%s: center_freq_hz:%u bandnum:%d\n", __func__,
2982 eq_params->eq_bands[i].center_freq_hz, i);
2983 pr_debug("%s: filter_gain:%d bandnum:%d\n", __func__,
2984 eq_params->eq_bands[i].filter_gain, i);
2985 pr_debug("%s: q_factor:%d bandnum:%d\n", __func__,
2986 eq_params->eq_bands[i].q_factor, i);
2987 }
2988 rc = apr_send_pkt(ac->apr, (uint32_t *) eq_cmd);
2989 if (rc < 0) {
2990 pr_err("%s: Equalizer Command failed\n", __func__);
2991 rc = -EINVAL;
2992 goto fail_cmd;
2993 }
2994
2995 rc = wait_event_timeout(ac->cmd_wait,
2996 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2997 if (!rc) {
2998 pr_err("%s: timeout in sending equalizer command to apr\n",
2999 __func__);
3000 rc = -EINVAL;
3001 goto fail_cmd;
3002 }
3003 rc = 0;
3004fail_cmd:
3005 kfree(eq_cmd);
3006 return rc;
3007}
3008
3009int q6asm_read(struct audio_client *ac)
3010{
3011 struct asm_stream_cmd_read read;
3012 struct audio_buffer *ab;
3013 int dsp_buf;
3014 struct audio_port_data *port;
3015 int rc;
3016 if (!ac || ac->apr == NULL) {
3017 pr_err("APR handle NULL\n");
3018 return -EINVAL;
3019 }
3020 if (ac->io_mode == SYNC_IO_MODE) {
3021 port = &ac->port[OUT];
3022
3023 q6asm_add_hdr(ac, &read.hdr, sizeof(read), FALSE);
3024
3025 mutex_lock(&port->lock);
3026
3027 dsp_buf = port->dsp_buf;
3028 ab = &port->buf[dsp_buf];
3029
3030 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
3031 __func__,
3032 ac->session,
3033 dsp_buf,
3034 (void *)port->buf[dsp_buf].data,
3035 port->cpu_buf,
3036 (void *)port->buf[port->cpu_buf].phys);
3037
3038 read.hdr.opcode = ASM_DATA_CMD_READ;
3039 read.buf_add = ab->phys;
3040 read.buf_size = ab->size;
3041 read.uid = port->dsp_buf;
3042 read.hdr.token = port->dsp_buf;
3043
3044 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3045 mutex_unlock(&port->lock);
3046 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
3047 read.buf_add,
3048 read.hdr.token,
3049 read.uid);
3050 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3051 if (rc < 0) {
3052 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
3053 goto fail_cmd;
3054 }
3055 return 0;
3056 }
3057fail_cmd:
3058 return -EINVAL;
3059}
3060
3061int q6asm_read_nolock(struct audio_client *ac)
3062{
3063 struct asm_stream_cmd_read read;
3064 struct audio_buffer *ab;
3065 int dsp_buf;
3066 struct audio_port_data *port;
3067 int rc;
3068 if (!ac || ac->apr == NULL) {
3069 pr_err("APR handle NULL\n");
3070 return -EINVAL;
3071 }
3072 if (ac->io_mode == SYNC_IO_MODE) {
3073 port = &ac->port[OUT];
3074
3075 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3076
3077
3078 dsp_buf = port->dsp_buf;
3079 ab = &port->buf[dsp_buf];
3080
3081 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
3082 __func__,
3083 ac->session,
3084 dsp_buf,
3085 (void *)port->buf[dsp_buf].data,
3086 port->cpu_buf,
3087 (void *)port->buf[port->cpu_buf].phys);
3088
3089 read.hdr.opcode = ASM_DATA_CMD_READ;
3090 read.buf_add = ab->phys;
3091 read.buf_size = ab->size;
3092 read.uid = port->dsp_buf;
3093 read.hdr.token = port->dsp_buf;
3094
3095 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3096 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
3097 read.buf_add,
3098 read.hdr.token,
3099 read.uid);
3100 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3101 if (rc < 0) {
3102 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
3103 goto fail_cmd;
3104 }
3105 return 0;
3106 }
3107fail_cmd:
3108 return -EINVAL;
3109}
3110
3111
3112static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
3113 uint32_t pkt_size, uint32_t cmd_flg)
3114{
3115 pr_debug("session=%d pkt size=%d cmd_flg=%d\n", pkt_size, cmd_flg,
3116 ac->session);
3117 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
3118 APR_HDR_LEN(sizeof(struct apr_hdr)),\
3119 APR_PKT_VER);
3120 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
3121 hdr->src_domain = APR_DOMAIN_APPS;
3122 hdr->dest_svc = APR_SVC_ASM;
3123 hdr->dest_domain = APR_DOMAIN_ADSP;
3124 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
3125 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
3126 if (cmd_flg) {
3127 hdr->token = ac->session;
3128 atomic_set(&ac->cmd_state, 1);
3129 }
3130 hdr->pkt_size = pkt_size;
3131 return;
3132}
3133
3134int q6asm_async_write(struct audio_client *ac,
3135 struct audio_aio_write_param *param)
3136{
3137 int rc = 0;
3138 struct asm_stream_cmd_write write;
3139
3140 if (!ac || ac->apr == NULL) {
3141 pr_err("%s: APR handle NULL\n", __func__);
3142 return -EINVAL;
3143 }
3144
3145 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write), FALSE);
3146
3147 /* Pass physical address as token for AIO scheme */
3148 write.hdr.token = param->uid;
3149 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3150 write.buf_add = param->paddr;
3151 write.avail_bytes = param->len;
3152 write.uid = param->uid;
3153 write.msw_ts = param->msw_ts;
3154 write.lsw_ts = param->lsw_ts;
3155 /* Use 0xFF00 for disabling timestamps */
3156 if (param->flags == 0xFF00)
3157 write.uflags = (0x00000000 | (param->flags & 0x800000FF));
3158 else
3159 write.uflags = (0x80000000 | param->flags);
3160
3161 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3162 write.buf_add, write.avail_bytes);
3163
3164 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3165 if (rc < 0) {
3166 pr_debug("[%s] write op[0x%x]rc[%d]\n", __func__,
3167 write.hdr.opcode, rc);
3168 goto fail_cmd;
3169 }
3170 return 0;
3171fail_cmd:
3172 return -EINVAL;
3173}
3174
3175int q6asm_async_read(struct audio_client *ac,
3176 struct audio_aio_read_param *param)
3177{
3178 int rc = 0;
3179 struct asm_stream_cmd_read read;
3180
3181 if (!ac || ac->apr == NULL) {
3182 pr_err("%s: APR handle NULL\n", __func__);
3183 return -EINVAL;
3184 }
3185
3186 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3187
3188 /* Pass physical address as token for AIO scheme */
3189 read.hdr.token = param->paddr;
3190 read.hdr.opcode = ASM_DATA_CMD_READ;
3191 read.buf_add = param->paddr;
3192 read.buf_size = param->len;
3193 read.uid = param->uid;
3194
3195 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3196 read.buf_add, read.buf_size);
3197
3198 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3199 if (rc < 0) {
3200 pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
3201 read.hdr.opcode, rc);
3202 goto fail_cmd;
3203 }
3204 return 0;
3205fail_cmd:
3206 return -EINVAL;
3207}
3208
3209int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3210 uint32_t lsw_ts, uint32_t flags)
3211{
3212 int rc = 0;
3213 struct asm_stream_cmd_write write;
3214 struct audio_port_data *port;
3215 struct audio_buffer *ab;
3216 int dsp_buf = 0;
3217
3218 if (!ac || ac->apr == NULL) {
3219 pr_err("APR handle NULL\n");
3220 return -EINVAL;
3221 }
3222 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3223 if (ac->io_mode == SYNC_IO_MODE) {
3224 port = &ac->port[IN];
3225
3226 q6asm_add_hdr(ac, &write.hdr, sizeof(write),
3227 FALSE);
3228 mutex_lock(&port->lock);
3229
3230 dsp_buf = port->dsp_buf;
3231 ab = &port->buf[dsp_buf];
3232
3233 write.hdr.token = port->dsp_buf;
3234 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3235 write.buf_add = ab->phys;
3236 write.avail_bytes = len;
3237 write.uid = port->dsp_buf;
3238 write.msw_ts = msw_ts;
3239 write.lsw_ts = lsw_ts;
3240 /* Use 0xFF00 for disabling timestamps */
3241 if (flags == 0xFF00)
3242 write.uflags = (0x00000000 | (flags & 0x800000FF));
3243 else
3244 write.uflags = (0x80000000 | flags);
3245 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3246
3247 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3248 , __func__,
3249 ab->phys,
3250 write.buf_add,
3251 write.hdr.token,
3252 write.uid);
3253 mutex_unlock(&port->lock);
Rajesha Kini3498c932011-07-19 19:58:27 +05303254#ifdef CONFIG_DEBUG_FS
3255 if (out_enable_flag) {
3256 char zero_pattern[2] = {0x00, 0x00};
3257 /* If First two byte is non zero and last two byte
3258 is zero then it is warm output pattern */
3259 if ((strncmp(((char *)ab->data), zero_pattern, 2)) &&
3260 (!strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3261 do_gettimeofday(&out_warm_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003262 pr_debug("WARM:apr_send_pkt at %ld sec %ld microsec\n",
3263 out_warm_tv.tv_sec,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303264 out_warm_tv.tv_usec);
3265 pr_debug("Warm Pattern Matched");
3266 }
3267 /* If First two byte is zero and last two byte is
3268 non zero then it is cont ouput pattern */
3269 else if ((!strncmp(((char *)ab->data), zero_pattern, 2))
3270 && (strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3271 do_gettimeofday(&out_cont_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003272 pr_debug("CONT:apr_send_pkt at %ld sec %ld microsec\n",
3273 out_cont_tv.tv_sec,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303274 out_cont_tv.tv_usec);
3275 pr_debug("Cont Pattern Matched");
3276 }
3277 }
3278#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003279 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3280 if (rc < 0) {
3281 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3282 goto fail_cmd;
3283 }
3284 pr_debug("%s: WRITE SUCCESS\n", __func__);
3285 return 0;
3286 }
3287fail_cmd:
3288 return -EINVAL;
3289}
3290
3291int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3292 uint32_t lsw_ts, uint32_t flags)
3293{
3294 int rc = 0;
3295 struct asm_stream_cmd_write write;
3296 struct audio_port_data *port;
3297 struct audio_buffer *ab;
3298 int dsp_buf = 0;
3299
3300 if (!ac || ac->apr == NULL) {
3301 pr_err("APR handle NULL\n");
3302 return -EINVAL;
3303 }
3304 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3305 if (ac->io_mode == SYNC_IO_MODE) {
3306 port = &ac->port[IN];
3307
3308 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write),
3309 FALSE);
3310
3311 dsp_buf = port->dsp_buf;
3312 ab = &port->buf[dsp_buf];
3313
3314 write.hdr.token = port->dsp_buf;
3315 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3316 write.buf_add = ab->phys;
3317 write.avail_bytes = len;
3318 write.uid = port->dsp_buf;
3319 write.msw_ts = msw_ts;
3320 write.lsw_ts = lsw_ts;
3321 /* Use 0xFF00 for disabling timestamps */
3322 if (flags == 0xFF00)
3323 write.uflags = (0x00000000 | (flags & 0x800000FF));
3324 else
3325 write.uflags = (0x80000000 | flags);
3326 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3327
3328 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3329 , __func__,
3330 ab->phys,
3331 write.buf_add,
3332 write.hdr.token,
3333 write.uid);
3334
3335 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3336 if (rc < 0) {
3337 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3338 goto fail_cmd;
3339 }
3340 pr_debug("%s: WRITE SUCCESS\n", __func__);
3341 return 0;
3342 }
3343fail_cmd:
3344 return -EINVAL;
3345}
3346
3347uint64_t q6asm_get_session_time(struct audio_client *ac)
3348{
3349 struct apr_hdr hdr;
3350 int rc;
3351
3352 if (!ac || ac->apr == NULL) {
3353 pr_err("APR handle NULL\n");
3354 return -EINVAL;
3355 }
3356 q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
3357 hdr.opcode = ASM_SESSION_CMD_GET_SESSION_TIME;
3358 atomic_set(&ac->time_flag, 1);
3359
3360 pr_debug("%s: session[%d]opcode[0x%x]\n", __func__,
3361 ac->session,
3362 hdr.opcode);
3363 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3364 if (rc < 0) {
3365 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3366 goto fail_cmd;
3367 }
3368 rc = wait_event_timeout(ac->time_wait,
3369 (atomic_read(&ac->time_flag) == 0), 5*HZ);
3370 if (!rc) {
3371 pr_err("%s: timeout in getting session time from DSP\n",
3372 __func__);
3373 goto fail_cmd;
3374 }
3375 return ac->time_stamp;
3376
3377fail_cmd:
3378 return -EINVAL;
3379}
3380
3381int q6asm_cmd(struct audio_client *ac, int cmd)
3382{
3383 struct apr_hdr hdr;
3384 int rc;
3385 atomic_t *state;
3386 int cnt = 0;
3387
3388 if (!ac || ac->apr == NULL) {
3389 pr_err("APR handle NULL\n");
3390 return -EINVAL;
3391 }
3392 q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
3393 switch (cmd) {
3394 case CMD_PAUSE:
3395 pr_debug("%s:CMD_PAUSE\n", __func__);
3396 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3397 state = &ac->cmd_state;
3398 break;
3399 case CMD_FLUSH:
3400 pr_debug("%s:CMD_FLUSH\n", __func__);
3401 hdr.opcode = ASM_STREAM_CMD_FLUSH;
3402 state = &ac->cmd_state;
3403 break;
3404 case CMD_OUT_FLUSH:
3405 pr_debug("%s:CMD_OUT_FLUSH\n", __func__);
3406 hdr.opcode = ASM_STREAM_CMD_FLUSH_READBUFS;
3407 state = &ac->cmd_state;
3408 break;
3409 case CMD_EOS:
3410 pr_debug("%s:CMD_EOS\n", __func__);
3411 hdr.opcode = ASM_DATA_CMD_EOS;
3412 atomic_set(&ac->cmd_state, 0);
3413 state = &ac->cmd_state;
3414 break;
3415 case CMD_CLOSE:
3416 pr_debug("%s:CMD_CLOSE\n", __func__);
3417 hdr.opcode = ASM_STREAM_CMD_CLOSE;
3418 state = &ac->cmd_state;
3419 break;
3420 default:
3421 pr_err("Invalid format[%d]\n", cmd);
3422 goto fail_cmd;
3423 }
3424 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3425 ac->session,
3426 hdr.opcode);
3427 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3428 if (rc < 0) {
3429 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3430 goto fail_cmd;
3431 }
3432 rc = wait_event_timeout(ac->cmd_wait, (atomic_read(state) == 0), 5*HZ);
3433 if (!rc) {
3434 pr_err("timeout. waited for response opcode[0x%x]\n",
3435 hdr.opcode);
3436 goto fail_cmd;
3437 }
3438 if (cmd == CMD_FLUSH)
3439 q6asm_reset_buf_state(ac);
3440 if (cmd == CMD_CLOSE) {
3441 /* check if DSP return all buffers */
3442 if (ac->port[IN].buf) {
3443 for (cnt = 0; cnt < ac->port[IN].max_buf_cnt;
3444 cnt++) {
3445 if (ac->port[IN].buf[cnt].used == IN) {
3446 pr_debug("Write Buf[%d] not returned\n",
3447 cnt);
3448 }
3449 }
3450 }
3451 if (ac->port[OUT].buf) {
3452 for (cnt = 0; cnt < ac->port[OUT].max_buf_cnt; cnt++) {
3453 if (ac->port[OUT].buf[cnt].used == OUT) {
3454 pr_debug("Read Buf[%d] not returned\n",
3455 cnt);
3456 }
3457 }
3458 }
3459 }
3460 return 0;
3461fail_cmd:
3462 return -EINVAL;
3463}
3464
3465int q6asm_cmd_nowait(struct audio_client *ac, int cmd)
3466{
3467 struct apr_hdr hdr;
3468 int rc;
3469
3470 if (!ac || ac->apr == NULL) {
3471 pr_err("%s:APR handle NULL\n", __func__);
3472 return -EINVAL;
3473 }
3474 q6asm_add_hdr_async(ac, &hdr, sizeof(hdr), TRUE);
3475 switch (cmd) {
3476 case CMD_PAUSE:
3477 pr_debug("%s:CMD_PAUSE\n", __func__);
3478 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3479 break;
3480 case CMD_EOS:
3481 pr_debug("%s:CMD_EOS\n", __func__);
3482 hdr.opcode = ASM_DATA_CMD_EOS;
3483 break;
3484 default:
3485 pr_err("%s:Invalid format[%d]\n", __func__, cmd);
3486 goto fail_cmd;
3487 }
3488 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3489 ac->session,
3490 hdr.opcode);
3491 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3492 if (rc < 0) {
3493 pr_err("%s:Commmand 0x%x failed\n", __func__, hdr.opcode);
3494 goto fail_cmd;
3495 }
3496 return 0;
3497fail_cmd:
3498 return -EINVAL;
3499}
3500
3501static void q6asm_reset_buf_state(struct audio_client *ac)
3502{
3503 int cnt = 0;
3504 int loopcnt = 0;
3505 struct audio_port_data *port = NULL;
3506
3507 if (ac->io_mode == SYNC_IO_MODE) {
3508 mutex_lock(&ac->cmd_lock);
3509 for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
3510 port = &ac->port[loopcnt];
3511 cnt = port->max_buf_cnt - 1;
3512 port->dsp_buf = 0;
3513 port->cpu_buf = 0;
3514 while (cnt >= 0) {
3515 if (!port->buf)
3516 continue;
3517 port->buf[cnt].used = 1;
3518 cnt--;
3519 }
3520 }
3521 mutex_unlock(&ac->cmd_lock);
3522 }
3523}
3524
3525int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable)
3526{
3527 struct asm_stream_cmd_reg_tx_overflow_event tx_overflow;
3528 int rc;
3529
3530 if (!ac || ac->apr == NULL) {
3531 pr_err("APR handle NULL\n");
3532 return -EINVAL;
3533 }
3534 pr_debug("%s:session[%d]enable[%d]\n", __func__,
3535 ac->session, enable);
3536 q6asm_add_hdr(ac, &tx_overflow.hdr, sizeof(tx_overflow), TRUE);
3537
3538 tx_overflow.hdr.opcode = \
3539 ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS;
3540 /* tx overflow event: enable */
3541 tx_overflow.enable = enable;
3542
3543 rc = apr_send_pkt(ac->apr, (uint32_t *) &tx_overflow);
3544 if (rc < 0) {
3545 pr_err("tx overflow op[0x%x]rc[%d]\n", \
3546 tx_overflow.hdr.opcode, rc);
3547 goto fail_cmd;
3548 }
3549 rc = wait_event_timeout(ac->cmd_wait,
3550 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3551 if (!rc) {
3552 pr_err("timeout. waited for tx overflow\n");
3553 goto fail_cmd;
3554 }
3555 return 0;
3556fail_cmd:
3557 return -EINVAL;
3558}
3559
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003560int q6asm_get_apr_service_id(int session_id)
3561{
3562 pr_debug("%s\n", __func__);
3563
Shiv Maliyappanahallia84982a2012-01-19 15:25:04 -08003564 if (session_id < 0 || session_id > SESSION_MAX) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003565 pr_err("%s: invalid session_id = %d\n", __func__, session_id);
3566 return -EINVAL;
3567 }
3568
3569 return ((struct apr_svc *)session[session_id]->apr)->id;
3570}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003571
3572
3573static int __init q6asm_init(void)
3574{
3575 pr_debug("%s\n", __func__);
3576 init_waitqueue_head(&this_mmap.cmd_wait);
3577 memset(session, 0, sizeof(session));
Rajesha Kini3498c932011-07-19 19:58:27 +05303578#ifdef CONFIG_DEBUG_FS
3579 out_buffer = kmalloc(OUT_BUFFER_SIZE, GFP_KERNEL);
3580 out_dentry = debugfs_create_file("audio_out_latency_measurement_node",\
3581 S_IFREG | S_IRUGO | S_IWUGO,\
3582 NULL, NULL, &audio_output_latency_debug_fops);
3583 if (IS_ERR(out_dentry))
3584 pr_err("debugfs_create_file failed\n");
3585 in_buffer = kmalloc(IN_BUFFER_SIZE, GFP_KERNEL);
3586 in_dentry = debugfs_create_file("audio_in_latency_measurement_node",\
3587 S_IFREG | S_IRUGO | S_IWUGO,\
3588 NULL, NULL, &audio_input_latency_debug_fops);
3589 if (IS_ERR(in_dentry))
3590 pr_err("debugfs_create_file failed\n");
3591#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003592 return 0;
3593}
3594
3595device_initcall(q6asm_init);