blob: f07da1aeb68a64a4225956e2d8d96b720e03f15b [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;
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700212 ac->perf_mode = false;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700213 return;
214}
215
216int q6asm_audio_client_buf_free(unsigned int dir,
217 struct audio_client *ac)
218{
219 struct audio_port_data *port;
220 int cnt = 0;
221 int rc = 0;
222 pr_debug("%s: Session id %d\n", __func__, ac->session);
223 mutex_lock(&ac->cmd_lock);
224 if (ac->io_mode == SYNC_IO_MODE) {
225 port = &ac->port[dir];
226 if (!port->buf) {
227 mutex_unlock(&ac->cmd_lock);
228 return 0;
229 }
230 cnt = port->max_buf_cnt - 1;
231
232 if (cnt >= 0) {
233 rc = q6asm_memory_unmap_regions(ac, dir,
234 port->buf[0].size,
235 port->max_buf_cnt);
236 if (rc < 0)
237 pr_err("%s CMD Memory_unmap_regions failed\n",
238 __func__);
239 }
240
241 while (cnt >= 0) {
242 if (port->buf[cnt].data) {
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800243#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
244 ion_unmap_kernel(port->buf[cnt].client,
245 port->buf[cnt].handle);
246 ion_free(port->buf[cnt].client,
247 port->buf[cnt].handle);
248 ion_client_destroy(port->buf[cnt].client);
249#else
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700250 pr_debug("%s:data[%p]phys[%p][%p] cnt[%d] mem_buffer[%p]\n",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700251 __func__, (void *)port->buf[cnt].data,
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700252 (void *)port->buf[cnt].phys,
253 (void *)&port->buf[cnt].phys, cnt,
254 (void *)port->buf[cnt].mem_buffer);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700255 if (IS_ERR((void *)port->buf[cnt].mem_buffer))
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700256 pr_err("%s:mem buffer invalid, error = %ld\n",
257 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700258 PTR_ERR((void *)port->buf[cnt].mem_buffer));
259 else {
Laura Abbottea3e7b62012-04-30 15:59:21 -0700260 if (iounmap(
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700261 port->buf[cnt].mem_buffer) < 0)
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700262 pr_err("%s: unmap buffer failed\n",
263 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700264 }
265 free_contiguous_memory_by_paddr(
266 port->buf[cnt].phys);
267
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800268#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700269 port->buf[cnt].data = NULL;
270 port->buf[cnt].phys = 0;
271 --(port->max_buf_cnt);
272 }
273 --cnt;
274 }
275 kfree(port->buf);
276 port->buf = NULL;
277 }
278 mutex_unlock(&ac->cmd_lock);
279 return 0;
280}
281
282int q6asm_audio_client_buf_free_contiguous(unsigned int dir,
283 struct audio_client *ac)
284{
285 struct audio_port_data *port;
286 int cnt = 0;
287 int rc = 0;
288 pr_debug("%s: Session id %d\n", __func__, ac->session);
289 mutex_lock(&ac->cmd_lock);
290 port = &ac->port[dir];
291 if (!port->buf) {
292 mutex_unlock(&ac->cmd_lock);
293 return 0;
294 }
295 cnt = port->max_buf_cnt - 1;
296
297 if (cnt >= 0) {
Deepa Madiregama7d52a402011-07-13 20:28:36 +0530298 rc = q6asm_memory_unmap(ac, port->buf[0].phys, dir);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700299 if (rc < 0)
300 pr_err("%s CMD Memory_unmap_regions failed\n",
301 __func__);
302 }
303
304 if (port->buf[0].data) {
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800305#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
306 ion_unmap_kernel(port->buf[0].client, port->buf[0].handle);
307 ion_free(port->buf[0].client, port->buf[0].handle);
308 ion_client_destroy(port->buf[0].client);
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700309 pr_debug("%s:data[%p]phys[%p][%p], client[%p] handle[%p]\n",
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800310 __func__,
311 (void *)port->buf[0].data,
312 (void *)port->buf[0].phys,
313 (void *)&port->buf[0].phys,
314 (void *)port->buf[0].client,
315 (void *)port->buf[0].handle);
316#else
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700317 pr_debug("%s:data[%p]phys[%p][%p] mem_buffer[%p]\n",
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700318 __func__,
319 (void *)port->buf[0].data,
320 (void *)port->buf[0].phys,
321 (void *)&port->buf[0].phys,
322 (void *)port->buf[0].mem_buffer);
323 if (IS_ERR((void *)port->buf[0].mem_buffer))
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700324 pr_err("%s:mem buffer invalid, error = %ld\n",
325 __func__,
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700326 PTR_ERR((void *)port->buf[0].mem_buffer));
327 else {
Laura Abbottea3e7b62012-04-30 15:59:21 -0700328 if (iounmap(
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700329 port->buf[0].mem_buffer) < 0)
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700330 pr_err("%s: unmap buffer failed\n", __func__);
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700331 }
332 free_contiguous_memory_by_paddr(port->buf[0].phys);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800333#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700334 }
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700335
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700336 while (cnt >= 0) {
337 port->buf[cnt].data = NULL;
338 port->buf[cnt].phys = 0;
339 cnt--;
340 }
341 port->max_buf_cnt = 0;
342 kfree(port->buf);
343 port->buf = NULL;
344 mutex_unlock(&ac->cmd_lock);
345 return 0;
346}
347
348void q6asm_audio_client_free(struct audio_client *ac)
349{
350 int loopcnt;
351 struct audio_port_data *port;
352 if (!ac || !ac->session)
353 return;
354 pr_debug("%s: Session id %d\n", __func__, ac->session);
355 if (ac->io_mode == SYNC_IO_MODE) {
356 for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
357 port = &ac->port[loopcnt];
358 if (!port->buf)
359 continue;
360 pr_debug("%s:loopcnt = %d\n", __func__, loopcnt);
361 q6asm_audio_client_buf_free(loopcnt, ac);
362 }
363 }
364
365 apr_deregister(ac->apr);
366 q6asm_session_free(ac);
367
368 pr_debug("%s: APR De-Register\n", __func__);
369 if (atomic_read(&this_mmap.ref_cnt) <= 0) {
370 pr_err("%s: APR Common Port Already Closed\n", __func__);
371 goto done;
372 }
373
374 atomic_dec(&this_mmap.ref_cnt);
375 if (atomic_read(&this_mmap.ref_cnt) == 0) {
376 apr_deregister(this_mmap.apr);
377 pr_debug("%s:APR De-Register common port\n", __func__);
378 }
379done:
380 kfree(ac);
381 return;
382}
383
384int q6asm_set_io_mode(struct audio_client *ac, uint32_t mode)
385{
386 if (ac == NULL) {
387 pr_err("%s APR handle NULL\n", __func__);
388 return -EINVAL;
389 }
390 if ((mode == ASYNC_IO_MODE) || (mode == SYNC_IO_MODE)) {
391 ac->io_mode = mode;
392 pr_debug("%s:Set Mode to %d\n", __func__, ac->io_mode);
393 return 0;
394 } else {
395 pr_err("%s:Not an valid IO Mode:%d\n", __func__, ac->io_mode);
396 return -EINVAL;
397 }
398}
399
400struct audio_client *q6asm_audio_client_alloc(app_cb cb, void *priv)
401{
402 struct audio_client *ac;
403 int n;
404 int lcnt = 0;
405
406 ac = kzalloc(sizeof(struct audio_client), GFP_KERNEL);
407 if (!ac)
408 return NULL;
409 n = q6asm_session_alloc(ac);
410 if (n <= 0)
411 goto fail_session;
412 ac->session = n;
413 ac->cb = cb;
414 ac->priv = priv;
415 ac->io_mode = SYNC_IO_MODE;
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700416 ac->perf_mode = false;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700417 ac->apr = apr_register("ADSP", "ASM", \
418 (apr_fn)q6asm_callback,\
419 ((ac->session) << 8 | 0x0001),\
420 ac);
421
422 if (ac->apr == NULL) {
423 pr_err("%s Registration with APR failed\n", __func__);
424 goto fail;
425 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700426 rtac_set_asm_handle(n, ac->apr);
Ben Rombergerfce8f512011-07-18 16:46:09 -0700427
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700428 pr_debug("%s Registering the common port with APR\n", __func__);
429 if (atomic_read(&this_mmap.ref_cnt) == 0) {
430 this_mmap.apr = apr_register("ADSP", "ASM", \
431 (apr_fn)q6asm_mmapcallback,\
432 0x0FFFFFFFF, &this_mmap);
433 if (this_mmap.apr == NULL) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700434 pr_debug("%s Unable to register APR ASM common port\n",
435 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700436 goto fail;
437 }
438 }
439
440 atomic_inc(&this_mmap.ref_cnt);
441 init_waitqueue_head(&ac->cmd_wait);
442 init_waitqueue_head(&ac->time_wait);
443 atomic_set(&ac->time_flag, 1);
444 mutex_init(&ac->cmd_lock);
445 for (lcnt = 0; lcnt <= OUT; lcnt++) {
446 mutex_init(&ac->port[lcnt].lock);
447 spin_lock_init(&ac->port[lcnt].dsp_lock);
448 }
449 atomic_set(&ac->cmd_state, 0);
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +0530450 atomic_set(&ac->cmd_response, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700451
452 pr_debug("%s: session[%d]\n", __func__, ac->session);
453
454 return ac;
455fail:
456 q6asm_audio_client_free(ac);
457 return NULL;
458fail_session:
459 kfree(ac);
460 return NULL;
461}
462
Ben Romberger61754dc2011-10-31 18:25:41 -0700463struct audio_client *q6asm_get_audio_client(int session_id)
464{
465 if ((session_id <= 0) || (session_id > SESSION_MAX)) {
466 pr_err("%s: invalid session: %d\n", __func__, session_id);
467 goto err;
468 }
469
470 if (!session[session_id]) {
471 pr_err("%s: session not active: %d\n", __func__, session_id);
472 goto err;
473 }
474
475 return session[session_id];
476err:
477 return NULL;
478}
479
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700480int q6asm_audio_client_buf_alloc(unsigned int dir,
481 struct audio_client *ac,
482 unsigned int bufsz,
483 unsigned int bufcnt)
484{
485 int cnt = 0;
486 int rc = 0;
487 struct audio_buffer *buf;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800488#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
489 int len;
490#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700491
492 if (!(ac) || ((dir != IN) && (dir != OUT)))
493 return -EINVAL;
494
495 pr_debug("%s: session[%d]bufsz[%d]bufcnt[%d]\n", __func__, ac->session,
496 bufsz, bufcnt);
497
498 if (ac->session <= 0 || ac->session > 8)
499 goto fail;
500
501 if (ac->io_mode == SYNC_IO_MODE) {
502 if (ac->port[dir].buf) {
503 pr_debug("%s: buffer already allocated\n", __func__);
504 return 0;
505 }
506 mutex_lock(&ac->cmd_lock);
507 buf = kzalloc(((sizeof(struct audio_buffer))*bufcnt),
508 GFP_KERNEL);
509
510 if (!buf) {
511 mutex_unlock(&ac->cmd_lock);
512 goto fail;
513 }
514
515 ac->port[dir].buf = buf;
516
517 while (cnt < bufcnt) {
518 if (bufsz > 0) {
519 if (!buf[cnt].data) {
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800520#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
521 buf[cnt].client = msm_ion_client_create
522 (UINT_MAX, "audio_client");
523 if (IS_ERR_OR_NULL((void *)
524 buf[cnt].client)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700525 pr_err("%s: ION create client for AUDIO failed\n",
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800526 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700527 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800528 goto fail;
529 }
530 buf[cnt].handle = ion_alloc
531 (buf[cnt].client, bufsz, SZ_4K,
532 (0x1 << ION_AUDIO_HEAP_ID));
533 if (IS_ERR_OR_NULL((void *)
534 buf[cnt].handle)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700535 pr_err("%s: ION memory allocation for AUDIO failed\n",
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800536 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700537 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800538 goto fail;
539 }
540
541 rc = ion_phys(buf[cnt].client,
542 buf[cnt].handle,
543 (ion_phys_addr_t *)
544 &buf[cnt].phys,
545 (size_t *)&len);
546 if (rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700547 pr_err("%s: ION Get Physical for AUDIO failed, rc = %d\n",
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800548 __func__, rc);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700549 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800550 goto fail;
551 }
552
553 buf[cnt].data = ion_map_kernel
554 (buf[cnt].client, buf[cnt].handle,
555 0);
556 if (IS_ERR_OR_NULL((void *)
557 buf[cnt].data)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700558 pr_err("%s: ION memory mapping for AUDIO failed\n",
559 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700560 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800561 goto fail;
562 }
563 memset((void *)buf[cnt].data, 0, bufsz);
564#else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700565 unsigned int flags = 0;
566 buf[cnt].phys =
567 allocate_contiguous_ebi_nomap(bufsz,
568 SZ_4K);
569 if (!buf[cnt].phys) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700570 pr_err("%s:Buf alloc failed size=%d\n",
571 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700572 bufsz);
573 mutex_unlock(&ac->cmd_lock);
574 goto fail;
575 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700576 buf[cnt].mem_buffer =
Laura Abbottea3e7b62012-04-30 15:59:21 -0700577 ioremap(buf[cnt].phys, bufsz);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700578 if (IS_ERR(
579 (void *)buf[cnt].mem_buffer)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700580 pr_err("%s:map_buffer failed, error = %ld\n",
581 __func__,
582 PTR_ERR((void *)buf[cnt].mem_buffer));
Jayasena Sangaraboina466e6b92012-01-17 21:10:55 -0800583 mutex_unlock(&ac->cmd_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700584 goto fail;
585 }
586 buf[cnt].data =
Laura Abbottea3e7b62012-04-30 15:59:21 -0700587 buf[cnt].mem_buffer;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700588 if (!buf[cnt].data) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700589 pr_err("%s:invalid vaddr, iomap failed\n",
590 __func__);
Jayasena Sangaraboina466e6b92012-01-17 21:10:55 -0800591 mutex_unlock(&ac->cmd_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700592 goto fail;
593 }
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800594#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700595 buf[cnt].used = 1;
596 buf[cnt].size = bufsz;
597 buf[cnt].actual_size = bufsz;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800598 pr_debug("%s data[%p]phys[%p][%p]\n",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700599 __func__,
600 (void *)buf[cnt].data,
601 (void *)buf[cnt].phys,
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800602 (void *)&buf[cnt].phys);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700603 cnt++;
604 }
605 }
606 }
607 ac->port[dir].max_buf_cnt = cnt;
608
609 mutex_unlock(&ac->cmd_lock);
610 rc = q6asm_memory_map_regions(ac, dir, bufsz, cnt);
611 if (rc < 0) {
612 pr_err("%s:CMD Memory_map_regions failed\n", __func__);
613 goto fail;
614 }
615 }
616 return 0;
617fail:
618 q6asm_audio_client_buf_free(dir, ac);
619 return -EINVAL;
620}
621
622int q6asm_audio_client_buf_alloc_contiguous(unsigned int dir,
623 struct audio_client *ac,
624 unsigned int bufsz,
625 unsigned int bufcnt)
626{
627 int cnt = 0;
628 int rc = 0;
629 struct audio_buffer *buf;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800630#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
631 int len;
632#else
633 int flags = 0;
634#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700635 if (!(ac) || ((dir != IN) && (dir != OUT)))
636 return -EINVAL;
637
638 pr_debug("%s: session[%d]bufsz[%d]bufcnt[%d]\n",
639 __func__, ac->session,
640 bufsz, bufcnt);
641
642 if (ac->session <= 0 || ac->session > 8)
643 goto fail;
644
645 if (ac->port[dir].buf) {
646 pr_debug("%s: buffer already allocated\n", __func__);
647 return 0;
648 }
649 mutex_lock(&ac->cmd_lock);
650 buf = kzalloc(((sizeof(struct audio_buffer))*bufcnt),
651 GFP_KERNEL);
652
653 if (!buf) {
654 mutex_unlock(&ac->cmd_lock);
655 goto fail;
656 }
657
658 ac->port[dir].buf = buf;
659
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800660#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
661 buf[0].client = msm_ion_client_create(UINT_MAX, "audio_client");
662 if (IS_ERR_OR_NULL((void *)buf[0].client)) {
663 pr_err("%s: ION create client for AUDIO failed\n", __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700664 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800665 goto fail;
666 }
667 buf[0].handle = ion_alloc(buf[0].client, bufsz * bufcnt, SZ_4K,
668 (0x1 << ION_AUDIO_HEAP_ID));
669 if (IS_ERR_OR_NULL((void *) buf[0].handle)) {
670 pr_err("%s: ION memory allocation for AUDIO failed\n",
671 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700672 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800673 goto fail;
674 }
675
676 rc = ion_phys(buf[0].client, buf[0].handle,
677 (ion_phys_addr_t *)&buf[0].phys, (size_t *)&len);
678 if (rc) {
679 pr_err("%s: ION Get Physical for AUDIO failed, rc = %d\n",
680 __func__, rc);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700681 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800682 goto fail;
683 }
684
685 buf[0].data = ion_map_kernel(buf[0].client, buf[0].handle, 0);
686 if (IS_ERR_OR_NULL((void *) buf[0].data)) {
687 pr_err("%s: ION memory mapping for AUDIO failed\n", __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700688 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800689 goto fail;
690 }
691 memset((void *)buf[0].data, 0, (bufsz * bufcnt));
692#else
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700693 buf[0].phys = allocate_contiguous_ebi_nomap(bufsz * bufcnt,
694 SZ_4K);
695 if (!buf[0].phys) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700696 pr_err("%s:Buf alloc failed size=%d, bufcnt=%d\n",
697 __func__, bufsz, bufcnt);
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700698 mutex_unlock(&ac->cmd_lock);
699 goto fail;
700 }
701
Laura Abbottea3e7b62012-04-30 15:59:21 -0700702 buf[0].mem_buffer = ioremap(buf[0].phys, bufsz * bufcnt);
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700703 if (IS_ERR((void *)buf[cnt].mem_buffer)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700704 pr_err("%s:map_buffer failed, error = %ld\n",
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700705 __func__, PTR_ERR((void *)buf[0].mem_buffer));
706
707 mutex_unlock(&ac->cmd_lock);
708 goto fail;
709 }
Laura Abbottea3e7b62012-04-30 15:59:21 -0700710 buf[0].data = buf[0].mem_buffer;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800711#endif
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700712 if (!buf[0].data) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700713 pr_err("%s:invalid vaddr, iomap failed\n", __func__);
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700714 mutex_unlock(&ac->cmd_lock);
715 goto fail;
716 }
717
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700718 buf[0].used = dir ^ 1;
719 buf[0].size = bufsz;
720 buf[0].actual_size = bufsz;
721 cnt = 1;
722 while (cnt < bufcnt) {
723 if (bufsz > 0) {
724 buf[cnt].data = buf[0].data + (cnt * bufsz);
725 buf[cnt].phys = buf[0].phys + (cnt * bufsz);
726 if (!buf[cnt].data) {
727 pr_err("%s Buf alloc failed\n",
728 __func__);
729 mutex_unlock(&ac->cmd_lock);
730 goto fail;
731 }
732 buf[cnt].used = dir ^ 1;
733 buf[cnt].size = bufsz;
734 buf[cnt].actual_size = bufsz;
735 pr_debug("%s data[%p]phys[%p][%p]\n", __func__,
736 (void *)buf[cnt].data,
737 (void *)buf[cnt].phys,
738 (void *)&buf[cnt].phys);
739 }
740 cnt++;
741 }
742 ac->port[dir].max_buf_cnt = cnt;
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -0700743
744 pr_debug("%s ac->port[%d].max_buf_cnt[%d]\n", __func__, dir,
745 ac->port[dir].max_buf_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700746 mutex_unlock(&ac->cmd_lock);
747 rc = q6asm_memory_map(ac, buf[0].phys, dir, bufsz, cnt);
748 if (rc < 0) {
749 pr_err("%s:CMD Memory_map_regions failed\n", __func__);
750 goto fail;
751 }
752 return 0;
753fail:
754 q6asm_audio_client_buf_free_contiguous(dir, ac);
755 return -EINVAL;
756}
757
758static int32_t q6asm_mmapcallback(struct apr_client_data *data, void *priv)
759{
760 uint32_t token;
761 uint32_t *payload = data->payload;
762
763 if (data->opcode == RESET_EVENTS) {
764 pr_debug("%s: Reset event is received: %d %d apr[%p]\n",
765 __func__,
766 data->reset_event,
767 data->reset_proc,
768 this_mmap.apr);
769 apr_reset(this_mmap.apr);
770 this_mmap.apr = NULL;
771 atomic_set(&this_mmap.cmd_state, 0);
772 return 0;
773 }
774
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700775 pr_debug("%s:ptr0[0x%x]ptr1[0x%x]opcode[0x%x] token[0x%x]payload_s[%d] src[%d] dest[%d]\n",
776 __func__, payload[0], payload[1], data->opcode, data->token,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700777 data->payload_size, data->src_port, data->dest_port);
778
779 if (data->opcode == APR_BASIC_RSP_RESULT) {
780 token = data->token;
781 switch (payload[0]) {
782 case ASM_SESSION_CMD_MEMORY_MAP:
783 case ASM_SESSION_CMD_MEMORY_UNMAP:
784 case ASM_SESSION_CMD_MEMORY_MAP_REGIONS:
785 case ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS:
786 pr_debug("%s:command[0x%x]success [0x%x]\n",
787 __func__, payload[0], payload[1]);
788 if (atomic_read(&this_mmap.cmd_state)) {
789 atomic_set(&this_mmap.cmd_state, 0);
790 wake_up(&this_mmap.cmd_wait);
791 }
792 break;
793 default:
794 pr_debug("%s:command[0x%x] not expecting rsp\n",
795 __func__, payload[0]);
796 break;
797 }
798 }
799 return 0;
800}
801
802
803static int32_t q6asm_callback(struct apr_client_data *data, void *priv)
804{
805 int i = 0;
806 struct audio_client *ac = (struct audio_client *)priv;
807 uint32_t token;
808 unsigned long dsp_flags;
809 uint32_t *payload;
Jay Wang0668d1062012-07-11 18:53:21 -0700810 uint32_t wakeup_flag = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700811
812
813 if ((ac == NULL) || (data == NULL)) {
814 pr_err("ac or priv NULL\n");
815 return -EINVAL;
816 }
817 if (ac->session <= 0 || ac->session > 8) {
818 pr_err("%s:Session ID is invalid, session = %d\n", __func__,
819 ac->session);
820 return -EINVAL;
821 }
Jay Wang0668d1062012-07-11 18:53:21 -0700822 if (atomic_read(&ac->nowait_cmd_cnt) > 0) {
823 pr_debug("%s: nowait_cmd_cnt %d\n",
824 __func__,
825 atomic_read(&ac->nowait_cmd_cnt));
826 atomic_dec(&ac->nowait_cmd_cnt);
827 wakeup_flag = 0;
828 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700829 payload = data->payload;
830
831 if (data->opcode == RESET_EVENTS) {
832 pr_debug("q6asm_callback: Reset event is received: %d %d apr[%p]\n",
833 data->reset_event, data->reset_proc, ac->apr);
Laxminath Kasam692c6542012-02-21 11:17:47 +0530834 if (ac->cb)
835 ac->cb(data->opcode, data->token,
836 (uint32_t *)data->payload, ac->priv);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700837 apr_reset(ac->apr);
838 return 0;
839 }
840
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700841 pr_debug("%s: session[%d]opcode[0x%x] token[0x%x]payload_s[%d] src[%d] dest[%d]\n",
842 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700843 ac->session, data->opcode,
844 data->token, data->payload_size, data->src_port,
845 data->dest_port);
846
847 if (data->opcode == APR_BASIC_RSP_RESULT) {
848 token = data->token;
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700849 pr_debug("%s payload[0]:%x", __func__, payload[0]);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700850 switch (payload[0]) {
851 case ASM_STREAM_CMD_SET_PP_PARAMS:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700852 if (rtac_make_asm_callback(ac->session, payload,
853 data->payload_size))
854 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700855 case ASM_SESSION_CMD_PAUSE:
856 case ASM_DATA_CMD_EOS:
857 case ASM_STREAM_CMD_CLOSE:
858 case ASM_STREAM_CMD_FLUSH:
859 case ASM_SESSION_CMD_RUN:
860 case ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS:
861 case ASM_STREAM_CMD_FLUSH_READBUFS:
862 pr_debug("%s:Payload = [0x%x]\n", __func__, payload[0]);
863 if (token != ac->session) {
864 pr_err("%s:Invalid session[%d] rxed expected[%d]",
865 __func__, token, ac->session);
866 return -EINVAL;
867 }
868 case ASM_STREAM_CMD_OPEN_READ:
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700869 case ASM_STREAM_CMD_OPEN_READ_V2_1:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700870 case ASM_STREAM_CMD_OPEN_WRITE:
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700871 case ASM_STREAM_CMD_OPEN_WRITE_V2_1:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700872 case ASM_STREAM_CMD_OPEN_READWRITE:
873 case ASM_DATA_CMD_MEDIA_FORMAT_UPDATE:
874 case ASM_STREAM_CMD_SET_ENCDEC_PARAM:
Santosh Mardi23321202012-03-22 04:33:25 +0530875 case ASM_STREAM_CMD_OPEN_WRITE_COMPRESSED:
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -0700876 case ASM_STREAM_CMD_OPEN_READ_COMPRESSED:
Jay Wang0668d1062012-07-11 18:53:21 -0700877 if (atomic_read(&ac->cmd_state) && wakeup_flag) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700878 atomic_set(&ac->cmd_state, 0);
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700879 if (payload[1] == ADSP_EUNSUPPORTED) {
880 pr_debug("paload[1]:%d unsupported",
881 payload[1]);
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +0530882 atomic_set(&ac->cmd_response, 1);
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700883 }
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +0530884 else
885 atomic_set(&ac->cmd_response, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700886 wake_up(&ac->cmd_wait);
887 }
888 if (ac->cb)
889 ac->cb(data->opcode, data->token,
890 (uint32_t *)data->payload, ac->priv);
891 break;
892 default:
893 pr_debug("%s:command[0x%x] not expecting rsp\n",
894 __func__, payload[0]);
895 break;
896 }
897 return 0;
898 }
899
900 switch (data->opcode) {
901 case ASM_DATA_EVENT_WRITE_DONE:{
902 struct audio_port_data *port = &ac->port[IN];
903 pr_debug("%s: Rxed opcode[0x%x] status[0x%x] token[%d]",
904 __func__, payload[0], payload[1],
905 data->token);
906 if (ac->io_mode == SYNC_IO_MODE) {
907 if (port->buf == NULL) {
908 pr_err("%s: Unexpected Write Done\n",
909 __func__);
910 return -EINVAL;
911 }
912 spin_lock_irqsave(&port->dsp_lock, dsp_flags);
913 if (port->buf[data->token].phys !=
914 payload[0]) {
915 pr_err("Buf expected[%p]rxed[%p]\n",\
916 (void *)port->buf[data->token].phys,\
917 (void *)payload[0]);
918 spin_unlock_irqrestore(&port->dsp_lock,
919 dsp_flags);
920 return -EINVAL;
921 }
922 token = data->token;
923 port->buf[token].used = 1;
924 spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
Rajesha Kini3498c932011-07-19 19:58:27 +0530925#ifdef CONFIG_DEBUG_FS
926 if (out_enable_flag) {
927 /* For first Write done log the time and reset
928 out_cold_index*/
929 if (out_cold_index != 1) {
930 do_gettimeofday(&out_cold_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700931 pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",
932 out_cold_tv.tv_sec,
Rajesha Kini3498c932011-07-19 19:58:27 +0530933 out_cold_tv.tv_usec);
934 out_cold_index = 1;
935 }
936 pr_debug("out_enable_flag %ld",\
937 out_enable_flag);
938 }
939#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700940 for (i = 0; i < port->max_buf_cnt; i++)
941 pr_debug("%d ", port->buf[i].used);
942
943 }
944 break;
945 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700946 case ASM_STREAM_CMDRSP_GET_PP_PARAMS:
947 rtac_make_asm_callback(ac->session, payload,
948 data->payload_size);
949 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700950 case ASM_DATA_EVENT_READ_DONE:{
951
952 struct audio_port_data *port = &ac->port[OUT];
Rajesha Kini3498c932011-07-19 19:58:27 +0530953#ifdef CONFIG_DEBUG_FS
954 if (in_enable_flag) {
955 /* when in_cont_index == 7, DSP would be
956 * writing into the 8th 512 byte buffer and this
957 * timestamp is tapped here.Once done it then writes
958 * to 9th 512 byte buffer.These two buffers(8th, 9th)
959 * reach the test application in 5th iteration and that
960 * timestamp is tapped at user level. The difference
961 * of these two timestamps gives us the time between
962 * the time at which dsp started filling the sample
963 * required and when it reached the test application.
964 * Hence continuous input latency
965 */
966 if (in_cont_index == 7) {
967 do_gettimeofday(&in_cont_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700968 pr_err("In_CONT:previous read buffer done at %ld sec %ld microsec\n",
Sriranjan Srikantam74753532011-10-03 14:48:37 -0700969 in_cont_tv.tv_sec, in_cont_tv.tv_usec);
Rajesha Kini3498c932011-07-19 19:58:27 +0530970 }
971 }
972#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700973 pr_debug("%s:R-D: status=%d buff_add=%x act_size=%d offset=%d\n",
974 __func__, payload[READDONE_IDX_STATUS],
975 payload[READDONE_IDX_BUFFER],
976 payload[READDONE_IDX_SIZE],
977 payload[READDONE_IDX_OFFSET]);
978 pr_debug("%s:R-D:msw_ts=%d lsw_ts=%d flags=%d id=%d num=%d\n",
979 __func__, payload[READDONE_IDX_MSW_TS],
980 payload[READDONE_IDX_LSW_TS],
981 payload[READDONE_IDX_FLAGS],
982 payload[READDONE_IDX_ID],
983 payload[READDONE_IDX_NUMFRAMES]);
Rajesha Kini3498c932011-07-19 19:58:27 +0530984#ifdef CONFIG_DEBUG_FS
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700985 if (in_enable_flag)
Rajesha Kini3498c932011-07-19 19:58:27 +0530986 in_cont_index++;
Rajesha Kini3498c932011-07-19 19:58:27 +0530987#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700988 if (ac->io_mode == SYNC_IO_MODE) {
989 if (port->buf == NULL) {
990 pr_err("%s: Unexpected Write Done\n", __func__);
991 return -EINVAL;
992 }
993 spin_lock_irqsave(&port->dsp_lock, dsp_flags);
994 token = data->token;
995 port->buf[token].used = 0;
996 if (port->buf[token].phys !=
997 payload[READDONE_IDX_BUFFER]) {
998 pr_err("Buf expected[%p]rxed[%p]\n",\
999 (void *)port->buf[token].phys,\
1000 (void *)payload[READDONE_IDX_BUFFER]);
1001 spin_unlock_irqrestore(&port->dsp_lock,
1002 dsp_flags);
1003 break;
1004 }
1005 port->buf[token].actual_size =
1006 payload[READDONE_IDX_SIZE];
1007 spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
1008 }
1009 break;
1010 }
1011 case ASM_DATA_EVENT_EOS:
1012 case ASM_DATA_CMDRSP_EOS:
1013 pr_debug("%s:EOS ACK received: rxed opcode[0x%x]\n",
1014 __func__, data->opcode);
1015 break;
1016 case ASM_STREAM_CMDRSP_GET_ENCDEC_PARAM:
1017 break;
1018 case ASM_SESSION_EVENT_TX_OVERFLOW:
1019 pr_err("ASM_SESSION_EVENT_TX_OVERFLOW\n");
1020 break;
1021 case ASM_SESSION_CMDRSP_GET_SESSION_TIME:
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001022 pr_debug("%s: ASM_SESSION_CMDRSP_GET_SESSION_TIME, payload[0] = %d, payload[1] = %d, payload[2] = %d\n",
1023 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001024 payload[0], payload[1], payload[2]);
1025 ac->time_stamp = (uint64_t)(((uint64_t)payload[1] << 32) |
1026 payload[2]);
1027 if (atomic_read(&ac->time_flag)) {
1028 atomic_set(&ac->time_flag, 0);
1029 wake_up(&ac->time_wait);
1030 }
1031 break;
1032 case ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY:
Deepa Madiregama55cbf782011-09-10 05:44:39 +05301033 case ASM_DATA_EVENT_ENC_SR_CM_NOTIFY:
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001034 pr_debug("%s: ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY, payload[0] = %d, payload[1] = %d, payload[2] = %d, payload[3] = %d\n",
1035 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001036 payload[0], payload[1], payload[2],
1037 payload[3]);
1038 break;
1039 }
1040 if (ac->cb)
1041 ac->cb(data->opcode, data->token,
1042 data->payload, ac->priv);
1043
1044 return 0;
1045}
1046
1047void *q6asm_is_cpu_buf_avail(int dir, struct audio_client *ac, uint32_t *size,
1048 uint32_t *index)
1049{
1050 void *data;
1051 unsigned char idx;
1052 struct audio_port_data *port;
1053
1054 if (!ac || ((dir != IN) && (dir != OUT)))
1055 return NULL;
1056
1057 if (ac->io_mode == SYNC_IO_MODE) {
1058 port = &ac->port[dir];
1059
1060 mutex_lock(&port->lock);
1061 idx = port->cpu_buf;
1062 if (port->buf == NULL) {
1063 pr_debug("%s:Buffer pointer null\n", __func__);
Jayasena Sangaraboina466e6b92012-01-17 21:10:55 -08001064 mutex_unlock(&port->lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001065 return NULL;
1066 }
1067 /* dir 0: used = 0 means buf in use
1068 dir 1: used = 1 means buf in use */
1069 if (port->buf[idx].used == dir) {
1070 /* To make it more robust, we could loop and get the
1071 next avail buf, its risky though */
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001072 pr_debug("%s:Next buf idx[0x%x] not available,dir[%d]\n",
1073 __func__, idx, dir);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001074 mutex_unlock(&port->lock);
1075 return NULL;
1076 }
1077 *size = port->buf[idx].actual_size;
1078 *index = port->cpu_buf;
1079 data = port->buf[idx].data;
1080 pr_debug("%s:session[%d]index[%d] data[%p]size[%d]\n",
1081 __func__,
1082 ac->session,
1083 port->cpu_buf,
1084 data, *size);
1085 /* By default increase the cpu_buf cnt
1086 user accesses this function,increase cpu
1087 buf(to avoid another api)*/
1088 port->buf[idx].used = dir;
1089 port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1));
1090 mutex_unlock(&port->lock);
1091 return data;
1092 }
1093 return NULL;
1094}
1095
Jay Wang9cf59a02011-08-10 16:58:40 -07001096void *q6asm_is_cpu_buf_avail_nolock(int dir, struct audio_client *ac,
1097 uint32_t *size, uint32_t *index)
1098{
1099 void *data;
1100 unsigned char idx;
1101 struct audio_port_data *port;
1102
1103 if (!ac || ((dir != IN) && (dir != OUT)))
1104 return NULL;
1105
1106 port = &ac->port[dir];
1107
1108 idx = port->cpu_buf;
1109 if (port->buf == NULL) {
1110 pr_debug("%s:Buffer pointer null\n", __func__);
1111 return NULL;
1112 }
1113 /*
1114 * dir 0: used = 0 means buf in use
1115 * dir 1: used = 1 means buf in use
1116 */
1117 if (port->buf[idx].used == dir) {
1118 /*
1119 * To make it more robust, we could loop and get the
1120 * next avail buf, its risky though
1121 */
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001122 pr_debug("%s:Next buf idx[0x%x] not available, dir[%d]\n",
1123 __func__, idx, dir);
Jay Wang9cf59a02011-08-10 16:58:40 -07001124 return NULL;
1125 }
1126 *size = port->buf[idx].actual_size;
1127 *index = port->cpu_buf;
1128 data = port->buf[idx].data;
1129 pr_debug("%s:session[%d]index[%d] data[%p]size[%d]\n",
1130 __func__, ac->session, port->cpu_buf,
1131 data, *size);
1132 /*
1133 * By default increase the cpu_buf cnt
1134 * user accesses this function,increase cpu
1135 * buf(to avoid another api)
1136 */
1137 port->buf[idx].used = dir;
1138 port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1));
1139 return data;
1140}
1141
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001142int q6asm_is_dsp_buf_avail(int dir, struct audio_client *ac)
1143{
1144 int ret = -1;
1145 struct audio_port_data *port;
1146 uint32_t idx;
1147
1148 if (!ac || (dir != OUT))
1149 return ret;
1150
1151 if (ac->io_mode == SYNC_IO_MODE) {
1152 port = &ac->port[dir];
1153
1154 mutex_lock(&port->lock);
1155 idx = port->dsp_buf;
1156
1157 if (port->buf[idx].used == (dir ^ 1)) {
1158 /* To make it more robust, we could loop and get the
1159 next avail buf, its risky though */
1160 pr_err("Next buf idx[0x%x] not available, dir[%d]\n",
1161 idx, dir);
1162 mutex_unlock(&port->lock);
1163 return ret;
1164 }
1165 pr_debug("%s: session[%d]dsp_buf=%d cpu_buf=%d\n", __func__,
1166 ac->session, port->dsp_buf, port->cpu_buf);
1167 ret = ((port->dsp_buf != port->cpu_buf) ? 0 : -1);
1168 mutex_unlock(&port->lock);
1169 }
1170 return ret;
1171}
1172
1173static void q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
1174 uint32_t pkt_size, uint32_t cmd_flg)
1175{
1176 pr_debug("%s:session=%d pkt size=%d cmd_flg=%d\n", __func__, pkt_size,
1177 cmd_flg, ac->session);
1178 mutex_lock(&ac->cmd_lock);
1179 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
1180 APR_HDR_LEN(sizeof(struct apr_hdr)),\
1181 APR_PKT_VER);
1182 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
1183 hdr->src_domain = APR_DOMAIN_APPS;
1184 hdr->dest_svc = APR_SVC_ASM;
1185 hdr->dest_domain = APR_DOMAIN_ADSP;
1186 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
1187 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
1188 if (cmd_flg) {
1189 hdr->token = ac->session;
1190 atomic_set(&ac->cmd_state, 1);
1191 }
1192 hdr->pkt_size = pkt_size;
1193 mutex_unlock(&ac->cmd_lock);
1194 return;
1195}
1196
1197static void q6asm_add_mmaphdr(struct apr_hdr *hdr, uint32_t pkt_size,
1198 uint32_t cmd_flg)
1199{
1200 pr_debug("%s:pkt size=%d cmd_flg=%d\n", __func__, pkt_size, cmd_flg);
1201 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
1202 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1203 hdr->src_port = 0;
1204 hdr->dest_port = 0;
1205 if (cmd_flg) {
1206 hdr->token = 0;
1207 atomic_set(&this_mmap.cmd_state, 1);
1208 }
1209 hdr->pkt_size = pkt_size;
1210 return;
1211}
1212
1213int q6asm_open_read(struct audio_client *ac,
1214 uint32_t format)
1215{
1216 int rc = 0x00;
1217 struct asm_stream_cmd_open_read open;
Rajesha Kini3498c932011-07-19 19:58:27 +05301218#ifdef CONFIG_DEBUG_FS
1219 in_cont_index = 0;
1220#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001221 if ((ac == NULL) || (ac->apr == NULL)) {
1222 pr_err("%s: APR handle NULL\n", __func__);
1223 return -EINVAL;
1224 }
1225 pr_debug("%s:session[%d]", __func__, ac->session);
1226
1227 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1228 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ;
1229 /* Stream prio : High, provide meta info with encoded frames */
1230 open.src_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1231
1232 open.pre_proc_top = get_asm_topology();
1233 if (open.pre_proc_top == 0)
1234 open.pre_proc_top = DEFAULT_POPP_TOPOLOGY;
1235
1236 switch (format) {
1237 case FORMAT_LINEAR_PCM:
1238 open.uMode = STREAM_PRIORITY_HIGH;
1239 open.format = LINEAR_PCM;
1240 break;
Mingming Yin647e9ea2012-03-17 19:56:10 -07001241 case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
1242 open.uMode = STREAM_PRIORITY_HIGH;
1243 open.format = MULTI_CHANNEL_PCM;
1244 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001245 case FORMAT_MPEG4_AAC:
1246 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1247 open.format = MPEG4_AAC;
1248 break;
1249 case FORMAT_V13K:
1250 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1251 open.format = V13K_FS;
1252 break;
1253 case FORMAT_EVRC:
1254 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1255 open.format = EVRC_FS;
1256 break;
1257 case FORMAT_AMRNB:
1258 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1259 open.format = AMRNB_FS;
1260 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301261 case FORMAT_AMRWB:
1262 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1263 open.format = AMRWB_FS;
1264 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001265 default:
1266 pr_err("Invalid format[%d]\n", format);
1267 goto fail_cmd;
1268 }
1269 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1270 if (rc < 0) {
1271 pr_err("open failed op[0x%x]rc[%d]\n", \
1272 open.hdr.opcode, rc);
1273 goto fail_cmd;
1274 }
1275 rc = wait_event_timeout(ac->cmd_wait,
1276 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1277 if (!rc) {
1278 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1279 rc);
1280 goto fail_cmd;
1281 }
1282 return 0;
1283fail_cmd:
1284 return -EINVAL;
1285}
1286
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -07001287int q6asm_open_read_v2_1(struct audio_client *ac,
1288 uint32_t format)
1289{
1290 int rc = 0x00;
1291 struct asm_stream_cmd_open_read_v2_1 open;
1292#ifdef CONFIG_DEBUG_FS
1293 in_cont_index = 0;
1294#endif
1295 if ((ac == NULL) || (ac->apr == NULL)) {
1296 pr_err("%s: APR handle NULL\n", __func__);
1297 return -EINVAL;
1298 }
1299 pr_debug("%s:session[%d]", __func__, ac->session);
1300
1301 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1302 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ_V2_1;
1303 open.src_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1304 open.pre_proc_top = get_asm_topology();
1305 if (open.pre_proc_top == 0)
1306 open.pre_proc_top = DEFAULT_POPP_TOPOLOGY;
1307
1308 switch (format) {
1309 case FORMAT_LINEAR_PCM:
1310 open.uMode = STREAM_PRIORITY_HIGH;
1311 open.format = LINEAR_PCM;
1312 break;
1313 case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
1314 open.uMode = STREAM_PRIORITY_HIGH;
1315 open.format = MULTI_CHANNEL_PCM;
1316 break;
1317 case FORMAT_MPEG4_AAC:
1318 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1319 open.format = MPEG4_AAC;
1320 break;
1321 case FORMAT_V13K:
1322 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1323 open.format = V13K_FS;
1324 break;
1325 case FORMAT_EVRC:
1326 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1327 open.format = EVRC_FS;
1328 break;
1329 case FORMAT_AMRNB:
1330 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1331 open.format = AMRNB_FS;
1332 break;
1333 case FORMAT_AMRWB:
1334 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1335 open.format = AMRWB_FS;
1336 break;
1337 default:
1338 pr_err("Invalid format[%d]\n", format);
1339 goto fail_cmd;
1340 }
1341 open.uMode = ASM_OPEN_READ_PERF_MODE_BIT;
1342 open.bits_per_sample = PCM_BITS_PER_SAMPLE;
1343 open.reserved = 0;
1344 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1345 if (rc < 0) {
1346 pr_err("open failed op[0x%x]rc[%d]\n", \
1347 open.hdr.opcode, rc);
1348 goto fail_cmd;
1349 }
1350 rc = wait_event_timeout(ac->cmd_wait,
1351 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1352 if (!rc) {
1353 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1354 rc);
1355 goto fail_cmd;
1356 }
1357 return 0;
1358fail_cmd:
1359 return -EINVAL;
1360}
1361
1362
Subhash Chandra Bose Naripeddy694b7d92012-06-20 20:46:13 -07001363int q6asm_open_read_compressed(struct audio_client *ac,
1364 uint32_t frames_per_buffer, uint32_t meta_data_mode)
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -07001365{
1366 int rc = 0x00;
1367 struct asm_stream_cmd_open_read_compressed open;
1368#ifdef CONFIG_DEBUG_FS
1369 in_cont_index = 0;
1370#endif
1371 if ((ac == NULL) || (ac->apr == NULL)) {
1372 pr_err("%s: APR handle NULL\n", __func__);
1373 return -EINVAL;
1374 }
1375 pr_debug("%s:session[%d]", __func__, ac->session);
1376
1377 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1378 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ_COMPRESSED;
1379 /* hardcoded as following*/
Subhash Chandra Bose Naripeddy694b7d92012-06-20 20:46:13 -07001380 open.frame_per_buf = frames_per_buffer;
1381 open.uMode = meta_data_mode;
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -07001382
1383 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1384 if (rc < 0) {
1385 pr_err("open failed op[0x%x]rc[%d]\n", open.hdr.opcode, rc);
1386 goto fail_cmd;
1387 }
1388 rc = wait_event_timeout(ac->cmd_wait,
1389 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1390 if (!rc) {
1391 pr_err("%s: timeout. waited for OPEN_READ_COMPRESSED rc[%d]\n",
1392 __func__, rc);
1393 goto fail_cmd;
1394 }
1395 return 0;
1396fail_cmd:
1397 return -EINVAL;
1398}
1399
Santosh Mardi23321202012-03-22 04:33:25 +05301400int q6asm_open_write_compressed(struct audio_client *ac, uint32_t format)
1401{
1402 int rc = 0x00;
1403 struct asm_stream_cmd_open_write_compressed open;
1404
1405 if ((ac == NULL) || (ac->apr == NULL)) {
1406 pr_err("%s: APR handle NULL\n", __func__);
1407 return -EINVAL;
1408 }
1409 pr_debug("%s: session[%d] wr_format[0x%x]", __func__, ac->session,
1410 format);
1411
1412 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1413
1414 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_COMPRESSED;
1415
1416 switch (format) {
1417 case FORMAT_AC3:
1418 open.format = AC3_DECODER;
1419 break;
1420 case FORMAT_EAC3:
1421 open.format = EAC3_DECODER;
1422 break;
1423 case FORMAT_MP3:
1424 open.format = MP3;
1425 break;
1426 case FORMAT_DTS:
1427 open.format = DTS;
1428 break;
Srikanth Uyyala66f781a2012-06-13 23:23:25 +05301429 case FORMAT_DTS_LBR:
1430 open.format = DTS_LBR;
1431 break;
Santosh Mardi23321202012-03-22 04:33:25 +05301432 case FORMAT_AAC:
1433 open.format = MPEG4_AAC;
1434 break;
1435 case FORMAT_ATRAC:
1436 open.format = ATRAC;
1437 break;
1438 case FORMAT_WMA_V10PRO:
1439 open.format = WMA_V10PRO;
1440 break;
1441 case FORMAT_MAT:
1442 open.format = MAT;
1443 break;
1444 default:
1445 pr_err("%s: Invalid format[%d]\n", __func__, format);
1446 goto fail_cmd;
1447 }
1448 /*Below flag indicates the DSP that Compressed audio input
1449 stream is not IEC 61937 or IEC 60958 packetizied*/
1450 open.flags = 0x00000000;
1451 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1452 if (rc < 0) {
1453 pr_err("%s: open failed op[0x%x]rc[%d]\n", \
1454 __func__, open.hdr.opcode, rc);
1455 goto fail_cmd;
1456 }
1457 rc = wait_event_timeout(ac->cmd_wait,
1458 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1459 if (!rc) {
1460 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1461 rc);
1462 goto fail_cmd;
1463 }
1464 return 0;
1465fail_cmd:
1466 return -EINVAL;
1467}
1468
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001469int q6asm_open_write(struct audio_client *ac, uint32_t format)
1470{
1471 int rc = 0x00;
1472 struct asm_stream_cmd_open_write open;
1473
1474 if ((ac == NULL) || (ac->apr == NULL)) {
1475 pr_err("%s: APR handle NULL\n", __func__);
1476 return -EINVAL;
1477 }
1478 pr_debug("%s: session[%d] wr_format[0x%x]", __func__, ac->session,
1479 format);
1480
1481 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1482
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -07001483 if (ac->perf_mode) {
1484 pr_debug("%s In Performance/lowlatency mode", __func__);
1485 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_V2_1;
1486 open.uMode = ASM_OPEN_WRITE_PERF_MODE_BIT;
1487 /* source endpoint : matrix */
1488 open.sink_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1489 open.stream_handle = PCM_BITS_PER_SAMPLE;
1490 } else {
1491 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE;
1492 open.uMode = STREAM_PRIORITY_HIGH;
1493 /* source endpoint : matrix */
1494 open.sink_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1495 open.stream_handle = 0x00;
1496 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001497 open.post_proc_top = get_asm_topology();
1498 if (open.post_proc_top == 0)
1499 open.post_proc_top = DEFAULT_POPP_TOPOLOGY;
1500
1501 switch (format) {
1502 case FORMAT_LINEAR_PCM:
1503 open.format = LINEAR_PCM;
1504 break;
Kiran Kandi5e809b02012-01-31 00:24:33 -08001505 case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
1506 open.format = MULTI_CHANNEL_PCM;
1507 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001508 case FORMAT_MPEG4_AAC:
1509 open.format = MPEG4_AAC;
1510 break;
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07001511 case FORMAT_MPEG4_MULTI_AAC:
1512 open.format = MPEG4_MULTI_AAC;
1513 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001514 case FORMAT_WMA_V9:
1515 open.format = WMA_V9;
1516 break;
1517 case FORMAT_WMA_V10PRO:
1518 open.format = WMA_V10PRO;
1519 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05301520 case FORMAT_MP3:
1521 open.format = MP3;
1522 break;
Srikanth Uyyala66f781a2012-06-13 23:23:25 +05301523 case FORMAT_DTS:
1524 open.format = DTS;
1525 break;
1526 case FORMAT_DTS_LBR:
1527 open.format = DTS_LBR;
1528 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001529 default:
1530 pr_err("%s: Invalid format[%d]\n", __func__, format);
1531 goto fail_cmd;
1532 }
1533 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1534 if (rc < 0) {
1535 pr_err("%s: open failed op[0x%x]rc[%d]\n", \
1536 __func__, open.hdr.opcode, rc);
1537 goto fail_cmd;
1538 }
1539 rc = wait_event_timeout(ac->cmd_wait,
1540 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1541 if (!rc) {
1542 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1543 rc);
1544 goto fail_cmd;
1545 }
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +05301546 if (atomic_read(&ac->cmd_response)) {
1547 pr_err("%s: format = %x not supported\n", __func__, format);
1548 goto fail_cmd;
1549 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001550 return 0;
1551fail_cmd:
1552 return -EINVAL;
1553}
1554
1555int q6asm_open_read_write(struct audio_client *ac,
1556 uint32_t rd_format,
1557 uint32_t wr_format)
1558{
1559 int rc = 0x00;
1560 struct asm_stream_cmd_open_read_write open;
1561
1562 if ((ac == NULL) || (ac->apr == NULL)) {
1563 pr_err("APR handle NULL\n");
1564 return -EINVAL;
1565 }
1566 pr_debug("%s: session[%d]", __func__, ac->session);
1567 pr_debug("wr_format[0x%x]rd_format[0x%x]",
1568 wr_format, rd_format);
1569
1570 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1571 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READWRITE;
1572
Deepa Madiregama55cbf782011-09-10 05:44:39 +05301573 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_NORMAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001574 /* source endpoint : matrix */
1575 open.post_proc_top = get_asm_topology();
1576 if (open.post_proc_top == 0)
1577 open.post_proc_top = DEFAULT_POPP_TOPOLOGY;
1578
1579 switch (wr_format) {
1580 case FORMAT_LINEAR_PCM:
1581 open.write_format = LINEAR_PCM;
1582 break;
1583 case FORMAT_MPEG4_AAC:
1584 open.write_format = MPEG4_AAC;
1585 break;
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07001586 case FORMAT_MPEG4_MULTI_AAC:
1587 open.write_format = MPEG4_MULTI_AAC;
1588 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001589 case FORMAT_WMA_V9:
1590 open.write_format = WMA_V9;
1591 break;
1592 case FORMAT_WMA_V10PRO:
1593 open.write_format = WMA_V10PRO;
1594 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301595 case FORMAT_AMRNB:
1596 open.write_format = AMRNB_FS;
1597 break;
1598 case FORMAT_AMRWB:
1599 open.write_format = AMRWB_FS;
1600 break;
1601 case FORMAT_V13K:
1602 open.write_format = V13K_FS;
1603 break;
1604 case FORMAT_EVRC:
1605 open.write_format = EVRC_FS;
1606 break;
1607 case FORMAT_EVRCB:
1608 open.write_format = EVRCB_FS;
1609 break;
1610 case FORMAT_EVRCWB:
1611 open.write_format = EVRCWB_FS;
1612 break;
1613 case FORMAT_MP3:
1614 open.write_format = MP3;
1615 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001616 default:
1617 pr_err("Invalid format[%d]\n", wr_format);
1618 goto fail_cmd;
1619 }
1620
1621 switch (rd_format) {
1622 case FORMAT_LINEAR_PCM:
1623 open.read_format = LINEAR_PCM;
1624 break;
1625 case FORMAT_MPEG4_AAC:
1626 open.read_format = MPEG4_AAC;
1627 break;
1628 case FORMAT_V13K:
1629 open.read_format = V13K_FS;
1630 break;
1631 case FORMAT_EVRC:
1632 open.read_format = EVRC_FS;
1633 break;
1634 case FORMAT_AMRNB:
1635 open.read_format = AMRNB_FS;
1636 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301637 case FORMAT_AMRWB:
1638 open.read_format = AMRWB_FS;
1639 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001640 default:
1641 pr_err("Invalid format[%d]\n", rd_format);
1642 goto fail_cmd;
1643 }
1644 pr_debug("%s:rdformat[0x%x]wrformat[0x%x]\n", __func__,
1645 open.read_format, open.write_format);
1646
1647 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1648 if (rc < 0) {
1649 pr_err("open failed op[0x%x]rc[%d]\n", \
1650 open.hdr.opcode, rc);
1651 goto fail_cmd;
1652 }
1653 rc = wait_event_timeout(ac->cmd_wait,
1654 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1655 if (!rc) {
1656 pr_err("timeout. waited for OPEN_WRITE rc[%d]\n", rc);
1657 goto fail_cmd;
1658 }
1659 return 0;
1660fail_cmd:
1661 return -EINVAL;
1662}
1663
1664int q6asm_run(struct audio_client *ac, uint32_t flags,
1665 uint32_t msw_ts, uint32_t lsw_ts)
1666{
1667 struct asm_stream_cmd_run run;
1668 int rc;
1669 if (!ac || ac->apr == NULL) {
1670 pr_err("APR handle NULL\n");
1671 return -EINVAL;
1672 }
1673 pr_debug("%s session[%d]", __func__, ac->session);
1674 q6asm_add_hdr(ac, &run.hdr, sizeof(run), TRUE);
1675
1676 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1677 run.flags = flags;
1678 run.msw_ts = msw_ts;
1679 run.lsw_ts = lsw_ts;
Rajesha Kini3498c932011-07-19 19:58:27 +05301680#ifdef CONFIG_DEBUG_FS
1681 if (out_enable_flag) {
1682 do_gettimeofday(&out_cold_tv);
1683 pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",\
1684 out_cold_tv.tv_sec, out_cold_tv.tv_usec);
1685 }
1686#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001687 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1688 if (rc < 0) {
1689 pr_err("Commmand run failed[%d]", rc);
1690 goto fail_cmd;
1691 }
1692
1693 rc = wait_event_timeout(ac->cmd_wait,
1694 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1695 if (!rc) {
1696 pr_err("timeout. waited for run success rc[%d]", rc);
1697 goto fail_cmd;
1698 }
1699
1700 return 0;
1701fail_cmd:
1702 return -EINVAL;
1703}
1704
1705int q6asm_run_nowait(struct audio_client *ac, uint32_t flags,
1706 uint32_t msw_ts, uint32_t lsw_ts)
1707{
1708 struct asm_stream_cmd_run run;
1709 int rc;
1710 if (!ac || ac->apr == NULL) {
1711 pr_err("%s:APR handle NULL\n", __func__);
1712 return -EINVAL;
1713 }
1714 pr_debug("session[%d]", ac->session);
1715 q6asm_add_hdr_async(ac, &run.hdr, sizeof(run), TRUE);
1716
1717 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1718 run.flags = flags;
1719 run.msw_ts = msw_ts;
1720 run.lsw_ts = lsw_ts;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001721 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1722 if (rc < 0) {
1723 pr_err("%s:Commmand run failed[%d]", __func__, rc);
1724 return -EINVAL;
1725 }
Jay Wang0668d1062012-07-11 18:53:21 -07001726 atomic_inc(&ac->nowait_cmd_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001727 return 0;
1728}
1729
1730
1731int q6asm_enc_cfg_blk_aac(struct audio_client *ac,
1732 uint32_t frames_per_buf,
1733 uint32_t sample_rate, uint32_t channels,
1734 uint32_t bit_rate, uint32_t mode, uint32_t format)
1735{
1736 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1737 int rc = 0;
1738
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001739 pr_debug("%s:session[%d]frames[%d]SR[%d]ch[%d]bitrate[%d]mode[%d] format[%d]",
1740 __func__, ac->session, frames_per_buf,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001741 sample_rate, channels, bit_rate, mode, format);
1742
1743 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1744
1745 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1746 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1747 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1748 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1749 enc_cfg.enc_blk.format_id = MPEG4_AAC;
1750 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_aac_read_cfg);
1751 enc_cfg.enc_blk.cfg.aac.bitrate = bit_rate;
1752 enc_cfg.enc_blk.cfg.aac.enc_mode = mode;
1753 enc_cfg.enc_blk.cfg.aac.format = format;
1754 enc_cfg.enc_blk.cfg.aac.ch_cfg = channels;
1755 enc_cfg.enc_blk.cfg.aac.sample_rate = sample_rate;
1756
1757 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1758 if (rc < 0) {
1759 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1760 rc = -EINVAL;
1761 goto fail_cmd;
1762 }
1763 rc = wait_event_timeout(ac->cmd_wait,
1764 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1765 if (!rc) {
1766 pr_err("timeout. waited for FORMAT_UPDATE\n");
1767 goto fail_cmd;
1768 }
1769 return 0;
1770fail_cmd:
1771 return -EINVAL;
1772}
1773
1774int q6asm_enc_cfg_blk_pcm(struct audio_client *ac,
1775 uint32_t rate, uint32_t channels)
1776{
1777 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1778
1779 int rc = 0;
1780
1781 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1782 ac->session, rate, channels);
1783
1784 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1785
1786 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1787 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1788 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1789 enc_cfg.enc_blk.frames_per_buf = 1;
1790 enc_cfg.enc_blk.format_id = LINEAR_PCM;
1791 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg);
1792 enc_cfg.enc_blk.cfg.pcm.ch_cfg = channels;
1793 enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16;
1794 enc_cfg.enc_blk.cfg.pcm.sample_rate = rate;
1795 enc_cfg.enc_blk.cfg.pcm.is_signed = 1;
1796 enc_cfg.enc_blk.cfg.pcm.interleaved = 1;
1797
1798 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1799 if (rc < 0) {
1800 pr_err("Comamnd open failed\n");
1801 rc = -EINVAL;
1802 goto fail_cmd;
1803 }
1804 rc = wait_event_timeout(ac->cmd_wait,
1805 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1806 if (!rc) {
1807 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1808 goto fail_cmd;
1809 }
1810 return 0;
1811fail_cmd:
1812 return -EINVAL;
1813}
1814
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001815int q6asm_enc_cfg_blk_pcm_native(struct audio_client *ac,
1816 uint32_t rate, uint32_t channels)
1817{
1818 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1819
1820 int rc = 0;
1821
1822 pr_debug("%s: Session %d, rate = %d, channels = %d, setting the rate and channels to 0 for native\n",
1823 __func__, ac->session, rate, channels);
1824
1825 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1826
1827 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1828 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1829 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1830 enc_cfg.enc_blk.frames_per_buf = 1;
1831 enc_cfg.enc_blk.format_id = LINEAR_PCM;
1832 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg);
1833 enc_cfg.enc_blk.cfg.pcm.ch_cfg = 0;/*channels;*/
1834 enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16;
1835 enc_cfg.enc_blk.cfg.pcm.sample_rate = 0;/*rate;*/
1836 enc_cfg.enc_blk.cfg.pcm.is_signed = 1;
1837 enc_cfg.enc_blk.cfg.pcm.interleaved = 1;
1838
1839 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1840 if (rc < 0) {
1841 pr_err("Comamnd open failed\n");
1842 rc = -EINVAL;
1843 goto fail_cmd;
1844 }
1845 rc = wait_event_timeout(ac->cmd_wait,
1846 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1847 if (!rc) {
1848 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1849 goto fail_cmd;
1850 }
1851 return 0;
1852fail_cmd:
1853 return -EINVAL;
1854}
1855
Mingming Yin647e9ea2012-03-17 19:56:10 -07001856int q6asm_enc_cfg_blk_multi_ch_pcm(struct audio_client *ac,
1857 uint32_t rate, uint32_t channels)
1858{
1859 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1860
1861 int rc = 0;
1862
1863 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1864 ac->session, rate, channels);
1865
1866 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1867
1868 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1869 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1870 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1871 enc_cfg.enc_blk.frames_per_buf = 1;
1872 enc_cfg.enc_blk.format_id = MULTI_CHANNEL_PCM;
1873 enc_cfg.enc_blk.cfg_size =
1874 sizeof(struct asm_multi_channel_pcm_fmt_blk);
1875 enc_cfg.enc_blk.cfg.mpcm.num_channels = channels;
1876 enc_cfg.enc_blk.cfg.mpcm.bits_per_sample = 16;
1877 enc_cfg.enc_blk.cfg.mpcm.sample_rate = rate;
1878 enc_cfg.enc_blk.cfg.mpcm.is_signed = 1;
1879 enc_cfg.enc_blk.cfg.mpcm.is_interleaved = 1;
Subhash Chandra Bose Naripeddy8477d222012-06-12 00:30:54 -07001880 if (channels == 2) {
1881 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1882 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1883 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = 0;
1884 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = 0;
1885 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1886 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1887 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1888 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1889 } else if (channels == 4) {
1890 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1891 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1892 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_RB;
1893 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_LB;
1894 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1895 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1896 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1897 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1898 } else if (channels == 6) {
1899 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1900 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1901 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_LFE;
1902 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_FC;
1903 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = PCM_CHANNEL_LB;
1904 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = PCM_CHANNEL_RB;
1905 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1906 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1907 } else if (channels == 8) {
1908 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1909 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1910 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_LFE;
1911 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_FC;
1912 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = PCM_CHANNEL_LB;
1913 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = PCM_CHANNEL_RB;
1914 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = PCM_CHANNEL_FLC;
1915 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = PCM_CHANNEL_FRC;
1916 }
Mingming Yin647e9ea2012-03-17 19:56:10 -07001917
1918 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1919 if (rc < 0) {
1920 pr_err("Comamnd open failed\n");
1921 rc = -EINVAL;
1922 goto fail_cmd;
1923 }
1924 rc = wait_event_timeout(ac->cmd_wait,
1925 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1926 if (!rc) {
1927 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1928 goto fail_cmd;
1929 }
1930 return 0;
1931fail_cmd:
1932 return -EINVAL;
1933}
1934
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001935int q6asm_enable_sbrps(struct audio_client *ac,
1936 uint32_t sbr_ps_enable)
1937{
1938 struct asm_stream_cmd_encdec_sbr sbrps;
1939
1940 int rc = 0;
1941
1942 pr_debug("%s: Session %d\n", __func__, ac->session);
1943
1944 q6asm_add_hdr(ac, &sbrps.hdr, sizeof(sbrps), TRUE);
1945
1946 sbrps.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1947 sbrps.param_id = ASM_ENABLE_SBR_PS;
1948 sbrps.param_size = sizeof(struct asm_sbr_ps);
1949 sbrps.sbr_ps.enable = sbr_ps_enable;
1950
1951 rc = apr_send_pkt(ac->apr, (uint32_t *) &sbrps);
1952 if (rc < 0) {
1953 pr_err("Command opcode[0x%x]paramid[0x%x] failed\n",
1954 ASM_STREAM_CMD_SET_ENCDEC_PARAM,
1955 ASM_ENABLE_SBR_PS);
1956 rc = -EINVAL;
1957 goto fail_cmd;
1958 }
1959 rc = wait_event_timeout(ac->cmd_wait,
1960 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1961 if (!rc) {
1962 pr_err("timeout opcode[0x%x] ", sbrps.hdr.opcode);
1963 goto fail_cmd;
1964 }
1965 return 0;
1966fail_cmd:
1967 return -EINVAL;
1968}
1969
Swaminathan Sathappan70765cd2011-07-19 18:42:47 -07001970int q6asm_cfg_dual_mono_aac(struct audio_client *ac,
1971 uint16_t sce_left, uint16_t sce_right)
1972{
1973 struct asm_stream_cmd_encdec_dualmono dual_mono;
1974
1975 int rc = 0;
1976
1977 pr_debug("%s: Session %d, sce_left = %d, sce_right = %d\n",
1978 __func__, ac->session, sce_left, sce_right);
1979
1980 q6asm_add_hdr(ac, &dual_mono.hdr, sizeof(dual_mono), TRUE);
1981
1982 dual_mono.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1983 dual_mono.param_id = ASM_CONFIGURE_DUAL_MONO;
1984 dual_mono.param_size = sizeof(struct asm_dual_mono);
1985 dual_mono.channel_map.sce_left = sce_left;
1986 dual_mono.channel_map.sce_right = sce_right;
1987
1988 rc = apr_send_pkt(ac->apr, (uint32_t *) &dual_mono);
1989 if (rc < 0) {
1990 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
1991 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
1992 ASM_CONFIGURE_DUAL_MONO);
1993 rc = -EINVAL;
1994 goto fail_cmd;
1995 }
1996 rc = wait_event_timeout(ac->cmd_wait,
1997 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1998 if (!rc) {
1999 pr_err("%s:timeout opcode[0x%x]\n", __func__,
2000 dual_mono.hdr.opcode);
2001 goto fail_cmd;
2002 }
2003 return 0;
2004fail_cmd:
2005 return -EINVAL;
2006}
2007
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07002008int q6asm_set_encdec_chan_map(struct audio_client *ac,
2009 uint32_t num_channels)
2010{
2011 struct asm_stream_cmd_encdec_channelmap chan_map;
2012 u8 *channel_mapping;
2013
2014 int rc = 0;
2015
2016 pr_debug("%s: Session %d, num_channels = %d\n",
2017 __func__, ac->session, num_channels);
2018
2019 q6asm_add_hdr(ac, &chan_map.hdr, sizeof(chan_map), TRUE);
2020
2021 chan_map.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2022 chan_map.param_id = ASM_ENCDEC_DEC_CHAN_MAP;
2023 chan_map.param_size = sizeof(struct asm_dec_chan_map);
2024 chan_map.chan_map.num_channels = num_channels;
2025
2026 channel_mapping =
2027 chan_map.chan_map.channel_mapping;
2028
2029 memset(channel_mapping, PCM_CHANNEL_NULL, MAX_CHAN_MAP_CHANNELS);
2030 if (num_channels == 1) {
2031 channel_mapping[0] = PCM_CHANNEL_FL;
2032 } else if (num_channels == 2) {
2033 channel_mapping[0] = PCM_CHANNEL_FL;
2034 channel_mapping[1] = PCM_CHANNEL_FR;
2035 } else if (num_channels == 6) {
2036 channel_mapping[0] = PCM_CHANNEL_FC;
2037 channel_mapping[1] = PCM_CHANNEL_FL;
2038 channel_mapping[2] = PCM_CHANNEL_FR;
2039 channel_mapping[3] = PCM_CHANNEL_LB;
2040 channel_mapping[4] = PCM_CHANNEL_RB;
2041 channel_mapping[5] = PCM_CHANNEL_LFE;
2042 } else {
2043 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
2044 num_channels);
2045 rc = -EINVAL;
2046 goto fail_cmd;
2047 }
2048
2049 rc = apr_send_pkt(ac->apr, (uint32_t *) &chan_map);
2050 if (rc < 0) {
2051 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
2052 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
2053 ASM_ENCDEC_DEC_CHAN_MAP);
2054 goto fail_cmd;
2055 }
2056 rc = wait_event_timeout(ac->cmd_wait,
2057 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2058 if (!rc) {
2059 pr_err("%s:timeout opcode[0x%x]\n", __func__,
2060 chan_map.hdr.opcode);
2061 rc = -ETIMEDOUT;
2062 goto fail_cmd;
2063 }
2064 return 0;
2065fail_cmd:
2066 return rc;
2067}
2068
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002069int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf,
2070 uint16_t min_rate, uint16_t max_rate,
2071 uint16_t reduced_rate_level, uint16_t rate_modulation_cmd)
2072{
2073 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2074 int rc = 0;
2075
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002076 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]",
2077 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002078 ac->session, frames_per_buf, min_rate, max_rate,
2079 reduced_rate_level, rate_modulation_cmd);
2080
2081 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2082
2083 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2084
2085 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2086 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2087
2088 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2089 enc_cfg.enc_blk.format_id = V13K_FS;
2090 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_qcelp13_read_cfg);
2091 enc_cfg.enc_blk.cfg.qcelp13.min_rate = min_rate;
2092 enc_cfg.enc_blk.cfg.qcelp13.max_rate = max_rate;
2093 enc_cfg.enc_blk.cfg.qcelp13.reduced_rate_level = reduced_rate_level;
2094 enc_cfg.enc_blk.cfg.qcelp13.rate_modulation_cmd = rate_modulation_cmd;
2095
2096 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2097 if (rc < 0) {
2098 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2099 goto fail_cmd;
2100 }
2101 rc = wait_event_timeout(ac->cmd_wait,
2102 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2103 if (!rc) {
2104 pr_err("timeout. waited for FORMAT_UPDATE\n");
2105 goto fail_cmd;
2106 }
2107 return 0;
2108fail_cmd:
2109 return -EINVAL;
2110}
2111
2112int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf,
2113 uint16_t min_rate, uint16_t max_rate,
2114 uint16_t rate_modulation_cmd)
2115{
2116 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2117 int rc = 0;
2118
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002119 pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] rate_modulation_cmd[0x%4x]",
2120 __func__, ac->session,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002121 frames_per_buf, min_rate, max_rate, rate_modulation_cmd);
2122
2123 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2124
2125 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2126
2127 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2128 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2129
2130 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2131 enc_cfg.enc_blk.format_id = EVRC_FS;
2132 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_evrc_read_cfg);
2133 enc_cfg.enc_blk.cfg.evrc.min_rate = min_rate;
2134 enc_cfg.enc_blk.cfg.evrc.max_rate = max_rate;
2135 enc_cfg.enc_blk.cfg.evrc.rate_modulation_cmd = rate_modulation_cmd;
2136 enc_cfg.enc_blk.cfg.evrc.reserved = 0;
2137
2138 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2139 if (rc < 0) {
2140 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2141 goto fail_cmd;
2142 }
2143 rc = wait_event_timeout(ac->cmd_wait,
2144 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2145 if (!rc) {
2146 pr_err("timeout. waited for FORMAT_UPDATE\n");
2147 goto fail_cmd;
2148 }
2149 return 0;
2150fail_cmd:
2151 return -EINVAL;
2152}
2153
2154int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf,
2155 uint16_t band_mode, uint16_t dtx_enable)
2156{
2157 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2158 int rc = 0;
2159
2160 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
2161 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
2162
2163 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2164
2165 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2166
2167 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2168 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2169
2170 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2171 enc_cfg.enc_blk.format_id = AMRNB_FS;
2172 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrnb_read_cfg);
2173 enc_cfg.enc_blk.cfg.amrnb.mode = band_mode;
2174 enc_cfg.enc_blk.cfg.amrnb.dtx_mode = dtx_enable;
2175
2176 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2177 if (rc < 0) {
2178 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2179 goto fail_cmd;
2180 }
2181 rc = wait_event_timeout(ac->cmd_wait,
2182 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2183 if (!rc) {
2184 pr_err("timeout. waited for FORMAT_UPDATE\n");
2185 goto fail_cmd;
2186 }
2187 return 0;
2188fail_cmd:
2189 return -EINVAL;
2190}
2191
Alex Wong2caeecc2011-10-28 10:52:15 +05302192int q6asm_enc_cfg_blk_amrwb(struct audio_client *ac, uint32_t frames_per_buf,
2193 uint16_t band_mode, uint16_t dtx_enable)
2194{
2195 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2196 int rc = 0;
2197
2198 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
2199 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
2200
2201 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2202
2203 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2204
2205 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2206 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2207
2208 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2209 enc_cfg.enc_blk.format_id = AMRWB_FS;
2210 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrwb_read_cfg);
2211 enc_cfg.enc_blk.cfg.amrwb.mode = band_mode;
2212 enc_cfg.enc_blk.cfg.amrwb.dtx_mode = dtx_enable;
2213
2214 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2215 if (rc < 0) {
2216 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2217 goto fail_cmd;
2218 }
2219 rc = wait_event_timeout(ac->cmd_wait,
2220 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2221 if (!rc) {
2222 pr_err("timeout. waited for FORMAT_UPDATE\n");
2223 goto fail_cmd;
2224 }
2225 return 0;
2226fail_cmd:
2227 return -EINVAL;
2228}
2229
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002230int q6asm_media_format_block_pcm(struct audio_client *ac,
2231 uint32_t rate, uint32_t channels)
2232{
2233 struct asm_stream_media_format_update fmt;
2234 int rc = 0;
2235
2236 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
2237 channels);
2238
2239 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2240
2241 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2242
2243 fmt.format = LINEAR_PCM;
2244 fmt.cfg_size = sizeof(struct asm_pcm_cfg);
2245 fmt.write_cfg.pcm_cfg.ch_cfg = channels;
2246 fmt.write_cfg.pcm_cfg.bits_per_sample = 16;
2247 fmt.write_cfg.pcm_cfg.sample_rate = rate;
2248 fmt.write_cfg.pcm_cfg.is_signed = 1;
2249 fmt.write_cfg.pcm_cfg.interleaved = 1;
2250
2251 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2252 if (rc < 0) {
2253 pr_err("%s:Comamnd open failed\n", __func__);
2254 goto fail_cmd;
2255 }
2256 rc = wait_event_timeout(ac->cmd_wait,
2257 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2258 if (!rc) {
2259 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2260 goto fail_cmd;
2261 }
2262 return 0;
2263fail_cmd:
2264 return -EINVAL;
2265}
2266
Kiran Kandi5e809b02012-01-31 00:24:33 -08002267int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
2268 uint32_t rate, uint32_t channels)
2269{
2270 struct asm_stream_media_format_update fmt;
2271 u8 *channel_mapping;
2272 int rc = 0;
2273
2274 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
2275 channels);
2276
2277 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2278
2279 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2280
2281 fmt.format = MULTI_CHANNEL_PCM;
2282 fmt.cfg_size = sizeof(struct asm_multi_channel_pcm_fmt_blk);
2283 fmt.write_cfg.multi_ch_pcm_cfg.num_channels = channels;
2284 fmt.write_cfg.multi_ch_pcm_cfg.bits_per_sample = 16;
2285 fmt.write_cfg.multi_ch_pcm_cfg.sample_rate = rate;
2286 fmt.write_cfg.multi_ch_pcm_cfg.is_signed = 1;
2287 fmt.write_cfg.multi_ch_pcm_cfg.is_interleaved = 1;
2288 channel_mapping =
2289 fmt.write_cfg.multi_ch_pcm_cfg.channel_mapping;
2290
2291 memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
2292
2293 if (channels == 1) {
2294 channel_mapping[0] = PCM_CHANNEL_FL;
2295 } else if (channels == 2) {
2296 channel_mapping[0] = PCM_CHANNEL_FL;
2297 channel_mapping[1] = PCM_CHANNEL_FR;
2298 } else if (channels == 6) {
SathishKumar Mani6074b772012-09-26 13:49:49 -07002299 channel_mapping[0] = PCM_CHANNEL_FL;
2300 channel_mapping[1] = PCM_CHANNEL_FR;
2301 channel_mapping[2] = PCM_CHANNEL_FC;
2302 channel_mapping[3] = PCM_CHANNEL_LFE;
2303 channel_mapping[4] = PCM_CHANNEL_LB;
2304 channel_mapping[5] = PCM_CHANNEL_RB;
Kiran Kandi5e809b02012-01-31 00:24:33 -08002305 } else {
2306 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
2307 channels);
2308 return -EINVAL;
2309 }
2310
2311 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2312 if (rc < 0) {
2313 pr_err("%s:Comamnd open failed\n", __func__);
2314 goto fail_cmd;
2315 }
2316 rc = wait_event_timeout(ac->cmd_wait,
2317 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2318 if (!rc) {
2319 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2320 goto fail_cmd;
2321 }
2322 return 0;
2323fail_cmd:
2324 return -EINVAL;
2325}
2326
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002327int q6asm_media_format_block_aac(struct audio_client *ac,
2328 struct asm_aac_cfg *cfg)
2329{
2330 struct asm_stream_media_format_update fmt;
2331 int rc = 0;
2332
2333 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2334 cfg->sample_rate, cfg->ch_cfg);
2335
2336 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2337
2338 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2339
2340 fmt.format = MPEG4_AAC;
2341 fmt.cfg_size = sizeof(struct asm_aac_cfg);
2342 fmt.write_cfg.aac_cfg.format = cfg->format;
2343 fmt.write_cfg.aac_cfg.aot = cfg->aot;
2344 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
2345 fmt.write_cfg.aac_cfg.section_data_resilience =
2346 cfg->section_data_resilience;
2347 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2348 cfg->scalefactor_data_resilience;
2349 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2350 cfg->spectral_data_resilience;
2351 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2352 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2353 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2354 __func__, fmt.format, fmt.cfg_size,
2355 fmt.write_cfg.aac_cfg.format,
2356 fmt.write_cfg.aac_cfg.aot,
2357 fmt.write_cfg.aac_cfg.ch_cfg,
2358 fmt.write_cfg.aac_cfg.sample_rate);
2359 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2360 if (rc < 0) {
2361 pr_err("%s:Comamnd open failed\n", __func__);
2362 goto fail_cmd;
2363 }
2364 rc = wait_event_timeout(ac->cmd_wait,
2365 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2366 if (!rc) {
2367 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2368 goto fail_cmd;
2369 }
2370 return 0;
2371fail_cmd:
2372 return -EINVAL;
2373}
2374
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07002375
2376int q6asm_media_format_block_multi_aac(struct audio_client *ac,
2377 struct asm_aac_cfg *cfg)
2378{
2379 struct asm_stream_media_format_update fmt;
2380 int rc = 0;
2381
2382 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2383 cfg->sample_rate, cfg->ch_cfg);
2384
2385 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2386
2387 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2388
2389 fmt.format = MPEG4_MULTI_AAC;
2390 fmt.cfg_size = sizeof(struct asm_aac_cfg);
2391 fmt.write_cfg.aac_cfg.format = cfg->format;
2392 fmt.write_cfg.aac_cfg.aot = cfg->aot;
2393 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
2394 fmt.write_cfg.aac_cfg.section_data_resilience =
2395 cfg->section_data_resilience;
2396 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2397 cfg->scalefactor_data_resilience;
2398 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2399 cfg->spectral_data_resilience;
2400 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2401 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2402 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2403 __func__, fmt.format, fmt.cfg_size,
2404 fmt.write_cfg.aac_cfg.format,
2405 fmt.write_cfg.aac_cfg.aot,
2406 fmt.write_cfg.aac_cfg.ch_cfg,
2407 fmt.write_cfg.aac_cfg.sample_rate);
2408 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2409 if (rc < 0) {
2410 pr_err("%s:Comamnd open failed\n", __func__);
2411 goto fail_cmd;
2412 }
2413 rc = wait_event_timeout(ac->cmd_wait,
2414 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2415 if (!rc) {
2416 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2417 goto fail_cmd;
2418 }
2419 return 0;
2420fail_cmd:
2421 return -EINVAL;
2422}
2423
2424
Alex Wong2caeecc2011-10-28 10:52:15 +05302425
2426int q6asm_media_format_block(struct audio_client *ac, uint32_t format)
2427{
2428
2429 struct asm_stream_media_format_update fmt;
2430 int rc = 0;
2431
2432 pr_debug("%s:session[%d] format[0x%x]\n", __func__,
2433 ac->session, format);
2434
2435 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2436 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302437 switch (format) {
2438 case FORMAT_V13K:
2439 fmt.format = V13K_FS;
2440 break;
2441 case FORMAT_EVRC:
2442 fmt.format = EVRC_FS;
2443 break;
2444 case FORMAT_AMRWB:
2445 fmt.format = AMRWB_FS;
2446 break;
2447 case FORMAT_AMRNB:
2448 fmt.format = AMRNB_FS;
2449 break;
2450 case FORMAT_MP3:
2451 fmt.format = MP3;
2452 break;
Srikanth Uyyala66f781a2012-06-13 23:23:25 +05302453 case FORMAT_DTS:
2454 fmt.format = DTS;
2455 break;
2456 case FORMAT_DTS_LBR:
2457 fmt.format = DTS_LBR;
2458 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302459 default:
2460 pr_err("Invalid format[%d]\n", format);
2461 goto fail_cmd;
2462 }
Alex Wong2caeecc2011-10-28 10:52:15 +05302463 fmt.cfg_size = 0;
2464
2465 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2466 if (rc < 0) {
2467 pr_err("%s:Comamnd open failed\n", __func__);
2468 goto fail_cmd;
2469 }
2470 rc = wait_event_timeout(ac->cmd_wait,
2471 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2472 if (!rc) {
2473 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2474 goto fail_cmd;
2475 }
2476 return 0;
2477fail_cmd:
2478 return -EINVAL;
2479}
2480
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002481int q6asm_media_format_block_wma(struct audio_client *ac,
2482 void *cfg)
2483{
2484 struct asm_stream_media_format_update fmt;
2485 struct asm_wma_cfg *wma_cfg = (struct asm_wma_cfg *)cfg;
2486 int rc = 0;
2487
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002488 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 -07002489 ac->session, wma_cfg->format_tag, wma_cfg->sample_rate,
2490 wma_cfg->ch_cfg, wma_cfg->avg_bytes_per_sec,
2491 wma_cfg->block_align, wma_cfg->valid_bits_per_sample,
2492 wma_cfg->ch_mask, wma_cfg->encode_opt);
2493
2494 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2495
2496 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2497
2498 fmt.format = WMA_V9;
2499 fmt.cfg_size = sizeof(struct asm_wma_cfg);
2500 fmt.write_cfg.wma_cfg.format_tag = wma_cfg->format_tag;
2501 fmt.write_cfg.wma_cfg.ch_cfg = wma_cfg->ch_cfg;
2502 fmt.write_cfg.wma_cfg.sample_rate = wma_cfg->sample_rate;
2503 fmt.write_cfg.wma_cfg.avg_bytes_per_sec = wma_cfg->avg_bytes_per_sec;
2504 fmt.write_cfg.wma_cfg.block_align = wma_cfg->block_align;
2505 fmt.write_cfg.wma_cfg.valid_bits_per_sample =
2506 wma_cfg->valid_bits_per_sample;
2507 fmt.write_cfg.wma_cfg.ch_mask = wma_cfg->ch_mask;
2508 fmt.write_cfg.wma_cfg.encode_opt = wma_cfg->encode_opt;
2509 fmt.write_cfg.wma_cfg.adv_encode_opt = 0;
2510 fmt.write_cfg.wma_cfg.adv_encode_opt2 = 0;
2511 fmt.write_cfg.wma_cfg.drc_peak_ref = 0;
2512 fmt.write_cfg.wma_cfg.drc_peak_target = 0;
2513 fmt.write_cfg.wma_cfg.drc_ave_ref = 0;
2514 fmt.write_cfg.wma_cfg.drc_ave_target = 0;
2515
2516 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2517 if (rc < 0) {
2518 pr_err("%s:Comamnd open failed\n", __func__);
2519 goto fail_cmd;
2520 }
2521 rc = wait_event_timeout(ac->cmd_wait,
2522 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2523 if (!rc) {
2524 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2525 goto fail_cmd;
2526 }
2527 return 0;
2528fail_cmd:
2529 return -EINVAL;
2530}
2531
2532int q6asm_media_format_block_wmapro(struct audio_client *ac,
2533 void *cfg)
2534{
2535 struct asm_stream_media_format_update fmt;
2536 struct asm_wmapro_cfg *wmapro_cfg = (struct asm_wmapro_cfg *)cfg;
2537 int rc = 0;
2538
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002539 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 -07002540 ac->session, wmapro_cfg->format_tag, wmapro_cfg->sample_rate,
2541 wmapro_cfg->ch_cfg, wmapro_cfg->avg_bytes_per_sec,
2542 wmapro_cfg->block_align, wmapro_cfg->valid_bits_per_sample,
2543 wmapro_cfg->ch_mask, wmapro_cfg->encode_opt,
2544 wmapro_cfg->adv_encode_opt, wmapro_cfg->adv_encode_opt2);
2545
2546 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2547
2548 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2549
2550 fmt.format = WMA_V10PRO;
2551 fmt.cfg_size = sizeof(struct asm_wmapro_cfg);
2552 fmt.write_cfg.wmapro_cfg.format_tag = wmapro_cfg->format_tag;
2553 fmt.write_cfg.wmapro_cfg.ch_cfg = wmapro_cfg->ch_cfg;
2554 fmt.write_cfg.wmapro_cfg.sample_rate = wmapro_cfg->sample_rate;
2555 fmt.write_cfg.wmapro_cfg.avg_bytes_per_sec =
2556 wmapro_cfg->avg_bytes_per_sec;
2557 fmt.write_cfg.wmapro_cfg.block_align = wmapro_cfg->block_align;
2558 fmt.write_cfg.wmapro_cfg.valid_bits_per_sample =
2559 wmapro_cfg->valid_bits_per_sample;
2560 fmt.write_cfg.wmapro_cfg.ch_mask = wmapro_cfg->ch_mask;
2561 fmt.write_cfg.wmapro_cfg.encode_opt = wmapro_cfg->encode_opt;
2562 fmt.write_cfg.wmapro_cfg.adv_encode_opt = wmapro_cfg->adv_encode_opt;
2563 fmt.write_cfg.wmapro_cfg.adv_encode_opt2 = wmapro_cfg->adv_encode_opt2;
2564 fmt.write_cfg.wmapro_cfg.drc_peak_ref = 0;
2565 fmt.write_cfg.wmapro_cfg.drc_peak_target = 0;
2566 fmt.write_cfg.wmapro_cfg.drc_ave_ref = 0;
2567 fmt.write_cfg.wmapro_cfg.drc_ave_target = 0;
2568
2569 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2570 if (rc < 0) {
2571 pr_err("%s:Comamnd open failed\n", __func__);
2572 goto fail_cmd;
2573 }
2574 rc = wait_event_timeout(ac->cmd_wait,
2575 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2576 if (!rc) {
2577 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2578 goto fail_cmd;
2579 }
2580 return 0;
2581fail_cmd:
2582 return -EINVAL;
2583}
2584
2585int q6asm_memory_map(struct audio_client *ac, uint32_t buf_add, int dir,
2586 uint32_t bufsz, uint32_t bufcnt)
2587{
2588 struct asm_stream_cmd_memory_map mem_map;
2589 int rc = 0;
2590
2591 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2592 pr_err("APR handle NULL\n");
2593 return -EINVAL;
2594 }
2595
2596 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2597
2598 mem_map.hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP;
2599
2600 mem_map.buf_add = buf_add;
2601 mem_map.buf_size = bufsz * bufcnt;
2602 mem_map.mempool_id = 0; /* EBI */
2603 mem_map.reserved = 0;
2604
2605 q6asm_add_mmaphdr(&mem_map.hdr,
2606 sizeof(struct asm_stream_cmd_memory_map), TRUE);
2607
2608 pr_debug("buf add[%x] buf_add_parameter[%x]\n",
2609 mem_map.buf_add, buf_add);
2610
2611 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_map);
2612 if (rc < 0) {
2613 pr_err("mem_map op[0x%x]rc[%d]\n",
2614 mem_map.hdr.opcode, rc);
2615 rc = -EINVAL;
2616 goto fail_cmd;
2617 }
2618
2619 rc = wait_event_timeout(this_mmap.cmd_wait,
2620 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2621 if (!rc) {
2622 pr_err("timeout. waited for memory_map\n");
2623 rc = -EINVAL;
2624 goto fail_cmd;
2625 }
2626 rc = 0;
2627fail_cmd:
2628 return rc;
2629}
2630
2631int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add, int dir)
2632{
2633 struct asm_stream_cmd_memory_unmap mem_unmap;
2634 int rc = 0;
2635
2636 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2637 pr_err("APR handle NULL\n");
2638 return -EINVAL;
2639 }
2640 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2641
2642 q6asm_add_mmaphdr(&mem_unmap.hdr,
2643 sizeof(struct asm_stream_cmd_memory_unmap), TRUE);
2644 mem_unmap.hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP;
2645 mem_unmap.buf_add = buf_add;
2646
2647 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_unmap);
2648 if (rc < 0) {
2649 pr_err("mem_unmap op[0x%x]rc[%d]\n",
2650 mem_unmap.hdr.opcode, rc);
2651 rc = -EINVAL;
2652 goto fail_cmd;
2653 }
2654
2655 rc = wait_event_timeout(this_mmap.cmd_wait,
2656 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2657 if (!rc) {
2658 pr_err("timeout. waited for memory_map\n");
2659 rc = -EINVAL;
2660 goto fail_cmd;
2661 }
2662 rc = 0;
2663fail_cmd:
2664 return rc;
2665}
2666
2667int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain)
2668{
2669 void *vol_cmd = NULL;
2670 void *payload = NULL;
2671 struct asm_pp_params_command *cmd = NULL;
2672 struct asm_lrchannel_gain_params *lrgain = NULL;
2673 int sz = 0;
2674 int rc = 0;
2675
2676 sz = sizeof(struct asm_pp_params_command) +
2677 + sizeof(struct asm_lrchannel_gain_params);
2678 vol_cmd = kzalloc(sz, GFP_KERNEL);
2679 if (vol_cmd == NULL) {
2680 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2681 rc = -EINVAL;
2682 return rc;
2683 }
2684 cmd = (struct asm_pp_params_command *)vol_cmd;
2685 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2686 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2687 cmd->payload = NULL;
2688 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2689 sizeof(struct asm_lrchannel_gain_params);
2690 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2691 cmd->params.param_id = L_R_CHANNEL_GAIN_PARAM_ID;
2692 cmd->params.param_size = sizeof(struct asm_lrchannel_gain_params);
2693 cmd->params.reserved = 0;
2694
2695 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2696 lrgain = (struct asm_lrchannel_gain_params *)payload;
2697
2698 lrgain->left_gain = left_gain;
2699 lrgain->right_gain = right_gain;
2700 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2701 if (rc < 0) {
2702 pr_err("%s: Volume Command failed\n", __func__);
2703 rc = -EINVAL;
2704 goto fail_cmd;
2705 }
2706
2707 rc = wait_event_timeout(ac->cmd_wait,
2708 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2709 if (!rc) {
2710 pr_err("%s: timeout in sending volume command to apr\n",
2711 __func__);
2712 rc = -EINVAL;
2713 goto fail_cmd;
2714 }
2715 rc = 0;
2716fail_cmd:
2717 kfree(vol_cmd);
2718 return rc;
2719}
2720
2721static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
2722 uint32_t bufsz, uint32_t bufcnt)
2723{
2724 struct asm_stream_cmd_memory_map_regions *mmap_regions = NULL;
2725 struct asm_memory_map_regions *mregions = NULL;
2726 struct audio_port_data *port = NULL;
2727 struct audio_buffer *ab = NULL;
2728 void *mmap_region_cmd = NULL;
2729 void *payload = NULL;
2730 int rc = 0;
2731 int i = 0;
2732 int cmd_size = 0;
2733
2734 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2735 pr_err("APR handle NULL\n");
2736 return -EINVAL;
2737 }
2738 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2739
2740 cmd_size = sizeof(struct asm_stream_cmd_memory_map_regions)
2741 + sizeof(struct asm_memory_map_regions) * bufcnt;
2742
2743 mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302744 if (mmap_region_cmd == NULL) {
2745 pr_err("%s: Mem alloc failed\n", __func__);
2746 rc = -EINVAL;
2747 return rc;
2748 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002749 mmap_regions = (struct asm_stream_cmd_memory_map_regions *)
2750 mmap_region_cmd;
2751 q6asm_add_mmaphdr(&mmap_regions->hdr, cmd_size, TRUE);
2752 mmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP_REGIONS;
2753 mmap_regions->mempool_id = 0;
2754 mmap_regions->nregions = bufcnt & 0x00ff;
2755 pr_debug("map_regions->nregions = %d\n", mmap_regions->nregions);
2756 payload = ((u8 *) mmap_region_cmd +
2757 sizeof(struct asm_stream_cmd_memory_map_regions));
2758 mregions = (struct asm_memory_map_regions *)payload;
2759
2760 port = &ac->port[dir];
2761 for (i = 0; i < bufcnt; i++) {
2762 ab = &port->buf[i];
2763 mregions->phys = ab->phys;
2764 mregions->buf_size = ab->size;
2765 ++mregions;
2766 }
2767
2768 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) mmap_region_cmd);
2769 if (rc < 0) {
2770 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2771 mmap_regions->hdr.opcode, rc);
2772 rc = -EINVAL;
2773 goto fail_cmd;
2774 }
2775
2776 rc = wait_event_timeout(this_mmap.cmd_wait,
2777 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2778 if (!rc) {
2779 pr_err("timeout. waited for memory_map\n");
2780 rc = -EINVAL;
2781 goto fail_cmd;
2782 }
2783 rc = 0;
2784fail_cmd:
2785 kfree(mmap_region_cmd);
2786 return rc;
2787}
2788
2789static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir,
2790 uint32_t bufsz, uint32_t bufcnt)
2791{
2792 struct asm_stream_cmd_memory_unmap_regions *unmap_regions = NULL;
2793 struct asm_memory_unmap_regions *mregions = NULL;
2794 struct audio_port_data *port = NULL;
2795 struct audio_buffer *ab = NULL;
2796 void *unmap_region_cmd = NULL;
2797 void *payload = NULL;
2798 int rc = 0;
2799 int i = 0;
2800 int cmd_size = 0;
2801
2802 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2803 pr_err("APR handle NULL\n");
2804 return -EINVAL;
2805 }
2806 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2807
2808 cmd_size = sizeof(struct asm_stream_cmd_memory_unmap_regions) +
2809 sizeof(struct asm_memory_unmap_regions) * bufcnt;
2810
2811 unmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302812 if (unmap_region_cmd == NULL) {
2813 pr_err("%s: Mem alloc failed\n", __func__);
2814 rc = -EINVAL;
2815 return rc;
2816 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002817 unmap_regions = (struct asm_stream_cmd_memory_unmap_regions *)
2818 unmap_region_cmd;
2819 q6asm_add_mmaphdr(&unmap_regions->hdr, cmd_size, TRUE);
2820 unmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS;
2821 unmap_regions->nregions = bufcnt & 0x00ff;
2822 pr_debug("unmap_regions->nregions = %d\n", unmap_regions->nregions);
2823 payload = ((u8 *) unmap_region_cmd +
2824 sizeof(struct asm_stream_cmd_memory_unmap_regions));
2825 mregions = (struct asm_memory_unmap_regions *)payload;
2826 port = &ac->port[dir];
2827 for (i = 0; i < bufcnt; i++) {
2828 ab = &port->buf[i];
2829 mregions->phys = ab->phys;
2830 ++mregions;
2831 }
2832
2833 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) unmap_region_cmd);
2834 if (rc < 0) {
2835 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2836 unmap_regions->hdr.opcode, rc);
2837 goto fail_cmd;
2838 }
2839
2840 rc = wait_event_timeout(this_mmap.cmd_wait,
2841 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2842 if (!rc) {
2843 pr_err("timeout. waited for memory_unmap\n");
2844 goto fail_cmd;
2845 }
2846 rc = 0;
2847
2848fail_cmd:
2849 kfree(unmap_region_cmd);
2850 return rc;
2851}
2852
2853int q6asm_set_mute(struct audio_client *ac, int muteflag)
2854{
2855 void *vol_cmd = NULL;
2856 void *payload = NULL;
2857 struct asm_pp_params_command *cmd = NULL;
2858 struct asm_mute_params *mute = NULL;
2859 int sz = 0;
2860 int rc = 0;
2861
2862 sz = sizeof(struct asm_pp_params_command) +
2863 + sizeof(struct asm_mute_params);
2864 vol_cmd = kzalloc(sz, GFP_KERNEL);
2865 if (vol_cmd == NULL) {
2866 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2867 rc = -EINVAL;
2868 return rc;
2869 }
2870 cmd = (struct asm_pp_params_command *)vol_cmd;
2871 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2872 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2873 cmd->payload = NULL;
2874 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2875 sizeof(struct asm_mute_params);
2876 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2877 cmd->params.param_id = MUTE_CONFIG_PARAM_ID;
2878 cmd->params.param_size = sizeof(struct asm_mute_params);
2879 cmd->params.reserved = 0;
2880
2881 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2882 mute = (struct asm_mute_params *)payload;
2883
2884 mute->muteflag = muteflag;
2885 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2886 if (rc < 0) {
2887 pr_err("%s: Mute Command failed\n", __func__);
2888 rc = -EINVAL;
2889 goto fail_cmd;
2890 }
2891
2892 rc = wait_event_timeout(ac->cmd_wait,
2893 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2894 if (!rc) {
2895 pr_err("%s: timeout in sending mute command to apr\n",
2896 __func__);
2897 rc = -EINVAL;
2898 goto fail_cmd;
2899 }
2900 rc = 0;
2901fail_cmd:
2902 kfree(vol_cmd);
2903 return rc;
2904}
2905
2906int q6asm_set_volume(struct audio_client *ac, int volume)
2907{
2908 void *vol_cmd = NULL;
2909 void *payload = NULL;
2910 struct asm_pp_params_command *cmd = NULL;
2911 struct asm_master_gain_params *mgain = NULL;
2912 int sz = 0;
2913 int rc = 0;
2914
2915 sz = sizeof(struct asm_pp_params_command) +
2916 + sizeof(struct asm_master_gain_params);
2917 vol_cmd = kzalloc(sz, GFP_KERNEL);
2918 if (vol_cmd == NULL) {
2919 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2920 rc = -EINVAL;
2921 return rc;
2922 }
2923 cmd = (struct asm_pp_params_command *)vol_cmd;
2924 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2925 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2926 cmd->payload = NULL;
2927 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2928 sizeof(struct asm_master_gain_params);
2929 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2930 cmd->params.param_id = MASTER_GAIN_PARAM_ID;
2931 cmd->params.param_size = sizeof(struct asm_master_gain_params);
2932 cmd->params.reserved = 0;
2933
2934 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2935 mgain = (struct asm_master_gain_params *)payload;
2936
2937 mgain->master_gain = volume;
2938 mgain->padding = 0x00;
2939 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2940 if (rc < 0) {
2941 pr_err("%s: Volume Command failed\n", __func__);
2942 rc = -EINVAL;
2943 goto fail_cmd;
2944 }
2945
2946 rc = wait_event_timeout(ac->cmd_wait,
2947 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2948 if (!rc) {
2949 pr_err("%s: timeout in sending volume command to apr\n",
2950 __func__);
2951 rc = -EINVAL;
2952 goto fail_cmd;
2953 }
2954 rc = 0;
2955fail_cmd:
2956 kfree(vol_cmd);
2957 return rc;
2958}
2959
2960int q6asm_set_softpause(struct audio_client *ac,
2961 struct asm_softpause_params *pause_param)
2962{
2963 void *vol_cmd = NULL;
2964 void *payload = NULL;
2965 struct asm_pp_params_command *cmd = NULL;
2966 struct asm_softpause_params *params = NULL;
2967 int sz = 0;
2968 int rc = 0;
2969
2970 sz = sizeof(struct asm_pp_params_command) +
2971 + sizeof(struct asm_softpause_params);
2972 vol_cmd = kzalloc(sz, GFP_KERNEL);
2973 if (vol_cmd == NULL) {
2974 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2975 rc = -EINVAL;
2976 return rc;
2977 }
2978 cmd = (struct asm_pp_params_command *)vol_cmd;
2979 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2980 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2981 cmd->payload = NULL;
2982 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2983 sizeof(struct asm_softpause_params);
2984 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2985 cmd->params.param_id = SOFT_PAUSE_PARAM_ID;
2986 cmd->params.param_size = sizeof(struct asm_softpause_params);
2987 cmd->params.reserved = 0;
2988
2989 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2990 params = (struct asm_softpause_params *)payload;
2991
2992 params->enable = pause_param->enable;
2993 params->period = pause_param->period;
2994 params->step = pause_param->step;
2995 params->rampingcurve = pause_param->rampingcurve;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002996 pr_debug("%s: soft Pause Command: enable = %d, period = %d, step = %d, curve = %d\n",
2997 __func__, params->enable,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002998 params->period, params->step, params->rampingcurve);
2999 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3000 if (rc < 0) {
3001 pr_err("%s: Volume Command(soft_pause) failed\n", __func__);
3002 rc = -EINVAL;
3003 goto fail_cmd;
3004 }
3005
3006 rc = wait_event_timeout(ac->cmd_wait,
3007 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3008 if (!rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003009 pr_err("%s: timeout in sending volume command(soft_pause) to apr\n",
3010 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003011 rc = -EINVAL;
3012 goto fail_cmd;
3013 }
3014 rc = 0;
3015fail_cmd:
3016 kfree(vol_cmd);
3017 return rc;
3018}
3019
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003020int q6asm_set_softvolume(struct audio_client *ac,
3021 struct asm_softvolume_params *softvol_param)
3022{
3023 void *vol_cmd = NULL;
3024 void *payload = NULL;
3025 struct asm_pp_params_command *cmd = NULL;
3026 struct asm_softvolume_params *params = NULL;
3027 int sz = 0;
3028 int rc = 0;
3029
3030 sz = sizeof(struct asm_pp_params_command) +
3031 + sizeof(struct asm_softvolume_params);
3032 vol_cmd = kzalloc(sz, GFP_KERNEL);
3033 if (vol_cmd == NULL) {
3034 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3035 rc = -EINVAL;
3036 return rc;
3037 }
3038 cmd = (struct asm_pp_params_command *)vol_cmd;
3039 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3040 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3041 cmd->payload = NULL;
3042 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3043 sizeof(struct asm_softvolume_params);
3044 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3045 cmd->params.param_id = SOFT_VOLUME_PARAM_ID;
3046 cmd->params.param_size = sizeof(struct asm_softvolume_params);
3047 cmd->params.reserved = 0;
3048
3049 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3050 params = (struct asm_softvolume_params *)payload;
3051
3052 params->period = softvol_param->period;
3053 params->step = softvol_param->step;
3054 params->rampingcurve = softvol_param->rampingcurve;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003055 pr_debug("%s: soft Volume:opcode = %d,payload_sz =%d,module_id =%d, param_id = %d, param_sz = %d\n",
3056 __func__,
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003057 cmd->hdr.opcode, cmd->payload_size,
3058 cmd->params.module_id, cmd->params.param_id,
3059 cmd->params.param_size);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003060 pr_debug("%s: soft Volume Command: period = %d, step = %d, curve = %d\n",
3061 __func__, params->period,
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003062 params->step, params->rampingcurve);
3063 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3064 if (rc < 0) {
3065 pr_err("%s: Volume Command(soft_volume) failed\n", __func__);
3066 rc = -EINVAL;
3067 goto fail_cmd;
3068 }
3069
3070 rc = wait_event_timeout(ac->cmd_wait,
3071 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3072 if (!rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003073 pr_err("%s: timeout in sending volume command(soft_volume) to apr\n",
3074 __func__);
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003075 rc = -EINVAL;
3076 goto fail_cmd;
3077 }
3078 rc = 0;
3079fail_cmd:
3080 kfree(vol_cmd);
3081 return rc;
3082}
3083
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003084int q6asm_equalizer(struct audio_client *ac, void *eq)
3085{
3086 void *eq_cmd = NULL;
3087 void *payload = NULL;
3088 struct asm_pp_params_command *cmd = NULL;
3089 struct asm_equalizer_params *equalizer = NULL;
3090 struct msm_audio_eq_stream_config *eq_params = NULL;
3091 int i = 0;
3092 int sz = 0;
3093 int rc = 0;
3094
3095 sz = sizeof(struct asm_pp_params_command) +
3096 + sizeof(struct asm_equalizer_params);
3097 eq_cmd = kzalloc(sz, GFP_KERNEL);
3098 if (eq_cmd == NULL) {
3099 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3100 rc = -EINVAL;
3101 goto fail_cmd;
3102 }
3103 eq_params = (struct msm_audio_eq_stream_config *) eq;
3104 cmd = (struct asm_pp_params_command *)eq_cmd;
3105 q6asm_add_hdr(ac, &cmd->hdr, sz, TRUE);
3106 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3107 cmd->payload = NULL;
3108 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3109 sizeof(struct asm_equalizer_params);
3110 cmd->params.module_id = EQUALIZER_MODULE_ID;
3111 cmd->params.param_id = EQUALIZER_PARAM_ID;
3112 cmd->params.param_size = sizeof(struct asm_equalizer_params);
3113 cmd->params.reserved = 0;
3114 payload = (u8 *)(eq_cmd + sizeof(struct asm_pp_params_command));
3115 equalizer = (struct asm_equalizer_params *)payload;
3116
3117 equalizer->enable = eq_params->enable;
3118 equalizer->num_bands = eq_params->num_bands;
3119 pr_debug("%s: enable:%d numbands:%d\n", __func__, eq_params->enable,
3120 eq_params->num_bands);
3121 for (i = 0; i < eq_params->num_bands; i++) {
3122 equalizer->eq_bands[i].band_idx =
3123 eq_params->eq_bands[i].band_idx;
3124 equalizer->eq_bands[i].filter_type =
3125 eq_params->eq_bands[i].filter_type;
3126 equalizer->eq_bands[i].center_freq_hz =
3127 eq_params->eq_bands[i].center_freq_hz;
3128 equalizer->eq_bands[i].filter_gain =
3129 eq_params->eq_bands[i].filter_gain;
3130 equalizer->eq_bands[i].q_factor =
3131 eq_params->eq_bands[i].q_factor;
3132 pr_debug("%s: filter_type:%u bandnum:%d\n", __func__,
3133 eq_params->eq_bands[i].filter_type, i);
3134 pr_debug("%s: center_freq_hz:%u bandnum:%d\n", __func__,
3135 eq_params->eq_bands[i].center_freq_hz, i);
3136 pr_debug("%s: filter_gain:%d bandnum:%d\n", __func__,
3137 eq_params->eq_bands[i].filter_gain, i);
3138 pr_debug("%s: q_factor:%d bandnum:%d\n", __func__,
3139 eq_params->eq_bands[i].q_factor, i);
3140 }
3141 rc = apr_send_pkt(ac->apr, (uint32_t *) eq_cmd);
3142 if (rc < 0) {
3143 pr_err("%s: Equalizer Command failed\n", __func__);
3144 rc = -EINVAL;
3145 goto fail_cmd;
3146 }
3147
3148 rc = wait_event_timeout(ac->cmd_wait,
3149 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3150 if (!rc) {
3151 pr_err("%s: timeout in sending equalizer command to apr\n",
3152 __func__);
3153 rc = -EINVAL;
3154 goto fail_cmd;
3155 }
3156 rc = 0;
3157fail_cmd:
3158 kfree(eq_cmd);
3159 return rc;
3160}
3161
3162int q6asm_read(struct audio_client *ac)
3163{
3164 struct asm_stream_cmd_read read;
3165 struct audio_buffer *ab;
3166 int dsp_buf;
3167 struct audio_port_data *port;
3168 int rc;
3169 if (!ac || ac->apr == NULL) {
3170 pr_err("APR handle NULL\n");
3171 return -EINVAL;
3172 }
3173 if (ac->io_mode == SYNC_IO_MODE) {
3174 port = &ac->port[OUT];
3175
3176 q6asm_add_hdr(ac, &read.hdr, sizeof(read), FALSE);
3177
3178 mutex_lock(&port->lock);
3179
3180 dsp_buf = port->dsp_buf;
3181 ab = &port->buf[dsp_buf];
3182
3183 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
3184 __func__,
3185 ac->session,
3186 dsp_buf,
3187 (void *)port->buf[dsp_buf].data,
3188 port->cpu_buf,
3189 (void *)port->buf[port->cpu_buf].phys);
3190
3191 read.hdr.opcode = ASM_DATA_CMD_READ;
3192 read.buf_add = ab->phys;
3193 read.buf_size = ab->size;
3194 read.uid = port->dsp_buf;
3195 read.hdr.token = port->dsp_buf;
3196
3197 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3198 mutex_unlock(&port->lock);
3199 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
3200 read.buf_add,
3201 read.hdr.token,
3202 read.uid);
3203 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3204 if (rc < 0) {
3205 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
3206 goto fail_cmd;
3207 }
3208 return 0;
3209 }
3210fail_cmd:
3211 return -EINVAL;
3212}
3213
3214int q6asm_read_nolock(struct audio_client *ac)
3215{
3216 struct asm_stream_cmd_read read;
3217 struct audio_buffer *ab;
3218 int dsp_buf;
3219 struct audio_port_data *port;
3220 int rc;
3221 if (!ac || ac->apr == NULL) {
3222 pr_err("APR handle NULL\n");
3223 return -EINVAL;
3224 }
3225 if (ac->io_mode == SYNC_IO_MODE) {
3226 port = &ac->port[OUT];
3227
3228 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3229
3230
3231 dsp_buf = port->dsp_buf;
3232 ab = &port->buf[dsp_buf];
3233
3234 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
3235 __func__,
3236 ac->session,
3237 dsp_buf,
3238 (void *)port->buf[dsp_buf].data,
3239 port->cpu_buf,
3240 (void *)port->buf[port->cpu_buf].phys);
3241
3242 read.hdr.opcode = ASM_DATA_CMD_READ;
3243 read.buf_add = ab->phys;
3244 read.buf_size = ab->size;
3245 read.uid = port->dsp_buf;
3246 read.hdr.token = port->dsp_buf;
3247
3248 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3249 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
3250 read.buf_add,
3251 read.hdr.token,
3252 read.uid);
3253 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3254 if (rc < 0) {
3255 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
3256 goto fail_cmd;
3257 }
3258 return 0;
3259 }
3260fail_cmd:
3261 return -EINVAL;
3262}
3263
3264
3265static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
3266 uint32_t pkt_size, uint32_t cmd_flg)
3267{
3268 pr_debug("session=%d pkt size=%d cmd_flg=%d\n", pkt_size, cmd_flg,
3269 ac->session);
3270 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
3271 APR_HDR_LEN(sizeof(struct apr_hdr)),\
3272 APR_PKT_VER);
3273 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
3274 hdr->src_domain = APR_DOMAIN_APPS;
3275 hdr->dest_svc = APR_SVC_ASM;
3276 hdr->dest_domain = APR_DOMAIN_ADSP;
3277 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
3278 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
3279 if (cmd_flg) {
3280 hdr->token = ac->session;
3281 atomic_set(&ac->cmd_state, 1);
3282 }
3283 hdr->pkt_size = pkt_size;
3284 return;
3285}
3286
3287int q6asm_async_write(struct audio_client *ac,
3288 struct audio_aio_write_param *param)
3289{
3290 int rc = 0;
3291 struct asm_stream_cmd_write write;
3292
3293 if (!ac || ac->apr == NULL) {
3294 pr_err("%s: APR handle NULL\n", __func__);
3295 return -EINVAL;
3296 }
3297
3298 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write), FALSE);
3299
3300 /* Pass physical address as token for AIO scheme */
3301 write.hdr.token = param->uid;
3302 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3303 write.buf_add = param->paddr;
3304 write.avail_bytes = param->len;
3305 write.uid = param->uid;
3306 write.msw_ts = param->msw_ts;
3307 write.lsw_ts = param->lsw_ts;
3308 /* Use 0xFF00 for disabling timestamps */
3309 if (param->flags == 0xFF00)
3310 write.uflags = (0x00000000 | (param->flags & 0x800000FF));
3311 else
3312 write.uflags = (0x80000000 | param->flags);
3313
3314 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3315 write.buf_add, write.avail_bytes);
3316
3317 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3318 if (rc < 0) {
3319 pr_debug("[%s] write op[0x%x]rc[%d]\n", __func__,
3320 write.hdr.opcode, rc);
3321 goto fail_cmd;
3322 }
3323 return 0;
3324fail_cmd:
3325 return -EINVAL;
3326}
3327
3328int q6asm_async_read(struct audio_client *ac,
3329 struct audio_aio_read_param *param)
3330{
3331 int rc = 0;
3332 struct asm_stream_cmd_read read;
3333
3334 if (!ac || ac->apr == NULL) {
3335 pr_err("%s: APR handle NULL\n", __func__);
3336 return -EINVAL;
3337 }
3338
3339 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3340
3341 /* Pass physical address as token for AIO scheme */
3342 read.hdr.token = param->paddr;
3343 read.hdr.opcode = ASM_DATA_CMD_READ;
3344 read.buf_add = param->paddr;
3345 read.buf_size = param->len;
3346 read.uid = param->uid;
3347
3348 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3349 read.buf_add, read.buf_size);
3350
3351 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3352 if (rc < 0) {
3353 pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
3354 read.hdr.opcode, rc);
3355 goto fail_cmd;
3356 }
3357 return 0;
3358fail_cmd:
3359 return -EINVAL;
3360}
3361
Subhash Chandra Bose Naripeddy694b7d92012-06-20 20:46:13 -07003362int q6asm_async_read_compressed(struct audio_client *ac,
3363 struct audio_aio_read_param *param)
3364{
3365 int rc = 0;
3366 struct asm_stream_cmd_read read;
3367
3368 if (!ac || ac->apr == NULL) {
3369 pr_err("%s: APR handle NULL\n", __func__);
3370 return -EINVAL;
3371 }
3372
3373 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3374
3375 /* Pass physical address as token for AIO scheme */
3376 read.hdr.token = param->paddr;
3377 read.hdr.opcode = ASM_DATA_CMD_READ_COMPRESSED;
3378 read.buf_add = param->paddr;
3379 read.buf_size = param->len;
3380 read.uid = param->uid;
3381
3382 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3383 read.buf_add, read.buf_size);
3384
3385 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3386 if (rc < 0) {
3387 pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
3388 read.hdr.opcode, rc);
3389 goto fail_cmd;
3390 }
3391 return 0;
3392fail_cmd:
3393 return -EINVAL;
3394}
3395
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003396int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3397 uint32_t lsw_ts, uint32_t flags)
3398{
3399 int rc = 0;
3400 struct asm_stream_cmd_write write;
3401 struct audio_port_data *port;
3402 struct audio_buffer *ab;
3403 int dsp_buf = 0;
3404
3405 if (!ac || ac->apr == NULL) {
3406 pr_err("APR handle NULL\n");
3407 return -EINVAL;
3408 }
3409 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3410 if (ac->io_mode == SYNC_IO_MODE) {
3411 port = &ac->port[IN];
3412
3413 q6asm_add_hdr(ac, &write.hdr, sizeof(write),
3414 FALSE);
3415 mutex_lock(&port->lock);
3416
3417 dsp_buf = port->dsp_buf;
3418 ab = &port->buf[dsp_buf];
3419
3420 write.hdr.token = port->dsp_buf;
3421 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3422 write.buf_add = ab->phys;
3423 write.avail_bytes = len;
3424 write.uid = port->dsp_buf;
3425 write.msw_ts = msw_ts;
3426 write.lsw_ts = lsw_ts;
3427 /* Use 0xFF00 for disabling timestamps */
3428 if (flags == 0xFF00)
3429 write.uflags = (0x00000000 | (flags & 0x800000FF));
3430 else
3431 write.uflags = (0x80000000 | flags);
3432 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3433
3434 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3435 , __func__,
3436 ab->phys,
3437 write.buf_add,
3438 write.hdr.token,
3439 write.uid);
3440 mutex_unlock(&port->lock);
Rajesha Kini3498c932011-07-19 19:58:27 +05303441#ifdef CONFIG_DEBUG_FS
3442 if (out_enable_flag) {
3443 char zero_pattern[2] = {0x00, 0x00};
3444 /* If First two byte is non zero and last two byte
3445 is zero then it is warm output pattern */
3446 if ((strncmp(((char *)ab->data), zero_pattern, 2)) &&
3447 (!strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3448 do_gettimeofday(&out_warm_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003449 pr_debug("WARM:apr_send_pkt at %ld sec %ld microsec\n",
3450 out_warm_tv.tv_sec,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303451 out_warm_tv.tv_usec);
3452 pr_debug("Warm Pattern Matched");
3453 }
3454 /* If First two byte is zero and last two byte is
3455 non zero then it is cont ouput pattern */
3456 else if ((!strncmp(((char *)ab->data), zero_pattern, 2))
3457 && (strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3458 do_gettimeofday(&out_cont_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003459 pr_debug("CONT:apr_send_pkt at %ld sec %ld microsec\n",
3460 out_cont_tv.tv_sec,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303461 out_cont_tv.tv_usec);
3462 pr_debug("Cont Pattern Matched");
3463 }
3464 }
3465#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003466 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3467 if (rc < 0) {
3468 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3469 goto fail_cmd;
3470 }
3471 pr_debug("%s: WRITE SUCCESS\n", __func__);
3472 return 0;
3473 }
3474fail_cmd:
3475 return -EINVAL;
3476}
3477
3478int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3479 uint32_t lsw_ts, uint32_t flags)
3480{
3481 int rc = 0;
3482 struct asm_stream_cmd_write write;
3483 struct audio_port_data *port;
3484 struct audio_buffer *ab;
3485 int dsp_buf = 0;
3486
3487 if (!ac || ac->apr == NULL) {
3488 pr_err("APR handle NULL\n");
3489 return -EINVAL;
3490 }
3491 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3492 if (ac->io_mode == SYNC_IO_MODE) {
3493 port = &ac->port[IN];
3494
3495 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write),
3496 FALSE);
3497
3498 dsp_buf = port->dsp_buf;
3499 ab = &port->buf[dsp_buf];
3500
3501 write.hdr.token = port->dsp_buf;
3502 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3503 write.buf_add = ab->phys;
3504 write.avail_bytes = len;
3505 write.uid = port->dsp_buf;
3506 write.msw_ts = msw_ts;
3507 write.lsw_ts = lsw_ts;
3508 /* Use 0xFF00 for disabling timestamps */
3509 if (flags == 0xFF00)
3510 write.uflags = (0x00000000 | (flags & 0x800000FF));
3511 else
3512 write.uflags = (0x80000000 | flags);
3513 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3514
3515 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3516 , __func__,
3517 ab->phys,
3518 write.buf_add,
3519 write.hdr.token,
3520 write.uid);
3521
3522 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3523 if (rc < 0) {
3524 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3525 goto fail_cmd;
3526 }
3527 pr_debug("%s: WRITE SUCCESS\n", __func__);
3528 return 0;
3529 }
3530fail_cmd:
3531 return -EINVAL;
3532}
3533
3534uint64_t q6asm_get_session_time(struct audio_client *ac)
3535{
3536 struct apr_hdr hdr;
3537 int rc;
3538
3539 if (!ac || ac->apr == NULL) {
3540 pr_err("APR handle NULL\n");
3541 return -EINVAL;
3542 }
Swaminathan Sathappanc7f98992012-07-09 11:07:12 -07003543 q6asm_add_hdr(ac, &hdr, sizeof(hdr), FALSE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003544 hdr.opcode = ASM_SESSION_CMD_GET_SESSION_TIME;
3545 atomic_set(&ac->time_flag, 1);
3546
3547 pr_debug("%s: session[%d]opcode[0x%x]\n", __func__,
3548 ac->session,
3549 hdr.opcode);
3550 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3551 if (rc < 0) {
3552 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3553 goto fail_cmd;
3554 }
3555 rc = wait_event_timeout(ac->time_wait,
3556 (atomic_read(&ac->time_flag) == 0), 5*HZ);
3557 if (!rc) {
3558 pr_err("%s: timeout in getting session time from DSP\n",
3559 __func__);
3560 goto fail_cmd;
3561 }
3562 return ac->time_stamp;
3563
3564fail_cmd:
3565 return -EINVAL;
3566}
3567
3568int q6asm_cmd(struct audio_client *ac, int cmd)
3569{
3570 struct apr_hdr hdr;
3571 int rc;
3572 atomic_t *state;
3573 int cnt = 0;
3574
3575 if (!ac || ac->apr == NULL) {
3576 pr_err("APR handle NULL\n");
3577 return -EINVAL;
3578 }
3579 q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
3580 switch (cmd) {
3581 case CMD_PAUSE:
3582 pr_debug("%s:CMD_PAUSE\n", __func__);
3583 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3584 state = &ac->cmd_state;
3585 break;
3586 case CMD_FLUSH:
3587 pr_debug("%s:CMD_FLUSH\n", __func__);
3588 hdr.opcode = ASM_STREAM_CMD_FLUSH;
3589 state = &ac->cmd_state;
3590 break;
3591 case CMD_OUT_FLUSH:
3592 pr_debug("%s:CMD_OUT_FLUSH\n", __func__);
3593 hdr.opcode = ASM_STREAM_CMD_FLUSH_READBUFS;
3594 state = &ac->cmd_state;
3595 break;
3596 case CMD_EOS:
3597 pr_debug("%s:CMD_EOS\n", __func__);
3598 hdr.opcode = ASM_DATA_CMD_EOS;
3599 atomic_set(&ac->cmd_state, 0);
3600 state = &ac->cmd_state;
3601 break;
3602 case CMD_CLOSE:
3603 pr_debug("%s:CMD_CLOSE\n", __func__);
3604 hdr.opcode = ASM_STREAM_CMD_CLOSE;
3605 state = &ac->cmd_state;
3606 break;
3607 default:
3608 pr_err("Invalid format[%d]\n", cmd);
3609 goto fail_cmd;
3610 }
3611 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3612 ac->session,
3613 hdr.opcode);
3614 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3615 if (rc < 0) {
3616 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3617 goto fail_cmd;
3618 }
3619 rc = wait_event_timeout(ac->cmd_wait, (atomic_read(state) == 0), 5*HZ);
3620 if (!rc) {
3621 pr_err("timeout. waited for response opcode[0x%x]\n",
3622 hdr.opcode);
3623 goto fail_cmd;
3624 }
3625 if (cmd == CMD_FLUSH)
3626 q6asm_reset_buf_state(ac);
3627 if (cmd == CMD_CLOSE) {
3628 /* check if DSP return all buffers */
3629 if (ac->port[IN].buf) {
3630 for (cnt = 0; cnt < ac->port[IN].max_buf_cnt;
3631 cnt++) {
3632 if (ac->port[IN].buf[cnt].used == IN) {
3633 pr_debug("Write Buf[%d] not returned\n",
3634 cnt);
3635 }
3636 }
3637 }
3638 if (ac->port[OUT].buf) {
3639 for (cnt = 0; cnt < ac->port[OUT].max_buf_cnt; cnt++) {
3640 if (ac->port[OUT].buf[cnt].used == OUT) {
3641 pr_debug("Read Buf[%d] not returned\n",
3642 cnt);
3643 }
3644 }
3645 }
3646 }
3647 return 0;
3648fail_cmd:
3649 return -EINVAL;
3650}
3651
3652int q6asm_cmd_nowait(struct audio_client *ac, int cmd)
3653{
3654 struct apr_hdr hdr;
3655 int rc;
3656
3657 if (!ac || ac->apr == NULL) {
3658 pr_err("%s:APR handle NULL\n", __func__);
3659 return -EINVAL;
3660 }
3661 q6asm_add_hdr_async(ac, &hdr, sizeof(hdr), TRUE);
3662 switch (cmd) {
3663 case CMD_PAUSE:
3664 pr_debug("%s:CMD_PAUSE\n", __func__);
3665 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3666 break;
3667 case CMD_EOS:
3668 pr_debug("%s:CMD_EOS\n", __func__);
3669 hdr.opcode = ASM_DATA_CMD_EOS;
3670 break;
3671 default:
3672 pr_err("%s:Invalid format[%d]\n", __func__, cmd);
3673 goto fail_cmd;
3674 }
3675 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3676 ac->session,
3677 hdr.opcode);
Jay Wang0668d1062012-07-11 18:53:21 -07003678
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003679 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3680 if (rc < 0) {
3681 pr_err("%s:Commmand 0x%x failed\n", __func__, hdr.opcode);
3682 goto fail_cmd;
3683 }
Jay Wang0668d1062012-07-11 18:53:21 -07003684 atomic_inc(&ac->nowait_cmd_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003685 return 0;
3686fail_cmd:
3687 return -EINVAL;
3688}
3689
3690static void q6asm_reset_buf_state(struct audio_client *ac)
3691{
3692 int cnt = 0;
3693 int loopcnt = 0;
3694 struct audio_port_data *port = NULL;
3695
3696 if (ac->io_mode == SYNC_IO_MODE) {
3697 mutex_lock(&ac->cmd_lock);
3698 for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
3699 port = &ac->port[loopcnt];
3700 cnt = port->max_buf_cnt - 1;
3701 port->dsp_buf = 0;
3702 port->cpu_buf = 0;
3703 while (cnt >= 0) {
3704 if (!port->buf)
3705 continue;
3706 port->buf[cnt].used = 1;
3707 cnt--;
3708 }
3709 }
3710 mutex_unlock(&ac->cmd_lock);
3711 }
3712}
3713
3714int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable)
3715{
3716 struct asm_stream_cmd_reg_tx_overflow_event tx_overflow;
3717 int rc;
3718
3719 if (!ac || ac->apr == NULL) {
3720 pr_err("APR handle NULL\n");
3721 return -EINVAL;
3722 }
3723 pr_debug("%s:session[%d]enable[%d]\n", __func__,
3724 ac->session, enable);
3725 q6asm_add_hdr(ac, &tx_overflow.hdr, sizeof(tx_overflow), TRUE);
3726
3727 tx_overflow.hdr.opcode = \
3728 ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS;
3729 /* tx overflow event: enable */
3730 tx_overflow.enable = enable;
3731
3732 rc = apr_send_pkt(ac->apr, (uint32_t *) &tx_overflow);
3733 if (rc < 0) {
3734 pr_err("tx overflow op[0x%x]rc[%d]\n", \
3735 tx_overflow.hdr.opcode, rc);
3736 goto fail_cmd;
3737 }
3738 rc = wait_event_timeout(ac->cmd_wait,
3739 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3740 if (!rc) {
3741 pr_err("timeout. waited for tx overflow\n");
3742 goto fail_cmd;
3743 }
3744 return 0;
3745fail_cmd:
3746 return -EINVAL;
3747}
3748
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003749int q6asm_get_apr_service_id(int session_id)
3750{
3751 pr_debug("%s\n", __func__);
3752
Shiv Maliyappanahallia84982a2012-01-19 15:25:04 -08003753 if (session_id < 0 || session_id > SESSION_MAX) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003754 pr_err("%s: invalid session_id = %d\n", __func__, session_id);
3755 return -EINVAL;
3756 }
3757
3758 return ((struct apr_svc *)session[session_id]->apr)->id;
3759}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003760
3761
3762static int __init q6asm_init(void)
3763{
3764 pr_debug("%s\n", __func__);
3765 init_waitqueue_head(&this_mmap.cmd_wait);
3766 memset(session, 0, sizeof(session));
Rajesha Kini3498c932011-07-19 19:58:27 +05303767#ifdef CONFIG_DEBUG_FS
3768 out_buffer = kmalloc(OUT_BUFFER_SIZE, GFP_KERNEL);
3769 out_dentry = debugfs_create_file("audio_out_latency_measurement_node",\
3770 S_IFREG | S_IRUGO | S_IWUGO,\
3771 NULL, NULL, &audio_output_latency_debug_fops);
3772 if (IS_ERR(out_dentry))
3773 pr_err("debugfs_create_file failed\n");
3774 in_buffer = kmalloc(IN_BUFFER_SIZE, GFP_KERNEL);
3775 in_dentry = debugfs_create_file("audio_in_latency_measurement_node",\
3776 S_IFREG | S_IRUGO | S_IWUGO,\
3777 NULL, NULL, &audio_input_latency_debug_fops);
3778 if (IS_ERR(in_dentry))
3779 pr_err("debugfs_create_file failed\n");
3780#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003781 return 0;
3782}
3783
3784device_initcall(q6asm_init);