Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved. |
| 4 | * 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 Romberger | fce8f51 | 2011-07-18 16:46:09 -0700 | [diff] [blame] | 30 | #include <linux/debugfs.h> |
| 31 | #include <linux/time.h> |
| 32 | #include <linux/atomic.h> |
| 33 | |
| 34 | #include <asm/ioctls.h> |
| 35 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 36 | #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> |
| 41 | #include <mach/msm_subsystem_map.h> |
Ben Romberger | fce8f51 | 2011-07-18 16:46:09 -0700 | [diff] [blame] | 42 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 43 | #include <sound/apr_audio.h> |
| 44 | #include <sound/q6asm.h> |
Ben Romberger | fce8f51 | 2011-07-18 16:46:09 -0700 | [diff] [blame] | 45 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 46 | |
| 47 | #define TRUE 0x01 |
| 48 | #define FALSE 0x00 |
| 49 | #define READDONE_IDX_STATUS 0 |
| 50 | #define READDONE_IDX_BUFFER 1 |
| 51 | #define READDONE_IDX_SIZE 2 |
| 52 | #define READDONE_IDX_OFFSET 3 |
| 53 | #define READDONE_IDX_MSW_TS 4 |
| 54 | #define READDONE_IDX_LSW_TS 5 |
| 55 | #define READDONE_IDX_FLAGS 6 |
| 56 | #define READDONE_IDX_NUMFRAMES 7 |
| 57 | #define READDONE_IDX_ID 8 |
Rajesha Kini | 3498c93 | 2011-07-19 19:58:27 +0530 | [diff] [blame] | 58 | #ifdef CONFIG_DEBUG_FS |
| 59 | #define OUT_BUFFER_SIZE 56 |
| 60 | #define IN_BUFFER_SIZE 24 |
| 61 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 62 | static DEFINE_MUTEX(session_lock); |
| 63 | |
| 64 | /* session id: 0 reserved */ |
| 65 | static struct audio_client *session[SESSION_MAX+1]; |
| 66 | static int32_t q6asm_mmapcallback(struct apr_client_data *data, void *priv); |
| 67 | static int32_t q6asm_callback(struct apr_client_data *data, void *priv); |
| 68 | static void q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr, |
| 69 | uint32_t pkt_size, uint32_t cmd_flg); |
| 70 | static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr, |
| 71 | uint32_t pkt_size, uint32_t cmd_flg); |
| 72 | static int q6asm_memory_map_regions(struct audio_client *ac, int dir, |
| 73 | uint32_t bufsz, uint32_t bufcnt); |
| 74 | static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir, |
| 75 | uint32_t bufsz, uint32_t bufcnt); |
| 76 | |
| 77 | static void q6asm_reset_buf_state(struct audio_client *ac); |
| 78 | |
Rajesha Kini | 3498c93 | 2011-07-19 19:58:27 +0530 | [diff] [blame] | 79 | #ifdef CONFIG_DEBUG_FS |
| 80 | static struct timeval out_cold_tv; |
| 81 | static struct timeval out_warm_tv; |
| 82 | static struct timeval out_cont_tv; |
| 83 | static struct timeval in_cont_tv; |
| 84 | static long out_enable_flag; |
| 85 | static long in_enable_flag; |
| 86 | static struct dentry *out_dentry; |
| 87 | static struct dentry *in_dentry; |
| 88 | static int in_cont_index; |
| 89 | /*This var is used to keep track of first write done for cold output latency */ |
| 90 | static int out_cold_index; |
| 91 | static char *out_buffer; |
| 92 | static char *in_buffer; |
| 93 | static int audio_output_latency_dbgfs_open(struct inode *inode, |
| 94 | struct file *file) |
| 95 | { |
| 96 | file->private_data = inode->i_private; |
| 97 | return 0; |
| 98 | } |
| 99 | static ssize_t audio_output_latency_dbgfs_read(struct file *file, |
| 100 | char __user *buf, size_t count, loff_t *ppos) |
| 101 | { |
| 102 | snprintf(out_buffer, OUT_BUFFER_SIZE, "%ld,%ld,%ld,%ld,%ld,%ld,",\ |
| 103 | out_cold_tv.tv_sec, out_cold_tv.tv_usec, out_warm_tv.tv_sec,\ |
| 104 | out_warm_tv.tv_usec, out_cont_tv.tv_sec, out_cont_tv.tv_usec); |
| 105 | return simple_read_from_buffer(buf, OUT_BUFFER_SIZE, ppos, |
| 106 | out_buffer, OUT_BUFFER_SIZE); |
| 107 | } |
| 108 | static ssize_t audio_output_latency_dbgfs_write(struct file *file, |
| 109 | const char __user *buf, size_t count, loff_t *ppos) |
| 110 | { |
| 111 | char *temp; |
| 112 | |
| 113 | if (count > 2*sizeof(char)) |
| 114 | return -EINVAL; |
| 115 | else |
| 116 | temp = kmalloc(2*sizeof(char), GFP_KERNEL); |
| 117 | |
| 118 | out_cold_index = 0; |
| 119 | |
| 120 | if (temp) { |
| 121 | if (copy_from_user(temp, buf, 2*sizeof(char))) { |
| 122 | kfree(temp); |
| 123 | return -EFAULT; |
| 124 | } |
| 125 | if (!strict_strtol(temp, 10, &out_enable_flag)) { |
| 126 | kfree(temp); |
| 127 | return count; |
| 128 | } |
| 129 | kfree(temp); |
| 130 | } |
| 131 | return -EINVAL; |
| 132 | } |
| 133 | static const struct file_operations audio_output_latency_debug_fops = { |
| 134 | .open = audio_output_latency_dbgfs_open, |
| 135 | .read = audio_output_latency_dbgfs_read, |
| 136 | .write = audio_output_latency_dbgfs_write |
| 137 | }; |
| 138 | |
| 139 | static int audio_input_latency_dbgfs_open(struct inode *inode, |
| 140 | struct file *file) |
| 141 | { |
| 142 | file->private_data = inode->i_private; |
| 143 | return 0; |
| 144 | } |
| 145 | static ssize_t audio_input_latency_dbgfs_read(struct file *file, |
| 146 | char __user *buf, size_t count, loff_t *ppos) |
| 147 | { |
| 148 | snprintf(in_buffer, IN_BUFFER_SIZE, "%ld,%ld,",\ |
| 149 | in_cont_tv.tv_sec, in_cont_tv.tv_usec); |
| 150 | return simple_read_from_buffer(buf, IN_BUFFER_SIZE, ppos, |
| 151 | in_buffer, IN_BUFFER_SIZE); |
| 152 | } |
| 153 | static ssize_t audio_input_latency_dbgfs_write(struct file *file, |
| 154 | const char __user *buf, size_t count, loff_t *ppos) |
| 155 | { |
| 156 | char *temp; |
| 157 | |
| 158 | if (count > 2*sizeof(char)) |
| 159 | return -EINVAL; |
| 160 | else |
| 161 | temp = kmalloc(2*sizeof(char), GFP_KERNEL); |
| 162 | if (temp) { |
| 163 | if (copy_from_user(temp, buf, 2*sizeof(char))) { |
| 164 | kfree(temp); |
| 165 | return -EFAULT; |
| 166 | } |
| 167 | if (!strict_strtol(temp, 10, &in_enable_flag)) { |
| 168 | kfree(temp); |
| 169 | return count; |
| 170 | } |
| 171 | kfree(temp); |
| 172 | } |
| 173 | return -EINVAL; |
| 174 | } |
| 175 | static const struct file_operations audio_input_latency_debug_fops = { |
| 176 | .open = audio_input_latency_dbgfs_open, |
| 177 | .read = audio_input_latency_dbgfs_read, |
| 178 | .write = audio_input_latency_dbgfs_write |
| 179 | }; |
| 180 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 181 | struct asm_mmap { |
| 182 | atomic_t ref_cnt; |
| 183 | atomic_t cmd_state; |
| 184 | wait_queue_head_t cmd_wait; |
| 185 | void *apr; |
| 186 | }; |
| 187 | |
| 188 | static struct asm_mmap this_mmap; |
| 189 | |
| 190 | static int q6asm_session_alloc(struct audio_client *ac) |
| 191 | { |
| 192 | int n; |
| 193 | mutex_lock(&session_lock); |
| 194 | for (n = 1; n <= SESSION_MAX; n++) { |
| 195 | if (!session[n]) { |
| 196 | session[n] = ac; |
| 197 | mutex_unlock(&session_lock); |
| 198 | return n; |
| 199 | } |
| 200 | } |
| 201 | mutex_unlock(&session_lock); |
| 202 | return -ENOMEM; |
| 203 | } |
| 204 | |
| 205 | static void q6asm_session_free(struct audio_client *ac) |
| 206 | { |
| 207 | pr_debug("%s: sessionid[%d]\n", __func__, ac->session); |
| 208 | mutex_lock(&session_lock); |
| 209 | session[ac->session] = 0; |
| 210 | mutex_unlock(&session_lock); |
| 211 | ac->session = 0; |
| 212 | return; |
| 213 | } |
| 214 | |
| 215 | int q6asm_audio_client_buf_free(unsigned int dir, |
| 216 | struct audio_client *ac) |
| 217 | { |
| 218 | struct audio_port_data *port; |
| 219 | int cnt = 0; |
| 220 | int rc = 0; |
| 221 | pr_debug("%s: Session id %d\n", __func__, ac->session); |
| 222 | mutex_lock(&ac->cmd_lock); |
| 223 | if (ac->io_mode == SYNC_IO_MODE) { |
| 224 | port = &ac->port[dir]; |
| 225 | if (!port->buf) { |
| 226 | mutex_unlock(&ac->cmd_lock); |
| 227 | return 0; |
| 228 | } |
| 229 | cnt = port->max_buf_cnt - 1; |
| 230 | |
| 231 | if (cnt >= 0) { |
| 232 | rc = q6asm_memory_unmap_regions(ac, dir, |
| 233 | port->buf[0].size, |
| 234 | port->max_buf_cnt); |
| 235 | if (rc < 0) |
| 236 | pr_err("%s CMD Memory_unmap_regions failed\n", |
| 237 | __func__); |
| 238 | } |
| 239 | |
| 240 | while (cnt >= 0) { |
| 241 | if (port->buf[cnt].data) { |
| 242 | pr_debug("%s:data[%p]phys[%p][%p] cnt[%d]" |
| 243 | "mem_buffer[%p]\n", |
| 244 | __func__, (void *)port->buf[cnt].data, |
| 245 | (void *)port->buf[cnt].phys, |
| 246 | (void *)&port->buf[cnt].phys, cnt, |
| 247 | (void *)port->buf[cnt].mem_buffer); |
| 248 | if (IS_ERR((void *)port->buf[cnt].mem_buffer)) |
| 249 | pr_err("%s:mem buffer invalid, error =" |
| 250 | "%ld\n", __func__, |
| 251 | PTR_ERR((void *)port->buf[cnt].mem_buffer)); |
| 252 | else { |
| 253 | if (msm_subsystem_unmap_buffer( |
| 254 | port->buf[cnt].mem_buffer) < 0) |
| 255 | pr_err("%s: unmap buffer" |
| 256 | " failed\n", __func__); |
| 257 | } |
| 258 | free_contiguous_memory_by_paddr( |
| 259 | port->buf[cnt].phys); |
| 260 | |
| 261 | port->buf[cnt].data = NULL; |
| 262 | port->buf[cnt].phys = 0; |
| 263 | --(port->max_buf_cnt); |
| 264 | } |
| 265 | --cnt; |
| 266 | } |
| 267 | kfree(port->buf); |
| 268 | port->buf = NULL; |
| 269 | } |
| 270 | mutex_unlock(&ac->cmd_lock); |
| 271 | return 0; |
| 272 | } |
| 273 | |
| 274 | int q6asm_audio_client_buf_free_contiguous(unsigned int dir, |
| 275 | struct audio_client *ac) |
| 276 | { |
| 277 | struct audio_port_data *port; |
| 278 | int cnt = 0; |
| 279 | int rc = 0; |
| 280 | pr_debug("%s: Session id %d\n", __func__, ac->session); |
| 281 | mutex_lock(&ac->cmd_lock); |
| 282 | port = &ac->port[dir]; |
| 283 | if (!port->buf) { |
| 284 | mutex_unlock(&ac->cmd_lock); |
| 285 | return 0; |
| 286 | } |
| 287 | cnt = port->max_buf_cnt - 1; |
| 288 | |
| 289 | if (cnt >= 0) { |
Deepa Madiregama | 7d52a40 | 2011-07-13 20:28:36 +0530 | [diff] [blame] | 290 | rc = q6asm_memory_unmap(ac, port->buf[0].phys, dir); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 291 | if (rc < 0) |
| 292 | pr_err("%s CMD Memory_unmap_regions failed\n", |
| 293 | __func__); |
| 294 | } |
| 295 | |
| 296 | if (port->buf[0].data) { |
| 297 | pr_debug("%s:data[%p]phys[%p][%p] cnt[%d]\n", |
| 298 | __func__, |
| 299 | (void *)port->buf[0].data, |
| 300 | (void *)port->buf[0].phys, |
| 301 | (void *)&port->buf[0].phys, cnt); |
| 302 | dma_free_coherent(NULL, |
| 303 | port->buf[0].size * port->max_buf_cnt, |
| 304 | port->buf[0].data, |
| 305 | port->buf[0].phys); |
| 306 | } |
| 307 | while (cnt >= 0) { |
| 308 | port->buf[cnt].data = NULL; |
| 309 | port->buf[cnt].phys = 0; |
| 310 | cnt--; |
| 311 | } |
| 312 | port->max_buf_cnt = 0; |
| 313 | kfree(port->buf); |
| 314 | port->buf = NULL; |
| 315 | mutex_unlock(&ac->cmd_lock); |
| 316 | return 0; |
| 317 | } |
| 318 | |
| 319 | void q6asm_audio_client_free(struct audio_client *ac) |
| 320 | { |
| 321 | int loopcnt; |
| 322 | struct audio_port_data *port; |
| 323 | if (!ac || !ac->session) |
| 324 | return; |
| 325 | pr_debug("%s: Session id %d\n", __func__, ac->session); |
| 326 | if (ac->io_mode == SYNC_IO_MODE) { |
| 327 | for (loopcnt = 0; loopcnt <= OUT; loopcnt++) { |
| 328 | port = &ac->port[loopcnt]; |
| 329 | if (!port->buf) |
| 330 | continue; |
| 331 | pr_debug("%s:loopcnt = %d\n", __func__, loopcnt); |
| 332 | q6asm_audio_client_buf_free(loopcnt, ac); |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | apr_deregister(ac->apr); |
| 337 | q6asm_session_free(ac); |
| 338 | |
| 339 | pr_debug("%s: APR De-Register\n", __func__); |
| 340 | if (atomic_read(&this_mmap.ref_cnt) <= 0) { |
| 341 | pr_err("%s: APR Common Port Already Closed\n", __func__); |
| 342 | goto done; |
| 343 | } |
| 344 | |
| 345 | atomic_dec(&this_mmap.ref_cnt); |
| 346 | if (atomic_read(&this_mmap.ref_cnt) == 0) { |
| 347 | apr_deregister(this_mmap.apr); |
| 348 | pr_debug("%s:APR De-Register common port\n", __func__); |
| 349 | } |
| 350 | done: |
| 351 | kfree(ac); |
| 352 | return; |
| 353 | } |
| 354 | |
| 355 | int q6asm_set_io_mode(struct audio_client *ac, uint32_t mode) |
| 356 | { |
| 357 | if (ac == NULL) { |
| 358 | pr_err("%s APR handle NULL\n", __func__); |
| 359 | return -EINVAL; |
| 360 | } |
| 361 | if ((mode == ASYNC_IO_MODE) || (mode == SYNC_IO_MODE)) { |
| 362 | ac->io_mode = mode; |
| 363 | pr_debug("%s:Set Mode to %d\n", __func__, ac->io_mode); |
| 364 | return 0; |
| 365 | } else { |
| 366 | pr_err("%s:Not an valid IO Mode:%d\n", __func__, ac->io_mode); |
| 367 | return -EINVAL; |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | struct audio_client *q6asm_audio_client_alloc(app_cb cb, void *priv) |
| 372 | { |
| 373 | struct audio_client *ac; |
| 374 | int n; |
| 375 | int lcnt = 0; |
| 376 | |
| 377 | ac = kzalloc(sizeof(struct audio_client), GFP_KERNEL); |
| 378 | if (!ac) |
| 379 | return NULL; |
| 380 | n = q6asm_session_alloc(ac); |
| 381 | if (n <= 0) |
| 382 | goto fail_session; |
| 383 | ac->session = n; |
| 384 | ac->cb = cb; |
| 385 | ac->priv = priv; |
| 386 | ac->io_mode = SYNC_IO_MODE; |
| 387 | ac->apr = apr_register("ADSP", "ASM", \ |
| 388 | (apr_fn)q6asm_callback,\ |
| 389 | ((ac->session) << 8 | 0x0001),\ |
| 390 | ac); |
| 391 | |
| 392 | if (ac->apr == NULL) { |
| 393 | pr_err("%s Registration with APR failed\n", __func__); |
| 394 | goto fail; |
| 395 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 396 | rtac_set_asm_handle(n, ac->apr); |
Ben Romberger | fce8f51 | 2011-07-18 16:46:09 -0700 | [diff] [blame] | 397 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 398 | pr_debug("%s Registering the common port with APR\n", __func__); |
| 399 | if (atomic_read(&this_mmap.ref_cnt) == 0) { |
| 400 | this_mmap.apr = apr_register("ADSP", "ASM", \ |
| 401 | (apr_fn)q6asm_mmapcallback,\ |
| 402 | 0x0FFFFFFFF, &this_mmap); |
| 403 | if (this_mmap.apr == NULL) { |
| 404 | pr_debug("%s Unable to register \ |
| 405 | APR ASM common port \n", __func__); |
| 406 | goto fail; |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | atomic_inc(&this_mmap.ref_cnt); |
| 411 | init_waitqueue_head(&ac->cmd_wait); |
| 412 | init_waitqueue_head(&ac->time_wait); |
| 413 | atomic_set(&ac->time_flag, 1); |
| 414 | mutex_init(&ac->cmd_lock); |
| 415 | for (lcnt = 0; lcnt <= OUT; lcnt++) { |
| 416 | mutex_init(&ac->port[lcnt].lock); |
| 417 | spin_lock_init(&ac->port[lcnt].dsp_lock); |
| 418 | } |
| 419 | atomic_set(&ac->cmd_state, 0); |
| 420 | |
| 421 | pr_debug("%s: session[%d]\n", __func__, ac->session); |
| 422 | |
| 423 | return ac; |
| 424 | fail: |
| 425 | q6asm_audio_client_free(ac); |
| 426 | return NULL; |
| 427 | fail_session: |
| 428 | kfree(ac); |
| 429 | return NULL; |
| 430 | } |
| 431 | |
| 432 | int q6asm_audio_client_buf_alloc(unsigned int dir, |
| 433 | struct audio_client *ac, |
| 434 | unsigned int bufsz, |
| 435 | unsigned int bufcnt) |
| 436 | { |
| 437 | int cnt = 0; |
| 438 | int rc = 0; |
| 439 | struct audio_buffer *buf; |
| 440 | |
| 441 | if (!(ac) || ((dir != IN) && (dir != OUT))) |
| 442 | return -EINVAL; |
| 443 | |
| 444 | pr_debug("%s: session[%d]bufsz[%d]bufcnt[%d]\n", __func__, ac->session, |
| 445 | bufsz, bufcnt); |
| 446 | |
| 447 | if (ac->session <= 0 || ac->session > 8) |
| 448 | goto fail; |
| 449 | |
| 450 | if (ac->io_mode == SYNC_IO_MODE) { |
| 451 | if (ac->port[dir].buf) { |
| 452 | pr_debug("%s: buffer already allocated\n", __func__); |
| 453 | return 0; |
| 454 | } |
| 455 | mutex_lock(&ac->cmd_lock); |
| 456 | buf = kzalloc(((sizeof(struct audio_buffer))*bufcnt), |
| 457 | GFP_KERNEL); |
| 458 | |
| 459 | if (!buf) { |
| 460 | mutex_unlock(&ac->cmd_lock); |
| 461 | goto fail; |
| 462 | } |
| 463 | |
| 464 | ac->port[dir].buf = buf; |
| 465 | |
| 466 | while (cnt < bufcnt) { |
| 467 | if (bufsz > 0) { |
| 468 | if (!buf[cnt].data) { |
| 469 | unsigned int flags = 0; |
| 470 | buf[cnt].phys = |
| 471 | allocate_contiguous_ebi_nomap(bufsz, |
| 472 | SZ_4K); |
| 473 | if (!buf[cnt].phys) { |
| 474 | pr_err("%s:Buf alloc failed " |
| 475 | " size=%d\n", __func__, |
| 476 | bufsz); |
| 477 | mutex_unlock(&ac->cmd_lock); |
| 478 | goto fail; |
| 479 | } |
| 480 | flags = MSM_SUBSYSTEM_MAP_KADDR | |
| 481 | MSM_SUBSYSTEM_MAP_CACHED; |
| 482 | buf[cnt].mem_buffer = |
| 483 | msm_subsystem_map_buffer(buf[cnt].phys, |
| 484 | bufsz, flags, NULL, 0); |
| 485 | if (IS_ERR( |
| 486 | (void *)buf[cnt].mem_buffer)) { |
| 487 | pr_err("%s:map_buffer failed," |
| 488 | "error = %ld\n", |
| 489 | __func__, PTR_ERR((void *)buf[cnt].mem_buffer)); |
| 490 | goto fail; |
| 491 | } |
| 492 | buf[cnt].data = |
| 493 | buf[cnt].mem_buffer->vaddr; |
| 494 | if (!buf[cnt].data) { |
| 495 | pr_err("%s:invalid vaddr," |
| 496 | " iomap failed\n", __func__); |
| 497 | goto fail; |
| 498 | } |
| 499 | buf[cnt].used = 1; |
| 500 | buf[cnt].size = bufsz; |
| 501 | buf[cnt].actual_size = bufsz; |
| 502 | pr_debug("%s data[%p]phys[%p][%p]" |
| 503 | "mem_buffer[%p]\n", |
| 504 | __func__, |
| 505 | (void *)buf[cnt].data, |
| 506 | (void *)buf[cnt].phys, |
| 507 | (void *)&buf[cnt].phys, |
| 508 | (void *)buf[cnt].mem_buffer); |
| 509 | cnt++; |
| 510 | } |
| 511 | } |
| 512 | } |
| 513 | ac->port[dir].max_buf_cnt = cnt; |
| 514 | |
| 515 | mutex_unlock(&ac->cmd_lock); |
| 516 | rc = q6asm_memory_map_regions(ac, dir, bufsz, cnt); |
| 517 | if (rc < 0) { |
| 518 | pr_err("%s:CMD Memory_map_regions failed\n", __func__); |
| 519 | goto fail; |
| 520 | } |
| 521 | } |
| 522 | return 0; |
| 523 | fail: |
| 524 | q6asm_audio_client_buf_free(dir, ac); |
| 525 | return -EINVAL; |
| 526 | } |
| 527 | |
| 528 | int q6asm_audio_client_buf_alloc_contiguous(unsigned int dir, |
| 529 | struct audio_client *ac, |
| 530 | unsigned int bufsz, |
| 531 | unsigned int bufcnt) |
| 532 | { |
| 533 | int cnt = 0; |
| 534 | int rc = 0; |
| 535 | struct audio_buffer *buf; |
| 536 | |
| 537 | if (!(ac) || ((dir != IN) && (dir != OUT))) |
| 538 | return -EINVAL; |
| 539 | |
| 540 | pr_debug("%s: session[%d]bufsz[%d]bufcnt[%d]\n", |
| 541 | __func__, ac->session, |
| 542 | bufsz, bufcnt); |
| 543 | |
| 544 | if (ac->session <= 0 || ac->session > 8) |
| 545 | goto fail; |
| 546 | |
| 547 | if (ac->port[dir].buf) { |
| 548 | pr_debug("%s: buffer already allocated\n", __func__); |
| 549 | return 0; |
| 550 | } |
| 551 | mutex_lock(&ac->cmd_lock); |
| 552 | buf = kzalloc(((sizeof(struct audio_buffer))*bufcnt), |
| 553 | GFP_KERNEL); |
| 554 | |
| 555 | if (!buf) { |
| 556 | mutex_unlock(&ac->cmd_lock); |
| 557 | goto fail; |
| 558 | } |
| 559 | |
| 560 | ac->port[dir].buf = buf; |
| 561 | |
| 562 | buf[0].data = dma_alloc_coherent(NULL, bufsz * bufcnt, |
| 563 | &buf[0].phys, GFP_KERNEL); |
| 564 | buf[0].used = dir ^ 1; |
| 565 | buf[0].size = bufsz; |
| 566 | buf[0].actual_size = bufsz; |
| 567 | cnt = 1; |
| 568 | while (cnt < bufcnt) { |
| 569 | if (bufsz > 0) { |
| 570 | buf[cnt].data = buf[0].data + (cnt * bufsz); |
| 571 | buf[cnt].phys = buf[0].phys + (cnt * bufsz); |
| 572 | if (!buf[cnt].data) { |
| 573 | pr_err("%s Buf alloc failed\n", |
| 574 | __func__); |
| 575 | mutex_unlock(&ac->cmd_lock); |
| 576 | goto fail; |
| 577 | } |
| 578 | buf[cnt].used = dir ^ 1; |
| 579 | buf[cnt].size = bufsz; |
| 580 | buf[cnt].actual_size = bufsz; |
| 581 | pr_debug("%s data[%p]phys[%p][%p]\n", __func__, |
| 582 | (void *)buf[cnt].data, |
| 583 | (void *)buf[cnt].phys, |
| 584 | (void *)&buf[cnt].phys); |
| 585 | } |
| 586 | cnt++; |
| 587 | } |
| 588 | ac->port[dir].max_buf_cnt = cnt; |
| 589 | mutex_unlock(&ac->cmd_lock); |
| 590 | rc = q6asm_memory_map(ac, buf[0].phys, dir, bufsz, cnt); |
| 591 | if (rc < 0) { |
| 592 | pr_err("%s:CMD Memory_map_regions failed\n", __func__); |
| 593 | goto fail; |
| 594 | } |
| 595 | return 0; |
| 596 | fail: |
| 597 | q6asm_audio_client_buf_free_contiguous(dir, ac); |
| 598 | return -EINVAL; |
| 599 | } |
| 600 | |
| 601 | static int32_t q6asm_mmapcallback(struct apr_client_data *data, void *priv) |
| 602 | { |
| 603 | uint32_t token; |
| 604 | uint32_t *payload = data->payload; |
| 605 | |
| 606 | if (data->opcode == RESET_EVENTS) { |
| 607 | pr_debug("%s: Reset event is received: %d %d apr[%p]\n", |
| 608 | __func__, |
| 609 | data->reset_event, |
| 610 | data->reset_proc, |
| 611 | this_mmap.apr); |
| 612 | apr_reset(this_mmap.apr); |
| 613 | this_mmap.apr = NULL; |
| 614 | atomic_set(&this_mmap.cmd_state, 0); |
| 615 | return 0; |
| 616 | } |
| 617 | |
| 618 | pr_debug("%s:ptr0[0x%x]ptr1[0x%x]opcode[0x%x]" |
| 619 | "token[0x%x]payload_s[%d] src[%d] dest[%d]\n", __func__, |
| 620 | payload[0], payload[1], data->opcode, data->token, |
| 621 | data->payload_size, data->src_port, data->dest_port); |
| 622 | |
| 623 | if (data->opcode == APR_BASIC_RSP_RESULT) { |
| 624 | token = data->token; |
| 625 | switch (payload[0]) { |
| 626 | case ASM_SESSION_CMD_MEMORY_MAP: |
| 627 | case ASM_SESSION_CMD_MEMORY_UNMAP: |
| 628 | case ASM_SESSION_CMD_MEMORY_MAP_REGIONS: |
| 629 | case ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS: |
| 630 | pr_debug("%s:command[0x%x]success [0x%x]\n", |
| 631 | __func__, payload[0], payload[1]); |
| 632 | if (atomic_read(&this_mmap.cmd_state)) { |
| 633 | atomic_set(&this_mmap.cmd_state, 0); |
| 634 | wake_up(&this_mmap.cmd_wait); |
| 635 | } |
| 636 | break; |
| 637 | default: |
| 638 | pr_debug("%s:command[0x%x] not expecting rsp\n", |
| 639 | __func__, payload[0]); |
| 640 | break; |
| 641 | } |
| 642 | } |
| 643 | return 0; |
| 644 | } |
| 645 | |
| 646 | |
| 647 | static int32_t q6asm_callback(struct apr_client_data *data, void *priv) |
| 648 | { |
| 649 | int i = 0; |
| 650 | struct audio_client *ac = (struct audio_client *)priv; |
| 651 | uint32_t token; |
| 652 | unsigned long dsp_flags; |
| 653 | uint32_t *payload; |
| 654 | |
| 655 | |
| 656 | if ((ac == NULL) || (data == NULL)) { |
| 657 | pr_err("ac or priv NULL\n"); |
| 658 | return -EINVAL; |
| 659 | } |
| 660 | if (ac->session <= 0 || ac->session > 8) { |
| 661 | pr_err("%s:Session ID is invalid, session = %d\n", __func__, |
| 662 | ac->session); |
| 663 | return -EINVAL; |
| 664 | } |
| 665 | |
| 666 | payload = data->payload; |
| 667 | |
| 668 | if (data->opcode == RESET_EVENTS) { |
| 669 | pr_debug("q6asm_callback: Reset event is received: %d %d apr[%p]\n", |
| 670 | data->reset_event, data->reset_proc, ac->apr); |
| 671 | apr_reset(ac->apr); |
| 672 | return 0; |
| 673 | } |
| 674 | |
| 675 | pr_debug("%s: session[%d]opcode[0x%x] \ |
| 676 | token[0x%x]payload_s[%d] src[%d] dest[%d]\n", __func__, |
| 677 | ac->session, data->opcode, |
| 678 | data->token, data->payload_size, data->src_port, |
| 679 | data->dest_port); |
| 680 | |
| 681 | if (data->opcode == APR_BASIC_RSP_RESULT) { |
| 682 | token = data->token; |
| 683 | switch (payload[0]) { |
| 684 | case ASM_STREAM_CMD_SET_PP_PARAMS: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 685 | if (rtac_make_asm_callback(ac->session, payload, |
| 686 | data->payload_size)) |
| 687 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 688 | case ASM_SESSION_CMD_PAUSE: |
| 689 | case ASM_DATA_CMD_EOS: |
| 690 | case ASM_STREAM_CMD_CLOSE: |
| 691 | case ASM_STREAM_CMD_FLUSH: |
| 692 | case ASM_SESSION_CMD_RUN: |
| 693 | case ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS: |
| 694 | case ASM_STREAM_CMD_FLUSH_READBUFS: |
| 695 | pr_debug("%s:Payload = [0x%x]\n", __func__, payload[0]); |
| 696 | if (token != ac->session) { |
| 697 | pr_err("%s:Invalid session[%d] rxed expected[%d]", |
| 698 | __func__, token, ac->session); |
| 699 | return -EINVAL; |
| 700 | } |
| 701 | case ASM_STREAM_CMD_OPEN_READ: |
| 702 | case ASM_STREAM_CMD_OPEN_WRITE: |
| 703 | case ASM_STREAM_CMD_OPEN_READWRITE: |
| 704 | case ASM_DATA_CMD_MEDIA_FORMAT_UPDATE: |
| 705 | case ASM_STREAM_CMD_SET_ENCDEC_PARAM: |
| 706 | if (atomic_read(&ac->cmd_state)) { |
| 707 | atomic_set(&ac->cmd_state, 0); |
| 708 | wake_up(&ac->cmd_wait); |
| 709 | } |
| 710 | if (ac->cb) |
| 711 | ac->cb(data->opcode, data->token, |
| 712 | (uint32_t *)data->payload, ac->priv); |
| 713 | break; |
| 714 | default: |
| 715 | pr_debug("%s:command[0x%x] not expecting rsp\n", |
| 716 | __func__, payload[0]); |
| 717 | break; |
| 718 | } |
| 719 | return 0; |
| 720 | } |
| 721 | |
| 722 | switch (data->opcode) { |
| 723 | case ASM_DATA_EVENT_WRITE_DONE:{ |
| 724 | struct audio_port_data *port = &ac->port[IN]; |
| 725 | pr_debug("%s: Rxed opcode[0x%x] status[0x%x] token[%d]", |
| 726 | __func__, payload[0], payload[1], |
| 727 | data->token); |
| 728 | if (ac->io_mode == SYNC_IO_MODE) { |
| 729 | if (port->buf == NULL) { |
| 730 | pr_err("%s: Unexpected Write Done\n", |
| 731 | __func__); |
| 732 | return -EINVAL; |
| 733 | } |
| 734 | spin_lock_irqsave(&port->dsp_lock, dsp_flags); |
| 735 | if (port->buf[data->token].phys != |
| 736 | payload[0]) { |
| 737 | pr_err("Buf expected[%p]rxed[%p]\n",\ |
| 738 | (void *)port->buf[data->token].phys,\ |
| 739 | (void *)payload[0]); |
| 740 | spin_unlock_irqrestore(&port->dsp_lock, |
| 741 | dsp_flags); |
| 742 | return -EINVAL; |
| 743 | } |
| 744 | token = data->token; |
| 745 | port->buf[token].used = 1; |
| 746 | spin_unlock_irqrestore(&port->dsp_lock, dsp_flags); |
Rajesha Kini | 3498c93 | 2011-07-19 19:58:27 +0530 | [diff] [blame] | 747 | #ifdef CONFIG_DEBUG_FS |
| 748 | if (out_enable_flag) { |
| 749 | /* For first Write done log the time and reset |
| 750 | out_cold_index*/ |
| 751 | if (out_cold_index != 1) { |
| 752 | do_gettimeofday(&out_cold_tv); |
| 753 | pr_debug("COLD: apr_send_pkt at %ld \ |
| 754 | sec %ld microsec\n",\ |
| 755 | out_cold_tv.tv_sec,\ |
| 756 | out_cold_tv.tv_usec); |
| 757 | out_cold_index = 1; |
| 758 | } |
| 759 | pr_debug("out_enable_flag %ld",\ |
| 760 | out_enable_flag); |
| 761 | } |
| 762 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 763 | for (i = 0; i < port->max_buf_cnt; i++) |
| 764 | pr_debug("%d ", port->buf[i].used); |
| 765 | |
| 766 | } |
| 767 | break; |
| 768 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 769 | case ASM_STREAM_CMDRSP_GET_PP_PARAMS: |
| 770 | rtac_make_asm_callback(ac->session, payload, |
| 771 | data->payload_size); |
| 772 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 773 | case ASM_DATA_EVENT_READ_DONE:{ |
| 774 | |
| 775 | struct audio_port_data *port = &ac->port[OUT]; |
Rajesha Kini | 3498c93 | 2011-07-19 19:58:27 +0530 | [diff] [blame] | 776 | #ifdef CONFIG_DEBUG_FS |
| 777 | if (in_enable_flag) { |
| 778 | /* when in_cont_index == 7, DSP would be |
| 779 | * writing into the 8th 512 byte buffer and this |
| 780 | * timestamp is tapped here.Once done it then writes |
| 781 | * to 9th 512 byte buffer.These two buffers(8th, 9th) |
| 782 | * reach the test application in 5th iteration and that |
| 783 | * timestamp is tapped at user level. The difference |
| 784 | * of these two timestamps gives us the time between |
| 785 | * the time at which dsp started filling the sample |
| 786 | * required and when it reached the test application. |
| 787 | * Hence continuous input latency |
| 788 | */ |
| 789 | if (in_cont_index == 7) { |
| 790 | do_gettimeofday(&in_cont_tv); |
| 791 | pr_err("In_CONT:previous read buffer done \ |
| 792 | at %ld sec %ld microsec\n",\ |
Sriranjan Srikantam | 7475353 | 2011-10-03 14:48:37 -0700 | [diff] [blame] | 793 | in_cont_tv.tv_sec, in_cont_tv.tv_usec); |
Rajesha Kini | 3498c93 | 2011-07-19 19:58:27 +0530 | [diff] [blame] | 794 | } |
| 795 | } |
| 796 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 797 | pr_debug("%s:R-D: status=%d buff_add=%x act_size=%d offset=%d\n", |
| 798 | __func__, payload[READDONE_IDX_STATUS], |
| 799 | payload[READDONE_IDX_BUFFER], |
| 800 | payload[READDONE_IDX_SIZE], |
| 801 | payload[READDONE_IDX_OFFSET]); |
| 802 | pr_debug("%s:R-D:msw_ts=%d lsw_ts=%d flags=%d id=%d num=%d\n", |
| 803 | __func__, payload[READDONE_IDX_MSW_TS], |
| 804 | payload[READDONE_IDX_LSW_TS], |
| 805 | payload[READDONE_IDX_FLAGS], |
| 806 | payload[READDONE_IDX_ID], |
| 807 | payload[READDONE_IDX_NUMFRAMES]); |
Rajesha Kini | 3498c93 | 2011-07-19 19:58:27 +0530 | [diff] [blame] | 808 | #ifdef CONFIG_DEBUG_FS |
| 809 | if (in_enable_flag) { |
| 810 | in_cont_index++; |
| 811 | } |
| 812 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 813 | if (ac->io_mode == SYNC_IO_MODE) { |
| 814 | if (port->buf == NULL) { |
| 815 | pr_err("%s: Unexpected Write Done\n", __func__); |
| 816 | return -EINVAL; |
| 817 | } |
| 818 | spin_lock_irqsave(&port->dsp_lock, dsp_flags); |
| 819 | token = data->token; |
| 820 | port->buf[token].used = 0; |
| 821 | if (port->buf[token].phys != |
| 822 | payload[READDONE_IDX_BUFFER]) { |
| 823 | pr_err("Buf expected[%p]rxed[%p]\n",\ |
| 824 | (void *)port->buf[token].phys,\ |
| 825 | (void *)payload[READDONE_IDX_BUFFER]); |
| 826 | spin_unlock_irqrestore(&port->dsp_lock, |
| 827 | dsp_flags); |
| 828 | break; |
| 829 | } |
| 830 | port->buf[token].actual_size = |
| 831 | payload[READDONE_IDX_SIZE]; |
| 832 | spin_unlock_irqrestore(&port->dsp_lock, dsp_flags); |
| 833 | } |
| 834 | break; |
| 835 | } |
| 836 | case ASM_DATA_EVENT_EOS: |
| 837 | case ASM_DATA_CMDRSP_EOS: |
| 838 | pr_debug("%s:EOS ACK received: rxed opcode[0x%x]\n", |
| 839 | __func__, data->opcode); |
| 840 | break; |
| 841 | case ASM_STREAM_CMDRSP_GET_ENCDEC_PARAM: |
| 842 | break; |
| 843 | case ASM_SESSION_EVENT_TX_OVERFLOW: |
| 844 | pr_err("ASM_SESSION_EVENT_TX_OVERFLOW\n"); |
| 845 | break; |
| 846 | case ASM_SESSION_CMDRSP_GET_SESSION_TIME: |
| 847 | pr_debug("%s: ASM_SESSION_CMDRSP_GET_SESSION_TIME, " |
| 848 | "payload[0] = %d, payload[1] = %d, " |
| 849 | "payload[2] = %d\n", __func__, |
| 850 | payload[0], payload[1], payload[2]); |
| 851 | ac->time_stamp = (uint64_t)(((uint64_t)payload[1] << 32) | |
| 852 | payload[2]); |
| 853 | if (atomic_read(&ac->time_flag)) { |
| 854 | atomic_set(&ac->time_flag, 0); |
| 855 | wake_up(&ac->time_wait); |
| 856 | } |
| 857 | break; |
| 858 | case ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY: |
Deepa Madiregama | 55cbf78 | 2011-09-10 05:44:39 +0530 | [diff] [blame] | 859 | case ASM_DATA_EVENT_ENC_SR_CM_NOTIFY: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 860 | pr_debug("%s: ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY, " |
| 861 | "payload[0] = %d, payload[1] = %d, " |
| 862 | "payload[2] = %d, payload[3] = %d\n", __func__, |
| 863 | payload[0], payload[1], payload[2], |
| 864 | payload[3]); |
| 865 | break; |
| 866 | } |
| 867 | if (ac->cb) |
| 868 | ac->cb(data->opcode, data->token, |
| 869 | data->payload, ac->priv); |
| 870 | |
| 871 | return 0; |
| 872 | } |
| 873 | |
| 874 | void *q6asm_is_cpu_buf_avail(int dir, struct audio_client *ac, uint32_t *size, |
| 875 | uint32_t *index) |
| 876 | { |
| 877 | void *data; |
| 878 | unsigned char idx; |
| 879 | struct audio_port_data *port; |
| 880 | |
| 881 | if (!ac || ((dir != IN) && (dir != OUT))) |
| 882 | return NULL; |
| 883 | |
| 884 | if (ac->io_mode == SYNC_IO_MODE) { |
| 885 | port = &ac->port[dir]; |
| 886 | |
| 887 | mutex_lock(&port->lock); |
| 888 | idx = port->cpu_buf; |
| 889 | if (port->buf == NULL) { |
| 890 | pr_debug("%s:Buffer pointer null\n", __func__); |
| 891 | return NULL; |
| 892 | } |
| 893 | /* dir 0: used = 0 means buf in use |
| 894 | dir 1: used = 1 means buf in use */ |
| 895 | if (port->buf[idx].used == dir) { |
| 896 | /* To make it more robust, we could loop and get the |
| 897 | next avail buf, its risky though */ |
| 898 | pr_debug("%s:Next buf idx[0x%x] not available,\ |
| 899 | dir[%d]\n", __func__, idx, dir); |
| 900 | mutex_unlock(&port->lock); |
| 901 | return NULL; |
| 902 | } |
| 903 | *size = port->buf[idx].actual_size; |
| 904 | *index = port->cpu_buf; |
| 905 | data = port->buf[idx].data; |
| 906 | pr_debug("%s:session[%d]index[%d] data[%p]size[%d]\n", |
| 907 | __func__, |
| 908 | ac->session, |
| 909 | port->cpu_buf, |
| 910 | data, *size); |
| 911 | /* By default increase the cpu_buf cnt |
| 912 | user accesses this function,increase cpu |
| 913 | buf(to avoid another api)*/ |
| 914 | port->buf[idx].used = dir; |
| 915 | port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1)); |
| 916 | mutex_unlock(&port->lock); |
| 917 | return data; |
| 918 | } |
| 919 | return NULL; |
| 920 | } |
| 921 | |
Jay Wang | 9cf59a0 | 2011-08-10 16:58:40 -0700 | [diff] [blame] | 922 | void *q6asm_is_cpu_buf_avail_nolock(int dir, struct audio_client *ac, |
| 923 | uint32_t *size, uint32_t *index) |
| 924 | { |
| 925 | void *data; |
| 926 | unsigned char idx; |
| 927 | struct audio_port_data *port; |
| 928 | |
| 929 | if (!ac || ((dir != IN) && (dir != OUT))) |
| 930 | return NULL; |
| 931 | |
| 932 | port = &ac->port[dir]; |
| 933 | |
| 934 | idx = port->cpu_buf; |
| 935 | if (port->buf == NULL) { |
| 936 | pr_debug("%s:Buffer pointer null\n", __func__); |
| 937 | return NULL; |
| 938 | } |
| 939 | /* |
| 940 | * dir 0: used = 0 means buf in use |
| 941 | * dir 1: used = 1 means buf in use |
| 942 | */ |
| 943 | if (port->buf[idx].used == dir) { |
| 944 | /* |
| 945 | * To make it more robust, we could loop and get the |
| 946 | * next avail buf, its risky though |
| 947 | */ |
| 948 | pr_debug("%s:Next buf idx[0x%x] not available,\ |
| 949 | dir[%d]\n", __func__, idx, dir); |
| 950 | return NULL; |
| 951 | } |
| 952 | *size = port->buf[idx].actual_size; |
| 953 | *index = port->cpu_buf; |
| 954 | data = port->buf[idx].data; |
| 955 | pr_debug("%s:session[%d]index[%d] data[%p]size[%d]\n", |
| 956 | __func__, ac->session, port->cpu_buf, |
| 957 | data, *size); |
| 958 | /* |
| 959 | * By default increase the cpu_buf cnt |
| 960 | * user accesses this function,increase cpu |
| 961 | * buf(to avoid another api) |
| 962 | */ |
| 963 | port->buf[idx].used = dir; |
| 964 | port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1)); |
| 965 | return data; |
| 966 | } |
| 967 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 968 | int q6asm_is_dsp_buf_avail(int dir, struct audio_client *ac) |
| 969 | { |
| 970 | int ret = -1; |
| 971 | struct audio_port_data *port; |
| 972 | uint32_t idx; |
| 973 | |
| 974 | if (!ac || (dir != OUT)) |
| 975 | return ret; |
| 976 | |
| 977 | if (ac->io_mode == SYNC_IO_MODE) { |
| 978 | port = &ac->port[dir]; |
| 979 | |
| 980 | mutex_lock(&port->lock); |
| 981 | idx = port->dsp_buf; |
| 982 | |
| 983 | if (port->buf[idx].used == (dir ^ 1)) { |
| 984 | /* To make it more robust, we could loop and get the |
| 985 | next avail buf, its risky though */ |
| 986 | pr_err("Next buf idx[0x%x] not available, dir[%d]\n", |
| 987 | idx, dir); |
| 988 | mutex_unlock(&port->lock); |
| 989 | return ret; |
| 990 | } |
| 991 | pr_debug("%s: session[%d]dsp_buf=%d cpu_buf=%d\n", __func__, |
| 992 | ac->session, port->dsp_buf, port->cpu_buf); |
| 993 | ret = ((port->dsp_buf != port->cpu_buf) ? 0 : -1); |
| 994 | mutex_unlock(&port->lock); |
| 995 | } |
| 996 | return ret; |
| 997 | } |
| 998 | |
| 999 | static void q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr, |
| 1000 | uint32_t pkt_size, uint32_t cmd_flg) |
| 1001 | { |
| 1002 | pr_debug("%s:session=%d pkt size=%d cmd_flg=%d\n", __func__, pkt_size, |
| 1003 | cmd_flg, ac->session); |
| 1004 | mutex_lock(&ac->cmd_lock); |
| 1005 | hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \ |
| 1006 | APR_HDR_LEN(sizeof(struct apr_hdr)),\ |
| 1007 | APR_PKT_VER); |
| 1008 | hdr->src_svc = ((struct apr_svc *)ac->apr)->id; |
| 1009 | hdr->src_domain = APR_DOMAIN_APPS; |
| 1010 | hdr->dest_svc = APR_SVC_ASM; |
| 1011 | hdr->dest_domain = APR_DOMAIN_ADSP; |
| 1012 | hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01; |
| 1013 | hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01; |
| 1014 | if (cmd_flg) { |
| 1015 | hdr->token = ac->session; |
| 1016 | atomic_set(&ac->cmd_state, 1); |
| 1017 | } |
| 1018 | hdr->pkt_size = pkt_size; |
| 1019 | mutex_unlock(&ac->cmd_lock); |
| 1020 | return; |
| 1021 | } |
| 1022 | |
| 1023 | static void q6asm_add_mmaphdr(struct apr_hdr *hdr, uint32_t pkt_size, |
| 1024 | uint32_t cmd_flg) |
| 1025 | { |
| 1026 | pr_debug("%s:pkt size=%d cmd_flg=%d\n", __func__, pkt_size, cmd_flg); |
| 1027 | hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \ |
| 1028 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 1029 | hdr->src_port = 0; |
| 1030 | hdr->dest_port = 0; |
| 1031 | if (cmd_flg) { |
| 1032 | hdr->token = 0; |
| 1033 | atomic_set(&this_mmap.cmd_state, 1); |
| 1034 | } |
| 1035 | hdr->pkt_size = pkt_size; |
| 1036 | return; |
| 1037 | } |
| 1038 | |
| 1039 | int q6asm_open_read(struct audio_client *ac, |
| 1040 | uint32_t format) |
| 1041 | { |
| 1042 | int rc = 0x00; |
| 1043 | struct asm_stream_cmd_open_read open; |
Rajesha Kini | 3498c93 | 2011-07-19 19:58:27 +0530 | [diff] [blame] | 1044 | #ifdef CONFIG_DEBUG_FS |
| 1045 | in_cont_index = 0; |
| 1046 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1047 | if ((ac == NULL) || (ac->apr == NULL)) { |
| 1048 | pr_err("%s: APR handle NULL\n", __func__); |
| 1049 | return -EINVAL; |
| 1050 | } |
| 1051 | pr_debug("%s:session[%d]", __func__, ac->session); |
| 1052 | |
| 1053 | q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE); |
| 1054 | open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ; |
| 1055 | /* Stream prio : High, provide meta info with encoded frames */ |
| 1056 | open.src_endpoint = ASM_END_POINT_DEVICE_MATRIX; |
| 1057 | |
| 1058 | open.pre_proc_top = get_asm_topology(); |
| 1059 | if (open.pre_proc_top == 0) |
| 1060 | open.pre_proc_top = DEFAULT_POPP_TOPOLOGY; |
| 1061 | |
| 1062 | switch (format) { |
| 1063 | case FORMAT_LINEAR_PCM: |
| 1064 | open.uMode = STREAM_PRIORITY_HIGH; |
| 1065 | open.format = LINEAR_PCM; |
| 1066 | break; |
| 1067 | case FORMAT_MPEG4_AAC: |
| 1068 | open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH; |
| 1069 | open.format = MPEG4_AAC; |
| 1070 | break; |
| 1071 | case FORMAT_V13K: |
| 1072 | open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH; |
| 1073 | open.format = V13K_FS; |
| 1074 | break; |
| 1075 | case FORMAT_EVRC: |
| 1076 | open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH; |
| 1077 | open.format = EVRC_FS; |
| 1078 | break; |
| 1079 | case FORMAT_AMRNB: |
| 1080 | open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH; |
| 1081 | open.format = AMRNB_FS; |
| 1082 | break; |
| 1083 | default: |
| 1084 | pr_err("Invalid format[%d]\n", format); |
| 1085 | goto fail_cmd; |
| 1086 | } |
| 1087 | rc = apr_send_pkt(ac->apr, (uint32_t *) &open); |
| 1088 | if (rc < 0) { |
| 1089 | pr_err("open failed op[0x%x]rc[%d]\n", \ |
| 1090 | open.hdr.opcode, rc); |
| 1091 | goto fail_cmd; |
| 1092 | } |
| 1093 | rc = wait_event_timeout(ac->cmd_wait, |
| 1094 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 1095 | if (!rc) { |
| 1096 | pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__, |
| 1097 | rc); |
| 1098 | goto fail_cmd; |
| 1099 | } |
| 1100 | return 0; |
| 1101 | fail_cmd: |
| 1102 | return -EINVAL; |
| 1103 | } |
| 1104 | |
| 1105 | int q6asm_open_write(struct audio_client *ac, uint32_t format) |
| 1106 | { |
| 1107 | int rc = 0x00; |
| 1108 | struct asm_stream_cmd_open_write open; |
| 1109 | |
| 1110 | if ((ac == NULL) || (ac->apr == NULL)) { |
| 1111 | pr_err("%s: APR handle NULL\n", __func__); |
| 1112 | return -EINVAL; |
| 1113 | } |
| 1114 | pr_debug("%s: session[%d] wr_format[0x%x]", __func__, ac->session, |
| 1115 | format); |
| 1116 | |
| 1117 | q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE); |
| 1118 | |
| 1119 | open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE; |
| 1120 | open.uMode = STREAM_PRIORITY_HIGH; |
| 1121 | /* source endpoint : matrix */ |
| 1122 | open.sink_endpoint = ASM_END_POINT_DEVICE_MATRIX; |
| 1123 | open.stream_handle = 0x00; |
| 1124 | |
| 1125 | open.post_proc_top = get_asm_topology(); |
| 1126 | if (open.post_proc_top == 0) |
| 1127 | open.post_proc_top = DEFAULT_POPP_TOPOLOGY; |
| 1128 | |
| 1129 | switch (format) { |
| 1130 | case FORMAT_LINEAR_PCM: |
| 1131 | open.format = LINEAR_PCM; |
| 1132 | break; |
| 1133 | case FORMAT_MPEG4_AAC: |
| 1134 | open.format = MPEG4_AAC; |
| 1135 | break; |
Bharath Ramachandramurthy | 4f71d50 | 2011-10-23 19:45:22 -0700 | [diff] [blame^] | 1136 | case FORMAT_MPEG4_MULTI_AAC: |
| 1137 | open.format = MPEG4_MULTI_AAC; |
| 1138 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1139 | case FORMAT_WMA_V9: |
| 1140 | open.format = WMA_V9; |
| 1141 | break; |
| 1142 | case FORMAT_WMA_V10PRO: |
| 1143 | open.format = WMA_V10PRO; |
| 1144 | break; |
| 1145 | default: |
| 1146 | pr_err("%s: Invalid format[%d]\n", __func__, format); |
| 1147 | goto fail_cmd; |
| 1148 | } |
| 1149 | rc = apr_send_pkt(ac->apr, (uint32_t *) &open); |
| 1150 | if (rc < 0) { |
| 1151 | pr_err("%s: open failed op[0x%x]rc[%d]\n", \ |
| 1152 | __func__, open.hdr.opcode, rc); |
| 1153 | goto fail_cmd; |
| 1154 | } |
| 1155 | rc = wait_event_timeout(ac->cmd_wait, |
| 1156 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 1157 | if (!rc) { |
| 1158 | pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__, |
| 1159 | rc); |
| 1160 | goto fail_cmd; |
| 1161 | } |
| 1162 | return 0; |
| 1163 | fail_cmd: |
| 1164 | return -EINVAL; |
| 1165 | } |
| 1166 | |
| 1167 | int q6asm_open_read_write(struct audio_client *ac, |
| 1168 | uint32_t rd_format, |
| 1169 | uint32_t wr_format) |
| 1170 | { |
| 1171 | int rc = 0x00; |
| 1172 | struct asm_stream_cmd_open_read_write open; |
| 1173 | |
| 1174 | if ((ac == NULL) || (ac->apr == NULL)) { |
| 1175 | pr_err("APR handle NULL\n"); |
| 1176 | return -EINVAL; |
| 1177 | } |
| 1178 | pr_debug("%s: session[%d]", __func__, ac->session); |
| 1179 | pr_debug("wr_format[0x%x]rd_format[0x%x]", |
| 1180 | wr_format, rd_format); |
| 1181 | |
| 1182 | q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE); |
| 1183 | open.hdr.opcode = ASM_STREAM_CMD_OPEN_READWRITE; |
| 1184 | |
Deepa Madiregama | 55cbf78 | 2011-09-10 05:44:39 +0530 | [diff] [blame] | 1185 | open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_NORMAL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1186 | /* source endpoint : matrix */ |
| 1187 | open.post_proc_top = get_asm_topology(); |
| 1188 | if (open.post_proc_top == 0) |
| 1189 | open.post_proc_top = DEFAULT_POPP_TOPOLOGY; |
| 1190 | |
| 1191 | switch (wr_format) { |
| 1192 | case FORMAT_LINEAR_PCM: |
| 1193 | open.write_format = LINEAR_PCM; |
| 1194 | break; |
| 1195 | case FORMAT_MPEG4_AAC: |
| 1196 | open.write_format = MPEG4_AAC; |
| 1197 | break; |
Bharath Ramachandramurthy | 4f71d50 | 2011-10-23 19:45:22 -0700 | [diff] [blame^] | 1198 | case FORMAT_MPEG4_MULTI_AAC: |
| 1199 | open.write_format = MPEG4_MULTI_AAC; |
| 1200 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1201 | case FORMAT_WMA_V9: |
| 1202 | open.write_format = WMA_V9; |
| 1203 | break; |
| 1204 | case FORMAT_WMA_V10PRO: |
| 1205 | open.write_format = WMA_V10PRO; |
| 1206 | break; |
| 1207 | default: |
| 1208 | pr_err("Invalid format[%d]\n", wr_format); |
| 1209 | goto fail_cmd; |
| 1210 | } |
| 1211 | |
| 1212 | switch (rd_format) { |
| 1213 | case FORMAT_LINEAR_PCM: |
| 1214 | open.read_format = LINEAR_PCM; |
| 1215 | break; |
| 1216 | case FORMAT_MPEG4_AAC: |
| 1217 | open.read_format = MPEG4_AAC; |
| 1218 | break; |
| 1219 | case FORMAT_V13K: |
| 1220 | open.read_format = V13K_FS; |
| 1221 | break; |
| 1222 | case FORMAT_EVRC: |
| 1223 | open.read_format = EVRC_FS; |
| 1224 | break; |
| 1225 | case FORMAT_AMRNB: |
| 1226 | open.read_format = AMRNB_FS; |
| 1227 | break; |
| 1228 | default: |
| 1229 | pr_err("Invalid format[%d]\n", rd_format); |
| 1230 | goto fail_cmd; |
| 1231 | } |
| 1232 | pr_debug("%s:rdformat[0x%x]wrformat[0x%x]\n", __func__, |
| 1233 | open.read_format, open.write_format); |
| 1234 | |
| 1235 | rc = apr_send_pkt(ac->apr, (uint32_t *) &open); |
| 1236 | if (rc < 0) { |
| 1237 | pr_err("open failed op[0x%x]rc[%d]\n", \ |
| 1238 | open.hdr.opcode, rc); |
| 1239 | goto fail_cmd; |
| 1240 | } |
| 1241 | rc = wait_event_timeout(ac->cmd_wait, |
| 1242 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 1243 | if (!rc) { |
| 1244 | pr_err("timeout. waited for OPEN_WRITE rc[%d]\n", rc); |
| 1245 | goto fail_cmd; |
| 1246 | } |
| 1247 | return 0; |
| 1248 | fail_cmd: |
| 1249 | return -EINVAL; |
| 1250 | } |
| 1251 | |
| 1252 | int q6asm_run(struct audio_client *ac, uint32_t flags, |
| 1253 | uint32_t msw_ts, uint32_t lsw_ts) |
| 1254 | { |
| 1255 | struct asm_stream_cmd_run run; |
| 1256 | int rc; |
| 1257 | if (!ac || ac->apr == NULL) { |
| 1258 | pr_err("APR handle NULL\n"); |
| 1259 | return -EINVAL; |
| 1260 | } |
| 1261 | pr_debug("%s session[%d]", __func__, ac->session); |
| 1262 | q6asm_add_hdr(ac, &run.hdr, sizeof(run), TRUE); |
| 1263 | |
| 1264 | run.hdr.opcode = ASM_SESSION_CMD_RUN; |
| 1265 | run.flags = flags; |
| 1266 | run.msw_ts = msw_ts; |
| 1267 | run.lsw_ts = lsw_ts; |
Rajesha Kini | 3498c93 | 2011-07-19 19:58:27 +0530 | [diff] [blame] | 1268 | #ifdef CONFIG_DEBUG_FS |
| 1269 | if (out_enable_flag) { |
| 1270 | do_gettimeofday(&out_cold_tv); |
| 1271 | pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",\ |
| 1272 | out_cold_tv.tv_sec, out_cold_tv.tv_usec); |
| 1273 | } |
| 1274 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1275 | rc = apr_send_pkt(ac->apr, (uint32_t *) &run); |
| 1276 | if (rc < 0) { |
| 1277 | pr_err("Commmand run failed[%d]", rc); |
| 1278 | goto fail_cmd; |
| 1279 | } |
| 1280 | |
| 1281 | rc = wait_event_timeout(ac->cmd_wait, |
| 1282 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 1283 | if (!rc) { |
| 1284 | pr_err("timeout. waited for run success rc[%d]", rc); |
| 1285 | goto fail_cmd; |
| 1286 | } |
| 1287 | |
| 1288 | return 0; |
| 1289 | fail_cmd: |
| 1290 | return -EINVAL; |
| 1291 | } |
| 1292 | |
| 1293 | int q6asm_run_nowait(struct audio_client *ac, uint32_t flags, |
| 1294 | uint32_t msw_ts, uint32_t lsw_ts) |
| 1295 | { |
| 1296 | struct asm_stream_cmd_run run; |
| 1297 | int rc; |
| 1298 | if (!ac || ac->apr == NULL) { |
| 1299 | pr_err("%s:APR handle NULL\n", __func__); |
| 1300 | return -EINVAL; |
| 1301 | } |
| 1302 | pr_debug("session[%d]", ac->session); |
| 1303 | q6asm_add_hdr_async(ac, &run.hdr, sizeof(run), TRUE); |
| 1304 | |
| 1305 | run.hdr.opcode = ASM_SESSION_CMD_RUN; |
| 1306 | run.flags = flags; |
| 1307 | run.msw_ts = msw_ts; |
| 1308 | run.lsw_ts = lsw_ts; |
| 1309 | |
| 1310 | rc = apr_send_pkt(ac->apr, (uint32_t *) &run); |
| 1311 | if (rc < 0) { |
| 1312 | pr_err("%s:Commmand run failed[%d]", __func__, rc); |
| 1313 | return -EINVAL; |
| 1314 | } |
| 1315 | return 0; |
| 1316 | } |
| 1317 | |
| 1318 | |
| 1319 | int q6asm_enc_cfg_blk_aac(struct audio_client *ac, |
| 1320 | uint32_t frames_per_buf, |
| 1321 | uint32_t sample_rate, uint32_t channels, |
| 1322 | uint32_t bit_rate, uint32_t mode, uint32_t format) |
| 1323 | { |
| 1324 | struct asm_stream_cmd_encdec_cfg_blk enc_cfg; |
| 1325 | int rc = 0; |
| 1326 | |
| 1327 | pr_debug("%s:session[%d]frames[%d]SR[%d]ch[%d]bitrate[%d]mode[%d]" |
| 1328 | "format[%d]", __func__, ac->session, frames_per_buf, |
| 1329 | sample_rate, channels, bit_rate, mode, format); |
| 1330 | |
| 1331 | q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE); |
| 1332 | |
| 1333 | enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM; |
| 1334 | enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID; |
| 1335 | enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk); |
| 1336 | enc_cfg.enc_blk.frames_per_buf = frames_per_buf; |
| 1337 | enc_cfg.enc_blk.format_id = MPEG4_AAC; |
| 1338 | enc_cfg.enc_blk.cfg_size = sizeof(struct asm_aac_read_cfg); |
| 1339 | enc_cfg.enc_blk.cfg.aac.bitrate = bit_rate; |
| 1340 | enc_cfg.enc_blk.cfg.aac.enc_mode = mode; |
| 1341 | enc_cfg.enc_blk.cfg.aac.format = format; |
| 1342 | enc_cfg.enc_blk.cfg.aac.ch_cfg = channels; |
| 1343 | enc_cfg.enc_blk.cfg.aac.sample_rate = sample_rate; |
| 1344 | |
| 1345 | rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg); |
| 1346 | if (rc < 0) { |
| 1347 | pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM); |
| 1348 | rc = -EINVAL; |
| 1349 | goto fail_cmd; |
| 1350 | } |
| 1351 | rc = wait_event_timeout(ac->cmd_wait, |
| 1352 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 1353 | if (!rc) { |
| 1354 | pr_err("timeout. waited for FORMAT_UPDATE\n"); |
| 1355 | goto fail_cmd; |
| 1356 | } |
| 1357 | return 0; |
| 1358 | fail_cmd: |
| 1359 | return -EINVAL; |
| 1360 | } |
| 1361 | |
| 1362 | int q6asm_enc_cfg_blk_pcm(struct audio_client *ac, |
| 1363 | uint32_t rate, uint32_t channels) |
| 1364 | { |
| 1365 | struct asm_stream_cmd_encdec_cfg_blk enc_cfg; |
| 1366 | |
| 1367 | int rc = 0; |
| 1368 | |
| 1369 | pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__, |
| 1370 | ac->session, rate, channels); |
| 1371 | |
| 1372 | q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE); |
| 1373 | |
| 1374 | enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM; |
| 1375 | enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID; |
| 1376 | enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk); |
| 1377 | enc_cfg.enc_blk.frames_per_buf = 1; |
| 1378 | enc_cfg.enc_blk.format_id = LINEAR_PCM; |
| 1379 | enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg); |
| 1380 | enc_cfg.enc_blk.cfg.pcm.ch_cfg = channels; |
| 1381 | enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16; |
| 1382 | enc_cfg.enc_blk.cfg.pcm.sample_rate = rate; |
| 1383 | enc_cfg.enc_blk.cfg.pcm.is_signed = 1; |
| 1384 | enc_cfg.enc_blk.cfg.pcm.interleaved = 1; |
| 1385 | |
| 1386 | rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg); |
| 1387 | if (rc < 0) { |
| 1388 | pr_err("Comamnd open failed\n"); |
| 1389 | rc = -EINVAL; |
| 1390 | goto fail_cmd; |
| 1391 | } |
| 1392 | rc = wait_event_timeout(ac->cmd_wait, |
| 1393 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 1394 | if (!rc) { |
| 1395 | pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode); |
| 1396 | goto fail_cmd; |
| 1397 | } |
| 1398 | return 0; |
| 1399 | fail_cmd: |
| 1400 | return -EINVAL; |
| 1401 | } |
| 1402 | |
| 1403 | int q6asm_enable_sbrps(struct audio_client *ac, |
| 1404 | uint32_t sbr_ps_enable) |
| 1405 | { |
| 1406 | struct asm_stream_cmd_encdec_sbr sbrps; |
| 1407 | |
| 1408 | int rc = 0; |
| 1409 | |
| 1410 | pr_debug("%s: Session %d\n", __func__, ac->session); |
| 1411 | |
| 1412 | q6asm_add_hdr(ac, &sbrps.hdr, sizeof(sbrps), TRUE); |
| 1413 | |
| 1414 | sbrps.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM; |
| 1415 | sbrps.param_id = ASM_ENABLE_SBR_PS; |
| 1416 | sbrps.param_size = sizeof(struct asm_sbr_ps); |
| 1417 | sbrps.sbr_ps.enable = sbr_ps_enable; |
| 1418 | |
| 1419 | rc = apr_send_pkt(ac->apr, (uint32_t *) &sbrps); |
| 1420 | if (rc < 0) { |
| 1421 | pr_err("Command opcode[0x%x]paramid[0x%x] failed\n", |
| 1422 | ASM_STREAM_CMD_SET_ENCDEC_PARAM, |
| 1423 | ASM_ENABLE_SBR_PS); |
| 1424 | rc = -EINVAL; |
| 1425 | goto fail_cmd; |
| 1426 | } |
| 1427 | rc = wait_event_timeout(ac->cmd_wait, |
| 1428 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 1429 | if (!rc) { |
| 1430 | pr_err("timeout opcode[0x%x] ", sbrps.hdr.opcode); |
| 1431 | goto fail_cmd; |
| 1432 | } |
| 1433 | return 0; |
| 1434 | fail_cmd: |
| 1435 | return -EINVAL; |
| 1436 | } |
| 1437 | |
Swaminathan Sathappan | 70765cd | 2011-07-19 18:42:47 -0700 | [diff] [blame] | 1438 | int q6asm_cfg_dual_mono_aac(struct audio_client *ac, |
| 1439 | uint16_t sce_left, uint16_t sce_right) |
| 1440 | { |
| 1441 | struct asm_stream_cmd_encdec_dualmono dual_mono; |
| 1442 | |
| 1443 | int rc = 0; |
| 1444 | |
| 1445 | pr_debug("%s: Session %d, sce_left = %d, sce_right = %d\n", |
| 1446 | __func__, ac->session, sce_left, sce_right); |
| 1447 | |
| 1448 | q6asm_add_hdr(ac, &dual_mono.hdr, sizeof(dual_mono), TRUE); |
| 1449 | |
| 1450 | dual_mono.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM; |
| 1451 | dual_mono.param_id = ASM_CONFIGURE_DUAL_MONO; |
| 1452 | dual_mono.param_size = sizeof(struct asm_dual_mono); |
| 1453 | dual_mono.channel_map.sce_left = sce_left; |
| 1454 | dual_mono.channel_map.sce_right = sce_right; |
| 1455 | |
| 1456 | rc = apr_send_pkt(ac->apr, (uint32_t *) &dual_mono); |
| 1457 | if (rc < 0) { |
| 1458 | pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n", |
| 1459 | __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM, |
| 1460 | ASM_CONFIGURE_DUAL_MONO); |
| 1461 | rc = -EINVAL; |
| 1462 | goto fail_cmd; |
| 1463 | } |
| 1464 | rc = wait_event_timeout(ac->cmd_wait, |
| 1465 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 1466 | if (!rc) { |
| 1467 | pr_err("%s:timeout opcode[0x%x]\n", __func__, |
| 1468 | dual_mono.hdr.opcode); |
| 1469 | goto fail_cmd; |
| 1470 | } |
| 1471 | return 0; |
| 1472 | fail_cmd: |
| 1473 | return -EINVAL; |
| 1474 | } |
| 1475 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1476 | int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf, |
| 1477 | uint16_t min_rate, uint16_t max_rate, |
| 1478 | uint16_t reduced_rate_level, uint16_t rate_modulation_cmd) |
| 1479 | { |
| 1480 | struct asm_stream_cmd_encdec_cfg_blk enc_cfg; |
| 1481 | int rc = 0; |
| 1482 | |
| 1483 | pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] \ |
| 1484 | reduced_rate_level[0x%4x]rate_modulation_cmd[0x%4x]", __func__, |
| 1485 | ac->session, frames_per_buf, min_rate, max_rate, |
| 1486 | reduced_rate_level, rate_modulation_cmd); |
| 1487 | |
| 1488 | q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE); |
| 1489 | |
| 1490 | enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM; |
| 1491 | |
| 1492 | enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID; |
| 1493 | enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk); |
| 1494 | |
| 1495 | enc_cfg.enc_blk.frames_per_buf = frames_per_buf; |
| 1496 | enc_cfg.enc_blk.format_id = V13K_FS; |
| 1497 | enc_cfg.enc_blk.cfg_size = sizeof(struct asm_qcelp13_read_cfg); |
| 1498 | enc_cfg.enc_blk.cfg.qcelp13.min_rate = min_rate; |
| 1499 | enc_cfg.enc_blk.cfg.qcelp13.max_rate = max_rate; |
| 1500 | enc_cfg.enc_blk.cfg.qcelp13.reduced_rate_level = reduced_rate_level; |
| 1501 | enc_cfg.enc_blk.cfg.qcelp13.rate_modulation_cmd = rate_modulation_cmd; |
| 1502 | |
| 1503 | rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg); |
| 1504 | if (rc < 0) { |
| 1505 | pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM); |
| 1506 | goto fail_cmd; |
| 1507 | } |
| 1508 | rc = wait_event_timeout(ac->cmd_wait, |
| 1509 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 1510 | if (!rc) { |
| 1511 | pr_err("timeout. waited for FORMAT_UPDATE\n"); |
| 1512 | goto fail_cmd; |
| 1513 | } |
| 1514 | return 0; |
| 1515 | fail_cmd: |
| 1516 | return -EINVAL; |
| 1517 | } |
| 1518 | |
| 1519 | int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf, |
| 1520 | uint16_t min_rate, uint16_t max_rate, |
| 1521 | uint16_t rate_modulation_cmd) |
| 1522 | { |
| 1523 | struct asm_stream_cmd_encdec_cfg_blk enc_cfg; |
| 1524 | int rc = 0; |
| 1525 | |
| 1526 | pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] \ |
| 1527 | rate_modulation_cmd[0x%4x]", __func__, ac->session, |
| 1528 | frames_per_buf, min_rate, max_rate, rate_modulation_cmd); |
| 1529 | |
| 1530 | q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE); |
| 1531 | |
| 1532 | enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM; |
| 1533 | |
| 1534 | enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID; |
| 1535 | enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk); |
| 1536 | |
| 1537 | enc_cfg.enc_blk.frames_per_buf = frames_per_buf; |
| 1538 | enc_cfg.enc_blk.format_id = EVRC_FS; |
| 1539 | enc_cfg.enc_blk.cfg_size = sizeof(struct asm_evrc_read_cfg); |
| 1540 | enc_cfg.enc_blk.cfg.evrc.min_rate = min_rate; |
| 1541 | enc_cfg.enc_blk.cfg.evrc.max_rate = max_rate; |
| 1542 | enc_cfg.enc_blk.cfg.evrc.rate_modulation_cmd = rate_modulation_cmd; |
| 1543 | enc_cfg.enc_blk.cfg.evrc.reserved = 0; |
| 1544 | |
| 1545 | rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg); |
| 1546 | if (rc < 0) { |
| 1547 | pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM); |
| 1548 | goto fail_cmd; |
| 1549 | } |
| 1550 | rc = wait_event_timeout(ac->cmd_wait, |
| 1551 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 1552 | if (!rc) { |
| 1553 | pr_err("timeout. waited for FORMAT_UPDATE\n"); |
| 1554 | goto fail_cmd; |
| 1555 | } |
| 1556 | return 0; |
| 1557 | fail_cmd: |
| 1558 | return -EINVAL; |
| 1559 | } |
| 1560 | |
| 1561 | int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf, |
| 1562 | uint16_t band_mode, uint16_t dtx_enable) |
| 1563 | { |
| 1564 | struct asm_stream_cmd_encdec_cfg_blk enc_cfg; |
| 1565 | int rc = 0; |
| 1566 | |
| 1567 | pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]", |
| 1568 | __func__, ac->session, frames_per_buf, band_mode, dtx_enable); |
| 1569 | |
| 1570 | q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE); |
| 1571 | |
| 1572 | enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM; |
| 1573 | |
| 1574 | enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID; |
| 1575 | enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk); |
| 1576 | |
| 1577 | enc_cfg.enc_blk.frames_per_buf = frames_per_buf; |
| 1578 | enc_cfg.enc_blk.format_id = AMRNB_FS; |
| 1579 | enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrnb_read_cfg); |
| 1580 | enc_cfg.enc_blk.cfg.amrnb.mode = band_mode; |
| 1581 | enc_cfg.enc_blk.cfg.amrnb.dtx_mode = dtx_enable; |
| 1582 | |
| 1583 | rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg); |
| 1584 | if (rc < 0) { |
| 1585 | pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM); |
| 1586 | goto fail_cmd; |
| 1587 | } |
| 1588 | rc = wait_event_timeout(ac->cmd_wait, |
| 1589 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 1590 | if (!rc) { |
| 1591 | pr_err("timeout. waited for FORMAT_UPDATE\n"); |
| 1592 | goto fail_cmd; |
| 1593 | } |
| 1594 | return 0; |
| 1595 | fail_cmd: |
| 1596 | return -EINVAL; |
| 1597 | } |
| 1598 | |
| 1599 | int q6asm_media_format_block_pcm(struct audio_client *ac, |
| 1600 | uint32_t rate, uint32_t channels) |
| 1601 | { |
| 1602 | struct asm_stream_media_format_update fmt; |
| 1603 | int rc = 0; |
| 1604 | |
| 1605 | pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate, |
| 1606 | channels); |
| 1607 | |
| 1608 | q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE); |
| 1609 | |
| 1610 | fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE; |
| 1611 | |
| 1612 | fmt.format = LINEAR_PCM; |
| 1613 | fmt.cfg_size = sizeof(struct asm_pcm_cfg); |
| 1614 | fmt.write_cfg.pcm_cfg.ch_cfg = channels; |
| 1615 | fmt.write_cfg.pcm_cfg.bits_per_sample = 16; |
| 1616 | fmt.write_cfg.pcm_cfg.sample_rate = rate; |
| 1617 | fmt.write_cfg.pcm_cfg.is_signed = 1; |
| 1618 | fmt.write_cfg.pcm_cfg.interleaved = 1; |
| 1619 | |
| 1620 | rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt); |
| 1621 | if (rc < 0) { |
| 1622 | pr_err("%s:Comamnd open failed\n", __func__); |
| 1623 | goto fail_cmd; |
| 1624 | } |
| 1625 | rc = wait_event_timeout(ac->cmd_wait, |
| 1626 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 1627 | if (!rc) { |
| 1628 | pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__); |
| 1629 | goto fail_cmd; |
| 1630 | } |
| 1631 | return 0; |
| 1632 | fail_cmd: |
| 1633 | return -EINVAL; |
| 1634 | } |
| 1635 | |
| 1636 | int q6asm_media_format_block_aac(struct audio_client *ac, |
| 1637 | struct asm_aac_cfg *cfg) |
| 1638 | { |
| 1639 | struct asm_stream_media_format_update fmt; |
| 1640 | int rc = 0; |
| 1641 | |
| 1642 | pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, |
| 1643 | cfg->sample_rate, cfg->ch_cfg); |
| 1644 | |
| 1645 | q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE); |
| 1646 | |
| 1647 | fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE; |
| 1648 | |
| 1649 | fmt.format = MPEG4_AAC; |
| 1650 | fmt.cfg_size = sizeof(struct asm_aac_cfg); |
| 1651 | fmt.write_cfg.aac_cfg.format = cfg->format; |
| 1652 | fmt.write_cfg.aac_cfg.aot = cfg->aot; |
| 1653 | fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config; |
| 1654 | fmt.write_cfg.aac_cfg.section_data_resilience = |
| 1655 | cfg->section_data_resilience; |
| 1656 | fmt.write_cfg.aac_cfg.scalefactor_data_resilience = |
| 1657 | cfg->scalefactor_data_resilience; |
| 1658 | fmt.write_cfg.aac_cfg.spectral_data_resilience = |
| 1659 | cfg->spectral_data_resilience; |
| 1660 | fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg; |
| 1661 | fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate; |
| 1662 | pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n", |
| 1663 | __func__, fmt.format, fmt.cfg_size, |
| 1664 | fmt.write_cfg.aac_cfg.format, |
| 1665 | fmt.write_cfg.aac_cfg.aot, |
| 1666 | fmt.write_cfg.aac_cfg.ch_cfg, |
| 1667 | fmt.write_cfg.aac_cfg.sample_rate); |
| 1668 | rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt); |
| 1669 | if (rc < 0) { |
| 1670 | pr_err("%s:Comamnd open failed\n", __func__); |
| 1671 | goto fail_cmd; |
| 1672 | } |
| 1673 | rc = wait_event_timeout(ac->cmd_wait, |
| 1674 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 1675 | if (!rc) { |
| 1676 | pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__); |
| 1677 | goto fail_cmd; |
| 1678 | } |
| 1679 | return 0; |
| 1680 | fail_cmd: |
| 1681 | return -EINVAL; |
| 1682 | } |
| 1683 | |
Bharath Ramachandramurthy | 4f71d50 | 2011-10-23 19:45:22 -0700 | [diff] [blame^] | 1684 | |
| 1685 | int q6asm_media_format_block_multi_aac(struct audio_client *ac, |
| 1686 | struct asm_aac_cfg *cfg) |
| 1687 | { |
| 1688 | struct asm_stream_media_format_update fmt; |
| 1689 | int rc = 0; |
| 1690 | |
| 1691 | pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, |
| 1692 | cfg->sample_rate, cfg->ch_cfg); |
| 1693 | |
| 1694 | q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE); |
| 1695 | |
| 1696 | fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE; |
| 1697 | |
| 1698 | fmt.format = MPEG4_MULTI_AAC; |
| 1699 | fmt.cfg_size = sizeof(struct asm_aac_cfg); |
| 1700 | fmt.write_cfg.aac_cfg.format = cfg->format; |
| 1701 | fmt.write_cfg.aac_cfg.aot = cfg->aot; |
| 1702 | fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config; |
| 1703 | fmt.write_cfg.aac_cfg.section_data_resilience = |
| 1704 | cfg->section_data_resilience; |
| 1705 | fmt.write_cfg.aac_cfg.scalefactor_data_resilience = |
| 1706 | cfg->scalefactor_data_resilience; |
| 1707 | fmt.write_cfg.aac_cfg.spectral_data_resilience = |
| 1708 | cfg->spectral_data_resilience; |
| 1709 | fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg; |
| 1710 | fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate; |
| 1711 | pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n", |
| 1712 | __func__, fmt.format, fmt.cfg_size, |
| 1713 | fmt.write_cfg.aac_cfg.format, |
| 1714 | fmt.write_cfg.aac_cfg.aot, |
| 1715 | fmt.write_cfg.aac_cfg.ch_cfg, |
| 1716 | fmt.write_cfg.aac_cfg.sample_rate); |
| 1717 | rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt); |
| 1718 | if (rc < 0) { |
| 1719 | pr_err("%s:Comamnd open failed\n", __func__); |
| 1720 | goto fail_cmd; |
| 1721 | } |
| 1722 | rc = wait_event_timeout(ac->cmd_wait, |
| 1723 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 1724 | if (!rc) { |
| 1725 | pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__); |
| 1726 | goto fail_cmd; |
| 1727 | } |
| 1728 | return 0; |
| 1729 | fail_cmd: |
| 1730 | return -EINVAL; |
| 1731 | } |
| 1732 | |
| 1733 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1734 | int q6asm_media_format_block_wma(struct audio_client *ac, |
| 1735 | void *cfg) |
| 1736 | { |
| 1737 | struct asm_stream_media_format_update fmt; |
| 1738 | struct asm_wma_cfg *wma_cfg = (struct asm_wma_cfg *)cfg; |
| 1739 | int rc = 0; |
| 1740 | |
| 1741 | pr_debug("session[%d]format_tag[0x%4x] rate[%d] ch[0x%4x] bps[%d],\ |
| 1742 | balign[0x%4x], bit_sample[0x%4x], ch_msk[%d], enc_opt[0x%4x]\n", |
| 1743 | ac->session, wma_cfg->format_tag, wma_cfg->sample_rate, |
| 1744 | wma_cfg->ch_cfg, wma_cfg->avg_bytes_per_sec, |
| 1745 | wma_cfg->block_align, wma_cfg->valid_bits_per_sample, |
| 1746 | wma_cfg->ch_mask, wma_cfg->encode_opt); |
| 1747 | |
| 1748 | q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE); |
| 1749 | |
| 1750 | fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE; |
| 1751 | |
| 1752 | fmt.format = WMA_V9; |
| 1753 | fmt.cfg_size = sizeof(struct asm_wma_cfg); |
| 1754 | fmt.write_cfg.wma_cfg.format_tag = wma_cfg->format_tag; |
| 1755 | fmt.write_cfg.wma_cfg.ch_cfg = wma_cfg->ch_cfg; |
| 1756 | fmt.write_cfg.wma_cfg.sample_rate = wma_cfg->sample_rate; |
| 1757 | fmt.write_cfg.wma_cfg.avg_bytes_per_sec = wma_cfg->avg_bytes_per_sec; |
| 1758 | fmt.write_cfg.wma_cfg.block_align = wma_cfg->block_align; |
| 1759 | fmt.write_cfg.wma_cfg.valid_bits_per_sample = |
| 1760 | wma_cfg->valid_bits_per_sample; |
| 1761 | fmt.write_cfg.wma_cfg.ch_mask = wma_cfg->ch_mask; |
| 1762 | fmt.write_cfg.wma_cfg.encode_opt = wma_cfg->encode_opt; |
| 1763 | fmt.write_cfg.wma_cfg.adv_encode_opt = 0; |
| 1764 | fmt.write_cfg.wma_cfg.adv_encode_opt2 = 0; |
| 1765 | fmt.write_cfg.wma_cfg.drc_peak_ref = 0; |
| 1766 | fmt.write_cfg.wma_cfg.drc_peak_target = 0; |
| 1767 | fmt.write_cfg.wma_cfg.drc_ave_ref = 0; |
| 1768 | fmt.write_cfg.wma_cfg.drc_ave_target = 0; |
| 1769 | |
| 1770 | rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt); |
| 1771 | if (rc < 0) { |
| 1772 | pr_err("%s:Comamnd open failed\n", __func__); |
| 1773 | goto fail_cmd; |
| 1774 | } |
| 1775 | rc = wait_event_timeout(ac->cmd_wait, |
| 1776 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 1777 | if (!rc) { |
| 1778 | pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__); |
| 1779 | goto fail_cmd; |
| 1780 | } |
| 1781 | return 0; |
| 1782 | fail_cmd: |
| 1783 | return -EINVAL; |
| 1784 | } |
| 1785 | |
| 1786 | int q6asm_media_format_block_wmapro(struct audio_client *ac, |
| 1787 | void *cfg) |
| 1788 | { |
| 1789 | struct asm_stream_media_format_update fmt; |
| 1790 | struct asm_wmapro_cfg *wmapro_cfg = (struct asm_wmapro_cfg *)cfg; |
| 1791 | int rc = 0; |
| 1792 | |
| 1793 | pr_debug("session[%d]format_tag[0x%4x] rate[%d] ch[0x%4x] bps[%d]," |
| 1794 | "balign[0x%4x], bit_sample[0x%4x], ch_msk[%d], enc_opt[0x%4x],\ |
| 1795 | adv_enc_opt[0x%4x], adv_enc_opt2[0x%8x]\n", |
| 1796 | ac->session, wmapro_cfg->format_tag, wmapro_cfg->sample_rate, |
| 1797 | wmapro_cfg->ch_cfg, wmapro_cfg->avg_bytes_per_sec, |
| 1798 | wmapro_cfg->block_align, wmapro_cfg->valid_bits_per_sample, |
| 1799 | wmapro_cfg->ch_mask, wmapro_cfg->encode_opt, |
| 1800 | wmapro_cfg->adv_encode_opt, wmapro_cfg->adv_encode_opt2); |
| 1801 | |
| 1802 | q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE); |
| 1803 | |
| 1804 | fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE; |
| 1805 | |
| 1806 | fmt.format = WMA_V10PRO; |
| 1807 | fmt.cfg_size = sizeof(struct asm_wmapro_cfg); |
| 1808 | fmt.write_cfg.wmapro_cfg.format_tag = wmapro_cfg->format_tag; |
| 1809 | fmt.write_cfg.wmapro_cfg.ch_cfg = wmapro_cfg->ch_cfg; |
| 1810 | fmt.write_cfg.wmapro_cfg.sample_rate = wmapro_cfg->sample_rate; |
| 1811 | fmt.write_cfg.wmapro_cfg.avg_bytes_per_sec = |
| 1812 | wmapro_cfg->avg_bytes_per_sec; |
| 1813 | fmt.write_cfg.wmapro_cfg.block_align = wmapro_cfg->block_align; |
| 1814 | fmt.write_cfg.wmapro_cfg.valid_bits_per_sample = |
| 1815 | wmapro_cfg->valid_bits_per_sample; |
| 1816 | fmt.write_cfg.wmapro_cfg.ch_mask = wmapro_cfg->ch_mask; |
| 1817 | fmt.write_cfg.wmapro_cfg.encode_opt = wmapro_cfg->encode_opt; |
| 1818 | fmt.write_cfg.wmapro_cfg.adv_encode_opt = wmapro_cfg->adv_encode_opt; |
| 1819 | fmt.write_cfg.wmapro_cfg.adv_encode_opt2 = wmapro_cfg->adv_encode_opt2; |
| 1820 | fmt.write_cfg.wmapro_cfg.drc_peak_ref = 0; |
| 1821 | fmt.write_cfg.wmapro_cfg.drc_peak_target = 0; |
| 1822 | fmt.write_cfg.wmapro_cfg.drc_ave_ref = 0; |
| 1823 | fmt.write_cfg.wmapro_cfg.drc_ave_target = 0; |
| 1824 | |
| 1825 | rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt); |
| 1826 | if (rc < 0) { |
| 1827 | pr_err("%s:Comamnd open failed\n", __func__); |
| 1828 | goto fail_cmd; |
| 1829 | } |
| 1830 | rc = wait_event_timeout(ac->cmd_wait, |
| 1831 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 1832 | if (!rc) { |
| 1833 | pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__); |
| 1834 | goto fail_cmd; |
| 1835 | } |
| 1836 | return 0; |
| 1837 | fail_cmd: |
| 1838 | return -EINVAL; |
| 1839 | } |
| 1840 | |
| 1841 | int q6asm_memory_map(struct audio_client *ac, uint32_t buf_add, int dir, |
| 1842 | uint32_t bufsz, uint32_t bufcnt) |
| 1843 | { |
| 1844 | struct asm_stream_cmd_memory_map mem_map; |
| 1845 | int rc = 0; |
| 1846 | |
| 1847 | if (!ac || ac->apr == NULL || this_mmap.apr == NULL) { |
| 1848 | pr_err("APR handle NULL\n"); |
| 1849 | return -EINVAL; |
| 1850 | } |
| 1851 | |
| 1852 | pr_debug("%s: Session[%d]\n", __func__, ac->session); |
| 1853 | |
| 1854 | mem_map.hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP; |
| 1855 | |
| 1856 | mem_map.buf_add = buf_add; |
| 1857 | mem_map.buf_size = bufsz * bufcnt; |
| 1858 | mem_map.mempool_id = 0; /* EBI */ |
| 1859 | mem_map.reserved = 0; |
| 1860 | |
| 1861 | q6asm_add_mmaphdr(&mem_map.hdr, |
| 1862 | sizeof(struct asm_stream_cmd_memory_map), TRUE); |
| 1863 | |
| 1864 | pr_debug("buf add[%x] buf_add_parameter[%x]\n", |
| 1865 | mem_map.buf_add, buf_add); |
| 1866 | |
| 1867 | rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_map); |
| 1868 | if (rc < 0) { |
| 1869 | pr_err("mem_map op[0x%x]rc[%d]\n", |
| 1870 | mem_map.hdr.opcode, rc); |
| 1871 | rc = -EINVAL; |
| 1872 | goto fail_cmd; |
| 1873 | } |
| 1874 | |
| 1875 | rc = wait_event_timeout(this_mmap.cmd_wait, |
| 1876 | (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ); |
| 1877 | if (!rc) { |
| 1878 | pr_err("timeout. waited for memory_map\n"); |
| 1879 | rc = -EINVAL; |
| 1880 | goto fail_cmd; |
| 1881 | } |
| 1882 | rc = 0; |
| 1883 | fail_cmd: |
| 1884 | return rc; |
| 1885 | } |
| 1886 | |
| 1887 | int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add, int dir) |
| 1888 | { |
| 1889 | struct asm_stream_cmd_memory_unmap mem_unmap; |
| 1890 | int rc = 0; |
| 1891 | |
| 1892 | if (!ac || ac->apr == NULL || this_mmap.apr == NULL) { |
| 1893 | pr_err("APR handle NULL\n"); |
| 1894 | return -EINVAL; |
| 1895 | } |
| 1896 | pr_debug("%s: Session[%d]\n", __func__, ac->session); |
| 1897 | |
| 1898 | q6asm_add_mmaphdr(&mem_unmap.hdr, |
| 1899 | sizeof(struct asm_stream_cmd_memory_unmap), TRUE); |
| 1900 | mem_unmap.hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP; |
| 1901 | mem_unmap.buf_add = buf_add; |
| 1902 | |
| 1903 | rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_unmap); |
| 1904 | if (rc < 0) { |
| 1905 | pr_err("mem_unmap op[0x%x]rc[%d]\n", |
| 1906 | mem_unmap.hdr.opcode, rc); |
| 1907 | rc = -EINVAL; |
| 1908 | goto fail_cmd; |
| 1909 | } |
| 1910 | |
| 1911 | rc = wait_event_timeout(this_mmap.cmd_wait, |
| 1912 | (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ); |
| 1913 | if (!rc) { |
| 1914 | pr_err("timeout. waited for memory_map\n"); |
| 1915 | rc = -EINVAL; |
| 1916 | goto fail_cmd; |
| 1917 | } |
| 1918 | rc = 0; |
| 1919 | fail_cmd: |
| 1920 | return rc; |
| 1921 | } |
| 1922 | |
| 1923 | int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain) |
| 1924 | { |
| 1925 | void *vol_cmd = NULL; |
| 1926 | void *payload = NULL; |
| 1927 | struct asm_pp_params_command *cmd = NULL; |
| 1928 | struct asm_lrchannel_gain_params *lrgain = NULL; |
| 1929 | int sz = 0; |
| 1930 | int rc = 0; |
| 1931 | |
| 1932 | sz = sizeof(struct asm_pp_params_command) + |
| 1933 | + sizeof(struct asm_lrchannel_gain_params); |
| 1934 | vol_cmd = kzalloc(sz, GFP_KERNEL); |
| 1935 | if (vol_cmd == NULL) { |
| 1936 | pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session); |
| 1937 | rc = -EINVAL; |
| 1938 | return rc; |
| 1939 | } |
| 1940 | cmd = (struct asm_pp_params_command *)vol_cmd; |
| 1941 | q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE); |
| 1942 | cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS; |
| 1943 | cmd->payload = NULL; |
| 1944 | cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) + |
| 1945 | sizeof(struct asm_lrchannel_gain_params); |
| 1946 | cmd->params.module_id = VOLUME_CONTROL_MODULE_ID; |
| 1947 | cmd->params.param_id = L_R_CHANNEL_GAIN_PARAM_ID; |
| 1948 | cmd->params.param_size = sizeof(struct asm_lrchannel_gain_params); |
| 1949 | cmd->params.reserved = 0; |
| 1950 | |
| 1951 | payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command)); |
| 1952 | lrgain = (struct asm_lrchannel_gain_params *)payload; |
| 1953 | |
| 1954 | lrgain->left_gain = left_gain; |
| 1955 | lrgain->right_gain = right_gain; |
| 1956 | rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd); |
| 1957 | if (rc < 0) { |
| 1958 | pr_err("%s: Volume Command failed\n", __func__); |
| 1959 | rc = -EINVAL; |
| 1960 | goto fail_cmd; |
| 1961 | } |
| 1962 | |
| 1963 | rc = wait_event_timeout(ac->cmd_wait, |
| 1964 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 1965 | if (!rc) { |
| 1966 | pr_err("%s: timeout in sending volume command to apr\n", |
| 1967 | __func__); |
| 1968 | rc = -EINVAL; |
| 1969 | goto fail_cmd; |
| 1970 | } |
| 1971 | rc = 0; |
| 1972 | fail_cmd: |
| 1973 | kfree(vol_cmd); |
| 1974 | return rc; |
| 1975 | } |
| 1976 | |
| 1977 | static int q6asm_memory_map_regions(struct audio_client *ac, int dir, |
| 1978 | uint32_t bufsz, uint32_t bufcnt) |
| 1979 | { |
| 1980 | struct asm_stream_cmd_memory_map_regions *mmap_regions = NULL; |
| 1981 | struct asm_memory_map_regions *mregions = NULL; |
| 1982 | struct audio_port_data *port = NULL; |
| 1983 | struct audio_buffer *ab = NULL; |
| 1984 | void *mmap_region_cmd = NULL; |
| 1985 | void *payload = NULL; |
| 1986 | int rc = 0; |
| 1987 | int i = 0; |
| 1988 | int cmd_size = 0; |
| 1989 | |
| 1990 | if (!ac || ac->apr == NULL || this_mmap.apr == NULL) { |
| 1991 | pr_err("APR handle NULL\n"); |
| 1992 | return -EINVAL; |
| 1993 | } |
| 1994 | pr_debug("%s: Session[%d]\n", __func__, ac->session); |
| 1995 | |
| 1996 | cmd_size = sizeof(struct asm_stream_cmd_memory_map_regions) |
| 1997 | + sizeof(struct asm_memory_map_regions) * bufcnt; |
| 1998 | |
| 1999 | mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL); |
Vasudeva Rao Thumati | 86edf6c | 2011-07-06 16:25:13 +0530 | [diff] [blame] | 2000 | if (mmap_region_cmd == NULL) { |
| 2001 | pr_err("%s: Mem alloc failed\n", __func__); |
| 2002 | rc = -EINVAL; |
| 2003 | return rc; |
| 2004 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2005 | mmap_regions = (struct asm_stream_cmd_memory_map_regions *) |
| 2006 | mmap_region_cmd; |
| 2007 | q6asm_add_mmaphdr(&mmap_regions->hdr, cmd_size, TRUE); |
| 2008 | mmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP_REGIONS; |
| 2009 | mmap_regions->mempool_id = 0; |
| 2010 | mmap_regions->nregions = bufcnt & 0x00ff; |
| 2011 | pr_debug("map_regions->nregions = %d\n", mmap_regions->nregions); |
| 2012 | payload = ((u8 *) mmap_region_cmd + |
| 2013 | sizeof(struct asm_stream_cmd_memory_map_regions)); |
| 2014 | mregions = (struct asm_memory_map_regions *)payload; |
| 2015 | |
| 2016 | port = &ac->port[dir]; |
| 2017 | for (i = 0; i < bufcnt; i++) { |
| 2018 | ab = &port->buf[i]; |
| 2019 | mregions->phys = ab->phys; |
| 2020 | mregions->buf_size = ab->size; |
| 2021 | ++mregions; |
| 2022 | } |
| 2023 | |
| 2024 | rc = apr_send_pkt(this_mmap.apr, (uint32_t *) mmap_region_cmd); |
| 2025 | if (rc < 0) { |
| 2026 | pr_err("mmap_regions op[0x%x]rc[%d]\n", |
| 2027 | mmap_regions->hdr.opcode, rc); |
| 2028 | rc = -EINVAL; |
| 2029 | goto fail_cmd; |
| 2030 | } |
| 2031 | |
| 2032 | rc = wait_event_timeout(this_mmap.cmd_wait, |
| 2033 | (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ); |
| 2034 | if (!rc) { |
| 2035 | pr_err("timeout. waited for memory_map\n"); |
| 2036 | rc = -EINVAL; |
| 2037 | goto fail_cmd; |
| 2038 | } |
| 2039 | rc = 0; |
| 2040 | fail_cmd: |
| 2041 | kfree(mmap_region_cmd); |
| 2042 | return rc; |
| 2043 | } |
| 2044 | |
| 2045 | static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir, |
| 2046 | uint32_t bufsz, uint32_t bufcnt) |
| 2047 | { |
| 2048 | struct asm_stream_cmd_memory_unmap_regions *unmap_regions = NULL; |
| 2049 | struct asm_memory_unmap_regions *mregions = NULL; |
| 2050 | struct audio_port_data *port = NULL; |
| 2051 | struct audio_buffer *ab = NULL; |
| 2052 | void *unmap_region_cmd = NULL; |
| 2053 | void *payload = NULL; |
| 2054 | int rc = 0; |
| 2055 | int i = 0; |
| 2056 | int cmd_size = 0; |
| 2057 | |
| 2058 | if (!ac || ac->apr == NULL || this_mmap.apr == NULL) { |
| 2059 | pr_err("APR handle NULL\n"); |
| 2060 | return -EINVAL; |
| 2061 | } |
| 2062 | pr_debug("%s: Session[%d]\n", __func__, ac->session); |
| 2063 | |
| 2064 | cmd_size = sizeof(struct asm_stream_cmd_memory_unmap_regions) + |
| 2065 | sizeof(struct asm_memory_unmap_regions) * bufcnt; |
| 2066 | |
| 2067 | unmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL); |
Vasudeva Rao Thumati | 86edf6c | 2011-07-06 16:25:13 +0530 | [diff] [blame] | 2068 | if (unmap_region_cmd == NULL) { |
| 2069 | pr_err("%s: Mem alloc failed\n", __func__); |
| 2070 | rc = -EINVAL; |
| 2071 | return rc; |
| 2072 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2073 | unmap_regions = (struct asm_stream_cmd_memory_unmap_regions *) |
| 2074 | unmap_region_cmd; |
| 2075 | q6asm_add_mmaphdr(&unmap_regions->hdr, cmd_size, TRUE); |
| 2076 | unmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS; |
| 2077 | unmap_regions->nregions = bufcnt & 0x00ff; |
| 2078 | pr_debug("unmap_regions->nregions = %d\n", unmap_regions->nregions); |
| 2079 | payload = ((u8 *) unmap_region_cmd + |
| 2080 | sizeof(struct asm_stream_cmd_memory_unmap_regions)); |
| 2081 | mregions = (struct asm_memory_unmap_regions *)payload; |
| 2082 | port = &ac->port[dir]; |
| 2083 | for (i = 0; i < bufcnt; i++) { |
| 2084 | ab = &port->buf[i]; |
| 2085 | mregions->phys = ab->phys; |
| 2086 | ++mregions; |
| 2087 | } |
| 2088 | |
| 2089 | rc = apr_send_pkt(this_mmap.apr, (uint32_t *) unmap_region_cmd); |
| 2090 | if (rc < 0) { |
| 2091 | pr_err("mmap_regions op[0x%x]rc[%d]\n", |
| 2092 | unmap_regions->hdr.opcode, rc); |
| 2093 | goto fail_cmd; |
| 2094 | } |
| 2095 | |
| 2096 | rc = wait_event_timeout(this_mmap.cmd_wait, |
| 2097 | (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ); |
| 2098 | if (!rc) { |
| 2099 | pr_err("timeout. waited for memory_unmap\n"); |
| 2100 | goto fail_cmd; |
| 2101 | } |
| 2102 | rc = 0; |
| 2103 | |
| 2104 | fail_cmd: |
| 2105 | kfree(unmap_region_cmd); |
| 2106 | return rc; |
| 2107 | } |
| 2108 | |
| 2109 | int q6asm_set_mute(struct audio_client *ac, int muteflag) |
| 2110 | { |
| 2111 | void *vol_cmd = NULL; |
| 2112 | void *payload = NULL; |
| 2113 | struct asm_pp_params_command *cmd = NULL; |
| 2114 | struct asm_mute_params *mute = NULL; |
| 2115 | int sz = 0; |
| 2116 | int rc = 0; |
| 2117 | |
| 2118 | sz = sizeof(struct asm_pp_params_command) + |
| 2119 | + sizeof(struct asm_mute_params); |
| 2120 | vol_cmd = kzalloc(sz, GFP_KERNEL); |
| 2121 | if (vol_cmd == NULL) { |
| 2122 | pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session); |
| 2123 | rc = -EINVAL; |
| 2124 | return rc; |
| 2125 | } |
| 2126 | cmd = (struct asm_pp_params_command *)vol_cmd; |
| 2127 | q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE); |
| 2128 | cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS; |
| 2129 | cmd->payload = NULL; |
| 2130 | cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) + |
| 2131 | sizeof(struct asm_mute_params); |
| 2132 | cmd->params.module_id = VOLUME_CONTROL_MODULE_ID; |
| 2133 | cmd->params.param_id = MUTE_CONFIG_PARAM_ID; |
| 2134 | cmd->params.param_size = sizeof(struct asm_mute_params); |
| 2135 | cmd->params.reserved = 0; |
| 2136 | |
| 2137 | payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command)); |
| 2138 | mute = (struct asm_mute_params *)payload; |
| 2139 | |
| 2140 | mute->muteflag = muteflag; |
| 2141 | rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd); |
| 2142 | if (rc < 0) { |
| 2143 | pr_err("%s: Mute Command failed\n", __func__); |
| 2144 | rc = -EINVAL; |
| 2145 | goto fail_cmd; |
| 2146 | } |
| 2147 | |
| 2148 | rc = wait_event_timeout(ac->cmd_wait, |
| 2149 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 2150 | if (!rc) { |
| 2151 | pr_err("%s: timeout in sending mute command to apr\n", |
| 2152 | __func__); |
| 2153 | rc = -EINVAL; |
| 2154 | goto fail_cmd; |
| 2155 | } |
| 2156 | rc = 0; |
| 2157 | fail_cmd: |
| 2158 | kfree(vol_cmd); |
| 2159 | return rc; |
| 2160 | } |
| 2161 | |
| 2162 | int q6asm_set_volume(struct audio_client *ac, int volume) |
| 2163 | { |
| 2164 | void *vol_cmd = NULL; |
| 2165 | void *payload = NULL; |
| 2166 | struct asm_pp_params_command *cmd = NULL; |
| 2167 | struct asm_master_gain_params *mgain = NULL; |
| 2168 | int sz = 0; |
| 2169 | int rc = 0; |
| 2170 | |
| 2171 | sz = sizeof(struct asm_pp_params_command) + |
| 2172 | + sizeof(struct asm_master_gain_params); |
| 2173 | vol_cmd = kzalloc(sz, GFP_KERNEL); |
| 2174 | if (vol_cmd == NULL) { |
| 2175 | pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session); |
| 2176 | rc = -EINVAL; |
| 2177 | return rc; |
| 2178 | } |
| 2179 | cmd = (struct asm_pp_params_command *)vol_cmd; |
| 2180 | q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE); |
| 2181 | cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS; |
| 2182 | cmd->payload = NULL; |
| 2183 | cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) + |
| 2184 | sizeof(struct asm_master_gain_params); |
| 2185 | cmd->params.module_id = VOLUME_CONTROL_MODULE_ID; |
| 2186 | cmd->params.param_id = MASTER_GAIN_PARAM_ID; |
| 2187 | cmd->params.param_size = sizeof(struct asm_master_gain_params); |
| 2188 | cmd->params.reserved = 0; |
| 2189 | |
| 2190 | payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command)); |
| 2191 | mgain = (struct asm_master_gain_params *)payload; |
| 2192 | |
| 2193 | mgain->master_gain = volume; |
| 2194 | mgain->padding = 0x00; |
| 2195 | rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd); |
| 2196 | if (rc < 0) { |
| 2197 | pr_err("%s: Volume Command failed\n", __func__); |
| 2198 | rc = -EINVAL; |
| 2199 | goto fail_cmd; |
| 2200 | } |
| 2201 | |
| 2202 | rc = wait_event_timeout(ac->cmd_wait, |
| 2203 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 2204 | if (!rc) { |
| 2205 | pr_err("%s: timeout in sending volume command to apr\n", |
| 2206 | __func__); |
| 2207 | rc = -EINVAL; |
| 2208 | goto fail_cmd; |
| 2209 | } |
| 2210 | rc = 0; |
| 2211 | fail_cmd: |
| 2212 | kfree(vol_cmd); |
| 2213 | return rc; |
| 2214 | } |
| 2215 | |
| 2216 | int q6asm_set_softpause(struct audio_client *ac, |
| 2217 | struct asm_softpause_params *pause_param) |
| 2218 | { |
| 2219 | void *vol_cmd = NULL; |
| 2220 | void *payload = NULL; |
| 2221 | struct asm_pp_params_command *cmd = NULL; |
| 2222 | struct asm_softpause_params *params = NULL; |
| 2223 | int sz = 0; |
| 2224 | int rc = 0; |
| 2225 | |
| 2226 | sz = sizeof(struct asm_pp_params_command) + |
| 2227 | + sizeof(struct asm_softpause_params); |
| 2228 | vol_cmd = kzalloc(sz, GFP_KERNEL); |
| 2229 | if (vol_cmd == NULL) { |
| 2230 | pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session); |
| 2231 | rc = -EINVAL; |
| 2232 | return rc; |
| 2233 | } |
| 2234 | cmd = (struct asm_pp_params_command *)vol_cmd; |
| 2235 | q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE); |
| 2236 | cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS; |
| 2237 | cmd->payload = NULL; |
| 2238 | cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) + |
| 2239 | sizeof(struct asm_softpause_params); |
| 2240 | cmd->params.module_id = VOLUME_CONTROL_MODULE_ID; |
| 2241 | cmd->params.param_id = SOFT_PAUSE_PARAM_ID; |
| 2242 | cmd->params.param_size = sizeof(struct asm_softpause_params); |
| 2243 | cmd->params.reserved = 0; |
| 2244 | |
| 2245 | payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command)); |
| 2246 | params = (struct asm_softpause_params *)payload; |
| 2247 | |
| 2248 | params->enable = pause_param->enable; |
| 2249 | params->period = pause_param->period; |
| 2250 | params->step = pause_param->step; |
| 2251 | params->rampingcurve = pause_param->rampingcurve; |
| 2252 | pr_debug("%s: soft Pause Command: enable = %d, period = %d," |
| 2253 | "step = %d, curve = %d\n", __func__, params->enable, |
| 2254 | params->period, params->step, params->rampingcurve); |
| 2255 | rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd); |
| 2256 | if (rc < 0) { |
| 2257 | pr_err("%s: Volume Command(soft_pause) failed\n", __func__); |
| 2258 | rc = -EINVAL; |
| 2259 | goto fail_cmd; |
| 2260 | } |
| 2261 | |
| 2262 | rc = wait_event_timeout(ac->cmd_wait, |
| 2263 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 2264 | if (!rc) { |
| 2265 | pr_err("%s: timeout in sending volume command(soft_pause)" |
| 2266 | "to apr\n", __func__); |
| 2267 | rc = -EINVAL; |
| 2268 | goto fail_cmd; |
| 2269 | } |
| 2270 | rc = 0; |
| 2271 | fail_cmd: |
| 2272 | kfree(vol_cmd); |
| 2273 | return rc; |
| 2274 | } |
| 2275 | |
Swaminathan Sathappan | b0021cd | 2011-08-31 15:20:12 -0700 | [diff] [blame] | 2276 | int q6asm_set_softvolume(struct audio_client *ac, |
| 2277 | struct asm_softvolume_params *softvol_param) |
| 2278 | { |
| 2279 | void *vol_cmd = NULL; |
| 2280 | void *payload = NULL; |
| 2281 | struct asm_pp_params_command *cmd = NULL; |
| 2282 | struct asm_softvolume_params *params = NULL; |
| 2283 | int sz = 0; |
| 2284 | int rc = 0; |
| 2285 | |
| 2286 | sz = sizeof(struct asm_pp_params_command) + |
| 2287 | + sizeof(struct asm_softvolume_params); |
| 2288 | vol_cmd = kzalloc(sz, GFP_KERNEL); |
| 2289 | if (vol_cmd == NULL) { |
| 2290 | pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session); |
| 2291 | rc = -EINVAL; |
| 2292 | return rc; |
| 2293 | } |
| 2294 | cmd = (struct asm_pp_params_command *)vol_cmd; |
| 2295 | q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE); |
| 2296 | cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS; |
| 2297 | cmd->payload = NULL; |
| 2298 | cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) + |
| 2299 | sizeof(struct asm_softvolume_params); |
| 2300 | cmd->params.module_id = VOLUME_CONTROL_MODULE_ID; |
| 2301 | cmd->params.param_id = SOFT_VOLUME_PARAM_ID; |
| 2302 | cmd->params.param_size = sizeof(struct asm_softvolume_params); |
| 2303 | cmd->params.reserved = 0; |
| 2304 | |
| 2305 | payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command)); |
| 2306 | params = (struct asm_softvolume_params *)payload; |
| 2307 | |
| 2308 | params->period = softvol_param->period; |
| 2309 | params->step = softvol_param->step; |
| 2310 | params->rampingcurve = softvol_param->rampingcurve; |
| 2311 | pr_debug("%s: soft Volume:opcode = %d,payload_sz =%d,module_id =%d," |
| 2312 | "param_id = %d, param_sz = %d\n", __func__, |
| 2313 | cmd->hdr.opcode, cmd->payload_size, |
| 2314 | cmd->params.module_id, cmd->params.param_id, |
| 2315 | cmd->params.param_size); |
| 2316 | pr_debug("%s: soft Volume Command: period = %d," |
| 2317 | "step = %d, curve = %d\n", __func__, params->period, |
| 2318 | params->step, params->rampingcurve); |
| 2319 | rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd); |
| 2320 | if (rc < 0) { |
| 2321 | pr_err("%s: Volume Command(soft_volume) failed\n", __func__); |
| 2322 | rc = -EINVAL; |
| 2323 | goto fail_cmd; |
| 2324 | } |
| 2325 | |
| 2326 | rc = wait_event_timeout(ac->cmd_wait, |
| 2327 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 2328 | if (!rc) { |
| 2329 | pr_err("%s: timeout in sending volume command(soft_volume)" |
| 2330 | "to apr\n", __func__); |
| 2331 | rc = -EINVAL; |
| 2332 | goto fail_cmd; |
| 2333 | } |
| 2334 | rc = 0; |
| 2335 | fail_cmd: |
| 2336 | kfree(vol_cmd); |
| 2337 | return rc; |
| 2338 | } |
| 2339 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2340 | int q6asm_equalizer(struct audio_client *ac, void *eq) |
| 2341 | { |
| 2342 | void *eq_cmd = NULL; |
| 2343 | void *payload = NULL; |
| 2344 | struct asm_pp_params_command *cmd = NULL; |
| 2345 | struct asm_equalizer_params *equalizer = NULL; |
| 2346 | struct msm_audio_eq_stream_config *eq_params = NULL; |
| 2347 | int i = 0; |
| 2348 | int sz = 0; |
| 2349 | int rc = 0; |
| 2350 | |
| 2351 | sz = sizeof(struct asm_pp_params_command) + |
| 2352 | + sizeof(struct asm_equalizer_params); |
| 2353 | eq_cmd = kzalloc(sz, GFP_KERNEL); |
| 2354 | if (eq_cmd == NULL) { |
| 2355 | pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session); |
| 2356 | rc = -EINVAL; |
| 2357 | goto fail_cmd; |
| 2358 | } |
| 2359 | eq_params = (struct msm_audio_eq_stream_config *) eq; |
| 2360 | cmd = (struct asm_pp_params_command *)eq_cmd; |
| 2361 | q6asm_add_hdr(ac, &cmd->hdr, sz, TRUE); |
| 2362 | cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS; |
| 2363 | cmd->payload = NULL; |
| 2364 | cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) + |
| 2365 | sizeof(struct asm_equalizer_params); |
| 2366 | cmd->params.module_id = EQUALIZER_MODULE_ID; |
| 2367 | cmd->params.param_id = EQUALIZER_PARAM_ID; |
| 2368 | cmd->params.param_size = sizeof(struct asm_equalizer_params); |
| 2369 | cmd->params.reserved = 0; |
| 2370 | payload = (u8 *)(eq_cmd + sizeof(struct asm_pp_params_command)); |
| 2371 | equalizer = (struct asm_equalizer_params *)payload; |
| 2372 | |
| 2373 | equalizer->enable = eq_params->enable; |
| 2374 | equalizer->num_bands = eq_params->num_bands; |
| 2375 | pr_debug("%s: enable:%d numbands:%d\n", __func__, eq_params->enable, |
| 2376 | eq_params->num_bands); |
| 2377 | for (i = 0; i < eq_params->num_bands; i++) { |
| 2378 | equalizer->eq_bands[i].band_idx = |
| 2379 | eq_params->eq_bands[i].band_idx; |
| 2380 | equalizer->eq_bands[i].filter_type = |
| 2381 | eq_params->eq_bands[i].filter_type; |
| 2382 | equalizer->eq_bands[i].center_freq_hz = |
| 2383 | eq_params->eq_bands[i].center_freq_hz; |
| 2384 | equalizer->eq_bands[i].filter_gain = |
| 2385 | eq_params->eq_bands[i].filter_gain; |
| 2386 | equalizer->eq_bands[i].q_factor = |
| 2387 | eq_params->eq_bands[i].q_factor; |
| 2388 | pr_debug("%s: filter_type:%u bandnum:%d\n", __func__, |
| 2389 | eq_params->eq_bands[i].filter_type, i); |
| 2390 | pr_debug("%s: center_freq_hz:%u bandnum:%d\n", __func__, |
| 2391 | eq_params->eq_bands[i].center_freq_hz, i); |
| 2392 | pr_debug("%s: filter_gain:%d bandnum:%d\n", __func__, |
| 2393 | eq_params->eq_bands[i].filter_gain, i); |
| 2394 | pr_debug("%s: q_factor:%d bandnum:%d\n", __func__, |
| 2395 | eq_params->eq_bands[i].q_factor, i); |
| 2396 | } |
| 2397 | rc = apr_send_pkt(ac->apr, (uint32_t *) eq_cmd); |
| 2398 | if (rc < 0) { |
| 2399 | pr_err("%s: Equalizer Command failed\n", __func__); |
| 2400 | rc = -EINVAL; |
| 2401 | goto fail_cmd; |
| 2402 | } |
| 2403 | |
| 2404 | rc = wait_event_timeout(ac->cmd_wait, |
| 2405 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 2406 | if (!rc) { |
| 2407 | pr_err("%s: timeout in sending equalizer command to apr\n", |
| 2408 | __func__); |
| 2409 | rc = -EINVAL; |
| 2410 | goto fail_cmd; |
| 2411 | } |
| 2412 | rc = 0; |
| 2413 | fail_cmd: |
| 2414 | kfree(eq_cmd); |
| 2415 | return rc; |
| 2416 | } |
| 2417 | |
| 2418 | int q6asm_read(struct audio_client *ac) |
| 2419 | { |
| 2420 | struct asm_stream_cmd_read read; |
| 2421 | struct audio_buffer *ab; |
| 2422 | int dsp_buf; |
| 2423 | struct audio_port_data *port; |
| 2424 | int rc; |
| 2425 | if (!ac || ac->apr == NULL) { |
| 2426 | pr_err("APR handle NULL\n"); |
| 2427 | return -EINVAL; |
| 2428 | } |
| 2429 | if (ac->io_mode == SYNC_IO_MODE) { |
| 2430 | port = &ac->port[OUT]; |
| 2431 | |
| 2432 | q6asm_add_hdr(ac, &read.hdr, sizeof(read), FALSE); |
| 2433 | |
| 2434 | mutex_lock(&port->lock); |
| 2435 | |
| 2436 | dsp_buf = port->dsp_buf; |
| 2437 | ab = &port->buf[dsp_buf]; |
| 2438 | |
| 2439 | pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n", |
| 2440 | __func__, |
| 2441 | ac->session, |
| 2442 | dsp_buf, |
| 2443 | (void *)port->buf[dsp_buf].data, |
| 2444 | port->cpu_buf, |
| 2445 | (void *)port->buf[port->cpu_buf].phys); |
| 2446 | |
| 2447 | read.hdr.opcode = ASM_DATA_CMD_READ; |
| 2448 | read.buf_add = ab->phys; |
| 2449 | read.buf_size = ab->size; |
| 2450 | read.uid = port->dsp_buf; |
| 2451 | read.hdr.token = port->dsp_buf; |
| 2452 | |
| 2453 | port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1); |
| 2454 | mutex_unlock(&port->lock); |
| 2455 | pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__, |
| 2456 | read.buf_add, |
| 2457 | read.hdr.token, |
| 2458 | read.uid); |
| 2459 | rc = apr_send_pkt(ac->apr, (uint32_t *) &read); |
| 2460 | if (rc < 0) { |
| 2461 | pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc); |
| 2462 | goto fail_cmd; |
| 2463 | } |
| 2464 | return 0; |
| 2465 | } |
| 2466 | fail_cmd: |
| 2467 | return -EINVAL; |
| 2468 | } |
| 2469 | |
| 2470 | int q6asm_read_nolock(struct audio_client *ac) |
| 2471 | { |
| 2472 | struct asm_stream_cmd_read read; |
| 2473 | struct audio_buffer *ab; |
| 2474 | int dsp_buf; |
| 2475 | struct audio_port_data *port; |
| 2476 | int rc; |
| 2477 | if (!ac || ac->apr == NULL) { |
| 2478 | pr_err("APR handle NULL\n"); |
| 2479 | return -EINVAL; |
| 2480 | } |
| 2481 | if (ac->io_mode == SYNC_IO_MODE) { |
| 2482 | port = &ac->port[OUT]; |
| 2483 | |
| 2484 | q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE); |
| 2485 | |
| 2486 | |
| 2487 | dsp_buf = port->dsp_buf; |
| 2488 | ab = &port->buf[dsp_buf]; |
| 2489 | |
| 2490 | pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n", |
| 2491 | __func__, |
| 2492 | ac->session, |
| 2493 | dsp_buf, |
| 2494 | (void *)port->buf[dsp_buf].data, |
| 2495 | port->cpu_buf, |
| 2496 | (void *)port->buf[port->cpu_buf].phys); |
| 2497 | |
| 2498 | read.hdr.opcode = ASM_DATA_CMD_READ; |
| 2499 | read.buf_add = ab->phys; |
| 2500 | read.buf_size = ab->size; |
| 2501 | read.uid = port->dsp_buf; |
| 2502 | read.hdr.token = port->dsp_buf; |
| 2503 | |
| 2504 | port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1); |
| 2505 | pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__, |
| 2506 | read.buf_add, |
| 2507 | read.hdr.token, |
| 2508 | read.uid); |
| 2509 | rc = apr_send_pkt(ac->apr, (uint32_t *) &read); |
| 2510 | if (rc < 0) { |
| 2511 | pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc); |
| 2512 | goto fail_cmd; |
| 2513 | } |
| 2514 | return 0; |
| 2515 | } |
| 2516 | fail_cmd: |
| 2517 | return -EINVAL; |
| 2518 | } |
| 2519 | |
| 2520 | |
| 2521 | static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr, |
| 2522 | uint32_t pkt_size, uint32_t cmd_flg) |
| 2523 | { |
| 2524 | pr_debug("session=%d pkt size=%d cmd_flg=%d\n", pkt_size, cmd_flg, |
| 2525 | ac->session); |
| 2526 | hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \ |
| 2527 | APR_HDR_LEN(sizeof(struct apr_hdr)),\ |
| 2528 | APR_PKT_VER); |
| 2529 | hdr->src_svc = ((struct apr_svc *)ac->apr)->id; |
| 2530 | hdr->src_domain = APR_DOMAIN_APPS; |
| 2531 | hdr->dest_svc = APR_SVC_ASM; |
| 2532 | hdr->dest_domain = APR_DOMAIN_ADSP; |
| 2533 | hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01; |
| 2534 | hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01; |
| 2535 | if (cmd_flg) { |
| 2536 | hdr->token = ac->session; |
| 2537 | atomic_set(&ac->cmd_state, 1); |
| 2538 | } |
| 2539 | hdr->pkt_size = pkt_size; |
| 2540 | return; |
| 2541 | } |
| 2542 | |
| 2543 | int q6asm_async_write(struct audio_client *ac, |
| 2544 | struct audio_aio_write_param *param) |
| 2545 | { |
| 2546 | int rc = 0; |
| 2547 | struct asm_stream_cmd_write write; |
| 2548 | |
| 2549 | if (!ac || ac->apr == NULL) { |
| 2550 | pr_err("%s: APR handle NULL\n", __func__); |
| 2551 | return -EINVAL; |
| 2552 | } |
| 2553 | |
| 2554 | q6asm_add_hdr_async(ac, &write.hdr, sizeof(write), FALSE); |
| 2555 | |
| 2556 | /* Pass physical address as token for AIO scheme */ |
| 2557 | write.hdr.token = param->uid; |
| 2558 | write.hdr.opcode = ASM_DATA_CMD_WRITE; |
| 2559 | write.buf_add = param->paddr; |
| 2560 | write.avail_bytes = param->len; |
| 2561 | write.uid = param->uid; |
| 2562 | write.msw_ts = param->msw_ts; |
| 2563 | write.lsw_ts = param->lsw_ts; |
| 2564 | /* Use 0xFF00 for disabling timestamps */ |
| 2565 | if (param->flags == 0xFF00) |
| 2566 | write.uflags = (0x00000000 | (param->flags & 0x800000FF)); |
| 2567 | else |
| 2568 | write.uflags = (0x80000000 | param->flags); |
| 2569 | |
| 2570 | pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session, |
| 2571 | write.buf_add, write.avail_bytes); |
| 2572 | |
| 2573 | rc = apr_send_pkt(ac->apr, (uint32_t *) &write); |
| 2574 | if (rc < 0) { |
| 2575 | pr_debug("[%s] write op[0x%x]rc[%d]\n", __func__, |
| 2576 | write.hdr.opcode, rc); |
| 2577 | goto fail_cmd; |
| 2578 | } |
| 2579 | return 0; |
| 2580 | fail_cmd: |
| 2581 | return -EINVAL; |
| 2582 | } |
| 2583 | |
| 2584 | int q6asm_async_read(struct audio_client *ac, |
| 2585 | struct audio_aio_read_param *param) |
| 2586 | { |
| 2587 | int rc = 0; |
| 2588 | struct asm_stream_cmd_read read; |
| 2589 | |
| 2590 | if (!ac || ac->apr == NULL) { |
| 2591 | pr_err("%s: APR handle NULL\n", __func__); |
| 2592 | return -EINVAL; |
| 2593 | } |
| 2594 | |
| 2595 | q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE); |
| 2596 | |
| 2597 | /* Pass physical address as token for AIO scheme */ |
| 2598 | read.hdr.token = param->paddr; |
| 2599 | read.hdr.opcode = ASM_DATA_CMD_READ; |
| 2600 | read.buf_add = param->paddr; |
| 2601 | read.buf_size = param->len; |
| 2602 | read.uid = param->uid; |
| 2603 | |
| 2604 | pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session, |
| 2605 | read.buf_add, read.buf_size); |
| 2606 | |
| 2607 | rc = apr_send_pkt(ac->apr, (uint32_t *) &read); |
| 2608 | if (rc < 0) { |
| 2609 | pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__, |
| 2610 | read.hdr.opcode, rc); |
| 2611 | goto fail_cmd; |
| 2612 | } |
| 2613 | return 0; |
| 2614 | fail_cmd: |
| 2615 | return -EINVAL; |
| 2616 | } |
| 2617 | |
| 2618 | int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts, |
| 2619 | uint32_t lsw_ts, uint32_t flags) |
| 2620 | { |
| 2621 | int rc = 0; |
| 2622 | struct asm_stream_cmd_write write; |
| 2623 | struct audio_port_data *port; |
| 2624 | struct audio_buffer *ab; |
| 2625 | int dsp_buf = 0; |
| 2626 | |
| 2627 | if (!ac || ac->apr == NULL) { |
| 2628 | pr_err("APR handle NULL\n"); |
| 2629 | return -EINVAL; |
| 2630 | } |
| 2631 | pr_debug("%s: session[%d] len=%d", __func__, ac->session, len); |
| 2632 | if (ac->io_mode == SYNC_IO_MODE) { |
| 2633 | port = &ac->port[IN]; |
| 2634 | |
| 2635 | q6asm_add_hdr(ac, &write.hdr, sizeof(write), |
| 2636 | FALSE); |
| 2637 | mutex_lock(&port->lock); |
| 2638 | |
| 2639 | dsp_buf = port->dsp_buf; |
| 2640 | ab = &port->buf[dsp_buf]; |
| 2641 | |
| 2642 | write.hdr.token = port->dsp_buf; |
| 2643 | write.hdr.opcode = ASM_DATA_CMD_WRITE; |
| 2644 | write.buf_add = ab->phys; |
| 2645 | write.avail_bytes = len; |
| 2646 | write.uid = port->dsp_buf; |
| 2647 | write.msw_ts = msw_ts; |
| 2648 | write.lsw_ts = lsw_ts; |
| 2649 | /* Use 0xFF00 for disabling timestamps */ |
| 2650 | if (flags == 0xFF00) |
| 2651 | write.uflags = (0x00000000 | (flags & 0x800000FF)); |
| 2652 | else |
| 2653 | write.uflags = (0x80000000 | flags); |
| 2654 | port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1); |
| 2655 | |
| 2656 | pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]" |
| 2657 | , __func__, |
| 2658 | ab->phys, |
| 2659 | write.buf_add, |
| 2660 | write.hdr.token, |
| 2661 | write.uid); |
| 2662 | mutex_unlock(&port->lock); |
Rajesha Kini | 3498c93 | 2011-07-19 19:58:27 +0530 | [diff] [blame] | 2663 | #ifdef CONFIG_DEBUG_FS |
| 2664 | if (out_enable_flag) { |
| 2665 | char zero_pattern[2] = {0x00, 0x00}; |
| 2666 | /* If First two byte is non zero and last two byte |
| 2667 | is zero then it is warm output pattern */ |
| 2668 | if ((strncmp(((char *)ab->data), zero_pattern, 2)) && |
| 2669 | (!strncmp(((char *)ab->data + 2), zero_pattern, 2))) { |
| 2670 | do_gettimeofday(&out_warm_tv); |
| 2671 | pr_debug("WARM:apr_send_pkt at \ |
| 2672 | %ld sec %ld microsec\n", out_warm_tv.tv_sec,\ |
| 2673 | out_warm_tv.tv_usec); |
| 2674 | pr_debug("Warm Pattern Matched"); |
| 2675 | } |
| 2676 | /* If First two byte is zero and last two byte is |
| 2677 | non zero then it is cont ouput pattern */ |
| 2678 | else if ((!strncmp(((char *)ab->data), zero_pattern, 2)) |
| 2679 | && (strncmp(((char *)ab->data + 2), zero_pattern, 2))) { |
| 2680 | do_gettimeofday(&out_cont_tv); |
| 2681 | pr_debug("CONT:apr_send_pkt at \ |
| 2682 | %ld sec %ld microsec\n", out_cont_tv.tv_sec,\ |
| 2683 | out_cont_tv.tv_usec); |
| 2684 | pr_debug("Cont Pattern Matched"); |
| 2685 | } |
| 2686 | } |
| 2687 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2688 | rc = apr_send_pkt(ac->apr, (uint32_t *) &write); |
| 2689 | if (rc < 0) { |
| 2690 | pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc); |
| 2691 | goto fail_cmd; |
| 2692 | } |
| 2693 | pr_debug("%s: WRITE SUCCESS\n", __func__); |
| 2694 | return 0; |
| 2695 | } |
| 2696 | fail_cmd: |
| 2697 | return -EINVAL; |
| 2698 | } |
| 2699 | |
| 2700 | int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts, |
| 2701 | uint32_t lsw_ts, uint32_t flags) |
| 2702 | { |
| 2703 | int rc = 0; |
| 2704 | struct asm_stream_cmd_write write; |
| 2705 | struct audio_port_data *port; |
| 2706 | struct audio_buffer *ab; |
| 2707 | int dsp_buf = 0; |
| 2708 | |
| 2709 | if (!ac || ac->apr == NULL) { |
| 2710 | pr_err("APR handle NULL\n"); |
| 2711 | return -EINVAL; |
| 2712 | } |
| 2713 | pr_debug("%s: session[%d] len=%d", __func__, ac->session, len); |
| 2714 | if (ac->io_mode == SYNC_IO_MODE) { |
| 2715 | port = &ac->port[IN]; |
| 2716 | |
| 2717 | q6asm_add_hdr_async(ac, &write.hdr, sizeof(write), |
| 2718 | FALSE); |
| 2719 | |
| 2720 | dsp_buf = port->dsp_buf; |
| 2721 | ab = &port->buf[dsp_buf]; |
| 2722 | |
| 2723 | write.hdr.token = port->dsp_buf; |
| 2724 | write.hdr.opcode = ASM_DATA_CMD_WRITE; |
| 2725 | write.buf_add = ab->phys; |
| 2726 | write.avail_bytes = len; |
| 2727 | write.uid = port->dsp_buf; |
| 2728 | write.msw_ts = msw_ts; |
| 2729 | write.lsw_ts = lsw_ts; |
| 2730 | /* Use 0xFF00 for disabling timestamps */ |
| 2731 | if (flags == 0xFF00) |
| 2732 | write.uflags = (0x00000000 | (flags & 0x800000FF)); |
| 2733 | else |
| 2734 | write.uflags = (0x80000000 | flags); |
| 2735 | port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1); |
| 2736 | |
| 2737 | pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]" |
| 2738 | , __func__, |
| 2739 | ab->phys, |
| 2740 | write.buf_add, |
| 2741 | write.hdr.token, |
| 2742 | write.uid); |
| 2743 | |
| 2744 | rc = apr_send_pkt(ac->apr, (uint32_t *) &write); |
| 2745 | if (rc < 0) { |
| 2746 | pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc); |
| 2747 | goto fail_cmd; |
| 2748 | } |
| 2749 | pr_debug("%s: WRITE SUCCESS\n", __func__); |
| 2750 | return 0; |
| 2751 | } |
| 2752 | fail_cmd: |
| 2753 | return -EINVAL; |
| 2754 | } |
| 2755 | |
| 2756 | uint64_t q6asm_get_session_time(struct audio_client *ac) |
| 2757 | { |
| 2758 | struct apr_hdr hdr; |
| 2759 | int rc; |
| 2760 | |
| 2761 | if (!ac || ac->apr == NULL) { |
| 2762 | pr_err("APR handle NULL\n"); |
| 2763 | return -EINVAL; |
| 2764 | } |
| 2765 | q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE); |
| 2766 | hdr.opcode = ASM_SESSION_CMD_GET_SESSION_TIME; |
| 2767 | atomic_set(&ac->time_flag, 1); |
| 2768 | |
| 2769 | pr_debug("%s: session[%d]opcode[0x%x]\n", __func__, |
| 2770 | ac->session, |
| 2771 | hdr.opcode); |
| 2772 | rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr); |
| 2773 | if (rc < 0) { |
| 2774 | pr_err("Commmand 0x%x failed\n", hdr.opcode); |
| 2775 | goto fail_cmd; |
| 2776 | } |
| 2777 | rc = wait_event_timeout(ac->time_wait, |
| 2778 | (atomic_read(&ac->time_flag) == 0), 5*HZ); |
| 2779 | if (!rc) { |
| 2780 | pr_err("%s: timeout in getting session time from DSP\n", |
| 2781 | __func__); |
| 2782 | goto fail_cmd; |
| 2783 | } |
| 2784 | return ac->time_stamp; |
| 2785 | |
| 2786 | fail_cmd: |
| 2787 | return -EINVAL; |
| 2788 | } |
| 2789 | |
| 2790 | int q6asm_cmd(struct audio_client *ac, int cmd) |
| 2791 | { |
| 2792 | struct apr_hdr hdr; |
| 2793 | int rc; |
| 2794 | atomic_t *state; |
| 2795 | int cnt = 0; |
| 2796 | |
| 2797 | if (!ac || ac->apr == NULL) { |
| 2798 | pr_err("APR handle NULL\n"); |
| 2799 | return -EINVAL; |
| 2800 | } |
| 2801 | q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE); |
| 2802 | switch (cmd) { |
| 2803 | case CMD_PAUSE: |
| 2804 | pr_debug("%s:CMD_PAUSE\n", __func__); |
| 2805 | hdr.opcode = ASM_SESSION_CMD_PAUSE; |
| 2806 | state = &ac->cmd_state; |
| 2807 | break; |
| 2808 | case CMD_FLUSH: |
| 2809 | pr_debug("%s:CMD_FLUSH\n", __func__); |
| 2810 | hdr.opcode = ASM_STREAM_CMD_FLUSH; |
| 2811 | state = &ac->cmd_state; |
| 2812 | break; |
| 2813 | case CMD_OUT_FLUSH: |
| 2814 | pr_debug("%s:CMD_OUT_FLUSH\n", __func__); |
| 2815 | hdr.opcode = ASM_STREAM_CMD_FLUSH_READBUFS; |
| 2816 | state = &ac->cmd_state; |
| 2817 | break; |
| 2818 | case CMD_EOS: |
| 2819 | pr_debug("%s:CMD_EOS\n", __func__); |
| 2820 | hdr.opcode = ASM_DATA_CMD_EOS; |
| 2821 | atomic_set(&ac->cmd_state, 0); |
| 2822 | state = &ac->cmd_state; |
| 2823 | break; |
| 2824 | case CMD_CLOSE: |
| 2825 | pr_debug("%s:CMD_CLOSE\n", __func__); |
| 2826 | hdr.opcode = ASM_STREAM_CMD_CLOSE; |
| 2827 | state = &ac->cmd_state; |
| 2828 | break; |
| 2829 | default: |
| 2830 | pr_err("Invalid format[%d]\n", cmd); |
| 2831 | goto fail_cmd; |
| 2832 | } |
| 2833 | pr_debug("%s:session[%d]opcode[0x%x] ", __func__, |
| 2834 | ac->session, |
| 2835 | hdr.opcode); |
| 2836 | rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr); |
| 2837 | if (rc < 0) { |
| 2838 | pr_err("Commmand 0x%x failed\n", hdr.opcode); |
| 2839 | goto fail_cmd; |
| 2840 | } |
| 2841 | rc = wait_event_timeout(ac->cmd_wait, (atomic_read(state) == 0), 5*HZ); |
| 2842 | if (!rc) { |
| 2843 | pr_err("timeout. waited for response opcode[0x%x]\n", |
| 2844 | hdr.opcode); |
| 2845 | goto fail_cmd; |
| 2846 | } |
| 2847 | if (cmd == CMD_FLUSH) |
| 2848 | q6asm_reset_buf_state(ac); |
| 2849 | if (cmd == CMD_CLOSE) { |
| 2850 | /* check if DSP return all buffers */ |
| 2851 | if (ac->port[IN].buf) { |
| 2852 | for (cnt = 0; cnt < ac->port[IN].max_buf_cnt; |
| 2853 | cnt++) { |
| 2854 | if (ac->port[IN].buf[cnt].used == IN) { |
| 2855 | pr_debug("Write Buf[%d] not returned\n", |
| 2856 | cnt); |
| 2857 | } |
| 2858 | } |
| 2859 | } |
| 2860 | if (ac->port[OUT].buf) { |
| 2861 | for (cnt = 0; cnt < ac->port[OUT].max_buf_cnt; cnt++) { |
| 2862 | if (ac->port[OUT].buf[cnt].used == OUT) { |
| 2863 | pr_debug("Read Buf[%d] not returned\n", |
| 2864 | cnt); |
| 2865 | } |
| 2866 | } |
| 2867 | } |
| 2868 | } |
| 2869 | return 0; |
| 2870 | fail_cmd: |
| 2871 | return -EINVAL; |
| 2872 | } |
| 2873 | |
| 2874 | int q6asm_cmd_nowait(struct audio_client *ac, int cmd) |
| 2875 | { |
| 2876 | struct apr_hdr hdr; |
| 2877 | int rc; |
| 2878 | |
| 2879 | if (!ac || ac->apr == NULL) { |
| 2880 | pr_err("%s:APR handle NULL\n", __func__); |
| 2881 | return -EINVAL; |
| 2882 | } |
| 2883 | q6asm_add_hdr_async(ac, &hdr, sizeof(hdr), TRUE); |
| 2884 | switch (cmd) { |
| 2885 | case CMD_PAUSE: |
| 2886 | pr_debug("%s:CMD_PAUSE\n", __func__); |
| 2887 | hdr.opcode = ASM_SESSION_CMD_PAUSE; |
| 2888 | break; |
| 2889 | case CMD_EOS: |
| 2890 | pr_debug("%s:CMD_EOS\n", __func__); |
| 2891 | hdr.opcode = ASM_DATA_CMD_EOS; |
| 2892 | break; |
| 2893 | default: |
| 2894 | pr_err("%s:Invalid format[%d]\n", __func__, cmd); |
| 2895 | goto fail_cmd; |
| 2896 | } |
| 2897 | pr_debug("%s:session[%d]opcode[0x%x] ", __func__, |
| 2898 | ac->session, |
| 2899 | hdr.opcode); |
| 2900 | rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr); |
| 2901 | if (rc < 0) { |
| 2902 | pr_err("%s:Commmand 0x%x failed\n", __func__, hdr.opcode); |
| 2903 | goto fail_cmd; |
| 2904 | } |
| 2905 | return 0; |
| 2906 | fail_cmd: |
| 2907 | return -EINVAL; |
| 2908 | } |
| 2909 | |
| 2910 | static void q6asm_reset_buf_state(struct audio_client *ac) |
| 2911 | { |
| 2912 | int cnt = 0; |
| 2913 | int loopcnt = 0; |
| 2914 | struct audio_port_data *port = NULL; |
| 2915 | |
| 2916 | if (ac->io_mode == SYNC_IO_MODE) { |
| 2917 | mutex_lock(&ac->cmd_lock); |
| 2918 | for (loopcnt = 0; loopcnt <= OUT; loopcnt++) { |
| 2919 | port = &ac->port[loopcnt]; |
| 2920 | cnt = port->max_buf_cnt - 1; |
| 2921 | port->dsp_buf = 0; |
| 2922 | port->cpu_buf = 0; |
| 2923 | while (cnt >= 0) { |
| 2924 | if (!port->buf) |
| 2925 | continue; |
| 2926 | port->buf[cnt].used = 1; |
| 2927 | cnt--; |
| 2928 | } |
| 2929 | } |
| 2930 | mutex_unlock(&ac->cmd_lock); |
| 2931 | } |
| 2932 | } |
| 2933 | |
| 2934 | int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable) |
| 2935 | { |
| 2936 | struct asm_stream_cmd_reg_tx_overflow_event tx_overflow; |
| 2937 | int rc; |
| 2938 | |
| 2939 | if (!ac || ac->apr == NULL) { |
| 2940 | pr_err("APR handle NULL\n"); |
| 2941 | return -EINVAL; |
| 2942 | } |
| 2943 | pr_debug("%s:session[%d]enable[%d]\n", __func__, |
| 2944 | ac->session, enable); |
| 2945 | q6asm_add_hdr(ac, &tx_overflow.hdr, sizeof(tx_overflow), TRUE); |
| 2946 | |
| 2947 | tx_overflow.hdr.opcode = \ |
| 2948 | ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS; |
| 2949 | /* tx overflow event: enable */ |
| 2950 | tx_overflow.enable = enable; |
| 2951 | |
| 2952 | rc = apr_send_pkt(ac->apr, (uint32_t *) &tx_overflow); |
| 2953 | if (rc < 0) { |
| 2954 | pr_err("tx overflow op[0x%x]rc[%d]\n", \ |
| 2955 | tx_overflow.hdr.opcode, rc); |
| 2956 | goto fail_cmd; |
| 2957 | } |
| 2958 | rc = wait_event_timeout(ac->cmd_wait, |
| 2959 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 2960 | if (!rc) { |
| 2961 | pr_err("timeout. waited for tx overflow\n"); |
| 2962 | goto fail_cmd; |
| 2963 | } |
| 2964 | return 0; |
| 2965 | fail_cmd: |
| 2966 | return -EINVAL; |
| 2967 | } |
| 2968 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2969 | int q6asm_get_apr_service_id(int session_id) |
| 2970 | { |
| 2971 | pr_debug("%s\n", __func__); |
| 2972 | |
| 2973 | if (session_id < 0) { |
| 2974 | pr_err("%s: invalid session_id = %d\n", __func__, session_id); |
| 2975 | return -EINVAL; |
| 2976 | } |
| 2977 | |
| 2978 | return ((struct apr_svc *)session[session_id]->apr)->id; |
| 2979 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2980 | |
| 2981 | |
| 2982 | static int __init q6asm_init(void) |
| 2983 | { |
| 2984 | pr_debug("%s\n", __func__); |
| 2985 | init_waitqueue_head(&this_mmap.cmd_wait); |
| 2986 | memset(session, 0, sizeof(session)); |
Rajesha Kini | 3498c93 | 2011-07-19 19:58:27 +0530 | [diff] [blame] | 2987 | #ifdef CONFIG_DEBUG_FS |
| 2988 | out_buffer = kmalloc(OUT_BUFFER_SIZE, GFP_KERNEL); |
| 2989 | out_dentry = debugfs_create_file("audio_out_latency_measurement_node",\ |
| 2990 | S_IFREG | S_IRUGO | S_IWUGO,\ |
| 2991 | NULL, NULL, &audio_output_latency_debug_fops); |
| 2992 | if (IS_ERR(out_dentry)) |
| 2993 | pr_err("debugfs_create_file failed\n"); |
| 2994 | in_buffer = kmalloc(IN_BUFFER_SIZE, GFP_KERNEL); |
| 2995 | in_dentry = debugfs_create_file("audio_in_latency_measurement_node",\ |
| 2996 | S_IFREG | S_IRUGO | S_IWUGO,\ |
| 2997 | NULL, NULL, &audio_input_latency_debug_fops); |
| 2998 | if (IS_ERR(in_dentry)) |
| 2999 | pr_err("debugfs_create_file failed\n"); |
| 3000 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3001 | return 0; |
| 3002 | } |
| 3003 | |
| 3004 | device_initcall(q6asm_init); |