From patchwork Fri May 26 09:31:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trevor Wu X-Patchwork-Id: 685953 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 06ED4C77B7C for ; Fri, 26 May 2023 09:35:44 +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 E7E691FE; Fri, 26 May 2023 11:34:52 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz E7E691FE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1685093743; bh=65tOch2Y6MXqyQdtfM7ZDxaNN//CkTWoNHMobAWexQA=; 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=BqJFAmJ2a6vxQUC2h0zl+g1/9wYQOB5bK2wJfHmC4sDhCy+C4Shg0O5OE5Kgg5vj8 otXu5nxzUaI+YZIacuQ2Qp8Jk/mnP5402IIQYHmslVQ28WkAik3O41RYh/Wllh2ubq OzFoI8RylbkwNH4sXkUKE20A1tPjVgxGxzHiZJRQ= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 34ED2F80563; Fri, 26 May 2023 11:33:58 +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 CEAEDF80564; Fri, 26 May 2023 11:33:57 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 96139F80542; Fri, 26 May 2023 11:32:19 +0200 (CEST) Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 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 B4113F80249 for ; Fri, 26 May 2023 11:32:03 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz B4113F80249 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=U3H0e6V/ X-UUID: 2685717cfba811edb20a276fd37b9834-20230526 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=6L+uHBH+GT44LFZu9z47mQWC0nQz60GKwD8yOpDVV1M=; b=U3H0e6V//cNH3j0GBvsvbdOT4Rh0CsCGOCQDSVDYFwXskADzhLoavtn3RPvYKppi5RQVnLD8Ydvs23Y0DrCiVIP88Fu3HN71resKWkfSkHoHZl2VgWuPX/cX7PBoJ/LYYgC6QPKV2biB3XKCyNSjN+qdKfgm6PK33qOVV/jOLMo=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.25, REQID:736b3c7c-babb-4d7c-87e8-b62da33b603d, IP:0, U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:d5b0ae3, CLOUDID:890e1a6d-2f20-4998-991c-3b78627e4938, B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-UUID: 2685717cfba811edb20a276fd37b9834-20230526 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 2012086621; Fri, 26 May 2023 17:31:53 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by mtkmbs11n2.mediatek.inc (172.21.101.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Fri, 26 May 2023 17:31:52 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs13n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Fri, 26 May 2023 17:31:52 +0800 From: Trevor Wu To: , , , , , , , , CC: , , , , , , Subject: [PATCH v3 4/7] ASoC: mediatek: common: soundcard driver add dai_fmt support Date: Fri, 26 May 2023 17:31:47 +0800 Message-ID: <20230526093150.22923-5-trevor.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20230526093150.22923-1-trevor.wu@mediatek.com> References: <20230526093150.22923-1-trevor.wu@mediatek.com> MIME-Version: 1.0 X-MTK: N Message-ID-Hash: BVEHQFH3L7CMNU3J6NK2SVP73XFQWYNW X-Message-ID-Hash: BVEHQFH3L7CMNU3J6NK2SVP73XFQWYNW X-MailFrom: trevor.wu@mediatek.com 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; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header 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: There are two changes included in the patch. First, add set_dailink_daifmt() function, so dai_fmt can be updated by the configuration in dai-link sub node. Second, remove codec phandle from required property in dai-link sub node. For example, user possibly needs to update dai-format for all etdm co-clock dai-links, but codec doesn't need to be specified in capture dai-link for a speaker amp. Signed-off-by: Trevor Wu Reviewed-by: Alexandre Mergnat --- .../mediatek/common/mtk-soundcard-driver.c | 53 ++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/sound/soc/mediatek/common/mtk-soundcard-driver.c b/sound/soc/mediatek/common/mtk-soundcard-driver.c index 738093451ccb..a58e1e3674de 100644 --- a/sound/soc/mediatek/common/mtk-soundcard-driver.c +++ b/sound/soc/mediatek/common/mtk-soundcard-driver.c @@ -21,8 +21,10 @@ static int set_card_codec_info(struct snd_soc_card *card, int ret; codec_node = of_get_child_by_name(sub_node, "codec"); - if (!codec_node) - return -EINVAL; + if (!codec_node) { + dev_dbg(dev, "%s no specified codec\n", dai_link->name); + return 0; + } /* set card codec info */ ret = snd_soc_of_get_dai_link_codecs(dev, codec_node, dai_link); @@ -36,6 +38,47 @@ static int set_card_codec_info(struct snd_soc_card *card, return 0; } +static int set_dailink_daifmt(struct snd_soc_card *card, + struct device_node *sub_node, + struct snd_soc_dai_link *dai_link) +{ + unsigned int daifmt; + const char *str; + int ret; + struct { + char *name; + unsigned int val; + } of_clk_table[] = { + { "cpu", SND_SOC_DAIFMT_CBC_CFC }, + { "codec", SND_SOC_DAIFMT_CBP_CFP }, + }; + + daifmt = snd_soc_daifmt_parse_format(sub_node, NULL); + if (daifmt) { + dai_link->dai_fmt &= SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK; + dai_link->dai_fmt |= daifmt; + } + + /* + * check "mediatek,clk-provider = xxx" + * SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK area + */ + ret = of_property_read_string(sub_node, "mediatek,clk-provider", &str); + if (ret == 0) { + int i; + + for (i = 0; i < ARRAY_SIZE(of_clk_table); i++) { + if (strcmp(str, of_clk_table[i].name) == 0) { + dai_link->dai_fmt &= ~SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK; + dai_link->dai_fmt |= of_clk_table[i].val; + break; + } + } + } + + return 0; +} + int parse_dai_link_info(struct snd_soc_card *card) { struct device *dev = card->dev; @@ -67,6 +110,12 @@ int parse_dai_link_info(struct snd_soc_card *card) of_node_put(sub_node); return ret; } + + ret = set_dailink_daifmt(card, sub_node, dai_link); + if (ret < 0) { + of_node_put(sub_node); + return ret; + } } return 0;