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