xref: /linux/sound/soc/tegra/tegra210_mbdrc.h (revision 7358a803c778f28314721e78339f3fa5b787f55c)
1*7358a803SSameer Pujar /* SPDX-License-Identifier: GPL-2.0-only */
2*7358a803SSameer Pujar /*
3*7358a803SSameer Pujar  * tegra210_mbdrc.h - Definitions for Tegra210 MBDRC driver
4*7358a803SSameer Pujar  *
5*7358a803SSameer Pujar  * Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
6*7358a803SSameer Pujar  *
7*7358a803SSameer Pujar  */
8*7358a803SSameer Pujar 
9*7358a803SSameer Pujar #ifndef __TEGRA210_MBDRC_H__
10*7358a803SSameer Pujar #define __TEGRA210_MBDRC_H__
11*7358a803SSameer Pujar 
12*7358a803SSameer Pujar #include <linux/platform_device.h>
13*7358a803SSameer Pujar #include <sound/soc.h>
14*7358a803SSameer Pujar 
15*7358a803SSameer Pujar /* Register offsets from TEGRA210_MBDRC*_BASE */
16*7358a803SSameer Pujar #define TEGRA210_MBDRC_SOFT_RESET			0x4
17*7358a803SSameer Pujar #define TEGRA210_MBDRC_CG				0x8
18*7358a803SSameer Pujar #define TEGRA210_MBDRC_STATUS				0xc
19*7358a803SSameer Pujar #define TEGRA210_MBDRC_CFG				0x28
20*7358a803SSameer Pujar #define TEGRA210_MBDRC_CHANNEL_MASK			0x2c
21*7358a803SSameer Pujar #define TEGRA210_MBDRC_MASTER_VOL			0x30
22*7358a803SSameer Pujar #define TEGRA210_MBDRC_FAST_FACTOR			0x34
23*7358a803SSameer Pujar 
24*7358a803SSameer Pujar #define TEGRA210_MBDRC_FILTER_COUNT			3
25*7358a803SSameer Pujar #define TEGRA210_MBDRC_FILTER_PARAM_STRIDE		0x4
26*7358a803SSameer Pujar 
27*7358a803SSameer Pujar #define TEGRA210_MBDRC_IIR_CFG				0x38
28*7358a803SSameer Pujar #define TEGRA210_MBDRC_IN_ATTACK			0x44
29*7358a803SSameer Pujar #define TEGRA210_MBDRC_IN_RELEASE			0x50
30*7358a803SSameer Pujar #define TEGRA210_MBDRC_FAST_ATTACK			0x5c
31*7358a803SSameer Pujar #define TEGRA210_MBDRC_IN_THRESHOLD			0x68
32*7358a803SSameer Pujar #define TEGRA210_MBDRC_OUT_THRESHOLD			0x74
33*7358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_1ST			0x80
34*7358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_2ND			0x8c
35*7358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_3RD			0x98
36*7358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_4TH			0xa4
37*7358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_5TH			0xb0
38*7358a803SSameer Pujar #define TEGRA210_MBDRC_MAKEUP_GAIN			0xbc
39*7358a803SSameer Pujar #define TEGRA210_MBDRC_INIT_GAIN			0xc8
40*7358a803SSameer Pujar #define TEGRA210_MBDRC_GAIN_ATTACK			0xd4
41*7358a803SSameer Pujar #define TEGRA210_MBDRC_GAIN_RELEASE			0xe0
42*7358a803SSameer Pujar #define TEGRA210_MBDRC_FAST_RELEASE			0xec
43*7358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_RAM_CTRL			0xf8
44*7358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_RAM_DATA			0x104
45*7358a803SSameer Pujar 
46*7358a803SSameer Pujar #define TEGRA210_MBDRC_MAX_REG				(TEGRA210_MBDRC_CFG_RAM_DATA +		\
47*7358a803SSameer Pujar 							 (TEGRA210_MBDRC_FILTER_PARAM_STRIDE *	\
48*7358a803SSameer Pujar 							  (TEGRA210_MBDRC_FILTER_COUNT - 1)))
49*7358a803SSameer Pujar 
50*7358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_CFG */
51*7358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_RMS_OFFSET_SHIFT		16
52*7358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_RMS_OFFSET_MASK		(0x1ff << TEGRA210_MBDRC_CFG_RMS_OFFSET_SHIFT)
53*7358a803SSameer Pujar 
54*7358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_PEAK_RMS_SHIFT		14
55*7358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_PEAK_RMS_MASK		(0x1 << TEGRA210_MBDRC_CFG_PEAK_RMS_SHIFT)
56*7358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_PEAK				(1 << TEGRA210_MBDRC_CFG_PEAK_RMS_SHIFT)
57*7358a803SSameer Pujar 
58*7358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_FILTER_STRUCTURE_SHIFT	13
59*7358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_FILTER_STRUCTURE_MASK	(0x1 << TEGRA210_MBDRC_CFG_FILTER_STRUCTURE_SHIFT)
60*7358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_FILTER_STRUCTURE_FLEX	(1 << TEGRA210_MBDRC_CFG_FILTER_STRUCTURE_SHIFT)
61*7358a803SSameer Pujar 
62*7358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_SHIFT_CTRL_SHIFT		8
63*7358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_SHIFT_CTRL_MASK		(0x1f << TEGRA210_MBDRC_CFG_SHIFT_CTRL_SHIFT)
64*7358a803SSameer Pujar 
65*7358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_FRAME_SIZE_SHIFT		4
66*7358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_FRAME_SIZE_MASK		(0xf << TEGRA210_MBDRC_CFG_FRAME_SIZE_SHIFT)
67*7358a803SSameer Pujar 
68*7358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_MBDRC_MODE_SHIFT		0
69*7358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_MBDRC_MODE_MASK		(0x3 << TEGRA210_MBDRC_CFG_MBDRC_MODE_SHIFT)
70*7358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_MBDRC_MODE_BYPASS		(0 << TEGRA210_MBDRC_CFG_MBDRC_MODE_SHIFT)
71*7358a803SSameer Pujar 
72*7358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_CHANNEL_MASK */
73*7358a803SSameer Pujar #define TEGRA210_MBDRC_CHANNEL_MASK_SHIFT		0
74*7358a803SSameer Pujar #define TEGRA210_MBDRC_CHANNEL_MASK_MASK		(0xff << TEGRA210_MBDRC_CHANNEL_MASK_SHIFT)
75*7358a803SSameer Pujar 
76*7358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_MASTER_VOL */
77*7358a803SSameer Pujar #define TEGRA210_MBDRC_MASTER_VOL_SHIFT			23
78*7358a803SSameer Pujar #define TEGRA210_MBDRC_MASTER_VOL_MIN			-256
79*7358a803SSameer Pujar #define TEGRA210_MBDRC_MASTER_VOL_MAX			256
80*7358a803SSameer Pujar 
81*7358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_FAST_FACTOR */
82*7358a803SSameer Pujar #define TEGRA210_MBDRC_FAST_FACTOR_RELEASE_SHIFT	16
83*7358a803SSameer Pujar #define TEGRA210_MBDRC_FAST_FACTOR_RELEASE_MASK		(0xffff << TEGRA210_MBDRC_FAST_FACTOR_RELEASE_SHIFT)
84*7358a803SSameer Pujar 
85*7358a803SSameer Pujar #define TEGRA210_MBDRC_FAST_FACTOR_ATTACK_SHIFT		0
86*7358a803SSameer Pujar #define TEGRA210_MBDRC_FAST_FACTOR_ATTACK_MASK		(0xffff << TEGRA210_MBDRC_FAST_FACTOR_ATTACK_SHIFT)
87*7358a803SSameer Pujar 
88*7358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_IIR_CFG */
89*7358a803SSameer Pujar #define TEGRA210_MBDRC_IIR_CFG_NUM_STAGES_SHIFT		0
90*7358a803SSameer Pujar #define TEGRA210_MBDRC_IIR_CFG_NUM_STAGES_MASK		(0xf << TEGRA210_MBDRC_IIR_CFG_NUM_STAGES_SHIFT)
91*7358a803SSameer Pujar 
92*7358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_IN_ATTACK */
93*7358a803SSameer Pujar #define TEGRA210_MBDRC_IN_ATTACK_TC_SHIFT		0
94*7358a803SSameer Pujar #define TEGRA210_MBDRC_IN_ATTACK_TC_MASK		(0xffffffff << TEGRA210_MBDRC_IN_ATTACK_TC_SHIFT)
95*7358a803SSameer Pujar 
96*7358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_IN_RELEASE */
97*7358a803SSameer Pujar #define TEGRA210_MBDRC_IN_RELEASE_TC_SHIFT		0
98*7358a803SSameer Pujar #define TEGRA210_MBDRC_IN_RELEASE_TC_MASK		(0xffffffff << TEGRA210_MBDRC_IN_RELEASE_TC_SHIFT)
99*7358a803SSameer Pujar 
100*7358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_FAST_ATTACK */
101*7358a803SSameer Pujar #define TEGRA210_MBDRC_FAST_ATTACK_TC_SHIFT		0
102*7358a803SSameer Pujar #define TEGRA210_MBDRC_FAST_ATTACK_TC_MASK		(0xffffffff << TEGRA210_MBDRC_FAST_ATTACK_TC_SHIFT)
103*7358a803SSameer Pujar 
104*7358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_IN_THRESHOLD / TEGRA210_MBDRC_OUT_THRESHOLD */
105*7358a803SSameer Pujar #define TEGRA210_MBDRC_THRESH_4TH_SHIFT			24
106*7358a803SSameer Pujar #define TEGRA210_MBDRC_THRESH_4TH_MASK			(0xff << TEGRA210_MBDRC_THRESH_4TH_SHIFT)
107*7358a803SSameer Pujar 
108*7358a803SSameer Pujar #define TEGRA210_MBDRC_THRESH_3RD_SHIFT			16
109*7358a803SSameer Pujar #define TEGRA210_MBDRC_THRESH_3RD_MASK			(0xff << TEGRA210_MBDRC_THRESH_3RD_SHIFT)
110*7358a803SSameer Pujar 
111*7358a803SSameer Pujar #define TEGRA210_MBDRC_THRESH_2ND_SHIFT			8
112*7358a803SSameer Pujar #define TEGRA210_MBDRC_THRESH_2ND_MASK			(0xff << TEGRA210_MBDRC_THRESH_2ND_SHIFT)
113*7358a803SSameer Pujar 
114*7358a803SSameer Pujar #define TEGRA210_MBDRC_THRESH_1ST_SHIFT			0
115*7358a803SSameer Pujar #define TEGRA210_MBDRC_THRESH_1ST_MASK			(0xff << TEGRA210_MBDRC_THRESH_1ST_SHIFT)
116*7358a803SSameer Pujar 
117*7358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_RATIO_1ST */
118*7358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_1ST_SHIFT			0
119*7358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_1ST_MASK			(0xffff << TEGRA210_MBDRC_RATIO_1ST_SHIFT)
120*7358a803SSameer Pujar 
121*7358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_RATIO_2ND */
122*7358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_2ND_SHIFT			0
123*7358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_2ND_MASK			(0xffff << TEGRA210_MBDRC_RATIO_2ND_SHIFT)
124*7358a803SSameer Pujar 
125*7358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_RATIO_3RD */
126*7358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_3RD_SHIFT			0
127*7358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_3RD_MASK			(0xffff << TEGRA210_MBDRC_RATIO_3RD_SHIFT)
128*7358a803SSameer Pujar 
129*7358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_RATIO_4TH */
130*7358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_4TH_SHIFT			0
131*7358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_4TH_MASK			(0xffff << TEGRA210_MBDRC_RATIO_4TH_SHIFT)
132*7358a803SSameer Pujar 
133*7358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_RATIO_5TH */
134*7358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_5TH_SHIFT			0
135*7358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_5TH_MASK			(0xffff << TEGRA210_MBDRC_RATIO_5TH_SHIFT)
136*7358a803SSameer Pujar 
137*7358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_MAKEUP_GAIN */
138*7358a803SSameer Pujar #define TEGRA210_MBDRC_MAKEUP_GAIN_SHIFT		0
139*7358a803SSameer Pujar #define TEGRA210_MBDRC_MAKEUP_GAIN_MASK			(0x3f << TEGRA210_MBDRC_MAKEUP_GAIN_SHIFT)
140*7358a803SSameer Pujar 
141*7358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_INIT_GAIN */
142*7358a803SSameer Pujar #define TEGRA210_MBDRC_INIT_GAIN_SHIFT			0
143*7358a803SSameer Pujar #define TEGRA210_MBDRC_INIT_GAIN_MASK			(0xffffffff << TEGRA210_MBDRC_INIT_GAIN_SHIFT)
144*7358a803SSameer Pujar 
145*7358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_GAIN_ATTACK */
146*7358a803SSameer Pujar #define TEGRA210_MBDRC_GAIN_ATTACK_SHIFT		0
147*7358a803SSameer Pujar #define TEGRA210_MBDRC_GAIN_ATTACK_MASK			(0xffffffff << TEGRA210_MBDRC_GAIN_ATTACK_SHIFT)
148*7358a803SSameer Pujar 
149*7358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_GAIN_RELEASE */
150*7358a803SSameer Pujar #define TEGRA210_MBDRC_GAIN_RELEASE_SHIFT		0
151*7358a803SSameer Pujar #define TEGRA210_MBDRC_GAIN_RELEASE_MASK		(0xffffffff << TEGRA210_MBDRC_GAIN_RELEASE_SHIFT)
152*7358a803SSameer Pujar 
153*7358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_FAST_RELEASE */
154*7358a803SSameer Pujar #define TEGRA210_MBDRC_FAST_RELEASE_SHIFT		0
155*7358a803SSameer Pujar #define TEGRA210_MBDRC_FAST_RELEASE_MASK		(0xffffffff << TEGRA210_MBDRC_FAST_RELEASE_SHIFT)
156*7358a803SSameer Pujar 
157*7358a803SSameer Pujar #define TEGRA210_MBDRC_RAM_CTRL_RW_READ			0
158*7358a803SSameer Pujar #define TEGRA210_MBDRC_RAM_CTRL_RW_WRITE		(1 << 14)
159*7358a803SSameer Pujar #define TEGRA210_MBDRC_RAM_CTRL_ADDR_INIT_EN		(1 << 13)
160*7358a803SSameer Pujar #define TEGRA210_MBDRC_RAM_CTRL_SEQ_ACCESS_EN		(1 << 12)
161*7358a803SSameer Pujar #define TEGRA210_MBDRC_RAM_CTRL_RAM_ADDR_MASK		0x1ff
162*7358a803SSameer Pujar 
163*7358a803SSameer Pujar /*
164*7358a803SSameer Pujar  * Order and size of each structure element for following structures should not
165*7358a803SSameer Pujar  * be altered size order of elements and their size are based on PEQ co-eff ram
166*7358a803SSameer Pujar  * and shift ram layout.
167*7358a803SSameer Pujar  */
168*7358a803SSameer Pujar #define TEGRA210_MBDRC_THRESHOLD_NUM				4
169*7358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_NUM				(TEGRA210_MBDRC_THRESHOLD_NUM + 1)
170*7358a803SSameer Pujar #define TEGRA210_MBDRC_MAX_BIQUAD_STAGES			8
171*7358a803SSameer Pujar 
172*7358a803SSameer Pujar /* Order of these enums are same as the order of band specific hw registers */
173*7358a803SSameer Pujar enum {
174*7358a803SSameer Pujar 	MBDRC_LOW_BAND,
175*7358a803SSameer Pujar 	MBDRC_MID_BAND,
176*7358a803SSameer Pujar 	MBDRC_HIGH_BAND,
177*7358a803SSameer Pujar 	MBDRC_NUM_BAND,
178*7358a803SSameer Pujar };
179*7358a803SSameer Pujar 
180*7358a803SSameer Pujar struct tegra210_mbdrc_band_params {
181*7358a803SSameer Pujar 	u32 band;
182*7358a803SSameer Pujar 	u32 iir_stages;
183*7358a803SSameer Pujar 	u32 in_attack_tc;
184*7358a803SSameer Pujar 	u32 in_release_tc;
185*7358a803SSameer Pujar 	u32 fast_attack_tc;
186*7358a803SSameer Pujar 	u32 in_threshold[TEGRA210_MBDRC_THRESHOLD_NUM];
187*7358a803SSameer Pujar 	u32 out_threshold[TEGRA210_MBDRC_THRESHOLD_NUM];
188*7358a803SSameer Pujar 	u32 ratio[TEGRA210_MBDRC_RATIO_NUM];
189*7358a803SSameer Pujar 	u32 makeup_gain;
190*7358a803SSameer Pujar 	u32 gain_init;
191*7358a803SSameer Pujar 	u32 gain_attack_tc;
192*7358a803SSameer Pujar 	u32 gain_release_tc;
193*7358a803SSameer Pujar 	u32 fast_release_tc;
194*7358a803SSameer Pujar 	/* For biquad_params[][5] order of coeff is b0, b1, a0, a1, a2 */
195*7358a803SSameer Pujar 	u32 biquad_params[TEGRA210_MBDRC_MAX_BIQUAD_STAGES * 5];
196*7358a803SSameer Pujar };
197*7358a803SSameer Pujar 
198*7358a803SSameer Pujar struct tegra210_mbdrc_config {
199*7358a803SSameer Pujar 	unsigned int mode;
200*7358a803SSameer Pujar 	unsigned int rms_off;
201*7358a803SSameer Pujar 	unsigned int peak_rms_mode;
202*7358a803SSameer Pujar 	unsigned int fliter_structure;
203*7358a803SSameer Pujar 	unsigned int shift_ctrl;
204*7358a803SSameer Pujar 	unsigned int frame_size;
205*7358a803SSameer Pujar 	unsigned int channel_mask;
206*7358a803SSameer Pujar 	unsigned int fa_factor;	/* Fast attack factor */
207*7358a803SSameer Pujar 	unsigned int fr_factor;	/* Fast release factor */
208*7358a803SSameer Pujar 	struct tegra210_mbdrc_band_params band_params[MBDRC_NUM_BAND];
209*7358a803SSameer Pujar };
210*7358a803SSameer Pujar 
211*7358a803SSameer Pujar int tegra210_mbdrc_regmap_init(struct platform_device *pdev);
212*7358a803SSameer Pujar int tegra210_mbdrc_component_init(struct snd_soc_component *cmpnt);
213*7358a803SSameer Pujar int tegra210_mbdrc_hw_params(struct snd_soc_component *cmpnt);
214*7358a803SSameer Pujar 
215*7358a803SSameer Pujar #endif
216