From: Darren.Ye <darren.ye@mediatek.com>
To: Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <brgl@bgdev.pl>
Cc: <linux-sound@vger.kernel.org>, <devicetree@vger.kernel.org>,
<linux-kernel@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-mediatek@lists.infradead.org>,
<linux-gpio@vger.kernel.org>, Darren Ye <darren.ye@mediatek.com>
Subject: [PATCH 04/14] ASoC: mediatek: mt8196: add common interface for mt8196 DAI driver
Date: Fri, 7 Mar 2025 20:47:30 +0800 [thread overview]
Message-ID: <20250307124841.23777-5-darren.ye@mediatek.com> (raw)
In-Reply-To: <20250307124841.23777-1-darren.ye@mediatek.com>
From: Darren Ye <darren.ye@mediatek.com>
Implement sample rate conversion and set private data for mt8196.
Signed-off-by: Darren Ye <darren.ye@mediatek.com>
---
.../soc/mediatek/mt8196/mt8196-afe-control.c | 109 ++++++++++++++++++
1 file changed, 109 insertions(+)
create mode 100644 sound/soc/mediatek/mt8196/mt8196-afe-control.c
diff --git a/sound/soc/mediatek/mt8196/mt8196-afe-control.c b/sound/soc/mediatek/mt8196/mt8196-afe-control.c
new file mode 100644
index 000000000000..bb85f4ad8585
--- /dev/null
+++ b/sound/soc/mediatek/mt8196/mt8196-afe-control.c
@@ -0,0 +1,109 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * MediaTek ALSA SoC Audio Control
+ *
+ * Copyright (c) 2024 MediaTek Inc.
+ * Author: Darren Ye <darren.ye@mediatek.com>
+ */
+
+#include "mt8196-afe-common.h"
+#include <linux/pm_runtime.h>
+
+unsigned int mt8196_general_rate_transform(struct device *dev,
+ unsigned int rate)
+{
+ switch (rate) {
+ case 8000:
+ return MTK_AFE_IPM2P0_RATE_8K;
+ case 11025:
+ return MTK_AFE_IPM2P0_RATE_11K;
+ case 12000:
+ return MTK_AFE_IPM2P0_RATE_12K;
+ case 16000:
+ return MTK_AFE_IPM2P0_RATE_16K;
+ case 22050:
+ return MTK_AFE_IPM2P0_RATE_22K;
+ case 24000:
+ return MTK_AFE_IPM2P0_RATE_24K;
+ case 32000:
+ return MTK_AFE_IPM2P0_RATE_32K;
+ case 44100:
+ return MTK_AFE_IPM2P0_RATE_44K;
+ case 48000:
+ return MTK_AFE_IPM2P0_RATE_48K;
+ case 88200:
+ return MTK_AFE_IPM2P0_RATE_88K;
+ case 96000:
+ return MTK_AFE_IPM2P0_RATE_96K;
+ case 176400:
+ return MTK_AFE_IPM2P0_RATE_176K;
+ case 192000:
+ return MTK_AFE_IPM2P0_RATE_192K;
+ /* not support 260K */
+ case 352800:
+ return MTK_AFE_IPM2P0_RATE_352K;
+ case 384000:
+ return MTK_AFE_IPM2P0_RATE_384K;
+ default:
+ dev_info(dev, "%s(), rate %u invalid, use %d!!!\n",
+ __func__,
+ rate, MTK_AFE_IPM2P0_RATE_48K);
+ return MTK_AFE_IPM2P0_RATE_48K;
+ }
+}
+
+static unsigned int pcm_rate_transform(struct device *dev,
+ unsigned int rate)
+{
+ switch (rate) {
+ case 8000:
+ return MTK_AFE_PCM_RATE_8K;
+ case 16000:
+ return MTK_AFE_PCM_RATE_16K;
+ case 32000:
+ return MTK_AFE_PCM_RATE_32K;
+ case 48000:
+ return MTK_AFE_PCM_RATE_48K;
+ default:
+ dev_info(dev, "%s(), rate %u invalid, use %d!!!\n",
+ __func__,
+ rate, MTK_AFE_PCM_RATE_32K);
+ return MTK_AFE_PCM_RATE_32K;
+ }
+}
+
+unsigned int mt8196_rate_transform(struct device *dev,
+ unsigned int rate, int aud_blk)
+{
+ switch (aud_blk) {
+ case MT8196_DAI_PCM_0:
+ case MT8196_DAI_PCM_1:
+ return pcm_rate_transform(dev, rate);
+ default:
+ return mt8196_general_rate_transform(dev, rate);
+ }
+}
+
+int mt8196_dai_set_priv(struct mtk_base_afe *afe, int id,
+ int priv_size, const void *priv_data)
+{
+ struct mt8196_afe_private *afe_priv = afe->platform_priv;
+ void *temp_data;
+
+ temp_data = devm_kzalloc(afe->dev,
+ priv_size,
+ GFP_KERNEL);
+ if (!temp_data)
+ return -ENOMEM;
+
+ if (priv_data)
+ memcpy(temp_data, priv_data, priv_size);
+
+ if (id >= MT8196_DAI_NUM || id < 0)
+ return -EINVAL;
+
+ afe_priv->dai_priv[id] = temp_data;
+
+ return 0;
+}
+
--
2.45.2
next prev parent reply other threads:[~2025-03-07 12:49 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-07 12:47 [PATCH 00/14] ASoC: mediatek: Add support for MT8196 SoC Darren.Ye
2025-03-07 12:47 ` [PATCH 01/14] ASoC: mediatek: common: modify mtk afe common driver for mt8196 Darren.Ye
2025-03-07 15:20 ` Krzysztof Kozlowski
2025-03-10 15:23 ` AngeloGioacchino Del Regno
2025-03-07 12:47 ` [PATCH 02/14] ASoC: mediatek: common: modify mtk afe platform " Darren.Ye
2025-03-07 15:21 ` Krzysztof Kozlowski
2025-03-07 12:47 ` [PATCH 03/14] ASoC: mediatek: mt8196: add common header Darren.Ye
2025-03-07 12:47 ` Darren.Ye [this message]
2025-03-07 15:22 ` [PATCH 04/14] ASoC: mediatek: mt8196: add common interface for mt8196 DAI driver Krzysztof Kozlowski
2025-03-10 15:23 ` AngeloGioacchino Del Regno
2025-03-07 12:47 ` [PATCH 05/14] ASoC: mediatek: mt8196: support audio clock control Darren.Ye
2025-03-07 15:32 ` Krzysztof Kozlowski
2025-03-10 15:23 ` AngeloGioacchino Del Regno
2025-03-07 12:47 ` [PATCH 06/14] ASoC: mediatek: mt8196: support audio GPIO control Darren.Ye
2025-03-14 10:21 ` Linus Walleij
2025-03-07 12:47 ` [PATCH 07/14] ASoC: mediatek: mt8196: support ADDA in platform driver Darren.Ye
2025-03-07 12:47 ` [PATCH 08/14] ASoC: mediatek: mt8196: support I2S " Darren.Ye
2025-03-07 15:24 ` Krzysztof Kozlowski
2025-03-07 12:47 ` [PATCH 09/14] ASoC: mediatek: mt8196: support TDM " Darren.Ye
2025-03-07 12:47 ` [PATCH 10/14] ASoC: mediatek: mt8196: support CM " Darren.Ye
2025-03-07 15:33 ` Krzysztof Kozlowski
2025-03-07 12:47 ` [PATCH 11/14] ASoC: mediatek: mt8196: add " Darren.Ye
2025-03-07 15:32 ` Krzysztof Kozlowski
2025-03-07 12:47 ` [PATCH 12/14] dt-bindings: mediatek: mt8196: add audio AFE document Darren.Ye
2025-03-07 14:35 ` Rob Herring (Arm)
2025-03-07 15:15 ` Krzysztof Kozlowski
2025-03-07 12:47 ` [PATCH 13/14] ASoC: mediatek: mt8196: add machine driver with mt6681 Darren.Ye
2025-03-07 12:47 ` [PATCH 14/14] dt-bindings: mediatek: mt8196: add mt8196-mt6681 document Darren.Ye
2025-03-07 14:35 ` Rob Herring (Arm)
2025-03-07 15:19 ` Krzysztof Kozlowski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250307124841.23777-5-darren.ye@mediatek.com \
--to=darren.ye@mediatek.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=brgl@bgdev.pl \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linus.walleij@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-sound@vger.kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=perex@perex.cz \
--cc=robh@kernel.org \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox