diff mbox series

[10/14] ASoC: mediatek: mt8196: support CM in platform driver

Message ID 20250307124841.23777-11-darren.ye@mediatek.com (mailing list archive)
State New
Headers show
Series ASoC: mediatek: Add support for MT8196 SoC | expand

Commit Message

Darren.Ye March 7, 2025, 12:47 p.m. UTC
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

Comments

Krzysztof Kozlowski March 7, 2025, 3:33 p.m. UTC | #1
On 07/03/2025 13:47, Darren.Ye wrote:
> +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");

If this is module, where is Makefile and Kconfig?

All previous comments about missing kerneldoc also apply.

Best regards,
Krzysztof
diff mbox series

Patch

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_ */
+