xref: /linux/sound/soc/mediatek/mt8365/mt8365-afe-pcm.c (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
1e1991d10SAlexandre Mergnat // SPDX-License-Identifier: GPL-2.0
2e1991d10SAlexandre Mergnat /*
3e1991d10SAlexandre Mergnat  * MediaTek 8365 ALSA SoC AFE platform driver
4e1991d10SAlexandre Mergnat  *
5e1991d10SAlexandre Mergnat  * Copyright (c) 2024 MediaTek Inc.
6e1991d10SAlexandre Mergnat  * Authors: Jia Zeng <jia.zeng@mediatek.com>
7e1991d10SAlexandre Mergnat  *          Alexandre Mergnat <amergnat@baylibre.com>
8e1991d10SAlexandre Mergnat  */
9e1991d10SAlexandre Mergnat 
10e1991d10SAlexandre Mergnat #include <linux/delay.h>
11e1991d10SAlexandre Mergnat #include <linux/module.h>
12e1991d10SAlexandre Mergnat #include <linux/of.h>
13e1991d10SAlexandre Mergnat #include <linux/of_address.h>
14e1991d10SAlexandre Mergnat #include <linux/dma-mapping.h>
15e1991d10SAlexandre Mergnat #include <linux/pm_runtime.h>
16e1991d10SAlexandre Mergnat #include <sound/soc.h>
17e1991d10SAlexandre Mergnat #include <sound/pcm_params.h>
18e1991d10SAlexandre Mergnat #include "mt8365-afe-common.h"
19e1991d10SAlexandre Mergnat #include "mt8365-afe-clk.h"
20e1991d10SAlexandre Mergnat #include "mt8365-reg.h"
21e1991d10SAlexandre Mergnat #include "../common/mtk-base-afe.h"
22e1991d10SAlexandre Mergnat #include "../common/mtk-afe-platform-driver.h"
23e1991d10SAlexandre Mergnat #include "../common/mtk-afe-fe-dai.h"
24e1991d10SAlexandre Mergnat 
25e1991d10SAlexandre Mergnat #define AFE_BASE_END_OFFSET 8
26e1991d10SAlexandre Mergnat 
27e1991d10SAlexandre Mergnat static unsigned int mCM2Input;
28e1991d10SAlexandre Mergnat 
29e1991d10SAlexandre Mergnat static const unsigned int mt8365_afe_backup_list[] = {
30e1991d10SAlexandre Mergnat 	AUDIO_TOP_CON0,
31e1991d10SAlexandre Mergnat 	AFE_CONN0,
32e1991d10SAlexandre Mergnat 	AFE_CONN1,
33e1991d10SAlexandre Mergnat 	AFE_CONN3,
34e1991d10SAlexandre Mergnat 	AFE_CONN4,
35e1991d10SAlexandre Mergnat 	AFE_CONN5,
36e1991d10SAlexandre Mergnat 	AFE_CONN6,
37e1991d10SAlexandre Mergnat 	AFE_CONN7,
38e1991d10SAlexandre Mergnat 	AFE_CONN8,
39e1991d10SAlexandre Mergnat 	AFE_CONN9,
40e1991d10SAlexandre Mergnat 	AFE_CONN10,
41e1991d10SAlexandre Mergnat 	AFE_CONN11,
42e1991d10SAlexandre Mergnat 	AFE_CONN12,
43e1991d10SAlexandre Mergnat 	AFE_CONN13,
44e1991d10SAlexandre Mergnat 	AFE_CONN14,
45e1991d10SAlexandre Mergnat 	AFE_CONN15,
46e1991d10SAlexandre Mergnat 	AFE_CONN16,
47e1991d10SAlexandre Mergnat 	AFE_CONN17,
48e1991d10SAlexandre Mergnat 	AFE_CONN18,
49e1991d10SAlexandre Mergnat 	AFE_CONN19,
50e1991d10SAlexandre Mergnat 	AFE_CONN20,
51e1991d10SAlexandre Mergnat 	AFE_CONN21,
52e1991d10SAlexandre Mergnat 	AFE_CONN26,
53e1991d10SAlexandre Mergnat 	AFE_CONN27,
54e1991d10SAlexandre Mergnat 	AFE_CONN28,
55e1991d10SAlexandre Mergnat 	AFE_CONN29,
56e1991d10SAlexandre Mergnat 	AFE_CONN30,
57e1991d10SAlexandre Mergnat 	AFE_CONN31,
58e1991d10SAlexandre Mergnat 	AFE_CONN32,
59e1991d10SAlexandre Mergnat 	AFE_CONN33,
60e1991d10SAlexandre Mergnat 	AFE_CONN34,
61e1991d10SAlexandre Mergnat 	AFE_CONN35,
62e1991d10SAlexandre Mergnat 	AFE_CONN36,
63e1991d10SAlexandre Mergnat 	AFE_CONN_24BIT,
64e1991d10SAlexandre Mergnat 	AFE_CONN_24BIT_1,
65e1991d10SAlexandre Mergnat 	AFE_DAC_CON0,
66e1991d10SAlexandre Mergnat 	AFE_DAC_CON1,
67e1991d10SAlexandre Mergnat 	AFE_DL1_BASE,
68e1991d10SAlexandre Mergnat 	AFE_DL1_END,
69e1991d10SAlexandre Mergnat 	AFE_DL2_BASE,
70e1991d10SAlexandre Mergnat 	AFE_DL2_END,
71e1991d10SAlexandre Mergnat 	AFE_VUL_BASE,
72e1991d10SAlexandre Mergnat 	AFE_VUL_END,
73e1991d10SAlexandre Mergnat 	AFE_AWB_BASE,
74e1991d10SAlexandre Mergnat 	AFE_AWB_END,
75e1991d10SAlexandre Mergnat 	AFE_VUL3_BASE,
76e1991d10SAlexandre Mergnat 	AFE_VUL3_END,
77e1991d10SAlexandre Mergnat 	AFE_HDMI_OUT_BASE,
78e1991d10SAlexandre Mergnat 	AFE_HDMI_OUT_END,
79e1991d10SAlexandre Mergnat 	AFE_HDMI_IN_2CH_BASE,
80e1991d10SAlexandre Mergnat 	AFE_HDMI_IN_2CH_END,
81e1991d10SAlexandre Mergnat 	AFE_ADDA_UL_DL_CON0,
82e1991d10SAlexandre Mergnat 	AFE_ADDA_DL_SRC2_CON0,
83e1991d10SAlexandre Mergnat 	AFE_ADDA_DL_SRC2_CON1,
84e1991d10SAlexandre Mergnat 	AFE_I2S_CON,
85e1991d10SAlexandre Mergnat 	AFE_I2S_CON1,
86e1991d10SAlexandre Mergnat 	AFE_I2S_CON2,
87e1991d10SAlexandre Mergnat 	AFE_I2S_CON3,
88e1991d10SAlexandre Mergnat 	AFE_ADDA_UL_SRC_CON0,
89e1991d10SAlexandre Mergnat 	AFE_AUD_PAD_TOP,
90e1991d10SAlexandre Mergnat 	AFE_HD_ENGEN_ENABLE,
91e1991d10SAlexandre Mergnat };
92e1991d10SAlexandre Mergnat 
93e1991d10SAlexandre Mergnat static const struct snd_pcm_hardware mt8365_afe_hardware = {
94e1991d10SAlexandre Mergnat 	.info = (SNDRV_PCM_INFO_MMAP |
95e1991d10SAlexandre Mergnat 		 SNDRV_PCM_INFO_INTERLEAVED |
96e1991d10SAlexandre Mergnat 		 SNDRV_PCM_INFO_MMAP_VALID),
97e1991d10SAlexandre Mergnat 	.buffer_bytes_max = 256 * 1024,
98e1991d10SAlexandre Mergnat 	.period_bytes_min = 512,
99e1991d10SAlexandre Mergnat 	.period_bytes_max = 128 * 1024,
100e1991d10SAlexandre Mergnat 	.periods_min = 2,
101e1991d10SAlexandre Mergnat 	.periods_max = 256,
102e1991d10SAlexandre Mergnat 	.fifo_size = 0,
103e1991d10SAlexandre Mergnat };
104e1991d10SAlexandre Mergnat 
105e1991d10SAlexandre Mergnat struct mt8365_afe_rate {
106e1991d10SAlexandre Mergnat 	unsigned int rate;
107e1991d10SAlexandre Mergnat 	unsigned int reg_val;
108e1991d10SAlexandre Mergnat };
109e1991d10SAlexandre Mergnat 
110e1991d10SAlexandre Mergnat static const struct mt8365_afe_rate mt8365_afe_fs_rates[] = {
111e1991d10SAlexandre Mergnat 	{ .rate = 8000, .reg_val = MT8365_FS_8K },
112e1991d10SAlexandre Mergnat 	{ .rate = 11025, .reg_val = MT8365_FS_11D025K },
113e1991d10SAlexandre Mergnat 	{ .rate = 12000, .reg_val = MT8365_FS_12K },
114e1991d10SAlexandre Mergnat 	{ .rate = 16000, .reg_val = MT8365_FS_16K },
115e1991d10SAlexandre Mergnat 	{ .rate = 22050, .reg_val = MT8365_FS_22D05K },
116e1991d10SAlexandre Mergnat 	{ .rate = 24000, .reg_val = MT8365_FS_24K },
117e1991d10SAlexandre Mergnat 	{ .rate = 32000, .reg_val = MT8365_FS_32K },
118e1991d10SAlexandre Mergnat 	{ .rate = 44100, .reg_val = MT8365_FS_44D1K },
119e1991d10SAlexandre Mergnat 	{ .rate = 48000, .reg_val = MT8365_FS_48K },
120e1991d10SAlexandre Mergnat 	{ .rate = 88200, .reg_val = MT8365_FS_88D2K },
121e1991d10SAlexandre Mergnat 	{ .rate = 96000, .reg_val = MT8365_FS_96K },
122e1991d10SAlexandre Mergnat 	{ .rate = 176400, .reg_val = MT8365_FS_176D4K },
123e1991d10SAlexandre Mergnat 	{ .rate = 192000, .reg_val = MT8365_FS_192K },
124e1991d10SAlexandre Mergnat };
125e1991d10SAlexandre Mergnat 
mt8365_afe_fs_timing(unsigned int rate)126e1991d10SAlexandre Mergnat int mt8365_afe_fs_timing(unsigned int rate)
127e1991d10SAlexandre Mergnat {
128e1991d10SAlexandre Mergnat 	int i;
129e1991d10SAlexandre Mergnat 
130e1991d10SAlexandre Mergnat 	for (i = 0; i < ARRAY_SIZE(mt8365_afe_fs_rates); i++)
131e1991d10SAlexandre Mergnat 		if (mt8365_afe_fs_rates[i].rate == rate)
132e1991d10SAlexandre Mergnat 			return mt8365_afe_fs_rates[i].reg_val;
133e1991d10SAlexandre Mergnat 
134e1991d10SAlexandre Mergnat 	return -EINVAL;
135e1991d10SAlexandre Mergnat }
136e1991d10SAlexandre Mergnat 
mt8365_afe_rate_supported(unsigned int rate,unsigned int id)137e1991d10SAlexandre Mergnat bool mt8365_afe_rate_supported(unsigned int rate, unsigned int id)
138e1991d10SAlexandre Mergnat {
139e1991d10SAlexandre Mergnat 	switch (id) {
140e1991d10SAlexandre Mergnat 	case MT8365_AFE_IO_TDM_IN:
141e1991d10SAlexandre Mergnat 		if (rate >= 8000 && rate <= 192000)
142e1991d10SAlexandre Mergnat 			return true;
143e1991d10SAlexandre Mergnat 		break;
144e1991d10SAlexandre Mergnat 	case MT8365_AFE_IO_DMIC:
145e1991d10SAlexandre Mergnat 		if (rate >= 8000 && rate <= 48000)
146e1991d10SAlexandre Mergnat 			return true;
147e1991d10SAlexandre Mergnat 		break;
148e1991d10SAlexandre Mergnat 	default:
149e1991d10SAlexandre Mergnat 		break;
150e1991d10SAlexandre Mergnat 	}
151e1991d10SAlexandre Mergnat 
152e1991d10SAlexandre Mergnat 	return false;
153e1991d10SAlexandre Mergnat }
154e1991d10SAlexandre Mergnat 
mt8365_afe_channel_supported(unsigned int channel,unsigned int id)155e1991d10SAlexandre Mergnat bool mt8365_afe_channel_supported(unsigned int channel, unsigned int id)
156e1991d10SAlexandre Mergnat {
157e1991d10SAlexandre Mergnat 	switch (id) {
158e1991d10SAlexandre Mergnat 	case MT8365_AFE_IO_TDM_IN:
159e1991d10SAlexandre Mergnat 		if (channel >= 1 && channel <= 8)
160e1991d10SAlexandre Mergnat 			return true;
161e1991d10SAlexandre Mergnat 		break;
162e1991d10SAlexandre Mergnat 	case MT8365_AFE_IO_DMIC:
163e1991d10SAlexandre Mergnat 		if (channel >= 1 && channel <= 8)
164e1991d10SAlexandre Mergnat 			return true;
165e1991d10SAlexandre Mergnat 		break;
166e1991d10SAlexandre Mergnat 	default:
167e1991d10SAlexandre Mergnat 		break;
168e1991d10SAlexandre Mergnat 	}
169e1991d10SAlexandre Mergnat 
170e1991d10SAlexandre Mergnat 	return false;
171e1991d10SAlexandre Mergnat }
172e1991d10SAlexandre Mergnat 
mt8365_afe_clk_group_44k(int sample_rate)17363157d99SMark Brown static bool mt8365_afe_clk_group_44k(int sample_rate)
174e1991d10SAlexandre Mergnat {
175e1991d10SAlexandre Mergnat 	if (sample_rate == 11025 ||
176e1991d10SAlexandre Mergnat 	    sample_rate == 22050 ||
177e1991d10SAlexandre Mergnat 	    sample_rate == 44100 ||
178e1991d10SAlexandre Mergnat 	    sample_rate == 88200 ||
179e1991d10SAlexandre Mergnat 	    sample_rate == 176400)
180e1991d10SAlexandre Mergnat 		return true;
181e1991d10SAlexandre Mergnat 	else
182e1991d10SAlexandre Mergnat 		return false;
183e1991d10SAlexandre Mergnat }
184e1991d10SAlexandre Mergnat 
mt8365_afe_clk_group_48k(int sample_rate)18563157d99SMark Brown static bool mt8365_afe_clk_group_48k(int sample_rate)
186e1991d10SAlexandre Mergnat {
187e1991d10SAlexandre Mergnat 	return (!mt8365_afe_clk_group_44k(sample_rate));
188e1991d10SAlexandre Mergnat }
189e1991d10SAlexandre Mergnat 
mt8365_dai_set_priv(struct mtk_base_afe * afe,int id,int priv_size,const void * priv_data)190e1991d10SAlexandre Mergnat int mt8365_dai_set_priv(struct mtk_base_afe *afe, int id,
191e1991d10SAlexandre Mergnat 			int priv_size, const void *priv_data)
192e1991d10SAlexandre Mergnat {
193e1991d10SAlexandre Mergnat 	struct mt8365_afe_private *afe_priv = afe->platform_priv;
194e1991d10SAlexandre Mergnat 	void *temp_data;
195e1991d10SAlexandre Mergnat 
196e1991d10SAlexandre Mergnat 	temp_data = devm_kzalloc(afe->dev, priv_size, GFP_KERNEL);
197e1991d10SAlexandre Mergnat 	if (!temp_data)
198e1991d10SAlexandre Mergnat 		return -ENOMEM;
199e1991d10SAlexandre Mergnat 
200e1991d10SAlexandre Mergnat 	if (priv_data)
201e1991d10SAlexandre Mergnat 		memcpy(temp_data, priv_data, priv_size);
202e1991d10SAlexandre Mergnat 
203e1991d10SAlexandre Mergnat 	afe_priv->dai_priv[id] = temp_data;
204e1991d10SAlexandre Mergnat 
205e1991d10SAlexandre Mergnat 	return 0;
206e1991d10SAlexandre Mergnat }
207e1991d10SAlexandre Mergnat 
mt8365_afe_irq_direction_enable(struct mtk_base_afe * afe,int irq_id,int direction)208e1991d10SAlexandre Mergnat static int mt8365_afe_irq_direction_enable(struct mtk_base_afe *afe,
209e1991d10SAlexandre Mergnat 					   int irq_id, int direction)
210e1991d10SAlexandre Mergnat {
211e1991d10SAlexandre Mergnat 	struct mtk_base_afe_irq *irq;
212e1991d10SAlexandre Mergnat 
213e1991d10SAlexandre Mergnat 	if (irq_id >= MT8365_AFE_IRQ_NUM)
214e1991d10SAlexandre Mergnat 		return -1;
215e1991d10SAlexandre Mergnat 
216e1991d10SAlexandre Mergnat 	irq = &afe->irqs[irq_id];
217e1991d10SAlexandre Mergnat 
218e1991d10SAlexandre Mergnat 	if (direction == MT8365_AFE_IRQ_DIR_MCU) {
219e1991d10SAlexandre Mergnat 		regmap_update_bits(afe->regmap, AFE_IRQ_MCU_DSP_EN,
220e1991d10SAlexandre Mergnat 				   (1 << irq->irq_data->irq_clr_shift),
221e1991d10SAlexandre Mergnat 				   0);
222e1991d10SAlexandre Mergnat 		regmap_update_bits(afe->regmap, AFE_IRQ_MCU_EN,
223e1991d10SAlexandre Mergnat 				   (1 << irq->irq_data->irq_clr_shift),
224e1991d10SAlexandre Mergnat 				   (1 << irq->irq_data->irq_clr_shift));
225e1991d10SAlexandre Mergnat 	} else if (direction == MT8365_AFE_IRQ_DIR_DSP) {
226e1991d10SAlexandre Mergnat 		regmap_update_bits(afe->regmap, AFE_IRQ_MCU_DSP_EN,
227e1991d10SAlexandre Mergnat 				   (1 << irq->irq_data->irq_clr_shift),
228e1991d10SAlexandre Mergnat 				   (1 << irq->irq_data->irq_clr_shift));
229e1991d10SAlexandre Mergnat 		regmap_update_bits(afe->regmap, AFE_IRQ_MCU_EN,
230e1991d10SAlexandre Mergnat 				   (1 << irq->irq_data->irq_clr_shift),
231e1991d10SAlexandre Mergnat 				   0);
232e1991d10SAlexandre Mergnat 	} else {
233e1991d10SAlexandre Mergnat 		regmap_update_bits(afe->regmap, AFE_IRQ_MCU_DSP_EN,
234e1991d10SAlexandre Mergnat 				   (1 << irq->irq_data->irq_clr_shift),
235e1991d10SAlexandre Mergnat 				   (1 << irq->irq_data->irq_clr_shift));
236e1991d10SAlexandre Mergnat 		regmap_update_bits(afe->regmap, AFE_IRQ_MCU_EN,
237e1991d10SAlexandre Mergnat 				   (1 << irq->irq_data->irq_clr_shift),
238e1991d10SAlexandre Mergnat 				   (1 << irq->irq_data->irq_clr_shift));
239e1991d10SAlexandre Mergnat 	}
240e1991d10SAlexandre Mergnat 	return 0;
241e1991d10SAlexandre Mergnat }
242e1991d10SAlexandre Mergnat 
mt8365_memif_fs(struct snd_pcm_substream * substream,unsigned int rate)243e1991d10SAlexandre Mergnat static int mt8365_memif_fs(struct snd_pcm_substream *substream,
244e1991d10SAlexandre Mergnat 			   unsigned int rate)
245e1991d10SAlexandre Mergnat {
246e1991d10SAlexandre Mergnat 	return mt8365_afe_fs_timing(rate);
247e1991d10SAlexandre Mergnat }
248e1991d10SAlexandre Mergnat 
mt8365_irq_fs(struct snd_pcm_substream * substream,unsigned int rate)249e1991d10SAlexandre Mergnat static int mt8365_irq_fs(struct snd_pcm_substream *substream,
250e1991d10SAlexandre Mergnat 			 unsigned int rate)
251e1991d10SAlexandre Mergnat {
252e1991d10SAlexandre Mergnat 	return mt8365_memif_fs(substream, rate);
253e1991d10SAlexandre Mergnat }
254e1991d10SAlexandre Mergnat 
255e1991d10SAlexandre Mergnat static const struct mt8365_cm_ctrl_reg cm_ctrl_reg[MT8365_CM_NUM] = {
256e1991d10SAlexandre Mergnat 	[MT8365_CM1] = {
257e1991d10SAlexandre Mergnat 		.con0 = AFE_CM1_CON0,
258e1991d10SAlexandre Mergnat 		.con1 = AFE_CM1_CON1,
259e1991d10SAlexandre Mergnat 		.con2 = AFE_CM1_CON2,
260e1991d10SAlexandre Mergnat 		.con3 = AFE_CM1_CON3,
261e1991d10SAlexandre Mergnat 		.con4 = AFE_CM1_CON4,
262e1991d10SAlexandre Mergnat 	},
263e1991d10SAlexandre Mergnat 	[MT8365_CM2] = {
264e1991d10SAlexandre Mergnat 		.con0 = AFE_CM2_CON0,
265e1991d10SAlexandre Mergnat 		.con1 = AFE_CM2_CON1,
266e1991d10SAlexandre Mergnat 		.con2 = AFE_CM2_CON2,
267e1991d10SAlexandre Mergnat 		.con3 = AFE_CM2_CON3,
268e1991d10SAlexandre Mergnat 		.con4 = AFE_CM2_CON4,
269e1991d10SAlexandre Mergnat 	}
270e1991d10SAlexandre Mergnat };
271e1991d10SAlexandre Mergnat 
mt8365_afe_cm2_mux_conn(struct mtk_base_afe * afe)272e1991d10SAlexandre Mergnat static int mt8365_afe_cm2_mux_conn(struct mtk_base_afe *afe)
273e1991d10SAlexandre Mergnat {
274e1991d10SAlexandre Mergnat 	struct mt8365_afe_private *afe_priv = afe->platform_priv;
275e1991d10SAlexandre Mergnat 	unsigned int input = afe_priv->cm2_mux_input;
276e1991d10SAlexandre Mergnat 
277e1991d10SAlexandre Mergnat 	/* TDM_IN interconnect to CM2 */
278e1991d10SAlexandre Mergnat 	regmap_update_bits(afe->regmap, AFE_CM2_CONN0,
279e1991d10SAlexandre Mergnat 			   CM2_AFE_CM2_CONN_CFG1_MASK,
280e1991d10SAlexandre Mergnat 			   CM2_AFE_CM2_CONN_CFG1(TDM_IN_CH0));
281e1991d10SAlexandre Mergnat 	regmap_update_bits(afe->regmap, AFE_CM2_CONN0,
282e1991d10SAlexandre Mergnat 			   CM2_AFE_CM2_CONN_CFG2_MASK,
283e1991d10SAlexandre Mergnat 			   CM2_AFE_CM2_CONN_CFG2(TDM_IN_CH1));
284e1991d10SAlexandre Mergnat 	regmap_update_bits(afe->regmap, AFE_CM2_CONN0,
285e1991d10SAlexandre Mergnat 			   CM2_AFE_CM2_CONN_CFG3_MASK,
286e1991d10SAlexandre Mergnat 			   CM2_AFE_CM2_CONN_CFG3(TDM_IN_CH2));
287e1991d10SAlexandre Mergnat 	regmap_update_bits(afe->regmap, AFE_CM2_CONN0,
288e1991d10SAlexandre Mergnat 			   CM2_AFE_CM2_CONN_CFG4_MASK,
289e1991d10SAlexandre Mergnat 			   CM2_AFE_CM2_CONN_CFG4(TDM_IN_CH3));
290e1991d10SAlexandre Mergnat 	regmap_update_bits(afe->regmap, AFE_CM2_CONN0,
291e1991d10SAlexandre Mergnat 			   CM2_AFE_CM2_CONN_CFG5_MASK,
292e1991d10SAlexandre Mergnat 			   CM2_AFE_CM2_CONN_CFG5(TDM_IN_CH4));
293e1991d10SAlexandre Mergnat 	regmap_update_bits(afe->regmap, AFE_CM2_CONN0,
294e1991d10SAlexandre Mergnat 			   CM2_AFE_CM2_CONN_CFG6_MASK,
295e1991d10SAlexandre Mergnat 			   CM2_AFE_CM2_CONN_CFG6(TDM_IN_CH5));
296e1991d10SAlexandre Mergnat 	regmap_update_bits(afe->regmap, AFE_CM2_CONN1,
297e1991d10SAlexandre Mergnat 			   CM2_AFE_CM2_CONN_CFG7_MASK,
298e1991d10SAlexandre Mergnat 			   CM2_AFE_CM2_CONN_CFG7(TDM_IN_CH6));
299e1991d10SAlexandre Mergnat 	regmap_update_bits(afe->regmap, AFE_CM2_CONN1,
300e1991d10SAlexandre Mergnat 			   CM2_AFE_CM2_CONN_CFG8_MASK,
301e1991d10SAlexandre Mergnat 			   CM2_AFE_CM2_CONN_CFG8(TDM_IN_CH7));
302e1991d10SAlexandre Mergnat 
303e1991d10SAlexandre Mergnat 	/* ref data interconnect to CM2 */
304e1991d10SAlexandre Mergnat 	if (input == MT8365_FROM_GASRC1) {
305e1991d10SAlexandre Mergnat 		regmap_update_bits(afe->regmap, AFE_CM2_CONN1,
306e1991d10SAlexandre Mergnat 				   CM2_AFE_CM2_CONN_CFG9_MASK,
307e1991d10SAlexandre Mergnat 				   CM2_AFE_CM2_CONN_CFG9(GENERAL1_ASRC_OUT_LCH));
308e1991d10SAlexandre Mergnat 		regmap_update_bits(afe->regmap, AFE_CM2_CONN1,
309e1991d10SAlexandre Mergnat 				   CM2_AFE_CM2_CONN_CFG10_MASK,
310e1991d10SAlexandre Mergnat 				   CM2_AFE_CM2_CONN_CFG10(GENERAL1_ASRC_OUT_RCH));
311e1991d10SAlexandre Mergnat 	} else if (input == MT8365_FROM_GASRC2) {
312e1991d10SAlexandre Mergnat 		regmap_update_bits(afe->regmap, AFE_CM2_CONN1,
313e1991d10SAlexandre Mergnat 				   CM2_AFE_CM2_CONN_CFG9_MASK,
314e1991d10SAlexandre Mergnat 				   CM2_AFE_CM2_CONN_CFG9(GENERAL2_ASRC_OUT_LCH));
315e1991d10SAlexandre Mergnat 		regmap_update_bits(afe->regmap, AFE_CM2_CONN1,
316e1991d10SAlexandre Mergnat 				   CM2_AFE_CM2_CONN_CFG10_MASK,
317e1991d10SAlexandre Mergnat 				   CM2_AFE_CM2_CONN_CFG10(GENERAL2_ASRC_OUT_RCH));
318e1991d10SAlexandre Mergnat 	} else if (input == MT8365_FROM_TDM_ASRC) {
319e1991d10SAlexandre Mergnat 		regmap_update_bits(afe->regmap, AFE_CM2_CONN1,
320e1991d10SAlexandre Mergnat 				   CM2_AFE_CM2_CONN_CFG9_MASK,
321e1991d10SAlexandre Mergnat 				   CM2_AFE_CM2_CONN_CFG9(TDM_OUT_ASRC_CH0));
322e1991d10SAlexandre Mergnat 		regmap_update_bits(afe->regmap, AFE_CM2_CONN1,
323e1991d10SAlexandre Mergnat 				   CM2_AFE_CM2_CONN_CFG10_MASK,
324e1991d10SAlexandre Mergnat 				   CM2_AFE_CM2_CONN_CFG10(TDM_OUT_ASRC_CH1));
325e1991d10SAlexandre Mergnat 		regmap_update_bits(afe->regmap, AFE_CM2_CONN1,
326e1991d10SAlexandre Mergnat 				   CM2_AFE_CM2_CONN_CFG11_MASK,
327e1991d10SAlexandre Mergnat 				   CM2_AFE_CM2_CONN_CFG11(TDM_OUT_ASRC_CH2));
328e1991d10SAlexandre Mergnat 		regmap_update_bits(afe->regmap, AFE_CM2_CONN1,
329e1991d10SAlexandre Mergnat 				   CM2_AFE_CM2_CONN_CFG12_MASK,
330e1991d10SAlexandre Mergnat 				   CM2_AFE_CM2_CONN_CFG12(TDM_OUT_ASRC_CH3));
331e1991d10SAlexandre Mergnat 		regmap_update_bits(afe->regmap, AFE_CM2_CONN2,
332e1991d10SAlexandre Mergnat 				   CM2_AFE_CM2_CONN_CFG13_MASK,
333e1991d10SAlexandre Mergnat 				   CM2_AFE_CM2_CONN_CFG13(TDM_OUT_ASRC_CH4));
334e1991d10SAlexandre Mergnat 		regmap_update_bits(afe->regmap, AFE_CM2_CONN2,
335e1991d10SAlexandre Mergnat 				   CM2_AFE_CM2_CONN_CFG14_MASK,
336e1991d10SAlexandre Mergnat 				   CM2_AFE_CM2_CONN_CFG14(TDM_OUT_ASRC_CH5));
337e1991d10SAlexandre Mergnat 		regmap_update_bits(afe->regmap, AFE_CM2_CONN2,
338e1991d10SAlexandre Mergnat 				   CM2_AFE_CM2_CONN_CFG15_MASK,
339e1991d10SAlexandre Mergnat 				   CM2_AFE_CM2_CONN_CFG15(TDM_OUT_ASRC_CH6));
340e1991d10SAlexandre Mergnat 		regmap_update_bits(afe->regmap, AFE_CM2_CONN2,
341e1991d10SAlexandre Mergnat 				   CM2_AFE_CM2_CONN_CFG16_MASK,
342e1991d10SAlexandre Mergnat 				   CM2_AFE_CM2_CONN_CFG16(TDM_OUT_ASRC_CH7));
343e1991d10SAlexandre Mergnat 	} else {
344e1991d10SAlexandre Mergnat 		dev_err(afe->dev, "%s wrong CM2 input %d\n", __func__, input);
345e1991d10SAlexandre Mergnat 		return -1;
346e1991d10SAlexandre Mergnat 	}
347e1991d10SAlexandre Mergnat 
348e1991d10SAlexandre Mergnat 	return 0;
349e1991d10SAlexandre Mergnat }
350e1991d10SAlexandre Mergnat 
mt8365_afe_get_cm_update_cnt(struct mtk_base_afe * afe,enum mt8365_cm_num cmNum,unsigned int rate,unsigned int channel)351e1991d10SAlexandre Mergnat static int mt8365_afe_get_cm_update_cnt(struct mtk_base_afe *afe,
352e1991d10SAlexandre Mergnat 					enum mt8365_cm_num cmNum,
353e1991d10SAlexandre Mergnat 					unsigned int rate, unsigned int channel)
354e1991d10SAlexandre Mergnat {
355e1991d10SAlexandre Mergnat 	unsigned int total_cnt, div_cnt, ch_pair, best_cnt;
356e1991d10SAlexandre Mergnat 	unsigned int ch_update_cnt[MT8365_CM_UPDATA_CNT_SET];
357e1991d10SAlexandre Mergnat 	int i;
358e1991d10SAlexandre Mergnat 
359e1991d10SAlexandre Mergnat 	/* calculate cm update cnt
360e1991d10SAlexandre Mergnat 	 * total_cnt = clk / fs, clk is 26m or 24m or 22m
361e1991d10SAlexandre Mergnat 	 * div_cnt = total_cnt / ch_pair, max ch 16ch ,2ch is a set
362e1991d10SAlexandre Mergnat 	 * best_cnt < div_cnt ,we set best_cnt = div_cnt -10
363e1991d10SAlexandre Mergnat 	 * ch01 = best_cnt, ch23 = 2* ch01_up_cnt
364e1991d10SAlexandre Mergnat 	 * ch45 = 3* ch01_up_cnt ...ch1415 = 8* ch01_up_cnt
365e1991d10SAlexandre Mergnat 	 */
366e1991d10SAlexandre Mergnat 
367e1991d10SAlexandre Mergnat 	if (cmNum == MT8365_CM1) {
368e1991d10SAlexandre Mergnat 		total_cnt = MT8365_CLK_26M / rate;
369e1991d10SAlexandre Mergnat 	} else if (cmNum == MT8365_CM2) {
370e1991d10SAlexandre Mergnat 		if (mt8365_afe_clk_group_48k(rate))
371e1991d10SAlexandre Mergnat 			total_cnt = MT8365_CLK_24M / rate;
372e1991d10SAlexandre Mergnat 		else
373e1991d10SAlexandre Mergnat 			total_cnt = MT8365_CLK_22M / rate;
374e1991d10SAlexandre Mergnat 	} else {
375e1991d10SAlexandre Mergnat 		return -1;
376e1991d10SAlexandre Mergnat 	}
377e1991d10SAlexandre Mergnat 
378e1991d10SAlexandre Mergnat 	if (channel % 2)
379e1991d10SAlexandre Mergnat 		ch_pair = (channel / 2) + 1;
380e1991d10SAlexandre Mergnat 	else
381e1991d10SAlexandre Mergnat 		ch_pair = channel / 2;
382e1991d10SAlexandre Mergnat 
383e1991d10SAlexandre Mergnat 	div_cnt =  total_cnt / ch_pair;
384e1991d10SAlexandre Mergnat 	best_cnt = div_cnt - 10;
385e1991d10SAlexandre Mergnat 
386e1991d10SAlexandre Mergnat 	if (best_cnt <= 0)
387e1991d10SAlexandre Mergnat 		return -1;
388e1991d10SAlexandre Mergnat 
389e1991d10SAlexandre Mergnat 	for (i = 0; i < ch_pair; i++)
390e1991d10SAlexandre Mergnat 		ch_update_cnt[i] = (i + 1) * best_cnt;
391e1991d10SAlexandre Mergnat 
392e1991d10SAlexandre Mergnat 	switch (channel) {
393e1991d10SAlexandre Mergnat 	case 16:
394e1991d10SAlexandre Mergnat 		fallthrough;
395e1991d10SAlexandre Mergnat 	case 15:
396e1991d10SAlexandre Mergnat 		regmap_update_bits(afe->regmap, cm_ctrl_reg[cmNum].con4,
397e1991d10SAlexandre Mergnat 				   CM_AFE_CM_UPDATE_CNT2_MASK,
398e1991d10SAlexandre Mergnat 				   CM_AFE_CM_UPDATE_CNT2(ch_update_cnt[7]));
399e1991d10SAlexandre Mergnat 		fallthrough;
400e1991d10SAlexandre Mergnat 	case 14:
401e1991d10SAlexandre Mergnat 		fallthrough;
402e1991d10SAlexandre Mergnat 	case 13:
403e1991d10SAlexandre Mergnat 		regmap_update_bits(afe->regmap, cm_ctrl_reg[cmNum].con4,
404e1991d10SAlexandre Mergnat 				   CM_AFE_CM_UPDATE_CNT1_MASK,
405e1991d10SAlexandre Mergnat 				   CM_AFE_CM_UPDATE_CNT1(ch_update_cnt[6]));
406e1991d10SAlexandre Mergnat 		fallthrough;
407e1991d10SAlexandre Mergnat 	case 12:
408e1991d10SAlexandre Mergnat 		fallthrough;
409e1991d10SAlexandre Mergnat 	case 11:
410e1991d10SAlexandre Mergnat 		regmap_update_bits(afe->regmap, cm_ctrl_reg[cmNum].con3,
411e1991d10SAlexandre Mergnat 				   CM_AFE_CM_UPDATE_CNT2_MASK,
412e1991d10SAlexandre Mergnat 				   CM_AFE_CM_UPDATE_CNT2(ch_update_cnt[5]));
413e1991d10SAlexandre Mergnat 		fallthrough;
414e1991d10SAlexandre Mergnat 	case 10:
415e1991d10SAlexandre Mergnat 		fallthrough;
416e1991d10SAlexandre Mergnat 	case 9:
417e1991d10SAlexandre Mergnat 		regmap_update_bits(afe->regmap, cm_ctrl_reg[cmNum].con3,
418e1991d10SAlexandre Mergnat 				   CM_AFE_CM_UPDATE_CNT1_MASK,
419e1991d10SAlexandre Mergnat 				   CM_AFE_CM_UPDATE_CNT1(ch_update_cnt[4]));
420e1991d10SAlexandre Mergnat 		fallthrough;
421e1991d10SAlexandre Mergnat 	case 8:
422e1991d10SAlexandre Mergnat 		fallthrough;
423e1991d10SAlexandre Mergnat 	case 7:
424e1991d10SAlexandre Mergnat 		regmap_update_bits(afe->regmap, cm_ctrl_reg[cmNum].con2,
425e1991d10SAlexandre Mergnat 				   CM_AFE_CM_UPDATE_CNT2_MASK,
426e1991d10SAlexandre Mergnat 				   CM_AFE_CM_UPDATE_CNT2(ch_update_cnt[3]));
427e1991d10SAlexandre Mergnat 		fallthrough;
428e1991d10SAlexandre Mergnat 	case 6:
429e1991d10SAlexandre Mergnat 		fallthrough;
430e1991d10SAlexandre Mergnat 	case 5:
431e1991d10SAlexandre Mergnat 		regmap_update_bits(afe->regmap, cm_ctrl_reg[cmNum].con2,
432e1991d10SAlexandre Mergnat 				   CM_AFE_CM_UPDATE_CNT1_MASK,
433e1991d10SAlexandre Mergnat 				   CM_AFE_CM_UPDATE_CNT1(ch_update_cnt[2]));
434e1991d10SAlexandre Mergnat 		fallthrough;
435e1991d10SAlexandre Mergnat 	case 4:
436e1991d10SAlexandre Mergnat 		fallthrough;
437e1991d10SAlexandre Mergnat 	case 3:
438e1991d10SAlexandre Mergnat 		regmap_update_bits(afe->regmap, cm_ctrl_reg[cmNum].con1,
439e1991d10SAlexandre Mergnat 				   CM_AFE_CM_UPDATE_CNT2_MASK,
440e1991d10SAlexandre Mergnat 				   CM_AFE_CM_UPDATE_CNT2(ch_update_cnt[1]));
441e1991d10SAlexandre Mergnat 		fallthrough;
442e1991d10SAlexandre Mergnat 	case 2:
443e1991d10SAlexandre Mergnat 		fallthrough;
444e1991d10SAlexandre Mergnat 	case 1:
445e1991d10SAlexandre Mergnat 		regmap_update_bits(afe->regmap, cm_ctrl_reg[cmNum].con1,
446e1991d10SAlexandre Mergnat 				   CM_AFE_CM_UPDATE_CNT1_MASK,
447e1991d10SAlexandre Mergnat 				   CM_AFE_CM_UPDATE_CNT1(ch_update_cnt[0]));
448e1991d10SAlexandre Mergnat 		break;
449e1991d10SAlexandre Mergnat 	default:
450e1991d10SAlexandre Mergnat 		return -1;
451e1991d10SAlexandre Mergnat 	}
452e1991d10SAlexandre Mergnat 
453e1991d10SAlexandre Mergnat 	return 0;
454e1991d10SAlexandre Mergnat }
455e1991d10SAlexandre Mergnat 
mt8365_afe_configure_cm(struct mtk_base_afe * afe,enum mt8365_cm_num cmNum,unsigned int channels,unsigned int rate)456e1991d10SAlexandre Mergnat static int mt8365_afe_configure_cm(struct mtk_base_afe *afe,
457e1991d10SAlexandre Mergnat 				   enum mt8365_cm_num cmNum,
458e1991d10SAlexandre Mergnat 				   unsigned int channels,
459e1991d10SAlexandre Mergnat 				   unsigned int rate)
460e1991d10SAlexandre Mergnat {
461e1991d10SAlexandre Mergnat 	unsigned int val, mask;
462e1991d10SAlexandre Mergnat 	unsigned int fs = mt8365_afe_fs_timing(rate);
463e1991d10SAlexandre Mergnat 
464e1991d10SAlexandre Mergnat 	val = FIELD_PREP(CM_AFE_CM_CH_NUM_MASK, (channels - 1)) |
465e1991d10SAlexandre Mergnat 	      FIELD_PREP(CM_AFE_CM_START_DATA_MASK, 0);
466e1991d10SAlexandre Mergnat 
467e1991d10SAlexandre Mergnat 	mask = CM_AFE_CM_CH_NUM_MASK |
468e1991d10SAlexandre Mergnat 	       CM_AFE_CM_START_DATA_MASK;
469e1991d10SAlexandre Mergnat 
470e1991d10SAlexandre Mergnat 	if (cmNum == MT8365_CM1) {
471e1991d10SAlexandre Mergnat 		val |= FIELD_PREP(CM_AFE_CM1_IN_MODE_MASK, fs);
472e1991d10SAlexandre Mergnat 
473e1991d10SAlexandre Mergnat 		mask |= CM_AFE_CM1_VUL_SEL |
474e1991d10SAlexandre Mergnat 			CM_AFE_CM1_IN_MODE_MASK;
475e1991d10SAlexandre Mergnat 	} else if (cmNum == MT8365_CM2) {
476e1991d10SAlexandre Mergnat 		if (mt8365_afe_clk_group_48k(rate))
477e1991d10SAlexandre Mergnat 			val |= FIELD_PREP(CM_AFE_CM2_CLK_SEL, 0);
478e1991d10SAlexandre Mergnat 		else
479e1991d10SAlexandre Mergnat 			val |= FIELD_PREP(CM_AFE_CM2_CLK_SEL, 1);
480e1991d10SAlexandre Mergnat 
481e1991d10SAlexandre Mergnat 		val |= FIELD_PREP(CM_AFE_CM2_TDM_SEL, 1);
482e1991d10SAlexandre Mergnat 
483e1991d10SAlexandre Mergnat 		mask |= CM_AFE_CM2_TDM_SEL |
484e1991d10SAlexandre Mergnat 			CM_AFE_CM1_IN_MODE_MASK |
485e1991d10SAlexandre Mergnat 			CM_AFE_CM2_CLK_SEL;
486e1991d10SAlexandre Mergnat 
487e1991d10SAlexandre Mergnat 		mt8365_afe_cm2_mux_conn(afe);
488e1991d10SAlexandre Mergnat 	} else {
489e1991d10SAlexandre Mergnat 		return -1;
490e1991d10SAlexandre Mergnat 	}
491e1991d10SAlexandre Mergnat 
492e1991d10SAlexandre Mergnat 	regmap_update_bits(afe->regmap, cm_ctrl_reg[cmNum].con0, mask, val);
493e1991d10SAlexandre Mergnat 
494e1991d10SAlexandre Mergnat 	mt8365_afe_get_cm_update_cnt(afe, cmNum, rate, channels);
495e1991d10SAlexandre Mergnat 
496e1991d10SAlexandre Mergnat 	return 0;
497e1991d10SAlexandre Mergnat }
498e1991d10SAlexandre Mergnat 
mt8365_afe_fe_startup(struct snd_pcm_substream * substream,struct snd_soc_dai * dai)49963157d99SMark Brown static int mt8365_afe_fe_startup(struct snd_pcm_substream *substream,
500e1991d10SAlexandre Mergnat 				 struct snd_soc_dai *dai)
501e1991d10SAlexandre Mergnat {
502e1991d10SAlexandre Mergnat 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
503e1991d10SAlexandre Mergnat 	struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
504e1991d10SAlexandre Mergnat 	struct snd_pcm_runtime *runtime = substream->runtime;
505e1991d10SAlexandre Mergnat 	int memif_num = snd_soc_rtd_to_cpu(rtd, 0)->id;
506e1991d10SAlexandre Mergnat 	struct mtk_base_afe_memif *memif = &afe->memif[memif_num];
507e1991d10SAlexandre Mergnat 	int ret;
508e1991d10SAlexandre Mergnat 
509e1991d10SAlexandre Mergnat 	memif->substream = substream;
510e1991d10SAlexandre Mergnat 
511e1991d10SAlexandre Mergnat 	snd_pcm_hw_constraint_step(substream->runtime, 0,
512e1991d10SAlexandre Mergnat 				   SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 16);
513e1991d10SAlexandre Mergnat 
514e1991d10SAlexandre Mergnat 	snd_soc_set_runtime_hwparams(substream, afe->mtk_afe_hardware);
515e1991d10SAlexandre Mergnat 
516e1991d10SAlexandre Mergnat 	ret = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
517e1991d10SAlexandre Mergnat 	if (ret < 0)
518e1991d10SAlexandre Mergnat 		dev_err(afe->dev, "snd_pcm_hw_constraint_integer failed\n");
519e1991d10SAlexandre Mergnat 
520e1991d10SAlexandre Mergnat 	mt8365_afe_enable_main_clk(afe);
521e1991d10SAlexandre Mergnat 	return ret;
522e1991d10SAlexandre Mergnat }
523e1991d10SAlexandre Mergnat 
mt8365_afe_fe_shutdown(struct snd_pcm_substream * substream,struct snd_soc_dai * dai)524e1991d10SAlexandre Mergnat static void mt8365_afe_fe_shutdown(struct snd_pcm_substream *substream,
525e1991d10SAlexandre Mergnat 				   struct snd_soc_dai *dai)
526e1991d10SAlexandre Mergnat {
527e1991d10SAlexandre Mergnat 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
528e1991d10SAlexandre Mergnat 	struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
529e1991d10SAlexandre Mergnat 	int memif_num = snd_soc_rtd_to_cpu(rtd, 0)->id;
530e1991d10SAlexandre Mergnat 	struct mtk_base_afe_memif *memif = &afe->memif[memif_num];
531e1991d10SAlexandre Mergnat 
532e1991d10SAlexandre Mergnat 	memif->substream = NULL;
533e1991d10SAlexandre Mergnat 
534e1991d10SAlexandre Mergnat 	mt8365_afe_disable_main_clk(afe);
535e1991d10SAlexandre Mergnat }
536e1991d10SAlexandre Mergnat 
mt8365_afe_fe_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params,struct snd_soc_dai * dai)537e1991d10SAlexandre Mergnat static int mt8365_afe_fe_hw_params(struct snd_pcm_substream *substream,
538e1991d10SAlexandre Mergnat 				   struct snd_pcm_hw_params *params,
539e1991d10SAlexandre Mergnat 				   struct snd_soc_dai *dai)
540e1991d10SAlexandre Mergnat {
541e1991d10SAlexandre Mergnat 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
542e1991d10SAlexandre Mergnat 	struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
543e1991d10SAlexandre Mergnat 	struct mt8365_afe_private *afe_priv = afe->platform_priv;
544e1991d10SAlexandre Mergnat 	struct mt8365_control_data *ctrl_data = &afe_priv->ctrl_data;
545e1991d10SAlexandre Mergnat 	int dai_id = snd_soc_rtd_to_cpu(rtd, 0)->id;
546e1991d10SAlexandre Mergnat 	struct mtk_base_afe_memif *memif = &afe->memif[dai_id];
547e1991d10SAlexandre Mergnat 	struct mt8365_fe_dai_data *fe_data = &afe_priv->fe_data[dai_id];
548e1991d10SAlexandre Mergnat 	size_t request_size = params_buffer_bytes(params);
549e1991d10SAlexandre Mergnat 	unsigned int channels = params_channels(params);
550e1991d10SAlexandre Mergnat 	unsigned int rate = params_rate(params);
551e1991d10SAlexandre Mergnat 	unsigned int base_end_offset = 8;
552e1991d10SAlexandre Mergnat 	int ret, fs;
553e1991d10SAlexandre Mergnat 
554e1991d10SAlexandre Mergnat 	dev_info(afe->dev, "%s %s period = %d rate = %d channels = %d\n",
555e1991d10SAlexandre Mergnat 		 __func__, memif->data->name, params_period_size(params),
556e1991d10SAlexandre Mergnat 		 rate, channels);
557e1991d10SAlexandre Mergnat 
558e1991d10SAlexandre Mergnat 	if (dai_id == MT8365_AFE_MEMIF_VUL2) {
559e1991d10SAlexandre Mergnat 		if (!ctrl_data->bypass_cm1)
560e1991d10SAlexandre Mergnat 			/* configure cm1 */
561e1991d10SAlexandre Mergnat 			mt8365_afe_configure_cm(afe, MT8365_CM1,
562e1991d10SAlexandre Mergnat 						channels, rate);
563e1991d10SAlexandre Mergnat 		else
564e1991d10SAlexandre Mergnat 			regmap_update_bits(afe->regmap, AFE_CM1_CON0,
565e1991d10SAlexandre Mergnat 					   CM_AFE_CM1_VUL_SEL,
566e1991d10SAlexandre Mergnat 					   CM_AFE_CM1_VUL_SEL);
567e1991d10SAlexandre Mergnat 	} else if (dai_id == MT8365_AFE_MEMIF_TDM_IN) {
568e1991d10SAlexandre Mergnat 		if (!ctrl_data->bypass_cm2)
569e1991d10SAlexandre Mergnat 			/* configure cm2 */
570e1991d10SAlexandre Mergnat 			mt8365_afe_configure_cm(afe, MT8365_CM2,
571e1991d10SAlexandre Mergnat 						channels, rate);
572e1991d10SAlexandre Mergnat 		else
573e1991d10SAlexandre Mergnat 			regmap_update_bits(afe->regmap, AFE_CM2_CON0,
574e1991d10SAlexandre Mergnat 					   CM_AFE_CM2_TDM_SEL,
575e1991d10SAlexandre Mergnat 					   ~CM_AFE_CM2_TDM_SEL);
576e1991d10SAlexandre Mergnat 
577e1991d10SAlexandre Mergnat 		base_end_offset = 4;
578e1991d10SAlexandre Mergnat 	}
579e1991d10SAlexandre Mergnat 
580e1991d10SAlexandre Mergnat 	if (request_size > fe_data->sram_size) {
581e1991d10SAlexandre Mergnat 		ret = snd_pcm_lib_malloc_pages(substream, request_size);
582e1991d10SAlexandre Mergnat 		if (ret < 0) {
583e1991d10SAlexandre Mergnat 			dev_err(afe->dev,
584e1991d10SAlexandre Mergnat 				"%s %s malloc pages %zu bytes failed %d\n",
585e1991d10SAlexandre Mergnat 				__func__, memif->data->name, request_size, ret);
586e1991d10SAlexandre Mergnat 			return ret;
587e1991d10SAlexandre Mergnat 		}
588e1991d10SAlexandre Mergnat 
589e1991d10SAlexandre Mergnat 		fe_data->use_sram = false;
590e1991d10SAlexandre Mergnat 
591e1991d10SAlexandre Mergnat 		mt8365_afe_emi_clk_on(afe);
592e1991d10SAlexandre Mergnat 	} else {
593e1991d10SAlexandre Mergnat 		struct snd_dma_buffer *dma_buf = &substream->dma_buffer;
594e1991d10SAlexandre Mergnat 
595e1991d10SAlexandre Mergnat 		dma_buf->dev.type = SNDRV_DMA_TYPE_DEV;
596e1991d10SAlexandre Mergnat 		dma_buf->dev.dev = substream->pcm->card->dev;
597e1991d10SAlexandre Mergnat 		dma_buf->area = (unsigned char *)fe_data->sram_vir_addr;
598e1991d10SAlexandre Mergnat 		dma_buf->addr = fe_data->sram_phy_addr;
599e1991d10SAlexandre Mergnat 		dma_buf->bytes = request_size;
600e1991d10SAlexandre Mergnat 		snd_pcm_set_runtime_buffer(substream, dma_buf);
601e1991d10SAlexandre Mergnat 
602e1991d10SAlexandre Mergnat 		fe_data->use_sram = true;
603e1991d10SAlexandre Mergnat 	}
604e1991d10SAlexandre Mergnat 
605e1991d10SAlexandre Mergnat 	memif->phys_buf_addr = lower_32_bits(substream->runtime->dma_addr);
606e1991d10SAlexandre Mergnat 	memif->buffer_size = substream->runtime->dma_bytes;
607e1991d10SAlexandre Mergnat 
608e1991d10SAlexandre Mergnat 	/* start */
609e1991d10SAlexandre Mergnat 	regmap_write(afe->regmap, memif->data->reg_ofs_base,
610e1991d10SAlexandre Mergnat 		     memif->phys_buf_addr);
611e1991d10SAlexandre Mergnat 	/* end */
612e1991d10SAlexandre Mergnat 	regmap_write(afe->regmap,
613e1991d10SAlexandre Mergnat 		     memif->data->reg_ofs_base + base_end_offset,
614e1991d10SAlexandre Mergnat 		     memif->phys_buf_addr + memif->buffer_size - 1);
615e1991d10SAlexandre Mergnat 
616e1991d10SAlexandre Mergnat 	/* set channel */
617e1991d10SAlexandre Mergnat 	if (memif->data->mono_shift >= 0) {
618e1991d10SAlexandre Mergnat 		unsigned int mono = (params_channels(params) == 1) ? 1 : 0;
619e1991d10SAlexandre Mergnat 
620e1991d10SAlexandre Mergnat 		if (memif->data->mono_reg < 0)
621e1991d10SAlexandre Mergnat 			dev_info(afe->dev, "%s mono_reg is NULL\n", __func__);
622e1991d10SAlexandre Mergnat 		else
623e1991d10SAlexandre Mergnat 			regmap_update_bits(afe->regmap, memif->data->mono_reg,
624e1991d10SAlexandre Mergnat 					   1 << memif->data->mono_shift,
625e1991d10SAlexandre Mergnat 					   mono << memif->data->mono_shift);
626e1991d10SAlexandre Mergnat 	}
627e1991d10SAlexandre Mergnat 
628e1991d10SAlexandre Mergnat 	/* set rate */
629e1991d10SAlexandre Mergnat 	if (memif->data->fs_shift < 0)
630e1991d10SAlexandre Mergnat 		return 0;
631e1991d10SAlexandre Mergnat 
632e1991d10SAlexandre Mergnat 	fs = afe->memif_fs(substream, params_rate(params));
633e1991d10SAlexandre Mergnat 
634e1991d10SAlexandre Mergnat 	if (fs < 0)
635e1991d10SAlexandre Mergnat 		return -EINVAL;
636e1991d10SAlexandre Mergnat 
637e1991d10SAlexandre Mergnat 	if (memif->data->fs_reg < 0)
638e1991d10SAlexandre Mergnat 		dev_info(afe->dev, "%s fs_reg is NULL\n", __func__);
639e1991d10SAlexandre Mergnat 	else
640e1991d10SAlexandre Mergnat 		regmap_update_bits(afe->regmap, memif->data->fs_reg,
641e1991d10SAlexandre Mergnat 				   memif->data->fs_maskbit << memif->data->fs_shift,
642e1991d10SAlexandre Mergnat 				   fs << memif->data->fs_shift);
643e1991d10SAlexandre Mergnat 
644e1991d10SAlexandre Mergnat 	return 0;
645e1991d10SAlexandre Mergnat }
646e1991d10SAlexandre Mergnat 
mt8365_afe_fe_hw_free(struct snd_pcm_substream * substream,struct snd_soc_dai * dai)647e1991d10SAlexandre Mergnat static int mt8365_afe_fe_hw_free(struct snd_pcm_substream *substream,
648e1991d10SAlexandre Mergnat 				 struct snd_soc_dai *dai)
649e1991d10SAlexandre Mergnat {
650e1991d10SAlexandre Mergnat 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
651e1991d10SAlexandre Mergnat 	struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
652e1991d10SAlexandre Mergnat 	struct mt8365_afe_private *afe_priv = afe->platform_priv;
653e1991d10SAlexandre Mergnat 	int dai_id = snd_soc_rtd_to_cpu(rtd, 0)->id;
654e1991d10SAlexandre Mergnat 	struct mt8365_fe_dai_data *fe_data = &afe_priv->fe_data[dai_id];
655e1991d10SAlexandre Mergnat 	int ret = 0;
656e1991d10SAlexandre Mergnat 
657e1991d10SAlexandre Mergnat 	if (fe_data->use_sram) {
658e1991d10SAlexandre Mergnat 		snd_pcm_set_runtime_buffer(substream, NULL);
659e1991d10SAlexandre Mergnat 	} else {
660e1991d10SAlexandre Mergnat 		ret = snd_pcm_lib_free_pages(substream);
661e1991d10SAlexandre Mergnat 
662e1991d10SAlexandre Mergnat 		mt8365_afe_emi_clk_off(afe);
663e1991d10SAlexandre Mergnat 	}
664e1991d10SAlexandre Mergnat 
665e1991d10SAlexandre Mergnat 	return ret;
666e1991d10SAlexandre Mergnat }
667e1991d10SAlexandre Mergnat 
mt8365_afe_fe_prepare(struct snd_pcm_substream * substream,struct snd_soc_dai * dai)668e1991d10SAlexandre Mergnat static int mt8365_afe_fe_prepare(struct snd_pcm_substream *substream,
669e1991d10SAlexandre Mergnat 				 struct snd_soc_dai *dai)
670e1991d10SAlexandre Mergnat {
671e1991d10SAlexandre Mergnat 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
672e1991d10SAlexandre Mergnat 	struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
673e1991d10SAlexandre Mergnat 	int dai_id = snd_soc_rtd_to_cpu(rtd, 0)->id;
674e1991d10SAlexandre Mergnat 	struct mtk_base_afe_memif *memif = &afe->memif[dai_id];
675e1991d10SAlexandre Mergnat 
676e1991d10SAlexandre Mergnat 	/* set format */
677e1991d10SAlexandre Mergnat 	if (memif->data->hd_reg >= 0) {
678e1991d10SAlexandre Mergnat 		switch (substream->runtime->format) {
679e1991d10SAlexandre Mergnat 		case SNDRV_PCM_FORMAT_S16_LE:
680e1991d10SAlexandre Mergnat 			regmap_update_bits(afe->regmap, memif->data->hd_reg,
681e1991d10SAlexandre Mergnat 					   3 << memif->data->hd_shift,
682e1991d10SAlexandre Mergnat 					   0 << memif->data->hd_shift);
683e1991d10SAlexandre Mergnat 			break;
684e1991d10SAlexandre Mergnat 		case SNDRV_PCM_FORMAT_S32_LE:
685e1991d10SAlexandre Mergnat 			regmap_update_bits(afe->regmap, memif->data->hd_reg,
686e1991d10SAlexandre Mergnat 					   3 << memif->data->hd_shift,
687e1991d10SAlexandre Mergnat 					   3 << memif->data->hd_shift);
688e1991d10SAlexandre Mergnat 
689e1991d10SAlexandre Mergnat 			if (dai_id == MT8365_AFE_MEMIF_TDM_IN) {
690e1991d10SAlexandre Mergnat 				regmap_update_bits(afe->regmap,
691e1991d10SAlexandre Mergnat 						   memif->data->hd_reg,
692e1991d10SAlexandre Mergnat 						   3 << memif->data->hd_shift,
693e1991d10SAlexandre Mergnat 						   1 << memif->data->hd_shift);
694e1991d10SAlexandre Mergnat 				regmap_update_bits(afe->regmap,
695e1991d10SAlexandre Mergnat 						   memif->data->hd_reg,
696e1991d10SAlexandre Mergnat 						   1 << memif->data->hd_align_mshift,
697e1991d10SAlexandre Mergnat 						   1 << memif->data->hd_align_mshift);
698e1991d10SAlexandre Mergnat 			}
699e1991d10SAlexandre Mergnat 			break;
700e1991d10SAlexandre Mergnat 		case SNDRV_PCM_FORMAT_S24_LE:
701e1991d10SAlexandre Mergnat 			regmap_update_bits(afe->regmap, memif->data->hd_reg,
702e1991d10SAlexandre Mergnat 					   3 << memif->data->hd_shift,
703e1991d10SAlexandre Mergnat 					   1 << memif->data->hd_shift);
704e1991d10SAlexandre Mergnat 			break;
705e1991d10SAlexandre Mergnat 		default:
706e1991d10SAlexandre Mergnat 			return -EINVAL;
707e1991d10SAlexandre Mergnat 		}
708e1991d10SAlexandre Mergnat 	}
709e1991d10SAlexandre Mergnat 
710e1991d10SAlexandre Mergnat 	mt8365_afe_irq_direction_enable(afe, memif->irq_usage,
711e1991d10SAlexandre Mergnat 					MT8365_AFE_IRQ_DIR_MCU);
712e1991d10SAlexandre Mergnat 
713e1991d10SAlexandre Mergnat 	return 0;
714e1991d10SAlexandre Mergnat }
715e1991d10SAlexandre Mergnat 
mt8365_afe_fe_trigger(struct snd_pcm_substream * substream,int cmd,struct snd_soc_dai * dai)71663157d99SMark Brown static int mt8365_afe_fe_trigger(struct snd_pcm_substream *substream, int cmd,
717e1991d10SAlexandre Mergnat 				 struct snd_soc_dai *dai)
718e1991d10SAlexandre Mergnat {
719e1991d10SAlexandre Mergnat 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
720e1991d10SAlexandre Mergnat 	struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
721e1991d10SAlexandre Mergnat 	struct mt8365_afe_private *afe_priv = afe->platform_priv;
722e1991d10SAlexandre Mergnat 	int dai_id = snd_soc_rtd_to_cpu(rtd, 0)->id;
723e1991d10SAlexandre Mergnat 	struct mt8365_control_data *ctrl_data = &afe_priv->ctrl_data;
724e1991d10SAlexandre Mergnat 
725e1991d10SAlexandre Mergnat 	switch (cmd) {
726e1991d10SAlexandre Mergnat 	case SNDRV_PCM_TRIGGER_START:
727e1991d10SAlexandre Mergnat 	case SNDRV_PCM_TRIGGER_RESUME:
728e1991d10SAlexandre Mergnat 		/* enable channel merge */
729e1991d10SAlexandre Mergnat 		if (dai_id == MT8365_AFE_MEMIF_VUL2 &&
730e1991d10SAlexandre Mergnat 		    !ctrl_data->bypass_cm1) {
731e1991d10SAlexandre Mergnat 			regmap_update_bits(afe->regmap, AFE_CM1_CON0,
732e1991d10SAlexandre Mergnat 					   CM_AFE_CM_ON, CM_AFE_CM_ON);
733e1991d10SAlexandre Mergnat 		} else if (dai_id == MT8365_AFE_MEMIF_TDM_IN &&
734e1991d10SAlexandre Mergnat 			   !ctrl_data->bypass_cm2) {
735e1991d10SAlexandre Mergnat 			regmap_update_bits(afe->regmap, AFE_CM2_CON0,
736e1991d10SAlexandre Mergnat 					   CM_AFE_CM_ON, CM_AFE_CM_ON);
737e1991d10SAlexandre Mergnat 		}
738e1991d10SAlexandre Mergnat 		break;
739e1991d10SAlexandre Mergnat 	case SNDRV_PCM_TRIGGER_STOP:
740e1991d10SAlexandre Mergnat 	case SNDRV_PCM_TRIGGER_SUSPEND:
741e1991d10SAlexandre Mergnat 		/* disable channel merge */
742e1991d10SAlexandre Mergnat 		if (dai_id == MT8365_AFE_MEMIF_VUL2 &&
743e1991d10SAlexandre Mergnat 		    !ctrl_data->bypass_cm1) {
744e1991d10SAlexandre Mergnat 			regmap_update_bits(afe->regmap, AFE_CM1_CON0,
745e1991d10SAlexandre Mergnat 					   CM_AFE_CM_ON, ~CM_AFE_CM_ON);
746e1991d10SAlexandre Mergnat 		} else if (dai_id == MT8365_AFE_MEMIF_TDM_IN &&
747e1991d10SAlexandre Mergnat 			   !ctrl_data->bypass_cm2) {
748e1991d10SAlexandre Mergnat 			regmap_update_bits(afe->regmap, AFE_CM2_CON0,
749e1991d10SAlexandre Mergnat 					   CM_AFE_CM_ON, ~CM_AFE_CM_ON);
750e1991d10SAlexandre Mergnat 		}
751e1991d10SAlexandre Mergnat 		break;
752e1991d10SAlexandre Mergnat 	default:
753e1991d10SAlexandre Mergnat 		break;
754e1991d10SAlexandre Mergnat 	}
755e1991d10SAlexandre Mergnat 
756e1991d10SAlexandre Mergnat 	return mtk_afe_fe_trigger(substream, cmd, dai);
757e1991d10SAlexandre Mergnat }
758e1991d10SAlexandre Mergnat 
mt8365_afe_hw_gain1_startup(struct snd_pcm_substream * substream,struct snd_soc_dai * dai)759e1991d10SAlexandre Mergnat static int mt8365_afe_hw_gain1_startup(struct snd_pcm_substream *substream,
760e1991d10SAlexandre Mergnat 				       struct snd_soc_dai *dai)
761e1991d10SAlexandre Mergnat {
762e1991d10SAlexandre Mergnat 	struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
763e1991d10SAlexandre Mergnat 
764e1991d10SAlexandre Mergnat 	mt8365_afe_enable_main_clk(afe);
765e1991d10SAlexandre Mergnat 	return 0;
766e1991d10SAlexandre Mergnat }
767e1991d10SAlexandre Mergnat 
mt8365_afe_hw_gain1_shutdown(struct snd_pcm_substream * substream,struct snd_soc_dai * dai)768e1991d10SAlexandre Mergnat static void mt8365_afe_hw_gain1_shutdown(struct snd_pcm_substream *substream,
769e1991d10SAlexandre Mergnat 					 struct snd_soc_dai *dai)
770e1991d10SAlexandre Mergnat {
771e1991d10SAlexandre Mergnat 	struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
772e1991d10SAlexandre Mergnat 	struct mt8365_afe_private *afe_priv = afe->platform_priv;
773e1991d10SAlexandre Mergnat 	struct mt8365_be_dai_data *be =
774e1991d10SAlexandre Mergnat 		&afe_priv->be_data[dai->id - MT8365_AFE_BACKEND_BASE];
775e1991d10SAlexandre Mergnat 
776e1991d10SAlexandre Mergnat 	if (be->prepared[substream->stream]) {
777e1991d10SAlexandre Mergnat 		regmap_update_bits(afe->regmap, AFE_GAIN1_CON0,
778e1991d10SAlexandre Mergnat 				   AFE_GAIN1_CON0_EN_MASK, 0);
779e1991d10SAlexandre Mergnat 		be->prepared[substream->stream] = false;
780e1991d10SAlexandre Mergnat 	}
781e1991d10SAlexandre Mergnat 	mt8365_afe_disable_main_clk(afe);
782e1991d10SAlexandre Mergnat }
783e1991d10SAlexandre Mergnat 
mt8365_afe_hw_gain1_prepare(struct snd_pcm_substream * substream,struct snd_soc_dai * dai)784e1991d10SAlexandre Mergnat static int mt8365_afe_hw_gain1_prepare(struct snd_pcm_substream *substream,
785e1991d10SAlexandre Mergnat 				       struct snd_soc_dai *dai)
786e1991d10SAlexandre Mergnat {
787e1991d10SAlexandre Mergnat 	struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
788e1991d10SAlexandre Mergnat 	struct mt8365_afe_private *afe_priv = afe->platform_priv;
789e1991d10SAlexandre Mergnat 	struct mt8365_be_dai_data *be =
790e1991d10SAlexandre Mergnat 		&afe_priv->be_data[dai->id - MT8365_AFE_BACKEND_BASE];
791e1991d10SAlexandre Mergnat 
792e1991d10SAlexandre Mergnat 	int fs;
793e1991d10SAlexandre Mergnat 	unsigned int val1 = 0, val2 = 0;
794e1991d10SAlexandre Mergnat 
795e1991d10SAlexandre Mergnat 	if (be->prepared[substream->stream]) {
796e1991d10SAlexandre Mergnat 		dev_info(afe->dev, "%s prepared already\n", __func__);
797e1991d10SAlexandre Mergnat 		return 0;
798e1991d10SAlexandre Mergnat 	}
799e1991d10SAlexandre Mergnat 
800e1991d10SAlexandre Mergnat 	fs = mt8365_afe_fs_timing(substream->runtime->rate);
801e1991d10SAlexandre Mergnat 	regmap_update_bits(afe->regmap, AFE_GAIN1_CON0,
802e1991d10SAlexandre Mergnat 			   AFE_GAIN1_CON0_MODE_MASK, (unsigned int)fs << 4);
803e1991d10SAlexandre Mergnat 
804e1991d10SAlexandre Mergnat 	regmap_read(afe->regmap, AFE_GAIN1_CON1, &val1);
805e1991d10SAlexandre Mergnat 	regmap_read(afe->regmap, AFE_GAIN1_CUR, &val2);
806e1991d10SAlexandre Mergnat 	if ((val1 & AFE_GAIN1_CON1_MASK) != (val2 & AFE_GAIN1_CUR_MASK))
807e1991d10SAlexandre Mergnat 		regmap_update_bits(afe->regmap, AFE_GAIN1_CUR,
808e1991d10SAlexandre Mergnat 				   AFE_GAIN1_CUR_MASK, val1);
809e1991d10SAlexandre Mergnat 
810e1991d10SAlexandre Mergnat 	regmap_update_bits(afe->regmap, AFE_GAIN1_CON0,
811e1991d10SAlexandre Mergnat 			   AFE_GAIN1_CON0_EN_MASK, 1);
812e1991d10SAlexandre Mergnat 	be->prepared[substream->stream] = true;
813e1991d10SAlexandre Mergnat 
814e1991d10SAlexandre Mergnat 	return 0;
815e1991d10SAlexandre Mergnat }
816e1991d10SAlexandre Mergnat 
817e1991d10SAlexandre Mergnat static const struct snd_pcm_hardware mt8365_hostless_hardware = {
818e1991d10SAlexandre Mergnat 	.info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
819e1991d10SAlexandre Mergnat 		 SNDRV_PCM_INFO_MMAP_VALID),
820e1991d10SAlexandre Mergnat 	.period_bytes_min = 256,
821e1991d10SAlexandre Mergnat 	.period_bytes_max = 4 * 48 * 1024,
822e1991d10SAlexandre Mergnat 	.periods_min = 2,
823e1991d10SAlexandre Mergnat 	.periods_max = 256,
824e1991d10SAlexandre Mergnat 	.buffer_bytes_max = 8 * 48 * 1024,
825e1991d10SAlexandre Mergnat 	.fifo_size = 0,
826e1991d10SAlexandre Mergnat };
827e1991d10SAlexandre Mergnat 
828e1991d10SAlexandre Mergnat /* dai ops */
mtk_dai_hostless_startup(struct snd_pcm_substream * substream,struct snd_soc_dai * dai)829e1991d10SAlexandre Mergnat static int mtk_dai_hostless_startup(struct snd_pcm_substream *substream,
830e1991d10SAlexandre Mergnat 				    struct snd_soc_dai *dai)
831e1991d10SAlexandre Mergnat {
832e1991d10SAlexandre Mergnat 	struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
833e1991d10SAlexandre Mergnat 	struct snd_pcm_runtime *runtime = substream->runtime;
834e1991d10SAlexandre Mergnat 	int ret;
835e1991d10SAlexandre Mergnat 
836e1991d10SAlexandre Mergnat 	snd_soc_set_runtime_hwparams(substream, &mt8365_hostless_hardware);
837e1991d10SAlexandre Mergnat 
838e1991d10SAlexandre Mergnat 	ret = snd_pcm_hw_constraint_integer(runtime,
839e1991d10SAlexandre Mergnat 					    SNDRV_PCM_HW_PARAM_PERIODS);
840e1991d10SAlexandre Mergnat 	if (ret < 0)
841e1991d10SAlexandre Mergnat 		dev_err(afe->dev, "snd_pcm_hw_constraint_integer failed\n");
842e1991d10SAlexandre Mergnat 	return ret;
843e1991d10SAlexandre Mergnat }
844e1991d10SAlexandre Mergnat 
845e1991d10SAlexandre Mergnat /* FE DAIs */
846e1991d10SAlexandre Mergnat static const struct snd_soc_dai_ops mt8365_afe_fe_dai_ops = {
847e1991d10SAlexandre Mergnat 	.startup	= mt8365_afe_fe_startup,
848e1991d10SAlexandre Mergnat 	.shutdown	= mt8365_afe_fe_shutdown,
849e1991d10SAlexandre Mergnat 	.hw_params	= mt8365_afe_fe_hw_params,
850e1991d10SAlexandre Mergnat 	.hw_free	= mt8365_afe_fe_hw_free,
851e1991d10SAlexandre Mergnat 	.prepare	= mt8365_afe_fe_prepare,
852e1991d10SAlexandre Mergnat 	.trigger	= mt8365_afe_fe_trigger,
853e1991d10SAlexandre Mergnat };
854e1991d10SAlexandre Mergnat 
855e1991d10SAlexandre Mergnat static const struct snd_soc_dai_ops mt8365_dai_hostless_ops = {
856e1991d10SAlexandre Mergnat 	.startup = mtk_dai_hostless_startup,
857e1991d10SAlexandre Mergnat };
858e1991d10SAlexandre Mergnat 
859e1991d10SAlexandre Mergnat static const struct snd_soc_dai_ops mt8365_afe_hw_gain1_ops = {
860e1991d10SAlexandre Mergnat 	.startup	= mt8365_afe_hw_gain1_startup,
861e1991d10SAlexandre Mergnat 	.shutdown	= mt8365_afe_hw_gain1_shutdown,
862e1991d10SAlexandre Mergnat 	.prepare	= mt8365_afe_hw_gain1_prepare,
863e1991d10SAlexandre Mergnat };
864e1991d10SAlexandre Mergnat 
865e1991d10SAlexandre Mergnat static struct snd_soc_dai_driver mt8365_memif_dai_driver[] = {
866e1991d10SAlexandre Mergnat 	/* FE DAIs: memory intefaces to CPU */
867e1991d10SAlexandre Mergnat 	{
868e1991d10SAlexandre Mergnat 		.name = "DL1",
869e1991d10SAlexandre Mergnat 		.id = MT8365_AFE_MEMIF_DL1,
870e1991d10SAlexandre Mergnat 		.playback = {
871e1991d10SAlexandre Mergnat 			.stream_name = "DL1",
872e1991d10SAlexandre Mergnat 			.channels_min = 1,
873e1991d10SAlexandre Mergnat 			.channels_max = 2,
874e1991d10SAlexandre Mergnat 			.rates = SNDRV_PCM_RATE_8000_192000,
875e1991d10SAlexandre Mergnat 			.formats = SNDRV_PCM_FMTBIT_S16_LE |
876e1991d10SAlexandre Mergnat 				   SNDRV_PCM_FMTBIT_S32_LE,
877e1991d10SAlexandre Mergnat 		},
878e1991d10SAlexandre Mergnat 		.ops = &mt8365_afe_fe_dai_ops,
879e1991d10SAlexandre Mergnat 	}, {
880e1991d10SAlexandre Mergnat 		.name = "DL2",
881e1991d10SAlexandre Mergnat 		.id = MT8365_AFE_MEMIF_DL2,
882e1991d10SAlexandre Mergnat 		.playback = {
883e1991d10SAlexandre Mergnat 			.stream_name = "DL2",
884e1991d10SAlexandre Mergnat 			.channels_min = 1,
885e1991d10SAlexandre Mergnat 			.channels_max = 2,
886e1991d10SAlexandre Mergnat 			.rates = SNDRV_PCM_RATE_8000_192000,
887e1991d10SAlexandre Mergnat 			.formats = SNDRV_PCM_FMTBIT_S16_LE |
888e1991d10SAlexandre Mergnat 				   SNDRV_PCM_FMTBIT_S32_LE,
889e1991d10SAlexandre Mergnat 		},
890e1991d10SAlexandre Mergnat 		.ops = &mt8365_afe_fe_dai_ops,
891e1991d10SAlexandre Mergnat 	}, {
892e1991d10SAlexandre Mergnat 		.name = "TDM_OUT",
893e1991d10SAlexandre Mergnat 		.id = MT8365_AFE_MEMIF_TDM_OUT,
894e1991d10SAlexandre Mergnat 		.playback = {
895e1991d10SAlexandre Mergnat 			.stream_name = "TDM_OUT",
896e1991d10SAlexandre Mergnat 			.channels_min = 1,
897e1991d10SAlexandre Mergnat 			.channels_max = 8,
898e1991d10SAlexandre Mergnat 			.rates = SNDRV_PCM_RATE_8000_192000,
899e1991d10SAlexandre Mergnat 			.formats = SNDRV_PCM_FMTBIT_S16_LE |
900e1991d10SAlexandre Mergnat 				   SNDRV_PCM_FMTBIT_S32_LE,
901e1991d10SAlexandre Mergnat 		},
902e1991d10SAlexandre Mergnat 		.ops = &mt8365_afe_fe_dai_ops,
903e1991d10SAlexandre Mergnat 	}, {
904e1991d10SAlexandre Mergnat 		.name = "AWB",
905e1991d10SAlexandre Mergnat 		.id = MT8365_AFE_MEMIF_AWB,
906e1991d10SAlexandre Mergnat 		.capture = {
907e1991d10SAlexandre Mergnat 			.stream_name = "AWB",
908e1991d10SAlexandre Mergnat 			.channels_min = 1,
909e1991d10SAlexandre Mergnat 			.channels_max = 2,
910e1991d10SAlexandre Mergnat 			.rates = SNDRV_PCM_RATE_8000_192000,
911e1991d10SAlexandre Mergnat 			.formats = SNDRV_PCM_FMTBIT_S16_LE |
912e1991d10SAlexandre Mergnat 				   SNDRV_PCM_FMTBIT_S32_LE,
913e1991d10SAlexandre Mergnat 		},
914e1991d10SAlexandre Mergnat 		.ops = &mt8365_afe_fe_dai_ops,
915e1991d10SAlexandre Mergnat 	}, {
916e1991d10SAlexandre Mergnat 		.name = "VUL",
917e1991d10SAlexandre Mergnat 		.id = MT8365_AFE_MEMIF_VUL,
918e1991d10SAlexandre Mergnat 		.capture = {
919e1991d10SAlexandre Mergnat 			.stream_name = "VUL",
920e1991d10SAlexandre Mergnat 			.channels_min = 1,
921e1991d10SAlexandre Mergnat 			.channels_max = 2,
922e1991d10SAlexandre Mergnat 			.rates = SNDRV_PCM_RATE_8000_192000,
923e1991d10SAlexandre Mergnat 			.formats = SNDRV_PCM_FMTBIT_S16_LE |
924e1991d10SAlexandre Mergnat 				   SNDRV_PCM_FMTBIT_S32_LE,
925e1991d10SAlexandre Mergnat 		},
926e1991d10SAlexandre Mergnat 		.ops = &mt8365_afe_fe_dai_ops,
927e1991d10SAlexandre Mergnat 	}, {
928e1991d10SAlexandre Mergnat 		.name = "VUL2",
929e1991d10SAlexandre Mergnat 		.id = MT8365_AFE_MEMIF_VUL2,
930e1991d10SAlexandre Mergnat 		.capture = {
931e1991d10SAlexandre Mergnat 			.stream_name = "VUL2",
932e1991d10SAlexandre Mergnat 			.channels_min = 1,
933e1991d10SAlexandre Mergnat 			.channels_max = 16,
934e1991d10SAlexandre Mergnat 			.rates = SNDRV_PCM_RATE_8000_192000,
935e1991d10SAlexandre Mergnat 			.formats = SNDRV_PCM_FMTBIT_S16_LE |
936e1991d10SAlexandre Mergnat 				   SNDRV_PCM_FMTBIT_S32_LE,
937e1991d10SAlexandre Mergnat 		},
938e1991d10SAlexandre Mergnat 		.ops = &mt8365_afe_fe_dai_ops,
939e1991d10SAlexandre Mergnat 	}, {
940e1991d10SAlexandre Mergnat 		.name = "VUL3",
941e1991d10SAlexandre Mergnat 		.id = MT8365_AFE_MEMIF_VUL3,
942e1991d10SAlexandre Mergnat 		.capture = {
943e1991d10SAlexandre Mergnat 			.stream_name = "VUL3",
944e1991d10SAlexandre Mergnat 			.channels_min = 1,
945e1991d10SAlexandre Mergnat 			.channels_max = 2,
946e1991d10SAlexandre Mergnat 			.rates = SNDRV_PCM_RATE_8000_192000,
947e1991d10SAlexandre Mergnat 			.formats = SNDRV_PCM_FMTBIT_S16_LE |
948e1991d10SAlexandre Mergnat 				   SNDRV_PCM_FMTBIT_S32_LE,
949e1991d10SAlexandre Mergnat 		},
950e1991d10SAlexandre Mergnat 		.ops = &mt8365_afe_fe_dai_ops,
951e1991d10SAlexandre Mergnat 	}, {
952e1991d10SAlexandre Mergnat 		.name = "TDM_IN",
953e1991d10SAlexandre Mergnat 		.id = MT8365_AFE_MEMIF_TDM_IN,
954e1991d10SAlexandre Mergnat 		.capture = {
955e1991d10SAlexandre Mergnat 			.stream_name = "TDM_IN",
956e1991d10SAlexandre Mergnat 			.channels_min = 1,
957e1991d10SAlexandre Mergnat 			.channels_max = 16,
958e1991d10SAlexandre Mergnat 			.rates = SNDRV_PCM_RATE_8000_192000,
959e1991d10SAlexandre Mergnat 			.formats = SNDRV_PCM_FMTBIT_S16_LE |
960e1991d10SAlexandre Mergnat 				   SNDRV_PCM_FMTBIT_S32_LE,
961e1991d10SAlexandre Mergnat 		},
962e1991d10SAlexandre Mergnat 		.ops = &mt8365_afe_fe_dai_ops,
963e1991d10SAlexandre Mergnat 	}, {
964e1991d10SAlexandre Mergnat 		.name = "Hostless FM DAI",
965e1991d10SAlexandre Mergnat 		.id = MT8365_AFE_IO_VIRTUAL_FM,
966e1991d10SAlexandre Mergnat 		.playback = {
967e1991d10SAlexandre Mergnat 			.stream_name = "Hostless FM DL",
968e1991d10SAlexandre Mergnat 			.channels_min = 1,
969e1991d10SAlexandre Mergnat 			.channels_max = 2,
970e1991d10SAlexandre Mergnat 			.rates = SNDRV_PCM_RATE_8000_192000,
971e1991d10SAlexandre Mergnat 			.formats = SNDRV_PCM_FMTBIT_S16_LE |
972e1991d10SAlexandre Mergnat 					  SNDRV_PCM_FMTBIT_S24_LE |
973e1991d10SAlexandre Mergnat 					   SNDRV_PCM_FMTBIT_S32_LE,
974e1991d10SAlexandre Mergnat 		},
975e1991d10SAlexandre Mergnat 		.capture = {
976e1991d10SAlexandre Mergnat 			.stream_name = "Hostless FM UL",
977e1991d10SAlexandre Mergnat 			.channels_min = 1,
978e1991d10SAlexandre Mergnat 			.channels_max = 2,
979e1991d10SAlexandre Mergnat 			.rates = SNDRV_PCM_RATE_8000_192000,
980e1991d10SAlexandre Mergnat 			.formats = SNDRV_PCM_FMTBIT_S16_LE |
981e1991d10SAlexandre Mergnat 					  SNDRV_PCM_FMTBIT_S24_LE |
982e1991d10SAlexandre Mergnat 					   SNDRV_PCM_FMTBIT_S32_LE,
983e1991d10SAlexandre Mergnat 		},
984e1991d10SAlexandre Mergnat 		.ops = &mt8365_dai_hostless_ops,
985e1991d10SAlexandre Mergnat 	}, {
986e1991d10SAlexandre Mergnat 		.name = "HW_GAIN1",
987e1991d10SAlexandre Mergnat 		.id = MT8365_AFE_IO_HW_GAIN1,
988e1991d10SAlexandre Mergnat 		.playback = {
989e1991d10SAlexandre Mergnat 			.stream_name = "HW Gain 1 In",
990e1991d10SAlexandre Mergnat 			.channels_min = 1,
991e1991d10SAlexandre Mergnat 			.channels_max = 2,
992e1991d10SAlexandre Mergnat 			.rates = SNDRV_PCM_RATE_8000_192000,
993e1991d10SAlexandre Mergnat 			.formats = SNDRV_PCM_FMTBIT_S16_LE |
994e1991d10SAlexandre Mergnat 				   SNDRV_PCM_FMTBIT_S24_LE |
995e1991d10SAlexandre Mergnat 				   SNDRV_PCM_FMTBIT_S32_LE,
996e1991d10SAlexandre Mergnat 		},
997e1991d10SAlexandre Mergnat 		.capture = {
998e1991d10SAlexandre Mergnat 			.stream_name = "HW Gain 1 Out",
999e1991d10SAlexandre Mergnat 			.channels_min = 1,
1000e1991d10SAlexandre Mergnat 			.channels_max = 2,
1001e1991d10SAlexandre Mergnat 			.rates = SNDRV_PCM_RATE_8000_192000,
1002e1991d10SAlexandre Mergnat 			.formats = SNDRV_PCM_FMTBIT_S16_LE |
1003e1991d10SAlexandre Mergnat 				   SNDRV_PCM_FMTBIT_S24_LE |
1004e1991d10SAlexandre Mergnat 				   SNDRV_PCM_FMTBIT_S32_LE,
1005e1991d10SAlexandre Mergnat 		},
1006e1991d10SAlexandre Mergnat 		.ops = &mt8365_afe_hw_gain1_ops,
1007e1991d10SAlexandre Mergnat 		.symmetric_rate = 1,
1008e1991d10SAlexandre Mergnat 		.symmetric_channels = 1,
1009e1991d10SAlexandre Mergnat 		.symmetric_sample_bits = 1,
1010e1991d10SAlexandre Mergnat 	},
1011e1991d10SAlexandre Mergnat };
1012e1991d10SAlexandre Mergnat 
1013e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o00_mix[] = {
1014e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I05 Switch", AFE_CONN0, 5, 1, 0),
1015e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I07 Switch", AFE_CONN0, 7, 1, 0),
1016e1991d10SAlexandre Mergnat };
1017e1991d10SAlexandre Mergnat 
1018e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o01_mix[] = {
1019e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I06 Switch", AFE_CONN1, 6, 1, 0),
1020e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I08 Switch", AFE_CONN1, 8, 1, 0),
1021e1991d10SAlexandre Mergnat };
1022e1991d10SAlexandre Mergnat 
1023e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o03_mix[] = {
1024e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I05 Switch", AFE_CONN3, 5, 1, 0),
1025e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I07 Switch", AFE_CONN3, 7, 1, 0),
1026e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I00 Switch", AFE_CONN3, 0, 1, 0),
1027e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I10 Switch", AFE_CONN3, 10, 1, 0),
1028e1991d10SAlexandre Mergnat };
1029e1991d10SAlexandre Mergnat 
1030e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o04_mix[] = {
1031e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I06 Switch", AFE_CONN4, 6, 1, 0),
1032e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I08 Switch", AFE_CONN4, 8, 1, 0),
1033e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I01 Switch", AFE_CONN4, 1, 1, 0),
1034e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I11 Switch", AFE_CONN4, 11, 1, 0),
1035e1991d10SAlexandre Mergnat };
1036e1991d10SAlexandre Mergnat 
1037e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o05_mix[] = {
1038e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I00 Switch", AFE_CONN5, 0, 1, 0),
1039e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I03 Switch", AFE_CONN5, 3, 1, 0),
1040e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I05 Switch", AFE_CONN5, 5, 1, 0),
1041e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I07 Switch", AFE_CONN5, 7, 1, 0),
1042e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I09 Switch", AFE_CONN5, 9, 1, 0),
1043e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I14 Switch", AFE_CONN5, 14, 1, 0),
1044e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I16 Switch", AFE_CONN5, 16, 1, 0),
1045e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I18 Switch", AFE_CONN5, 18, 1, 0),
1046e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I20 Switch", AFE_CONN5, 20, 1, 0),
1047e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I23 Switch", AFE_CONN5, 23, 1, 0),
1048e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I10L Switch", AFE_CONN5, 10, 1, 0),
1049e1991d10SAlexandre Mergnat };
1050e1991d10SAlexandre Mergnat 
1051e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o06_mix[] = {
1052e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I01 Switch", AFE_CONN6, 1, 1, 0),
1053e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I04 Switch", AFE_CONN6, 4, 1, 0),
1054e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I06 Switch", AFE_CONN6, 6, 1, 0),
1055e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I08 Switch", AFE_CONN6, 8, 1, 0),
1056e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I22 Switch", AFE_CONN6, 22, 1, 0),
1057e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I15 Switch", AFE_CONN6, 15, 1, 0),
1058e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I17 Switch", AFE_CONN6, 17, 1, 0),
1059e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I19 Switch", AFE_CONN6, 19, 1, 0),
1060e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I21 Switch", AFE_CONN6, 21, 1, 0),
1061e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I24 Switch", AFE_CONN6, 24, 1, 0),
1062e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I11L Switch", AFE_CONN6, 11, 1, 0),
1063e1991d10SAlexandre Mergnat };
1064e1991d10SAlexandre Mergnat 
1065e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o07_mix[] = {
1066e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I05 Switch", AFE_CONN7, 5, 1, 0),
1067e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I07 Switch", AFE_CONN7, 7, 1, 0),
1068e1991d10SAlexandre Mergnat };
1069e1991d10SAlexandre Mergnat 
1070e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o08_mix[] = {
1071e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I06 Switch", AFE_CONN8, 6, 1, 0),
1072e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I08 Switch", AFE_CONN8, 8, 1, 0),
1073e1991d10SAlexandre Mergnat };
1074e1991d10SAlexandre Mergnat 
1075e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o09_mix[] = {
1076e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I00 Switch", AFE_CONN9, 0, 1, 0),
1077e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I03 Switch", AFE_CONN9, 3, 1, 0),
1078e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I09 Switch", AFE_CONN9, 9, 1, 0),
1079e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I14 Switch", AFE_CONN9, 14, 1, 0),
1080e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I16 Switch", AFE_CONN9, 16, 1, 0),
1081e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I18 Switch", AFE_CONN9, 18, 1, 0),
1082e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I20 Switch", AFE_CONN9, 20, 1, 0),
1083e1991d10SAlexandre Mergnat };
1084e1991d10SAlexandre Mergnat 
1085e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o10_mix[] = {
1086e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I01 Switch", AFE_CONN10, 1, 1, 0),
1087e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I04 Switch", AFE_CONN10, 4, 1, 0),
1088e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I22 Switch", AFE_CONN10, 22, 1, 0),
1089e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I15 Switch", AFE_CONN10, 15, 1, 0),
1090e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I17 Switch", AFE_CONN10, 17, 1, 0),
1091e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I19 Switch", AFE_CONN10, 19, 1, 0),
1092e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I21 Switch", AFE_CONN10, 21, 1, 0),
1093e1991d10SAlexandre Mergnat };
1094e1991d10SAlexandre Mergnat 
1095e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o11_mix[] = {
1096e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I00 Switch", AFE_CONN11, 0, 1, 0),
1097e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I03 Switch", AFE_CONN11, 3, 1, 0),
1098e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I09 Switch", AFE_CONN11, 9, 1, 0),
1099e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I14 Switch", AFE_CONN11, 14, 1, 0),
1100e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I16 Switch", AFE_CONN11, 16, 1, 0),
1101e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I18 Switch", AFE_CONN11, 18, 1, 0),
1102e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I20 Switch", AFE_CONN11, 20, 1, 0),
1103e1991d10SAlexandre Mergnat };
1104e1991d10SAlexandre Mergnat 
1105e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o12_mix[] = {
1106e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I01 Switch", AFE_CONN12, 1, 1, 0),
1107e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I04 Switch", AFE_CONN12, 4, 1, 0),
1108e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I22 Switch", AFE_CONN12, 22, 1, 0),
1109e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I15 Switch", AFE_CONN12, 15, 1, 0),
1110e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I17 Switch", AFE_CONN12, 17, 1, 0),
1111e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I19 Switch", AFE_CONN12, 19, 1, 0),
1112e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I21 Switch", AFE_CONN12, 21, 1, 0),
1113e1991d10SAlexandre Mergnat };
1114e1991d10SAlexandre Mergnat 
1115e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o13_mix[] = {
1116e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I00 Switch", AFE_CONN13, 0, 1, 0),
1117e1991d10SAlexandre Mergnat };
1118e1991d10SAlexandre Mergnat 
1119e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o14_mix[] = {
1120e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I01 Switch", AFE_CONN14, 1, 1, 0),
1121e1991d10SAlexandre Mergnat };
1122e1991d10SAlexandre Mergnat 
1123e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o15_mix[] = {
1124e1991d10SAlexandre Mergnat };
1125e1991d10SAlexandre Mergnat 
1126e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o16_mix[] = {
1127e1991d10SAlexandre Mergnat };
1128e1991d10SAlexandre Mergnat 
1129e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o17_mix[] = {
1130e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I03 Switch", AFE_CONN17, 3, 1, 0),
1131e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I14 Switch", AFE_CONN17, 14, 1, 0),
1132e1991d10SAlexandre Mergnat };
1133e1991d10SAlexandre Mergnat 
1134e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o18_mix[] = {
1135e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I04 Switch", AFE_CONN18, 4, 1, 0),
1136e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I15 Switch", AFE_CONN18, 15, 1, 0),
1137e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I23 Switch", AFE_CONN18, 23, 1, 0),
1138e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I25 Switch", AFE_CONN18, 25, 1, 0),
1139e1991d10SAlexandre Mergnat };
1140e1991d10SAlexandre Mergnat 
1141e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o19_mix[] = {
1142e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I04 Switch", AFE_CONN19, 4, 1, 0),
1143e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I16 Switch", AFE_CONN19, 16, 1, 0),
1144e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I23 Switch", AFE_CONN19, 23, 1, 0),
1145e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I24 Switch", AFE_CONN19, 24, 1, 0),
1146e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I25 Switch", AFE_CONN19, 25, 1, 0),
1147e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I26 Switch", AFE_CONN19, 26, 1, 0),
1148e1991d10SAlexandre Mergnat };
1149e1991d10SAlexandre Mergnat 
1150e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o20_mix[] = {
1151e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I17 Switch", AFE_CONN20, 17, 1, 0),
1152e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I24 Switch", AFE_CONN20, 24, 1, 0),
1153e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I26 Switch", AFE_CONN20, 26, 1, 0),
1154e1991d10SAlexandre Mergnat };
1155e1991d10SAlexandre Mergnat 
1156e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o21_mix[] = {
1157e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I18 Switch", AFE_CONN21, 18, 1, 0),
1158e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I23 Switch", AFE_CONN21, 23, 1, 0),
1159e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I25 Switch", AFE_CONN21, 25, 1, 0),
1160e1991d10SAlexandre Mergnat };
1161e1991d10SAlexandre Mergnat 
1162e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o22_mix[] = {
1163e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I19 Switch", AFE_CONN22, 19, 1, 0),
1164e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I24 Switch", AFE_CONN22, 24, 1, 0),
1165e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I26 Switch", AFE_CONN22, 26, 1, 0),
1166e1991d10SAlexandre Mergnat };
1167e1991d10SAlexandre Mergnat 
1168e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o23_mix[] = {
1169e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I20 Switch", AFE_CONN23, 20, 1, 0),
1170e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I23 Switch", AFE_CONN23, 23, 1, 0),
1171e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I25 Switch", AFE_CONN23, 25, 1, 0),
1172e1991d10SAlexandre Mergnat };
1173e1991d10SAlexandre Mergnat 
1174e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o24_mix[] = {
1175e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I21 Switch", AFE_CONN24, 21, 1, 0),
1176e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I24 Switch", AFE_CONN24, 24, 1, 0),
1177e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I26 Switch", AFE_CONN24, 26, 1, 0),
1178e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I23 Switch", AFE_CONN24, 23, 1, 0),
1179e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I25 Switch", AFE_CONN24, 25, 1, 0),
1180e1991d10SAlexandre Mergnat };
1181e1991d10SAlexandre Mergnat 
1182e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o25_mix[] = {
1183e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I27 Switch", AFE_CONN25, 27, 1, 0),
1184e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I23 Switch", AFE_CONN25, 23, 1, 0),
1185e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I25 Switch", AFE_CONN25, 25, 1, 0),
1186e1991d10SAlexandre Mergnat };
1187e1991d10SAlexandre Mergnat 
1188e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o26_mix[] = {
1189e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I28 Switch", AFE_CONN26, 28, 1, 0),
1190e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I24 Switch", AFE_CONN26, 24, 1, 0),
1191e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I26 Switch", AFE_CONN26, 26, 1, 0),
1192e1991d10SAlexandre Mergnat };
1193e1991d10SAlexandre Mergnat 
1194e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o27_mix[] = {
1195e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I05 Switch", AFE_CONN27, 5, 1, 0),
1196e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I07 Switch", AFE_CONN27, 7, 1, 0),
1197e1991d10SAlexandre Mergnat };
1198e1991d10SAlexandre Mergnat 
1199e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o28_mix[] = {
1200e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I06 Switch", AFE_CONN28, 6, 1, 0),
1201e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I08 Switch", AFE_CONN28, 8, 1, 0),
1202e1991d10SAlexandre Mergnat };
1203e1991d10SAlexandre Mergnat 
1204e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o29_mix[] = {
1205e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I05 Switch", AFE_CONN29, 5, 1, 0),
1206e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I07 Switch", AFE_CONN29, 7, 1, 0),
1207e1991d10SAlexandre Mergnat };
1208e1991d10SAlexandre Mergnat 
1209e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o30_mix[] = {
1210e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I06 Switch", AFE_CONN30, 6, 1, 0),
1211e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I08 Switch", AFE_CONN30, 8, 1, 0),
1212e1991d10SAlexandre Mergnat };
1213e1991d10SAlexandre Mergnat 
1214e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o31_mix[] = {
1215e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I29 Switch", AFE_CONN31, 29, 1, 0),
1216e1991d10SAlexandre Mergnat };
1217e1991d10SAlexandre Mergnat 
1218e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o32_mix[] = {
1219e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I30 Switch", AFE_CONN32, 30, 1, 0),
1220e1991d10SAlexandre Mergnat };
1221e1991d10SAlexandre Mergnat 
1222e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o33_mix[] = {
1223e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I31 Switch", AFE_CONN33, 31, 1, 0),
1224e1991d10SAlexandre Mergnat };
1225e1991d10SAlexandre Mergnat 
1226e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o34_mix[] = {
1227e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I32 Switch", AFE_CONN34_1, 0, 1, 0),
1228e1991d10SAlexandre Mergnat };
1229e1991d10SAlexandre Mergnat 
1230e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o35_mix[] = {
1231e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I33 Switch", AFE_CONN35_1, 1, 1, 0),
1232e1991d10SAlexandre Mergnat };
1233e1991d10SAlexandre Mergnat 
1234e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_o36_mix[] = {
1235e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("I34 Switch", AFE_CONN36_1, 2, 1, 0),
1236e1991d10SAlexandre Mergnat };
1237e1991d10SAlexandre Mergnat 
1238e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mtk_hw_gain1_in_ch1_mix[] = {
1239e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("CONNSYS_I2S_CH1 Switch", AFE_CONN13,
1240e1991d10SAlexandre Mergnat 				    0, 1, 0),
1241e1991d10SAlexandre Mergnat };
1242e1991d10SAlexandre Mergnat 
1243e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mtk_hw_gain1_in_ch2_mix[] = {
1244e1991d10SAlexandre Mergnat 	SOC_DAPM_SINGLE_AUTODISABLE("CONNSYS_I2S_CH2 Switch", AFE_CONN14,
1245e1991d10SAlexandre Mergnat 				    1, 1, 0),
1246e1991d10SAlexandre Mergnat };
1247e1991d10SAlexandre Mergnat 
mt8365_afe_cm2_io_input_mux_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1248e1991d10SAlexandre Mergnat static int mt8365_afe_cm2_io_input_mux_get(struct snd_kcontrol *kcontrol,
1249e1991d10SAlexandre Mergnat 					   struct snd_ctl_elem_value *ucontrol)
1250e1991d10SAlexandre Mergnat {
1251e1991d10SAlexandre Mergnat 	ucontrol->value.integer.value[0] = mCM2Input;
1252e1991d10SAlexandre Mergnat 
1253e1991d10SAlexandre Mergnat 	return 0;
1254e1991d10SAlexandre Mergnat }
1255e1991d10SAlexandre Mergnat 
mt8365_afe_cm2_io_input_mux_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1256e1991d10SAlexandre Mergnat static int mt8365_afe_cm2_io_input_mux_put(struct snd_kcontrol *kcontrol,
1257e1991d10SAlexandre Mergnat 					   struct snd_ctl_elem_value *ucontrol)
1258e1991d10SAlexandre Mergnat {
1259e1991d10SAlexandre Mergnat 	struct snd_soc_dapm_context *dapm =
1260e1991d10SAlexandre Mergnat 		snd_soc_dapm_kcontrol_dapm(kcontrol);
1261e1991d10SAlexandre Mergnat 	struct snd_soc_component *comp = snd_soc_dapm_to_component(dapm);
1262e1991d10SAlexandre Mergnat 	struct mtk_base_afe *afe = snd_soc_component_get_drvdata(comp);
1263e1991d10SAlexandre Mergnat 	struct mt8365_afe_private *afe_priv = afe->platform_priv;
1264e1991d10SAlexandre Mergnat 	int ret;
1265e1991d10SAlexandre Mergnat 
1266e1991d10SAlexandre Mergnat 	mCM2Input = ucontrol->value.enumerated.item[0];
1267e1991d10SAlexandre Mergnat 
1268e1991d10SAlexandre Mergnat 	afe_priv->cm2_mux_input = mCM2Input;
1269e1991d10SAlexandre Mergnat 	ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
1270e1991d10SAlexandre Mergnat 
1271e1991d10SAlexandre Mergnat 	return ret;
1272e1991d10SAlexandre Mergnat }
1273e1991d10SAlexandre Mergnat 
1274e1991d10SAlexandre Mergnat static const char * const fmhwgain_text[] = {
1275e1991d10SAlexandre Mergnat 	"OPEN", "FM_HW_GAIN_IO"
1276e1991d10SAlexandre Mergnat };
1277e1991d10SAlexandre Mergnat 
1278e1991d10SAlexandre Mergnat static const char * const ain_text[] = {
1279e1991d10SAlexandre Mergnat 	"INT ADC", "EXT ADC",
1280e1991d10SAlexandre Mergnat };
1281e1991d10SAlexandre Mergnat 
1282e1991d10SAlexandre Mergnat static const char * const vul2_in_input_text[] = {
1283e1991d10SAlexandre Mergnat 	"VUL2_IN_FROM_O17O18", "VUL2_IN_FROM_CM1",
1284e1991d10SAlexandre Mergnat };
1285e1991d10SAlexandre Mergnat 
1286e1991d10SAlexandre Mergnat static const char * const mt8365_afe_cm2_mux_text[] = {
1287e1991d10SAlexandre Mergnat 	"OPEN", "FROM_GASRC1_OUT", "FROM_GASRC2_OUT", "FROM_TDM_ASRC_OUT",
1288e1991d10SAlexandre Mergnat };
1289e1991d10SAlexandre Mergnat 
1290e1991d10SAlexandre Mergnat static SOC_ENUM_SINGLE_VIRT_DECL(fmhwgain_enum, fmhwgain_text);
1291e1991d10SAlexandre Mergnat static SOC_ENUM_SINGLE_DECL(ain_enum, AFE_ADDA_TOP_CON0, 0, ain_text);
1292e1991d10SAlexandre Mergnat static SOC_ENUM_SINGLE_VIRT_DECL(vul2_in_input_enum, vul2_in_input_text);
1293e1991d10SAlexandre Mergnat static SOC_ENUM_SINGLE_VIRT_DECL(mt8365_afe_cm2_mux_input_enum,
1294e1991d10SAlexandre Mergnat 	mt8365_afe_cm2_mux_text);
1295e1991d10SAlexandre Mergnat 
1296e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new fmhwgain_mux =
1297e1991d10SAlexandre Mergnat 	SOC_DAPM_ENUM("FM HW Gain Source", fmhwgain_enum);
1298e1991d10SAlexandre Mergnat 
1299e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new ain_mux =
1300e1991d10SAlexandre Mergnat 	SOC_DAPM_ENUM("AIN Source", ain_enum);
1301e1991d10SAlexandre Mergnat 
1302e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new vul2_in_input_mux =
1303e1991d10SAlexandre Mergnat 	SOC_DAPM_ENUM("VUL2 Input", vul2_in_input_enum);
1304e1991d10SAlexandre Mergnat 
1305e1991d10SAlexandre Mergnat static const struct snd_kcontrol_new mt8365_afe_cm2_mux_input_mux =
1306e1991d10SAlexandre Mergnat 	SOC_DAPM_ENUM_EXT("CM2_MUX Source", mt8365_afe_cm2_mux_input_enum,
1307e1991d10SAlexandre Mergnat 			  mt8365_afe_cm2_io_input_mux_get,
1308e1991d10SAlexandre Mergnat 			  mt8365_afe_cm2_io_input_mux_put);
1309e1991d10SAlexandre Mergnat 
1310e1991d10SAlexandre Mergnat static const struct snd_soc_dapm_widget mt8365_memif_widgets[] = {
1311e1991d10SAlexandre Mergnat 	/* inter-connections */
1312e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I00", SND_SOC_NOPM, 0, 0, NULL, 0),
1313e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I01", SND_SOC_NOPM, 0, 0, NULL, 0),
1314e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I03", SND_SOC_NOPM, 0, 0, NULL, 0),
1315e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I04", SND_SOC_NOPM, 0, 0, NULL, 0),
1316e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I05", SND_SOC_NOPM, 0, 0, NULL, 0),
1317e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I06", SND_SOC_NOPM, 0, 0, NULL, 0),
1318e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I07", SND_SOC_NOPM, 0, 0, NULL, 0),
1319e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I08", SND_SOC_NOPM, 0, 0, NULL, 0),
1320e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I05L", SND_SOC_NOPM, 0, 0, NULL, 0),
1321e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I06L", SND_SOC_NOPM, 0, 0, NULL, 0),
1322e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I07L", SND_SOC_NOPM, 0, 0, NULL, 0),
1323e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I08L", SND_SOC_NOPM, 0, 0, NULL, 0),
1324e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I09", SND_SOC_NOPM, 0, 0, NULL, 0),
1325e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I10", SND_SOC_NOPM, 0, 0, NULL, 0),
1326e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I11", SND_SOC_NOPM, 0, 0, NULL, 0),
1327e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I10L", SND_SOC_NOPM, 0, 0, NULL, 0),
1328e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I11L", SND_SOC_NOPM, 0, 0, NULL, 0),
1329e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I12", SND_SOC_NOPM, 0, 0, NULL, 0),
1330e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I13", SND_SOC_NOPM, 0, 0, NULL, 0),
1331e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I14", SND_SOC_NOPM, 0, 0, NULL, 0),
1332e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I15", SND_SOC_NOPM, 0, 0, NULL, 0),
1333e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I16", SND_SOC_NOPM, 0, 0, NULL, 0),
1334e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I17", SND_SOC_NOPM, 0, 0, NULL, 0),
1335e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I18", SND_SOC_NOPM, 0, 0, NULL, 0),
1336e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I19", SND_SOC_NOPM, 0, 0, NULL, 0),
1337e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I20", SND_SOC_NOPM, 0, 0, NULL, 0),
1338e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I21", SND_SOC_NOPM, 0, 0, NULL, 0),
1339e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I22", SND_SOC_NOPM, 0, 0, NULL, 0),
1340e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I23", SND_SOC_NOPM, 0, 0, NULL, 0),
1341e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I24", SND_SOC_NOPM, 0, 0, NULL, 0),
1342e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I25", SND_SOC_NOPM, 0, 0, NULL, 0),
1343e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I26", SND_SOC_NOPM, 0, 0, NULL, 0),
1344e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I27", SND_SOC_NOPM, 0, 0, NULL, 0),
1345e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I28", SND_SOC_NOPM, 0, 0, NULL, 0),
1346e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I29", SND_SOC_NOPM, 0, 0, NULL, 0),
1347e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I30", SND_SOC_NOPM, 0, 0, NULL, 0),
1348e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I31", SND_SOC_NOPM, 0, 0, NULL, 0),
1349e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I32", SND_SOC_NOPM, 0, 0, NULL, 0),
1350e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I33", SND_SOC_NOPM, 0, 0, NULL, 0),
1351e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("I34", SND_SOC_NOPM, 0, 0, NULL, 0),
1352e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O00", SND_SOC_NOPM, 0, 0,
1353e1991d10SAlexandre Mergnat 			   mt8365_afe_o00_mix, ARRAY_SIZE(mt8365_afe_o00_mix)),
1354e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O01", SND_SOC_NOPM, 0, 0,
1355e1991d10SAlexandre Mergnat 			   mt8365_afe_o01_mix, ARRAY_SIZE(mt8365_afe_o01_mix)),
1356e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O03", SND_SOC_NOPM, 0, 0,
1357e1991d10SAlexandre Mergnat 			   mt8365_afe_o03_mix, ARRAY_SIZE(mt8365_afe_o03_mix)),
1358e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O04", SND_SOC_NOPM, 0, 0,
1359e1991d10SAlexandre Mergnat 			   mt8365_afe_o04_mix, ARRAY_SIZE(mt8365_afe_o04_mix)),
1360e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O05", SND_SOC_NOPM, 0, 0,
1361e1991d10SAlexandre Mergnat 			   mt8365_afe_o05_mix, ARRAY_SIZE(mt8365_afe_o05_mix)),
1362e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O06", SND_SOC_NOPM, 0, 0,
1363e1991d10SAlexandre Mergnat 			   mt8365_afe_o06_mix, ARRAY_SIZE(mt8365_afe_o06_mix)),
1364e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O07", SND_SOC_NOPM, 0, 0,
1365e1991d10SAlexandre Mergnat 			   mt8365_afe_o07_mix, ARRAY_SIZE(mt8365_afe_o07_mix)),
1366e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O08", SND_SOC_NOPM, 0, 0,
1367e1991d10SAlexandre Mergnat 			   mt8365_afe_o08_mix, ARRAY_SIZE(mt8365_afe_o08_mix)),
1368e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O09", SND_SOC_NOPM, 0, 0,
1369e1991d10SAlexandre Mergnat 			   mt8365_afe_o09_mix, ARRAY_SIZE(mt8365_afe_o09_mix)),
1370e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O10", SND_SOC_NOPM, 0, 0,
1371e1991d10SAlexandre Mergnat 			   mt8365_afe_o10_mix, ARRAY_SIZE(mt8365_afe_o10_mix)),
1372e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O11", SND_SOC_NOPM, 0, 0,
1373e1991d10SAlexandre Mergnat 			   mt8365_afe_o11_mix, ARRAY_SIZE(mt8365_afe_o11_mix)),
1374e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O12", SND_SOC_NOPM, 0, 0,
1375e1991d10SAlexandre Mergnat 			   mt8365_afe_o12_mix, ARRAY_SIZE(mt8365_afe_o12_mix)),
1376e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O13", SND_SOC_NOPM, 0, 0,
1377e1991d10SAlexandre Mergnat 			   mt8365_afe_o13_mix, ARRAY_SIZE(mt8365_afe_o13_mix)),
1378e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O14", SND_SOC_NOPM, 0, 0,
1379e1991d10SAlexandre Mergnat 			   mt8365_afe_o14_mix, ARRAY_SIZE(mt8365_afe_o14_mix)),
1380e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O15", SND_SOC_NOPM, 0, 0,
1381e1991d10SAlexandre Mergnat 			   mt8365_afe_o15_mix, ARRAY_SIZE(mt8365_afe_o15_mix)),
1382e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O16", SND_SOC_NOPM, 0, 0,
1383e1991d10SAlexandre Mergnat 			   mt8365_afe_o16_mix, ARRAY_SIZE(mt8365_afe_o16_mix)),
1384e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O17", SND_SOC_NOPM, 0, 0,
1385e1991d10SAlexandre Mergnat 			   mt8365_afe_o17_mix, ARRAY_SIZE(mt8365_afe_o17_mix)),
1386e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O18", SND_SOC_NOPM, 0, 0,
1387e1991d10SAlexandre Mergnat 			   mt8365_afe_o18_mix, ARRAY_SIZE(mt8365_afe_o18_mix)),
1388e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O19", SND_SOC_NOPM, 0, 0,
1389e1991d10SAlexandre Mergnat 			   mt8365_afe_o19_mix, ARRAY_SIZE(mt8365_afe_o19_mix)),
1390e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O20", SND_SOC_NOPM, 0, 0,
1391e1991d10SAlexandre Mergnat 			   mt8365_afe_o20_mix, ARRAY_SIZE(mt8365_afe_o20_mix)),
1392e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O21", SND_SOC_NOPM, 0, 0,
1393e1991d10SAlexandre Mergnat 			   mt8365_afe_o21_mix, ARRAY_SIZE(mt8365_afe_o21_mix)),
1394e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O22", SND_SOC_NOPM, 0, 0,
1395e1991d10SAlexandre Mergnat 			   mt8365_afe_o22_mix, ARRAY_SIZE(mt8365_afe_o22_mix)),
1396e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O23", SND_SOC_NOPM, 0, 0,
1397e1991d10SAlexandre Mergnat 			   mt8365_afe_o23_mix, ARRAY_SIZE(mt8365_afe_o23_mix)),
1398e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O24", SND_SOC_NOPM, 0, 0,
1399e1991d10SAlexandre Mergnat 			   mt8365_afe_o24_mix, ARRAY_SIZE(mt8365_afe_o24_mix)),
1400e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O25", SND_SOC_NOPM, 0, 0,
1401e1991d10SAlexandre Mergnat 			   mt8365_afe_o25_mix, ARRAY_SIZE(mt8365_afe_o25_mix)),
1402e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O26", SND_SOC_NOPM, 0, 0,
1403e1991d10SAlexandre Mergnat 			   mt8365_afe_o26_mix, ARRAY_SIZE(mt8365_afe_o26_mix)),
1404e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O27", SND_SOC_NOPM, 0, 0,
1405e1991d10SAlexandre Mergnat 			   mt8365_afe_o27_mix, ARRAY_SIZE(mt8365_afe_o27_mix)),
1406e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O28", SND_SOC_NOPM, 0, 0,
1407e1991d10SAlexandre Mergnat 			   mt8365_afe_o28_mix, ARRAY_SIZE(mt8365_afe_o28_mix)),
1408e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O29", SND_SOC_NOPM, 0, 0,
1409e1991d10SAlexandre Mergnat 			   mt8365_afe_o29_mix, ARRAY_SIZE(mt8365_afe_o29_mix)),
1410e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O30", SND_SOC_NOPM, 0, 0,
1411e1991d10SAlexandre Mergnat 			   mt8365_afe_o30_mix, ARRAY_SIZE(mt8365_afe_o30_mix)),
1412e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O31", SND_SOC_NOPM, 0, 0,
1413e1991d10SAlexandre Mergnat 			   mt8365_afe_o31_mix, ARRAY_SIZE(mt8365_afe_o31_mix)),
1414e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O32", SND_SOC_NOPM, 0, 0,
1415e1991d10SAlexandre Mergnat 			   mt8365_afe_o32_mix, ARRAY_SIZE(mt8365_afe_o32_mix)),
1416e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O33", SND_SOC_NOPM, 0, 0,
1417e1991d10SAlexandre Mergnat 			   mt8365_afe_o33_mix, ARRAY_SIZE(mt8365_afe_o33_mix)),
1418e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O34", SND_SOC_NOPM, 0, 0,
1419e1991d10SAlexandre Mergnat 			   mt8365_afe_o34_mix, ARRAY_SIZE(mt8365_afe_o34_mix)),
1420e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O35", SND_SOC_NOPM, 0, 0,
1421e1991d10SAlexandre Mergnat 			   mt8365_afe_o35_mix, ARRAY_SIZE(mt8365_afe_o35_mix)),
1422e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O36", SND_SOC_NOPM, 0, 0,
1423e1991d10SAlexandre Mergnat 			   mt8365_afe_o36_mix, ARRAY_SIZE(mt8365_afe_o36_mix)),
1424e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("CM2_Mux IO", SND_SOC_NOPM, 0, 0, NULL, 0),
1425e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("CM1_IO", SND_SOC_NOPM, 0, 0, NULL, 0),
1426e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("O17O18", SND_SOC_NOPM, 0, 0, NULL, 0),
1427e1991d10SAlexandre Mergnat 	/* inter-connections */
1428e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("HW_GAIN1_IN_CH1", SND_SOC_NOPM, 0, 0,
1429e1991d10SAlexandre Mergnat 			   mtk_hw_gain1_in_ch1_mix,
1430e1991d10SAlexandre Mergnat 			   ARRAY_SIZE(mtk_hw_gain1_in_ch1_mix)),
1431e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MIXER("HW_GAIN1_IN_CH2", SND_SOC_NOPM, 0, 0,
1432e1991d10SAlexandre Mergnat 			   mtk_hw_gain1_in_ch2_mix,
1433e1991d10SAlexandre Mergnat 			   ARRAY_SIZE(mtk_hw_gain1_in_ch2_mix)),
1434e1991d10SAlexandre Mergnat 
1435e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_INPUT("DL Source"),
1436e1991d10SAlexandre Mergnat 
1437e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MUX("CM2_Mux_IO Input Mux", SND_SOC_NOPM, 0, 0,
1438e1991d10SAlexandre Mergnat 			 &mt8365_afe_cm2_mux_input_mux),
1439e1991d10SAlexandre Mergnat 
1440e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MUX("AIN Mux", SND_SOC_NOPM, 0, 0, &ain_mux),
1441e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MUX("VUL2 Input Mux", SND_SOC_NOPM, 0, 0,
1442e1991d10SAlexandre Mergnat 			 &vul2_in_input_mux),
1443e1991d10SAlexandre Mergnat 
1444e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_MUX("FM HW Gain Mux", SND_SOC_NOPM, 0, 0, &fmhwgain_mux),
1445e1991d10SAlexandre Mergnat 
1446e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_INPUT("HW Gain 1 Out Endpoint"),
1447e1991d10SAlexandre Mergnat 	SND_SOC_DAPM_OUTPUT("HW Gain 1 In Endpoint"),
1448e1991d10SAlexandre Mergnat };
1449e1991d10SAlexandre Mergnat 
1450e1991d10SAlexandre Mergnat static const struct snd_soc_dapm_route mt8365_memif_routes[] = {
1451e1991d10SAlexandre Mergnat 	/* downlink */
1452e1991d10SAlexandre Mergnat 	{"I00", NULL, "2ND I2S Capture"},
1453e1991d10SAlexandre Mergnat 	{"I01", NULL, "2ND I2S Capture"},
1454e1991d10SAlexandre Mergnat 	{"I05", NULL, "DL1"},
1455e1991d10SAlexandre Mergnat 	{"I06", NULL, "DL1"},
1456e1991d10SAlexandre Mergnat 	{"I07", NULL, "DL2"},
1457e1991d10SAlexandre Mergnat 	{"I08", NULL, "DL2"},
1458e1991d10SAlexandre Mergnat 
1459e1991d10SAlexandre Mergnat 	{"O03", "I05 Switch", "I05"},
1460e1991d10SAlexandre Mergnat 	{"O04", "I06 Switch", "I06"},
1461e1991d10SAlexandre Mergnat 	{"O00", "I05 Switch", "I05"},
1462e1991d10SAlexandre Mergnat 	{"O01", "I06 Switch", "I06"},
1463e1991d10SAlexandre Mergnat 	{"O07", "I05 Switch", "I05"},
1464e1991d10SAlexandre Mergnat 	{"O08", "I06 Switch", "I06"},
1465e1991d10SAlexandre Mergnat 	{"O27", "I05 Switch", "I05"},
1466e1991d10SAlexandre Mergnat 	{"O28", "I06 Switch", "I06"},
1467e1991d10SAlexandre Mergnat 	{"O29", "I05 Switch", "I05"},
1468e1991d10SAlexandre Mergnat 	{"O30", "I06 Switch", "I06"},
1469e1991d10SAlexandre Mergnat 
1470e1991d10SAlexandre Mergnat 	{"O03", "I07 Switch", "I07"},
1471e1991d10SAlexandre Mergnat 	{"O04", "I08 Switch", "I08"},
1472e1991d10SAlexandre Mergnat 	{"O00", "I07 Switch", "I07"},
1473e1991d10SAlexandre Mergnat 	{"O01", "I08 Switch", "I08"},
1474e1991d10SAlexandre Mergnat 	{"O07", "I07 Switch", "I07"},
1475e1991d10SAlexandre Mergnat 	{"O08", "I08 Switch", "I08"},
1476e1991d10SAlexandre Mergnat 
1477e1991d10SAlexandre Mergnat 	/* uplink */
1478e1991d10SAlexandre Mergnat 	{"AWB", NULL, "O05"},
1479e1991d10SAlexandre Mergnat 	{"AWB", NULL, "O06"},
1480e1991d10SAlexandre Mergnat 	{"VUL", NULL, "O09"},
1481e1991d10SAlexandre Mergnat 	{"VUL", NULL, "O10"},
1482e1991d10SAlexandre Mergnat 	{"VUL3", NULL, "O11"},
1483e1991d10SAlexandre Mergnat 	{"VUL3", NULL, "O12"},
1484e1991d10SAlexandre Mergnat 
1485e1991d10SAlexandre Mergnat 	{"AIN Mux", "EXT ADC", "I2S Capture"},
1486e1991d10SAlexandre Mergnat 	{"I03", NULL, "AIN Mux"},
1487e1991d10SAlexandre Mergnat 	{"I04", NULL, "AIN Mux"},
1488e1991d10SAlexandre Mergnat 
1489e1991d10SAlexandre Mergnat 	{"HW_GAIN1_IN_CH1", "CONNSYS_I2S_CH1", "Hostless FM DL"},
1490e1991d10SAlexandre Mergnat 	{"HW_GAIN1_IN_CH2", "CONNSYS_I2S_CH2", "Hostless FM DL"},
1491e1991d10SAlexandre Mergnat 
1492e1991d10SAlexandre Mergnat 	{"HW Gain 1 In Endpoint", NULL, "HW Gain 1 In"},
1493e1991d10SAlexandre Mergnat 	{"HW Gain 1 Out", NULL, "HW Gain 1 Out Endpoint"},
1494e1991d10SAlexandre Mergnat 	{"HW Gain 1 In", NULL, "HW_GAIN1_IN_CH1"},
1495e1991d10SAlexandre Mergnat 	{"HW Gain 1 In", NULL, "HW_GAIN1_IN_CH2"},
1496e1991d10SAlexandre Mergnat 
1497e1991d10SAlexandre Mergnat 	{"FM HW Gain Mux", "FM_HW_GAIN_IO", "HW Gain 1 Out"},
1498e1991d10SAlexandre Mergnat 	{"Hostless FM UL", NULL, "FM HW Gain Mux"},
1499e1991d10SAlexandre Mergnat 	{"Hostless FM UL", NULL, "FM 2ND I2S Mux"},
1500e1991d10SAlexandre Mergnat 
1501e1991d10SAlexandre Mergnat 	{"O05", "I05 Switch", "I05L"},
1502e1991d10SAlexandre Mergnat 	{"O06", "I06 Switch", "I06L"},
1503e1991d10SAlexandre Mergnat 	{"O05", "I07 Switch", "I07L"},
1504e1991d10SAlexandre Mergnat 	{"O06", "I08 Switch", "I08L"},
1505e1991d10SAlexandre Mergnat 
1506e1991d10SAlexandre Mergnat 	{"O05", "I03 Switch", "I03"},
1507e1991d10SAlexandre Mergnat 	{"O06", "I04 Switch", "I04"},
1508e1991d10SAlexandre Mergnat 	{"O05", "I00 Switch", "I00"},
1509e1991d10SAlexandre Mergnat 	{"O06", "I01 Switch", "I01"},
1510e1991d10SAlexandre Mergnat 	{"O05", "I09 Switch", "I09"},
1511e1991d10SAlexandre Mergnat 	{"O06", "I22 Switch", "I22"},
1512e1991d10SAlexandre Mergnat 	{"O05", "I14 Switch", "I14"},
1513e1991d10SAlexandre Mergnat 	{"O06", "I15 Switch", "I15"},
1514e1991d10SAlexandre Mergnat 	{"O05", "I16 Switch", "I16"},
1515e1991d10SAlexandre Mergnat 	{"O06", "I17 Switch", "I17"},
1516e1991d10SAlexandre Mergnat 	{"O05", "I18 Switch", "I18"},
1517e1991d10SAlexandre Mergnat 	{"O06", "I19 Switch", "I19"},
1518e1991d10SAlexandre Mergnat 	{"O05", "I20 Switch", "I20"},
1519e1991d10SAlexandre Mergnat 	{"O06", "I21 Switch", "I21"},
1520e1991d10SAlexandre Mergnat 	{"O05", "I23 Switch", "I23"},
1521e1991d10SAlexandre Mergnat 	{"O06", "I24 Switch", "I24"},
1522e1991d10SAlexandre Mergnat 
1523e1991d10SAlexandre Mergnat 	{"O09", "I03 Switch", "I03"},
1524e1991d10SAlexandre Mergnat 	{"O10", "I04 Switch", "I04"},
1525e1991d10SAlexandre Mergnat 	{"O09", "I00 Switch", "I00"},
1526e1991d10SAlexandre Mergnat 	{"O10", "I01 Switch", "I01"},
1527e1991d10SAlexandre Mergnat 	{"O09", "I09 Switch", "I09"},
1528e1991d10SAlexandre Mergnat 	{"O10", "I22 Switch", "I22"},
1529e1991d10SAlexandre Mergnat 	{"O09", "I14 Switch", "I14"},
1530e1991d10SAlexandre Mergnat 	{"O10", "I15 Switch", "I15"},
1531e1991d10SAlexandre Mergnat 	{"O09", "I16 Switch", "I16"},
1532e1991d10SAlexandre Mergnat 	{"O10", "I17 Switch", "I17"},
1533e1991d10SAlexandre Mergnat 	{"O09", "I18 Switch", "I18"},
1534e1991d10SAlexandre Mergnat 	{"O10", "I19 Switch", "I19"},
1535e1991d10SAlexandre Mergnat 	{"O09", "I20 Switch", "I20"},
1536e1991d10SAlexandre Mergnat 	{"O10", "I21 Switch", "I21"},
1537e1991d10SAlexandre Mergnat 
1538e1991d10SAlexandre Mergnat 	{"O11", "I03 Switch", "I03"},
1539e1991d10SAlexandre Mergnat 	{"O12", "I04 Switch", "I04"},
1540e1991d10SAlexandre Mergnat 	{"O11", "I00 Switch", "I00"},
1541e1991d10SAlexandre Mergnat 	{"O12", "I01 Switch", "I01"},
1542e1991d10SAlexandre Mergnat 	{"O11", "I09 Switch", "I09"},
1543e1991d10SAlexandre Mergnat 	{"O12", "I22 Switch", "I22"},
1544e1991d10SAlexandre Mergnat 	{"O11", "I14 Switch", "I14"},
1545e1991d10SAlexandre Mergnat 	{"O12", "I15 Switch", "I15"},
1546e1991d10SAlexandre Mergnat 	{"O11", "I16 Switch", "I16"},
1547e1991d10SAlexandre Mergnat 	{"O12", "I17 Switch", "I17"},
1548e1991d10SAlexandre Mergnat 	{"O11", "I18 Switch", "I18"},
1549e1991d10SAlexandre Mergnat 	{"O12", "I19 Switch", "I19"},
1550e1991d10SAlexandre Mergnat 	{"O11", "I20 Switch", "I20"},
1551e1991d10SAlexandre Mergnat 	{"O12", "I21 Switch", "I21"},
1552e1991d10SAlexandre Mergnat 
1553e1991d10SAlexandre Mergnat 	/* CM2_Mux*/
1554e1991d10SAlexandre Mergnat 	{"CM2_Mux IO", NULL, "CM2_Mux_IO Input Mux"},
1555e1991d10SAlexandre Mergnat 
1556e1991d10SAlexandre Mergnat 	/* VUL2 */
1557e1991d10SAlexandre Mergnat 	{"VUL2", NULL, "VUL2 Input Mux"},
1558e1991d10SAlexandre Mergnat 	{"VUL2 Input Mux", "VUL2_IN_FROM_O17O18", "O17O18"},
1559e1991d10SAlexandre Mergnat 	{"VUL2 Input Mux", "VUL2_IN_FROM_CM1", "CM1_IO"},
1560e1991d10SAlexandre Mergnat 
1561e1991d10SAlexandre Mergnat 	{"O17O18", NULL, "O17"},
1562e1991d10SAlexandre Mergnat 	{"O17O18", NULL, "O18"},
1563e1991d10SAlexandre Mergnat 	{"CM1_IO", NULL, "O17"},
1564e1991d10SAlexandre Mergnat 	{"CM1_IO", NULL, "O18"},
1565e1991d10SAlexandre Mergnat 	{"CM1_IO", NULL, "O19"},
1566e1991d10SAlexandre Mergnat 	{"CM1_IO", NULL, "O20"},
1567e1991d10SAlexandre Mergnat 	{"CM1_IO", NULL, "O21"},
1568e1991d10SAlexandre Mergnat 	{"CM1_IO", NULL, "O22"},
1569e1991d10SAlexandre Mergnat 	{"CM1_IO", NULL, "O23"},
1570e1991d10SAlexandre Mergnat 	{"CM1_IO", NULL, "O24"},
1571e1991d10SAlexandre Mergnat 	{"CM1_IO", NULL, "O25"},
1572e1991d10SAlexandre Mergnat 	{"CM1_IO", NULL, "O26"},
1573e1991d10SAlexandre Mergnat 	{"CM1_IO", NULL, "O31"},
1574e1991d10SAlexandre Mergnat 	{"CM1_IO", NULL, "O32"},
1575e1991d10SAlexandre Mergnat 	{"CM1_IO", NULL, "O33"},
1576e1991d10SAlexandre Mergnat 	{"CM1_IO", NULL, "O34"},
1577e1991d10SAlexandre Mergnat 	{"CM1_IO", NULL, "O35"},
1578e1991d10SAlexandre Mergnat 	{"CM1_IO", NULL, "O36"},
1579e1991d10SAlexandre Mergnat 
1580e1991d10SAlexandre Mergnat 	{"O17", "I14 Switch", "I14"},
1581e1991d10SAlexandre Mergnat 	{"O18", "I15 Switch", "I15"},
1582e1991d10SAlexandre Mergnat 	{"O19", "I16 Switch", "I16"},
1583e1991d10SAlexandre Mergnat 	{"O20", "I17 Switch", "I17"},
1584e1991d10SAlexandre Mergnat 	{"O21", "I18 Switch", "I18"},
1585e1991d10SAlexandre Mergnat 	{"O22", "I19 Switch", "I19"},
1586e1991d10SAlexandre Mergnat 	{"O23", "I20 Switch", "I20"},
1587e1991d10SAlexandre Mergnat 	{"O24", "I21 Switch", "I21"},
1588e1991d10SAlexandre Mergnat 	{"O25", "I23 Switch", "I23"},
1589e1991d10SAlexandre Mergnat 	{"O26", "I24 Switch", "I24"},
1590e1991d10SAlexandre Mergnat 	{"O25", "I25 Switch", "I25"},
1591e1991d10SAlexandre Mergnat 	{"O26", "I26 Switch", "I26"},
1592e1991d10SAlexandre Mergnat 
1593e1991d10SAlexandre Mergnat 	{"O17", "I03 Switch", "I03"},
1594e1991d10SAlexandre Mergnat 	{"O18", "I04 Switch", "I04"},
1595e1991d10SAlexandre Mergnat 	{"O18", "I23 Switch", "I23"},
1596e1991d10SAlexandre Mergnat 	{"O18", "I25 Switch", "I25"},
1597e1991d10SAlexandre Mergnat 	{"O19", "I04 Switch", "I04"},
1598e1991d10SAlexandre Mergnat 	{"O19", "I23 Switch", "I23"},
1599e1991d10SAlexandre Mergnat 	{"O19", "I24 Switch", "I24"},
1600e1991d10SAlexandre Mergnat 	{"O19", "I25 Switch", "I25"},
1601e1991d10SAlexandre Mergnat 	{"O19", "I26 Switch", "I26"},
1602e1991d10SAlexandre Mergnat 	{"O20", "I24 Switch", "I24"},
1603e1991d10SAlexandre Mergnat 	{"O20", "I26 Switch", "I26"},
1604e1991d10SAlexandre Mergnat 	{"O21", "I23 Switch", "I23"},
1605e1991d10SAlexandre Mergnat 	{"O21", "I25 Switch", "I25"},
1606e1991d10SAlexandre Mergnat 	{"O22", "I24 Switch", "I24"},
1607e1991d10SAlexandre Mergnat 	{"O22", "I26 Switch", "I26"},
1608e1991d10SAlexandre Mergnat 
1609e1991d10SAlexandre Mergnat 	{"O23", "I23 Switch", "I23"},
1610e1991d10SAlexandre Mergnat 	{"O23", "I25 Switch", "I25"},
1611e1991d10SAlexandre Mergnat 	{"O24", "I24 Switch", "I24"},
1612e1991d10SAlexandre Mergnat 	{"O24", "I26 Switch", "I26"},
1613e1991d10SAlexandre Mergnat 	{"O24", "I23 Switch", "I23"},
1614e1991d10SAlexandre Mergnat 	{"O24", "I25 Switch", "I25"},
1615e1991d10SAlexandre Mergnat 	{"O13", "I00 Switch", "I00"},
1616e1991d10SAlexandre Mergnat 	{"O14", "I01 Switch", "I01"},
1617e1991d10SAlexandre Mergnat 	{"O03", "I10 Switch", "I10"},
1618e1991d10SAlexandre Mergnat 	{"O04", "I11 Switch", "I11"},
1619e1991d10SAlexandre Mergnat };
1620e1991d10SAlexandre Mergnat 
1621e1991d10SAlexandre Mergnat static const struct mtk_base_memif_data memif_data[MT8365_AFE_MEMIF_NUM] = {
1622e1991d10SAlexandre Mergnat 	{
1623e1991d10SAlexandre Mergnat 		.name = "DL1",
1624e1991d10SAlexandre Mergnat 		.id = MT8365_AFE_MEMIF_DL1,
1625e1991d10SAlexandre Mergnat 		.reg_ofs_base = AFE_DL1_BASE,
1626e1991d10SAlexandre Mergnat 		.reg_ofs_cur = AFE_DL1_CUR,
1627e1991d10SAlexandre Mergnat 		.fs_reg = AFE_DAC_CON1,
1628e1991d10SAlexandre Mergnat 		.fs_shift = 0,
1629e1991d10SAlexandre Mergnat 		.fs_maskbit = 0xf,
1630e1991d10SAlexandre Mergnat 		.mono_reg = AFE_DAC_CON1,
1631e1991d10SAlexandre Mergnat 		.mono_shift = 21,
1632e1991d10SAlexandre Mergnat 		.hd_reg = AFE_MEMIF_PBUF_SIZE,
1633e1991d10SAlexandre Mergnat 		.hd_shift = 16,
1634e1991d10SAlexandre Mergnat 		.enable_reg = AFE_DAC_CON0,
1635e1991d10SAlexandre Mergnat 		.enable_shift = 1,
1636e1991d10SAlexandre Mergnat 		.msb_reg = -1,
1637e1991d10SAlexandre Mergnat 		.msb_shift = -1,
1638e1991d10SAlexandre Mergnat 		.agent_disable_reg = -1,
1639e1991d10SAlexandre Mergnat 		.agent_disable_shift = -1,
1640e1991d10SAlexandre Mergnat 	}, {
1641e1991d10SAlexandre Mergnat 		.name = "DL2",
1642e1991d10SAlexandre Mergnat 		.id = MT8365_AFE_MEMIF_DL2,
1643e1991d10SAlexandre Mergnat 		.reg_ofs_base = AFE_DL2_BASE,
1644e1991d10SAlexandre Mergnat 		.reg_ofs_cur = AFE_DL2_CUR,
1645e1991d10SAlexandre Mergnat 		.fs_reg = AFE_DAC_CON1,
1646e1991d10SAlexandre Mergnat 		.fs_shift = 4,
1647e1991d10SAlexandre Mergnat 		.fs_maskbit = 0xf,
1648e1991d10SAlexandre Mergnat 		.mono_reg = AFE_DAC_CON1,
1649e1991d10SAlexandre Mergnat 		.mono_shift = 22,
1650e1991d10SAlexandre Mergnat 		.hd_reg = AFE_MEMIF_PBUF_SIZE,
1651e1991d10SAlexandre Mergnat 		.hd_shift = 18,
1652e1991d10SAlexandre Mergnat 		.enable_reg = AFE_DAC_CON0,
1653e1991d10SAlexandre Mergnat 		.enable_shift = 2,
1654e1991d10SAlexandre Mergnat 		.msb_reg = -1,
1655e1991d10SAlexandre Mergnat 		.msb_shift = -1,
1656e1991d10SAlexandre Mergnat 		.agent_disable_reg = -1,
1657e1991d10SAlexandre Mergnat 		.agent_disable_shift = -1,
1658e1991d10SAlexandre Mergnat 	}, {
1659e1991d10SAlexandre Mergnat 		.name = "TDM OUT",
1660e1991d10SAlexandre Mergnat 		.id = MT8365_AFE_MEMIF_TDM_OUT,
1661e1991d10SAlexandre Mergnat 		.reg_ofs_base = AFE_HDMI_OUT_BASE,
1662e1991d10SAlexandre Mergnat 		.reg_ofs_cur = AFE_HDMI_OUT_CUR,
1663e1991d10SAlexandre Mergnat 		.fs_reg = -1,
1664e1991d10SAlexandre Mergnat 		.fs_shift = -1,
1665e1991d10SAlexandre Mergnat 		.fs_maskbit = -1,
1666e1991d10SAlexandre Mergnat 		.mono_reg = -1,
1667e1991d10SAlexandre Mergnat 		.mono_shift = -1,
1668e1991d10SAlexandre Mergnat 		.hd_reg = AFE_MEMIF_PBUF_SIZE,
1669e1991d10SAlexandre Mergnat 		.hd_shift = 28,
1670e1991d10SAlexandre Mergnat 		.enable_reg = AFE_HDMI_OUT_CON0,
1671e1991d10SAlexandre Mergnat 		.enable_shift = 0,
1672e1991d10SAlexandre Mergnat 		.msb_reg = -1,
1673e1991d10SAlexandre Mergnat 		.msb_shift = -1,
1674e1991d10SAlexandre Mergnat 		.agent_disable_reg = -1,
1675e1991d10SAlexandre Mergnat 		.agent_disable_shift = -1,
1676e1991d10SAlexandre Mergnat 	}, {
1677e1991d10SAlexandre Mergnat 		.name = "AWB",
1678e1991d10SAlexandre Mergnat 		.id = MT8365_AFE_MEMIF_AWB,
1679e1991d10SAlexandre Mergnat 		.reg_ofs_base = AFE_AWB_BASE,
1680e1991d10SAlexandre Mergnat 		.reg_ofs_cur = AFE_AWB_CUR,
1681e1991d10SAlexandre Mergnat 		.fs_reg = AFE_DAC_CON1,
1682e1991d10SAlexandre Mergnat 		.fs_shift = 12,
1683e1991d10SAlexandre Mergnat 		.fs_maskbit = 0xf,
1684e1991d10SAlexandre Mergnat 		.mono_reg = AFE_DAC_CON1,
1685e1991d10SAlexandre Mergnat 		.mono_shift = 24,
1686e1991d10SAlexandre Mergnat 		.hd_reg = AFE_MEMIF_PBUF_SIZE,
1687e1991d10SAlexandre Mergnat 		.hd_shift = 20,
1688e1991d10SAlexandre Mergnat 		.enable_reg = AFE_DAC_CON0,
1689e1991d10SAlexandre Mergnat 		.enable_shift = 6,
1690e1991d10SAlexandre Mergnat 		.msb_reg = AFE_MEMIF_MSB,
1691e1991d10SAlexandre Mergnat 		.msb_shift = 17,
1692e1991d10SAlexandre Mergnat 		.agent_disable_reg = -1,
1693e1991d10SAlexandre Mergnat 		.agent_disable_shift = -1,
1694e1991d10SAlexandre Mergnat 	}, {
1695e1991d10SAlexandre Mergnat 		.name = "VUL",
1696e1991d10SAlexandre Mergnat 		.id = MT8365_AFE_MEMIF_VUL,
1697e1991d10SAlexandre Mergnat 		.reg_ofs_base = AFE_VUL_BASE,
1698e1991d10SAlexandre Mergnat 		.reg_ofs_cur = AFE_VUL_CUR,
1699e1991d10SAlexandre Mergnat 		.fs_reg = AFE_DAC_CON1,
1700e1991d10SAlexandre Mergnat 		.fs_shift = 16,
1701e1991d10SAlexandre Mergnat 		.fs_maskbit = 0xf,
1702e1991d10SAlexandre Mergnat 		.mono_reg = AFE_DAC_CON1,
1703e1991d10SAlexandre Mergnat 		.mono_shift = 27,
1704e1991d10SAlexandre Mergnat 		.hd_reg = AFE_MEMIF_PBUF_SIZE,
1705e1991d10SAlexandre Mergnat 		.hd_shift = 22,
1706e1991d10SAlexandre Mergnat 		.enable_reg = AFE_DAC_CON0,
1707e1991d10SAlexandre Mergnat 		.enable_shift = 3,
1708e1991d10SAlexandre Mergnat 		.msb_reg = AFE_MEMIF_MSB,
1709e1991d10SAlexandre Mergnat 		.msb_shift = 20,
1710e1991d10SAlexandre Mergnat 		.agent_disable_reg = -1,
1711e1991d10SAlexandre Mergnat 		.agent_disable_shift = -1,
1712e1991d10SAlexandre Mergnat 	}, {
1713e1991d10SAlexandre Mergnat 		.name = "VUL2",
1714e1991d10SAlexandre Mergnat 		.id = MT8365_AFE_MEMIF_VUL2,
1715e1991d10SAlexandre Mergnat 		.reg_ofs_base = AFE_VUL_D2_BASE,
1716e1991d10SAlexandre Mergnat 		.reg_ofs_cur = AFE_VUL_D2_CUR,
1717e1991d10SAlexandre Mergnat 		.fs_reg = AFE_DAC_CON0,
1718e1991d10SAlexandre Mergnat 		.fs_shift = 20,
1719e1991d10SAlexandre Mergnat 		.fs_maskbit = 0xf,
1720e1991d10SAlexandre Mergnat 		.mono_reg = -1,
1721e1991d10SAlexandre Mergnat 		.mono_shift = -1,
1722e1991d10SAlexandre Mergnat 		.hd_reg = AFE_MEMIF_PBUF_SIZE,
1723e1991d10SAlexandre Mergnat 		.hd_shift = 14,
1724e1991d10SAlexandre Mergnat 		.enable_reg = AFE_DAC_CON0,
1725e1991d10SAlexandre Mergnat 		.enable_shift = 9,
1726e1991d10SAlexandre Mergnat 		.msb_reg = AFE_MEMIF_MSB,
1727e1991d10SAlexandre Mergnat 		.msb_shift = 21,
1728e1991d10SAlexandre Mergnat 		.agent_disable_reg = -1,
1729e1991d10SAlexandre Mergnat 		.agent_disable_shift = -1,
1730e1991d10SAlexandre Mergnat 	}, {
1731e1991d10SAlexandre Mergnat 		.name = "VUL3",
1732e1991d10SAlexandre Mergnat 		.id = MT8365_AFE_MEMIF_VUL3,
1733e1991d10SAlexandre Mergnat 		.reg_ofs_base = AFE_VUL3_BASE,
1734e1991d10SAlexandre Mergnat 		.reg_ofs_cur = AFE_VUL3_CUR,
1735e1991d10SAlexandre Mergnat 		.fs_reg = AFE_DAC_CON1,
1736e1991d10SAlexandre Mergnat 		.fs_shift = 8,
1737e1991d10SAlexandre Mergnat 		.fs_maskbit = 0xf,
1738e1991d10SAlexandre Mergnat 		.mono_reg = AFE_DAC_CON0,
1739e1991d10SAlexandre Mergnat 		.mono_shift = 13,
1740e1991d10SAlexandre Mergnat 		.hd_reg = AFE_MEMIF_PBUF2_SIZE,
1741e1991d10SAlexandre Mergnat 		.hd_shift = 10,
1742e1991d10SAlexandre Mergnat 		.enable_reg = AFE_DAC_CON0,
1743e1991d10SAlexandre Mergnat 		.enable_shift = 12,
1744e1991d10SAlexandre Mergnat 		.msb_reg = AFE_MEMIF_MSB,
1745e1991d10SAlexandre Mergnat 		.msb_shift = 27,
1746e1991d10SAlexandre Mergnat 		.agent_disable_reg = -1,
1747e1991d10SAlexandre Mergnat 		.agent_disable_shift = -1,
1748e1991d10SAlexandre Mergnat 	}, {
1749e1991d10SAlexandre Mergnat 		.name = "TDM IN",
1750e1991d10SAlexandre Mergnat 		.id = MT8365_AFE_MEMIF_TDM_IN,
1751e1991d10SAlexandre Mergnat 		.reg_ofs_base = AFE_HDMI_IN_2CH_BASE,
1752e1991d10SAlexandre Mergnat 		.reg_ofs_cur = AFE_HDMI_IN_2CH_CUR,
1753e1991d10SAlexandre Mergnat 		.fs_reg = -1,
1754e1991d10SAlexandre Mergnat 		.fs_shift = -1,
1755e1991d10SAlexandre Mergnat 		.fs_maskbit = -1,
1756e1991d10SAlexandre Mergnat 		.mono_reg = AFE_HDMI_IN_2CH_CON0,
1757e1991d10SAlexandre Mergnat 		.mono_shift = 1,
1758e1991d10SAlexandre Mergnat 		.hd_reg = AFE_MEMIF_PBUF2_SIZE,
1759e1991d10SAlexandre Mergnat 		.hd_shift = 8,
1760e1991d10SAlexandre Mergnat 		.hd_align_mshift = 5,
1761e1991d10SAlexandre Mergnat 		.enable_reg = AFE_HDMI_IN_2CH_CON0,
1762e1991d10SAlexandre Mergnat 		.enable_shift = 0,
1763e1991d10SAlexandre Mergnat 		.msb_reg = AFE_MEMIF_MSB,
1764e1991d10SAlexandre Mergnat 		.msb_shift = 28,
1765e1991d10SAlexandre Mergnat 		.agent_disable_reg = -1,
1766e1991d10SAlexandre Mergnat 		.agent_disable_shift = -1,
1767e1991d10SAlexandre Mergnat 	},
1768e1991d10SAlexandre Mergnat };
1769e1991d10SAlexandre Mergnat 
1770e1991d10SAlexandre Mergnat static const struct mtk_base_irq_data irq_data[MT8365_AFE_IRQ_NUM] = {
1771e1991d10SAlexandre Mergnat 	{
1772e1991d10SAlexandre Mergnat 		.id = MT8365_AFE_IRQ1,
1773e1991d10SAlexandre Mergnat 		.irq_cnt_reg = AFE_IRQ_MCU_CNT1,
1774e1991d10SAlexandre Mergnat 		.irq_cnt_shift = 0,
1775e1991d10SAlexandre Mergnat 		.irq_cnt_maskbit = 0x3ffff,
1776e1991d10SAlexandre Mergnat 		.irq_en_reg = AFE_IRQ_MCU_CON,
1777e1991d10SAlexandre Mergnat 		.irq_en_shift = 0,
1778e1991d10SAlexandre Mergnat 		.irq_fs_reg = AFE_IRQ_MCU_CON,
1779e1991d10SAlexandre Mergnat 		.irq_fs_shift = 4,
1780e1991d10SAlexandre Mergnat 		.irq_fs_maskbit = 0xf,
1781e1991d10SAlexandre Mergnat 		.irq_clr_reg = AFE_IRQ_MCU_CLR,
1782e1991d10SAlexandre Mergnat 		.irq_clr_shift = 0,
1783e1991d10SAlexandre Mergnat 	}, {
1784e1991d10SAlexandre Mergnat 		.id = MT8365_AFE_IRQ2,
1785e1991d10SAlexandre Mergnat 		.irq_cnt_reg = AFE_IRQ_MCU_CNT2,
1786e1991d10SAlexandre Mergnat 		.irq_cnt_shift = 0,
1787e1991d10SAlexandre Mergnat 		.irq_cnt_maskbit = 0x3ffff,
1788e1991d10SAlexandre Mergnat 		.irq_en_reg = AFE_IRQ_MCU_CON,
1789e1991d10SAlexandre Mergnat 		.irq_en_shift = 1,
1790e1991d10SAlexandre Mergnat 		.irq_fs_reg = AFE_IRQ_MCU_CON,
1791e1991d10SAlexandre Mergnat 		.irq_fs_shift = 8,
1792e1991d10SAlexandre Mergnat 		.irq_fs_maskbit = 0xf,
1793e1991d10SAlexandre Mergnat 		.irq_clr_reg = AFE_IRQ_MCU_CLR,
1794e1991d10SAlexandre Mergnat 		.irq_clr_shift = 1,
1795e1991d10SAlexandre Mergnat 	}, {
1796e1991d10SAlexandre Mergnat 		.id = MT8365_AFE_IRQ3,
1797e1991d10SAlexandre Mergnat 		.irq_cnt_reg = AFE_IRQ_MCU_CNT3,
1798e1991d10SAlexandre Mergnat 		.irq_cnt_shift = 0,
1799e1991d10SAlexandre Mergnat 		.irq_cnt_maskbit = 0x3ffff,
1800e1991d10SAlexandre Mergnat 		.irq_en_reg = AFE_IRQ_MCU_CON,
1801e1991d10SAlexandre Mergnat 		.irq_en_shift = 2,
1802e1991d10SAlexandre Mergnat 		.irq_fs_reg = AFE_IRQ_MCU_CON,
1803e1991d10SAlexandre Mergnat 		.irq_fs_shift = 16,
1804e1991d10SAlexandre Mergnat 		.irq_fs_maskbit = 0xf,
1805e1991d10SAlexandre Mergnat 		.irq_clr_reg = AFE_IRQ_MCU_CLR,
1806e1991d10SAlexandre Mergnat 		.irq_clr_shift = 2,
1807e1991d10SAlexandre Mergnat 	}, {
1808e1991d10SAlexandre Mergnat 		.id = MT8365_AFE_IRQ4,
1809e1991d10SAlexandre Mergnat 		.irq_cnt_reg = AFE_IRQ_MCU_CNT4,
1810e1991d10SAlexandre Mergnat 		.irq_cnt_shift = 0,
1811e1991d10SAlexandre Mergnat 		.irq_cnt_maskbit = 0x3ffff,
1812e1991d10SAlexandre Mergnat 		.irq_en_reg = AFE_IRQ_MCU_CON,
1813e1991d10SAlexandre Mergnat 		.irq_en_shift = 3,
1814e1991d10SAlexandre Mergnat 		.irq_fs_reg = AFE_IRQ_MCU_CON,
1815e1991d10SAlexandre Mergnat 		.irq_fs_shift = 20,
1816e1991d10SAlexandre Mergnat 		.irq_fs_maskbit = 0xf,
1817e1991d10SAlexandre Mergnat 		.irq_clr_reg = AFE_IRQ_MCU_CLR,
1818e1991d10SAlexandre Mergnat 		.irq_clr_shift = 3,
1819e1991d10SAlexandre Mergnat 	}, {
1820e1991d10SAlexandre Mergnat 		.id = MT8365_AFE_IRQ5,
1821e1991d10SAlexandre Mergnat 		.irq_cnt_reg = AFE_IRQ_MCU_CNT5,
1822e1991d10SAlexandre Mergnat 		.irq_cnt_shift = 0,
1823e1991d10SAlexandre Mergnat 		.irq_cnt_maskbit = 0x3ffff,
1824e1991d10SAlexandre Mergnat 		.irq_en_reg = AFE_IRQ_MCU_CON2,
1825e1991d10SAlexandre Mergnat 		.irq_en_shift = 3,
1826e1991d10SAlexandre Mergnat 		.irq_fs_reg = -1,
1827e1991d10SAlexandre Mergnat 		.irq_fs_shift = 0,
1828e1991d10SAlexandre Mergnat 		.irq_fs_maskbit = 0x0,
1829e1991d10SAlexandre Mergnat 		.irq_clr_reg = AFE_IRQ_MCU_CLR,
1830e1991d10SAlexandre Mergnat 		.irq_clr_shift = 4,
1831e1991d10SAlexandre Mergnat 	}, {
1832e1991d10SAlexandre Mergnat 		.id = MT8365_AFE_IRQ6,
1833e1991d10SAlexandre Mergnat 		.irq_cnt_reg = -1,
1834e1991d10SAlexandre Mergnat 		.irq_cnt_shift = 0,
1835e1991d10SAlexandre Mergnat 		.irq_cnt_maskbit = 0x0,
1836e1991d10SAlexandre Mergnat 		.irq_en_reg = AFE_IRQ_MCU_CON,
1837e1991d10SAlexandre Mergnat 		.irq_en_shift = 13,
1838e1991d10SAlexandre Mergnat 		.irq_fs_reg = -1,
1839e1991d10SAlexandre Mergnat 		.irq_fs_shift = 0,
1840e1991d10SAlexandre Mergnat 		.irq_fs_maskbit = 0x0,
1841e1991d10SAlexandre Mergnat 		.irq_clr_reg = AFE_IRQ_MCU_CLR,
1842e1991d10SAlexandre Mergnat 		.irq_clr_shift = 5,
1843e1991d10SAlexandre Mergnat 	}, {
1844e1991d10SAlexandre Mergnat 		.id = MT8365_AFE_IRQ7,
1845e1991d10SAlexandre Mergnat 		.irq_cnt_reg = AFE_IRQ_MCU_CNT7,
1846e1991d10SAlexandre Mergnat 		.irq_cnt_shift = 0,
1847e1991d10SAlexandre Mergnat 		.irq_cnt_maskbit = 0x3ffff,
1848e1991d10SAlexandre Mergnat 		.irq_en_reg = AFE_IRQ_MCU_CON,
1849e1991d10SAlexandre Mergnat 		.irq_en_shift = 14,
1850e1991d10SAlexandre Mergnat 		.irq_fs_reg = AFE_IRQ_MCU_CON,
1851e1991d10SAlexandre Mergnat 		.irq_fs_shift = 24,
1852e1991d10SAlexandre Mergnat 		.irq_fs_maskbit = 0xf,
1853e1991d10SAlexandre Mergnat 		.irq_clr_reg = AFE_IRQ_MCU_CLR,
1854e1991d10SAlexandre Mergnat 		.irq_clr_shift = 6,
1855e1991d10SAlexandre Mergnat 	}, {
1856e1991d10SAlexandre Mergnat 		.id = MT8365_AFE_IRQ8,
1857e1991d10SAlexandre Mergnat 		.irq_cnt_reg = AFE_IRQ_MCU_CNT8,
1858e1991d10SAlexandre Mergnat 		.irq_cnt_shift = 0,
1859e1991d10SAlexandre Mergnat 		.irq_cnt_maskbit = 0x3ffff,
1860e1991d10SAlexandre Mergnat 		.irq_en_reg = AFE_IRQ_MCU_CON,
1861e1991d10SAlexandre Mergnat 		.irq_en_shift = 15,
1862e1991d10SAlexandre Mergnat 		.irq_fs_reg = AFE_IRQ_MCU_CON,
1863e1991d10SAlexandre Mergnat 		.irq_fs_shift = 28,
1864e1991d10SAlexandre Mergnat 		.irq_fs_maskbit = 0xf,
1865e1991d10SAlexandre Mergnat 		.irq_clr_reg = AFE_IRQ_MCU_CLR,
1866e1991d10SAlexandre Mergnat 		.irq_clr_shift = 7,
1867e1991d10SAlexandre Mergnat 	}, {
1868e1991d10SAlexandre Mergnat 		.id = MT8365_AFE_IRQ9,
1869e1991d10SAlexandre Mergnat 		.irq_cnt_reg = -1,
1870e1991d10SAlexandre Mergnat 		.irq_cnt_shift = 0,
1871e1991d10SAlexandre Mergnat 		.irq_cnt_maskbit = 0x0,
1872e1991d10SAlexandre Mergnat 		.irq_en_reg = AFE_IRQ_MCU_CON2,
1873e1991d10SAlexandre Mergnat 		.irq_en_shift = 2,
1874e1991d10SAlexandre Mergnat 		.irq_fs_reg = -1,
1875e1991d10SAlexandre Mergnat 		.irq_fs_shift = 0,
1876e1991d10SAlexandre Mergnat 		.irq_fs_maskbit = 0x0,
1877e1991d10SAlexandre Mergnat 		.irq_clr_reg = AFE_IRQ_MCU_CLR,
1878e1991d10SAlexandre Mergnat 		.irq_clr_shift = 8,
1879e1991d10SAlexandre Mergnat 	}, {
1880e1991d10SAlexandre Mergnat 		.id = MT8365_AFE_IRQ10,
1881e1991d10SAlexandre Mergnat 		.irq_cnt_reg = AFE_IRQ_MCU_CNT10,
1882e1991d10SAlexandre Mergnat 		.irq_cnt_shift = 0,
1883e1991d10SAlexandre Mergnat 		.irq_cnt_maskbit = 0x3ffff,
1884e1991d10SAlexandre Mergnat 		.irq_en_reg = AFE_IRQ_MCU_CON2,
1885e1991d10SAlexandre Mergnat 		.irq_en_shift = 4,
1886e1991d10SAlexandre Mergnat 		.irq_fs_reg = -1,
1887e1991d10SAlexandre Mergnat 		.irq_fs_shift = 0,
1888e1991d10SAlexandre Mergnat 		.irq_fs_maskbit = 0x0,
1889e1991d10SAlexandre Mergnat 		.irq_clr_reg = AFE_IRQ_MCU_CLR,
1890e1991d10SAlexandre Mergnat 		.irq_clr_shift = 9,
1891e1991d10SAlexandre Mergnat 	},
1892e1991d10SAlexandre Mergnat };
1893e1991d10SAlexandre Mergnat 
1894e1991d10SAlexandre Mergnat static int memif_specified_irqs[MT8365_AFE_MEMIF_NUM] = {
1895e1991d10SAlexandre Mergnat 	[MT8365_AFE_MEMIF_DL1] = MT8365_AFE_IRQ1,
1896e1991d10SAlexandre Mergnat 	[MT8365_AFE_MEMIF_DL2] = MT8365_AFE_IRQ2,
1897e1991d10SAlexandre Mergnat 	[MT8365_AFE_MEMIF_TDM_OUT] = MT8365_AFE_IRQ5,
1898e1991d10SAlexandre Mergnat 	[MT8365_AFE_MEMIF_AWB] = MT8365_AFE_IRQ3,
1899e1991d10SAlexandre Mergnat 	[MT8365_AFE_MEMIF_VUL] = MT8365_AFE_IRQ4,
1900e1991d10SAlexandre Mergnat 	[MT8365_AFE_MEMIF_VUL2] = MT8365_AFE_IRQ7,
1901e1991d10SAlexandre Mergnat 	[MT8365_AFE_MEMIF_VUL3] = MT8365_AFE_IRQ8,
1902e1991d10SAlexandre Mergnat 	[MT8365_AFE_MEMIF_TDM_IN] = MT8365_AFE_IRQ10,
1903e1991d10SAlexandre Mergnat };
1904e1991d10SAlexandre Mergnat 
1905e1991d10SAlexandre Mergnat static const struct regmap_config mt8365_afe_regmap_config = {
1906e1991d10SAlexandre Mergnat 	.reg_bits = 32,
1907e1991d10SAlexandre Mergnat 	.reg_stride = 4,
1908e1991d10SAlexandre Mergnat 	.val_bits = 32,
1909e1991d10SAlexandre Mergnat 	.max_register = MAX_REGISTER,
1910e1991d10SAlexandre Mergnat 	.cache_type = REGCACHE_NONE,
1911e1991d10SAlexandre Mergnat };
1912e1991d10SAlexandre Mergnat 
mt8365_afe_irq_handler(int irq,void * dev_id)1913e1991d10SAlexandre Mergnat static irqreturn_t mt8365_afe_irq_handler(int irq, void *dev_id)
1914e1991d10SAlexandre Mergnat {
1915e1991d10SAlexandre Mergnat 	struct mtk_base_afe *afe = dev_id;
1916e1991d10SAlexandre Mergnat 	unsigned int reg_value;
1917e1991d10SAlexandre Mergnat 	unsigned int mcu_irq_mask;
1918e1991d10SAlexandre Mergnat 	int i, ret;
1919e1991d10SAlexandre Mergnat 
1920e1991d10SAlexandre Mergnat 	ret = regmap_read(afe->regmap, AFE_IRQ_MCU_STATUS, &reg_value);
1921e1991d10SAlexandre Mergnat 	if (ret) {
1922e1991d10SAlexandre Mergnat 		dev_err_ratelimited(afe->dev, "%s irq status err\n", __func__);
1923e1991d10SAlexandre Mergnat 		reg_value = AFE_IRQ_STATUS_BITS;
1924e1991d10SAlexandre Mergnat 		goto err_irq;
1925e1991d10SAlexandre Mergnat 	}
1926e1991d10SAlexandre Mergnat 
1927e1991d10SAlexandre Mergnat 	ret = regmap_read(afe->regmap, AFE_IRQ_MCU_EN, &mcu_irq_mask);
1928e1991d10SAlexandre Mergnat 	if (ret) {
1929e1991d10SAlexandre Mergnat 		dev_err_ratelimited(afe->dev, "%s irq mcu_en err\n", __func__);
1930e1991d10SAlexandre Mergnat 		reg_value = AFE_IRQ_STATUS_BITS;
1931e1991d10SAlexandre Mergnat 		goto err_irq;
1932e1991d10SAlexandre Mergnat 	}
1933e1991d10SAlexandre Mergnat 
1934e1991d10SAlexandre Mergnat 	/* only clr cpu irq */
1935e1991d10SAlexandre Mergnat 	reg_value &= mcu_irq_mask;
1936e1991d10SAlexandre Mergnat 
1937e1991d10SAlexandre Mergnat 	for (i = 0; i < MT8365_AFE_MEMIF_NUM; i++) {
1938e1991d10SAlexandre Mergnat 		struct mtk_base_afe_memif *memif = &afe->memif[i];
1939e1991d10SAlexandre Mergnat 		struct mtk_base_afe_irq *mcu_irq;
1940e1991d10SAlexandre Mergnat 
1941e1991d10SAlexandre Mergnat 		if (memif->irq_usage < 0)
1942e1991d10SAlexandre Mergnat 			continue;
1943e1991d10SAlexandre Mergnat 
1944e1991d10SAlexandre Mergnat 		mcu_irq = &afe->irqs[memif->irq_usage];
1945e1991d10SAlexandre Mergnat 
1946e1991d10SAlexandre Mergnat 		if (!(reg_value & (1 << mcu_irq->irq_data->irq_clr_shift)))
1947e1991d10SAlexandre Mergnat 			continue;
1948e1991d10SAlexandre Mergnat 
1949e1991d10SAlexandre Mergnat 		snd_pcm_period_elapsed(memif->substream);
1950e1991d10SAlexandre Mergnat 	}
1951e1991d10SAlexandre Mergnat 
1952e1991d10SAlexandre Mergnat err_irq:
1953e1991d10SAlexandre Mergnat 	/* clear irq */
1954e1991d10SAlexandre Mergnat 	regmap_write(afe->regmap, AFE_IRQ_MCU_CLR,
1955e1991d10SAlexandre Mergnat 		     reg_value & AFE_IRQ_STATUS_BITS);
1956e1991d10SAlexandre Mergnat 
1957e1991d10SAlexandre Mergnat 	return IRQ_HANDLED;
1958e1991d10SAlexandre Mergnat }
1959e1991d10SAlexandre Mergnat 
mt8365_afe_runtime_suspend(struct device * dev)1960e1991d10SAlexandre Mergnat static int __maybe_unused mt8365_afe_runtime_suspend(struct device *dev)
1961e1991d10SAlexandre Mergnat {
1962e1991d10SAlexandre Mergnat 	return 0;
1963e1991d10SAlexandre Mergnat }
1964e1991d10SAlexandre Mergnat 
mt8365_afe_runtime_resume(struct device * dev)1965e1991d10SAlexandre Mergnat static int mt8365_afe_runtime_resume(struct device *dev)
1966e1991d10SAlexandre Mergnat {
1967e1991d10SAlexandre Mergnat 	return 0;
1968e1991d10SAlexandre Mergnat }
1969e1991d10SAlexandre Mergnat 
mt8365_afe_suspend(struct device * dev)1970e1991d10SAlexandre Mergnat static int __maybe_unused mt8365_afe_suspend(struct device *dev)
1971e1991d10SAlexandre Mergnat {
1972e1991d10SAlexandre Mergnat 	struct mtk_base_afe *afe = dev_get_drvdata(dev);
1973e1991d10SAlexandre Mergnat 	struct regmap *regmap = afe->regmap;
1974e1991d10SAlexandre Mergnat 	int i;
1975e1991d10SAlexandre Mergnat 
1976e1991d10SAlexandre Mergnat 	mt8365_afe_enable_main_clk(afe);
1977e1991d10SAlexandre Mergnat 
1978e1991d10SAlexandre Mergnat 	if (!afe->reg_back_up)
1979e1991d10SAlexandre Mergnat 		afe->reg_back_up =
1980e1991d10SAlexandre Mergnat 			devm_kcalloc(dev, afe->reg_back_up_list_num,
1981e1991d10SAlexandre Mergnat 				     sizeof(unsigned int), GFP_KERNEL);
1982e1991d10SAlexandre Mergnat 
1983e1991d10SAlexandre Mergnat 	for (i = 0; i < afe->reg_back_up_list_num; i++)
1984e1991d10SAlexandre Mergnat 		regmap_read(regmap, afe->reg_back_up_list[i],
1985e1991d10SAlexandre Mergnat 			    &afe->reg_back_up[i]);
1986e1991d10SAlexandre Mergnat 
1987e1991d10SAlexandre Mergnat 	mt8365_afe_disable_main_clk(afe);
1988e1991d10SAlexandre Mergnat 
1989e1991d10SAlexandre Mergnat 	return 0;
1990e1991d10SAlexandre Mergnat }
1991e1991d10SAlexandre Mergnat 
mt8365_afe_resume(struct device * dev)1992e1991d10SAlexandre Mergnat static int __maybe_unused mt8365_afe_resume(struct device *dev)
1993e1991d10SAlexandre Mergnat {
1994e1991d10SAlexandre Mergnat 	struct mtk_base_afe *afe = dev_get_drvdata(dev);
1995e1991d10SAlexandre Mergnat 	struct regmap *regmap = afe->regmap;
1996e1991d10SAlexandre Mergnat 	int i = 0;
1997e1991d10SAlexandre Mergnat 
1998e1991d10SAlexandre Mergnat 	if (!afe->reg_back_up)
1999e1991d10SAlexandre Mergnat 		return 0;
2000e1991d10SAlexandre Mergnat 
2001e1991d10SAlexandre Mergnat 	mt8365_afe_enable_main_clk(afe);
2002e1991d10SAlexandre Mergnat 
2003e1991d10SAlexandre Mergnat 	for (i = 0; i < afe->reg_back_up_list_num; i++)
2004e1991d10SAlexandre Mergnat 		regmap_write(regmap, afe->reg_back_up_list[i],
2005e1991d10SAlexandre Mergnat 			     afe->reg_back_up[i]);
2006e1991d10SAlexandre Mergnat 
2007e1991d10SAlexandre Mergnat 	mt8365_afe_disable_main_clk(afe);
2008e1991d10SAlexandre Mergnat 
2009e1991d10SAlexandre Mergnat 	return 0;
2010e1991d10SAlexandre Mergnat }
2011e1991d10SAlexandre Mergnat 
mt8365_afe_dev_runtime_suspend(struct device * dev)2012e1991d10SAlexandre Mergnat static int __maybe_unused mt8365_afe_dev_runtime_suspend(struct device *dev)
2013e1991d10SAlexandre Mergnat {
2014e1991d10SAlexandre Mergnat 	struct mtk_base_afe *afe = dev_get_drvdata(dev);
2015e1991d10SAlexandre Mergnat 
2016e1991d10SAlexandre Mergnat 	if (pm_runtime_status_suspended(dev) || afe->suspended)
2017e1991d10SAlexandre Mergnat 		return 0;
2018e1991d10SAlexandre Mergnat 
2019e1991d10SAlexandre Mergnat 	mt8365_afe_suspend(dev);
2020e1991d10SAlexandre Mergnat 	afe->suspended = true;
2021e1991d10SAlexandre Mergnat 	return 0;
2022e1991d10SAlexandre Mergnat }
2023e1991d10SAlexandre Mergnat 
mt8365_afe_dev_runtime_resume(struct device * dev)2024e1991d10SAlexandre Mergnat static int __maybe_unused mt8365_afe_dev_runtime_resume(struct device *dev)
2025e1991d10SAlexandre Mergnat {
2026e1991d10SAlexandre Mergnat 	struct mtk_base_afe *afe = dev_get_drvdata(dev);
2027e1991d10SAlexandre Mergnat 
2028e1991d10SAlexandre Mergnat 	if (pm_runtime_status_suspended(dev) || !afe->suspended)
2029e1991d10SAlexandre Mergnat 		return 0;
2030e1991d10SAlexandre Mergnat 
2031e1991d10SAlexandre Mergnat 	mt8365_afe_resume(dev);
2032e1991d10SAlexandre Mergnat 	afe->suspended = false;
2033e1991d10SAlexandre Mergnat 	return 0;
2034e1991d10SAlexandre Mergnat }
2035e1991d10SAlexandre Mergnat 
mt8365_afe_init_registers(struct mtk_base_afe * afe)2036e1991d10SAlexandre Mergnat static int mt8365_afe_init_registers(struct mtk_base_afe *afe)
2037e1991d10SAlexandre Mergnat {
2038e1991d10SAlexandre Mergnat 	size_t i;
2039e1991d10SAlexandre Mergnat 
2040e1991d10SAlexandre Mergnat 	static struct {
2041e1991d10SAlexandre Mergnat 		unsigned int reg;
2042e1991d10SAlexandre Mergnat 		unsigned int mask;
2043e1991d10SAlexandre Mergnat 		unsigned int val;
2044e1991d10SAlexandre Mergnat 	} init_regs[] = {
2045e1991d10SAlexandre Mergnat 		{ AFE_CONN_24BIT, GENMASK(31, 0), GENMASK(31, 0) },
2046e1991d10SAlexandre Mergnat 		{ AFE_CONN_24BIT_1, GENMASK(21, 0), GENMASK(21, 0) },
2047e1991d10SAlexandre Mergnat 	};
2048e1991d10SAlexandre Mergnat 
2049e1991d10SAlexandre Mergnat 	mt8365_afe_enable_main_clk(afe);
2050e1991d10SAlexandre Mergnat 
2051e1991d10SAlexandre Mergnat 	for (i = 0; i < ARRAY_SIZE(init_regs); i++)
2052e1991d10SAlexandre Mergnat 		regmap_update_bits(afe->regmap, init_regs[i].reg,
2053e1991d10SAlexandre Mergnat 				   init_regs[i].mask, init_regs[i].val);
2054e1991d10SAlexandre Mergnat 
2055e1991d10SAlexandre Mergnat 	mt8365_afe_disable_main_clk(afe);
2056e1991d10SAlexandre Mergnat 
2057e1991d10SAlexandre Mergnat 	return 0;
2058e1991d10SAlexandre Mergnat }
2059e1991d10SAlexandre Mergnat 
mt8365_dai_memif_register(struct mtk_base_afe * afe)2060e1991d10SAlexandre Mergnat static int mt8365_dai_memif_register(struct mtk_base_afe *afe)
2061e1991d10SAlexandre Mergnat {
2062e1991d10SAlexandre Mergnat 	struct mtk_base_afe_dai *dai;
2063e1991d10SAlexandre Mergnat 
2064e1991d10SAlexandre Mergnat 	dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL);
2065e1991d10SAlexandre Mergnat 	if (!dai)
2066e1991d10SAlexandre Mergnat 		return -ENOMEM;
2067e1991d10SAlexandre Mergnat 
2068e1991d10SAlexandre Mergnat 	list_add(&dai->list, &afe->sub_dais);
2069e1991d10SAlexandre Mergnat 
2070e1991d10SAlexandre Mergnat 	dai->dai_drivers = mt8365_memif_dai_driver;
2071e1991d10SAlexandre Mergnat 	dai->num_dai_drivers = ARRAY_SIZE(mt8365_memif_dai_driver);
2072e1991d10SAlexandre Mergnat 
2073e1991d10SAlexandre Mergnat 	dai->dapm_widgets = mt8365_memif_widgets;
2074e1991d10SAlexandre Mergnat 	dai->num_dapm_widgets = ARRAY_SIZE(mt8365_memif_widgets);
2075e1991d10SAlexandre Mergnat 	dai->dapm_routes = mt8365_memif_routes;
2076e1991d10SAlexandre Mergnat 	dai->num_dapm_routes = ARRAY_SIZE(mt8365_memif_routes);
2077e1991d10SAlexandre Mergnat 	return 0;
2078e1991d10SAlexandre Mergnat }
2079e1991d10SAlexandre Mergnat 
2080e1991d10SAlexandre Mergnat typedef int (*dai_register_cb)(struct mtk_base_afe *);
2081e1991d10SAlexandre Mergnat static const dai_register_cb dai_register_cbs[] = {
2082e1991d10SAlexandre Mergnat 	mt8365_dai_pcm_register,
2083e1991d10SAlexandre Mergnat 	mt8365_dai_i2s_register,
2084e1991d10SAlexandre Mergnat 	mt8365_dai_adda_register,
2085e1991d10SAlexandre Mergnat 	mt8365_dai_dmic_register,
2086e1991d10SAlexandre Mergnat 	mt8365_dai_memif_register,
2087e1991d10SAlexandre Mergnat };
2088e1991d10SAlexandre Mergnat 
mt8365_afe_pcm_dev_probe(struct platform_device * pdev)2089e1991d10SAlexandre Mergnat static int mt8365_afe_pcm_dev_probe(struct platform_device *pdev)
2090e1991d10SAlexandre Mergnat {
2091e1991d10SAlexandre Mergnat 	struct mtk_base_afe *afe;
2092e1991d10SAlexandre Mergnat 	struct mt8365_afe_private *afe_priv;
2093e1991d10SAlexandre Mergnat 	struct device *dev;
2094e1991d10SAlexandre Mergnat 	int ret, i, sel_irq;
2095e1991d10SAlexandre Mergnat 	unsigned int irq_id;
2096e1991d10SAlexandre Mergnat 	struct resource *res;
2097e1991d10SAlexandre Mergnat 
2098e1991d10SAlexandre Mergnat 	afe = devm_kzalloc(&pdev->dev, sizeof(*afe), GFP_KERNEL);
2099e1991d10SAlexandre Mergnat 	if (!afe)
2100e1991d10SAlexandre Mergnat 		return -ENOMEM;
2101e1991d10SAlexandre Mergnat 	platform_set_drvdata(pdev, afe);
2102e1991d10SAlexandre Mergnat 
2103e1991d10SAlexandre Mergnat 	afe->platform_priv = devm_kzalloc(&pdev->dev, sizeof(*afe_priv),
2104e1991d10SAlexandre Mergnat 					  GFP_KERNEL);
2105e1991d10SAlexandre Mergnat 	if (!afe->platform_priv)
2106e1991d10SAlexandre Mergnat 		return -ENOMEM;
2107e1991d10SAlexandre Mergnat 
2108e1991d10SAlexandre Mergnat 	afe_priv = afe->platform_priv;
2109e1991d10SAlexandre Mergnat 	afe->dev = &pdev->dev;
2110e1991d10SAlexandre Mergnat 	dev = afe->dev;
2111e1991d10SAlexandre Mergnat 
2112e1991d10SAlexandre Mergnat 	spin_lock_init(&afe_priv->afe_ctrl_lock);
2113e1991d10SAlexandre Mergnat 	mutex_init(&afe_priv->afe_clk_mutex);
2114e1991d10SAlexandre Mergnat 
2115e1991d10SAlexandre Mergnat 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2116e1991d10SAlexandre Mergnat 	afe->base_addr = devm_ioremap_resource(&pdev->dev, res);
2117e1991d10SAlexandre Mergnat 	if (IS_ERR(afe->base_addr))
2118e1991d10SAlexandre Mergnat 		return PTR_ERR(afe->base_addr);
2119e1991d10SAlexandre Mergnat 
2120e1991d10SAlexandre Mergnat 	res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
2121e1991d10SAlexandre Mergnat 	if (res) {
2122e1991d10SAlexandre Mergnat 		afe_priv->afe_sram_vir_addr =
2123e1991d10SAlexandre Mergnat 			devm_ioremap_resource(&pdev->dev, res);
2124e1991d10SAlexandre Mergnat 		if (!IS_ERR(afe_priv->afe_sram_vir_addr)) {
2125e1991d10SAlexandre Mergnat 			afe_priv->afe_sram_phy_addr = res->start;
2126e1991d10SAlexandre Mergnat 			afe_priv->afe_sram_size = resource_size(res);
2127e1991d10SAlexandre Mergnat 		}
2128e1991d10SAlexandre Mergnat 	}
2129e1991d10SAlexandre Mergnat 
2130e1991d10SAlexandre Mergnat 	/* initial audio related clock */
2131e1991d10SAlexandre Mergnat 	ret = mt8365_afe_init_audio_clk(afe);
2132e1991d10SAlexandre Mergnat 	if (ret)
2133e1991d10SAlexandre Mergnat 		return dev_err_probe(afe->dev, ret, "mt8365_afe_init_audio_clk fail\n");
2134e1991d10SAlexandre Mergnat 
2135e1991d10SAlexandre Mergnat 	afe->regmap = devm_regmap_init_mmio_clk(&pdev->dev, "top_audio_sel",
2136e1991d10SAlexandre Mergnat 						afe->base_addr,
2137e1991d10SAlexandre Mergnat 						&mt8365_afe_regmap_config);
2138e1991d10SAlexandre Mergnat 	if (IS_ERR(afe->regmap))
2139e1991d10SAlexandre Mergnat 		return PTR_ERR(afe->regmap);
2140e1991d10SAlexandre Mergnat 
2141e1991d10SAlexandre Mergnat 	/* memif % irq initialize*/
2142e1991d10SAlexandre Mergnat 	afe->memif_size = MT8365_AFE_MEMIF_NUM;
2143e1991d10SAlexandre Mergnat 	afe->memif = devm_kcalloc(afe->dev, afe->memif_size,
2144e1991d10SAlexandre Mergnat 				  sizeof(*afe->memif), GFP_KERNEL);
2145e1991d10SAlexandre Mergnat 	if (!afe->memif)
2146e1991d10SAlexandre Mergnat 		return -ENOMEM;
2147e1991d10SAlexandre Mergnat 
2148e1991d10SAlexandre Mergnat 	afe->irqs_size = MT8365_AFE_IRQ_NUM;
2149e1991d10SAlexandre Mergnat 	afe->irqs = devm_kcalloc(afe->dev, afe->irqs_size,
2150e1991d10SAlexandre Mergnat 				 sizeof(*afe->irqs), GFP_KERNEL);
2151e1991d10SAlexandre Mergnat 	if (!afe->irqs)
2152e1991d10SAlexandre Mergnat 		return -ENOMEM;
2153e1991d10SAlexandre Mergnat 
2154e1991d10SAlexandre Mergnat 	for (i = 0; i < afe->irqs_size; i++)
2155e1991d10SAlexandre Mergnat 		afe->irqs[i].irq_data = &irq_data[i];
2156e1991d10SAlexandre Mergnat 
2157130eb72dSTang Bin 	ret = platform_get_irq(pdev, 0);
2158130eb72dSTang Bin 	if (ret < 0)
2159130eb72dSTang Bin 		return ret;
2160130eb72dSTang Bin 
2161130eb72dSTang Bin 	irq_id = ret;
2162e1991d10SAlexandre Mergnat 	ret = devm_request_irq(afe->dev, irq_id, mt8365_afe_irq_handler,
2163e1991d10SAlexandre Mergnat 			       0, "Afe_ISR_Handle", (void *)afe);
2164e1991d10SAlexandre Mergnat 	if (ret)
2165e1991d10SAlexandre Mergnat 		return dev_err_probe(afe->dev, ret, "could not request_irq\n");
2166e1991d10SAlexandre Mergnat 
2167e1991d10SAlexandre Mergnat 	/* init sub_dais */
2168e1991d10SAlexandre Mergnat 	INIT_LIST_HEAD(&afe->sub_dais);
2169e1991d10SAlexandre Mergnat 
2170e1991d10SAlexandre Mergnat 	for (i = 0; i < ARRAY_SIZE(dai_register_cbs); i++) {
2171e1991d10SAlexandre Mergnat 		ret = dai_register_cbs[i](afe);
2172e1991d10SAlexandre Mergnat 		if (ret) {
2173e1991d10SAlexandre Mergnat 			dev_warn(afe->dev, "dai register i %d fail, ret %d\n",
2174e1991d10SAlexandre Mergnat 				 i, ret);
2175e1991d10SAlexandre Mergnat 			return ret;
2176e1991d10SAlexandre Mergnat 		}
2177e1991d10SAlexandre Mergnat 	}
2178e1991d10SAlexandre Mergnat 
2179e1991d10SAlexandre Mergnat 	/* init dai_driver and component_driver */
2180e1991d10SAlexandre Mergnat 	ret = mtk_afe_combine_sub_dai(afe);
2181e1991d10SAlexandre Mergnat 	if (ret) {
2182e1991d10SAlexandre Mergnat 		dev_warn(afe->dev, "mtk_afe_combine_sub_dai fail, ret %d\n",
2183e1991d10SAlexandre Mergnat 			 ret);
2184e1991d10SAlexandre Mergnat 		return ret;
2185e1991d10SAlexandre Mergnat 	}
2186e1991d10SAlexandre Mergnat 
2187e1991d10SAlexandre Mergnat 	for (i = 0; i < afe->memif_size; i++) {
2188e1991d10SAlexandre Mergnat 		afe->memif[i].data = &memif_data[i];
2189e1991d10SAlexandre Mergnat 		sel_irq = memif_specified_irqs[i];
2190e1991d10SAlexandre Mergnat 		if (sel_irq >= 0) {
2191e1991d10SAlexandre Mergnat 			afe->memif[i].irq_usage = sel_irq;
2192e1991d10SAlexandre Mergnat 			afe->memif[i].const_irq = 1;
2193e1991d10SAlexandre Mergnat 			afe->irqs[sel_irq].irq_occupyed = true;
2194e1991d10SAlexandre Mergnat 		} else {
2195e1991d10SAlexandre Mergnat 			afe->memif[i].irq_usage = -1;
2196e1991d10SAlexandre Mergnat 		}
2197e1991d10SAlexandre Mergnat 	}
2198e1991d10SAlexandre Mergnat 
2199e1991d10SAlexandre Mergnat 	afe->mtk_afe_hardware = &mt8365_afe_hardware;
2200e1991d10SAlexandre Mergnat 	afe->memif_fs = mt8365_memif_fs;
2201e1991d10SAlexandre Mergnat 	afe->irq_fs = mt8365_irq_fs;
2202e1991d10SAlexandre Mergnat 
2203e1991d10SAlexandre Mergnat 	ret = devm_pm_runtime_enable(&pdev->dev);
2204e1991d10SAlexandre Mergnat 	if (ret)
2205e1991d10SAlexandre Mergnat 		return ret;
2206e1991d10SAlexandre Mergnat 
2207e1991d10SAlexandre Mergnat 	pm_runtime_get_sync(&pdev->dev);
2208e1991d10SAlexandre Mergnat 	afe->reg_back_up_list = mt8365_afe_backup_list;
2209e1991d10SAlexandre Mergnat 	afe->reg_back_up_list_num = ARRAY_SIZE(mt8365_afe_backup_list);
2210e1991d10SAlexandre Mergnat 	afe->runtime_resume = mt8365_afe_runtime_resume;
2211e1991d10SAlexandre Mergnat 	afe->runtime_suspend = mt8365_afe_runtime_suspend;
2212e1991d10SAlexandre Mergnat 
2213e1991d10SAlexandre Mergnat 	/* open afe pdn for dapm read/write audio register */
2214e1991d10SAlexandre Mergnat 	mt8365_afe_enable_top_cg(afe, MT8365_TOP_CG_AFE);
2215e1991d10SAlexandre Mergnat 
2216e1991d10SAlexandre Mergnat 	/* Set 26m parent clk */
2217e1991d10SAlexandre Mergnat 	mt8365_afe_set_clk_parent(afe,
2218e1991d10SAlexandre Mergnat 				  afe_priv->clocks[MT8365_CLK_TOP_AUD_SEL],
2219e1991d10SAlexandre Mergnat 				  afe_priv->clocks[MT8365_CLK_CLK26M]);
2220e1991d10SAlexandre Mergnat 
2221e1991d10SAlexandre Mergnat 	ret = devm_snd_soc_register_component(&pdev->dev,
2222e1991d10SAlexandre Mergnat 					      &mtk_afe_pcm_platform,
2223e1991d10SAlexandre Mergnat 					      afe->dai_drivers,
2224e1991d10SAlexandre Mergnat 					      afe->num_dai_drivers);
2225e1991d10SAlexandre Mergnat 	if (ret) {
2226e1991d10SAlexandre Mergnat 		dev_warn(dev, "err_platform\n");
2227e1991d10SAlexandre Mergnat 		return ret;
2228e1991d10SAlexandre Mergnat 	}
2229e1991d10SAlexandre Mergnat 
2230e1991d10SAlexandre Mergnat 	mt8365_afe_init_registers(afe);
2231e1991d10SAlexandre Mergnat 
2232e1991d10SAlexandre Mergnat 	return 0;
2233e1991d10SAlexandre Mergnat }
2234e1991d10SAlexandre Mergnat 
mt8365_afe_pcm_dev_remove(struct platform_device * pdev)2235e1991d10SAlexandre Mergnat static void mt8365_afe_pcm_dev_remove(struct platform_device *pdev)
2236e1991d10SAlexandre Mergnat {
2237e1991d10SAlexandre Mergnat 	struct mtk_base_afe *afe = platform_get_drvdata(pdev);
2238e1991d10SAlexandre Mergnat 
2239e1991d10SAlexandre Mergnat 	mt8365_afe_disable_top_cg(afe, MT8365_TOP_CG_AFE);
2240e1991d10SAlexandre Mergnat 
2241e1991d10SAlexandre Mergnat 	pm_runtime_disable(&pdev->dev);
2242e1991d10SAlexandre Mergnat 	if (!pm_runtime_status_suspended(&pdev->dev))
2243e1991d10SAlexandre Mergnat 		mt8365_afe_runtime_suspend(&pdev->dev);
2244e1991d10SAlexandre Mergnat }
2245e1991d10SAlexandre Mergnat 
2246e1991d10SAlexandre Mergnat static const struct of_device_id mt8365_afe_pcm_dt_match[] = {
2247e1991d10SAlexandre Mergnat 	{ .compatible = "mediatek,mt8365-afe-pcm", },
2248e1991d10SAlexandre Mergnat 	{ }
2249e1991d10SAlexandre Mergnat };
2250e1991d10SAlexandre Mergnat MODULE_DEVICE_TABLE(of, mt8365_afe_pcm_dt_match);
2251e1991d10SAlexandre Mergnat 
2252e1991d10SAlexandre Mergnat static const struct dev_pm_ops mt8365_afe_pm_ops = {
2253e1991d10SAlexandre Mergnat 	SET_RUNTIME_PM_OPS(mt8365_afe_dev_runtime_suspend,
2254e1991d10SAlexandre Mergnat 			   mt8365_afe_dev_runtime_resume, NULL)
2255e1991d10SAlexandre Mergnat 	SET_SYSTEM_SLEEP_PM_OPS(mt8365_afe_suspend,
2256e1991d10SAlexandre Mergnat 				mt8365_afe_resume)
2257e1991d10SAlexandre Mergnat };
2258e1991d10SAlexandre Mergnat 
2259e1991d10SAlexandre Mergnat static struct platform_driver mt8365_afe_pcm_driver = {
2260e1991d10SAlexandre Mergnat 	.driver = {
2261e1991d10SAlexandre Mergnat 		   .name = "mt8365-afe-pcm",
2262e1991d10SAlexandre Mergnat 		   .of_match_table = mt8365_afe_pcm_dt_match,
2263e1991d10SAlexandre Mergnat 		   .pm = &mt8365_afe_pm_ops,
2264e1991d10SAlexandre Mergnat 	},
2265e1991d10SAlexandre Mergnat 	.probe = mt8365_afe_pcm_dev_probe,
2266*130af75bSUwe Kleine-König 	.remove = mt8365_afe_pcm_dev_remove,
2267e1991d10SAlexandre Mergnat };
2268e1991d10SAlexandre Mergnat 
2269e1991d10SAlexandre Mergnat module_platform_driver(mt8365_afe_pcm_driver);
2270e1991d10SAlexandre Mergnat 
2271e1991d10SAlexandre Mergnat MODULE_DESCRIPTION("MediaTek ALSA SoC AFE platform driver");
2272e1991d10SAlexandre Mergnat MODULE_AUTHOR("Jia Zeng <jia.zeng@mediatek.com>");
2273e1991d10SAlexandre Mergnat MODULE_AUTHOR("Alexandre Mergnat <amergnat@baylibre.com>");
2274e1991d10SAlexandre Mergnat MODULE_LICENSE("GPL");
2275