xref: /linux/sound/soc/fsl/fsl_micfil.h (revision 4ddd51ccff911a2e9e961307692532a325f6c78a)
1f803ec63SDaniel Baluta /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
247a70e6fSCosmin Samoila /*
347a70e6fSCosmin Samoila  * PDM Microphone Interface for the NXP i.MX SoC
447a70e6fSCosmin Samoila  * Copyright 2018 NXP
547a70e6fSCosmin Samoila  */
647a70e6fSCosmin Samoila 
747a70e6fSCosmin Samoila #ifndef _FSL_MICFIL_H
847a70e6fSCosmin Samoila #define _FSL_MICFIL_H
947a70e6fSCosmin Samoila 
1047a70e6fSCosmin Samoila /* MICFIL Register Map */
1147a70e6fSCosmin Samoila #define REG_MICFIL_CTRL1		0x00
1247a70e6fSCosmin Samoila #define REG_MICFIL_CTRL2		0x04
1347a70e6fSCosmin Samoila #define REG_MICFIL_STAT			0x08
1447a70e6fSCosmin Samoila #define REG_MICFIL_FIFO_CTRL		0x10
1547a70e6fSCosmin Samoila #define REG_MICFIL_FIFO_STAT		0x14
1647a70e6fSCosmin Samoila #define REG_MICFIL_DATACH0		0x24
1747a70e6fSCosmin Samoila #define REG_MICFIL_DATACH1		0x28
1847a70e6fSCosmin Samoila #define REG_MICFIL_DATACH2		0x2C
1947a70e6fSCosmin Samoila #define REG_MICFIL_DATACH3		0x30
2047a70e6fSCosmin Samoila #define REG_MICFIL_DATACH4		0x34
2147a70e6fSCosmin Samoila #define REG_MICFIL_DATACH5		0x38
2247a70e6fSCosmin Samoila #define REG_MICFIL_DATACH6		0x3C
2347a70e6fSCosmin Samoila #define REG_MICFIL_DATACH7		0x40
2447a70e6fSCosmin Samoila #define REG_MICFIL_DC_CTRL		0x64
2547a70e6fSCosmin Samoila #define REG_MICFIL_OUT_CTRL		0x74
2647a70e6fSCosmin Samoila #define REG_MICFIL_OUT_STAT		0x7C
2751d765f7SChancel Liu #define REG_MICFIL_FSYNC_CTRL		0x80
2851d765f7SChancel Liu #define REG_MICFIL_VERID		0x84
2951d765f7SChancel Liu #define REG_MICFIL_PARAM		0x88
3047a70e6fSCosmin Samoila #define REG_MICFIL_VAD0_CTRL1		0x90
3147a70e6fSCosmin Samoila #define REG_MICFIL_VAD0_CTRL2		0x94
3247a70e6fSCosmin Samoila #define REG_MICFIL_VAD0_STAT		0x98
3347a70e6fSCosmin Samoila #define REG_MICFIL_VAD0_SCONFIG		0x9C
3447a70e6fSCosmin Samoila #define REG_MICFIL_VAD0_NCONFIG		0xA0
3547a70e6fSCosmin Samoila #define REG_MICFIL_VAD0_NDATA		0xA4
3647a70e6fSCosmin Samoila #define REG_MICFIL_VAD0_ZCD		0xA8
3747a70e6fSCosmin Samoila 
3847a70e6fSCosmin Samoila /* MICFIL Control Register 1 -- REG_MICFILL_CTRL1 0x00 */
39bd2cffd1SSascha Hauer #define MICFIL_CTRL1_MDIS		BIT(31)
40bd2cffd1SSascha Hauer #define MICFIL_CTRL1_DOZEN		BIT(30)
41bd2cffd1SSascha Hauer #define MICFIL_CTRL1_PDMIEN		BIT(29)
42bd2cffd1SSascha Hauer #define MICFIL_CTRL1_DBG		BIT(28)
43bd2cffd1SSascha Hauer #define MICFIL_CTRL1_SRES		BIT(27)
44bd2cffd1SSascha Hauer #define MICFIL_CTRL1_DBGE		BIT(26)
4551d765f7SChancel Liu #define MICFIL_CTRL1_DECFILS		BIT(20)
4651d765f7SChancel Liu #define MICFIL_CTRL1_FSYNCEN		BIT(16)
4717f2142bSSascha Hauer 
4817f2142bSSascha Hauer #define MICFIL_CTRL1_DISEL_DISABLE	0
4917f2142bSSascha Hauer #define MICFIL_CTRL1_DISEL_DMA		1
5017f2142bSSascha Hauer #define MICFIL_CTRL1_DISEL_IRQ		2
5117f2142bSSascha Hauer #define MICFIL_CTRL1_DISEL		GENMASK(25, 24)
52bd2cffd1SSascha Hauer #define MICFIL_CTRL1_ERREN		BIT(23)
5317f2142bSSascha Hauer #define MICFIL_CTRL1_CHEN(ch)		BIT(ch)
5447a70e6fSCosmin Samoila 
5547a70e6fSCosmin Samoila /* MICFIL Control Register 2 -- REG_MICFILL_CTRL2 0x04 */
5647a70e6fSCosmin Samoila #define MICFIL_CTRL2_QSEL_SHIFT		25
5717f2142bSSascha Hauer #define MICFIL_CTRL2_QSEL		GENMASK(27, 25)
5817f2142bSSascha Hauer #define MICFIL_QSEL_MEDIUM_QUALITY	0
5917f2142bSSascha Hauer #define MICFIL_QSEL_HIGH_QUALITY	1
6017f2142bSSascha Hauer #define MICFIL_QSEL_LOW_QUALITY		7
6117f2142bSSascha Hauer #define MICFIL_QSEL_VLOW0_QUALITY	6
6217f2142bSSascha Hauer #define MICFIL_QSEL_VLOW1_QUALITY	5
6317f2142bSSascha Hauer #define MICFIL_QSEL_VLOW2_QUALITY	4
6447a70e6fSCosmin Samoila 
6517f2142bSSascha Hauer #define MICFIL_CTRL2_CICOSR		GENMASK(19, 16)
6617f2142bSSascha Hauer #define MICFIL_CTRL2_CLKDIV		GENMASK(7, 0)
6747a70e6fSCosmin Samoila 
6847a70e6fSCosmin Samoila /* MICFIL Status Register -- REG_MICFIL_STAT 0x08 */
69bd2cffd1SSascha Hauer #define MICFIL_STAT_BSY_FIL		BIT(31)
70bd2cffd1SSascha Hauer #define MICFIL_STAT_FIR_RDY		BIT(30)
71bd2cffd1SSascha Hauer #define MICFIL_STAT_LOWFREQF		BIT(29)
7217f2142bSSascha Hauer #define MICFIL_STAT_CHXF(ch)		BIT(ch)
7347a70e6fSCosmin Samoila 
7447a70e6fSCosmin Samoila /* MICFIL FIFO Control Register -- REG_MICFIL_FIFO_CTRL 0x10 */
75*4ddd51ccSShengjiu Wang #define MICFIL_FIFO_CTRL_FIFOWMK	GENMASK(4, 0)
7647a70e6fSCosmin Samoila 
7747a70e6fSCosmin Samoila /* MICFIL FIFO Status Register -- REG_MICFIL_FIFO_STAT 0x14 */
7817f2142bSSascha Hauer #define MICFIL_FIFO_STAT_FIFOX_OVER(ch)	BIT(ch)
7917f2142bSSascha Hauer #define MICFIL_FIFO_STAT_FIFOX_UNDER(ch)	BIT((ch) + 8)
8047a70e6fSCosmin Samoila 
813b13b143SShengjiu Wang /* MICFIL DC Remover Control Register -- REG_MICFIL_DC_CTRL */
823b13b143SShengjiu Wang #define MICFIL_DC_CTRL_CONFIG          GENMASK(15, 0)
833b13b143SShengjiu Wang #define MICFIL_DC_CHX_SHIFT(ch)        ((ch) << 1)
843b13b143SShengjiu Wang #define MICFIL_DC_CHX(ch)              GENMASK((((ch) << 1) + 1), ((ch) << 1))
853b13b143SShengjiu Wang #define MICFIL_DC_CUTOFF_21HZ          0
863b13b143SShengjiu Wang #define MICFIL_DC_CUTOFF_83HZ          1
873b13b143SShengjiu Wang #define MICFIL_DC_CUTOFF_152Hz         2
883b13b143SShengjiu Wang #define MICFIL_DC_BYPASS               3
893b13b143SShengjiu Wang 
9051d765f7SChancel Liu /* MICFIL VERID Register -- REG_MICFIL_VERID */
9151d765f7SChancel Liu #define MICFIL_VERID_MAJOR_SHIFT        24
9251d765f7SChancel Liu #define MICFIL_VERID_MAJOR_MASK         GENMASK(31, 24)
9351d765f7SChancel Liu #define MICFIL_VERID_MINOR_SHIFT        16
9451d765f7SChancel Liu #define MICFIL_VERID_MINOR_MASK         GENMASK(23, 16)
9551d765f7SChancel Liu #define MICFIL_VERID_FEATURE_SHIFT      0
9651d765f7SChancel Liu #define MICFIL_VERID_FEATURE_MASK       GENMASK(15, 0)
9751d765f7SChancel Liu 
9851d765f7SChancel Liu /* MICFIL PARAM Register -- REG_MICFIL_PARAM */
9951d765f7SChancel Liu #define MICFIL_PARAM_NUM_HWVAD_SHIFT    24
10051d765f7SChancel Liu #define MICFIL_PARAM_NUM_HWVAD_MASK     GENMASK(27, 24)
10151d765f7SChancel Liu #define MICFIL_PARAM_HWVAD_ZCD          BIT(19)
10251d765f7SChancel Liu #define MICFIL_PARAM_HWVAD_ENERGY_MODE  BIT(17)
10351d765f7SChancel Liu #define MICFIL_PARAM_HWVAD              BIT(16)
10451d765f7SChancel Liu #define MICFIL_PARAM_DC_OUT_BYPASS      BIT(11)
10551d765f7SChancel Liu #define MICFIL_PARAM_DC_IN_BYPASS       BIT(10)
10651d765f7SChancel Liu #define MICFIL_PARAM_LOW_POWER          BIT(9)
10751d765f7SChancel Liu #define MICFIL_PARAM_FIL_OUT_WIDTH      BIT(8)
10851d765f7SChancel Liu #define MICFIL_PARAM_FIFO_PTRWID_SHIFT  4
10951d765f7SChancel Liu #define MICFIL_PARAM_FIFO_PTRWID_MASK   GENMASK(7, 4)
11051d765f7SChancel Liu #define MICFIL_PARAM_NPAIR_SHIFT        0
11151d765f7SChancel Liu #define MICFIL_PARAM_NPAIR_MASK         GENMASK(3, 0)
11251d765f7SChancel Liu 
11347a70e6fSCosmin Samoila /* MICFIL HWVAD0 Control 1 Register -- REG_MICFIL_VAD0_CTRL1*/
114101b096bSShengjiu Wang #define MICFIL_VAD0_CTRL1_CHSEL		GENMASK(26, 24)
115101b096bSShengjiu Wang #define MICFIL_VAD0_CTRL1_CICOSR	GENMASK(19, 16)
116101b096bSShengjiu Wang #define MICFIL_VAD0_CTRL1_INITT		GENMASK(12, 8)
117bd2cffd1SSascha Hauer #define MICFIL_VAD0_CTRL1_ST10		BIT(4)
118bd2cffd1SSascha Hauer #define MICFIL_VAD0_CTRL1_ERIE		BIT(3)
119bd2cffd1SSascha Hauer #define MICFIL_VAD0_CTRL1_IE		BIT(2)
120bd2cffd1SSascha Hauer #define MICFIL_VAD0_CTRL1_RST		BIT(1)
121bd2cffd1SSascha Hauer #define MICFIL_VAD0_CTRL1_EN		BIT(0)
12247a70e6fSCosmin Samoila 
12347a70e6fSCosmin Samoila /* MICFIL HWVAD0 Control 2 Register -- REG_MICFIL_VAD0_CTRL2*/
124bd2cffd1SSascha Hauer #define MICFIL_VAD0_CTRL2_FRENDIS	BIT(31)
125bd2cffd1SSascha Hauer #define MICFIL_VAD0_CTRL2_PREFEN	BIT(30)
126bd2cffd1SSascha Hauer #define MICFIL_VAD0_CTRL2_FOUTDIS	BIT(28)
12717f2142bSSascha Hauer #define MICFIL_VAD0_CTRL2_FRAMET	GENMASK(21, 16)
12817f2142bSSascha Hauer #define MICFIL_VAD0_CTRL2_INPGAIN	GENMASK(11, 8)
12917f2142bSSascha Hauer #define MICFIL_VAD0_CTRL2_HPF		GENMASK(1, 0)
13047a70e6fSCosmin Samoila 
13147a70e6fSCosmin Samoila /* MICFIL HWVAD0 Signal CONFIG Register -- REG_MICFIL_VAD0_SCONFIG */
132bd2cffd1SSascha Hauer #define MICFIL_VAD0_SCONFIG_SFILEN		BIT(31)
133bd2cffd1SSascha Hauer #define MICFIL_VAD0_SCONFIG_SMAXEN		BIT(30)
13417f2142bSSascha Hauer #define MICFIL_VAD0_SCONFIG_SGAIN		GENMASK(3, 0)
13547a70e6fSCosmin Samoila 
13647a70e6fSCosmin Samoila /* MICFIL HWVAD0 Noise CONFIG Register -- REG_MICFIL_VAD0_NCONFIG */
137bd2cffd1SSascha Hauer #define MICFIL_VAD0_NCONFIG_NFILAUT		BIT(31)
138bd2cffd1SSascha Hauer #define MICFIL_VAD0_NCONFIG_NMINEN		BIT(30)
139bd2cffd1SSascha Hauer #define MICFIL_VAD0_NCONFIG_NDECEN		BIT(29)
140bd2cffd1SSascha Hauer #define MICFIL_VAD0_NCONFIG_NOREN		BIT(28)
14117f2142bSSascha Hauer #define MICFIL_VAD0_NCONFIG_NFILADJ		GENMASK(12, 8)
14217f2142bSSascha Hauer #define MICFIL_VAD0_NCONFIG_NGAIN		GENMASK(3, 0)
14347a70e6fSCosmin Samoila 
14447a70e6fSCosmin Samoila /* MICFIL HWVAD0 Zero-Crossing Detector - REG_MICFIL_VAD0_ZCD */
14517f2142bSSascha Hauer #define MICFIL_VAD0_ZCD_ZCDTH		GENMASK(25, 16)
146101b096bSShengjiu Wang #define MICFIL_VAD0_ZCD_ZCDADJ		GENMASK(11, 8)
147bd2cffd1SSascha Hauer #define MICFIL_VAD0_ZCD_ZCDAND		BIT(4)
148bd2cffd1SSascha Hauer #define MICFIL_VAD0_ZCD_ZCDAUT		BIT(2)
149bd2cffd1SSascha Hauer #define MICFIL_VAD0_ZCD_ZCDEN		BIT(0)
15047a70e6fSCosmin Samoila 
15147a70e6fSCosmin Samoila /* MICFIL HWVAD0 Status Register - REG_MICFIL_VAD0_STAT */
152bd2cffd1SSascha Hauer #define MICFIL_VAD0_STAT_INITF		BIT(31)
153bd2cffd1SSascha Hauer #define MICFIL_VAD0_STAT_INSATF		BIT(16)
154bd2cffd1SSascha Hauer #define MICFIL_VAD0_STAT_EF		BIT(15)
155bd2cffd1SSascha Hauer #define MICFIL_VAD0_STAT_IF		BIT(0)
15647a70e6fSCosmin Samoila 
15747a70e6fSCosmin Samoila /* MICFIL Output Control Register */
15847a70e6fSCosmin Samoila #define MICFIL_OUTGAIN_CHX_SHIFT(v)	(4 * (v))
15947a70e6fSCosmin Samoila 
16047a70e6fSCosmin Samoila /* Constants */
16147a70e6fSCosmin Samoila #define MICFIL_OUTPUT_CHANNELS		8
16247a70e6fSCosmin Samoila #define MICFIL_FIFO_NUM			8
16347a70e6fSCosmin Samoila 
16447a70e6fSCosmin Samoila #define FIFO_PTRWID			3
16547a70e6fSCosmin Samoila #define FIFO_LEN			BIT(FIFO_PTRWID)
16647a70e6fSCosmin Samoila 
16729dbfeecSShengjiu Wang #define MICFIL_IRQ_LINES		4
16847a70e6fSCosmin Samoila #define MICFIL_MAX_RETRY		25
16947a70e6fSCosmin Samoila #define MICFIL_SLEEP_MIN		90000 /* in us */
17047a70e6fSCosmin Samoila #define MICFIL_SLEEP_MAX		100000 /* in us */
17147a70e6fSCosmin Samoila #define MICFIL_DMA_MAXBURST_RX		6
17247a70e6fSCosmin Samoila 
17329dbfeecSShengjiu Wang /* HWVAD Constants */
17429dbfeecSShengjiu Wang #define MICFIL_HWVAD_ENVELOPE_MODE	0
17529dbfeecSShengjiu Wang #define MICFIL_HWVAD_ENERGY_MODE	1
17629dbfeecSShengjiu Wang 
17736736505SChancel Liu /**
17836736505SChancel Liu  * struct fsl_micfil_verid - version id data
17936736505SChancel Liu  * @version: version number
18036736505SChancel Liu  * @feature: feature specification number
18136736505SChancel Liu  */
18236736505SChancel Liu struct fsl_micfil_verid {
18336736505SChancel Liu 	u32 version;
18436736505SChancel Liu 	u32 feature;
18536736505SChancel Liu };
18636736505SChancel Liu 
18736736505SChancel Liu /**
18836736505SChancel Liu  * struct fsl_micfil_param - parameter data
18936736505SChancel Liu  * @hwvad_num: the number of HWVADs
19036736505SChancel Liu  * @hwvad_zcd: HWVAD zero-cross detector is active
19136736505SChancel Liu  * @hwvad_energy_mode: HWVAD energy mode is active
19236736505SChancel Liu  * @hwvad: HWVAD is active
19336736505SChancel Liu  * @dc_out_bypass: points out if the output DC remover is disabled
19436736505SChancel Liu  * @dc_in_bypass: points out if the input DC remover is disabled
19536736505SChancel Liu  * @low_power: low power decimation filter
19636736505SChancel Liu  * @fil_out_width: filter output width
19736736505SChancel Liu  * @fifo_ptrwid: FIFO pointer width
19836736505SChancel Liu  * @npair: number of microphone pairs
19936736505SChancel Liu  */
20036736505SChancel Liu struct fsl_micfil_param {
20136736505SChancel Liu 	u32 hwvad_num;
20236736505SChancel Liu 	bool hwvad_zcd;
20336736505SChancel Liu 	bool hwvad_energy_mode;
20436736505SChancel Liu 	bool hwvad;
20536736505SChancel Liu 	bool dc_out_bypass;
20636736505SChancel Liu 	bool dc_in_bypass;
20736736505SChancel Liu 	bool low_power;
20836736505SChancel Liu 	bool fil_out_width;
20936736505SChancel Liu 	u32 fifo_ptrwid;
21036736505SChancel Liu 	u32 npair;
21136736505SChancel Liu };
21236736505SChancel Liu 
21347a70e6fSCosmin Samoila #endif /* _FSL_MICFIL_H */
214