Skip to content

Commit

Permalink
copier: dmic: enable gain for dmic dai
Browse files Browse the repository at this point in the history
Enable gain for DMIC interface. Configure gain feature based on
paremeters received in DMIC BLOB.

Signed-off-by: Ievgen Ganakov <[email protected]>
  • Loading branch information
iganakov committed Jul 24, 2024
1 parent ed5c2d7 commit da2e26f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/audio/copier/copier_dai.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ int copier_dai_create(struct comp_dev *dev, struct copier_data *cd,
return -EINVAL;
}
dai.out_fmt = &copier->out_fmt;

#if CONFIG_COPIER_GAIN
/* Enable gain for DMIC interface */
dai.apply_gain = true;
#endif
break;
default:
return -EINVAL;
Expand Down
53 changes: 53 additions & 0 deletions src/audio/copier/copier_gain.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <ipc4/base-config.h>
#include <sof/audio/component_ext.h>
#include <module/module/base.h>
#include <sof/tlv.h>
#include <ipc4/dmic.h>
#include "copier.h"
#include "copier_gain.h"

Expand All @@ -27,6 +29,32 @@ int copier_gain_set_params(struct comp_dev *dev, struct dai_data *dd)
/* Set basic gain parameters */
copier_gain_set_basic_params(dev, dd);

switch (dd->dai->type) {
case SOF_DAI_INTEL_DMIC:
{
struct dmic_config_data *dmic_gtw_cfg = cd->gtw_cfg;
struct dmic_ext_global_cfg *dmic_ext_glb_cfg =
&dmic_gtw_cfg->dmic_blob.global_cfg.ext_cfg;

if (!dmic_ext_glb_cfg) {
comp_err(dev, "No dmic global config found");
return -EINVAL;
}

fade_period = dmic_ext_glb_cfg->fade_in_period;
/* Convert and assign silence and fade length values received
* in DMIC blob.
*/
gain_params->silence_sg_length =
frames * dmic_ext_glb_cfg->silence_period;
gain_params->fade_sg_length = frames * fade_period;
}
break;
default:
comp_info(dev, "Apply default fade period for dai type %d", dd->dai->type);
break;
}

/* Set fade parameters */
ret = copier_gain_set_fade_params(dev, dd, fade_period, frames);
if (ret)
Expand Down Expand Up @@ -78,13 +106,15 @@ int copier_gain_dma_control(uint32_t node_id, const uint32_t *config_data,
size_t config_size, enum sof_ipc_dai_type dai_type)
{
union ipc4_connector_node_id node = (union ipc4_connector_node_id)node_id;
struct sof_tlv *tlv = (struct sof_tlv *)config_data;
struct gain_dma_control_data *gain_data = NULL;
struct ipc_comp_dev *icd = NULL;
struct processing_module *mod = NULL;
struct copier_data *cd = NULL;
struct ipc *ipc = ipc_get();
struct list_item *clist;
struct comp_dev *dev;
void *tlv_val;
int ret;

list_for_item(clist, &ipc->comp_list) {
Expand All @@ -101,6 +131,29 @@ int copier_gain_dma_control(uint32_t node_id, const uint32_t *config_data,
mod = comp_mod(dev);
cd = module_get_private_data(mod);

switch (dai_type) {
case SOF_DAI_INTEL_DMIC:
if (cd->dd[0]->dai->index != node.f.v_index)
continue;

if (!config_size) {
comp_err(dev, "Config length for DMIC couldn't be zero");
return -EINVAL;
}

/* Gain coefficients for DMIC */
tlv_val = tlv_value_ptr_get(tlv, DMIC_SET_GAIN_COEFFICIENTS);
if (!tlv_val) {
comp_err(dev, "No gain coefficients in DMA_CONTROL ipc");
return -EINVAL;
}
gain_data = tlv_val;
break;
default:
comp_warn(dev, "Gain DMA control: no dai type=%d found", dai_type);
break;
}

ret = copier_set_gain(dev, cd->dd[0], gain_data);
if (ret)
comp_err(dev, "Gain DMA control: failed to set gain");
Expand Down

0 comments on commit da2e26f

Please sign in to comment.