Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6c5713fe authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "ASoC: msm8996: Update speaker path gain offset for WSA8810"

parents af6aabe1 0b9726d2
Loading
Loading
Loading
Loading
+172 −78
Original line number Diff line number Diff line
@@ -753,6 +753,7 @@ struct tasha_priv {

	int (*machine_codec_event_cb)(struct snd_soc_codec *codec,
				      enum wcd9335_codec_event);
	int spkr_gain_offset;
	int spkr_mode;
	struct hpf_work tx_hpf_work[TASHA_NUM_DECIMATORS];
	struct tx_mute_work tx_mute_dwork[TASHA_NUM_DECIMATORS];
@@ -779,6 +780,27 @@ static const struct tasha_reg_mask_val tasha_spkr_mode1[] = {
	{WCD9335_CDC_BOOST1_BOOST_CTL, 0x7C, 0x34},
};

/**
 * tasha_set_spkr_gain_offset - offset the speaker path
 * gain with the given offset value.
 *
 * @codec: codec instance
 * @offset: Indicates speaker path gain offset value.
 *
 * Returns 0 on success or -EINVAL on error.
 */
int tasha_set_spkr_gain_offset(struct snd_soc_codec *codec, int offset)
{
	struct tasha_priv *priv = snd_soc_codec_get_drvdata(codec);

	if (!priv)
		return -EINVAL;

	priv->spkr_gain_offset = offset;
	return 0;
}
EXPORT_SYMBOL(tasha_set_spkr_gain_offset);

/**
 * tasha_set_spkr_mode - Configures speaker compander and smartboost
 * settings based on speaker mode.
@@ -4303,13 +4325,13 @@ static int tasha_codec_enable_mix_path(struct snd_soc_dapm_widget *w,
		struct snd_kcontrol *kcontrol, int event)
{
	struct snd_soc_codec *codec = w->codec;
	struct tasha_priv *tasha = snd_soc_codec_get_drvdata(codec);
	u16 gain_reg;
	int offset_val = 0;
	int val = 0;

	dev_dbg(codec->dev, "%s %d %s\n", __func__, event, w->name);

	switch (event) {
	case SND_SOC_DAPM_POST_PMU:
		/* apply gain after int clk is enabled */
	switch (w->reg) {
	case WCD9335_CDC_RX0_RX_PATH_MIX_CTL:
		gain_reg = WCD9335_CDC_RX0_RX_VOL_MIX_CTL;
@@ -4343,7 +4365,51 @@ static int tasha_codec_enable_mix_path(struct snd_soc_dapm_widget *w,
			__func__, w->name);
		return 0;
	};
		snd_soc_write(codec, gain_reg, snd_soc_read(codec, gain_reg));

	switch (event) {
	case SND_SOC_DAPM_POST_PMU:
		if ((tasha->spkr_gain_offset == RX_GAIN_OFFSET_M1P5_DB) &&
		    (tasha->comp_enabled[COMPANDER_7] ||
		     tasha->comp_enabled[COMPANDER_8]) &&
		    (gain_reg == WCD9335_CDC_RX7_RX_VOL_MIX_CTL ||
		     gain_reg == WCD9335_CDC_RX8_RX_VOL_MIX_CTL)) {
			snd_soc_update_bits(codec, WCD9335_CDC_RX7_RX_PATH_SEC1,
					    0x01, 0x01);
			snd_soc_update_bits(codec,
					    WCD9335_CDC_RX7_RX_PATH_MIX_SEC0,
					    0x01, 0x01);
			snd_soc_update_bits(codec, WCD9335_CDC_RX8_RX_PATH_SEC1,
					    0x01, 0x01);
			snd_soc_update_bits(codec,
					    WCD9335_CDC_RX8_RX_PATH_MIX_SEC0,
					    0x01, 0x01);
			offset_val = -2;
		}
		val = snd_soc_read(codec, gain_reg);
		val += offset_val;
		snd_soc_write(codec, gain_reg, val);
		break;
	case SND_SOC_DAPM_POST_PMD:
		if ((tasha->spkr_gain_offset == RX_GAIN_OFFSET_M1P5_DB) &&
		    (tasha->comp_enabled[COMPANDER_7] ||
		     tasha->comp_enabled[COMPANDER_8]) &&
		    (gain_reg == WCD9335_CDC_RX7_RX_VOL_MIX_CTL ||
		     gain_reg == WCD9335_CDC_RX8_RX_VOL_MIX_CTL)) {
			snd_soc_update_bits(codec, WCD9335_CDC_RX7_RX_PATH_SEC1,
					    0x01, 0x00);
			snd_soc_update_bits(codec,
					    WCD9335_CDC_RX7_RX_PATH_MIX_SEC0,
					    0x01, 0x00);
			snd_soc_update_bits(codec, WCD9335_CDC_RX8_RX_PATH_SEC1,
					    0x01, 0x00);
			snd_soc_update_bits(codec,
					    WCD9335_CDC_RX8_RX_PATH_MIX_SEC0,
					    0x01, 0x00);
			offset_val = 2;
			val = snd_soc_read(codec, gain_reg);
			val += offset_val;
			snd_soc_write(codec, gain_reg, val);
		}
		break;
	};

@@ -4478,30 +4544,42 @@ static int tasha_codec_enable_interpolator(struct snd_soc_dapm_widget *w,
		struct snd_kcontrol *kcontrol, int event)
{
	struct snd_soc_codec *codec = w->codec;
	struct tasha_priv *tasha = snd_soc_codec_get_drvdata(codec);
	u16 gain_reg;
	u16 reg;
	int val;
	int offset_val = 0;

	dev_dbg(codec->dev, "%s %d %s\n", __func__, event, w->name);

	if (!(strcmp(w->name, "RX INT0 INTERP")))
	if (!(strcmp(w->name, "RX INT0 INTERP"))) {
		reg = WCD9335_CDC_RX0_RX_PATH_CTL;
	else if (!(strcmp(w->name, "RX INT1 INTERP")))
		gain_reg = WCD9335_CDC_RX0_RX_VOL_CTL;
	} else if (!(strcmp(w->name, "RX INT1 INTERP"))) {
		reg = WCD9335_CDC_RX1_RX_PATH_CTL;
	else if (!(strcmp(w->name, "RX INT2 INTERP")))
		gain_reg = WCD9335_CDC_RX1_RX_VOL_CTL;
	} else if (!(strcmp(w->name, "RX INT2 INTERP"))) {
		reg = WCD9335_CDC_RX2_RX_PATH_CTL;
	else if (!(strcmp(w->name, "RX INT3 INTERP")))
		gain_reg = WCD9335_CDC_RX2_RX_VOL_CTL;
	} else if (!(strcmp(w->name, "RX INT3 INTERP"))) {
		reg = WCD9335_CDC_RX3_RX_PATH_CTL;
	else if (!(strcmp(w->name, "RX INT4 INTERP")))
		gain_reg = WCD9335_CDC_RX3_RX_VOL_CTL;
	} else if (!(strcmp(w->name, "RX INT4 INTERP"))) {
		reg = WCD9335_CDC_RX4_RX_PATH_CTL;
	else if (!(strcmp(w->name, "RX INT5 INTERP")))
		gain_reg = WCD9335_CDC_RX4_RX_VOL_CTL;
	} else if (!(strcmp(w->name, "RX INT5 INTERP"))) {
		reg = WCD9335_CDC_RX5_RX_PATH_CTL;
	else if (!(strcmp(w->name, "RX INT6 INTERP")))
		gain_reg = WCD9335_CDC_RX5_RX_VOL_CTL;
	} else if (!(strcmp(w->name, "RX INT6 INTERP"))) {
		reg = WCD9335_CDC_RX6_RX_PATH_CTL;
	else if (!(strcmp(w->name, "RX INT7 INTERP")))
		gain_reg = WCD9335_CDC_RX6_RX_VOL_CTL;
	} else if (!(strcmp(w->name, "RX INT7 INTERP"))) {
		reg = WCD9335_CDC_RX7_RX_PATH_CTL;
	else if (!(strcmp(w->name, "RX INT8 INTERP")))
		gain_reg = WCD9335_CDC_RX7_RX_VOL_CTL;
	} else if (!(strcmp(w->name, "RX INT8 INTERP"))) {
		reg = WCD9335_CDC_RX8_RX_PATH_CTL;
	else {
		gain_reg = WCD9335_CDC_RX8_RX_VOL_CTL;
	} else {
		dev_err(codec->dev, "%s: Interpolator reg not found\n",
			__func__);
		return -EINVAL;
@@ -4514,36 +4592,51 @@ static int tasha_codec_enable_interpolator(struct snd_soc_dapm_widget *w,
		break;
	case SND_SOC_DAPM_POST_PMU:
		tasha_config_compander(codec, w->shift, event);

		/* apply gain after int clk is enabled */
		if (reg == WCD9335_CDC_RX0_RX_PATH_CTL)
			gain_reg = WCD9335_CDC_RX0_RX_VOL_CTL;
		else if (reg == WCD9335_CDC_RX1_RX_PATH_CTL)
			gain_reg = WCD9335_CDC_RX1_RX_VOL_CTL;
		else if (reg == WCD9335_CDC_RX2_RX_PATH_CTL)
			gain_reg = WCD9335_CDC_RX2_RX_VOL_CTL;
		else if (reg == WCD9335_CDC_RX3_RX_PATH_CTL)
			gain_reg = WCD9335_CDC_RX3_RX_VOL_CTL;
		else if (reg == WCD9335_CDC_RX4_RX_PATH_CTL)
			gain_reg = WCD9335_CDC_RX4_RX_VOL_CTL;
		else if (reg == WCD9335_CDC_RX5_RX_PATH_CTL)
			gain_reg = WCD9335_CDC_RX5_RX_VOL_CTL;
		else if (reg == WCD9335_CDC_RX6_RX_PATH_CTL)
			gain_reg = WCD9335_CDC_RX6_RX_VOL_CTL;
		else if (reg == WCD9335_CDC_RX7_RX_PATH_CTL)
			gain_reg = WCD9335_CDC_RX7_RX_VOL_CTL;
		else if (reg == WCD9335_CDC_RX8_RX_PATH_CTL)
			gain_reg = WCD9335_CDC_RX8_RX_VOL_CTL;
		else {
			dev_err(codec->dev, "%s: No gain register avail for %s\n",
				__func__, w->name);
			return 0;
		if ((tasha->spkr_gain_offset == RX_GAIN_OFFSET_M1P5_DB) &&
		    (tasha->comp_enabled[COMPANDER_7] ||
		     tasha->comp_enabled[COMPANDER_8]) &&
		    (gain_reg == WCD9335_CDC_RX7_RX_VOL_CTL ||
		     gain_reg == WCD9335_CDC_RX8_RX_VOL_CTL)) {
			snd_soc_update_bits(codec, WCD9335_CDC_RX7_RX_PATH_SEC1,
					    0x01, 0x01);
			snd_soc_update_bits(codec,
					    WCD9335_CDC_RX7_RX_PATH_MIX_SEC0,
					    0x01, 0x01);
			snd_soc_update_bits(codec, WCD9335_CDC_RX8_RX_PATH_SEC1,
					    0x01, 0x01);
			snd_soc_update_bits(codec,
					    WCD9335_CDC_RX8_RX_PATH_MIX_SEC0,
					    0x01, 0x01);
			offset_val = -2;
		}
		snd_soc_write(codec, gain_reg, snd_soc_read(codec, gain_reg));
		val = snd_soc_read(codec, gain_reg);
		val += offset_val;
		snd_soc_write(codec, gain_reg, val);
		break;
	case SND_SOC_DAPM_POST_PMD:
		tasha_config_compander(codec, w->shift, event);
		tasha_codec_enable_prim_interpolator(codec, reg, event);
		if ((tasha->spkr_gain_offset == RX_GAIN_OFFSET_M1P5_DB) &&
		    (tasha->comp_enabled[COMPANDER_7] ||
		     tasha->comp_enabled[COMPANDER_8]) &&
		    (gain_reg == WCD9335_CDC_RX7_RX_VOL_CTL ||
		     gain_reg == WCD9335_CDC_RX8_RX_VOL_CTL)) {
			snd_soc_update_bits(codec, WCD9335_CDC_RX7_RX_PATH_SEC1,
					    0x01, 0x00);
			snd_soc_update_bits(codec,
					    WCD9335_CDC_RX7_RX_PATH_MIX_SEC0,
					    0x01, 0x00);
			snd_soc_update_bits(codec, WCD9335_CDC_RX8_RX_PATH_SEC1,
					    0x01, 0x00);
			snd_soc_update_bits(codec,
					    WCD9335_CDC_RX8_RX_PATH_MIX_SEC0,
					    0x01, 0x00);
			offset_val = 2;
			val = snd_soc_read(codec, gain_reg);
			val += offset_val;
			snd_soc_write(codec, gain_reg, val);
		}
		break;
	};

@@ -11645,6 +11738,7 @@ static int tasha_codec_probe(struct snd_soc_codec *codec)
	for (i = 0; i < COMPANDER_MAX; i++)
		tasha->comp_enabled[i] = 0;

	tasha->spkr_gain_offset = RX_GAIN_OFFSET_0_DB;
	tasha_update_reg_reset_values(codec);
	pr_debug("%s: MCLK Rate = %x\n", __func__, control->mclk_rate);
	if (control->mclk_rate == TASHA_MCLK_CLK_12P288MHZ)
+9 −0
Original line number Diff line number Diff line
@@ -114,6 +114,14 @@ enum {
	SPKR_MODE_1,          /* COMP Gain = 12dB, Smartboost Max = 5.5V */
};

/*
 * Rx path gain offsets
 */
enum {
	RX_GAIN_OFFSET_M1P5_DB,
	RX_GAIN_OFFSET_0_DB,
};

extern void *tasha_get_afe_config(struct snd_soc_codec *codec,
				  enum afe_config_type config_type);
extern int tasha_cdc_mclk_enable(struct snd_soc_codec *codec, int enable,
@@ -135,4 +143,5 @@ extern int tasha_codec_enable_standalone_micbias(struct snd_soc_codec *codec,
						 int micb_num,
						 bool enable);
extern int tasha_set_spkr_mode(struct snd_soc_codec *codec, int mode);
extern int tasha_set_spkr_gain_offset(struct snd_soc_codec *codec, int offset);
#endif
+4 −2
Original line number Diff line number Diff line
@@ -1869,9 +1869,11 @@ static int msm_audrx_init(struct snd_soc_pcm_runtime *rtd)
	 */
	if (rtd_aux && rtd_aux->component)
		if (!strcmp(rtd_aux->component->name, WSA8810_NAME_1) ||
		    !strcmp(rtd_aux->component->name, WSA8810_NAME_2))
		    !strcmp(rtd_aux->component->name, WSA8810_NAME_2)) {
			tasha_set_spkr_mode(rtd->codec, SPKR_MODE_1);

			tasha_set_spkr_gain_offset(rtd->codec,
						   RX_GAIN_OFFSET_M1P5_DB);
	}
	codec_reg_done = true;

	card = rtd->card->snd_card;