diff --git a/sound/soc/codecs/msm8x16-wcd.c b/sound/soc/codecs/msm8x16-wcd.c index fcc7af4379a9..b3311ec05af7 100644 --- a/sound/soc/codecs/msm8x16-wcd.c +++ b/sound/soc/codecs/msm8x16-wcd.c @@ -170,6 +170,7 @@ static struct msm8x16_wcd_pdata *msm8x16_wcd_populate_dt_pdata( struct device *dev); static int msm8x16_wcd_enable_ext_mb_source(struct snd_soc_codec *codec, bool turn_on); +static void msm8x16_trim_btn_reg(struct snd_soc_codec *codec); struct msm8x16_wcd_spmi msm8x16_wcd_modules[MAX_MSM8X16_WCD_DEVICE]; @@ -179,6 +180,7 @@ static struct snd_soc_codec *registered_codec; static const struct wcd_mbhc_cb mbhc_cb = { .enable_mb_source = msm8x16_wcd_enable_ext_mb_source, + .trim_btn_reg = msm8x16_trim_btn_reg, }; int msm8x16_unregister_notifier(struct snd_soc_codec *codec, @@ -1812,6 +1814,26 @@ static int msm8x16_wcd_codec_enable_dmic(struct snd_soc_dapm_widget *w, return 0; } +static void msm8x16_trim_btn_reg(struct snd_soc_codec *codec) +{ + struct msm8x16_wcd_priv *msm8x16_wcd = snd_soc_codec_get_drvdata(codec); + + if (TOMBAK_IS_1_0(msm8x16_wcd->pmic_rev)) { + pr_debug("%s: This device needs to be trimmed\n", __func__); + /* + * Calculate the trim value for each device used + * till is comes in production by hardware team + */ + snd_soc_update_bits(codec, + MSM8X16_WCD_A_ANALOG_SEC_ACCESS, + 0xA5, 0xA5); + snd_soc_update_bits(codec, + MSM8X16_WCD_A_ANALOG_TRIM_CTRL2, + 0xFF, 0x30); + } else { + pr_debug("%s: This device is trimmed at ATE\n", __func__); + } +} static int msm8x16_wcd_enable_ext_mb_source(struct snd_soc_codec *codec, bool turn_on) { diff --git a/sound/soc/codecs/wcd-mbhc-v2.c b/sound/soc/codecs/wcd-mbhc-v2.c index ac3af2560068..22d6ca0c1d96 100644 --- a/sound/soc/codecs/wcd-mbhc-v2.c +++ b/sound/soc/codecs/wcd-mbhc-v2.c @@ -1121,16 +1121,9 @@ static void wcd_mbhc_swch_irq_handler(struct wcd_mbhc *mbhc) snd_soc_update_bits(codec, MSM8X16_WCD_A_ANALOG_MBHC_FSM_CTL, 0x80, 0x80); - /* - * Calculate the trim value for each device used - * till is comes in production by hardware team. - */ - snd_soc_update_bits(codec, - MSM8X16_WCD_A_ANALOG_SEC_ACCESS, - 0xA5, 0xA5); - snd_soc_update_bits(codec, - MSM8X16_WCD_A_ANALOG_TRIM_CTRL2, - 0xFF, 0x30); + /* Apply trim if needed on the device */ + if (mbhc->mbhc_cb && mbhc->mbhc_cb->trim_btn_reg) + mbhc->mbhc_cb->trim_btn_reg(codec); wcd_mbhc_detect_plug_type(mbhc); } else if ((mbhc->current_plug != MBHC_PLUG_TYPE_NONE) && !detection_type) { diff --git a/sound/soc/codecs/wcd-mbhc-v2.h b/sound/soc/codecs/wcd-mbhc-v2.h index d4eff3a2a200..aba9a875c4ef 100644 --- a/sound/soc/codecs/wcd-mbhc-v2.h +++ b/sound/soc/codecs/wcd-mbhc-v2.h @@ -64,6 +64,7 @@ struct wcd_mbhc_intr { struct wcd_mbhc_cb { int (*enable_mb_source) (struct snd_soc_codec *, bool); + void (*trim_btn_reg) (struct snd_soc_codec *); }; struct wcd_mbhc {