sound/soc/mediatek/mt8365/mt8365-dai-dmic.c

Source file repositories/reference/linux-study-clean/sound/soc/mediatek/mt8365/mt8365-dai-dmic.c

File Facts

System
Linux kernel
Corpus path
sound/soc/mediatek/mt8365/mt8365-dai-dmic.c
Extension
.c
Size
8106 bytes
Lines
311
Domain
Driver Families
Bucket
sound/soc
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct mt8365_dmic_data {
	bool two_wire_mode;
	unsigned int clk_phase_sel_ch1;
	unsigned int clk_phase_sel_ch2;
	bool iir_on;
	unsigned int irr_mode;
	unsigned int dmic_mode;
	unsigned int dmic_channel;
};

static int get_chan_reg(unsigned int channel)
{
	switch (channel) {
	case 8:
		fallthrough;
	case 7:
		return AFE_DMIC3_UL_SRC_CON0;
	case 6:
		fallthrough;
	case 5:
		return AFE_DMIC2_UL_SRC_CON0;
	case 4:
		fallthrough;
	case 3:
		return AFE_DMIC1_UL_SRC_CON0;
	case 2:
		fallthrough;
	case 1:
		return AFE_DMIC0_UL_SRC_CON0;
	default:
		return -EINVAL;
	}
}

/* DAI Drivers */

static void audio_dmic_adda_enable(struct mtk_base_afe *afe)
{
	mt8365_dai_enable_adda_on(afe);
	regmap_update_bits(afe->regmap, AFE_ADDA_UL_DL_CON0,
			   AFE_ADDA_UL_DL_DMIC_CLKDIV_ON,
			   AFE_ADDA_UL_DL_DMIC_CLKDIV_ON);
}

static void audio_dmic_adda_disable(struct mtk_base_afe *afe)
{
	regmap_update_bits(afe->regmap, AFE_ADDA_UL_DL_CON0,
			   AFE_ADDA_UL_DL_DMIC_CLKDIV_ON,
			   ~AFE_ADDA_UL_DL_DMIC_CLKDIV_ON);
	mt8365_dai_disable_adda_on(afe);
}

static void mt8365_dai_enable_dmic(struct mtk_base_afe *afe,
				   struct snd_pcm_substream *substream,
				   struct snd_soc_dai *dai)
{
	struct mt8365_afe_private *afe_priv = afe->platform_priv;
	struct mt8365_dmic_data *dmic_data = afe_priv->dai_priv[MT8365_AFE_IO_DMIC];
	unsigned int val_mask;
	int reg = get_chan_reg(dmic_data->dmic_channel);

	if (reg < 0)
		return;

	/* val and mask will be always same to enable */
	val_mask = DMIC_TOP_CON_CH1_ON |
		   DMIC_TOP_CON_CH2_ON |
		   DMIC_TOP_CON_SRC_ON;

	regmap_update_bits(afe->regmap, reg, val_mask, val_mask);
}

static void mt8365_dai_disable_dmic(struct mtk_base_afe *afe,
				    struct snd_pcm_substream *substream,
				    struct snd_soc_dai *dai)
{
	struct mt8365_afe_private *afe_priv = afe->platform_priv;
	struct mt8365_dmic_data *dmic_data = afe_priv->dai_priv[MT8365_AFE_IO_DMIC];
	unsigned int mask;
	int reg = get_chan_reg(dmic_data->dmic_channel);

	if (reg < 0)
		return;

	dev_dbg(afe->dev, "%s dmic_channel %d\n", __func__, dmic_data->dmic_channel);

	mask = DMIC_TOP_CON_CH1_ON |
	       DMIC_TOP_CON_CH2_ON |
	       DMIC_TOP_CON_SRC_ON |
	       DMIC_TOP_CON_SDM3_LEVEL_MODE;

Annotation

Implementation Notes