1*38c7c9ddSAlexandre Mergnat /* SPDX-License-Identifier: GPL-2.0
2*38c7c9ddSAlexandre Mergnat *
3*38c7c9ddSAlexandre Mergnat * MediaTek 8365 audio driver common definitions
4*38c7c9ddSAlexandre Mergnat *
5*38c7c9ddSAlexandre Mergnat * Copyright (c) 2024 MediaTek Inc.
6*38c7c9ddSAlexandre Mergnat * Authors: Jia Zeng <jia.zeng@mediatek.com>
7*38c7c9ddSAlexandre Mergnat * Alexandre Mergnat <amergnat@baylibre.com>
8*38c7c9ddSAlexandre Mergnat */
9*38c7c9ddSAlexandre Mergnat
10*38c7c9ddSAlexandre Mergnat #ifndef _MT8365_AFE_COMMON_H_
11*38c7c9ddSAlexandre Mergnat #define _MT8365_AFE_COMMON_H_
12*38c7c9ddSAlexandre Mergnat
13*38c7c9ddSAlexandre Mergnat #include <linux/clk.h>
14*38c7c9ddSAlexandre Mergnat #include <linux/list.h>
15*38c7c9ddSAlexandre Mergnat #include <linux/regmap.h>
16*38c7c9ddSAlexandre Mergnat #include <sound/soc.h>
17*38c7c9ddSAlexandre Mergnat #include <sound/asound.h>
18*38c7c9ddSAlexandre Mergnat #include "../common/mtk-base-afe.h"
19*38c7c9ddSAlexandre Mergnat #include "mt8365-reg.h"
20*38c7c9ddSAlexandre Mergnat
21*38c7c9ddSAlexandre Mergnat enum {
22*38c7c9ddSAlexandre Mergnat MT8365_AFE_MEMIF_DL1,
23*38c7c9ddSAlexandre Mergnat MT8365_AFE_MEMIF_DL2,
24*38c7c9ddSAlexandre Mergnat MT8365_AFE_MEMIF_TDM_OUT,
25*38c7c9ddSAlexandre Mergnat /*
26*38c7c9ddSAlexandre Mergnat * MT8365_AFE_MEMIF_SPDIF_OUT,
27*38c7c9ddSAlexandre Mergnat */
28*38c7c9ddSAlexandre Mergnat MT8365_AFE_MEMIF_AWB,
29*38c7c9ddSAlexandre Mergnat MT8365_AFE_MEMIF_VUL,
30*38c7c9ddSAlexandre Mergnat MT8365_AFE_MEMIF_VUL2,
31*38c7c9ddSAlexandre Mergnat MT8365_AFE_MEMIF_VUL3,
32*38c7c9ddSAlexandre Mergnat MT8365_AFE_MEMIF_TDM_IN,
33*38c7c9ddSAlexandre Mergnat /*
34*38c7c9ddSAlexandre Mergnat * MT8365_AFE_MEMIF_SPDIF_IN,
35*38c7c9ddSAlexandre Mergnat */
36*38c7c9ddSAlexandre Mergnat MT8365_AFE_MEMIF_NUM,
37*38c7c9ddSAlexandre Mergnat MT8365_AFE_BACKEND_BASE = MT8365_AFE_MEMIF_NUM,
38*38c7c9ddSAlexandre Mergnat MT8365_AFE_IO_TDM_OUT = MT8365_AFE_BACKEND_BASE,
39*38c7c9ddSAlexandre Mergnat MT8365_AFE_IO_TDM_IN,
40*38c7c9ddSAlexandre Mergnat MT8365_AFE_IO_I2S,
41*38c7c9ddSAlexandre Mergnat MT8365_AFE_IO_2ND_I2S,
42*38c7c9ddSAlexandre Mergnat MT8365_AFE_IO_PCM1,
43*38c7c9ddSAlexandre Mergnat MT8365_AFE_IO_VIRTUAL_DL_SRC,
44*38c7c9ddSAlexandre Mergnat MT8365_AFE_IO_VIRTUAL_TDM_OUT_SRC,
45*38c7c9ddSAlexandre Mergnat MT8365_AFE_IO_VIRTUAL_FM,
46*38c7c9ddSAlexandre Mergnat MT8365_AFE_IO_DMIC,
47*38c7c9ddSAlexandre Mergnat MT8365_AFE_IO_INT_ADDA,
48*38c7c9ddSAlexandre Mergnat MT8365_AFE_IO_GASRC1,
49*38c7c9ddSAlexandre Mergnat MT8365_AFE_IO_GASRC2,
50*38c7c9ddSAlexandre Mergnat MT8365_AFE_IO_TDM_ASRC,
51*38c7c9ddSAlexandre Mergnat MT8365_AFE_IO_HW_GAIN1,
52*38c7c9ddSAlexandre Mergnat MT8365_AFE_IO_HW_GAIN2,
53*38c7c9ddSAlexandre Mergnat MT8365_AFE_BACKEND_END,
54*38c7c9ddSAlexandre Mergnat MT8365_AFE_BACKEND_NUM = (MT8365_AFE_BACKEND_END -
55*38c7c9ddSAlexandre Mergnat MT8365_AFE_BACKEND_BASE),
56*38c7c9ddSAlexandre Mergnat };
57*38c7c9ddSAlexandre Mergnat
58*38c7c9ddSAlexandre Mergnat enum {
59*38c7c9ddSAlexandre Mergnat MT8365_AFE_IRQ1,
60*38c7c9ddSAlexandre Mergnat MT8365_AFE_IRQ2,
61*38c7c9ddSAlexandre Mergnat MT8365_AFE_IRQ3,
62*38c7c9ddSAlexandre Mergnat MT8365_AFE_IRQ4,
63*38c7c9ddSAlexandre Mergnat MT8365_AFE_IRQ5,
64*38c7c9ddSAlexandre Mergnat MT8365_AFE_IRQ6,
65*38c7c9ddSAlexandre Mergnat MT8365_AFE_IRQ7,
66*38c7c9ddSAlexandre Mergnat MT8365_AFE_IRQ8,
67*38c7c9ddSAlexandre Mergnat MT8365_AFE_IRQ9,
68*38c7c9ddSAlexandre Mergnat MT8365_AFE_IRQ10,
69*38c7c9ddSAlexandre Mergnat MT8365_AFE_IRQ_NUM,
70*38c7c9ddSAlexandre Mergnat };
71*38c7c9ddSAlexandre Mergnat
72*38c7c9ddSAlexandre Mergnat enum {
73*38c7c9ddSAlexandre Mergnat MT8365_TOP_CG_AFE,
74*38c7c9ddSAlexandre Mergnat MT8365_TOP_CG_I2S_IN,
75*38c7c9ddSAlexandre Mergnat MT8365_TOP_CG_22M,
76*38c7c9ddSAlexandre Mergnat MT8365_TOP_CG_24M,
77*38c7c9ddSAlexandre Mergnat MT8365_TOP_CG_INTDIR_CK,
78*38c7c9ddSAlexandre Mergnat MT8365_TOP_CG_APLL2_TUNER,
79*38c7c9ddSAlexandre Mergnat MT8365_TOP_CG_APLL_TUNER,
80*38c7c9ddSAlexandre Mergnat MT8365_TOP_CG_SPDIF,
81*38c7c9ddSAlexandre Mergnat MT8365_TOP_CG_TDM_OUT,
82*38c7c9ddSAlexandre Mergnat MT8365_TOP_CG_TDM_IN,
83*38c7c9ddSAlexandre Mergnat MT8365_TOP_CG_ADC,
84*38c7c9ddSAlexandre Mergnat MT8365_TOP_CG_DAC,
85*38c7c9ddSAlexandre Mergnat MT8365_TOP_CG_DAC_PREDIS,
86*38c7c9ddSAlexandre Mergnat MT8365_TOP_CG_TML,
87*38c7c9ddSAlexandre Mergnat MT8365_TOP_CG_I2S1_BCLK,
88*38c7c9ddSAlexandre Mergnat MT8365_TOP_CG_I2S2_BCLK,
89*38c7c9ddSAlexandre Mergnat MT8365_TOP_CG_I2S3_BCLK,
90*38c7c9ddSAlexandre Mergnat MT8365_TOP_CG_I2S4_BCLK,
91*38c7c9ddSAlexandre Mergnat MT8365_TOP_CG_DMIC0_ADC,
92*38c7c9ddSAlexandre Mergnat MT8365_TOP_CG_DMIC1_ADC,
93*38c7c9ddSAlexandre Mergnat MT8365_TOP_CG_DMIC2_ADC,
94*38c7c9ddSAlexandre Mergnat MT8365_TOP_CG_DMIC3_ADC,
95*38c7c9ddSAlexandre Mergnat MT8365_TOP_CG_CONNSYS_I2S_ASRC,
96*38c7c9ddSAlexandre Mergnat MT8365_TOP_CG_GENERAL1_ASRC,
97*38c7c9ddSAlexandre Mergnat MT8365_TOP_CG_GENERAL2_ASRC,
98*38c7c9ddSAlexandre Mergnat MT8365_TOP_CG_TDM_ASRC,
99*38c7c9ddSAlexandre Mergnat MT8365_TOP_CG_NUM
100*38c7c9ddSAlexandre Mergnat };
101*38c7c9ddSAlexandre Mergnat
102*38c7c9ddSAlexandre Mergnat enum {
103*38c7c9ddSAlexandre Mergnat MT8365_CLK_TOP_AUD_SEL,
104*38c7c9ddSAlexandre Mergnat MT8365_CLK_AUD_I2S0_M,
105*38c7c9ddSAlexandre Mergnat MT8365_CLK_AUD_I2S1_M,
106*38c7c9ddSAlexandre Mergnat MT8365_CLK_AUD_I2S2_M,
107*38c7c9ddSAlexandre Mergnat MT8365_CLK_AUD_I2S3_M,
108*38c7c9ddSAlexandre Mergnat MT8365_CLK_ENGEN1,
109*38c7c9ddSAlexandre Mergnat MT8365_CLK_ENGEN2,
110*38c7c9ddSAlexandre Mergnat MT8365_CLK_AUD1,
111*38c7c9ddSAlexandre Mergnat MT8365_CLK_AUD2,
112*38c7c9ddSAlexandre Mergnat MT8365_CLK_I2S0_M_SEL,
113*38c7c9ddSAlexandre Mergnat MT8365_CLK_I2S1_M_SEL,
114*38c7c9ddSAlexandre Mergnat MT8365_CLK_I2S2_M_SEL,
115*38c7c9ddSAlexandre Mergnat MT8365_CLK_I2S3_M_SEL,
116*38c7c9ddSAlexandre Mergnat MT8365_CLK_CLK26M,
117*38c7c9ddSAlexandre Mergnat MT8365_CLK_NUM
118*38c7c9ddSAlexandre Mergnat };
119*38c7c9ddSAlexandre Mergnat
120*38c7c9ddSAlexandre Mergnat enum {
121*38c7c9ddSAlexandre Mergnat MT8365_AFE_APLL1 = 0,
122*38c7c9ddSAlexandre Mergnat MT8365_AFE_APLL2,
123*38c7c9ddSAlexandre Mergnat MT8365_AFE_APLL_NUM,
124*38c7c9ddSAlexandre Mergnat };
125*38c7c9ddSAlexandre Mergnat
126*38c7c9ddSAlexandre Mergnat enum {
127*38c7c9ddSAlexandre Mergnat MT8365_AFE_1ST_I2S = 0,
128*38c7c9ddSAlexandre Mergnat MT8365_AFE_2ND_I2S,
129*38c7c9ddSAlexandre Mergnat MT8365_AFE_I2S_SETS,
130*38c7c9ddSAlexandre Mergnat };
131*38c7c9ddSAlexandre Mergnat
132*38c7c9ddSAlexandre Mergnat enum {
133*38c7c9ddSAlexandre Mergnat MT8365_AFE_I2S_SEPARATE_CLOCK = 0,
134*38c7c9ddSAlexandre Mergnat MT8365_AFE_I2S_SHARED_CLOCK,
135*38c7c9ddSAlexandre Mergnat };
136*38c7c9ddSAlexandre Mergnat
137*38c7c9ddSAlexandre Mergnat enum {
138*38c7c9ddSAlexandre Mergnat MT8365_AFE_TDM_OUT_I2S = 0,
139*38c7c9ddSAlexandre Mergnat MT8365_AFE_TDM_OUT_TDM,
140*38c7c9ddSAlexandre Mergnat MT8365_AFE_TDM_OUT_I2S_32BITS,
141*38c7c9ddSAlexandre Mergnat };
142*38c7c9ddSAlexandre Mergnat
143*38c7c9ddSAlexandre Mergnat enum mt8365_afe_tdm_ch_start {
144*38c7c9ddSAlexandre Mergnat AFE_TDM_CH_START_O28_O29 = 0,
145*38c7c9ddSAlexandre Mergnat AFE_TDM_CH_START_O30_O31,
146*38c7c9ddSAlexandre Mergnat AFE_TDM_CH_START_O32_O33,
147*38c7c9ddSAlexandre Mergnat AFE_TDM_CH_START_O34_O35,
148*38c7c9ddSAlexandre Mergnat AFE_TDM_CH_ZERO,
149*38c7c9ddSAlexandre Mergnat };
150*38c7c9ddSAlexandre Mergnat
151*38c7c9ddSAlexandre Mergnat enum {
152*38c7c9ddSAlexandre Mergnat MT8365_PCM_FORMAT_I2S = 0,
153*38c7c9ddSAlexandre Mergnat MT8365_PCM_FORMAT_EIAJ,
154*38c7c9ddSAlexandre Mergnat MT8365_PCM_FORMAT_PCMA,
155*38c7c9ddSAlexandre Mergnat MT8365_PCM_FORMAT_PCMB,
156*38c7c9ddSAlexandre Mergnat };
157*38c7c9ddSAlexandre Mergnat
158*38c7c9ddSAlexandre Mergnat enum {
159*38c7c9ddSAlexandre Mergnat MT8365_FS_8K = 0,
160*38c7c9ddSAlexandre Mergnat MT8365_FS_11D025K,
161*38c7c9ddSAlexandre Mergnat MT8365_FS_12K,
162*38c7c9ddSAlexandre Mergnat MT8365_FS_384K,
163*38c7c9ddSAlexandre Mergnat MT8365_FS_16K,
164*38c7c9ddSAlexandre Mergnat MT8365_FS_22D05K,
165*38c7c9ddSAlexandre Mergnat MT8365_FS_24K,
166*38c7c9ddSAlexandre Mergnat MT8365_FS_130K,
167*38c7c9ddSAlexandre Mergnat MT8365_FS_32K,
168*38c7c9ddSAlexandre Mergnat MT8365_FS_44D1K,
169*38c7c9ddSAlexandre Mergnat MT8365_FS_48K,
170*38c7c9ddSAlexandre Mergnat MT8365_FS_88D2K,
171*38c7c9ddSAlexandre Mergnat MT8365_FS_96K,
172*38c7c9ddSAlexandre Mergnat MT8365_FS_176D4K,
173*38c7c9ddSAlexandre Mergnat MT8365_FS_192K,
174*38c7c9ddSAlexandre Mergnat };
175*38c7c9ddSAlexandre Mergnat
176*38c7c9ddSAlexandre Mergnat enum {
177*38c7c9ddSAlexandre Mergnat FS_8000HZ = 0, /* 0000b */
178*38c7c9ddSAlexandre Mergnat FS_11025HZ = 1, /* 0001b */
179*38c7c9ddSAlexandre Mergnat FS_12000HZ = 2, /* 0010b */
180*38c7c9ddSAlexandre Mergnat FS_384000HZ = 3, /* 0011b */
181*38c7c9ddSAlexandre Mergnat FS_16000HZ = 4, /* 0100b */
182*38c7c9ddSAlexandre Mergnat FS_22050HZ = 5, /* 0101b */
183*38c7c9ddSAlexandre Mergnat FS_24000HZ = 6, /* 0110b */
184*38c7c9ddSAlexandre Mergnat FS_130000HZ = 7, /* 0111b */
185*38c7c9ddSAlexandre Mergnat FS_32000HZ = 8, /* 1000b */
186*38c7c9ddSAlexandre Mergnat FS_44100HZ = 9, /* 1001b */
187*38c7c9ddSAlexandre Mergnat FS_48000HZ = 10, /* 1010b */
188*38c7c9ddSAlexandre Mergnat FS_88200HZ = 11, /* 1011b */
189*38c7c9ddSAlexandre Mergnat FS_96000HZ = 12, /* 1100b */
190*38c7c9ddSAlexandre Mergnat FS_176400HZ = 13, /* 1101b */
191*38c7c9ddSAlexandre Mergnat FS_192000HZ = 14, /* 1110b */
192*38c7c9ddSAlexandre Mergnat FS_260000HZ = 15, /* 1111b */
193*38c7c9ddSAlexandre Mergnat };
194*38c7c9ddSAlexandre Mergnat
195*38c7c9ddSAlexandre Mergnat enum {
196*38c7c9ddSAlexandre Mergnat MT8365_AFE_DEBUGFS_AFE,
197*38c7c9ddSAlexandre Mergnat MT8365_AFE_DEBUGFS_MEMIF,
198*38c7c9ddSAlexandre Mergnat MT8365_AFE_DEBUGFS_IRQ,
199*38c7c9ddSAlexandre Mergnat MT8365_AFE_DEBUGFS_CONN,
200*38c7c9ddSAlexandre Mergnat MT8365_AFE_DEBUGFS_DBG,
201*38c7c9ddSAlexandre Mergnat MT8365_AFE_DEBUGFS_NUM,
202*38c7c9ddSAlexandre Mergnat };
203*38c7c9ddSAlexandre Mergnat
204*38c7c9ddSAlexandre Mergnat enum {
205*38c7c9ddSAlexandre Mergnat MT8365_AFE_IRQ_DIR_MCU = 0,
206*38c7c9ddSAlexandre Mergnat MT8365_AFE_IRQ_DIR_DSP,
207*38c7c9ddSAlexandre Mergnat MT8365_AFE_IRQ_DIR_BOTH,
208*38c7c9ddSAlexandre Mergnat };
209*38c7c9ddSAlexandre Mergnat
210*38c7c9ddSAlexandre Mergnat /* MCLK */
211*38c7c9ddSAlexandre Mergnat enum {
212*38c7c9ddSAlexandre Mergnat MT8365_I2S0_MCK = 0,
213*38c7c9ddSAlexandre Mergnat MT8365_I2S3_MCK,
214*38c7c9ddSAlexandre Mergnat MT8365_MCK_NUM,
215*38c7c9ddSAlexandre Mergnat };
216*38c7c9ddSAlexandre Mergnat
217*38c7c9ddSAlexandre Mergnat struct mt8365_fe_dai_data {
218*38c7c9ddSAlexandre Mergnat bool use_sram;
219*38c7c9ddSAlexandre Mergnat unsigned int sram_phy_addr;
220*38c7c9ddSAlexandre Mergnat void __iomem *sram_vir_addr;
221*38c7c9ddSAlexandre Mergnat unsigned int sram_size;
222*38c7c9ddSAlexandre Mergnat };
223*38c7c9ddSAlexandre Mergnat
224*38c7c9ddSAlexandre Mergnat struct mt8365_be_dai_data {
225*38c7c9ddSAlexandre Mergnat bool prepared[SNDRV_PCM_STREAM_LAST + 1];
226*38c7c9ddSAlexandre Mergnat unsigned int fmt_mode;
227*38c7c9ddSAlexandre Mergnat };
228*38c7c9ddSAlexandre Mergnat
229*38c7c9ddSAlexandre Mergnat #define MT8365_CLK_26M 26000000
230*38c7c9ddSAlexandre Mergnat #define MT8365_CLK_24M 24000000
231*38c7c9ddSAlexandre Mergnat #define MT8365_CLK_22M 22000000
232*38c7c9ddSAlexandre Mergnat #define MT8365_CM_UPDATA_CNT_SET 8
233*38c7c9ddSAlexandre Mergnat
234*38c7c9ddSAlexandre Mergnat enum mt8365_cm_num {
235*38c7c9ddSAlexandre Mergnat MT8365_CM1 = 0,
236*38c7c9ddSAlexandre Mergnat MT8365_CM2,
237*38c7c9ddSAlexandre Mergnat MT8365_CM_NUM,
238*38c7c9ddSAlexandre Mergnat };
239*38c7c9ddSAlexandre Mergnat
240*38c7c9ddSAlexandre Mergnat enum mt8365_cm2_mux_in {
241*38c7c9ddSAlexandre Mergnat MT8365_FROM_GASRC1 = 1,
242*38c7c9ddSAlexandre Mergnat MT8365_FROM_GASRC2,
243*38c7c9ddSAlexandre Mergnat MT8365_FROM_TDM_ASRC,
244*38c7c9ddSAlexandre Mergnat MT8365_CM_MUX_NUM,
245*38c7c9ddSAlexandre Mergnat };
246*38c7c9ddSAlexandre Mergnat
247*38c7c9ddSAlexandre Mergnat enum cm2_mux_conn_in {
248*38c7c9ddSAlexandre Mergnat GENERAL2_ASRC_OUT_LCH = 0,
249*38c7c9ddSAlexandre Mergnat GENERAL2_ASRC_OUT_RCH = 1,
250*38c7c9ddSAlexandre Mergnat TDM_IN_CH0 = 2,
251*38c7c9ddSAlexandre Mergnat TDM_IN_CH1 = 3,
252*38c7c9ddSAlexandre Mergnat TDM_IN_CH2 = 4,
253*38c7c9ddSAlexandre Mergnat TDM_IN_CH3 = 5,
254*38c7c9ddSAlexandre Mergnat TDM_IN_CH4 = 6,
255*38c7c9ddSAlexandre Mergnat TDM_IN_CH5 = 7,
256*38c7c9ddSAlexandre Mergnat TDM_IN_CH6 = 8,
257*38c7c9ddSAlexandre Mergnat TDM_IN_CH7 = 9,
258*38c7c9ddSAlexandre Mergnat GENERAL1_ASRC_OUT_LCH = 10,
259*38c7c9ddSAlexandre Mergnat GENERAL1_ASRC_OUT_RCH = 11,
260*38c7c9ddSAlexandre Mergnat TDM_OUT_ASRC_CH0 = 12,
261*38c7c9ddSAlexandre Mergnat TDM_OUT_ASRC_CH1 = 13,
262*38c7c9ddSAlexandre Mergnat TDM_OUT_ASRC_CH2 = 14,
263*38c7c9ddSAlexandre Mergnat TDM_OUT_ASRC_CH3 = 15,
264*38c7c9ddSAlexandre Mergnat TDM_OUT_ASRC_CH4 = 16,
265*38c7c9ddSAlexandre Mergnat TDM_OUT_ASRC_CH5 = 17,
266*38c7c9ddSAlexandre Mergnat TDM_OUT_ASRC_CH6 = 18,
267*38c7c9ddSAlexandre Mergnat TDM_OUT_ASRC_CH7 = 19
268*38c7c9ddSAlexandre Mergnat };
269*38c7c9ddSAlexandre Mergnat
270*38c7c9ddSAlexandre Mergnat struct mt8365_cm_ctrl_reg {
271*38c7c9ddSAlexandre Mergnat unsigned int con0;
272*38c7c9ddSAlexandre Mergnat unsigned int con1;
273*38c7c9ddSAlexandre Mergnat unsigned int con2;
274*38c7c9ddSAlexandre Mergnat unsigned int con3;
275*38c7c9ddSAlexandre Mergnat unsigned int con4;
276*38c7c9ddSAlexandre Mergnat };
277*38c7c9ddSAlexandre Mergnat
278*38c7c9ddSAlexandre Mergnat struct mt8365_control_data {
279*38c7c9ddSAlexandre Mergnat bool bypass_cm1;
280*38c7c9ddSAlexandre Mergnat bool bypass_cm2;
281*38c7c9ddSAlexandre Mergnat unsigned int loopback_type;
282*38c7c9ddSAlexandre Mergnat };
283*38c7c9ddSAlexandre Mergnat
284*38c7c9ddSAlexandre Mergnat enum dmic_input_mode {
285*38c7c9ddSAlexandre Mergnat DMIC_MODE_3P25M = 0,
286*38c7c9ddSAlexandre Mergnat DMIC_MODE_1P625M,
287*38c7c9ddSAlexandre Mergnat DMIC_MODE_812P5K,
288*38c7c9ddSAlexandre Mergnat DMIC_MODE_406P25K,
289*38c7c9ddSAlexandre Mergnat };
290*38c7c9ddSAlexandre Mergnat
291*38c7c9ddSAlexandre Mergnat enum iir_mode {
292*38c7c9ddSAlexandre Mergnat IIR_MODE0 = 0,
293*38c7c9ddSAlexandre Mergnat IIR_MODE1,
294*38c7c9ddSAlexandre Mergnat IIR_MODE2,
295*38c7c9ddSAlexandre Mergnat IIR_MODE3,
296*38c7c9ddSAlexandre Mergnat IIR_MODE4,
297*38c7c9ddSAlexandre Mergnat IIR_MODE5,
298*38c7c9ddSAlexandre Mergnat };
299*38c7c9ddSAlexandre Mergnat
300*38c7c9ddSAlexandre Mergnat enum {
301*38c7c9ddSAlexandre Mergnat MT8365_GASRC1 = 0,
302*38c7c9ddSAlexandre Mergnat MT8365_GASRC2,
303*38c7c9ddSAlexandre Mergnat MT8365_GASRC_NUM,
304*38c7c9ddSAlexandre Mergnat MT8365_TDM_ASRC1 = MT8365_GASRC_NUM,
305*38c7c9ddSAlexandre Mergnat MT8365_TDM_ASRC2,
306*38c7c9ddSAlexandre Mergnat MT8365_TDM_ASRC3,
307*38c7c9ddSAlexandre Mergnat MT8365_TDM_ASRC4,
308*38c7c9ddSAlexandre Mergnat MT8365_TDM_ASRC_NUM,
309*38c7c9ddSAlexandre Mergnat };
310*38c7c9ddSAlexandre Mergnat
311*38c7c9ddSAlexandre Mergnat struct mt8365_gasrc_ctrl_reg {
312*38c7c9ddSAlexandre Mergnat unsigned int con0;
313*38c7c9ddSAlexandre Mergnat unsigned int con2;
314*38c7c9ddSAlexandre Mergnat unsigned int con3;
315*38c7c9ddSAlexandre Mergnat unsigned int con4;
316*38c7c9ddSAlexandre Mergnat unsigned int con5;
317*38c7c9ddSAlexandre Mergnat unsigned int con6;
318*38c7c9ddSAlexandre Mergnat unsigned int con9;
319*38c7c9ddSAlexandre Mergnat unsigned int con10;
320*38c7c9ddSAlexandre Mergnat unsigned int con12;
321*38c7c9ddSAlexandre Mergnat unsigned int con13;
322*38c7c9ddSAlexandre Mergnat };
323*38c7c9ddSAlexandre Mergnat
324*38c7c9ddSAlexandre Mergnat struct mt8365_gasrc_data {
325*38c7c9ddSAlexandre Mergnat bool duplex;
326*38c7c9ddSAlexandre Mergnat bool tx_mode;
327*38c7c9ddSAlexandre Mergnat bool cali_on;
328*38c7c9ddSAlexandre Mergnat bool tdm_asrc_out_cm2;
329*38c7c9ddSAlexandre Mergnat bool iir_on;
330*38c7c9ddSAlexandre Mergnat };
331*38c7c9ddSAlexandre Mergnat
332*38c7c9ddSAlexandre Mergnat struct mt8365_afe_private {
333*38c7c9ddSAlexandre Mergnat struct clk *clocks[MT8365_CLK_NUM];
334*38c7c9ddSAlexandre Mergnat struct regmap *topckgen;
335*38c7c9ddSAlexandre Mergnat struct mt8365_fe_dai_data fe_data[MT8365_AFE_MEMIF_NUM];
336*38c7c9ddSAlexandre Mergnat struct mt8365_be_dai_data be_data[MT8365_AFE_BACKEND_NUM];
337*38c7c9ddSAlexandre Mergnat struct mt8365_control_data ctrl_data;
338*38c7c9ddSAlexandre Mergnat struct mt8365_gasrc_data gasrc_data[MT8365_TDM_ASRC_NUM];
339*38c7c9ddSAlexandre Mergnat int afe_on_ref_cnt;
340*38c7c9ddSAlexandre Mergnat int top_cg_ref_cnt[MT8365_TOP_CG_NUM];
341*38c7c9ddSAlexandre Mergnat void __iomem *afe_sram_vir_addr;
342*38c7c9ddSAlexandre Mergnat unsigned int afe_sram_phy_addr;
343*38c7c9ddSAlexandre Mergnat unsigned int afe_sram_size;
344*38c7c9ddSAlexandre Mergnat /* locks */
345*38c7c9ddSAlexandre Mergnat spinlock_t afe_ctrl_lock;
346*38c7c9ddSAlexandre Mergnat struct mutex afe_clk_mutex; /* Protect & sync APLL TUNER registers access*/
347*38c7c9ddSAlexandre Mergnat #ifdef CONFIG_DEBUG_FS
348*38c7c9ddSAlexandre Mergnat struct dentry *debugfs_dentry[MT8365_AFE_DEBUGFS_NUM];
349*38c7c9ddSAlexandre Mergnat #endif
350*38c7c9ddSAlexandre Mergnat int apll_tuner_ref_cnt[MT8365_AFE_APLL_NUM];
351*38c7c9ddSAlexandre Mergnat unsigned int tdm_out_mode;
352*38c7c9ddSAlexandre Mergnat unsigned int cm2_mux_input;
353*38c7c9ddSAlexandre Mergnat
354*38c7c9ddSAlexandre Mergnat /* dai */
355*38c7c9ddSAlexandre Mergnat bool dai_on[MT8365_AFE_BACKEND_END];
356*38c7c9ddSAlexandre Mergnat void *dai_priv[MT8365_AFE_BACKEND_END];
357*38c7c9ddSAlexandre Mergnat };
358*38c7c9ddSAlexandre Mergnat
rx_frequency_palette(unsigned int fs)359*38c7c9ddSAlexandre Mergnat static inline u32 rx_frequency_palette(unsigned int fs)
360*38c7c9ddSAlexandre Mergnat {
361*38c7c9ddSAlexandre Mergnat /* *
362*38c7c9ddSAlexandre Mergnat * A = (26M / fs) * 64
363*38c7c9ddSAlexandre Mergnat * B = 8125 / A
364*38c7c9ddSAlexandre Mergnat * return = DEC2HEX(B * 2^23)
365*38c7c9ddSAlexandre Mergnat */
366*38c7c9ddSAlexandre Mergnat switch (fs) {
367*38c7c9ddSAlexandre Mergnat case FS_8000HZ: return 0x050000;
368*38c7c9ddSAlexandre Mergnat case FS_11025HZ: return 0x06E400;
369*38c7c9ddSAlexandre Mergnat case FS_12000HZ: return 0x078000;
370*38c7c9ddSAlexandre Mergnat case FS_16000HZ: return 0x0A0000;
371*38c7c9ddSAlexandre Mergnat case FS_22050HZ: return 0x0DC800;
372*38c7c9ddSAlexandre Mergnat case FS_24000HZ: return 0x0F0000;
373*38c7c9ddSAlexandre Mergnat case FS_32000HZ: return 0x140000;
374*38c7c9ddSAlexandre Mergnat case FS_44100HZ: return 0x1B9000;
375*38c7c9ddSAlexandre Mergnat case FS_48000HZ: return 0x1E0000;
376*38c7c9ddSAlexandre Mergnat case FS_88200HZ: return 0x372000;
377*38c7c9ddSAlexandre Mergnat case FS_96000HZ: return 0x3C0000;
378*38c7c9ddSAlexandre Mergnat case FS_176400HZ: return 0x6E4000;
379*38c7c9ddSAlexandre Mergnat case FS_192000HZ: return 0x780000;
380*38c7c9ddSAlexandre Mergnat default: return 0x0;
381*38c7c9ddSAlexandre Mergnat }
382*38c7c9ddSAlexandre Mergnat }
383*38c7c9ddSAlexandre Mergnat
AutoRstThHi(unsigned int fs)384*38c7c9ddSAlexandre Mergnat static inline u32 AutoRstThHi(unsigned int fs)
385*38c7c9ddSAlexandre Mergnat {
386*38c7c9ddSAlexandre Mergnat switch (fs) {
387*38c7c9ddSAlexandre Mergnat case FS_8000HZ: return 0x36000;
388*38c7c9ddSAlexandre Mergnat case FS_11025HZ: return 0x27000;
389*38c7c9ddSAlexandre Mergnat case FS_12000HZ: return 0x24000;
390*38c7c9ddSAlexandre Mergnat case FS_16000HZ: return 0x1B000;
391*38c7c9ddSAlexandre Mergnat case FS_22050HZ: return 0x14000;
392*38c7c9ddSAlexandre Mergnat case FS_24000HZ: return 0x12000;
393*38c7c9ddSAlexandre Mergnat case FS_32000HZ: return 0x0D800;
394*38c7c9ddSAlexandre Mergnat case FS_44100HZ: return 0x09D00;
395*38c7c9ddSAlexandre Mergnat case FS_48000HZ: return 0x08E00;
396*38c7c9ddSAlexandre Mergnat case FS_88200HZ: return 0x04E00;
397*38c7c9ddSAlexandre Mergnat case FS_96000HZ: return 0x04800;
398*38c7c9ddSAlexandre Mergnat case FS_176400HZ: return 0x02700;
399*38c7c9ddSAlexandre Mergnat case FS_192000HZ: return 0x02400;
400*38c7c9ddSAlexandre Mergnat default: return 0x0;
401*38c7c9ddSAlexandre Mergnat }
402*38c7c9ddSAlexandre Mergnat }
403*38c7c9ddSAlexandre Mergnat
AutoRstThLo(unsigned int fs)404*38c7c9ddSAlexandre Mergnat static inline u32 AutoRstThLo(unsigned int fs)
405*38c7c9ddSAlexandre Mergnat {
406*38c7c9ddSAlexandre Mergnat switch (fs) {
407*38c7c9ddSAlexandre Mergnat case FS_8000HZ: return 0x30000;
408*38c7c9ddSAlexandre Mergnat case FS_11025HZ: return 0x23000;
409*38c7c9ddSAlexandre Mergnat case FS_12000HZ: return 0x20000;
410*38c7c9ddSAlexandre Mergnat case FS_16000HZ: return 0x18000;
411*38c7c9ddSAlexandre Mergnat case FS_22050HZ: return 0x11000;
412*38c7c9ddSAlexandre Mergnat case FS_24000HZ: return 0x0FE00;
413*38c7c9ddSAlexandre Mergnat case FS_32000HZ: return 0x0BE00;
414*38c7c9ddSAlexandre Mergnat case FS_44100HZ: return 0x08A00;
415*38c7c9ddSAlexandre Mergnat case FS_48000HZ: return 0x07F00;
416*38c7c9ddSAlexandre Mergnat case FS_88200HZ: return 0x04500;
417*38c7c9ddSAlexandre Mergnat case FS_96000HZ: return 0x04000;
418*38c7c9ddSAlexandre Mergnat case FS_176400HZ: return 0x02300;
419*38c7c9ddSAlexandre Mergnat case FS_192000HZ: return 0x02000;
420*38c7c9ddSAlexandre Mergnat default: return 0x0;
421*38c7c9ddSAlexandre Mergnat }
422*38c7c9ddSAlexandre Mergnat }
423*38c7c9ddSAlexandre Mergnat
424*38c7c9ddSAlexandre Mergnat bool mt8365_afe_rate_supported(unsigned int rate, unsigned int id);
425*38c7c9ddSAlexandre Mergnat bool mt8365_afe_channel_supported(unsigned int channel, unsigned int id);
426*38c7c9ddSAlexandre Mergnat
427*38c7c9ddSAlexandre Mergnat int mt8365_dai_i2s_register(struct mtk_base_afe *afe);
428*38c7c9ddSAlexandre Mergnat int mt8365_dai_set_priv(struct mtk_base_afe *afe,
429*38c7c9ddSAlexandre Mergnat int id,
430*38c7c9ddSAlexandre Mergnat int priv_size,
431*38c7c9ddSAlexandre Mergnat const void *priv_data);
432*38c7c9ddSAlexandre Mergnat
433*38c7c9ddSAlexandre Mergnat int mt8365_afe_fs_timing(unsigned int rate);
434*38c7c9ddSAlexandre Mergnat
435*38c7c9ddSAlexandre Mergnat void mt8365_afe_set_i2s_out_enable(struct mtk_base_afe *afe, bool enable);
436*38c7c9ddSAlexandre Mergnat int mt8365_afe_set_i2s_out(struct mtk_base_afe *afe, unsigned int rate, int bit_width);
437*38c7c9ddSAlexandre Mergnat
438*38c7c9ddSAlexandre Mergnat int mt8365_dai_adda_register(struct mtk_base_afe *afe);
439*38c7c9ddSAlexandre Mergnat int mt8365_dai_enable_adda_on(struct mtk_base_afe *afe);
440*38c7c9ddSAlexandre Mergnat int mt8365_dai_disable_adda_on(struct mtk_base_afe *afe);
441*38c7c9ddSAlexandre Mergnat
442*38c7c9ddSAlexandre Mergnat int mt8365_dai_dmic_register(struct mtk_base_afe *afe);
443*38c7c9ddSAlexandre Mergnat
444*38c7c9ddSAlexandre Mergnat int mt8365_dai_pcm_register(struct mtk_base_afe *afe);
445*38c7c9ddSAlexandre Mergnat
446*38c7c9ddSAlexandre Mergnat int mt8365_dai_tdm_register(struct mtk_base_afe *afe);
447*38c7c9ddSAlexandre Mergnat
448*38c7c9ddSAlexandre Mergnat #endif
449