Bharath Ramachandramurthy | 2e3168f | 2012-05-03 16:29:09 -0700 | [diff] [blame^] | 1 | /* Copyright (c) 2012, 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 | #include <linux/slab.h> |
| 14 | #include <linux/debugfs.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/kthread.h> |
| 17 | #include <linux/uaccess.h> |
| 18 | #include <linux/wait.h> |
| 19 | #include <linux/jiffies.h> |
| 20 | #include <linux/sched.h> |
| 21 | #include <mach/qdsp6v2/audio_acdb.h> |
| 22 | #include <sound/apr_audio-v2.h> |
| 23 | #include <sound/q6afe-v2.h> |
| 24 | |
| 25 | #include <sound/q6audio-v2.h> |
| 26 | |
| 27 | |
| 28 | struct afe_ctl { |
| 29 | void *apr; |
| 30 | atomic_t state; |
| 31 | atomic_t status; |
| 32 | wait_queue_head_t wait[AFE_MAX_PORTS]; |
| 33 | void (*tx_cb) (uint32_t opcode, |
| 34 | uint32_t token, uint32_t *payload, void *priv); |
| 35 | void (*rx_cb) (uint32_t opcode, |
| 36 | uint32_t token, uint32_t *payload, void *priv); |
| 37 | void *tx_private_data; |
| 38 | void *rx_private_data; |
| 39 | }; |
| 40 | |
| 41 | static struct afe_ctl this_afe; |
| 42 | |
| 43 | static struct acdb_cal_block afe_cal_addr[MAX_AUDPROC_TYPES]; |
| 44 | |
| 45 | #define TIMEOUT_MS 1000 |
| 46 | #define Q6AFE_MAX_VOLUME 0x3FFF |
| 47 | |
| 48 | #define SIZEOF_CFG_CMD(y) \ |
| 49 | (sizeof(struct apr_hdr) + sizeof(u16) + (sizeof(struct y))) |
| 50 | |
| 51 | static int32_t afe_callback(struct apr_client_data *data, void *priv) |
| 52 | { |
| 53 | if (data->opcode == RESET_EVENTS) { |
| 54 | pr_debug("q6afe: reset event = %d %d apr[%p]\n", |
| 55 | data->reset_event, data->reset_proc, this_afe.apr); |
| 56 | if (this_afe.apr) { |
| 57 | apr_reset(this_afe.apr); |
| 58 | atomic_set(&this_afe.state, 0); |
| 59 | this_afe.apr = NULL; |
| 60 | } |
| 61 | return 0; |
| 62 | } |
| 63 | pr_debug("%s:opcode = 0x%x cmd = 0x%x status = 0x%x\n", |
| 64 | __func__, data->opcode, |
| 65 | ((uint32_t *)(data->payload))[0], |
| 66 | ((uint32_t *)(data->payload))[1]); |
| 67 | if (data->payload_size) { |
| 68 | uint32_t *payload; |
| 69 | uint16_t port_id = 0; |
| 70 | payload = data->payload; |
| 71 | pr_debug("%s:opcode = 0x%x cmd = 0x%x status = 0x%x token=%d\n", |
| 72 | __func__, data->opcode, |
| 73 | payload[0], payload[1], data->token); |
| 74 | /* payload[1] contains the error status for response */ |
| 75 | if (payload[1] != 0) { |
| 76 | atomic_set(&this_afe.status, -1); |
| 77 | pr_err("%s: cmd = 0x%x returned error = 0x%x\n", |
| 78 | __func__, payload[0], payload[1]); |
| 79 | } |
| 80 | if (data->opcode == APR_BASIC_RSP_RESULT) { |
| 81 | switch (payload[0]) { |
| 82 | case AFE_PORT_CMD_DEVICE_STOP: |
| 83 | case AFE_PORT_CMD_DEVICE_START: |
| 84 | case AFE_PORT_CMD_SET_PARAM_V2: |
| 85 | case AFE_PSEUDOPORT_CMD_START: |
| 86 | case AFE_PSEUDOPORT_CMD_STOP: |
| 87 | case AFE_SERVICE_CMD_SHARED_MEM_MAP_REGIONS: |
| 88 | case AFE_SERVICE_CMD_SHARED_MEM_UNMAP_REGIONS: |
| 89 | case AFE_SERVICE_CMD_UNREGISTER_RT_PORT_DRIVER: |
| 90 | atomic_set(&this_afe.state, 0); |
| 91 | wake_up(&this_afe.wait[data->token]); |
| 92 | break; |
| 93 | case AFE_SERVICE_CMD_REGISTER_RT_PORT_DRIVER: |
| 94 | break; |
| 95 | case AFE_PORT_DATA_CMD_RT_PROXY_PORT_WRITE_V2: |
| 96 | port_id = RT_PROXY_PORT_001_TX; |
| 97 | break; |
| 98 | case AFE_PORT_DATA_CMD_RT_PROXY_PORT_READ_V2: |
| 99 | port_id = RT_PROXY_PORT_001_RX; |
| 100 | break; |
| 101 | default: |
| 102 | pr_err("%s:Unknown cmd 0x%x\n", __func__, |
| 103 | payload[0]); |
| 104 | break; |
| 105 | } |
| 106 | } else if (data->opcode == AFE_EVENT_RT_PROXY_PORT_STATUS) { |
| 107 | port_id = (uint16_t)(0x0000FFFF & payload[0]); |
| 108 | } |
| 109 | pr_debug("%s:port_id = %x\n", __func__, port_id); |
| 110 | switch (port_id) { |
| 111 | case RT_PROXY_PORT_001_TX: { |
| 112 | if (this_afe.tx_cb) { |
| 113 | this_afe.tx_cb(data->opcode, data->token, |
| 114 | data->payload, |
| 115 | this_afe.tx_private_data); |
| 116 | } |
| 117 | break; |
| 118 | } |
| 119 | case RT_PROXY_PORT_001_RX: { |
| 120 | if (this_afe.rx_cb) { |
| 121 | this_afe.rx_cb(data->opcode, data->token, |
| 122 | data->payload, |
| 123 | this_afe.rx_private_data); |
| 124 | } |
| 125 | break; |
| 126 | } |
| 127 | default: |
| 128 | break; |
| 129 | } |
| 130 | } |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | |
| 135 | int afe_get_port_type(u16 port_id) |
| 136 | { |
| 137 | int ret; |
| 138 | |
| 139 | switch (port_id) { |
| 140 | case PRIMARY_I2S_RX: |
| 141 | case PCM_RX: |
| 142 | case SECONDARY_I2S_RX: |
| 143 | case MI2S_RX: |
| 144 | case HDMI_RX: |
| 145 | case SLIMBUS_0_RX: |
| 146 | case SLIMBUS_1_RX: |
| 147 | case INT_BT_SCO_RX: |
| 148 | case INT_BT_A2DP_RX: |
| 149 | case INT_FM_RX: |
| 150 | case VOICE_PLAYBACK_TX: |
| 151 | case RT_PROXY_PORT_001_RX: |
| 152 | ret = MSM_AFE_PORT_TYPE_RX; |
| 153 | break; |
| 154 | |
| 155 | case PRIMARY_I2S_TX: |
| 156 | case PCM_TX: |
| 157 | case SECONDARY_I2S_TX: |
| 158 | case MI2S_TX: |
| 159 | case DIGI_MIC_TX: |
| 160 | case VOICE_RECORD_TX: |
| 161 | case SLIMBUS_0_TX: |
| 162 | case SLIMBUS_1_TX: |
| 163 | case INT_FM_TX: |
| 164 | case VOICE_RECORD_RX: |
| 165 | case INT_BT_SCO_TX: |
| 166 | case RT_PROXY_PORT_001_TX: |
| 167 | ret = MSM_AFE_PORT_TYPE_TX; |
| 168 | break; |
| 169 | |
| 170 | default: |
| 171 | pr_err("%s: invalid port id %d\n", __func__, port_id); |
| 172 | ret = -EINVAL; |
| 173 | } |
| 174 | |
| 175 | return ret; |
| 176 | } |
| 177 | |
| 178 | int afe_sizeof_cfg_cmd(u16 port_id) |
| 179 | { |
| 180 | int ret_size; |
| 181 | switch (port_id) { |
| 182 | case PRIMARY_I2S_RX: |
| 183 | case PRIMARY_I2S_TX: |
| 184 | case SECONDARY_I2S_RX: |
| 185 | case SECONDARY_I2S_TX: |
| 186 | case MI2S_RX: |
| 187 | case MI2S_TX: |
| 188 | ret_size = SIZEOF_CFG_CMD(afe_param_id_i2s_cfg); |
| 189 | break; |
| 190 | case HDMI_RX: |
| 191 | ret_size = |
| 192 | SIZEOF_CFG_CMD(afe_param_id_hdmi_multi_chan_audio_cfg); |
| 193 | break; |
| 194 | case SLIMBUS_0_RX: |
| 195 | case SLIMBUS_0_TX: |
| 196 | case SLIMBUS_1_RX: |
| 197 | case SLIMBUS_1_TX: |
| 198 | ret_size = SIZEOF_CFG_CMD(afe_param_id_slimbus_cfg); |
| 199 | break; |
| 200 | case RT_PROXY_PORT_001_RX: |
| 201 | case RT_PROXY_PORT_001_TX: |
| 202 | ret_size = SIZEOF_CFG_CMD(afe_param_id_rt_proxy_port_cfg); |
| 203 | break; |
| 204 | case PCM_RX: |
| 205 | case PCM_TX: |
| 206 | default: |
| 207 | ret_size = SIZEOF_CFG_CMD(afe_param_id_pcm_cfg); |
| 208 | break; |
| 209 | } |
| 210 | return ret_size; |
| 211 | } |
| 212 | |
| 213 | int afe_q6_interface_prepare(void) |
| 214 | { |
| 215 | int ret = 0; |
| 216 | |
| 217 | pr_debug("%s:", __func__); |
| 218 | |
| 219 | if (this_afe.apr == NULL) { |
| 220 | this_afe.apr = apr_register("ADSP", "AFE", afe_callback, |
| 221 | 0xFFFFFFFF, &this_afe); |
| 222 | if (this_afe.apr == NULL) { |
| 223 | pr_err("%s: Unable to register AFE\n", __func__); |
| 224 | ret = -ENODEV; |
| 225 | } |
| 226 | } |
| 227 | return ret; |
| 228 | } |
| 229 | static void afe_send_cal_block(int32_t path, u16 port_id) |
| 230 | { |
| 231 | /* To come back */ |
| 232 | } |
| 233 | |
| 234 | void afe_send_cal(u16 port_id) |
| 235 | { |
| 236 | pr_debug("%s\n", __func__); |
| 237 | |
| 238 | if (afe_get_port_type(port_id) == MSM_AFE_PORT_TYPE_TX) |
| 239 | afe_send_cal_block(TX_CAL, port_id); |
| 240 | else if (afe_get_port_type(port_id) == MSM_AFE_PORT_TYPE_RX) |
| 241 | afe_send_cal_block(RX_CAL, port_id); |
| 242 | } |
| 243 | |
| 244 | int afe_port_start_nowait(u16 port_id, union afe_port_config *afe_config, |
| 245 | u32 rate) /* This function is no blocking */ |
| 246 | { |
| 247 | struct afe_port_cmd_device_start start; |
| 248 | struct afe_audioif_config_command config; |
| 249 | int ret; |
| 250 | int cfg_type; |
| 251 | int index = 0; |
| 252 | |
| 253 | if (!afe_config) { |
| 254 | pr_err("%s: Error, no configuration data\n", __func__); |
| 255 | ret = -EINVAL; |
| 256 | return ret; |
| 257 | } |
| 258 | pr_err("%s: %d %d\n", __func__, port_id, rate); |
| 259 | index = q6audio_get_port_index(port_id); |
| 260 | if (q6audio_validate_port(port_id) < 0) |
| 261 | return -EINVAL; |
| 262 | |
| 263 | if ((port_id == RT_PROXY_DAI_001_RX) || |
| 264 | (port_id == RT_PROXY_DAI_002_TX)) |
| 265 | return -EINVAL; |
| 266 | if ((port_id == RT_PROXY_DAI_002_RX) || |
| 267 | (port_id == RT_PROXY_DAI_001_TX)) |
| 268 | port_id = VIRTUAL_ID_TO_PORTID(port_id); |
| 269 | |
| 270 | ret = afe_q6_interface_prepare(); |
| 271 | if (ret != 0) |
| 272 | return ret; |
| 273 | if (q6audio_validate_port(port_id) < 0) { |
| 274 | pr_err("%s: Failed : Invalid Port id = %d\n", __func__, |
| 275 | port_id); |
| 276 | ret = -EINVAL; |
| 277 | goto fail_cmd; |
| 278 | } |
| 279 | |
| 280 | config.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 281 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 282 | config.hdr.pkt_size = afe_sizeof_cfg_cmd(port_id); |
| 283 | config.hdr.src_port = 0; |
| 284 | config.hdr.dest_port = 0; |
| 285 | |
| 286 | config.hdr.token = index; |
| 287 | switch (port_id) { |
| 288 | case PRIMARY_I2S_RX: |
| 289 | case PRIMARY_I2S_TX: |
| 290 | cfg_type = AFE_PARAM_ID_PCM_CONFIG; |
| 291 | break; |
| 292 | case PCM_RX: |
| 293 | case PCM_TX: |
| 294 | cfg_type = AFE_PARAM_ID_HDMI_CONFIG; |
| 295 | break; |
| 296 | case SECONDARY_I2S_RX: |
| 297 | case SECONDARY_I2S_TX: |
| 298 | case MI2S_RX: |
| 299 | case MI2S_TX: |
| 300 | cfg_type = AFE_PARAM_ID_I2S_CONFIG; |
| 301 | break; |
| 302 | case HDMI_RX: |
| 303 | cfg_type = AFE_PARAM_ID_HDMI_CONFIG; |
| 304 | break; |
| 305 | case SLIMBUS_0_RX: |
| 306 | case SLIMBUS_0_TX: |
| 307 | case SLIMBUS_1_RX: |
| 308 | case SLIMBUS_1_TX: |
| 309 | case SLIMBUS_2_RX: |
| 310 | case SLIMBUS_2_TX: |
| 311 | case SLIMBUS_3_RX: |
| 312 | case SLIMBUS_3_TX: |
| 313 | case SLIMBUS_4_RX: |
| 314 | case SLIMBUS_4_TX: |
| 315 | cfg_type = AFE_PARAM_ID_SLIMBUS_CONFIG; |
| 316 | break; |
| 317 | default: |
| 318 | pr_err("%s: Invalid port id 0x%x\n", __func__, port_id); |
| 319 | ret = -EINVAL; |
| 320 | goto fail_cmd; |
| 321 | } |
| 322 | config.hdr.opcode = AFE_PORT_CMD_SET_PARAM_V2; |
| 323 | config.param.port_id = port_id; |
| 324 | config.param.payload_size = (afe_sizeof_cfg_cmd(port_id) + |
| 325 | sizeof(struct afe_port_param_data_v2)); |
| 326 | config.param.payload_address_lsw = 0x00; |
| 327 | config.param.payload_address_msw = 0x00; |
| 328 | config.param.mem_map_handle = 0x00; |
| 329 | config.pdata.module_id = AFE_MODULE_AUDIO_DEV_INTERFACE; |
| 330 | config.pdata.param_id = cfg_type; |
| 331 | config.pdata.param_size = afe_sizeof_cfg_cmd(port_id); |
| 332 | |
| 333 | config.port = *afe_config; |
| 334 | |
| 335 | ret = apr_send_pkt(this_afe.apr, (uint32_t *) &config); |
| 336 | if (ret < 0) { |
| 337 | pr_err("%s: AFE enable for port %d failed\n", __func__, |
| 338 | port_id); |
| 339 | ret = -EINVAL; |
| 340 | goto fail_cmd; |
| 341 | } |
| 342 | |
| 343 | /* send AFE cal */ |
| 344 | afe_send_cal(port_id); |
| 345 | |
| 346 | start.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 347 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 348 | start.hdr.pkt_size = sizeof(start); |
| 349 | start.hdr.src_port = 0; |
| 350 | start.hdr.dest_port = 0; |
| 351 | start.hdr.token = 0; |
| 352 | start.hdr.opcode = AFE_PORT_CMD_DEVICE_START; |
| 353 | start.port_id = port_id; |
| 354 | |
| 355 | ret = apr_send_pkt(this_afe.apr, (uint32_t *) &start); |
| 356 | |
| 357 | if (IS_ERR_VALUE(ret)) { |
| 358 | pr_err("%s: AFE enable for port %d failed\n", __func__, |
| 359 | port_id); |
| 360 | ret = -EINVAL; |
| 361 | goto fail_cmd; |
| 362 | } |
| 363 | |
| 364 | return 0; |
| 365 | |
| 366 | fail_cmd: |
| 367 | return ret; |
| 368 | } |
| 369 | |
| 370 | int afe_open(u16 port_id, |
| 371 | union afe_port_config *afe_config, int rate) |
| 372 | { |
| 373 | struct afe_port_cmd_device_start start; |
| 374 | struct afe_audioif_config_command config; |
| 375 | int ret = 0; |
| 376 | int cfg_type; |
| 377 | int index = 0; |
| 378 | |
| 379 | if (!afe_config) { |
| 380 | pr_err("%s: Error, no configuration data\n", __func__); |
| 381 | ret = -EINVAL; |
| 382 | return ret; |
| 383 | } |
| 384 | |
| 385 | pr_err("%s: %d %d\n", __func__, port_id, rate); |
| 386 | |
| 387 | index = q6audio_get_port_index(port_id); |
| 388 | if (q6audio_validate_port(port_id) < 0) |
| 389 | return -EINVAL; |
| 390 | |
| 391 | if ((port_id == RT_PROXY_DAI_001_RX) || |
| 392 | (port_id == RT_PROXY_DAI_002_TX)) |
| 393 | return -EINVAL; |
| 394 | if ((port_id == RT_PROXY_DAI_002_RX) || |
| 395 | (port_id == RT_PROXY_DAI_001_TX)) |
| 396 | port_id = VIRTUAL_ID_TO_PORTID(port_id); |
| 397 | |
| 398 | ret = afe_q6_interface_prepare(); |
| 399 | if (ret != 0) |
| 400 | return ret; |
| 401 | |
| 402 | if (q6audio_validate_port(port_id) < 0) { |
| 403 | pr_err("%s: Failed : Invalid Port id = %d\n", __func__, |
| 404 | port_id); |
| 405 | ret = -EINVAL; |
| 406 | goto fail_cmd; |
| 407 | } |
| 408 | |
| 409 | config.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 410 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 411 | config.hdr.pkt_size = sizeof(config); |
| 412 | config.hdr.src_port = 0; |
| 413 | config.hdr.dest_port = 0; |
| 414 | config.hdr.token = index; |
| 415 | switch (port_id) { |
| 416 | case PRIMARY_I2S_RX: |
| 417 | case PRIMARY_I2S_TX: |
| 418 | cfg_type = AFE_PARAM_ID_I2S_CONFIG; |
| 419 | break; |
| 420 | case PCM_RX: |
| 421 | case PCM_TX: |
| 422 | cfg_type = AFE_PARAM_ID_PCM_CONFIG; |
| 423 | break; |
| 424 | case SECONDARY_I2S_RX: |
| 425 | case SECONDARY_I2S_TX: |
| 426 | case MI2S_RX: |
| 427 | case MI2S_TX: |
| 428 | cfg_type = AFE_PARAM_ID_I2S_CONFIG; |
| 429 | break; |
| 430 | case HDMI_RX: |
| 431 | cfg_type = AFE_PARAM_ID_HDMI_CONFIG; |
| 432 | break; |
| 433 | case SLIMBUS_0_RX: |
| 434 | case SLIMBUS_0_TX: |
| 435 | case SLIMBUS_1_RX: |
| 436 | case SLIMBUS_1_TX: |
| 437 | case SLIMBUS_2_RX: |
| 438 | case SLIMBUS_2_TX: |
| 439 | case SLIMBUS_3_RX: |
| 440 | case SLIMBUS_3_TX: |
| 441 | case SLIMBUS_4_RX: |
| 442 | case SLIMBUS_4_TX: |
| 443 | cfg_type = AFE_PARAM_ID_SLIMBUS_CONFIG; |
| 444 | break; |
| 445 | default: |
| 446 | pr_err("%s: Invalid port id 0x%x\n", __func__, port_id); |
| 447 | ret = -EINVAL; |
| 448 | goto fail_cmd; |
| 449 | } |
| 450 | config.hdr.opcode = AFE_PORT_CMD_SET_PARAM_V2; |
| 451 | config.param.port_id = q6audio_get_port_id(port_id); |
| 452 | config.param.payload_size = sizeof(config) - sizeof(struct apr_hdr) |
| 453 | - sizeof(config.param); |
| 454 | config.param.payload_address_lsw = 0x00; |
| 455 | config.param.payload_address_msw = 0x00; |
| 456 | config.param.mem_map_handle = 0x00; |
| 457 | config.pdata.module_id = AFE_MODULE_AUDIO_DEV_INTERFACE; |
| 458 | config.pdata.param_id = cfg_type; |
| 459 | config.pdata.param_size = sizeof(config.port); |
| 460 | |
| 461 | config.port = *afe_config; |
| 462 | pr_debug("%s: param PL size=%d iparam_size[%d][%d %d %d %d]" |
| 463 | " param_id[%x]\n", |
| 464 | __func__, config.param.payload_size, config.pdata.param_size, |
| 465 | sizeof(config), sizeof(config.param), sizeof(config.port), |
| 466 | sizeof(struct apr_hdr), config.pdata.param_id); |
| 467 | atomic_set(&this_afe.state, 1); |
| 468 | atomic_set(&this_afe.status, 0); |
| 469 | ret = apr_send_pkt(this_afe.apr, (uint32_t *) &config); |
| 470 | if (ret < 0) { |
| 471 | pr_err("%s: AFE enable for port %d opcode[0x%x]failed\n", |
| 472 | __func__, port_id, cfg_type); |
| 473 | ret = -EINVAL; |
| 474 | goto fail_cmd; |
| 475 | } |
| 476 | |
| 477 | ret = wait_event_timeout(this_afe.wait[index], |
| 478 | (atomic_read(&this_afe.state) == 0), |
| 479 | msecs_to_jiffies(TIMEOUT_MS)); |
| 480 | if (!ret) { |
| 481 | pr_err("%s: wait_event timeout\n", __func__); |
| 482 | ret = -EINVAL; |
| 483 | goto fail_cmd; |
| 484 | } |
| 485 | if (atomic_read(&this_afe.status) != 0) { |
| 486 | pr_err("%s: config cmd failed\n", __func__); |
| 487 | ret = -EINVAL; |
| 488 | goto fail_cmd; |
| 489 | } |
| 490 | start.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 491 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 492 | start.hdr.pkt_size = sizeof(start); |
| 493 | start.hdr.src_port = 0; |
| 494 | start.hdr.dest_port = 0; |
| 495 | start.hdr.token = index; |
| 496 | start.hdr.opcode = AFE_PORT_CMD_DEVICE_START; |
| 497 | start.port_id = q6audio_get_port_id(port_id); |
| 498 | pr_debug("%s: cmd device start opcode[0x%x] port id[0x%x]\n", |
| 499 | __func__, start.hdr.opcode, start.port_id); |
| 500 | atomic_set(&this_afe.state, 1); |
| 501 | ret = apr_send_pkt(this_afe.apr, (uint32_t *) &start); |
| 502 | if (ret < 0) { |
| 503 | pr_err("%s: AFE enable for port %d failed\n", __func__, |
| 504 | port_id); |
| 505 | ret = -EINVAL; |
| 506 | goto fail_cmd; |
| 507 | } |
| 508 | ret = wait_event_timeout(this_afe.wait[index], |
| 509 | (atomic_read(&this_afe.state) == 0), |
| 510 | msecs_to_jiffies(TIMEOUT_MS)); |
| 511 | if (!ret) { |
| 512 | pr_err("%s: wait_event timeout\n", __func__); |
| 513 | ret = -EINVAL; |
| 514 | goto fail_cmd; |
| 515 | } |
| 516 | |
| 517 | return 0; |
| 518 | fail_cmd: |
| 519 | return ret; |
| 520 | } |
| 521 | |
| 522 | int afe_loopback(u16 enable, u16 rx_port, u16 tx_port) |
| 523 | { |
| 524 | struct afe_loopback_cfg_v1 lb_cmd; |
| 525 | int ret = 0; |
| 526 | int index = 0; |
| 527 | |
| 528 | ret = afe_q6_interface_prepare(); |
| 529 | if (ret != 0) |
| 530 | return ret; |
| 531 | |
| 532 | index = q6audio_get_port_index(rx_port); |
| 533 | if (q6audio_validate_port(rx_port) < 0) |
| 534 | return -EINVAL; |
| 535 | |
| 536 | lb_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 537 | APR_HDR_LEN(20), APR_PKT_VER); |
| 538 | lb_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 539 | sizeof(lb_cmd) - APR_HDR_SIZE); |
| 540 | lb_cmd.hdr.src_port = 0; |
| 541 | lb_cmd.hdr.dest_port = 0; |
| 542 | lb_cmd.hdr.token = 0; |
| 543 | lb_cmd.hdr.opcode = AFE_PORT_CMD_SET_PARAM_V2; |
| 544 | lb_cmd.param.port_id = tx_port; |
| 545 | lb_cmd.param.payload_size = (sizeof(lb_cmd) - |
| 546 | sizeof(struct apr_hdr) - |
| 547 | sizeof(struct afe_port_cmd_set_param_v2)); |
| 548 | lb_cmd.param.payload_address_lsw = 0x00; |
| 549 | lb_cmd.param.payload_address_msw = 0x00; |
| 550 | lb_cmd.param.mem_map_handle = 0x00; |
| 551 | lb_cmd.pdata.module_id = AFE_MODULE_LOOPBACK; |
| 552 | lb_cmd.pdata.param_id = AFE_PARAM_ID_LOOPBACK_CONFIG; |
| 553 | lb_cmd.pdata.param_size = lb_cmd.param.payload_size - |
| 554 | sizeof(struct afe_port_param_data_v2); |
| 555 | |
| 556 | lb_cmd.dst_port_id = rx_port; |
| 557 | lb_cmd.routing_mode = LB_MODE_DEFAULT; |
| 558 | lb_cmd.enable = (enable ? 1 : 0); |
| 559 | lb_cmd.loopback_cfg_minor_version = |
| 560 | AFE_API_VERSION_LOOPBACK_CONFIG; |
| 561 | atomic_set(&this_afe.state, 1); |
| 562 | |
| 563 | ret = apr_send_pkt(this_afe.apr, (uint32_t *) &lb_cmd); |
| 564 | if (ret < 0) { |
| 565 | pr_err("%s: AFE loopback failed\n", __func__); |
| 566 | ret = -EINVAL; |
| 567 | goto done; |
| 568 | } |
| 569 | ret = wait_event_timeout(this_afe.wait[index], |
| 570 | (atomic_read(&this_afe.state) == 0), |
| 571 | msecs_to_jiffies(TIMEOUT_MS)); |
| 572 | if (!ret) { |
| 573 | pr_err("%s: wait_event timeout\n", __func__); |
| 574 | ret = -EINVAL; |
| 575 | } |
| 576 | done: |
| 577 | return ret; |
| 578 | } |
| 579 | |
| 580 | int afe_loopback_gain(u16 port_id, u16 volume) |
| 581 | { |
| 582 | struct afe_loopback_gain_per_path_param set_param; |
| 583 | int ret = 0; |
| 584 | int index = 0; |
| 585 | |
| 586 | if (this_afe.apr == NULL) { |
| 587 | this_afe.apr = apr_register("ADSP", "AFE", afe_callback, |
| 588 | 0xFFFFFFFF, &this_afe); |
| 589 | pr_debug("%s: Register AFE\n", __func__); |
| 590 | if (this_afe.apr == NULL) { |
| 591 | pr_err("%s: Unable to register AFE\n", __func__); |
| 592 | ret = -ENODEV; |
| 593 | return ret; |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | if (q6audio_validate_port(port_id) < 0) { |
| 598 | |
| 599 | pr_err("%s: Failed : Invalid Port id = %d\n", __func__, |
| 600 | port_id); |
| 601 | ret = -EINVAL; |
| 602 | goto fail_cmd; |
| 603 | } |
| 604 | index = q6audio_get_port_index(port_id); |
| 605 | if (q6audio_validate_port(port_id) < 0) |
| 606 | return -EINVAL; |
| 607 | |
| 608 | /* RX ports numbers are even .TX ports numbers are odd. */ |
| 609 | if (port_id % 2 == 0) { |
| 610 | pr_err("%s: Failed : afe loopback gain only for TX ports." |
| 611 | " port_id %d\n", __func__, port_id); |
| 612 | ret = -EINVAL; |
| 613 | goto fail_cmd; |
| 614 | } |
| 615 | |
| 616 | pr_debug("%s: %d %hX\n", __func__, port_id, volume); |
| 617 | |
| 618 | set_param.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 619 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 620 | set_param.hdr.pkt_size = sizeof(set_param); |
| 621 | set_param.hdr.src_port = 0; |
| 622 | set_param.hdr.dest_port = 0; |
| 623 | set_param.hdr.token = 0; |
| 624 | set_param.hdr.opcode = AFE_PORT_CMD_SET_PARAM_V2; |
| 625 | |
| 626 | set_param.param.port_id = port_id; |
| 627 | set_param.param.payload_size = |
| 628 | (sizeof(struct afe_loopback_gain_per_path_param) - |
| 629 | sizeof(struct apr_hdr) - |
| 630 | sizeof(struct afe_port_cmd_set_param_v2)); |
| 631 | set_param.param.payload_address_lsw = 0; |
| 632 | set_param.param.payload_address_msw = 0; |
| 633 | set_param.param.mem_map_handle = 0; |
| 634 | |
| 635 | set_param.pdata.module_id = AFE_MODULE_LOOPBACK; |
| 636 | set_param.pdata.param_id = AFE_PARAM_ID_LOOPBACK_GAIN_PER_PATH; |
| 637 | set_param.pdata.param_size = (set_param.param.payload_size - |
| 638 | sizeof(struct afe_port_param_data_v2)); |
| 639 | set_param.rx_port_id = port_id; |
| 640 | set_param.gain = volume; |
| 641 | |
| 642 | set_param.hdr.token = index; |
| 643 | |
| 644 | atomic_set(&this_afe.state, 1); |
| 645 | ret = apr_send_pkt(this_afe.apr, (uint32_t *) &set_param); |
| 646 | if (ret < 0) { |
| 647 | pr_err("%s: AFE param set failed for port %d\n", |
| 648 | __func__, port_id); |
| 649 | ret = -EINVAL; |
| 650 | goto fail_cmd; |
| 651 | } |
| 652 | |
| 653 | ret = wait_event_timeout(this_afe.wait[index], |
| 654 | (atomic_read(&this_afe.state) == 0), |
| 655 | msecs_to_jiffies(TIMEOUT_MS)); |
| 656 | if (ret < 0) { |
| 657 | pr_err("%s: wait_event timeout\n", __func__); |
| 658 | ret = -EINVAL; |
| 659 | goto fail_cmd; |
| 660 | } |
| 661 | return 0; |
| 662 | fail_cmd: |
| 663 | return ret; |
| 664 | } |
| 665 | |
| 666 | int afe_pseudo_port_start_nowait(u16 port_id) |
| 667 | { |
| 668 | struct afe_pseudoport_start_command start; |
| 669 | int ret = 0; |
| 670 | |
| 671 | pr_debug("%s: port_id=%d\n", __func__, port_id); |
| 672 | if (this_afe.apr == NULL) { |
| 673 | pr_err("%s: AFE APR is not registered\n", __func__); |
| 674 | return -ENODEV; |
| 675 | } |
| 676 | |
| 677 | |
| 678 | start.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 679 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 680 | start.hdr.pkt_size = sizeof(start); |
| 681 | start.hdr.src_port = 0; |
| 682 | start.hdr.dest_port = 0; |
| 683 | start.hdr.token = 0; |
| 684 | start.hdr.opcode = AFE_PSEUDOPORT_CMD_START; |
| 685 | start.port_id = port_id; |
| 686 | start.timing = 1; |
| 687 | |
| 688 | atomic_set(&this_afe.state, 1); |
| 689 | ret = apr_send_pkt(this_afe.apr, (uint32_t *) &start); |
| 690 | if (ret < 0) { |
| 691 | pr_err("%s: AFE enable for port %d failed %d\n", |
| 692 | __func__, port_id, ret); |
| 693 | return -EINVAL; |
| 694 | } |
| 695 | return 0; |
| 696 | } |
| 697 | |
| 698 | int afe_start_pseudo_port(u16 port_id) |
| 699 | { |
| 700 | int ret = 0; |
| 701 | struct afe_pseudoport_start_command start; |
| 702 | int index = 0; |
| 703 | |
| 704 | pr_debug("%s: port_id=%d\n", __func__, port_id); |
| 705 | |
| 706 | ret = afe_q6_interface_prepare(); |
| 707 | if (ret != 0) |
| 708 | return ret; |
| 709 | |
| 710 | index = q6audio_get_port_index(port_id); |
| 711 | if (q6audio_validate_port(port_id) < 0) |
| 712 | return -EINVAL; |
| 713 | |
| 714 | start.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 715 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 716 | start.hdr.pkt_size = sizeof(start); |
| 717 | start.hdr.src_port = 0; |
| 718 | start.hdr.dest_port = 0; |
| 719 | start.hdr.token = 0; |
| 720 | start.hdr.opcode = AFE_PSEUDOPORT_CMD_START; |
| 721 | start.port_id = port_id; |
| 722 | start.timing = 1; |
| 723 | |
| 724 | start.hdr.token = index; |
| 725 | atomic_set(&this_afe.state, 1); |
| 726 | ret = apr_send_pkt(this_afe.apr, (uint32_t *) &start); |
| 727 | if (ret < 0) { |
| 728 | pr_err("%s: AFE enable for port %d failed %d\n", |
| 729 | __func__, port_id, ret); |
| 730 | return -EINVAL; |
| 731 | } |
| 732 | |
| 733 | ret = wait_event_timeout(this_afe.wait[index], |
| 734 | (atomic_read(&this_afe.state) == 0), |
| 735 | msecs_to_jiffies(TIMEOUT_MS)); |
| 736 | if (!ret) { |
| 737 | pr_err("%s: wait_event timeout\n", __func__); |
| 738 | return -EINVAL; |
| 739 | } |
| 740 | |
| 741 | return 0; |
| 742 | } |
| 743 | |
| 744 | int afe_pseudo_port_stop_nowait(u16 port_id) |
| 745 | { |
| 746 | int ret = 0; |
| 747 | struct afe_pseudoport_stop_command stop; |
| 748 | int index = 0; |
| 749 | |
| 750 | pr_debug("%s: port_id=%d\n", __func__, port_id); |
| 751 | |
| 752 | if (this_afe.apr == NULL) { |
| 753 | pr_err("%s: AFE is already closed\n", __func__); |
| 754 | return -EINVAL; |
| 755 | } |
| 756 | index = q6audio_get_port_index(port_id); |
| 757 | if (q6audio_validate_port(port_id) < 0) |
| 758 | return -EINVAL; |
| 759 | |
| 760 | stop.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 761 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 762 | stop.hdr.pkt_size = sizeof(stop); |
| 763 | stop.hdr.src_port = 0; |
| 764 | stop.hdr.dest_port = 0; |
| 765 | stop.hdr.token = 0; |
| 766 | stop.hdr.opcode = AFE_PSEUDOPORT_CMD_STOP; |
| 767 | stop.port_id = port_id; |
| 768 | stop.reserved = 0; |
| 769 | |
| 770 | stop.hdr.token = index; |
| 771 | atomic_set(&this_afe.state, 1); |
| 772 | ret = apr_send_pkt(this_afe.apr, (uint32_t *) &stop); |
| 773 | if (ret < 0) { |
| 774 | pr_err("%s: AFE close failed %d\n", __func__, ret); |
| 775 | return -EINVAL; |
| 776 | } |
| 777 | |
| 778 | return 0; |
| 779 | |
| 780 | } |
| 781 | |
| 782 | int afe_stop_pseudo_port(u16 port_id) |
| 783 | { |
| 784 | int ret = 0; |
| 785 | struct afe_pseudoport_stop_command stop; |
| 786 | int index = 0; |
| 787 | |
| 788 | pr_debug("%s: port_id=%d\n", __func__, port_id); |
| 789 | |
| 790 | if (this_afe.apr == NULL) { |
| 791 | pr_err("%s: AFE is already closed\n", __func__); |
| 792 | return -EINVAL; |
| 793 | } |
| 794 | |
| 795 | index = q6audio_get_port_index(port_id); |
| 796 | if (q6audio_validate_port(port_id) < 0) |
| 797 | return -EINVAL; |
| 798 | |
| 799 | stop.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 800 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 801 | stop.hdr.pkt_size = sizeof(stop); |
| 802 | stop.hdr.src_port = 0; |
| 803 | stop.hdr.dest_port = 0; |
| 804 | stop.hdr.token = 0; |
| 805 | stop.hdr.opcode = AFE_PSEUDOPORT_CMD_STOP; |
| 806 | stop.port_id = port_id; |
| 807 | stop.reserved = 0; |
| 808 | |
| 809 | stop.hdr.token = index; |
| 810 | atomic_set(&this_afe.state, 1); |
| 811 | ret = apr_send_pkt(this_afe.apr, (uint32_t *) &stop); |
| 812 | if (ret < 0) { |
| 813 | pr_err("%s: AFE close failed %d\n", __func__, ret); |
| 814 | return -EINVAL; |
| 815 | } |
| 816 | |
| 817 | ret = wait_event_timeout(this_afe.wait[index], |
| 818 | (atomic_read(&this_afe.state) == 0), |
| 819 | msecs_to_jiffies(TIMEOUT_MS)); |
| 820 | if (!ret) { |
| 821 | pr_err("%s: wait_event timeout\n", __func__); |
| 822 | return -EINVAL; |
| 823 | } |
| 824 | |
| 825 | return 0; |
| 826 | } |
| 827 | |
| 828 | /*bharath, memory map handle needs to be stored by AFE client */ |
| 829 | int afe_cmd_memory_map(u32 dma_addr_p, u32 dma_buf_sz) |
| 830 | { |
| 831 | int ret = 0; |
| 832 | int cmd_size = 0; |
| 833 | void *payload = NULL; |
| 834 | void *mmap_region_cmd = NULL; |
| 835 | struct afe_service_cmd_shared_mem_map_regions *mregion = NULL; |
| 836 | struct afe_service_shared_map_region_payload *mregion_pl = NULL; |
| 837 | int index = 0; |
| 838 | |
| 839 | pr_debug("%s:\n", __func__); |
| 840 | |
| 841 | if (this_afe.apr == NULL) { |
| 842 | this_afe.apr = apr_register("ADSP", "AFE", afe_callback, |
| 843 | 0xFFFFFFFF, &this_afe); |
| 844 | pr_debug("%s: Register AFE\n", __func__); |
| 845 | if (this_afe.apr == NULL) { |
| 846 | pr_err("%s: Unable to register AFE\n", __func__); |
| 847 | ret = -ENODEV; |
| 848 | return ret; |
| 849 | } |
| 850 | } |
| 851 | |
| 852 | cmd_size = sizeof(struct afe_service_cmd_shared_mem_map_regions) \ |
| 853 | + sizeof(struct afe_service_shared_map_region_payload); |
| 854 | |
| 855 | mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL); |
| 856 | if (!mmap_region_cmd) { |
| 857 | pr_err("%s: allocate mmap_region_cmd failed\n", __func__); |
| 858 | return -ENOMEM; |
| 859 | } |
| 860 | |
| 861 | mregion = (struct afe_service_cmd_shared_mem_map_regions *) |
| 862 | mmap_region_cmd; |
| 863 | mregion->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 864 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 865 | mregion->hdr.pkt_size = sizeof(mregion); |
| 866 | mregion->hdr.src_port = 0; |
| 867 | mregion->hdr.dest_port = 0; |
| 868 | mregion->hdr.token = 0; |
| 869 | mregion->hdr.opcode = AFE_SERVICE_CMD_SHARED_MEM_MAP_REGIONS; |
| 870 | mregion->mem_pool_id = ADSP_MEMORY_MAP_EBI_POOL; |
| 871 | mregion->num_regions = 1; |
| 872 | mregion->property_flag = 0x00; |
| 873 | /* Todo */ |
| 874 | index = mregion->hdr.token = IDX_RSVD_2; |
| 875 | |
| 876 | payload = ((u8 *) mmap_region_cmd + |
| 877 | sizeof(struct afe_service_cmd_shared_mem_map_regions)); |
| 878 | |
| 879 | mregion_pl = (struct afe_service_shared_map_region_payload *)payload; |
| 880 | |
| 881 | mregion_pl->shm_addr_lsw = dma_addr_p; |
| 882 | mregion_pl->shm_addr_msw = 0x00; |
| 883 | mregion_pl->mem_size_bytes = dma_buf_sz; |
| 884 | |
| 885 | atomic_set(&this_afe.state, 1); |
| 886 | ret = apr_send_pkt(this_afe.apr, (uint32_t *) mmap_region_cmd); |
| 887 | if (ret < 0) { |
| 888 | pr_err("%s: AFE memory map cmd failed %d\n", |
| 889 | __func__, ret); |
| 890 | ret = -EINVAL; |
| 891 | return ret; |
| 892 | } |
| 893 | |
| 894 | ret = wait_event_timeout(this_afe.wait[index], |
| 895 | (atomic_read(&this_afe.state) == 0), |
| 896 | msecs_to_jiffies(TIMEOUT_MS)); |
| 897 | if (!ret) { |
| 898 | pr_err("%s: wait_event timeout\n", __func__); |
| 899 | ret = -EINVAL; |
| 900 | return ret; |
| 901 | } |
| 902 | |
| 903 | return 0; |
| 904 | } |
| 905 | |
| 906 | int afe_cmd_memory_map_nowait(int port_id, u32 dma_addr_p, u32 dma_buf_sz) |
| 907 | { |
| 908 | int ret = 0; |
| 909 | int cmd_size = 0; |
| 910 | void *payload = NULL; |
| 911 | void *mmap_region_cmd = NULL; |
| 912 | struct afe_service_cmd_shared_mem_map_regions *mregion = NULL; |
| 913 | struct afe_service_shared_map_region_payload *mregion_pl = NULL; |
| 914 | int index = 0; |
| 915 | |
| 916 | pr_debug("%s:\n", __func__); |
| 917 | |
| 918 | if (this_afe.apr == NULL) { |
| 919 | this_afe.apr = apr_register("ADSP", "AFE", afe_callback, |
| 920 | 0xFFFFFFFF, &this_afe); |
| 921 | pr_debug("%s: Register AFE\n", __func__); |
| 922 | if (this_afe.apr == NULL) { |
| 923 | pr_err("%s: Unable to register AFE\n", __func__); |
| 924 | ret = -ENODEV; |
| 925 | return ret; |
| 926 | } |
| 927 | } |
| 928 | index = q6audio_get_port_index(port_id); |
| 929 | if (q6audio_validate_port(port_id) < 0) |
| 930 | return -EINVAL; |
| 931 | |
| 932 | cmd_size = sizeof(struct afe_service_cmd_shared_mem_map_regions) |
| 933 | + sizeof(struct afe_service_shared_map_region_payload); |
| 934 | |
| 935 | mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL); |
| 936 | if (!mmap_region_cmd) { |
| 937 | pr_err("%s: allocate mmap_region_cmd failed\n", __func__); |
| 938 | return -ENOMEM; |
| 939 | } |
| 940 | mregion = (struct afe_service_cmd_shared_mem_map_regions *) |
| 941 | mmap_region_cmd; |
| 942 | mregion->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 943 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 944 | mregion->hdr.pkt_size = sizeof(mregion); |
| 945 | mregion->hdr.src_port = 0; |
| 946 | mregion->hdr.dest_port = 0; |
| 947 | mregion->hdr.token = 0; |
| 948 | mregion->hdr.opcode = AFE_SERVICE_CMD_SHARED_MEM_MAP_REGIONS; |
| 949 | mregion->mem_pool_id = ADSP_MEMORY_MAP_EBI_POOL; |
| 950 | mregion->num_regions = 1; |
| 951 | mregion->property_flag = 0x00; |
| 952 | |
| 953 | payload = ((u8 *) mmap_region_cmd + |
| 954 | sizeof(struct afe_service_cmd_shared_mem_map_regions)); |
| 955 | mregion_pl = (struct afe_service_shared_map_region_payload *)payload; |
| 956 | |
| 957 | mregion_pl->shm_addr_lsw = dma_addr_p; |
| 958 | mregion_pl->shm_addr_msw = 0x00; |
| 959 | mregion_pl->mem_size_bytes = dma_buf_sz; |
| 960 | |
| 961 | atomic_set(&this_afe.state, 1); |
| 962 | ret = apr_send_pkt(this_afe.apr, (uint32_t *) mmap_region_cmd); |
| 963 | if (ret < 0) { |
| 964 | pr_err("%s: AFE memory map cmd failed %d\n", |
| 965 | __func__, ret); |
| 966 | ret = -EINVAL; |
| 967 | return ret; |
| 968 | } |
| 969 | return 0; |
| 970 | } |
| 971 | |
| 972 | int afe_cmd_memory_unmap(u32 mem_map_handle) |
| 973 | { |
| 974 | int ret = 0; |
| 975 | struct afe_service_cmd_shared_mem_unmap_regions mregion; |
| 976 | int index = 0; |
| 977 | |
| 978 | pr_debug("%s:\n", __func__); |
| 979 | |
| 980 | if (this_afe.apr == NULL) { |
| 981 | this_afe.apr = apr_register("ADSP", "AFE", afe_callback, |
| 982 | 0xFFFFFFFF, &this_afe); |
| 983 | pr_debug("%s: Register AFE\n", __func__); |
| 984 | if (this_afe.apr == NULL) { |
| 985 | pr_err("%s: Unable to register AFE\n", __func__); |
| 986 | ret = -ENODEV; |
| 987 | return ret; |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | mregion.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 992 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 993 | mregion.hdr.pkt_size = sizeof(mregion); |
| 994 | mregion.hdr.src_port = 0; |
| 995 | mregion.hdr.dest_port = 0; |
| 996 | mregion.hdr.token = 0; |
| 997 | mregion.hdr.opcode = AFE_SERVICE_CMD_SHARED_MEM_UNMAP_REGIONS; |
| 998 | mregion.mem_map_handle = mem_map_handle; |
| 999 | |
| 1000 | /* Todo */ |
| 1001 | index = mregion.hdr.token = IDX_RSVD_2; |
| 1002 | |
| 1003 | atomic_set(&this_afe.state, 1); |
| 1004 | ret = apr_send_pkt(this_afe.apr, (uint32_t *) &mregion); |
| 1005 | if (ret < 0) { |
| 1006 | pr_err("%s: AFE memory unmap cmd failed %d\n", |
| 1007 | __func__, ret); |
| 1008 | ret = -EINVAL; |
| 1009 | return ret; |
| 1010 | } |
| 1011 | |
| 1012 | ret = wait_event_timeout(this_afe.wait[index], |
| 1013 | (atomic_read(&this_afe.state) == 0), |
| 1014 | msecs_to_jiffies(TIMEOUT_MS)); |
| 1015 | if (!ret) { |
| 1016 | pr_err("%s: wait_event timeout\n", __func__); |
| 1017 | ret = -EINVAL; |
| 1018 | return ret; |
| 1019 | } |
| 1020 | return 0; |
| 1021 | } |
| 1022 | |
| 1023 | int afe_cmd_memory_unmap_nowait(u32 mem_map_handle) |
| 1024 | { |
| 1025 | int ret = 0; |
| 1026 | struct afe_service_cmd_shared_mem_unmap_regions mregion; |
| 1027 | |
| 1028 | pr_debug("%s:\n", __func__); |
| 1029 | |
| 1030 | if (this_afe.apr == NULL) { |
| 1031 | this_afe.apr = apr_register("ADSP", "AFE", afe_callback, |
| 1032 | 0xFFFFFFFF, &this_afe); |
| 1033 | pr_debug("%s: Register AFE\n", __func__); |
| 1034 | if (this_afe.apr == NULL) { |
| 1035 | pr_err("%s: Unable to register AFE\n", __func__); |
| 1036 | ret = -ENODEV; |
| 1037 | return ret; |
| 1038 | } |
| 1039 | } |
| 1040 | |
| 1041 | mregion.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1042 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 1043 | mregion.hdr.pkt_size = sizeof(mregion); |
| 1044 | mregion.hdr.src_port = 0; |
| 1045 | mregion.hdr.dest_port = 0; |
| 1046 | mregion.hdr.token = 0; |
| 1047 | mregion.hdr.opcode = AFE_SERVICE_CMD_SHARED_MEM_UNMAP_REGIONS; |
| 1048 | mregion.mem_map_handle = mem_map_handle; |
| 1049 | |
| 1050 | ret = apr_send_pkt(this_afe.apr, (uint32_t *) &mregion); |
| 1051 | if (ret < 0) { |
| 1052 | pr_err("%s: AFE memory unmap cmd failed %d\n", |
| 1053 | __func__, ret); |
| 1054 | ret = -EINVAL; |
| 1055 | } |
| 1056 | return 0; |
| 1057 | } |
| 1058 | |
| 1059 | int afe_register_get_events(u16 port_id, |
| 1060 | void (*cb) (uint32_t opcode, |
| 1061 | uint32_t token, uint32_t *payload, void *priv), |
| 1062 | void *private_data) |
| 1063 | { |
| 1064 | int ret = 0; |
| 1065 | struct afe_service_cmd_register_rt_port_driver rtproxy; |
| 1066 | |
| 1067 | pr_debug("%s:\n", __func__); |
| 1068 | |
| 1069 | if (this_afe.apr == NULL) { |
| 1070 | this_afe.apr = apr_register("ADSP", "AFE", afe_callback, |
| 1071 | 0xFFFFFFFF, &this_afe); |
| 1072 | pr_debug("%s: Register AFE\n", __func__); |
| 1073 | if (this_afe.apr == NULL) { |
| 1074 | pr_err("%s: Unable to register AFE\n", __func__); |
| 1075 | ret = -ENODEV; |
| 1076 | return ret; |
| 1077 | } |
| 1078 | } |
| 1079 | if ((port_id == RT_PROXY_DAI_002_RX) || |
| 1080 | (port_id == RT_PROXY_DAI_001_TX)) |
| 1081 | port_id = VIRTUAL_ID_TO_PORTID(port_id); |
| 1082 | else |
| 1083 | return -EINVAL; |
| 1084 | |
| 1085 | if (port_id == RT_PROXY_PORT_001_TX) { |
| 1086 | this_afe.tx_cb = cb; |
| 1087 | this_afe.tx_private_data = private_data; |
| 1088 | } else if (port_id == RT_PROXY_PORT_001_RX) { |
| 1089 | this_afe.rx_cb = cb; |
| 1090 | this_afe.rx_private_data = private_data; |
| 1091 | } |
| 1092 | |
| 1093 | rtproxy.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1094 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 1095 | rtproxy.hdr.pkt_size = sizeof(rtproxy); |
| 1096 | rtproxy.hdr.src_port = 1; |
| 1097 | rtproxy.hdr.dest_port = 1; |
| 1098 | rtproxy.hdr.opcode = AFE_SERVICE_CMD_REGISTER_RT_PORT_DRIVER; |
| 1099 | rtproxy.port_id = port_id; |
| 1100 | rtproxy.reserved = 0; |
| 1101 | |
| 1102 | ret = apr_send_pkt(this_afe.apr, (uint32_t *) &rtproxy); |
| 1103 | if (ret < 0) { |
| 1104 | pr_err("%s: AFE reg. rtproxy_event failed %d\n", |
| 1105 | __func__, ret); |
| 1106 | ret = -EINVAL; |
| 1107 | return ret; |
| 1108 | } |
| 1109 | return 0; |
| 1110 | } |
| 1111 | |
| 1112 | int afe_unregister_get_events(u16 port_id) |
| 1113 | { |
| 1114 | int ret = 0; |
| 1115 | struct afe_service_cmd_unregister_rt_port_driver rtproxy; |
| 1116 | int index = 0; |
| 1117 | |
| 1118 | pr_debug("%s:\n", __func__); |
| 1119 | |
| 1120 | if (this_afe.apr == NULL) { |
| 1121 | this_afe.apr = apr_register("ADSP", "AFE", afe_callback, |
| 1122 | 0xFFFFFFFF, &this_afe); |
| 1123 | pr_debug("%s: Register AFE\n", __func__); |
| 1124 | if (this_afe.apr == NULL) { |
| 1125 | pr_err("%s: Unable to register AFE\n", __func__); |
| 1126 | ret = -ENODEV; |
| 1127 | return ret; |
| 1128 | } |
| 1129 | } |
| 1130 | index = q6audio_get_port_index(port_id); |
| 1131 | if (q6audio_validate_port(port_id) < 0) |
| 1132 | return -EINVAL; |
| 1133 | |
| 1134 | if ((port_id == RT_PROXY_DAI_002_RX) || |
| 1135 | (port_id == RT_PROXY_DAI_001_TX)) |
| 1136 | port_id = VIRTUAL_ID_TO_PORTID(port_id); |
| 1137 | else |
| 1138 | return -EINVAL; |
| 1139 | |
| 1140 | rtproxy.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1141 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 1142 | rtproxy.hdr.pkt_size = sizeof(rtproxy); |
| 1143 | rtproxy.hdr.src_port = 0; |
| 1144 | rtproxy.hdr.dest_port = 0; |
| 1145 | rtproxy.hdr.token = 0; |
| 1146 | rtproxy.hdr.opcode = AFE_SERVICE_CMD_UNREGISTER_RT_PORT_DRIVER; |
| 1147 | rtproxy.port_id = port_id; |
| 1148 | rtproxy.reserved = 0; |
| 1149 | |
| 1150 | rtproxy.hdr.token = index; |
| 1151 | |
| 1152 | if (port_id == RT_PROXY_PORT_001_TX) { |
| 1153 | this_afe.tx_cb = NULL; |
| 1154 | this_afe.tx_private_data = NULL; |
| 1155 | } else if (port_id == RT_PROXY_PORT_001_RX) { |
| 1156 | this_afe.rx_cb = NULL; |
| 1157 | this_afe.rx_private_data = NULL; |
| 1158 | } |
| 1159 | |
| 1160 | atomic_set(&this_afe.state, 1); |
| 1161 | ret = apr_send_pkt(this_afe.apr, (uint32_t *) &rtproxy); |
| 1162 | if (ret < 0) { |
| 1163 | pr_err("%s: AFE enable Unreg. rtproxy_event failed %d\n", |
| 1164 | __func__, ret); |
| 1165 | ret = -EINVAL; |
| 1166 | return ret; |
| 1167 | } |
| 1168 | |
| 1169 | ret = wait_event_timeout(this_afe.wait[index], |
| 1170 | (atomic_read(&this_afe.state) == 0), |
| 1171 | msecs_to_jiffies(TIMEOUT_MS)); |
| 1172 | if (!ret) { |
| 1173 | pr_err("%s: wait_event timeout\n", __func__); |
| 1174 | ret = -EINVAL; |
| 1175 | return ret; |
| 1176 | } |
| 1177 | return 0; |
| 1178 | } |
| 1179 | |
| 1180 | int afe_rt_proxy_port_write(u32 buf_addr_p, u32 mem_map_handle, int bytes) |
| 1181 | { |
| 1182 | int ret = 0; |
| 1183 | struct afe_port_data_cmd_rt_proxy_port_write_v2 afecmd_wr; |
| 1184 | |
| 1185 | if (this_afe.apr == NULL) { |
| 1186 | pr_err("%s:register to AFE is not done\n", __func__); |
| 1187 | ret = -ENODEV; |
| 1188 | return ret; |
| 1189 | } |
| 1190 | pr_debug("%s: buf_addr_p = 0x%08x bytes = %d\n", __func__, |
| 1191 | buf_addr_p, bytes); |
| 1192 | |
| 1193 | afecmd_wr.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1194 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 1195 | afecmd_wr.hdr.pkt_size = sizeof(afecmd_wr); |
| 1196 | afecmd_wr.hdr.src_port = 0; |
| 1197 | afecmd_wr.hdr.dest_port = 0; |
| 1198 | afecmd_wr.hdr.token = 0; |
| 1199 | afecmd_wr.hdr.opcode = AFE_PORT_DATA_CMD_RT_PROXY_PORT_WRITE_V2; |
| 1200 | afecmd_wr.port_id = RT_PROXY_PORT_001_TX; |
| 1201 | afecmd_wr.buffer_address_lsw = (uint32_t)buf_addr_p; |
| 1202 | afecmd_wr.buffer_address_msw = 0x00; |
| 1203 | afecmd_wr.mem_map_handle = mem_map_handle; |
| 1204 | afecmd_wr.available_bytes = bytes; |
| 1205 | afecmd_wr.reserved = 0; |
| 1206 | |
| 1207 | ret = apr_send_pkt(this_afe.apr, (uint32_t *) &afecmd_wr); |
| 1208 | if (ret < 0) { |
| 1209 | pr_err("%s: AFE rtproxy write to port 0x%x failed %d\n", |
| 1210 | __func__, afecmd_wr.port_id, ret); |
| 1211 | ret = -EINVAL; |
| 1212 | return ret; |
| 1213 | } |
| 1214 | return 0; |
| 1215 | |
| 1216 | } |
| 1217 | |
| 1218 | int afe_rt_proxy_port_read(u32 buf_addr_p, u32 mem_map_handle, int bytes) |
| 1219 | { |
| 1220 | int ret = 0; |
| 1221 | struct afe_port_data_cmd_rt_proxy_port_read_v2 afecmd_rd; |
| 1222 | |
| 1223 | if (this_afe.apr == NULL) { |
| 1224 | pr_err("%s: register to AFE is not done\n", __func__); |
| 1225 | ret = -ENODEV; |
| 1226 | return ret; |
| 1227 | } |
| 1228 | pr_debug("%s: buf_addr_p = 0x%08x bytes = %d\n", __func__, |
| 1229 | buf_addr_p, bytes); |
| 1230 | |
| 1231 | afecmd_rd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1232 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 1233 | afecmd_rd.hdr.pkt_size = sizeof(afecmd_rd); |
| 1234 | afecmd_rd.hdr.src_port = 0; |
| 1235 | afecmd_rd.hdr.dest_port = 0; |
| 1236 | afecmd_rd.hdr.token = 0; |
| 1237 | afecmd_rd.hdr.opcode = AFE_PORT_DATA_CMD_RT_PROXY_PORT_READ_V2; |
| 1238 | afecmd_rd.port_id = RT_PROXY_PORT_001_RX; |
| 1239 | afecmd_rd.buffer_address_lsw = (uint32_t)buf_addr_p; |
| 1240 | afecmd_rd.buffer_address_msw = 0x00; |
| 1241 | afecmd_rd.available_bytes = bytes; |
| 1242 | |
| 1243 | ret = apr_send_pkt(this_afe.apr, (uint32_t *) &afecmd_rd); |
| 1244 | if (ret < 0) { |
| 1245 | pr_err("%s: AFE rtproxy read cmd to port 0x%x failed %d\n", |
| 1246 | __func__, afecmd_rd.port_id, ret); |
| 1247 | ret = -EINVAL; |
| 1248 | return ret; |
| 1249 | } |
| 1250 | return 0; |
| 1251 | } |
| 1252 | |
| 1253 | #ifdef CONFIG_DEBUG_FS |
| 1254 | static struct dentry *debugfs_afelb; |
| 1255 | static struct dentry *debugfs_afelb_gain; |
| 1256 | |
| 1257 | static int afe_debug_open(struct inode *inode, struct file *file) |
| 1258 | { |
| 1259 | file->private_data = inode->i_private; |
| 1260 | pr_info("debug intf %s\n", (char *) file->private_data); |
| 1261 | return 0; |
| 1262 | } |
| 1263 | |
| 1264 | static int afe_get_parameters(char *buf, long int *param1, int num_of_par) |
| 1265 | { |
| 1266 | char *token; |
| 1267 | int base, cnt; |
| 1268 | |
| 1269 | token = strsep(&buf, " "); |
| 1270 | |
| 1271 | for (cnt = 0; cnt < num_of_par; cnt++) { |
| 1272 | if (token != NULL) { |
| 1273 | if ((token[1] == 'x') || (token[1] == 'X')) |
| 1274 | base = 16; |
| 1275 | else |
| 1276 | base = 10; |
| 1277 | |
| 1278 | if (strict_strtoul(token, base, ¶m1[cnt]) != 0) |
| 1279 | return -EINVAL; |
| 1280 | |
| 1281 | token = strsep(&buf, " "); |
| 1282 | } else |
| 1283 | return -EINVAL; |
| 1284 | } |
| 1285 | return 0; |
| 1286 | } |
| 1287 | #define AFE_LOOPBACK_ON (1) |
| 1288 | #define AFE_LOOPBACK_OFF (0) |
| 1289 | static ssize_t afe_debug_write(struct file *filp, |
| 1290 | const char __user *ubuf, size_t cnt, loff_t *ppos) |
| 1291 | { |
| 1292 | char *lb_str = filp->private_data; |
| 1293 | char lbuf[32]; |
| 1294 | int rc; |
| 1295 | unsigned long param[5]; |
| 1296 | |
| 1297 | if (cnt > sizeof(lbuf) - 1) |
| 1298 | return -EINVAL; |
| 1299 | |
| 1300 | rc = copy_from_user(lbuf, ubuf, cnt); |
| 1301 | if (rc) |
| 1302 | return -EFAULT; |
| 1303 | |
| 1304 | lbuf[cnt] = '\0'; |
| 1305 | |
| 1306 | if (!strncmp(lb_str, "afe_loopback", 12)) { |
| 1307 | rc = afe_get_parameters(lbuf, param, 3); |
| 1308 | if (!rc) { |
| 1309 | pr_info("%s %lu %lu %lu\n", lb_str, param[0], param[1], |
| 1310 | param[2]); |
| 1311 | |
| 1312 | if ((param[0] != AFE_LOOPBACK_ON) && (param[0] != |
| 1313 | AFE_LOOPBACK_OFF)) { |
| 1314 | pr_err("%s: Error, parameter 0 incorrect\n", |
| 1315 | __func__); |
| 1316 | rc = -EINVAL; |
| 1317 | goto afe_error; |
| 1318 | } |
| 1319 | if ((q6audio_validate_port(param[1]) < 0) || |
| 1320 | (q6audio_validate_port(param[2])) < 0) { |
| 1321 | pr_err("%s: Error, invalid afe port\n", |
| 1322 | __func__); |
| 1323 | } |
| 1324 | if (this_afe.apr == NULL) { |
| 1325 | pr_err("%s: Error, AFE not opened\n", __func__); |
| 1326 | rc = -EINVAL; |
| 1327 | } else { |
| 1328 | rc = afe_loopback(param[0], param[1], param[2]); |
| 1329 | } |
| 1330 | } else { |
| 1331 | pr_err("%s: Error, invalid parameters\n", __func__); |
| 1332 | rc = -EINVAL; |
| 1333 | } |
| 1334 | |
| 1335 | } else if (!strncmp(lb_str, "afe_loopback_gain", 17)) { |
| 1336 | rc = afe_get_parameters(lbuf, param, 2); |
| 1337 | if (!rc) { |
| 1338 | pr_info("%s %lu %lu\n", lb_str, param[0], param[1]); |
| 1339 | |
| 1340 | if (q6audio_validate_port(param[0]) < 0) { |
| 1341 | pr_err("%s: Error, invalid afe port\n", |
| 1342 | __func__); |
| 1343 | rc = -EINVAL; |
| 1344 | goto afe_error; |
| 1345 | } |
| 1346 | |
| 1347 | if (param[1] < 0 || param[1] > 100) { |
| 1348 | pr_err("%s: Error, volume shoud be 0 to 100" |
| 1349 | " percentage param = %lu\n", |
| 1350 | __func__, param[1]); |
| 1351 | rc = -EINVAL; |
| 1352 | goto afe_error; |
| 1353 | } |
| 1354 | |
| 1355 | param[1] = (Q6AFE_MAX_VOLUME * param[1]) / 100; |
| 1356 | |
| 1357 | if (this_afe.apr == NULL) { |
| 1358 | pr_err("%s: Error, AFE not opened\n", __func__); |
| 1359 | rc = -EINVAL; |
| 1360 | } else { |
| 1361 | rc = afe_loopback_gain(param[0], param[1]); |
| 1362 | } |
| 1363 | } else { |
| 1364 | pr_err("%s: Error, invalid parameters\n", __func__); |
| 1365 | rc = -EINVAL; |
| 1366 | } |
| 1367 | } |
| 1368 | |
| 1369 | afe_error: |
| 1370 | if (rc == 0) |
| 1371 | rc = cnt; |
| 1372 | else |
| 1373 | pr_err("%s: rc = %d\n", __func__, rc); |
| 1374 | |
| 1375 | return rc; |
| 1376 | } |
| 1377 | |
| 1378 | static const struct file_operations afe_debug_fops = { |
| 1379 | .open = afe_debug_open, |
| 1380 | .write = afe_debug_write |
| 1381 | }; |
| 1382 | |
| 1383 | static void config_debug_fs_init(void) |
| 1384 | { |
| 1385 | debugfs_afelb = debugfs_create_file("afe_loopback", |
| 1386 | S_IFREG | S_IWUGO, NULL, (void *) "afe_loopback", |
| 1387 | &afe_debug_fops); |
| 1388 | |
| 1389 | debugfs_afelb_gain = debugfs_create_file("afe_loopback_gain", |
| 1390 | S_IFREG | S_IWUGO, NULL, (void *) "afe_loopback_gain", |
| 1391 | &afe_debug_fops); |
| 1392 | } |
| 1393 | static void config_debug_fs_exit(void) |
| 1394 | { |
| 1395 | if (debugfs_afelb) |
| 1396 | debugfs_remove(debugfs_afelb); |
| 1397 | if (debugfs_afelb_gain) |
| 1398 | debugfs_remove(debugfs_afelb_gain); |
| 1399 | } |
| 1400 | #else |
| 1401 | static void config_debug_fs_init(void) |
| 1402 | { |
| 1403 | return; |
| 1404 | } |
| 1405 | static void config_debug_fs_exit(void) |
| 1406 | { |
| 1407 | return; |
| 1408 | } |
| 1409 | #endif |
| 1410 | int afe_sidetone(u16 tx_port_id, u16 rx_port_id, u16 enable, uint16_t gain) |
| 1411 | { |
| 1412 | struct afe_loopback_cfg_v1 cmd_sidetone; |
| 1413 | int ret = 0; |
| 1414 | int index = 0; |
| 1415 | |
| 1416 | pr_info("%s: tx_port_id:%d rx_port_id:%d enable:%d gain:%d\n", __func__, |
| 1417 | tx_port_id, rx_port_id, enable, gain); |
| 1418 | index = q6audio_get_port_index(rx_port_id); |
| 1419 | if (q6audio_validate_port(rx_port_id) < 0) |
| 1420 | return -EINVAL; |
| 1421 | |
| 1422 | cmd_sidetone.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1423 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 1424 | cmd_sidetone.hdr.pkt_size = sizeof(cmd_sidetone); |
| 1425 | cmd_sidetone.hdr.src_port = 0; |
| 1426 | cmd_sidetone.hdr.dest_port = 0; |
| 1427 | cmd_sidetone.hdr.token = 0; |
| 1428 | cmd_sidetone.hdr.opcode = AFE_PORT_CMD_SET_PARAM_V2; |
| 1429 | /* should it be rx or tx port id ?? , bharath*/ |
| 1430 | cmd_sidetone.param.port_id = tx_port_id; |
| 1431 | /* size of data param & payload */ |
| 1432 | cmd_sidetone.param.payload_size = (sizeof(cmd_sidetone) - |
| 1433 | sizeof(struct apr_hdr) - |
| 1434 | sizeof(struct afe_port_cmd_set_param_v2)); |
| 1435 | cmd_sidetone.param.payload_address_lsw = 0x00; |
| 1436 | cmd_sidetone.param.payload_address_msw = 0x00; |
| 1437 | cmd_sidetone.param.mem_map_handle = 0x00; |
| 1438 | cmd_sidetone.pdata.module_id = AFE_MODULE_LOOPBACK; |
| 1439 | cmd_sidetone.pdata.param_id = AFE_PARAM_ID_LOOPBACK_CONFIG; |
| 1440 | /* size of actual payload only */ |
| 1441 | cmd_sidetone.pdata.param_size = cmd_sidetone.param.payload_size - |
| 1442 | sizeof(struct afe_port_param_data_v2); |
| 1443 | |
| 1444 | cmd_sidetone.loopback_cfg_minor_version = |
| 1445 | AFE_API_VERSION_LOOPBACK_CONFIG; |
| 1446 | cmd_sidetone.dst_port_id = rx_port_id; |
| 1447 | cmd_sidetone.routing_mode = LB_MODE_SIDETONE; |
| 1448 | cmd_sidetone.enable = enable; |
| 1449 | |
| 1450 | atomic_set(&this_afe.state, 1); |
| 1451 | ret = apr_send_pkt(this_afe.apr, (uint32_t *) &cmd_sidetone); |
| 1452 | if (ret < 0) { |
| 1453 | pr_err("%s: AFE sidetone failed for tx_port:%d rx_port:%d\n", |
| 1454 | __func__, tx_port_id, rx_port_id); |
| 1455 | ret = -EINVAL; |
| 1456 | goto fail_cmd; |
| 1457 | } |
| 1458 | |
| 1459 | ret = wait_event_timeout(this_afe.wait[index], |
| 1460 | (atomic_read(&this_afe.state) == 0), |
| 1461 | msecs_to_jiffies(TIMEOUT_MS)); |
| 1462 | if (ret < 0) { |
| 1463 | pr_err("%s: wait_event timeout\n", __func__); |
| 1464 | ret = -EINVAL; |
| 1465 | goto fail_cmd; |
| 1466 | } |
| 1467 | return 0; |
| 1468 | fail_cmd: |
| 1469 | return ret; |
| 1470 | } |
| 1471 | |
| 1472 | int afe_port_stop_nowait(int port_id) |
| 1473 | { |
| 1474 | struct afe_port_cmd_device_stop stop; |
| 1475 | int ret = 0; |
| 1476 | |
| 1477 | if (this_afe.apr == NULL) { |
| 1478 | pr_err("AFE is already closed\n"); |
| 1479 | ret = -EINVAL; |
| 1480 | goto fail_cmd; |
| 1481 | } |
| 1482 | pr_debug("%s: port_id=%d\n", __func__, port_id); |
| 1483 | port_id = q6audio_convert_virtual_to_portid(port_id); |
| 1484 | |
| 1485 | stop.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1486 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 1487 | stop.hdr.pkt_size = sizeof(stop); |
| 1488 | stop.hdr.src_port = 0; |
| 1489 | stop.hdr.dest_port = 0; |
| 1490 | stop.hdr.token = 0; |
| 1491 | stop.hdr.opcode = AFE_PORT_CMD_DEVICE_STOP; |
| 1492 | stop.port_id = port_id; |
| 1493 | stop.reserved = 0; |
| 1494 | |
| 1495 | ret = apr_send_pkt(this_afe.apr, (uint32_t *) &stop); |
| 1496 | |
| 1497 | if (IS_ERR_VALUE(ret)) { |
| 1498 | pr_err("%s: AFE close failed\n", __func__); |
| 1499 | ret = -EINVAL; |
| 1500 | } |
| 1501 | |
| 1502 | fail_cmd: |
| 1503 | return ret; |
| 1504 | |
| 1505 | } |
| 1506 | |
| 1507 | int afe_close(int port_id) |
| 1508 | { |
| 1509 | struct afe_port_cmd_device_stop stop; |
| 1510 | int ret = 0; |
| 1511 | int index = 0; |
| 1512 | |
| 1513 | |
| 1514 | if (this_afe.apr == NULL) { |
| 1515 | pr_err("AFE is already closed\n"); |
| 1516 | ret = -EINVAL; |
| 1517 | goto fail_cmd; |
| 1518 | } |
| 1519 | pr_debug("%s: port_id=%d\n", __func__, port_id); |
| 1520 | |
| 1521 | index = q6audio_get_port_index(port_id); |
| 1522 | if (q6audio_validate_port(port_id) < 0) |
| 1523 | return -EINVAL; |
| 1524 | |
| 1525 | port_id = q6audio_convert_virtual_to_portid(port_id); |
| 1526 | |
| 1527 | stop.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1528 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 1529 | stop.hdr.pkt_size = sizeof(stop); |
| 1530 | stop.hdr.src_port = 0; |
| 1531 | stop.hdr.dest_port = 0; |
| 1532 | stop.hdr.token = index; |
| 1533 | stop.hdr.opcode = AFE_PORT_CMD_DEVICE_STOP; |
| 1534 | stop.port_id = q6audio_get_port_id(port_id); |
| 1535 | stop.reserved = 0; |
| 1536 | |
| 1537 | atomic_set(&this_afe.state, 1); |
| 1538 | ret = apr_send_pkt(this_afe.apr, (uint32_t *) &stop); |
| 1539 | |
| 1540 | if (ret < 0) { |
| 1541 | pr_err("%s: AFE close failed\n", __func__); |
| 1542 | ret = -EINVAL; |
| 1543 | goto fail_cmd; |
| 1544 | } |
| 1545 | |
| 1546 | ret = wait_event_timeout(this_afe.wait[index], |
| 1547 | (atomic_read(&this_afe.state) == 0), |
| 1548 | msecs_to_jiffies(TIMEOUT_MS)); |
| 1549 | if (!ret) { |
| 1550 | pr_err("%s: wait_event timeout\n", __func__); |
| 1551 | ret = -EINVAL; |
| 1552 | goto fail_cmd; |
| 1553 | } |
| 1554 | fail_cmd: |
| 1555 | return ret; |
| 1556 | } |
| 1557 | |
| 1558 | static int __init afe_init(void) |
| 1559 | { |
| 1560 | int i = 0; |
| 1561 | atomic_set(&this_afe.state, 0); |
| 1562 | atomic_set(&this_afe.status, 0); |
| 1563 | this_afe.apr = NULL; |
| 1564 | for (i = 0; i < AFE_MAX_PORTS; i++) |
| 1565 | init_waitqueue_head(&this_afe.wait[i]); |
| 1566 | |
| 1567 | config_debug_fs_init(); |
| 1568 | return 0; |
| 1569 | } |
| 1570 | |
| 1571 | static void __exit afe_exit(void) |
| 1572 | { |
| 1573 | int i; |
| 1574 | |
| 1575 | config_debug_fs_exit(); |
| 1576 | for (i = 0; i < MAX_AUDPROC_TYPES; i++) { |
| 1577 | if (afe_cal_addr[i].cal_paddr != 0) |
| 1578 | afe_cmd_memory_unmap_nowait( |
| 1579 | afe_cal_addr[i].cal_paddr); |
| 1580 | } |
| 1581 | } |
| 1582 | |
| 1583 | device_initcall(afe_init); |
| 1584 | __exitcall(afe_exit); |