blob: 06be186096f99e5c27ebbd928d7170b0e62b6962 [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);
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +0530448 atomic_set(&ac->cmd_response, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700449
450 pr_debug("%s: session[%d]\n", __func__, ac->session);
451
452 return ac;
453fail:
454 q6asm_audio_client_free(ac);
455 return NULL;
456fail_session:
457 kfree(ac);
458 return NULL;
459}
460
Ben Romberger61754dc2011-10-31 18:25:41 -0700461struct audio_client *q6asm_get_audio_client(int session_id)
462{
463 if ((session_id <= 0) || (session_id > SESSION_MAX)) {
464 pr_err("%s: invalid session: %d\n", __func__, session_id);
465 goto err;
466 }
467
468 if (!session[session_id]) {
469 pr_err("%s: session not active: %d\n", __func__, session_id);
470 goto err;
471 }
472
473 return session[session_id];
474err:
475 return NULL;
476}
477
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700478int q6asm_audio_client_buf_alloc(unsigned int dir,
479 struct audio_client *ac,
480 unsigned int bufsz,
481 unsigned int bufcnt)
482{
483 int cnt = 0;
484 int rc = 0;
485 struct audio_buffer *buf;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800486#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
487 int len;
488#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700489
490 if (!(ac) || ((dir != IN) && (dir != OUT)))
491 return -EINVAL;
492
493 pr_debug("%s: session[%d]bufsz[%d]bufcnt[%d]\n", __func__, ac->session,
494 bufsz, bufcnt);
495
496 if (ac->session <= 0 || ac->session > 8)
497 goto fail;
498
499 if (ac->io_mode == SYNC_IO_MODE) {
500 if (ac->port[dir].buf) {
501 pr_debug("%s: buffer already allocated\n", __func__);
502 return 0;
503 }
504 mutex_lock(&ac->cmd_lock);
505 buf = kzalloc(((sizeof(struct audio_buffer))*bufcnt),
506 GFP_KERNEL);
507
508 if (!buf) {
509 mutex_unlock(&ac->cmd_lock);
510 goto fail;
511 }
512
513 ac->port[dir].buf = buf;
514
515 while (cnt < bufcnt) {
516 if (bufsz > 0) {
517 if (!buf[cnt].data) {
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800518#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
519 buf[cnt].client = msm_ion_client_create
520 (UINT_MAX, "audio_client");
521 if (IS_ERR_OR_NULL((void *)
522 buf[cnt].client)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700523 pr_err("%s: ION create client for AUDIO failed\n",
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800524 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700525 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800526 goto fail;
527 }
528 buf[cnt].handle = ion_alloc
529 (buf[cnt].client, bufsz, SZ_4K,
530 (0x1 << ION_AUDIO_HEAP_ID));
531 if (IS_ERR_OR_NULL((void *)
532 buf[cnt].handle)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700533 pr_err("%s: ION memory allocation for AUDIO failed\n",
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800534 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700535 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800536 goto fail;
537 }
538
539 rc = ion_phys(buf[cnt].client,
540 buf[cnt].handle,
541 (ion_phys_addr_t *)
542 &buf[cnt].phys,
543 (size_t *)&len);
544 if (rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700545 pr_err("%s: ION Get Physical for AUDIO failed, rc = %d\n",
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800546 __func__, rc);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700547 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800548 goto fail;
549 }
550
551 buf[cnt].data = ion_map_kernel
552 (buf[cnt].client, buf[cnt].handle,
553 0);
554 if (IS_ERR_OR_NULL((void *)
555 buf[cnt].data)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700556 pr_err("%s: ION memory mapping for AUDIO failed\n",
557 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700558 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800559 goto fail;
560 }
561 memset((void *)buf[cnt].data, 0, bufsz);
562#else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700563 unsigned int flags = 0;
564 buf[cnt].phys =
565 allocate_contiguous_ebi_nomap(bufsz,
566 SZ_4K);
567 if (!buf[cnt].phys) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700568 pr_err("%s:Buf alloc failed size=%d\n",
569 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700570 bufsz);
571 mutex_unlock(&ac->cmd_lock);
572 goto fail;
573 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700574 buf[cnt].mem_buffer =
Laura Abbottea3e7b62012-04-30 15:59:21 -0700575 ioremap(buf[cnt].phys, bufsz);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700576 if (IS_ERR(
577 (void *)buf[cnt].mem_buffer)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700578 pr_err("%s:map_buffer failed, error = %ld\n",
579 __func__,
580 PTR_ERR((void *)buf[cnt].mem_buffer));
Jayasena Sangaraboina466e6b92012-01-17 21:10:55 -0800581 mutex_unlock(&ac->cmd_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700582 goto fail;
583 }
584 buf[cnt].data =
Laura Abbottea3e7b62012-04-30 15:59:21 -0700585 buf[cnt].mem_buffer;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700586 if (!buf[cnt].data) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700587 pr_err("%s:invalid vaddr, iomap failed\n",
588 __func__);
Jayasena Sangaraboina466e6b92012-01-17 21:10:55 -0800589 mutex_unlock(&ac->cmd_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700590 goto fail;
591 }
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800592#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700593 buf[cnt].used = 1;
594 buf[cnt].size = bufsz;
595 buf[cnt].actual_size = bufsz;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800596 pr_debug("%s data[%p]phys[%p][%p]\n",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700597 __func__,
598 (void *)buf[cnt].data,
599 (void *)buf[cnt].phys,
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800600 (void *)&buf[cnt].phys);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700601 cnt++;
602 }
603 }
604 }
605 ac->port[dir].max_buf_cnt = cnt;
606
607 mutex_unlock(&ac->cmd_lock);
608 rc = q6asm_memory_map_regions(ac, dir, bufsz, cnt);
609 if (rc < 0) {
610 pr_err("%s:CMD Memory_map_regions failed\n", __func__);
611 goto fail;
612 }
613 }
614 return 0;
615fail:
616 q6asm_audio_client_buf_free(dir, ac);
617 return -EINVAL;
618}
619
620int q6asm_audio_client_buf_alloc_contiguous(unsigned int dir,
621 struct audio_client *ac,
622 unsigned int bufsz,
623 unsigned int bufcnt)
624{
625 int cnt = 0;
626 int rc = 0;
627 struct audio_buffer *buf;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800628#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
629 int len;
630#else
631 int flags = 0;
632#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700633 if (!(ac) || ((dir != IN) && (dir != OUT)))
634 return -EINVAL;
635
636 pr_debug("%s: session[%d]bufsz[%d]bufcnt[%d]\n",
637 __func__, ac->session,
638 bufsz, bufcnt);
639
640 if (ac->session <= 0 || ac->session > 8)
641 goto fail;
642
643 if (ac->port[dir].buf) {
644 pr_debug("%s: buffer already allocated\n", __func__);
645 return 0;
646 }
647 mutex_lock(&ac->cmd_lock);
648 buf = kzalloc(((sizeof(struct audio_buffer))*bufcnt),
649 GFP_KERNEL);
650
651 if (!buf) {
652 mutex_unlock(&ac->cmd_lock);
653 goto fail;
654 }
655
656 ac->port[dir].buf = buf;
657
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800658#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
659 buf[0].client = msm_ion_client_create(UINT_MAX, "audio_client");
660 if (IS_ERR_OR_NULL((void *)buf[0].client)) {
661 pr_err("%s: ION create client for AUDIO failed\n", __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700662 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800663 goto fail;
664 }
665 buf[0].handle = ion_alloc(buf[0].client, bufsz * bufcnt, SZ_4K,
666 (0x1 << ION_AUDIO_HEAP_ID));
667 if (IS_ERR_OR_NULL((void *) buf[0].handle)) {
668 pr_err("%s: ION memory allocation for AUDIO failed\n",
669 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700670 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800671 goto fail;
672 }
673
674 rc = ion_phys(buf[0].client, buf[0].handle,
675 (ion_phys_addr_t *)&buf[0].phys, (size_t *)&len);
676 if (rc) {
677 pr_err("%s: ION Get Physical for AUDIO failed, rc = %d\n",
678 __func__, rc);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700679 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800680 goto fail;
681 }
682
683 buf[0].data = ion_map_kernel(buf[0].client, buf[0].handle, 0);
684 if (IS_ERR_OR_NULL((void *) buf[0].data)) {
685 pr_err("%s: ION memory mapping for AUDIO failed\n", __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700686 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800687 goto fail;
688 }
689 memset((void *)buf[0].data, 0, (bufsz * bufcnt));
690#else
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700691 buf[0].phys = allocate_contiguous_ebi_nomap(bufsz * bufcnt,
692 SZ_4K);
693 if (!buf[0].phys) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700694 pr_err("%s:Buf alloc failed size=%d, bufcnt=%d\n",
695 __func__, bufsz, bufcnt);
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700696 mutex_unlock(&ac->cmd_lock);
697 goto fail;
698 }
699
Laura Abbottea3e7b62012-04-30 15:59:21 -0700700 buf[0].mem_buffer = ioremap(buf[0].phys, bufsz * bufcnt);
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700701 if (IS_ERR((void *)buf[cnt].mem_buffer)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700702 pr_err("%s:map_buffer failed, error = %ld\n",
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700703 __func__, PTR_ERR((void *)buf[0].mem_buffer));
704
705 mutex_unlock(&ac->cmd_lock);
706 goto fail;
707 }
Laura Abbottea3e7b62012-04-30 15:59:21 -0700708 buf[0].data = buf[0].mem_buffer;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800709#endif
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700710 if (!buf[0].data) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700711 pr_err("%s:invalid vaddr, iomap failed\n", __func__);
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700712 mutex_unlock(&ac->cmd_lock);
713 goto fail;
714 }
715
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700716 buf[0].used = dir ^ 1;
717 buf[0].size = bufsz;
718 buf[0].actual_size = bufsz;
719 cnt = 1;
720 while (cnt < bufcnt) {
721 if (bufsz > 0) {
722 buf[cnt].data = buf[0].data + (cnt * bufsz);
723 buf[cnt].phys = buf[0].phys + (cnt * bufsz);
724 if (!buf[cnt].data) {
725 pr_err("%s Buf alloc failed\n",
726 __func__);
727 mutex_unlock(&ac->cmd_lock);
728 goto fail;
729 }
730 buf[cnt].used = dir ^ 1;
731 buf[cnt].size = bufsz;
732 buf[cnt].actual_size = bufsz;
733 pr_debug("%s data[%p]phys[%p][%p]\n", __func__,
734 (void *)buf[cnt].data,
735 (void *)buf[cnt].phys,
736 (void *)&buf[cnt].phys);
737 }
738 cnt++;
739 }
740 ac->port[dir].max_buf_cnt = cnt;
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -0700741
742 pr_debug("%s ac->port[%d].max_buf_cnt[%d]\n", __func__, dir,
743 ac->port[dir].max_buf_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700744 mutex_unlock(&ac->cmd_lock);
745 rc = q6asm_memory_map(ac, buf[0].phys, dir, bufsz, cnt);
746 if (rc < 0) {
747 pr_err("%s:CMD Memory_map_regions failed\n", __func__);
748 goto fail;
749 }
750 return 0;
751fail:
752 q6asm_audio_client_buf_free_contiguous(dir, ac);
753 return -EINVAL;
754}
755
756static int32_t q6asm_mmapcallback(struct apr_client_data *data, void *priv)
757{
758 uint32_t token;
759 uint32_t *payload = data->payload;
760
761 if (data->opcode == RESET_EVENTS) {
762 pr_debug("%s: Reset event is received: %d %d apr[%p]\n",
763 __func__,
764 data->reset_event,
765 data->reset_proc,
766 this_mmap.apr);
767 apr_reset(this_mmap.apr);
768 this_mmap.apr = NULL;
769 atomic_set(&this_mmap.cmd_state, 0);
770 return 0;
771 }
772
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700773 pr_debug("%s:ptr0[0x%x]ptr1[0x%x]opcode[0x%x] token[0x%x]payload_s[%d] src[%d] dest[%d]\n",
774 __func__, payload[0], payload[1], data->opcode, data->token,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700775 data->payload_size, data->src_port, data->dest_port);
776
777 if (data->opcode == APR_BASIC_RSP_RESULT) {
778 token = data->token;
779 switch (payload[0]) {
780 case ASM_SESSION_CMD_MEMORY_MAP:
781 case ASM_SESSION_CMD_MEMORY_UNMAP:
782 case ASM_SESSION_CMD_MEMORY_MAP_REGIONS:
783 case ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS:
784 pr_debug("%s:command[0x%x]success [0x%x]\n",
785 __func__, payload[0], payload[1]);
786 if (atomic_read(&this_mmap.cmd_state)) {
787 atomic_set(&this_mmap.cmd_state, 0);
788 wake_up(&this_mmap.cmd_wait);
789 }
790 break;
791 default:
792 pr_debug("%s:command[0x%x] not expecting rsp\n",
793 __func__, payload[0]);
794 break;
795 }
796 }
797 return 0;
798}
799
800
801static int32_t q6asm_callback(struct apr_client_data *data, void *priv)
802{
803 int i = 0;
804 struct audio_client *ac = (struct audio_client *)priv;
805 uint32_t token;
806 unsigned long dsp_flags;
807 uint32_t *payload;
Jay Wang0668d1062012-07-11 18:53:21 -0700808 uint32_t wakeup_flag = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700809
810
811 if ((ac == NULL) || (data == NULL)) {
812 pr_err("ac or priv NULL\n");
813 return -EINVAL;
814 }
815 if (ac->session <= 0 || ac->session > 8) {
816 pr_err("%s:Session ID is invalid, session = %d\n", __func__,
817 ac->session);
818 return -EINVAL;
819 }
Jay Wang0668d1062012-07-11 18:53:21 -0700820 if (atomic_read(&ac->nowait_cmd_cnt) > 0) {
821 pr_debug("%s: nowait_cmd_cnt %d\n",
822 __func__,
823 atomic_read(&ac->nowait_cmd_cnt));
824 atomic_dec(&ac->nowait_cmd_cnt);
825 wakeup_flag = 0;
826 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700827 payload = data->payload;
828
829 if (data->opcode == RESET_EVENTS) {
830 pr_debug("q6asm_callback: Reset event is received: %d %d apr[%p]\n",
831 data->reset_event, data->reset_proc, ac->apr);
Laxminath Kasam692c6542012-02-21 11:17:47 +0530832 if (ac->cb)
833 ac->cb(data->opcode, data->token,
834 (uint32_t *)data->payload, ac->priv);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700835 apr_reset(ac->apr);
836 return 0;
837 }
838
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700839 pr_debug("%s: session[%d]opcode[0x%x] token[0x%x]payload_s[%d] src[%d] dest[%d]\n",
840 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700841 ac->session, data->opcode,
842 data->token, data->payload_size, data->src_port,
843 data->dest_port);
844
845 if (data->opcode == APR_BASIC_RSP_RESULT) {
846 token = data->token;
847 switch (payload[0]) {
848 case ASM_STREAM_CMD_SET_PP_PARAMS:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700849 if (rtac_make_asm_callback(ac->session, payload,
850 data->payload_size))
851 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700852 case ASM_SESSION_CMD_PAUSE:
853 case ASM_DATA_CMD_EOS:
854 case ASM_STREAM_CMD_CLOSE:
855 case ASM_STREAM_CMD_FLUSH:
856 case ASM_SESSION_CMD_RUN:
857 case ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS:
858 case ASM_STREAM_CMD_FLUSH_READBUFS:
859 pr_debug("%s:Payload = [0x%x]\n", __func__, payload[0]);
860 if (token != ac->session) {
861 pr_err("%s:Invalid session[%d] rxed expected[%d]",
862 __func__, token, ac->session);
863 return -EINVAL;
864 }
865 case ASM_STREAM_CMD_OPEN_READ:
866 case ASM_STREAM_CMD_OPEN_WRITE:
867 case ASM_STREAM_CMD_OPEN_READWRITE:
868 case ASM_DATA_CMD_MEDIA_FORMAT_UPDATE:
869 case ASM_STREAM_CMD_SET_ENCDEC_PARAM:
Santosh Mardi23321202012-03-22 04:33:25 +0530870 case ASM_STREAM_CMD_OPEN_WRITE_COMPRESSED:
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -0700871 case ASM_STREAM_CMD_OPEN_READ_COMPRESSED:
Jay Wang0668d1062012-07-11 18:53:21 -0700872 if (atomic_read(&ac->cmd_state) && wakeup_flag) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700873 atomic_set(&ac->cmd_state, 0);
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +0530874 if (payload[1] == ADSP_EUNSUPPORTED)
875 atomic_set(&ac->cmd_response, 1);
876 else
877 atomic_set(&ac->cmd_response, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700878 wake_up(&ac->cmd_wait);
879 }
880 if (ac->cb)
881 ac->cb(data->opcode, data->token,
882 (uint32_t *)data->payload, ac->priv);
883 break;
884 default:
885 pr_debug("%s:command[0x%x] not expecting rsp\n",
886 __func__, payload[0]);
887 break;
888 }
889 return 0;
890 }
891
892 switch (data->opcode) {
893 case ASM_DATA_EVENT_WRITE_DONE:{
894 struct audio_port_data *port = &ac->port[IN];
895 pr_debug("%s: Rxed opcode[0x%x] status[0x%x] token[%d]",
896 __func__, payload[0], payload[1],
897 data->token);
898 if (ac->io_mode == SYNC_IO_MODE) {
899 if (port->buf == NULL) {
900 pr_err("%s: Unexpected Write Done\n",
901 __func__);
902 return -EINVAL;
903 }
904 spin_lock_irqsave(&port->dsp_lock, dsp_flags);
905 if (port->buf[data->token].phys !=
906 payload[0]) {
907 pr_err("Buf expected[%p]rxed[%p]\n",\
908 (void *)port->buf[data->token].phys,\
909 (void *)payload[0]);
910 spin_unlock_irqrestore(&port->dsp_lock,
911 dsp_flags);
912 return -EINVAL;
913 }
914 token = data->token;
915 port->buf[token].used = 1;
916 spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
Rajesha Kini3498c932011-07-19 19:58:27 +0530917#ifdef CONFIG_DEBUG_FS
918 if (out_enable_flag) {
919 /* For first Write done log the time and reset
920 out_cold_index*/
921 if (out_cold_index != 1) {
922 do_gettimeofday(&out_cold_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700923 pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",
924 out_cold_tv.tv_sec,
Rajesha Kini3498c932011-07-19 19:58:27 +0530925 out_cold_tv.tv_usec);
926 out_cold_index = 1;
927 }
928 pr_debug("out_enable_flag %ld",\
929 out_enable_flag);
930 }
931#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700932 for (i = 0; i < port->max_buf_cnt; i++)
933 pr_debug("%d ", port->buf[i].used);
934
935 }
936 break;
937 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700938 case ASM_STREAM_CMDRSP_GET_PP_PARAMS:
939 rtac_make_asm_callback(ac->session, payload,
940 data->payload_size);
941 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700942 case ASM_DATA_EVENT_READ_DONE:{
943
944 struct audio_port_data *port = &ac->port[OUT];
Rajesha Kini3498c932011-07-19 19:58:27 +0530945#ifdef CONFIG_DEBUG_FS
946 if (in_enable_flag) {
947 /* when in_cont_index == 7, DSP would be
948 * writing into the 8th 512 byte buffer and this
949 * timestamp is tapped here.Once done it then writes
950 * to 9th 512 byte buffer.These two buffers(8th, 9th)
951 * reach the test application in 5th iteration and that
952 * timestamp is tapped at user level. The difference
953 * of these two timestamps gives us the time between
954 * the time at which dsp started filling the sample
955 * required and when it reached the test application.
956 * Hence continuous input latency
957 */
958 if (in_cont_index == 7) {
959 do_gettimeofday(&in_cont_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700960 pr_err("In_CONT:previous read buffer done at %ld sec %ld microsec\n",
Sriranjan Srikantam74753532011-10-03 14:48:37 -0700961 in_cont_tv.tv_sec, in_cont_tv.tv_usec);
Rajesha Kini3498c932011-07-19 19:58:27 +0530962 }
963 }
964#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700965 pr_debug("%s:R-D: status=%d buff_add=%x act_size=%d offset=%d\n",
966 __func__, payload[READDONE_IDX_STATUS],
967 payload[READDONE_IDX_BUFFER],
968 payload[READDONE_IDX_SIZE],
969 payload[READDONE_IDX_OFFSET]);
970 pr_debug("%s:R-D:msw_ts=%d lsw_ts=%d flags=%d id=%d num=%d\n",
971 __func__, payload[READDONE_IDX_MSW_TS],
972 payload[READDONE_IDX_LSW_TS],
973 payload[READDONE_IDX_FLAGS],
974 payload[READDONE_IDX_ID],
975 payload[READDONE_IDX_NUMFRAMES]);
Rajesha Kini3498c932011-07-19 19:58:27 +0530976#ifdef CONFIG_DEBUG_FS
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700977 if (in_enable_flag)
Rajesha Kini3498c932011-07-19 19:58:27 +0530978 in_cont_index++;
Rajesha Kini3498c932011-07-19 19:58:27 +0530979#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700980 if (ac->io_mode == SYNC_IO_MODE) {
981 if (port->buf == NULL) {
982 pr_err("%s: Unexpected Write Done\n", __func__);
983 return -EINVAL;
984 }
985 spin_lock_irqsave(&port->dsp_lock, dsp_flags);
986 token = data->token;
987 port->buf[token].used = 0;
988 if (port->buf[token].phys !=
989 payload[READDONE_IDX_BUFFER]) {
990 pr_err("Buf expected[%p]rxed[%p]\n",\
991 (void *)port->buf[token].phys,\
992 (void *)payload[READDONE_IDX_BUFFER]);
993 spin_unlock_irqrestore(&port->dsp_lock,
994 dsp_flags);
995 break;
996 }
997 port->buf[token].actual_size =
998 payload[READDONE_IDX_SIZE];
999 spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
1000 }
1001 break;
1002 }
1003 case ASM_DATA_EVENT_EOS:
1004 case ASM_DATA_CMDRSP_EOS:
1005 pr_debug("%s:EOS ACK received: rxed opcode[0x%x]\n",
1006 __func__, data->opcode);
1007 break;
1008 case ASM_STREAM_CMDRSP_GET_ENCDEC_PARAM:
1009 break;
1010 case ASM_SESSION_EVENT_TX_OVERFLOW:
1011 pr_err("ASM_SESSION_EVENT_TX_OVERFLOW\n");
1012 break;
1013 case ASM_SESSION_CMDRSP_GET_SESSION_TIME:
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001014 pr_debug("%s: ASM_SESSION_CMDRSP_GET_SESSION_TIME, payload[0] = %d, payload[1] = %d, payload[2] = %d\n",
1015 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001016 payload[0], payload[1], payload[2]);
1017 ac->time_stamp = (uint64_t)(((uint64_t)payload[1] << 32) |
1018 payload[2]);
1019 if (atomic_read(&ac->time_flag)) {
1020 atomic_set(&ac->time_flag, 0);
1021 wake_up(&ac->time_wait);
1022 }
1023 break;
1024 case ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY:
Deepa Madiregama55cbf782011-09-10 05:44:39 +05301025 case ASM_DATA_EVENT_ENC_SR_CM_NOTIFY:
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001026 pr_debug("%s: ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY, payload[0] = %d, payload[1] = %d, payload[2] = %d, payload[3] = %d\n",
1027 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001028 payload[0], payload[1], payload[2],
1029 payload[3]);
1030 break;
1031 }
1032 if (ac->cb)
1033 ac->cb(data->opcode, data->token,
1034 data->payload, ac->priv);
1035
1036 return 0;
1037}
1038
1039void *q6asm_is_cpu_buf_avail(int dir, struct audio_client *ac, uint32_t *size,
1040 uint32_t *index)
1041{
1042 void *data;
1043 unsigned char idx;
1044 struct audio_port_data *port;
1045
1046 if (!ac || ((dir != IN) && (dir != OUT)))
1047 return NULL;
1048
1049 if (ac->io_mode == SYNC_IO_MODE) {
1050 port = &ac->port[dir];
1051
1052 mutex_lock(&port->lock);
1053 idx = port->cpu_buf;
1054 if (port->buf == NULL) {
1055 pr_debug("%s:Buffer pointer null\n", __func__);
Jayasena Sangaraboina466e6b92012-01-17 21:10:55 -08001056 mutex_unlock(&port->lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001057 return NULL;
1058 }
1059 /* dir 0: used = 0 means buf in use
1060 dir 1: used = 1 means buf in use */
1061 if (port->buf[idx].used == dir) {
1062 /* To make it more robust, we could loop and get the
1063 next avail buf, its risky though */
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001064 pr_debug("%s:Next buf idx[0x%x] not available,dir[%d]\n",
1065 __func__, idx, dir);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001066 mutex_unlock(&port->lock);
1067 return NULL;
1068 }
1069 *size = port->buf[idx].actual_size;
1070 *index = port->cpu_buf;
1071 data = port->buf[idx].data;
1072 pr_debug("%s:session[%d]index[%d] data[%p]size[%d]\n",
1073 __func__,
1074 ac->session,
1075 port->cpu_buf,
1076 data, *size);
1077 /* By default increase the cpu_buf cnt
1078 user accesses this function,increase cpu
1079 buf(to avoid another api)*/
1080 port->buf[idx].used = dir;
1081 port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1));
1082 mutex_unlock(&port->lock);
1083 return data;
1084 }
1085 return NULL;
1086}
1087
Jay Wang9cf59a02011-08-10 16:58:40 -07001088void *q6asm_is_cpu_buf_avail_nolock(int dir, struct audio_client *ac,
1089 uint32_t *size, uint32_t *index)
1090{
1091 void *data;
1092 unsigned char idx;
1093 struct audio_port_data *port;
1094
1095 if (!ac || ((dir != IN) && (dir != OUT)))
1096 return NULL;
1097
1098 port = &ac->port[dir];
1099
1100 idx = port->cpu_buf;
1101 if (port->buf == NULL) {
1102 pr_debug("%s:Buffer pointer null\n", __func__);
1103 return NULL;
1104 }
1105 /*
1106 * dir 0: used = 0 means buf in use
1107 * dir 1: used = 1 means buf in use
1108 */
1109 if (port->buf[idx].used == dir) {
1110 /*
1111 * To make it more robust, we could loop and get the
1112 * next avail buf, its risky though
1113 */
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001114 pr_debug("%s:Next buf idx[0x%x] not available, dir[%d]\n",
1115 __func__, idx, dir);
Jay Wang9cf59a02011-08-10 16:58:40 -07001116 return NULL;
1117 }
1118 *size = port->buf[idx].actual_size;
1119 *index = port->cpu_buf;
1120 data = port->buf[idx].data;
1121 pr_debug("%s:session[%d]index[%d] data[%p]size[%d]\n",
1122 __func__, ac->session, port->cpu_buf,
1123 data, *size);
1124 /*
1125 * By default increase the cpu_buf cnt
1126 * user accesses this function,increase cpu
1127 * buf(to avoid another api)
1128 */
1129 port->buf[idx].used = dir;
1130 port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1));
1131 return data;
1132}
1133
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001134int q6asm_is_dsp_buf_avail(int dir, struct audio_client *ac)
1135{
1136 int ret = -1;
1137 struct audio_port_data *port;
1138 uint32_t idx;
1139
1140 if (!ac || (dir != OUT))
1141 return ret;
1142
1143 if (ac->io_mode == SYNC_IO_MODE) {
1144 port = &ac->port[dir];
1145
1146 mutex_lock(&port->lock);
1147 idx = port->dsp_buf;
1148
1149 if (port->buf[idx].used == (dir ^ 1)) {
1150 /* To make it more robust, we could loop and get the
1151 next avail buf, its risky though */
1152 pr_err("Next buf idx[0x%x] not available, dir[%d]\n",
1153 idx, dir);
1154 mutex_unlock(&port->lock);
1155 return ret;
1156 }
1157 pr_debug("%s: session[%d]dsp_buf=%d cpu_buf=%d\n", __func__,
1158 ac->session, port->dsp_buf, port->cpu_buf);
1159 ret = ((port->dsp_buf != port->cpu_buf) ? 0 : -1);
1160 mutex_unlock(&port->lock);
1161 }
1162 return ret;
1163}
1164
1165static void q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
1166 uint32_t pkt_size, uint32_t cmd_flg)
1167{
1168 pr_debug("%s:session=%d pkt size=%d cmd_flg=%d\n", __func__, pkt_size,
1169 cmd_flg, ac->session);
1170 mutex_lock(&ac->cmd_lock);
1171 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
1172 APR_HDR_LEN(sizeof(struct apr_hdr)),\
1173 APR_PKT_VER);
1174 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
1175 hdr->src_domain = APR_DOMAIN_APPS;
1176 hdr->dest_svc = APR_SVC_ASM;
1177 hdr->dest_domain = APR_DOMAIN_ADSP;
1178 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
1179 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
1180 if (cmd_flg) {
1181 hdr->token = ac->session;
1182 atomic_set(&ac->cmd_state, 1);
1183 }
1184 hdr->pkt_size = pkt_size;
1185 mutex_unlock(&ac->cmd_lock);
1186 return;
1187}
1188
1189static void q6asm_add_mmaphdr(struct apr_hdr *hdr, uint32_t pkt_size,
1190 uint32_t cmd_flg)
1191{
1192 pr_debug("%s:pkt size=%d cmd_flg=%d\n", __func__, pkt_size, cmd_flg);
1193 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
1194 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1195 hdr->src_port = 0;
1196 hdr->dest_port = 0;
1197 if (cmd_flg) {
1198 hdr->token = 0;
1199 atomic_set(&this_mmap.cmd_state, 1);
1200 }
1201 hdr->pkt_size = pkt_size;
1202 return;
1203}
1204
1205int q6asm_open_read(struct audio_client *ac,
1206 uint32_t format)
1207{
1208 int rc = 0x00;
1209 struct asm_stream_cmd_open_read open;
Rajesha Kini3498c932011-07-19 19:58:27 +05301210#ifdef CONFIG_DEBUG_FS
1211 in_cont_index = 0;
1212#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001213 if ((ac == NULL) || (ac->apr == NULL)) {
1214 pr_err("%s: APR handle NULL\n", __func__);
1215 return -EINVAL;
1216 }
1217 pr_debug("%s:session[%d]", __func__, ac->session);
1218
1219 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1220 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ;
1221 /* Stream prio : High, provide meta info with encoded frames */
1222 open.src_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1223
1224 open.pre_proc_top = get_asm_topology();
1225 if (open.pre_proc_top == 0)
1226 open.pre_proc_top = DEFAULT_POPP_TOPOLOGY;
1227
1228 switch (format) {
1229 case FORMAT_LINEAR_PCM:
1230 open.uMode = STREAM_PRIORITY_HIGH;
1231 open.format = LINEAR_PCM;
1232 break;
Mingming Yin647e9ea2012-03-17 19:56:10 -07001233 case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
1234 open.uMode = STREAM_PRIORITY_HIGH;
1235 open.format = MULTI_CHANNEL_PCM;
1236 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001237 case FORMAT_MPEG4_AAC:
1238 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1239 open.format = MPEG4_AAC;
1240 break;
1241 case FORMAT_V13K:
1242 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1243 open.format = V13K_FS;
1244 break;
1245 case FORMAT_EVRC:
1246 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1247 open.format = EVRC_FS;
1248 break;
1249 case FORMAT_AMRNB:
1250 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1251 open.format = AMRNB_FS;
1252 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301253 case FORMAT_AMRWB:
1254 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1255 open.format = AMRWB_FS;
1256 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001257 default:
1258 pr_err("Invalid format[%d]\n", format);
1259 goto fail_cmd;
1260 }
1261 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1262 if (rc < 0) {
1263 pr_err("open failed op[0x%x]rc[%d]\n", \
1264 open.hdr.opcode, rc);
1265 goto fail_cmd;
1266 }
1267 rc = wait_event_timeout(ac->cmd_wait,
1268 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1269 if (!rc) {
1270 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1271 rc);
1272 goto fail_cmd;
1273 }
1274 return 0;
1275fail_cmd:
1276 return -EINVAL;
1277}
1278
Subhash Chandra Bose Naripeddy694b7d92012-06-20 20:46:13 -07001279int q6asm_open_read_compressed(struct audio_client *ac,
1280 uint32_t frames_per_buffer, uint32_t meta_data_mode)
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -07001281{
1282 int rc = 0x00;
1283 struct asm_stream_cmd_open_read_compressed open;
1284#ifdef CONFIG_DEBUG_FS
1285 in_cont_index = 0;
1286#endif
1287 if ((ac == NULL) || (ac->apr == NULL)) {
1288 pr_err("%s: APR handle NULL\n", __func__);
1289 return -EINVAL;
1290 }
1291 pr_debug("%s:session[%d]", __func__, ac->session);
1292
1293 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1294 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ_COMPRESSED;
1295 /* hardcoded as following*/
Subhash Chandra Bose Naripeddy694b7d92012-06-20 20:46:13 -07001296 open.frame_per_buf = frames_per_buffer;
1297 open.uMode = meta_data_mode;
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -07001298
1299 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1300 if (rc < 0) {
1301 pr_err("open failed op[0x%x]rc[%d]\n", open.hdr.opcode, rc);
1302 goto fail_cmd;
1303 }
1304 rc = wait_event_timeout(ac->cmd_wait,
1305 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1306 if (!rc) {
1307 pr_err("%s: timeout. waited for OPEN_READ_COMPRESSED rc[%d]\n",
1308 __func__, rc);
1309 goto fail_cmd;
1310 }
1311 return 0;
1312fail_cmd:
1313 return -EINVAL;
1314}
1315
Santosh Mardi23321202012-03-22 04:33:25 +05301316int q6asm_open_write_compressed(struct audio_client *ac, uint32_t format)
1317{
1318 int rc = 0x00;
1319 struct asm_stream_cmd_open_write_compressed open;
1320
1321 if ((ac == NULL) || (ac->apr == NULL)) {
1322 pr_err("%s: APR handle NULL\n", __func__);
1323 return -EINVAL;
1324 }
1325 pr_debug("%s: session[%d] wr_format[0x%x]", __func__, ac->session,
1326 format);
1327
1328 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1329
1330 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_COMPRESSED;
1331
1332 switch (format) {
1333 case FORMAT_AC3:
1334 open.format = AC3_DECODER;
1335 break;
1336 case FORMAT_EAC3:
1337 open.format = EAC3_DECODER;
1338 break;
1339 case FORMAT_MP3:
1340 open.format = MP3;
1341 break;
1342 case FORMAT_DTS:
1343 open.format = DTS;
1344 break;
Srikanth Uyyala66f781a2012-06-13 23:23:25 +05301345 case FORMAT_DTS_LBR:
1346 open.format = DTS_LBR;
1347 break;
Santosh Mardi23321202012-03-22 04:33:25 +05301348 case FORMAT_AAC:
1349 open.format = MPEG4_AAC;
1350 break;
1351 case FORMAT_ATRAC:
1352 open.format = ATRAC;
1353 break;
1354 case FORMAT_WMA_V10PRO:
1355 open.format = WMA_V10PRO;
1356 break;
1357 case FORMAT_MAT:
1358 open.format = MAT;
1359 break;
1360 default:
1361 pr_err("%s: Invalid format[%d]\n", __func__, format);
1362 goto fail_cmd;
1363 }
1364 /*Below flag indicates the DSP that Compressed audio input
1365 stream is not IEC 61937 or IEC 60958 packetizied*/
1366 open.flags = 0x00000000;
1367 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1368 if (rc < 0) {
1369 pr_err("%s: open failed op[0x%x]rc[%d]\n", \
1370 __func__, open.hdr.opcode, rc);
1371 goto fail_cmd;
1372 }
1373 rc = wait_event_timeout(ac->cmd_wait,
1374 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1375 if (!rc) {
1376 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1377 rc);
1378 goto fail_cmd;
1379 }
1380 return 0;
1381fail_cmd:
1382 return -EINVAL;
1383}
1384
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001385int q6asm_open_write(struct audio_client *ac, uint32_t format)
1386{
1387 int rc = 0x00;
1388 struct asm_stream_cmd_open_write open;
1389
1390 if ((ac == NULL) || (ac->apr == NULL)) {
1391 pr_err("%s: APR handle NULL\n", __func__);
1392 return -EINVAL;
1393 }
1394 pr_debug("%s: session[%d] wr_format[0x%x]", __func__, ac->session,
1395 format);
1396
1397 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1398
1399 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE;
1400 open.uMode = STREAM_PRIORITY_HIGH;
1401 /* source endpoint : matrix */
1402 open.sink_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1403 open.stream_handle = 0x00;
1404
1405 open.post_proc_top = get_asm_topology();
1406 if (open.post_proc_top == 0)
1407 open.post_proc_top = DEFAULT_POPP_TOPOLOGY;
1408
1409 switch (format) {
1410 case FORMAT_LINEAR_PCM:
1411 open.format = LINEAR_PCM;
1412 break;
Kiran Kandi5e809b02012-01-31 00:24:33 -08001413 case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
1414 open.format = MULTI_CHANNEL_PCM;
1415 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001416 case FORMAT_MPEG4_AAC:
1417 open.format = MPEG4_AAC;
1418 break;
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07001419 case FORMAT_MPEG4_MULTI_AAC:
1420 open.format = MPEG4_MULTI_AAC;
1421 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001422 case FORMAT_WMA_V9:
1423 open.format = WMA_V9;
1424 break;
1425 case FORMAT_WMA_V10PRO:
1426 open.format = WMA_V10PRO;
1427 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05301428 case FORMAT_MP3:
1429 open.format = MP3;
1430 break;
Srikanth Uyyala66f781a2012-06-13 23:23:25 +05301431 case FORMAT_DTS:
1432 open.format = DTS;
1433 break;
1434 case FORMAT_DTS_LBR:
1435 open.format = DTS_LBR;
1436 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001437 default:
1438 pr_err("%s: Invalid format[%d]\n", __func__, format);
1439 goto fail_cmd;
1440 }
1441 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1442 if (rc < 0) {
1443 pr_err("%s: open failed op[0x%x]rc[%d]\n", \
1444 __func__, open.hdr.opcode, rc);
1445 goto fail_cmd;
1446 }
1447 rc = wait_event_timeout(ac->cmd_wait,
1448 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1449 if (!rc) {
1450 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1451 rc);
1452 goto fail_cmd;
1453 }
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +05301454 if (atomic_read(&ac->cmd_response)) {
1455 pr_err("%s: format = %x not supported\n", __func__, format);
1456 goto fail_cmd;
1457 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001458 return 0;
1459fail_cmd:
1460 return -EINVAL;
1461}
1462
1463int q6asm_open_read_write(struct audio_client *ac,
1464 uint32_t rd_format,
1465 uint32_t wr_format)
1466{
1467 int rc = 0x00;
1468 struct asm_stream_cmd_open_read_write open;
1469
1470 if ((ac == NULL) || (ac->apr == NULL)) {
1471 pr_err("APR handle NULL\n");
1472 return -EINVAL;
1473 }
1474 pr_debug("%s: session[%d]", __func__, ac->session);
1475 pr_debug("wr_format[0x%x]rd_format[0x%x]",
1476 wr_format, rd_format);
1477
1478 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1479 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READWRITE;
1480
Deepa Madiregama55cbf782011-09-10 05:44:39 +05301481 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_NORMAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001482 /* source endpoint : matrix */
1483 open.post_proc_top = get_asm_topology();
1484 if (open.post_proc_top == 0)
1485 open.post_proc_top = DEFAULT_POPP_TOPOLOGY;
1486
1487 switch (wr_format) {
1488 case FORMAT_LINEAR_PCM:
1489 open.write_format = LINEAR_PCM;
1490 break;
1491 case FORMAT_MPEG4_AAC:
1492 open.write_format = MPEG4_AAC;
1493 break;
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07001494 case FORMAT_MPEG4_MULTI_AAC:
1495 open.write_format = MPEG4_MULTI_AAC;
1496 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001497 case FORMAT_WMA_V9:
1498 open.write_format = WMA_V9;
1499 break;
1500 case FORMAT_WMA_V10PRO:
1501 open.write_format = WMA_V10PRO;
1502 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301503 case FORMAT_AMRNB:
1504 open.write_format = AMRNB_FS;
1505 break;
1506 case FORMAT_AMRWB:
1507 open.write_format = AMRWB_FS;
1508 break;
1509 case FORMAT_V13K:
1510 open.write_format = V13K_FS;
1511 break;
1512 case FORMAT_EVRC:
1513 open.write_format = EVRC_FS;
1514 break;
1515 case FORMAT_EVRCB:
1516 open.write_format = EVRCB_FS;
1517 break;
1518 case FORMAT_EVRCWB:
1519 open.write_format = EVRCWB_FS;
1520 break;
1521 case FORMAT_MP3:
1522 open.write_format = MP3;
1523 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001524 default:
1525 pr_err("Invalid format[%d]\n", wr_format);
1526 goto fail_cmd;
1527 }
1528
1529 switch (rd_format) {
1530 case FORMAT_LINEAR_PCM:
1531 open.read_format = LINEAR_PCM;
1532 break;
1533 case FORMAT_MPEG4_AAC:
1534 open.read_format = MPEG4_AAC;
1535 break;
1536 case FORMAT_V13K:
1537 open.read_format = V13K_FS;
1538 break;
1539 case FORMAT_EVRC:
1540 open.read_format = EVRC_FS;
1541 break;
1542 case FORMAT_AMRNB:
1543 open.read_format = AMRNB_FS;
1544 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301545 case FORMAT_AMRWB:
1546 open.read_format = AMRWB_FS;
1547 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001548 default:
1549 pr_err("Invalid format[%d]\n", rd_format);
1550 goto fail_cmd;
1551 }
1552 pr_debug("%s:rdformat[0x%x]wrformat[0x%x]\n", __func__,
1553 open.read_format, open.write_format);
1554
1555 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1556 if (rc < 0) {
1557 pr_err("open failed op[0x%x]rc[%d]\n", \
1558 open.hdr.opcode, rc);
1559 goto fail_cmd;
1560 }
1561 rc = wait_event_timeout(ac->cmd_wait,
1562 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1563 if (!rc) {
1564 pr_err("timeout. waited for OPEN_WRITE rc[%d]\n", rc);
1565 goto fail_cmd;
1566 }
1567 return 0;
1568fail_cmd:
1569 return -EINVAL;
1570}
1571
1572int q6asm_run(struct audio_client *ac, uint32_t flags,
1573 uint32_t msw_ts, uint32_t lsw_ts)
1574{
1575 struct asm_stream_cmd_run run;
1576 int rc;
1577 if (!ac || ac->apr == NULL) {
1578 pr_err("APR handle NULL\n");
1579 return -EINVAL;
1580 }
1581 pr_debug("%s session[%d]", __func__, ac->session);
1582 q6asm_add_hdr(ac, &run.hdr, sizeof(run), TRUE);
1583
1584 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1585 run.flags = flags;
1586 run.msw_ts = msw_ts;
1587 run.lsw_ts = lsw_ts;
Rajesha Kini3498c932011-07-19 19:58:27 +05301588#ifdef CONFIG_DEBUG_FS
1589 if (out_enable_flag) {
1590 do_gettimeofday(&out_cold_tv);
1591 pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",\
1592 out_cold_tv.tv_sec, out_cold_tv.tv_usec);
1593 }
1594#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001595 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1596 if (rc < 0) {
1597 pr_err("Commmand run failed[%d]", rc);
1598 goto fail_cmd;
1599 }
1600
1601 rc = wait_event_timeout(ac->cmd_wait,
1602 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1603 if (!rc) {
1604 pr_err("timeout. waited for run success rc[%d]", rc);
1605 goto fail_cmd;
1606 }
1607
1608 return 0;
1609fail_cmd:
1610 return -EINVAL;
1611}
1612
1613int q6asm_run_nowait(struct audio_client *ac, uint32_t flags,
1614 uint32_t msw_ts, uint32_t lsw_ts)
1615{
1616 struct asm_stream_cmd_run run;
1617 int rc;
1618 if (!ac || ac->apr == NULL) {
1619 pr_err("%s:APR handle NULL\n", __func__);
1620 return -EINVAL;
1621 }
1622 pr_debug("session[%d]", ac->session);
1623 q6asm_add_hdr_async(ac, &run.hdr, sizeof(run), TRUE);
1624
1625 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1626 run.flags = flags;
1627 run.msw_ts = msw_ts;
1628 run.lsw_ts = lsw_ts;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001629 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1630 if (rc < 0) {
1631 pr_err("%s:Commmand run failed[%d]", __func__, rc);
1632 return -EINVAL;
1633 }
Jay Wang0668d1062012-07-11 18:53:21 -07001634 atomic_inc(&ac->nowait_cmd_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001635 return 0;
1636}
1637
1638
1639int q6asm_enc_cfg_blk_aac(struct audio_client *ac,
1640 uint32_t frames_per_buf,
1641 uint32_t sample_rate, uint32_t channels,
1642 uint32_t bit_rate, uint32_t mode, uint32_t format)
1643{
1644 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1645 int rc = 0;
1646
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001647 pr_debug("%s:session[%d]frames[%d]SR[%d]ch[%d]bitrate[%d]mode[%d] format[%d]",
1648 __func__, ac->session, frames_per_buf,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001649 sample_rate, channels, bit_rate, mode, format);
1650
1651 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1652
1653 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1654 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1655 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1656 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1657 enc_cfg.enc_blk.format_id = MPEG4_AAC;
1658 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_aac_read_cfg);
1659 enc_cfg.enc_blk.cfg.aac.bitrate = bit_rate;
1660 enc_cfg.enc_blk.cfg.aac.enc_mode = mode;
1661 enc_cfg.enc_blk.cfg.aac.format = format;
1662 enc_cfg.enc_blk.cfg.aac.ch_cfg = channels;
1663 enc_cfg.enc_blk.cfg.aac.sample_rate = sample_rate;
1664
1665 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1666 if (rc < 0) {
1667 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1668 rc = -EINVAL;
1669 goto fail_cmd;
1670 }
1671 rc = wait_event_timeout(ac->cmd_wait,
1672 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1673 if (!rc) {
1674 pr_err("timeout. waited for FORMAT_UPDATE\n");
1675 goto fail_cmd;
1676 }
1677 return 0;
1678fail_cmd:
1679 return -EINVAL;
1680}
1681
1682int q6asm_enc_cfg_blk_pcm(struct audio_client *ac,
1683 uint32_t rate, uint32_t channels)
1684{
1685 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1686
1687 int rc = 0;
1688
1689 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1690 ac->session, rate, channels);
1691
1692 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1693
1694 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1695 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1696 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1697 enc_cfg.enc_blk.frames_per_buf = 1;
1698 enc_cfg.enc_blk.format_id = LINEAR_PCM;
1699 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg);
1700 enc_cfg.enc_blk.cfg.pcm.ch_cfg = channels;
1701 enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16;
1702 enc_cfg.enc_blk.cfg.pcm.sample_rate = rate;
1703 enc_cfg.enc_blk.cfg.pcm.is_signed = 1;
1704 enc_cfg.enc_blk.cfg.pcm.interleaved = 1;
1705
1706 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1707 if (rc < 0) {
1708 pr_err("Comamnd open failed\n");
1709 rc = -EINVAL;
1710 goto fail_cmd;
1711 }
1712 rc = wait_event_timeout(ac->cmd_wait,
1713 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1714 if (!rc) {
1715 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1716 goto fail_cmd;
1717 }
1718 return 0;
1719fail_cmd:
1720 return -EINVAL;
1721}
1722
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001723int q6asm_enc_cfg_blk_pcm_native(struct audio_client *ac,
1724 uint32_t rate, uint32_t channels)
1725{
1726 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1727
1728 int rc = 0;
1729
1730 pr_debug("%s: Session %d, rate = %d, channels = %d, setting the rate and channels to 0 for native\n",
1731 __func__, ac->session, rate, channels);
1732
1733 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1734
1735 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1736 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1737 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1738 enc_cfg.enc_blk.frames_per_buf = 1;
1739 enc_cfg.enc_blk.format_id = LINEAR_PCM;
1740 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg);
1741 enc_cfg.enc_blk.cfg.pcm.ch_cfg = 0;/*channels;*/
1742 enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16;
1743 enc_cfg.enc_blk.cfg.pcm.sample_rate = 0;/*rate;*/
1744 enc_cfg.enc_blk.cfg.pcm.is_signed = 1;
1745 enc_cfg.enc_blk.cfg.pcm.interleaved = 1;
1746
1747 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1748 if (rc < 0) {
1749 pr_err("Comamnd open failed\n");
1750 rc = -EINVAL;
1751 goto fail_cmd;
1752 }
1753 rc = wait_event_timeout(ac->cmd_wait,
1754 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1755 if (!rc) {
1756 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1757 goto fail_cmd;
1758 }
1759 return 0;
1760fail_cmd:
1761 return -EINVAL;
1762}
1763
Mingming Yin647e9ea2012-03-17 19:56:10 -07001764int q6asm_enc_cfg_blk_multi_ch_pcm(struct audio_client *ac,
1765 uint32_t rate, uint32_t channels)
1766{
1767 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1768
1769 int rc = 0;
1770
1771 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1772 ac->session, rate, channels);
1773
1774 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1775
1776 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1777 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1778 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1779 enc_cfg.enc_blk.frames_per_buf = 1;
1780 enc_cfg.enc_blk.format_id = MULTI_CHANNEL_PCM;
1781 enc_cfg.enc_blk.cfg_size =
1782 sizeof(struct asm_multi_channel_pcm_fmt_blk);
1783 enc_cfg.enc_blk.cfg.mpcm.num_channels = channels;
1784 enc_cfg.enc_blk.cfg.mpcm.bits_per_sample = 16;
1785 enc_cfg.enc_blk.cfg.mpcm.sample_rate = rate;
1786 enc_cfg.enc_blk.cfg.mpcm.is_signed = 1;
1787 enc_cfg.enc_blk.cfg.mpcm.is_interleaved = 1;
Subhash Chandra Bose Naripeddy8477d222012-06-12 00:30:54 -07001788 if (channels == 2) {
1789 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1790 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1791 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = 0;
1792 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = 0;
1793 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1794 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1795 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1796 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1797 } else if (channels == 4) {
1798 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1799 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1800 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_RB;
1801 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_LB;
1802 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1803 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1804 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1805 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1806 } else if (channels == 6) {
1807 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1808 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1809 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_LFE;
1810 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_FC;
1811 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = PCM_CHANNEL_LB;
1812 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = PCM_CHANNEL_RB;
1813 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1814 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1815 } else if (channels == 8) {
1816 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1817 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1818 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_LFE;
1819 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_FC;
1820 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = PCM_CHANNEL_LB;
1821 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = PCM_CHANNEL_RB;
1822 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = PCM_CHANNEL_FLC;
1823 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = PCM_CHANNEL_FRC;
1824 }
Mingming Yin647e9ea2012-03-17 19:56:10 -07001825
1826 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1827 if (rc < 0) {
1828 pr_err("Comamnd open failed\n");
1829 rc = -EINVAL;
1830 goto fail_cmd;
1831 }
1832 rc = wait_event_timeout(ac->cmd_wait,
1833 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1834 if (!rc) {
1835 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1836 goto fail_cmd;
1837 }
1838 return 0;
1839fail_cmd:
1840 return -EINVAL;
1841}
1842
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001843int q6asm_enable_sbrps(struct audio_client *ac,
1844 uint32_t sbr_ps_enable)
1845{
1846 struct asm_stream_cmd_encdec_sbr sbrps;
1847
1848 int rc = 0;
1849
1850 pr_debug("%s: Session %d\n", __func__, ac->session);
1851
1852 q6asm_add_hdr(ac, &sbrps.hdr, sizeof(sbrps), TRUE);
1853
1854 sbrps.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1855 sbrps.param_id = ASM_ENABLE_SBR_PS;
1856 sbrps.param_size = sizeof(struct asm_sbr_ps);
1857 sbrps.sbr_ps.enable = sbr_ps_enable;
1858
1859 rc = apr_send_pkt(ac->apr, (uint32_t *) &sbrps);
1860 if (rc < 0) {
1861 pr_err("Command opcode[0x%x]paramid[0x%x] failed\n",
1862 ASM_STREAM_CMD_SET_ENCDEC_PARAM,
1863 ASM_ENABLE_SBR_PS);
1864 rc = -EINVAL;
1865 goto fail_cmd;
1866 }
1867 rc = wait_event_timeout(ac->cmd_wait,
1868 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1869 if (!rc) {
1870 pr_err("timeout opcode[0x%x] ", sbrps.hdr.opcode);
1871 goto fail_cmd;
1872 }
1873 return 0;
1874fail_cmd:
1875 return -EINVAL;
1876}
1877
Swaminathan Sathappan70765cd2011-07-19 18:42:47 -07001878int q6asm_cfg_dual_mono_aac(struct audio_client *ac,
1879 uint16_t sce_left, uint16_t sce_right)
1880{
1881 struct asm_stream_cmd_encdec_dualmono dual_mono;
1882
1883 int rc = 0;
1884
1885 pr_debug("%s: Session %d, sce_left = %d, sce_right = %d\n",
1886 __func__, ac->session, sce_left, sce_right);
1887
1888 q6asm_add_hdr(ac, &dual_mono.hdr, sizeof(dual_mono), TRUE);
1889
1890 dual_mono.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1891 dual_mono.param_id = ASM_CONFIGURE_DUAL_MONO;
1892 dual_mono.param_size = sizeof(struct asm_dual_mono);
1893 dual_mono.channel_map.sce_left = sce_left;
1894 dual_mono.channel_map.sce_right = sce_right;
1895
1896 rc = apr_send_pkt(ac->apr, (uint32_t *) &dual_mono);
1897 if (rc < 0) {
1898 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
1899 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
1900 ASM_CONFIGURE_DUAL_MONO);
1901 rc = -EINVAL;
1902 goto fail_cmd;
1903 }
1904 rc = wait_event_timeout(ac->cmd_wait,
1905 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1906 if (!rc) {
1907 pr_err("%s:timeout opcode[0x%x]\n", __func__,
1908 dual_mono.hdr.opcode);
1909 goto fail_cmd;
1910 }
1911 return 0;
1912fail_cmd:
1913 return -EINVAL;
1914}
1915
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07001916int q6asm_set_encdec_chan_map(struct audio_client *ac,
1917 uint32_t num_channels)
1918{
1919 struct asm_stream_cmd_encdec_channelmap chan_map;
1920 u8 *channel_mapping;
1921
1922 int rc = 0;
1923
1924 pr_debug("%s: Session %d, num_channels = %d\n",
1925 __func__, ac->session, num_channels);
1926
1927 q6asm_add_hdr(ac, &chan_map.hdr, sizeof(chan_map), TRUE);
1928
1929 chan_map.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1930 chan_map.param_id = ASM_ENCDEC_DEC_CHAN_MAP;
1931 chan_map.param_size = sizeof(struct asm_dec_chan_map);
1932 chan_map.chan_map.num_channels = num_channels;
1933
1934 channel_mapping =
1935 chan_map.chan_map.channel_mapping;
1936
1937 memset(channel_mapping, PCM_CHANNEL_NULL, MAX_CHAN_MAP_CHANNELS);
1938 if (num_channels == 1) {
1939 channel_mapping[0] = PCM_CHANNEL_FL;
1940 } else if (num_channels == 2) {
1941 channel_mapping[0] = PCM_CHANNEL_FL;
1942 channel_mapping[1] = PCM_CHANNEL_FR;
1943 } else if (num_channels == 6) {
1944 channel_mapping[0] = PCM_CHANNEL_FC;
1945 channel_mapping[1] = PCM_CHANNEL_FL;
1946 channel_mapping[2] = PCM_CHANNEL_FR;
1947 channel_mapping[3] = PCM_CHANNEL_LB;
1948 channel_mapping[4] = PCM_CHANNEL_RB;
1949 channel_mapping[5] = PCM_CHANNEL_LFE;
1950 } else {
1951 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
1952 num_channels);
1953 rc = -EINVAL;
1954 goto fail_cmd;
1955 }
1956
1957 rc = apr_send_pkt(ac->apr, (uint32_t *) &chan_map);
1958 if (rc < 0) {
1959 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
1960 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
1961 ASM_ENCDEC_DEC_CHAN_MAP);
1962 goto fail_cmd;
1963 }
1964 rc = wait_event_timeout(ac->cmd_wait,
1965 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1966 if (!rc) {
1967 pr_err("%s:timeout opcode[0x%x]\n", __func__,
1968 chan_map.hdr.opcode);
1969 rc = -ETIMEDOUT;
1970 goto fail_cmd;
1971 }
1972 return 0;
1973fail_cmd:
1974 return rc;
1975}
1976
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001977int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf,
1978 uint16_t min_rate, uint16_t max_rate,
1979 uint16_t reduced_rate_level, uint16_t rate_modulation_cmd)
1980{
1981 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1982 int rc = 0;
1983
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001984 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]",
1985 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001986 ac->session, frames_per_buf, min_rate, max_rate,
1987 reduced_rate_level, rate_modulation_cmd);
1988
1989 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1990
1991 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1992
1993 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1994 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1995
1996 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1997 enc_cfg.enc_blk.format_id = V13K_FS;
1998 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_qcelp13_read_cfg);
1999 enc_cfg.enc_blk.cfg.qcelp13.min_rate = min_rate;
2000 enc_cfg.enc_blk.cfg.qcelp13.max_rate = max_rate;
2001 enc_cfg.enc_blk.cfg.qcelp13.reduced_rate_level = reduced_rate_level;
2002 enc_cfg.enc_blk.cfg.qcelp13.rate_modulation_cmd = rate_modulation_cmd;
2003
2004 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2005 if (rc < 0) {
2006 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2007 goto fail_cmd;
2008 }
2009 rc = wait_event_timeout(ac->cmd_wait,
2010 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2011 if (!rc) {
2012 pr_err("timeout. waited for FORMAT_UPDATE\n");
2013 goto fail_cmd;
2014 }
2015 return 0;
2016fail_cmd:
2017 return -EINVAL;
2018}
2019
2020int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf,
2021 uint16_t min_rate, uint16_t max_rate,
2022 uint16_t rate_modulation_cmd)
2023{
2024 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2025 int rc = 0;
2026
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002027 pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] rate_modulation_cmd[0x%4x]",
2028 __func__, ac->session,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002029 frames_per_buf, min_rate, max_rate, rate_modulation_cmd);
2030
2031 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2032
2033 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2034
2035 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2036 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2037
2038 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2039 enc_cfg.enc_blk.format_id = EVRC_FS;
2040 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_evrc_read_cfg);
2041 enc_cfg.enc_blk.cfg.evrc.min_rate = min_rate;
2042 enc_cfg.enc_blk.cfg.evrc.max_rate = max_rate;
2043 enc_cfg.enc_blk.cfg.evrc.rate_modulation_cmd = rate_modulation_cmd;
2044 enc_cfg.enc_blk.cfg.evrc.reserved = 0;
2045
2046 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2047 if (rc < 0) {
2048 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2049 goto fail_cmd;
2050 }
2051 rc = wait_event_timeout(ac->cmd_wait,
2052 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2053 if (!rc) {
2054 pr_err("timeout. waited for FORMAT_UPDATE\n");
2055 goto fail_cmd;
2056 }
2057 return 0;
2058fail_cmd:
2059 return -EINVAL;
2060}
2061
2062int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf,
2063 uint16_t band_mode, uint16_t dtx_enable)
2064{
2065 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2066 int rc = 0;
2067
2068 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
2069 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
2070
2071 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2072
2073 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2074
2075 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2076 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2077
2078 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2079 enc_cfg.enc_blk.format_id = AMRNB_FS;
2080 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrnb_read_cfg);
2081 enc_cfg.enc_blk.cfg.amrnb.mode = band_mode;
2082 enc_cfg.enc_blk.cfg.amrnb.dtx_mode = dtx_enable;
2083
2084 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2085 if (rc < 0) {
2086 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2087 goto fail_cmd;
2088 }
2089 rc = wait_event_timeout(ac->cmd_wait,
2090 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2091 if (!rc) {
2092 pr_err("timeout. waited for FORMAT_UPDATE\n");
2093 goto fail_cmd;
2094 }
2095 return 0;
2096fail_cmd:
2097 return -EINVAL;
2098}
2099
Alex Wong2caeecc2011-10-28 10:52:15 +05302100int q6asm_enc_cfg_blk_amrwb(struct audio_client *ac, uint32_t frames_per_buf,
2101 uint16_t band_mode, uint16_t dtx_enable)
2102{
2103 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2104 int rc = 0;
2105
2106 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
2107 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
2108
2109 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2110
2111 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2112
2113 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2114 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2115
2116 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2117 enc_cfg.enc_blk.format_id = AMRWB_FS;
2118 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrwb_read_cfg);
2119 enc_cfg.enc_blk.cfg.amrwb.mode = band_mode;
2120 enc_cfg.enc_blk.cfg.amrwb.dtx_mode = dtx_enable;
2121
2122 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2123 if (rc < 0) {
2124 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2125 goto fail_cmd;
2126 }
2127 rc = wait_event_timeout(ac->cmd_wait,
2128 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2129 if (!rc) {
2130 pr_err("timeout. waited for FORMAT_UPDATE\n");
2131 goto fail_cmd;
2132 }
2133 return 0;
2134fail_cmd:
2135 return -EINVAL;
2136}
2137
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002138int q6asm_media_format_block_pcm(struct audio_client *ac,
2139 uint32_t rate, uint32_t channels)
2140{
2141 struct asm_stream_media_format_update fmt;
2142 int rc = 0;
2143
2144 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
2145 channels);
2146
2147 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2148
2149 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2150
2151 fmt.format = LINEAR_PCM;
2152 fmt.cfg_size = sizeof(struct asm_pcm_cfg);
2153 fmt.write_cfg.pcm_cfg.ch_cfg = channels;
2154 fmt.write_cfg.pcm_cfg.bits_per_sample = 16;
2155 fmt.write_cfg.pcm_cfg.sample_rate = rate;
2156 fmt.write_cfg.pcm_cfg.is_signed = 1;
2157 fmt.write_cfg.pcm_cfg.interleaved = 1;
2158
2159 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2160 if (rc < 0) {
2161 pr_err("%s:Comamnd open failed\n", __func__);
2162 goto fail_cmd;
2163 }
2164 rc = wait_event_timeout(ac->cmd_wait,
2165 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2166 if (!rc) {
2167 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2168 goto fail_cmd;
2169 }
2170 return 0;
2171fail_cmd:
2172 return -EINVAL;
2173}
2174
Kiran Kandi5e809b02012-01-31 00:24:33 -08002175int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
2176 uint32_t rate, uint32_t channels)
2177{
2178 struct asm_stream_media_format_update fmt;
2179 u8 *channel_mapping;
2180 int rc = 0;
2181
2182 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
2183 channels);
2184
2185 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2186
2187 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2188
2189 fmt.format = MULTI_CHANNEL_PCM;
2190 fmt.cfg_size = sizeof(struct asm_multi_channel_pcm_fmt_blk);
2191 fmt.write_cfg.multi_ch_pcm_cfg.num_channels = channels;
2192 fmt.write_cfg.multi_ch_pcm_cfg.bits_per_sample = 16;
2193 fmt.write_cfg.multi_ch_pcm_cfg.sample_rate = rate;
2194 fmt.write_cfg.multi_ch_pcm_cfg.is_signed = 1;
2195 fmt.write_cfg.multi_ch_pcm_cfg.is_interleaved = 1;
2196 channel_mapping =
2197 fmt.write_cfg.multi_ch_pcm_cfg.channel_mapping;
2198
2199 memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
2200
2201 if (channels == 1) {
2202 channel_mapping[0] = PCM_CHANNEL_FL;
2203 } else if (channels == 2) {
2204 channel_mapping[0] = PCM_CHANNEL_FL;
2205 channel_mapping[1] = PCM_CHANNEL_FR;
2206 } else if (channels == 6) {
2207 channel_mapping[0] = PCM_CHANNEL_FC;
2208 channel_mapping[1] = PCM_CHANNEL_FL;
2209 channel_mapping[2] = PCM_CHANNEL_FR;
2210 channel_mapping[3] = PCM_CHANNEL_LB;
2211 channel_mapping[4] = PCM_CHANNEL_RB;
2212 channel_mapping[5] = PCM_CHANNEL_LFE;
2213 } else {
2214 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
2215 channels);
2216 return -EINVAL;
2217 }
2218
2219 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2220 if (rc < 0) {
2221 pr_err("%s:Comamnd open failed\n", __func__);
2222 goto fail_cmd;
2223 }
2224 rc = wait_event_timeout(ac->cmd_wait,
2225 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2226 if (!rc) {
2227 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2228 goto fail_cmd;
2229 }
2230 return 0;
2231fail_cmd:
2232 return -EINVAL;
2233}
2234
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002235int q6asm_media_format_block_aac(struct audio_client *ac,
2236 struct asm_aac_cfg *cfg)
2237{
2238 struct asm_stream_media_format_update fmt;
2239 int rc = 0;
2240
2241 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2242 cfg->sample_rate, cfg->ch_cfg);
2243
2244 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2245
2246 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2247
2248 fmt.format = MPEG4_AAC;
2249 fmt.cfg_size = sizeof(struct asm_aac_cfg);
2250 fmt.write_cfg.aac_cfg.format = cfg->format;
2251 fmt.write_cfg.aac_cfg.aot = cfg->aot;
2252 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
2253 fmt.write_cfg.aac_cfg.section_data_resilience =
2254 cfg->section_data_resilience;
2255 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2256 cfg->scalefactor_data_resilience;
2257 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2258 cfg->spectral_data_resilience;
2259 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2260 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2261 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2262 __func__, fmt.format, fmt.cfg_size,
2263 fmt.write_cfg.aac_cfg.format,
2264 fmt.write_cfg.aac_cfg.aot,
2265 fmt.write_cfg.aac_cfg.ch_cfg,
2266 fmt.write_cfg.aac_cfg.sample_rate);
2267 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2268 if (rc < 0) {
2269 pr_err("%s:Comamnd open failed\n", __func__);
2270 goto fail_cmd;
2271 }
2272 rc = wait_event_timeout(ac->cmd_wait,
2273 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2274 if (!rc) {
2275 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2276 goto fail_cmd;
2277 }
2278 return 0;
2279fail_cmd:
2280 return -EINVAL;
2281}
2282
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07002283
2284int q6asm_media_format_block_multi_aac(struct audio_client *ac,
2285 struct asm_aac_cfg *cfg)
2286{
2287 struct asm_stream_media_format_update fmt;
2288 int rc = 0;
2289
2290 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2291 cfg->sample_rate, cfg->ch_cfg);
2292
2293 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2294
2295 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2296
2297 fmt.format = MPEG4_MULTI_AAC;
2298 fmt.cfg_size = sizeof(struct asm_aac_cfg);
2299 fmt.write_cfg.aac_cfg.format = cfg->format;
2300 fmt.write_cfg.aac_cfg.aot = cfg->aot;
2301 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
2302 fmt.write_cfg.aac_cfg.section_data_resilience =
2303 cfg->section_data_resilience;
2304 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2305 cfg->scalefactor_data_resilience;
2306 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2307 cfg->spectral_data_resilience;
2308 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2309 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2310 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2311 __func__, fmt.format, fmt.cfg_size,
2312 fmt.write_cfg.aac_cfg.format,
2313 fmt.write_cfg.aac_cfg.aot,
2314 fmt.write_cfg.aac_cfg.ch_cfg,
2315 fmt.write_cfg.aac_cfg.sample_rate);
2316 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2317 if (rc < 0) {
2318 pr_err("%s:Comamnd open failed\n", __func__);
2319 goto fail_cmd;
2320 }
2321 rc = wait_event_timeout(ac->cmd_wait,
2322 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2323 if (!rc) {
2324 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2325 goto fail_cmd;
2326 }
2327 return 0;
2328fail_cmd:
2329 return -EINVAL;
2330}
2331
2332
Alex Wong2caeecc2011-10-28 10:52:15 +05302333
2334int q6asm_media_format_block(struct audio_client *ac, uint32_t format)
2335{
2336
2337 struct asm_stream_media_format_update fmt;
2338 int rc = 0;
2339
2340 pr_debug("%s:session[%d] format[0x%x]\n", __func__,
2341 ac->session, format);
2342
2343 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2344 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302345 switch (format) {
2346 case FORMAT_V13K:
2347 fmt.format = V13K_FS;
2348 break;
2349 case FORMAT_EVRC:
2350 fmt.format = EVRC_FS;
2351 break;
2352 case FORMAT_AMRWB:
2353 fmt.format = AMRWB_FS;
2354 break;
2355 case FORMAT_AMRNB:
2356 fmt.format = AMRNB_FS;
2357 break;
2358 case FORMAT_MP3:
2359 fmt.format = MP3;
2360 break;
Srikanth Uyyala66f781a2012-06-13 23:23:25 +05302361 case FORMAT_DTS:
2362 fmt.format = DTS;
2363 break;
2364 case FORMAT_DTS_LBR:
2365 fmt.format = DTS_LBR;
2366 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302367 default:
2368 pr_err("Invalid format[%d]\n", format);
2369 goto fail_cmd;
2370 }
Alex Wong2caeecc2011-10-28 10:52:15 +05302371 fmt.cfg_size = 0;
2372
2373 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2374 if (rc < 0) {
2375 pr_err("%s:Comamnd open failed\n", __func__);
2376 goto fail_cmd;
2377 }
2378 rc = wait_event_timeout(ac->cmd_wait,
2379 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2380 if (!rc) {
2381 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2382 goto fail_cmd;
2383 }
2384 return 0;
2385fail_cmd:
2386 return -EINVAL;
2387}
2388
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002389int q6asm_media_format_block_wma(struct audio_client *ac,
2390 void *cfg)
2391{
2392 struct asm_stream_media_format_update fmt;
2393 struct asm_wma_cfg *wma_cfg = (struct asm_wma_cfg *)cfg;
2394 int rc = 0;
2395
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002396 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 -07002397 ac->session, wma_cfg->format_tag, wma_cfg->sample_rate,
2398 wma_cfg->ch_cfg, wma_cfg->avg_bytes_per_sec,
2399 wma_cfg->block_align, wma_cfg->valid_bits_per_sample,
2400 wma_cfg->ch_mask, wma_cfg->encode_opt);
2401
2402 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2403
2404 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2405
2406 fmt.format = WMA_V9;
2407 fmt.cfg_size = sizeof(struct asm_wma_cfg);
2408 fmt.write_cfg.wma_cfg.format_tag = wma_cfg->format_tag;
2409 fmt.write_cfg.wma_cfg.ch_cfg = wma_cfg->ch_cfg;
2410 fmt.write_cfg.wma_cfg.sample_rate = wma_cfg->sample_rate;
2411 fmt.write_cfg.wma_cfg.avg_bytes_per_sec = wma_cfg->avg_bytes_per_sec;
2412 fmt.write_cfg.wma_cfg.block_align = wma_cfg->block_align;
2413 fmt.write_cfg.wma_cfg.valid_bits_per_sample =
2414 wma_cfg->valid_bits_per_sample;
2415 fmt.write_cfg.wma_cfg.ch_mask = wma_cfg->ch_mask;
2416 fmt.write_cfg.wma_cfg.encode_opt = wma_cfg->encode_opt;
2417 fmt.write_cfg.wma_cfg.adv_encode_opt = 0;
2418 fmt.write_cfg.wma_cfg.adv_encode_opt2 = 0;
2419 fmt.write_cfg.wma_cfg.drc_peak_ref = 0;
2420 fmt.write_cfg.wma_cfg.drc_peak_target = 0;
2421 fmt.write_cfg.wma_cfg.drc_ave_ref = 0;
2422 fmt.write_cfg.wma_cfg.drc_ave_target = 0;
2423
2424 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2425 if (rc < 0) {
2426 pr_err("%s:Comamnd open failed\n", __func__);
2427 goto fail_cmd;
2428 }
2429 rc = wait_event_timeout(ac->cmd_wait,
2430 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2431 if (!rc) {
2432 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2433 goto fail_cmd;
2434 }
2435 return 0;
2436fail_cmd:
2437 return -EINVAL;
2438}
2439
2440int q6asm_media_format_block_wmapro(struct audio_client *ac,
2441 void *cfg)
2442{
2443 struct asm_stream_media_format_update fmt;
2444 struct asm_wmapro_cfg *wmapro_cfg = (struct asm_wmapro_cfg *)cfg;
2445 int rc = 0;
2446
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002447 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 -07002448 ac->session, wmapro_cfg->format_tag, wmapro_cfg->sample_rate,
2449 wmapro_cfg->ch_cfg, wmapro_cfg->avg_bytes_per_sec,
2450 wmapro_cfg->block_align, wmapro_cfg->valid_bits_per_sample,
2451 wmapro_cfg->ch_mask, wmapro_cfg->encode_opt,
2452 wmapro_cfg->adv_encode_opt, wmapro_cfg->adv_encode_opt2);
2453
2454 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2455
2456 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2457
2458 fmt.format = WMA_V10PRO;
2459 fmt.cfg_size = sizeof(struct asm_wmapro_cfg);
2460 fmt.write_cfg.wmapro_cfg.format_tag = wmapro_cfg->format_tag;
2461 fmt.write_cfg.wmapro_cfg.ch_cfg = wmapro_cfg->ch_cfg;
2462 fmt.write_cfg.wmapro_cfg.sample_rate = wmapro_cfg->sample_rate;
2463 fmt.write_cfg.wmapro_cfg.avg_bytes_per_sec =
2464 wmapro_cfg->avg_bytes_per_sec;
2465 fmt.write_cfg.wmapro_cfg.block_align = wmapro_cfg->block_align;
2466 fmt.write_cfg.wmapro_cfg.valid_bits_per_sample =
2467 wmapro_cfg->valid_bits_per_sample;
2468 fmt.write_cfg.wmapro_cfg.ch_mask = wmapro_cfg->ch_mask;
2469 fmt.write_cfg.wmapro_cfg.encode_opt = wmapro_cfg->encode_opt;
2470 fmt.write_cfg.wmapro_cfg.adv_encode_opt = wmapro_cfg->adv_encode_opt;
2471 fmt.write_cfg.wmapro_cfg.adv_encode_opt2 = wmapro_cfg->adv_encode_opt2;
2472 fmt.write_cfg.wmapro_cfg.drc_peak_ref = 0;
2473 fmt.write_cfg.wmapro_cfg.drc_peak_target = 0;
2474 fmt.write_cfg.wmapro_cfg.drc_ave_ref = 0;
2475 fmt.write_cfg.wmapro_cfg.drc_ave_target = 0;
2476
2477 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2478 if (rc < 0) {
2479 pr_err("%s:Comamnd open failed\n", __func__);
2480 goto fail_cmd;
2481 }
2482 rc = wait_event_timeout(ac->cmd_wait,
2483 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2484 if (!rc) {
2485 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2486 goto fail_cmd;
2487 }
2488 return 0;
2489fail_cmd:
2490 return -EINVAL;
2491}
2492
2493int q6asm_memory_map(struct audio_client *ac, uint32_t buf_add, int dir,
2494 uint32_t bufsz, uint32_t bufcnt)
2495{
2496 struct asm_stream_cmd_memory_map mem_map;
2497 int rc = 0;
2498
2499 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2500 pr_err("APR handle NULL\n");
2501 return -EINVAL;
2502 }
2503
2504 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2505
2506 mem_map.hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP;
2507
2508 mem_map.buf_add = buf_add;
2509 mem_map.buf_size = bufsz * bufcnt;
2510 mem_map.mempool_id = 0; /* EBI */
2511 mem_map.reserved = 0;
2512
2513 q6asm_add_mmaphdr(&mem_map.hdr,
2514 sizeof(struct asm_stream_cmd_memory_map), TRUE);
2515
2516 pr_debug("buf add[%x] buf_add_parameter[%x]\n",
2517 mem_map.buf_add, buf_add);
2518
2519 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_map);
2520 if (rc < 0) {
2521 pr_err("mem_map op[0x%x]rc[%d]\n",
2522 mem_map.hdr.opcode, rc);
2523 rc = -EINVAL;
2524 goto fail_cmd;
2525 }
2526
2527 rc = wait_event_timeout(this_mmap.cmd_wait,
2528 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2529 if (!rc) {
2530 pr_err("timeout. waited for memory_map\n");
2531 rc = -EINVAL;
2532 goto fail_cmd;
2533 }
2534 rc = 0;
2535fail_cmd:
2536 return rc;
2537}
2538
2539int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add, int dir)
2540{
2541 struct asm_stream_cmd_memory_unmap mem_unmap;
2542 int rc = 0;
2543
2544 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2545 pr_err("APR handle NULL\n");
2546 return -EINVAL;
2547 }
2548 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2549
2550 q6asm_add_mmaphdr(&mem_unmap.hdr,
2551 sizeof(struct asm_stream_cmd_memory_unmap), TRUE);
2552 mem_unmap.hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP;
2553 mem_unmap.buf_add = buf_add;
2554
2555 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_unmap);
2556 if (rc < 0) {
2557 pr_err("mem_unmap op[0x%x]rc[%d]\n",
2558 mem_unmap.hdr.opcode, rc);
2559 rc = -EINVAL;
2560 goto fail_cmd;
2561 }
2562
2563 rc = wait_event_timeout(this_mmap.cmd_wait,
2564 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2565 if (!rc) {
2566 pr_err("timeout. waited for memory_map\n");
2567 rc = -EINVAL;
2568 goto fail_cmd;
2569 }
2570 rc = 0;
2571fail_cmd:
2572 return rc;
2573}
2574
2575int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain)
2576{
2577 void *vol_cmd = NULL;
2578 void *payload = NULL;
2579 struct asm_pp_params_command *cmd = NULL;
2580 struct asm_lrchannel_gain_params *lrgain = NULL;
2581 int sz = 0;
2582 int rc = 0;
2583
2584 sz = sizeof(struct asm_pp_params_command) +
2585 + sizeof(struct asm_lrchannel_gain_params);
2586 vol_cmd = kzalloc(sz, GFP_KERNEL);
2587 if (vol_cmd == NULL) {
2588 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2589 rc = -EINVAL;
2590 return rc;
2591 }
2592 cmd = (struct asm_pp_params_command *)vol_cmd;
2593 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2594 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2595 cmd->payload = NULL;
2596 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2597 sizeof(struct asm_lrchannel_gain_params);
2598 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2599 cmd->params.param_id = L_R_CHANNEL_GAIN_PARAM_ID;
2600 cmd->params.param_size = sizeof(struct asm_lrchannel_gain_params);
2601 cmd->params.reserved = 0;
2602
2603 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2604 lrgain = (struct asm_lrchannel_gain_params *)payload;
2605
2606 lrgain->left_gain = left_gain;
2607 lrgain->right_gain = right_gain;
2608 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2609 if (rc < 0) {
2610 pr_err("%s: Volume Command failed\n", __func__);
2611 rc = -EINVAL;
2612 goto fail_cmd;
2613 }
2614
2615 rc = wait_event_timeout(ac->cmd_wait,
2616 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2617 if (!rc) {
2618 pr_err("%s: timeout in sending volume command to apr\n",
2619 __func__);
2620 rc = -EINVAL;
2621 goto fail_cmd;
2622 }
2623 rc = 0;
2624fail_cmd:
2625 kfree(vol_cmd);
2626 return rc;
2627}
2628
2629static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
2630 uint32_t bufsz, uint32_t bufcnt)
2631{
2632 struct asm_stream_cmd_memory_map_regions *mmap_regions = NULL;
2633 struct asm_memory_map_regions *mregions = NULL;
2634 struct audio_port_data *port = NULL;
2635 struct audio_buffer *ab = NULL;
2636 void *mmap_region_cmd = NULL;
2637 void *payload = NULL;
2638 int rc = 0;
2639 int i = 0;
2640 int cmd_size = 0;
2641
2642 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2643 pr_err("APR handle NULL\n");
2644 return -EINVAL;
2645 }
2646 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2647
2648 cmd_size = sizeof(struct asm_stream_cmd_memory_map_regions)
2649 + sizeof(struct asm_memory_map_regions) * bufcnt;
2650
2651 mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302652 if (mmap_region_cmd == NULL) {
2653 pr_err("%s: Mem alloc failed\n", __func__);
2654 rc = -EINVAL;
2655 return rc;
2656 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002657 mmap_regions = (struct asm_stream_cmd_memory_map_regions *)
2658 mmap_region_cmd;
2659 q6asm_add_mmaphdr(&mmap_regions->hdr, cmd_size, TRUE);
2660 mmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP_REGIONS;
2661 mmap_regions->mempool_id = 0;
2662 mmap_regions->nregions = bufcnt & 0x00ff;
2663 pr_debug("map_regions->nregions = %d\n", mmap_regions->nregions);
2664 payload = ((u8 *) mmap_region_cmd +
2665 sizeof(struct asm_stream_cmd_memory_map_regions));
2666 mregions = (struct asm_memory_map_regions *)payload;
2667
2668 port = &ac->port[dir];
2669 for (i = 0; i < bufcnt; i++) {
2670 ab = &port->buf[i];
2671 mregions->phys = ab->phys;
2672 mregions->buf_size = ab->size;
2673 ++mregions;
2674 }
2675
2676 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) mmap_region_cmd);
2677 if (rc < 0) {
2678 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2679 mmap_regions->hdr.opcode, rc);
2680 rc = -EINVAL;
2681 goto fail_cmd;
2682 }
2683
2684 rc = wait_event_timeout(this_mmap.cmd_wait,
2685 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2686 if (!rc) {
2687 pr_err("timeout. waited for memory_map\n");
2688 rc = -EINVAL;
2689 goto fail_cmd;
2690 }
2691 rc = 0;
2692fail_cmd:
2693 kfree(mmap_region_cmd);
2694 return rc;
2695}
2696
2697static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir,
2698 uint32_t bufsz, uint32_t bufcnt)
2699{
2700 struct asm_stream_cmd_memory_unmap_regions *unmap_regions = NULL;
2701 struct asm_memory_unmap_regions *mregions = NULL;
2702 struct audio_port_data *port = NULL;
2703 struct audio_buffer *ab = NULL;
2704 void *unmap_region_cmd = NULL;
2705 void *payload = NULL;
2706 int rc = 0;
2707 int i = 0;
2708 int cmd_size = 0;
2709
2710 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2711 pr_err("APR handle NULL\n");
2712 return -EINVAL;
2713 }
2714 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2715
2716 cmd_size = sizeof(struct asm_stream_cmd_memory_unmap_regions) +
2717 sizeof(struct asm_memory_unmap_regions) * bufcnt;
2718
2719 unmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302720 if (unmap_region_cmd == NULL) {
2721 pr_err("%s: Mem alloc failed\n", __func__);
2722 rc = -EINVAL;
2723 return rc;
2724 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002725 unmap_regions = (struct asm_stream_cmd_memory_unmap_regions *)
2726 unmap_region_cmd;
2727 q6asm_add_mmaphdr(&unmap_regions->hdr, cmd_size, TRUE);
2728 unmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS;
2729 unmap_regions->nregions = bufcnt & 0x00ff;
2730 pr_debug("unmap_regions->nregions = %d\n", unmap_regions->nregions);
2731 payload = ((u8 *) unmap_region_cmd +
2732 sizeof(struct asm_stream_cmd_memory_unmap_regions));
2733 mregions = (struct asm_memory_unmap_regions *)payload;
2734 port = &ac->port[dir];
2735 for (i = 0; i < bufcnt; i++) {
2736 ab = &port->buf[i];
2737 mregions->phys = ab->phys;
2738 ++mregions;
2739 }
2740
2741 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) unmap_region_cmd);
2742 if (rc < 0) {
2743 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2744 unmap_regions->hdr.opcode, rc);
2745 goto fail_cmd;
2746 }
2747
2748 rc = wait_event_timeout(this_mmap.cmd_wait,
2749 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2750 if (!rc) {
2751 pr_err("timeout. waited for memory_unmap\n");
2752 goto fail_cmd;
2753 }
2754 rc = 0;
2755
2756fail_cmd:
2757 kfree(unmap_region_cmd);
2758 return rc;
2759}
2760
2761int q6asm_set_mute(struct audio_client *ac, int muteflag)
2762{
2763 void *vol_cmd = NULL;
2764 void *payload = NULL;
2765 struct asm_pp_params_command *cmd = NULL;
2766 struct asm_mute_params *mute = NULL;
2767 int sz = 0;
2768 int rc = 0;
2769
2770 sz = sizeof(struct asm_pp_params_command) +
2771 + sizeof(struct asm_mute_params);
2772 vol_cmd = kzalloc(sz, GFP_KERNEL);
2773 if (vol_cmd == NULL) {
2774 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2775 rc = -EINVAL;
2776 return rc;
2777 }
2778 cmd = (struct asm_pp_params_command *)vol_cmd;
2779 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2780 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2781 cmd->payload = NULL;
2782 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2783 sizeof(struct asm_mute_params);
2784 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2785 cmd->params.param_id = MUTE_CONFIG_PARAM_ID;
2786 cmd->params.param_size = sizeof(struct asm_mute_params);
2787 cmd->params.reserved = 0;
2788
2789 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2790 mute = (struct asm_mute_params *)payload;
2791
2792 mute->muteflag = muteflag;
2793 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2794 if (rc < 0) {
2795 pr_err("%s: Mute Command failed\n", __func__);
2796 rc = -EINVAL;
2797 goto fail_cmd;
2798 }
2799
2800 rc = wait_event_timeout(ac->cmd_wait,
2801 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2802 if (!rc) {
2803 pr_err("%s: timeout in sending mute command to apr\n",
2804 __func__);
2805 rc = -EINVAL;
2806 goto fail_cmd;
2807 }
2808 rc = 0;
2809fail_cmd:
2810 kfree(vol_cmd);
2811 return rc;
2812}
2813
2814int q6asm_set_volume(struct audio_client *ac, int volume)
2815{
2816 void *vol_cmd = NULL;
2817 void *payload = NULL;
2818 struct asm_pp_params_command *cmd = NULL;
2819 struct asm_master_gain_params *mgain = NULL;
2820 int sz = 0;
2821 int rc = 0;
2822
2823 sz = sizeof(struct asm_pp_params_command) +
2824 + sizeof(struct asm_master_gain_params);
2825 vol_cmd = kzalloc(sz, GFP_KERNEL);
2826 if (vol_cmd == NULL) {
2827 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2828 rc = -EINVAL;
2829 return rc;
2830 }
2831 cmd = (struct asm_pp_params_command *)vol_cmd;
2832 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2833 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2834 cmd->payload = NULL;
2835 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2836 sizeof(struct asm_master_gain_params);
2837 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2838 cmd->params.param_id = MASTER_GAIN_PARAM_ID;
2839 cmd->params.param_size = sizeof(struct asm_master_gain_params);
2840 cmd->params.reserved = 0;
2841
2842 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2843 mgain = (struct asm_master_gain_params *)payload;
2844
2845 mgain->master_gain = volume;
2846 mgain->padding = 0x00;
2847 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2848 if (rc < 0) {
2849 pr_err("%s: Volume Command failed\n", __func__);
2850 rc = -EINVAL;
2851 goto fail_cmd;
2852 }
2853
2854 rc = wait_event_timeout(ac->cmd_wait,
2855 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2856 if (!rc) {
2857 pr_err("%s: timeout in sending volume command to apr\n",
2858 __func__);
2859 rc = -EINVAL;
2860 goto fail_cmd;
2861 }
2862 rc = 0;
2863fail_cmd:
2864 kfree(vol_cmd);
2865 return rc;
2866}
2867
2868int q6asm_set_softpause(struct audio_client *ac,
2869 struct asm_softpause_params *pause_param)
2870{
2871 void *vol_cmd = NULL;
2872 void *payload = NULL;
2873 struct asm_pp_params_command *cmd = NULL;
2874 struct asm_softpause_params *params = NULL;
2875 int sz = 0;
2876 int rc = 0;
2877
2878 sz = sizeof(struct asm_pp_params_command) +
2879 + sizeof(struct asm_softpause_params);
2880 vol_cmd = kzalloc(sz, GFP_KERNEL);
2881 if (vol_cmd == NULL) {
2882 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2883 rc = -EINVAL;
2884 return rc;
2885 }
2886 cmd = (struct asm_pp_params_command *)vol_cmd;
2887 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2888 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2889 cmd->payload = NULL;
2890 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2891 sizeof(struct asm_softpause_params);
2892 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2893 cmd->params.param_id = SOFT_PAUSE_PARAM_ID;
2894 cmd->params.param_size = sizeof(struct asm_softpause_params);
2895 cmd->params.reserved = 0;
2896
2897 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2898 params = (struct asm_softpause_params *)payload;
2899
2900 params->enable = pause_param->enable;
2901 params->period = pause_param->period;
2902 params->step = pause_param->step;
2903 params->rampingcurve = pause_param->rampingcurve;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002904 pr_debug("%s: soft Pause Command: enable = %d, period = %d, step = %d, curve = %d\n",
2905 __func__, params->enable,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002906 params->period, params->step, params->rampingcurve);
2907 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2908 if (rc < 0) {
2909 pr_err("%s: Volume Command(soft_pause) failed\n", __func__);
2910 rc = -EINVAL;
2911 goto fail_cmd;
2912 }
2913
2914 rc = wait_event_timeout(ac->cmd_wait,
2915 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2916 if (!rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002917 pr_err("%s: timeout in sending volume command(soft_pause) to apr\n",
2918 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002919 rc = -EINVAL;
2920 goto fail_cmd;
2921 }
2922 rc = 0;
2923fail_cmd:
2924 kfree(vol_cmd);
2925 return rc;
2926}
2927
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07002928int q6asm_set_softvolume(struct audio_client *ac,
2929 struct asm_softvolume_params *softvol_param)
2930{
2931 void *vol_cmd = NULL;
2932 void *payload = NULL;
2933 struct asm_pp_params_command *cmd = NULL;
2934 struct asm_softvolume_params *params = NULL;
2935 int sz = 0;
2936 int rc = 0;
2937
2938 sz = sizeof(struct asm_pp_params_command) +
2939 + sizeof(struct asm_softvolume_params);
2940 vol_cmd = kzalloc(sz, GFP_KERNEL);
2941 if (vol_cmd == NULL) {
2942 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2943 rc = -EINVAL;
2944 return rc;
2945 }
2946 cmd = (struct asm_pp_params_command *)vol_cmd;
2947 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2948 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2949 cmd->payload = NULL;
2950 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2951 sizeof(struct asm_softvolume_params);
2952 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2953 cmd->params.param_id = SOFT_VOLUME_PARAM_ID;
2954 cmd->params.param_size = sizeof(struct asm_softvolume_params);
2955 cmd->params.reserved = 0;
2956
2957 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2958 params = (struct asm_softvolume_params *)payload;
2959
2960 params->period = softvol_param->period;
2961 params->step = softvol_param->step;
2962 params->rampingcurve = softvol_param->rampingcurve;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002963 pr_debug("%s: soft Volume:opcode = %d,payload_sz =%d,module_id =%d, param_id = %d, param_sz = %d\n",
2964 __func__,
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07002965 cmd->hdr.opcode, cmd->payload_size,
2966 cmd->params.module_id, cmd->params.param_id,
2967 cmd->params.param_size);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002968 pr_debug("%s: soft Volume Command: period = %d, step = %d, curve = %d\n",
2969 __func__, params->period,
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07002970 params->step, params->rampingcurve);
2971 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2972 if (rc < 0) {
2973 pr_err("%s: Volume Command(soft_volume) failed\n", __func__);
2974 rc = -EINVAL;
2975 goto fail_cmd;
2976 }
2977
2978 rc = wait_event_timeout(ac->cmd_wait,
2979 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2980 if (!rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002981 pr_err("%s: timeout in sending volume command(soft_volume) to apr\n",
2982 __func__);
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07002983 rc = -EINVAL;
2984 goto fail_cmd;
2985 }
2986 rc = 0;
2987fail_cmd:
2988 kfree(vol_cmd);
2989 return rc;
2990}
2991
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002992int q6asm_equalizer(struct audio_client *ac, void *eq)
2993{
2994 void *eq_cmd = NULL;
2995 void *payload = NULL;
2996 struct asm_pp_params_command *cmd = NULL;
2997 struct asm_equalizer_params *equalizer = NULL;
2998 struct msm_audio_eq_stream_config *eq_params = NULL;
2999 int i = 0;
3000 int sz = 0;
3001 int rc = 0;
3002
3003 sz = sizeof(struct asm_pp_params_command) +
3004 + sizeof(struct asm_equalizer_params);
3005 eq_cmd = kzalloc(sz, GFP_KERNEL);
3006 if (eq_cmd == NULL) {
3007 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3008 rc = -EINVAL;
3009 goto fail_cmd;
3010 }
3011 eq_params = (struct msm_audio_eq_stream_config *) eq;
3012 cmd = (struct asm_pp_params_command *)eq_cmd;
3013 q6asm_add_hdr(ac, &cmd->hdr, sz, TRUE);
3014 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3015 cmd->payload = NULL;
3016 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3017 sizeof(struct asm_equalizer_params);
3018 cmd->params.module_id = EQUALIZER_MODULE_ID;
3019 cmd->params.param_id = EQUALIZER_PARAM_ID;
3020 cmd->params.param_size = sizeof(struct asm_equalizer_params);
3021 cmd->params.reserved = 0;
3022 payload = (u8 *)(eq_cmd + sizeof(struct asm_pp_params_command));
3023 equalizer = (struct asm_equalizer_params *)payload;
3024
3025 equalizer->enable = eq_params->enable;
3026 equalizer->num_bands = eq_params->num_bands;
3027 pr_debug("%s: enable:%d numbands:%d\n", __func__, eq_params->enable,
3028 eq_params->num_bands);
3029 for (i = 0; i < eq_params->num_bands; i++) {
3030 equalizer->eq_bands[i].band_idx =
3031 eq_params->eq_bands[i].band_idx;
3032 equalizer->eq_bands[i].filter_type =
3033 eq_params->eq_bands[i].filter_type;
3034 equalizer->eq_bands[i].center_freq_hz =
3035 eq_params->eq_bands[i].center_freq_hz;
3036 equalizer->eq_bands[i].filter_gain =
3037 eq_params->eq_bands[i].filter_gain;
3038 equalizer->eq_bands[i].q_factor =
3039 eq_params->eq_bands[i].q_factor;
3040 pr_debug("%s: filter_type:%u bandnum:%d\n", __func__,
3041 eq_params->eq_bands[i].filter_type, i);
3042 pr_debug("%s: center_freq_hz:%u bandnum:%d\n", __func__,
3043 eq_params->eq_bands[i].center_freq_hz, i);
3044 pr_debug("%s: filter_gain:%d bandnum:%d\n", __func__,
3045 eq_params->eq_bands[i].filter_gain, i);
3046 pr_debug("%s: q_factor:%d bandnum:%d\n", __func__,
3047 eq_params->eq_bands[i].q_factor, i);
3048 }
3049 rc = apr_send_pkt(ac->apr, (uint32_t *) eq_cmd);
3050 if (rc < 0) {
3051 pr_err("%s: Equalizer Command failed\n", __func__);
3052 rc = -EINVAL;
3053 goto fail_cmd;
3054 }
3055
3056 rc = wait_event_timeout(ac->cmd_wait,
3057 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3058 if (!rc) {
3059 pr_err("%s: timeout in sending equalizer command to apr\n",
3060 __func__);
3061 rc = -EINVAL;
3062 goto fail_cmd;
3063 }
3064 rc = 0;
3065fail_cmd:
3066 kfree(eq_cmd);
3067 return rc;
3068}
3069
3070int q6asm_read(struct audio_client *ac)
3071{
3072 struct asm_stream_cmd_read read;
3073 struct audio_buffer *ab;
3074 int dsp_buf;
3075 struct audio_port_data *port;
3076 int rc;
3077 if (!ac || ac->apr == NULL) {
3078 pr_err("APR handle NULL\n");
3079 return -EINVAL;
3080 }
3081 if (ac->io_mode == SYNC_IO_MODE) {
3082 port = &ac->port[OUT];
3083
3084 q6asm_add_hdr(ac, &read.hdr, sizeof(read), FALSE);
3085
3086 mutex_lock(&port->lock);
3087
3088 dsp_buf = port->dsp_buf;
3089 ab = &port->buf[dsp_buf];
3090
3091 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
3092 __func__,
3093 ac->session,
3094 dsp_buf,
3095 (void *)port->buf[dsp_buf].data,
3096 port->cpu_buf,
3097 (void *)port->buf[port->cpu_buf].phys);
3098
3099 read.hdr.opcode = ASM_DATA_CMD_READ;
3100 read.buf_add = ab->phys;
3101 read.buf_size = ab->size;
3102 read.uid = port->dsp_buf;
3103 read.hdr.token = port->dsp_buf;
3104
3105 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3106 mutex_unlock(&port->lock);
3107 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
3108 read.buf_add,
3109 read.hdr.token,
3110 read.uid);
3111 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3112 if (rc < 0) {
3113 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
3114 goto fail_cmd;
3115 }
3116 return 0;
3117 }
3118fail_cmd:
3119 return -EINVAL;
3120}
3121
3122int q6asm_read_nolock(struct audio_client *ac)
3123{
3124 struct asm_stream_cmd_read read;
3125 struct audio_buffer *ab;
3126 int dsp_buf;
3127 struct audio_port_data *port;
3128 int rc;
3129 if (!ac || ac->apr == NULL) {
3130 pr_err("APR handle NULL\n");
3131 return -EINVAL;
3132 }
3133 if (ac->io_mode == SYNC_IO_MODE) {
3134 port = &ac->port[OUT];
3135
3136 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3137
3138
3139 dsp_buf = port->dsp_buf;
3140 ab = &port->buf[dsp_buf];
3141
3142 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
3143 __func__,
3144 ac->session,
3145 dsp_buf,
3146 (void *)port->buf[dsp_buf].data,
3147 port->cpu_buf,
3148 (void *)port->buf[port->cpu_buf].phys);
3149
3150 read.hdr.opcode = ASM_DATA_CMD_READ;
3151 read.buf_add = ab->phys;
3152 read.buf_size = ab->size;
3153 read.uid = port->dsp_buf;
3154 read.hdr.token = port->dsp_buf;
3155
3156 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3157 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
3158 read.buf_add,
3159 read.hdr.token,
3160 read.uid);
3161 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3162 if (rc < 0) {
3163 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
3164 goto fail_cmd;
3165 }
3166 return 0;
3167 }
3168fail_cmd:
3169 return -EINVAL;
3170}
3171
3172
3173static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
3174 uint32_t pkt_size, uint32_t cmd_flg)
3175{
3176 pr_debug("session=%d pkt size=%d cmd_flg=%d\n", pkt_size, cmd_flg,
3177 ac->session);
3178 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
3179 APR_HDR_LEN(sizeof(struct apr_hdr)),\
3180 APR_PKT_VER);
3181 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
3182 hdr->src_domain = APR_DOMAIN_APPS;
3183 hdr->dest_svc = APR_SVC_ASM;
3184 hdr->dest_domain = APR_DOMAIN_ADSP;
3185 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
3186 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
3187 if (cmd_flg) {
3188 hdr->token = ac->session;
3189 atomic_set(&ac->cmd_state, 1);
3190 }
3191 hdr->pkt_size = pkt_size;
3192 return;
3193}
3194
3195int q6asm_async_write(struct audio_client *ac,
3196 struct audio_aio_write_param *param)
3197{
3198 int rc = 0;
3199 struct asm_stream_cmd_write write;
3200
3201 if (!ac || ac->apr == NULL) {
3202 pr_err("%s: APR handle NULL\n", __func__);
3203 return -EINVAL;
3204 }
3205
3206 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write), FALSE);
3207
3208 /* Pass physical address as token for AIO scheme */
3209 write.hdr.token = param->uid;
3210 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3211 write.buf_add = param->paddr;
3212 write.avail_bytes = param->len;
3213 write.uid = param->uid;
3214 write.msw_ts = param->msw_ts;
3215 write.lsw_ts = param->lsw_ts;
3216 /* Use 0xFF00 for disabling timestamps */
3217 if (param->flags == 0xFF00)
3218 write.uflags = (0x00000000 | (param->flags & 0x800000FF));
3219 else
3220 write.uflags = (0x80000000 | param->flags);
3221
3222 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3223 write.buf_add, write.avail_bytes);
3224
3225 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3226 if (rc < 0) {
3227 pr_debug("[%s] write op[0x%x]rc[%d]\n", __func__,
3228 write.hdr.opcode, rc);
3229 goto fail_cmd;
3230 }
3231 return 0;
3232fail_cmd:
3233 return -EINVAL;
3234}
3235
3236int q6asm_async_read(struct audio_client *ac,
3237 struct audio_aio_read_param *param)
3238{
3239 int rc = 0;
3240 struct asm_stream_cmd_read read;
3241
3242 if (!ac || ac->apr == NULL) {
3243 pr_err("%s: APR handle NULL\n", __func__);
3244 return -EINVAL;
3245 }
3246
3247 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3248
3249 /* Pass physical address as token for AIO scheme */
3250 read.hdr.token = param->paddr;
3251 read.hdr.opcode = ASM_DATA_CMD_READ;
3252 read.buf_add = param->paddr;
3253 read.buf_size = param->len;
3254 read.uid = param->uid;
3255
3256 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3257 read.buf_add, read.buf_size);
3258
3259 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3260 if (rc < 0) {
3261 pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
3262 read.hdr.opcode, rc);
3263 goto fail_cmd;
3264 }
3265 return 0;
3266fail_cmd:
3267 return -EINVAL;
3268}
3269
Subhash Chandra Bose Naripeddy694b7d92012-06-20 20:46:13 -07003270int q6asm_async_read_compressed(struct audio_client *ac,
3271 struct audio_aio_read_param *param)
3272{
3273 int rc = 0;
3274 struct asm_stream_cmd_read read;
3275
3276 if (!ac || ac->apr == NULL) {
3277 pr_err("%s: APR handle NULL\n", __func__);
3278 return -EINVAL;
3279 }
3280
3281 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3282
3283 /* Pass physical address as token for AIO scheme */
3284 read.hdr.token = param->paddr;
3285 read.hdr.opcode = ASM_DATA_CMD_READ_COMPRESSED;
3286 read.buf_add = param->paddr;
3287 read.buf_size = param->len;
3288 read.uid = param->uid;
3289
3290 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3291 read.buf_add, read.buf_size);
3292
3293 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3294 if (rc < 0) {
3295 pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
3296 read.hdr.opcode, rc);
3297 goto fail_cmd;
3298 }
3299 return 0;
3300fail_cmd:
3301 return -EINVAL;
3302}
3303
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003304int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3305 uint32_t lsw_ts, uint32_t flags)
3306{
3307 int rc = 0;
3308 struct asm_stream_cmd_write write;
3309 struct audio_port_data *port;
3310 struct audio_buffer *ab;
3311 int dsp_buf = 0;
3312
3313 if (!ac || ac->apr == NULL) {
3314 pr_err("APR handle NULL\n");
3315 return -EINVAL;
3316 }
3317 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3318 if (ac->io_mode == SYNC_IO_MODE) {
3319 port = &ac->port[IN];
3320
3321 q6asm_add_hdr(ac, &write.hdr, sizeof(write),
3322 FALSE);
3323 mutex_lock(&port->lock);
3324
3325 dsp_buf = port->dsp_buf;
3326 ab = &port->buf[dsp_buf];
3327
3328 write.hdr.token = port->dsp_buf;
3329 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3330 write.buf_add = ab->phys;
3331 write.avail_bytes = len;
3332 write.uid = port->dsp_buf;
3333 write.msw_ts = msw_ts;
3334 write.lsw_ts = lsw_ts;
3335 /* Use 0xFF00 for disabling timestamps */
3336 if (flags == 0xFF00)
3337 write.uflags = (0x00000000 | (flags & 0x800000FF));
3338 else
3339 write.uflags = (0x80000000 | flags);
3340 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3341
3342 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3343 , __func__,
3344 ab->phys,
3345 write.buf_add,
3346 write.hdr.token,
3347 write.uid);
3348 mutex_unlock(&port->lock);
Rajesha Kini3498c932011-07-19 19:58:27 +05303349#ifdef CONFIG_DEBUG_FS
3350 if (out_enable_flag) {
3351 char zero_pattern[2] = {0x00, 0x00};
3352 /* If First two byte is non zero and last two byte
3353 is zero then it is warm output pattern */
3354 if ((strncmp(((char *)ab->data), zero_pattern, 2)) &&
3355 (!strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3356 do_gettimeofday(&out_warm_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003357 pr_debug("WARM:apr_send_pkt at %ld sec %ld microsec\n",
3358 out_warm_tv.tv_sec,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303359 out_warm_tv.tv_usec);
3360 pr_debug("Warm Pattern Matched");
3361 }
3362 /* If First two byte is zero and last two byte is
3363 non zero then it is cont ouput pattern */
3364 else if ((!strncmp(((char *)ab->data), zero_pattern, 2))
3365 && (strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3366 do_gettimeofday(&out_cont_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003367 pr_debug("CONT:apr_send_pkt at %ld sec %ld microsec\n",
3368 out_cont_tv.tv_sec,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303369 out_cont_tv.tv_usec);
3370 pr_debug("Cont Pattern Matched");
3371 }
3372 }
3373#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003374 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3375 if (rc < 0) {
3376 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3377 goto fail_cmd;
3378 }
3379 pr_debug("%s: WRITE SUCCESS\n", __func__);
3380 return 0;
3381 }
3382fail_cmd:
3383 return -EINVAL;
3384}
3385
3386int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3387 uint32_t lsw_ts, uint32_t flags)
3388{
3389 int rc = 0;
3390 struct asm_stream_cmd_write write;
3391 struct audio_port_data *port;
3392 struct audio_buffer *ab;
3393 int dsp_buf = 0;
3394
3395 if (!ac || ac->apr == NULL) {
3396 pr_err("APR handle NULL\n");
3397 return -EINVAL;
3398 }
3399 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3400 if (ac->io_mode == SYNC_IO_MODE) {
3401 port = &ac->port[IN];
3402
3403 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write),
3404 FALSE);
3405
3406 dsp_buf = port->dsp_buf;
3407 ab = &port->buf[dsp_buf];
3408
3409 write.hdr.token = port->dsp_buf;
3410 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3411 write.buf_add = ab->phys;
3412 write.avail_bytes = len;
3413 write.uid = port->dsp_buf;
3414 write.msw_ts = msw_ts;
3415 write.lsw_ts = lsw_ts;
3416 /* Use 0xFF00 for disabling timestamps */
3417 if (flags == 0xFF00)
3418 write.uflags = (0x00000000 | (flags & 0x800000FF));
3419 else
3420 write.uflags = (0x80000000 | flags);
3421 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3422
3423 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3424 , __func__,
3425 ab->phys,
3426 write.buf_add,
3427 write.hdr.token,
3428 write.uid);
3429
3430 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3431 if (rc < 0) {
3432 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3433 goto fail_cmd;
3434 }
3435 pr_debug("%s: WRITE SUCCESS\n", __func__);
3436 return 0;
3437 }
3438fail_cmd:
3439 return -EINVAL;
3440}
3441
3442uint64_t q6asm_get_session_time(struct audio_client *ac)
3443{
3444 struct apr_hdr hdr;
3445 int rc;
3446
3447 if (!ac || ac->apr == NULL) {
3448 pr_err("APR handle NULL\n");
3449 return -EINVAL;
3450 }
Swaminathan Sathappanc7f98992012-07-09 11:07:12 -07003451 q6asm_add_hdr(ac, &hdr, sizeof(hdr), FALSE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003452 hdr.opcode = ASM_SESSION_CMD_GET_SESSION_TIME;
3453 atomic_set(&ac->time_flag, 1);
3454
3455 pr_debug("%s: session[%d]opcode[0x%x]\n", __func__,
3456 ac->session,
3457 hdr.opcode);
3458 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3459 if (rc < 0) {
3460 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3461 goto fail_cmd;
3462 }
3463 rc = wait_event_timeout(ac->time_wait,
3464 (atomic_read(&ac->time_flag) == 0), 5*HZ);
3465 if (!rc) {
3466 pr_err("%s: timeout in getting session time from DSP\n",
3467 __func__);
3468 goto fail_cmd;
3469 }
3470 return ac->time_stamp;
3471
3472fail_cmd:
3473 return -EINVAL;
3474}
3475
3476int q6asm_cmd(struct audio_client *ac, int cmd)
3477{
3478 struct apr_hdr hdr;
3479 int rc;
3480 atomic_t *state;
3481 int cnt = 0;
3482
3483 if (!ac || ac->apr == NULL) {
3484 pr_err("APR handle NULL\n");
3485 return -EINVAL;
3486 }
3487 q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
3488 switch (cmd) {
3489 case CMD_PAUSE:
3490 pr_debug("%s:CMD_PAUSE\n", __func__);
3491 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3492 state = &ac->cmd_state;
3493 break;
3494 case CMD_FLUSH:
3495 pr_debug("%s:CMD_FLUSH\n", __func__);
3496 hdr.opcode = ASM_STREAM_CMD_FLUSH;
3497 state = &ac->cmd_state;
3498 break;
3499 case CMD_OUT_FLUSH:
3500 pr_debug("%s:CMD_OUT_FLUSH\n", __func__);
3501 hdr.opcode = ASM_STREAM_CMD_FLUSH_READBUFS;
3502 state = &ac->cmd_state;
3503 break;
3504 case CMD_EOS:
3505 pr_debug("%s:CMD_EOS\n", __func__);
3506 hdr.opcode = ASM_DATA_CMD_EOS;
3507 atomic_set(&ac->cmd_state, 0);
3508 state = &ac->cmd_state;
3509 break;
3510 case CMD_CLOSE:
3511 pr_debug("%s:CMD_CLOSE\n", __func__);
3512 hdr.opcode = ASM_STREAM_CMD_CLOSE;
3513 state = &ac->cmd_state;
3514 break;
3515 default:
3516 pr_err("Invalid format[%d]\n", cmd);
3517 goto fail_cmd;
3518 }
3519 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3520 ac->session,
3521 hdr.opcode);
3522 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3523 if (rc < 0) {
3524 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3525 goto fail_cmd;
3526 }
3527 rc = wait_event_timeout(ac->cmd_wait, (atomic_read(state) == 0), 5*HZ);
3528 if (!rc) {
3529 pr_err("timeout. waited for response opcode[0x%x]\n",
3530 hdr.opcode);
3531 goto fail_cmd;
3532 }
3533 if (cmd == CMD_FLUSH)
3534 q6asm_reset_buf_state(ac);
3535 if (cmd == CMD_CLOSE) {
3536 /* check if DSP return all buffers */
3537 if (ac->port[IN].buf) {
3538 for (cnt = 0; cnt < ac->port[IN].max_buf_cnt;
3539 cnt++) {
3540 if (ac->port[IN].buf[cnt].used == IN) {
3541 pr_debug("Write Buf[%d] not returned\n",
3542 cnt);
3543 }
3544 }
3545 }
3546 if (ac->port[OUT].buf) {
3547 for (cnt = 0; cnt < ac->port[OUT].max_buf_cnt; cnt++) {
3548 if (ac->port[OUT].buf[cnt].used == OUT) {
3549 pr_debug("Read Buf[%d] not returned\n",
3550 cnt);
3551 }
3552 }
3553 }
3554 }
3555 return 0;
3556fail_cmd:
3557 return -EINVAL;
3558}
3559
3560int q6asm_cmd_nowait(struct audio_client *ac, int cmd)
3561{
3562 struct apr_hdr hdr;
3563 int rc;
3564
3565 if (!ac || ac->apr == NULL) {
3566 pr_err("%s:APR handle NULL\n", __func__);
3567 return -EINVAL;
3568 }
3569 q6asm_add_hdr_async(ac, &hdr, sizeof(hdr), TRUE);
3570 switch (cmd) {
3571 case CMD_PAUSE:
3572 pr_debug("%s:CMD_PAUSE\n", __func__);
3573 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3574 break;
3575 case CMD_EOS:
3576 pr_debug("%s:CMD_EOS\n", __func__);
3577 hdr.opcode = ASM_DATA_CMD_EOS;
3578 break;
3579 default:
3580 pr_err("%s:Invalid format[%d]\n", __func__, cmd);
3581 goto fail_cmd;
3582 }
3583 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3584 ac->session,
3585 hdr.opcode);
Jay Wang0668d1062012-07-11 18:53:21 -07003586
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003587 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3588 if (rc < 0) {
3589 pr_err("%s:Commmand 0x%x failed\n", __func__, hdr.opcode);
3590 goto fail_cmd;
3591 }
Jay Wang0668d1062012-07-11 18:53:21 -07003592 atomic_inc(&ac->nowait_cmd_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003593 return 0;
3594fail_cmd:
3595 return -EINVAL;
3596}
3597
3598static void q6asm_reset_buf_state(struct audio_client *ac)
3599{
3600 int cnt = 0;
3601 int loopcnt = 0;
3602 struct audio_port_data *port = NULL;
3603
3604 if (ac->io_mode == SYNC_IO_MODE) {
3605 mutex_lock(&ac->cmd_lock);
3606 for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
3607 port = &ac->port[loopcnt];
3608 cnt = port->max_buf_cnt - 1;
3609 port->dsp_buf = 0;
3610 port->cpu_buf = 0;
3611 while (cnt >= 0) {
3612 if (!port->buf)
3613 continue;
3614 port->buf[cnt].used = 1;
3615 cnt--;
3616 }
3617 }
3618 mutex_unlock(&ac->cmd_lock);
3619 }
3620}
3621
3622int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable)
3623{
3624 struct asm_stream_cmd_reg_tx_overflow_event tx_overflow;
3625 int rc;
3626
3627 if (!ac || ac->apr == NULL) {
3628 pr_err("APR handle NULL\n");
3629 return -EINVAL;
3630 }
3631 pr_debug("%s:session[%d]enable[%d]\n", __func__,
3632 ac->session, enable);
3633 q6asm_add_hdr(ac, &tx_overflow.hdr, sizeof(tx_overflow), TRUE);
3634
3635 tx_overflow.hdr.opcode = \
3636 ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS;
3637 /* tx overflow event: enable */
3638 tx_overflow.enable = enable;
3639
3640 rc = apr_send_pkt(ac->apr, (uint32_t *) &tx_overflow);
3641 if (rc < 0) {
3642 pr_err("tx overflow op[0x%x]rc[%d]\n", \
3643 tx_overflow.hdr.opcode, rc);
3644 goto fail_cmd;
3645 }
3646 rc = wait_event_timeout(ac->cmd_wait,
3647 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3648 if (!rc) {
3649 pr_err("timeout. waited for tx overflow\n");
3650 goto fail_cmd;
3651 }
3652 return 0;
3653fail_cmd:
3654 return -EINVAL;
3655}
3656
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003657int q6asm_get_apr_service_id(int session_id)
3658{
3659 pr_debug("%s\n", __func__);
3660
Shiv Maliyappanahallia84982a2012-01-19 15:25:04 -08003661 if (session_id < 0 || session_id > SESSION_MAX) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003662 pr_err("%s: invalid session_id = %d\n", __func__, session_id);
3663 return -EINVAL;
3664 }
3665
3666 return ((struct apr_svc *)session[session_id]->apr)->id;
3667}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003668
3669
3670static int __init q6asm_init(void)
3671{
3672 pr_debug("%s\n", __func__);
3673 init_waitqueue_head(&this_mmap.cmd_wait);
3674 memset(session, 0, sizeof(session));
Rajesha Kini3498c932011-07-19 19:58:27 +05303675#ifdef CONFIG_DEBUG_FS
3676 out_buffer = kmalloc(OUT_BUFFER_SIZE, GFP_KERNEL);
3677 out_dentry = debugfs_create_file("audio_out_latency_measurement_node",\
3678 S_IFREG | S_IRUGO | S_IWUGO,\
3679 NULL, NULL, &audio_output_latency_debug_fops);
3680 if (IS_ERR(out_dentry))
3681 pr_err("debugfs_create_file failed\n");
3682 in_buffer = kmalloc(IN_BUFFER_SIZE, GFP_KERNEL);
3683 in_dentry = debugfs_create_file("audio_in_latency_measurement_node",\
3684 S_IFREG | S_IRUGO | S_IWUGO,\
3685 NULL, NULL, &audio_input_latency_debug_fops);
3686 if (IS_ERR(in_dentry))
3687 pr_err("debugfs_create_file failed\n");
3688#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003689 return 0;
3690}
3691
3692device_initcall(q6asm_init);