diff --git a/asoc/codecs/wcd937x/wcd937x-mbhc.c b/asoc/codecs/wcd937x/wcd937x-mbhc.c index d1a36ba72d..f83271b083 100644 --- a/asoc/codecs/wcd937x/wcd937x-mbhc.c +++ b/asoc/codecs/wcd937x/wcd937x-mbhc.c @@ -721,6 +721,63 @@ static void wcd937x_mbhc_moisture_config(struct wcd_mbhc *mbhc) 0x0C, mbhc->moist_rref << 2); } +static void wcd937x_mbhc_moisture_detect_en(struct wcd_mbhc *mbhc, bool enable) +{ + struct snd_soc_codec *codec = mbhc->codec; + + if (enable) + snd_soc_update_bits(codec, WCD937X_MBHC_NEW_CTL_2, + 0x0C, mbhc->moist_rref << 2); + else + snd_soc_update_bits(codec, WCD937X_MBHC_NEW_CTL_2, + 0x0C, R_OFF << 2); +} + +static bool wcd937x_mbhc_get_moisture_status(struct wcd_mbhc *mbhc) +{ + struct snd_soc_codec *codec = mbhc->codec; + bool ret = false; + + if ((mbhc->moist_rref == R_OFF) || + (mbhc->mbhc_cfg->enable_usbc_analog)) { + snd_soc_update_bits(codec, WCD937X_MBHC_NEW_CTL_2, + 0x0C, R_OFF << 2); + goto done; + } + + /* Do not enable moisture detection if jack type is NC */ + if (!mbhc->hphl_swh) { + dev_dbg(codec->dev, "%s: disable moisture detection for NC\n", + __func__); + snd_soc_update_bits(codec, WCD937X_MBHC_NEW_CTL_2, + 0x0C, R_OFF << 2); + goto done; + } + + /* If moisture_en is already enabled, then skip to plug type + * detection. + */ + if ((snd_soc_update_bits(codec, WCD937X_MBHC_NEW_CTL_2) & 0x0C)) + goto done; + + wcd937x_mbhc_moisture_detect_en(mbhc, true); + /* Read moisture comparator status */ + ret = ((snd_soc_read(codec, WCD937X_MBHC_NEW_FSM_STATUS) + & 0x20) ? 0 : 1); + +done: + return ret; + +} + +static void wcd937x_mbhc_moisture_polling_ctrl(struct wcd_mbhc *mbhc, + bool enable) +{ + snd_soc_update_bits(codec, + WCD937X_MBHC_NEW_INT_MOISTURE_DET_POLLING_CTRL, + 0x04, (enable << 2)); +} + static const struct wcd_mbhc_cb mbhc_cb = { .request_irq = wcd937x_mbhc_request_irq, .irq_control = wcd937x_mbhc_irq_control, @@ -742,6 +799,9 @@ static const struct wcd_mbhc_cb mbhc_cb = { .mbhc_gnd_det_ctrl = wcd937x_mbhc_gnd_det_ctrl, .hph_pull_down_ctrl = wcd937x_mbhc_hph_pull_down_ctrl, .mbhc_moisture_config = wcd937x_mbhc_moisture_config, + .mbhc_get_moisture_status = wcd937x_mbhc_get_moisture_status, + .mbhc_moisture_polling_ctrl = wcd937x_mbhc_moisture_polling_ctrl, + .mbhc_moisture_detect_en = wcd937x_mbhc_moisture_detect_en, }; static int wcd937x_get_hph_type(struct snd_kcontrol *kcontrol,