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: 13024156 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 alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (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 62E65ECAAA1 for ; Fri, 28 Oct 2022 17:24:14 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 56C0E1B2B; Fri, 28 Oct 2022 19:23:22 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 56C0E1B2B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1666977852; bh=II2yHfT0fuZlQd2MiizXYIJKhqvvZ+ugo0x5N5uFX2I=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=uXtdgEPIS/kvlKCTc9OLY4M6C8jmP3h5BjzDuDaRRWbh6BLUvERBUgQX64vHYT8W6 C5VcVN2tOO5Dr8sXLTBTkng2K0PEuDOyefO6KIhh5DbNV6J4zYbCMt2G4+b+5F+MGx 1krGnOFj2uu776Kct2skTdx5C1bfJuc3hzsvhz3c= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 3ED25F8054A; Fri, 28 Oct 2022 19:22:42 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id CDC23F80551; Fri, 28 Oct 2022 19:22:40 +0200 (CEST) Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id A107DF804C1 for ; Fri, 28 Oct 2022 19:22:34 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz A107DF804C1 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=compal-corp-partner-google-com.20210112.gappssmtp.com header.i=@compal-corp-partner-google-com.20210112.gappssmtp.com header.b="JG4Bz2Xt" Received: by mail-pj1-x102e.google.com with SMTP id 3-20020a17090a0f8300b00212d5cd4e5eso10427051pjz.4 for ; Fri, 28 Oct 2022 10:22:34 -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=L6zPoY9GSFEgwm9qTLP44jwyxZMyztyxuiCHSsT78yC8v8S6aPELsM6X4P6TLp3EbI osRtEiy2teH4nsnsVv5Hvz8j0yGLrhgLNBNXl5JFQZQWKKRjJLR5u6gNQddwnfKvuOI9 iHES7qhEZFsWS/mjd7ZmZSi6nA3z4PxCgiFlV2uoycP8OYRMWRgwBNHugo2zKEwzmNwb ar/yU+TUYLpANNPTXJZ+3cORybowx3Kyc7CYsO9+YL6fAXBkbsAmdo/8e9igFIIzwkvK R46qHcr3TXukTS5qJIR7ZIQLk7yp52gmgl3LxTOM8FqKx/svxRQQeB7h736EkC9bXOQm b0cg== X-Gm-Message-State: ACrzQf2x/D/IlKtg3v6WjI1U0komTNZdojpktB5zOcwq6Agp3m+uXHLt NTtPJMJ9ikOkbjEwqOfjcKR11A== 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 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 Cc: devicetree@vger.kernel.org, alsa-devel@alsa-project.org, "chunxu . li" , =?utf-8?q?N=C3=ADcolas_F_=2E_R_=2E_?= =?utf-8?q?A_=2E_Prado?= , Mark Brown , Ajye Huang , Liam Girdwood , Jiaxin Yu , Takashi Iwai , Rob Herring , linux-mediatek@lists.infradead.org, Krzysztof Kozlowski , Matthias Brugger , linux-arm-kernel@lists.infradead.org, AngeloGioacchino Del Regno X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" 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;