ASoC: mediatek: mt8188-mt6359: support dynamic pinctrl
authorTrevor Wu <trevor.wu@mediatek.com>
Fri, 25 Aug 2023 02:49:33 +0000 (10:49 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 28 Nov 2023 17:19:42 +0000 (17:19 +0000)
[ Upstream commit d601bb78f06b9e3cbb52e6b87b88add9920a11b6 ]

To avoid power leakage, it is recommended to replace the default pinctrl
state with dynamic pinctrl since certain audio pinmux functions can
remain in a HIGH state even when audio is disabled. Linking pinctrl with
DAPM using SND_SOC_DAPM_PINCTRL will ensure that audio pins remain in
GPIO mode by default and only switch to an audio function when necessary.

Signed-off-by: Trevor Wu <trevor.wu@mediatek.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Link: https://lore.kernel.org/r/20230825024935.10878-2-trevor.wu@mediatek.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
sound/soc/mediatek/mt8188/mt8188-mt6359.c

index 9017f48..f7e22ab 100644 (file)
@@ -246,6 +246,11 @@ static const struct snd_soc_dapm_widget mt8188_mt6359_widgets[] = {
        SND_SOC_DAPM_MIC("Headset Mic", NULL),
        SND_SOC_DAPM_SINK("HDMI"),
        SND_SOC_DAPM_SINK("DP"),
+
+       /* dynamic pinctrl */
+       SND_SOC_DAPM_PINCTRL("ETDM_SPK_PIN", "aud_etdm_spk_on", "aud_etdm_spk_off"),
+       SND_SOC_DAPM_PINCTRL("ETDM_HP_PIN", "aud_etdm_hp_on", "aud_etdm_hp_off"),
+       SND_SOC_DAPM_PINCTRL("MTKAIF_PIN", "aud_mtkaif_on", "aud_mtkaif_off"),
 };
 
 static const struct snd_kcontrol_new mt8188_mt6359_controls[] = {
@@ -267,6 +272,7 @@ static int mt8188_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd)
                snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
        struct snd_soc_component *cmpnt_codec =
                asoc_rtd_to_codec(rtd, 0)->component;
+       struct snd_soc_dapm_widget *pin_w = NULL, *w;
        struct mtk_base_afe *afe;
        struct mt8188_afe_private *afe_priv;
        struct mtkaif_param *param;
@@ -306,6 +312,18 @@ static int mt8188_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd)
                return 0;
        }
 
+       for_each_card_widgets(rtd->card, w) {
+               if (!strcmp(w->name, "MTKAIF_PIN")) {
+                       pin_w = w;
+                       break;
+               }
+       }
+
+       if (pin_w)
+               dapm_pinctrl_event(pin_w, NULL, SND_SOC_DAPM_PRE_PMU);
+       else
+               dev_dbg(afe->dev, "%s(), no pinmux widget, please check if default on\n", __func__);
+
        pm_runtime_get_sync(afe->dev);
        mt6359_mtkaif_calibration_enable(cmpnt_codec);
 
@@ -403,6 +421,9 @@ static int mt8188_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd)
        for (i = 0; i < MT8188_MTKAIF_MISO_NUM; i++)
                param->mtkaif_phase_cycle[i] = mtkaif_phase_cycle[i];
 
+       if (pin_w)
+               dapm_pinctrl_event(pin_w, NULL, SND_SOC_DAPM_POST_PMD);
+
        dev_dbg(afe->dev, "%s(), end, calibration ok %d\n",
                __func__, param->mtkaif_calibration_ok);