sound/soc/mediatek/mt8186/mt8186-dai-hw-gain.c

Source file repositories/reference/linux-study-clean/sound/soc/mediatek/mt8186/mt8186-dai-hw-gain.c

File Facts

System
Linux kernel
Corpus path
sound/soc/mediatek/mt8186/mt8186-dai-hw-gain.c
Extension
.c
Size
6878 bytes
Lines
237
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

if (snd_soc_dapm_widget_name_cmp(w, HW_GAIN_1_EN_W_NAME) == 0) {
			gain_cur = AFE_GAIN1_CUR;
			gain_con1 = AFE_GAIN1_CON1;
		} else {
			gain_cur = AFE_GAIN2_CUR;
			gain_con1 = AFE_GAIN2_CON1;
		}

		/* let hw gain ramp up, set cur gain to 0 */
		regmap_update_bits(afe->regmap, gain_cur, AFE_GAIN1_CUR_MASK_SFT, 0);

		/* set target gain to 0 */
		regmap_update_bits(afe->regmap, gain_con1, GAIN1_TARGET_MASK_SFT, 0);
		break;
	default:
		break;
	}

	return 0;
}

static const struct snd_soc_dapm_widget mtk_dai_hw_gain_widgets[] = {
	/* inter-connections */
	SND_SOC_DAPM_MIXER("HW_GAIN1_IN_CH1", SND_SOC_NOPM, 0, 0,
			   mtk_hw_gain1_in_ch1_mix,
			   ARRAY_SIZE(mtk_hw_gain1_in_ch1_mix)),
	SND_SOC_DAPM_MIXER("HW_GAIN1_IN_CH2", SND_SOC_NOPM, 0, 0,
			   mtk_hw_gain1_in_ch2_mix,
			   ARRAY_SIZE(mtk_hw_gain1_in_ch2_mix)),
	SND_SOC_DAPM_MIXER("HW_GAIN2_IN_CH1", SND_SOC_NOPM, 0, 0,
			   mtk_hw_gain2_in_ch1_mix,
			   ARRAY_SIZE(mtk_hw_gain2_in_ch1_mix)),
	SND_SOC_DAPM_MIXER("HW_GAIN2_IN_CH2", SND_SOC_NOPM, 0, 0,
			   mtk_hw_gain2_in_ch2_mix,
			   ARRAY_SIZE(mtk_hw_gain2_in_ch2_mix)),

	SND_SOC_DAPM_SUPPLY(HW_GAIN_1_EN_W_NAME,
			    AFE_GAIN1_CON0, GAIN1_ON_SFT, 0,
			    mtk_hw_gain_event,
			    SND_SOC_DAPM_PRE_PMU),

	SND_SOC_DAPM_SUPPLY(HW_GAIN_2_EN_W_NAME,
			    AFE_GAIN2_CON0, GAIN2_ON_SFT, 0,
			    mtk_hw_gain_event,
			    SND_SOC_DAPM_PRE_PMU),

	SND_SOC_DAPM_INPUT("HW Gain 1 Out Endpoint"),
	SND_SOC_DAPM_INPUT("HW Gain 2 Out Endpoint"),
	SND_SOC_DAPM_OUTPUT("HW Gain 1 In Endpoint"),
};

static const struct snd_soc_dapm_route mtk_dai_hw_gain_routes[] = {
	{"HW Gain 1 In", NULL, "HW_GAIN1_IN_CH1"},
	{"HW Gain 1 In", NULL, "HW_GAIN1_IN_CH2"},
	{"HW Gain 2 In", NULL, "HW_GAIN2_IN_CH1"},
	{"HW Gain 2 In", NULL, "HW_GAIN2_IN_CH2"},

	{"HW Gain 1 In", NULL, HW_GAIN_1_EN_W_NAME},
	{"HW Gain 1 Out", NULL, HW_GAIN_1_EN_W_NAME},
	{"HW Gain 2 In", NULL, HW_GAIN_2_EN_W_NAME},
	{"HW Gain 2 Out", NULL, HW_GAIN_2_EN_W_NAME},

	{"HW Gain 1 In Endpoint", NULL, "HW Gain 1 In"},
	{"HW Gain 1 Out", NULL, "HW Gain 1 Out Endpoint"},
	{"HW Gain 2 Out", NULL, "HW Gain 2 Out Endpoint"},
};

static const struct snd_kcontrol_new mtk_hw_gain_controls[] = {
	SOC_SINGLE("HW Gain 1 Volume", AFE_GAIN1_CON1,
		   GAIN1_TARGET_SFT, GAIN1_TARGET_MASK, 0),
	SOC_SINGLE("HW Gain 2 Volume", AFE_GAIN2_CON1,
		   GAIN2_TARGET_SFT, GAIN2_TARGET_MASK, 0),
};

/* dai ops */
static int mtk_dai_gain_hw_params(struct snd_pcm_substream *substream,
				  struct snd_pcm_hw_params *params,
				  struct snd_soc_dai *dai)
{
	struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
	unsigned int rate = params_rate(params);
	unsigned int rate_reg = mt8186_rate_transform(afe->dev, rate, dai->id);

	dev_dbg(afe->dev, "%s(), id %d, stream %d, rate %d\n",
		__func__, dai->id, substream->stream, rate);

	/* rate */
	regmap_update_bits(afe->regmap,
			   dai->id == MT8186_DAI_HW_GAIN_1 ?
			   AFE_GAIN1_CON0 : AFE_GAIN2_CON0,

Annotation

Implementation Notes