From 912fd67d6cf3d88b2a60fb90514541a5586f13f5 Mon Sep 17 00:00:00 2001 From: Vignesh Kulothungan Date: Wed, 5 Aug 2020 23:26:06 -0700 Subject: [PATCH 1/3] ASoC: wsa883x: add function to get swr device number Add a function in wsa883x which returns the sound wire device number for a given wsa883x codec slave instance. Change-Id: Ie3d0e309870f488b1643a853bcddcf93314d94b5 Signed-off-by: Vignesh Kulothungan --- asoc/codecs/wsa883x/wsa883x.c | 24 ++++++++++++++++++++++++ asoc/codecs/wsa883x/wsa883x.h | 5 +++++ 2 files changed, 29 insertions(+) diff --git a/asoc/codecs/wsa883x/wsa883x.c b/asoc/codecs/wsa883x/wsa883x.c index a228ab5e137f..752d4b7f5a7a 100644 --- a/asoc/codecs/wsa883x/wsa883x.c +++ b/asoc/codecs/wsa883x/wsa883x.c @@ -801,6 +801,30 @@ int wsa883x_codec_info_create_codec_entry(struct snd_info_entry *codec_root, } EXPORT_SYMBOL(wsa883x_codec_info_create_codec_entry); +/* + * wsa883x_codec_get_dev_num - returns swr device number + * @component: Codec instance + * + * Return: swr device number on success or negative error + * code on failure. + */ +int wsa883x_codec_get_dev_num(struct snd_soc_component *component) +{ + struct wsa883x_priv *wsa883x; + + if (!component) + return -EINVAL; + + wsa883x = snd_soc_component_get_drvdata(component); + if (!wsa883x) { + pr_err("%s: wsa883x component is NULL\n", __func__); + return -EINVAL; + } + + return wsa883x->swr_slave->dev_num; +} +EXPORT_SYMBOL(wsa883x_codec_get_dev_num); + static int wsa883x_get_compander(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { diff --git a/asoc/codecs/wsa883x/wsa883x.h b/asoc/codecs/wsa883x/wsa883x.h index e080134eb016..bb719831ed61 100644 --- a/asoc/codecs/wsa883x/wsa883x.h +++ b/asoc/codecs/wsa883x/wsa883x.h @@ -21,6 +21,7 @@ int wsa883x_set_channel_map(struct snd_soc_component *component, int wsa883x_codec_info_create_codec_entry( struct snd_info_entry *codec_root, struct snd_soc_component *component); +int wsa883x_codec_get_dev_num(struct snd_soc_component *component); #else static int wsa883x_set_channel_map(struct snd_soc_component *component, u8 *port, u8 num_port, unsigned int *ch_mask, @@ -36,6 +37,10 @@ static int wsa883x_codec_info_create_codec_entry( return 0; } +static int wsa883x_codec_get_dev_num(struct snd_soc_component *component) +{ + return 0; +} #endif #endif /* _WSA883X_H */ From 3fa8c9411fcdc709437480a2a198734b3e3219c0 Mon Sep 17 00:00:00 2001 From: Vignesh Kulothungan Date: Wed, 5 Aug 2020 23:39:37 -0700 Subject: [PATCH 2/3] dsp: add afe function to send cps configuration Define cps hw interface configuration structures. Add AFE_PARAM_ID_CPS_LPASS_HW_INTF_CFG parameter id. Add a function to send afe cps speaker protection configuration. Change-Id: I865e9981b6dd1da4b9ef1a3e18be82cea2996309 Signed-off-by: Vignesh Kulothungan --- dsp/q6afe.c | 60 ++++++++++++++++++++++++++++++++++++++ include/dsp/apr_audio-v2.h | 26 +++++++++++++++++ include/dsp/q6afe-v2.h | 3 ++ 3 files changed, 89 insertions(+) diff --git a/dsp/q6afe.c b/dsp/q6afe.c index 8fbbfd9b873e..1f8c102ae328 100644 --- a/dsp/q6afe.c +++ b/dsp/q6afe.c @@ -2179,6 +2179,66 @@ fail_cmd: return ret; } +/** + * afe_send_cps_config - + * to send cps speaker protection configuration + * + * @src_port: source port to send configuration to + * @cps_config: cps speaker protection v4 configuration + * @param_size: size of payload + * + * Returns 0 on success or error value on failure. + */ +int afe_send_cps_config(int src_port, + struct afe_cps_hw_intf_cfg *cps_config, + int param_size) +{ + struct param_hdr_v3 param_info; + int ret = -EINVAL; + u8 *packed_payload = NULL; + int cpy_size = 0; + + ret = q6audio_validate_port(src_port); + if (ret < 0) { + pr_err("%s: Invalid src port 0x%x ret %d", __func__, + src_port, ret); + return -EINVAL; + } + + packed_payload = kzalloc(param_size, GFP_KERNEL); + if (packed_payload == NULL) + return -ENOMEM; + + cpy_size = sizeof(struct afe_cps_hw_intf_cfg) - + sizeof(cps_config->spkr_dep_cfg); + memcpy(packed_payload, cps_config, cpy_size); + memcpy(packed_payload + cpy_size, cps_config->spkr_dep_cfg, + sizeof(struct lpass_swr_spkr_dep_cfg_t) + * cps_config->hw_reg_cfg.num_spkr); + + memset(¶m_info, 0, sizeof(param_info)); + + mutex_lock(&this_afe.afe_cmd_lock); + param_info.module_id = AFE_MODULE_SPEAKER_PROTECTION_V4_RX; + param_info.instance_id = INSTANCE_ID_0; + param_info.param_id = AFE_PARAM_ID_CPS_LPASS_HW_INTF_CFG; + param_info.param_size = param_size; + + ret = q6afe_pack_and_set_param_in_band(src_port, + q6audio_get_port_index(src_port), + param_info, packed_payload); + if (ret) + pr_err("%s: port = 0x%x param = 0x%x failed %d\n", __func__, + src_port, param_info.param_id, ret); + + mutex_unlock(&this_afe.afe_cmd_lock); + pr_debug("%s: config.pdata.param_id 0x%x status %d 0x%x\n", __func__, + param_info.param_id, ret, src_port); + kfree(packed_payload); + return ret; +} +EXPORT_SYMBOL(afe_send_cps_config); + static int afe_spk_prot_prepare(int src_port, int dst_port, int param_id, union afe_spkr_prot_config *prot_config, uint32_t param_size) { diff --git a/include/dsp/apr_audio-v2.h b/include/dsp/apr_audio-v2.h index 090bceb4d5f9..4cd34ddbf362 100644 --- a/include/dsp/apr_audio-v2.h +++ b/include/dsp/apr_audio-v2.h @@ -10,6 +10,9 @@ #include #include