From patchwork Wed May 17 11:15:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?VHJldm9yIFd1ICjlkLPmlofoia8p?= X-Patchwork-Id: 13244740 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 0F58DC77B75 for ; Wed, 17 May 2023 11:20: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 67DDA1F7; Wed, 17 May 2023 13:19:11 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 67DDA1F7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684322401; bh=myE6rSm2A9YRtZMvo4Djss9NyJPPIcdTAXvvCn2nX/M=; 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=JqcCdgK8nooJ0/umaYXq30tKUWL9ogfNDBl/z2wK4zQiVi+xwuJRvfNjM8JNvNV39 0XVloCorlFZ/QtLXQAOdlMvT/tMS3/vFYyqP2l8CtqdvtG81pBLZyWXTJUZQe3C/Sj WSquKwps58QGeY5to6Ox2eYteyKlVPMxp5P0hzH0= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 94FB6F80431; Wed, 17 May 2023 13:16:18 +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 5855CF80563; Wed, 17 May 2023 13:16:18 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id EEC0BF80563; Wed, 17 May 2023 13:16:14 +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 CD9F2F80431 for ; Wed, 17 May 2023 13:15:45 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz CD9F2F80431 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=In0Hu4Yu X-UUID: 2663cb7cf4a411edb20a276fd37b9834-20230517 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=wwKjF0dgzn4sw9jpbPBz5pPHmhzAFBmOncmAdxxMpSI=; b=In0Hu4YuoBIhqfB9NYjBci5iTL+8KBpVSuk7LCvYwtvcGEuTMyQl/xsFdZSxD71D6/4Sp7+94Doznoeig3AGeui01eqXa5csERSktEPm6oIzcd7tl+nLXXDCHgFol0NsYVYzrRDQQJ6ZnMfSPy3JJLVtjPnXL51/QNBsr8LmHtM=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.25,REQID:144c14fc-ad09-4290-9dcc-2c7883357a71,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:071a793b-de1e-4348-bc35-c96f92f1dcbb,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: 2663cb7cf4a411edb20a276fd37b9834-20230517 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 1830841433; Wed, 17 May 2023 19:15:37 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.186) 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.1118.26; Wed, 17 May 2023 19:15:36 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Wed, 17 May 2023 19:15:36 +0800 From: Trevor Wu To: , , , , , , , , CC: , , , , , Subject: [PATCH 3/5] ASoC: mediatek: common: soundcard driver add dai_fmt support Date: Wed, 17 May 2023 19:15:32 +0800 Message-ID: <20230517111534.32630-4-trevor.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20230517111534.32630-1-trevor.wu@mediatek.com> References: <20230517111534.32630-1-trevor.wu@mediatek.com> MIME-Version: 1.0 X-MTK: N Message-ID-Hash: 5PZLLSOVBFEX5FOXVKEY6TYNBSLA7HGM X-Message-ID-Hash: 5PZLLSOVBFEX5FOXVKEY6TYNBSLA7HGM 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 --- .../mediatek/common/mtk-soundcard-driver.c | 49 ++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/sound/soc/mediatek/common/mtk-soundcard-driver.c b/sound/soc/mediatek/common/mtk-soundcard-driver.c index 738093451ccb..5e291092046b 100644 --- a/sound/soc/mediatek/common/mtk-soundcard-driver.c +++ b/sound/soc/mediatek/common/mtk-soundcard-driver.c @@ -22,7 +22,7 @@ static int set_card_codec_info(struct snd_soc_card *card, codec_node = of_get_child_by_name(sub_node, "codec"); if (!codec_node) - return -EINVAL; + return 0; /* set card codec info */ ret = snd_soc_of_get_dai_link_codecs(dev, codec_node, dai_link); @@ -36,6 +36,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 +108,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;