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