int q6lsm_deregister_sound_model(struct lsm_client *client) { int rc; struct lsm_cmd_reg_snd_model cmd; if (!client || !client->apr) { pr_err("APR handle NULL\n"); return -EINVAL; } pr_debug("%s: session[%d]", __func__, client->session); if (CHECK_SESSION(client->session)) return -EINVAL; memset(&cmd, 0, sizeof(cmd)); q6lsm_add_hdr(client, &cmd.hdr, sizeof(cmd.hdr), false); cmd.hdr.opcode = LSM_SESSION_CMD_DEREGISTER_SOUND_MODEL; rc = q6lsm_apr_send_pkt(client, client->apr, &cmd.hdr, true, NULL); if (rc < 0) { pr_err("%s: Failed cmd opcode 0x%x, rc %d\n", __func__, cmd.hdr.opcode, rc); } else { pr_debug("%s: Deregister sound model succeeded\n", __func__); } q6lsm_snd_model_buf_free(client); return rc; }
static int q6lsm_send_cal(struct lsm_client *client) { int rc; struct lsm_cmd_set_params params; struct acdb_cal_block lsm_cal; pr_debug("%s: Session %d\n", __func__, client->session); if (CHECK_SESSION(client->session)) return -EINVAL; memset(&lsm_cal, 0, sizeof(lsm_cal)); get_lsm_cal(&lsm_cal); lsm_common.common_client[client->session].session = client->session; q6lsm_add_hdr(client, ¶ms.hdr, sizeof(params), true); params.hdr.opcode = LSM_SESSION_CMD_SET_PARAMS; params.data_payload_addr_lsw = lower_32_bits(client->lsm_cal_phy_addr); params.data_payload_addr_msw = upper_32_bits(client->lsm_cal_phy_addr); params.mem_map_handle = client->sound_model.mem_map_handle; params.data_payload_size = lsm_cal.cal_size; pr_debug("%s: Cal Size = %x", __func__, client->lsm_cal_size); rc = q6lsm_apr_send_pkt(client, client->apr, ¶ms, true, NULL); if (rc) pr_err("%s: Failed set_params opcode 0x%x, rc %d\n", __func__, params.hdr.opcode, rc); return rc; }
int q6lsm_open(struct lsm_client *client, uint16_t app_id) { int rc = 0; struct lsm_stream_cmd_open_tx open; memset(&open, 0, sizeof(open)); q6lsm_add_hdr(client, &open.hdr, sizeof(open), true); switch (client->app_id) { case LSM_VOICE_WAKEUP_APP_ID: case LSM_VOICE_WAKEUP_APP_ID_V2: open.app_id = client->app_id; break; default: rc = -EINVAL; break; } if (!rc) { open.sampling_rate = LSM_SAMPLE_RATE; open.hdr.opcode = LSM_SESSION_CMD_OPEN_TX; rc = q6lsm_apr_send_pkt(client, client->apr, &open, true, NULL); if (rc) pr_err("%s: Open failed opcode 0x%x, rc %d\n", __func__, open.hdr.opcode, rc); } pr_debug("%s: leave %d\n", __func__, rc); return rc; }
int q6lsm_register_sound_model(struct lsm_client *client, enum lsm_detection_mode mode, bool detectfailure) { int rc; struct lsm_cmd_reg_snd_model cmd; memset(&cmd, 0, sizeof(cmd)); rc = q6lsm_set_data(client, mode, detectfailure); if (rc) { pr_err("%s: Failed to set lsm data, err = %d\n", __func__, rc); return rc; } q6lsm_add_hdr(client, &cmd.hdr, sizeof(cmd), true); cmd.hdr.opcode = LSM_SESSION_CMD_REGISTER_SOUND_MODEL; cmd.model_addr_lsw = lower_32_bits(client->sound_model.phys); cmd.model_addr_msw = upper_32_bits(client->sound_model.phys); cmd.model_size = client->sound_model.size; /* read updated mem_map_handle by q6lsm_mmapcallback */ rmb(); cmd.mem_map_handle = client->sound_model.mem_map_handle; pr_debug("%s: addr %pa, size %d, handle 0x%x\n", __func__, &client->sound_model.phys, cmd.model_size, cmd.mem_map_handle); rc = q6lsm_apr_send_pkt(client, client->apr, &cmd, true, NULL); if (rc) pr_err("%s: Failed cmd op[0x%x]rc[%d]\n", __func__, cmd.hdr.opcode, rc); else pr_debug("%s: Register sound model succeeded\n", __func__); return rc; }
static int q6lsm_memory_unmap_regions(struct lsm_client *client, uint32_t handle) { struct avs_cmd_shared_mem_unmap_regions unmap; int rc = 0; int cmd_size = 0; if (CHECK_SESSION(client->session)) { pr_err("%s: session[%d]", __func__, client->session); return -EINVAL; } cmd_size = sizeof(struct avs_cmd_shared_mem_unmap_regions); q6lsm_add_mmaphdr(client, &unmap.hdr, cmd_size, true, (client->session << 8)); unmap.hdr.opcode = LSM_SESSION_CMD_SHARED_MEM_UNMAP_REGIONS; unmap.mem_map_handle = handle; pr_debug("%s: unmap handle 0x%x\n", __func__, unmap.mem_map_handle); rc = q6lsm_apr_send_pkt(client, client->mmap_apr, &unmap, true, NULL); if (rc) pr_err("%s: Failed mmap_regions opcode 0x%x rc %d\n", __func__, unmap.hdr.opcode, rc); return rc; }
static int q6lsm_set_params(struct lsm_client *client) { int rc; struct lsm_cmd_set_params params; struct lsm_params_payload *payload = ¶ms.payload; pr_debug("%s: enter\n", __func__); q6lsm_add_hdr(client, ¶ms.hdr, sizeof(params), true); params.hdr.opcode = LSM_SESSION_CMD_SET_PARAMS; params.data_payload_addr_lsw = 0; params.data_payload_addr_msw = 0; params.mem_map_handle = 0; params.data_payload_size = sizeof(struct lsm_params_payload); payload->op_mode.common.module_id = LSM_MODULE_ID_VOICE_WAKEUP; payload->op_mode.common.param_id = LSM_PARAM_ID_OPERATION_MODE; payload->op_mode.common.param_size = sizeof(struct lsm_param_op_mode) - sizeof(payload->op_mode.common); payload->op_mode.common.reserved = 0; payload->op_mode.minor_version = 1; payload->op_mode.mode = client->mode; payload->op_mode.reserved = 0; payload->connect_to_port.common.module_id = LSM_MODULE_ID_VOICE_WAKEUP; payload->connect_to_port.common.param_id = LSM_PARAM_ID_CONNECT_TO_PORT; payload->connect_to_port.common.param_size = sizeof(payload->connect_to_port) - sizeof(payload->op_mode.common); payload->connect_to_port.common.reserved = 0; payload->connect_to_port.minor_version = 1; payload->connect_to_port.port_id = client->connect_to_port; payload->connect_to_port.reserved = 0; payload->kwds.common.module_id = LSM_MODULE_ID_VOICE_WAKEUP; payload->kwds.common.param_id = LSM_PARAM_ID_KEYWORD_DETECT_SENSITIVITY; payload->kwds.common.param_size = sizeof(payload->kwds) - sizeof(payload->op_mode.common); payload->kwds.common.reserved = 0; payload->kwds.minor_version = 1; payload->kwds.keyword_sensitivity = client->kw_sensitivity; payload->kwds.reserved = 0; payload->uds.common.module_id = LSM_MODULE_ID_VOICE_WAKEUP; payload->uds.common.param_id = LSM_PARAM_ID_USER_DETECT_SENSITIVITY; payload->uds.common.param_size = sizeof(payload->uds) - sizeof(payload->op_mode.common); payload->uds.common.reserved = 0; payload->uds.minor_version = 1; payload->uds.user_sensitivity = client->user_sensitivity; payload->uds.reserved = 0; rc = q6lsm_apr_send_pkt(client, client->apr, ¶ms, true, NULL); if (rc) pr_err("%s: Failed set_params opcode 0x%x, rc %d\n", __func__, params.hdr.opcode, rc); pr_debug("%s: leave %d\n", __func__, rc); return rc; }
static int q6lsm_memory_map_regions(struct lsm_client *client, dma_addr_t dma_addr_p, uint32_t dma_buf_sz, uint32_t *mmap_p) { struct avs_cmd_shared_mem_map_regions *mmap_regions = NULL; struct avs_shared_map_region_payload *mregions = NULL; void *mmap_region_cmd = NULL; void *payload = NULL; int rc; int cmd_size = 0; pr_debug("%s: dma_addr_p 0x%pa, dma_buf_sz %d, mmap_p 0x%p, session %d\n", __func__, &dma_addr_p, dma_buf_sz, mmap_p, client->session); if (CHECK_SESSION(client->session)) { pr_err("%s: session[%d]", __func__, client->session); return -EINVAL; } cmd_size = sizeof(struct avs_cmd_shared_mem_map_regions) + sizeof(struct avs_shared_map_region_payload); mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL); if (!mmap_region_cmd) { pr_err("%s: memory allocation failed\n", __func__); return -ENOMEM; } mmap_regions = (struct avs_cmd_shared_mem_map_regions *)mmap_region_cmd; q6lsm_add_mmaphdr(client, &mmap_regions->hdr, cmd_size, true, (client->session << 8)); mmap_regions->hdr.opcode = LSM_SESSION_CMD_SHARED_MEM_MAP_REGIONS; mmap_regions->mem_pool_id = ADSP_MEMORY_MAP_SHMEM8_4K_POOL; mmap_regions->num_regions = 1; mmap_regions->property_flag = 0x00; payload = ((u8 *)mmap_region_cmd + sizeof(struct avs_cmd_shared_mem_map_regions)); mregions = (struct avs_shared_map_region_payload *)payload; mregions->shm_addr_lsw = lower_32_bits(dma_addr_p); mregions->shm_addr_msw = upper_32_bits(dma_addr_p); mregions->mem_size_bytes = dma_buf_sz; rc = q6lsm_apr_send_pkt(client, client->mmap_apr, mmap_region_cmd, true, mmap_p); if (rc) pr_err("%s: Failed mmap_regions opcode 0x%x, rc %d\n", __func__, mmap_regions->hdr.opcode, rc); pr_debug("%s: leave %d\n", __func__, rc); kfree(mmap_region_cmd); return rc; }
int q6lsm_register_sound_model(struct lsm_client *client, enum lsm_detection_mode mode, u16 minkeyword, u16 minuser, bool detectfailure) { int rc; struct lsm_cmd_reg_snd_model cmd; memset(&cmd, 0, sizeof(cmd)); if (mode == LSM_MODE_KEYWORD_ONLY_DETECTION) { client->mode = 0x01; } else if (mode == LSM_MODE_USER_KEYWORD_DETECTION) { client->mode = 0x03; } else { pr_err("%s: Incorrect detection mode %d\n", __func__, mode); return -EINVAL; } client->mode |= detectfailure << 2; client->kw_sensitivity = minkeyword; client->user_sensitivity = minuser; client->connect_to_port = AFE_PORT_ID_SLIMBUS_MULTI_CHAN_5_TX; rc = q6lsm_set_params(client); if (rc < 0) { pr_err("%s: Failed to set lsm config params\n", __func__); return rc; } rc = q6lsm_send_cal(client); if (rc < 0) { pr_err("%s: Failed to send calibration data\n", __func__); return rc; } q6lsm_add_hdr(client, &cmd.hdr, sizeof(cmd), true); cmd.hdr.opcode = LSM_SESSION_CMD_REGISTER_SOUND_MODEL; cmd.model_addr_lsw = lower_32_bits(client->sound_model.phys); cmd.model_addr_msw = upper_32_bits(client->sound_model.phys); cmd.model_size = client->sound_model.size; /* read updated mem_map_handle by q6lsm_mmapcallback */ rmb(); cmd.mem_map_handle = client->sound_model.mem_map_handle; pr_debug("%s: addr %pa, size %d, handle %x\n", __func__, &client->sound_model.phys, cmd.model_size, cmd.mem_map_handle); rc = q6lsm_apr_send_pkt(client, client->apr, &cmd, true, NULL); if (rc) pr_err("%s: Failed cmd op[0x%x]rc[%d]\n", __func__, cmd.hdr.opcode, rc); else pr_debug("%s: Register sound model succeeded\n", __func__); return rc; }
static int q6lsm_send_cal(struct lsm_client *client) { int rc = 0; struct lsm_cmd_set_params params; struct cal_block_data *cal_block = NULL; pr_debug("%s: Session id %d\n", __func__, client->session); if (CHECK_SESSION(client->session)) { pr_err("%s: session[%d]", __func__, client->session); return -EINVAL; } if (lsm_common.cal_data == NULL) goto done; mutex_lock(&lsm_common.cal_data->lock); cal_block = cal_utils_get_only_cal_block(lsm_common.cal_data); if (cal_block == NULL) goto unlock; if (cal_block->cal_data.size <= 0) { pr_debug("%s: No cal to send!\n", __func__); rc = -EINVAL; goto unlock; } if (cal_block->cal_data.size != client->lsm_cal_size) { pr_err("%s: Cal size %zd doesn't match lsm cal size %d\n", __func__, cal_block->cal_data.size, client->lsm_cal_size); rc = -EINVAL; goto unlock; } /* Cache mmap address, only map once or if new addr */ lsm_common.common_client[client->session].session = client->session; q6lsm_add_hdr(client, ¶ms.hdr, sizeof(params), true); params.hdr.opcode = LSM_SESSION_CMD_SET_PARAMS; params.data_payload_addr_lsw = lower_32_bits(client->lsm_cal_phy_addr); params.data_payload_addr_msw = upper_32_bits(client->lsm_cal_phy_addr); params.mem_map_handle = client->sound_model.mem_map_handle; params.data_payload_size = cal_block->cal_data.size; pr_debug("%s: Cal Size = %zd", __func__, cal_block->cal_data.size); rc = q6lsm_apr_send_pkt(client, client->apr, ¶ms, true, NULL); if (rc) pr_err("%s: Failed set_params opcode 0x%x, rc %d\n", __func__, params.hdr.opcode, rc); unlock: mutex_unlock(&lsm_common.cal_data->lock); done: return rc; }
int q6lsm_open(struct lsm_client *client) { int rc; struct lsm_stream_cmd_open_tx open; memset(&open, 0, sizeof(open)); q6lsm_add_hdr(client, &open.hdr, sizeof(open), true); open.hdr.opcode = LSM_SESSION_CMD_OPEN_TX; open.app_id = 1; open.sampling_rate = 16000; rc = q6lsm_apr_send_pkt(client, client->apr, &open, true, NULL); if (rc) pr_err("%s: Open failed opcode 0x%x, rc %d\n", __func__, open.hdr.opcode, rc); pr_debug("%s: leave %d\n", __func__, rc); return rc; }
static int q6lsm_set_params(struct lsm_client *client) { int rc; struct lsm_cmd_set_params params; struct lsm_cmd_set_params_conf_v2 params_conf_v2; struct lsm_cmd_set_params_v2 params_v2; struct apr_hdr *hdr; struct lsm_param_connect_to_port *connect_to_port; struct lsm_param_op_mode *op_mode; struct lsm_param_kw_detect_sensitivity *kwds; struct lsm_param_user_detect_sensitivity *uds; struct lsm_param_min_confidence_levels *cfl; void *param_data; pr_debug("%s: Set KW/Confidence params\n", __func__); if (client->snd_model_ver_inuse == SND_MODEL_IN_USE_V1) { q6lsm_add_hdr(client, ¶ms.hdr, sizeof(params), true); hdr = ¶ms.hdr; params.hdr.opcode = LSM_SESSION_CMD_SET_PARAMS; params.data_payload_addr_lsw = 0; params.data_payload_addr_msw = 0; params.mem_map_handle = 0; params.data_payload_size = sizeof(struct lsm_params_payload); connect_to_port = ¶ms.payload.connect_to_port; op_mode = ¶ms.payload.op_mode; kwds = ¶ms.payload.kwds; uds = ¶ms.payload.uds; param_data = ¶ms; } else if (client->snd_model_ver_inuse == SND_MODEL_IN_USE_V2) { q6lsm_add_hdr(client, ¶ms_v2.hdr, sizeof(params_v2), true); hdr = ¶ms_v2.hdr; params_v2.hdr.opcode = LSM_SESSION_CMD_SET_PARAMS; params_v2.data_payload_addr_lsw = 0; params_v2.data_payload_addr_msw = 0; params_v2.mem_map_handle = 0; params_v2.data_payload_size = sizeof(struct lsm_params_payload_v2); connect_to_port = ¶ms_v2.payload.connect_to_port; op_mode = ¶ms_v2.payload.op_mode; param_data = ¶ms_v2; } else { pr_err("%s: Invalid sound model %d\n", __func__, client->snd_model_ver_inuse); rc = -EINVAL; return rc; } rc = q6lsm_set_operation_mode(op_mode, client->mode); if (rc) goto exit; rc = q6lsm_set_port_connected(connect_to_port, client->connect_to_port); if (rc) goto exit; if (client->snd_model_ver_inuse == SND_MODEL_IN_USE_V1) { rc = q6lsm_set_kw_sensitivity(kwds, client->kw_sensitivity); if (rc) goto exit; rc = q6lsm_set_user_sensitivity(uds, client->user_sensitivity); if (rc) goto exit; } rc = q6lsm_apr_send_pkt(client, client->apr, param_data, true, NULL); if (rc) pr_err("%s: Failed set_params opcode 0x%x, rc %d\n", __func__, hdr->opcode, rc); if (client->snd_model_ver_inuse == SND_MODEL_IN_USE_V2) { q6lsm_add_hdr(client, ¶ms_conf_v2.hdr, sizeof(params_conf_v2), true); hdr = ¶ms_conf_v2.hdr; params_conf_v2.hdr.opcode = LSM_SESSION_CMD_SET_PARAMS; params_conf_v2.data_payload_addr_lsw = 0; params_conf_v2.data_payload_addr_msw = 0; params_conf_v2.mem_map_handle = 0; params_conf_v2.data_payload_size = sizeof(struct lsm_param_min_confidence_levels); param_data = ¶ms_conf_v2; cfl = ¶ms_conf_v2.conf_payload; rc = q6lsm_set_confidence_level(cfl, client->num_confidence_levels, client->confidence_levels); if (rc) goto exit; rc = q6lsm_apr_send_pkt(client, client->apr, param_data, true, NULL); if (rc) { pr_err("%s: Failed set_params opcode 0x%x, rc %d\n", __func__, hdr->opcode, rc); goto exit; } } pr_debug("%s: leave %d\n", __func__, rc); exit: pr_debug("%s: rc =%x", __func__, rc); return rc; }