162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * sound/soc/rockchip/rockchip_i2s.h
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * ALSA SoC Audio Layer - Rockchip I2S Controller driver
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Copyright (c) 2014 Rockchip Electronics Co. Ltd.
862306a36Sopenharmony_ci * Author: Jianqun xu <jay.xu@rock-chips.com>
962306a36Sopenharmony_ci */
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#ifndef _ROCKCHIP_IIS_H
1262306a36Sopenharmony_ci#define _ROCKCHIP_IIS_H
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci/*
1562306a36Sopenharmony_ci * TXCR
1662306a36Sopenharmony_ci * transmit operation control register
1762306a36Sopenharmony_ci*/
1862306a36Sopenharmony_ci#define I2S_TXCR_RCNT_SHIFT	17
1962306a36Sopenharmony_ci#define I2S_TXCR_RCNT_MASK	(0x3f << I2S_TXCR_RCNT_SHIFT)
2062306a36Sopenharmony_ci#define I2S_TXCR_CSR_SHIFT	15
2162306a36Sopenharmony_ci#define I2S_TXCR_CSR(x)		(x << I2S_TXCR_CSR_SHIFT)
2262306a36Sopenharmony_ci#define I2S_TXCR_CSR_MASK	(3 << I2S_TXCR_CSR_SHIFT)
2362306a36Sopenharmony_ci#define I2S_TXCR_HWT		BIT(14)
2462306a36Sopenharmony_ci#define I2S_TXCR_SJM_SHIFT	12
2562306a36Sopenharmony_ci#define I2S_TXCR_SJM_R		(0 << I2S_TXCR_SJM_SHIFT)
2662306a36Sopenharmony_ci#define I2S_TXCR_SJM_L		(1 << I2S_TXCR_SJM_SHIFT)
2762306a36Sopenharmony_ci#define I2S_TXCR_FBM_SHIFT	11
2862306a36Sopenharmony_ci#define I2S_TXCR_FBM_MSB	(0 << I2S_TXCR_FBM_SHIFT)
2962306a36Sopenharmony_ci#define I2S_TXCR_FBM_LSB	(1 << I2S_TXCR_FBM_SHIFT)
3062306a36Sopenharmony_ci#define I2S_TXCR_IBM_SHIFT	9
3162306a36Sopenharmony_ci#define I2S_TXCR_IBM_NORMAL	(0 << I2S_TXCR_IBM_SHIFT)
3262306a36Sopenharmony_ci#define I2S_TXCR_IBM_LSJM	(1 << I2S_TXCR_IBM_SHIFT)
3362306a36Sopenharmony_ci#define I2S_TXCR_IBM_RSJM	(2 << I2S_TXCR_IBM_SHIFT)
3462306a36Sopenharmony_ci#define I2S_TXCR_IBM_MASK	(3 << I2S_TXCR_IBM_SHIFT)
3562306a36Sopenharmony_ci#define I2S_TXCR_PBM_SHIFT	7
3662306a36Sopenharmony_ci#define I2S_TXCR_PBM_MODE(x)	(x << I2S_TXCR_PBM_SHIFT)
3762306a36Sopenharmony_ci#define I2S_TXCR_PBM_MASK	(3 << I2S_TXCR_PBM_SHIFT)
3862306a36Sopenharmony_ci#define I2S_TXCR_TFS_SHIFT	5
3962306a36Sopenharmony_ci#define I2S_TXCR_TFS_I2S	(0 << I2S_TXCR_TFS_SHIFT)
4062306a36Sopenharmony_ci#define I2S_TXCR_TFS_PCM	(1 << I2S_TXCR_TFS_SHIFT)
4162306a36Sopenharmony_ci#define I2S_TXCR_TFS_MASK	(1 << I2S_TXCR_TFS_SHIFT)
4262306a36Sopenharmony_ci#define I2S_TXCR_VDW_SHIFT	0
4362306a36Sopenharmony_ci#define I2S_TXCR_VDW(x)		((x - 1) << I2S_TXCR_VDW_SHIFT)
4462306a36Sopenharmony_ci#define I2S_TXCR_VDW_MASK	(0x1f << I2S_TXCR_VDW_SHIFT)
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci/*
4762306a36Sopenharmony_ci * RXCR
4862306a36Sopenharmony_ci * receive operation control register
4962306a36Sopenharmony_ci*/
5062306a36Sopenharmony_ci#define I2S_RXCR_CSR_SHIFT	15
5162306a36Sopenharmony_ci#define I2S_RXCR_CSR(x)		(x << I2S_RXCR_CSR_SHIFT)
5262306a36Sopenharmony_ci#define I2S_RXCR_CSR_MASK	(3 << I2S_RXCR_CSR_SHIFT)
5362306a36Sopenharmony_ci#define I2S_RXCR_HWT		BIT(14)
5462306a36Sopenharmony_ci#define I2S_RXCR_SJM_SHIFT	12
5562306a36Sopenharmony_ci#define I2S_RXCR_SJM_R		(0 << I2S_RXCR_SJM_SHIFT)
5662306a36Sopenharmony_ci#define I2S_RXCR_SJM_L		(1 << I2S_RXCR_SJM_SHIFT)
5762306a36Sopenharmony_ci#define I2S_RXCR_FBM_SHIFT	11
5862306a36Sopenharmony_ci#define I2S_RXCR_FBM_MSB	(0 << I2S_RXCR_FBM_SHIFT)
5962306a36Sopenharmony_ci#define I2S_RXCR_FBM_LSB	(1 << I2S_RXCR_FBM_SHIFT)
6062306a36Sopenharmony_ci#define I2S_RXCR_IBM_SHIFT	9
6162306a36Sopenharmony_ci#define I2S_RXCR_IBM_NORMAL	(0 << I2S_RXCR_IBM_SHIFT)
6262306a36Sopenharmony_ci#define I2S_RXCR_IBM_LSJM	(1 << I2S_RXCR_IBM_SHIFT)
6362306a36Sopenharmony_ci#define I2S_RXCR_IBM_RSJM	(2 << I2S_RXCR_IBM_SHIFT)
6462306a36Sopenharmony_ci#define I2S_RXCR_IBM_MASK	(3 << I2S_RXCR_IBM_SHIFT)
6562306a36Sopenharmony_ci#define I2S_RXCR_PBM_SHIFT	7
6662306a36Sopenharmony_ci#define I2S_RXCR_PBM_MODE(x)	(x << I2S_RXCR_PBM_SHIFT)
6762306a36Sopenharmony_ci#define I2S_RXCR_PBM_MASK	(3 << I2S_RXCR_PBM_SHIFT)
6862306a36Sopenharmony_ci#define I2S_RXCR_TFS_SHIFT	5
6962306a36Sopenharmony_ci#define I2S_RXCR_TFS_I2S	(0 << I2S_RXCR_TFS_SHIFT)
7062306a36Sopenharmony_ci#define I2S_RXCR_TFS_PCM	(1 << I2S_RXCR_TFS_SHIFT)
7162306a36Sopenharmony_ci#define I2S_RXCR_TFS_MASK	(1 << I2S_RXCR_TFS_SHIFT)
7262306a36Sopenharmony_ci#define I2S_RXCR_VDW_SHIFT	0
7362306a36Sopenharmony_ci#define I2S_RXCR_VDW(x)		((x - 1) << I2S_RXCR_VDW_SHIFT)
7462306a36Sopenharmony_ci#define I2S_RXCR_VDW_MASK	(0x1f << I2S_RXCR_VDW_SHIFT)
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci/*
7762306a36Sopenharmony_ci * CKR
7862306a36Sopenharmony_ci * clock generation register
7962306a36Sopenharmony_ci*/
8062306a36Sopenharmony_ci#define I2S_CKR_TRCM_SHIFT	28
8162306a36Sopenharmony_ci#define I2S_CKR_TRCM(x)	(x << I2S_CKR_TRCM_SHIFT)
8262306a36Sopenharmony_ci#define I2S_CKR_TRCM_TXRX	(0 << I2S_CKR_TRCM_SHIFT)
8362306a36Sopenharmony_ci#define I2S_CKR_TRCM_TXONLY	(1 << I2S_CKR_TRCM_SHIFT)
8462306a36Sopenharmony_ci#define I2S_CKR_TRCM_RXONLY	(2 << I2S_CKR_TRCM_SHIFT)
8562306a36Sopenharmony_ci#define I2S_CKR_TRCM_MASK	(3 << I2S_CKR_TRCM_SHIFT)
8662306a36Sopenharmony_ci#define I2S_CKR_MSS_SHIFT	27
8762306a36Sopenharmony_ci#define I2S_CKR_MSS_MASTER	(0 << I2S_CKR_MSS_SHIFT)
8862306a36Sopenharmony_ci#define I2S_CKR_MSS_SLAVE	(1 << I2S_CKR_MSS_SHIFT)
8962306a36Sopenharmony_ci#define I2S_CKR_MSS_MASK	(1 << I2S_CKR_MSS_SHIFT)
9062306a36Sopenharmony_ci#define I2S_CKR_CKP_SHIFT	26
9162306a36Sopenharmony_ci#define I2S_CKR_CKP_NORMAL	(0 << I2S_CKR_CKP_SHIFT)
9262306a36Sopenharmony_ci#define I2S_CKR_CKP_INVERTED	(1 << I2S_CKR_CKP_SHIFT)
9362306a36Sopenharmony_ci#define I2S_CKR_CKP_MASK	(1 << I2S_CKR_CKP_SHIFT)
9462306a36Sopenharmony_ci#define I2S_CKR_RLP_SHIFT	25
9562306a36Sopenharmony_ci#define I2S_CKR_RLP_NORMAL	(0 << I2S_CKR_RLP_SHIFT)
9662306a36Sopenharmony_ci#define I2S_CKR_RLP_INVERTED	(1 << I2S_CKR_RLP_SHIFT)
9762306a36Sopenharmony_ci#define I2S_CKR_RLP_MASK	(1 << I2S_CKR_RLP_SHIFT)
9862306a36Sopenharmony_ci#define I2S_CKR_TLP_SHIFT	24
9962306a36Sopenharmony_ci#define I2S_CKR_TLP_NORMAL	(0 << I2S_CKR_TLP_SHIFT)
10062306a36Sopenharmony_ci#define I2S_CKR_TLP_INVERTED	(1 << I2S_CKR_TLP_SHIFT)
10162306a36Sopenharmony_ci#define I2S_CKR_TLP_MASK	(1 << I2S_CKR_TLP_SHIFT)
10262306a36Sopenharmony_ci#define I2S_CKR_MDIV_SHIFT	16
10362306a36Sopenharmony_ci#define I2S_CKR_MDIV(x)		((x - 1) << I2S_CKR_MDIV_SHIFT)
10462306a36Sopenharmony_ci#define I2S_CKR_MDIV_MASK	(0xff << I2S_CKR_MDIV_SHIFT)
10562306a36Sopenharmony_ci#define I2S_CKR_RSD_SHIFT	8
10662306a36Sopenharmony_ci#define I2S_CKR_RSD(x)		((x - 1) << I2S_CKR_RSD_SHIFT)
10762306a36Sopenharmony_ci#define I2S_CKR_RSD_MASK	(0xff << I2S_CKR_RSD_SHIFT)
10862306a36Sopenharmony_ci#define I2S_CKR_TSD_SHIFT	0
10962306a36Sopenharmony_ci#define I2S_CKR_TSD(x)		((x - 1) << I2S_CKR_TSD_SHIFT)
11062306a36Sopenharmony_ci#define I2S_CKR_TSD_MASK	(0xff << I2S_CKR_TSD_SHIFT)
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ci/*
11362306a36Sopenharmony_ci * FIFOLR
11462306a36Sopenharmony_ci * FIFO level register
11562306a36Sopenharmony_ci*/
11662306a36Sopenharmony_ci#define I2S_FIFOLR_RFL_SHIFT	24
11762306a36Sopenharmony_ci#define I2S_FIFOLR_RFL_MASK	(0x3f << I2S_FIFOLR_RFL_SHIFT)
11862306a36Sopenharmony_ci#define I2S_FIFOLR_TFL3_SHIFT	18
11962306a36Sopenharmony_ci#define I2S_FIFOLR_TFL3_MASK	(0x3f << I2S_FIFOLR_TFL3_SHIFT)
12062306a36Sopenharmony_ci#define I2S_FIFOLR_TFL2_SHIFT	12
12162306a36Sopenharmony_ci#define I2S_FIFOLR_TFL2_MASK	(0x3f << I2S_FIFOLR_TFL2_SHIFT)
12262306a36Sopenharmony_ci#define I2S_FIFOLR_TFL1_SHIFT	6
12362306a36Sopenharmony_ci#define I2S_FIFOLR_TFL1_MASK	(0x3f << I2S_FIFOLR_TFL1_SHIFT)
12462306a36Sopenharmony_ci#define I2S_FIFOLR_TFL0_SHIFT	0
12562306a36Sopenharmony_ci#define I2S_FIFOLR_TFL0_MASK	(0x3f << I2S_FIFOLR_TFL0_SHIFT)
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_ci/*
12862306a36Sopenharmony_ci * DMACR
12962306a36Sopenharmony_ci * DMA control register
13062306a36Sopenharmony_ci*/
13162306a36Sopenharmony_ci#define I2S_DMACR_RDE_SHIFT	24
13262306a36Sopenharmony_ci#define I2S_DMACR_RDE_DISABLE	(0 << I2S_DMACR_RDE_SHIFT)
13362306a36Sopenharmony_ci#define I2S_DMACR_RDE_ENABLE	(1 << I2S_DMACR_RDE_SHIFT)
13462306a36Sopenharmony_ci#define I2S_DMACR_RDL_SHIFT	16
13562306a36Sopenharmony_ci#define I2S_DMACR_RDL(x)	((x - 1) << I2S_DMACR_RDL_SHIFT)
13662306a36Sopenharmony_ci#define I2S_DMACR_RDL_MASK	(0x1f << I2S_DMACR_RDL_SHIFT)
13762306a36Sopenharmony_ci#define I2S_DMACR_TDE_SHIFT	8
13862306a36Sopenharmony_ci#define I2S_DMACR_TDE_DISABLE	(0 << I2S_DMACR_TDE_SHIFT)
13962306a36Sopenharmony_ci#define I2S_DMACR_TDE_ENABLE	(1 << I2S_DMACR_TDE_SHIFT)
14062306a36Sopenharmony_ci#define I2S_DMACR_TDL_SHIFT	0
14162306a36Sopenharmony_ci#define I2S_DMACR_TDL(x)	((x) << I2S_DMACR_TDL_SHIFT)
14262306a36Sopenharmony_ci#define I2S_DMACR_TDL_MASK	(0x1f << I2S_DMACR_TDL_SHIFT)
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ci/*
14562306a36Sopenharmony_ci * INTCR
14662306a36Sopenharmony_ci * interrupt control register
14762306a36Sopenharmony_ci*/
14862306a36Sopenharmony_ci#define I2S_INTCR_RFT_SHIFT	20
14962306a36Sopenharmony_ci#define I2S_INTCR_RFT(x)	((x - 1) << I2S_INTCR_RFT_SHIFT)
15062306a36Sopenharmony_ci#define I2S_INTCR_RXOIC		BIT(18)
15162306a36Sopenharmony_ci#define I2S_INTCR_RXOIE_SHIFT	17
15262306a36Sopenharmony_ci#define I2S_INTCR_RXOIE_DISABLE	(0 << I2S_INTCR_RXOIE_SHIFT)
15362306a36Sopenharmony_ci#define I2S_INTCR_RXOIE_ENABLE	(1 << I2S_INTCR_RXOIE_SHIFT)
15462306a36Sopenharmony_ci#define I2S_INTCR_RXFIE_SHIFT	16
15562306a36Sopenharmony_ci#define I2S_INTCR_RXFIE_DISABLE	(0 << I2S_INTCR_RXFIE_SHIFT)
15662306a36Sopenharmony_ci#define I2S_INTCR_RXFIE_ENABLE	(1 << I2S_INTCR_RXFIE_SHIFT)
15762306a36Sopenharmony_ci#define I2S_INTCR_TFT_SHIFT	4
15862306a36Sopenharmony_ci#define I2S_INTCR_TFT(x)	((x - 1) << I2S_INTCR_TFT_SHIFT)
15962306a36Sopenharmony_ci#define I2S_INTCR_TFT_MASK	(0x1f << I2S_INTCR_TFT_SHIFT)
16062306a36Sopenharmony_ci#define I2S_INTCR_TXUIC		BIT(2)
16162306a36Sopenharmony_ci#define I2S_INTCR_TXUIE_SHIFT	1
16262306a36Sopenharmony_ci#define I2S_INTCR_TXUIE_DISABLE	(0 << I2S_INTCR_TXUIE_SHIFT)
16362306a36Sopenharmony_ci#define I2S_INTCR_TXUIE_ENABLE	(1 << I2S_INTCR_TXUIE_SHIFT)
16462306a36Sopenharmony_ci
16562306a36Sopenharmony_ci/*
16662306a36Sopenharmony_ci * INTSR
16762306a36Sopenharmony_ci * interrupt status register
16862306a36Sopenharmony_ci*/
16962306a36Sopenharmony_ci#define I2S_INTSR_TXEIE_SHIFT	0
17062306a36Sopenharmony_ci#define I2S_INTSR_TXEIE_DISABLE	(0 << I2S_INTSR_TXEIE_SHIFT)
17162306a36Sopenharmony_ci#define I2S_INTSR_TXEIE_ENABLE	(1 << I2S_INTSR_TXEIE_SHIFT)
17262306a36Sopenharmony_ci#define I2S_INTSR_RXOI_SHIFT	17
17362306a36Sopenharmony_ci#define I2S_INTSR_RXOI_INA	(0 << I2S_INTSR_RXOI_SHIFT)
17462306a36Sopenharmony_ci#define I2S_INTSR_RXOI_ACT	(1 << I2S_INTSR_RXOI_SHIFT)
17562306a36Sopenharmony_ci#define I2S_INTSR_RXFI_SHIFT	16
17662306a36Sopenharmony_ci#define I2S_INTSR_RXFI_INA	(0 << I2S_INTSR_RXFI_SHIFT)
17762306a36Sopenharmony_ci#define I2S_INTSR_RXFI_ACT	(1 << I2S_INTSR_RXFI_SHIFT)
17862306a36Sopenharmony_ci#define I2S_INTSR_TXUI_SHIFT	1
17962306a36Sopenharmony_ci#define I2S_INTSR_TXUI_INA	(0 << I2S_INTSR_TXUI_SHIFT)
18062306a36Sopenharmony_ci#define I2S_INTSR_TXUI_ACT	(1 << I2S_INTSR_TXUI_SHIFT)
18162306a36Sopenharmony_ci#define I2S_INTSR_TXEI_SHIFT	0
18262306a36Sopenharmony_ci#define I2S_INTSR_TXEI_INA	(0 << I2S_INTSR_TXEI_SHIFT)
18362306a36Sopenharmony_ci#define I2S_INTSR_TXEI_ACT	(1 << I2S_INTSR_TXEI_SHIFT)
18462306a36Sopenharmony_ci
18562306a36Sopenharmony_ci/*
18662306a36Sopenharmony_ci * XFER
18762306a36Sopenharmony_ci * Transfer start register
18862306a36Sopenharmony_ci*/
18962306a36Sopenharmony_ci#define I2S_XFER_RXS_SHIFT	1
19062306a36Sopenharmony_ci#define I2S_XFER_RXS_STOP	(0 << I2S_XFER_RXS_SHIFT)
19162306a36Sopenharmony_ci#define I2S_XFER_RXS_START	(1 << I2S_XFER_RXS_SHIFT)
19262306a36Sopenharmony_ci#define I2S_XFER_TXS_SHIFT	0
19362306a36Sopenharmony_ci#define I2S_XFER_TXS_STOP	(0 << I2S_XFER_TXS_SHIFT)
19462306a36Sopenharmony_ci#define I2S_XFER_TXS_START	(1 << I2S_XFER_TXS_SHIFT)
19562306a36Sopenharmony_ci
19662306a36Sopenharmony_ci/*
19762306a36Sopenharmony_ci * CLR
19862306a36Sopenharmony_ci * clear SCLK domain logic register
19962306a36Sopenharmony_ci*/
20062306a36Sopenharmony_ci#define I2S_CLR_RXC	BIT(1)
20162306a36Sopenharmony_ci#define I2S_CLR_TXC	BIT(0)
20262306a36Sopenharmony_ci
20362306a36Sopenharmony_ci/*
20462306a36Sopenharmony_ci * TXDR
20562306a36Sopenharmony_ci * Transimt FIFO data register, write only.
20662306a36Sopenharmony_ci*/
20762306a36Sopenharmony_ci#define I2S_TXDR_MASK	(0xff)
20862306a36Sopenharmony_ci
20962306a36Sopenharmony_ci/*
21062306a36Sopenharmony_ci * RXDR
21162306a36Sopenharmony_ci * Receive FIFO data register, write only.
21262306a36Sopenharmony_ci*/
21362306a36Sopenharmony_ci#define I2S_RXDR_MASK	(0xff)
21462306a36Sopenharmony_ci
21562306a36Sopenharmony_ci/* Clock divider id */
21662306a36Sopenharmony_cienum {
21762306a36Sopenharmony_ci	ROCKCHIP_DIV_MCLK = 0,
21862306a36Sopenharmony_ci	ROCKCHIP_DIV_BCLK,
21962306a36Sopenharmony_ci};
22062306a36Sopenharmony_ci
22162306a36Sopenharmony_ci/* channel select */
22262306a36Sopenharmony_ci#define I2S_CSR_SHIFT	15
22362306a36Sopenharmony_ci#define I2S_CHN_2	(0 << I2S_CSR_SHIFT)
22462306a36Sopenharmony_ci#define I2S_CHN_4	(1 << I2S_CSR_SHIFT)
22562306a36Sopenharmony_ci#define I2S_CHN_6	(2 << I2S_CSR_SHIFT)
22662306a36Sopenharmony_ci#define I2S_CHN_8	(3 << I2S_CSR_SHIFT)
22762306a36Sopenharmony_ci
22862306a36Sopenharmony_ci/* I2S REGS */
22962306a36Sopenharmony_ci#define I2S_TXCR	(0x0000)
23062306a36Sopenharmony_ci#define I2S_RXCR	(0x0004)
23162306a36Sopenharmony_ci#define I2S_CKR		(0x0008)
23262306a36Sopenharmony_ci#define I2S_FIFOLR	(0x000c)
23362306a36Sopenharmony_ci#define I2S_DMACR	(0x0010)
23462306a36Sopenharmony_ci#define I2S_INTCR	(0x0014)
23562306a36Sopenharmony_ci#define I2S_INTSR	(0x0018)
23662306a36Sopenharmony_ci#define I2S_XFER	(0x001c)
23762306a36Sopenharmony_ci#define I2S_CLR		(0x0020)
23862306a36Sopenharmony_ci#define I2S_TXDR	(0x0024)
23962306a36Sopenharmony_ci#define I2S_RXDR	(0x0028)
24062306a36Sopenharmony_ci
24162306a36Sopenharmony_ci/* io direction cfg register */
24262306a36Sopenharmony_ci#define I2S_IO_DIRECTION_MASK	(7)
24362306a36Sopenharmony_ci#define I2S_IO_8CH_OUT_2CH_IN	(0)
24462306a36Sopenharmony_ci#define I2S_IO_6CH_OUT_4CH_IN	(4)
24562306a36Sopenharmony_ci#define I2S_IO_4CH_OUT_6CH_IN	(6)
24662306a36Sopenharmony_ci#define I2S_IO_2CH_OUT_8CH_IN	(7)
24762306a36Sopenharmony_ci
24862306a36Sopenharmony_ci#endif /* _ROCKCHIP_IIS_H */
249