From patchwork Tue Oct 10 02:37:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhengqiao Xia X-Patchwork-Id: 13421943 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 7469DCDB465 for ; Sat, 14 Oct 2023 09:29:04 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 2F28CA4A; Sat, 14 Oct 2023 11:28:12 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 2F28CA4A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1697275742; bh=G18K9/NbjyU0eodhg6uBP+C2urhz0Zryadum4wUyL1k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=cBncHnREIJYN+NhrSXpCXb1M0n5VX8wvxg2IoFeQpqn+MEAtANpliylyUlLpwNRU9 z+DoYECQ/CHgcgg8M+EpT48O7b4hD5x2s1IWlklwDb3WG6sRMKmNWpcCwzA3HCFq92 iFv2Pk5lgVAEK8lmJRFp0fX1jJWyT2Koj8sswMhI= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 1312CF80558; Sat, 14 Oct 2023 11:27:38 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 8DB67F80567; Sat, 14 Oct 2023 11:27:38 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id B35BFF802BE; Tue, 10 Oct 2023 04:37:59 +0200 (CEST) Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 9F9C9F8019B for ; Tue, 10 Oct 2023 04:37:55 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 9F9C9F8019B Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=huaqin-corp-partner-google-com.20230601.gappssmtp.com header.i=@huaqin-corp-partner-google-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=X1n+xpHk Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1c60f1a2652so38373065ad.0 for ; Mon, 09 Oct 2023 19:37:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=huaqin-corp-partner-google-com.20230601.gappssmtp.com; s=20230601; t=1696905474; x=1697510274; darn=alsa-project.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=FBRoIXxc4ljc8DF/PDtBoqS0A6CYruv097EKMy33JAI=; b=X1n+xpHk0uspTLV6iqQJn4l9XvmKL2SSBEmi21tMoWHeoFOGfimUmmaNhV/o0yg8Y5 Zb+x3pvv++xUw0uvMeGOvR0UqA2nqg21x0Ow7JejfmNpRTj7lFgeMBfcr3LlpPX6Rmls TqGwJ9x3CGHA37BJfR1ylfYla271PjpcFHlRIvTxE8oG05a6XdaGHiwCZrWZO5iIwwnL lpWaK75585q8puUbSwbQIzc6AGvxeUlHuHrQRJob8fGPSRY7p7brWuFveSZxPoEaTFDN 3mT98ExS/2l4n2dZeKTMVMXUg0sR53lFJaX3YNRP1IxReCZ5VQirbqxt0omtmXc79OT3 5oOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696905474; x=1697510274; h=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=FBRoIXxc4ljc8DF/PDtBoqS0A6CYruv097EKMy33JAI=; b=fppBx8YchSN18WOvtlu8hiy736sEncCCu44oBP8f5Qvr+ibUlpaueIb9jYC1m+v0T4 kmB19l4ZZk6PyRYGnuey1YG/wktucbMcALwM0wR2Ys9SCVs0bhguXE/Zcc8CvBUG8OJg KHp53JW8q2H2VPjvQKP+3o7ou7KhOAPn21s42WV6RZKwq3dAXIicGGWZzN0o0HQ18vvT RgqkEOX4LpvUuet8WooufCE/HJ4y9WiW821ZRnGNxWGdpjub+BtH5zbQp7lXgwsvS5Y9 cC0wgLPbsQQ+FuGZtv4D4c89I14ZqaMdUhIW9khZ5yOvu3cKJ9UXetsMWNpP6iMntCce 8kWg== X-Gm-Message-State: AOJu0YwEzciG1y+PSQAIagJhgFRNq+78qRNhgfcRMzWeSPwRxAXpMVmo FYa2g7BGFwHgs484dJPq0Fr3SOt7D9oL3EwgQgk= X-Google-Smtp-Source: AGHT+IEv18QaxmdXF/vUEo7prCg0gx1O29LYJaDyQoUVhpU9JZshh+ovBSvE4QZw0O7F38u1Ae0ekQ== X-Received: by 2002:a17:902:ecd1:b0:1bc:1e17:6d70 with SMTP id a17-20020a170902ecd100b001bc1e176d70mr20438926plh.24.1696905473655; Mon, 09 Oct 2023 19:37:53 -0700 (PDT) Received: from ubuntu.huaqin.com ([101.78.151.205]) by smtp.gmail.com with ESMTPSA id e1-20020a17090301c100b001c613091aeesm10269039plh.293.2023.10.09.19.37.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 19:37:53 -0700 (PDT) From: xiazhengqiao To: lgirdwood@gmail.com, broonie@kernel.org, robh+dt@kernel.org, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, perex@perex.cz, trevor.wu@mediatek.com Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, xiazhengqiao Subject: [v5 1/2] ASoC: dt-bindings: mediatek,mt8188-mt6359: add RT5682S support Date: Tue, 10 Oct 2023 10:37:37 +0800 Message-Id: <20231010023738.8241-2-xiazhengqiao@huaqin.corp-partner.google.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231010023738.8241-1-xiazhengqiao@huaqin.corp-partner.google.com> References: <20231010023738.8241-1-xiazhengqiao@huaqin.corp-partner.google.com> X-MailFrom: xiazhengqiao@huaqin.corp-partner.google.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1 Message-ID-Hash: TO3HNA5DJ3NQJT2BARZZPC6ZWAG275SD X-Message-ID-Hash: TO3HNA5DJ3NQJT2BARZZPC6ZWAG275SD X-Mailman-Approved-At: Sat, 14 Oct 2023 09:24:38 +0000 X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Add compatible string "mediatek,mt8188-rt5682s" to support new board with rt5682s codec. Signed-off-by: xiazhengqiao Acked-by: Rob Herring Reviewed-by: AngeloGioacchino Del Regno --- .../devicetree/bindings/sound/mediatek,mt8188-mt6359.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/sound/mediatek,mt8188-mt6359.yaml b/Documentation/devicetree/bindings/sound/mediatek,mt8188-mt6359.yaml index 43b3b67bdf3b..4c8c95057ef7 100644 --- a/Documentation/devicetree/bindings/sound/mediatek,mt8188-mt6359.yaml +++ b/Documentation/devicetree/bindings/sound/mediatek,mt8188-mt6359.yaml @@ -17,6 +17,7 @@ properties: enum: - mediatek,mt8188-mt6359-evb - mediatek,mt8188-nau8825 + - mediatek,mt8188-rt5682s audio-routing: description: From patchwork Tue Oct 10 02:37:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhengqiao Xia X-Patchwork-Id: 13421944 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 2F04ACDB465 for ; Sat, 14 Oct 2023 09:29:20 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 68B3ADEB; Sat, 14 Oct 2023 11:28:28 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 68B3ADEB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1697275758; bh=426E33T2LO/TBHu7zgUDLO5CLfNwHx526jeIp7gkegs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=k7LrkQbZtgdzUc6cQdoktmoTSrag1gLWO364un61MtCW0YD7gPn/a+3biTR7EVhTr LRjoBI1hxdi76ARU+9uZqM+sOAZup9i4oEsvutNjowZmX30p/p5TcIMaU49/+1knOD NwfzE4xfBjPxOQPqU3pvivwo6VKaxr5hOOodBl6E= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 9FFB4F8057F; Sat, 14 Oct 2023 11:27:40 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 26A4BF8057A; Sat, 14 Oct 2023 11:27:40 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id A7B8CF802BE; Tue, 10 Oct 2023 04:38:07 +0200 (CEST) Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id E7776F8019B for ; Tue, 10 Oct 2023 04:38:00 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz E7776F8019B Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=huaqin-corp-partner-google-com.20230601.gappssmtp.com header.i=@huaqin-corp-partner-google-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=BxmLe9pD Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1c0ecb9a075so31898935ad.2 for ; Mon, 09 Oct 2023 19:38:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=huaqin-corp-partner-google-com.20230601.gappssmtp.com; s=20230601; t=1696905479; x=1697510279; darn=alsa-project.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=w4bmb1xR8OcWB9e5UdpWJ8Bp88C+jyGpoKKuNYhtM58=; b=BxmLe9pDVf8QUCfwAO6kICYXAvs+BsPsD6M1wO7s9Zi9YCo0XcorfYVKb3E20foWvM NCqvlFcoT3q5gKXTq/QVP/foOUMVFKKkrvocSslRB/KaYmAIxsFrZuUuIl4g9sOLsMTa DOyxMUw0GBvW0/joFKibJM4b42K8HKZRtFuUaUZ8BsaNBkC4ujWI6CMw8Db6dCJa4jvP JtBiL3b/W6+RMtwHzCdl1txtRdH+O+qYFgrrH9inTkacTgFou8BdpOdauIrJEaChw7CZ iw0a22g/an2HVI77dfEesJHIpWCXgn0lfJw316C9ScWy6OdFIddRQhoSax8mC3+3f+wH HGsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696905479; x=1697510279; h=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=w4bmb1xR8OcWB9e5UdpWJ8Bp88C+jyGpoKKuNYhtM58=; b=uBs1Ov2mfcK2ujhxb9mRGgXdZVp8bcW4Y2zvlbIt3SuLTQ9bIay6Lvi3k2zgRBDm1n 81xdhPqEX4gbGadRqOYPgG85qRl+ro7QKLBrgTnuERkhMOrnuGadaWjhj+X7nmiqP1D9 cmb1/SLczRXJCzlofIu23BfG2VjQOaSfCckVmHX05Ln79Sq0PtSy5VQ5LMe/nSwZGVh9 YfB7drWUEeTHnXJUuy2ec9GB4R6TBnNE2JQCtmflu0Wp4A+j4RNoMYwTvYzVqatZjlCk QyYNu/Bjex6GUamh8wfWtoUrdV7fWgL61XVBsxFeJWLzHSXIJJFJZTD5jW5UJ7anBxhh USHg== X-Gm-Message-State: AOJu0YyuPZbTxAmz7IVwWGN64QPeYFgKhSq91Kuv55ZhR5Su0s7KUctB 4emDZOMHF21EOdpRP5N20WVrNg== X-Google-Smtp-Source: AGHT+IH9LOo0tQ4Yc+ymws96WFTOJEo86wA1EZW7c1AxAijqrRQc/MBForoANuU0NMiOTHa5cbR+XA== X-Received: by 2002:a17:902:ce90:b0:1c8:9d32:3397 with SMTP id f16-20020a170902ce9000b001c89d323397mr6990238plg.57.1696905478639; Mon, 09 Oct 2023 19:37:58 -0700 (PDT) Received: from ubuntu.huaqin.com ([101.78.151.205]) by smtp.gmail.com with ESMTPSA id e1-20020a17090301c100b001c613091aeesm10269039plh.293.2023.10.09.19.37.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 19:37:58 -0700 (PDT) From: xiazhengqiao To: lgirdwood@gmail.com, broonie@kernel.org, robh+dt@kernel.org, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, perex@perex.cz, trevor.wu@mediatek.com Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, xiazhengqiao Subject: [v5 2/2] ASoC: mediatek: mt8188-mt6359: add rt5682s support Date: Tue, 10 Oct 2023 10:37:38 +0800 Message-Id: <20231010023738.8241-3-xiazhengqiao@huaqin.corp-partner.google.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231010023738.8241-1-xiazhengqiao@huaqin.corp-partner.google.com> References: <20231010023738.8241-1-xiazhengqiao@huaqin.corp-partner.google.com> X-MailFrom: xiazhengqiao@huaqin.corp-partner.google.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1 Message-ID-Hash: Y23F22KP25NENOBYCP6BVRGZBRV52I7L X-Message-ID-Hash: Y23F22KP25NENOBYCP6BVRGZBRV52I7L X-Mailman-Approved-At: Sat, 14 Oct 2023 09:24:39 +0000 X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: To use RT5682S as the codec and MAX98390 as the amp, add a new sound card named mt8188_rt5682s. Signed-off-by: xiazhengqiao Reviewed-by: Trevor Wu --- sound/soc/mediatek/Kconfig | 1 + sound/soc/mediatek/mt8188/mt8188-mt6359.c | 122 +++++++++++++++++++++- 2 files changed, 121 insertions(+), 2 deletions(-) diff --git a/sound/soc/mediatek/Kconfig b/sound/soc/mediatek/Kconfig index 8d1bc8814486..43c8fea00439 100644 --- a/sound/soc/mediatek/Kconfig +++ b/sound/soc/mediatek/Kconfig @@ -250,6 +250,7 @@ config SND_SOC_MT8188_MT6359 select SND_SOC_MAX98390 select SND_SOC_NAU8315 select SND_SOC_NAU8825 + select SND_SOC_RT5682S help This adds support for ASoC machine driver for MediaTek MT8188 boards with the MT6359 and other I2S audio codecs. diff --git a/sound/soc/mediatek/mt8188/mt8188-mt6359.c b/sound/soc/mediatek/mt8188/mt8188-mt6359.c index 1564eaa1b290..a7e569e5f76d 100644 --- a/sound/soc/mediatek/mt8188/mt8188-mt6359.c +++ b/sound/soc/mediatek/mt8188/mt8188-mt6359.c @@ -17,6 +17,7 @@ #include "mt8188-afe-common.h" #include "../../codecs/nau8825.h" #include "../../codecs/mt6359.h" +#include "../../codecs/rt5682.h" #include "../common/mtk-afe-platform-driver.h" #include "../common/mtk-soundcard-driver.h" #include "../common/mtk-dsp-sof-common.h" @@ -32,7 +33,7 @@ #define TEST_MISO_DONE_2 BIT(29) #define NAU8825_HS_PRESENT BIT(0) - +#define RT5682S_HS_PRESENT BIT(1) /* * Maxim MAX98390 */ @@ -52,6 +53,8 @@ #define SOF_DMA_UL4 "SOF_DMA_UL4" #define SOF_DMA_UL5 "SOF_DMA_UL5" +#define RT5682S_CODEC_DAI "rt5682s-aif1" + /* FE */ SND_SOC_DAILINK_DEFS(playback2, DAILINK_COMP_ARRAY(COMP_CPU("DL2")), @@ -772,6 +775,55 @@ static int mt8188_nau8825_codec_init(struct snd_soc_pcm_runtime *rtd) return 0; }; +static int mt8188_rt5682s_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 mt8188_mt6359_priv *priv = soc_card_data->mach_priv; + struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component; + struct snd_soc_jack *jack = &priv->headset_jack; + int ret; + + ret = snd_soc_dapm_new_controls(&card->dapm, mt8188_nau8825_widgets, + ARRAY_SIZE(mt8188_nau8825_widgets)); + if (ret) { + dev_err(rtd->dev, "unable to add rt5682s card widget, ret %d\n", ret); + return ret; + } + + ret = snd_soc_add_card_controls(card, mt8188_nau8825_controls, + ARRAY_SIZE(mt8188_nau8825_controls)); + if (ret) { + dev_err(rtd->dev, "unable to add rt5682s card controls, ret %d\n", ret); + return ret; + } + + ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack", + SND_JACK_HEADSET | SND_JACK_BTN_0 | + SND_JACK_BTN_1 | SND_JACK_BTN_2 | + SND_JACK_BTN_3, + jack, + nau8825_jack_pins, + ARRAY_SIZE(nau8825_jack_pins)); + if (ret) { + dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret); + return ret; + } + + snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); + snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND); + snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP); + snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN); + ret = snd_soc_component_set_jack(component, jack, NULL); + + if (ret) { + dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret); + return ret; + } + + return 0; +}; + static void mt8188_nau8825_codec_exit(struct snd_soc_pcm_runtime *rtd) { struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component; @@ -779,6 +831,13 @@ static void mt8188_nau8825_codec_exit(struct snd_soc_pcm_runtime *rtd) snd_soc_component_set_jack(component, NULL, NULL); } +static void mt8188_rt5682s_codec_exit(struct snd_soc_pcm_runtime *rtd) +{ + struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component; + + snd_soc_component_set_jack(component, NULL, NULL); +} + static int mt8188_nau8825_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { @@ -813,6 +872,51 @@ static const struct snd_soc_ops mt8188_nau8825_ops = { .hw_params = mt8188_nau8825_hw_params, }; +static int mt8188_rt5682s_i2s_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params) +{ + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snd_soc_card *card = rtd->card; + struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); + struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0); + unsigned int rate = params_rate(params); + int bitwidth; + int ret; + + bitwidth = snd_pcm_format_width(params_format(params)); + if (bitwidth < 0) { + dev_err(card->dev, "invalid bit width: %d\n", bitwidth); + return bitwidth; + } + + ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x00, 0x0, 0x2, bitwidth); + if (ret) { + dev_err(card->dev, "failed to set tdm slot\n"); + return ret; + } + + ret = snd_soc_dai_set_pll(codec_dai, RT5682_PLL1, RT5682_PLL1_S_BCLK1, + rate * 32, rate * 512); + if (ret) { + dev_err(card->dev, "failed to set pll\n"); + return ret; + } + + ret = snd_soc_dai_set_sysclk(codec_dai, RT5682_SCLK_S_PLL1, + rate * 512, SND_SOC_CLOCK_IN); + if (ret) { + dev_err(card->dev, "failed to set sysclk\n"); + return ret; + } + + return snd_soc_dai_set_sysclk(cpu_dai, 0, rate * 128, + SND_SOC_CLOCK_OUT); +} + +static const struct snd_soc_ops mt8188_rt5682s_i2s_ops = { + .hw_params = mt8188_rt5682s_i2s_hw_params, +}; + static int mt8188_sof_be_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { @@ -1148,7 +1252,7 @@ static void mt8188_fixup_controls(struct snd_soc_card *card) struct mt8188_card_data *card_data = (struct mt8188_card_data *)priv->private_data; struct snd_kcontrol *kctl; - if (card_data->quirk & NAU8825_HS_PRESENT) { + if (card_data->quirk & (NAU8825_HS_PRESENT | RT5682S_HS_PRESENT)) { struct snd_soc_dapm_widget *w, *next_w; for_each_card_widgets_safe(card, w, next_w) { @@ -1190,6 +1294,7 @@ static int mt8188_mt6359_dev_probe(struct platform_device *pdev) struct snd_soc_dai_link *dai_link; bool init_mt6359 = false; bool init_nau8825 = false; + bool init_rt5682s = false; bool init_max98390 = false; bool init_dumb = false; int ret, i; @@ -1306,6 +1411,13 @@ static int mt8188_mt6359_dev_probe(struct platform_device *pdev) dai_link->exit = mt8188_nau8825_codec_exit; init_nau8825 = true; } + } else if (!strcmp(dai_link->codecs->dai_name, RT5682S_CODEC_DAI)) { + dai_link->ops = &mt8188_rt5682s_i2s_ops; + if (!init_rt5682s) { + dai_link->init = mt8188_rt5682s_codec_init; + dai_link->exit = mt8188_rt5682s_codec_exit; + init_rt5682s = true; + } } else { if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai")) { if (!init_dumb) { @@ -1343,9 +1455,15 @@ static struct mt8188_card_data mt8188_nau8825_card = { .quirk = NAU8825_HS_PRESENT, }; +static struct mt8188_card_data mt8188_rt5682s_card = { + .name = "mt8188_rt5682s", + .quirk = RT5682S_HS_PRESENT, +}; + static const struct of_device_id mt8188_mt6359_dt_match[] = { { .compatible = "mediatek,mt8188-mt6359-evb", .data = &mt8188_evb_card, }, { .compatible = "mediatek,mt8188-nau8825", .data = &mt8188_nau8825_card, }, + { .compatible = "mediatek,mt8188-rt5682s", .data = &mt8188_rt5682s_card, }, { /* sentinel */ }, }; MODULE_DEVICE_TABLE(of, mt8188_mt6359_dt_match);