162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * PDM Microphone Interface for the NXP i.MX SoC
462306a36Sopenharmony_ci * Copyright 2018 NXP
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#ifndef _FSL_MICFIL_H
862306a36Sopenharmony_ci#define _FSL_MICFIL_H
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci/* MICFIL Register Map */
1162306a36Sopenharmony_ci#define REG_MICFIL_CTRL1		0x00
1262306a36Sopenharmony_ci#define REG_MICFIL_CTRL2		0x04
1362306a36Sopenharmony_ci#define REG_MICFIL_STAT			0x08
1462306a36Sopenharmony_ci#define REG_MICFIL_FIFO_CTRL		0x10
1562306a36Sopenharmony_ci#define REG_MICFIL_FIFO_STAT		0x14
1662306a36Sopenharmony_ci#define REG_MICFIL_DATACH0		0x24
1762306a36Sopenharmony_ci#define REG_MICFIL_DATACH1		0x28
1862306a36Sopenharmony_ci#define REG_MICFIL_DATACH2		0x2C
1962306a36Sopenharmony_ci#define REG_MICFIL_DATACH3		0x30
2062306a36Sopenharmony_ci#define REG_MICFIL_DATACH4		0x34
2162306a36Sopenharmony_ci#define REG_MICFIL_DATACH5		0x38
2262306a36Sopenharmony_ci#define REG_MICFIL_DATACH6		0x3C
2362306a36Sopenharmony_ci#define REG_MICFIL_DATACH7		0x40
2462306a36Sopenharmony_ci#define REG_MICFIL_DC_CTRL		0x64
2562306a36Sopenharmony_ci#define REG_MICFIL_OUT_CTRL		0x74
2662306a36Sopenharmony_ci#define REG_MICFIL_OUT_STAT		0x7C
2762306a36Sopenharmony_ci#define REG_MICFIL_FSYNC_CTRL		0x80
2862306a36Sopenharmony_ci#define REG_MICFIL_VERID		0x84
2962306a36Sopenharmony_ci#define REG_MICFIL_PARAM		0x88
3062306a36Sopenharmony_ci#define REG_MICFIL_VAD0_CTRL1		0x90
3162306a36Sopenharmony_ci#define REG_MICFIL_VAD0_CTRL2		0x94
3262306a36Sopenharmony_ci#define REG_MICFIL_VAD0_STAT		0x98
3362306a36Sopenharmony_ci#define REG_MICFIL_VAD0_SCONFIG		0x9C
3462306a36Sopenharmony_ci#define REG_MICFIL_VAD0_NCONFIG		0xA0
3562306a36Sopenharmony_ci#define REG_MICFIL_VAD0_NDATA		0xA4
3662306a36Sopenharmony_ci#define REG_MICFIL_VAD0_ZCD		0xA8
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci/* MICFIL Control Register 1 -- REG_MICFILL_CTRL1 0x00 */
3962306a36Sopenharmony_ci#define MICFIL_CTRL1_MDIS		BIT(31)
4062306a36Sopenharmony_ci#define MICFIL_CTRL1_DOZEN		BIT(30)
4162306a36Sopenharmony_ci#define MICFIL_CTRL1_PDMIEN		BIT(29)
4262306a36Sopenharmony_ci#define MICFIL_CTRL1_DBG		BIT(28)
4362306a36Sopenharmony_ci#define MICFIL_CTRL1_SRES		BIT(27)
4462306a36Sopenharmony_ci#define MICFIL_CTRL1_DBGE		BIT(26)
4562306a36Sopenharmony_ci#define MICFIL_CTRL1_DECFILS		BIT(20)
4662306a36Sopenharmony_ci#define MICFIL_CTRL1_FSYNCEN		BIT(16)
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci#define MICFIL_CTRL1_DISEL_DISABLE	0
4962306a36Sopenharmony_ci#define MICFIL_CTRL1_DISEL_DMA		1
5062306a36Sopenharmony_ci#define MICFIL_CTRL1_DISEL_IRQ		2
5162306a36Sopenharmony_ci#define MICFIL_CTRL1_DISEL		GENMASK(25, 24)
5262306a36Sopenharmony_ci#define MICFIL_CTRL1_ERREN		BIT(23)
5362306a36Sopenharmony_ci#define MICFIL_CTRL1_CHEN(ch)		BIT(ch)
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci/* MICFIL Control Register 2 -- REG_MICFILL_CTRL2 0x04 */
5662306a36Sopenharmony_ci#define MICFIL_CTRL2_QSEL_SHIFT		25
5762306a36Sopenharmony_ci#define MICFIL_CTRL2_QSEL		GENMASK(27, 25)
5862306a36Sopenharmony_ci#define MICFIL_QSEL_MEDIUM_QUALITY	0
5962306a36Sopenharmony_ci#define MICFIL_QSEL_HIGH_QUALITY	1
6062306a36Sopenharmony_ci#define MICFIL_QSEL_LOW_QUALITY		7
6162306a36Sopenharmony_ci#define MICFIL_QSEL_VLOW0_QUALITY	6
6262306a36Sopenharmony_ci#define MICFIL_QSEL_VLOW1_QUALITY	5
6362306a36Sopenharmony_ci#define MICFIL_QSEL_VLOW2_QUALITY	4
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci#define MICFIL_CTRL2_CICOSR		GENMASK(19, 16)
6662306a36Sopenharmony_ci#define MICFIL_CTRL2_CLKDIV		GENMASK(7, 0)
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci/* MICFIL Status Register -- REG_MICFIL_STAT 0x08 */
6962306a36Sopenharmony_ci#define MICFIL_STAT_BSY_FIL		BIT(31)
7062306a36Sopenharmony_ci#define MICFIL_STAT_FIR_RDY		BIT(30)
7162306a36Sopenharmony_ci#define MICFIL_STAT_LOWFREQF		BIT(29)
7262306a36Sopenharmony_ci#define MICFIL_STAT_CHXF(ch)		BIT(ch)
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci/* MICFIL FIFO Control Register -- REG_MICFIL_FIFO_CTRL 0x10 */
7562306a36Sopenharmony_ci#define MICFIL_FIFO_CTRL_FIFOWMK	GENMASK(2, 0)
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci/* MICFIL FIFO Status Register -- REG_MICFIL_FIFO_STAT 0x14 */
7862306a36Sopenharmony_ci#define MICFIL_FIFO_STAT_FIFOX_OVER(ch)	BIT(ch)
7962306a36Sopenharmony_ci#define MICFIL_FIFO_STAT_FIFOX_UNDER(ch)	BIT((ch) + 8)
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci/* MICFIL DC Remover Control Register -- REG_MICFIL_DC_CTRL */
8262306a36Sopenharmony_ci#define MICFIL_DC_CTRL_CONFIG          GENMASK(15, 0)
8362306a36Sopenharmony_ci#define MICFIL_DC_CHX_SHIFT(ch)        ((ch) << 1)
8462306a36Sopenharmony_ci#define MICFIL_DC_CHX(ch)              GENMASK((((ch) << 1) + 1), ((ch) << 1))
8562306a36Sopenharmony_ci#define MICFIL_DC_CUTOFF_21HZ          0
8662306a36Sopenharmony_ci#define MICFIL_DC_CUTOFF_83HZ          1
8762306a36Sopenharmony_ci#define MICFIL_DC_CUTOFF_152Hz         2
8862306a36Sopenharmony_ci#define MICFIL_DC_BYPASS               3
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ci/* MICFIL VERID Register -- REG_MICFIL_VERID */
9162306a36Sopenharmony_ci#define MICFIL_VERID_MAJOR_SHIFT        24
9262306a36Sopenharmony_ci#define MICFIL_VERID_MAJOR_MASK         GENMASK(31, 24)
9362306a36Sopenharmony_ci#define MICFIL_VERID_MINOR_SHIFT        16
9462306a36Sopenharmony_ci#define MICFIL_VERID_MINOR_MASK         GENMASK(23, 16)
9562306a36Sopenharmony_ci#define MICFIL_VERID_FEATURE_SHIFT      0
9662306a36Sopenharmony_ci#define MICFIL_VERID_FEATURE_MASK       GENMASK(15, 0)
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_ci/* MICFIL PARAM Register -- REG_MICFIL_PARAM */
9962306a36Sopenharmony_ci#define MICFIL_PARAM_NUM_HWVAD_SHIFT    24
10062306a36Sopenharmony_ci#define MICFIL_PARAM_NUM_HWVAD_MASK     GENMASK(27, 24)
10162306a36Sopenharmony_ci#define MICFIL_PARAM_HWVAD_ZCD          BIT(19)
10262306a36Sopenharmony_ci#define MICFIL_PARAM_HWVAD_ENERGY_MODE  BIT(17)
10362306a36Sopenharmony_ci#define MICFIL_PARAM_HWVAD              BIT(16)
10462306a36Sopenharmony_ci#define MICFIL_PARAM_DC_OUT_BYPASS      BIT(11)
10562306a36Sopenharmony_ci#define MICFIL_PARAM_DC_IN_BYPASS       BIT(10)
10662306a36Sopenharmony_ci#define MICFIL_PARAM_LOW_POWER          BIT(9)
10762306a36Sopenharmony_ci#define MICFIL_PARAM_FIL_OUT_WIDTH      BIT(8)
10862306a36Sopenharmony_ci#define MICFIL_PARAM_FIFO_PTRWID_SHIFT  4
10962306a36Sopenharmony_ci#define MICFIL_PARAM_FIFO_PTRWID_MASK   GENMASK(7, 4)
11062306a36Sopenharmony_ci#define MICFIL_PARAM_NPAIR_SHIFT        0
11162306a36Sopenharmony_ci#define MICFIL_PARAM_NPAIR_MASK         GENMASK(3, 0)
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci/* MICFIL HWVAD0 Control 1 Register -- REG_MICFIL_VAD0_CTRL1*/
11462306a36Sopenharmony_ci#define MICFIL_VAD0_CTRL1_CHSEL		GENMASK(26, 24)
11562306a36Sopenharmony_ci#define MICFIL_VAD0_CTRL1_CICOSR	GENMASK(19, 16)
11662306a36Sopenharmony_ci#define MICFIL_VAD0_CTRL1_INITT		GENMASK(12, 8)
11762306a36Sopenharmony_ci#define MICFIL_VAD0_CTRL1_ST10		BIT(4)
11862306a36Sopenharmony_ci#define MICFIL_VAD0_CTRL1_ERIE		BIT(3)
11962306a36Sopenharmony_ci#define MICFIL_VAD0_CTRL1_IE		BIT(2)
12062306a36Sopenharmony_ci#define MICFIL_VAD0_CTRL1_RST		BIT(1)
12162306a36Sopenharmony_ci#define MICFIL_VAD0_CTRL1_EN		BIT(0)
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_ci/* MICFIL HWVAD0 Control 2 Register -- REG_MICFIL_VAD0_CTRL2*/
12462306a36Sopenharmony_ci#define MICFIL_VAD0_CTRL2_FRENDIS	BIT(31)
12562306a36Sopenharmony_ci#define MICFIL_VAD0_CTRL2_PREFEN	BIT(30)
12662306a36Sopenharmony_ci#define MICFIL_VAD0_CTRL2_FOUTDIS	BIT(28)
12762306a36Sopenharmony_ci#define MICFIL_VAD0_CTRL2_FRAMET	GENMASK(21, 16)
12862306a36Sopenharmony_ci#define MICFIL_VAD0_CTRL2_INPGAIN	GENMASK(11, 8)
12962306a36Sopenharmony_ci#define MICFIL_VAD0_CTRL2_HPF		GENMASK(1, 0)
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_ci/* MICFIL HWVAD0 Signal CONFIG Register -- REG_MICFIL_VAD0_SCONFIG */
13262306a36Sopenharmony_ci#define MICFIL_VAD0_SCONFIG_SFILEN		BIT(31)
13362306a36Sopenharmony_ci#define MICFIL_VAD0_SCONFIG_SMAXEN		BIT(30)
13462306a36Sopenharmony_ci#define MICFIL_VAD0_SCONFIG_SGAIN		GENMASK(3, 0)
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci/* MICFIL HWVAD0 Noise CONFIG Register -- REG_MICFIL_VAD0_NCONFIG */
13762306a36Sopenharmony_ci#define MICFIL_VAD0_NCONFIG_NFILAUT		BIT(31)
13862306a36Sopenharmony_ci#define MICFIL_VAD0_NCONFIG_NMINEN		BIT(30)
13962306a36Sopenharmony_ci#define MICFIL_VAD0_NCONFIG_NDECEN		BIT(29)
14062306a36Sopenharmony_ci#define MICFIL_VAD0_NCONFIG_NOREN		BIT(28)
14162306a36Sopenharmony_ci#define MICFIL_VAD0_NCONFIG_NFILADJ		GENMASK(12, 8)
14262306a36Sopenharmony_ci#define MICFIL_VAD0_NCONFIG_NGAIN		GENMASK(3, 0)
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ci/* MICFIL HWVAD0 Zero-Crossing Detector - REG_MICFIL_VAD0_ZCD */
14562306a36Sopenharmony_ci#define MICFIL_VAD0_ZCD_ZCDTH		GENMASK(25, 16)
14662306a36Sopenharmony_ci#define MICFIL_VAD0_ZCD_ZCDADJ		GENMASK(11, 8)
14762306a36Sopenharmony_ci#define MICFIL_VAD0_ZCD_ZCDAND		BIT(4)
14862306a36Sopenharmony_ci#define MICFIL_VAD0_ZCD_ZCDAUT		BIT(2)
14962306a36Sopenharmony_ci#define MICFIL_VAD0_ZCD_ZCDEN		BIT(0)
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ci/* MICFIL HWVAD0 Status Register - REG_MICFIL_VAD0_STAT */
15262306a36Sopenharmony_ci#define MICFIL_VAD0_STAT_INITF		BIT(31)
15362306a36Sopenharmony_ci#define MICFIL_VAD0_STAT_INSATF		BIT(16)
15462306a36Sopenharmony_ci#define MICFIL_VAD0_STAT_EF		BIT(15)
15562306a36Sopenharmony_ci#define MICFIL_VAD0_STAT_IF		BIT(0)
15662306a36Sopenharmony_ci
15762306a36Sopenharmony_ci/* MICFIL Output Control Register */
15862306a36Sopenharmony_ci#define MICFIL_OUTGAIN_CHX_SHIFT(v)	(4 * (v))
15962306a36Sopenharmony_ci
16062306a36Sopenharmony_ci/* Constants */
16162306a36Sopenharmony_ci#define MICFIL_OUTPUT_CHANNELS		8
16262306a36Sopenharmony_ci#define MICFIL_FIFO_NUM			8
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_ci#define FIFO_PTRWID			3
16562306a36Sopenharmony_ci#define FIFO_LEN			BIT(FIFO_PTRWID)
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_ci#define MICFIL_IRQ_LINES		4
16862306a36Sopenharmony_ci#define MICFIL_MAX_RETRY		25
16962306a36Sopenharmony_ci#define MICFIL_SLEEP_MIN		90000 /* in us */
17062306a36Sopenharmony_ci#define MICFIL_SLEEP_MAX		100000 /* in us */
17162306a36Sopenharmony_ci#define MICFIL_DMA_MAXBURST_RX		6
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ci/* HWVAD Constants */
17462306a36Sopenharmony_ci#define MICFIL_HWVAD_ENVELOPE_MODE	0
17562306a36Sopenharmony_ci#define MICFIL_HWVAD_ENERGY_MODE	1
17662306a36Sopenharmony_ci
17762306a36Sopenharmony_ci/**
17862306a36Sopenharmony_ci * struct fsl_micfil_verid - version id data
17962306a36Sopenharmony_ci * @version: version number
18062306a36Sopenharmony_ci * @feature: feature specification number
18162306a36Sopenharmony_ci */
18262306a36Sopenharmony_cistruct fsl_micfil_verid {
18362306a36Sopenharmony_ci	u32 version;
18462306a36Sopenharmony_ci	u32 feature;
18562306a36Sopenharmony_ci};
18662306a36Sopenharmony_ci
18762306a36Sopenharmony_ci/**
18862306a36Sopenharmony_ci * struct fsl_micfil_param - parameter data
18962306a36Sopenharmony_ci * @hwvad_num: the number of HWVADs
19062306a36Sopenharmony_ci * @hwvad_zcd: HWVAD zero-cross detector is active
19162306a36Sopenharmony_ci * @hwvad_energy_mode: HWVAD energy mode is active
19262306a36Sopenharmony_ci * @hwvad: HWVAD is active
19362306a36Sopenharmony_ci * @dc_out_bypass: points out if the output DC remover is disabled
19462306a36Sopenharmony_ci * @dc_in_bypass: points out if the input DC remover is disabled
19562306a36Sopenharmony_ci * @low_power: low power decimation filter
19662306a36Sopenharmony_ci * @fil_out_width: filter output width
19762306a36Sopenharmony_ci * @fifo_ptrwid: FIFO pointer width
19862306a36Sopenharmony_ci * @npair: number of microphone pairs
19962306a36Sopenharmony_ci */
20062306a36Sopenharmony_cistruct fsl_micfil_param {
20162306a36Sopenharmony_ci	u32 hwvad_num;
20262306a36Sopenharmony_ci	bool hwvad_zcd;
20362306a36Sopenharmony_ci	bool hwvad_energy_mode;
20462306a36Sopenharmony_ci	bool hwvad;
20562306a36Sopenharmony_ci	bool dc_out_bypass;
20662306a36Sopenharmony_ci	bool dc_in_bypass;
20762306a36Sopenharmony_ci	bool low_power;
20862306a36Sopenharmony_ci	bool fil_out_width;
20962306a36Sopenharmony_ci	u32 fifo_ptrwid;
21062306a36Sopenharmony_ci	u32 npair;
21162306a36Sopenharmony_ci};
21262306a36Sopenharmony_ci
21362306a36Sopenharmony_ci#endif /* _FSL_MICFIL_H */
214