btfmcodec: Cache configs for all the transitions

This change will cache configs for all the transitions

Change-Id: If1201fd8cf045fcc2a6c4d83d50e3dd939ebc3a4
Signed-off-by: Balakrishna Godavarthi <quic_bgodavar@quicinc.com>
This commit is contained in:
Balakrishna Godavarthi
2023-07-07 12:02:22 +05:30
committed by Gerrit - the friendly Code Review server
parent c0568d1c4d
commit 6b32d8743b
3 changed files with 23 additions and 16 deletions

View File

@@ -13,6 +13,7 @@
static struct snd_soc_dai_driver *btfmcodec_dai_info; static struct snd_soc_dai_driver *btfmcodec_dai_info;
uint32_t bits_per_second; uint32_t bits_per_second;
uint8_t num_channels;
static int btfm_codec_get_mixer_control(struct snd_kcontrol *kcontrol, static int btfm_codec_get_mixer_control(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol) 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, 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_data *hwep_info = btfmcodec->hwep_info;
struct hwep_dai_driver *dai_drv = (struct hwep_dai_driver *) 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) { 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, return dai_drv->dai_ops->hwep_hw_params((void *)btfmcodec->hwep_info,
bps, direction); bps, direction,
num_channels);
} else { } else {
return -1; 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_data *btfmcodec = snd_soc_component_get_drvdata(dai->component);
struct btfmcodec_state_machine *state = &btfmcodec->states; struct btfmcodec_state_machine *state = &btfmcodec->states;
uint32_t bps = params_width(params);
uint32_t direction = substream->stream; uint32_t direction = substream->stream;
BTFMCODEC_DBG("dai->name = %s DAI-ID %x rate %d bps %d num_ch %d", 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), dai->name, dai->id, params_rate(params), params_width(params),
params_channels(params)); params_channels(params));
bits_per_second = params_width(params);
num_channels = params_channels(params);
if (btfmcodec_get_current_transport(state) != IDLE && if (btfmcodec_get_current_transport(state) != IDLE &&
btfmcodec_get_current_transport(state) != BT_Connected) { 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))); coverttostring(btfmcodec_get_current_transport(state)));
bits_per_second = bps;
} else { } else {
return btfmcodec_hwep_hw_params(btfmcodec, bps, direction); return btfmcodec_hwep_hw_params(btfmcodec, bits_per_second,
direction, num_channels);
} }
return 0; 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->bit_width = bits_per_second;
hwep_configs->codectype = codectype; hwep_configs->codectype = codectype;
hwep_configs->direction = direction; hwep_configs->direction = direction;
hwep_configs->num_channels = num_channels;
list_add(&hwep_configs->dai_list, head); 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); BTFMCODEC_INFO("added dai id:%d to list with sampling_rate :%u, direction:%u", id, sampling_rate, direction);
@@ -540,19 +544,19 @@ static int btfmcodec_dai_prepare(struct snd_pcm_substream *substream,
BTFMCODEC_INFO("dai->name: %s, dai->id: %d, dai->rate: %d direction: %d", BTFMCODEC_INFO("dai->name: %s, dai->id: %d, dai->rate: %d direction: %d",
dai->name, id, sampling_rate, direction); 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 && if (btfmcodec_get_current_transport(state) != IDLE &&
btfmcodec_get_current_transport(state) != BT_Connected) { 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))); coverttostring(btfmcodec_get_current_transport(state)));
ret = btfmcodec_check_and_cache_configs(btfmcodec, sampling_rate, direction,
id, *codectype);
} else { } else {
ret = btfmcodec_hwep_prepare(btfmcodec, sampling_rate, direction, id); ret = btfmcodec_hwep_prepare(btfmcodec, sampling_rate, direction, id);
if (ret >= 0) { /* if (ret >= 0) {
btfmcodec_check_and_cache_configs(btfmcodec, sampling_rate, direction, btfmcodec_check_and_cache_configs(btfmcodec, sampling_rate, direction,
id, *codectype); id, *codectype);
} }
} */ }
return ret; return ret;
} }
@@ -641,7 +645,7 @@ void btfmcodec_wq_hwep_configure(struct work_struct *work)
int ret; int ret;
int idx = BTM_PKT_TYPE_HWEP_CONFIG; int idx = BTM_PKT_TYPE_HWEP_CONFIG;
uint32_t sample_rate, direction; 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) { list_for_each_entry(hwep_configs, head, dai_list) {
id = hwep_configs->stream_id; id = hwep_configs->stream_id;
@@ -649,11 +653,12 @@ void btfmcodec_wq_hwep_configure(struct work_struct *work)
bit_width = hwep_configs->bit_width; bit_width = hwep_configs->bit_width;
codectype = hwep_configs->codectype; codectype = hwep_configs->codectype;
direction = hwep_configs->direction; 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); BTFMCODEC_INFO("configuring dai id:%d with sampling rate:%d bit_width:%d", id, sample_rate, bit_width);
ret = btfmcodec_hwep_startup(btfmcodec); ret = btfmcodec_hwep_startup(btfmcodec);
if (ret >= 0) 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) if (ret >= 0)
ret = btfmcodec_hwep_prepare(btfmcodec, sample_rate, direction, id); ret = btfmcodec_hwep_prepare(btfmcodec, sample_rate, direction, id);
if (ret < 0) { if (ret < 0) {

View File

@@ -27,6 +27,7 @@ struct hwep_configurations {
uint8_t bit_width; uint8_t bit_width;
uint8_t codectype; uint8_t codectype;
uint32_t direction; uint32_t direction;
uint8_t num_channels;
struct list_head dai_list; struct list_head dai_list;
}; };
@@ -51,7 +52,7 @@ struct hwep_comp_drv {
struct hwep_dai_ops { struct hwep_dai_ops {
int (*hwep_startup)(void *); int (*hwep_startup)(void *);
void (*hwep_shutdown)(void *, int); 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_prepare)(void *, uint32_t, uint32_t, int);
int (*hwep_set_channel_map)(void *, unsigned int, unsigned int *, int (*hwep_set_channel_map)(void *, unsigned int, unsigned int *,
unsigned int, unsigned int *); unsigned int, unsigned int *);

View File

@@ -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, 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 hwep_data *hwep_info = (struct hwep_data *)dai;
struct btfmslim *btfmslim = dev_get_drvdata(hwep_info->dev); struct btfmslim *btfmslim = dev_get_drvdata(hwep_info->dev);