Message ID | 20230725035304.2864-2-trevor.wu@mediatek.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp2225659vqg; Mon, 24 Jul 2023 21:22:27 -0700 (PDT) X-Google-Smtp-Source: APBJJlEeZlNgHWo2wd52kbO3kuphzZkDvkiUkiSIBc4CT+EizGwS2+GxnP0SMpctmT7yRlF0Ai8N X-Received: by 2002:a17:906:3f1a:b0:998:de72:4c8c with SMTP id c26-20020a1709063f1a00b00998de724c8cmr1160092ejj.35.1690258947601; Mon, 24 Jul 2023 21:22:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690258947; cv=none; d=google.com; s=arc-20160816; b=fOTShbyG80Db4sK/4eM6JgnaLdR57DLTRMkWM7dwV0R8t7DizKMU67YiIE7YJAc72o ZDcjzpfs3bGclp1moG3gvwqgB5Q5LY7SSxAw5pIzXd4bb/fu+3bzXbvSAd36jDs9RCu1 kGWg3BYj0mcekOJcWwHW31esE02Vxl9A96nxPQ7lcjFoqoPB1eayk89oOn5eqYAGSgEv ta6ptnQMhVk85waZ6Un9qRpdDzccrux61gfCjEO76PMMhSOwAHsv1OZXv4IopeJGdnka kcaj61jW/jNqzGZShKjv2V4Q09XhZXG0g1YkUzgGc06+xPyu0JBnAluPOPNxZ7aZ+1HX Gt0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=bkuFlQZm1wGXwCPWMA9dpYXbQ7euJCFPWKLDx347OEc=; fh=OefNpeZjFU3zRj2edEV1JgSnXinLzjcidQ7oAoONT8A=; b=oxUB2xRDpnVm5GrlxnHPsyvkLStj4GplLQMmyXFDCGJvKeD5uopL5TLMoSJpVRI6Lq BRwUEIRklmOGkv6NuOtSjOnhy97n7tJefq1trBV6MR4axAnGqstmcDFZ/rI8tMCCZF7b MraE+tNzmaSdmwdNptBv5In3oPe5e0JSvC4OeRD1IGT48oCLng5vd658u5i8C2bs29cJ 9efCTFZZqNdmxAzqudmsKmC8Xzag0K6WlQQmTcO5B6Ua1a5hIZmqC+KW6rhb6iZN1D9s KUu/HWhROamtgQsX+bTXIYZo4eXHs3pt7Bqmkwy2uConvWm93a8isZNKg8jX+EhCzGuG sLbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=ubp69Jpr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h26-20020a1709066d9a00b0099ba5ef93d6si1223879ejt.891.2023.07.24.21.21.57; Mon, 24 Jul 2023 21:22:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=ubp69Jpr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230395AbjGYDxT (ORCPT <rfc822;kautuk.consul.80@gmail.com> + 99 others); Mon, 24 Jul 2023 23:53:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229945AbjGYDxS (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 24 Jul 2023 23:53:18 -0400 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55E4919A1 for <linux-kernel@vger.kernel.org>; Mon, 24 Jul 2023 20:53:13 -0700 (PDT) X-UUID: c414113a2a9e11ee9cb5633481061a41-20230725 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=bkuFlQZm1wGXwCPWMA9dpYXbQ7euJCFPWKLDx347OEc=; b=ubp69JprWmDfGzxGEXavzXr/gV6AImb1kHHIUJ9FvlPUTGtj7rUOfi5zyXeu1/Rfh/9YOFRzAw48yKE2m0A0ZixM/sQ3t4nRlF2cVYj+1c54F70zacFYS+XrAEiZOpNITmT1/TFZhk4OBTOhbAIhyCKaLmCJ9uvNdZNZAN8MZb8=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.29,REQID:8df923d3-a68e-4c15-b743-df486784f5f4,IP:0,U RL:0,TC:0,Content:-25,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:70 X-CID-INFO: VERSION:1.1.29,REQID:8df923d3-a68e-4c15-b743-df486784f5f4,IP:0,URL :0,TC:0,Content:-25,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Spam_GS981B3D,ACTI ON:quarantine,TS:70 X-CID-META: VersionHash:e7562a7,CLOUDID:575549d2-cd77-4e67-bbfd-aa4eaace762f,B ulkID:230725115308CPP61VZA,BulkQuantity:0,Recheck:0,SF:19|48|38|29|28|17,T C:nil,Content:0,EDM:-3,IP:nil,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 ,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_SDM,TF_CID_SPAM_ASC,TF_CID_SPAM_FAS, TF_CID_SPAM_FSD X-UUID: c414113a2a9e11ee9cb5633481061a41-20230725 Received: from mtkmbs14n2.mediatek.inc [(172.21.101.76)] by mailgw01.mediatek.com (envelope-from <trevor.wu@mediatek.com>) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 418060739; Tue, 25 Jul 2023 11:53:07 +0800 Received: from mtkmbs13n2.mediatek.inc (172.21.101.108) by mtkmbs13n2.mediatek.inc (172.21.101.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Tue, 25 Jul 2023 11:53:06 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs13n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Tue, 25 Jul 2023 11:53:06 +0800 From: Trevor Wu <trevor.wu@mediatek.com> To: <broonie@kernel.org>, <lgirdwood@gmail.com>, <tiwai@suse.com>, <perex@perex.cz>, <matthias.bgg@gmail.com>, <angelogioacchino.delregno@collabora.com> CC: <trevor.wu@mediatek.com>, <alsa-devel@alsa-project.org>, <linux-mediatek@lists.infradead.org>, <linux-arm-kernel@lists.infradead.org>, <linux-kernel@vger.kernel.org> Subject: [PATCH 1/3] ASoC: mediatek: mt8188-mt6359: support dynamic pinctrl Date: Tue, 25 Jul 2023 11:53:02 +0800 Message-ID: <20230725035304.2864-2-trevor.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20230725035304.2864-1-trevor.wu@mediatek.com> References: <20230725035304.2864-1-trevor.wu@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS, T_SCC_BODY_TEXT_LINE,T_SPF_TEMPERROR,UNPARSEABLE_RELAY,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772364966665086299 X-GMAIL-MSGID: 1772364966665086299 |
Series |
ASoC: mt8188-mt6359: add SOF support
|
|
Commit Message
Trevor Wu (吳文良)
July 25, 2023, 3:53 a.m. UTC
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>
---
sound/soc/mediatek/mt8188/mt8188-mt6359.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
Comments
Il 25/07/23 05:53, Trevor Wu ha scritto: > 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> > --- > sound/soc/mediatek/mt8188/mt8188-mt6359.c | 21 +++++++++++++++++++++ > 1 file changed, 21 insertions(+) > > diff --git a/sound/soc/mediatek/mt8188/mt8188-mt6359.c b/sound/soc/mediatek/mt8188/mt8188-mt6359.c > index 7c9e08e6a4f5..667d79f33bf2 100644 > --- a/sound/soc/mediatek/mt8188/mt8188-mt6359.c > +++ b/sound/soc/mediatek/mt8188/mt8188-mt6359.c > @@ -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")) { if (strncmp(w->name, "MTKAIF_PIN", strlen(w->name) == 0) { pin_w = w; break; } That's safer. > + pin_w = w; > + break; > + } > + } > + > + if (!pin_w) Just a nitpick: you're checking for `if (pin_w)` later in this function, so to increase readability please do the same here. if (pin_w) dapm_pinctrl_event(...) else dev_dbg(...) Regards, Angelo
On Tue, 2023-07-25 at 09:06 +0200, AngeloGioacchino Del Regno wrote: > Il 25/07/23 05:53, Trevor Wu ha scritto: > > 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> > > --- > > sound/soc/mediatek/mt8188/mt8188-mt6359.c | 21 > > +++++++++++++++++++++ > > 1 file changed, 21 insertions(+) > > > > diff --git a/sound/soc/mediatek/mt8188/mt8188-mt6359.c > > b/sound/soc/mediatek/mt8188/mt8188-mt6359.c > > index 7c9e08e6a4f5..667d79f33bf2 100644 > > --- a/sound/soc/mediatek/mt8188/mt8188-mt6359.c > > +++ b/sound/soc/mediatek/mt8188/mt8188-mt6359.c > > @@ -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")) { > > if (strncmp(w->name, "MTKAIF_PIN", strlen(w->name) == 0) { > pin_w = w; > break; > } > > That's safer. > If w->name is MTKAIF, the strncmp expression will return 0. However, the result is not expected. I prefer to keep strcmp here. > > + pin_w = w; > > + break; > > + } > > + } > > + > > + if (!pin_w) > > Just a nitpick: you're checking for `if (pin_w)` later in this > function, so > to increase readability please do the same here. > > if (pin_w) > dapm_pinctrl_event(...) > else > dev_dbg(...) > OK. I will update it in v2. Thanks, Trevor
Il 26/07/23 04:19, Trevor Wu (吳文良) ha scritto: > On Tue, 2023-07-25 at 09:06 +0200, AngeloGioacchino Del Regno wrote: >> Il 25/07/23 05:53, Trevor Wu ha scritto: >>> 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> >>> --- >>> sound/soc/mediatek/mt8188/mt8188-mt6359.c | 21 >>> +++++++++++++++++++++ >>> 1 file changed, 21 insertions(+) >>> >>> diff --git a/sound/soc/mediatek/mt8188/mt8188-mt6359.c >>> b/sound/soc/mediatek/mt8188/mt8188-mt6359.c >>> index 7c9e08e6a4f5..667d79f33bf2 100644 >>> --- a/sound/soc/mediatek/mt8188/mt8188-mt6359.c >>> +++ b/sound/soc/mediatek/mt8188/mt8188-mt6359.c >>> @@ -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")) { >> >> if (strncmp(w->name, "MTKAIF_PIN", strlen(w->name) == 0) { >> pin_w = w; >> break; >> } >> >> That's safer. >> > > If w->name is MTKAIF, the strncmp expression will return 0. However, > the result is not expected. I prefer to keep strcmp here. > You could also do, instead if (strncmp(w->name, "MTKAIF_PIN", strlen("MTKAIF_PIN") == 0)) ...solving your concern. Regards, Angelo >>> + pin_w = w; >>> + break; >>> + } >>> + } >>> + >>> + if (!pin_w) >> >> Just a nitpick: you're checking for `if (pin_w)` later in this >> function, so >> to increase readability please do the same here. >> >> if (pin_w) >> dapm_pinctrl_event(...) >> else >> dev_dbg(...) >> > > OK. I will update it in v2. > > Thanks, > Trevor
On Wed, 2023-07-26 at 08:43 +0200, AngeloGioacchino Del Regno wrote: > Il 26/07/23 04:19, Trevor Wu (吳文良) ha scritto: > > On Tue, 2023-07-25 at 09:06 +0200, AngeloGioacchino Del Regno > > wrote: > > > Il 25/07/23 05:53, Trevor Wu ha scritto: > > > > 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> > > > > --- > > > > sound/soc/mediatek/mt8188/mt8188-mt6359.c | 21 > > > > +++++++++++++++++++++ > > > > 1 file changed, 21 insertions(+) > > > > > > > > diff --git a/sound/soc/mediatek/mt8188/mt8188-mt6359.c > > > > b/sound/soc/mediatek/mt8188/mt8188-mt6359.c > > > > index 7c9e08e6a4f5..667d79f33bf2 100644 > > > > --- a/sound/soc/mediatek/mt8188/mt8188-mt6359.c > > > > +++ b/sound/soc/mediatek/mt8188/mt8188-mt6359.c > > > > @@ -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")) { > > > > > > if (strncmp(w->name, "MTKAIF_PIN", strlen(w->name) == 0) { > > > pin_w = w; > > > break; > > > } > > > > > > That's safer. > > > > > > > If w->name is MTKAIF, the strncmp expression will return 0. > > However, > > the result is not expected. I prefer to keep strcmp here. > > > > You could also do, instead > > if (strncmp(w->name, "MTKAIF_PIN", strlen("MTKAIF_PIN") == 0)) > > ...solving your concern. > > From my understanding, strncmp is utilized to determine a string begins with a particular prefix while strcmp is used to compare a whole string. In this scenario, I wish to verify if the widget name is exactly 'MTKAIF_PIN', so I believe using strcmp would be more appropriate. Using either strlen(w->name) or strlen("MTKAIF_PIN") may lead to incorrect results when w->name is either MTKAIF or MTKAIF_PIN1. Thanks, Trevor
Il 26/07/23 13:36, Trevor Wu (吳文良) ha scritto: > On Wed, 2023-07-26 at 08:43 +0200, AngeloGioacchino Del Regno wrote: >> Il 26/07/23 04:19, Trevor Wu (吳文良) ha scritto: >>> On Tue, 2023-07-25 at 09:06 +0200, AngeloGioacchino Del Regno >>> wrote: >>>> Il 25/07/23 05:53, Trevor Wu ha scritto: >>>>> 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> >>>>> --- >>>>> sound/soc/mediatek/mt8188/mt8188-mt6359.c | 21 >>>>> +++++++++++++++++++++ >>>>> 1 file changed, 21 insertions(+) >>>>> >>>>> diff --git a/sound/soc/mediatek/mt8188/mt8188-mt6359.c >>>>> b/sound/soc/mediatek/mt8188/mt8188-mt6359.c >>>>> index 7c9e08e6a4f5..667d79f33bf2 100644 >>>>> --- a/sound/soc/mediatek/mt8188/mt8188-mt6359.c >>>>> +++ b/sound/soc/mediatek/mt8188/mt8188-mt6359.c >>>>> @@ -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")) { >>>> >>>> if (strncmp(w->name, "MTKAIF_PIN", strlen(w->name) == 0) { >>>> pin_w = w; >>>> break; >>>> } >>>> >>>> That's safer. >>>> >>> >>> If w->name is MTKAIF, the strncmp expression will return 0. >>> However, >>> the result is not expected. I prefer to keep strcmp here. >>> >> >> You could also do, instead >> >> if (strncmp(w->name, "MTKAIF_PIN", strlen("MTKAIF_PIN") == 0)) >> >> ...solving your concern. >> >> > > From my understanding, strncmp is utilized to determine a string begins > with a particular prefix while strcmp is used to compare a whole > string. In this scenario, I wish to verify if the widget name is > exactly 'MTKAIF_PIN', so I believe using strcmp would be more > appropriate. > > Using either strlen(w->name) or strlen("MTKAIF_PIN") may lead to > incorrect results when w->name is either MTKAIF or MTKAIF_PIN1. > > Thanks, > Trevor strcmp() and strncmp() are the same; except strncmp() compares *at most* `n` bytes, where `n` is my `strlen("MTKAIF_PIN")`. From Linux man pages.... https://www.man7.org/linux/man-pages/man3/strcmp.3.html Regards, Angelo
On Wed, 2023-07-26 at 13:54 +0200, AngeloGioacchino Del Regno wrote: ..snip.. > > > > > > > > > > > > @@ -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")) { > > > > > > > > > > if (strncmp(w->name, "MTKAIF_PIN", strlen(w->name) == 0) { > > > > > pin_w = w; > > > > > break; > > > > > } > > > > > > > > > > That's safer. > > > > > > > > > > > > > If w->name is MTKAIF, the strncmp expression will return 0. > > > > However, > > > > the result is not expected. I prefer to keep strcmp here. > > > > > > > > > > You could also do, instead > > > > > > if (strncmp(w->name, "MTKAIF_PIN", strlen("MTKAIF_PIN") == 0)) > > > > > > ...solving your concern. > > > > > > > > > > From my understanding, strncmp is utilized to determine a string > > begins > > with a particular prefix while strcmp is used to compare a whole > > string. In this scenario, I wish to verify if the widget name is > > exactly 'MTKAIF_PIN', so I believe using strcmp would be more > > appropriate. > > > > Using either strlen(w->name) or strlen("MTKAIF_PIN") may lead to > > incorrect results when w->name is either MTKAIF or MTKAIF_PIN1. > > > > Thanks, > > Trevor > > strcmp() and strncmp() are the same; except strncmp() compares *at > most* `n` bytes, > where `n` is my `strlen("MTKAIF_PIN")`. > > From Linux man pages.... > https://urldefense.com/v3/__https://www.man7.org/linux/man-pages/man3/strcmp.3.html__;!!CTRNKA9wMg0ARbw!n-X-ckbkVYv4cbrhpwb2f7NH6sQkxx1czmCU2-q5BtSOhQU0C68wj9JNcu47YfbYeTpVEzjYQVXGuQb5ulpeWwKjnVMdZpg$ > > > Hi Angelo, My concern is that strncmp() compares at most `n` bytes, where `n` is the length of the string 'MTKAIF_PIN'. For instance, if both 'MTKAIF_PIN' and 'MTKAIF_PINMUX' exist in the widget list, they will both enter execute_something() function below when executing this code: if (strncmp(w->name, "MTKAIF_PIN", strlen("MTKAIF_PIN")) == 0) { execute_something(); }. This is not my expected scenario. To prevent this problem, we can use strcmp() instead of strncmp(). strcmp() compares two strings until it finds a difference or reaches the end of one of them. Therefore, it will compare the entire string 'MTKAIF_PIN' with w->name and make sure that only do execute_something() when w->names is the same as 'MTKAIF_PIN'. Thanks, Trevor
Il 25/07/23 05:53, Trevor Wu ha scritto: > 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>
diff --git a/sound/soc/mediatek/mt8188/mt8188-mt6359.c b/sound/soc/mediatek/mt8188/mt8188-mt6359.c index 7c9e08e6a4f5..667d79f33bf2 100644 --- a/sound/soc/mediatek/mt8188/mt8188-mt6359.c +++ b/sound/soc/mediatek/mt8188/mt8188-mt6359.c @@ -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) + dev_dbg(afe->dev, "%s(), no pinmux widget, please check if default on\n", __func__); + else + dapm_pinctrl_event(pin_w, NULL, SND_SOC_DAPM_PRE_PMU); + 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);