162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * fsl_asrc.h - Freescale ASRC ALSA SoC header file
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (C) 2014 Freescale Semiconductor, Inc.
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Author: Nicolin Chen <nicoleotsuka@gmail.com>
862306a36Sopenharmony_ci */
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#ifndef _FSL_ASRC_H
1162306a36Sopenharmony_ci#define _FSL_ASRC_H
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#include  "fsl_asrc_common.h"
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci#define ASRC_DMA_BUFFER_NUM		2
1662306a36Sopenharmony_ci#define ASRC_INPUTFIFO_THRESHOLD	32
1762306a36Sopenharmony_ci#define ASRC_OUTPUTFIFO_THRESHOLD	32
1862306a36Sopenharmony_ci#define ASRC_FIFO_THRESHOLD_MIN		0
1962306a36Sopenharmony_ci#define ASRC_FIFO_THRESHOLD_MAX		63
2062306a36Sopenharmony_ci#define ASRC_DMA_BUFFER_SIZE		(1024 * 48 * 4)
2162306a36Sopenharmony_ci#define ASRC_MAX_BUFFER_SIZE		(1024 * 48)
2262306a36Sopenharmony_ci#define ASRC_OUTPUT_LAST_SAMPLE		8
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci#define IDEAL_RATIO_RATE		1000000
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci#define REG_ASRCTR			0x00
2762306a36Sopenharmony_ci#define REG_ASRIER			0x04
2862306a36Sopenharmony_ci#define REG_ASRCNCR			0x0C
2962306a36Sopenharmony_ci#define REG_ASRCFG			0x10
3062306a36Sopenharmony_ci#define REG_ASRCSR			0x14
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci#define REG_ASRCDR1			0x18
3362306a36Sopenharmony_ci#define REG_ASRCDR2			0x1C
3462306a36Sopenharmony_ci#define REG_ASRCDR(i)			((i < 2) ? REG_ASRCDR1 : REG_ASRCDR2)
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci#define REG_ASRSTR			0x20
3762306a36Sopenharmony_ci#define REG_ASRRA			0x24
3862306a36Sopenharmony_ci#define REG_ASRRB			0x28
3962306a36Sopenharmony_ci#define REG_ASRRC			0x2C
4062306a36Sopenharmony_ci#define REG_ASRPM1			0x40
4162306a36Sopenharmony_ci#define REG_ASRPM2			0x44
4262306a36Sopenharmony_ci#define REG_ASRPM3			0x48
4362306a36Sopenharmony_ci#define REG_ASRPM4			0x4C
4462306a36Sopenharmony_ci#define REG_ASRPM5			0x50
4562306a36Sopenharmony_ci#define REG_ASRTFR1			0x54
4662306a36Sopenharmony_ci#define REG_ASRCCR			0x5C
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci#define REG_ASRDIA			0x60
4962306a36Sopenharmony_ci#define REG_ASRDOA			0x64
5062306a36Sopenharmony_ci#define REG_ASRDIB			0x68
5162306a36Sopenharmony_ci#define REG_ASRDOB			0x6C
5262306a36Sopenharmony_ci#define REG_ASRDIC			0x70
5362306a36Sopenharmony_ci#define REG_ASRDOC			0x74
5462306a36Sopenharmony_ci#define REG_ASRDI(i)			(REG_ASRDIA + (i << 3))
5562306a36Sopenharmony_ci#define REG_ASRDO(i)			(REG_ASRDOA + (i << 3))
5662306a36Sopenharmony_ci#define REG_ASRDx(x, i)			((x) == IN ? REG_ASRDI(i) : REG_ASRDO(i))
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci#define REG_ASRIDRHA			0x80
5962306a36Sopenharmony_ci#define REG_ASRIDRLA			0x84
6062306a36Sopenharmony_ci#define REG_ASRIDRHB			0x88
6162306a36Sopenharmony_ci#define REG_ASRIDRLB			0x8C
6262306a36Sopenharmony_ci#define REG_ASRIDRHC			0x90
6362306a36Sopenharmony_ci#define REG_ASRIDRLC			0x94
6462306a36Sopenharmony_ci#define REG_ASRIDRH(i)			(REG_ASRIDRHA + (i << 3))
6562306a36Sopenharmony_ci#define REG_ASRIDRL(i)			(REG_ASRIDRLA + (i << 3))
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci#define REG_ASR76K			0x98
6862306a36Sopenharmony_ci#define REG_ASR56K			0x9C
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ci#define REG_ASRMCRA			0xA0
7162306a36Sopenharmony_ci#define REG_ASRFSTA			0xA4
7262306a36Sopenharmony_ci#define REG_ASRMCRB			0xA8
7362306a36Sopenharmony_ci#define REG_ASRFSTB			0xAC
7462306a36Sopenharmony_ci#define REG_ASRMCRC			0xB0
7562306a36Sopenharmony_ci#define REG_ASRFSTC			0xB4
7662306a36Sopenharmony_ci#define REG_ASRMCR(i)			(REG_ASRMCRA + (i << 3))
7762306a36Sopenharmony_ci#define REG_ASRFST(i)			(REG_ASRFSTA + (i << 3))
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ci#define REG_ASRMCR1A			0xC0
8062306a36Sopenharmony_ci#define REG_ASRMCR1B			0xC4
8162306a36Sopenharmony_ci#define REG_ASRMCR1C			0xC8
8262306a36Sopenharmony_ci#define REG_ASRMCR1(i)			(REG_ASRMCR1A + (i << 2))
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci/* REG0 0x00 REG_ASRCTR */
8662306a36Sopenharmony_ci#define ASRCTR_ATSi_SHIFT(i)		(20 + i)
8762306a36Sopenharmony_ci#define ASRCTR_ATSi_MASK(i)		(1 << ASRCTR_ATSi_SHIFT(i))
8862306a36Sopenharmony_ci#define ASRCTR_ATS(i)			(1 << ASRCTR_ATSi_SHIFT(i))
8962306a36Sopenharmony_ci#define ASRCTR_USRi_SHIFT(i)		(14 + (i << 1))
9062306a36Sopenharmony_ci#define ASRCTR_USRi_MASK(i)		(1 << ASRCTR_USRi_SHIFT(i))
9162306a36Sopenharmony_ci#define ASRCTR_USR(i)			(1 << ASRCTR_USRi_SHIFT(i))
9262306a36Sopenharmony_ci#define ASRCTR_IDRi_SHIFT(i)		(13 + (i << 1))
9362306a36Sopenharmony_ci#define ASRCTR_IDRi_MASK(i)		(1 << ASRCTR_IDRi_SHIFT(i))
9462306a36Sopenharmony_ci#define ASRCTR_IDR(i)			(1 << ASRCTR_IDRi_SHIFT(i))
9562306a36Sopenharmony_ci#define ASRCTR_SRST_SHIFT		4
9662306a36Sopenharmony_ci#define ASRCTR_SRST_MASK		(1 << ASRCTR_SRST_SHIFT)
9762306a36Sopenharmony_ci#define ASRCTR_SRST			(1 << ASRCTR_SRST_SHIFT)
9862306a36Sopenharmony_ci#define ASRCTR_ASRCEi_SHIFT(i)		(1 + i)
9962306a36Sopenharmony_ci#define ASRCTR_ASRCEi_MASK(i)		(1 << ASRCTR_ASRCEi_SHIFT(i))
10062306a36Sopenharmony_ci#define ASRCTR_ASRCE(i)			(1 << ASRCTR_ASRCEi_SHIFT(i))
10162306a36Sopenharmony_ci#define ASRCTR_ASRCEi_ALL_MASK		(0x7 << ASRCTR_ASRCEi_SHIFT(0))
10262306a36Sopenharmony_ci#define ASRCTR_ASRCEN_SHIFT		0
10362306a36Sopenharmony_ci#define ASRCTR_ASRCEN_MASK		(1 << ASRCTR_ASRCEN_SHIFT)
10462306a36Sopenharmony_ci#define ASRCTR_ASRCEN			(1 << ASRCTR_ASRCEN_SHIFT)
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ci/* REG1 0x04 REG_ASRIER */
10762306a36Sopenharmony_ci#define ASRIER_AFPWE_SHIFT		7
10862306a36Sopenharmony_ci#define ASRIER_AFPWE_MASK		(1 << ASRIER_AFPWE_SHIFT)
10962306a36Sopenharmony_ci#define ASRIER_AFPWE			(1 << ASRIER_AFPWE_SHIFT)
11062306a36Sopenharmony_ci#define ASRIER_AOLIE_SHIFT		6
11162306a36Sopenharmony_ci#define ASRIER_AOLIE_MASK		(1 << ASRIER_AOLIE_SHIFT)
11262306a36Sopenharmony_ci#define ASRIER_AOLIE			(1 << ASRIER_AOLIE_SHIFT)
11362306a36Sopenharmony_ci#define ASRIER_ADOEi_SHIFT(i)		(3 + i)
11462306a36Sopenharmony_ci#define ASRIER_ADOEi_MASK(i)		(1 << ASRIER_ADOEi_SHIFT(i))
11562306a36Sopenharmony_ci#define ASRIER_ADOE(i)			(1 << ASRIER_ADOEi_SHIFT(i))
11662306a36Sopenharmony_ci#define ASRIER_ADIEi_SHIFT(i)		(0 + i)
11762306a36Sopenharmony_ci#define ASRIER_ADIEi_MASK(i)		(1 << ASRIER_ADIEi_SHIFT(i))
11862306a36Sopenharmony_ci#define ASRIER_ADIE(i)			(1 << ASRIER_ADIEi_SHIFT(i))
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ci/* REG2 0x0C REG_ASRCNCR */
12162306a36Sopenharmony_ci#define ASRCNCR_ANCi_SHIFT(i, b)	(b * i)
12262306a36Sopenharmony_ci#define ASRCNCR_ANCi_MASK(i, b)		(((1 << b) - 1) << ASRCNCR_ANCi_SHIFT(i, b))
12362306a36Sopenharmony_ci#define ASRCNCR_ANCi(i, v, b)		((v << ASRCNCR_ANCi_SHIFT(i, b)) & ASRCNCR_ANCi_MASK(i, b))
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_ci/* REG3 0x10 REG_ASRCFG */
12662306a36Sopenharmony_ci#define ASRCFG_INIRQi_SHIFT(i)		(21 + i)
12762306a36Sopenharmony_ci#define ASRCFG_INIRQi_MASK(i)		(1 << ASRCFG_INIRQi_SHIFT(i))
12862306a36Sopenharmony_ci#define ASRCFG_INIRQi			(1 << ASRCFG_INIRQi_SHIFT(i))
12962306a36Sopenharmony_ci#define ASRCFG_NDPRi_SHIFT(i)		(18 + i)
13062306a36Sopenharmony_ci#define ASRCFG_NDPRi_MASK(i)		(1 << ASRCFG_NDPRi_SHIFT(i))
13162306a36Sopenharmony_ci#define ASRCFG_NDPRi_ALL_SHIFT		18
13262306a36Sopenharmony_ci#define ASRCFG_NDPRi_ALL_MASK		(7 << ASRCFG_NDPRi_ALL_SHIFT)
13362306a36Sopenharmony_ci#define ASRCFG_NDPRi			(1 << ASRCFG_NDPRi_SHIFT(i))
13462306a36Sopenharmony_ci#define ASRCFG_POSTMODi_SHIFT(i)	(8 + (i << 2))
13562306a36Sopenharmony_ci#define ASRCFG_POSTMODi_WIDTH		2
13662306a36Sopenharmony_ci#define ASRCFG_POSTMODi_MASK(i)		(((1 << ASRCFG_POSTMODi_WIDTH) - 1) << ASRCFG_POSTMODi_SHIFT(i))
13762306a36Sopenharmony_ci#define ASRCFG_POSTMODi_ALL_MASK	(ASRCFG_POSTMODi_MASK(0) | ASRCFG_POSTMODi_MASK(1) | ASRCFG_POSTMODi_MASK(2))
13862306a36Sopenharmony_ci#define ASRCFG_POSTMOD(i, v)		((v) << ASRCFG_POSTMODi_SHIFT(i))
13962306a36Sopenharmony_ci#define ASRCFG_POSTMODi_UP(i)		(0 << ASRCFG_POSTMODi_SHIFT(i))
14062306a36Sopenharmony_ci#define ASRCFG_POSTMODi_DCON(i)		(1 << ASRCFG_POSTMODi_SHIFT(i))
14162306a36Sopenharmony_ci#define ASRCFG_POSTMODi_DOWN(i)		(2 << ASRCFG_POSTMODi_SHIFT(i))
14262306a36Sopenharmony_ci#define ASRCFG_PREMODi_SHIFT(i)		(6 + (i << 2))
14362306a36Sopenharmony_ci#define ASRCFG_PREMODi_WIDTH		2
14462306a36Sopenharmony_ci#define ASRCFG_PREMODi_MASK(i)		(((1 << ASRCFG_PREMODi_WIDTH) - 1) << ASRCFG_PREMODi_SHIFT(i))
14562306a36Sopenharmony_ci#define ASRCFG_PREMODi_ALL_MASK		(ASRCFG_PREMODi_MASK(0) | ASRCFG_PREMODi_MASK(1) | ASRCFG_PREMODi_MASK(2))
14662306a36Sopenharmony_ci#define ASRCFG_PREMOD(i, v)		((v) << ASRCFG_PREMODi_SHIFT(i))
14762306a36Sopenharmony_ci#define ASRCFG_PREMODi_UP(i)		(0 << ASRCFG_PREMODi_SHIFT(i))
14862306a36Sopenharmony_ci#define ASRCFG_PREMODi_DCON(i)		(1 << ASRCFG_PREMODi_SHIFT(i))
14962306a36Sopenharmony_ci#define ASRCFG_PREMODi_DOWN(i)		(2 << ASRCFG_PREMODi_SHIFT(i))
15062306a36Sopenharmony_ci#define ASRCFG_PREMODi_BYPASS(i)	(3 << ASRCFG_PREMODi_SHIFT(i))
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ci/* REG4 0x14 REG_ASRCSR */
15362306a36Sopenharmony_ci#define ASRCSR_AxCSi_WIDTH		4
15462306a36Sopenharmony_ci#define ASRCSR_AxCSi_MASK		((1 << ASRCSR_AxCSi_WIDTH) - 1)
15562306a36Sopenharmony_ci#define ASRCSR_AOCSi_SHIFT(i)		(12 + (i << 2))
15662306a36Sopenharmony_ci#define ASRCSR_AOCSi_MASK(i)		(((1 << ASRCSR_AxCSi_WIDTH) - 1) << ASRCSR_AOCSi_SHIFT(i))
15762306a36Sopenharmony_ci#define ASRCSR_AOCS(i, v)		((v) << ASRCSR_AOCSi_SHIFT(i))
15862306a36Sopenharmony_ci#define ASRCSR_AICSi_SHIFT(i)		(i << 2)
15962306a36Sopenharmony_ci#define ASRCSR_AICSi_MASK(i)		(((1 << ASRCSR_AxCSi_WIDTH) - 1) << ASRCSR_AICSi_SHIFT(i))
16062306a36Sopenharmony_ci#define ASRCSR_AICS(i, v)		((v) << ASRCSR_AICSi_SHIFT(i))
16162306a36Sopenharmony_ci
16262306a36Sopenharmony_ci/* REG5&6 0x18 & 0x1C REG_ASRCDR1 & ASRCDR2 */
16362306a36Sopenharmony_ci#define ASRCDRi_AxCPi_WIDTH		3
16462306a36Sopenharmony_ci#define ASRCDRi_AICPi_SHIFT(i)		(0 + (i % 2) * 6)
16562306a36Sopenharmony_ci#define ASRCDRi_AICPi_MASK(i)		(((1 << ASRCDRi_AxCPi_WIDTH) - 1) << ASRCDRi_AICPi_SHIFT(i))
16662306a36Sopenharmony_ci#define ASRCDRi_AICP(i, v)		((v) << ASRCDRi_AICPi_SHIFT(i))
16762306a36Sopenharmony_ci#define ASRCDRi_AICDi_SHIFT(i)		(3 + (i % 2) * 6)
16862306a36Sopenharmony_ci#define ASRCDRi_AICDi_MASK(i)		(((1 << ASRCDRi_AxCPi_WIDTH) - 1) << ASRCDRi_AICDi_SHIFT(i))
16962306a36Sopenharmony_ci#define ASRCDRi_AICD(i, v)		((v) << ASRCDRi_AICDi_SHIFT(i))
17062306a36Sopenharmony_ci#define ASRCDRi_AOCPi_SHIFT(i)		((i < 2) ? 12 + i * 6 : 6)
17162306a36Sopenharmony_ci#define ASRCDRi_AOCPi_MASK(i)		(((1 << ASRCDRi_AxCPi_WIDTH) - 1) << ASRCDRi_AOCPi_SHIFT(i))
17262306a36Sopenharmony_ci#define ASRCDRi_AOCP(i, v)		((v) << ASRCDRi_AOCPi_SHIFT(i))
17362306a36Sopenharmony_ci#define ASRCDRi_AOCDi_SHIFT(i)		((i < 2) ? 15 + i * 6 : 9)
17462306a36Sopenharmony_ci#define ASRCDRi_AOCDi_MASK(i)		(((1 << ASRCDRi_AxCPi_WIDTH) - 1) << ASRCDRi_AOCDi_SHIFT(i))
17562306a36Sopenharmony_ci#define ASRCDRi_AOCD(i, v)		((v) << ASRCDRi_AOCDi_SHIFT(i))
17662306a36Sopenharmony_ci
17762306a36Sopenharmony_ci/* REG7 0x20 REG_ASRSTR */
17862306a36Sopenharmony_ci#define ASRSTR_DSLCNT_SHIFT		21
17962306a36Sopenharmony_ci#define ASRSTR_DSLCNT_MASK		(1 << ASRSTR_DSLCNT_SHIFT)
18062306a36Sopenharmony_ci#define ASRSTR_DSLCNT			(1 << ASRSTR_DSLCNT_SHIFT)
18162306a36Sopenharmony_ci#define ASRSTR_ATQOL_SHIFT		20
18262306a36Sopenharmony_ci#define ASRSTR_ATQOL_MASK		(1 << ASRSTR_ATQOL_SHIFT)
18362306a36Sopenharmony_ci#define ASRSTR_ATQOL			(1 << ASRSTR_ATQOL_SHIFT)
18462306a36Sopenharmony_ci#define ASRSTR_AOOLi_SHIFT(i)		(17 + i)
18562306a36Sopenharmony_ci#define ASRSTR_AOOLi_MASK(i)		(1 << ASRSTR_AOOLi_SHIFT(i))
18662306a36Sopenharmony_ci#define ASRSTR_AOOL(i)			(1 << ASRSTR_AOOLi_SHIFT(i))
18762306a36Sopenharmony_ci#define ASRSTR_AIOLi_SHIFT(i)		(14 + i)
18862306a36Sopenharmony_ci#define ASRSTR_AIOLi_MASK(i)		(1 << ASRSTR_AIOLi_SHIFT(i))
18962306a36Sopenharmony_ci#define ASRSTR_AIOL(i)			(1 << ASRSTR_AIOLi_SHIFT(i))
19062306a36Sopenharmony_ci#define ASRSTR_AODOi_SHIFT(i)		(11 + i)
19162306a36Sopenharmony_ci#define ASRSTR_AODOi_MASK(i)		(1 << ASRSTR_AODOi_SHIFT(i))
19262306a36Sopenharmony_ci#define ASRSTR_AODO(i)			(1 << ASRSTR_AODOi_SHIFT(i))
19362306a36Sopenharmony_ci#define ASRSTR_AIDUi_SHIFT(i)		(8 + i)
19462306a36Sopenharmony_ci#define ASRSTR_AIDUi_MASK(i)		(1 << ASRSTR_AIDUi_SHIFT(i))
19562306a36Sopenharmony_ci#define ASRSTR_AIDU(i)			(1 << ASRSTR_AIDUi_SHIFT(i))
19662306a36Sopenharmony_ci#define ASRSTR_FPWT_SHIFT		7
19762306a36Sopenharmony_ci#define ASRSTR_FPWT_MASK		(1 << ASRSTR_FPWT_SHIFT)
19862306a36Sopenharmony_ci#define ASRSTR_FPWT			(1 << ASRSTR_FPWT_SHIFT)
19962306a36Sopenharmony_ci#define ASRSTR_AOLE_SHIFT		6
20062306a36Sopenharmony_ci#define ASRSTR_AOLE_MASK		(1 << ASRSTR_AOLE_SHIFT)
20162306a36Sopenharmony_ci#define ASRSTR_AOLE			(1 << ASRSTR_AOLE_SHIFT)
20262306a36Sopenharmony_ci#define ASRSTR_AODEi_SHIFT(i)		(3 + i)
20362306a36Sopenharmony_ci#define ASRSTR_AODFi_MASK(i)		(1 << ASRSTR_AODEi_SHIFT(i))
20462306a36Sopenharmony_ci#define ASRSTR_AODF(i)			(1 << ASRSTR_AODEi_SHIFT(i))
20562306a36Sopenharmony_ci#define ASRSTR_AIDEi_SHIFT(i)		(0 + i)
20662306a36Sopenharmony_ci#define ASRSTR_AIDEi_MASK(i)		(1 << ASRSTR_AIDEi_SHIFT(i))
20762306a36Sopenharmony_ci#define ASRSTR_AIDE(i)			(1 << ASRSTR_AIDEi_SHIFT(i))
20862306a36Sopenharmony_ci
20962306a36Sopenharmony_ci/* REG10 0x54 REG_ASRTFR1 */
21062306a36Sopenharmony_ci#define ASRTFR1_TF_BASE_WIDTH		7
21162306a36Sopenharmony_ci#define ASRTFR1_TF_BASE_SHIFT		6
21262306a36Sopenharmony_ci#define ASRTFR1_TF_BASE_MASK		(((1 << ASRTFR1_TF_BASE_WIDTH) - 1) << ASRTFR1_TF_BASE_SHIFT)
21362306a36Sopenharmony_ci#define ASRTFR1_TF_BASE(i)		((i) << ASRTFR1_TF_BASE_SHIFT)
21462306a36Sopenharmony_ci
21562306a36Sopenharmony_ci/*
21662306a36Sopenharmony_ci * REG22 0xA0 REG_ASRMCRA
21762306a36Sopenharmony_ci * REG24 0xA8 REG_ASRMCRB
21862306a36Sopenharmony_ci * REG26 0xB0 REG_ASRMCRC
21962306a36Sopenharmony_ci */
22062306a36Sopenharmony_ci#define ASRMCRi_ZEROBUFi_SHIFT		23
22162306a36Sopenharmony_ci#define ASRMCRi_ZEROBUFi_MASK		(1 << ASRMCRi_ZEROBUFi_SHIFT)
22262306a36Sopenharmony_ci#define ASRMCRi_ZEROBUFi		(1 << ASRMCRi_ZEROBUFi_SHIFT)
22362306a36Sopenharmony_ci#define ASRMCRi_EXTTHRSHi_SHIFT		22
22462306a36Sopenharmony_ci#define ASRMCRi_EXTTHRSHi_MASK		(1 << ASRMCRi_EXTTHRSHi_SHIFT)
22562306a36Sopenharmony_ci#define ASRMCRi_EXTTHRSHi		(1 << ASRMCRi_EXTTHRSHi_SHIFT)
22662306a36Sopenharmony_ci#define ASRMCRi_BUFSTALLi_SHIFT		21
22762306a36Sopenharmony_ci#define ASRMCRi_BUFSTALLi_MASK		(1 << ASRMCRi_BUFSTALLi_SHIFT)
22862306a36Sopenharmony_ci#define ASRMCRi_BUFSTALLi		(1 << ASRMCRi_BUFSTALLi_SHIFT)
22962306a36Sopenharmony_ci#define ASRMCRi_BYPASSPOLYi_SHIFT	20
23062306a36Sopenharmony_ci#define ASRMCRi_BYPASSPOLYi_MASK	(1 << ASRMCRi_BYPASSPOLYi_SHIFT)
23162306a36Sopenharmony_ci#define ASRMCRi_BYPASSPOLYi		(1 << ASRMCRi_BYPASSPOLYi_SHIFT)
23262306a36Sopenharmony_ci#define ASRMCRi_OUTFIFO_THRESHOLD_WIDTH	6
23362306a36Sopenharmony_ci#define ASRMCRi_OUTFIFO_THRESHOLD_SHIFT	12
23462306a36Sopenharmony_ci#define ASRMCRi_OUTFIFO_THRESHOLD_MASK	(((1 << ASRMCRi_OUTFIFO_THRESHOLD_WIDTH) - 1) << ASRMCRi_OUTFIFO_THRESHOLD_SHIFT)
23562306a36Sopenharmony_ci#define ASRMCRi_OUTFIFO_THRESHOLD(v)	(((v) << ASRMCRi_OUTFIFO_THRESHOLD_SHIFT) & ASRMCRi_OUTFIFO_THRESHOLD_MASK)
23662306a36Sopenharmony_ci#define ASRMCRi_RSYNIFi_SHIFT		11
23762306a36Sopenharmony_ci#define ASRMCRi_RSYNIFi_MASK		(1 << ASRMCRi_RSYNIFi_SHIFT)
23862306a36Sopenharmony_ci#define ASRMCRi_RSYNIFi			(1 << ASRMCRi_RSYNIFi_SHIFT)
23962306a36Sopenharmony_ci#define ASRMCRi_RSYNOFi_SHIFT		10
24062306a36Sopenharmony_ci#define ASRMCRi_RSYNOFi_MASK		(1 << ASRMCRi_RSYNOFi_SHIFT)
24162306a36Sopenharmony_ci#define ASRMCRi_RSYNOFi			(1 << ASRMCRi_RSYNOFi_SHIFT)
24262306a36Sopenharmony_ci#define ASRMCRi_INFIFO_THRESHOLD_WIDTH	6
24362306a36Sopenharmony_ci#define ASRMCRi_INFIFO_THRESHOLD_SHIFT	0
24462306a36Sopenharmony_ci#define ASRMCRi_INFIFO_THRESHOLD_MASK	(((1 << ASRMCRi_INFIFO_THRESHOLD_WIDTH) - 1) << ASRMCRi_INFIFO_THRESHOLD_SHIFT)
24562306a36Sopenharmony_ci#define ASRMCRi_INFIFO_THRESHOLD(v)	(((v) << ASRMCRi_INFIFO_THRESHOLD_SHIFT) & ASRMCRi_INFIFO_THRESHOLD_MASK)
24662306a36Sopenharmony_ci
24762306a36Sopenharmony_ci/*
24862306a36Sopenharmony_ci * REG23 0xA4 REG_ASRFSTA
24962306a36Sopenharmony_ci * REG25 0xAC REG_ASRFSTB
25062306a36Sopenharmony_ci * REG27 0xB4 REG_ASRFSTC
25162306a36Sopenharmony_ci */
25262306a36Sopenharmony_ci#define ASRFSTi_OAFi_SHIFT		23
25362306a36Sopenharmony_ci#define ASRFSTi_OAFi_MASK		(1 << ASRFSTi_OAFi_SHIFT)
25462306a36Sopenharmony_ci#define ASRFSTi_OAFi			(1 << ASRFSTi_OAFi_SHIFT)
25562306a36Sopenharmony_ci#define ASRFSTi_OUTPUT_FIFO_WIDTH	7
25662306a36Sopenharmony_ci#define ASRFSTi_OUTPUT_FIFO_SHIFT	12
25762306a36Sopenharmony_ci#define ASRFSTi_OUTPUT_FIFO_MASK	(((1 << ASRFSTi_OUTPUT_FIFO_WIDTH) - 1) << ASRFSTi_OUTPUT_FIFO_SHIFT)
25862306a36Sopenharmony_ci#define ASRFSTi_IAEi_SHIFT		11
25962306a36Sopenharmony_ci#define ASRFSTi_IAEi_MASK		(1 << ASRFSTi_IAEi_SHIFT)
26062306a36Sopenharmony_ci#define ASRFSTi_IAEi			(1 << ASRFSTi_IAEi_SHIFT)
26162306a36Sopenharmony_ci#define ASRFSTi_INPUT_FIFO_WIDTH	7
26262306a36Sopenharmony_ci#define ASRFSTi_INPUT_FIFO_SHIFT	0
26362306a36Sopenharmony_ci#define ASRFSTi_INPUT_FIFO_MASK		((1 << ASRFSTi_INPUT_FIFO_WIDTH) - 1)
26462306a36Sopenharmony_ci
26562306a36Sopenharmony_ci/* REG28 0xC0 & 0xC4 & 0xC8 REG_ASRMCR1i */
26662306a36Sopenharmony_ci#define ASRMCR1i_IWD_WIDTH		3
26762306a36Sopenharmony_ci#define ASRMCR1i_IWD_SHIFT		9
26862306a36Sopenharmony_ci#define ASRMCR1i_IWD_MASK		(((1 << ASRMCR1i_IWD_WIDTH) - 1) << ASRMCR1i_IWD_SHIFT)
26962306a36Sopenharmony_ci#define ASRMCR1i_IWD(v)			((v) << ASRMCR1i_IWD_SHIFT)
27062306a36Sopenharmony_ci#define ASRMCR1i_IMSB_SHIFT		8
27162306a36Sopenharmony_ci#define ASRMCR1i_IMSB_MASK		(1 << ASRMCR1i_IMSB_SHIFT)
27262306a36Sopenharmony_ci#define ASRMCR1i_IMSB_MSB		(1 << ASRMCR1i_IMSB_SHIFT)
27362306a36Sopenharmony_ci#define ASRMCR1i_IMSB_LSB		(0 << ASRMCR1i_IMSB_SHIFT)
27462306a36Sopenharmony_ci#define ASRMCR1i_OMSB_SHIFT		2
27562306a36Sopenharmony_ci#define ASRMCR1i_OMSB_MASK		(1 << ASRMCR1i_OMSB_SHIFT)
27662306a36Sopenharmony_ci#define ASRMCR1i_OMSB_MSB		(1 << ASRMCR1i_OMSB_SHIFT)
27762306a36Sopenharmony_ci#define ASRMCR1i_OMSB_LSB		(0 << ASRMCR1i_OMSB_SHIFT)
27862306a36Sopenharmony_ci#define ASRMCR1i_OSGN_SHIFT		1
27962306a36Sopenharmony_ci#define ASRMCR1i_OSGN_MASK		(1 << ASRMCR1i_OSGN_SHIFT)
28062306a36Sopenharmony_ci#define ASRMCR1i_OSGN			(1 << ASRMCR1i_OSGN_SHIFT)
28162306a36Sopenharmony_ci#define ASRMCR1i_OW16_SHIFT		0
28262306a36Sopenharmony_ci#define ASRMCR1i_OW16_MASK		(1 << ASRMCR1i_OW16_SHIFT)
28362306a36Sopenharmony_ci#define ASRMCR1i_OW16(v)		((v) << ASRMCR1i_OW16_SHIFT)
28462306a36Sopenharmony_ci
28562306a36Sopenharmony_ci#define ASRC_PAIR_MAX_NUM	(ASRC_PAIR_C + 1)
28662306a36Sopenharmony_ci
28762306a36Sopenharmony_cienum asrc_inclk {
28862306a36Sopenharmony_ci	INCLK_NONE = 0x03,
28962306a36Sopenharmony_ci	INCLK_ESAI_RX = 0x00,
29062306a36Sopenharmony_ci	INCLK_SSI1_RX = 0x01,
29162306a36Sopenharmony_ci	INCLK_SSI2_RX = 0x02,
29262306a36Sopenharmony_ci	INCLK_SSI3_RX = 0x07,
29362306a36Sopenharmony_ci	INCLK_SPDIF_RX = 0x04,
29462306a36Sopenharmony_ci	INCLK_MLB_CLK = 0x05,
29562306a36Sopenharmony_ci	INCLK_PAD = 0x06,
29662306a36Sopenharmony_ci	INCLK_ESAI_TX = 0x08,
29762306a36Sopenharmony_ci	INCLK_SSI1_TX = 0x09,
29862306a36Sopenharmony_ci	INCLK_SSI2_TX = 0x0a,
29962306a36Sopenharmony_ci	INCLK_SSI3_TX = 0x0b,
30062306a36Sopenharmony_ci	INCLK_SPDIF_TX = 0x0c,
30162306a36Sopenharmony_ci	INCLK_ASRCK1_CLK = 0x0f,
30262306a36Sopenharmony_ci
30362306a36Sopenharmony_ci	/* clocks for imx8 */
30462306a36Sopenharmony_ci	INCLK_AUD_PLL_DIV_CLK0 = 0x10,
30562306a36Sopenharmony_ci	INCLK_AUD_PLL_DIV_CLK1 = 0x11,
30662306a36Sopenharmony_ci	INCLK_AUD_CLK0         = 0x12,
30762306a36Sopenharmony_ci	INCLK_AUD_CLK1         = 0x13,
30862306a36Sopenharmony_ci	INCLK_ESAI0_RX_CLK     = 0x14,
30962306a36Sopenharmony_ci	INCLK_ESAI0_TX_CLK     = 0x15,
31062306a36Sopenharmony_ci	INCLK_SPDIF0_RX        = 0x16,
31162306a36Sopenharmony_ci	INCLK_SPDIF1_RX        = 0x17,
31262306a36Sopenharmony_ci	INCLK_SAI0_RX_BCLK     = 0x18,
31362306a36Sopenharmony_ci	INCLK_SAI0_TX_BCLK     = 0x19,
31462306a36Sopenharmony_ci	INCLK_SAI1_RX_BCLK     = 0x1a,
31562306a36Sopenharmony_ci	INCLK_SAI1_TX_BCLK     = 0x1b,
31662306a36Sopenharmony_ci	INCLK_SAI2_RX_BCLK     = 0x1c,
31762306a36Sopenharmony_ci	INCLK_SAI3_RX_BCLK     = 0x1d,
31862306a36Sopenharmony_ci	INCLK_ASRC0_MUX_CLK    = 0x1e,
31962306a36Sopenharmony_ci
32062306a36Sopenharmony_ci	INCLK_ESAI1_RX_CLK     = 0x20,
32162306a36Sopenharmony_ci	INCLK_ESAI1_TX_CLK     = 0x21,
32262306a36Sopenharmony_ci	INCLK_SAI6_TX_BCLK     = 0x22,
32362306a36Sopenharmony_ci	INCLK_HDMI_RX_SAI0_RX_BCLK     = 0x24,
32462306a36Sopenharmony_ci	INCLK_HDMI_TX_SAI0_TX_BCLK     = 0x25,
32562306a36Sopenharmony_ci};
32662306a36Sopenharmony_ci
32762306a36Sopenharmony_cienum asrc_outclk {
32862306a36Sopenharmony_ci	OUTCLK_NONE = 0x03,
32962306a36Sopenharmony_ci	OUTCLK_ESAI_TX = 0x00,
33062306a36Sopenharmony_ci	OUTCLK_SSI1_TX = 0x01,
33162306a36Sopenharmony_ci	OUTCLK_SSI2_TX = 0x02,
33262306a36Sopenharmony_ci	OUTCLK_SSI3_TX = 0x07,
33362306a36Sopenharmony_ci	OUTCLK_SPDIF_TX = 0x04,
33462306a36Sopenharmony_ci	OUTCLK_MLB_CLK = 0x05,
33562306a36Sopenharmony_ci	OUTCLK_PAD = 0x06,
33662306a36Sopenharmony_ci	OUTCLK_ESAI_RX = 0x08,
33762306a36Sopenharmony_ci	OUTCLK_SSI1_RX = 0x09,
33862306a36Sopenharmony_ci	OUTCLK_SSI2_RX = 0x0a,
33962306a36Sopenharmony_ci	OUTCLK_SSI3_RX = 0x0b,
34062306a36Sopenharmony_ci	OUTCLK_SPDIF_RX = 0x0c,
34162306a36Sopenharmony_ci	OUTCLK_ASRCK1_CLK = 0x0f,
34262306a36Sopenharmony_ci
34362306a36Sopenharmony_ci	/* clocks for imx8 */
34462306a36Sopenharmony_ci	OUTCLK_AUD_PLL_DIV_CLK0 = 0x10,
34562306a36Sopenharmony_ci	OUTCLK_AUD_PLL_DIV_CLK1 = 0x11,
34662306a36Sopenharmony_ci	OUTCLK_AUD_CLK0         = 0x12,
34762306a36Sopenharmony_ci	OUTCLK_AUD_CLK1         = 0x13,
34862306a36Sopenharmony_ci	OUTCLK_ESAI0_RX_CLK     = 0x14,
34962306a36Sopenharmony_ci	OUTCLK_ESAI0_TX_CLK     = 0x15,
35062306a36Sopenharmony_ci	OUTCLK_SPDIF0_RX        = 0x16,
35162306a36Sopenharmony_ci	OUTCLK_SPDIF1_RX        = 0x17,
35262306a36Sopenharmony_ci	OUTCLK_SAI0_RX_BCLK     = 0x18,
35362306a36Sopenharmony_ci	OUTCLK_SAI0_TX_BCLK     = 0x19,
35462306a36Sopenharmony_ci	OUTCLK_SAI1_RX_BCLK     = 0x1a,
35562306a36Sopenharmony_ci	OUTCLK_SAI1_TX_BCLK     = 0x1b,
35662306a36Sopenharmony_ci	OUTCLK_SAI2_RX_BCLK     = 0x1c,
35762306a36Sopenharmony_ci	OUTCLK_SAI3_RX_BCLK     = 0x1d,
35862306a36Sopenharmony_ci	OUTCLK_ASRCO_MUX_CLK    = 0x1e,
35962306a36Sopenharmony_ci
36062306a36Sopenharmony_ci	OUTCLK_ESAI1_RX_CLK     = 0x20,
36162306a36Sopenharmony_ci	OUTCLK_ESAI1_TX_CLK     = 0x21,
36262306a36Sopenharmony_ci	OUTCLK_SAI6_TX_BCLK     = 0x22,
36362306a36Sopenharmony_ci	OUTCLK_HDMI_RX_SAI0_RX_BCLK     = 0x24,
36462306a36Sopenharmony_ci	OUTCLK_HDMI_TX_SAI0_TX_BCLK     = 0x25,
36562306a36Sopenharmony_ci};
36662306a36Sopenharmony_ci
36762306a36Sopenharmony_ci#define ASRC_CLK_MAX_NUM	16
36862306a36Sopenharmony_ci#define ASRC_CLK_MAP_LEN	0x30
36962306a36Sopenharmony_ci
37062306a36Sopenharmony_cienum asrc_word_width {
37162306a36Sopenharmony_ci	ASRC_WIDTH_24_BIT = 0,
37262306a36Sopenharmony_ci	ASRC_WIDTH_16_BIT = 1,
37362306a36Sopenharmony_ci	ASRC_WIDTH_8_BIT = 2,
37462306a36Sopenharmony_ci};
37562306a36Sopenharmony_ci
37662306a36Sopenharmony_cistruct asrc_config {
37762306a36Sopenharmony_ci	enum asrc_pair_index pair;
37862306a36Sopenharmony_ci	unsigned int channel_num;
37962306a36Sopenharmony_ci	unsigned int buffer_num;
38062306a36Sopenharmony_ci	unsigned int dma_buffer_size;
38162306a36Sopenharmony_ci	unsigned int input_sample_rate;
38262306a36Sopenharmony_ci	unsigned int output_sample_rate;
38362306a36Sopenharmony_ci	snd_pcm_format_t input_format;
38462306a36Sopenharmony_ci	snd_pcm_format_t output_format;
38562306a36Sopenharmony_ci	enum asrc_inclk inclk;
38662306a36Sopenharmony_ci	enum asrc_outclk outclk;
38762306a36Sopenharmony_ci};
38862306a36Sopenharmony_ci
38962306a36Sopenharmony_cistruct asrc_req {
39062306a36Sopenharmony_ci	unsigned int chn_num;
39162306a36Sopenharmony_ci	enum asrc_pair_index index;
39262306a36Sopenharmony_ci};
39362306a36Sopenharmony_ci
39462306a36Sopenharmony_cistruct asrc_querybuf {
39562306a36Sopenharmony_ci	unsigned int buffer_index;
39662306a36Sopenharmony_ci	unsigned int input_length;
39762306a36Sopenharmony_ci	unsigned int output_length;
39862306a36Sopenharmony_ci	unsigned long input_offset;
39962306a36Sopenharmony_ci	unsigned long output_offset;
40062306a36Sopenharmony_ci};
40162306a36Sopenharmony_ci
40262306a36Sopenharmony_cistruct asrc_convert_buffer {
40362306a36Sopenharmony_ci	void *input_buffer_vaddr;
40462306a36Sopenharmony_ci	void *output_buffer_vaddr;
40562306a36Sopenharmony_ci	unsigned int input_buffer_length;
40662306a36Sopenharmony_ci	unsigned int output_buffer_length;
40762306a36Sopenharmony_ci};
40862306a36Sopenharmony_ci
40962306a36Sopenharmony_cistruct asrc_status_flags {
41062306a36Sopenharmony_ci	enum asrc_pair_index index;
41162306a36Sopenharmony_ci	unsigned int overload_error;
41262306a36Sopenharmony_ci};
41362306a36Sopenharmony_ci
41462306a36Sopenharmony_cienum asrc_error_status {
41562306a36Sopenharmony_ci	ASRC_TASK_Q_OVERLOAD		= 0x01,
41662306a36Sopenharmony_ci	ASRC_OUTPUT_TASK_OVERLOAD	= 0x02,
41762306a36Sopenharmony_ci	ASRC_INPUT_TASK_OVERLOAD	= 0x04,
41862306a36Sopenharmony_ci	ASRC_OUTPUT_BUFFER_OVERFLOW	= 0x08,
41962306a36Sopenharmony_ci	ASRC_INPUT_BUFFER_UNDERRUN	= 0x10,
42062306a36Sopenharmony_ci};
42162306a36Sopenharmony_ci
42262306a36Sopenharmony_cistruct dma_block {
42362306a36Sopenharmony_ci	dma_addr_t dma_paddr;
42462306a36Sopenharmony_ci	void *dma_vaddr;
42562306a36Sopenharmony_ci	unsigned int length;
42662306a36Sopenharmony_ci};
42762306a36Sopenharmony_ci
42862306a36Sopenharmony_ci/**
42962306a36Sopenharmony_ci * fsl_asrc_soc_data: soc specific data
43062306a36Sopenharmony_ci *
43162306a36Sopenharmony_ci * @use_edma: using edma as dma device or not
43262306a36Sopenharmony_ci * @channel_bits: width of ASRCNCR register for each pair
43362306a36Sopenharmony_ci */
43462306a36Sopenharmony_cistruct fsl_asrc_soc_data {
43562306a36Sopenharmony_ci	bool use_edma;
43662306a36Sopenharmony_ci	unsigned int channel_bits;
43762306a36Sopenharmony_ci};
43862306a36Sopenharmony_ci
43962306a36Sopenharmony_ci/**
44062306a36Sopenharmony_ci * fsl_asrc_pair_priv: ASRC Pair private data
44162306a36Sopenharmony_ci *
44262306a36Sopenharmony_ci * @config: configuration profile
44362306a36Sopenharmony_ci */
44462306a36Sopenharmony_cistruct fsl_asrc_pair_priv {
44562306a36Sopenharmony_ci	struct asrc_config *config;
44662306a36Sopenharmony_ci};
44762306a36Sopenharmony_ci
44862306a36Sopenharmony_ci/**
44962306a36Sopenharmony_ci * fsl_asrc_priv: ASRC private data
45062306a36Sopenharmony_ci *
45162306a36Sopenharmony_ci * @asrck_clk: clock sources to driver ASRC internal logic
45262306a36Sopenharmony_ci * @soc: soc specific data
45362306a36Sopenharmony_ci * @clk_map: clock map for input/output clock
45462306a36Sopenharmony_ci * @regcache_cfg: store register value of REG_ASRCFG
45562306a36Sopenharmony_ci */
45662306a36Sopenharmony_cistruct fsl_asrc_priv {
45762306a36Sopenharmony_ci	struct clk *asrck_clk[ASRC_CLK_MAX_NUM];
45862306a36Sopenharmony_ci	const struct fsl_asrc_soc_data *soc;
45962306a36Sopenharmony_ci	unsigned char *clk_map[2];
46062306a36Sopenharmony_ci
46162306a36Sopenharmony_ci	u32 regcache_cfg;
46262306a36Sopenharmony_ci};
46362306a36Sopenharmony_ci
46462306a36Sopenharmony_ci#endif /* _FSL_ASRC_H */
465