Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <linux/fs.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/miscdevice.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/uaccess.h> |
| 19 | #include <linux/mutex.h> |
| 20 | #include <linux/sched.h> |
| 21 | #include <linux/msm_audio_acdb.h> |
| 22 | #include <asm/atomic.h> |
Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame^] | 23 | #include <mach/qdsp6v2/audio_acdb.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 24 | #include <mach/qdsp6v2/rtac.h> |
Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame^] | 25 | #include <sound/q6asm.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 26 | #include <sound/q6adm.h> |
| 27 | |
| 28 | |
| 29 | /* Max size of payload (buf size - apr header) */ |
| 30 | #define MAX_PAYLOAD_SIZE 4076 |
| 31 | #define RTAC_MAX_ACTIVE_DEVICES 4 |
| 32 | #define RTAC_MAX_ACTIVE_VOICE_COMBOS 2 |
| 33 | #define RTAC_MAX_ACTIVE_POPP 8 |
| 34 | #define RTAC_BUF_SIZE 4096 |
| 35 | |
| 36 | #define TIMEOUT_MS 1000 |
| 37 | |
| 38 | /* APR data */ |
| 39 | struct rtac_apr_data { |
| 40 | void *apr_handle; |
| 41 | atomic_t cmd_state; |
| 42 | wait_queue_head_t cmd_wait; |
| 43 | }; |
| 44 | |
| 45 | static struct rtac_apr_data rtac_adm_apr_data; |
| 46 | static struct rtac_apr_data rtac_asm_apr_data[SESSION_MAX+1]; |
| 47 | static struct rtac_apr_data rtac_voice_apr_data[RTAC_VOICE_MODES]; |
| 48 | |
| 49 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 50 | /* ADM info & APR */ |
| 51 | struct rtac_adm_data { |
Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame^] | 52 | uint32_t topology_id; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 53 | uint32_t afe_port; |
| 54 | uint32_t copp; |
| 55 | uint32_t num_of_popp; |
| 56 | uint32_t popp[RTAC_MAX_ACTIVE_POPP]; |
| 57 | }; |
| 58 | |
| 59 | struct rtac_adm { |
| 60 | uint32_t num_of_dev; |
| 61 | struct rtac_adm_data device[RTAC_MAX_ACTIVE_DEVICES]; |
| 62 | }; |
| 63 | static struct rtac_adm rtac_adm_data; |
| 64 | static u32 rtac_adm_payload_size; |
| 65 | static u32 rtac_adm_user_buf_size; |
| 66 | static u8 *rtac_adm_buffer; |
| 67 | |
| 68 | |
| 69 | /* ASM APR */ |
| 70 | static u32 rtac_asm_payload_size; |
| 71 | static u32 rtac_asm_user_buf_size; |
| 72 | static u8 *rtac_asm_buffer; |
| 73 | |
| 74 | |
| 75 | /* Voice info & APR */ |
| 76 | struct rtac_voice_data { |
Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame^] | 77 | uint32_t tx_topology_id; |
| 78 | uint32_t rx_topology_id; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 79 | uint32_t tx_afe_port; |
| 80 | uint32_t rx_afe_port; |
| 81 | uint16_t cvs_handle; |
| 82 | uint16_t cvp_handle; |
| 83 | }; |
| 84 | |
| 85 | struct rtac_voice { |
| 86 | uint32_t num_of_voice_combos; |
| 87 | struct rtac_voice_data voice[RTAC_MAX_ACTIVE_VOICE_COMBOS]; |
| 88 | }; |
| 89 | |
| 90 | static struct rtac_voice rtac_voice_data; |
| 91 | static u32 rtac_voice_payload_size; |
| 92 | static u32 rtac_voice_user_buf_size; |
| 93 | static u8 *rtac_voice_buffer; |
| 94 | |
| 95 | |
| 96 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 97 | struct mutex rtac_adm_mutex; |
| 98 | struct mutex rtac_adm_apr_mutex; |
| 99 | struct mutex rtac_asm_apr_mutex; |
| 100 | struct mutex rtac_voice_mutex; |
| 101 | struct mutex rtac_voice_apr_mutex; |
| 102 | |
| 103 | static int rtac_open(struct inode *inode, struct file *f) |
| 104 | { |
| 105 | pr_debug("%s\n", __func__); |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | static int rtac_release(struct inode *inode, struct file *f) |
| 110 | { |
| 111 | pr_debug("%s\n", __func__); |
| 112 | return 0; |
| 113 | } |
| 114 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 115 | /* ADM Info */ |
| 116 | void add_popp(u32 dev_idx, u32 port_id, u32 popp_id) |
| 117 | { |
| 118 | u32 i = 0; |
| 119 | |
| 120 | for (; i < rtac_adm_data.device[dev_idx].num_of_popp; i++) |
| 121 | if (rtac_adm_data.device[dev_idx].popp[i] == popp_id) |
| 122 | goto done; |
| 123 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 124 | if (rtac_adm_data.device[dev_idx].num_of_popp == |
| 125 | RTAC_MAX_ACTIVE_POPP) { |
| 126 | pr_err("%s, Max POPP!\n", __func__); |
| 127 | goto done; |
| 128 | } |
| 129 | rtac_adm_data.device[dev_idx].popp[ |
| 130 | rtac_adm_data.device[dev_idx].num_of_popp++] = popp_id; |
| 131 | done: |
| 132 | return; |
| 133 | } |
| 134 | |
Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame^] | 135 | void rtac_add_adm_device(u32 port_id, u32 copp_id, u32 path_id, u32 popp_id) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 136 | { |
| 137 | u32 i = 0; |
Swaminathan Sathappan | 88163a7 | 2011-08-01 16:01:14 -0700 | [diff] [blame] | 138 | pr_debug("%s: port_id = %d, popp_id = %d\n", __func__, port_id, |
| 139 | popp_id); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 140 | |
| 141 | mutex_lock(&rtac_adm_mutex); |
| 142 | if (rtac_adm_data.num_of_dev == RTAC_MAX_ACTIVE_DEVICES) { |
| 143 | pr_err("%s, Can't add anymore RTAC devices!\n", __func__); |
| 144 | goto done; |
| 145 | } |
| 146 | |
| 147 | /* Check if device already added */ |
| 148 | if (rtac_adm_data.num_of_dev != 0) { |
| 149 | for (; i < rtac_adm_data.num_of_dev; i++) { |
Swaminathan Sathappan | 88163a7 | 2011-08-01 16:01:14 -0700 | [diff] [blame] | 150 | if (rtac_adm_data.device[i].afe_port == port_id) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 151 | add_popp(i, port_id, popp_id); |
| 152 | goto done; |
Swaminathan Sathappan | 88163a7 | 2011-08-01 16:01:14 -0700 | [diff] [blame] | 153 | } |
| 154 | if (rtac_adm_data.device[i].num_of_popp == |
| 155 | RTAC_MAX_ACTIVE_POPP) { |
| 156 | pr_err("%s, Max POPP!\n", __func__); |
| 157 | goto done; |
| 158 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 162 | /* Add device */ |
| 163 | rtac_adm_data.num_of_dev++; |
Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame^] | 164 | |
| 165 | if (path_id == ADM_PATH_PLAYBACK) |
| 166 | rtac_adm_data.device[i].topology_id = |
| 167 | get_adm_rx_topology(); |
| 168 | else |
| 169 | rtac_adm_data.device[i].topology_id = |
| 170 | get_adm_tx_topology(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 171 | rtac_adm_data.device[i].afe_port = port_id; |
Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame^] | 172 | rtac_adm_data.device[i].copp = copp_id; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 173 | rtac_adm_data.device[i].popp[ |
| 174 | rtac_adm_data.device[i].num_of_popp++] = popp_id; |
| 175 | done: |
| 176 | mutex_unlock(&rtac_adm_mutex); |
| 177 | return; |
| 178 | } |
| 179 | |
Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame^] | 180 | static void shift_adm_devices(u32 dev_idx) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 181 | { |
Swaminathan Sathappan | 88163a7 | 2011-08-01 16:01:14 -0700 | [diff] [blame] | 182 | for (; dev_idx < rtac_adm_data.num_of_dev; dev_idx++) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 183 | memcpy(&rtac_adm_data.device[dev_idx], |
| 184 | &rtac_adm_data.device[dev_idx + 1], |
| 185 | sizeof(rtac_adm_data.device[dev_idx])); |
Swaminathan Sathappan | 88163a7 | 2011-08-01 16:01:14 -0700 | [diff] [blame] | 186 | memset(&rtac_adm_data.device[dev_idx + 1], 0, |
| 187 | sizeof(rtac_adm_data.device[dev_idx])); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 188 | } |
| 189 | } |
| 190 | |
Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame^] | 191 | static void shift_popp(u32 copp_idx, u32 popp_idx) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 192 | { |
Swaminathan Sathappan | 88163a7 | 2011-08-01 16:01:14 -0700 | [diff] [blame] | 193 | for (; popp_idx < rtac_adm_data.device[copp_idx].num_of_popp; |
| 194 | popp_idx++) { |
| 195 | memcpy(&rtac_adm_data.device[copp_idx].popp[popp_idx], |
| 196 | &rtac_adm_data.device[copp_idx].popp[popp_idx + 1], |
| 197 | sizeof(uint32_t)); |
| 198 | memset(&rtac_adm_data.device[copp_idx].popp[popp_idx + 1], 0, |
| 199 | sizeof(uint32_t)); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | void rtac_remove_adm_device(u32 port_id, u32 popp_id) |
| 204 | { |
| 205 | s32 i, j; |
| 206 | pr_debug("%s: port_id = %d, popp_id = %d\n", __func__, port_id, |
| 207 | popp_id); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 208 | |
| 209 | mutex_lock(&rtac_adm_mutex); |
| 210 | /* look for device */ |
| 211 | for (i = 0; i < rtac_adm_data.num_of_dev; i++) { |
| 212 | if (rtac_adm_data.device[i].afe_port == port_id) { |
Swaminathan Sathappan | 88163a7 | 2011-08-01 16:01:14 -0700 | [diff] [blame] | 213 | if (rtac_adm_data.device[i].num_of_popp == 1) { |
| 214 | memset(&rtac_adm_data.device[i], 0, |
| 215 | sizeof(rtac_adm_data.device[i])); |
| 216 | rtac_adm_data.num_of_dev--; |
| 217 | } else { |
| 218 | for (j = 0; j < |
| 219 | rtac_adm_data.device[i].num_of_popp; j++) { |
| 220 | if (rtac_adm_data.device[i].popp[j] == |
| 221 | popp_id) { |
| 222 | rtac_adm_data.device[i].popp[j] |
| 223 | = 0; |
| 224 | rtac_adm_data.device[i].num_of_popp--; |
| 225 | shift_popp(i, j); |
| 226 | goto done; |
| 227 | } |
| 228 | } |
| 229 | } |
Swaminathan Sathappan | 88163a7 | 2011-08-01 16:01:14 -0700 | [diff] [blame] | 230 | if (rtac_adm_data.num_of_dev >= 1) { |
| 231 | shift_adm_devices(i); |
| 232 | break; |
| 233 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 234 | } |
| 235 | } |
Swaminathan Sathappan | 88163a7 | 2011-08-01 16:01:14 -0700 | [diff] [blame] | 236 | done: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 237 | mutex_unlock(&rtac_adm_mutex); |
| 238 | return; |
| 239 | } |
| 240 | |
| 241 | |
| 242 | /* Voice Info */ |
Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame^] | 243 | static void set_rtac_voice_data(int idx, struct voice_data *v) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 244 | { |
Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame^] | 245 | rtac_voice_data.voice[idx].tx_topology_id = get_voice_tx_topology(); |
| 246 | rtac_voice_data.voice[idx].rx_topology_id = get_voice_rx_topology(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 247 | rtac_voice_data.voice[idx].tx_afe_port = v->dev_tx.dev_port_id; |
| 248 | rtac_voice_data.voice[idx].rx_afe_port = v->dev_rx.dev_port_id; |
| 249 | rtac_voice_data.voice[idx].cvs_handle = v->cvs_handle; |
| 250 | rtac_voice_data.voice[idx].cvp_handle = v->cvp_handle; |
| 251 | |
| 252 | } |
| 253 | |
| 254 | void rtac_add_voice(struct voice_data *v) |
| 255 | { |
| 256 | u32 i = 0; |
| 257 | pr_debug("%s\n", __func__); |
| 258 | mutex_lock(&rtac_voice_mutex); |
| 259 | |
| 260 | if (rtac_voice_data.num_of_voice_combos == |
| 261 | RTAC_MAX_ACTIVE_VOICE_COMBOS) { |
| 262 | pr_err("%s, Can't add anymore RTAC devices!\n", __func__); |
| 263 | goto done; |
| 264 | } |
| 265 | |
| 266 | /* Check if device already added */ |
| 267 | if (rtac_voice_data.num_of_voice_combos != 0) { |
| 268 | for (; i < rtac_voice_data.num_of_voice_combos; i++) { |
| 269 | if (rtac_voice_data.voice[i].cvp_handle == |
| 270 | v->cvp_handle) { |
| 271 | set_rtac_voice_data(i, v); |
| 272 | goto done; |
| 273 | } |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | /* Add device */ |
| 278 | rtac_voice_data.num_of_voice_combos++; |
| 279 | set_rtac_voice_data(i, v); |
| 280 | done: |
| 281 | mutex_unlock(&rtac_voice_mutex); |
| 282 | return; |
| 283 | } |
| 284 | |
Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame^] | 285 | static void shift_voice_devices(u32 idx) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 286 | { |
| 287 | for (; idx < rtac_voice_data.num_of_voice_combos - 1; idx++) { |
| 288 | memcpy(&rtac_voice_data.voice[idx], |
| 289 | &rtac_voice_data.voice[idx + 1], |
| 290 | sizeof(rtac_voice_data.voice[idx])); |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | void rtac_remove_voice(struct voice_data *v) |
| 295 | { |
| 296 | u32 i = 0; |
| 297 | pr_debug("%s\n", __func__); |
| 298 | |
| 299 | mutex_lock(&rtac_voice_mutex); |
| 300 | /* look for device */ |
| 301 | for (i = 0; i < rtac_voice_data.num_of_voice_combos; i++) { |
| 302 | if (rtac_voice_data.voice[i].cvp_handle == v->cvp_handle) { |
| 303 | shift_voice_devices(i); |
| 304 | rtac_voice_data.num_of_voice_combos--; |
| 305 | memset(&rtac_voice_data.voice[ |
| 306 | rtac_voice_data.num_of_voice_combos], 0, |
| 307 | sizeof(rtac_voice_data.voice |
| 308 | [rtac_voice_data.num_of_voice_combos])); |
| 309 | break; |
| 310 | } |
| 311 | } |
| 312 | mutex_unlock(&rtac_voice_mutex); |
| 313 | return; |
| 314 | } |
| 315 | |
| 316 | |
| 317 | |
| 318 | /* ADM APR */ |
| 319 | void rtac_set_adm_handle(void *handle) |
| 320 | { |
Swaminathan Sathappan | 88163a7 | 2011-08-01 16:01:14 -0700 | [diff] [blame] | 321 | pr_debug("%s: handle = %d\n", __func__, (unsigned int)handle); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 322 | |
| 323 | mutex_lock(&rtac_adm_apr_mutex); |
| 324 | rtac_adm_apr_data.apr_handle = handle; |
| 325 | mutex_unlock(&rtac_adm_apr_mutex); |
| 326 | } |
| 327 | |
| 328 | bool rtac_make_adm_callback(uint32_t *payload, u32 payload_size) |
| 329 | { |
Swaminathan Sathappan | 88163a7 | 2011-08-01 16:01:14 -0700 | [diff] [blame] | 330 | pr_debug("%s:cmd_state = %d\n", __func__, |
| 331 | atomic_read(&rtac_adm_apr_data.cmd_state)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 332 | if (atomic_read(&rtac_adm_apr_data.cmd_state) != 1) |
| 333 | return false; |
| 334 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 335 | /* Offset data for in-band payload */ |
| 336 | rtac_copy_adm_payload_to_user(payload, payload_size); |
| 337 | atomic_set(&rtac_adm_apr_data.cmd_state, 0); |
| 338 | wake_up(&rtac_adm_apr_data.cmd_wait); |
| 339 | return true; |
| 340 | } |
| 341 | |
| 342 | void rtac_copy_adm_payload_to_user(void *payload, u32 payload_size) |
| 343 | { |
| 344 | pr_debug("%s\n", __func__); |
| 345 | rtac_adm_payload_size = payload_size; |
| 346 | |
| 347 | memcpy(rtac_adm_buffer, &payload_size, sizeof(u32)); |
| 348 | if (payload_size != 0) { |
| 349 | if (payload_size > rtac_adm_user_buf_size) { |
| 350 | pr_err("%s: Buffer set not big enough for " |
| 351 | "returned data, buf size = %d, " |
| 352 | "ret data = %d\n", __func__, |
| 353 | rtac_adm_user_buf_size, payload_size); |
| 354 | goto done; |
| 355 | } |
| 356 | memcpy(rtac_adm_buffer + sizeof(u32), payload, payload_size); |
| 357 | } |
| 358 | done: |
| 359 | return; |
| 360 | } |
| 361 | |
| 362 | u32 send_adm_apr(void *buf, u32 opcode) |
| 363 | { |
| 364 | s32 result; |
| 365 | u32 count = 0; |
| 366 | u32 bytes_returned = 0; |
Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame^] | 367 | u32 port_index = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 368 | u32 copp_id; |
| 369 | u32 payload_size; |
| 370 | struct apr_hdr adm_params; |
| 371 | pr_debug("%s\n", __func__); |
| 372 | |
| 373 | if (copy_from_user(&count, (void *)buf, sizeof(count))) { |
| 374 | pr_err("%s: Copy to user failed! buf = 0x%x\n", |
| 375 | __func__, (unsigned int)buf); |
| 376 | result = -EFAULT; |
| 377 | goto done; |
| 378 | } |
| 379 | |
| 380 | if (count <= 0) { |
| 381 | pr_err("%s: Invalid buffer size = %d\n", __func__, count); |
| 382 | goto done; |
| 383 | } |
| 384 | |
| 385 | if (copy_from_user(&payload_size, buf + sizeof(u32), sizeof(u32))) { |
| 386 | pr_err("%s: Could not copy payload size from user buffer\n", |
| 387 | __func__); |
| 388 | goto done; |
| 389 | } |
| 390 | |
| 391 | |
| 392 | if ((payload_size < 0) || |
| 393 | (payload_size > MAX_PAYLOAD_SIZE)) { |
| 394 | |
| 395 | pr_err("%s: Invalid payload size = %d\n", |
| 396 | __func__, payload_size); |
| 397 | goto done; |
| 398 | } |
| 399 | |
| 400 | if (copy_from_user(&copp_id, buf + 2 * sizeof(u32), sizeof(u32))) { |
| 401 | pr_err("%s: Could not copy port id from user buffer\n", |
| 402 | __func__); |
| 403 | goto done; |
| 404 | } |
| 405 | |
Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame^] | 406 | for (port_index = 0; port_index < AFE_MAX_PORTS; port_index++) { |
| 407 | if (adm_get_copp_id(port_index) == copp_id) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 408 | break; |
| 409 | } |
Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame^] | 410 | if (port_index >= AFE_MAX_PORTS) { |
| 411 | pr_err("%s: Could not find port index for copp = %d\n", |
| 412 | __func__, copp_id); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 413 | goto done; |
| 414 | } |
| 415 | |
| 416 | mutex_lock(&rtac_adm_apr_mutex); |
| 417 | if (rtac_adm_apr_data.apr_handle == NULL) { |
| 418 | pr_err("%s: APR not initialized\n", __func__); |
| 419 | goto err; |
| 420 | } |
| 421 | |
| 422 | /* Set globals for copy of returned payload */ |
| 423 | rtac_adm_user_buf_size = count; |
| 424 | /* Copy buffer to in-band payload */ |
| 425 | if (copy_from_user(rtac_adm_buffer + sizeof(adm_params), |
| 426 | buf + 3 * sizeof(u32), payload_size)) { |
| 427 | pr_err("%s: Could not copy payload from user buffer\n", |
| 428 | __func__); |
| 429 | goto err; |
| 430 | } |
| 431 | |
| 432 | /* Pack header */ |
| 433 | adm_params.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 434 | APR_HDR_LEN(20), APR_PKT_VER); |
| 435 | adm_params.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 436 | payload_size); |
| 437 | adm_params.src_svc = APR_SVC_ADM; |
| 438 | adm_params.src_domain = APR_DOMAIN_APPS; |
Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame^] | 439 | adm_params.src_port = port_index; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 440 | adm_params.dest_svc = APR_SVC_ADM; |
| 441 | adm_params.dest_domain = APR_DOMAIN_ADSP; |
Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame^] | 442 | adm_params.dest_port = copp_id; |
| 443 | adm_params.token = port_index; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 444 | adm_params.opcode = opcode; |
| 445 | |
| 446 | memcpy(rtac_adm_buffer, &adm_params, sizeof(adm_params)); |
| 447 | atomic_set(&rtac_adm_apr_data.cmd_state, 1); |
| 448 | |
| 449 | pr_debug("%s: Sending RTAC command size = %d\n", |
| 450 | __func__, adm_params.pkt_size); |
| 451 | |
| 452 | result = apr_send_pkt(rtac_adm_apr_data.apr_handle, |
| 453 | (uint32_t *)rtac_adm_buffer); |
| 454 | if (result < 0) { |
Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame^] | 455 | pr_err("%s: Set params failed port = %d, copp = %d\n", |
| 456 | __func__, port_index, copp_id); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 457 | goto err; |
| 458 | } |
| 459 | /* Wait for the callback */ |
| 460 | result = wait_event_timeout(rtac_adm_apr_data.cmd_wait, |
| 461 | (atomic_read(&rtac_adm_apr_data.cmd_state) == 0), |
| 462 | msecs_to_jiffies(TIMEOUT_MS)); |
| 463 | mutex_unlock(&rtac_adm_apr_mutex); |
| 464 | if (!result) { |
Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame^] | 465 | pr_err("%s: Set params timed out port = %d, copp = %d\n", |
| 466 | __func__, port_index, copp_id); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 467 | goto done; |
| 468 | } |
| 469 | |
| 470 | if (rtac_adm_payload_size != 0) { |
| 471 | if (copy_to_user(buf, rtac_adm_buffer, |
| 472 | rtac_adm_payload_size + sizeof(u32))) { |
| 473 | pr_err("%s: Could not copy buffer to user," |
| 474 | "size = %d\n", __func__, payload_size); |
| 475 | goto done; |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | /* Return data written for SET & data read for GET */ |
| 480 | if (opcode == ADM_CMD_GET_PARAMS) |
| 481 | bytes_returned = rtac_adm_payload_size; |
| 482 | else |
| 483 | bytes_returned = payload_size; |
| 484 | done: |
| 485 | return bytes_returned; |
| 486 | err: |
| 487 | mutex_unlock(&rtac_adm_apr_mutex); |
| 488 | return bytes_returned; |
| 489 | } |
| 490 | |
| 491 | |
| 492 | /* ASM APR */ |
| 493 | void rtac_set_asm_handle(u32 session_id, void *handle) |
| 494 | { |
| 495 | pr_debug("%s\n", __func__); |
| 496 | |
| 497 | mutex_lock(&rtac_asm_apr_mutex); |
| 498 | rtac_asm_apr_data[session_id].apr_handle = handle; |
| 499 | mutex_unlock(&rtac_asm_apr_mutex); |
| 500 | } |
| 501 | |
| 502 | bool rtac_make_asm_callback(u32 session_id, uint32_t *payload, |
| 503 | u32 payload_size) |
| 504 | { |
| 505 | if (atomic_read(&rtac_asm_apr_data[session_id].cmd_state) != 1) |
| 506 | return false; |
| 507 | |
| 508 | pr_debug("%s\n", __func__); |
| 509 | /* Offset data for in-band payload */ |
| 510 | rtac_copy_asm_payload_to_user(payload, payload_size); |
| 511 | atomic_set(&rtac_asm_apr_data[session_id].cmd_state, 0); |
| 512 | wake_up(&rtac_asm_apr_data[session_id].cmd_wait); |
| 513 | return true; |
| 514 | } |
| 515 | |
| 516 | void rtac_copy_asm_payload_to_user(void *payload, u32 payload_size) |
| 517 | { |
| 518 | pr_debug("%s\n", __func__); |
| 519 | rtac_asm_payload_size = payload_size; |
| 520 | |
| 521 | memcpy(rtac_asm_buffer, &payload_size, sizeof(u32)); |
| 522 | if (payload_size) { |
| 523 | if (payload_size > rtac_asm_user_buf_size) { |
| 524 | pr_err("%s: Buffer set not big enough for " |
| 525 | "returned data, buf size = %d, " |
| 526 | "ret data = %d\n", __func__, |
| 527 | rtac_asm_user_buf_size, payload_size); |
| 528 | goto done; |
| 529 | } |
| 530 | memcpy(rtac_asm_buffer + sizeof(u32), payload, payload_size); |
| 531 | } |
| 532 | done: |
| 533 | return; |
| 534 | } |
| 535 | |
| 536 | u32 send_rtac_asm_apr(void *buf, u32 opcode) |
| 537 | { |
| 538 | s32 result; |
| 539 | u32 count = 0; |
| 540 | u32 bytes_returned = 0; |
| 541 | u32 session_id = 0; |
| 542 | u32 payload_size; |
| 543 | struct apr_hdr asm_params; |
| 544 | pr_debug("%s\n", __func__); |
| 545 | |
| 546 | if (copy_from_user(&count, (void *)buf, sizeof(count))) { |
| 547 | pr_err("%s: Copy to user failed! buf = 0x%x\n", |
| 548 | __func__, (unsigned int)buf); |
| 549 | result = -EFAULT; |
| 550 | goto done; |
| 551 | } |
| 552 | |
| 553 | if (count <= 0) { |
| 554 | pr_err("%s: Invalid buffer size = %d\n", __func__, count); |
| 555 | goto done; |
| 556 | } |
| 557 | |
| 558 | if (copy_from_user(&payload_size, buf + sizeof(u32), sizeof(u32))) { |
| 559 | pr_err("%s: Could not copy payload size from user buffer\n", |
| 560 | __func__); |
| 561 | goto done; |
| 562 | } |
| 563 | |
| 564 | if ((payload_size < 0) || |
| 565 | (payload_size > MAX_PAYLOAD_SIZE)) { |
| 566 | |
| 567 | pr_err("%s: Invalid payload size = %d\n", |
| 568 | __func__, payload_size); |
| 569 | goto done; |
| 570 | } |
| 571 | |
| 572 | if (copy_from_user(&session_id, buf + 2 * sizeof(u32), sizeof(u32))) { |
| 573 | pr_err("%s: Could not copy session id from user buffer\n", |
| 574 | __func__); |
| 575 | goto done; |
| 576 | } |
| 577 | if (session_id >= AFE_MAX_PORTS) { |
| 578 | pr_err("%s: Invalid Session = %d\n", __func__, session_id); |
| 579 | goto done; |
| 580 | } |
| 581 | |
| 582 | mutex_lock(&rtac_asm_apr_mutex); |
| 583 | if (rtac_asm_apr_data[session_id].apr_handle == NULL) { |
| 584 | pr_err("%s: APR not initialized\n", __func__); |
| 585 | goto err; |
| 586 | } |
| 587 | |
| 588 | /* Set globals for copy of returned payload */ |
| 589 | rtac_asm_user_buf_size = count; |
| 590 | |
| 591 | /* Copy buffer to in-band payload */ |
| 592 | if (copy_from_user(rtac_asm_buffer + sizeof(asm_params), |
| 593 | buf + 3 * sizeof(u32), payload_size)) { |
| 594 | pr_err("%s: Could not copy payload from user buffer\n", |
| 595 | __func__); |
| 596 | goto err; |
| 597 | } |
| 598 | |
| 599 | /* Pack header */ |
| 600 | asm_params.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 601 | APR_HDR_LEN(20), APR_PKT_VER); |
| 602 | asm_params.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 603 | payload_size); |
| 604 | asm_params.src_svc = q6asm_get_apr_service_id(session_id); |
| 605 | asm_params.src_domain = APR_DOMAIN_APPS; |
| 606 | asm_params.src_port = (session_id << 8) | 0x0001; |
| 607 | asm_params.dest_svc = APR_SVC_ASM; |
| 608 | asm_params.dest_domain = APR_DOMAIN_ADSP; |
| 609 | asm_params.dest_port = (session_id << 8) | 0x0001; |
| 610 | asm_params.token = session_id; |
| 611 | asm_params.opcode = opcode; |
| 612 | |
| 613 | memcpy(rtac_asm_buffer, &asm_params, sizeof(asm_params)); |
| 614 | atomic_set(&rtac_asm_apr_data[session_id].cmd_state, 1); |
| 615 | |
| 616 | pr_debug("%s: Sending RTAC command size = %d, session_id=%d\n", |
| 617 | __func__, asm_params.pkt_size, session_id); |
| 618 | |
| 619 | result = apr_send_pkt(rtac_asm_apr_data[session_id].apr_handle, |
| 620 | (uint32_t *)rtac_asm_buffer); |
| 621 | if (result < 0) { |
| 622 | pr_err("%s: Set params failed session = %d\n", |
| 623 | __func__, session_id); |
| 624 | goto err; |
| 625 | } |
| 626 | |
| 627 | /* Wait for the callback */ |
| 628 | result = wait_event_timeout(rtac_asm_apr_data[session_id].cmd_wait, |
| 629 | (atomic_read(&rtac_asm_apr_data[session_id].cmd_state) == 0), |
| 630 | 5 * HZ); |
| 631 | mutex_unlock(&rtac_asm_apr_mutex); |
| 632 | if (!result) { |
| 633 | pr_err("%s: Set params timed out session = %d\n", |
| 634 | __func__, session_id); |
| 635 | goto done; |
| 636 | } |
| 637 | |
| 638 | if (rtac_asm_payload_size != 0) { |
| 639 | if (copy_to_user(buf, rtac_asm_buffer, |
| 640 | rtac_asm_payload_size + sizeof(u32))) { |
| 641 | pr_err("%s: Could not copy buffer to user," |
| 642 | "size = %d\n", __func__, payload_size); |
| 643 | goto done; |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | /* Return data written for SET & data read for GET */ |
| 648 | if (opcode == ASM_STREAM_CMD_GET_PP_PARAMS) |
| 649 | bytes_returned = rtac_asm_payload_size; |
| 650 | else |
| 651 | bytes_returned = payload_size; |
| 652 | done: |
| 653 | return bytes_returned; |
| 654 | err: |
| 655 | mutex_unlock(&rtac_asm_apr_mutex); |
| 656 | return bytes_returned; |
| 657 | } |
| 658 | |
| 659 | |
| 660 | /* Voice APR */ |
| 661 | void rtac_set_voice_handle(u32 mode, void *handle) |
| 662 | { |
| 663 | pr_debug("%s\n", __func__); |
| 664 | |
| 665 | mutex_lock(&rtac_voice_apr_mutex); |
| 666 | rtac_voice_apr_data[mode].apr_handle = handle; |
| 667 | mutex_unlock(&rtac_voice_apr_mutex); |
| 668 | } |
| 669 | |
| 670 | bool rtac_make_voice_callback(u32 mode, uint32_t *payload, u32 payload_size) |
| 671 | { |
| 672 | if ((atomic_read(&rtac_voice_apr_data[mode].cmd_state) != 1) || |
| 673 | (mode < 0) || (mode >= RTAC_VOICE_MODES)) |
| 674 | return false; |
| 675 | |
| 676 | pr_debug("%s\n", __func__); |
| 677 | /* Offset data for in-band payload */ |
| 678 | rtac_copy_voice_payload_to_user(payload, payload_size); |
| 679 | atomic_set(&rtac_voice_apr_data[mode].cmd_state, 0); |
| 680 | wake_up(&rtac_voice_apr_data[mode].cmd_wait); |
| 681 | return true; |
| 682 | } |
| 683 | |
| 684 | void rtac_copy_voice_payload_to_user(void *payload, u32 payload_size) |
| 685 | { |
| 686 | pr_debug("%s\n", __func__); |
| 687 | rtac_voice_payload_size = payload_size; |
| 688 | |
| 689 | memcpy(rtac_voice_buffer, &payload_size, sizeof(u32)); |
| 690 | if (payload_size) { |
| 691 | if (payload_size > rtac_voice_user_buf_size) { |
| 692 | pr_err("%s: Buffer set not big enough for " |
| 693 | "returned data, buf size = %d, " |
| 694 | "ret data = %d\n", __func__, |
| 695 | rtac_voice_user_buf_size, payload_size); |
| 696 | goto done; |
| 697 | } |
| 698 | memcpy(rtac_voice_buffer + sizeof(u32), payload, payload_size); |
| 699 | } |
| 700 | done: |
| 701 | return; |
| 702 | } |
| 703 | |
| 704 | u32 send_voice_apr(u32 mode, void *buf, u32 opcode) |
| 705 | { |
| 706 | s32 result; |
| 707 | u32 count = 0; |
| 708 | u32 bytes_returned = 0; |
| 709 | u32 payload_size; |
| 710 | u16 dest_port; |
| 711 | struct apr_hdr voice_params; |
| 712 | pr_debug("%s\n", __func__); |
| 713 | |
| 714 | if (copy_from_user(&count, (void *)buf, sizeof(count))) { |
| 715 | pr_err("%s: Copy to user failed! buf = 0x%x\n", |
| 716 | __func__, (unsigned int)buf); |
| 717 | result = -EFAULT; |
| 718 | goto done; |
| 719 | } |
| 720 | |
| 721 | if (count <= 0) { |
| 722 | pr_err("%s: Invalid buffer size = %d\n", __func__, count); |
| 723 | goto done; |
| 724 | } |
| 725 | |
| 726 | if (copy_from_user(&payload_size, buf + sizeof(u32), sizeof(u32))) { |
| 727 | pr_err("%s: Could not copy payload size from user buffer\n", |
| 728 | __func__); |
| 729 | goto done; |
| 730 | } |
| 731 | |
| 732 | if ((payload_size < 0) || |
| 733 | (payload_size > MAX_PAYLOAD_SIZE)) { |
| 734 | |
| 735 | pr_err("%s: Invalid payload size = %d\n", |
| 736 | __func__, payload_size); |
| 737 | goto done; |
| 738 | } |
| 739 | |
| 740 | if (copy_from_user(&dest_port, buf + 2 * sizeof(u32), sizeof(u32))) { |
| 741 | pr_err("%s: Could not copy port id from user buffer\n", |
| 742 | __func__); |
| 743 | goto done; |
| 744 | } |
| 745 | |
| 746 | if ((mode != RTAC_CVP) && (mode != RTAC_CVS)) { |
| 747 | pr_err("%s: Invalid Mode for APR, mode = %d\n", |
| 748 | __func__, mode); |
| 749 | goto done; |
| 750 | } |
| 751 | |
| 752 | mutex_lock(&rtac_voice_apr_mutex); |
| 753 | if (rtac_voice_apr_data[mode].apr_handle == NULL) { |
| 754 | pr_err("%s: APR not initialized\n", __func__); |
| 755 | goto err; |
| 756 | } |
| 757 | |
| 758 | /* Set globals for copy of returned payload */ |
| 759 | rtac_voice_user_buf_size = count; |
| 760 | |
| 761 | /* Copy buffer to in-band payload */ |
| 762 | if (copy_from_user(rtac_voice_buffer + sizeof(voice_params), |
| 763 | buf + 3 * sizeof(u32), payload_size)) { |
| 764 | pr_err("%s: Could not copy payload from user buffer\n", |
| 765 | __func__); |
| 766 | goto err; |
| 767 | } |
| 768 | |
| 769 | /* Pack header */ |
| 770 | voice_params.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 771 | APR_HDR_LEN(20), APR_PKT_VER); |
| 772 | voice_params.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 773 | payload_size); |
| 774 | voice_params.src_svc = 0; |
| 775 | voice_params.src_domain = APR_DOMAIN_APPS; |
| 776 | voice_params.src_port = 0; |
| 777 | voice_params.dest_svc = 0; |
| 778 | voice_params.dest_domain = APR_DOMAIN_MODEM; |
| 779 | voice_params.dest_port = dest_port; |
| 780 | voice_params.token = 0; |
| 781 | voice_params.opcode = opcode; |
| 782 | |
| 783 | memcpy(rtac_voice_buffer, &voice_params, sizeof(voice_params)); |
| 784 | atomic_set(&rtac_voice_apr_data[mode].cmd_state, 1); |
| 785 | |
| 786 | pr_debug("%s: Sending RTAC command size = %d, opcode = %x\n", |
| 787 | __func__, voice_params.pkt_size, opcode); |
| 788 | |
| 789 | result = apr_send_pkt(rtac_voice_apr_data[mode].apr_handle, |
| 790 | (uint32_t *)rtac_voice_buffer); |
| 791 | if (result < 0) { |
| 792 | pr_err("%s: apr_send_pkt failed opcode = %x\n", |
| 793 | __func__, opcode); |
| 794 | goto err; |
| 795 | } |
| 796 | /* Wait for the callback */ |
| 797 | result = wait_event_timeout(rtac_voice_apr_data[mode].cmd_wait, |
| 798 | (atomic_read(&rtac_voice_apr_data[mode].cmd_state) == 0), |
| 799 | msecs_to_jiffies(TIMEOUT_MS)); |
| 800 | mutex_unlock(&rtac_voice_apr_mutex); |
| 801 | if (!result) { |
| 802 | pr_err("%s: apr_send_pkt timed out opcode = %x\n", |
| 803 | __func__, opcode); |
| 804 | goto done; |
| 805 | } |
| 806 | |
| 807 | if (rtac_voice_payload_size != 0) { |
| 808 | if (copy_to_user(buf, rtac_voice_buffer, |
| 809 | rtac_voice_payload_size + sizeof(u32))) { |
| 810 | pr_err("%s: Could not copy buffer to user," |
| 811 | "size = %d\n", __func__, payload_size); |
| 812 | goto done; |
| 813 | } |
| 814 | } |
| 815 | |
| 816 | /* Return data written for SET & data read for GET */ |
| 817 | if (opcode == VOICE_CMD_GET_PARAM) |
| 818 | bytes_returned = rtac_voice_payload_size; |
| 819 | else |
| 820 | bytes_returned = payload_size; |
| 821 | done: |
| 822 | return bytes_returned; |
| 823 | err: |
| 824 | mutex_unlock(&rtac_voice_apr_mutex); |
| 825 | return bytes_returned; |
| 826 | } |
| 827 | |
| 828 | |
| 829 | |
Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame^] | 830 | static long rtac_ioctl(struct file *f, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 831 | unsigned int cmd, unsigned long arg) |
| 832 | { |
| 833 | s32 result = 0; |
| 834 | pr_debug("%s\n", __func__); |
| 835 | |
| 836 | if (arg == 0) { |
| 837 | pr_err("%s: No data sent to driver!\n", __func__); |
| 838 | result = -EFAULT; |
| 839 | goto done; |
| 840 | } |
| 841 | |
| 842 | switch (cmd) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 843 | case AUDIO_GET_RTAC_ADM_INFO: |
| 844 | if (copy_to_user((void *)arg, &rtac_adm_data, |
| 845 | sizeof(rtac_adm_data))) |
| 846 | pr_err("%s: Could not copy to userspace!\n", __func__); |
| 847 | else |
| 848 | result = sizeof(rtac_adm_data); |
| 849 | break; |
| 850 | case AUDIO_GET_RTAC_VOICE_INFO: |
| 851 | if (copy_to_user((void *)arg, &rtac_voice_data, |
| 852 | sizeof(rtac_voice_data))) |
| 853 | pr_err("%s: Could not copy to userspace!\n", __func__); |
| 854 | else |
| 855 | result = sizeof(rtac_voice_data); |
| 856 | break; |
| 857 | case AUDIO_GET_RTAC_ADM_CAL: |
| 858 | result = send_adm_apr((void *)arg, ADM_CMD_GET_PARAMS); |
| 859 | break; |
| 860 | case AUDIO_SET_RTAC_ADM_CAL: |
| 861 | result = send_adm_apr((void *)arg, ADM_CMD_SET_PARAMS); |
| 862 | break; |
| 863 | case AUDIO_GET_RTAC_ASM_CAL: |
| 864 | result = send_rtac_asm_apr((void *)arg, |
| 865 | ASM_STREAM_CMD_GET_PP_PARAMS); |
| 866 | break; |
| 867 | case AUDIO_SET_RTAC_ASM_CAL: |
| 868 | result = send_rtac_asm_apr((void *)arg, |
| 869 | ASM_STREAM_CMD_SET_PP_PARAMS); |
| 870 | break; |
| 871 | case AUDIO_GET_RTAC_CVS_CAL: |
| 872 | result = send_voice_apr(RTAC_CVS, (void *)arg, |
| 873 | VOICE_CMD_GET_PARAM); |
| 874 | break; |
| 875 | case AUDIO_SET_RTAC_CVS_CAL: |
| 876 | result = send_voice_apr(RTAC_CVS, (void *)arg, |
| 877 | VOICE_CMD_SET_PARAM); |
| 878 | break; |
| 879 | case AUDIO_GET_RTAC_CVP_CAL: |
| 880 | result = send_voice_apr(RTAC_CVP, (void *)arg, |
| 881 | VOICE_CMD_GET_PARAM); |
| 882 | break; |
| 883 | case AUDIO_SET_RTAC_CVP_CAL: |
| 884 | result = send_voice_apr(RTAC_CVP, (void *)arg, |
| 885 | VOICE_CMD_SET_PARAM); |
| 886 | break; |
| 887 | default: |
| 888 | pr_err("%s: Invalid IOCTL, command = %d!\n", |
| 889 | __func__, cmd); |
| 890 | } |
| 891 | done: |
| 892 | return result; |
| 893 | } |
| 894 | |
| 895 | |
| 896 | static const struct file_operations rtac_fops = { |
| 897 | .owner = THIS_MODULE, |
| 898 | .open = rtac_open, |
| 899 | .release = rtac_release, |
Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame^] | 900 | .unlocked_ioctl = rtac_ioctl, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 901 | }; |
| 902 | |
| 903 | struct miscdevice rtac_misc = { |
| 904 | .minor = MISC_DYNAMIC_MINOR, |
| 905 | .name = "msm_rtac", |
| 906 | .fops = &rtac_fops, |
| 907 | }; |
| 908 | |
| 909 | static int __init rtac_init(void) |
| 910 | { |
| 911 | int i = 0; |
| 912 | pr_debug("%s\n", __func__); |
| 913 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 914 | /* ADM */ |
| 915 | memset(&rtac_adm_data, 0, sizeof(rtac_adm_data)); |
| 916 | rtac_adm_apr_data.apr_handle = NULL; |
| 917 | atomic_set(&rtac_adm_apr_data.cmd_state, 0); |
| 918 | init_waitqueue_head(&rtac_adm_apr_data.cmd_wait); |
| 919 | mutex_init(&rtac_adm_mutex); |
| 920 | mutex_init(&rtac_adm_apr_mutex); |
| 921 | |
| 922 | rtac_adm_buffer = kmalloc(RTAC_BUF_SIZE, GFP_KERNEL); |
| 923 | if (rtac_adm_buffer == NULL) { |
| 924 | pr_err("%s: Could not allocate payload of size = %d\n", |
| 925 | __func__, RTAC_BUF_SIZE); |
| 926 | goto nomem; |
| 927 | } |
| 928 | |
| 929 | /* ASM */ |
| 930 | for (i = 0; i < SESSION_MAX+1; i++) { |
| 931 | rtac_asm_apr_data[i].apr_handle = NULL; |
| 932 | atomic_set(&rtac_asm_apr_data[i].cmd_state, 0); |
| 933 | init_waitqueue_head(&rtac_asm_apr_data[i].cmd_wait); |
| 934 | } |
| 935 | mutex_init(&rtac_asm_apr_mutex); |
| 936 | |
| 937 | rtac_asm_buffer = kmalloc(RTAC_BUF_SIZE, GFP_KERNEL); |
| 938 | if (rtac_asm_buffer == NULL) { |
| 939 | pr_err("%s: Could not allocate payload of size = %d\n", |
| 940 | __func__, RTAC_BUF_SIZE); |
| 941 | goto nomem; |
| 942 | } |
| 943 | |
| 944 | /* Voice */ |
| 945 | memset(&rtac_voice_data, 0, sizeof(rtac_voice_data)); |
| 946 | for (i = 0; i < RTAC_VOICE_MODES; i++) { |
| 947 | rtac_voice_apr_data[i].apr_handle = NULL; |
| 948 | atomic_set(&rtac_voice_apr_data[i].cmd_state, 0); |
| 949 | init_waitqueue_head(&rtac_voice_apr_data[i].cmd_wait); |
| 950 | } |
| 951 | mutex_init(&rtac_voice_mutex); |
| 952 | mutex_init(&rtac_voice_apr_mutex); |
| 953 | |
| 954 | rtac_voice_buffer = kmalloc(RTAC_BUF_SIZE, GFP_KERNEL); |
| 955 | if (rtac_voice_buffer == NULL) { |
| 956 | pr_err("%s: Could not allocate payload of size = %d\n", |
| 957 | __func__, RTAC_BUF_SIZE); |
| 958 | goto nomem; |
| 959 | } |
| 960 | |
| 961 | return misc_register(&rtac_misc); |
| 962 | nomem: |
| 963 | return -ENOMEM; |
| 964 | } |
| 965 | |
| 966 | module_init(rtac_init); |
| 967 | |
| 968 | MODULE_DESCRIPTION("MSM 8x60 Real-Time Audio Calibration driver"); |
| 969 | MODULE_LICENSE("GPL v2"); |