From patchwork Tue Dec 12 12:30:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rui Zhou X-Patchwork-Id: 13489150 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 269ECC38147 for ; Tue, 12 Dec 2023 12:31:39 +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:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=jqd7TRsRyVUdQi5OSpq75cF0EdySxPr0EEY5whyB93o=; b=tNJVxHmiLUTtB0SFSmp/jwvEk4 LWqG9W7aGGtvX262XTOJczjekxB4cOyQ0LmyiJd0NIK0OFZF5+0RzXahIKilB1FDJZ+Jgcns6HGmF iyn5BtsQ/SQYkq5010Zmzd720MgzLN9zmG/fO81pReiM7xG2A9q+KWwPKcvY79pohK3nNW4YJ2/Ct mhjyi27IMPdA1HSM1jFLlI5f77QmIcmkAGcIvg9iFkHijHUylgfXXxRoShqlQrbWlAI5FG+z3YvWX /P+tpi5FZLSfm5bm5ceETGw7ETHo0HfcJ/3I80usuUJnDBGqJ0uwX/Scy/WwdDCZNmXEBiBnoSebY qFuFDz/Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rD1vG-00BflY-0G; Tue, 12 Dec 2023 12:31:38 +0000 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rD1v7-00BfbB-0e for linux-mediatek@lists.infradead.org; Tue, 12 Dec 2023 12:31:33 +0000 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1d0ccda19eeso33244305ad.1 for ; Tue, 12 Dec 2023 04:31:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=huaqin-corp-partner-google-com.20230601.gappssmtp.com; s=20230601; t=1702384271; x=1702989071; darn=lists.infradead.org; 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=jqd7TRsRyVUdQi5OSpq75cF0EdySxPr0EEY5whyB93o=; b=R9zdbT1ZJWDXlR3CMVO86xNWuFRRO5TFzqE3RFUxHXYU5e+rPakO4FA2tN4uoVCEMz N/lOvYwqgm/vF1fIzgISXV0aP6G1a7Io+kO5mM0L9tzThhxlrd/KBKC0ISqrTvGu+Cjd lkaThGrZ8P5ulP4yBaGUOvvGaKlVf7DVdjawZ8Bc6UkBjYSrUH14qAZgjzrpQbJiMBG/ p69S5XeHk4wdbcUSTQVFy9tSD1TZlLZU8bhRdPIESBrvDb7cSHhh4v+yeUfl7Uw1Ecbw sC8to3svscJ1vI8gwYEPYqdBzoyiibDtzvG8U+ZalEjcwCt+ABn+hhtwjFRh/1y7OXgC w9AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702384271; x=1702989071; 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=jqd7TRsRyVUdQi5OSpq75cF0EdySxPr0EEY5whyB93o=; b=ENEKVzHYuB+63n1PRFWWpZ346pSVjfmjP+fNm58Zqk4/NEAFcq6iuNPztCWBoxUq96 mbsz9kek5gf5otHw3lnZNJx+1QekSkbtaZ0VbQcgw7LlnJbpLuzlDEOIccr1logARA9H 72k5Q1tNMBB0cLv3SrAbBe8N5yOiVZFVE4EZ6HQrM3604I2ZnDRPoDlyiYGsPDMc8ZxF CWr25OiZnrxxD+6NOA4RnlDUo69wvrbNI1Y45Ry/rCgRuB7BIRn2NlNmbhQvPWxFzWK2 2MzbtfVu4BjXkhcCJHYrzpKGIYtpFi2n76yuHYNHqTx6lGgtJRQgGgBDVmKYtbylJy1g cQJw== X-Gm-Message-State: AOJu0Yx4moMnhc057CAb7wMnQNvZfgpiz+Ssv7tnCmBZ8CbUg8zevIIe xU21GPxtn/yFxk2jpkGc0Wxx9Sgx/bTWuJ/hJtE= X-Google-Smtp-Source: AGHT+IF1JKcXHHfQcgzgVxTgWlYYiPnk1s20DzMawYPNMDy7eRr8GrcftFEmaKe2/Oi2og5InOcnYg== X-Received: by 2002:a17:902:eb8e:b0:1ce:64fb:e507 with SMTP id q14-20020a170902eb8e00b001ce64fbe507mr2976505plg.27.1702384271011; Tue, 12 Dec 2023 04:31:11 -0800 (PST) Received: from localhost.localdomain ([101.78.151.194]) by smtp.gmail.com with ESMTPSA id z5-20020a170903018500b001cf65844874sm8517471plg.45.2023.12.12.04.31.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 04:31:10 -0800 (PST) From: Rui Zhou To: lgirdwood@gmail.com, broonie@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, perex@perex.cz, tiwai@suse.com, trevor.wu@mediatek.com, allen-kh.cheng@mediatek.com, kuninori.morimoto.gx@renesas.com Cc: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Rui Zhou Subject: [v9 3/4] ASoC: mediatek: mt8188-mt6359: add es8326 support Date: Tue, 12 Dec 2023 20:30:49 +0800 Message-Id: <20231212123050.4080083-4-zhourui@huaqin.corp-partner.google.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231212123050.4080083-1-zhourui@huaqin.corp-partner.google.com> References: <20231212123050.4080083-1-zhourui@huaqin.corp-partner.google.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231212_043129_280394_B45B9D63 X-CRM114-Status: GOOD ( 21.63 ) 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 ES8326 as the codec, add a new sound card named mt8186_es8326. Reviewed-by: Trevor Wu Signed-off-by: Rui Zhou Reviewed-by: AngeloGioacchino Del Regno --- sound/soc/mediatek/Kconfig | 1 + sound/soc/mediatek/mt8188/mt8188-mt6359.c | 56 ++++++++++++++++++++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/sound/soc/mediatek/Kconfig b/sound/soc/mediatek/Kconfig index b93d455744ab..296b434caf81 100644 --- a/sound/soc/mediatek/Kconfig +++ b/sound/soc/mediatek/Kconfig @@ -252,6 +252,7 @@ config SND_SOC_MT8188_MT6359 select SND_SOC_NAU8315 select SND_SOC_NAU8825 select SND_SOC_RT5682S + select SND_SOC_ES8326 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 b4606a28794c..d1884f23a1a7 100644 --- a/sound/soc/mediatek/mt8188/mt8188-mt6359.c +++ b/sound/soc/mediatek/mt8188/mt8188-mt6359.c @@ -34,6 +34,8 @@ #define NAU8825_HS_PRESENT BIT(0) #define RT5682S_HS_PRESENT BIT(1) +#define ES8326_HS_PRESENT BIT(2) +#define MAX98390_TWO_AMP BIT(3) /* * Maxim MAX98390 */ @@ -48,6 +50,11 @@ */ #define NAU8825_CODEC_DAI "nau8825-hifi" +/* + * ES8326 + */ +#define ES8326_CODEC_DAI "ES8326 HiFi" + #define SOF_DMA_DL2 "SOF_DMA_DL2" #define SOF_DMA_DL3 "SOF_DMA_DL3" #define SOF_DMA_UL4 "SOF_DMA_UL4" @@ -888,6 +895,30 @@ static const struct snd_soc_ops mt8188_sof_be_ops = { .hw_params = mt8188_sof_be_hw_params, }; +static int mt8188_es8326_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params) +{ + struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); + 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 ret; + + /* Configure MCLK for codec */ + ret = snd_soc_dai_set_sysclk(codec_dai, 0, rate * 256, SND_SOC_CLOCK_IN); + if (ret < 0) { + dev_err(codec_dai->dev, "can't set MCLK %d\n", ret); + return ret; + } + + /* Configure MCLK for cpu */ + return snd_soc_dai_set_sysclk(cpu_dai, 0, rate * 256, SND_SOC_CLOCK_OUT); +} + +static const struct snd_soc_ops mt8188_es8326_ops = { + .hw_params = mt8188_es8326_hw_params, +}; + static struct snd_soc_dai_link mt8188_mt6359_dai_links[] = { /* FE */ [DAI_LINK_DL2_FE] = { @@ -1197,7 +1228,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 | RT5682S_HS_PRESENT)) { + if (card_data->quirk & (NAU8825_HS_PRESENT | RT5682S_HS_PRESENT | ES8326_HS_PRESENT)) { struct snd_soc_dapm_widget *w, *next_w; for_each_card_widgets_safe(card, w, next_w) { @@ -1238,6 +1269,7 @@ static int mt8188_mt6359_dev_probe(struct platform_device *pdev) struct mt8188_card_data *card_data; struct snd_soc_dai_link *dai_link; bool init_mt6359 = false; + bool init_es8326 = false; bool init_nau8825 = false; bool init_rt5682s = false; bool init_max98390 = false; @@ -1344,7 +1376,14 @@ static int mt8188_mt6359_dev_probe(struct platform_device *pdev) strcmp(dai_link->name, "ETDM1_IN_BE") == 0 || strcmp(dai_link->name, "ETDM2_IN_BE") == 0) { if (!strcmp(dai_link->codecs->dai_name, MAX98390_CODEC_DAI)) { - dai_link->ops = &mt8188_max98390_ops; + /* + * The TDM protocol settings with fixed 4 slots are defined in + * mt8188_max98390_ops. Two amps is I2S mode, + * SOC and codec don't require TDM settings. + */ + if (!(card_data->quirk & MAX98390_TWO_AMP)) { + dai_link->ops = &mt8188_max98390_ops; + } if (!init_max98390) { dai_link->init = mt8188_max98390_codec_init; init_max98390 = true; @@ -1363,6 +1402,13 @@ static int mt8188_mt6359_dev_probe(struct platform_device *pdev) dai_link->exit = mt8188_headset_codec_exit; init_rt5682s = true; } + } else if (!strcmp(dai_link->codecs->dai_name, ES8326_CODEC_DAI)) { + dai_link->ops = &mt8188_es8326_ops; + if (!init_es8326) { + dai_link->init = mt8188_headset_codec_init; + dai_link->exit = mt8188_headset_codec_exit; + init_es8326 = true; + } } else { if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai")) { if (!init_dumb) { @@ -1405,10 +1451,16 @@ static struct mt8188_card_data mt8188_rt5682s_card = { .quirk = RT5682S_HS_PRESENT, }; +static struct mt8188_card_data mt8188_es8326_card = { + .name = "mt8188_es8326", + .quirk = ES8326_HS_PRESENT | MAX98390_TWO_AMP, +}; + 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, }, + { .compatible = "mediatek,mt8188-es8326", .data = &mt8188_es8326_card, }, { /* sentinel */ }, }; MODULE_DEVICE_TABLE(of, mt8188_mt6359_dt_match);