From patchwork Sun Oct 8 01:46:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhengqiao Xia X-Patchwork-Id: 13412524 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 A0539E95A86 for ; Sun, 8 Oct 2023 01:46:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=AnkYs5/BG/9GOQBaCWwWyOfl1fNQBQrw4AiO+6MYmI8=; b=hMZbxlX5O/t8rYTO7zmQuuTgtJ K5IakEp18t1Uj3s8VDkOCaj09DFRXsXm0VfkUqs6YK6a8oFUgo3g7Z7v7y1nwrsnIXQHJcV/Sikd0 wId01Pdc/fLexYas9FvwCTaGDz49j00uq5EImhdol1kTRyAPBsme3tqnDO5Umlt6gMDWS5VqODEmJ AuLTcHkBpzN4XF6SL9PK3VKOALMvjGqUy4IKNK+eiYMd4Ak0ORQpmupmII6L5V8Is0PPNjorilHwq d6Am/MJXh+lpWZ+DhMbHcriBSJuxzI4/OossOnzs3Br+DWMBytAt0fUR4dOi8zvhiREbODWR0xJ7X ERlJy9Pw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qpIsc-0089nK-0h; Sun, 08 Oct 2023 01:46:50 +0000 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qpIsZ-0089l7-0o for linux-mediatek@lists.infradead.org; Sun, 08 Oct 2023 01:46:48 +0000 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-690d2441b95so2551298b3a.1 for ; Sat, 07 Oct 2023 18:46:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=huaqin-corp-partner-google-com.20230601.gappssmtp.com; s=20230601; t=1696729603; x=1697334403; darn=lists.infradead.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=AnkYs5/BG/9GOQBaCWwWyOfl1fNQBQrw4AiO+6MYmI8=; b=SJsFnG7FG2CL71+M9j86iN6IaZMFwSkHVttrDoZ+TLN/WyjPyglkbXGUxINLlezdK5 LCpSBjbWEDuhhoWQD/YOOYjC3DO4K0q7EFXuTlER8j0nkrRPHtuttQYIN5GUNfH2jd6r 6t7ERsn32BFBJq8rPKUYkzNdRLijeCZG3rI3dGnEoNQ6mIU6PimyfTU0P6tDZ5GR3nhm IuZzUTH0I4ujfr7KbcFwhP9D2gME5uP0ZAx8QfX7/XQo7cVv/uGfLVj5Ylm+slp7LmR0 Azk+8X1e+kHL2KEN8bpCi0Fq8VUcBFZEAe5UNC/QWcvu+ScGiMMES6RX7zgyQ6szkAbd fhgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696729603; x=1697334403; 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=AnkYs5/BG/9GOQBaCWwWyOfl1fNQBQrw4AiO+6MYmI8=; b=P7aSezt7eu+SlbnaAP9EDbTfp/9kLOzgmmHi5EcQ7CEcPL3U6+L/+HFYIXtxhbVG1g BJwzmUEYLH/9gfmyzVnkiYHeenJLu693QiypPRq+MBi8+24+dHFpTtbVelalGCCU9FPp Nw7BpRnL55lpNj2YPGRSpFiwEhw/ywR9NQbPi+T1vtjJVyCSOqjnSh3WRnTSEneNuJTI dUUvS9BFRy/mPk1wDg7h+u0ow3yvFufO638y8guiJIQUDj6jUEwpaW4jUS+o6jGs6+tN C8rXrbgBSKoDaxOg9DNSJwNqq6keyBRkgc54QBN0nUSyVdAlLoCAjolaKYeQyUvAOEPS kobQ== X-Gm-Message-State: AOJu0Yzc5xge1ELVEH1PevRzzrDIpXof4KJdiOHFcAE1ackrjLLr4kiR mazCe3ksfeAUe/3X8bRIY/+5Pw== X-Google-Smtp-Source: AGHT+IGWr16rliwrfcLVvoGiO2V3+fKoKVyKcsYrbchWrREpwol8Erq4V6J5un5az6Bk51HfqHF5TA== X-Received: by 2002:a05:6a20:8425:b0:135:bf8d:b758 with SMTP id c37-20020a056a20842500b00135bf8db758mr13343502pzd.16.1696729603504; Sat, 07 Oct 2023 18:46:43 -0700 (PDT) Received: from ubuntu.huaqin.com ([101.78.151.205]) by smtp.gmail.com with ESMTPSA id v1-20020a63bf01000000b00563826c66eesm4888846pgf.61.2023.10.07.18.46.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Oct 2023 18:46:43 -0700 (PDT) From: xiazhengqiao To: lgirdwood@gmail.com, robh+dt@kernel.org, broonie@kernel.org, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, perex@perex.cz, tiwai@suse.com, trevor.wu@mediatek.com, maso.huang@mediatek.com Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, xiazhengqiao Subject: [v4 1/2] ASoC: dt-bindings: mediatek,mt8188-mt6359: add RT5682S support Date: Sun, 8 Oct 2023 09:46:28 +0800 Message-Id: <20231008014629.4971-2-xiazhengqiao@huaqin.corp-partner.google.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231008014629.4971-1-xiazhengqiao@huaqin.corp-partner.google.com> References: <20231008014629.4971-1-xiazhengqiao@huaqin.corp-partner.google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231007_184647_287784_624EDA03 X-CRM114-Status: UNSURE ( 7.47 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-mediatek@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-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org 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 Sun Oct 8 01:46:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhengqiao Xia X-Patchwork-Id: 13412525 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 BE937E95A67 for ; Sun, 8 Oct 2023 01:46:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=f51u3gYqj0ZmKcLxg9BC8K4dJtNteTmeq9iXht4DLds=; b=li0MOAKNA6CyEg/tizHEK3pHza x181YTS2IhZq98udhvrmPjoWDEQNHewh6H5e30L3edLIbbbeTeJyVs63X7Yz8rPdmyAuJNAbVSeSh qsX1+V8tnjYLWPSpuNeNhjP3JpQT0bxtGbLMxfXy2JyS8E4iNvBOMgZoM9EU+8aRMB/qBFIc1tNQR ru1vkE3sMHf35cIKedmJKJKGFeMsnHqefkoSd4CbCISTqtmsbLHz4IAnZ+4um/bYCAJXsbOLTEMf6 fuU/soy1VG0GcTipxNzUrQRXR21DESY58VrOhAofDBZKfvHn55CXpZns0+5t5Bpd3hVRzB+u5IzHu Meibv2bA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qpIsf-0089o4-26; Sun, 08 Oct 2023 01:46:53 +0000 Received: from mail-yb1-xb2a.google.com ([2607:f8b0:4864:20::b2a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qpIsb-0089m7-34 for linux-mediatek@lists.infradead.org; Sun, 08 Oct 2023 01:46:51 +0000 Received: by mail-yb1-xb2a.google.com with SMTP id 3f1490d57ef6-d90da64499cso3711228276.0 for ; Sat, 07 Oct 2023 18:46:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=huaqin-corp-partner-google-com.20230601.gappssmtp.com; s=20230601; t=1696729608; x=1697334408; darn=lists.infradead.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=f51u3gYqj0ZmKcLxg9BC8K4dJtNteTmeq9iXht4DLds=; b=JC6OUt0z5QrSwzROkxFUgjkL31ecTjYDMGA/6lh7CXPU1BWE6n6tDFLfbJEc08Dj8S YgJKszXW2j16lO1tWPb/isxRqxQAEt5M/jJPCNhuMjDD7zsZxhodA0FysJ4GFHTDGLzh KcdBAxrp/RpF3T85VuZbn21yTtb+S+YmdWRexM68A6YF3+4kifdkMhjfM4kA1SioQAwi bEO0EDP4R+ClW8fTU/xdgcCFoqmNwst1bu99ZYsd7Q+qNUzyfHLEBNJXIGUP3WpbxQov 2lGiJdQT4cJW4ALmOFJuSpQ9xndW6JytO0KGXa7m3scUXIRSnATAtjYGxd81QoixyB2z JKSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696729608; x=1697334408; 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=f51u3gYqj0ZmKcLxg9BC8K4dJtNteTmeq9iXht4DLds=; b=I3bLTMmoZNN85otRMK17n8/49ft60mOeJDBVMSx9wJg/2fXOs1ar26GQYCZqxVdNvh 3Poo76Hney1370kb6vlaMkXh3ylCuFJJXQOg6Aa09DVMTVsE1aYZ3Y2a7U5Dx6jhACeL bwZ8UzxER5pTrpJQNqqSO8nZRVkSUUtEgS345um2/xTGchgJ+xp9J4Sb+ZDgxAZHaHw4 TFpLFrwT5+o+gqcTyXsmJ6sYHy9GAlRuJzc3F6S6xtm4TcJ1m4rXLBGp+wTi3YCafQHa 9hbCQf6G6GmMLHRwFD8AhGwpaoin3hyFBqR9L4DnVBB2gtpq8yD8VdIqMVMMylI1xuVb yrnQ== X-Gm-Message-State: AOJu0YyuQ7CN4NdZ+MSHnMPAr6zM2OAkZw1jL14XaDuvDYJDg2/UOX/c 0hiyjtuUOdMXFDcKO1YW417Keg== X-Google-Smtp-Source: AGHT+IH6KeQh5WWBmnv/cfFA9iNYpCKsCVbi0kvbXPzwevGrvele2RfVPxjOMZCa3KFC/xXLMT4jeQ== X-Received: by 2002:a25:238e:0:b0:d81:b9f0:455e with SMTP id j136-20020a25238e000000b00d81b9f0455emr11384399ybj.51.1696729607904; Sat, 07 Oct 2023 18:46:47 -0700 (PDT) Received: from ubuntu.huaqin.com ([101.78.151.205]) by smtp.gmail.com with ESMTPSA id v1-20020a63bf01000000b00563826c66eesm4888846pgf.61.2023.10.07.18.46.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Oct 2023 18:46:47 -0700 (PDT) From: xiazhengqiao To: lgirdwood@gmail.com, robh+dt@kernel.org, broonie@kernel.org, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, perex@perex.cz, tiwai@suse.com, trevor.wu@mediatek.com, maso.huang@mediatek.com Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, xiazhengqiao Subject: [v4 2/2] ASoC: mediatek: mt8188-mt6359: add rt5682s support Date: Sun, 8 Oct 2023 09:46:29 +0800 Message-Id: <20231008014629.4971-3-xiazhengqiao@huaqin.corp-partner.google.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231008014629.4971-1-xiazhengqiao@huaqin.corp-partner.google.com> References: <20231008014629.4971-1-xiazhengqiao@huaqin.corp-partner.google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231007_184650_005651_9F73BDD5 X-CRM114-Status: GOOD ( 21.13 ) X-BeenThere: linux-mediatek@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-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org 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 | 141 +++++++++++++++++++++- 2 files changed, 140 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 e2416b981e1f..66f246126728 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")), @@ -258,6 +261,17 @@ static struct snd_soc_jack_pin nau8825_jack_pins[] = { }, }; +static struct snd_soc_jack_pin rt5682s_jack_pins[] = { + { + .pin = "Headphone Jack", + .mask = SND_JACK_HEADPHONE, + }, + { + .pin = "Headset Mic", + .mask = SND_JACK_MICROPHONE, + }, +}; + struct mt8188_card_data { const char *name; unsigned long quirk; @@ -316,10 +330,18 @@ static const struct snd_soc_dapm_widget mt8188_nau8825_widgets[] = { SND_SOC_DAPM_HP("Headphone Jack", NULL), }; +static const struct snd_soc_dapm_widget mt8188_rt5682s_widgets[] = { + SND_SOC_DAPM_HP("Headphone Jack", NULL), +}; + static const struct snd_kcontrol_new mt8188_nau8825_controls[] = { SOC_DAPM_PIN_SWITCH("Headphone Jack"), }; +static const struct snd_kcontrol_new mt8188_rt5682s_controls[] = { + SOC_DAPM_PIN_SWITCH("Headphone Jack"), +}; + static const struct snd_soc_dapm_route mt8188_mt6359_routes[] = { /* SOF Uplink */ {SOF_DMA_UL4, NULL, "O034"}, @@ -772,6 +794,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 = asoc_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_rt5682s_widgets, + ARRAY_SIZE(mt8188_rt5682s_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_rt5682s_controls, + ARRAY_SIZE(mt8188_rt5682s_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, + rt5682s_jack_pins, + ARRAY_SIZE(rt5682s_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 = asoc_rtd_to_codec(rtd, 0)->component; @@ -779,6 +850,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 = asoc_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 +891,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 = asoc_rtd_to_cpu(rtd, 0); + struct snd_soc_dai *codec_dai = asoc_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 +1271,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 +1313,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 +1430,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 +1474,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);