From nobody Sat Sep 21 06:46:33 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF802C46467 for ; Mon, 16 Jan 2023 03:41:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231851AbjAPDlw (ORCPT ); Sun, 15 Jan 2023 22:41:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231787AbjAPDlr (ORCPT ); Sun, 15 Jan 2023 22:41:47 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8EF37A87; Sun, 15 Jan 2023 19:41:44 -0800 (PST) X-UUID: aee95228954f11eda06fc9ecc4dadd91-20230116 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=QsXVaBlLyZgLe3Omky45vD7Ia8dAb9dNk+EXoNiFXQE=; b=RuGMsMymFkAVicw6LOsqDlpLkRl2osnjAjZE7QvLcOEenn2NoBYw+A15t5LmeWa6/ZPrhWISStgu1oeI0E5XfE7G/Kp02FBePvJhB8JoMAXS/kqs/wnsHphNxbC1IjLeKjXqiPp9b76cQy7x9xjAqpOrj+6byDkTbIUBvVbXW+k=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.17,REQID:68f84e90-063d-4c0a-8451-dfd6d3202cd7,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:543e81c,CLOUDID:def1bb54-dd49-462e-a4be-2143a3ddc739,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 X-CID-BVR: 0,NGT X-UUID: aee95228954f11eda06fc9ecc4dadd91-20230116 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 423806250; Mon, 16 Jan 2023 11:41:38 +0800 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) 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.792.15; Mon, 16 Jan 2023 11:41:37 +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; Mon, 16 Jan 2023 11:41:37 +0800 From: Trevor Wu To: , , , , , , , CC: , , , , , , , Subject: [RESEND,v5 11/13] ASoC: mediatek: common: add soundcard driver common code Date: Mon, 16 Jan 2023 11:41:29 +0800 Message-ID: <20230116034131.23943-12-trevor.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20230116034131.23943-1-trevor.wu@mediatek.com> References: <20230116034131.23943-1-trevor.wu@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add common code to support of_node of codec parsing, so codec phandle can be assigned by sound-dai in dts. Signed-off-by: Trevor Wu Reviewed-by: AngeloGioacchino Del Regno --- sound/soc/mediatek/common/Makefile | 2 +- .../mediatek/common/mtk-soundcard-driver.c | 79 +++++++++++++++++++ .../mediatek/common/mtk-soundcard-driver.h | 14 ++++ 3 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 sound/soc/mediatek/common/mtk-soundcard-driver.c create mode 100644 sound/soc/mediatek/common/mtk-soundcard-driver.h diff --git a/sound/soc/mediatek/common/Makefile b/sound/soc/mediatek/common= /Makefile index 576deb7f8cce..42e636c10c1e 100644 --- a/sound/soc/mediatek/common/Makefile +++ b/sound/soc/mediatek/common/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 # platform driver -snd-soc-mtk-common-objs :=3D mtk-afe-platform-driver.o mtk-afe-fe-dai.o mt= k-dsp-sof-common.o +snd-soc-mtk-common-objs :=3D mtk-afe-platform-driver.o mtk-afe-fe-dai.o mt= k-dsp-sof-common.o mtk-soundcard-driver.o obj-$(CONFIG_SND_SOC_MEDIATEK) +=3D snd-soc-mtk-common.o =20 obj-$(CONFIG_SND_SOC_MTK_BTCVSD) +=3D mtk-btcvsd.o diff --git a/sound/soc/mediatek/common/mtk-soundcard-driver.c b/sound/soc/m= ediatek/common/mtk-soundcard-driver.c new file mode 100644 index 000000000000..7c55c2cb1f21 --- /dev/null +++ b/sound/soc/mediatek/common/mtk-soundcard-driver.c @@ -0,0 +1,79 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * mtk-soundcard-driver.c -- MediaTek soundcard driver common + * + * Copyright (c) 2022 MediaTek Inc. + * Author: Trevor Wu + */ + +#include +#include +#include + +#include "mtk-soundcard-driver.h" + +static int set_card_codec_info(struct snd_soc_card *card, + struct device_node *sub_node, + struct snd_soc_dai_link *dai_link) +{ + struct device *dev =3D card->dev; + struct device_node *codec_node; + int ret; + + codec_node =3D of_get_child_by_name(sub_node, "codec"); + if (!codec_node) + return -EINVAL; + + /* set card codec info */ + ret =3D snd_soc_of_get_dai_link_codecs(dev, codec_node, dai_link); + + of_node_put(codec_node); + + if (ret < 0) + return dev_err_probe(dev, ret, "%s: codec dai not found\n", + dai_link->name); + + return 0; +} + +int parse_dai_link_info(struct snd_soc_card *card) +{ + struct device *dev =3D card->dev; + struct device_node *sub_node; + struct snd_soc_dai_link *dai_link; + const char *dai_link_name; + int ret, i; + + /* Loop over all the dai link sub nodes */ + for_each_available_child_of_node(dev->of_node, sub_node) { + if (of_property_read_string(sub_node, "link-name", + &dai_link_name)) + return -EINVAL; + + for_each_card_prelinks(card, i, dai_link) { + if (!strcmp(dai_link_name, dai_link->name)) + break; + } + + if (i >=3D card->num_links) + return -EINVAL; + + ret =3D set_card_codec_info(card, sub_node, dai_link); + if (ret < 0) + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(parse_dai_link_info); + +void clean_card_reference(struct snd_soc_card *card) +{ + struct snd_soc_dai_link *dai_link; + int i; + + /* release codec reference gotten by set_card_codec_info */ + for_each_card_prelinks(card, i, dai_link) + snd_soc_of_put_dai_link_codecs(dai_link); +} +EXPORT_SYMBOL_GPL(clean_card_reference); diff --git a/sound/soc/mediatek/common/mtk-soundcard-driver.h b/sound/soc/m= ediatek/common/mtk-soundcard-driver.h new file mode 100644 index 000000000000..d92cac1d7b72 --- /dev/null +++ b/sound/soc/mediatek/common/mtk-soundcard-driver.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * mtk-soundcard-driver.h -- MediaTek soundcard driver common definition + * + * Copyright (c) 2022 MediaTek Inc. + * Author: Trevor Wu + */ + +#ifndef _MTK_SOUNDCARD_DRIVER_H_ +#define _MTK_SOUNDCARD_DRIVER_H_ + +int parse_dai_link_info(struct snd_soc_card *card); +void clean_card_reference(struct snd_soc_card *card); +#endif --=20 2.18.0