xref: /linux/sound/soc/fsl/fsl_micfil.h (revision 3b13b1437dcce4469db575c60d1da4fa9ff80694)
147a70e6fSCosmin Samoila /* SPDX-License-Identifier: GPL-2.0 */
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
2747a70e6fSCosmin Samoila #define REG_MICFIL_VAD0_CTRL1		0x90
2847a70e6fSCosmin Samoila #define REG_MICFIL_VAD0_CTRL2		0x94
2947a70e6fSCosmin Samoila #define REG_MICFIL_VAD0_STAT		0x98
3047a70e6fSCosmin Samoila #define REG_MICFIL_VAD0_SCONFIG		0x9C
3147a70e6fSCosmin Samoila #define REG_MICFIL_VAD0_NCONFIG		0xA0
3247a70e6fSCosmin Samoila #define REG_MICFIL_VAD0_NDATA		0xA4
3347a70e6fSCosmin Samoila #define REG_MICFIL_VAD0_ZCD		0xA8
3447a70e6fSCosmin Samoila 
3547a70e6fSCosmin Samoila /* MICFIL Control Register 1 -- REG_MICFILL_CTRL1 0x00 */
36bd2cffd1SSascha Hauer #define MICFIL_CTRL1_MDIS		BIT(31)
37bd2cffd1SSascha Hauer #define MICFIL_CTRL1_DOZEN		BIT(30)
38bd2cffd1SSascha Hauer #define MICFIL_CTRL1_PDMIEN		BIT(29)
39bd2cffd1SSascha Hauer #define MICFIL_CTRL1_DBG		BIT(28)
40bd2cffd1SSascha Hauer #define MICFIL_CTRL1_SRES		BIT(27)
41bd2cffd1SSascha Hauer #define MICFIL_CTRL1_DBGE		BIT(26)
4217f2142bSSascha Hauer 
4317f2142bSSascha Hauer #define MICFIL_CTRL1_DISEL_DISABLE	0
4417f2142bSSascha Hauer #define MICFIL_CTRL1_DISEL_DMA		1
4517f2142bSSascha Hauer #define MICFIL_CTRL1_DISEL_IRQ		2
4617f2142bSSascha Hauer #define MICFIL_CTRL1_DISEL		GENMASK(25, 24)
47bd2cffd1SSascha Hauer #define MICFIL_CTRL1_ERREN		BIT(23)
4817f2142bSSascha Hauer #define MICFIL_CTRL1_CHEN(ch)		BIT(ch)
4947a70e6fSCosmin Samoila 
5047a70e6fSCosmin Samoila /* MICFIL Control Register 2 -- REG_MICFILL_CTRL2 0x04 */
5147a70e6fSCosmin Samoila #define MICFIL_CTRL2_QSEL_SHIFT		25
5217f2142bSSascha Hauer #define MICFIL_CTRL2_QSEL		GENMASK(27, 25)
5317f2142bSSascha Hauer #define MICFIL_QSEL_MEDIUM_QUALITY	0
5417f2142bSSascha Hauer #define MICFIL_QSEL_HIGH_QUALITY	1
5517f2142bSSascha Hauer #define MICFIL_QSEL_LOW_QUALITY		7
5617f2142bSSascha Hauer #define MICFIL_QSEL_VLOW0_QUALITY	6
5717f2142bSSascha Hauer #define MICFIL_QSEL_VLOW1_QUALITY	5
5817f2142bSSascha Hauer #define MICFIL_QSEL_VLOW2_QUALITY	4
5947a70e6fSCosmin Samoila 
6017f2142bSSascha Hauer #define MICFIL_CTRL2_CICOSR		GENMASK(19, 16)
6117f2142bSSascha Hauer #define MICFIL_CTRL2_CLKDIV		GENMASK(7, 0)
6247a70e6fSCosmin Samoila 
6347a70e6fSCosmin Samoila /* MICFIL Status Register -- REG_MICFIL_STAT 0x08 */
64bd2cffd1SSascha Hauer #define MICFIL_STAT_BSY_FIL		BIT(31)
65bd2cffd1SSascha Hauer #define MICFIL_STAT_FIR_RDY		BIT(30)
66bd2cffd1SSascha Hauer #define MICFIL_STAT_LOWFREQF		BIT(29)
6717f2142bSSascha Hauer #define MICFIL_STAT_CHXF(ch)		BIT(ch)
6847a70e6fSCosmin Samoila 
6947a70e6fSCosmin Samoila /* MICFIL FIFO Control Register -- REG_MICFIL_FIFO_CTRL 0x10 */
7017f2142bSSascha Hauer #define MICFIL_FIFO_CTRL_FIFOWMK	GENMASK(2, 0)
7147a70e6fSCosmin Samoila 
7247a70e6fSCosmin Samoila /* MICFIL FIFO Status Register -- REG_MICFIL_FIFO_STAT 0x14 */
7317f2142bSSascha Hauer #define MICFIL_FIFO_STAT_FIFOX_OVER(ch)	BIT(ch)
7417f2142bSSascha Hauer #define MICFIL_FIFO_STAT_FIFOX_UNDER(ch)	BIT((ch) + 8)
7547a70e6fSCosmin Samoila 
76*3b13b143SShengjiu Wang /* MICFIL DC Remover Control Register -- REG_MICFIL_DC_CTRL */
77*3b13b143SShengjiu Wang #define MICFIL_DC_CTRL_CONFIG          GENMASK(15, 0)
78*3b13b143SShengjiu Wang #define MICFIL_DC_CHX_SHIFT(ch)        ((ch) << 1)
79*3b13b143SShengjiu Wang #define MICFIL_DC_CHX(ch)              GENMASK((((ch) << 1) + 1), ((ch) << 1))
80*3b13b143SShengjiu Wang #define MICFIL_DC_CUTOFF_21HZ          0
81*3b13b143SShengjiu Wang #define MICFIL_DC_CUTOFF_83HZ          1
82*3b13b143SShengjiu Wang #define MICFIL_DC_CUTOFF_152Hz         2
83*3b13b143SShengjiu Wang #define MICFIL_DC_BYPASS               3
84*3b13b143SShengjiu Wang 
8547a70e6fSCosmin Samoila /* MICFIL HWVAD0 Control 1 Register -- REG_MICFIL_VAD0_CTRL1*/
86101b096bSShengjiu Wang #define MICFIL_VAD0_CTRL1_CHSEL		GENMASK(26, 24)
87101b096bSShengjiu Wang #define MICFIL_VAD0_CTRL1_CICOSR	GENMASK(19, 16)
88101b096bSShengjiu Wang #define MICFIL_VAD0_CTRL1_INITT		GENMASK(12, 8)
89bd2cffd1SSascha Hauer #define MICFIL_VAD0_CTRL1_ST10		BIT(4)
90bd2cffd1SSascha Hauer #define MICFIL_VAD0_CTRL1_ERIE		BIT(3)
91bd2cffd1SSascha Hauer #define MICFIL_VAD0_CTRL1_IE		BIT(2)
92bd2cffd1SSascha Hauer #define MICFIL_VAD0_CTRL1_RST		BIT(1)
93bd2cffd1SSascha Hauer #define MICFIL_VAD0_CTRL1_EN		BIT(0)
9447a70e6fSCosmin Samoila 
9547a70e6fSCosmin Samoila /* MICFIL HWVAD0 Control 2 Register -- REG_MICFIL_VAD0_CTRL2*/
96bd2cffd1SSascha Hauer #define MICFIL_VAD0_CTRL2_FRENDIS	BIT(31)
97bd2cffd1SSascha Hauer #define MICFIL_VAD0_CTRL2_PREFEN	BIT(30)
98bd2cffd1SSascha Hauer #define MICFIL_VAD0_CTRL2_FOUTDIS	BIT(28)
9917f2142bSSascha Hauer #define MICFIL_VAD0_CTRL2_FRAMET	GENMASK(21, 16)
10017f2142bSSascha Hauer #define MICFIL_VAD0_CTRL2_INPGAIN	GENMASK(11, 8)
10117f2142bSSascha Hauer #define MICFIL_VAD0_CTRL2_HPF		GENMASK(1, 0)
10247a70e6fSCosmin Samoila 
10347a70e6fSCosmin Samoila /* MICFIL HWVAD0 Signal CONFIG Register -- REG_MICFIL_VAD0_SCONFIG */
104bd2cffd1SSascha Hauer #define MICFIL_VAD0_SCONFIG_SFILEN		BIT(31)
105bd2cffd1SSascha Hauer #define MICFIL_VAD0_SCONFIG_SMAXEN		BIT(30)
10617f2142bSSascha Hauer #define MICFIL_VAD0_SCONFIG_SGAIN		GENMASK(3, 0)
10747a70e6fSCosmin Samoila 
10847a70e6fSCosmin Samoila /* MICFIL HWVAD0 Noise CONFIG Register -- REG_MICFIL_VAD0_NCONFIG */
109bd2cffd1SSascha Hauer #define MICFIL_VAD0_NCONFIG_NFILAUT		BIT(31)
110bd2cffd1SSascha Hauer #define MICFIL_VAD0_NCONFIG_NMINEN		BIT(30)
111bd2cffd1SSascha Hauer #define MICFIL_VAD0_NCONFIG_NDECEN		BIT(29)
112bd2cffd1SSascha Hauer #define MICFIL_VAD0_NCONFIG_NOREN		BIT(28)
11317f2142bSSascha Hauer #define MICFIL_VAD0_NCONFIG_NFILADJ		GENMASK(12, 8)
11417f2142bSSascha Hauer #define MICFIL_VAD0_NCONFIG_NGAIN		GENMASK(3, 0)
11547a70e6fSCosmin Samoila 
11647a70e6fSCosmin Samoila /* MICFIL HWVAD0 Zero-Crossing Detector - REG_MICFIL_VAD0_ZCD */
11717f2142bSSascha Hauer #define MICFIL_VAD0_ZCD_ZCDTH		GENMASK(25, 16)
118101b096bSShengjiu Wang #define MICFIL_VAD0_ZCD_ZCDADJ		GENMASK(11, 8)
119bd2cffd1SSascha Hauer #define MICFIL_VAD0_ZCD_ZCDAND		BIT(4)
120bd2cffd1SSascha Hauer #define MICFIL_VAD0_ZCD_ZCDAUT		BIT(2)
121bd2cffd1SSascha Hauer #define MICFIL_VAD0_ZCD_ZCDEN		BIT(0)
12247a70e6fSCosmin Samoila 
12347a70e6fSCosmin Samoila /* MICFIL HWVAD0 Status Register - REG_MICFIL_VAD0_STAT */
124bd2cffd1SSascha Hauer #define MICFIL_VAD0_STAT_INITF		BIT(31)
125bd2cffd1SSascha Hauer #define MICFIL_VAD0_STAT_INSATF		BIT(16)
126bd2cffd1SSascha Hauer #define MICFIL_VAD0_STAT_EF		BIT(15)
127bd2cffd1SSascha Hauer #define MICFIL_VAD0_STAT_IF		BIT(0)
12847a70e6fSCosmin Samoila 
12947a70e6fSCosmin Samoila /* MICFIL Output Control Register */
13047a70e6fSCosmin Samoila #define MICFIL_OUTGAIN_CHX_SHIFT(v)	(4 * (v))
13147a70e6fSCosmin Samoila 
13247a70e6fSCosmin Samoila /* Constants */
13347a70e6fSCosmin Samoila #define MICFIL_OUTPUT_CHANNELS		8
13447a70e6fSCosmin Samoila #define MICFIL_FIFO_NUM			8
13547a70e6fSCosmin Samoila 
13647a70e6fSCosmin Samoila #define FIFO_PTRWID			3
13747a70e6fSCosmin Samoila #define FIFO_LEN			BIT(FIFO_PTRWID)
13847a70e6fSCosmin Samoila 
13947a70e6fSCosmin Samoila #define MICFIL_IRQ_LINES		2
14047a70e6fSCosmin Samoila #define MICFIL_MAX_RETRY		25
14147a70e6fSCosmin Samoila #define MICFIL_SLEEP_MIN		90000 /* in us */
14247a70e6fSCosmin Samoila #define MICFIL_SLEEP_MAX		100000 /* in us */
14347a70e6fSCosmin Samoila #define MICFIL_DMA_MAXBURST_RX		6
14447a70e6fSCosmin Samoila 
14547a70e6fSCosmin Samoila #endif /* _FSL_MICFIL_H */
146