void q6asm_audio_client_free(struct audio_client *ac) { int loopcnt; struct audio_port_data *port; if (!ac || !ac->session) return; pr_debug("\n"); for (loopcnt = 0; loopcnt <= OUT; loopcnt++) { port = &ac->port[loopcnt]; if (!port->buf) continue; pr_debug("loopcnt = %d\n", loopcnt); q6asm_audio_client_buf_free(loopcnt, ac); } q6asm_session_free(ac); apr_deregister(ac->apr); pr_debug("APR De-Register\n"); if (atomic_read(&this_mmap.ref_cnt) <= 0) { pr_err("APR Common Port Already Closed\n"); goto done; } atomic_dec(&this_mmap.ref_cnt); if (atomic_read(&this_mmap.ref_cnt) == 0) { apr_deregister(this_mmap.apr); pr_debug("APR De-Register common port\n"); } done: kfree(ac); return; }
void q6usm_us_client_free(struct us_client *usc) { int loopcnt = 0; struct us_port_data *port; uint32_t *p_mem_handle = NULL; if (usc == NULL) return; if (!(usc->session)) { kfree(usc); return; } for (loopcnt = 0; loopcnt <= OUT; ++loopcnt) { port = &usc->port[loopcnt]; if (port->data == NULL) continue; pr_debug("%s: loopcnt = %d\n", __func__, loopcnt); q6usm_us_client_buf_free(loopcnt, usc); q6usm_us_param_buf_free(loopcnt, usc); } q6usm_session_free(usc); apr_deregister(usc->apr); pr_debug("%s: APR De-Register\n", __func__); if (atomic_read(&this_mmap.ref_cnt) <= 0) { pr_err("%s: APR Common Port Already Closed\n", __func__); goto done; } atomic_dec(&this_mmap.ref_cnt); if (atomic_read(&this_mmap.ref_cnt) == 0) { apr_deregister(this_mmap.apr); pr_debug("%s: APR De-Register common port\n", __func__); } done: p_mem_handle = (uint32_t *)usc->port[IN].ext; kfree(p_mem_handle); kfree(usc); pr_debug("%s:\n", __func__); return; }
static int q6lsm_mmap_apr_dereg(void) { if (atomic_read(&lsm_common.apr_users) <= 0) { WARN("%s: APR common port already closed\n", __func__); } else { if (atomic_dec_return(&lsm_common.apr_users) == 0) { apr_deregister(lsm_common.apr); pr_debug("%s:APR De-Register common port\n", __func__); } } return 0; }
int afe_close(int port_id) { struct afe_port_stop_command stop; int ret = 0; if (this_afe.apr == NULL) { pr_err("AFE is already closed\n"); ret = -EINVAL; goto fail_cmd; } pr_info("%s: port_id=%d\n", __func__, port_id); port_id = afe_convert_virtual_to_portid(port_id); stop.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); stop.hdr.pkt_size = sizeof(stop); stop.hdr.src_port = 0; stop.hdr.dest_port = 0; stop.hdr.token = 0; stop.hdr.opcode = AFE_PORT_CMD_STOP; stop.port_id = port_id; stop.reserved = 0; atomic_set(&this_afe.state, 1); ret = apr_send_pkt(this_afe.apr, (uint32_t *) &stop); if (ret == -ENETRESET) { pr_info("%s: Need to reset, calling APR deregister", __func__); return apr_deregister(this_afe.apr); } if (ret < 0) { pr_err("%s: AFE close failed\n", __func__); ret = -EINVAL; goto fail_cmd; } ret = wait_event_timeout(this_afe.wait, (atomic_read(&this_afe.state) == 0), msecs_to_jiffies(TIMEOUT_MS)); if (!ret) { pr_err("%s: wait_event timeout\n", __func__); BUG(); ret = -EINVAL; goto fail_cmd; } fail_cmd: return ret; }
void q6lsm_client_free(struct lsm_client *client) { if (!client) return; if (CHECK_SESSION(client->session)) { pr_err("%s: Invalid Session %d\n", __func__, client->session); return; } apr_deregister(client->apr); client->mmap_apr = NULL; q6lsm_session_free(client); q6lsm_mmap_apr_dereg(); mutex_destroy(&client->cmd_lock); kfree(client); }
int afe_close(int port_id) { struct afe_port_stop_command stop; int rc = 0; mutex_lock(&afe_lock); if (this_afe.ref_cnt == 0) { pr_err("%s: AFE is already closed\n", __func__); rc = -EINVAL; goto fail_cmd; } stop.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); stop.hdr.pkt_size = sizeof(stop); stop.hdr.src_port = 0; stop.hdr.dest_port = 0; stop.hdr.token = 0; stop.hdr.opcode = AFE_PORT_CMD_STOP; stop.port_id = port_id; this_afe.state = 1; rc = apr_send_pkt(this_afe.apr, (uint32_t *) &stop); if (rc < 0) { pr_err("%s: AFE close failed\n", __func__); goto fail_cmd; } rc = wait_event_timeout(this_afe.wait, (this_afe.state == 0), msecs_to_jiffies(TIMEOUT_MS)); if (rc < 0) { pr_err("%s: wait_event timeout\n", __func__); goto fail_cmd; } this_afe.ref_cnt--; if (this_afe.ref_cnt == 0) { pr_info("%s: Deregister AFE\n", __func__); apr_deregister(this_afe.apr); } fail_cmd: mutex_unlock(&afe_lock); return rc; }
int afe_port_stop_nowait(int port_id) { struct afe_port_stop_command stop; int ret = 0; if (this_afe.apr == NULL) { pr_err("AFE is already closed\n"); ret = -EINVAL; goto fail_cmd; } pr_debug("%s: port_id=%d\n", __func__, port_id); port_id = afe_convert_virtual_to_portid(port_id); stop.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); stop.hdr.pkt_size = sizeof(stop); stop.hdr.src_port = 0; stop.hdr.dest_port = 0; stop.hdr.token = 0; stop.hdr.opcode = AFE_PORT_CMD_STOP; stop.port_id = port_id; stop.reserved = 0; ret = apr_send_pkt(this_afe.apr, (uint32_t *) &stop); if (ret == -ENETRESET) { pr_info("%s: Need to reset, calling APR deregister", __func__); return apr_deregister(this_afe.apr); } else if (IS_ERR_VALUE(ret)) { pr_err("%s: AFE close failed\n", __func__); ret = -EINVAL; } fail_cmd: return ret; }
int afe_close(int port_id) { struct afe_port_stop_command stop; int ret = 0; if (this_afe.apr == NULL) { pr_err("AFE is already closed\n"); ret = -EINVAL; goto fail_cmd; } pr_debug("%s: port_id=%d\n", __func__, port_id); if ((port_id == RT_PROXY_DAI_001_RX) || (port_id == RT_PROXY_DAI_002_TX)) { pr_debug("%s: before decrementing pcm_afe_instance %d\n", __func__, pcm_afe_instance[port_id & 0x1]); port_id = VIRTUAL_ID_TO_PORTID(port_id); pcm_afe_instance[port_id & 0x1]--; if (!(pcm_afe_instance[port_id & 0x1] == 0 && proxy_afe_instance[port_id & 0x1] == 0)) return 0; else afe_close_done[port_id & 0x1] = true; } if ((port_id == RT_PROXY_DAI_002_RX) || (port_id == RT_PROXY_DAI_001_TX)) { pr_debug("%s: before decrementing proxy_afe_instance %d\n", __func__, proxy_afe_instance[port_id & 0x1]); port_id = VIRTUAL_ID_TO_PORTID(port_id); proxy_afe_instance[port_id & 0x1]--; if (!(pcm_afe_instance[port_id & 0x1] == 0 && proxy_afe_instance[port_id & 0x1] == 0)) return 0; else afe_close_done[port_id & 0x1] = true; } port_id = afe_convert_virtual_to_portid(port_id); stop.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); stop.hdr.pkt_size = sizeof(stop); stop.hdr.src_port = 0; stop.hdr.dest_port = 0; stop.hdr.token = 0; stop.hdr.opcode = AFE_PORT_CMD_STOP; stop.port_id = port_id; stop.reserved = 0; atomic_set(&this_afe.state, 1); ret = apr_send_pkt(this_afe.apr, (uint32_t *) &stop); if (ret == -ENETRESET) { pr_info("%s: Need to reset, calling APR deregister", __func__); return apr_deregister(this_afe.apr); } if (ret < 0) { pr_err("%s: AFE close failed\n", __func__); ret = -EINVAL; goto fail_cmd; } ret = wait_event_timeout(this_afe.wait, (atomic_read(&this_afe.state) == 0), msecs_to_jiffies(TIMEOUT_MS)); if (!ret) { pr_err("%s: wait_event timeout\n", __func__); ret = -EINVAL; goto fail_cmd; } fail_cmd: return ret; }
int afe_open_pcmif(struct afe_port_pcm_cfg cfg) { struct afe_port_start_command start; struct afe_audioif_config_command config; int ret; mutex_lock(&afe_lock); if (this_afe.ref_cnt == 0) { this_afe.apr = apr_register("ADSP", "AFE", afe_callback, 0xFFFFFFFF, &this_afe); pr_info("%s: Register AFE\n", __func__); if (this_afe.apr == NULL) { pr_err("%s: Unable to register AFE\n", __func__); ret = -ENODEV; goto fail; } } config.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); config.hdr.pkt_size = sizeof(config); config.hdr.src_port = 0; config.hdr.dest_port = 0; config.hdr.token = 0; config.hdr.opcode = AFE_PORT_AUDIO_IF_CONFIG; config.port.pcm = cfg; this_afe.state = 1; ret = apr_send_pkt(this_afe.apr, (uint32_t *) &config); if (ret < 0) { pr_err("%s: AFE enable for port %d failed\n", __func__, cfg.port_id); ret = -EINVAL; goto fail; } ret = wait_event_timeout(this_afe.wait, (this_afe.state == 0), msecs_to_jiffies(TIMEOUT_MS)); if (ret < 0) { pr_err("%s: wait_event timeout\n", __func__); goto fail_cmd; } start.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); start.hdr.pkt_size = sizeof(start); start.hdr.src_port = 0; start.hdr.dest_port = 0; start.hdr.token = 0; start.hdr.opcode = AFE_PORT_CMD_START; start.port_id = cfg.port_id; start.gain = 0x4000; start.sample_rate = 8000; this_afe.state = 1; ret = apr_send_pkt(this_afe.apr, (uint32_t *) &start); if (ret < 0) { pr_err("%s: AFE enable for port %d failed\n", __func__, cfg.port_id); ret = -EINVAL; goto fail_cmd; } ret = wait_event_timeout(this_afe.wait, (this_afe.state == 0), msecs_to_jiffies(TIMEOUT_MS)); if (ret < 0) { pr_err("%s: wait_event timeout\n", __func__); ret = -EINVAL; goto fail_cmd; } this_afe.ref_cnt++; mutex_unlock(&afe_lock); return ret; fail_cmd: if (this_afe.ref_cnt == 0) apr_deregister(this_afe.apr); fail: mutex_unlock(&afe_lock); return ret; }
int afe_open(int port_id, int rate, int channel_mode) { struct afe_port_start_command start; struct afe_audioif_config_command config; int ret; pr_info("%s: %d %d %d\n", __func__, port_id, rate, channel_mode); mutex_lock(&afe_lock); if (this_afe.ref_cnt == 0) { this_afe.apr = apr_register("ADSP", "AFE", afe_callback, 0xFFFFFFFF, &this_afe); pr_info("%s: Register AFE\n", __func__); if (this_afe.apr == NULL) { pr_err("%s: Unable to register AFE\n", __func__); ret = -ENODEV; goto fail; } } config.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); config.hdr.pkt_size = sizeof(config); config.hdr.src_port = 0; config.hdr.dest_port = 0; config.hdr.token = 0; config.hdr.opcode = AFE_PORT_AUDIO_IF_CONFIG; if ((port_id == PRIMARY_I2S_RX) || (port_id == PRIMARY_I2S_TX)) { pr_info("%s: I2S %d %d %d\n", __func__, port_id, rate, channel_mode); config.port.mi2s.port_id = port_id; config.port.mi2s.bitwidth = 16; config.port.mi2s.line = 1; config.port.mi2s.channel = channel_mode; config.port.mi2s.ws = 1; } else if (port_id == HDMI_RX) { pr_info("%s: HDMI %d %d %d\n", __func__, port_id, rate, channel_mode); config.port.hdmi.port_id = port_id; config.port.hdmi.bitwidth = 16; config.port.hdmi.channel_mode = channel_mode; config.port.hdmi.data_type = 0; } else { pr_err("%s: Failed : Invalid Port id = %d\n", __func__, port_id); ret = -EINVAL; goto fail_cmd; } this_afe.state = 1; ret = apr_send_pkt(this_afe.apr, (uint32_t *) &config); if (ret < 0) { pr_err("%s: AFE enable for port %d failed\n", __func__, port_id); ret = -EINVAL; goto fail_cmd; } ret = wait_event_timeout(this_afe.wait, (this_afe.state == 0), msecs_to_jiffies(TIMEOUT_MS)); if (ret < 0) { pr_err("%s: wait_event timeout\n", __func__); ret = -EINVAL; goto fail_cmd; } start.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); start.hdr.pkt_size = sizeof(start); start.hdr.src_port = 0; start.hdr.dest_port = 0; start.hdr.token = 0; start.hdr.opcode = AFE_PORT_CMD_START; start.port_id = port_id; start.gain = 0x4000; start.sample_rate = rate; this_afe.state = 1; ret = apr_send_pkt(this_afe.apr, (uint32_t *) &start); if (ret < 0) { pr_err("%s: AFE enable for port %d failed\n", __func__, port_id); ret = -EINVAL; goto fail_cmd; } ret = wait_event_timeout(this_afe.wait, (this_afe.state == 0), msecs_to_jiffies(TIMEOUT_MS)); if (ret < 0) { pr_err("%s: wait_event timeout\n", __func__); ret = -EINVAL; goto fail_cmd; } this_afe.ref_cnt++; mutex_unlock(&afe_lock); return ret; fail_cmd: if (this_afe.ref_cnt == 0) apr_deregister(this_afe.apr); fail: mutex_unlock(&afe_lock); return ret; }