From patchwork Fri Dec 9 03:10:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: YC Hung X-Patchwork-Id: 13069207 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 98317C4332F for ; Fri, 9 Dec 2022 03:12:08 +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 68C9818E6; Fri, 9 Dec 2022 04:11:16 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 68C9818E6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1670555526; bh=IZlZhAPS/q6uyTz3wuxhj99OcjDMXb3bMNVWBtEsfVw=; h=From:To:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:Cc:From; b=TeOIStlvgKgyTWFHnecpCiW6ZYw3WInjJ49W1zcUs3uRkwXnkQvAaDczbSrMCVhnO +qvCJ6Rkrkb6/e+5zhittD3hcSpsiGgUc7lIFPzd8OEwNVcXlsFEAN6tAcF2mv04Ll cFgl6SWkwVqZNIyQrGXdAg2r881F0/Tl8W1H5ZRo= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 1D1E5F8022B; Fri, 9 Dec 2022 04:11:16 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 7FDFFF8022D; Fri, 9 Dec 2022 04:11:14 +0100 (CET) Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 609C2F8016E for ; Fri, 9 Dec 2022 04:11:09 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 609C2F8016E Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key, unprotected) header.d=mediatek.com header.i=@mediatek.com header.a=rsa-sha256 header.s=dk header.b=jEcYxOzA X-UUID: 477afe1c999b4addaeae07fecc270c2f-20221209 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=0IUYP1FMYMYrYJClJDGBDoSMePz+IPYu2tTV/hqTIg4=; b=jEcYxOzAoNoSBkLUSERUCtUaMruZag/aG/ZvjITUyuxv6zTVXPoQdFbgwrKyKgZVovE0EW69zY38t+HGVGM1dy70mIvt6RfmJ0xKco38ujCG66VTtvor29grs/RZtFiRZgZnQAE9k8F9T/hlpbdYdUVBEwmBoenK1X8J7lYNXLM=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.14, REQID:b2a5f13b-35ac-4432-a0ce-cf9ad2ad1484, IP:0, U RL:0,TC:0,Content:-5,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:90 X-CID-INFO: VERSION:1.1.14, REQID:b2a5f13b-35ac-4432-a0ce-cf9ad2ad1484, IP:0, URL :0,TC:0,Content:-5,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Spam_GS981B3D,ACTIO N:quarantine,TS:90 X-CID-META: VersionHash:dcaaed0, CLOUDID:2d1615d2-652d-43fd-a13a-a5dd3c69a43d, B ulkID:221209111100ORC5MHTL,BulkQuantity:1,Recheck:0,SF:40|28|17|19|48,TC:n il,Content:0,EDM:-3,IP:nil,URL:0,File:nil,Bulk:40,QS:nil,BEC:nil,COL:0 X-UUID: 477afe1c999b4addaeae07fecc270c2f-20221209 Received: from mtkcas10.mediatek.inc [(172.21.101.39)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 354103708; Fri, 09 Dec 2022 11:10:59 +0800 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.15; Fri, 9 Dec 2022 11:10:58 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Fri, 9 Dec 2022 11:10:58 +0800 From: YC Hung To: Subject: [PATCH] ASoC: mediatek: mt8195: add sof be ops to check audio active Date: Fri, 9 Dec 2022 11:10:53 +0800 Message-ID: <20221209031053.8444-1-yc.hung@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 X-MTK: N X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.29 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: , Cc: alsa-devel@alsa-project.org, "Nicolas F . R . A . Prado" , Liam Girdwood , linux-kernel@vger.kernel.org, whalechang@google.com, Takashi Iwai , Jiaxin Yu , Mark Brown , linux-mediatek@lists.infradead.org, Trevor Wu , Tzung-Bi Shih , yc.hung@mediatek.com, Matthias Brugger , Curtis Malainey , linux-arm-kernel@lists.infradead.org, AngeloGioacchino Del Regno Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" In MT8195 SOF design, both DSP and audio driver would access audio registers. Before DSP accesses audio registers, audio power and clock should be enabled. DSP will hang up if DSP access audio register but audio power and clock are disabled. Therefore, we add audio pm runtime active checking before accessing audio registers in SOF BE's callback hw_params function to avoid this situation. Signed-off-by: YC Hung Acked-by: Curtis Malainey Reviewed-by: AngeloGioacchino Del Regno --- sound/soc/mediatek/mt8195/mt8195-mt6359.c | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/sound/soc/mediatek/mt8195/mt8195-mt6359.c b/sound/soc/mediatek/mt8195/mt8195-mt6359.c index 61be66f47723..4682748d82be 100644 --- a/sound/soc/mediatek/mt8195/mt8195-mt6359.c +++ b/sound/soc/mediatek/mt8195/mt8195-mt6359.c @@ -633,6 +633,32 @@ static const struct snd_soc_ops mt8195_rt1011_etdm_ops = { .hw_params = mt8195_rt1011_etdm_hw_params, }; +static int mt8195_sof_be_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params) +{ + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); + struct snd_soc_component *cmpnt_afe = NULL; + struct snd_soc_pcm_runtime *runtime; + + /* find afe component */ + for_each_card_rtds(rtd->card, runtime) { + cmpnt_afe = snd_soc_rtdcom_lookup(runtime, AFE_PCM_NAME); + if (cmpnt_afe) + break; + } + + if (cmpnt_afe && !pm_runtime_active(cmpnt_afe->dev)) { + dev_err(rtd->dev, "afe pm runtime is not active!!\n"); + return -EINVAL; + } + + return 0; +} + +static const struct snd_soc_ops mt8195_sof_be_ops = { + .hw_params = mt8195_sof_be_hw_params, +}; + static int mt8195_rt1011_init(struct snd_soc_pcm_runtime *rtd) { struct snd_soc_card *card = rtd->card; @@ -1272,24 +1298,28 @@ static struct snd_soc_dai_link mt8195_mt6359_dai_links[] = { .name = "AFE_SOF_DL2", .no_pcm = 1, .dpcm_playback = 1, + .ops = &mt8195_sof_be_ops, SND_SOC_DAILINK_REG(AFE_SOF_DL2), }, [DAI_LINK_SOF_DL3_BE] = { .name = "AFE_SOF_DL3", .no_pcm = 1, .dpcm_playback = 1, + .ops = &mt8195_sof_be_ops, SND_SOC_DAILINK_REG(AFE_SOF_DL3), }, [DAI_LINK_SOF_UL4_BE] = { .name = "AFE_SOF_UL4", .no_pcm = 1, .dpcm_capture = 1, + .ops = &mt8195_sof_be_ops, SND_SOC_DAILINK_REG(AFE_SOF_UL4), }, [DAI_LINK_SOF_UL5_BE] = { .name = "AFE_SOF_UL5", .no_pcm = 1, .dpcm_capture = 1, + .ops = &mt8195_sof_be_ops, SND_SOC_DAILINK_REG(AFE_SOF_UL5), }, };