| Ben Romberger | 48fabc3 | 2012-01-06 17:39:39 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2010-2012, Code Aurora Forum. All rights reserved. |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 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 | #include <linux/slab.h> |
| 14 | #include <linux/wait.h> |
| 15 | #include <linux/sched.h> |
| 16 | #include <linux/jiffies.h> |
| 17 | #include <linux/uaccess.h> |
| 18 | #include <linux/atomic.h> |
| Ben Romberger | fce8f51 | 2011-07-18 16:46:09 -0700 | [diff] [blame] | 19 | |
| 20 | #include <mach/qdsp6v2/audio_dev_ctl.h> |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 21 | #include <mach/qdsp6v2/audio_acdb.h> |
| Ben Romberger | fce8f51 | 2011-07-18 16:46:09 -0700 | [diff] [blame] | 22 | #include <mach/qdsp6v2/rtac.h> |
| 23 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 24 | #include <sound/apr_audio.h> |
| 25 | #include <sound/q6afe.h> |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 26 | |
| 27 | #define TIMEOUT_MS 1000 |
| 28 | #define AUDIO_RX 0x0 |
| 29 | #define AUDIO_TX 0x1 |
| Patrick Lai | cf99911 | 2011-08-23 11:27:20 -0700 | [diff] [blame] | 30 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 31 | #define ASM_MAX_SESSION 0x8 /* To do: define in a header */ |
| 32 | #define RESET_COPP_ID 99 |
| 33 | #define INVALID_COPP_ID 0xFF |
| 34 | |
| 35 | struct adm_ctl { |
| 36 | void *apr; |
| 37 | atomic_t copp_id[AFE_MAX_PORTS]; |
| 38 | atomic_t copp_cnt[AFE_MAX_PORTS]; |
| 39 | atomic_t copp_stat[AFE_MAX_PORTS]; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 40 | wait_queue_head_t wait; |
| Jayasena Sangaraboina | f4ab0df | 2012-06-06 22:38:40 -0700 | [diff] [blame] | 41 | int ec_ref_rx; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 42 | }; |
| 43 | |
| Ben Romberger | 48fabc3 | 2012-01-06 17:39:39 -0800 | [diff] [blame] | 44 | static struct acdb_cal_block mem_addr_audproc[MAX_AUDPROC_TYPES]; |
| 45 | static struct acdb_cal_block mem_addr_audvol[MAX_AUDPROC_TYPES]; |
| 46 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 47 | static struct adm_ctl this_adm; |
| 48 | |
| Jayasena Sangaraboina | f4ab0df | 2012-06-06 22:38:40 -0700 | [diff] [blame] | 49 | |
| Sriranjan Srikantam | 22bee8b | 2012-05-31 15:21:53 -0700 | [diff] [blame] | 50 | int srs_trumedia_open(int port_id, int srs_tech_id, void *srs_params) |
| 51 | { |
| 52 | struct asm_pp_params_command *open = NULL; |
| 53 | int ret = 0, sz = 0; |
| 54 | int index; |
| 55 | |
| 56 | pr_debug("SRS - %s", __func__); |
| 57 | switch (srs_tech_id) { |
| 58 | case SRS_ID_GLOBAL: { |
| 59 | struct srs_trumedia_params_GLOBAL *glb_params = NULL; |
| 60 | sz = sizeof(struct asm_pp_params_command) + |
| 61 | sizeof(struct srs_trumedia_params_GLOBAL); |
| 62 | open = kzalloc(sz, GFP_KERNEL); |
| 63 | open->payload_size = sizeof(struct srs_trumedia_params_GLOBAL) + |
| 64 | sizeof(struct asm_pp_param_data_hdr); |
| 65 | open->params.param_id = SRS_TRUMEDIA_PARAMS; |
| 66 | open->params.param_size = |
| 67 | sizeof(struct srs_trumedia_params_GLOBAL); |
| 68 | glb_params = (struct srs_trumedia_params_GLOBAL *)((u8 *)open + |
| 69 | sizeof(struct asm_pp_params_command)); |
| 70 | memcpy(glb_params, srs_params, |
| 71 | sizeof(struct srs_trumedia_params_GLOBAL)); |
| 72 | pr_debug("SRS - %s: Global params - 1 = %x, 2 = %x, 3 = %x," |
| 73 | " 4 = %x, 5 = %x, 6 = %x, 7 = %x, 8 = %x\n", |
| 74 | __func__, (int)glb_params->v1, |
| 75 | (int)glb_params->v2, (int)glb_params->v3, |
| 76 | (int)glb_params->v4, (int)glb_params->v5, |
| 77 | (int)glb_params->v6, (int)glb_params->v7, |
| 78 | (int)glb_params->v8); |
| 79 | break; |
| 80 | } |
| 81 | case SRS_ID_WOWHD: { |
| 82 | struct srs_trumedia_params_WOWHD *whd_params = NULL; |
| 83 | sz = sizeof(struct asm_pp_params_command) + |
| 84 | sizeof(struct srs_trumedia_params_WOWHD); |
| 85 | open = kzalloc(sz, GFP_KERNEL); |
| 86 | open->payload_size = sizeof(struct srs_trumedia_params_WOWHD) + |
| 87 | sizeof(struct asm_pp_param_data_hdr); |
| 88 | open->params.param_id = SRS_TRUMEDIA_PARAMS_WOWHD; |
| 89 | open->params.param_size = |
| 90 | sizeof(struct srs_trumedia_params_WOWHD); |
| 91 | whd_params = (struct srs_trumedia_params_WOWHD *)((u8 *)open + |
| 92 | sizeof(struct asm_pp_params_command)); |
| 93 | memcpy(whd_params, srs_params, |
| 94 | sizeof(struct srs_trumedia_params_WOWHD)); |
| 95 | pr_debug("SRS - %s: WOWHD params - 1 = %x, 2 = %x, 3 = %x," |
| 96 | " 4 = %x, 5 = %x, 6 = %x, 7 = %x, 8 = %x, 9 = %x," |
| 97 | " 10 = %x, 11 = %x\n", __func__, (int)whd_params->v1, |
| 98 | (int)whd_params->v2, (int)whd_params->v3, |
| 99 | (int)whd_params->v4, (int)whd_params->v5, |
| 100 | (int)whd_params->v6, (int)whd_params->v7, |
| 101 | (int)whd_params->v8, (int)whd_params->v9, |
| 102 | (int)whd_params->v10, (int)whd_params->v11); |
| 103 | break; |
| 104 | } |
| 105 | case SRS_ID_CSHP: { |
| 106 | struct srs_trumedia_params_CSHP *chp_params = NULL; |
| 107 | sz = sizeof(struct asm_pp_params_command) + |
| 108 | sizeof(struct srs_trumedia_params_CSHP); |
| 109 | open = kzalloc(sz, GFP_KERNEL); |
| 110 | open->payload_size = sizeof(struct srs_trumedia_params_CSHP) + |
| 111 | sizeof(struct asm_pp_param_data_hdr); |
| 112 | open->params.param_id = SRS_TRUMEDIA_PARAMS_CSHP; |
| 113 | open->params.param_size = |
| 114 | sizeof(struct srs_trumedia_params_CSHP); |
| 115 | chp_params = (struct srs_trumedia_params_CSHP *)((u8 *)open + |
| 116 | sizeof(struct asm_pp_params_command)); |
| 117 | memcpy(chp_params, srs_params, |
| 118 | sizeof(struct srs_trumedia_params_CSHP)); |
| 119 | pr_debug("SRS - %s: CSHP params - 1 = %x, 2 = %x, 3 = %x," |
| 120 | " 4 = %x, 5 = %x, 6 = %x, 7 = %x, 8 = %x," |
| 121 | " 9 = %x\n", __func__, (int)chp_params->v1, |
| 122 | (int)chp_params->v2, (int)chp_params->v3, |
| 123 | (int)chp_params->v4, (int)chp_params->v5, |
| 124 | (int)chp_params->v6, (int)chp_params->v7, |
| 125 | (int)chp_params->v8, (int)chp_params->v9); |
| 126 | break; |
| 127 | } |
| 128 | case SRS_ID_HPF: { |
| 129 | struct srs_trumedia_params_HPF *hpf_params = NULL; |
| 130 | sz = sizeof(struct asm_pp_params_command) + |
| 131 | sizeof(struct srs_trumedia_params_HPF); |
| 132 | open = kzalloc(sz, GFP_KERNEL); |
| 133 | open->payload_size = sizeof(struct srs_trumedia_params_HPF) + |
| 134 | sizeof(struct asm_pp_param_data_hdr); |
| 135 | open->params.param_id = SRS_TRUMEDIA_PARAMS_HPF; |
| 136 | open->params.param_size = |
| 137 | sizeof(struct srs_trumedia_params_HPF); |
| 138 | hpf_params = (struct srs_trumedia_params_HPF *)((u8 *)open + |
| 139 | sizeof(struct asm_pp_params_command)); |
| 140 | memcpy(hpf_params, srs_params, |
| 141 | sizeof(struct srs_trumedia_params_HPF)); |
| 142 | pr_debug("SRS - %s: HPF params - 1 = %x\n", __func__, |
| 143 | (int)hpf_params->v1); |
| 144 | break; |
| 145 | } |
| 146 | case SRS_ID_PEQ: { |
| 147 | struct srs_trumedia_params_PEQ *peq_params = NULL; |
| 148 | sz = sizeof(struct asm_pp_params_command) + |
| 149 | sizeof(struct srs_trumedia_params_PEQ); |
| 150 | open = kzalloc(sz, GFP_KERNEL); |
| 151 | open->payload_size = sizeof(struct srs_trumedia_params_PEQ) + |
| 152 | sizeof(struct asm_pp_param_data_hdr); |
| 153 | open->params.param_id = SRS_TRUMEDIA_PARAMS_PEQ; |
| 154 | open->params.param_size = |
| 155 | sizeof(struct srs_trumedia_params_PEQ); |
| 156 | peq_params = (struct srs_trumedia_params_PEQ *)((u8 *)open + |
| 157 | sizeof(struct asm_pp_params_command)); |
| 158 | memcpy(peq_params, srs_params, |
| 159 | sizeof(struct srs_trumedia_params_PEQ)); |
| 160 | pr_debug("SRS - %s: PEQ params - 1 = %x 2 = %x, 3 = %x," |
| 161 | " 4 = %x\n", __func__, (int)peq_params->v1, |
| 162 | (int)peq_params->v2, (int)peq_params->v3, |
| 163 | (int)peq_params->v4); |
| 164 | break; |
| 165 | } |
| 166 | case SRS_ID_HL: { |
| 167 | struct srs_trumedia_params_HL *hl_params = NULL; |
| 168 | sz = sizeof(struct asm_pp_params_command) + |
| 169 | sizeof(struct srs_trumedia_params_HL); |
| 170 | open = kzalloc(sz, GFP_KERNEL); |
| 171 | open->payload_size = sizeof(struct srs_trumedia_params_HL) + |
| 172 | sizeof(struct asm_pp_param_data_hdr); |
| 173 | open->params.param_id = SRS_TRUMEDIA_PARAMS_HL; |
| 174 | open->params.param_size = sizeof(struct srs_trumedia_params_HL); |
| 175 | hl_params = (struct srs_trumedia_params_HL *)((u8 *)open + |
| 176 | sizeof(struct asm_pp_params_command)); |
| 177 | memcpy(hl_params, srs_params, |
| 178 | sizeof(struct srs_trumedia_params_HL)); |
| 179 | pr_debug("SRS - %s: HL params - 1 = %x, 2 = %x, 3 = %x, 4 = %x," |
| 180 | " 5 = %x, 6 = %x, 7 = %x\n", __func__, |
| 181 | (int)hl_params->v1, (int)hl_params->v2, |
| 182 | (int)hl_params->v3, (int)hl_params->v4, |
| 183 | (int)hl_params->v5, (int)hl_params->v6, |
| 184 | (int)hl_params->v7); |
| 185 | break; |
| 186 | } |
| 187 | default: |
| 188 | goto fail_cmd; |
| 189 | } |
| 190 | |
| 191 | open->payload = NULL; |
| 192 | open->params.module_id = SRS_TRUMEDIA_MODULE_ID; |
| 193 | open->params.reserved = 0; |
| 194 | open->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 195 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 196 | open->hdr.pkt_size = sz; |
| 197 | open->hdr.src_svc = APR_SVC_ADM; |
| 198 | open->hdr.src_domain = APR_DOMAIN_APPS; |
| 199 | open->hdr.src_port = port_id; |
| 200 | open->hdr.dest_svc = APR_SVC_ADM; |
| 201 | open->hdr.dest_domain = APR_DOMAIN_ADSP; |
| 202 | index = afe_get_port_index(port_id); |
| 203 | open->hdr.dest_port = atomic_read(&this_adm.copp_id[index]); |
| 204 | open->hdr.token = port_id; |
| 205 | open->hdr.opcode = ADM_CMD_SET_PARAMS; |
| 206 | pr_debug("SRS - %s: Command was sent now check Q6 - port id = %d," |
| 207 | " size %d, module id %x, param id %x.\n", __func__, |
| 208 | open->hdr.dest_port, open->payload_size, |
| 209 | open->params.module_id, open->params.param_id); |
| 210 | |
| 211 | ret = apr_send_pkt(this_adm.apr, (uint32_t *)open); |
| 212 | if (ret < 0) { |
| 213 | pr_err("SRS - %s: ADM enable for port %d failed\n", __func__, |
| 214 | port_id); |
| 215 | ret = -EINVAL; |
| 216 | goto fail_cmd; |
| 217 | } |
| 218 | /* Wait for the callback with copp id */ |
| 219 | ret = wait_event_timeout(this_adm.wait, 1, |
| 220 | msecs_to_jiffies(TIMEOUT_MS)); |
| 221 | if (!ret) { |
| 222 | pr_err("SRS - %s: ADM open failed for port %d\n", __func__, |
| 223 | port_id); |
| 224 | ret = -EINVAL; |
| 225 | goto fail_cmd; |
| 226 | } |
| 227 | |
| 228 | fail_cmd: |
| 229 | kfree(open); |
| 230 | return ret; |
| 231 | } |
| 232 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 233 | static int32_t adm_callback(struct apr_client_data *data, void *priv) |
| 234 | { |
| 235 | uint32_t *payload; |
| 236 | int i, index; |
| 237 | payload = data->payload; |
| 238 | |
| 239 | if (data->opcode == RESET_EVENTS) { |
| 240 | pr_debug("adm_callback: Reset event is received: %d %d apr[%p]\n", |
| 241 | data->reset_event, data->reset_proc, |
| 242 | this_adm.apr); |
| 243 | if (this_adm.apr) { |
| 244 | apr_reset(this_adm.apr); |
| 245 | for (i = 0; i < AFE_MAX_PORTS; i++) { |
| 246 | atomic_set(&this_adm.copp_id[i], |
| 247 | RESET_COPP_ID); |
| 248 | atomic_set(&this_adm.copp_cnt[i], 0); |
| 249 | atomic_set(&this_adm.copp_stat[i], 0); |
| 250 | } |
| 251 | this_adm.apr = NULL; |
| 252 | } |
| 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | pr_debug("%s: code = 0x%x %x %x size = %d\n", __func__, |
| 257 | data->opcode, payload[0], payload[1], |
| 258 | data->payload_size); |
| 259 | |
| 260 | if (data->payload_size) { |
| 261 | index = afe_get_port_index(data->token); |
| 262 | pr_debug("%s: Port ID %d, index %d\n", __func__, |
| 263 | data->token, index); |
| Bharath Ramachandramurthy | 94ad7e2 | 2012-02-28 18:44:07 -0800 | [diff] [blame] | 264 | if (index < 0 || index >= AFE_MAX_PORTS) { |
| 265 | pr_err("%s: invalid port idx %d token %d\n", |
| 266 | __func__, index, data->token); |
| 267 | return 0; |
| 268 | } |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 269 | if (data->opcode == APR_BASIC_RSP_RESULT) { |
| Santosh Mardi | 2332120 | 2012-03-22 04:33:25 +0530 | [diff] [blame] | 270 | pr_debug("APR_BASIC_RSP_RESULT id %x\n", payload[0]); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 271 | switch (payload[0]) { |
| 272 | case ADM_CMD_SET_PARAMS: |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 273 | if (rtac_make_adm_callback(payload, |
| 274 | data->payload_size)) |
| 275 | break; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 276 | case ADM_CMD_COPP_CLOSE: |
| 277 | case ADM_CMD_MEMORY_MAP: |
| 278 | case ADM_CMD_MEMORY_UNMAP: |
| 279 | case ADM_CMD_MEMORY_MAP_REGIONS: |
| 280 | case ADM_CMD_MEMORY_UNMAP_REGIONS: |
| 281 | case ADM_CMD_MATRIX_MAP_ROUTINGS: |
| Santosh Mardi | 2332120 | 2012-03-22 04:33:25 +0530 | [diff] [blame] | 282 | case ADM_CMD_CONNECT_AFE_PORT: |
| Santosh Mardi | d176079 | 2012-06-12 16:23:19 +0530 | [diff] [blame] | 283 | case ADM_CMD_DISCONNECT_AFE_PORT: |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 284 | atomic_set(&this_adm.copp_stat[index], 1); |
| 285 | wake_up(&this_adm.wait); |
| 286 | break; |
| 287 | default: |
| 288 | pr_err("%s: Unknown Cmd: 0x%x\n", __func__, |
| 289 | payload[0]); |
| 290 | break; |
| 291 | } |
| 292 | return 0; |
| 293 | } |
| 294 | |
| 295 | switch (data->opcode) { |
| Kiran Kandi | 5e809b0 | 2012-01-31 00:24:33 -0800 | [diff] [blame] | 296 | case ADM_CMDRSP_COPP_OPEN: |
| 297 | case ADM_CMDRSP_MULTI_CHANNEL_COPP_OPEN: { |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 298 | struct adm_copp_open_respond *open = data->payload; |
| 299 | if (open->copp_id == INVALID_COPP_ID) { |
| 300 | pr_err("%s: invalid coppid rxed %d\n", |
| 301 | __func__, open->copp_id); |
| 302 | atomic_set(&this_adm.copp_stat[index], 1); |
| 303 | wake_up(&this_adm.wait); |
| 304 | break; |
| 305 | } |
| 306 | atomic_set(&this_adm.copp_id[index], open->copp_id); |
| 307 | atomic_set(&this_adm.copp_stat[index], 1); |
| 308 | pr_debug("%s: coppid rxed=%d\n", __func__, |
| 309 | open->copp_id); |
| 310 | wake_up(&this_adm.wait); |
| 311 | } |
| 312 | break; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 313 | case ADM_CMDRSP_GET_PARAMS: |
| Swaminathan Sathappan | 88163a7 | 2011-08-01 16:01:14 -0700 | [diff] [blame] | 314 | pr_debug("%s: ADM_CMDRSP_GET_PARAMS\n", __func__); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 315 | rtac_make_adm_callback(payload, |
| 316 | data->payload_size); |
| 317 | break; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 318 | default: |
| 319 | pr_err("%s: Unknown cmd:0x%x\n", __func__, |
| 320 | data->opcode); |
| 321 | break; |
| 322 | } |
| 323 | } |
| 324 | return 0; |
| 325 | } |
| 326 | |
| Ben Romberger | 48fabc3 | 2012-01-06 17:39:39 -0800 | [diff] [blame] | 327 | static int send_adm_cal_block(int port_id, struct acdb_cal_block *aud_cal) |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 328 | { |
| Ben Romberger | dcab547 | 2011-12-08 19:20:12 -0800 | [diff] [blame] | 329 | s32 result = 0; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 330 | struct adm_set_params_command adm_params; |
| 331 | int index = afe_get_port_index(port_id); |
| Ben Romberger | 09dc65f | 2012-03-22 20:06:55 -0700 | [diff] [blame] | 332 | if (index < 0 || index >= AFE_MAX_PORTS) { |
| 333 | pr_err("%s: invalid port idx %d portid %d\n", |
| 334 | __func__, index, port_id); |
| Mingming Yin | c09967e | 2012-04-27 15:09:43 -0700 | [diff] [blame] | 335 | return 0; |
| Ben Romberger | 09dc65f | 2012-03-22 20:06:55 -0700 | [diff] [blame] | 336 | } |
| Mingming Yin | c09967e | 2012-04-27 15:09:43 -0700 | [diff] [blame] | 337 | |
| 338 | pr_debug("%s: Port id %d, index %d\n", __func__, port_id, index); |
| 339 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 340 | if (!aud_cal || aud_cal->cal_size == 0) { |
| Ben Romberger | dcab547 | 2011-12-08 19:20:12 -0800 | [diff] [blame] | 341 | pr_debug("%s: No ADM cal to send for port_id = %d!\n", |
| 342 | __func__, port_id); |
| 343 | result = -EINVAL; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 344 | goto done; |
| 345 | } |
| 346 | |
| 347 | adm_params.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 348 | APR_HDR_LEN(20), APR_PKT_VER); |
| 349 | adm_params.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 350 | sizeof(adm_params)); |
| 351 | adm_params.hdr.src_svc = APR_SVC_ADM; |
| 352 | adm_params.hdr.src_domain = APR_DOMAIN_APPS; |
| 353 | adm_params.hdr.src_port = port_id; |
| 354 | adm_params.hdr.dest_svc = APR_SVC_ADM; |
| 355 | adm_params.hdr.dest_domain = APR_DOMAIN_ADSP; |
| 356 | adm_params.hdr.dest_port = atomic_read(&this_adm.copp_id[index]); |
| 357 | adm_params.hdr.token = port_id; |
| 358 | adm_params.hdr.opcode = ADM_CMD_SET_PARAMS; |
| 359 | adm_params.payload = aud_cal->cal_paddr; |
| 360 | adm_params.payload_size = aud_cal->cal_size; |
| 361 | |
| 362 | atomic_set(&this_adm.copp_stat[index], 0); |
| 363 | pr_debug("%s: Sending SET_PARAMS payload = 0x%x, size = %d\n", |
| 364 | __func__, adm_params.payload, adm_params.payload_size); |
| 365 | result = apr_send_pkt(this_adm.apr, (uint32_t *)&adm_params); |
| 366 | if (result < 0) { |
| 367 | pr_err("%s: Set params failed port = %d payload = 0x%x\n", |
| 368 | __func__, port_id, aud_cal->cal_paddr); |
| Ben Romberger | dcab547 | 2011-12-08 19:20:12 -0800 | [diff] [blame] | 369 | result = -EINVAL; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 370 | goto done; |
| 371 | } |
| 372 | /* Wait for the callback */ |
| 373 | result = wait_event_timeout(this_adm.wait, |
| 374 | atomic_read(&this_adm.copp_stat[index]), |
| 375 | msecs_to_jiffies(TIMEOUT_MS)); |
| Ben Romberger | dcab547 | 2011-12-08 19:20:12 -0800 | [diff] [blame] | 376 | if (!result) { |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 377 | pr_err("%s: Set params timed out port = %d, payload = 0x%x\n", |
| 378 | __func__, port_id, aud_cal->cal_paddr); |
| Ben Romberger | dcab547 | 2011-12-08 19:20:12 -0800 | [diff] [blame] | 379 | result = -EINVAL; |
| 380 | goto done; |
| 381 | } |
| 382 | |
| 383 | result = 0; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 384 | done: |
| Ben Romberger | dcab547 | 2011-12-08 19:20:12 -0800 | [diff] [blame] | 385 | return result; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 386 | } |
| 387 | |
| Ben Romberger | 48fabc3 | 2012-01-06 17:39:39 -0800 | [diff] [blame] | 388 | static void send_adm_cal(int port_id, int path) |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 389 | { |
| Ben Romberger | 48fabc3 | 2012-01-06 17:39:39 -0800 | [diff] [blame] | 390 | int result = 0; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 391 | s32 acdb_path; |
| 392 | struct acdb_cal_block aud_cal; |
| 393 | |
| 394 | pr_debug("%s\n", __func__); |
| 395 | |
| 396 | /* Maps audio_dev_ctrl path definition to ACDB definition */ |
| 397 | acdb_path = path - 1; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 398 | |
| 399 | pr_debug("%s: Sending audproc cal\n", __func__); |
| 400 | get_audproc_cal(acdb_path, &aud_cal); |
| Ben Romberger | 48fabc3 | 2012-01-06 17:39:39 -0800 | [diff] [blame] | 401 | |
| 402 | /* map & cache buffers used */ |
| Ben Romberger | 9e79256 | 2012-02-24 12:29:01 -0800 | [diff] [blame] | 403 | if (((mem_addr_audproc[acdb_path].cal_paddr != aud_cal.cal_paddr) && |
| 404 | (aud_cal.cal_size > 0)) || |
| 405 | (aud_cal.cal_size > mem_addr_audproc[acdb_path].cal_size)) { |
| 406 | |
| Ben Romberger | 48fabc3 | 2012-01-06 17:39:39 -0800 | [diff] [blame] | 407 | if (mem_addr_audproc[acdb_path].cal_paddr != 0) |
| 408 | adm_memory_unmap_regions( |
| 409 | &mem_addr_audproc[acdb_path].cal_paddr, |
| 410 | &mem_addr_audproc[acdb_path].cal_size, 1); |
| 411 | |
| 412 | result = adm_memory_map_regions(&aud_cal.cal_paddr, 0, |
| 413 | &aud_cal.cal_size, 1); |
| 414 | if (result < 0) |
| 415 | pr_err("ADM audproc mmap did not work! path = %d, " |
| 416 | "addr = 0x%x, size = %d\n", acdb_path, |
| 417 | aud_cal.cal_paddr, aud_cal.cal_size); |
| 418 | else |
| 419 | mem_addr_audproc[acdb_path] = aud_cal; |
| 420 | } |
| 421 | |
| Ben Romberger | dcab547 | 2011-12-08 19:20:12 -0800 | [diff] [blame] | 422 | if (!send_adm_cal_block(port_id, &aud_cal)) |
| Ben Romberger | 48fabc3 | 2012-01-06 17:39:39 -0800 | [diff] [blame] | 423 | pr_debug("%s: Audproc cal sent for port id: %d, path %d\n", |
| Ben Romberger | dcab547 | 2011-12-08 19:20:12 -0800 | [diff] [blame] | 424 | __func__, port_id, acdb_path); |
| 425 | else |
| Ben Romberger | 48fabc3 | 2012-01-06 17:39:39 -0800 | [diff] [blame] | 426 | pr_debug("%s: Audproc cal not sent for port id: %d, path %d\n", |
| Ben Romberger | dcab547 | 2011-12-08 19:20:12 -0800 | [diff] [blame] | 427 | __func__, port_id, acdb_path); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 428 | |
| 429 | pr_debug("%s: Sending audvol cal\n", __func__); |
| 430 | get_audvol_cal(acdb_path, &aud_cal); |
| Ben Romberger | 48fabc3 | 2012-01-06 17:39:39 -0800 | [diff] [blame] | 431 | |
| 432 | /* map & cache buffers used */ |
| Ben Romberger | 9e79256 | 2012-02-24 12:29:01 -0800 | [diff] [blame] | 433 | if (((mem_addr_audvol[acdb_path].cal_paddr != aud_cal.cal_paddr) && |
| 434 | (aud_cal.cal_size > 0)) || |
| 435 | (aud_cal.cal_size > mem_addr_audvol[acdb_path].cal_size)) { |
| Ben Romberger | 48fabc3 | 2012-01-06 17:39:39 -0800 | [diff] [blame] | 436 | if (mem_addr_audvol[acdb_path].cal_paddr != 0) |
| 437 | adm_memory_unmap_regions( |
| 438 | &mem_addr_audvol[acdb_path].cal_paddr, |
| 439 | &mem_addr_audvol[acdb_path].cal_size, 1); |
| 440 | |
| 441 | result = adm_memory_map_regions(&aud_cal.cal_paddr, 0, |
| 442 | &aud_cal.cal_size, 1); |
| 443 | if (result < 0) |
| 444 | pr_err("ADM audvol mmap did not work! path = %d, " |
| 445 | "addr = 0x%x, size = %d\n", acdb_path, |
| 446 | aud_cal.cal_paddr, aud_cal.cal_size); |
| 447 | else |
| 448 | mem_addr_audvol[acdb_path] = aud_cal; |
| 449 | } |
| 450 | |
| Ben Romberger | dcab547 | 2011-12-08 19:20:12 -0800 | [diff] [blame] | 451 | if (!send_adm_cal_block(port_id, &aud_cal)) |
| Ben Romberger | 48fabc3 | 2012-01-06 17:39:39 -0800 | [diff] [blame] | 452 | pr_debug("%s: Audvol cal sent for port id: %d, path %d\n", |
| Ben Romberger | dcab547 | 2011-12-08 19:20:12 -0800 | [diff] [blame] | 453 | __func__, port_id, acdb_path); |
| 454 | else |
| Ben Romberger | 48fabc3 | 2012-01-06 17:39:39 -0800 | [diff] [blame] | 455 | pr_debug("%s: Audvol cal not sent for port id: %d, path %d\n", |
| Ben Romberger | dcab547 | 2011-12-08 19:20:12 -0800 | [diff] [blame] | 456 | __func__, port_id, acdb_path); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 457 | } |
| 458 | |
| Santosh Mardi | 2332120 | 2012-03-22 04:33:25 +0530 | [diff] [blame] | 459 | int adm_connect_afe_port(int mode, int session_id, int port_id) |
| 460 | { |
| 461 | struct adm_cmd_connect_afe_port cmd; |
| 462 | int ret = 0; |
| 463 | int index; |
| 464 | |
| 465 | pr_debug("%s: port %d session id:%d mode:%d\n", __func__, |
| 466 | port_id, session_id, mode); |
| 467 | |
| 468 | port_id = afe_convert_virtual_to_portid(port_id); |
| 469 | |
| 470 | if (afe_validate_port(port_id) < 0) { |
| 471 | pr_err("%s port idi[%d] is invalid\n", __func__, port_id); |
| 472 | return -ENODEV; |
| 473 | } |
| 474 | if (this_adm.apr == NULL) { |
| 475 | this_adm.apr = apr_register("ADSP", "ADM", adm_callback, |
| 476 | 0xFFFFFFFF, &this_adm); |
| 477 | if (this_adm.apr == NULL) { |
| 478 | pr_err("%s: Unable to register ADM\n", __func__); |
| 479 | ret = -ENODEV; |
| 480 | return ret; |
| 481 | } |
| 482 | rtac_set_adm_handle(this_adm.apr); |
| 483 | } |
| 484 | index = afe_get_port_index(port_id); |
| 485 | pr_debug("%s: Port ID %d, index %d\n", __func__, port_id, index); |
| 486 | |
| 487 | cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 488 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 489 | cmd.hdr.pkt_size = sizeof(cmd); |
| 490 | cmd.hdr.src_svc = APR_SVC_ADM; |
| 491 | cmd.hdr.src_domain = APR_DOMAIN_APPS; |
| 492 | cmd.hdr.src_port = port_id; |
| 493 | cmd.hdr.dest_svc = APR_SVC_ADM; |
| 494 | cmd.hdr.dest_domain = APR_DOMAIN_ADSP; |
| 495 | cmd.hdr.dest_port = port_id; |
| 496 | cmd.hdr.token = port_id; |
| 497 | cmd.hdr.opcode = ADM_CMD_CONNECT_AFE_PORT; |
| 498 | |
| 499 | cmd.mode = mode; |
| 500 | cmd.session_id = session_id; |
| 501 | cmd.afe_port_id = port_id; |
| 502 | |
| 503 | atomic_set(&this_adm.copp_stat[index], 0); |
| 504 | ret = apr_send_pkt(this_adm.apr, (uint32_t *)&cmd); |
| 505 | if (ret < 0) { |
| 506 | pr_err("%s:ADM enable for port %d failed\n", |
| 507 | __func__, port_id); |
| 508 | ret = -EINVAL; |
| 509 | goto fail_cmd; |
| 510 | } |
| 511 | /* Wait for the callback with copp id */ |
| 512 | ret = wait_event_timeout(this_adm.wait, |
| 513 | atomic_read(&this_adm.copp_stat[index]), |
| 514 | msecs_to_jiffies(TIMEOUT_MS)); |
| 515 | if (!ret) { |
| 516 | pr_err("%s ADM connect AFE failed for port %d\n", __func__, |
| 517 | port_id); |
| 518 | ret = -EINVAL; |
| 519 | goto fail_cmd; |
| 520 | } |
| 521 | atomic_inc(&this_adm.copp_cnt[index]); |
| 522 | return 0; |
| 523 | |
| 524 | fail_cmd: |
| 525 | |
| 526 | return ret; |
| 527 | } |
| 528 | |
| Santosh Mardi | d176079 | 2012-06-12 16:23:19 +0530 | [diff] [blame] | 529 | int adm_disconnect_afe_port(int mode, int session_id, int port_id) |
| 530 | { |
| 531 | struct adm_cmd_connect_afe_port cmd; |
| 532 | int ret = 0; |
| 533 | int index; |
| 534 | |
| 535 | pr_debug("%s: port %d session id:%d mode:%d\n", __func__, |
| 536 | port_id, session_id, mode); |
| 537 | |
| 538 | port_id = afe_convert_virtual_to_portid(port_id); |
| 539 | |
| 540 | if (afe_validate_port(port_id) < 0) { |
| 541 | pr_err("%s port idi[%d] is invalid\n", __func__, port_id); |
| 542 | return -ENODEV; |
| 543 | } |
| 544 | if (this_adm.apr == NULL) { |
| 545 | this_adm.apr = apr_register("ADSP", "ADM", adm_callback, |
| 546 | 0xFFFFFFFF, &this_adm); |
| 547 | if (this_adm.apr == NULL) { |
| 548 | pr_err("%s: Unable to register ADM\n", __func__); |
| 549 | ret = -ENODEV; |
| 550 | return ret; |
| 551 | } |
| 552 | rtac_set_adm_handle(this_adm.apr); |
| 553 | } |
| 554 | index = afe_get_port_index(port_id); |
| 555 | pr_debug("%s: Port ID %d, index %d\n", __func__, port_id, index); |
| 556 | |
| 557 | cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 558 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 559 | cmd.hdr.pkt_size = sizeof(cmd); |
| 560 | cmd.hdr.src_svc = APR_SVC_ADM; |
| 561 | cmd.hdr.src_domain = APR_DOMAIN_APPS; |
| 562 | cmd.hdr.src_port = port_id; |
| 563 | cmd.hdr.dest_svc = APR_SVC_ADM; |
| 564 | cmd.hdr.dest_domain = APR_DOMAIN_ADSP; |
| 565 | cmd.hdr.dest_port = port_id; |
| 566 | cmd.hdr.token = port_id; |
| 567 | cmd.hdr.opcode = ADM_CMD_DISCONNECT_AFE_PORT; |
| 568 | |
| 569 | cmd.mode = mode; |
| 570 | cmd.session_id = session_id; |
| 571 | cmd.afe_port_id = port_id; |
| 572 | |
| 573 | atomic_set(&this_adm.copp_stat[index], 0); |
| 574 | ret = apr_send_pkt(this_adm.apr, (uint32_t *)&cmd); |
| 575 | if (ret < 0) { |
| 576 | pr_err("%s:ADM enable for port %d failed\n", |
| 577 | __func__, port_id); |
| 578 | ret = -EINVAL; |
| 579 | goto fail_cmd; |
| 580 | } |
| 581 | /* Wait for the callback with copp id */ |
| 582 | ret = wait_event_timeout(this_adm.wait, |
| 583 | atomic_read(&this_adm.copp_stat[index]), |
| 584 | msecs_to_jiffies(TIMEOUT_MS)); |
| 585 | if (!ret) { |
| 586 | pr_err("%s ADM connect AFE failed for port %d\n", __func__, |
| 587 | port_id); |
| 588 | ret = -EINVAL; |
| 589 | goto fail_cmd; |
| 590 | } |
| 591 | atomic_dec(&this_adm.copp_cnt[index]); |
| 592 | return 0; |
| 593 | |
| 594 | fail_cmd: |
| 595 | |
| 596 | return ret; |
| 597 | } |
| 598 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 599 | int adm_open(int port_id, int path, int rate, int channel_mode, int topology) |
| 600 | { |
| 601 | struct adm_copp_open_command open; |
| 602 | int ret = 0; |
| 603 | int index; |
| 604 | |
| 605 | pr_debug("%s: port %d path:%d rate:%d mode:%d\n", __func__, |
| 606 | port_id, path, rate, channel_mode); |
| 607 | |
| Laxminath Kasam | 32657ec | 2011-08-01 19:26:57 +0530 | [diff] [blame] | 608 | port_id = afe_convert_virtual_to_portid(port_id); |
| 609 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 610 | if (afe_validate_port(port_id) < 0) { |
| 611 | pr_err("%s port idi[%d] is invalid\n", __func__, port_id); |
| 612 | return -ENODEV; |
| 613 | } |
| 614 | |
| 615 | index = afe_get_port_index(port_id); |
| 616 | pr_debug("%s: Port ID %d, index %d\n", __func__, port_id, index); |
| 617 | |
| 618 | if (this_adm.apr == NULL) { |
| 619 | this_adm.apr = apr_register("ADSP", "ADM", adm_callback, |
| 620 | 0xFFFFFFFF, &this_adm); |
| 621 | if (this_adm.apr == NULL) { |
| 622 | pr_err("%s: Unable to register ADM\n", __func__); |
| 623 | ret = -ENODEV; |
| 624 | return ret; |
| 625 | } |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 626 | rtac_set_adm_handle(this_adm.apr); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | |
| 630 | /* Create a COPP if port id are not enabled */ |
| 631 | if (atomic_read(&this_adm.copp_cnt[index]) == 0) { |
| 632 | |
| 633 | open.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 634 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 635 | open.hdr.pkt_size = sizeof(open); |
| 636 | open.hdr.src_svc = APR_SVC_ADM; |
| 637 | open.hdr.src_domain = APR_DOMAIN_APPS; |
| 638 | open.hdr.src_port = port_id; |
| 639 | open.hdr.dest_svc = APR_SVC_ADM; |
| 640 | open.hdr.dest_domain = APR_DOMAIN_ADSP; |
| 641 | open.hdr.dest_port = port_id; |
| 642 | open.hdr.token = port_id; |
| 643 | open.hdr.opcode = ADM_CMD_COPP_OPEN; |
| 644 | |
| 645 | open.mode = path; |
| 646 | open.endpoint_id1 = port_id; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 647 | |
| Jayasena Sangaraboina | f4ab0df | 2012-06-06 22:38:40 -0700 | [diff] [blame] | 648 | if (this_adm.ec_ref_rx == 0) { |
| 649 | open.endpoint_id2 = 0xFFFF; |
| 650 | } else if (this_adm.ec_ref_rx && (path != 1)) { |
| 651 | open.endpoint_id2 = this_adm.ec_ref_rx; |
| 652 | this_adm.ec_ref_rx = 0; |
| 653 | } |
| 654 | |
| 655 | pr_debug("%s open.endpoint_id1:%d open.endpoint_id2:%d", |
| 656 | __func__, open.endpoint_id1, open.endpoint_id2); |
| Ben Romberger | c49b85d | 2011-07-15 18:55:34 -0700 | [diff] [blame] | 657 | /* convert path to acdb path */ |
| Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame] | 658 | if (path == ADM_PATH_PLAYBACK) |
| Ben Romberger | c49b85d | 2011-07-15 18:55:34 -0700 | [diff] [blame] | 659 | open.topology_id = get_adm_rx_topology(); |
| Jay Wang | 4fa2ee4 | 2011-07-18 00:21:22 -0700 | [diff] [blame] | 660 | else { |
| Ben Romberger | c49b85d | 2011-07-15 18:55:34 -0700 | [diff] [blame] | 661 | open.topology_id = get_adm_tx_topology(); |
| Jay Wang | 4fa2ee4 | 2011-07-18 00:21:22 -0700 | [diff] [blame] | 662 | if ((open.topology_id == |
| 663 | VPM_TX_SM_ECNS_COPP_TOPOLOGY) || |
| 664 | (open.topology_id == |
| Jay Wang | 1728313 | 2012-03-30 15:18:12 -0700 | [diff] [blame] | 665 | VPM_TX_DM_FLUENCE_COPP_TOPOLOGY)) |
| Jay Wang | 4fa2ee4 | 2011-07-18 00:21:22 -0700 | [diff] [blame] | 666 | rate = 16000; |
| 667 | } |
| Ben Romberger | c49b85d | 2011-07-15 18:55:34 -0700 | [diff] [blame] | 668 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 669 | if (open.topology_id == 0) |
| 670 | open.topology_id = topology; |
| 671 | |
| 672 | open.channel_config = channel_mode & 0x00FF; |
| 673 | open.rate = rate; |
| 674 | |
| Bharath Ramachandramurthy | 94ad7e2 | 2012-02-28 18:44:07 -0800 | [diff] [blame] | 675 | pr_debug("%s: channel_config=%d port_id=%d rate=%d" |
| 676 | "topology_id=0x%X\n", __func__, open.channel_config,\ |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 677 | open.endpoint_id1, open.rate,\ |
| 678 | open.topology_id); |
| 679 | |
| 680 | atomic_set(&this_adm.copp_stat[index], 0); |
| 681 | |
| 682 | ret = apr_send_pkt(this_adm.apr, (uint32_t *)&open); |
| 683 | if (ret < 0) { |
| 684 | pr_err("%s:ADM enable for port %d failed\n", |
| 685 | __func__, port_id); |
| 686 | ret = -EINVAL; |
| 687 | goto fail_cmd; |
| 688 | } |
| 689 | /* Wait for the callback with copp id */ |
| 690 | ret = wait_event_timeout(this_adm.wait, |
| 691 | atomic_read(&this_adm.copp_stat[index]), |
| 692 | msecs_to_jiffies(TIMEOUT_MS)); |
| 693 | if (!ret) { |
| 694 | pr_err("%s ADM open failed for port %d\n", __func__, |
| 695 | port_id); |
| 696 | ret = -EINVAL; |
| 697 | goto fail_cmd; |
| 698 | } |
| 699 | } |
| 700 | atomic_inc(&this_adm.copp_cnt[index]); |
| 701 | return 0; |
| 702 | |
| 703 | fail_cmd: |
| 704 | |
| 705 | return ret; |
| 706 | } |
| 707 | |
| Kiran Kandi | 5e809b0 | 2012-01-31 00:24:33 -0800 | [diff] [blame] | 708 | |
| 709 | int adm_multi_ch_copp_open(int port_id, int path, int rate, int channel_mode, |
| 710 | int topology) |
| 711 | { |
| 712 | struct adm_multi_ch_copp_open_command open; |
| 713 | int ret = 0; |
| 714 | int index; |
| 715 | |
| 716 | pr_debug("%s: port %d path:%d rate:%d channel :%d\n", __func__, |
| 717 | port_id, path, rate, channel_mode); |
| 718 | |
| 719 | port_id = afe_convert_virtual_to_portid(port_id); |
| 720 | |
| 721 | if (afe_validate_port(port_id) < 0) { |
| 722 | pr_err("%s port idi[%d] is invalid\n", __func__, port_id); |
| 723 | return -ENODEV; |
| 724 | } |
| 725 | |
| 726 | index = afe_get_port_index(port_id); |
| 727 | pr_debug("%s: Port ID %d, index %d\n", __func__, port_id, index); |
| 728 | |
| 729 | if (this_adm.apr == NULL) { |
| 730 | this_adm.apr = apr_register("ADSP", "ADM", adm_callback, |
| 731 | 0xFFFFFFFF, &this_adm); |
| 732 | if (this_adm.apr == NULL) { |
| 733 | pr_err("%s: Unable to register ADM\n", __func__); |
| 734 | ret = -ENODEV; |
| 735 | return ret; |
| 736 | } |
| 737 | rtac_set_adm_handle(this_adm.apr); |
| 738 | } |
| 739 | |
| 740 | /* Create a COPP if port id are not enabled */ |
| 741 | if (atomic_read(&this_adm.copp_cnt[index]) == 0) { |
| 742 | |
| 743 | open.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 744 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 745 | |
| 746 | open.hdr.pkt_size = |
| 747 | sizeof(struct adm_multi_ch_copp_open_command); |
| 748 | open.hdr.opcode = ADM_CMD_MULTI_CHANNEL_COPP_OPEN; |
| 749 | memset(open.dev_channel_mapping, 0, 8); |
| 750 | |
| 751 | if (channel_mode == 1) { |
| 752 | open.dev_channel_mapping[0] = PCM_CHANNEL_FC; |
| 753 | } else if (channel_mode == 2) { |
| 754 | open.dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 755 | open.dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| Mingming Yin | 647e9ea | 2012-03-17 19:56:10 -0700 | [diff] [blame] | 756 | } else if (channel_mode == 4) { |
| 757 | open.dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 758 | open.dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 759 | open.dev_channel_mapping[2] = PCM_CHANNEL_RB; |
| 760 | open.dev_channel_mapping[3] = PCM_CHANNEL_LB; |
| Kiran Kandi | 5e809b0 | 2012-01-31 00:24:33 -0800 | [diff] [blame] | 761 | } else if (channel_mode == 6) { |
| 762 | open.dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 763 | open.dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 764 | open.dev_channel_mapping[2] = PCM_CHANNEL_LFE; |
| 765 | open.dev_channel_mapping[3] = PCM_CHANNEL_FC; |
| 766 | open.dev_channel_mapping[4] = PCM_CHANNEL_LB; |
| 767 | open.dev_channel_mapping[5] = PCM_CHANNEL_RB; |
| Subhash Chandra Bose Naripeddy | 8477d22 | 2012-06-12 00:30:54 -0700 | [diff] [blame^] | 768 | } else if (channel_mode == 8) { |
| 769 | open.dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 770 | open.dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 771 | open.dev_channel_mapping[2] = PCM_CHANNEL_LFE; |
| 772 | open.dev_channel_mapping[3] = PCM_CHANNEL_FC; |
| 773 | open.dev_channel_mapping[4] = PCM_CHANNEL_LB; |
| 774 | open.dev_channel_mapping[5] = PCM_CHANNEL_RB; |
| 775 | open.dev_channel_mapping[6] = PCM_CHANNEL_FLC; |
| 776 | open.dev_channel_mapping[7] = PCM_CHANNEL_FRC; |
| Kiran Kandi | 5e809b0 | 2012-01-31 00:24:33 -0800 | [diff] [blame] | 777 | } else { |
| 778 | pr_err("%s invalid num_chan %d\n", __func__, |
| 779 | channel_mode); |
| 780 | return -EINVAL; |
| 781 | } |
| 782 | |
| 783 | |
| 784 | open.hdr.src_svc = APR_SVC_ADM; |
| 785 | open.hdr.src_domain = APR_DOMAIN_APPS; |
| 786 | open.hdr.src_port = port_id; |
| 787 | open.hdr.dest_svc = APR_SVC_ADM; |
| 788 | open.hdr.dest_domain = APR_DOMAIN_ADSP; |
| 789 | open.hdr.dest_port = port_id; |
| 790 | open.hdr.token = port_id; |
| 791 | |
| 792 | open.mode = path; |
| 793 | open.endpoint_id1 = port_id; |
| Kiran Kandi | 5e809b0 | 2012-01-31 00:24:33 -0800 | [diff] [blame] | 794 | |
| Jayasena Sangaraboina | f4ab0df | 2012-06-06 22:38:40 -0700 | [diff] [blame] | 795 | if (this_adm.ec_ref_rx == 0) { |
| 796 | open.endpoint_id2 = 0xFFFF; |
| 797 | } else if (this_adm.ec_ref_rx && (path != 1)) { |
| 798 | open.endpoint_id2 = this_adm.ec_ref_rx; |
| 799 | this_adm.ec_ref_rx = 0; |
| 800 | } |
| 801 | |
| 802 | pr_debug("%s open.endpoint_id1:%d open.endpoint_id2:%d", |
| 803 | __func__, open.endpoint_id1, open.endpoint_id2); |
| Kiran Kandi | 5e809b0 | 2012-01-31 00:24:33 -0800 | [diff] [blame] | 804 | /* convert path to acdb path */ |
| 805 | if (path == ADM_PATH_PLAYBACK) |
| 806 | open.topology_id = get_adm_rx_topology(); |
| 807 | else { |
| 808 | open.topology_id = get_adm_tx_topology(); |
| 809 | if ((open.topology_id == |
| 810 | VPM_TX_SM_ECNS_COPP_TOPOLOGY) || |
| 811 | (open.topology_id == |
| Jay Wang | 0124d87 | 2012-05-23 14:10:36 -0700 | [diff] [blame] | 812 | VPM_TX_DM_FLUENCE_COPP_TOPOLOGY)) |
| Kiran Kandi | 5e809b0 | 2012-01-31 00:24:33 -0800 | [diff] [blame] | 813 | rate = 16000; |
| 814 | } |
| 815 | |
| 816 | if (open.topology_id == 0) |
| 817 | open.topology_id = topology; |
| 818 | |
| 819 | open.channel_config = channel_mode & 0x00FF; |
| 820 | open.rate = rate; |
| 821 | |
| 822 | pr_debug("%s: channel_config=%d port_id=%d rate=%d" |
| 823 | " topology_id=0x%X\n", __func__, open.channel_config, |
| 824 | open.endpoint_id1, open.rate, |
| 825 | open.topology_id); |
| 826 | |
| 827 | atomic_set(&this_adm.copp_stat[index], 0); |
| 828 | |
| 829 | ret = apr_send_pkt(this_adm.apr, (uint32_t *)&open); |
| 830 | if (ret < 0) { |
| 831 | pr_err("%s:ADM enable for port %d failed\n", |
| 832 | __func__, port_id); |
| 833 | ret = -EINVAL; |
| 834 | goto fail_cmd; |
| 835 | } |
| 836 | /* Wait for the callback with copp id */ |
| 837 | ret = wait_event_timeout(this_adm.wait, |
| 838 | atomic_read(&this_adm.copp_stat[index]), |
| 839 | msecs_to_jiffies(TIMEOUT_MS)); |
| 840 | if (!ret) { |
| 841 | pr_err("%s ADM open failed for port %d\n", __func__, |
| 842 | port_id); |
| 843 | ret = -EINVAL; |
| 844 | goto fail_cmd; |
| 845 | } |
| 846 | } |
| 847 | atomic_inc(&this_adm.copp_cnt[index]); |
| 848 | return 0; |
| 849 | |
| 850 | fail_cmd: |
| 851 | |
| 852 | return ret; |
| 853 | } |
| 854 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 855 | int adm_matrix_map(int session_id, int path, int num_copps, |
| 856 | unsigned int *port_id, int copp_id) |
| 857 | { |
| 858 | struct adm_routings_command route; |
| 859 | int ret = 0, i = 0; |
| 860 | /* Assumes port_ids have already been validated during adm_open */ |
| 861 | int index = afe_get_port_index(copp_id); |
| Mingming Yin | c09967e | 2012-04-27 15:09:43 -0700 | [diff] [blame] | 862 | if (index < 0 || index >= AFE_MAX_PORTS) { |
| 863 | pr_err("%s: invalid port idx %d token %d\n", |
| 864 | __func__, index, copp_id); |
| 865 | return 0; |
| 866 | } |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 867 | |
| 868 | pr_debug("%s: session 0x%x path:%d num_copps:%d port_id[0]:%d\n", |
| 869 | __func__, session_id, path, num_copps, port_id[0]); |
| 870 | |
| 871 | route.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 872 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 873 | route.hdr.pkt_size = sizeof(route); |
| 874 | route.hdr.src_svc = 0; |
| 875 | route.hdr.src_domain = APR_DOMAIN_APPS; |
| 876 | route.hdr.src_port = copp_id; |
| 877 | route.hdr.dest_svc = APR_SVC_ADM; |
| 878 | route.hdr.dest_domain = APR_DOMAIN_ADSP; |
| 879 | route.hdr.dest_port = atomic_read(&this_adm.copp_id[index]); |
| 880 | route.hdr.token = copp_id; |
| 881 | route.hdr.opcode = ADM_CMD_MATRIX_MAP_ROUTINGS; |
| 882 | route.num_sessions = 1; |
| 883 | route.session[0].id = session_id; |
| 884 | route.session[0].num_copps = num_copps; |
| 885 | |
| 886 | for (i = 0; i < num_copps; i++) { |
| 887 | int tmp; |
| Laxminath Kasam | 32657ec | 2011-08-01 19:26:57 +0530 | [diff] [blame] | 888 | port_id[i] = afe_convert_virtual_to_portid(port_id[i]); |
| 889 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 890 | tmp = afe_get_port_index(port_id[i]); |
| 891 | |
| 892 | pr_debug("%s: port_id[%d]: %d, index: %d\n", __func__, i, |
| 893 | port_id[i], tmp); |
| 894 | |
| Mingming Yin | c09967e | 2012-04-27 15:09:43 -0700 | [diff] [blame] | 895 | if (tmp >= 0 && tmp < AFE_MAX_PORTS) |
| Bharath Ramachandramurthy | 94ad7e2 | 2012-02-28 18:44:07 -0800 | [diff] [blame] | 896 | route.session[0].copp_id[i] = |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 897 | atomic_read(&this_adm.copp_id[tmp]); |
| 898 | } |
| 899 | if (num_copps % 2) |
| 900 | route.session[0].copp_id[i] = 0; |
| 901 | |
| 902 | switch (path) { |
| 903 | case 0x1: |
| 904 | route.path = AUDIO_RX; |
| 905 | break; |
| 906 | case 0x2: |
| 907 | case 0x3: |
| 908 | route.path = AUDIO_TX; |
| 909 | break; |
| 910 | default: |
| 911 | pr_err("%s: Wrong path set[%d]\n", __func__, path); |
| 912 | break; |
| 913 | } |
| 914 | atomic_set(&this_adm.copp_stat[index], 0); |
| 915 | |
| 916 | ret = apr_send_pkt(this_adm.apr, (uint32_t *)&route); |
| 917 | if (ret < 0) { |
| 918 | pr_err("%s: ADM routing for port %d failed\n", |
| 919 | __func__, port_id[0]); |
| 920 | ret = -EINVAL; |
| 921 | goto fail_cmd; |
| 922 | } |
| 923 | ret = wait_event_timeout(this_adm.wait, |
| 924 | atomic_read(&this_adm.copp_stat[index]), |
| 925 | msecs_to_jiffies(TIMEOUT_MS)); |
| 926 | if (!ret) { |
| 927 | pr_err("%s: ADM cmd Route failed for port %d\n", |
| 928 | __func__, port_id[0]); |
| 929 | ret = -EINVAL; |
| 930 | goto fail_cmd; |
| 931 | } |
| 932 | |
| 933 | for (i = 0; i < num_copps; i++) |
| 934 | send_adm_cal(port_id[i], path); |
| 935 | |
| Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame] | 936 | for (i = 0; i < num_copps; i++) |
| 937 | rtac_add_adm_device(port_id[i], atomic_read(&this_adm.copp_id |
| 938 | [afe_get_port_index(port_id[i])]), |
| 939 | path, session_id); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 940 | return 0; |
| 941 | |
| 942 | fail_cmd: |
| 943 | |
| 944 | return ret; |
| 945 | } |
| 946 | |
| 947 | int adm_memory_map_regions(uint32_t *buf_add, uint32_t mempool_id, |
| 948 | uint32_t *bufsz, uint32_t bufcnt) |
| 949 | { |
| 950 | struct adm_cmd_memory_map_regions *mmap_regions = NULL; |
| 951 | struct adm_memory_map_regions *mregions = NULL; |
| 952 | void *mmap_region_cmd = NULL; |
| 953 | void *payload = NULL; |
| 954 | int ret = 0; |
| 955 | int i = 0; |
| 956 | int cmd_size = 0; |
| 957 | |
| Ben Romberger | b760323 | 2011-11-23 17:16:27 -0800 | [diff] [blame] | 958 | pr_debug("%s\n", __func__); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 959 | if (this_adm.apr == NULL) { |
| 960 | this_adm.apr = apr_register("ADSP", "ADM", adm_callback, |
| 961 | 0xFFFFFFFF, &this_adm); |
| 962 | if (this_adm.apr == NULL) { |
| 963 | pr_err("%s: Unable to register ADM\n", __func__); |
| 964 | ret = -ENODEV; |
| 965 | return ret; |
| 966 | } |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 967 | rtac_set_adm_handle(this_adm.apr); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | cmd_size = sizeof(struct adm_cmd_memory_map_regions) |
| 971 | + sizeof(struct adm_memory_map_regions) * bufcnt; |
| 972 | |
| 973 | mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL); |
| 974 | if (!mmap_region_cmd) { |
| 975 | pr_err("%s: allocate mmap_region_cmd failed\n", __func__); |
| 976 | return -ENOMEM; |
| 977 | } |
| 978 | mmap_regions = (struct adm_cmd_memory_map_regions *)mmap_region_cmd; |
| 979 | mmap_regions->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 980 | APR_HDR_LEN(APR_HDR_SIZE), |
| 981 | APR_PKT_VER); |
| 982 | mmap_regions->hdr.pkt_size = cmd_size; |
| 983 | mmap_regions->hdr.src_port = 0; |
| 984 | mmap_regions->hdr.dest_port = 0; |
| 985 | mmap_regions->hdr.token = 0; |
| 986 | mmap_regions->hdr.opcode = ADM_CMD_MEMORY_MAP_REGIONS; |
| 987 | mmap_regions->mempool_id = mempool_id & 0x00ff; |
| 988 | mmap_regions->nregions = bufcnt & 0x00ff; |
| 989 | pr_debug("%s: map_regions->nregions = %d\n", __func__, |
| 990 | mmap_regions->nregions); |
| 991 | payload = ((u8 *) mmap_region_cmd + |
| 992 | sizeof(struct adm_cmd_memory_map_regions)); |
| 993 | mregions = (struct adm_memory_map_regions *)payload; |
| 994 | |
| 995 | for (i = 0; i < bufcnt; i++) { |
| 996 | mregions->phys = buf_add[i]; |
| 997 | mregions->buf_size = bufsz[i]; |
| 998 | ++mregions; |
| 999 | } |
| 1000 | |
| 1001 | atomic_set(&this_adm.copp_stat[0], 0); |
| 1002 | ret = apr_send_pkt(this_adm.apr, (uint32_t *) mmap_region_cmd); |
| 1003 | if (ret < 0) { |
| 1004 | pr_err("%s: mmap_regions op[0x%x]rc[%d]\n", __func__, |
| 1005 | mmap_regions->hdr.opcode, ret); |
| 1006 | ret = -EINVAL; |
| 1007 | goto fail_cmd; |
| 1008 | } |
| 1009 | |
| 1010 | ret = wait_event_timeout(this_adm.wait, |
| 1011 | atomic_read(&this_adm.copp_stat[0]), 5 * HZ); |
| 1012 | if (!ret) { |
| 1013 | pr_err("%s: timeout. waited for memory_map\n", __func__); |
| 1014 | ret = -EINVAL; |
| 1015 | goto fail_cmd; |
| 1016 | } |
| 1017 | fail_cmd: |
| 1018 | kfree(mmap_region_cmd); |
| 1019 | return ret; |
| 1020 | } |
| 1021 | |
| 1022 | int adm_memory_unmap_regions(uint32_t *buf_add, uint32_t *bufsz, |
| 1023 | uint32_t bufcnt) |
| 1024 | { |
| 1025 | struct adm_cmd_memory_unmap_regions *unmap_regions = NULL; |
| 1026 | struct adm_memory_unmap_regions *mregions = NULL; |
| 1027 | void *unmap_region_cmd = NULL; |
| 1028 | void *payload = NULL; |
| 1029 | int ret = 0; |
| 1030 | int i = 0; |
| 1031 | int cmd_size = 0; |
| 1032 | |
| Ben Romberger | b760323 | 2011-11-23 17:16:27 -0800 | [diff] [blame] | 1033 | pr_debug("%s\n", __func__); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1034 | |
| 1035 | if (this_adm.apr == NULL) { |
| 1036 | pr_err("%s APR handle NULL\n", __func__); |
| 1037 | return -EINVAL; |
| 1038 | } |
| 1039 | |
| 1040 | cmd_size = sizeof(struct adm_cmd_memory_unmap_regions) |
| 1041 | + sizeof(struct adm_memory_unmap_regions) * bufcnt; |
| 1042 | |
| 1043 | unmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL); |
| 1044 | if (!unmap_region_cmd) { |
| 1045 | pr_err("%s: allocate unmap_region_cmd failed\n", __func__); |
| 1046 | return -ENOMEM; |
| 1047 | } |
| 1048 | unmap_regions = (struct adm_cmd_memory_unmap_regions *) |
| 1049 | unmap_region_cmd; |
| 1050 | unmap_regions->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1051 | APR_HDR_LEN(APR_HDR_SIZE), |
| 1052 | APR_PKT_VER); |
| 1053 | unmap_regions->hdr.pkt_size = cmd_size; |
| 1054 | unmap_regions->hdr.src_port = 0; |
| 1055 | unmap_regions->hdr.dest_port = 0; |
| 1056 | unmap_regions->hdr.token = 0; |
| 1057 | unmap_regions->hdr.opcode = ADM_CMD_MEMORY_UNMAP_REGIONS; |
| 1058 | unmap_regions->nregions = bufcnt & 0x00ff; |
| 1059 | unmap_regions->reserved = 0; |
| 1060 | pr_debug("%s: unmap_regions->nregions = %d\n", __func__, |
| 1061 | unmap_regions->nregions); |
| 1062 | payload = ((u8 *) unmap_region_cmd + |
| 1063 | sizeof(struct adm_cmd_memory_unmap_regions)); |
| 1064 | mregions = (struct adm_memory_unmap_regions *)payload; |
| 1065 | |
| 1066 | for (i = 0; i < bufcnt; i++) { |
| 1067 | mregions->phys = buf_add[i]; |
| 1068 | ++mregions; |
| 1069 | } |
| 1070 | atomic_set(&this_adm.copp_stat[0], 0); |
| 1071 | ret = apr_send_pkt(this_adm.apr, (uint32_t *) unmap_region_cmd); |
| 1072 | if (ret < 0) { |
| 1073 | pr_err("%s: mmap_regions op[0x%x]rc[%d]\n", __func__, |
| 1074 | unmap_regions->hdr.opcode, ret); |
| 1075 | ret = -EINVAL; |
| 1076 | goto fail_cmd; |
| 1077 | } |
| 1078 | |
| 1079 | ret = wait_event_timeout(this_adm.wait, |
| 1080 | atomic_read(&this_adm.copp_stat[0]), 5 * HZ); |
| 1081 | if (!ret) { |
| 1082 | pr_err("%s: timeout. waited for memory_unmap\n", __func__); |
| 1083 | ret = -EINVAL; |
| 1084 | goto fail_cmd; |
| 1085 | } |
| 1086 | fail_cmd: |
| 1087 | kfree(unmap_region_cmd); |
| 1088 | return ret; |
| 1089 | } |
| 1090 | |
| Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame] | 1091 | int adm_get_copp_id(int port_index) |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1092 | { |
| 1093 | pr_debug("%s\n", __func__); |
| 1094 | |
| Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame] | 1095 | if (port_index < 0) { |
| 1096 | pr_err("%s: invalid port_id = %d\n", __func__, port_index); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1097 | return -EINVAL; |
| 1098 | } |
| 1099 | |
| Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame] | 1100 | return atomic_read(&this_adm.copp_id[port_index]); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1101 | } |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1102 | |
| Jayasena Sangaraboina | f4ab0df | 2012-06-06 22:38:40 -0700 | [diff] [blame] | 1103 | void adm_ec_ref_rx_id(int port_id) |
| 1104 | { |
| 1105 | this_adm.ec_ref_rx = port_id; |
| 1106 | pr_debug("%s ec_ref_rx:%d", __func__, this_adm.ec_ref_rx); |
| 1107 | } |
| 1108 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1109 | int adm_close(int port_id) |
| 1110 | { |
| 1111 | struct apr_hdr close; |
| 1112 | |
| 1113 | int ret = 0; |
| Laxminath Kasam | 32657ec | 2011-08-01 19:26:57 +0530 | [diff] [blame] | 1114 | int index = 0; |
| 1115 | |
| 1116 | port_id = afe_convert_virtual_to_portid(port_id); |
| 1117 | |
| 1118 | index = afe_get_port_index(port_id); |
| Bharath Ramachandramurthy | 51a8621 | 2011-07-29 12:43:43 -0700 | [diff] [blame] | 1119 | if (afe_validate_port(port_id) < 0) |
| 1120 | return -EINVAL; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1121 | |
| Jeff Ohlstein | 293b91f | 2011-12-16 13:22:46 -0800 | [diff] [blame] | 1122 | pr_debug("%s port_id=%d index %d\n", __func__, port_id, index); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1123 | |
| 1124 | if (!(atomic_read(&this_adm.copp_cnt[index]))) { |
| 1125 | pr_err("%s: copp count for port[%d]is 0\n", __func__, port_id); |
| 1126 | |
| 1127 | goto fail_cmd; |
| 1128 | } |
| 1129 | atomic_dec(&this_adm.copp_cnt[index]); |
| 1130 | if (!(atomic_read(&this_adm.copp_cnt[index]))) { |
| 1131 | |
| 1132 | close.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1133 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 1134 | close.pkt_size = sizeof(close); |
| 1135 | close.src_svc = APR_SVC_ADM; |
| 1136 | close.src_domain = APR_DOMAIN_APPS; |
| 1137 | close.src_port = port_id; |
| 1138 | close.dest_svc = APR_SVC_ADM; |
| 1139 | close.dest_domain = APR_DOMAIN_ADSP; |
| 1140 | close.dest_port = atomic_read(&this_adm.copp_id[index]); |
| 1141 | close.token = port_id; |
| 1142 | close.opcode = ADM_CMD_COPP_CLOSE; |
| 1143 | |
| 1144 | atomic_set(&this_adm.copp_id[index], RESET_COPP_ID); |
| 1145 | atomic_set(&this_adm.copp_stat[index], 0); |
| 1146 | |
| 1147 | |
| 1148 | pr_debug("%s:coppid %d portid=%d index=%d coppcnt=%d\n", |
| 1149 | __func__, |
| 1150 | atomic_read(&this_adm.copp_id[index]), |
| 1151 | port_id, index, |
| 1152 | atomic_read(&this_adm.copp_cnt[index])); |
| 1153 | |
| 1154 | ret = apr_send_pkt(this_adm.apr, (uint32_t *)&close); |
| 1155 | if (ret < 0) { |
| 1156 | pr_err("%s ADM close failed\n", __func__); |
| 1157 | ret = -EINVAL; |
| 1158 | goto fail_cmd; |
| 1159 | } |
| 1160 | |
| 1161 | ret = wait_event_timeout(this_adm.wait, |
| 1162 | atomic_read(&this_adm.copp_stat[index]), |
| 1163 | msecs_to_jiffies(TIMEOUT_MS)); |
| 1164 | if (!ret) { |
| 1165 | pr_err("%s: ADM cmd Route failed for port %d\n", |
| 1166 | __func__, port_id); |
| 1167 | ret = -EINVAL; |
| 1168 | goto fail_cmd; |
| 1169 | } |
| Ben Romberger | 93d4d2d | 2011-10-19 23:04:02 -0700 | [diff] [blame] | 1170 | |
| 1171 | rtac_remove_adm_device(port_id); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | fail_cmd: |
| 1175 | return ret; |
| 1176 | } |
| 1177 | |
| 1178 | static int __init adm_init(void) |
| 1179 | { |
| 1180 | int i = 0; |
| 1181 | init_waitqueue_head(&this_adm.wait); |
| 1182 | this_adm.apr = NULL; |
| 1183 | |
| 1184 | for (i = 0; i < AFE_MAX_PORTS; i++) { |
| 1185 | atomic_set(&this_adm.copp_id[i], RESET_COPP_ID); |
| 1186 | atomic_set(&this_adm.copp_cnt[i], 0); |
| 1187 | atomic_set(&this_adm.copp_stat[i], 0); |
| 1188 | } |
| 1189 | return 0; |
| 1190 | } |
| 1191 | |
| 1192 | device_initcall(adm_init); |