| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* |
| Patrick Lai | 3aabeae | 2013-01-06 00:52:34 -0800 | [diff] [blame] | 2 | * Copyright (c) 2010-2013, The Linux Foundation. All rights reserved. |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3 | * Author: Brian Swetland <swetland@google.com> |
| 4 | * |
| 5 | * This software is licensed under the terms of the GNU General Public |
| 6 | * License version 2, as published by the Free Software Foundation, and |
| 7 | * may be copied, distributed, and modified under those terms. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | */ |
| 15 | #include <linux/fs.h> |
| 16 | #include <linux/mutex.h> |
| 17 | #include <linux/wait.h> |
| 18 | #include <linux/miscdevice.h> |
| 19 | #include <linux/uaccess.h> |
| 20 | #include <linux/sched.h> |
| 21 | #include <linux/dma-mapping.h> |
| 22 | #include <linux/miscdevice.h> |
| 23 | #include <linux/delay.h> |
| 24 | #include <linux/spinlock.h> |
| 25 | #include <linux/slab.h> |
| 26 | #include <linux/msm_audio.h> |
| 27 | #include <linux/android_pmem.h> |
| 28 | #include <linux/memory_alloc.h> |
| Ben Romberger | fce8f51 | 2011-07-18 16:46:09 -0700 | [diff] [blame] | 29 | #include <linux/debugfs.h> |
| 30 | #include <linux/time.h> |
| 31 | #include <linux/atomic.h> |
| 32 | |
| 33 | #include <asm/ioctls.h> |
| 34 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 35 | #include <mach/memory.h> |
| 36 | #include <mach/debug_mm.h> |
| 37 | #include <mach/peripheral-loader.h> |
| 38 | #include <mach/qdsp6v2/audio_acdb.h> |
| 39 | #include <mach/qdsp6v2/rtac.h> |
| Ben Romberger | fce8f51 | 2011-07-18 16:46:09 -0700 | [diff] [blame] | 40 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 41 | #include <sound/apr_audio.h> |
| 42 | #include <sound/q6asm.h> |
| Ben Romberger | fce8f51 | 2011-07-18 16:46:09 -0700 | [diff] [blame] | 43 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 44 | |
| 45 | #define TRUE 0x01 |
| 46 | #define FALSE 0x00 |
| 47 | #define READDONE_IDX_STATUS 0 |
| 48 | #define READDONE_IDX_BUFFER 1 |
| 49 | #define READDONE_IDX_SIZE 2 |
| 50 | #define READDONE_IDX_OFFSET 3 |
| 51 | #define READDONE_IDX_MSW_TS 4 |
| 52 | #define READDONE_IDX_LSW_TS 5 |
| 53 | #define READDONE_IDX_FLAGS 6 |
| 54 | #define READDONE_IDX_NUMFRAMES 7 |
| 55 | #define READDONE_IDX_ID 8 |
| Rajesha Kini | 3498c93 | 2011-07-19 19:58:27 +0530 | [diff] [blame] | 56 | #ifdef CONFIG_DEBUG_FS |
| 57 | #define OUT_BUFFER_SIZE 56 |
| 58 | #define IN_BUFFER_SIZE 24 |
| 59 | #endif |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 60 | static DEFINE_MUTEX(session_lock); |
| 61 | |
| 62 | /* session id: 0 reserved */ |
| 63 | static struct audio_client *session[SESSION_MAX+1]; |
| 64 | static int32_t q6asm_mmapcallback(struct apr_client_data *data, void *priv); |
| 65 | static int32_t q6asm_callback(struct apr_client_data *data, void *priv); |
| 66 | static void q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr, |
| 67 | uint32_t pkt_size, uint32_t cmd_flg); |
| 68 | static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr, |
| 69 | uint32_t pkt_size, uint32_t cmd_flg); |
| 70 | static int q6asm_memory_map_regions(struct audio_client *ac, int dir, |
| 71 | uint32_t bufsz, uint32_t bufcnt); |
| 72 | static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir, |
| 73 | uint32_t bufsz, uint32_t bufcnt); |
| 74 | |
| 75 | static void q6asm_reset_buf_state(struct audio_client *ac); |
| 76 | |
| Rajesha Kini | 3498c93 | 2011-07-19 19:58:27 +0530 | [diff] [blame] | 77 | #ifdef CONFIG_DEBUG_FS |
| 78 | static struct timeval out_cold_tv; |
| 79 | static struct timeval out_warm_tv; |
| 80 | static struct timeval out_cont_tv; |
| 81 | static struct timeval in_cont_tv; |
| 82 | static long out_enable_flag; |
| 83 | static long in_enable_flag; |
| 84 | static struct dentry *out_dentry; |
| 85 | static struct dentry *in_dentry; |
| 86 | static int in_cont_index; |
| 87 | /*This var is used to keep track of first write done for cold output latency */ |
| 88 | static int out_cold_index; |
| 89 | static char *out_buffer; |
| 90 | static char *in_buffer; |
| 91 | static int audio_output_latency_dbgfs_open(struct inode *inode, |
| 92 | struct file *file) |
| 93 | { |
| 94 | file->private_data = inode->i_private; |
| 95 | return 0; |
| 96 | } |
| 97 | static ssize_t audio_output_latency_dbgfs_read(struct file *file, |
| 98 | char __user *buf, size_t count, loff_t *ppos) |
| 99 | { |
| 100 | snprintf(out_buffer, OUT_BUFFER_SIZE, "%ld,%ld,%ld,%ld,%ld,%ld,",\ |
| 101 | out_cold_tv.tv_sec, out_cold_tv.tv_usec, out_warm_tv.tv_sec,\ |
| 102 | out_warm_tv.tv_usec, out_cont_tv.tv_sec, out_cont_tv.tv_usec); |
| 103 | return simple_read_from_buffer(buf, OUT_BUFFER_SIZE, ppos, |
| 104 | out_buffer, OUT_BUFFER_SIZE); |
| 105 | } |
| 106 | static ssize_t audio_output_latency_dbgfs_write(struct file *file, |
| 107 | const char __user *buf, size_t count, loff_t *ppos) |
| 108 | { |
| 109 | char *temp; |
| 110 | |
| 111 | if (count > 2*sizeof(char)) |
| 112 | return -EINVAL; |
| 113 | else |
| 114 | temp = kmalloc(2*sizeof(char), GFP_KERNEL); |
| 115 | |
| 116 | out_cold_index = 0; |
| 117 | |
| 118 | if (temp) { |
| 119 | if (copy_from_user(temp, buf, 2*sizeof(char))) { |
| 120 | kfree(temp); |
| 121 | return -EFAULT; |
| 122 | } |
| 123 | if (!strict_strtol(temp, 10, &out_enable_flag)) { |
| 124 | kfree(temp); |
| 125 | return count; |
| 126 | } |
| 127 | kfree(temp); |
| 128 | } |
| 129 | return -EINVAL; |
| 130 | } |
| 131 | static const struct file_operations audio_output_latency_debug_fops = { |
| 132 | .open = audio_output_latency_dbgfs_open, |
| 133 | .read = audio_output_latency_dbgfs_read, |
| 134 | .write = audio_output_latency_dbgfs_write |
| 135 | }; |
| 136 | |
| 137 | static int audio_input_latency_dbgfs_open(struct inode *inode, |
| 138 | struct file *file) |
| 139 | { |
| 140 | file->private_data = inode->i_private; |
| 141 | return 0; |
| 142 | } |
| 143 | static ssize_t audio_input_latency_dbgfs_read(struct file *file, |
| 144 | char __user *buf, size_t count, loff_t *ppos) |
| 145 | { |
| 146 | snprintf(in_buffer, IN_BUFFER_SIZE, "%ld,%ld,",\ |
| 147 | in_cont_tv.tv_sec, in_cont_tv.tv_usec); |
| 148 | return simple_read_from_buffer(buf, IN_BUFFER_SIZE, ppos, |
| 149 | in_buffer, IN_BUFFER_SIZE); |
| 150 | } |
| 151 | static ssize_t audio_input_latency_dbgfs_write(struct file *file, |
| 152 | const char __user *buf, size_t count, loff_t *ppos) |
| 153 | { |
| 154 | char *temp; |
| 155 | |
| 156 | if (count > 2*sizeof(char)) |
| 157 | return -EINVAL; |
| 158 | else |
| 159 | temp = kmalloc(2*sizeof(char), GFP_KERNEL); |
| 160 | if (temp) { |
| 161 | if (copy_from_user(temp, buf, 2*sizeof(char))) { |
| 162 | kfree(temp); |
| 163 | return -EFAULT; |
| 164 | } |
| 165 | if (!strict_strtol(temp, 10, &in_enable_flag)) { |
| 166 | kfree(temp); |
| 167 | return count; |
| 168 | } |
| 169 | kfree(temp); |
| 170 | } |
| 171 | return -EINVAL; |
| 172 | } |
| 173 | static const struct file_operations audio_input_latency_debug_fops = { |
| 174 | .open = audio_input_latency_dbgfs_open, |
| 175 | .read = audio_input_latency_dbgfs_read, |
| 176 | .write = audio_input_latency_dbgfs_write |
| 177 | }; |
| 178 | #endif |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 179 | struct asm_mmap { |
| 180 | atomic_t ref_cnt; |
| 181 | atomic_t cmd_state; |
| 182 | wait_queue_head_t cmd_wait; |
| 183 | void *apr; |
| 184 | }; |
| 185 | |
| 186 | static struct asm_mmap this_mmap; |
| 187 | |
| 188 | static int q6asm_session_alloc(struct audio_client *ac) |
| 189 | { |
| 190 | int n; |
| 191 | mutex_lock(&session_lock); |
| 192 | for (n = 1; n <= SESSION_MAX; n++) { |
| 193 | if (!session[n]) { |
| 194 | session[n] = ac; |
| 195 | mutex_unlock(&session_lock); |
| 196 | return n; |
| 197 | } |
| 198 | } |
| 199 | mutex_unlock(&session_lock); |
| 200 | return -ENOMEM; |
| 201 | } |
| 202 | |
| 203 | static void q6asm_session_free(struct audio_client *ac) |
| 204 | { |
| 205 | pr_debug("%s: sessionid[%d]\n", __func__, ac->session); |
| Ben Romberger | 93d4d2d | 2011-10-19 23:04:02 -0700 | [diff] [blame] | 206 | rtac_remove_popp_from_adm_devices(ac->session); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 207 | mutex_lock(&session_lock); |
| 208 | session[ac->session] = 0; |
| 209 | mutex_unlock(&session_lock); |
| 210 | ac->session = 0; |
| Jayasena Sangaraboina | 99bf09c | 2012-07-17 12:03:08 -0700 | [diff] [blame] | 211 | ac->perf_mode = false; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 212 | return; |
| 213 | } |
| 214 | |
| 215 | int q6asm_audio_client_buf_free(unsigned int dir, |
| 216 | struct audio_client *ac) |
| 217 | { |
| 218 | struct audio_port_data *port; |
| 219 | int cnt = 0; |
| 220 | int rc = 0; |
| 221 | pr_debug("%s: Session id %d\n", __func__, ac->session); |
| 222 | mutex_lock(&ac->cmd_lock); |
| Patrick Lai | 55f54c5 | 2012-11-17 00:29:07 -0800 | [diff] [blame] | 223 | if (ac->io_mode & SYNC_IO_MODE) { |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 224 | port = &ac->port[dir]; |
| 225 | if (!port->buf) { |
| 226 | mutex_unlock(&ac->cmd_lock); |
| 227 | return 0; |
| 228 | } |
| 229 | cnt = port->max_buf_cnt - 1; |
| 230 | |
| 231 | if (cnt >= 0) { |
| 232 | rc = q6asm_memory_unmap_regions(ac, dir, |
| 233 | port->buf[0].size, |
| 234 | port->max_buf_cnt); |
| 235 | if (rc < 0) |
| 236 | pr_err("%s CMD Memory_unmap_regions failed\n", |
| 237 | __func__); |
| 238 | } |
| 239 | |
| 240 | while (cnt >= 0) { |
| 241 | if (port->buf[cnt].data) { |
| Swaminathan Sathappan | bdc5508 | 2012-02-16 22:47:40 -0800 | [diff] [blame] | 242 | #ifdef CONFIG_MSM_MULTIMEDIA_USE_ION |
| 243 | ion_unmap_kernel(port->buf[cnt].client, |
| 244 | port->buf[cnt].handle); |
| 245 | ion_free(port->buf[cnt].client, |
| 246 | port->buf[cnt].handle); |
| 247 | ion_client_destroy(port->buf[cnt].client); |
| 248 | #else |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 249 | pr_debug("%s:data[%p]phys[%p][%p] cnt[%d] mem_buffer[%p]\n", |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 250 | __func__, (void *)port->buf[cnt].data, |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 251 | (void *)port->buf[cnt].phys, |
| 252 | (void *)&port->buf[cnt].phys, cnt, |
| 253 | (void *)port->buf[cnt].mem_buffer); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 254 | if (IS_ERR((void *)port->buf[cnt].mem_buffer)) |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 255 | pr_err("%s:mem buffer invalid, error = %ld\n", |
| 256 | __func__, |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 257 | PTR_ERR((void *)port->buf[cnt].mem_buffer)); |
| 258 | else { |
| Laura Abbott | ea3e7b6 | 2012-04-30 15:59:21 -0700 | [diff] [blame] | 259 | if (iounmap( |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 260 | port->buf[cnt].mem_buffer) < 0) |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 261 | pr_err("%s: unmap buffer failed\n", |
| 262 | __func__); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 263 | } |
| 264 | free_contiguous_memory_by_paddr( |
| 265 | port->buf[cnt].phys); |
| 266 | |
| Swaminathan Sathappan | bdc5508 | 2012-02-16 22:47:40 -0800 | [diff] [blame] | 267 | #endif |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 268 | port->buf[cnt].data = NULL; |
| 269 | port->buf[cnt].phys = 0; |
| 270 | --(port->max_buf_cnt); |
| 271 | } |
| 272 | --cnt; |
| 273 | } |
| 274 | kfree(port->buf); |
| 275 | port->buf = NULL; |
| 276 | } |
| 277 | mutex_unlock(&ac->cmd_lock); |
| 278 | return 0; |
| 279 | } |
| 280 | |
| 281 | int q6asm_audio_client_buf_free_contiguous(unsigned int dir, |
| 282 | struct audio_client *ac) |
| 283 | { |
| 284 | struct audio_port_data *port; |
| 285 | int cnt = 0; |
| 286 | int rc = 0; |
| 287 | pr_debug("%s: Session id %d\n", __func__, ac->session); |
| 288 | mutex_lock(&ac->cmd_lock); |
| 289 | port = &ac->port[dir]; |
| 290 | if (!port->buf) { |
| 291 | mutex_unlock(&ac->cmd_lock); |
| 292 | return 0; |
| 293 | } |
| 294 | cnt = port->max_buf_cnt - 1; |
| 295 | |
| 296 | if (cnt >= 0) { |
| Deepa Madiregama | 7d52a40 | 2011-07-13 20:28:36 +0530 | [diff] [blame] | 297 | rc = q6asm_memory_unmap(ac, port->buf[0].phys, dir); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 298 | if (rc < 0) |
| 299 | pr_err("%s CMD Memory_unmap_regions failed\n", |
| 300 | __func__); |
| 301 | } |
| 302 | |
| 303 | if (port->buf[0].data) { |
| Swaminathan Sathappan | bdc5508 | 2012-02-16 22:47:40 -0800 | [diff] [blame] | 304 | #ifdef CONFIG_MSM_MULTIMEDIA_USE_ION |
| 305 | ion_unmap_kernel(port->buf[0].client, port->buf[0].handle); |
| 306 | ion_free(port->buf[0].client, port->buf[0].handle); |
| 307 | ion_client_destroy(port->buf[0].client); |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 308 | pr_debug("%s:data[%p]phys[%p][%p], client[%p] handle[%p]\n", |
| Swaminathan Sathappan | bdc5508 | 2012-02-16 22:47:40 -0800 | [diff] [blame] | 309 | __func__, |
| 310 | (void *)port->buf[0].data, |
| 311 | (void *)port->buf[0].phys, |
| 312 | (void *)&port->buf[0].phys, |
| 313 | (void *)port->buf[0].client, |
| 314 | (void *)port->buf[0].handle); |
| 315 | #else |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 316 | pr_debug("%s:data[%p]phys[%p][%p] mem_buffer[%p]\n", |
| Harmandeep Singh | 2f7c23c | 2011-11-04 11:57:35 -0700 | [diff] [blame] | 317 | __func__, |
| 318 | (void *)port->buf[0].data, |
| 319 | (void *)port->buf[0].phys, |
| 320 | (void *)&port->buf[0].phys, |
| 321 | (void *)port->buf[0].mem_buffer); |
| 322 | if (IS_ERR((void *)port->buf[0].mem_buffer)) |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 323 | pr_err("%s:mem buffer invalid, error = %ld\n", |
| 324 | __func__, |
| Harmandeep Singh | 2f7c23c | 2011-11-04 11:57:35 -0700 | [diff] [blame] | 325 | PTR_ERR((void *)port->buf[0].mem_buffer)); |
| 326 | else { |
| Laura Abbott | ea3e7b6 | 2012-04-30 15:59:21 -0700 | [diff] [blame] | 327 | if (iounmap( |
| Harmandeep Singh | 2f7c23c | 2011-11-04 11:57:35 -0700 | [diff] [blame] | 328 | port->buf[0].mem_buffer) < 0) |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 329 | pr_err("%s: unmap buffer failed\n", __func__); |
| Harmandeep Singh | 2f7c23c | 2011-11-04 11:57:35 -0700 | [diff] [blame] | 330 | } |
| 331 | free_contiguous_memory_by_paddr(port->buf[0].phys); |
| Swaminathan Sathappan | bdc5508 | 2012-02-16 22:47:40 -0800 | [diff] [blame] | 332 | #endif |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 333 | } |
| Harmandeep Singh | 2f7c23c | 2011-11-04 11:57:35 -0700 | [diff] [blame] | 334 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 335 | while (cnt >= 0) { |
| 336 | port->buf[cnt].data = NULL; |
| 337 | port->buf[cnt].phys = 0; |
| 338 | cnt--; |
| 339 | } |
| 340 | port->max_buf_cnt = 0; |
| 341 | kfree(port->buf); |
| 342 | port->buf = NULL; |
| 343 | mutex_unlock(&ac->cmd_lock); |
| 344 | return 0; |
| 345 | } |
| 346 | |
| 347 | void q6asm_audio_client_free(struct audio_client *ac) |
| 348 | { |
| 349 | int loopcnt; |
| 350 | struct audio_port_data *port; |
| 351 | if (!ac || !ac->session) |
| 352 | return; |
| 353 | pr_debug("%s: Session id %d\n", __func__, ac->session); |
| Patrick Lai | 55f54c5 | 2012-11-17 00:29:07 -0800 | [diff] [blame] | 354 | if (ac->io_mode & SYNC_IO_MODE) { |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 355 | for (loopcnt = 0; loopcnt <= OUT; loopcnt++) { |
| 356 | port = &ac->port[loopcnt]; |
| 357 | if (!port->buf) |
| 358 | continue; |
| 359 | pr_debug("%s:loopcnt = %d\n", __func__, loopcnt); |
| 360 | q6asm_audio_client_buf_free(loopcnt, ac); |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | apr_deregister(ac->apr); |
| 365 | q6asm_session_free(ac); |
| 366 | |
| 367 | pr_debug("%s: APR De-Register\n", __func__); |
| 368 | if (atomic_read(&this_mmap.ref_cnt) <= 0) { |
| 369 | pr_err("%s: APR Common Port Already Closed\n", __func__); |
| 370 | goto done; |
| 371 | } |
| 372 | |
| 373 | atomic_dec(&this_mmap.ref_cnt); |
| 374 | if (atomic_read(&this_mmap.ref_cnt) == 0) { |
| 375 | apr_deregister(this_mmap.apr); |
| 376 | pr_debug("%s:APR De-Register common port\n", __func__); |
| 377 | } |
| 378 | done: |
| 379 | kfree(ac); |
| 380 | return; |
| 381 | } |
| 382 | |
| 383 | int q6asm_set_io_mode(struct audio_client *ac, uint32_t mode) |
| 384 | { |
| 385 | if (ac == NULL) { |
| 386 | pr_err("%s APR handle NULL\n", __func__); |
| 387 | return -EINVAL; |
| 388 | } |
| Patrick Lai | 55f54c5 | 2012-11-17 00:29:07 -0800 | [diff] [blame] | 389 | |
| 390 | if (mode == ASYNC_IO_MODE) { |
| 391 | ac->io_mode &= ~SYNC_IO_MODE; |
| 392 | ac->io_mode |= ASYNC_IO_MODE; |
| 393 | } else if (mode == SYNC_IO_MODE) { |
| 394 | ac->io_mode &= ~ASYNC_IO_MODE; |
| 395 | ac->io_mode |= SYNC_IO_MODE; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 396 | } else { |
| 397 | pr_err("%s:Not an valid IO Mode:%d\n", __func__, ac->io_mode); |
| 398 | return -EINVAL; |
| 399 | } |
| Patrick Lai | 55f54c5 | 2012-11-17 00:29:07 -0800 | [diff] [blame] | 400 | |
| 401 | pr_debug("%s:Set Mode to %d\n", __func__, ac->io_mode); |
| 402 | return 0; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | struct audio_client *q6asm_audio_client_alloc(app_cb cb, void *priv) |
| 406 | { |
| 407 | struct audio_client *ac; |
| 408 | int n; |
| 409 | int lcnt = 0; |
| 410 | |
| 411 | ac = kzalloc(sizeof(struct audio_client), GFP_KERNEL); |
| 412 | if (!ac) |
| 413 | return NULL; |
| 414 | n = q6asm_session_alloc(ac); |
| 415 | if (n <= 0) |
| 416 | goto fail_session; |
| 417 | ac->session = n; |
| 418 | ac->cb = cb; |
| 419 | ac->priv = priv; |
| 420 | ac->io_mode = SYNC_IO_MODE; |
| Jayasena Sangaraboina | 99bf09c | 2012-07-17 12:03:08 -0700 | [diff] [blame] | 421 | ac->perf_mode = false; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 422 | ac->apr = apr_register("ADSP", "ASM", \ |
| 423 | (apr_fn)q6asm_callback,\ |
| 424 | ((ac->session) << 8 | 0x0001),\ |
| 425 | ac); |
| 426 | |
| 427 | if (ac->apr == NULL) { |
| 428 | pr_err("%s Registration with APR failed\n", __func__); |
| 429 | goto fail; |
| 430 | } |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 431 | rtac_set_asm_handle(n, ac->apr); |
| Ben Romberger | fce8f51 | 2011-07-18 16:46:09 -0700 | [diff] [blame] | 432 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 433 | pr_debug("%s Registering the common port with APR\n", __func__); |
| 434 | if (atomic_read(&this_mmap.ref_cnt) == 0) { |
| 435 | this_mmap.apr = apr_register("ADSP", "ASM", \ |
| 436 | (apr_fn)q6asm_mmapcallback,\ |
| 437 | 0x0FFFFFFFF, &this_mmap); |
| 438 | if (this_mmap.apr == NULL) { |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 439 | pr_debug("%s Unable to register APR ASM common port\n", |
| 440 | __func__); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 441 | goto fail; |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | atomic_inc(&this_mmap.ref_cnt); |
| 446 | init_waitqueue_head(&ac->cmd_wait); |
| 447 | init_waitqueue_head(&ac->time_wait); |
| 448 | atomic_set(&ac->time_flag, 1); |
| 449 | mutex_init(&ac->cmd_lock); |
| 450 | for (lcnt = 0; lcnt <= OUT; lcnt++) { |
| 451 | mutex_init(&ac->port[lcnt].lock); |
| 452 | spin_lock_init(&ac->port[lcnt].dsp_lock); |
| 453 | } |
| 454 | atomic_set(&ac->cmd_state, 0); |
| Srikanth Uyyala | a50b51d | 2012-07-02 16:02:24 +0530 | [diff] [blame] | 455 | atomic_set(&ac->cmd_response, 0); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 456 | |
| 457 | pr_debug("%s: session[%d]\n", __func__, ac->session); |
| 458 | |
| 459 | return ac; |
| 460 | fail: |
| 461 | q6asm_audio_client_free(ac); |
| 462 | return NULL; |
| 463 | fail_session: |
| 464 | kfree(ac); |
| 465 | return NULL; |
| 466 | } |
| 467 | |
| Ben Romberger | 61754dc | 2011-10-31 18:25:41 -0700 | [diff] [blame] | 468 | struct audio_client *q6asm_get_audio_client(int session_id) |
| 469 | { |
| 470 | if ((session_id <= 0) || (session_id > SESSION_MAX)) { |
| 471 | pr_err("%s: invalid session: %d\n", __func__, session_id); |
| 472 | goto err; |
| 473 | } |
| 474 | |
| 475 | if (!session[session_id]) { |
| 476 | pr_err("%s: session not active: %d\n", __func__, session_id); |
| 477 | goto err; |
| 478 | } |
| 479 | |
| 480 | return session[session_id]; |
| 481 | err: |
| 482 | return NULL; |
| 483 | } |
| 484 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 485 | int q6asm_audio_client_buf_alloc(unsigned int dir, |
| 486 | struct audio_client *ac, |
| 487 | unsigned int bufsz, |
| 488 | unsigned int bufcnt) |
| 489 | { |
| 490 | int cnt = 0; |
| 491 | int rc = 0; |
| 492 | struct audio_buffer *buf; |
| Swaminathan Sathappan | bdc5508 | 2012-02-16 22:47:40 -0800 | [diff] [blame] | 493 | #ifdef CONFIG_MSM_MULTIMEDIA_USE_ION |
| 494 | int len; |
| Deepa Madiregama | 636f80e | 2013-01-17 14:01:25 +0530 | [diff] [blame] | 495 | unsigned int bufsz_4k_aligned; |
| Swaminathan Sathappan | bdc5508 | 2012-02-16 22:47:40 -0800 | [diff] [blame] | 496 | #endif |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 497 | |
| 498 | if (!(ac) || ((dir != IN) && (dir != OUT))) |
| 499 | return -EINVAL; |
| 500 | |
| 501 | pr_debug("%s: session[%d]bufsz[%d]bufcnt[%d]\n", __func__, ac->session, |
| 502 | bufsz, bufcnt); |
| 503 | |
| 504 | if (ac->session <= 0 || ac->session > 8) |
| 505 | goto fail; |
| 506 | |
| Patrick Lai | 55f54c5 | 2012-11-17 00:29:07 -0800 | [diff] [blame] | 507 | if (ac->io_mode & SYNC_IO_MODE) { |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 508 | if (ac->port[dir].buf) { |
| 509 | pr_debug("%s: buffer already allocated\n", __func__); |
| 510 | return 0; |
| 511 | } |
| 512 | mutex_lock(&ac->cmd_lock); |
| 513 | buf = kzalloc(((sizeof(struct audio_buffer))*bufcnt), |
| 514 | GFP_KERNEL); |
| 515 | |
| 516 | if (!buf) { |
| 517 | mutex_unlock(&ac->cmd_lock); |
| 518 | goto fail; |
| 519 | } |
| 520 | |
| 521 | ac->port[dir].buf = buf; |
| 522 | |
| 523 | while (cnt < bufcnt) { |
| 524 | if (bufsz > 0) { |
| 525 | if (!buf[cnt].data) { |
| Swaminathan Sathappan | bdc5508 | 2012-02-16 22:47:40 -0800 | [diff] [blame] | 526 | #ifdef CONFIG_MSM_MULTIMEDIA_USE_ION |
| 527 | buf[cnt].client = msm_ion_client_create |
| 528 | (UINT_MAX, "audio_client"); |
| 529 | if (IS_ERR_OR_NULL((void *) |
| 530 | buf[cnt].client)) { |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 531 | pr_err("%s: ION create client for AUDIO failed\n", |
| Swaminathan Sathappan | bdc5508 | 2012-02-16 22:47:40 -0800 | [diff] [blame] | 532 | __func__); |
| Swaminathan Sathappan | 349fed6 | 2012-05-22 15:04:43 -0700 | [diff] [blame] | 533 | mutex_unlock(&ac->cmd_lock); |
| Swaminathan Sathappan | bdc5508 | 2012-02-16 22:47:40 -0800 | [diff] [blame] | 534 | goto fail; |
| 535 | } |
| Deepa Madiregama | 636f80e | 2013-01-17 14:01:25 +0530 | [diff] [blame] | 536 | bufsz_4k_aligned = (bufsz + 4095) & |
| 537 | (~4095); |
| 538 | pr_debug("%s: bufsz_4k_aligned %d"\ |
| 539 | "bufsz = %d\n", |
| 540 | __func__, bufsz_4k_aligned, |
| 541 | bufsz); |
| Swaminathan Sathappan | bdc5508 | 2012-02-16 22:47:40 -0800 | [diff] [blame] | 542 | buf[cnt].handle = ion_alloc |
| Deepa Madiregama | 636f80e | 2013-01-17 14:01:25 +0530 | [diff] [blame] | 543 | (buf[cnt].client, |
| 544 | bufsz_4k_aligned, SZ_4K, |
| Hanumant Singh | 2ac41c9 | 2012-08-29 18:39:44 -0700 | [diff] [blame] | 545 | (0x1 << ION_AUDIO_HEAP_ID), 0); |
| Swaminathan Sathappan | bdc5508 | 2012-02-16 22:47:40 -0800 | [diff] [blame] | 546 | if (IS_ERR_OR_NULL((void *) |
| 547 | buf[cnt].handle)) { |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 548 | pr_err("%s: ION memory allocation for AUDIO failed\n", |
| Swaminathan Sathappan | bdc5508 | 2012-02-16 22:47:40 -0800 | [diff] [blame] | 549 | __func__); |
| Swaminathan Sathappan | 349fed6 | 2012-05-22 15:04:43 -0700 | [diff] [blame] | 550 | mutex_unlock(&ac->cmd_lock); |
| Swaminathan Sathappan | bdc5508 | 2012-02-16 22:47:40 -0800 | [diff] [blame] | 551 | goto fail; |
| 552 | } |
| 553 | |
| 554 | rc = ion_phys(buf[cnt].client, |
| 555 | buf[cnt].handle, |
| 556 | (ion_phys_addr_t *) |
| 557 | &buf[cnt].phys, |
| 558 | (size_t *)&len); |
| 559 | if (rc) { |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 560 | pr_err("%s: ION Get Physical for AUDIO failed, rc = %d\n", |
| Swaminathan Sathappan | bdc5508 | 2012-02-16 22:47:40 -0800 | [diff] [blame] | 561 | __func__, rc); |
| Swaminathan Sathappan | 349fed6 | 2012-05-22 15:04:43 -0700 | [diff] [blame] | 562 | mutex_unlock(&ac->cmd_lock); |
| Swaminathan Sathappan | bdc5508 | 2012-02-16 22:47:40 -0800 | [diff] [blame] | 563 | goto fail; |
| 564 | } |
| 565 | |
| 566 | buf[cnt].data = ion_map_kernel |
| Mitchel Humpherys | 456e268 | 2012-09-12 14:42:50 -0700 | [diff] [blame] | 567 | (buf[cnt].client, buf[cnt].handle); |
| Swaminathan Sathappan | bdc5508 | 2012-02-16 22:47:40 -0800 | [diff] [blame] | 568 | if (IS_ERR_OR_NULL((void *) |
| 569 | buf[cnt].data)) { |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 570 | pr_err("%s: ION memory mapping for AUDIO failed\n", |
| 571 | __func__); |
| Swaminathan Sathappan | 349fed6 | 2012-05-22 15:04:43 -0700 | [diff] [blame] | 572 | mutex_unlock(&ac->cmd_lock); |
| Swaminathan Sathappan | bdc5508 | 2012-02-16 22:47:40 -0800 | [diff] [blame] | 573 | goto fail; |
| 574 | } |
| 575 | memset((void *)buf[cnt].data, 0, bufsz); |
| 576 | #else |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 577 | unsigned int flags = 0; |
| 578 | buf[cnt].phys = |
| 579 | allocate_contiguous_ebi_nomap(bufsz, |
| 580 | SZ_4K); |
| 581 | if (!buf[cnt].phys) { |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 582 | pr_err("%s:Buf alloc failed size=%d\n", |
| 583 | __func__, |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 584 | bufsz); |
| 585 | mutex_unlock(&ac->cmd_lock); |
| 586 | goto fail; |
| 587 | } |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 588 | buf[cnt].mem_buffer = |
| Laura Abbott | ea3e7b6 | 2012-04-30 15:59:21 -0700 | [diff] [blame] | 589 | ioremap(buf[cnt].phys, bufsz); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 590 | if (IS_ERR( |
| 591 | (void *)buf[cnt].mem_buffer)) { |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 592 | pr_err("%s:map_buffer failed, error = %ld\n", |
| 593 | __func__, |
| 594 | PTR_ERR((void *)buf[cnt].mem_buffer)); |
| Jayasena Sangaraboina | 466e6b9 | 2012-01-17 21:10:55 -0800 | [diff] [blame] | 595 | mutex_unlock(&ac->cmd_lock); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 596 | goto fail; |
| 597 | } |
| 598 | buf[cnt].data = |
| Laura Abbott | ea3e7b6 | 2012-04-30 15:59:21 -0700 | [diff] [blame] | 599 | buf[cnt].mem_buffer; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 600 | if (!buf[cnt].data) { |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 601 | pr_err("%s:invalid vaddr, iomap failed\n", |
| 602 | __func__); |
| Jayasena Sangaraboina | 466e6b9 | 2012-01-17 21:10:55 -0800 | [diff] [blame] | 603 | mutex_unlock(&ac->cmd_lock); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 604 | goto fail; |
| 605 | } |
| Swaminathan Sathappan | bdc5508 | 2012-02-16 22:47:40 -0800 | [diff] [blame] | 606 | #endif |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 607 | buf[cnt].used = 1; |
| 608 | buf[cnt].size = bufsz; |
| 609 | buf[cnt].actual_size = bufsz; |
| Swaminathan Sathappan | bdc5508 | 2012-02-16 22:47:40 -0800 | [diff] [blame] | 610 | pr_debug("%s data[%p]phys[%p][%p]\n", |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 611 | __func__, |
| 612 | (void *)buf[cnt].data, |
| 613 | (void *)buf[cnt].phys, |
| Swaminathan Sathappan | bdc5508 | 2012-02-16 22:47:40 -0800 | [diff] [blame] | 614 | (void *)&buf[cnt].phys); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 615 | cnt++; |
| 616 | } |
| 617 | } |
| 618 | } |
| 619 | ac->port[dir].max_buf_cnt = cnt; |
| 620 | |
| 621 | mutex_unlock(&ac->cmd_lock); |
| 622 | rc = q6asm_memory_map_regions(ac, dir, bufsz, cnt); |
| 623 | if (rc < 0) { |
| 624 | pr_err("%s:CMD Memory_map_regions failed\n", __func__); |
| 625 | goto fail; |
| 626 | } |
| 627 | } |
| 628 | return 0; |
| 629 | fail: |
| 630 | q6asm_audio_client_buf_free(dir, ac); |
| 631 | return -EINVAL; |
| 632 | } |
| 633 | |
| 634 | int q6asm_audio_client_buf_alloc_contiguous(unsigned int dir, |
| 635 | struct audio_client *ac, |
| 636 | unsigned int bufsz, |
| 637 | unsigned int bufcnt) |
| 638 | { |
| 639 | int cnt = 0; |
| 640 | int rc = 0; |
| 641 | struct audio_buffer *buf; |
| Swaminathan Sathappan | bdc5508 | 2012-02-16 22:47:40 -0800 | [diff] [blame] | 642 | #ifdef CONFIG_MSM_MULTIMEDIA_USE_ION |
| 643 | int len; |
| 644 | #else |
| 645 | int flags = 0; |
| 646 | #endif |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 647 | if (!(ac) || ((dir != IN) && (dir != OUT))) |
| 648 | return -EINVAL; |
| 649 | |
| 650 | pr_debug("%s: session[%d]bufsz[%d]bufcnt[%d]\n", |
| 651 | __func__, ac->session, |
| 652 | bufsz, bufcnt); |
| 653 | |
| 654 | if (ac->session <= 0 || ac->session > 8) |
| 655 | goto fail; |
| 656 | |
| 657 | if (ac->port[dir].buf) { |
| 658 | pr_debug("%s: buffer already allocated\n", __func__); |
| 659 | return 0; |
| 660 | } |
| 661 | mutex_lock(&ac->cmd_lock); |
| 662 | buf = kzalloc(((sizeof(struct audio_buffer))*bufcnt), |
| 663 | GFP_KERNEL); |
| 664 | |
| 665 | if (!buf) { |
| 666 | mutex_unlock(&ac->cmd_lock); |
| 667 | goto fail; |
| 668 | } |
| 669 | |
| 670 | ac->port[dir].buf = buf; |
| 671 | |
| Swaminathan Sathappan | bdc5508 | 2012-02-16 22:47:40 -0800 | [diff] [blame] | 672 | #ifdef CONFIG_MSM_MULTIMEDIA_USE_ION |
| 673 | buf[0].client = msm_ion_client_create(UINT_MAX, "audio_client"); |
| 674 | if (IS_ERR_OR_NULL((void *)buf[0].client)) { |
| 675 | pr_err("%s: ION create client for AUDIO failed\n", __func__); |
| Swaminathan Sathappan | 349fed6 | 2012-05-22 15:04:43 -0700 | [diff] [blame] | 676 | mutex_unlock(&ac->cmd_lock); |
| Swaminathan Sathappan | bdc5508 | 2012-02-16 22:47:40 -0800 | [diff] [blame] | 677 | goto fail; |
| 678 | } |
| 679 | buf[0].handle = ion_alloc(buf[0].client, bufsz * bufcnt, SZ_4K, |
| Hanumant Singh | 2ac41c9 | 2012-08-29 18:39:44 -0700 | [diff] [blame] | 680 | (0x1 << ION_AUDIO_HEAP_ID), 0); |
| Swaminathan Sathappan | bdc5508 | 2012-02-16 22:47:40 -0800 | [diff] [blame] | 681 | if (IS_ERR_OR_NULL((void *) buf[0].handle)) { |
| 682 | pr_err("%s: ION memory allocation for AUDIO failed\n", |
| 683 | __func__); |
| Swaminathan Sathappan | 349fed6 | 2012-05-22 15:04:43 -0700 | [diff] [blame] | 684 | mutex_unlock(&ac->cmd_lock); |
| Swaminathan Sathappan | bdc5508 | 2012-02-16 22:47:40 -0800 | [diff] [blame] | 685 | goto fail; |
| 686 | } |
| 687 | |
| 688 | rc = ion_phys(buf[0].client, buf[0].handle, |
| 689 | (ion_phys_addr_t *)&buf[0].phys, (size_t *)&len); |
| 690 | if (rc) { |
| 691 | pr_err("%s: ION Get Physical for AUDIO failed, rc = %d\n", |
| 692 | __func__, rc); |
| Swaminathan Sathappan | 349fed6 | 2012-05-22 15:04:43 -0700 | [diff] [blame] | 693 | mutex_unlock(&ac->cmd_lock); |
| Swaminathan Sathappan | bdc5508 | 2012-02-16 22:47:40 -0800 | [diff] [blame] | 694 | goto fail; |
| 695 | } |
| 696 | |
| Mitchel Humpherys | 456e268 | 2012-09-12 14:42:50 -0700 | [diff] [blame] | 697 | buf[0].data = ion_map_kernel(buf[0].client, buf[0].handle); |
| Swaminathan Sathappan | bdc5508 | 2012-02-16 22:47:40 -0800 | [diff] [blame] | 698 | if (IS_ERR_OR_NULL((void *) buf[0].data)) { |
| 699 | pr_err("%s: ION memory mapping for AUDIO failed\n", __func__); |
| Swaminathan Sathappan | 349fed6 | 2012-05-22 15:04:43 -0700 | [diff] [blame] | 700 | mutex_unlock(&ac->cmd_lock); |
| Swaminathan Sathappan | bdc5508 | 2012-02-16 22:47:40 -0800 | [diff] [blame] | 701 | goto fail; |
| 702 | } |
| 703 | memset((void *)buf[0].data, 0, (bufsz * bufcnt)); |
| 704 | #else |
| Harmandeep Singh | 2f7c23c | 2011-11-04 11:57:35 -0700 | [diff] [blame] | 705 | buf[0].phys = allocate_contiguous_ebi_nomap(bufsz * bufcnt, |
| 706 | SZ_4K); |
| 707 | if (!buf[0].phys) { |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 708 | pr_err("%s:Buf alloc failed size=%d, bufcnt=%d\n", |
| 709 | __func__, bufsz, bufcnt); |
| Harmandeep Singh | 2f7c23c | 2011-11-04 11:57:35 -0700 | [diff] [blame] | 710 | mutex_unlock(&ac->cmd_lock); |
| 711 | goto fail; |
| 712 | } |
| 713 | |
| Laura Abbott | ea3e7b6 | 2012-04-30 15:59:21 -0700 | [diff] [blame] | 714 | buf[0].mem_buffer = ioremap(buf[0].phys, bufsz * bufcnt); |
| Harmandeep Singh | 2f7c23c | 2011-11-04 11:57:35 -0700 | [diff] [blame] | 715 | if (IS_ERR((void *)buf[cnt].mem_buffer)) { |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 716 | pr_err("%s:map_buffer failed, error = %ld\n", |
| Harmandeep Singh | 2f7c23c | 2011-11-04 11:57:35 -0700 | [diff] [blame] | 717 | __func__, PTR_ERR((void *)buf[0].mem_buffer)); |
| 718 | |
| 719 | mutex_unlock(&ac->cmd_lock); |
| 720 | goto fail; |
| 721 | } |
| Laura Abbott | ea3e7b6 | 2012-04-30 15:59:21 -0700 | [diff] [blame] | 722 | buf[0].data = buf[0].mem_buffer; |
| Swaminathan Sathappan | bdc5508 | 2012-02-16 22:47:40 -0800 | [diff] [blame] | 723 | #endif |
| Harmandeep Singh | 2f7c23c | 2011-11-04 11:57:35 -0700 | [diff] [blame] | 724 | if (!buf[0].data) { |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 725 | pr_err("%s:invalid vaddr, iomap failed\n", __func__); |
| Harmandeep Singh | 2f7c23c | 2011-11-04 11:57:35 -0700 | [diff] [blame] | 726 | mutex_unlock(&ac->cmd_lock); |
| 727 | goto fail; |
| 728 | } |
| 729 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 730 | buf[0].used = dir ^ 1; |
| 731 | buf[0].size = bufsz; |
| 732 | buf[0].actual_size = bufsz; |
| 733 | cnt = 1; |
| 734 | while (cnt < bufcnt) { |
| 735 | if (bufsz > 0) { |
| 736 | buf[cnt].data = buf[0].data + (cnt * bufsz); |
| 737 | buf[cnt].phys = buf[0].phys + (cnt * bufsz); |
| 738 | if (!buf[cnt].data) { |
| 739 | pr_err("%s Buf alloc failed\n", |
| 740 | __func__); |
| 741 | mutex_unlock(&ac->cmd_lock); |
| 742 | goto fail; |
| 743 | } |
| 744 | buf[cnt].used = dir ^ 1; |
| 745 | buf[cnt].size = bufsz; |
| 746 | buf[cnt].actual_size = bufsz; |
| 747 | pr_debug("%s data[%p]phys[%p][%p]\n", __func__, |
| 748 | (void *)buf[cnt].data, |
| 749 | (void *)buf[cnt].phys, |
| 750 | (void *)&buf[cnt].phys); |
| 751 | } |
| 752 | cnt++; |
| 753 | } |
| 754 | ac->port[dir].max_buf_cnt = cnt; |
| Subhash Chandra Bose Naripeddy | 8f84689 | 2012-06-12 11:29:18 -0700 | [diff] [blame] | 755 | |
| 756 | pr_debug("%s ac->port[%d].max_buf_cnt[%d]\n", __func__, dir, |
| 757 | ac->port[dir].max_buf_cnt); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 758 | mutex_unlock(&ac->cmd_lock); |
| 759 | rc = q6asm_memory_map(ac, buf[0].phys, dir, bufsz, cnt); |
| 760 | if (rc < 0) { |
| 761 | pr_err("%s:CMD Memory_map_regions failed\n", __func__); |
| 762 | goto fail; |
| 763 | } |
| 764 | return 0; |
| 765 | fail: |
| 766 | q6asm_audio_client_buf_free_contiguous(dir, ac); |
| 767 | return -EINVAL; |
| 768 | } |
| 769 | |
| 770 | static int32_t q6asm_mmapcallback(struct apr_client_data *data, void *priv) |
| 771 | { |
| 772 | uint32_t token; |
| 773 | uint32_t *payload = data->payload; |
| Deepa Madiregama | 636f80e | 2013-01-17 14:01:25 +0530 | [diff] [blame] | 774 | struct audio_client *ac; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 775 | |
| 776 | if (data->opcode == RESET_EVENTS) { |
| 777 | pr_debug("%s: Reset event is received: %d %d apr[%p]\n", |
| 778 | __func__, |
| 779 | data->reset_event, |
| 780 | data->reset_proc, |
| 781 | this_mmap.apr); |
| 782 | apr_reset(this_mmap.apr); |
| 783 | this_mmap.apr = NULL; |
| 784 | atomic_set(&this_mmap.cmd_state, 0); |
| 785 | return 0; |
| 786 | } |
| 787 | |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 788 | pr_debug("%s:ptr0[0x%x]ptr1[0x%x]opcode[0x%x] token[0x%x]payload_s[%d] src[%d] dest[%d]\n", |
| 789 | __func__, payload[0], payload[1], data->opcode, data->token, |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 790 | data->payload_size, data->src_port, data->dest_port); |
| 791 | |
| 792 | if (data->opcode == APR_BASIC_RSP_RESULT) { |
| 793 | token = data->token; |
| Deepa Madiregama | 636f80e | 2013-01-17 14:01:25 +0530 | [diff] [blame] | 794 | ac = (struct audio_client *)data->token; |
| 795 | pr_debug("%s: audio_client addr %x\n", __func__, (uint32_t)ac); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 796 | switch (payload[0]) { |
| 797 | case ASM_SESSION_CMD_MEMORY_MAP: |
| 798 | case ASM_SESSION_CMD_MEMORY_UNMAP: |
| 799 | case ASM_SESSION_CMD_MEMORY_MAP_REGIONS: |
| 800 | case ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS: |
| 801 | pr_debug("%s:command[0x%x]success [0x%x]\n", |
| 802 | __func__, payload[0], payload[1]); |
| Deepa Madiregama | 636f80e | 2013-01-17 14:01:25 +0530 | [diff] [blame] | 803 | if (atomic_read(&ac->cmd_state)) { |
| 804 | atomic_set(&ac->cmd_state, 0); |
| 805 | if (payload[1] != ADSP_EOK) { |
| 806 | pr_err("payload[1]:%d error case\n", |
| 807 | payload[1]); |
| 808 | atomic_set(&ac->cmd_response, 1); |
| 809 | } else |
| 810 | atomic_set(&ac->cmd_response, 0); |
| 811 | wake_up(&ac->cmd_wait); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 812 | } |
| 813 | break; |
| 814 | default: |
| 815 | pr_debug("%s:command[0x%x] not expecting rsp\n", |
| 816 | __func__, payload[0]); |
| 817 | break; |
| 818 | } |
| 819 | } |
| 820 | return 0; |
| 821 | } |
| 822 | |
| Jay Wang | cd1d37d | 2012-10-03 16:17:18 -0700 | [diff] [blame] | 823 | static int32_t is_no_wait_cmd_rsp(uint32_t opcode, uint32_t *cmd_type) |
| 824 | { |
| 825 | if (opcode == APR_BASIC_RSP_RESULT) { |
| 826 | if (cmd_type != NULL) { |
| 827 | switch (cmd_type[0]) { |
| 828 | case ASM_SESSION_CMD_RUN: |
| 829 | case ASM_SESSION_CMD_PAUSE: |
| 830 | case ASM_DATA_CMD_EOS: |
| 831 | return 1; |
| 832 | default: |
| 833 | break; |
| 834 | } |
| 835 | } else |
| 836 | pr_err("%s: null pointer!", __func__); |
| 837 | } else if (opcode == ASM_DATA_CMDRSP_EOS) |
| 838 | return 1; |
| 839 | |
| 840 | return 0; |
| 841 | } |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 842 | |
| 843 | static int32_t q6asm_callback(struct apr_client_data *data, void *priv) |
| 844 | { |
| 845 | int i = 0; |
| 846 | struct audio_client *ac = (struct audio_client *)priv; |
| 847 | uint32_t token; |
| 848 | unsigned long dsp_flags; |
| 849 | uint32_t *payload; |
| Jay Wang | 0668d106 | 2012-07-11 18:53:21 -0700 | [diff] [blame] | 850 | uint32_t wakeup_flag = 1; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 851 | |
| 852 | |
| 853 | if ((ac == NULL) || (data == NULL)) { |
| 854 | pr_err("ac or priv NULL\n"); |
| 855 | return -EINVAL; |
| 856 | } |
| 857 | if (ac->session <= 0 || ac->session > 8) { |
| 858 | pr_err("%s:Session ID is invalid, session = %d\n", __func__, |
| 859 | ac->session); |
| 860 | return -EINVAL; |
| 861 | } |
| Jay Wang | cd1d37d | 2012-10-03 16:17:18 -0700 | [diff] [blame] | 862 | |
| 863 | payload = data->payload; |
| 864 | if ((atomic_read(&ac->nowait_cmd_cnt) > 0) && |
| 865 | is_no_wait_cmd_rsp(data->opcode, payload)) { |
| Jay Wang | 0668d106 | 2012-07-11 18:53:21 -0700 | [diff] [blame] | 866 | pr_debug("%s: nowait_cmd_cnt %d\n", |
| 867 | __func__, |
| 868 | atomic_read(&ac->nowait_cmd_cnt)); |
| 869 | atomic_dec(&ac->nowait_cmd_cnt); |
| 870 | wakeup_flag = 0; |
| 871 | } |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 872 | |
| 873 | if (data->opcode == RESET_EVENTS) { |
| 874 | pr_debug("q6asm_callback: Reset event is received: %d %d apr[%p]\n", |
| 875 | data->reset_event, data->reset_proc, ac->apr); |
| Laxminath Kasam | 692c654 | 2012-02-21 11:17:47 +0530 | [diff] [blame] | 876 | if (ac->cb) |
| 877 | ac->cb(data->opcode, data->token, |
| 878 | (uint32_t *)data->payload, ac->priv); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 879 | apr_reset(ac->apr); |
| 880 | return 0; |
| 881 | } |
| 882 | |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 883 | pr_debug("%s: session[%d]opcode[0x%x] token[0x%x]payload_s[%d] src[%d] dest[%d]\n", |
| 884 | __func__, |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 885 | ac->session, data->opcode, |
| 886 | data->token, data->payload_size, data->src_port, |
| 887 | data->dest_port); |
| 888 | |
| 889 | if (data->opcode == APR_BASIC_RSP_RESULT) { |
| 890 | token = data->token; |
| Jayasena Sangaraboina | 99bf09c | 2012-07-17 12:03:08 -0700 | [diff] [blame] | 891 | pr_debug("%s payload[0]:%x", __func__, payload[0]); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 892 | switch (payload[0]) { |
| 893 | case ASM_STREAM_CMD_SET_PP_PARAMS: |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 894 | if (rtac_make_asm_callback(ac->session, payload, |
| 895 | data->payload_size)) |
| 896 | break; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 897 | case ASM_SESSION_CMD_PAUSE: |
| 898 | case ASM_DATA_CMD_EOS: |
| 899 | case ASM_STREAM_CMD_CLOSE: |
| 900 | case ASM_STREAM_CMD_FLUSH: |
| 901 | case ASM_SESSION_CMD_RUN: |
| 902 | case ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS: |
| 903 | case ASM_STREAM_CMD_FLUSH_READBUFS: |
| 904 | pr_debug("%s:Payload = [0x%x]\n", __func__, payload[0]); |
| 905 | if (token != ac->session) { |
| 906 | pr_err("%s:Invalid session[%d] rxed expected[%d]", |
| 907 | __func__, token, ac->session); |
| 908 | return -EINVAL; |
| 909 | } |
| 910 | case ASM_STREAM_CMD_OPEN_READ: |
| Jayasena Sangaraboina | 99bf09c | 2012-07-17 12:03:08 -0700 | [diff] [blame] | 911 | case ASM_STREAM_CMD_OPEN_READ_V2_1: |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 912 | case ASM_STREAM_CMD_OPEN_WRITE: |
| Flemmard | 1bc7b1c | 2014-01-08 00:24:20 -0800 | [diff] [blame^] | 913 | case ASM_STREAM_CMD_OPEN_WRITE_V2: |
| Jayasena Sangaraboina | 99bf09c | 2012-07-17 12:03:08 -0700 | [diff] [blame] | 914 | case ASM_STREAM_CMD_OPEN_WRITE_V2_1: |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 915 | case ASM_STREAM_CMD_OPEN_READWRITE: |
| Laxminath Kasam | 2082450 | 2013-01-07 14:33:56 +0530 | [diff] [blame] | 916 | case ASM_STREAM_CMD_OPEN_LOOPBACK: |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 917 | case ASM_DATA_CMD_MEDIA_FORMAT_UPDATE: |
| 918 | case ASM_STREAM_CMD_SET_ENCDEC_PARAM: |
| Santosh Mardi | 2332120 | 2012-03-22 04:33:25 +0530 | [diff] [blame] | 919 | case ASM_STREAM_CMD_OPEN_WRITE_COMPRESSED: |
| Subhash Chandra Bose Naripeddy | 8f84689 | 2012-06-12 11:29:18 -0700 | [diff] [blame] | 920 | case ASM_STREAM_CMD_OPEN_READ_COMPRESSED: |
| Laxminath Kasam | f16d3fd | 2012-12-19 14:54:14 +0530 | [diff] [blame] | 921 | if (payload[0] == ASM_STREAM_CMD_CLOSE) { |
| 922 | atomic_set(&ac->cmd_close_state, 0); |
| 923 | wake_up(&ac->cmd_wait); |
| 924 | } else if (atomic_read(&ac->cmd_state) && |
| 925 | wakeup_flag) { |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 926 | atomic_set(&ac->cmd_state, 0); |
| Jayasena Sangaraboina | 99bf09c | 2012-07-17 12:03:08 -0700 | [diff] [blame] | 927 | if (payload[1] == ADSP_EUNSUPPORTED) { |
| 928 | pr_debug("paload[1]:%d unsupported", |
| 929 | payload[1]); |
| Srikanth Uyyala | a50b51d | 2012-07-02 16:02:24 +0530 | [diff] [blame] | 930 | atomic_set(&ac->cmd_response, 1); |
| Jayasena Sangaraboina | 99bf09c | 2012-07-17 12:03:08 -0700 | [diff] [blame] | 931 | } |
| Srikanth Uyyala | a50b51d | 2012-07-02 16:02:24 +0530 | [diff] [blame] | 932 | else |
| 933 | atomic_set(&ac->cmd_response, 0); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 934 | wake_up(&ac->cmd_wait); |
| 935 | } |
| 936 | if (ac->cb) |
| 937 | ac->cb(data->opcode, data->token, |
| 938 | (uint32_t *)data->payload, ac->priv); |
| 939 | break; |
| 940 | default: |
| 941 | pr_debug("%s:command[0x%x] not expecting rsp\n", |
| 942 | __func__, payload[0]); |
| 943 | break; |
| 944 | } |
| 945 | return 0; |
| 946 | } |
| 947 | |
| 948 | switch (data->opcode) { |
| 949 | case ASM_DATA_EVENT_WRITE_DONE:{ |
| 950 | struct audio_port_data *port = &ac->port[IN]; |
| 951 | pr_debug("%s: Rxed opcode[0x%x] status[0x%x] token[%d]", |
| 952 | __func__, payload[0], payload[1], |
| 953 | data->token); |
| Patrick Lai | 55f54c5 | 2012-11-17 00:29:07 -0800 | [diff] [blame] | 954 | if (ac->io_mode & SYNC_IO_MODE) { |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 955 | if (port->buf == NULL) { |
| 956 | pr_err("%s: Unexpected Write Done\n", |
| 957 | __func__); |
| 958 | return -EINVAL; |
| 959 | } |
| 960 | spin_lock_irqsave(&port->dsp_lock, dsp_flags); |
| 961 | if (port->buf[data->token].phys != |
| 962 | payload[0]) { |
| 963 | pr_err("Buf expected[%p]rxed[%p]\n",\ |
| 964 | (void *)port->buf[data->token].phys,\ |
| 965 | (void *)payload[0]); |
| 966 | spin_unlock_irqrestore(&port->dsp_lock, |
| 967 | dsp_flags); |
| 968 | return -EINVAL; |
| 969 | } |
| 970 | token = data->token; |
| 971 | port->buf[token].used = 1; |
| 972 | spin_unlock_irqrestore(&port->dsp_lock, dsp_flags); |
| Rajesha Kini | 3498c93 | 2011-07-19 19:58:27 +0530 | [diff] [blame] | 973 | #ifdef CONFIG_DEBUG_FS |
| 974 | if (out_enable_flag) { |
| 975 | /* For first Write done log the time and reset |
| 976 | out_cold_index*/ |
| 977 | if (out_cold_index != 1) { |
| 978 | do_gettimeofday(&out_cold_tv); |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 979 | pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n", |
| 980 | out_cold_tv.tv_sec, |
| Rajesha Kini | 3498c93 | 2011-07-19 19:58:27 +0530 | [diff] [blame] | 981 | out_cold_tv.tv_usec); |
| 982 | out_cold_index = 1; |
| 983 | } |
| 984 | pr_debug("out_enable_flag %ld",\ |
| 985 | out_enable_flag); |
| 986 | } |
| 987 | #endif |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 988 | for (i = 0; i < port->max_buf_cnt; i++) |
| 989 | pr_debug("%d ", port->buf[i].used); |
| 990 | |
| 991 | } |
| 992 | break; |
| 993 | } |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 994 | case ASM_STREAM_CMDRSP_GET_PP_PARAMS: |
| 995 | rtac_make_asm_callback(ac->session, payload, |
| 996 | data->payload_size); |
| 997 | break; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 998 | case ASM_DATA_EVENT_READ_DONE:{ |
| 999 | |
| 1000 | struct audio_port_data *port = &ac->port[OUT]; |
| Rajesha Kini | 3498c93 | 2011-07-19 19:58:27 +0530 | [diff] [blame] | 1001 | #ifdef CONFIG_DEBUG_FS |
| 1002 | if (in_enable_flag) { |
| 1003 | /* when in_cont_index == 7, DSP would be |
| 1004 | * writing into the 8th 512 byte buffer and this |
| 1005 | * timestamp is tapped here.Once done it then writes |
| 1006 | * to 9th 512 byte buffer.These two buffers(8th, 9th) |
| 1007 | * reach the test application in 5th iteration and that |
| 1008 | * timestamp is tapped at user level. The difference |
| 1009 | * of these two timestamps gives us the time between |
| 1010 | * the time at which dsp started filling the sample |
| 1011 | * required and when it reached the test application. |
| 1012 | * Hence continuous input latency |
| 1013 | */ |
| 1014 | if (in_cont_index == 7) { |
| 1015 | do_gettimeofday(&in_cont_tv); |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 1016 | pr_err("In_CONT:previous read buffer done at %ld sec %ld microsec\n", |
| Sriranjan Srikantam | 7475353 | 2011-10-03 14:48:37 -0700 | [diff] [blame] | 1017 | in_cont_tv.tv_sec, in_cont_tv.tv_usec); |
| Rajesha Kini | 3498c93 | 2011-07-19 19:58:27 +0530 | [diff] [blame] | 1018 | } |
| 1019 | } |
| 1020 | #endif |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1021 | pr_debug("%s:R-D: status=%d buff_add=%x act_size=%d offset=%d\n", |
| 1022 | __func__, payload[READDONE_IDX_STATUS], |
| 1023 | payload[READDONE_IDX_BUFFER], |
| 1024 | payload[READDONE_IDX_SIZE], |
| 1025 | payload[READDONE_IDX_OFFSET]); |
| 1026 | pr_debug("%s:R-D:msw_ts=%d lsw_ts=%d flags=%d id=%d num=%d\n", |
| 1027 | __func__, payload[READDONE_IDX_MSW_TS], |
| 1028 | payload[READDONE_IDX_LSW_TS], |
| 1029 | payload[READDONE_IDX_FLAGS], |
| 1030 | payload[READDONE_IDX_ID], |
| 1031 | payload[READDONE_IDX_NUMFRAMES]); |
| Rajesha Kini | 3498c93 | 2011-07-19 19:58:27 +0530 | [diff] [blame] | 1032 | #ifdef CONFIG_DEBUG_FS |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 1033 | if (in_enable_flag) |
| Rajesha Kini | 3498c93 | 2011-07-19 19:58:27 +0530 | [diff] [blame] | 1034 | in_cont_index++; |
| Rajesha Kini | 3498c93 | 2011-07-19 19:58:27 +0530 | [diff] [blame] | 1035 | #endif |
| Patrick Lai | 55f54c5 | 2012-11-17 00:29:07 -0800 | [diff] [blame] | 1036 | if (ac->io_mode & SYNC_IO_MODE) { |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1037 | if (port->buf == NULL) { |
| 1038 | pr_err("%s: Unexpected Write Done\n", __func__); |
| 1039 | return -EINVAL; |
| 1040 | } |
| 1041 | spin_lock_irqsave(&port->dsp_lock, dsp_flags); |
| 1042 | token = data->token; |
| 1043 | port->buf[token].used = 0; |
| 1044 | if (port->buf[token].phys != |
| 1045 | payload[READDONE_IDX_BUFFER]) { |
| 1046 | pr_err("Buf expected[%p]rxed[%p]\n",\ |
| 1047 | (void *)port->buf[token].phys,\ |
| 1048 | (void *)payload[READDONE_IDX_BUFFER]); |
| 1049 | spin_unlock_irqrestore(&port->dsp_lock, |
| 1050 | dsp_flags); |
| 1051 | break; |
| 1052 | } |
| 1053 | port->buf[token].actual_size = |
| 1054 | payload[READDONE_IDX_SIZE]; |
| 1055 | spin_unlock_irqrestore(&port->dsp_lock, dsp_flags); |
| 1056 | } |
| 1057 | break; |
| 1058 | } |
| 1059 | case ASM_DATA_EVENT_EOS: |
| 1060 | case ASM_DATA_CMDRSP_EOS: |
| 1061 | pr_debug("%s:EOS ACK received: rxed opcode[0x%x]\n", |
| 1062 | __func__, data->opcode); |
| 1063 | break; |
| 1064 | case ASM_STREAM_CMDRSP_GET_ENCDEC_PARAM: |
| 1065 | break; |
| 1066 | case ASM_SESSION_EVENT_TX_OVERFLOW: |
| 1067 | pr_err("ASM_SESSION_EVENT_TX_OVERFLOW\n"); |
| 1068 | break; |
| 1069 | case ASM_SESSION_CMDRSP_GET_SESSION_TIME: |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 1070 | pr_debug("%s: ASM_SESSION_CMDRSP_GET_SESSION_TIME, payload[0] = %d, payload[1] = %d, payload[2] = %d\n", |
| 1071 | __func__, |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1072 | payload[0], payload[1], payload[2]); |
| 1073 | ac->time_stamp = (uint64_t)(((uint64_t)payload[1] << 32) | |
| 1074 | payload[2]); |
| 1075 | if (atomic_read(&ac->time_flag)) { |
| 1076 | atomic_set(&ac->time_flag, 0); |
| 1077 | wake_up(&ac->time_wait); |
| 1078 | } |
| 1079 | break; |
| 1080 | case ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY: |
| Deepa Madiregama | 55cbf78 | 2011-09-10 05:44:39 +0530 | [diff] [blame] | 1081 | case ASM_DATA_EVENT_ENC_SR_CM_NOTIFY: |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 1082 | pr_debug("%s: ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY, payload[0] = %d, payload[1] = %d, payload[2] = %d, payload[3] = %d\n", |
| 1083 | __func__, |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1084 | payload[0], payload[1], payload[2], |
| 1085 | payload[3]); |
| 1086 | break; |
| 1087 | } |
| 1088 | if (ac->cb) |
| 1089 | ac->cb(data->opcode, data->token, |
| 1090 | data->payload, ac->priv); |
| 1091 | |
| 1092 | return 0; |
| 1093 | } |
| 1094 | |
| 1095 | void *q6asm_is_cpu_buf_avail(int dir, struct audio_client *ac, uint32_t *size, |
| 1096 | uint32_t *index) |
| 1097 | { |
| 1098 | void *data; |
| 1099 | unsigned char idx; |
| 1100 | struct audio_port_data *port; |
| 1101 | |
| 1102 | if (!ac || ((dir != IN) && (dir != OUT))) |
| 1103 | return NULL; |
| 1104 | |
| Patrick Lai | 55f54c5 | 2012-11-17 00:29:07 -0800 | [diff] [blame] | 1105 | if (ac->io_mode & SYNC_IO_MODE) { |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1106 | port = &ac->port[dir]; |
| 1107 | |
| 1108 | mutex_lock(&port->lock); |
| 1109 | idx = port->cpu_buf; |
| 1110 | if (port->buf == NULL) { |
| 1111 | pr_debug("%s:Buffer pointer null\n", __func__); |
| Jayasena Sangaraboina | 466e6b9 | 2012-01-17 21:10:55 -0800 | [diff] [blame] | 1112 | mutex_unlock(&port->lock); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1113 | return NULL; |
| 1114 | } |
| 1115 | /* dir 0: used = 0 means buf in use |
| 1116 | dir 1: used = 1 means buf in use */ |
| 1117 | if (port->buf[idx].used == dir) { |
| 1118 | /* To make it more robust, we could loop and get the |
| 1119 | next avail buf, its risky though */ |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 1120 | pr_debug("%s:Next buf idx[0x%x] not available,dir[%d]\n", |
| 1121 | __func__, idx, dir); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1122 | mutex_unlock(&port->lock); |
| 1123 | return NULL; |
| 1124 | } |
| 1125 | *size = port->buf[idx].actual_size; |
| 1126 | *index = port->cpu_buf; |
| 1127 | data = port->buf[idx].data; |
| 1128 | pr_debug("%s:session[%d]index[%d] data[%p]size[%d]\n", |
| 1129 | __func__, |
| 1130 | ac->session, |
| 1131 | port->cpu_buf, |
| 1132 | data, *size); |
| 1133 | /* By default increase the cpu_buf cnt |
| 1134 | user accesses this function,increase cpu |
| 1135 | buf(to avoid another api)*/ |
| 1136 | port->buf[idx].used = dir; |
| 1137 | port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1)); |
| 1138 | mutex_unlock(&port->lock); |
| 1139 | return data; |
| 1140 | } |
| 1141 | return NULL; |
| 1142 | } |
| 1143 | |
| Jay Wang | 9cf59a0 | 2011-08-10 16:58:40 -0700 | [diff] [blame] | 1144 | void *q6asm_is_cpu_buf_avail_nolock(int dir, struct audio_client *ac, |
| 1145 | uint32_t *size, uint32_t *index) |
| 1146 | { |
| 1147 | void *data; |
| 1148 | unsigned char idx; |
| 1149 | struct audio_port_data *port; |
| 1150 | |
| 1151 | if (!ac || ((dir != IN) && (dir != OUT))) |
| 1152 | return NULL; |
| 1153 | |
| 1154 | port = &ac->port[dir]; |
| 1155 | |
| 1156 | idx = port->cpu_buf; |
| 1157 | if (port->buf == NULL) { |
| 1158 | pr_debug("%s:Buffer pointer null\n", __func__); |
| 1159 | return NULL; |
| 1160 | } |
| 1161 | /* |
| 1162 | * dir 0: used = 0 means buf in use |
| 1163 | * dir 1: used = 1 means buf in use |
| 1164 | */ |
| 1165 | if (port->buf[idx].used == dir) { |
| 1166 | /* |
| 1167 | * To make it more robust, we could loop and get the |
| 1168 | * next avail buf, its risky though |
| 1169 | */ |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 1170 | pr_debug("%s:Next buf idx[0x%x] not available, dir[%d]\n", |
| 1171 | __func__, idx, dir); |
| Jay Wang | 9cf59a0 | 2011-08-10 16:58:40 -0700 | [diff] [blame] | 1172 | return NULL; |
| 1173 | } |
| 1174 | *size = port->buf[idx].actual_size; |
| 1175 | *index = port->cpu_buf; |
| 1176 | data = port->buf[idx].data; |
| 1177 | pr_debug("%s:session[%d]index[%d] data[%p]size[%d]\n", |
| 1178 | __func__, ac->session, port->cpu_buf, |
| 1179 | data, *size); |
| 1180 | /* |
| 1181 | * By default increase the cpu_buf cnt |
| 1182 | * user accesses this function,increase cpu |
| 1183 | * buf(to avoid another api) |
| 1184 | */ |
| 1185 | port->buf[idx].used = dir; |
| 1186 | port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1)); |
| 1187 | return data; |
| 1188 | } |
| 1189 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1190 | int q6asm_is_dsp_buf_avail(int dir, struct audio_client *ac) |
| 1191 | { |
| 1192 | int ret = -1; |
| 1193 | struct audio_port_data *port; |
| 1194 | uint32_t idx; |
| 1195 | |
| 1196 | if (!ac || (dir != OUT)) |
| 1197 | return ret; |
| 1198 | |
| Patrick Lai | 55f54c5 | 2012-11-17 00:29:07 -0800 | [diff] [blame] | 1199 | if (ac->io_mode & SYNC_IO_MODE) { |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1200 | port = &ac->port[dir]; |
| 1201 | |
| 1202 | mutex_lock(&port->lock); |
| 1203 | idx = port->dsp_buf; |
| 1204 | |
| 1205 | if (port->buf[idx].used == (dir ^ 1)) { |
| 1206 | /* To make it more robust, we could loop and get the |
| 1207 | next avail buf, its risky though */ |
| 1208 | pr_err("Next buf idx[0x%x] not available, dir[%d]\n", |
| 1209 | idx, dir); |
| 1210 | mutex_unlock(&port->lock); |
| 1211 | return ret; |
| 1212 | } |
| 1213 | pr_debug("%s: session[%d]dsp_buf=%d cpu_buf=%d\n", __func__, |
| 1214 | ac->session, port->dsp_buf, port->cpu_buf); |
| 1215 | ret = ((port->dsp_buf != port->cpu_buf) ? 0 : -1); |
| 1216 | mutex_unlock(&port->lock); |
| 1217 | } |
| 1218 | return ret; |
| 1219 | } |
| 1220 | |
| 1221 | static void q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr, |
| 1222 | uint32_t pkt_size, uint32_t cmd_flg) |
| 1223 | { |
| 1224 | pr_debug("%s:session=%d pkt size=%d cmd_flg=%d\n", __func__, pkt_size, |
| 1225 | cmd_flg, ac->session); |
| 1226 | mutex_lock(&ac->cmd_lock); |
| 1227 | hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \ |
| 1228 | APR_HDR_LEN(sizeof(struct apr_hdr)),\ |
| 1229 | APR_PKT_VER); |
| 1230 | hdr->src_svc = ((struct apr_svc *)ac->apr)->id; |
| 1231 | hdr->src_domain = APR_DOMAIN_APPS; |
| 1232 | hdr->dest_svc = APR_SVC_ASM; |
| 1233 | hdr->dest_domain = APR_DOMAIN_ADSP; |
| 1234 | hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01; |
| 1235 | hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01; |
| 1236 | if (cmd_flg) { |
| 1237 | hdr->token = ac->session; |
| 1238 | atomic_set(&ac->cmd_state, 1); |
| 1239 | } |
| 1240 | hdr->pkt_size = pkt_size; |
| 1241 | mutex_unlock(&ac->cmd_lock); |
| 1242 | return; |
| 1243 | } |
| 1244 | |
| 1245 | static void q6asm_add_mmaphdr(struct apr_hdr *hdr, uint32_t pkt_size, |
| 1246 | uint32_t cmd_flg) |
| 1247 | { |
| Deepa Madiregama | 636f80e | 2013-01-17 14:01:25 +0530 | [diff] [blame] | 1248 | struct audio_client *ac; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1249 | pr_debug("%s:pkt size=%d cmd_flg=%d\n", __func__, pkt_size, cmd_flg); |
| Deepa Madiregama | 636f80e | 2013-01-17 14:01:25 +0530 | [diff] [blame] | 1250 | ac = (struct audio_client *)hdr->token; |
| 1251 | pr_debug("%s: audio_client = %x\n", __func__, (uint32_t)ac); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1252 | hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \ |
| 1253 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 1254 | hdr->src_port = 0; |
| 1255 | hdr->dest_port = 0; |
| 1256 | if (cmd_flg) { |
| Deepa Madiregama | 636f80e | 2013-01-17 14:01:25 +0530 | [diff] [blame] | 1257 | atomic_set(&ac->cmd_state, 1); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1258 | } |
| 1259 | hdr->pkt_size = pkt_size; |
| 1260 | return; |
| 1261 | } |
| 1262 | |
| 1263 | int q6asm_open_read(struct audio_client *ac, |
| 1264 | uint32_t format) |
| 1265 | { |
| 1266 | int rc = 0x00; |
| 1267 | struct asm_stream_cmd_open_read open; |
| Rajesha Kini | 3498c93 | 2011-07-19 19:58:27 +0530 | [diff] [blame] | 1268 | #ifdef CONFIG_DEBUG_FS |
| 1269 | in_cont_index = 0; |
| 1270 | #endif |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1271 | if ((ac == NULL) || (ac->apr == NULL)) { |
| 1272 | pr_err("%s: APR handle NULL\n", __func__); |
| 1273 | return -EINVAL; |
| 1274 | } |
| 1275 | pr_debug("%s:session[%d]", __func__, ac->session); |
| 1276 | |
| 1277 | q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE); |
| 1278 | open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ; |
| 1279 | /* Stream prio : High, provide meta info with encoded frames */ |
| 1280 | open.src_endpoint = ASM_END_POINT_DEVICE_MATRIX; |
| 1281 | |
| 1282 | open.pre_proc_top = get_asm_topology(); |
| 1283 | if (open.pre_proc_top == 0) |
| 1284 | open.pre_proc_top = DEFAULT_POPP_TOPOLOGY; |
| 1285 | |
| 1286 | switch (format) { |
| 1287 | case FORMAT_LINEAR_PCM: |
| 1288 | open.uMode = STREAM_PRIORITY_HIGH; |
| 1289 | open.format = LINEAR_PCM; |
| 1290 | break; |
| Mingming Yin | 647e9ea | 2012-03-17 19:56:10 -0700 | [diff] [blame] | 1291 | case FORMAT_MULTI_CHANNEL_LINEAR_PCM: |
| 1292 | open.uMode = STREAM_PRIORITY_HIGH; |
| 1293 | open.format = MULTI_CHANNEL_PCM; |
| 1294 | break; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1295 | case FORMAT_MPEG4_AAC: |
| 1296 | open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH; |
| 1297 | open.format = MPEG4_AAC; |
| 1298 | break; |
| 1299 | case FORMAT_V13K: |
| 1300 | open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH; |
| 1301 | open.format = V13K_FS; |
| 1302 | break; |
| 1303 | case FORMAT_EVRC: |
| 1304 | open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH; |
| 1305 | open.format = EVRC_FS; |
| 1306 | break; |
| 1307 | case FORMAT_AMRNB: |
| 1308 | open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH; |
| 1309 | open.format = AMRNB_FS; |
| 1310 | break; |
| Alex Wong | 2caeecc | 2011-10-28 10:52:15 +0530 | [diff] [blame] | 1311 | case FORMAT_AMRWB: |
| 1312 | open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH; |
| 1313 | open.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", format); |
| 1317 | goto fail_cmd; |
| 1318 | } |
| 1319 | rc = apr_send_pkt(ac->apr, (uint32_t *) &open); |
| 1320 | if (rc < 0) { |
| 1321 | pr_err("open failed op[0x%x]rc[%d]\n", \ |
| 1322 | open.hdr.opcode, rc); |
| 1323 | goto fail_cmd; |
| 1324 | } |
| 1325 | rc = wait_event_timeout(ac->cmd_wait, |
| 1326 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 1327 | if (!rc) { |
| 1328 | pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__, |
| 1329 | rc); |
| 1330 | goto fail_cmd; |
| 1331 | } |
| Patrick Lai | 55f54c5 | 2012-11-17 00:29:07 -0800 | [diff] [blame] | 1332 | |
| 1333 | ac->io_mode |= TUN_READ_IO_MODE; |
| 1334 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1335 | return 0; |
| 1336 | fail_cmd: |
| 1337 | return -EINVAL; |
| 1338 | } |
| 1339 | |
| Jayasena Sangaraboina | 99bf09c | 2012-07-17 12:03:08 -0700 | [diff] [blame] | 1340 | int q6asm_open_read_v2_1(struct audio_client *ac, |
| 1341 | uint32_t format) |
| 1342 | { |
| 1343 | int rc = 0x00; |
| 1344 | struct asm_stream_cmd_open_read_v2_1 open; |
| 1345 | #ifdef CONFIG_DEBUG_FS |
| 1346 | in_cont_index = 0; |
| 1347 | #endif |
| 1348 | if ((ac == NULL) || (ac->apr == NULL)) { |
| 1349 | pr_err("%s: APR handle NULL\n", __func__); |
| 1350 | return -EINVAL; |
| 1351 | } |
| 1352 | pr_debug("%s:session[%d]", __func__, ac->session); |
| 1353 | |
| 1354 | q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE); |
| 1355 | open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ_V2_1; |
| 1356 | open.src_endpoint = ASM_END_POINT_DEVICE_MATRIX; |
| 1357 | open.pre_proc_top = get_asm_topology(); |
| 1358 | if (open.pre_proc_top == 0) |
| 1359 | open.pre_proc_top = DEFAULT_POPP_TOPOLOGY; |
| 1360 | |
| 1361 | switch (format) { |
| 1362 | case FORMAT_LINEAR_PCM: |
| 1363 | open.uMode = STREAM_PRIORITY_HIGH; |
| 1364 | open.format = LINEAR_PCM; |
| 1365 | break; |
| 1366 | case FORMAT_MULTI_CHANNEL_LINEAR_PCM: |
| 1367 | open.uMode = STREAM_PRIORITY_HIGH; |
| 1368 | open.format = MULTI_CHANNEL_PCM; |
| 1369 | break; |
| 1370 | case FORMAT_MPEG4_AAC: |
| 1371 | open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH; |
| 1372 | open.format = MPEG4_AAC; |
| 1373 | break; |
| 1374 | case FORMAT_V13K: |
| 1375 | open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH; |
| 1376 | open.format = V13K_FS; |
| 1377 | break; |
| 1378 | case FORMAT_EVRC: |
| 1379 | open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH; |
| 1380 | open.format = EVRC_FS; |
| 1381 | break; |
| 1382 | case FORMAT_AMRNB: |
| 1383 | open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH; |
| 1384 | open.format = AMRNB_FS; |
| 1385 | break; |
| 1386 | case FORMAT_AMRWB: |
| 1387 | open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH; |
| 1388 | open.format = AMRWB_FS; |
| 1389 | break; |
| 1390 | default: |
| 1391 | pr_err("Invalid format[%d]\n", format); |
| 1392 | goto fail_cmd; |
| 1393 | } |
| 1394 | open.uMode = ASM_OPEN_READ_PERF_MODE_BIT; |
| 1395 | open.bits_per_sample = PCM_BITS_PER_SAMPLE; |
| 1396 | open.reserved = 0; |
| 1397 | rc = apr_send_pkt(ac->apr, (uint32_t *) &open); |
| 1398 | if (rc < 0) { |
| 1399 | pr_err("open failed op[0x%x]rc[%d]\n", \ |
| 1400 | open.hdr.opcode, rc); |
| 1401 | goto fail_cmd; |
| 1402 | } |
| 1403 | rc = wait_event_timeout(ac->cmd_wait, |
| 1404 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 1405 | if (!rc) { |
| 1406 | pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__, |
| 1407 | rc); |
| 1408 | goto fail_cmd; |
| 1409 | } |
| 1410 | return 0; |
| 1411 | fail_cmd: |
| 1412 | return -EINVAL; |
| 1413 | } |
| 1414 | |
| 1415 | |
| Subhash Chandra Bose Naripeddy | 694b7d9 | 2012-06-20 20:46:13 -0700 | [diff] [blame] | 1416 | int q6asm_open_read_compressed(struct audio_client *ac, |
| 1417 | uint32_t frames_per_buffer, uint32_t meta_data_mode) |
| Subhash Chandra Bose Naripeddy | 8f84689 | 2012-06-12 11:29:18 -0700 | [diff] [blame] | 1418 | { |
| 1419 | int rc = 0x00; |
| 1420 | struct asm_stream_cmd_open_read_compressed open; |
| 1421 | #ifdef CONFIG_DEBUG_FS |
| 1422 | in_cont_index = 0; |
| 1423 | #endif |
| 1424 | if ((ac == NULL) || (ac->apr == NULL)) { |
| 1425 | pr_err("%s: APR handle NULL\n", __func__); |
| 1426 | return -EINVAL; |
| 1427 | } |
| 1428 | pr_debug("%s:session[%d]", __func__, ac->session); |
| 1429 | |
| 1430 | q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE); |
| 1431 | open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ_COMPRESSED; |
| 1432 | /* hardcoded as following*/ |
| Subhash Chandra Bose Naripeddy | 694b7d9 | 2012-06-20 20:46:13 -0700 | [diff] [blame] | 1433 | open.frame_per_buf = frames_per_buffer; |
| 1434 | open.uMode = meta_data_mode; |
| Subhash Chandra Bose Naripeddy | 8f84689 | 2012-06-12 11:29:18 -0700 | [diff] [blame] | 1435 | |
| 1436 | rc = apr_send_pkt(ac->apr, (uint32_t *) &open); |
| 1437 | if (rc < 0) { |
| 1438 | pr_err("open failed op[0x%x]rc[%d]\n", open.hdr.opcode, rc); |
| 1439 | goto fail_cmd; |
| 1440 | } |
| 1441 | rc = wait_event_timeout(ac->cmd_wait, |
| 1442 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 1443 | if (!rc) { |
| 1444 | pr_err("%s: timeout. waited for OPEN_READ_COMPRESSED rc[%d]\n", |
| 1445 | __func__, rc); |
| 1446 | goto fail_cmd; |
| 1447 | } |
| 1448 | return 0; |
| 1449 | fail_cmd: |
| 1450 | return -EINVAL; |
| 1451 | } |
| 1452 | |
| Santosh Mardi | 2332120 | 2012-03-22 04:33:25 +0530 | [diff] [blame] | 1453 | int q6asm_open_write_compressed(struct audio_client *ac, uint32_t format) |
| 1454 | { |
| 1455 | int rc = 0x00; |
| 1456 | struct asm_stream_cmd_open_write_compressed open; |
| 1457 | |
| 1458 | if ((ac == NULL) || (ac->apr == NULL)) { |
| 1459 | pr_err("%s: APR handle NULL\n", __func__); |
| 1460 | return -EINVAL; |
| 1461 | } |
| 1462 | pr_debug("%s: session[%d] wr_format[0x%x]", __func__, ac->session, |
| 1463 | format); |
| 1464 | |
| 1465 | q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE); |
| 1466 | |
| 1467 | open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_COMPRESSED; |
| 1468 | |
| 1469 | switch (format) { |
| 1470 | case FORMAT_AC3: |
| 1471 | open.format = AC3_DECODER; |
| 1472 | break; |
| 1473 | case FORMAT_EAC3: |
| 1474 | open.format = EAC3_DECODER; |
| 1475 | break; |
| 1476 | case FORMAT_MP3: |
| 1477 | open.format = MP3; |
| 1478 | break; |
| 1479 | case FORMAT_DTS: |
| 1480 | open.format = DTS; |
| 1481 | break; |
| Srikanth Uyyala | 66f781a | 2012-06-13 23:23:25 +0530 | [diff] [blame] | 1482 | case FORMAT_DTS_LBR: |
| 1483 | open.format = DTS_LBR; |
| 1484 | break; |
| Santosh Mardi | 2332120 | 2012-03-22 04:33:25 +0530 | [diff] [blame] | 1485 | case FORMAT_AAC: |
| 1486 | open.format = MPEG4_AAC; |
| 1487 | break; |
| 1488 | case FORMAT_ATRAC: |
| 1489 | open.format = ATRAC; |
| 1490 | break; |
| 1491 | case FORMAT_WMA_V10PRO: |
| 1492 | open.format = WMA_V10PRO; |
| 1493 | break; |
| 1494 | case FORMAT_MAT: |
| 1495 | open.format = MAT; |
| 1496 | break; |
| 1497 | default: |
| 1498 | pr_err("%s: Invalid format[%d]\n", __func__, format); |
| 1499 | goto fail_cmd; |
| 1500 | } |
| 1501 | /*Below flag indicates the DSP that Compressed audio input |
| 1502 | stream is not IEC 61937 or IEC 60958 packetizied*/ |
| 1503 | open.flags = 0x00000000; |
| 1504 | rc = apr_send_pkt(ac->apr, (uint32_t *) &open); |
| 1505 | if (rc < 0) { |
| 1506 | pr_err("%s: open failed op[0x%x]rc[%d]\n", \ |
| 1507 | __func__, open.hdr.opcode, rc); |
| 1508 | goto fail_cmd; |
| 1509 | } |
| 1510 | rc = wait_event_timeout(ac->cmd_wait, |
| 1511 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 1512 | if (!rc) { |
| 1513 | pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__, |
| 1514 | rc); |
| 1515 | goto fail_cmd; |
| 1516 | } |
| 1517 | return 0; |
| 1518 | fail_cmd: |
| 1519 | return -EINVAL; |
| 1520 | } |
| 1521 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1522 | int q6asm_open_write(struct audio_client *ac, uint32_t format) |
| 1523 | { |
| 1524 | int rc = 0x00; |
| 1525 | struct asm_stream_cmd_open_write open; |
| 1526 | |
| 1527 | if ((ac == NULL) || (ac->apr == NULL)) { |
| 1528 | pr_err("%s: APR handle NULL\n", __func__); |
| 1529 | return -EINVAL; |
| 1530 | } |
| 1531 | pr_debug("%s: session[%d] wr_format[0x%x]", __func__, ac->session, |
| 1532 | format); |
| 1533 | |
| 1534 | q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE); |
| 1535 | |
| Jayasena Sangaraboina | 99bf09c | 2012-07-17 12:03:08 -0700 | [diff] [blame] | 1536 | if (ac->perf_mode) { |
| 1537 | pr_debug("%s In Performance/lowlatency mode", __func__); |
| 1538 | open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_V2_1; |
| 1539 | open.uMode = ASM_OPEN_WRITE_PERF_MODE_BIT; |
| 1540 | /* source endpoint : matrix */ |
| 1541 | open.sink_endpoint = ASM_END_POINT_DEVICE_MATRIX; |
| 1542 | open.stream_handle = PCM_BITS_PER_SAMPLE; |
| 1543 | } else { |
| 1544 | open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE; |
| 1545 | open.uMode = STREAM_PRIORITY_HIGH; |
| 1546 | /* source endpoint : matrix */ |
| 1547 | open.sink_endpoint = ASM_END_POINT_DEVICE_MATRIX; |
| 1548 | open.stream_handle = 0x00; |
| 1549 | } |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1550 | open.post_proc_top = get_asm_topology(); |
| 1551 | if (open.post_proc_top == 0) |
| 1552 | open.post_proc_top = DEFAULT_POPP_TOPOLOGY; |
| 1553 | |
| 1554 | switch (format) { |
| 1555 | case FORMAT_LINEAR_PCM: |
| 1556 | open.format = LINEAR_PCM; |
| 1557 | break; |
| Kiran Kandi | 5e809b0 | 2012-01-31 00:24:33 -0800 | [diff] [blame] | 1558 | case FORMAT_MULTI_CHANNEL_LINEAR_PCM: |
| 1559 | open.format = MULTI_CHANNEL_PCM; |
| 1560 | break; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1561 | case FORMAT_MPEG4_AAC: |
| 1562 | open.format = MPEG4_AAC; |
| 1563 | break; |
| Bharath Ramachandramurthy | 4f71d50 | 2011-10-23 19:45:22 -0700 | [diff] [blame] | 1564 | case FORMAT_MPEG4_MULTI_AAC: |
| 1565 | open.format = MPEG4_MULTI_AAC; |
| 1566 | break; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1567 | case FORMAT_WMA_V9: |
| 1568 | open.format = WMA_V9; |
| 1569 | break; |
| 1570 | case FORMAT_WMA_V10PRO: |
| 1571 | open.format = WMA_V10PRO; |
| 1572 | break; |
| Asish Bhattacharya | 305d175 | 2011-11-01 20:38:26 +0530 | [diff] [blame] | 1573 | case FORMAT_MP3: |
| 1574 | open.format = MP3; |
| 1575 | break; |
| Srikanth Uyyala | 66f781a | 2012-06-13 23:23:25 +0530 | [diff] [blame] | 1576 | case FORMAT_DTS: |
| 1577 | open.format = DTS; |
| 1578 | break; |
| 1579 | case FORMAT_DTS_LBR: |
| 1580 | open.format = DTS_LBR; |
| 1581 | break; |
| Ajit Khare | 43fd883 | 2012-08-07 13:19:44 -0700 | [diff] [blame] | 1582 | case FORMAT_AMRWB: |
| 1583 | open.format = AMRWB_FS; |
| 1584 | pr_debug("q6asm_open_write FORMAT_AMRWB"); |
| 1585 | break; |
| 1586 | case FORMAT_AMR_WB_PLUS: |
| 1587 | open.format = AMR_WB_PLUS; |
| 1588 | pr_debug("q6asm_open_write FORMAT_AMR_WB_PLUS"); |
| 1589 | break; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1590 | default: |
| 1591 | pr_err("%s: Invalid format[%d]\n", __func__, format); |
| 1592 | goto fail_cmd; |
| 1593 | } |
| 1594 | rc = apr_send_pkt(ac->apr, (uint32_t *) &open); |
| 1595 | if (rc < 0) { |
| 1596 | pr_err("%s: open failed op[0x%x]rc[%d]\n", \ |
| 1597 | __func__, open.hdr.opcode, rc); |
| 1598 | goto fail_cmd; |
| 1599 | } |
| 1600 | rc = wait_event_timeout(ac->cmd_wait, |
| 1601 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 1602 | if (!rc) { |
| 1603 | pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__, |
| 1604 | rc); |
| 1605 | goto fail_cmd; |
| 1606 | } |
| Srikanth Uyyala | a50b51d | 2012-07-02 16:02:24 +0530 | [diff] [blame] | 1607 | if (atomic_read(&ac->cmd_response)) { |
| 1608 | pr_err("%s: format = %x not supported\n", __func__, format); |
| 1609 | goto fail_cmd; |
| 1610 | } |
| Patrick Lai | 55f54c5 | 2012-11-17 00:29:07 -0800 | [diff] [blame] | 1611 | |
| 1612 | ac->io_mode |= TUN_WRITE_IO_MODE; |
| 1613 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1614 | return 0; |
| 1615 | fail_cmd: |
| 1616 | return -EINVAL; |
| 1617 | } |
| 1618 | |
| Flemmard | 1bc7b1c | 2014-01-08 00:24:20 -0800 | [diff] [blame^] | 1619 | int q6asm_open_write_v2(struct audio_client *ac, uint32_t format, |
| 1620 | uint16_t bit_width) |
| 1621 | { |
| 1622 | int rc = 0x00; |
| 1623 | struct asm_stream_cmd_open_write_v2 open; |
| 1624 | static int if_first_open_write_v2 = 0; |
| 1625 | |
| 1626 | if ((ac == NULL) || (ac->apr == NULL)) { |
| 1627 | pr_err("%s: APR handle NULL\n", __func__); |
| 1628 | return -EINVAL; |
| 1629 | } |
| 1630 | pr_debug("%s: session[%d] wr_format[0x%x], bitwidth[%d]", |
| 1631 | __func__, ac->session, format, bit_width); |
| 1632 | |
| 1633 | |
| 1634 | if (!if_first_open_write_v2) |
| 1635 | { |
| 1636 | msleep(30); |
| 1637 | if_first_open_write_v2 = 1; |
| 1638 | } |
| 1639 | |
| 1640 | q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE); |
| 1641 | |
| 1642 | open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_V2; |
| 1643 | open.uMode = STREAM_PRIORITY_HIGH; |
| 1644 | open.bits_per_sample = bit_width; |
| 1645 | open.sink_endpoint = ASM_END_POINT_DEVICE_MATRIX; |
| 1646 | |
| 1647 | open.post_proc_top = get_asm_topology(); |
| 1648 | if (open.post_proc_top == 0) |
| 1649 | open.post_proc_top = DEFAULT_POPP_TOPOLOGY; |
| 1650 | |
| 1651 | switch (format) { |
| 1652 | case FORMAT_LINEAR_PCM: |
| 1653 | open.format = LINEAR_PCM; |
| 1654 | break; |
| 1655 | case FORMAT_MULTI_CHANNEL_LINEAR_PCM: |
| 1656 | open.format = MULTI_CHANNEL_PCM; |
| 1657 | break; |
| 1658 | case FORMAT_MPEG4_AAC: |
| 1659 | open.format = MPEG4_AAC; |
| 1660 | break; |
| 1661 | case FORMAT_MPEG4_MULTI_AAC: |
| 1662 | open.format = MPEG4_MULTI_AAC; |
| 1663 | break; |
| 1664 | case FORMAT_WMA_V9: |
| 1665 | open.format = WMA_V9; |
| 1666 | break; |
| 1667 | case FORMAT_WMA_V10PRO: |
| 1668 | open.format = WMA_V10PRO; |
| 1669 | break; |
| 1670 | case FORMAT_MP3: |
| 1671 | open.format = MP3; |
| 1672 | break; |
| 1673 | case FORMAT_DTS: |
| 1674 | open.format = DTS; |
| 1675 | break; |
| 1676 | case FORMAT_DTS_LBR: |
| 1677 | open.format = DTS_LBR; |
| 1678 | break; |
| 1679 | case FORMAT_AMRWB: |
| 1680 | open.format = AMRWB_FS; |
| 1681 | pr_debug("q6asm_open_write FORMAT_AMRWB"); |
| 1682 | break; |
| 1683 | case FORMAT_AMR_WB_PLUS: |
| 1684 | open.format = AMR_WB_PLUS; |
| 1685 | pr_debug("q6asm_open_write FORMAT_AMR_WB_PLUS"); |
| 1686 | break; |
| 1687 | default: |
| 1688 | pr_err("%s: Invalid format[%d]\n", __func__, format); |
| 1689 | goto fail_cmd; |
| 1690 | } |
| 1691 | rc = apr_send_pkt(ac->apr, (uint32_t *) &open); |
| 1692 | if (rc < 0) { |
| 1693 | pr_err("%s: open failed op[0x%x]rc[%d]\n", \ |
| 1694 | __func__, open.hdr.opcode, rc); |
| 1695 | goto fail_cmd; |
| 1696 | } |
| 1697 | rc = wait_event_timeout(ac->cmd_wait, |
| 1698 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 1699 | if (!rc) { |
| 1700 | pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__, |
| 1701 | rc); |
| 1702 | goto fail_cmd; |
| 1703 | } |
| 1704 | if (atomic_read(&ac->cmd_response)) { |
| 1705 | pr_err("%s: format = %x not supported\n", __func__, format); |
| 1706 | goto fail_cmd; |
| 1707 | } |
| 1708 | |
| 1709 | ac->io_mode |= TUN_WRITE_IO_MODE; |
| 1710 | |
| 1711 | return 0; |
| 1712 | fail_cmd: |
| 1713 | return -EINVAL; |
| 1714 | } |
| 1715 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1716 | int q6asm_open_read_write(struct audio_client *ac, |
| 1717 | uint32_t rd_format, |
| 1718 | uint32_t wr_format) |
| 1719 | { |
| 1720 | int rc = 0x00; |
| 1721 | struct asm_stream_cmd_open_read_write open; |
| 1722 | |
| 1723 | if ((ac == NULL) || (ac->apr == NULL)) { |
| 1724 | pr_err("APR handle NULL\n"); |
| 1725 | return -EINVAL; |
| 1726 | } |
| 1727 | pr_debug("%s: session[%d]", __func__, ac->session); |
| 1728 | pr_debug("wr_format[0x%x]rd_format[0x%x]", |
| 1729 | wr_format, rd_format); |
| 1730 | |
| 1731 | q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE); |
| 1732 | open.hdr.opcode = ASM_STREAM_CMD_OPEN_READWRITE; |
| 1733 | |
| Deepa Madiregama | 55cbf78 | 2011-09-10 05:44:39 +0530 | [diff] [blame] | 1734 | open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_NORMAL; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1735 | /* source endpoint : matrix */ |
| 1736 | open.post_proc_top = get_asm_topology(); |
| 1737 | if (open.post_proc_top == 0) |
| 1738 | open.post_proc_top = DEFAULT_POPP_TOPOLOGY; |
| 1739 | |
| 1740 | switch (wr_format) { |
| 1741 | case FORMAT_LINEAR_PCM: |
| 1742 | open.write_format = LINEAR_PCM; |
| 1743 | break; |
| 1744 | case FORMAT_MPEG4_AAC: |
| 1745 | open.write_format = MPEG4_AAC; |
| 1746 | break; |
| Bharath Ramachandramurthy | 4f71d50 | 2011-10-23 19:45:22 -0700 | [diff] [blame] | 1747 | case FORMAT_MPEG4_MULTI_AAC: |
| 1748 | open.write_format = MPEG4_MULTI_AAC; |
| 1749 | break; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1750 | case FORMAT_WMA_V9: |
| 1751 | open.write_format = WMA_V9; |
| 1752 | break; |
| 1753 | case FORMAT_WMA_V10PRO: |
| 1754 | open.write_format = WMA_V10PRO; |
| 1755 | break; |
| Alex Wong | 2caeecc | 2011-10-28 10:52:15 +0530 | [diff] [blame] | 1756 | case FORMAT_AMRNB: |
| 1757 | open.write_format = AMRNB_FS; |
| 1758 | break; |
| 1759 | case FORMAT_AMRWB: |
| 1760 | open.write_format = AMRWB_FS; |
| 1761 | break; |
| Ajit Khare | 7277bb7 | 2012-10-31 16:34:22 -0700 | [diff] [blame] | 1762 | case FORMAT_AMR_WB_PLUS: |
| 1763 | open.write_format = AMR_WB_PLUS; |
| 1764 | break; |
| Alex Wong | 2caeecc | 2011-10-28 10:52:15 +0530 | [diff] [blame] | 1765 | case FORMAT_V13K: |
| 1766 | open.write_format = V13K_FS; |
| 1767 | break; |
| 1768 | case FORMAT_EVRC: |
| 1769 | open.write_format = EVRC_FS; |
| 1770 | break; |
| 1771 | case FORMAT_EVRCB: |
| 1772 | open.write_format = EVRCB_FS; |
| 1773 | break; |
| 1774 | case FORMAT_EVRCWB: |
| 1775 | open.write_format = EVRCWB_FS; |
| 1776 | break; |
| 1777 | case FORMAT_MP3: |
| 1778 | open.write_format = MP3; |
| 1779 | break; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1780 | default: |
| 1781 | pr_err("Invalid format[%d]\n", wr_format); |
| 1782 | goto fail_cmd; |
| 1783 | } |
| 1784 | |
| 1785 | switch (rd_format) { |
| 1786 | case FORMAT_LINEAR_PCM: |
| 1787 | open.read_format = LINEAR_PCM; |
| 1788 | break; |
| 1789 | case FORMAT_MPEG4_AAC: |
| 1790 | open.read_format = MPEG4_AAC; |
| 1791 | break; |
| 1792 | case FORMAT_V13K: |
| 1793 | open.read_format = V13K_FS; |
| 1794 | break; |
| 1795 | case FORMAT_EVRC: |
| 1796 | open.read_format = EVRC_FS; |
| 1797 | break; |
| 1798 | case FORMAT_AMRNB: |
| 1799 | open.read_format = AMRNB_FS; |
| 1800 | break; |
| Alex Wong | 2caeecc | 2011-10-28 10:52:15 +0530 | [diff] [blame] | 1801 | case FORMAT_AMRWB: |
| 1802 | open.read_format = AMRWB_FS; |
| 1803 | break; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1804 | default: |
| 1805 | pr_err("Invalid format[%d]\n", rd_format); |
| 1806 | goto fail_cmd; |
| 1807 | } |
| 1808 | pr_debug("%s:rdformat[0x%x]wrformat[0x%x]\n", __func__, |
| 1809 | open.read_format, open.write_format); |
| 1810 | |
| 1811 | rc = apr_send_pkt(ac->apr, (uint32_t *) &open); |
| 1812 | if (rc < 0) { |
| 1813 | pr_err("open failed op[0x%x]rc[%d]\n", \ |
| 1814 | open.hdr.opcode, rc); |
| 1815 | goto fail_cmd; |
| 1816 | } |
| 1817 | rc = wait_event_timeout(ac->cmd_wait, |
| 1818 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 1819 | if (!rc) { |
| 1820 | pr_err("timeout. waited for OPEN_WRITE rc[%d]\n", rc); |
| 1821 | goto fail_cmd; |
| 1822 | } |
| 1823 | return 0; |
| 1824 | fail_cmd: |
| 1825 | return -EINVAL; |
| 1826 | } |
| 1827 | |
| Laxminath Kasam | 2082450 | 2013-01-07 14:33:56 +0530 | [diff] [blame] | 1828 | int q6asm_open_loopack(struct audio_client *ac) |
| 1829 | { |
| 1830 | int rc = 0x00; |
| 1831 | struct asm_stream_cmd_open_loopback open; |
| 1832 | |
| 1833 | if ((ac == NULL) || (ac->apr == NULL)) { |
| 1834 | pr_err("APR handle NULL\n"); |
| 1835 | return -EINVAL; |
| 1836 | } |
| 1837 | pr_debug("%s: session[%d]", __func__, ac->session); |
| 1838 | |
| 1839 | q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE); |
| 1840 | open.hdr.opcode = ASM_STREAM_CMD_OPEN_LOOPBACK; |
| 1841 | |
| 1842 | open.mode_flags = 0; |
| 1843 | open.src_endpointype = 0; |
| 1844 | open.sink_endpointype = 0; |
| 1845 | /* source endpoint : matrix */ |
| 1846 | open.postprocopo_id = get_asm_topology(); |
| 1847 | if (open.postprocopo_id == 0) |
| 1848 | open.postprocopo_id = DEFAULT_POPP_TOPOLOGY; |
| 1849 | |
| 1850 | rc = apr_send_pkt(ac->apr, (uint32_t *) &open); |
| 1851 | if (rc < 0) { |
| 1852 | pr_err("open failed op[0x%x]rc[%d]\n", \ |
| 1853 | open.hdr.opcode, rc); |
| 1854 | goto fail_cmd; |
| 1855 | } |
| 1856 | rc = wait_event_timeout(ac->cmd_wait, |
| 1857 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 1858 | if (!rc) { |
| 1859 | pr_err("timeout. waited for OPEN_WRITE rc[%d]\n", rc); |
| 1860 | goto fail_cmd; |
| 1861 | } |
| 1862 | return 0; |
| 1863 | fail_cmd: |
| 1864 | return -EINVAL; |
| 1865 | } |
| 1866 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1867 | int q6asm_run(struct audio_client *ac, uint32_t flags, |
| 1868 | uint32_t msw_ts, uint32_t lsw_ts) |
| 1869 | { |
| 1870 | struct asm_stream_cmd_run run; |
| 1871 | int rc; |
| 1872 | if (!ac || ac->apr == NULL) { |
| 1873 | pr_err("APR handle NULL\n"); |
| 1874 | return -EINVAL; |
| 1875 | } |
| 1876 | pr_debug("%s session[%d]", __func__, ac->session); |
| 1877 | q6asm_add_hdr(ac, &run.hdr, sizeof(run), TRUE); |
| 1878 | |
| 1879 | run.hdr.opcode = ASM_SESSION_CMD_RUN; |
| 1880 | run.flags = flags; |
| 1881 | run.msw_ts = msw_ts; |
| 1882 | run.lsw_ts = lsw_ts; |
| Rajesha Kini | 3498c93 | 2011-07-19 19:58:27 +0530 | [diff] [blame] | 1883 | #ifdef CONFIG_DEBUG_FS |
| 1884 | if (out_enable_flag) { |
| 1885 | do_gettimeofday(&out_cold_tv); |
| 1886 | pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",\ |
| 1887 | out_cold_tv.tv_sec, out_cold_tv.tv_usec); |
| 1888 | } |
| 1889 | #endif |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1890 | rc = apr_send_pkt(ac->apr, (uint32_t *) &run); |
| 1891 | if (rc < 0) { |
| 1892 | pr_err("Commmand run failed[%d]", rc); |
| 1893 | goto fail_cmd; |
| 1894 | } |
| 1895 | |
| 1896 | rc = wait_event_timeout(ac->cmd_wait, |
| 1897 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 1898 | if (!rc) { |
| 1899 | pr_err("timeout. waited for run success rc[%d]", rc); |
| 1900 | goto fail_cmd; |
| 1901 | } |
| 1902 | |
| 1903 | return 0; |
| 1904 | fail_cmd: |
| 1905 | return -EINVAL; |
| 1906 | } |
| 1907 | |
| 1908 | int q6asm_run_nowait(struct audio_client *ac, uint32_t flags, |
| 1909 | uint32_t msw_ts, uint32_t lsw_ts) |
| 1910 | { |
| 1911 | struct asm_stream_cmd_run run; |
| 1912 | int rc; |
| 1913 | if (!ac || ac->apr == NULL) { |
| 1914 | pr_err("%s:APR handle NULL\n", __func__); |
| 1915 | return -EINVAL; |
| 1916 | } |
| 1917 | pr_debug("session[%d]", ac->session); |
| 1918 | q6asm_add_hdr_async(ac, &run.hdr, sizeof(run), TRUE); |
| 1919 | |
| 1920 | run.hdr.opcode = ASM_SESSION_CMD_RUN; |
| 1921 | run.flags = flags; |
| 1922 | run.msw_ts = msw_ts; |
| 1923 | run.lsw_ts = lsw_ts; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1924 | rc = apr_send_pkt(ac->apr, (uint32_t *) &run); |
| 1925 | if (rc < 0) { |
| 1926 | pr_err("%s:Commmand run failed[%d]", __func__, rc); |
| 1927 | return -EINVAL; |
| 1928 | } |
| Jay Wang | 0668d106 | 2012-07-11 18:53:21 -0700 | [diff] [blame] | 1929 | atomic_inc(&ac->nowait_cmd_cnt); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1930 | return 0; |
| 1931 | } |
| 1932 | |
| 1933 | |
| 1934 | int q6asm_enc_cfg_blk_aac(struct audio_client *ac, |
| 1935 | uint32_t frames_per_buf, |
| 1936 | uint32_t sample_rate, uint32_t channels, |
| 1937 | uint32_t bit_rate, uint32_t mode, uint32_t format) |
| 1938 | { |
| 1939 | struct asm_stream_cmd_encdec_cfg_blk enc_cfg; |
| 1940 | int rc = 0; |
| 1941 | |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 1942 | pr_debug("%s:session[%d]frames[%d]SR[%d]ch[%d]bitrate[%d]mode[%d] format[%d]", |
| 1943 | __func__, ac->session, frames_per_buf, |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1944 | sample_rate, channels, bit_rate, mode, format); |
| 1945 | |
| 1946 | q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE); |
| 1947 | |
| 1948 | enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM; |
| 1949 | enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID; |
| 1950 | enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk); |
| 1951 | enc_cfg.enc_blk.frames_per_buf = frames_per_buf; |
| 1952 | enc_cfg.enc_blk.format_id = MPEG4_AAC; |
| 1953 | enc_cfg.enc_blk.cfg_size = sizeof(struct asm_aac_read_cfg); |
| 1954 | enc_cfg.enc_blk.cfg.aac.bitrate = bit_rate; |
| 1955 | enc_cfg.enc_blk.cfg.aac.enc_mode = mode; |
| 1956 | enc_cfg.enc_blk.cfg.aac.format = format; |
| 1957 | enc_cfg.enc_blk.cfg.aac.ch_cfg = channels; |
| 1958 | enc_cfg.enc_blk.cfg.aac.sample_rate = sample_rate; |
| 1959 | |
| 1960 | rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg); |
| 1961 | if (rc < 0) { |
| 1962 | pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM); |
| 1963 | rc = -EINVAL; |
| 1964 | goto fail_cmd; |
| 1965 | } |
| 1966 | rc = wait_event_timeout(ac->cmd_wait, |
| 1967 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 1968 | if (!rc) { |
| 1969 | pr_err("timeout. waited for FORMAT_UPDATE\n"); |
| 1970 | goto fail_cmd; |
| 1971 | } |
| 1972 | return 0; |
| 1973 | fail_cmd: |
| 1974 | return -EINVAL; |
| 1975 | } |
| 1976 | |
| 1977 | int q6asm_enc_cfg_blk_pcm(struct audio_client *ac, |
| 1978 | uint32_t rate, uint32_t channels) |
| 1979 | { |
| 1980 | struct asm_stream_cmd_encdec_cfg_blk enc_cfg; |
| 1981 | |
| 1982 | int rc = 0; |
| 1983 | |
| 1984 | pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__, |
| 1985 | ac->session, rate, channels); |
| 1986 | |
| 1987 | q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE); |
| 1988 | |
| 1989 | enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM; |
| 1990 | enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID; |
| 1991 | enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk); |
| 1992 | enc_cfg.enc_blk.frames_per_buf = 1; |
| 1993 | enc_cfg.enc_blk.format_id = LINEAR_PCM; |
| 1994 | enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg); |
| 1995 | enc_cfg.enc_blk.cfg.pcm.ch_cfg = channels; |
| 1996 | enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16; |
| 1997 | enc_cfg.enc_blk.cfg.pcm.sample_rate = rate; |
| 1998 | enc_cfg.enc_blk.cfg.pcm.is_signed = 1; |
| 1999 | enc_cfg.enc_blk.cfg.pcm.interleaved = 1; |
| 2000 | |
| 2001 | rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg); |
| 2002 | if (rc < 0) { |
| 2003 | pr_err("Comamnd open failed\n"); |
| 2004 | rc = -EINVAL; |
| 2005 | goto fail_cmd; |
| 2006 | } |
| 2007 | rc = wait_event_timeout(ac->cmd_wait, |
| 2008 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 2009 | if (!rc) { |
| 2010 | pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode); |
| 2011 | goto fail_cmd; |
| 2012 | } |
| 2013 | return 0; |
| 2014 | fail_cmd: |
| 2015 | return -EINVAL; |
| 2016 | } |
| 2017 | |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 2018 | int q6asm_enc_cfg_blk_pcm_native(struct audio_client *ac, |
| 2019 | uint32_t rate, uint32_t channels) |
| 2020 | { |
| 2021 | struct asm_stream_cmd_encdec_cfg_blk enc_cfg; |
| 2022 | |
| 2023 | int rc = 0; |
| 2024 | |
| 2025 | pr_debug("%s: Session %d, rate = %d, channels = %d, setting the rate and channels to 0 for native\n", |
| 2026 | __func__, ac->session, rate, channels); |
| 2027 | |
| 2028 | q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE); |
| 2029 | |
| 2030 | enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM; |
| 2031 | enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID; |
| 2032 | enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk); |
| 2033 | enc_cfg.enc_blk.frames_per_buf = 1; |
| 2034 | enc_cfg.enc_blk.format_id = LINEAR_PCM; |
| 2035 | enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg); |
| 2036 | enc_cfg.enc_blk.cfg.pcm.ch_cfg = 0;/*channels;*/ |
| 2037 | enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16; |
| 2038 | enc_cfg.enc_blk.cfg.pcm.sample_rate = 0;/*rate;*/ |
| 2039 | enc_cfg.enc_blk.cfg.pcm.is_signed = 1; |
| 2040 | enc_cfg.enc_blk.cfg.pcm.interleaved = 1; |
| 2041 | |
| 2042 | rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg); |
| 2043 | if (rc < 0) { |
| 2044 | pr_err("Comamnd open failed\n"); |
| 2045 | rc = -EINVAL; |
| 2046 | goto fail_cmd; |
| 2047 | } |
| 2048 | rc = wait_event_timeout(ac->cmd_wait, |
| 2049 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 2050 | if (!rc) { |
| 2051 | pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode); |
| 2052 | goto fail_cmd; |
| 2053 | } |
| 2054 | return 0; |
| 2055 | fail_cmd: |
| 2056 | return -EINVAL; |
| 2057 | } |
| 2058 | |
| Mingming Yin | 647e9ea | 2012-03-17 19:56:10 -0700 | [diff] [blame] | 2059 | int q6asm_enc_cfg_blk_multi_ch_pcm(struct audio_client *ac, |
| 2060 | uint32_t rate, uint32_t channels) |
| 2061 | { |
| 2062 | struct asm_stream_cmd_encdec_cfg_blk enc_cfg; |
| 2063 | |
| 2064 | int rc = 0; |
| 2065 | |
| 2066 | pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__, |
| 2067 | ac->session, rate, channels); |
| 2068 | |
| 2069 | q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE); |
| 2070 | |
| 2071 | enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM; |
| 2072 | enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID; |
| 2073 | enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk); |
| 2074 | enc_cfg.enc_blk.frames_per_buf = 1; |
| 2075 | enc_cfg.enc_blk.format_id = MULTI_CHANNEL_PCM; |
| 2076 | enc_cfg.enc_blk.cfg_size = |
| 2077 | sizeof(struct asm_multi_channel_pcm_fmt_blk); |
| 2078 | enc_cfg.enc_blk.cfg.mpcm.num_channels = channels; |
| 2079 | enc_cfg.enc_blk.cfg.mpcm.bits_per_sample = 16; |
| 2080 | enc_cfg.enc_blk.cfg.mpcm.sample_rate = rate; |
| 2081 | enc_cfg.enc_blk.cfg.mpcm.is_signed = 1; |
| 2082 | enc_cfg.enc_blk.cfg.mpcm.is_interleaved = 1; |
| Subhash Chandra Bose Naripeddy | 68d103a | 2012-08-17 21:03:19 -0700 | [diff] [blame] | 2083 | if (channels == 1) { |
| 2084 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL; |
| 2085 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = 0; |
| 2086 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = 0; |
| 2087 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = 0; |
| 2088 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0; |
| 2089 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0; |
| 2090 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0; |
| 2091 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0; |
| 2092 | } else if (channels == 2) { |
| Subhash Chandra Bose Naripeddy | 8477d22 | 2012-06-12 00:30:54 -0700 | [diff] [blame] | 2093 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL; |
| 2094 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR; |
| 2095 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = 0; |
| 2096 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = 0; |
| 2097 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0; |
| 2098 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0; |
| 2099 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0; |
| 2100 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0; |
| 2101 | } else if (channels == 4) { |
| 2102 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL; |
| 2103 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR; |
| 2104 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_RB; |
| 2105 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_LB; |
| 2106 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0; |
| 2107 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0; |
| 2108 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0; |
| 2109 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0; |
| 2110 | } else if (channels == 6) { |
| 2111 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL; |
| 2112 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR; |
| 2113 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_LFE; |
| 2114 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_FC; |
| 2115 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = PCM_CHANNEL_LB; |
| 2116 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = PCM_CHANNEL_RB; |
| 2117 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0; |
| 2118 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0; |
| 2119 | } else if (channels == 8) { |
| 2120 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL; |
| 2121 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR; |
| 2122 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_LFE; |
| 2123 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_FC; |
| 2124 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = PCM_CHANNEL_LB; |
| 2125 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = PCM_CHANNEL_RB; |
| 2126 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = PCM_CHANNEL_FLC; |
| 2127 | enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = PCM_CHANNEL_FRC; |
| 2128 | } |
| Mingming Yin | 647e9ea | 2012-03-17 19:56:10 -0700 | [diff] [blame] | 2129 | |
| 2130 | rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg); |
| 2131 | if (rc < 0) { |
| 2132 | pr_err("Comamnd open failed\n"); |
| 2133 | rc = -EINVAL; |
| 2134 | goto fail_cmd; |
| 2135 | } |
| 2136 | rc = wait_event_timeout(ac->cmd_wait, |
| 2137 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 2138 | if (!rc) { |
| 2139 | pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode); |
| 2140 | goto fail_cmd; |
| 2141 | } |
| 2142 | return 0; |
| 2143 | fail_cmd: |
| 2144 | return -EINVAL; |
| 2145 | } |
| 2146 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2147 | int q6asm_enable_sbrps(struct audio_client *ac, |
| 2148 | uint32_t sbr_ps_enable) |
| 2149 | { |
| 2150 | struct asm_stream_cmd_encdec_sbr sbrps; |
| 2151 | |
| 2152 | int rc = 0; |
| 2153 | |
| 2154 | pr_debug("%s: Session %d\n", __func__, ac->session); |
| 2155 | |
| 2156 | q6asm_add_hdr(ac, &sbrps.hdr, sizeof(sbrps), TRUE); |
| 2157 | |
| 2158 | sbrps.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM; |
| 2159 | sbrps.param_id = ASM_ENABLE_SBR_PS; |
| 2160 | sbrps.param_size = sizeof(struct asm_sbr_ps); |
| 2161 | sbrps.sbr_ps.enable = sbr_ps_enable; |
| 2162 | |
| 2163 | rc = apr_send_pkt(ac->apr, (uint32_t *) &sbrps); |
| 2164 | if (rc < 0) { |
| 2165 | pr_err("Command opcode[0x%x]paramid[0x%x] failed\n", |
| 2166 | ASM_STREAM_CMD_SET_ENCDEC_PARAM, |
| 2167 | ASM_ENABLE_SBR_PS); |
| 2168 | rc = -EINVAL; |
| 2169 | goto fail_cmd; |
| 2170 | } |
| 2171 | rc = wait_event_timeout(ac->cmd_wait, |
| 2172 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 2173 | if (!rc) { |
| 2174 | pr_err("timeout opcode[0x%x] ", sbrps.hdr.opcode); |
| 2175 | goto fail_cmd; |
| 2176 | } |
| 2177 | return 0; |
| 2178 | fail_cmd: |
| 2179 | return -EINVAL; |
| 2180 | } |
| 2181 | |
| Swaminathan Sathappan | 70765cd | 2011-07-19 18:42:47 -0700 | [diff] [blame] | 2182 | int q6asm_cfg_dual_mono_aac(struct audio_client *ac, |
| 2183 | uint16_t sce_left, uint16_t sce_right) |
| 2184 | { |
| 2185 | struct asm_stream_cmd_encdec_dualmono dual_mono; |
| 2186 | |
| 2187 | int rc = 0; |
| 2188 | |
| 2189 | pr_debug("%s: Session %d, sce_left = %d, sce_right = %d\n", |
| 2190 | __func__, ac->session, sce_left, sce_right); |
| 2191 | |
| 2192 | q6asm_add_hdr(ac, &dual_mono.hdr, sizeof(dual_mono), TRUE); |
| 2193 | |
| 2194 | dual_mono.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM; |
| 2195 | dual_mono.param_id = ASM_CONFIGURE_DUAL_MONO; |
| 2196 | dual_mono.param_size = sizeof(struct asm_dual_mono); |
| 2197 | dual_mono.channel_map.sce_left = sce_left; |
| 2198 | dual_mono.channel_map.sce_right = sce_right; |
| 2199 | |
| 2200 | rc = apr_send_pkt(ac->apr, (uint32_t *) &dual_mono); |
| 2201 | if (rc < 0) { |
| 2202 | pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n", |
| 2203 | __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM, |
| 2204 | ASM_CONFIGURE_DUAL_MONO); |
| 2205 | rc = -EINVAL; |
| 2206 | goto fail_cmd; |
| 2207 | } |
| 2208 | rc = wait_event_timeout(ac->cmd_wait, |
| 2209 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 2210 | if (!rc) { |
| 2211 | pr_err("%s:timeout opcode[0x%x]\n", __func__, |
| 2212 | dual_mono.hdr.opcode); |
| 2213 | goto fail_cmd; |
| 2214 | } |
| 2215 | return 0; |
| 2216 | fail_cmd: |
| 2217 | return -EINVAL; |
| 2218 | } |
| 2219 | |
| Amal Paul | 6e0f798 | 2013-02-21 19:36:35 -0800 | [diff] [blame] | 2220 | int q6asm_cfg_aac_sel_mix_coef(struct audio_client *ac, uint32_t mix_coeff) |
| 2221 | { |
| 2222 | struct asm_aac_stereo_mix_coeff_selection_param aac_mix_coeff; |
| 2223 | int rc = 0; |
| 2224 | q6asm_add_hdr(ac, &aac_mix_coeff.hdr, sizeof(aac_mix_coeff), TRUE); |
| 2225 | aac_mix_coeff.hdr.opcode = |
| 2226 | ASM_STREAM_CMD_SET_ENCDEC_PARAM; |
| 2227 | aac_mix_coeff.param_id = |
| 2228 | ASM_PARAM_ID_AAC_STEREO_MIX_COEFF_SELECTION_FLAG; |
| 2229 | aac_mix_coeff.param_size = |
| 2230 | sizeof(struct asm_aac_stereo_mix_coeff_selection_param); |
| 2231 | aac_mix_coeff.aac_stereo_mix_coeff_flag = mix_coeff; |
| 2232 | pr_debug("%s, mix_coeff = %u", __func__, mix_coeff); |
| 2233 | rc = apr_send_pkt(ac->apr, (uint32_t *) &aac_mix_coeff); |
| 2234 | if (rc < 0) { |
| 2235 | pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n", |
| 2236 | __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM, |
| 2237 | ASM_PARAM_ID_AAC_STEREO_MIX_COEFF_SELECTION_FLAG); |
| 2238 | rc = -EINVAL; |
| 2239 | goto fail_cmd; |
| 2240 | } |
| 2241 | rc = wait_event_timeout(ac->cmd_wait, |
| 2242 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 2243 | if (!rc) { |
| 2244 | pr_err("%s:timeout opcode[0x%x]\n", __func__, |
| 2245 | aac_mix_coeff.hdr.opcode); |
| 2246 | goto fail_cmd; |
| 2247 | } |
| 2248 | return 0; |
| 2249 | fail_cmd: |
| 2250 | return -EINVAL; |
| 2251 | } |
| 2252 | |
| Swaminathan Sathappan | 6f53088 | 2012-05-01 16:42:22 -0700 | [diff] [blame] | 2253 | int q6asm_set_encdec_chan_map(struct audio_client *ac, |
| 2254 | uint32_t num_channels) |
| 2255 | { |
| 2256 | struct asm_stream_cmd_encdec_channelmap chan_map; |
| 2257 | u8 *channel_mapping; |
| 2258 | |
| 2259 | int rc = 0; |
| 2260 | |
| 2261 | pr_debug("%s: Session %d, num_channels = %d\n", |
| 2262 | __func__, ac->session, num_channels); |
| 2263 | |
| 2264 | q6asm_add_hdr(ac, &chan_map.hdr, sizeof(chan_map), TRUE); |
| 2265 | |
| 2266 | chan_map.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM; |
| 2267 | chan_map.param_id = ASM_ENCDEC_DEC_CHAN_MAP; |
| 2268 | chan_map.param_size = sizeof(struct asm_dec_chan_map); |
| 2269 | chan_map.chan_map.num_channels = num_channels; |
| 2270 | |
| 2271 | channel_mapping = |
| 2272 | chan_map.chan_map.channel_mapping; |
| 2273 | |
| 2274 | memset(channel_mapping, PCM_CHANNEL_NULL, MAX_CHAN_MAP_CHANNELS); |
| 2275 | if (num_channels == 1) { |
| 2276 | channel_mapping[0] = PCM_CHANNEL_FL; |
| 2277 | } else if (num_channels == 2) { |
| 2278 | channel_mapping[0] = PCM_CHANNEL_FL; |
| 2279 | channel_mapping[1] = PCM_CHANNEL_FR; |
| Subhash Chandra Bose Naripeddy | 68d103a | 2012-08-17 21:03:19 -0700 | [diff] [blame] | 2280 | } else if (num_channels == 4) { |
| 2281 | channel_mapping[0] = PCM_CHANNEL_FL; |
| 2282 | channel_mapping[1] = PCM_CHANNEL_FR; |
| 2283 | channel_mapping[1] = PCM_CHANNEL_LB; |
| 2284 | channel_mapping[1] = PCM_CHANNEL_RB; |
| Swaminathan Sathappan | 6f53088 | 2012-05-01 16:42:22 -0700 | [diff] [blame] | 2285 | } else if (num_channels == 6) { |
| 2286 | channel_mapping[0] = PCM_CHANNEL_FC; |
| 2287 | channel_mapping[1] = PCM_CHANNEL_FL; |
| 2288 | channel_mapping[2] = PCM_CHANNEL_FR; |
| 2289 | channel_mapping[3] = PCM_CHANNEL_LB; |
| 2290 | channel_mapping[4] = PCM_CHANNEL_RB; |
| 2291 | channel_mapping[5] = PCM_CHANNEL_LFE; |
| Subhash Chandra Bose Naripeddy | 68d103a | 2012-08-17 21:03:19 -0700 | [diff] [blame] | 2292 | } else if (num_channels == 8) { |
| 2293 | channel_mapping[0] = PCM_CHANNEL_FC; |
| 2294 | channel_mapping[1] = PCM_CHANNEL_FL; |
| 2295 | channel_mapping[2] = PCM_CHANNEL_FR; |
| 2296 | channel_mapping[3] = PCM_CHANNEL_LB; |
| 2297 | channel_mapping[4] = PCM_CHANNEL_RB; |
| 2298 | channel_mapping[5] = PCM_CHANNEL_LFE; |
| 2299 | channel_mapping[6] = PCM_CHANNEL_FLC; |
| 2300 | channel_mapping[7] = PCM_CHANNEL_FRC; |
| Swaminathan Sathappan | 6f53088 | 2012-05-01 16:42:22 -0700 | [diff] [blame] | 2301 | } else { |
| 2302 | pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__, |
| 2303 | num_channels); |
| 2304 | rc = -EINVAL; |
| 2305 | goto fail_cmd; |
| 2306 | } |
| 2307 | |
| 2308 | rc = apr_send_pkt(ac->apr, (uint32_t *) &chan_map); |
| 2309 | if (rc < 0) { |
| 2310 | pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n", |
| 2311 | __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM, |
| 2312 | ASM_ENCDEC_DEC_CHAN_MAP); |
| 2313 | goto fail_cmd; |
| 2314 | } |
| 2315 | rc = wait_event_timeout(ac->cmd_wait, |
| 2316 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 2317 | if (!rc) { |
| 2318 | pr_err("%s:timeout opcode[0x%x]\n", __func__, |
| 2319 | chan_map.hdr.opcode); |
| 2320 | rc = -ETIMEDOUT; |
| 2321 | goto fail_cmd; |
| 2322 | } |
| 2323 | return 0; |
| 2324 | fail_cmd: |
| 2325 | return rc; |
| 2326 | } |
| 2327 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2328 | int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf, |
| 2329 | uint16_t min_rate, uint16_t max_rate, |
| 2330 | uint16_t reduced_rate_level, uint16_t rate_modulation_cmd) |
| 2331 | { |
| 2332 | struct asm_stream_cmd_encdec_cfg_blk enc_cfg; |
| 2333 | int rc = 0; |
| 2334 | |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 2335 | pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] reduced_rate_level[0x%4x]rate_modulation_cmd[0x%4x]", |
| 2336 | __func__, |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2337 | ac->session, frames_per_buf, min_rate, max_rate, |
| 2338 | reduced_rate_level, rate_modulation_cmd); |
| 2339 | |
| 2340 | q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE); |
| 2341 | |
| 2342 | enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM; |
| 2343 | |
| 2344 | enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID; |
| 2345 | enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk); |
| 2346 | |
| 2347 | enc_cfg.enc_blk.frames_per_buf = frames_per_buf; |
| 2348 | enc_cfg.enc_blk.format_id = V13K_FS; |
| 2349 | enc_cfg.enc_blk.cfg_size = sizeof(struct asm_qcelp13_read_cfg); |
| 2350 | enc_cfg.enc_blk.cfg.qcelp13.min_rate = min_rate; |
| 2351 | enc_cfg.enc_blk.cfg.qcelp13.max_rate = max_rate; |
| 2352 | enc_cfg.enc_blk.cfg.qcelp13.reduced_rate_level = reduced_rate_level; |
| 2353 | enc_cfg.enc_blk.cfg.qcelp13.rate_modulation_cmd = rate_modulation_cmd; |
| 2354 | |
| 2355 | rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg); |
| 2356 | if (rc < 0) { |
| 2357 | pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM); |
| 2358 | goto fail_cmd; |
| 2359 | } |
| 2360 | rc = wait_event_timeout(ac->cmd_wait, |
| 2361 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 2362 | if (!rc) { |
| 2363 | pr_err("timeout. waited for FORMAT_UPDATE\n"); |
| 2364 | goto fail_cmd; |
| 2365 | } |
| 2366 | return 0; |
| 2367 | fail_cmd: |
| 2368 | return -EINVAL; |
| 2369 | } |
| 2370 | |
| 2371 | int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf, |
| 2372 | uint16_t min_rate, uint16_t max_rate, |
| 2373 | uint16_t rate_modulation_cmd) |
| 2374 | { |
| 2375 | struct asm_stream_cmd_encdec_cfg_blk enc_cfg; |
| 2376 | int rc = 0; |
| 2377 | |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 2378 | pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] rate_modulation_cmd[0x%4x]", |
| 2379 | __func__, ac->session, |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2380 | frames_per_buf, min_rate, max_rate, rate_modulation_cmd); |
| 2381 | |
| 2382 | q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE); |
| 2383 | |
| 2384 | enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM; |
| 2385 | |
| 2386 | enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID; |
| 2387 | enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk); |
| 2388 | |
| 2389 | enc_cfg.enc_blk.frames_per_buf = frames_per_buf; |
| 2390 | enc_cfg.enc_blk.format_id = EVRC_FS; |
| 2391 | enc_cfg.enc_blk.cfg_size = sizeof(struct asm_evrc_read_cfg); |
| 2392 | enc_cfg.enc_blk.cfg.evrc.min_rate = min_rate; |
| 2393 | enc_cfg.enc_blk.cfg.evrc.max_rate = max_rate; |
| 2394 | enc_cfg.enc_blk.cfg.evrc.rate_modulation_cmd = rate_modulation_cmd; |
| 2395 | enc_cfg.enc_blk.cfg.evrc.reserved = 0; |
| 2396 | |
| 2397 | rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg); |
| 2398 | if (rc < 0) { |
| 2399 | pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM); |
| 2400 | goto fail_cmd; |
| 2401 | } |
| 2402 | rc = wait_event_timeout(ac->cmd_wait, |
| 2403 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 2404 | if (!rc) { |
| 2405 | pr_err("timeout. waited for FORMAT_UPDATE\n"); |
| 2406 | goto fail_cmd; |
| 2407 | } |
| 2408 | return 0; |
| 2409 | fail_cmd: |
| 2410 | return -EINVAL; |
| 2411 | } |
| 2412 | |
| 2413 | int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf, |
| 2414 | uint16_t band_mode, uint16_t dtx_enable) |
| 2415 | { |
| 2416 | struct asm_stream_cmd_encdec_cfg_blk enc_cfg; |
| 2417 | int rc = 0; |
| 2418 | |
| 2419 | pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]", |
| 2420 | __func__, ac->session, frames_per_buf, band_mode, dtx_enable); |
| 2421 | |
| 2422 | q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE); |
| 2423 | |
| 2424 | enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM; |
| 2425 | |
| 2426 | enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID; |
| 2427 | enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk); |
| 2428 | |
| 2429 | enc_cfg.enc_blk.frames_per_buf = frames_per_buf; |
| 2430 | enc_cfg.enc_blk.format_id = AMRNB_FS; |
| 2431 | enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrnb_read_cfg); |
| 2432 | enc_cfg.enc_blk.cfg.amrnb.mode = band_mode; |
| 2433 | enc_cfg.enc_blk.cfg.amrnb.dtx_mode = dtx_enable; |
| 2434 | |
| 2435 | rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg); |
| 2436 | if (rc < 0) { |
| 2437 | pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM); |
| 2438 | goto fail_cmd; |
| 2439 | } |
| 2440 | rc = wait_event_timeout(ac->cmd_wait, |
| 2441 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 2442 | if (!rc) { |
| 2443 | pr_err("timeout. waited for FORMAT_UPDATE\n"); |
| 2444 | goto fail_cmd; |
| 2445 | } |
| 2446 | return 0; |
| 2447 | fail_cmd: |
| 2448 | return -EINVAL; |
| 2449 | } |
| 2450 | |
| Alex Wong | 2caeecc | 2011-10-28 10:52:15 +0530 | [diff] [blame] | 2451 | int q6asm_enc_cfg_blk_amrwb(struct audio_client *ac, uint32_t frames_per_buf, |
| 2452 | uint16_t band_mode, uint16_t dtx_enable) |
| 2453 | { |
| 2454 | struct asm_stream_cmd_encdec_cfg_blk enc_cfg; |
| 2455 | int rc = 0; |
| 2456 | |
| 2457 | pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]", |
| 2458 | __func__, ac->session, frames_per_buf, band_mode, dtx_enable); |
| 2459 | |
| 2460 | q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE); |
| 2461 | |
| 2462 | enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM; |
| 2463 | |
| 2464 | enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID; |
| 2465 | enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk); |
| 2466 | |
| 2467 | enc_cfg.enc_blk.frames_per_buf = frames_per_buf; |
| 2468 | enc_cfg.enc_blk.format_id = AMRWB_FS; |
| 2469 | enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrwb_read_cfg); |
| 2470 | enc_cfg.enc_blk.cfg.amrwb.mode = band_mode; |
| 2471 | enc_cfg.enc_blk.cfg.amrwb.dtx_mode = dtx_enable; |
| 2472 | |
| 2473 | rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg); |
| 2474 | if (rc < 0) { |
| 2475 | pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM); |
| 2476 | goto fail_cmd; |
| 2477 | } |
| 2478 | rc = wait_event_timeout(ac->cmd_wait, |
| 2479 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 2480 | if (!rc) { |
| 2481 | pr_err("timeout. waited for FORMAT_UPDATE\n"); |
| 2482 | goto fail_cmd; |
| 2483 | } |
| 2484 | return 0; |
| 2485 | fail_cmd: |
| 2486 | return -EINVAL; |
| 2487 | } |
| 2488 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2489 | int q6asm_media_format_block_pcm(struct audio_client *ac, |
| 2490 | uint32_t rate, uint32_t channels) |
| 2491 | { |
| 2492 | struct asm_stream_media_format_update fmt; |
| 2493 | int rc = 0; |
| 2494 | |
| 2495 | pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate, |
| 2496 | channels); |
| 2497 | |
| 2498 | q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE); |
| 2499 | |
| 2500 | fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE; |
| 2501 | |
| 2502 | fmt.format = LINEAR_PCM; |
| 2503 | fmt.cfg_size = sizeof(struct asm_pcm_cfg); |
| 2504 | fmt.write_cfg.pcm_cfg.ch_cfg = channels; |
| 2505 | fmt.write_cfg.pcm_cfg.bits_per_sample = 16; |
| 2506 | fmt.write_cfg.pcm_cfg.sample_rate = rate; |
| 2507 | fmt.write_cfg.pcm_cfg.is_signed = 1; |
| 2508 | fmt.write_cfg.pcm_cfg.interleaved = 1; |
| 2509 | |
| 2510 | rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt); |
| 2511 | if (rc < 0) { |
| 2512 | pr_err("%s:Comamnd open failed\n", __func__); |
| 2513 | goto fail_cmd; |
| 2514 | } |
| 2515 | rc = wait_event_timeout(ac->cmd_wait, |
| 2516 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 2517 | if (!rc) { |
| 2518 | pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__); |
| 2519 | goto fail_cmd; |
| 2520 | } |
| 2521 | return 0; |
| 2522 | fail_cmd: |
| 2523 | return -EINVAL; |
| 2524 | } |
| 2525 | |
| Flemmard | 1bc7b1c | 2014-01-08 00:24:20 -0800 | [diff] [blame^] | 2526 | int q6asm_media_format_block_pcm_format_support(struct audio_client *ac, |
| 2527 | uint32_t rate, uint32_t channels, uint16_t bit_width) |
| 2528 | { |
| 2529 | struct asm_stream_media_format_update fmt; |
| 2530 | int rc = 0; |
| 2531 | |
| 2532 | pr_debug("%s:session[%d]rate[%d]ch[%d]bit_width[%d]\n", __func__, |
| 2533 | ac->session, rate, channels, bit_width); |
| 2534 | |
| 2535 | q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE); |
| 2536 | |
| 2537 | fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE; |
| 2538 | |
| 2539 | fmt.format = LINEAR_PCM; |
| 2540 | fmt.cfg_size = sizeof(struct asm_pcm_cfg); |
| 2541 | fmt.write_cfg.multi_ch_pcm_cfg.num_channels = channels; |
| 2542 | fmt.write_cfg.multi_ch_pcm_cfg.bits_per_sample = bit_width; |
| 2543 | fmt.write_cfg.multi_ch_pcm_cfg.sample_rate = rate; |
| 2544 | fmt.write_cfg.multi_ch_pcm_cfg.is_signed = 1; |
| 2545 | fmt.write_cfg.multi_ch_pcm_cfg.is_interleaved = 1; |
| 2546 | |
| 2547 | rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt); |
| 2548 | if (rc < 0) { |
| 2549 | pr_err("%s:Comamnd open failed\n", __func__); |
| 2550 | goto fail_cmd; |
| 2551 | } |
| 2552 | rc = wait_event_timeout(ac->cmd_wait, |
| 2553 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 2554 | if (!rc) { |
| 2555 | pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__); |
| 2556 | goto fail_cmd; |
| 2557 | } |
| 2558 | return 0; |
| 2559 | fail_cmd: |
| 2560 | return -EINVAL; |
| 2561 | } |
| 2562 | |
| Kiran Kandi | 5e809b0 | 2012-01-31 00:24:33 -0800 | [diff] [blame] | 2563 | int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac, |
| 2564 | uint32_t rate, uint32_t channels) |
| 2565 | { |
| 2566 | struct asm_stream_media_format_update fmt; |
| 2567 | u8 *channel_mapping; |
| 2568 | int rc = 0; |
| 2569 | |
| 2570 | pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate, |
| 2571 | channels); |
| 2572 | |
| 2573 | q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE); |
| 2574 | |
| 2575 | fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE; |
| 2576 | |
| 2577 | fmt.format = MULTI_CHANNEL_PCM; |
| 2578 | fmt.cfg_size = sizeof(struct asm_multi_channel_pcm_fmt_blk); |
| 2579 | fmt.write_cfg.multi_ch_pcm_cfg.num_channels = channels; |
| 2580 | fmt.write_cfg.multi_ch_pcm_cfg.bits_per_sample = 16; |
| 2581 | fmt.write_cfg.multi_ch_pcm_cfg.sample_rate = rate; |
| 2582 | fmt.write_cfg.multi_ch_pcm_cfg.is_signed = 1; |
| 2583 | fmt.write_cfg.multi_ch_pcm_cfg.is_interleaved = 1; |
| 2584 | channel_mapping = |
| 2585 | fmt.write_cfg.multi_ch_pcm_cfg.channel_mapping; |
| 2586 | |
| 2587 | memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL); |
| 2588 | |
| 2589 | if (channels == 1) { |
| 2590 | channel_mapping[0] = PCM_CHANNEL_FL; |
| 2591 | } else if (channels == 2) { |
| 2592 | channel_mapping[0] = PCM_CHANNEL_FL; |
| 2593 | channel_mapping[1] = PCM_CHANNEL_FR; |
| Subhash Chandra Bose Naripeddy | 68d103a | 2012-08-17 21:03:19 -0700 | [diff] [blame] | 2594 | } else if (channels == 4) { |
| 2595 | channel_mapping[0] = PCM_CHANNEL_FL; |
| 2596 | channel_mapping[1] = PCM_CHANNEL_FR; |
| 2597 | channel_mapping[1] = PCM_CHANNEL_LB; |
| 2598 | channel_mapping[1] = PCM_CHANNEL_RB; |
| Kiran Kandi | 5e809b0 | 2012-01-31 00:24:33 -0800 | [diff] [blame] | 2599 | } else if (channels == 6) { |
| SathishKumar Mani | 6074b77 | 2012-09-26 13:49:49 -0700 | [diff] [blame] | 2600 | channel_mapping[0] = PCM_CHANNEL_FL; |
| 2601 | channel_mapping[1] = PCM_CHANNEL_FR; |
| 2602 | channel_mapping[2] = PCM_CHANNEL_FC; |
| 2603 | channel_mapping[3] = PCM_CHANNEL_LFE; |
| 2604 | channel_mapping[4] = PCM_CHANNEL_LB; |
| 2605 | channel_mapping[5] = PCM_CHANNEL_RB; |
| Subhash Chandra Bose Naripeddy | 68d103a | 2012-08-17 21:03:19 -0700 | [diff] [blame] | 2606 | } else if (channels == 8) { |
| 2607 | channel_mapping[0] = PCM_CHANNEL_FC; |
| 2608 | channel_mapping[1] = PCM_CHANNEL_FL; |
| 2609 | channel_mapping[2] = PCM_CHANNEL_FR; |
| 2610 | channel_mapping[3] = PCM_CHANNEL_LB; |
| 2611 | channel_mapping[4] = PCM_CHANNEL_RB; |
| 2612 | channel_mapping[5] = PCM_CHANNEL_LFE; |
| 2613 | channel_mapping[6] = PCM_CHANNEL_FLC; |
| 2614 | channel_mapping[7] = PCM_CHANNEL_FRC; |
| Kiran Kandi | 5e809b0 | 2012-01-31 00:24:33 -0800 | [diff] [blame] | 2615 | } else { |
| 2616 | pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__, |
| 2617 | channels); |
| 2618 | return -EINVAL; |
| 2619 | } |
| 2620 | |
| 2621 | rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt); |
| 2622 | if (rc < 0) { |
| 2623 | pr_err("%s:Comamnd open failed\n", __func__); |
| 2624 | goto fail_cmd; |
| 2625 | } |
| 2626 | rc = wait_event_timeout(ac->cmd_wait, |
| 2627 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 2628 | if (!rc) { |
| 2629 | pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__); |
| 2630 | goto fail_cmd; |
| 2631 | } |
| 2632 | return 0; |
| 2633 | fail_cmd: |
| 2634 | return -EINVAL; |
| 2635 | } |
| 2636 | |
| Flemmard | 1bc7b1c | 2014-01-08 00:24:20 -0800 | [diff] [blame^] | 2637 | int q6asm_media_format_block_multi_ch_pcm_format_support( |
| 2638 | struct audio_client *ac, uint32_t rate, |
| 2639 | uint32_t channels, uint16_t bit_width) |
| 2640 | { |
| 2641 | struct asm_stream_media_format_update fmt; |
| 2642 | u8 *channel_mapping; |
| 2643 | int rc = 0; |
| 2644 | |
| 2645 | pr_debug("%s:session[%d]rate[%d]ch[%d]bit_width[%d]\n", __func__, |
| 2646 | ac->session, rate, channels, bit_width); |
| 2647 | |
| 2648 | q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE); |
| 2649 | |
| 2650 | fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE; |
| 2651 | |
| 2652 | fmt.format = MULTI_CHANNEL_PCM; |
| 2653 | fmt.cfg_size = sizeof(struct asm_multi_channel_pcm_fmt_blk); |
| 2654 | fmt.write_cfg.multi_ch_pcm_cfg.num_channels = channels; |
| 2655 | fmt.write_cfg.multi_ch_pcm_cfg.bits_per_sample = bit_width; |
| 2656 | fmt.write_cfg.multi_ch_pcm_cfg.sample_rate = rate; |
| 2657 | fmt.write_cfg.multi_ch_pcm_cfg.is_signed = 1; |
| 2658 | fmt.write_cfg.multi_ch_pcm_cfg.is_interleaved = 1; |
| 2659 | channel_mapping = |
| 2660 | fmt.write_cfg.multi_ch_pcm_cfg.channel_mapping; |
| 2661 | |
| 2662 | memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL); |
| 2663 | |
| 2664 | if (channels == 1) { |
| 2665 | channel_mapping[0] = PCM_CHANNEL_FL; |
| 2666 | } else if (channels == 2) { |
| 2667 | channel_mapping[0] = PCM_CHANNEL_FL; |
| 2668 | channel_mapping[1] = PCM_CHANNEL_FR; |
| 2669 | } else if (channels == 4) { |
| 2670 | channel_mapping[0] = PCM_CHANNEL_FL; |
| 2671 | channel_mapping[1] = PCM_CHANNEL_FR; |
| 2672 | channel_mapping[1] = PCM_CHANNEL_LB; |
| 2673 | channel_mapping[1] = PCM_CHANNEL_RB; |
| 2674 | } else if (channels == 6) { |
| 2675 | channel_mapping[0] = PCM_CHANNEL_FL; |
| 2676 | channel_mapping[1] = PCM_CHANNEL_FR; |
| 2677 | channel_mapping[2] = PCM_CHANNEL_FC; |
| 2678 | channel_mapping[3] = PCM_CHANNEL_LFE; |
| 2679 | channel_mapping[4] = PCM_CHANNEL_LB; |
| 2680 | channel_mapping[5] = PCM_CHANNEL_RB; |
| 2681 | } else if (channels == 8) { |
| 2682 | channel_mapping[0] = PCM_CHANNEL_FC; |
| 2683 | channel_mapping[1] = PCM_CHANNEL_FL; |
| 2684 | channel_mapping[2] = PCM_CHANNEL_FR; |
| 2685 | channel_mapping[3] = PCM_CHANNEL_LB; |
| 2686 | channel_mapping[4] = PCM_CHANNEL_RB; |
| 2687 | channel_mapping[5] = PCM_CHANNEL_LFE; |
| 2688 | channel_mapping[6] = PCM_CHANNEL_FLC; |
| 2689 | channel_mapping[7] = PCM_CHANNEL_FRC; |
| 2690 | } else { |
| 2691 | pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__, |
| 2692 | channels); |
| 2693 | return -EINVAL; |
| 2694 | } |
| 2695 | |
| 2696 | rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt); |
| 2697 | if (rc < 0) { |
| 2698 | pr_err("%s:Comamnd open failed\n", __func__); |
| 2699 | goto fail_cmd; |
| 2700 | } |
| 2701 | rc = wait_event_timeout(ac->cmd_wait, |
| 2702 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 2703 | if (!rc) { |
| 2704 | pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__); |
| 2705 | goto fail_cmd; |
| 2706 | } |
| 2707 | return 0; |
| 2708 | fail_cmd: |
| 2709 | return -EINVAL; |
| 2710 | } |
| 2711 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2712 | int q6asm_media_format_block_aac(struct audio_client *ac, |
| 2713 | struct asm_aac_cfg *cfg) |
| 2714 | { |
| 2715 | struct asm_stream_media_format_update fmt; |
| 2716 | int rc = 0; |
| 2717 | |
| 2718 | pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, |
| 2719 | cfg->sample_rate, cfg->ch_cfg); |
| 2720 | |
| 2721 | q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE); |
| 2722 | |
| 2723 | fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE; |
| 2724 | |
| 2725 | fmt.format = MPEG4_AAC; |
| 2726 | fmt.cfg_size = sizeof(struct asm_aac_cfg); |
| 2727 | fmt.write_cfg.aac_cfg.format = cfg->format; |
| 2728 | fmt.write_cfg.aac_cfg.aot = cfg->aot; |
| 2729 | fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config; |
| 2730 | fmt.write_cfg.aac_cfg.section_data_resilience = |
| 2731 | cfg->section_data_resilience; |
| 2732 | fmt.write_cfg.aac_cfg.scalefactor_data_resilience = |
| 2733 | cfg->scalefactor_data_resilience; |
| 2734 | fmt.write_cfg.aac_cfg.spectral_data_resilience = |
| 2735 | cfg->spectral_data_resilience; |
| 2736 | fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg; |
| 2737 | fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate; |
| 2738 | pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n", |
| 2739 | __func__, fmt.format, fmt.cfg_size, |
| 2740 | fmt.write_cfg.aac_cfg.format, |
| 2741 | fmt.write_cfg.aac_cfg.aot, |
| 2742 | fmt.write_cfg.aac_cfg.ch_cfg, |
| 2743 | fmt.write_cfg.aac_cfg.sample_rate); |
| 2744 | rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt); |
| 2745 | if (rc < 0) { |
| 2746 | pr_err("%s:Comamnd open failed\n", __func__); |
| 2747 | goto fail_cmd; |
| 2748 | } |
| 2749 | rc = wait_event_timeout(ac->cmd_wait, |
| 2750 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 2751 | if (!rc) { |
| 2752 | pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__); |
| 2753 | goto fail_cmd; |
| 2754 | } |
| 2755 | return 0; |
| 2756 | fail_cmd: |
| 2757 | return -EINVAL; |
| 2758 | } |
| 2759 | |
| Ajit Khare | 43fd883 | 2012-08-07 13:19:44 -0700 | [diff] [blame] | 2760 | int q6asm_media_format_block_amrwbplus(struct audio_client *ac, |
| 2761 | struct asm_amrwbplus_cfg *cfg) |
| 2762 | { |
| 2763 | struct asm_stream_media_format_update fmt; |
| 2764 | int rc = 0; |
| 2765 | pr_debug("q6asm_media_format_block_amrwbplus"); |
| Bharath Ramachandramurthy | 4f71d50 | 2011-10-23 19:45:22 -0700 | [diff] [blame] | 2766 | |
| Ajit Khare | 43fd883 | 2012-08-07 13:19:44 -0700 | [diff] [blame] | 2767 | pr_debug("%s:session[%d]band-mode[%d]frame-fmt[%d]ch[%d]\n", |
| 2768 | __func__, |
| 2769 | ac->session, |
| 2770 | cfg->amr_band_mode, |
| 2771 | cfg->amr_frame_fmt, |
| 2772 | cfg->num_channels); |
| 2773 | |
| 2774 | q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE); |
| 2775 | |
| 2776 | fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE; |
| 2777 | |
| 2778 | fmt.format = AMR_WB_PLUS; |
| 2779 | fmt.cfg_size = cfg->size_bytes; |
| 2780 | |
| 2781 | fmt.write_cfg.amrwbplus_cfg.size_bytes = cfg->size_bytes; |
| 2782 | fmt.write_cfg.amrwbplus_cfg.version = cfg->version; |
| 2783 | fmt.write_cfg.amrwbplus_cfg.num_channels = cfg->num_channels; |
| 2784 | fmt.write_cfg.amrwbplus_cfg.amr_band_mode = cfg->amr_band_mode; |
| 2785 | fmt.write_cfg.amrwbplus_cfg.amr_dtx_mode = cfg->amr_dtx_mode; |
| 2786 | fmt.write_cfg.amrwbplus_cfg.amr_frame_fmt = cfg->amr_frame_fmt; |
| 2787 | fmt.write_cfg.amrwbplus_cfg.amr_lsf_idx = cfg->amr_lsf_idx; |
| 2788 | |
| 2789 | pr_debug("%s: num_channels=%x amr_band_mode=%d amr_frame_fmt=%d\n", |
| 2790 | __func__, |
| 2791 | cfg->num_channels, |
| 2792 | cfg->amr_band_mode, |
| 2793 | cfg->amr_frame_fmt); |
| 2794 | |
| 2795 | rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt); |
| 2796 | if (rc < 0) { |
| 2797 | pr_err("%s:Comamnd media format update failed..\n", __func__); |
| 2798 | goto fail_cmd; |
| 2799 | } |
| 2800 | rc = wait_event_timeout(ac->cmd_wait, |
| 2801 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 2802 | if (!rc) { |
| 2803 | pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__); |
| 2804 | goto fail_cmd; |
| 2805 | } |
| 2806 | return 0; |
| 2807 | fail_cmd: |
| 2808 | return -EINVAL; |
| 2809 | } |
| Bharath Ramachandramurthy | 4f71d50 | 2011-10-23 19:45:22 -0700 | [diff] [blame] | 2810 | int q6asm_media_format_block_multi_aac(struct audio_client *ac, |
| 2811 | struct asm_aac_cfg *cfg) |
| 2812 | { |
| 2813 | struct asm_stream_media_format_update fmt; |
| 2814 | int rc = 0; |
| 2815 | |
| 2816 | pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, |
| 2817 | cfg->sample_rate, cfg->ch_cfg); |
| 2818 | |
| 2819 | q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE); |
| 2820 | |
| 2821 | fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE; |
| 2822 | |
| 2823 | fmt.format = MPEG4_MULTI_AAC; |
| 2824 | fmt.cfg_size = sizeof(struct asm_aac_cfg); |
| 2825 | fmt.write_cfg.aac_cfg.format = cfg->format; |
| 2826 | fmt.write_cfg.aac_cfg.aot = cfg->aot; |
| 2827 | fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config; |
| 2828 | fmt.write_cfg.aac_cfg.section_data_resilience = |
| 2829 | cfg->section_data_resilience; |
| 2830 | fmt.write_cfg.aac_cfg.scalefactor_data_resilience = |
| 2831 | cfg->scalefactor_data_resilience; |
| 2832 | fmt.write_cfg.aac_cfg.spectral_data_resilience = |
| 2833 | cfg->spectral_data_resilience; |
| 2834 | fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg; |
| 2835 | fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate; |
| 2836 | pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n", |
| 2837 | __func__, fmt.format, fmt.cfg_size, |
| 2838 | fmt.write_cfg.aac_cfg.format, |
| 2839 | fmt.write_cfg.aac_cfg.aot, |
| 2840 | fmt.write_cfg.aac_cfg.ch_cfg, |
| 2841 | fmt.write_cfg.aac_cfg.sample_rate); |
| 2842 | rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt); |
| 2843 | if (rc < 0) { |
| 2844 | pr_err("%s:Comamnd open failed\n", __func__); |
| 2845 | goto fail_cmd; |
| 2846 | } |
| 2847 | rc = wait_event_timeout(ac->cmd_wait, |
| 2848 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 2849 | if (!rc) { |
| 2850 | pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__); |
| 2851 | goto fail_cmd; |
| 2852 | } |
| 2853 | return 0; |
| 2854 | fail_cmd: |
| 2855 | return -EINVAL; |
| 2856 | } |
| 2857 | |
| 2858 | |
| Alex Wong | 2caeecc | 2011-10-28 10:52:15 +0530 | [diff] [blame] | 2859 | |
| 2860 | int q6asm_media_format_block(struct audio_client *ac, uint32_t format) |
| 2861 | { |
| 2862 | |
| 2863 | struct asm_stream_media_format_update fmt; |
| 2864 | int rc = 0; |
| 2865 | |
| 2866 | pr_debug("%s:session[%d] format[0x%x]\n", __func__, |
| 2867 | ac->session, format); |
| 2868 | |
| 2869 | q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE); |
| 2870 | fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE; |
| Asish Bhattacharya | 305d175 | 2011-11-01 20:38:26 +0530 | [diff] [blame] | 2871 | switch (format) { |
| 2872 | case FORMAT_V13K: |
| 2873 | fmt.format = V13K_FS; |
| 2874 | break; |
| 2875 | case FORMAT_EVRC: |
| 2876 | fmt.format = EVRC_FS; |
| 2877 | break; |
| 2878 | case FORMAT_AMRWB: |
| 2879 | fmt.format = AMRWB_FS; |
| 2880 | break; |
| Ajit Khare | 43fd883 | 2012-08-07 13:19:44 -0700 | [diff] [blame] | 2881 | case FORMAT_AMR_WB_PLUS: |
| 2882 | fmt.format = AMR_WB_PLUS; |
| 2883 | break; |
| Asish Bhattacharya | 305d175 | 2011-11-01 20:38:26 +0530 | [diff] [blame] | 2884 | case FORMAT_AMRNB: |
| 2885 | fmt.format = AMRNB_FS; |
| 2886 | break; |
| 2887 | case FORMAT_MP3: |
| 2888 | fmt.format = MP3; |
| 2889 | break; |
| Srikanth Uyyala | 66f781a | 2012-06-13 23:23:25 +0530 | [diff] [blame] | 2890 | case FORMAT_DTS: |
| 2891 | fmt.format = DTS; |
| 2892 | break; |
| 2893 | case FORMAT_DTS_LBR: |
| 2894 | fmt.format = DTS_LBR; |
| 2895 | break; |
| Asish Bhattacharya | 305d175 | 2011-11-01 20:38:26 +0530 | [diff] [blame] | 2896 | default: |
| 2897 | pr_err("Invalid format[%d]\n", format); |
| 2898 | goto fail_cmd; |
| 2899 | } |
| Alex Wong | 2caeecc | 2011-10-28 10:52:15 +0530 | [diff] [blame] | 2900 | fmt.cfg_size = 0; |
| 2901 | |
| 2902 | rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt); |
| 2903 | if (rc < 0) { |
| 2904 | pr_err("%s:Comamnd open failed\n", __func__); |
| 2905 | goto fail_cmd; |
| 2906 | } |
| 2907 | rc = wait_event_timeout(ac->cmd_wait, |
| 2908 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 2909 | if (!rc) { |
| 2910 | pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__); |
| 2911 | goto fail_cmd; |
| 2912 | } |
| 2913 | return 0; |
| 2914 | fail_cmd: |
| 2915 | return -EINVAL; |
| 2916 | } |
| 2917 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2918 | int q6asm_media_format_block_wma(struct audio_client *ac, |
| 2919 | void *cfg) |
| 2920 | { |
| 2921 | struct asm_stream_media_format_update fmt; |
| 2922 | struct asm_wma_cfg *wma_cfg = (struct asm_wma_cfg *)cfg; |
| 2923 | int rc = 0; |
| 2924 | |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 2925 | pr_debug("session[%d]format_tag[0x%4x] rate[%d] ch[0x%4x] bps[%d], balign[0x%4x], bit_sample[0x%4x], ch_msk[%d], enc_opt[0x%4x]\n", |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2926 | ac->session, wma_cfg->format_tag, wma_cfg->sample_rate, |
| 2927 | wma_cfg->ch_cfg, wma_cfg->avg_bytes_per_sec, |
| 2928 | wma_cfg->block_align, wma_cfg->valid_bits_per_sample, |
| 2929 | wma_cfg->ch_mask, wma_cfg->encode_opt); |
| 2930 | |
| 2931 | q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE); |
| 2932 | |
| 2933 | fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE; |
| 2934 | |
| 2935 | fmt.format = WMA_V9; |
| 2936 | fmt.cfg_size = sizeof(struct asm_wma_cfg); |
| 2937 | fmt.write_cfg.wma_cfg.format_tag = wma_cfg->format_tag; |
| 2938 | fmt.write_cfg.wma_cfg.ch_cfg = wma_cfg->ch_cfg; |
| 2939 | fmt.write_cfg.wma_cfg.sample_rate = wma_cfg->sample_rate; |
| 2940 | fmt.write_cfg.wma_cfg.avg_bytes_per_sec = wma_cfg->avg_bytes_per_sec; |
| 2941 | fmt.write_cfg.wma_cfg.block_align = wma_cfg->block_align; |
| 2942 | fmt.write_cfg.wma_cfg.valid_bits_per_sample = |
| 2943 | wma_cfg->valid_bits_per_sample; |
| 2944 | fmt.write_cfg.wma_cfg.ch_mask = wma_cfg->ch_mask; |
| 2945 | fmt.write_cfg.wma_cfg.encode_opt = wma_cfg->encode_opt; |
| 2946 | fmt.write_cfg.wma_cfg.adv_encode_opt = 0; |
| 2947 | fmt.write_cfg.wma_cfg.adv_encode_opt2 = 0; |
| 2948 | fmt.write_cfg.wma_cfg.drc_peak_ref = 0; |
| 2949 | fmt.write_cfg.wma_cfg.drc_peak_target = 0; |
| 2950 | fmt.write_cfg.wma_cfg.drc_ave_ref = 0; |
| 2951 | fmt.write_cfg.wma_cfg.drc_ave_target = 0; |
| 2952 | |
| 2953 | rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt); |
| 2954 | if (rc < 0) { |
| 2955 | pr_err("%s:Comamnd open failed\n", __func__); |
| 2956 | goto fail_cmd; |
| 2957 | } |
| 2958 | rc = wait_event_timeout(ac->cmd_wait, |
| 2959 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 2960 | if (!rc) { |
| 2961 | pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__); |
| 2962 | goto fail_cmd; |
| 2963 | } |
| 2964 | return 0; |
| 2965 | fail_cmd: |
| 2966 | return -EINVAL; |
| 2967 | } |
| 2968 | |
| 2969 | int q6asm_media_format_block_wmapro(struct audio_client *ac, |
| 2970 | void *cfg) |
| 2971 | { |
| 2972 | struct asm_stream_media_format_update fmt; |
| 2973 | struct asm_wmapro_cfg *wmapro_cfg = (struct asm_wmapro_cfg *)cfg; |
| 2974 | int rc = 0; |
| 2975 | |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 2976 | pr_debug("session[%d]format_tag[0x%4x] rate[%d] ch[0x%4x] bps[%d], balign[0x%4x], bit_sample[0x%4x], ch_msk[%d], enc_opt[0x%4x], adv_enc_opt[0x%4x], adv_enc_opt2[0x%8x]\n", |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2977 | ac->session, wmapro_cfg->format_tag, wmapro_cfg->sample_rate, |
| 2978 | wmapro_cfg->ch_cfg, wmapro_cfg->avg_bytes_per_sec, |
| 2979 | wmapro_cfg->block_align, wmapro_cfg->valid_bits_per_sample, |
| 2980 | wmapro_cfg->ch_mask, wmapro_cfg->encode_opt, |
| 2981 | wmapro_cfg->adv_encode_opt, wmapro_cfg->adv_encode_opt2); |
| 2982 | |
| 2983 | q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE); |
| 2984 | |
| 2985 | fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE; |
| 2986 | |
| 2987 | fmt.format = WMA_V10PRO; |
| 2988 | fmt.cfg_size = sizeof(struct asm_wmapro_cfg); |
| 2989 | fmt.write_cfg.wmapro_cfg.format_tag = wmapro_cfg->format_tag; |
| 2990 | fmt.write_cfg.wmapro_cfg.ch_cfg = wmapro_cfg->ch_cfg; |
| 2991 | fmt.write_cfg.wmapro_cfg.sample_rate = wmapro_cfg->sample_rate; |
| 2992 | fmt.write_cfg.wmapro_cfg.avg_bytes_per_sec = |
| 2993 | wmapro_cfg->avg_bytes_per_sec; |
| 2994 | fmt.write_cfg.wmapro_cfg.block_align = wmapro_cfg->block_align; |
| 2995 | fmt.write_cfg.wmapro_cfg.valid_bits_per_sample = |
| 2996 | wmapro_cfg->valid_bits_per_sample; |
| 2997 | fmt.write_cfg.wmapro_cfg.ch_mask = wmapro_cfg->ch_mask; |
| 2998 | fmt.write_cfg.wmapro_cfg.encode_opt = wmapro_cfg->encode_opt; |
| 2999 | fmt.write_cfg.wmapro_cfg.adv_encode_opt = wmapro_cfg->adv_encode_opt; |
| 3000 | fmt.write_cfg.wmapro_cfg.adv_encode_opt2 = wmapro_cfg->adv_encode_opt2; |
| 3001 | fmt.write_cfg.wmapro_cfg.drc_peak_ref = 0; |
| 3002 | fmt.write_cfg.wmapro_cfg.drc_peak_target = 0; |
| 3003 | fmt.write_cfg.wmapro_cfg.drc_ave_ref = 0; |
| 3004 | fmt.write_cfg.wmapro_cfg.drc_ave_target = 0; |
| 3005 | |
| 3006 | rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt); |
| 3007 | if (rc < 0) { |
| 3008 | pr_err("%s:Comamnd open failed\n", __func__); |
| 3009 | goto fail_cmd; |
| 3010 | } |
| 3011 | rc = wait_event_timeout(ac->cmd_wait, |
| 3012 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 3013 | if (!rc) { |
| 3014 | pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__); |
| 3015 | goto fail_cmd; |
| 3016 | } |
| 3017 | return 0; |
| 3018 | fail_cmd: |
| 3019 | return -EINVAL; |
| 3020 | } |
| 3021 | |
| 3022 | int q6asm_memory_map(struct audio_client *ac, uint32_t buf_add, int dir, |
| 3023 | uint32_t bufsz, uint32_t bufcnt) |
| 3024 | { |
| 3025 | struct asm_stream_cmd_memory_map mem_map; |
| 3026 | int rc = 0; |
| 3027 | |
| 3028 | if (!ac || ac->apr == NULL || this_mmap.apr == NULL) { |
| 3029 | pr_err("APR handle NULL\n"); |
| 3030 | return -EINVAL; |
| 3031 | } |
| 3032 | |
| 3033 | pr_debug("%s: Session[%d]\n", __func__, ac->session); |
| 3034 | |
| 3035 | mem_map.hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP; |
| 3036 | |
| 3037 | mem_map.buf_add = buf_add; |
| 3038 | mem_map.buf_size = bufsz * bufcnt; |
| 3039 | mem_map.mempool_id = 0; /* EBI */ |
| 3040 | mem_map.reserved = 0; |
| 3041 | |
| Deepa Madiregama | 636f80e | 2013-01-17 14:01:25 +0530 | [diff] [blame] | 3042 | pr_debug("%s: audio_client addr %x\n", __func__, (uint32_t)ac); |
| 3043 | mem_map.hdr.token = (uint32_t)ac; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3044 | q6asm_add_mmaphdr(&mem_map.hdr, |
| 3045 | sizeof(struct asm_stream_cmd_memory_map), TRUE); |
| 3046 | |
| 3047 | pr_debug("buf add[%x] buf_add_parameter[%x]\n", |
| 3048 | mem_map.buf_add, buf_add); |
| 3049 | |
| 3050 | rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_map); |
| 3051 | if (rc < 0) { |
| 3052 | pr_err("mem_map op[0x%x]rc[%d]\n", |
| 3053 | mem_map.hdr.opcode, rc); |
| 3054 | rc = -EINVAL; |
| 3055 | goto fail_cmd; |
| 3056 | } |
| 3057 | |
| Deepa Madiregama | 636f80e | 2013-01-17 14:01:25 +0530 | [diff] [blame] | 3058 | rc = wait_event_timeout(ac->cmd_wait, |
| 3059 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3060 | if (!rc) { |
| 3061 | pr_err("timeout. waited for memory_map\n"); |
| 3062 | rc = -EINVAL; |
| 3063 | goto fail_cmd; |
| 3064 | } |
| Deepa Madiregama | 636f80e | 2013-01-17 14:01:25 +0530 | [diff] [blame] | 3065 | if (atomic_read(&ac->cmd_response)) { |
| 3066 | pr_err("%s: ASM_SESSION_CMD_MEMORY_MAP cmd failed\n", __func__); |
| 3067 | rc = -EINVAL; |
| 3068 | goto fail_cmd; |
| 3069 | } |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3070 | rc = 0; |
| Deepa Madiregama | 636f80e | 2013-01-17 14:01:25 +0530 | [diff] [blame] | 3071 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3072 | fail_cmd: |
| 3073 | return rc; |
| 3074 | } |
| 3075 | |
| 3076 | int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add, int dir) |
| 3077 | { |
| 3078 | struct asm_stream_cmd_memory_unmap mem_unmap; |
| 3079 | int rc = 0; |
| 3080 | |
| 3081 | if (!ac || ac->apr == NULL || this_mmap.apr == NULL) { |
| 3082 | pr_err("APR handle NULL\n"); |
| 3083 | return -EINVAL; |
| 3084 | } |
| 3085 | pr_debug("%s: Session[%d]\n", __func__, ac->session); |
| 3086 | |
| Deepa Madiregama | 636f80e | 2013-01-17 14:01:25 +0530 | [diff] [blame] | 3087 | pr_debug("%s: audio_client addr %x\n", __func__, (uint32_t)ac); |
| 3088 | mem_unmap.hdr.token = (uint32_t)ac; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3089 | q6asm_add_mmaphdr(&mem_unmap.hdr, |
| 3090 | sizeof(struct asm_stream_cmd_memory_unmap), TRUE); |
| 3091 | mem_unmap.hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP; |
| 3092 | mem_unmap.buf_add = buf_add; |
| 3093 | |
| 3094 | rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_unmap); |
| 3095 | if (rc < 0) { |
| 3096 | pr_err("mem_unmap op[0x%x]rc[%d]\n", |
| 3097 | mem_unmap.hdr.opcode, rc); |
| 3098 | rc = -EINVAL; |
| 3099 | goto fail_cmd; |
| 3100 | } |
| 3101 | |
| Deepa Madiregama | 636f80e | 2013-01-17 14:01:25 +0530 | [diff] [blame] | 3102 | rc = wait_event_timeout(ac->cmd_wait, |
| 3103 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3104 | if (!rc) { |
| Deepa Madiregama | 636f80e | 2013-01-17 14:01:25 +0530 | [diff] [blame] | 3105 | pr_err("timeout. waited for memory_unmap\n"); |
| 3106 | rc = -EINVAL; |
| 3107 | goto fail_cmd; |
| 3108 | } |
| 3109 | if (atomic_read(&ac->cmd_response)) { |
| 3110 | pr_err("%s: ASM_SESSION_CMD_MEMORY_UNMAP cmd failed\n", |
| 3111 | __func__); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3112 | rc = -EINVAL; |
| 3113 | goto fail_cmd; |
| 3114 | } |
| 3115 | rc = 0; |
| Deepa Madiregama | 636f80e | 2013-01-17 14:01:25 +0530 | [diff] [blame] | 3116 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3117 | fail_cmd: |
| 3118 | return rc; |
| 3119 | } |
| 3120 | |
| 3121 | int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain) |
| 3122 | { |
| 3123 | void *vol_cmd = NULL; |
| 3124 | void *payload = NULL; |
| 3125 | struct asm_pp_params_command *cmd = NULL; |
| 3126 | struct asm_lrchannel_gain_params *lrgain = NULL; |
| 3127 | int sz = 0; |
| 3128 | int rc = 0; |
| 3129 | |
| 3130 | sz = sizeof(struct asm_pp_params_command) + |
| 3131 | + sizeof(struct asm_lrchannel_gain_params); |
| 3132 | vol_cmd = kzalloc(sz, GFP_KERNEL); |
| 3133 | if (vol_cmd == NULL) { |
| 3134 | pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session); |
| 3135 | rc = -EINVAL; |
| 3136 | return rc; |
| 3137 | } |
| 3138 | cmd = (struct asm_pp_params_command *)vol_cmd; |
| 3139 | q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE); |
| 3140 | cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS; |
| 3141 | cmd->payload = NULL; |
| 3142 | cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) + |
| 3143 | sizeof(struct asm_lrchannel_gain_params); |
| 3144 | cmd->params.module_id = VOLUME_CONTROL_MODULE_ID; |
| 3145 | cmd->params.param_id = L_R_CHANNEL_GAIN_PARAM_ID; |
| 3146 | cmd->params.param_size = sizeof(struct asm_lrchannel_gain_params); |
| 3147 | cmd->params.reserved = 0; |
| 3148 | |
| 3149 | payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command)); |
| 3150 | lrgain = (struct asm_lrchannel_gain_params *)payload; |
| 3151 | |
| 3152 | lrgain->left_gain = left_gain; |
| 3153 | lrgain->right_gain = right_gain; |
| 3154 | rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd); |
| 3155 | if (rc < 0) { |
| 3156 | pr_err("%s: Volume Command failed\n", __func__); |
| 3157 | rc = -EINVAL; |
| 3158 | goto fail_cmd; |
| 3159 | } |
| 3160 | |
| 3161 | rc = wait_event_timeout(ac->cmd_wait, |
| 3162 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 3163 | if (!rc) { |
| 3164 | pr_err("%s: timeout in sending volume command to apr\n", |
| 3165 | __func__); |
| 3166 | rc = -EINVAL; |
| 3167 | goto fail_cmd; |
| 3168 | } |
| 3169 | rc = 0; |
| 3170 | fail_cmd: |
| 3171 | kfree(vol_cmd); |
| 3172 | return rc; |
| 3173 | } |
| 3174 | |
| 3175 | static int q6asm_memory_map_regions(struct audio_client *ac, int dir, |
| 3176 | uint32_t bufsz, uint32_t bufcnt) |
| 3177 | { |
| 3178 | struct asm_stream_cmd_memory_map_regions *mmap_regions = NULL; |
| 3179 | struct asm_memory_map_regions *mregions = NULL; |
| 3180 | struct audio_port_data *port = NULL; |
| 3181 | struct audio_buffer *ab = NULL; |
| 3182 | void *mmap_region_cmd = NULL; |
| 3183 | void *payload = NULL; |
| 3184 | int rc = 0; |
| 3185 | int i = 0; |
| 3186 | int cmd_size = 0; |
| 3187 | |
| 3188 | if (!ac || ac->apr == NULL || this_mmap.apr == NULL) { |
| 3189 | pr_err("APR handle NULL\n"); |
| 3190 | return -EINVAL; |
| 3191 | } |
| 3192 | pr_debug("%s: Session[%d]\n", __func__, ac->session); |
| 3193 | |
| 3194 | cmd_size = sizeof(struct asm_stream_cmd_memory_map_regions) |
| 3195 | + sizeof(struct asm_memory_map_regions) * bufcnt; |
| 3196 | |
| 3197 | mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL); |
| Vasudeva Rao Thumati | 86edf6c | 2011-07-06 16:25:13 +0530 | [diff] [blame] | 3198 | if (mmap_region_cmd == NULL) { |
| 3199 | pr_err("%s: Mem alloc failed\n", __func__); |
| 3200 | rc = -EINVAL; |
| 3201 | return rc; |
| 3202 | } |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3203 | mmap_regions = (struct asm_stream_cmd_memory_map_regions *) |
| 3204 | mmap_region_cmd; |
| Deepa Madiregama | 636f80e | 2013-01-17 14:01:25 +0530 | [diff] [blame] | 3205 | mmap_regions->hdr.token = (uint32_t)ac; |
| 3206 | pr_debug("%s: audio_client addr %x\n", __func__, (uint32_t)ac); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3207 | q6asm_add_mmaphdr(&mmap_regions->hdr, cmd_size, TRUE); |
| 3208 | mmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP_REGIONS; |
| 3209 | mmap_regions->mempool_id = 0; |
| 3210 | mmap_regions->nregions = bufcnt & 0x00ff; |
| 3211 | pr_debug("map_regions->nregions = %d\n", mmap_regions->nregions); |
| 3212 | payload = ((u8 *) mmap_region_cmd + |
| 3213 | sizeof(struct asm_stream_cmd_memory_map_regions)); |
| 3214 | mregions = (struct asm_memory_map_regions *)payload; |
| 3215 | |
| 3216 | port = &ac->port[dir]; |
| 3217 | for (i = 0; i < bufcnt; i++) { |
| 3218 | ab = &port->buf[i]; |
| 3219 | mregions->phys = ab->phys; |
| 3220 | mregions->buf_size = ab->size; |
| 3221 | ++mregions; |
| 3222 | } |
| 3223 | |
| 3224 | rc = apr_send_pkt(this_mmap.apr, (uint32_t *) mmap_region_cmd); |
| 3225 | if (rc < 0) { |
| 3226 | pr_err("mmap_regions op[0x%x]rc[%d]\n", |
| 3227 | mmap_regions->hdr.opcode, rc); |
| 3228 | rc = -EINVAL; |
| 3229 | goto fail_cmd; |
| 3230 | } |
| 3231 | |
| Deepa Madiregama | 636f80e | 2013-01-17 14:01:25 +0530 | [diff] [blame] | 3232 | rc = wait_event_timeout(ac->cmd_wait, |
| 3233 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3234 | if (!rc) { |
| Deepa Madiregama | 636f80e | 2013-01-17 14:01:25 +0530 | [diff] [blame] | 3235 | pr_err("timeout. waited for map_regions\n"); |
| 3236 | rc = -EINVAL; |
| 3237 | goto fail_cmd; |
| 3238 | } |
| 3239 | if (atomic_read(&ac->cmd_response)) { |
| 3240 | pr_err("%s: ASM_SESSION_CMD_MEMORY_MAP_REGIONS cmd failed\n", |
| 3241 | __func__); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3242 | rc = -EINVAL; |
| 3243 | goto fail_cmd; |
| 3244 | } |
| 3245 | rc = 0; |
| Deepa Madiregama | 636f80e | 2013-01-17 14:01:25 +0530 | [diff] [blame] | 3246 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3247 | fail_cmd: |
| 3248 | kfree(mmap_region_cmd); |
| 3249 | return rc; |
| 3250 | } |
| 3251 | |
| 3252 | static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir, |
| 3253 | uint32_t bufsz, uint32_t bufcnt) |
| 3254 | { |
| 3255 | struct asm_stream_cmd_memory_unmap_regions *unmap_regions = NULL; |
| 3256 | struct asm_memory_unmap_regions *mregions = NULL; |
| 3257 | struct audio_port_data *port = NULL; |
| 3258 | struct audio_buffer *ab = NULL; |
| 3259 | void *unmap_region_cmd = NULL; |
| 3260 | void *payload = NULL; |
| 3261 | int rc = 0; |
| 3262 | int i = 0; |
| 3263 | int cmd_size = 0; |
| 3264 | |
| 3265 | if (!ac || ac->apr == NULL || this_mmap.apr == NULL) { |
| 3266 | pr_err("APR handle NULL\n"); |
| 3267 | return -EINVAL; |
| 3268 | } |
| 3269 | pr_debug("%s: Session[%d]\n", __func__, ac->session); |
| 3270 | |
| 3271 | cmd_size = sizeof(struct asm_stream_cmd_memory_unmap_regions) + |
| 3272 | sizeof(struct asm_memory_unmap_regions) * bufcnt; |
| 3273 | |
| 3274 | unmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL); |
| Vasudeva Rao Thumati | 86edf6c | 2011-07-06 16:25:13 +0530 | [diff] [blame] | 3275 | if (unmap_region_cmd == NULL) { |
| 3276 | pr_err("%s: Mem alloc failed\n", __func__); |
| 3277 | rc = -EINVAL; |
| 3278 | return rc; |
| 3279 | } |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3280 | unmap_regions = (struct asm_stream_cmd_memory_unmap_regions *) |
| 3281 | unmap_region_cmd; |
| Deepa Madiregama | 636f80e | 2013-01-17 14:01:25 +0530 | [diff] [blame] | 3282 | unmap_regions->hdr.token = (uint32_t)ac; |
| 3283 | pr_debug("%s: audio_client addr %x\n", __func__, (uint32_t)ac); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3284 | q6asm_add_mmaphdr(&unmap_regions->hdr, cmd_size, TRUE); |
| 3285 | unmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS; |
| 3286 | unmap_regions->nregions = bufcnt & 0x00ff; |
| 3287 | pr_debug("unmap_regions->nregions = %d\n", unmap_regions->nregions); |
| 3288 | payload = ((u8 *) unmap_region_cmd + |
| 3289 | sizeof(struct asm_stream_cmd_memory_unmap_regions)); |
| 3290 | mregions = (struct asm_memory_unmap_regions *)payload; |
| 3291 | port = &ac->port[dir]; |
| 3292 | for (i = 0; i < bufcnt; i++) { |
| 3293 | ab = &port->buf[i]; |
| 3294 | mregions->phys = ab->phys; |
| 3295 | ++mregions; |
| 3296 | } |
| 3297 | |
| 3298 | rc = apr_send_pkt(this_mmap.apr, (uint32_t *) unmap_region_cmd); |
| 3299 | if (rc < 0) { |
| 3300 | pr_err("mmap_regions op[0x%x]rc[%d]\n", |
| 3301 | unmap_regions->hdr.opcode, rc); |
| 3302 | goto fail_cmd; |
| 3303 | } |
| 3304 | |
| Deepa Madiregama | 636f80e | 2013-01-17 14:01:25 +0530 | [diff] [blame] | 3305 | rc = wait_event_timeout(ac->cmd_wait, |
| 3306 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3307 | if (!rc) { |
| Deepa Madiregama | 636f80e | 2013-01-17 14:01:25 +0530 | [diff] [blame] | 3308 | pr_err("timeout. waited for unmap_regions\n"); |
| 3309 | rc = -EINVAL; |
| 3310 | goto fail_cmd; |
| 3311 | } |
| 3312 | if (atomic_read(&ac->cmd_response)) { |
| 3313 | pr_err("%s: ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS cmd failed\n", |
| 3314 | __func__); |
| 3315 | rc = -EINVAL; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3316 | goto fail_cmd; |
| 3317 | } |
| 3318 | rc = 0; |
| 3319 | |
| 3320 | fail_cmd: |
| 3321 | kfree(unmap_region_cmd); |
| 3322 | return rc; |
| 3323 | } |
| 3324 | |
| 3325 | int q6asm_set_mute(struct audio_client *ac, int muteflag) |
| 3326 | { |
| 3327 | void *vol_cmd = NULL; |
| 3328 | void *payload = NULL; |
| 3329 | struct asm_pp_params_command *cmd = NULL; |
| 3330 | struct asm_mute_params *mute = NULL; |
| 3331 | int sz = 0; |
| 3332 | int rc = 0; |
| 3333 | |
| 3334 | sz = sizeof(struct asm_pp_params_command) + |
| 3335 | + sizeof(struct asm_mute_params); |
| 3336 | vol_cmd = kzalloc(sz, GFP_KERNEL); |
| 3337 | if (vol_cmd == NULL) { |
| 3338 | pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session); |
| 3339 | rc = -EINVAL; |
| 3340 | return rc; |
| 3341 | } |
| 3342 | cmd = (struct asm_pp_params_command *)vol_cmd; |
| 3343 | q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE); |
| 3344 | cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS; |
| 3345 | cmd->payload = NULL; |
| 3346 | cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) + |
| 3347 | sizeof(struct asm_mute_params); |
| 3348 | cmd->params.module_id = VOLUME_CONTROL_MODULE_ID; |
| 3349 | cmd->params.param_id = MUTE_CONFIG_PARAM_ID; |
| 3350 | cmd->params.param_size = sizeof(struct asm_mute_params); |
| 3351 | cmd->params.reserved = 0; |
| 3352 | |
| 3353 | payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command)); |
| 3354 | mute = (struct asm_mute_params *)payload; |
| 3355 | |
| 3356 | mute->muteflag = muteflag; |
| 3357 | rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd); |
| 3358 | if (rc < 0) { |
| 3359 | pr_err("%s: Mute Command failed\n", __func__); |
| 3360 | rc = -EINVAL; |
| 3361 | goto fail_cmd; |
| 3362 | } |
| 3363 | |
| 3364 | rc = wait_event_timeout(ac->cmd_wait, |
| 3365 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 3366 | if (!rc) { |
| 3367 | pr_err("%s: timeout in sending mute command to apr\n", |
| 3368 | __func__); |
| 3369 | rc = -EINVAL; |
| 3370 | goto fail_cmd; |
| 3371 | } |
| 3372 | rc = 0; |
| 3373 | fail_cmd: |
| 3374 | kfree(vol_cmd); |
| 3375 | return rc; |
| 3376 | } |
| 3377 | |
| 3378 | int q6asm_set_volume(struct audio_client *ac, int volume) |
| 3379 | { |
| 3380 | void *vol_cmd = NULL; |
| 3381 | void *payload = NULL; |
| 3382 | struct asm_pp_params_command *cmd = NULL; |
| 3383 | struct asm_master_gain_params *mgain = NULL; |
| 3384 | int sz = 0; |
| 3385 | int rc = 0; |
| 3386 | |
| 3387 | sz = sizeof(struct asm_pp_params_command) + |
| 3388 | + sizeof(struct asm_master_gain_params); |
| 3389 | vol_cmd = kzalloc(sz, GFP_KERNEL); |
| 3390 | if (vol_cmd == NULL) { |
| 3391 | pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session); |
| 3392 | rc = -EINVAL; |
| 3393 | return rc; |
| 3394 | } |
| 3395 | cmd = (struct asm_pp_params_command *)vol_cmd; |
| 3396 | q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE); |
| 3397 | cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS; |
| 3398 | cmd->payload = NULL; |
| 3399 | cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) + |
| 3400 | sizeof(struct asm_master_gain_params); |
| 3401 | cmd->params.module_id = VOLUME_CONTROL_MODULE_ID; |
| 3402 | cmd->params.param_id = MASTER_GAIN_PARAM_ID; |
| 3403 | cmd->params.param_size = sizeof(struct asm_master_gain_params); |
| 3404 | cmd->params.reserved = 0; |
| 3405 | |
| 3406 | payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command)); |
| 3407 | mgain = (struct asm_master_gain_params *)payload; |
| 3408 | |
| 3409 | mgain->master_gain = volume; |
| 3410 | mgain->padding = 0x00; |
| 3411 | rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd); |
| 3412 | if (rc < 0) { |
| 3413 | pr_err("%s: Volume Command failed\n", __func__); |
| 3414 | rc = -EINVAL; |
| 3415 | goto fail_cmd; |
| 3416 | } |
| 3417 | |
| 3418 | rc = wait_event_timeout(ac->cmd_wait, |
| 3419 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 3420 | if (!rc) { |
| 3421 | pr_err("%s: timeout in sending volume command to apr\n", |
| 3422 | __func__); |
| 3423 | rc = -EINVAL; |
| 3424 | goto fail_cmd; |
| 3425 | } |
| 3426 | rc = 0; |
| 3427 | fail_cmd: |
| 3428 | kfree(vol_cmd); |
| 3429 | return rc; |
| 3430 | } |
| 3431 | |
| 3432 | int q6asm_set_softpause(struct audio_client *ac, |
| 3433 | struct asm_softpause_params *pause_param) |
| 3434 | { |
| 3435 | void *vol_cmd = NULL; |
| 3436 | void *payload = NULL; |
| 3437 | struct asm_pp_params_command *cmd = NULL; |
| 3438 | struct asm_softpause_params *params = NULL; |
| 3439 | int sz = 0; |
| 3440 | int rc = 0; |
| 3441 | |
| 3442 | sz = sizeof(struct asm_pp_params_command) + |
| 3443 | + sizeof(struct asm_softpause_params); |
| 3444 | vol_cmd = kzalloc(sz, GFP_KERNEL); |
| 3445 | if (vol_cmd == NULL) { |
| 3446 | pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session); |
| 3447 | rc = -EINVAL; |
| 3448 | return rc; |
| 3449 | } |
| 3450 | cmd = (struct asm_pp_params_command *)vol_cmd; |
| 3451 | q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE); |
| 3452 | cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS; |
| 3453 | cmd->payload = NULL; |
| 3454 | cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) + |
| 3455 | sizeof(struct asm_softpause_params); |
| 3456 | cmd->params.module_id = VOLUME_CONTROL_MODULE_ID; |
| 3457 | cmd->params.param_id = SOFT_PAUSE_PARAM_ID; |
| 3458 | cmd->params.param_size = sizeof(struct asm_softpause_params); |
| 3459 | cmd->params.reserved = 0; |
| 3460 | |
| 3461 | payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command)); |
| 3462 | params = (struct asm_softpause_params *)payload; |
| 3463 | |
| 3464 | params->enable = pause_param->enable; |
| 3465 | params->period = pause_param->period; |
| 3466 | params->step = pause_param->step; |
| 3467 | params->rampingcurve = pause_param->rampingcurve; |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 3468 | pr_debug("%s: soft Pause Command: enable = %d, period = %d, step = %d, curve = %d\n", |
| 3469 | __func__, params->enable, |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3470 | params->period, params->step, params->rampingcurve); |
| 3471 | rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd); |
| 3472 | if (rc < 0) { |
| 3473 | pr_err("%s: Volume Command(soft_pause) failed\n", __func__); |
| 3474 | rc = -EINVAL; |
| 3475 | goto fail_cmd; |
| 3476 | } |
| 3477 | |
| 3478 | rc = wait_event_timeout(ac->cmd_wait, |
| 3479 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 3480 | if (!rc) { |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 3481 | pr_err("%s: timeout in sending volume command(soft_pause) to apr\n", |
| 3482 | __func__); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3483 | rc = -EINVAL; |
| 3484 | goto fail_cmd; |
| 3485 | } |
| 3486 | rc = 0; |
| 3487 | fail_cmd: |
| 3488 | kfree(vol_cmd); |
| 3489 | return rc; |
| 3490 | } |
| 3491 | |
| Swaminathan Sathappan | b0021cd | 2011-08-31 15:20:12 -0700 | [diff] [blame] | 3492 | int q6asm_set_softvolume(struct audio_client *ac, |
| 3493 | struct asm_softvolume_params *softvol_param) |
| 3494 | { |
| 3495 | void *vol_cmd = NULL; |
| 3496 | void *payload = NULL; |
| 3497 | struct asm_pp_params_command *cmd = NULL; |
| 3498 | struct asm_softvolume_params *params = NULL; |
| 3499 | int sz = 0; |
| 3500 | int rc = 0; |
| 3501 | |
| 3502 | sz = sizeof(struct asm_pp_params_command) + |
| 3503 | + sizeof(struct asm_softvolume_params); |
| 3504 | vol_cmd = kzalloc(sz, GFP_KERNEL); |
| 3505 | if (vol_cmd == NULL) { |
| 3506 | pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session); |
| 3507 | rc = -EINVAL; |
| 3508 | return rc; |
| 3509 | } |
| 3510 | cmd = (struct asm_pp_params_command *)vol_cmd; |
| 3511 | q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE); |
| 3512 | cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS; |
| 3513 | cmd->payload = NULL; |
| 3514 | cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) + |
| 3515 | sizeof(struct asm_softvolume_params); |
| 3516 | cmd->params.module_id = VOLUME_CONTROL_MODULE_ID; |
| 3517 | cmd->params.param_id = SOFT_VOLUME_PARAM_ID; |
| 3518 | cmd->params.param_size = sizeof(struct asm_softvolume_params); |
| 3519 | cmd->params.reserved = 0; |
| 3520 | |
| 3521 | payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command)); |
| 3522 | params = (struct asm_softvolume_params *)payload; |
| 3523 | |
| 3524 | params->period = softvol_param->period; |
| 3525 | params->step = softvol_param->step; |
| 3526 | params->rampingcurve = softvol_param->rampingcurve; |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 3527 | pr_debug("%s: soft Volume:opcode = %d,payload_sz =%d,module_id =%d, param_id = %d, param_sz = %d\n", |
| 3528 | __func__, |
| Swaminathan Sathappan | b0021cd | 2011-08-31 15:20:12 -0700 | [diff] [blame] | 3529 | cmd->hdr.opcode, cmd->payload_size, |
| 3530 | cmd->params.module_id, cmd->params.param_id, |
| 3531 | cmd->params.param_size); |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 3532 | pr_debug("%s: soft Volume Command: period = %d, step = %d, curve = %d\n", |
| 3533 | __func__, params->period, |
| Swaminathan Sathappan | b0021cd | 2011-08-31 15:20:12 -0700 | [diff] [blame] | 3534 | params->step, params->rampingcurve); |
| 3535 | rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd); |
| 3536 | if (rc < 0) { |
| 3537 | pr_err("%s: Volume Command(soft_volume) failed\n", __func__); |
| 3538 | rc = -EINVAL; |
| 3539 | goto fail_cmd; |
| 3540 | } |
| 3541 | |
| 3542 | rc = wait_event_timeout(ac->cmd_wait, |
| 3543 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 3544 | if (!rc) { |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 3545 | pr_err("%s: timeout in sending volume command(soft_volume) to apr\n", |
| 3546 | __func__); |
| Swaminathan Sathappan | b0021cd | 2011-08-31 15:20:12 -0700 | [diff] [blame] | 3547 | rc = -EINVAL; |
| 3548 | goto fail_cmd; |
| 3549 | } |
| 3550 | rc = 0; |
| 3551 | fail_cmd: |
| 3552 | kfree(vol_cmd); |
| 3553 | return rc; |
| 3554 | } |
| 3555 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3556 | int q6asm_equalizer(struct audio_client *ac, void *eq) |
| 3557 | { |
| 3558 | void *eq_cmd = NULL; |
| 3559 | void *payload = NULL; |
| 3560 | struct asm_pp_params_command *cmd = NULL; |
| 3561 | struct asm_equalizer_params *equalizer = NULL; |
| 3562 | struct msm_audio_eq_stream_config *eq_params = NULL; |
| 3563 | int i = 0; |
| 3564 | int sz = 0; |
| 3565 | int rc = 0; |
| 3566 | |
| 3567 | sz = sizeof(struct asm_pp_params_command) + |
| 3568 | + sizeof(struct asm_equalizer_params); |
| 3569 | eq_cmd = kzalloc(sz, GFP_KERNEL); |
| 3570 | if (eq_cmd == NULL) { |
| 3571 | pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session); |
| 3572 | rc = -EINVAL; |
| 3573 | goto fail_cmd; |
| 3574 | } |
| 3575 | eq_params = (struct msm_audio_eq_stream_config *) eq; |
| 3576 | cmd = (struct asm_pp_params_command *)eq_cmd; |
| 3577 | q6asm_add_hdr(ac, &cmd->hdr, sz, TRUE); |
| 3578 | cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS; |
| 3579 | cmd->payload = NULL; |
| 3580 | cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) + |
| 3581 | sizeof(struct asm_equalizer_params); |
| 3582 | cmd->params.module_id = EQUALIZER_MODULE_ID; |
| 3583 | cmd->params.param_id = EQUALIZER_PARAM_ID; |
| 3584 | cmd->params.param_size = sizeof(struct asm_equalizer_params); |
| 3585 | cmd->params.reserved = 0; |
| 3586 | payload = (u8 *)(eq_cmd + sizeof(struct asm_pp_params_command)); |
| 3587 | equalizer = (struct asm_equalizer_params *)payload; |
| 3588 | |
| 3589 | equalizer->enable = eq_params->enable; |
| 3590 | equalizer->num_bands = eq_params->num_bands; |
| 3591 | pr_debug("%s: enable:%d numbands:%d\n", __func__, eq_params->enable, |
| 3592 | eq_params->num_bands); |
| 3593 | for (i = 0; i < eq_params->num_bands; i++) { |
| 3594 | equalizer->eq_bands[i].band_idx = |
| 3595 | eq_params->eq_bands[i].band_idx; |
| 3596 | equalizer->eq_bands[i].filter_type = |
| 3597 | eq_params->eq_bands[i].filter_type; |
| 3598 | equalizer->eq_bands[i].center_freq_hz = |
| 3599 | eq_params->eq_bands[i].center_freq_hz; |
| 3600 | equalizer->eq_bands[i].filter_gain = |
| 3601 | eq_params->eq_bands[i].filter_gain; |
| 3602 | equalizer->eq_bands[i].q_factor = |
| 3603 | eq_params->eq_bands[i].q_factor; |
| 3604 | pr_debug("%s: filter_type:%u bandnum:%d\n", __func__, |
| 3605 | eq_params->eq_bands[i].filter_type, i); |
| 3606 | pr_debug("%s: center_freq_hz:%u bandnum:%d\n", __func__, |
| 3607 | eq_params->eq_bands[i].center_freq_hz, i); |
| 3608 | pr_debug("%s: filter_gain:%d bandnum:%d\n", __func__, |
| 3609 | eq_params->eq_bands[i].filter_gain, i); |
| 3610 | pr_debug("%s: q_factor:%d bandnum:%d\n", __func__, |
| 3611 | eq_params->eq_bands[i].q_factor, i); |
| 3612 | } |
| 3613 | rc = apr_send_pkt(ac->apr, (uint32_t *) eq_cmd); |
| 3614 | if (rc < 0) { |
| 3615 | pr_err("%s: Equalizer Command failed\n", __func__); |
| 3616 | rc = -EINVAL; |
| 3617 | goto fail_cmd; |
| 3618 | } |
| 3619 | |
| 3620 | rc = wait_event_timeout(ac->cmd_wait, |
| 3621 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 3622 | if (!rc) { |
| 3623 | pr_err("%s: timeout in sending equalizer command to apr\n", |
| 3624 | __func__); |
| 3625 | rc = -EINVAL; |
| 3626 | goto fail_cmd; |
| 3627 | } |
| 3628 | rc = 0; |
| 3629 | fail_cmd: |
| 3630 | kfree(eq_cmd); |
| 3631 | return rc; |
| 3632 | } |
| 3633 | |
| 3634 | int q6asm_read(struct audio_client *ac) |
| 3635 | { |
| 3636 | struct asm_stream_cmd_read read; |
| 3637 | struct audio_buffer *ab; |
| 3638 | int dsp_buf; |
| 3639 | struct audio_port_data *port; |
| 3640 | int rc; |
| 3641 | if (!ac || ac->apr == NULL) { |
| 3642 | pr_err("APR handle NULL\n"); |
| 3643 | return -EINVAL; |
| 3644 | } |
| Patrick Lai | 55f54c5 | 2012-11-17 00:29:07 -0800 | [diff] [blame] | 3645 | if (ac->io_mode & SYNC_IO_MODE) { |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3646 | port = &ac->port[OUT]; |
| 3647 | |
| 3648 | q6asm_add_hdr(ac, &read.hdr, sizeof(read), FALSE); |
| 3649 | |
| 3650 | mutex_lock(&port->lock); |
| 3651 | |
| 3652 | dsp_buf = port->dsp_buf; |
| 3653 | ab = &port->buf[dsp_buf]; |
| 3654 | |
| 3655 | pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n", |
| 3656 | __func__, |
| 3657 | ac->session, |
| 3658 | dsp_buf, |
| 3659 | (void *)port->buf[dsp_buf].data, |
| 3660 | port->cpu_buf, |
| 3661 | (void *)port->buf[port->cpu_buf].phys); |
| 3662 | |
| 3663 | read.hdr.opcode = ASM_DATA_CMD_READ; |
| 3664 | read.buf_add = ab->phys; |
| 3665 | read.buf_size = ab->size; |
| 3666 | read.uid = port->dsp_buf; |
| 3667 | read.hdr.token = port->dsp_buf; |
| 3668 | |
| 3669 | port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1); |
| 3670 | mutex_unlock(&port->lock); |
| 3671 | pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__, |
| 3672 | read.buf_add, |
| 3673 | read.hdr.token, |
| 3674 | read.uid); |
| 3675 | rc = apr_send_pkt(ac->apr, (uint32_t *) &read); |
| 3676 | if (rc < 0) { |
| 3677 | pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc); |
| 3678 | goto fail_cmd; |
| 3679 | } |
| 3680 | return 0; |
| 3681 | } |
| 3682 | fail_cmd: |
| 3683 | return -EINVAL; |
| 3684 | } |
| 3685 | |
| 3686 | int q6asm_read_nolock(struct audio_client *ac) |
| 3687 | { |
| 3688 | struct asm_stream_cmd_read read; |
| 3689 | struct audio_buffer *ab; |
| 3690 | int dsp_buf; |
| 3691 | struct audio_port_data *port; |
| 3692 | int rc; |
| 3693 | if (!ac || ac->apr == NULL) { |
| 3694 | pr_err("APR handle NULL\n"); |
| 3695 | return -EINVAL; |
| 3696 | } |
| Patrick Lai | 55f54c5 | 2012-11-17 00:29:07 -0800 | [diff] [blame] | 3697 | if (ac->io_mode & SYNC_IO_MODE) { |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3698 | port = &ac->port[OUT]; |
| 3699 | |
| 3700 | q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE); |
| 3701 | |
| 3702 | |
| 3703 | dsp_buf = port->dsp_buf; |
| 3704 | ab = &port->buf[dsp_buf]; |
| 3705 | |
| 3706 | pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n", |
| 3707 | __func__, |
| 3708 | ac->session, |
| 3709 | dsp_buf, |
| 3710 | (void *)port->buf[dsp_buf].data, |
| 3711 | port->cpu_buf, |
| 3712 | (void *)port->buf[port->cpu_buf].phys); |
| 3713 | |
| 3714 | read.hdr.opcode = ASM_DATA_CMD_READ; |
| 3715 | read.buf_add = ab->phys; |
| 3716 | read.buf_size = ab->size; |
| 3717 | read.uid = port->dsp_buf; |
| 3718 | read.hdr.token = port->dsp_buf; |
| 3719 | |
| 3720 | port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1); |
| Patrick Lai | 55f54c5 | 2012-11-17 00:29:07 -0800 | [diff] [blame] | 3721 | pr_info("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__, |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3722 | read.buf_add, |
| 3723 | read.hdr.token, |
| 3724 | read.uid); |
| 3725 | rc = apr_send_pkt(ac->apr, (uint32_t *) &read); |
| 3726 | if (rc < 0) { |
| 3727 | pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc); |
| 3728 | goto fail_cmd; |
| 3729 | } |
| 3730 | return 0; |
| 3731 | } |
| 3732 | fail_cmd: |
| 3733 | return -EINVAL; |
| 3734 | } |
| 3735 | |
| 3736 | |
| 3737 | static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr, |
| 3738 | uint32_t pkt_size, uint32_t cmd_flg) |
| 3739 | { |
| 3740 | pr_debug("session=%d pkt size=%d cmd_flg=%d\n", pkt_size, cmd_flg, |
| 3741 | ac->session); |
| 3742 | hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \ |
| 3743 | APR_HDR_LEN(sizeof(struct apr_hdr)),\ |
| 3744 | APR_PKT_VER); |
| 3745 | hdr->src_svc = ((struct apr_svc *)ac->apr)->id; |
| 3746 | hdr->src_domain = APR_DOMAIN_APPS; |
| 3747 | hdr->dest_svc = APR_SVC_ASM; |
| 3748 | hdr->dest_domain = APR_DOMAIN_ADSP; |
| 3749 | hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01; |
| 3750 | hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01; |
| 3751 | if (cmd_flg) { |
| 3752 | hdr->token = ac->session; |
| 3753 | atomic_set(&ac->cmd_state, 1); |
| 3754 | } |
| 3755 | hdr->pkt_size = pkt_size; |
| 3756 | return; |
| 3757 | } |
| 3758 | |
| 3759 | int q6asm_async_write(struct audio_client *ac, |
| 3760 | struct audio_aio_write_param *param) |
| 3761 | { |
| 3762 | int rc = 0; |
| 3763 | struct asm_stream_cmd_write write; |
| 3764 | |
| 3765 | if (!ac || ac->apr == NULL) { |
| 3766 | pr_err("%s: APR handle NULL\n", __func__); |
| 3767 | return -EINVAL; |
| 3768 | } |
| 3769 | |
| 3770 | q6asm_add_hdr_async(ac, &write.hdr, sizeof(write), FALSE); |
| 3771 | |
| 3772 | /* Pass physical address as token for AIO scheme */ |
| 3773 | write.hdr.token = param->uid; |
| 3774 | write.hdr.opcode = ASM_DATA_CMD_WRITE; |
| 3775 | write.buf_add = param->paddr; |
| 3776 | write.avail_bytes = param->len; |
| 3777 | write.uid = param->uid; |
| 3778 | write.msw_ts = param->msw_ts; |
| 3779 | write.lsw_ts = param->lsw_ts; |
| 3780 | /* Use 0xFF00 for disabling timestamps */ |
| 3781 | if (param->flags == 0xFF00) |
| 3782 | write.uflags = (0x00000000 | (param->flags & 0x800000FF)); |
| 3783 | else |
| 3784 | write.uflags = (0x80000000 | param->flags); |
| 3785 | |
| 3786 | pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session, |
| 3787 | write.buf_add, write.avail_bytes); |
| 3788 | |
| 3789 | rc = apr_send_pkt(ac->apr, (uint32_t *) &write); |
| 3790 | if (rc < 0) { |
| 3791 | pr_debug("[%s] write op[0x%x]rc[%d]\n", __func__, |
| 3792 | write.hdr.opcode, rc); |
| 3793 | goto fail_cmd; |
| 3794 | } |
| 3795 | return 0; |
| 3796 | fail_cmd: |
| 3797 | return -EINVAL; |
| 3798 | } |
| 3799 | |
| 3800 | int q6asm_async_read(struct audio_client *ac, |
| 3801 | struct audio_aio_read_param *param) |
| 3802 | { |
| 3803 | int rc = 0; |
| 3804 | struct asm_stream_cmd_read read; |
| 3805 | |
| 3806 | if (!ac || ac->apr == NULL) { |
| 3807 | pr_err("%s: APR handle NULL\n", __func__); |
| 3808 | return -EINVAL; |
| 3809 | } |
| 3810 | |
| 3811 | q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE); |
| 3812 | |
| 3813 | /* Pass physical address as token for AIO scheme */ |
| 3814 | read.hdr.token = param->paddr; |
| 3815 | read.hdr.opcode = ASM_DATA_CMD_READ; |
| 3816 | read.buf_add = param->paddr; |
| 3817 | read.buf_size = param->len; |
| 3818 | read.uid = param->uid; |
| 3819 | |
| 3820 | pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session, |
| 3821 | read.buf_add, read.buf_size); |
| 3822 | |
| 3823 | rc = apr_send_pkt(ac->apr, (uint32_t *) &read); |
| 3824 | if (rc < 0) { |
| 3825 | pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__, |
| 3826 | read.hdr.opcode, rc); |
| 3827 | goto fail_cmd; |
| 3828 | } |
| 3829 | return 0; |
| 3830 | fail_cmd: |
| 3831 | return -EINVAL; |
| 3832 | } |
| 3833 | |
| Subhash Chandra Bose Naripeddy | 694b7d9 | 2012-06-20 20:46:13 -0700 | [diff] [blame] | 3834 | int q6asm_async_read_compressed(struct audio_client *ac, |
| 3835 | struct audio_aio_read_param *param) |
| 3836 | { |
| 3837 | int rc = 0; |
| 3838 | struct asm_stream_cmd_read read; |
| 3839 | |
| 3840 | if (!ac || ac->apr == NULL) { |
| 3841 | pr_err("%s: APR handle NULL\n", __func__); |
| 3842 | return -EINVAL; |
| 3843 | } |
| 3844 | |
| 3845 | q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE); |
| 3846 | |
| 3847 | /* Pass physical address as token for AIO scheme */ |
| 3848 | read.hdr.token = param->paddr; |
| 3849 | read.hdr.opcode = ASM_DATA_CMD_READ_COMPRESSED; |
| 3850 | read.buf_add = param->paddr; |
| 3851 | read.buf_size = param->len; |
| 3852 | read.uid = param->uid; |
| 3853 | |
| 3854 | pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session, |
| 3855 | read.buf_add, read.buf_size); |
| 3856 | |
| 3857 | rc = apr_send_pkt(ac->apr, (uint32_t *) &read); |
| 3858 | if (rc < 0) { |
| 3859 | pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__, |
| 3860 | read.hdr.opcode, rc); |
| 3861 | goto fail_cmd; |
| 3862 | } |
| 3863 | return 0; |
| 3864 | fail_cmd: |
| 3865 | return -EINVAL; |
| 3866 | } |
| 3867 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3868 | int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts, |
| 3869 | uint32_t lsw_ts, uint32_t flags) |
| 3870 | { |
| 3871 | int rc = 0; |
| 3872 | struct asm_stream_cmd_write write; |
| 3873 | struct audio_port_data *port; |
| 3874 | struct audio_buffer *ab; |
| 3875 | int dsp_buf = 0; |
| 3876 | |
| 3877 | if (!ac || ac->apr == NULL) { |
| 3878 | pr_err("APR handle NULL\n"); |
| 3879 | return -EINVAL; |
| 3880 | } |
| 3881 | pr_debug("%s: session[%d] len=%d", __func__, ac->session, len); |
| Patrick Lai | 55f54c5 | 2012-11-17 00:29:07 -0800 | [diff] [blame] | 3882 | if (ac->io_mode & SYNC_IO_MODE) { |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3883 | port = &ac->port[IN]; |
| 3884 | |
| 3885 | q6asm_add_hdr(ac, &write.hdr, sizeof(write), |
| 3886 | FALSE); |
| 3887 | mutex_lock(&port->lock); |
| 3888 | |
| 3889 | dsp_buf = port->dsp_buf; |
| 3890 | ab = &port->buf[dsp_buf]; |
| 3891 | |
| 3892 | write.hdr.token = port->dsp_buf; |
| 3893 | write.hdr.opcode = ASM_DATA_CMD_WRITE; |
| 3894 | write.buf_add = ab->phys; |
| 3895 | write.avail_bytes = len; |
| 3896 | write.uid = port->dsp_buf; |
| 3897 | write.msw_ts = msw_ts; |
| 3898 | write.lsw_ts = lsw_ts; |
| 3899 | /* Use 0xFF00 for disabling timestamps */ |
| 3900 | if (flags == 0xFF00) |
| 3901 | write.uflags = (0x00000000 | (flags & 0x800000FF)); |
| 3902 | else |
| 3903 | write.uflags = (0x80000000 | flags); |
| 3904 | port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1); |
| 3905 | |
| 3906 | pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]" |
| 3907 | , __func__, |
| 3908 | ab->phys, |
| 3909 | write.buf_add, |
| 3910 | write.hdr.token, |
| 3911 | write.uid); |
| 3912 | mutex_unlock(&port->lock); |
| Rajesha Kini | 3498c93 | 2011-07-19 19:58:27 +0530 | [diff] [blame] | 3913 | #ifdef CONFIG_DEBUG_FS |
| 3914 | if (out_enable_flag) { |
| 3915 | char zero_pattern[2] = {0x00, 0x00}; |
| 3916 | /* If First two byte is non zero and last two byte |
| 3917 | is zero then it is warm output pattern */ |
| 3918 | if ((strncmp(((char *)ab->data), zero_pattern, 2)) && |
| 3919 | (!strncmp(((char *)ab->data + 2), zero_pattern, 2))) { |
| 3920 | do_gettimeofday(&out_warm_tv); |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 3921 | pr_debug("WARM:apr_send_pkt at %ld sec %ld microsec\n", |
| 3922 | out_warm_tv.tv_sec,\ |
| Rajesha Kini | 3498c93 | 2011-07-19 19:58:27 +0530 | [diff] [blame] | 3923 | out_warm_tv.tv_usec); |
| 3924 | pr_debug("Warm Pattern Matched"); |
| 3925 | } |
| 3926 | /* If First two byte is zero and last two byte is |
| 3927 | non zero then it is cont ouput pattern */ |
| 3928 | else if ((!strncmp(((char *)ab->data), zero_pattern, 2)) |
| 3929 | && (strncmp(((char *)ab->data + 2), zero_pattern, 2))) { |
| 3930 | do_gettimeofday(&out_cont_tv); |
| Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 3931 | pr_debug("CONT:apr_send_pkt at %ld sec %ld microsec\n", |
| 3932 | out_cont_tv.tv_sec,\ |
| Rajesha Kini | 3498c93 | 2011-07-19 19:58:27 +0530 | [diff] [blame] | 3933 | out_cont_tv.tv_usec); |
| 3934 | pr_debug("Cont Pattern Matched"); |
| 3935 | } |
| 3936 | } |
| 3937 | #endif |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3938 | rc = apr_send_pkt(ac->apr, (uint32_t *) &write); |
| 3939 | if (rc < 0) { |
| 3940 | pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc); |
| 3941 | goto fail_cmd; |
| 3942 | } |
| 3943 | pr_debug("%s: WRITE SUCCESS\n", __func__); |
| 3944 | return 0; |
| 3945 | } |
| 3946 | fail_cmd: |
| 3947 | return -EINVAL; |
| 3948 | } |
| 3949 | |
| 3950 | int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts, |
| 3951 | uint32_t lsw_ts, uint32_t flags) |
| 3952 | { |
| 3953 | int rc = 0; |
| 3954 | struct asm_stream_cmd_write write; |
| 3955 | struct audio_port_data *port; |
| 3956 | struct audio_buffer *ab; |
| 3957 | int dsp_buf = 0; |
| 3958 | |
| 3959 | if (!ac || ac->apr == NULL) { |
| 3960 | pr_err("APR handle NULL\n"); |
| 3961 | return -EINVAL; |
| 3962 | } |
| 3963 | pr_debug("%s: session[%d] len=%d", __func__, ac->session, len); |
| Patrick Lai | 55f54c5 | 2012-11-17 00:29:07 -0800 | [diff] [blame] | 3964 | if (ac->io_mode & SYNC_IO_MODE) { |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3965 | port = &ac->port[IN]; |
| 3966 | |
| 3967 | q6asm_add_hdr_async(ac, &write.hdr, sizeof(write), |
| 3968 | FALSE); |
| 3969 | |
| 3970 | dsp_buf = port->dsp_buf; |
| 3971 | ab = &port->buf[dsp_buf]; |
| 3972 | |
| 3973 | write.hdr.token = port->dsp_buf; |
| 3974 | write.hdr.opcode = ASM_DATA_CMD_WRITE; |
| 3975 | write.buf_add = ab->phys; |
| 3976 | write.avail_bytes = len; |
| 3977 | write.uid = port->dsp_buf; |
| 3978 | write.msw_ts = msw_ts; |
| 3979 | write.lsw_ts = lsw_ts; |
| 3980 | /* Use 0xFF00 for disabling timestamps */ |
| 3981 | if (flags == 0xFF00) |
| 3982 | write.uflags = (0x00000000 | (flags & 0x800000FF)); |
| 3983 | else |
| 3984 | write.uflags = (0x80000000 | flags); |
| 3985 | port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1); |
| 3986 | |
| 3987 | pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]" |
| 3988 | , __func__, |
| 3989 | ab->phys, |
| 3990 | write.buf_add, |
| 3991 | write.hdr.token, |
| 3992 | write.uid); |
| 3993 | |
| 3994 | rc = apr_send_pkt(ac->apr, (uint32_t *) &write); |
| 3995 | if (rc < 0) { |
| 3996 | pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc); |
| 3997 | goto fail_cmd; |
| 3998 | } |
| 3999 | pr_debug("%s: WRITE SUCCESS\n", __func__); |
| 4000 | return 0; |
| 4001 | } |
| 4002 | fail_cmd: |
| 4003 | return -EINVAL; |
| 4004 | } |
| 4005 | |
| Patrick Lai | 3aabeae | 2013-01-06 00:52:34 -0800 | [diff] [blame] | 4006 | int q6asm_get_session_time(struct audio_client *ac, uint64_t *tstamp) |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4007 | { |
| 4008 | struct apr_hdr hdr; |
| 4009 | int rc; |
| 4010 | |
| Patrick Lai | 3aabeae | 2013-01-06 00:52:34 -0800 | [diff] [blame] | 4011 | if (!ac || ac->apr == NULL || tstamp == NULL) { |
| 4012 | pr_err("APR handle or tstamp NULL\n"); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4013 | return -EINVAL; |
| 4014 | } |
| Swaminathan Sathappan | c7f9899 | 2012-07-09 11:07:12 -0700 | [diff] [blame] | 4015 | q6asm_add_hdr(ac, &hdr, sizeof(hdr), FALSE); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4016 | hdr.opcode = ASM_SESSION_CMD_GET_SESSION_TIME; |
| 4017 | atomic_set(&ac->time_flag, 1); |
| 4018 | |
| 4019 | pr_debug("%s: session[%d]opcode[0x%x]\n", __func__, |
| 4020 | ac->session, |
| 4021 | hdr.opcode); |
| 4022 | rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr); |
| 4023 | if (rc < 0) { |
| 4024 | pr_err("Commmand 0x%x failed\n", hdr.opcode); |
| 4025 | goto fail_cmd; |
| 4026 | } |
| 4027 | rc = wait_event_timeout(ac->time_wait, |
| 4028 | (atomic_read(&ac->time_flag) == 0), 5*HZ); |
| 4029 | if (!rc) { |
| 4030 | pr_err("%s: timeout in getting session time from DSP\n", |
| 4031 | __func__); |
| 4032 | goto fail_cmd; |
| 4033 | } |
| Patrick Lai | 3aabeae | 2013-01-06 00:52:34 -0800 | [diff] [blame] | 4034 | |
| 4035 | *tstamp = ac->time_stamp; |
| 4036 | return 0; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4037 | |
| 4038 | fail_cmd: |
| 4039 | return -EINVAL; |
| 4040 | } |
| 4041 | |
| 4042 | int q6asm_cmd(struct audio_client *ac, int cmd) |
| 4043 | { |
| 4044 | struct apr_hdr hdr; |
| 4045 | int rc; |
| 4046 | atomic_t *state; |
| 4047 | int cnt = 0; |
| 4048 | |
| 4049 | if (!ac || ac->apr == NULL) { |
| 4050 | pr_err("APR handle NULL\n"); |
| 4051 | return -EINVAL; |
| 4052 | } |
| 4053 | q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE); |
| 4054 | switch (cmd) { |
| 4055 | case CMD_PAUSE: |
| 4056 | pr_debug("%s:CMD_PAUSE\n", __func__); |
| 4057 | hdr.opcode = ASM_SESSION_CMD_PAUSE; |
| 4058 | state = &ac->cmd_state; |
| 4059 | break; |
| 4060 | case CMD_FLUSH: |
| 4061 | pr_debug("%s:CMD_FLUSH\n", __func__); |
| 4062 | hdr.opcode = ASM_STREAM_CMD_FLUSH; |
| 4063 | state = &ac->cmd_state; |
| 4064 | break; |
| 4065 | case CMD_OUT_FLUSH: |
| 4066 | pr_debug("%s:CMD_OUT_FLUSH\n", __func__); |
| 4067 | hdr.opcode = ASM_STREAM_CMD_FLUSH_READBUFS; |
| 4068 | state = &ac->cmd_state; |
| 4069 | break; |
| 4070 | case CMD_EOS: |
| 4071 | pr_debug("%s:CMD_EOS\n", __func__); |
| 4072 | hdr.opcode = ASM_DATA_CMD_EOS; |
| 4073 | atomic_set(&ac->cmd_state, 0); |
| 4074 | state = &ac->cmd_state; |
| 4075 | break; |
| 4076 | case CMD_CLOSE: |
| 4077 | pr_debug("%s:CMD_CLOSE\n", __func__); |
| 4078 | hdr.opcode = ASM_STREAM_CMD_CLOSE; |
| Laxminath Kasam | f16d3fd | 2012-12-19 14:54:14 +0530 | [diff] [blame] | 4079 | atomic_set(&ac->cmd_close_state, 1); |
| 4080 | state = &ac->cmd_close_state; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4081 | break; |
| 4082 | default: |
| 4083 | pr_err("Invalid format[%d]\n", cmd); |
| 4084 | goto fail_cmd; |
| 4085 | } |
| 4086 | pr_debug("%s:session[%d]opcode[0x%x] ", __func__, |
| 4087 | ac->session, |
| 4088 | hdr.opcode); |
| 4089 | rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr); |
| 4090 | if (rc < 0) { |
| 4091 | pr_err("Commmand 0x%x failed\n", hdr.opcode); |
| 4092 | goto fail_cmd; |
| 4093 | } |
| 4094 | rc = wait_event_timeout(ac->cmd_wait, (atomic_read(state) == 0), 5*HZ); |
| 4095 | if (!rc) { |
| 4096 | pr_err("timeout. waited for response opcode[0x%x]\n", |
| 4097 | hdr.opcode); |
| 4098 | goto fail_cmd; |
| 4099 | } |
| 4100 | if (cmd == CMD_FLUSH) |
| 4101 | q6asm_reset_buf_state(ac); |
| 4102 | if (cmd == CMD_CLOSE) { |
| 4103 | /* check if DSP return all buffers */ |
| 4104 | if (ac->port[IN].buf) { |
| 4105 | for (cnt = 0; cnt < ac->port[IN].max_buf_cnt; |
| 4106 | cnt++) { |
| 4107 | if (ac->port[IN].buf[cnt].used == IN) { |
| 4108 | pr_debug("Write Buf[%d] not returned\n", |
| 4109 | cnt); |
| 4110 | } |
| 4111 | } |
| 4112 | } |
| 4113 | if (ac->port[OUT].buf) { |
| 4114 | for (cnt = 0; cnt < ac->port[OUT].max_buf_cnt; cnt++) { |
| 4115 | if (ac->port[OUT].buf[cnt].used == OUT) { |
| 4116 | pr_debug("Read Buf[%d] not returned\n", |
| 4117 | cnt); |
| 4118 | } |
| 4119 | } |
| 4120 | } |
| 4121 | } |
| 4122 | return 0; |
| 4123 | fail_cmd: |
| 4124 | return -EINVAL; |
| 4125 | } |
| 4126 | |
| 4127 | int q6asm_cmd_nowait(struct audio_client *ac, int cmd) |
| 4128 | { |
| 4129 | struct apr_hdr hdr; |
| 4130 | int rc; |
| 4131 | |
| 4132 | if (!ac || ac->apr == NULL) { |
| 4133 | pr_err("%s:APR handle NULL\n", __func__); |
| 4134 | return -EINVAL; |
| 4135 | } |
| 4136 | q6asm_add_hdr_async(ac, &hdr, sizeof(hdr), TRUE); |
| 4137 | switch (cmd) { |
| 4138 | case CMD_PAUSE: |
| 4139 | pr_debug("%s:CMD_PAUSE\n", __func__); |
| 4140 | hdr.opcode = ASM_SESSION_CMD_PAUSE; |
| 4141 | break; |
| 4142 | case CMD_EOS: |
| 4143 | pr_debug("%s:CMD_EOS\n", __func__); |
| 4144 | hdr.opcode = ASM_DATA_CMD_EOS; |
| 4145 | break; |
| 4146 | default: |
| 4147 | pr_err("%s:Invalid format[%d]\n", __func__, cmd); |
| 4148 | goto fail_cmd; |
| 4149 | } |
| 4150 | pr_debug("%s:session[%d]opcode[0x%x] ", __func__, |
| 4151 | ac->session, |
| 4152 | hdr.opcode); |
| Jay Wang | 0668d106 | 2012-07-11 18:53:21 -0700 | [diff] [blame] | 4153 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4154 | rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr); |
| 4155 | if (rc < 0) { |
| 4156 | pr_err("%s:Commmand 0x%x failed\n", __func__, hdr.opcode); |
| 4157 | goto fail_cmd; |
| 4158 | } |
| Jay Wang | 0668d106 | 2012-07-11 18:53:21 -0700 | [diff] [blame] | 4159 | atomic_inc(&ac->nowait_cmd_cnt); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4160 | return 0; |
| 4161 | fail_cmd: |
| 4162 | return -EINVAL; |
| 4163 | } |
| 4164 | |
| 4165 | static void q6asm_reset_buf_state(struct audio_client *ac) |
| 4166 | { |
| 4167 | int cnt = 0; |
| 4168 | int loopcnt = 0; |
| Patrick Lai | 55f54c5 | 2012-11-17 00:29:07 -0800 | [diff] [blame] | 4169 | int used; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4170 | struct audio_port_data *port = NULL; |
| 4171 | |
| Patrick Lai | 55f54c5 | 2012-11-17 00:29:07 -0800 | [diff] [blame] | 4172 | if (ac->io_mode & SYNC_IO_MODE) { |
| 4173 | used = (ac->io_mode & TUN_WRITE_IO_MODE ? 1 : 0); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4174 | mutex_lock(&ac->cmd_lock); |
| 4175 | for (loopcnt = 0; loopcnt <= OUT; loopcnt++) { |
| 4176 | port = &ac->port[loopcnt]; |
| 4177 | cnt = port->max_buf_cnt - 1; |
| 4178 | port->dsp_buf = 0; |
| 4179 | port->cpu_buf = 0; |
| 4180 | while (cnt >= 0) { |
| 4181 | if (!port->buf) |
| 4182 | continue; |
| Patrick Lai | 55f54c5 | 2012-11-17 00:29:07 -0800 | [diff] [blame] | 4183 | port->buf[cnt].used = used; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4184 | cnt--; |
| 4185 | } |
| 4186 | } |
| 4187 | mutex_unlock(&ac->cmd_lock); |
| 4188 | } |
| 4189 | } |
| 4190 | |
| 4191 | int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable) |
| 4192 | { |
| 4193 | struct asm_stream_cmd_reg_tx_overflow_event tx_overflow; |
| 4194 | int rc; |
| 4195 | |
| 4196 | if (!ac || ac->apr == NULL) { |
| 4197 | pr_err("APR handle NULL\n"); |
| 4198 | return -EINVAL; |
| 4199 | } |
| 4200 | pr_debug("%s:session[%d]enable[%d]\n", __func__, |
| 4201 | ac->session, enable); |
| 4202 | q6asm_add_hdr(ac, &tx_overflow.hdr, sizeof(tx_overflow), TRUE); |
| 4203 | |
| 4204 | tx_overflow.hdr.opcode = \ |
| 4205 | ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS; |
| 4206 | /* tx overflow event: enable */ |
| 4207 | tx_overflow.enable = enable; |
| 4208 | |
| 4209 | rc = apr_send_pkt(ac->apr, (uint32_t *) &tx_overflow); |
| 4210 | if (rc < 0) { |
| 4211 | pr_err("tx overflow op[0x%x]rc[%d]\n", \ |
| 4212 | tx_overflow.hdr.opcode, rc); |
| 4213 | goto fail_cmd; |
| 4214 | } |
| 4215 | rc = wait_event_timeout(ac->cmd_wait, |
| 4216 | (atomic_read(&ac->cmd_state) == 0), 5*HZ); |
| 4217 | if (!rc) { |
| 4218 | pr_err("timeout. waited for tx overflow\n"); |
| 4219 | goto fail_cmd; |
| 4220 | } |
| 4221 | return 0; |
| 4222 | fail_cmd: |
| 4223 | return -EINVAL; |
| 4224 | } |
| 4225 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4226 | int q6asm_get_apr_service_id(int session_id) |
| 4227 | { |
| 4228 | pr_debug("%s\n", __func__); |
| 4229 | |
| Shiv Maliyappanahalli | a84982a | 2012-01-19 15:25:04 -0800 | [diff] [blame] | 4230 | if (session_id < 0 || session_id > SESSION_MAX) { |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4231 | pr_err("%s: invalid session_id = %d\n", __func__, session_id); |
| 4232 | return -EINVAL; |
| 4233 | } |
| 4234 | |
| 4235 | return ((struct apr_svc *)session[session_id]->apr)->id; |
| 4236 | } |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4237 | |
| 4238 | |
| 4239 | static int __init q6asm_init(void) |
| 4240 | { |
| 4241 | pr_debug("%s\n", __func__); |
| 4242 | init_waitqueue_head(&this_mmap.cmd_wait); |
| 4243 | memset(session, 0, sizeof(session)); |
| Rajesha Kini | 3498c93 | 2011-07-19 19:58:27 +0530 | [diff] [blame] | 4244 | #ifdef CONFIG_DEBUG_FS |
| 4245 | out_buffer = kmalloc(OUT_BUFFER_SIZE, GFP_KERNEL); |
| 4246 | out_dentry = debugfs_create_file("audio_out_latency_measurement_node",\ |
| Glenn Kasten | 5dfda80 | 2012-10-04 16:40:27 -0700 | [diff] [blame] | 4247 | 0664,\ |
| Rajesha Kini | 3498c93 | 2011-07-19 19:58:27 +0530 | [diff] [blame] | 4248 | NULL, NULL, &audio_output_latency_debug_fops); |
| 4249 | if (IS_ERR(out_dentry)) |
| 4250 | pr_err("debugfs_create_file failed\n"); |
| 4251 | in_buffer = kmalloc(IN_BUFFER_SIZE, GFP_KERNEL); |
| 4252 | in_dentry = debugfs_create_file("audio_in_latency_measurement_node",\ |
| Glenn Kasten | 5dfda80 | 2012-10-04 16:40:27 -0700 | [diff] [blame] | 4253 | 0664,\ |
| Rajesha Kini | 3498c93 | 2011-07-19 19:58:27 +0530 | [diff] [blame] | 4254 | NULL, NULL, &audio_input_latency_debug_fops); |
| 4255 | if (IS_ERR(in_dentry)) |
| 4256 | pr_err("debugfs_create_file failed\n"); |
| 4257 | #endif |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4258 | return 0; |
| 4259 | } |
| 4260 | |
| 4261 | device_initcall(q6asm_init); |