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 10/14] ASoC: mediatek: mt8196: support CM in platform driver
Date: Fri, 7 Mar 2025 20:47:36 +0800 [thread overview]
Message-ID: <20250307124841.23777-11-darren.ye@mediatek.com> (raw)
In-Reply-To: <20250307124841.23777-1-darren.ye@mediatek.com>
From: Darren Ye <darren.ye@mediatek.com>
Add mt8196 CM driver support for ADDA multi-channel.
Signed-off-by: Darren Ye <darren.ye@mediatek.com>
---
sound/soc/mediatek/mt8196/mt8196-afe-cm.c | 94 +++++++++++++++++++++++
sound/soc/mediatek/mt8196/mt8196-afe-cm.h | 23 ++++++
2 files changed, 117 insertions(+)
create mode 100644 sound/soc/mediatek/mt8196/mt8196-afe-cm.c
create mode 100644 sound/soc/mediatek/mt8196/mt8196-afe-cm.h
diff --git a/sound/soc/mediatek/mt8196/mt8196-afe-cm.c b/sound/soc/mediatek/mt8196/mt8196-afe-cm.c
new file mode 100644
index 000000000000..b923844a76f8
--- /dev/null
+++ b/sound/soc/mediatek/mt8196/mt8196-afe-cm.c
@@ -0,0 +1,94 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2024 MediaTek Inc.
+ * Author: Darren Ye <darren.ye@mediatek.com>
+ */
+
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/regmap.h>
+#include <sound/soc.h>
+
+#include "mtk-afe-fe-dai.h"
+#include "mtk-base-afe.h"
+
+#include "mt8196-afe-cm.h"
+#include "mt8196-afe-common.h"
+
+void mt8196_set_cm_rate(struct mtk_base_afe *afe, int id, unsigned int rate)
+{
+ struct mt8196_afe_private *afe_priv = afe->platform_priv;
+
+ afe_priv->cm_rate[id] = rate;
+}
+EXPORT_SYMBOL_GPL(mt8196_set_cm_rate);
+
+static int mt8196_convert_cm_ch(unsigned int ch)
+{
+ return ch - 1;
+}
+
+static unsigned int calculate_cm_update(int rate, int ch)
+{
+ unsigned int update_val;
+
+ update_val = 26000000 / rate / (ch / 2);
+ update_val = update_val * 10 / 7;
+ if (update_val > 100)
+ update_val = 100;
+ if (update_val < 7)
+ update_val = 7;
+
+ return update_val;
+}
+
+int mt8196_set_cm(struct mtk_base_afe *afe, int id,
+ bool update, bool swap, unsigned int ch)
+{
+ unsigned int rate = 0;
+ unsigned int update_val = 0;
+ int reg;
+ struct mt8196_afe_private *afe_priv = afe->platform_priv;
+
+ dev_dbg(afe->dev, "%s()-0, CM%d, rate %d, update %d, swap %d, ch %d\n",
+ __func__, id, rate, update, swap, ch);
+
+ rate = afe_priv->cm_rate[id];
+ update_val = update ? calculate_cm_update(rate, (int)ch) : 0x64;
+
+ reg = AFE_CM0_CON0 + 0x10 * id;
+ /* update cnt */
+ mtk_regmap_update_bits(afe->regmap, reg, AFE_CM_UPDATE_CNT_MASK,
+ update_val, AFE_CM_UPDATE_CNT_SFT);
+
+ /* rate */
+ mtk_regmap_update_bits(afe->regmap, reg, AFE_CM_1X_EN_SEL_FS_MASK,
+ rate, AFE_CM_1X_EN_SEL_FS_SFT);
+
+ /* ch num */
+ ch = mt8196_convert_cm_ch(ch);
+ mtk_regmap_update_bits(afe->regmap, reg, AFE_CM_CH_NUM_MASK,
+ ch, AFE_CM_CH_NUM_SFT);
+
+ /* swap */
+ mtk_regmap_update_bits(afe->regmap, reg, AFE_CM_BYTE_SWAP_MASK,
+ swap, AFE_CM_BYTE_SWAP_SFT);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(mt8196_set_cm);
+
+int mt8196_enable_cm_bypass(struct mtk_base_afe *afe, int id, bool en)
+{
+ int reg = AFE_CM0_CON0 + 0x10 * id;
+
+ mtk_regmap_update_bits(afe->regmap, reg, AFE_CM_BYPASS_MODE_MASK,
+ en, AFE_CM_BYPASS_MODE_SFT);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(mt8196_enable_cm_bypass);
+
+MODULE_DESCRIPTION("Mediatek afe cm");
+MODULE_AUTHOR("darren ye <darren.ye@mediatek.com>");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/mediatek/mt8196/mt8196-afe-cm.h b/sound/soc/mediatek/mt8196/mt8196-afe-cm.h
new file mode 100644
index 000000000000..18115ec8fa70
--- /dev/null
+++ b/sound/soc/mediatek/mt8196/mt8196-afe-cm.h
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2024 MediaTek Inc.
+ * Author: Darren Ye <darren.ye@mediatek.com>
+ */
+
+#ifndef MTK_AFE_CM_H_
+#define MTK_AFE_CM_H_
+enum {
+ CM0,
+ CM1,
+ CM2,
+ CM_NUM,
+};
+
+void mt8196_set_cm_rate(struct mtk_base_afe *afe, int id, unsigned int rate);
+
+int mt8196_set_cm(struct mtk_base_afe *afe, int id, bool update,
+ bool swap, unsigned int ch);
+int mt8196_enable_cm_bypass(struct mtk_base_afe *afe, int id, bool en);
+
+#endif /* MTK_AFE_CM_H_ */
+
--
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 ` [PATCH 04/14] ASoC: mediatek: mt8196: add common interface for mt8196 DAI driver Darren.Ye
2025-03-07 15:22 ` 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 ` Darren.Ye [this message]
2025-03-07 15:33 ` [PATCH 10/14] ASoC: mediatek: mt8196: support CM " 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-11-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