diff options
| author | Linux Build Service Account <lnxbuild@localhost> | 2018-10-09 09:43:44 -0700 |
|---|---|---|
| committer | Gerrit - the friendly Code Review server <code-review@localhost> | 2018-10-09 09:43:44 -0700 |
| commit | a5a34b69d420ab8a1fdf6d8494e7789b41f2132a (patch) | |
| tree | 5c602aaee85caff773cfb481d89ff7cb8a009f81 /drivers/soc | |
| parent | b6179196216ef375d53165a9f2e08f352a9dfb7f (diff) | |
| parent | aef8b38fdd280a4c8890df4f5172c400d3762866 (diff) | |
Merge "soc: msm: add sensor dsp dynamic calibration support for anc"
Diffstat (limited to 'drivers/soc')
| -rw-r--r-- | drivers/soc/qcom/qdsp6v2/audio-anc-dev-mgr.c | 69 | ||||
| -rw-r--r-- | drivers/soc/qcom/qdsp6v2/audio_anc.c | 17 | ||||
| -rw-r--r-- | drivers/soc/qcom/qdsp6v2/sdsp-anc.c | 243 |
3 files changed, 186 insertions, 143 deletions
diff --git a/drivers/soc/qcom/qdsp6v2/audio-anc-dev-mgr.c b/drivers/soc/qcom/qdsp6v2/audio-anc-dev-mgr.c index 75b114e6905c..95562d2cbfad 100644 --- a/drivers/soc/qcom/qdsp6v2/audio-anc-dev-mgr.c +++ b/drivers/soc/qcom/qdsp6v2/audio-anc-dev-mgr.c @@ -53,8 +53,6 @@ struct anc_tdm_group_set_info { struct anc_dev_drv_info { uint32_t state; - uint32_t rpm; - uint32_t bypass_mode; uint32_t algo_module_id; }; @@ -311,52 +309,68 @@ static int anc_dev_port_stop(int32_t which_port) int msm_anc_dev_set_info(void *info_p, int32_t anc_cmd) { - int rc = 0; + int rc = -EINVAL; switch (anc_cmd) { - case ANC_CMD_RPM: { - struct audio_anc_rpm_info *rpm_info_p = - (struct audio_anc_rpm_info *)info_p; + case ANC_CMD_ALGO_MODULE: { + struct audio_anc_algo_module_info *module_info_p = + (struct audio_anc_algo_module_info *)info_p; + + rc = 0; if (this_anc_dev_info.state) - rc = anc_if_set_rpm( + rc = anc_if_set_algo_module_id( anc_port_cfg[ANC_DEV_PORT_ANC_SPKR].port_id, - rpm_info_p->rpm); + module_info_p->module_id); else - this_anc_dev_info.rpm = 0; + this_anc_dev_info.algo_module_id = + module_info_p->module_id; break; } - case ANC_CMD_BYPASS_MODE: { - struct audio_anc_bypass_mode *bypass_mode_p = - (struct audio_anc_bypass_mode *)info_p; - + case ANC_CMD_ALGO_CALIBRATION: { + rc = -EINVAL; if (this_anc_dev_info.state) - rc = anc_if_set_bypass_mode( + rc = anc_if_set_algo_module_cali_data( anc_port_cfg[ANC_DEV_PORT_ANC_SPKR].port_id, - bypass_mode_p->mode); + info_p); else - this_anc_dev_info.bypass_mode = bypass_mode_p->mode; + pr_err("%s: ANC is not running yet\n", + __func__); + break; + } + default: + pr_err("%s: ANC cmd wrong\n", + __func__); break; } - case ANC_CMD_ALGO_MODULE: { - struct audio_anc_algo_module_info *module_info_p = - (struct audio_anc_algo_module_info *)info_p; + return rc; +} + +int msm_anc_dev_get_info(void *info_p, int32_t anc_cmd) +{ + int rc = -EINVAL; + + switch (anc_cmd) { + case ANC_CMD_ALGO_CALIBRATION: { if (this_anc_dev_info.state) - rc = anc_if_set_algo_module_id( + rc = anc_if_get_algo_module_cali_data( anc_port_cfg[ANC_DEV_PORT_ANC_SPKR].port_id, - module_info_p->module_id); + info_p); else - this_anc_dev_info.algo_module_id = - module_info_p->module_id; + pr_err("%s: ANC is not running yet\n", + __func__); break; } + default: + pr_err("%s: ANC cmd wrong\n", + __func__); + break; } return rc; } - int msm_anc_dev_start(void) { int rc = 0; @@ -514,11 +528,6 @@ int msm_anc_dev_start(void) anc_port_cfg[ANC_DEV_PORT_ANC_SPKR].port_id, this_anc_dev_info.algo_module_id); - if (this_anc_dev_info.bypass_mode != 0) - rc = anc_if_set_bypass_mode( - anc_port_cfg[ANC_DEV_PORT_ANC_SPKR].port_id, - this_anc_dev_info.bypass_mode); - group_id = get_group_id_from_port_id( anc_port_cfg[ANC_DEV_PORT_ANC_SPKR].port_id); @@ -612,8 +621,6 @@ int msm_anc_dev_stop(void) this_anc_dev_info.state = 0; this_anc_dev_info.algo_module_id = 0; - this_anc_dev_info.rpm = 0; - this_anc_dev_info.bypass_mode = 0; pr_debug("%s: ANC devices stop successfully!\n", __func__); diff --git a/drivers/soc/qcom/qdsp6v2/audio_anc.c b/drivers/soc/qcom/qdsp6v2/audio_anc.c index 65c585886453..50cc255043df 100644 --- a/drivers/soc/qcom/qdsp6v2/audio_anc.c +++ b/drivers/soc/qcom/qdsp6v2/audio_anc.c @@ -44,17 +44,11 @@ static size_t get_user_anc_cmd_size(int32_t anc_cmd) case ANC_CMD_STOP: size = 0; break; - case ANC_CMD_RPM: - size = sizeof(struct audio_anc_rpm_info); - break; - case ANC_CMD_BYPASS_MODE: - size = sizeof(struct audio_anc_bypass_mode); - break; case ANC_CMD_ALGO_MODULE: size = sizeof(struct audio_anc_algo_module_info); break; case ANC_CMD_ALGO_CALIBRATION: - size = sizeof(struct audio_anc_algo_calibration_info); + size = sizeof(struct audio_anc_algo_calibration_header); break; default: pr_err("%s:Invalid anc cmd %d!", @@ -77,8 +71,6 @@ static int call_set_anc(int32_t anc_cmd, case ANC_CMD_STOP: ret = msm_anc_dev_stop(); break; - case ANC_CMD_RPM: - case ANC_CMD_BYPASS_MODE: case ANC_CMD_ALGO_MODULE: case ANC_CMD_ALGO_CALIBRATION: ret = msm_anc_dev_set_info(data, anc_cmd); @@ -98,7 +90,8 @@ static int call_get_anc(int32_t anc_cmd, int ret = 0; switch (anc_cmd) { - case ANC_CMD_RPM: + case ANC_CMD_ALGO_CALIBRATION: + ret = msm_anc_dev_get_info(data, anc_cmd); break; default: break; @@ -146,9 +139,9 @@ static long audio_anc_shared_ioctl(struct file *file, unsigned int cmd, pr_err("%s: Could not copy size value from user\n", __func__); ret = -EFAULT; goto done; - } else if (size < sizeof(struct audio_anc_packet)) { + } else if (size < sizeof(struct audio_anc_header)) { pr_err("%s: Invalid size sent to driver: %d, min size is %zd\n", - __func__, size, sizeof(struct audio_anc_packet)); + __func__, size, sizeof(struct audio_anc_header)); ret = -EINVAL; goto done; } diff --git a/drivers/soc/qcom/qdsp6v2/sdsp-anc.c b/drivers/soc/qcom/qdsp6v2/sdsp-anc.c index 9294485f7ff2..4e75bc89aa8f 100644 --- a/drivers/soc/qcom/qdsp6v2/sdsp-anc.c +++ b/drivers/soc/qcom/qdsp6v2/sdsp-anc.c @@ -38,7 +38,7 @@ struct anc_if_ctl { atomic_t status; wait_queue_head_t wait[AFE_MAX_PORTS]; struct task_struct *task; - struct anc_get_rpm_resp rpm_calib_data; + struct anc_get_algo_module_cali_data_resp cali_data_resp; uint32_t mmap_handle; struct mutex afe_cmd_lock; }; @@ -48,33 +48,23 @@ static struct anc_if_ctl this_anc_if; static int32_t anc_get_param_callback(uint32_t *payload, uint32_t payload_size) { - u32 param_id; - struct anc_get_rpm_resp *resp = - (struct anc_get_rpm_resp *) payload; - - if (!(&(resp->pdata))) { - pr_err("%s: Error: resp pdata is NULL\n", __func__); + if ((payload_size < (sizeof(uint32_t) + + sizeof(this_anc_if.cali_data_resp.pdata))) || + (payload_size > sizeof(this_anc_if.cali_data_resp))) { + pr_err("%s: Error: received size %d, calib_data size %zu\n", + __func__, payload_size, + sizeof(this_anc_if.cali_data_resp)); return -EINVAL; } - param_id = resp->pdata.param_id; - if (param_id == AUD_MSVC_PARAM_ID_PORT_ANC_ALGO_RPM) { - if (payload_size < sizeof(this_anc_if.rpm_calib_data)) { - pr_err("%s: Error: received size %d, calib_data size %zu\n", - __func__, payload_size, - sizeof(this_anc_if.rpm_calib_data)); - return -EINVAL; - } - - memcpy(&this_anc_if.rpm_calib_data, payload, - sizeof(this_anc_if.rpm_calib_data)); - if (!this_anc_if.rpm_calib_data.status) { - atomic_set(&this_anc_if.state, 0); - } else { - pr_debug("%s: calib resp status: %d", __func__, - this_anc_if.rpm_calib_data.status); - atomic_set(&this_anc_if.state, -1); - } + memcpy(&this_anc_if.cali_data_resp, payload, + payload_size); + if (!this_anc_if.cali_data_resp.status) { + atomic_set(&this_anc_if.state, 0); + } else { + pr_debug("%s: calib resp status: %d", __func__, + this_anc_if.cali_data_resp.status); + atomic_set(&this_anc_if.state, -1); } return 0; @@ -465,7 +455,7 @@ int anc_if_tdm_port_stop(u16 port_id) return anc_if_send_cmd_port_stop(port_id); } -int anc_if_set_rpm(u16 port_id, u32 rpm) +int anc_if_set_algo_module_id(u16 port_id, u32 module_id) { int ret = 0; int index; @@ -479,7 +469,7 @@ int anc_if_set_rpm(u16 port_id, u32 rpm) index = q6audio_get_port_index(port_id); { - struct anc_set_rpm_command config; + struct anc_set_algo_module_id_command config; memset(&config, 0, sizeof(config)); config.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, @@ -496,16 +486,16 @@ int anc_if_set_rpm(u16 port_id, u32 rpm) config.param.payload_address_lsw = 0x00; config.param.payload_address_msw = 0x00; config.param.mem_map_handle = 0x00; - config.pdata.module_id = AUD_MSVC_MODULE_AUDIO_DEV_ANC_ALGO; - config.pdata.param_id = AUD_MSVC_PARAM_ID_PORT_ANC_ALGO_RPM; - config.pdata.param_size = sizeof(config.set_rpm); - config.set_rpm.minor_version = - AUD_MSVC_API_VERSION_DEV_ANC_ALGO_RPM; - config.set_rpm.rpm = rpm; + config.pdata.module_id = AFE_MODULE_AUDIO_DEV_INTERFACE; + config.pdata.param_id = + AUD_MSVC_PARAM_ID_PORT_ANC_ALGO_MODULE_ID; + config.pdata.param_size = sizeof(config.set_algo_module_id); + config.set_algo_module_id.minor_version = 1; + config.set_algo_module_id.module_id = module_id; ret = anc_if_apr_send_pkt(&config, &this_anc_if.wait[index]); if (ret) { - pr_err("%s: share resource for port 0x%x failed ret = %d\n", + pr_err("%s: anc algo module ID for port 0x%x failed ret = %d\n", __func__, port_id, ret); } } @@ -513,10 +503,10 @@ int anc_if_set_rpm(u16 port_id, u32 rpm) return ret; } -int anc_if_set_bypass_mode(u16 port_id, u32 bypass_mode) +int anc_if_set_anc_mic_spkr_layout(u16 port_id, +struct aud_msvc_param_id_dev_anc_mic_spkr_layout_info *set_mic_spkr_layout_p) { int ret = 0; - int index; ret = anc_sdsp_interface_prepare(); @@ -528,7 +518,7 @@ int anc_if_set_bypass_mode(u16 port_id, u32 bypass_mode) index = q6audio_get_port_index(port_id); { - struct anc_set_bypass_mode_command config; + struct anc_set_mic_spkr_layout_info_command config; memset(&config, 0, sizeof(config)); config.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, @@ -545,17 +535,16 @@ int anc_if_set_bypass_mode(u16 port_id, u32 bypass_mode) config.param.payload_address_lsw = 0x00; config.param.payload_address_msw = 0x00; config.param.mem_map_handle = 0x00; - config.pdata.module_id = AUD_MSVC_MODULE_AUDIO_DEV_ANC_ALGO; + config.pdata.module_id = AFE_MODULE_AUDIO_DEV_INTERFACE; config.pdata.param_id = - AUD_MSVC_PARAM_ID_PORT_ANC_ALGO_BYPASS_MODE; - config.pdata.param_size = sizeof(config.set_bypass_mode); - config.set_bypass_mode.minor_version = - AUD_MSVC_API_VERSION_DEV_ANC_ALGO_BYPASS_MODE; - config.set_bypass_mode.bypass_mode = bypass_mode; + AUD_MSVC_PARAM_ID_PORT_ANC_MIC_SPKR_LAYOUT_INFO; + config.pdata.param_size = sizeof(config.set_mic_spkr_layout); + memcpy(&config.set_mic_spkr_layout, set_mic_spkr_layout_p, + sizeof(config.set_mic_spkr_layout)); ret = anc_if_apr_send_pkt(&config, &this_anc_if.wait[index]); if (ret) { - pr_err("%s: share resource for port 0x%x failed ret = %d\n", + pr_err("%s: anc algo module ID for port 0x%x failed ret = %d\n", __func__, port_id, ret); } } @@ -563,10 +552,10 @@ int anc_if_set_bypass_mode(u16 port_id, u32 bypass_mode) return ret; } -int anc_if_set_algo_module_id(u16 port_id, u32 module_id) + +int anc_if_set_algo_module_cali_data(u16 port_id, void *data_p) { int ret = 0; - int index; ret = anc_sdsp_interface_prepare(); @@ -578,45 +567,67 @@ int anc_if_set_algo_module_id(u16 port_id, u32 module_id) index = q6audio_get_port_index(port_id); { - struct anc_set_algo_module_id_command config; + struct anc_set_algo_module_cali_data_command *cali_data_cfg_p; + void *config_p = NULL; + int cmd_size = 0; + void *out_payload_p = NULL; + uint32_t *in_payload_p = (uint32_t *)data_p; + + uint32_t module_id = *in_payload_p; + uint32_t param_id = *(in_payload_p + 1); + uint32_t payload_size = *(in_payload_p + 2); + + cmd_size = sizeof(struct anc_set_algo_module_cali_data_command) + + payload_size; + config_p = kzalloc(cmd_size, GFP_KERNEL); + if (!config_p) { + ret = -ENOMEM; + return ret; + } - memset(&config, 0, sizeof(config)); - config.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, + memset(config_p, 0, cmd_size); + out_payload_p = config_p + + sizeof(struct anc_set_algo_module_cali_data_command); + + cali_data_cfg_p = + (struct anc_set_algo_module_cali_data_command *)config_p; + + cali_data_cfg_p->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 = index; - config.hdr.opcode = AFE_PORT_CMD_SET_PARAM_V2; - config.param.port_id = q6audio_get_port_id(port_id); - config.param.payload_size = sizeof(config) - + cali_data_cfg_p->hdr.pkt_size = cmd_size; + cali_data_cfg_p->hdr.src_port = 0; + cali_data_cfg_p->hdr.dest_port = 0; + cali_data_cfg_p->hdr.token = index; + cali_data_cfg_p->hdr.opcode = AFE_PORT_CMD_SET_PARAM_V2; + cali_data_cfg_p->param.port_id = q6audio_get_port_id(port_id); + cali_data_cfg_p->param.payload_size = cmd_size - sizeof(struct apr_hdr) - - sizeof(config.param); - config.param.payload_address_lsw = 0x00; - config.param.payload_address_msw = 0x00; - config.param.mem_map_handle = 0x00; - config.pdata.module_id = AUD_MSVC_MODULE_AUDIO_DEV_ANC_ALGO; - config.pdata.param_id = - AUD_MSVC_PARAM_ID_PORT_ANC_ALGO_MODULE_ID; - config.pdata.param_size = sizeof(config.set_algo_module_id); - config.set_algo_module_id.minor_version = 1; - config.set_algo_module_id.module_id = module_id; + sizeof(struct aud_msvc_port_cmd_set_param_v2); + cali_data_cfg_p->param.payload_address_lsw = 0x00; + cali_data_cfg_p->param.payload_address_msw = 0x00; + cali_data_cfg_p->param.mem_map_handle = 0x00; + cali_data_cfg_p->pdata.module_id = module_id; + cali_data_cfg_p->pdata.param_id = param_id; + cali_data_cfg_p->pdata.param_size = payload_size; + + memcpy(out_payload_p, (in_payload_p + 3), payload_size); + + ret = anc_if_apr_send_pkt(cali_data_cfg_p, + &this_anc_if.wait[index]); + if (ret) + pr_err("%s: anc algo module calibration data for port 0x%x failed ret = %d\n", + __func__, port_id, ret); - ret = anc_if_apr_send_pkt(&config, &this_anc_if.wait[index]); - if (ret) { - pr_err("%s: anc algo module ID for port 0x%x failed ret = %d\n", - __func__, port_id, ret); - } + kfree(config_p); } return ret; } -int anc_if_set_anc_mic_spkr_layout(u16 port_id, -struct aud_msvc_param_id_dev_anc_mic_spkr_layout_info *set_mic_spkr_layout_p) +int anc_if_get_algo_module_cali_data(u16 port_id, void *data_p) { int ret = 0; - int index; ret = anc_sdsp_interface_prepare(); @@ -628,35 +639,68 @@ struct aud_msvc_param_id_dev_anc_mic_spkr_layout_info *set_mic_spkr_layout_p) index = q6audio_get_port_index(port_id); { - struct anc_set_mic_spkr_layout_info_command config; + struct anc_get_algo_module_cali_data_command *cali_data_cfg_p; + void *config_p = NULL; + int cmd_size = 0; + void *out_payload_p = NULL; + uint32_t *in_payload_p = (uint32_t *)data_p; + + uint32_t module_id = *in_payload_p; + uint32_t param_id = *(in_payload_p + 1); + uint32_t payload_size = *(in_payload_p + 2); + + cmd_size = sizeof(struct anc_get_algo_module_cali_data_command) + + payload_size; + config_p = kzalloc(cmd_size, GFP_KERNEL); + if (!config_p) { + ret = -ENOMEM; + return ret; + } - memset(&config, 0, sizeof(config)); - config.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, + memset(config_p, 0, cmd_size); + out_payload_p = config_p + + sizeof(struct anc_set_algo_module_cali_data_command); + + cali_data_cfg_p = + (struct anc_get_algo_module_cali_data_command *)config_p; + + cali_data_cfg_p->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 = index; - config.hdr.opcode = AFE_PORT_CMD_SET_PARAM_V2; - config.param.port_id = q6audio_get_port_id(port_id); - config.param.payload_size = sizeof(config) - + cali_data_cfg_p->hdr.pkt_size = cmd_size; + cali_data_cfg_p->hdr.src_port = 0; + cali_data_cfg_p->hdr.dest_port = 0; + cali_data_cfg_p->hdr.token = index; + cali_data_cfg_p->hdr.opcode = AFE_PORT_CMD_GET_PARAM_V2; + cali_data_cfg_p->param.port_id = q6audio_get_port_id(port_id); + cali_data_cfg_p->param.payload_size = cmd_size - sizeof(struct apr_hdr) - - sizeof(config.param); - config.param.payload_address_lsw = 0x00; - config.param.payload_address_msw = 0x00; - config.param.mem_map_handle = 0x00; - config.pdata.module_id = AUD_MSVC_MODULE_AUDIO_DEV_ANC_ALGO; - config.pdata.param_id = - AUD_MSVC_PARAM_ID_PORT_ANC_MIC_SPKR_LAYOUT_INFO; - config.pdata.param_size = sizeof(config.set_mic_spkr_layout); - - memcpy(&config.set_mic_spkr_layout, set_mic_spkr_layout_p, - sizeof(config.set_mic_spkr_layout)); - ret = anc_if_apr_send_pkt(&config, &this_anc_if.wait[index]); - if (ret) { - pr_err("%s: anc algo module ID for port 0x%x failed ret = %d\n", + sizeof(struct aud_msvc_port_cmd_get_param_v2); + cali_data_cfg_p->param.payload_address_lsw = 0x00; + cali_data_cfg_p->param.payload_address_msw = 0x00; + cali_data_cfg_p->param.mem_map_handle = 0x00; + cali_data_cfg_p->param.module_id = module_id; + cali_data_cfg_p->param.param_id = param_id; + cali_data_cfg_p->pdata.param_size = 0; + cali_data_cfg_p->pdata.module_id = 0; + cali_data_cfg_p->pdata.param_id = 0; + + ret = anc_if_apr_send_pkt(cali_data_cfg_p, + &this_anc_if.wait[index]); + if (ret) + pr_err("%s: anc algo module calibration data for port 0x%x failed ret = %d\n", __func__, port_id, ret); - } + + memcpy((in_payload_p + 3), + &this_anc_if.cali_data_resp.payload[0], payload_size); + + *in_payload_p = this_anc_if.cali_data_resp.pdata.module_id; + *(in_payload_p + 1) = + this_anc_if.cali_data_resp.pdata.param_id; + *(in_payload_p + 2) = + this_anc_if.cali_data_resp.pdata.param_size; + + kfree(config_p); } return ret; @@ -700,7 +744,6 @@ int anc_if_cmd_memory_map(int port_id, phys_addr_t dma_addr_p, mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL); if (!mmap_region_cmd) { ret = -ENOMEM; - pr_err("%s: allocate mmap_region_cmd failed\n", __func__); return ret; } |
