From patchwork Fri Oct 28 17:22:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajye Huang X-Patchwork-Id: 13024172 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 52508C38A02 for ; Fri, 28 Oct 2022 17:41:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=vJXHLP78G8aPWmFVZ0GtUjR9KOUyE34n0SqnwyZN2+M=; b=SJ9suUlv/DP1fF P0odhzFXznJFmCsmN/vkszFR3Bup5GbXGakfwTHqps5CLkum/E6J4t+QfxMiOc6Tnjt+B/9cSTQjl vMLwpUk5CEzMEkLAQMwHOc/Fc5hq6ugjs3tkUBZhaTmWn3cyIr4D70kV8+RxZsobbda6pEwYCEN/J w9eve6RFll/chIxXtqoPF6dIet6GllhE4MxUVC7ziGAnD02Kn13TdIJ2Z2jXEXfxsTVZ0e7LjqkPD 0jZWJqxpoT34id+ClP84CVBWcJJZPeC5vl2ksmcJr2XtCvc4IP9jojsTNrB1GLN22OMwQEg7ZnmsY /dgjx6x4bbHP2vQOzkYg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ooTL2-001PYu-Hx; Fri, 28 Oct 2022 17:40:13 +0000 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ooT3s-001FpC-JZ for linux-arm-kernel@lists.infradead.org; Fri, 28 Oct 2022 17:22:30 +0000 Received: by mail-pj1-x1032.google.com with SMTP id r61-20020a17090a43c300b00212f4e9cccdso10411986pjg.5 for ; Fri, 28 Oct 2022 10:22:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=compal-corp-partner-google-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MFMOsXdTB5Df8ggzsilthr4+D/qAdNxZr6+urTN5nT0=; b=8U/f+2hJhjF5TA6s84eiTLKl/O3fHVNMKbmkkAJ5FX/aRcszHn6fJBjnhGYYHQFhG2 fTBTsLcL84cBOXGg2Q2mgiqcOwDnk0opQiYBNiOu+hlqD6C3F0E27LwvFgrg+Gg2KVws IY4kwfWNNnR2taX0KaH5Xdz+RlGQDTjTI2U7QhXlmr6JX79RWzIM7O4kL64obG6g93Ap mWD4qOOieD+oZ44d4vdRDuRIkCdVolcJZunUq0em5vrp7EzLh/2OkrNn4jIuIg3M2bYE cuTIJeKO+N8Hd8kHyOTSeNXd5vXuSV/aBQl2AyhpHg9klUbUKNp4gciAvT5jrIToqZuN lHbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MFMOsXdTB5Df8ggzsilthr4+D/qAdNxZr6+urTN5nT0=; b=aLuAEUu6wTBuiOAZTCHGDLDwfIBNE32nbkkyUvQzyhIEe6ZQAzUEuIwW3Wne8zBnNj 06QU3rr5EUeO/2Mp36P9NvO7ovpvnw0JPcrCfWMEhUVWWPcqUcnNAoFZ/eyaIo8KgjRs +aDjlGt5AzCI55sny6zJy3a0eE3kVGKYORV85QO/2/9Hbb5a5Vex+WtdGCTEcQeZuC0c o4LD9i+sAkOBz+nVJ627cz5Y8MjXYsXaingW9Nn34qzWlQoIwPu1ye4WMq4fIu4ZkiDC FSLi5N8JUDRcnN9dc60sIeiWP9QmxwKFfsf0o7F2UOmFxc2/xg/NMvQUX0uY6hF38FyS G1fw== X-Gm-Message-State: ACrzQf03Pz0o6Ftv9JGiuuvhcl3Q4OiAy5FAJm7SypDx/mBk+1tKGd4b 70xfqG7dXBAzq1LSUfGYtd8o9Q== X-Google-Smtp-Source: AMsMyM7tCLeMSIkzuM8wzGQXwgjziB10x1ohi/U73N7eYMIHY7EgkGmX+ArJKDN2eNOxLRCaa23Crw== X-Received: by 2002:a17:902:968f:b0:180:a7ff:78ba with SMTP id n15-20020a170902968f00b00180a7ff78bamr10947plp.87.1666977747715; Fri, 28 Oct 2022 10:22:27 -0700 (PDT) Received: from localhost.localdomain (118-167-210-30.dynamic-ip.hinet.net. [118.167.210.30]) by smtp.gmail.com with ESMTPSA id rm10-20020a17090b3eca00b0021282014066sm4604945pjb.9.2022.10.28.10.22.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Oct 2022 10:22:27 -0700 (PDT) From: Ajye Huang To: linux-kernel@vger.kernel.org Cc: Mark Brown , Liam Girdwood , Krzysztof Kozlowski , Rob Herring , linux-mediatek@lists.infradead.org, "chunxu . li" , Takashi Iwai , Jaroslav Kysela , Jiaxin Yu , Matthias Brugger , AngeloGioacchino Del Regno , Ajye Huang , =?utf-8?q?N=C3=ADco?= =?utf-8?q?las_F_=2E_R_=2E_A_=2E_Prado?= , linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, alsa-devel@alsa-project.org Subject: [PATCH v2 1/2] ASoC: mediatek: dt-bindings: modify machine bindings for two MICs case Date: Sat, 29 Oct 2022 01:22:14 +0800 Message-Id: <20221028172215.1471235-2-ajye_huang@compal.corp-partner.google.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221028172215.1471235-1-ajye_huang@compal.corp-partner.google.com> References: <20221028172215.1471235-1-ajye_huang@compal.corp-partner.google.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221028_102228_738063_67C5F8E7 X-CRM114-Status: GOOD ( 11.33 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add a property "dmic-gpios" for switching between two MICs. Signed-off-by: Ajye Huang --- .../bindings/sound/mt8186-mt6366-rt1019-rt5682s.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/sound/mt8186-mt6366-rt1019-rt5682s.yaml b/Documentation/devicetree/bindings/sound/mt8186-mt6366-rt1019-rt5682s.yaml index 4fc5b045d3cf..212d2982590a 100644 --- a/Documentation/devicetree/bindings/sound/mt8186-mt6366-rt1019-rt5682s.yaml +++ b/Documentation/devicetree/bindings/sound/mt8186-mt6366-rt1019-rt5682s.yaml @@ -21,6 +21,10 @@ properties: $ref: "/schemas/types.yaml#/definitions/phandle" description: The phandle of MT8186 ASoC platform. + dmic-gpios: + maxItems: 1 + description: GPIO for switching between DMICs + headset-codec: type: object additionalProperties: false @@ -72,6 +76,8 @@ examples: pinctrl-0 = <&aud_clk_mosi_off>; pinctrl-1 = <&aud_clk_mosi_on>; + dmic-gpios = <&pio 23 0>; + headset-codec { sound-dai = <&rt5682s>; }; From patchwork Fri Oct 28 17:22:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajye Huang X-Patchwork-Id: 13024181 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A0931C38A02 for ; Fri, 28 Oct 2022 17:42:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Qo1UT11BzNVZRQph5k3rSdP7dT9v/rJPE4xQs/OcJwY=; b=AWeojPuXVyh/wz H3S/etFI2RKVMWz0LhHZU36e/QV7RjZy96j2lFkLBcFCGkKnVbbHEGtT2j/sto2NZ3NCu8O/obkyF omk3iywmzAsyKwNFu4w7VzxL7yd/ZU4m3NGAgGWJL1FlGjMFHYxen0Ci40QwiHYKHErB0py+SLT5r tKwI6ABIJTbt+QUiEwVK4i5TA9E4pozs12w6pY/jLnPT/4kwO+QA+vhR3TgEM/2BrDzFIcYNbh+c9 Ps7jXbGorVedgpd70TmvSFLcOMdg7MKH7HKO1xjVAm5bmM94U3rI7NhnJgrMlr+w7Qq9+9UDwrJ8h bYE+cSs/2PZc2Ah6lu3g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ooTLm-001Put-E8; Fri, 28 Oct 2022 17:40:58 +0000 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ooT3x-001Fs9-Ru for linux-arm-kernel@lists.infradead.org; Fri, 28 Oct 2022 17:22:35 +0000 Received: by mail-pj1-x102b.google.com with SMTP id m14-20020a17090a3f8e00b00212dab39bcdso10497086pjc.0 for ; Fri, 28 Oct 2022 10:22:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=compal-corp-partner-google-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wBzTxDjyto5LMQswRTp7KBmkgk5W/wTuc9ACHOfSi38=; b=JG4Bz2Xt7TpUN2+LJ1cuM3aGSLn5E38fvyTlnpd+HZqOkrNsWQqFfHBJgVet95OwS6 crQziBTP8KRRFagUdV3nFX/sYlaGGwpBrLhvDsgzADtNGe/mswTcdbOb8Hm8T65tBmg6 GLSydsw0BnI0Y97y7UjHC+E7D4pR7NMxml6FcUIfnw4SUCxhUAR2U+rX64sxYHyr7+oi RWDSqa5SEBX+Ac1hkb9/9xQ7En5Gio0tvG6u329Ow1adVh5L6pg2hf5LGP1gQaqpT42y G8bnwgaBo8FdMW5f2poNr3lWbjkQ+FVmDJRd6/oBjmynCxvJKRWsSaVSrFVM8MyX1Gck yvcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wBzTxDjyto5LMQswRTp7KBmkgk5W/wTuc9ACHOfSi38=; b=zG8wZ0GKwCqjT+ZXetnhpFxHbsloVW/ob5ApU0aatg9j1KwzuI2sEvvNrrcpwlgT6t ee0jmfmPbCL7Zg2Z9+rivC1tKDedXmitofCh1RPDoF4fwboQCofZVYbUibXorzO3nOp1 onXvVpKApVkuLaijnqtZtnVMj7BiDCoEMS/wcLROU/ViyArX6R2YHTlVIYmcNY8zGRNR JBpLbw9g/7b7KLwLvz6PhURzOnxJML9hHkA7yGyek4QkFFyuRdN+35FrgPWTpbwaPndm /MGs7vK3Y1+7wsVWDKY1yT/JXHcruVy0CcBgw3bq1rIIDBneNehVagEGzqqXuGIgFidi 11+A== X-Gm-Message-State: ACrzQf16+INTXrLm8vHTfZBT73QpOkdfN9LU2arrzU1VAnNP3k+6fS+H lpB0ZjIWAGuvSU9H/SwkXoBlKA== X-Google-Smtp-Source: AMsMyM6DPrBHcZgw0FfDAPonOtDjiUr4/LhdgLvqWh99+d+DYIHGfBg4evRMFrHi+DnkRKoF2rA42A== X-Received: by 2002:a17:902:da8e:b0:186:9869:adfa with SMTP id j14-20020a170902da8e00b001869869adfamr20040plx.57.1666977752566; Fri, 28 Oct 2022 10:22:32 -0700 (PDT) Received: from localhost.localdomain (118-167-210-30.dynamic-ip.hinet.net. [118.167.210.30]) by smtp.gmail.com with ESMTPSA id rm10-20020a17090b3eca00b0021282014066sm4604945pjb.9.2022.10.28.10.22.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Oct 2022 10:22:32 -0700 (PDT) From: Ajye Huang To: linux-kernel@vger.kernel.org Cc: Mark Brown , Liam Girdwood , Krzysztof Kozlowski , Rob Herring , linux-mediatek@lists.infradead.org, "chunxu . li" , Takashi Iwai , Jaroslav Kysela , Jiaxin Yu , Matthias Brugger , AngeloGioacchino Del Regno , Ajye Huang , =?utf-8?q?N=C3=ADco?= =?utf-8?q?las_F_=2E_R_=2E_A_=2E_Prado?= , linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, alsa-devel@alsa-project.org Subject: [PATCH v2 2/2] ASoC: mediatek: mt8186-rt5682: Modify machine driver for two DMICs case Date: Sat, 29 Oct 2022 01:22:15 +0800 Message-Id: <20221028172215.1471235-3-ajye_huang@compal.corp-partner.google.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221028172215.1471235-1-ajye_huang@compal.corp-partner.google.com> References: <20221028172215.1471235-1-ajye_huang@compal.corp-partner.google.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221028_102233_947109_9F3E646A X-CRM114-Status: GOOD ( 20.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Having two DMICs, a front DMIC and a Rear DMIC, but only host audio input AUX port0 is used for these two Dmics. A "dmic-gpios" property is used for a mixer control to switch the dmic signal source between the Front and Rear Dmic. Refer to this one as an example, commit 3cfbf07c6d27 ("ASoC: qcom: sc7180: Modify machine driver for 2mic") Signed-off-by: Ajye Huang --- .../mt8186/mt8186-mt6366-rt1019-rt5682s.c | 102 +++++++++++++++++- 1 file changed, 101 insertions(+), 1 deletion(-) diff --git a/sound/soc/mediatek/mt8186/mt8186-mt6366-rt1019-rt5682s.c b/sound/soc/mediatek/mt8186/mt8186-mt6366-rt1019-rt5682s.c index 2414c5b77233..b5c25d1247be 100644 --- a/sound/soc/mediatek/mt8186/mt8186-mt6366-rt1019-rt5682s.c +++ b/sound/soc/mediatek/mt8186/mt8186-mt6366-rt1019-rt5682s.c @@ -7,6 +7,8 @@ // Author: Jiaxin Yu // +#include +#include #include #include #include @@ -39,6 +41,8 @@ struct mt8186_mt6366_rt1019_rt5682s_priv { struct snd_soc_jack headset_jack, hdmi_jack; + struct gpio_desc *dmic_sel; + int dmic_switch; }; /* Headset jack detection DAPM pins */ @@ -68,6 +72,94 @@ static struct snd_soc_codec_conf mt8186_mt6366_rt1019_rt5682s_codec_conf[] = { }, }; +static int dmic_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol); + struct mtk_soc_card_data *soc_card_data = + snd_soc_card_get_drvdata(dapm->card); + struct mt8186_mt6366_rt1019_rt5682s_priv *priv = soc_card_data->mach_priv; + + ucontrol->value.integer.value[0] = priv->dmic_switch; + return 0; +} + +static int dmic_set(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol); + struct mtk_soc_card_data *soc_card_data = + snd_soc_card_get_drvdata(dapm->card); + struct mt8186_mt6366_rt1019_rt5682s_priv *priv = soc_card_data->mach_priv; + + priv->dmic_switch = ucontrol->value.integer.value[0]; + if (priv->dmic_sel) { + gpiod_set_value(priv->dmic_sel, priv->dmic_switch); + dev_info(dapm->card->dev, "dmic_set_value %d\n", + priv->dmic_switch); + } + return 0; +} + +static const char * const dmic_mux_text[] = { + "FrontMic", + "RearMic", +}; + +static SOC_ENUM_SINGLE_DECL(mt8186_dmic_enum, + SND_SOC_NOPM, 0, dmic_mux_text); + +static const struct snd_kcontrol_new mt8186_dmic_mux_control = + SOC_DAPM_ENUM_EXT("DMIC Select Mux", mt8186_dmic_enum, + dmic_get, dmic_set); + +static const struct snd_soc_dapm_widget dmic_widgets[] = { + SND_SOC_DAPM_MIC("DMIC", NULL), + SND_SOC_DAPM_MUX("Dmic Mux", SND_SOC_NOPM, 0, 0, &mt8186_dmic_mux_control), +}; + +static const struct snd_soc_dapm_route dmic_map[] = { + /* digital mics */ + {"Dmic Mux", "FrontMic", "DMIC"}, + {"Dmic Mux", "RearMic", "DMIC"}, +}; + +static int primary_codec_init(struct snd_soc_pcm_runtime *rtd) +{ + struct snd_soc_card *card = rtd->card; + struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(card); + struct mt8186_mt6366_rt1019_rt5682s_priv *priv = soc_card_data->mach_priv; + int ret; + + ret = mt8186_mt6366_init(rtd); + + if (ret) { + dev_err(card->dev, "mt8186_mt6366_init failed: %d\n", ret); + return ret; + } + + if (!priv->dmic_sel) { + dev_info(card->dev, "dmic_sel is null\n"); + return ret; + } + + ret = snd_soc_dapm_new_controls(&card->dapm, dmic_widgets, + ARRAY_SIZE(dmic_widgets)); + if (ret) { + dev_err(card->dev, "DMic widget addition failed: %d\n", ret); + /* Don't need to add routes if widget addition failed */ + return ret; + } + + ret = snd_soc_dapm_add_routes(&card->dapm, dmic_map, + ARRAY_SIZE(dmic_map)); + + if (ret) + dev_err(card->dev, "DMic map addition failed: %d\n", ret); + + return ret; +} + static int mt8186_rt5682s_init(struct snd_soc_pcm_runtime *rtd) { struct snd_soc_component *cmpnt_afe = @@ -775,7 +867,7 @@ static struct snd_soc_dai_link mt8186_mt6366_rt1019_rt5682s_dai_links[] = { .dpcm_playback = 1, .dpcm_capture = 1, .ignore_suspend = 1, - .init = mt8186_mt6366_init, + .init = primary_codec_init, SND_SOC_DAILINK_REG(adda), }, { @@ -1015,6 +1107,14 @@ static int mt8186_mt6366_rt1019_rt5682s_dev_probe(struct platform_device *pdev) soc_card_data->mach_priv = mach_priv; + mach_priv->dmic_sel = devm_gpiod_get_optional(&pdev->dev, + "dmic", GPIOD_OUT_LOW); + if (IS_ERR(mach_priv->dmic_sel)) { + dev_err(&pdev->dev, "DMIC gpio failed err=%ld\n", + PTR_ERR(mach_priv->dmic_sel)); + return PTR_ERR(mach_priv->dmic_sel); + } + adsp_node = of_parse_phandle(pdev->dev.of_node, "mediatek,adsp", 0); if (adsp_node) { struct mtk_sof_priv *sof_priv;