From 6b32d8743b9cf349fce2819b2e34d611b34a7feb Mon Sep 17 00:00:00 2001 From: Balakrishna Godavarthi Date: Fri, 7 Jul 2023 12:02:22 +0530 Subject: [PATCH] btfmcodec: Cache configs for all the transitions This change will cache configs for all the transitions Change-Id: If1201fd8cf045fcc2a6c4d83d50e3dd939ebc3a4 Signed-off-by: Balakrishna Godavarthi --- btfmcodec/btfm_codec_interface.c | 33 ++++++++++++--------- btfmcodec/include/btfm_codec_hw_interface.h | 3 +- slimbus/btfm_slim_hw_interface.c | 3 +- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/btfmcodec/btfm_codec_interface.c b/btfmcodec/btfm_codec_interface.c index b3c563b76a..5fe7e3c905 100644 --- a/btfmcodec/btfm_codec_interface.c +++ b/btfmcodec/btfm_codec_interface.c @@ -13,6 +13,7 @@ static struct snd_soc_dai_driver *btfmcodec_dai_info; uint32_t bits_per_second; +uint8_t num_channels; static int btfm_codec_get_mixer_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) @@ -344,7 +345,7 @@ static void btfmcodec_dai_shutdown(struct snd_pcm_substream *substream, } int btfmcodec_hwep_hw_params (struct btfmcodec_data *btfmcodec, uint32_t bps, - uint32_t direction) + uint32_t direction, uint8_t num_channels) { struct hwep_data *hwep_info = btfmcodec->hwep_info; struct hwep_dai_driver *dai_drv = (struct hwep_dai_driver *) @@ -352,7 +353,8 @@ int btfmcodec_hwep_hw_params (struct btfmcodec_data *btfmcodec, uint32_t bps, if (dai_drv && dai_drv->dai_ops && dai_drv->dai_ops->hwep_hw_params) { return dai_drv->dai_ops->hwep_hw_params((void *)btfmcodec->hwep_info, - bps, direction); + bps, direction, + num_channels); } else { return -1; } @@ -364,20 +366,21 @@ static int btfmcodec_dai_hw_params(struct snd_pcm_substream *substream, { struct btfmcodec_data *btfmcodec = snd_soc_component_get_drvdata(dai->component); struct btfmcodec_state_machine *state = &btfmcodec->states; - uint32_t bps = params_width(params); uint32_t direction = substream->stream; BTFMCODEC_DBG("dai->name = %s DAI-ID %x rate %d bps %d num_ch %d", dai->name, dai->id, params_rate(params), params_width(params), params_channels(params)); + bits_per_second = params_width(params); + num_channels = params_channels(params); if (btfmcodec_get_current_transport(state) != IDLE && btfmcodec_get_current_transport(state) != BT_Connected) { - BTFMCODEC_WARN("caching bps as state is :%s", + BTFMCODEC_WARN("caching bps and num_channels as state is :%s", coverttostring(btfmcodec_get_current_transport(state))); - bits_per_second = bps; } else { - return btfmcodec_hwep_hw_params(btfmcodec, bps, direction); + return btfmcodec_hwep_hw_params(btfmcodec, bits_per_second, + direction, num_channels); } return 0; @@ -424,6 +427,7 @@ static int btfmcodec_check_and_cache_configs(struct btfmcodec_data *btfmcodec, hwep_configs->bit_width = bits_per_second; hwep_configs->codectype = codectype; hwep_configs->direction = direction; + hwep_configs->num_channels = num_channels; list_add(&hwep_configs->dai_list, head); BTFMCODEC_INFO("added dai id:%d to list with sampling_rate :%u, direction:%u", id, sampling_rate, direction); @@ -535,24 +539,24 @@ static int btfmcodec_dai_prepare(struct snd_pcm_substream *substream, uint32_t sampling_rate = dai->rate; uint32_t direction = substream->stream; int id = dai->id; - int ret; + int ret ; BTFMCODEC_INFO("dai->name: %s, dai->id: %d, dai->rate: %d direction: %d", dai->name, id, sampling_rate, direction); + ret = btfmcodec_check_and_cache_configs(btfmcodec, sampling_rate, + direction, id, *codectype); if (btfmcodec_get_current_transport(state) != IDLE && btfmcodec_get_current_transport(state) != BT_Connected) { - BTFMCODEC_WARN("caching required info as state is:%s", + BTFMCODEC_WARN("cached required info as state is:%s", coverttostring(btfmcodec_get_current_transport(state))); - ret = btfmcodec_check_and_cache_configs(btfmcodec, sampling_rate, direction, - id, *codectype); } else { ret = btfmcodec_hwep_prepare(btfmcodec, sampling_rate, direction, id); - if (ret >= 0) { +/* if (ret >= 0) { btfmcodec_check_and_cache_configs(btfmcodec, sampling_rate, direction, id, *codectype); } - } +*/ } return ret; } @@ -641,7 +645,7 @@ void btfmcodec_wq_hwep_configure(struct work_struct *work) int ret; int idx = BTM_PKT_TYPE_HWEP_CONFIG; uint32_t sample_rate, direction; - uint8_t id, bit_width, codectype; + uint8_t id, bit_width, codectype, num_channels; list_for_each_entry(hwep_configs, head, dai_list) { id = hwep_configs->stream_id; @@ -649,11 +653,12 @@ void btfmcodec_wq_hwep_configure(struct work_struct *work) bit_width = hwep_configs->bit_width; codectype = hwep_configs->codectype; direction = hwep_configs->direction; + num_channels = hwep_configs->num_channels; BTFMCODEC_INFO("configuring dai id:%d with sampling rate:%d bit_width:%d", id, sample_rate, bit_width); ret = btfmcodec_hwep_startup(btfmcodec); if (ret >= 0) - ret = btfmcodec_hwep_hw_params(btfmcodec, bit_width, direction); + ret = btfmcodec_hwep_hw_params(btfmcodec, bit_width, direction, num_channels); if (ret >= 0) ret = btfmcodec_hwep_prepare(btfmcodec, sample_rate, direction, id); if (ret < 0) { diff --git a/btfmcodec/include/btfm_codec_hw_interface.h b/btfmcodec/include/btfm_codec_hw_interface.h index 60163b95ab..bf8e2e6790 100644 --- a/btfmcodec/include/btfm_codec_hw_interface.h +++ b/btfmcodec/include/btfm_codec_hw_interface.h @@ -27,6 +27,7 @@ struct hwep_configurations { uint8_t bit_width; uint8_t codectype; uint32_t direction; + uint8_t num_channels; struct list_head dai_list; }; @@ -51,7 +52,7 @@ struct hwep_comp_drv { struct hwep_dai_ops { int (*hwep_startup)(void *); void (*hwep_shutdown)(void *, int); - int (*hwep_hw_params)(void *, uint32_t, uint32_t); + int (*hwep_hw_params)(void *, uint32_t, uint32_t, uint8_t); int (*hwep_prepare)(void *, uint32_t, uint32_t, int); int (*hwep_set_channel_map)(void *, unsigned int, unsigned int *, unsigned int, unsigned int *); diff --git a/slimbus/btfm_slim_hw_interface.c b/slimbus/btfm_slim_hw_interface.c index 34567253b8..9cc08cc9bd 100644 --- a/slimbus/btfm_slim_hw_interface.c +++ b/slimbus/btfm_slim_hw_interface.c @@ -167,7 +167,8 @@ static void btfm_slim_dai_shutdown(void *dai, int id) } static int btfm_slim_dai_hw_params(void *dai, uint32_t bps, - uint32_t direction) { + uint32_t direction, + uint8_t num_channels) { struct hwep_data *hwep_info = (struct hwep_data *)dai; struct btfmslim *btfmslim = dev_get_drvdata(hwep_info->dev);