| 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; |
| 41 | }; |
| 42 | |
| Ben Romberger | 48fabc3 | 2012-01-06 17:39:39 -0800 | [diff] [blame] | 43 | static struct acdb_cal_block mem_addr_audproc[MAX_AUDPROC_TYPES]; |
| 44 | static struct acdb_cal_block mem_addr_audvol[MAX_AUDPROC_TYPES]; |
| 45 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 46 | static struct adm_ctl this_adm; |
| 47 | |
| 48 | static int32_t adm_callback(struct apr_client_data *data, void *priv) |
| 49 | { |
| 50 | uint32_t *payload; |
| 51 | int i, index; |
| 52 | payload = data->payload; |
| 53 | |
| 54 | if (data->opcode == RESET_EVENTS) { |
| 55 | pr_debug("adm_callback: Reset event is received: %d %d apr[%p]\n", |
| 56 | data->reset_event, data->reset_proc, |
| 57 | this_adm.apr); |
| 58 | if (this_adm.apr) { |
| 59 | apr_reset(this_adm.apr); |
| 60 | for (i = 0; i < AFE_MAX_PORTS; i++) { |
| 61 | atomic_set(&this_adm.copp_id[i], |
| 62 | RESET_COPP_ID); |
| 63 | atomic_set(&this_adm.copp_cnt[i], 0); |
| 64 | atomic_set(&this_adm.copp_stat[i], 0); |
| 65 | } |
| 66 | this_adm.apr = NULL; |
| 67 | } |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | pr_debug("%s: code = 0x%x %x %x size = %d\n", __func__, |
| 72 | data->opcode, payload[0], payload[1], |
| 73 | data->payload_size); |
| 74 | |
| 75 | if (data->payload_size) { |
| 76 | index = afe_get_port_index(data->token); |
| 77 | pr_debug("%s: Port ID %d, index %d\n", __func__, |
| 78 | data->token, index); |
| 79 | |
| 80 | if (data->opcode == APR_BASIC_RSP_RESULT) { |
| 81 | pr_debug("APR_BASIC_RSP_RESULT\n"); |
| 82 | switch (payload[0]) { |
| 83 | case ADM_CMD_SET_PARAMS: |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 84 | if (rtac_make_adm_callback(payload, |
| 85 | data->payload_size)) |
| 86 | break; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 87 | case ADM_CMD_COPP_CLOSE: |
| 88 | case ADM_CMD_MEMORY_MAP: |
| 89 | case ADM_CMD_MEMORY_UNMAP: |
| 90 | case ADM_CMD_MEMORY_MAP_REGIONS: |
| 91 | case ADM_CMD_MEMORY_UNMAP_REGIONS: |
| 92 | case ADM_CMD_MATRIX_MAP_ROUTINGS: |
| 93 | pr_debug("ADM_CMD_MATRIX_MAP_ROUTINGS\n"); |
| 94 | atomic_set(&this_adm.copp_stat[index], 1); |
| 95 | wake_up(&this_adm.wait); |
| 96 | break; |
| 97 | default: |
| 98 | pr_err("%s: Unknown Cmd: 0x%x\n", __func__, |
| 99 | payload[0]); |
| 100 | break; |
| 101 | } |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | switch (data->opcode) { |
| Kiran Kandi | 5e809b0 | 2012-01-31 00:24:33 -0800 | [diff] [blame] | 106 | case ADM_CMDRSP_COPP_OPEN: |
| 107 | case ADM_CMDRSP_MULTI_CHANNEL_COPP_OPEN: { |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 108 | struct adm_copp_open_respond *open = data->payload; |
| 109 | if (open->copp_id == INVALID_COPP_ID) { |
| 110 | pr_err("%s: invalid coppid rxed %d\n", |
| 111 | __func__, open->copp_id); |
| 112 | atomic_set(&this_adm.copp_stat[index], 1); |
| 113 | wake_up(&this_adm.wait); |
| 114 | break; |
| 115 | } |
| 116 | atomic_set(&this_adm.copp_id[index], open->copp_id); |
| 117 | atomic_set(&this_adm.copp_stat[index], 1); |
| 118 | pr_debug("%s: coppid rxed=%d\n", __func__, |
| 119 | open->copp_id); |
| 120 | wake_up(&this_adm.wait); |
| 121 | } |
| 122 | break; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 123 | case ADM_CMDRSP_GET_PARAMS: |
| Swaminathan Sathappan | 88163a7 | 2011-08-01 16:01:14 -0700 | [diff] [blame] | 124 | pr_debug("%s: ADM_CMDRSP_GET_PARAMS\n", __func__); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 125 | rtac_make_adm_callback(payload, |
| 126 | data->payload_size); |
| 127 | break; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 128 | default: |
| 129 | pr_err("%s: Unknown cmd:0x%x\n", __func__, |
| 130 | data->opcode); |
| 131 | break; |
| 132 | } |
| 133 | } |
| 134 | return 0; |
| 135 | } |
| 136 | |
| Ben Romberger | 48fabc3 | 2012-01-06 17:39:39 -0800 | [diff] [blame] | 137 | 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] | 138 | { |
| Ben Romberger | dcab547 | 2011-12-08 19:20:12 -0800 | [diff] [blame] | 139 | s32 result = 0; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 140 | struct adm_set_params_command adm_params; |
| 141 | int index = afe_get_port_index(port_id); |
| 142 | |
| 143 | pr_debug("%s: Port id %d, index %d\n", __func__, port_id, index); |
| 144 | |
| 145 | if (!aud_cal || aud_cal->cal_size == 0) { |
| Ben Romberger | dcab547 | 2011-12-08 19:20:12 -0800 | [diff] [blame] | 146 | pr_debug("%s: No ADM cal to send for port_id = %d!\n", |
| 147 | __func__, port_id); |
| 148 | result = -EINVAL; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 149 | goto done; |
| 150 | } |
| 151 | |
| 152 | adm_params.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 153 | APR_HDR_LEN(20), APR_PKT_VER); |
| 154 | adm_params.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 155 | sizeof(adm_params)); |
| 156 | adm_params.hdr.src_svc = APR_SVC_ADM; |
| 157 | adm_params.hdr.src_domain = APR_DOMAIN_APPS; |
| 158 | adm_params.hdr.src_port = port_id; |
| 159 | adm_params.hdr.dest_svc = APR_SVC_ADM; |
| 160 | adm_params.hdr.dest_domain = APR_DOMAIN_ADSP; |
| 161 | adm_params.hdr.dest_port = atomic_read(&this_adm.copp_id[index]); |
| 162 | adm_params.hdr.token = port_id; |
| 163 | adm_params.hdr.opcode = ADM_CMD_SET_PARAMS; |
| 164 | adm_params.payload = aud_cal->cal_paddr; |
| 165 | adm_params.payload_size = aud_cal->cal_size; |
| 166 | |
| 167 | atomic_set(&this_adm.copp_stat[index], 0); |
| 168 | pr_debug("%s: Sending SET_PARAMS payload = 0x%x, size = %d\n", |
| 169 | __func__, adm_params.payload, adm_params.payload_size); |
| 170 | result = apr_send_pkt(this_adm.apr, (uint32_t *)&adm_params); |
| 171 | if (result < 0) { |
| 172 | pr_err("%s: Set params failed port = %d payload = 0x%x\n", |
| 173 | __func__, port_id, aud_cal->cal_paddr); |
| Ben Romberger | dcab547 | 2011-12-08 19:20:12 -0800 | [diff] [blame] | 174 | result = -EINVAL; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 175 | goto done; |
| 176 | } |
| 177 | /* Wait for the callback */ |
| 178 | result = wait_event_timeout(this_adm.wait, |
| 179 | atomic_read(&this_adm.copp_stat[index]), |
| 180 | msecs_to_jiffies(TIMEOUT_MS)); |
| Ben Romberger | dcab547 | 2011-12-08 19:20:12 -0800 | [diff] [blame] | 181 | if (!result) { |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 182 | pr_err("%s: Set params timed out port = %d, payload = 0x%x\n", |
| 183 | __func__, port_id, aud_cal->cal_paddr); |
| Ben Romberger | dcab547 | 2011-12-08 19:20:12 -0800 | [diff] [blame] | 184 | result = -EINVAL; |
| 185 | goto done; |
| 186 | } |
| 187 | |
| 188 | result = 0; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 189 | done: |
| Ben Romberger | dcab547 | 2011-12-08 19:20:12 -0800 | [diff] [blame] | 190 | return result; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| Ben Romberger | 48fabc3 | 2012-01-06 17:39:39 -0800 | [diff] [blame] | 193 | static void send_adm_cal(int port_id, int path) |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 194 | { |
| Ben Romberger | 48fabc3 | 2012-01-06 17:39:39 -0800 | [diff] [blame] | 195 | int result = 0; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 196 | s32 acdb_path; |
| 197 | struct acdb_cal_block aud_cal; |
| 198 | |
| 199 | pr_debug("%s\n", __func__); |
| 200 | |
| 201 | /* Maps audio_dev_ctrl path definition to ACDB definition */ |
| 202 | acdb_path = path - 1; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 203 | |
| 204 | pr_debug("%s: Sending audproc cal\n", __func__); |
| 205 | get_audproc_cal(acdb_path, &aud_cal); |
| Ben Romberger | 48fabc3 | 2012-01-06 17:39:39 -0800 | [diff] [blame] | 206 | |
| 207 | /* map & cache buffers used */ |
| Ben Romberger | 9e79256 | 2012-02-24 12:29:01 -0800 | [diff] [blame^] | 208 | if (((mem_addr_audproc[acdb_path].cal_paddr != aud_cal.cal_paddr) && |
| 209 | (aud_cal.cal_size > 0)) || |
| 210 | (aud_cal.cal_size > mem_addr_audproc[acdb_path].cal_size)) { |
| 211 | |
| Ben Romberger | 48fabc3 | 2012-01-06 17:39:39 -0800 | [diff] [blame] | 212 | if (mem_addr_audproc[acdb_path].cal_paddr != 0) |
| 213 | adm_memory_unmap_regions( |
| 214 | &mem_addr_audproc[acdb_path].cal_paddr, |
| 215 | &mem_addr_audproc[acdb_path].cal_size, 1); |
| 216 | |
| 217 | result = adm_memory_map_regions(&aud_cal.cal_paddr, 0, |
| 218 | &aud_cal.cal_size, 1); |
| 219 | if (result < 0) |
| 220 | pr_err("ADM audproc mmap did not work! path = %d, " |
| 221 | "addr = 0x%x, size = %d\n", acdb_path, |
| 222 | aud_cal.cal_paddr, aud_cal.cal_size); |
| 223 | else |
| 224 | mem_addr_audproc[acdb_path] = aud_cal; |
| 225 | } |
| 226 | |
| Ben Romberger | dcab547 | 2011-12-08 19:20:12 -0800 | [diff] [blame] | 227 | if (!send_adm_cal_block(port_id, &aud_cal)) |
| Ben Romberger | 48fabc3 | 2012-01-06 17:39:39 -0800 | [diff] [blame] | 228 | 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] | 229 | __func__, port_id, acdb_path); |
| 230 | else |
| Ben Romberger | 48fabc3 | 2012-01-06 17:39:39 -0800 | [diff] [blame] | 231 | 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] | 232 | __func__, port_id, acdb_path); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 233 | |
| 234 | pr_debug("%s: Sending audvol cal\n", __func__); |
| 235 | get_audvol_cal(acdb_path, &aud_cal); |
| Ben Romberger | 48fabc3 | 2012-01-06 17:39:39 -0800 | [diff] [blame] | 236 | |
| 237 | /* map & cache buffers used */ |
| Ben Romberger | 9e79256 | 2012-02-24 12:29:01 -0800 | [diff] [blame^] | 238 | if (((mem_addr_audvol[acdb_path].cal_paddr != aud_cal.cal_paddr) && |
| 239 | (aud_cal.cal_size > 0)) || |
| 240 | (aud_cal.cal_size > mem_addr_audvol[acdb_path].cal_size)) { |
| Ben Romberger | 48fabc3 | 2012-01-06 17:39:39 -0800 | [diff] [blame] | 241 | if (mem_addr_audvol[acdb_path].cal_paddr != 0) |
| 242 | adm_memory_unmap_regions( |
| 243 | &mem_addr_audvol[acdb_path].cal_paddr, |
| 244 | &mem_addr_audvol[acdb_path].cal_size, 1); |
| 245 | |
| 246 | result = adm_memory_map_regions(&aud_cal.cal_paddr, 0, |
| 247 | &aud_cal.cal_size, 1); |
| 248 | if (result < 0) |
| 249 | pr_err("ADM audvol mmap did not work! path = %d, " |
| 250 | "addr = 0x%x, size = %d\n", acdb_path, |
| 251 | aud_cal.cal_paddr, aud_cal.cal_size); |
| 252 | else |
| 253 | mem_addr_audvol[acdb_path] = aud_cal; |
| 254 | } |
| 255 | |
| Ben Romberger | dcab547 | 2011-12-08 19:20:12 -0800 | [diff] [blame] | 256 | if (!send_adm_cal_block(port_id, &aud_cal)) |
| Ben Romberger | 48fabc3 | 2012-01-06 17:39:39 -0800 | [diff] [blame] | 257 | 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] | 258 | __func__, port_id, acdb_path); |
| 259 | else |
| Ben Romberger | 48fabc3 | 2012-01-06 17:39:39 -0800 | [diff] [blame] | 260 | 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] | 261 | __func__, port_id, acdb_path); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 264 | int adm_open(int port_id, int path, int rate, int channel_mode, int topology) |
| 265 | { |
| 266 | struct adm_copp_open_command open; |
| 267 | int ret = 0; |
| 268 | int index; |
| 269 | |
| 270 | pr_debug("%s: port %d path:%d rate:%d mode:%d\n", __func__, |
| 271 | port_id, path, rate, channel_mode); |
| 272 | |
| Laxminath Kasam | 32657ec | 2011-08-01 19:26:57 +0530 | [diff] [blame] | 273 | port_id = afe_convert_virtual_to_portid(port_id); |
| 274 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 275 | if (afe_validate_port(port_id) < 0) { |
| 276 | pr_err("%s port idi[%d] is invalid\n", __func__, port_id); |
| 277 | return -ENODEV; |
| 278 | } |
| 279 | |
| 280 | index = afe_get_port_index(port_id); |
| 281 | pr_debug("%s: Port ID %d, index %d\n", __func__, port_id, index); |
| 282 | |
| 283 | if (this_adm.apr == NULL) { |
| 284 | this_adm.apr = apr_register("ADSP", "ADM", adm_callback, |
| 285 | 0xFFFFFFFF, &this_adm); |
| 286 | if (this_adm.apr == NULL) { |
| 287 | pr_err("%s: Unable to register ADM\n", __func__); |
| 288 | ret = -ENODEV; |
| 289 | return ret; |
| 290 | } |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 291 | rtac_set_adm_handle(this_adm.apr); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | |
| 295 | /* Create a COPP if port id are not enabled */ |
| 296 | if (atomic_read(&this_adm.copp_cnt[index]) == 0) { |
| 297 | |
| 298 | open.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 299 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 300 | open.hdr.pkt_size = sizeof(open); |
| 301 | open.hdr.src_svc = APR_SVC_ADM; |
| 302 | open.hdr.src_domain = APR_DOMAIN_APPS; |
| 303 | open.hdr.src_port = port_id; |
| 304 | open.hdr.dest_svc = APR_SVC_ADM; |
| 305 | open.hdr.dest_domain = APR_DOMAIN_ADSP; |
| 306 | open.hdr.dest_port = port_id; |
| 307 | open.hdr.token = port_id; |
| 308 | open.hdr.opcode = ADM_CMD_COPP_OPEN; |
| 309 | |
| 310 | open.mode = path; |
| 311 | open.endpoint_id1 = port_id; |
| 312 | open.endpoint_id2 = 0xFFFF; |
| 313 | |
| Ben Romberger | c49b85d | 2011-07-15 18:55:34 -0700 | [diff] [blame] | 314 | /* convert path to acdb path */ |
| Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame] | 315 | if (path == ADM_PATH_PLAYBACK) |
| Ben Romberger | c49b85d | 2011-07-15 18:55:34 -0700 | [diff] [blame] | 316 | open.topology_id = get_adm_rx_topology(); |
| Jay Wang | 4fa2ee4 | 2011-07-18 00:21:22 -0700 | [diff] [blame] | 317 | else { |
| Ben Romberger | c49b85d | 2011-07-15 18:55:34 -0700 | [diff] [blame] | 318 | open.topology_id = get_adm_tx_topology(); |
| Jay Wang | 4fa2ee4 | 2011-07-18 00:21:22 -0700 | [diff] [blame] | 319 | if ((open.topology_id == |
| 320 | VPM_TX_SM_ECNS_COPP_TOPOLOGY) || |
| 321 | (open.topology_id == |
| Jayasena Sangaraboina | 0fc197d | 2011-12-09 13:20:33 -0800 | [diff] [blame] | 322 | VPM_TX_DM_FLUENCE_COPP_TOPOLOGY) || |
| 323 | (open.topology_id == |
| 324 | VPM_TX_QMIC_FLUENCE_COPP_TOPOLOGY)) |
| Jay Wang | 4fa2ee4 | 2011-07-18 00:21:22 -0700 | [diff] [blame] | 325 | rate = 16000; |
| 326 | } |
| Ben Romberger | c49b85d | 2011-07-15 18:55:34 -0700 | [diff] [blame] | 327 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 328 | if (open.topology_id == 0) |
| 329 | open.topology_id = topology; |
| 330 | |
| 331 | open.channel_config = channel_mode & 0x00FF; |
| 332 | open.rate = rate; |
| 333 | |
| 334 | pr_debug("%s: channel_config=%d port_id=%d rate=%d\ |
| 335 | topology_id=0x%X\n", __func__, open.channel_config,\ |
| 336 | open.endpoint_id1, open.rate,\ |
| 337 | open.topology_id); |
| 338 | |
| 339 | atomic_set(&this_adm.copp_stat[index], 0); |
| 340 | |
| 341 | ret = apr_send_pkt(this_adm.apr, (uint32_t *)&open); |
| 342 | if (ret < 0) { |
| 343 | pr_err("%s:ADM enable for port %d failed\n", |
| 344 | __func__, port_id); |
| 345 | ret = -EINVAL; |
| 346 | goto fail_cmd; |
| 347 | } |
| 348 | /* Wait for the callback with copp id */ |
| 349 | ret = wait_event_timeout(this_adm.wait, |
| 350 | atomic_read(&this_adm.copp_stat[index]), |
| 351 | msecs_to_jiffies(TIMEOUT_MS)); |
| 352 | if (!ret) { |
| 353 | pr_err("%s ADM open failed for port %d\n", __func__, |
| 354 | port_id); |
| 355 | ret = -EINVAL; |
| 356 | goto fail_cmd; |
| 357 | } |
| 358 | } |
| 359 | atomic_inc(&this_adm.copp_cnt[index]); |
| 360 | return 0; |
| 361 | |
| 362 | fail_cmd: |
| 363 | |
| 364 | return ret; |
| 365 | } |
| 366 | |
| Kiran Kandi | 5e809b0 | 2012-01-31 00:24:33 -0800 | [diff] [blame] | 367 | |
| 368 | int adm_multi_ch_copp_open(int port_id, int path, int rate, int channel_mode, |
| 369 | int topology) |
| 370 | { |
| 371 | struct adm_multi_ch_copp_open_command open; |
| 372 | int ret = 0; |
| 373 | int index; |
| 374 | |
| 375 | pr_debug("%s: port %d path:%d rate:%d channel :%d\n", __func__, |
| 376 | port_id, path, rate, channel_mode); |
| 377 | |
| 378 | port_id = afe_convert_virtual_to_portid(port_id); |
| 379 | |
| 380 | if (afe_validate_port(port_id) < 0) { |
| 381 | pr_err("%s port idi[%d] is invalid\n", __func__, port_id); |
| 382 | return -ENODEV; |
| 383 | } |
| 384 | |
| 385 | index = afe_get_port_index(port_id); |
| 386 | pr_debug("%s: Port ID %d, index %d\n", __func__, port_id, index); |
| 387 | |
| 388 | if (this_adm.apr == NULL) { |
| 389 | this_adm.apr = apr_register("ADSP", "ADM", adm_callback, |
| 390 | 0xFFFFFFFF, &this_adm); |
| 391 | if (this_adm.apr == NULL) { |
| 392 | pr_err("%s: Unable to register ADM\n", __func__); |
| 393 | ret = -ENODEV; |
| 394 | return ret; |
| 395 | } |
| 396 | rtac_set_adm_handle(this_adm.apr); |
| 397 | } |
| 398 | |
| 399 | /* Create a COPP if port id are not enabled */ |
| 400 | if (atomic_read(&this_adm.copp_cnt[index]) == 0) { |
| 401 | |
| 402 | open.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 403 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 404 | |
| 405 | open.hdr.pkt_size = |
| 406 | sizeof(struct adm_multi_ch_copp_open_command); |
| 407 | open.hdr.opcode = ADM_CMD_MULTI_CHANNEL_COPP_OPEN; |
| 408 | memset(open.dev_channel_mapping, 0, 8); |
| 409 | |
| 410 | if (channel_mode == 1) { |
| 411 | open.dev_channel_mapping[0] = PCM_CHANNEL_FC; |
| 412 | } else if (channel_mode == 2) { |
| 413 | open.dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 414 | open.dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 415 | } else if (channel_mode == 6) { |
| 416 | open.dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 417 | open.dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 418 | open.dev_channel_mapping[2] = PCM_CHANNEL_LFE; |
| 419 | open.dev_channel_mapping[3] = PCM_CHANNEL_FC; |
| 420 | open.dev_channel_mapping[4] = PCM_CHANNEL_LB; |
| 421 | open.dev_channel_mapping[5] = PCM_CHANNEL_RB; |
| 422 | } else { |
| 423 | pr_err("%s invalid num_chan %d\n", __func__, |
| 424 | channel_mode); |
| 425 | return -EINVAL; |
| 426 | } |
| 427 | |
| 428 | |
| 429 | open.hdr.src_svc = APR_SVC_ADM; |
| 430 | open.hdr.src_domain = APR_DOMAIN_APPS; |
| 431 | open.hdr.src_port = port_id; |
| 432 | open.hdr.dest_svc = APR_SVC_ADM; |
| 433 | open.hdr.dest_domain = APR_DOMAIN_ADSP; |
| 434 | open.hdr.dest_port = port_id; |
| 435 | open.hdr.token = port_id; |
| 436 | |
| 437 | open.mode = path; |
| 438 | open.endpoint_id1 = port_id; |
| 439 | open.endpoint_id2 = 0xFFFF; |
| 440 | |
| 441 | /* convert path to acdb path */ |
| 442 | if (path == ADM_PATH_PLAYBACK) |
| 443 | open.topology_id = get_adm_rx_topology(); |
| 444 | else { |
| 445 | open.topology_id = get_adm_tx_topology(); |
| 446 | if ((open.topology_id == |
| 447 | VPM_TX_SM_ECNS_COPP_TOPOLOGY) || |
| 448 | (open.topology_id == |
| 449 | VPM_TX_DM_FLUENCE_COPP_TOPOLOGY) || |
| 450 | (open.topology_id == |
| 451 | VPM_TX_QMIC_FLUENCE_COPP_TOPOLOGY)) |
| 452 | rate = 16000; |
| 453 | } |
| 454 | |
| 455 | if (open.topology_id == 0) |
| 456 | open.topology_id = topology; |
| 457 | |
| 458 | open.channel_config = channel_mode & 0x00FF; |
| 459 | open.rate = rate; |
| 460 | |
| 461 | pr_debug("%s: channel_config=%d port_id=%d rate=%d" |
| 462 | " topology_id=0x%X\n", __func__, open.channel_config, |
| 463 | open.endpoint_id1, open.rate, |
| 464 | open.topology_id); |
| 465 | |
| 466 | atomic_set(&this_adm.copp_stat[index], 0); |
| 467 | |
| 468 | ret = apr_send_pkt(this_adm.apr, (uint32_t *)&open); |
| 469 | if (ret < 0) { |
| 470 | pr_err("%s:ADM enable for port %d failed\n", |
| 471 | __func__, port_id); |
| 472 | ret = -EINVAL; |
| 473 | goto fail_cmd; |
| 474 | } |
| 475 | /* Wait for the callback with copp id */ |
| 476 | ret = wait_event_timeout(this_adm.wait, |
| 477 | atomic_read(&this_adm.copp_stat[index]), |
| 478 | msecs_to_jiffies(TIMEOUT_MS)); |
| 479 | if (!ret) { |
| 480 | pr_err("%s ADM open failed for port %d\n", __func__, |
| 481 | port_id); |
| 482 | ret = -EINVAL; |
| 483 | goto fail_cmd; |
| 484 | } |
| 485 | } |
| 486 | atomic_inc(&this_adm.copp_cnt[index]); |
| 487 | return 0; |
| 488 | |
| 489 | fail_cmd: |
| 490 | |
| 491 | return ret; |
| 492 | } |
| 493 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 494 | int adm_matrix_map(int session_id, int path, int num_copps, |
| 495 | unsigned int *port_id, int copp_id) |
| 496 | { |
| 497 | struct adm_routings_command route; |
| 498 | int ret = 0, i = 0; |
| 499 | /* Assumes port_ids have already been validated during adm_open */ |
| 500 | int index = afe_get_port_index(copp_id); |
| 501 | |
| 502 | pr_debug("%s: session 0x%x path:%d num_copps:%d port_id[0]:%d\n", |
| 503 | __func__, session_id, path, num_copps, port_id[0]); |
| 504 | |
| 505 | route.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 506 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 507 | route.hdr.pkt_size = sizeof(route); |
| 508 | route.hdr.src_svc = 0; |
| 509 | route.hdr.src_domain = APR_DOMAIN_APPS; |
| 510 | route.hdr.src_port = copp_id; |
| 511 | route.hdr.dest_svc = APR_SVC_ADM; |
| 512 | route.hdr.dest_domain = APR_DOMAIN_ADSP; |
| 513 | route.hdr.dest_port = atomic_read(&this_adm.copp_id[index]); |
| 514 | route.hdr.token = copp_id; |
| 515 | route.hdr.opcode = ADM_CMD_MATRIX_MAP_ROUTINGS; |
| 516 | route.num_sessions = 1; |
| 517 | route.session[0].id = session_id; |
| 518 | route.session[0].num_copps = num_copps; |
| 519 | |
| 520 | for (i = 0; i < num_copps; i++) { |
| 521 | int tmp; |
| Laxminath Kasam | 32657ec | 2011-08-01 19:26:57 +0530 | [diff] [blame] | 522 | port_id[i] = afe_convert_virtual_to_portid(port_id[i]); |
| 523 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 524 | tmp = afe_get_port_index(port_id[i]); |
| 525 | |
| 526 | pr_debug("%s: port_id[%d]: %d, index: %d\n", __func__, i, |
| 527 | port_id[i], tmp); |
| 528 | |
| 529 | route.session[0].copp_id[i] = |
| 530 | atomic_read(&this_adm.copp_id[tmp]); |
| 531 | } |
| 532 | if (num_copps % 2) |
| 533 | route.session[0].copp_id[i] = 0; |
| 534 | |
| 535 | switch (path) { |
| 536 | case 0x1: |
| 537 | route.path = AUDIO_RX; |
| 538 | break; |
| 539 | case 0x2: |
| 540 | case 0x3: |
| 541 | route.path = AUDIO_TX; |
| 542 | break; |
| 543 | default: |
| 544 | pr_err("%s: Wrong path set[%d]\n", __func__, path); |
| 545 | break; |
| 546 | } |
| 547 | atomic_set(&this_adm.copp_stat[index], 0); |
| 548 | |
| 549 | ret = apr_send_pkt(this_adm.apr, (uint32_t *)&route); |
| 550 | if (ret < 0) { |
| 551 | pr_err("%s: ADM routing for port %d failed\n", |
| 552 | __func__, port_id[0]); |
| 553 | ret = -EINVAL; |
| 554 | goto fail_cmd; |
| 555 | } |
| 556 | ret = wait_event_timeout(this_adm.wait, |
| 557 | atomic_read(&this_adm.copp_stat[index]), |
| 558 | msecs_to_jiffies(TIMEOUT_MS)); |
| 559 | if (!ret) { |
| 560 | pr_err("%s: ADM cmd Route failed for port %d\n", |
| 561 | __func__, port_id[0]); |
| 562 | ret = -EINVAL; |
| 563 | goto fail_cmd; |
| 564 | } |
| 565 | |
| 566 | for (i = 0; i < num_copps; i++) |
| 567 | send_adm_cal(port_id[i], path); |
| 568 | |
| Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame] | 569 | for (i = 0; i < num_copps; i++) |
| 570 | rtac_add_adm_device(port_id[i], atomic_read(&this_adm.copp_id |
| 571 | [afe_get_port_index(port_id[i])]), |
| 572 | path, session_id); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 573 | return 0; |
| 574 | |
| 575 | fail_cmd: |
| 576 | |
| 577 | return ret; |
| 578 | } |
| 579 | |
| 580 | int adm_memory_map_regions(uint32_t *buf_add, uint32_t mempool_id, |
| 581 | uint32_t *bufsz, uint32_t bufcnt) |
| 582 | { |
| 583 | struct adm_cmd_memory_map_regions *mmap_regions = NULL; |
| 584 | struct adm_memory_map_regions *mregions = NULL; |
| 585 | void *mmap_region_cmd = NULL; |
| 586 | void *payload = NULL; |
| 587 | int ret = 0; |
| 588 | int i = 0; |
| 589 | int cmd_size = 0; |
| 590 | |
| Ben Romberger | b760323 | 2011-11-23 17:16:27 -0800 | [diff] [blame] | 591 | pr_debug("%s\n", __func__); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 592 | if (this_adm.apr == NULL) { |
| 593 | this_adm.apr = apr_register("ADSP", "ADM", adm_callback, |
| 594 | 0xFFFFFFFF, &this_adm); |
| 595 | if (this_adm.apr == NULL) { |
| 596 | pr_err("%s: Unable to register ADM\n", __func__); |
| 597 | ret = -ENODEV; |
| 598 | return ret; |
| 599 | } |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 600 | rtac_set_adm_handle(this_adm.apr); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | cmd_size = sizeof(struct adm_cmd_memory_map_regions) |
| 604 | + sizeof(struct adm_memory_map_regions) * bufcnt; |
| 605 | |
| 606 | mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL); |
| 607 | if (!mmap_region_cmd) { |
| 608 | pr_err("%s: allocate mmap_region_cmd failed\n", __func__); |
| 609 | return -ENOMEM; |
| 610 | } |
| 611 | mmap_regions = (struct adm_cmd_memory_map_regions *)mmap_region_cmd; |
| 612 | mmap_regions->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 613 | APR_HDR_LEN(APR_HDR_SIZE), |
| 614 | APR_PKT_VER); |
| 615 | mmap_regions->hdr.pkt_size = cmd_size; |
| 616 | mmap_regions->hdr.src_port = 0; |
| 617 | mmap_regions->hdr.dest_port = 0; |
| 618 | mmap_regions->hdr.token = 0; |
| 619 | mmap_regions->hdr.opcode = ADM_CMD_MEMORY_MAP_REGIONS; |
| 620 | mmap_regions->mempool_id = mempool_id & 0x00ff; |
| 621 | mmap_regions->nregions = bufcnt & 0x00ff; |
| 622 | pr_debug("%s: map_regions->nregions = %d\n", __func__, |
| 623 | mmap_regions->nregions); |
| 624 | payload = ((u8 *) mmap_region_cmd + |
| 625 | sizeof(struct adm_cmd_memory_map_regions)); |
| 626 | mregions = (struct adm_memory_map_regions *)payload; |
| 627 | |
| 628 | for (i = 0; i < bufcnt; i++) { |
| 629 | mregions->phys = buf_add[i]; |
| 630 | mregions->buf_size = bufsz[i]; |
| 631 | ++mregions; |
| 632 | } |
| 633 | |
| 634 | atomic_set(&this_adm.copp_stat[0], 0); |
| 635 | ret = apr_send_pkt(this_adm.apr, (uint32_t *) mmap_region_cmd); |
| 636 | if (ret < 0) { |
| 637 | pr_err("%s: mmap_regions op[0x%x]rc[%d]\n", __func__, |
| 638 | mmap_regions->hdr.opcode, ret); |
| 639 | ret = -EINVAL; |
| 640 | goto fail_cmd; |
| 641 | } |
| 642 | |
| 643 | ret = wait_event_timeout(this_adm.wait, |
| 644 | atomic_read(&this_adm.copp_stat[0]), 5 * HZ); |
| 645 | if (!ret) { |
| 646 | pr_err("%s: timeout. waited for memory_map\n", __func__); |
| 647 | ret = -EINVAL; |
| 648 | goto fail_cmd; |
| 649 | } |
| 650 | fail_cmd: |
| 651 | kfree(mmap_region_cmd); |
| 652 | return ret; |
| 653 | } |
| 654 | |
| 655 | int adm_memory_unmap_regions(uint32_t *buf_add, uint32_t *bufsz, |
| 656 | uint32_t bufcnt) |
| 657 | { |
| 658 | struct adm_cmd_memory_unmap_regions *unmap_regions = NULL; |
| 659 | struct adm_memory_unmap_regions *mregions = NULL; |
| 660 | void *unmap_region_cmd = NULL; |
| 661 | void *payload = NULL; |
| 662 | int ret = 0; |
| 663 | int i = 0; |
| 664 | int cmd_size = 0; |
| 665 | |
| Ben Romberger | b760323 | 2011-11-23 17:16:27 -0800 | [diff] [blame] | 666 | pr_debug("%s\n", __func__); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 667 | |
| 668 | if (this_adm.apr == NULL) { |
| 669 | pr_err("%s APR handle NULL\n", __func__); |
| 670 | return -EINVAL; |
| 671 | } |
| 672 | |
| 673 | cmd_size = sizeof(struct adm_cmd_memory_unmap_regions) |
| 674 | + sizeof(struct adm_memory_unmap_regions) * bufcnt; |
| 675 | |
| 676 | unmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL); |
| 677 | if (!unmap_region_cmd) { |
| 678 | pr_err("%s: allocate unmap_region_cmd failed\n", __func__); |
| 679 | return -ENOMEM; |
| 680 | } |
| 681 | unmap_regions = (struct adm_cmd_memory_unmap_regions *) |
| 682 | unmap_region_cmd; |
| 683 | unmap_regions->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 684 | APR_HDR_LEN(APR_HDR_SIZE), |
| 685 | APR_PKT_VER); |
| 686 | unmap_regions->hdr.pkt_size = cmd_size; |
| 687 | unmap_regions->hdr.src_port = 0; |
| 688 | unmap_regions->hdr.dest_port = 0; |
| 689 | unmap_regions->hdr.token = 0; |
| 690 | unmap_regions->hdr.opcode = ADM_CMD_MEMORY_UNMAP_REGIONS; |
| 691 | unmap_regions->nregions = bufcnt & 0x00ff; |
| 692 | unmap_regions->reserved = 0; |
| 693 | pr_debug("%s: unmap_regions->nregions = %d\n", __func__, |
| 694 | unmap_regions->nregions); |
| 695 | payload = ((u8 *) unmap_region_cmd + |
| 696 | sizeof(struct adm_cmd_memory_unmap_regions)); |
| 697 | mregions = (struct adm_memory_unmap_regions *)payload; |
| 698 | |
| 699 | for (i = 0; i < bufcnt; i++) { |
| 700 | mregions->phys = buf_add[i]; |
| 701 | ++mregions; |
| 702 | } |
| 703 | atomic_set(&this_adm.copp_stat[0], 0); |
| 704 | ret = apr_send_pkt(this_adm.apr, (uint32_t *) unmap_region_cmd); |
| 705 | if (ret < 0) { |
| 706 | pr_err("%s: mmap_regions op[0x%x]rc[%d]\n", __func__, |
| 707 | unmap_regions->hdr.opcode, ret); |
| 708 | ret = -EINVAL; |
| 709 | goto fail_cmd; |
| 710 | } |
| 711 | |
| 712 | ret = wait_event_timeout(this_adm.wait, |
| 713 | atomic_read(&this_adm.copp_stat[0]), 5 * HZ); |
| 714 | if (!ret) { |
| 715 | pr_err("%s: timeout. waited for memory_unmap\n", __func__); |
| 716 | ret = -EINVAL; |
| 717 | goto fail_cmd; |
| 718 | } |
| 719 | fail_cmd: |
| 720 | kfree(unmap_region_cmd); |
| 721 | return ret; |
| 722 | } |
| 723 | |
| Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame] | 724 | int adm_get_copp_id(int port_index) |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 725 | { |
| 726 | pr_debug("%s\n", __func__); |
| 727 | |
| Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame] | 728 | if (port_index < 0) { |
| 729 | pr_err("%s: invalid port_id = %d\n", __func__, port_index); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 730 | return -EINVAL; |
| 731 | } |
| 732 | |
| Ben Romberger | 974a40d | 2011-07-18 15:08:21 -0700 | [diff] [blame] | 733 | return atomic_read(&this_adm.copp_id[port_index]); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 734 | } |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 735 | |
| 736 | int adm_close(int port_id) |
| 737 | { |
| 738 | struct apr_hdr close; |
| 739 | |
| 740 | int ret = 0; |
| Laxminath Kasam | 32657ec | 2011-08-01 19:26:57 +0530 | [diff] [blame] | 741 | int index = 0; |
| 742 | |
| 743 | port_id = afe_convert_virtual_to_portid(port_id); |
| 744 | |
| 745 | index = afe_get_port_index(port_id); |
| Bharath Ramachandramurthy | 51a8621 | 2011-07-29 12:43:43 -0700 | [diff] [blame] | 746 | if (afe_validate_port(port_id) < 0) |
| 747 | return -EINVAL; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 748 | |
| Jeff Ohlstein | 293b91f | 2011-12-16 13:22:46 -0800 | [diff] [blame] | 749 | 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] | 750 | |
| 751 | if (!(atomic_read(&this_adm.copp_cnt[index]))) { |
| 752 | pr_err("%s: copp count for port[%d]is 0\n", __func__, port_id); |
| 753 | |
| 754 | goto fail_cmd; |
| 755 | } |
| 756 | atomic_dec(&this_adm.copp_cnt[index]); |
| 757 | if (!(atomic_read(&this_adm.copp_cnt[index]))) { |
| 758 | |
| 759 | close.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 760 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 761 | close.pkt_size = sizeof(close); |
| 762 | close.src_svc = APR_SVC_ADM; |
| 763 | close.src_domain = APR_DOMAIN_APPS; |
| 764 | close.src_port = port_id; |
| 765 | close.dest_svc = APR_SVC_ADM; |
| 766 | close.dest_domain = APR_DOMAIN_ADSP; |
| 767 | close.dest_port = atomic_read(&this_adm.copp_id[index]); |
| 768 | close.token = port_id; |
| 769 | close.opcode = ADM_CMD_COPP_CLOSE; |
| 770 | |
| 771 | atomic_set(&this_adm.copp_id[index], RESET_COPP_ID); |
| 772 | atomic_set(&this_adm.copp_stat[index], 0); |
| 773 | |
| 774 | |
| 775 | pr_debug("%s:coppid %d portid=%d index=%d coppcnt=%d\n", |
| 776 | __func__, |
| 777 | atomic_read(&this_adm.copp_id[index]), |
| 778 | port_id, index, |
| 779 | atomic_read(&this_adm.copp_cnt[index])); |
| 780 | |
| 781 | ret = apr_send_pkt(this_adm.apr, (uint32_t *)&close); |
| 782 | if (ret < 0) { |
| 783 | pr_err("%s ADM close failed\n", __func__); |
| 784 | ret = -EINVAL; |
| 785 | goto fail_cmd; |
| 786 | } |
| 787 | |
| 788 | ret = wait_event_timeout(this_adm.wait, |
| 789 | atomic_read(&this_adm.copp_stat[index]), |
| 790 | msecs_to_jiffies(TIMEOUT_MS)); |
| 791 | if (!ret) { |
| 792 | pr_err("%s: ADM cmd Route failed for port %d\n", |
| 793 | __func__, port_id); |
| 794 | ret = -EINVAL; |
| 795 | goto fail_cmd; |
| 796 | } |
| Ben Romberger | 93d4d2d | 2011-10-19 23:04:02 -0700 | [diff] [blame] | 797 | |
| 798 | rtac_remove_adm_device(port_id); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | fail_cmd: |
| 802 | return ret; |
| 803 | } |
| 804 | |
| 805 | static int __init adm_init(void) |
| 806 | { |
| 807 | int i = 0; |
| 808 | init_waitqueue_head(&this_adm.wait); |
| 809 | this_adm.apr = NULL; |
| 810 | |
| 811 | for (i = 0; i < AFE_MAX_PORTS; i++) { |
| 812 | atomic_set(&this_adm.copp_id[i], RESET_COPP_ID); |
| 813 | atomic_set(&this_adm.copp_cnt[i], 0); |
| 814 | atomic_set(&this_adm.copp_stat[i], 0); |
| 815 | } |
| 816 | return 0; |
| 817 | } |
| 818 | |
| 819 | device_initcall(adm_init); |