xref: /linux/sound/soc/tegra/tegra210_mbdrc.h (revision 7ae9fb1b7ecbb5d85d07857943f677fd1a559b18)
17358a803SSameer Pujar /* SPDX-License-Identifier: GPL-2.0-only */
27358a803SSameer Pujar /*
37358a803SSameer Pujar  * tegra210_mbdrc.h - Definitions for Tegra210 MBDRC driver
47358a803SSameer Pujar  *
57358a803SSameer Pujar  * Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
67358a803SSameer Pujar  *
77358a803SSameer Pujar  */
87358a803SSameer Pujar 
97358a803SSameer Pujar #ifndef __TEGRA210_MBDRC_H__
107358a803SSameer Pujar #define __TEGRA210_MBDRC_H__
117358a803SSameer Pujar 
127358a803SSameer Pujar #include <linux/platform_device.h>
137358a803SSameer Pujar #include <sound/soc.h>
147358a803SSameer Pujar 
157358a803SSameer Pujar /* Register offsets from TEGRA210_MBDRC*_BASE */
167358a803SSameer Pujar #define TEGRA210_MBDRC_SOFT_RESET			0x4
177358a803SSameer Pujar #define TEGRA210_MBDRC_CG				0x8
187358a803SSameer Pujar #define TEGRA210_MBDRC_STATUS				0xc
197358a803SSameer Pujar #define TEGRA210_MBDRC_CFG				0x28
207358a803SSameer Pujar #define TEGRA210_MBDRC_CHANNEL_MASK			0x2c
217358a803SSameer Pujar #define TEGRA210_MBDRC_MASTER_VOL			0x30
227358a803SSameer Pujar #define TEGRA210_MBDRC_FAST_FACTOR			0x34
237358a803SSameer Pujar 
247358a803SSameer Pujar #define TEGRA210_MBDRC_FILTER_COUNT			3
257358a803SSameer Pujar #define TEGRA210_MBDRC_FILTER_PARAM_STRIDE		0x4
267358a803SSameer Pujar 
277358a803SSameer Pujar #define TEGRA210_MBDRC_IIR_CFG				0x38
287358a803SSameer Pujar #define TEGRA210_MBDRC_IN_ATTACK			0x44
297358a803SSameer Pujar #define TEGRA210_MBDRC_IN_RELEASE			0x50
307358a803SSameer Pujar #define TEGRA210_MBDRC_FAST_ATTACK			0x5c
317358a803SSameer Pujar #define TEGRA210_MBDRC_IN_THRESHOLD			0x68
327358a803SSameer Pujar #define TEGRA210_MBDRC_OUT_THRESHOLD			0x74
337358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_1ST			0x80
347358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_2ND			0x8c
357358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_3RD			0x98
367358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_4TH			0xa4
377358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_5TH			0xb0
387358a803SSameer Pujar #define TEGRA210_MBDRC_MAKEUP_GAIN			0xbc
397358a803SSameer Pujar #define TEGRA210_MBDRC_INIT_GAIN			0xc8
407358a803SSameer Pujar #define TEGRA210_MBDRC_GAIN_ATTACK			0xd4
417358a803SSameer Pujar #define TEGRA210_MBDRC_GAIN_RELEASE			0xe0
427358a803SSameer Pujar #define TEGRA210_MBDRC_FAST_RELEASE			0xec
437358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_RAM_CTRL			0xf8
447358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_RAM_DATA			0x104
457358a803SSameer Pujar 
467358a803SSameer Pujar #define TEGRA210_MBDRC_MAX_REG				(TEGRA210_MBDRC_CFG_RAM_DATA +		\
477358a803SSameer Pujar 							 (TEGRA210_MBDRC_FILTER_PARAM_STRIDE *	\
487358a803SSameer Pujar 							  (TEGRA210_MBDRC_FILTER_COUNT - 1)))
497358a803SSameer Pujar 
507358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_CFG */
517358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_RMS_OFFSET_SHIFT		16
527358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_RMS_OFFSET_MASK		(0x1ff << TEGRA210_MBDRC_CFG_RMS_OFFSET_SHIFT)
537358a803SSameer Pujar 
547358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_PEAK_RMS_SHIFT		14
557358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_PEAK_RMS_MASK		(0x1 << TEGRA210_MBDRC_CFG_PEAK_RMS_SHIFT)
567358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_PEAK				(1 << TEGRA210_MBDRC_CFG_PEAK_RMS_SHIFT)
577358a803SSameer Pujar 
587358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_FILTER_STRUCTURE_SHIFT	13
597358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_FILTER_STRUCTURE_MASK	(0x1 << TEGRA210_MBDRC_CFG_FILTER_STRUCTURE_SHIFT)
607358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_FILTER_STRUCTURE_FLEX	(1 << TEGRA210_MBDRC_CFG_FILTER_STRUCTURE_SHIFT)
617358a803SSameer Pujar 
627358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_SHIFT_CTRL_SHIFT		8
637358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_SHIFT_CTRL_MASK		(0x1f << TEGRA210_MBDRC_CFG_SHIFT_CTRL_SHIFT)
647358a803SSameer Pujar 
657358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_FRAME_SIZE_SHIFT		4
667358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_FRAME_SIZE_MASK		(0xf << TEGRA210_MBDRC_CFG_FRAME_SIZE_SHIFT)
677358a803SSameer Pujar 
687358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_MBDRC_MODE_SHIFT		0
697358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_MBDRC_MODE_MASK		(0x3 << TEGRA210_MBDRC_CFG_MBDRC_MODE_SHIFT)
707358a803SSameer Pujar #define TEGRA210_MBDRC_CFG_MBDRC_MODE_BYPASS		(0 << TEGRA210_MBDRC_CFG_MBDRC_MODE_SHIFT)
717358a803SSameer Pujar 
727358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_CHANNEL_MASK */
737358a803SSameer Pujar #define TEGRA210_MBDRC_CHANNEL_MASK_SHIFT		0
747358a803SSameer Pujar #define TEGRA210_MBDRC_CHANNEL_MASK_MASK		(0xff << TEGRA210_MBDRC_CHANNEL_MASK_SHIFT)
757358a803SSameer Pujar 
767358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_MASTER_VOL */
777358a803SSameer Pujar #define TEGRA210_MBDRC_MASTER_VOL_SHIFT			23
787358a803SSameer Pujar #define TEGRA210_MBDRC_MASTER_VOL_MIN			-256
797358a803SSameer Pujar #define TEGRA210_MBDRC_MASTER_VOL_MAX			256
807358a803SSameer Pujar 
817358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_FAST_FACTOR */
827358a803SSameer Pujar #define TEGRA210_MBDRC_FAST_FACTOR_RELEASE_SHIFT	16
837358a803SSameer Pujar #define TEGRA210_MBDRC_FAST_FACTOR_RELEASE_MASK		(0xffff << TEGRA210_MBDRC_FAST_FACTOR_RELEASE_SHIFT)
847358a803SSameer Pujar 
857358a803SSameer Pujar #define TEGRA210_MBDRC_FAST_FACTOR_ATTACK_SHIFT		0
867358a803SSameer Pujar #define TEGRA210_MBDRC_FAST_FACTOR_ATTACK_MASK		(0xffff << TEGRA210_MBDRC_FAST_FACTOR_ATTACK_SHIFT)
877358a803SSameer Pujar 
887358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_IIR_CFG */
897358a803SSameer Pujar #define TEGRA210_MBDRC_IIR_CFG_NUM_STAGES_SHIFT		0
907358a803SSameer Pujar #define TEGRA210_MBDRC_IIR_CFG_NUM_STAGES_MASK		(0xf << TEGRA210_MBDRC_IIR_CFG_NUM_STAGES_SHIFT)
917358a803SSameer Pujar 
927358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_IN_ATTACK */
937358a803SSameer Pujar #define TEGRA210_MBDRC_IN_ATTACK_TC_SHIFT		0
947358a803SSameer Pujar #define TEGRA210_MBDRC_IN_ATTACK_TC_MASK		(0xffffffff << TEGRA210_MBDRC_IN_ATTACK_TC_SHIFT)
957358a803SSameer Pujar 
967358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_IN_RELEASE */
977358a803SSameer Pujar #define TEGRA210_MBDRC_IN_RELEASE_TC_SHIFT		0
987358a803SSameer Pujar #define TEGRA210_MBDRC_IN_RELEASE_TC_MASK		(0xffffffff << TEGRA210_MBDRC_IN_RELEASE_TC_SHIFT)
997358a803SSameer Pujar 
1007358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_FAST_ATTACK */
1017358a803SSameer Pujar #define TEGRA210_MBDRC_FAST_ATTACK_TC_SHIFT		0
1027358a803SSameer Pujar #define TEGRA210_MBDRC_FAST_ATTACK_TC_MASK		(0xffffffff << TEGRA210_MBDRC_FAST_ATTACK_TC_SHIFT)
1037358a803SSameer Pujar 
1047358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_IN_THRESHOLD / TEGRA210_MBDRC_OUT_THRESHOLD */
1057358a803SSameer Pujar #define TEGRA210_MBDRC_THRESH_4TH_SHIFT			24
1067358a803SSameer Pujar #define TEGRA210_MBDRC_THRESH_4TH_MASK			(0xff << TEGRA210_MBDRC_THRESH_4TH_SHIFT)
1077358a803SSameer Pujar 
1087358a803SSameer Pujar #define TEGRA210_MBDRC_THRESH_3RD_SHIFT			16
1097358a803SSameer Pujar #define TEGRA210_MBDRC_THRESH_3RD_MASK			(0xff << TEGRA210_MBDRC_THRESH_3RD_SHIFT)
1107358a803SSameer Pujar 
1117358a803SSameer Pujar #define TEGRA210_MBDRC_THRESH_2ND_SHIFT			8
1127358a803SSameer Pujar #define TEGRA210_MBDRC_THRESH_2ND_MASK			(0xff << TEGRA210_MBDRC_THRESH_2ND_SHIFT)
1137358a803SSameer Pujar 
1147358a803SSameer Pujar #define TEGRA210_MBDRC_THRESH_1ST_SHIFT			0
1157358a803SSameer Pujar #define TEGRA210_MBDRC_THRESH_1ST_MASK			(0xff << TEGRA210_MBDRC_THRESH_1ST_SHIFT)
1167358a803SSameer Pujar 
1177358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_RATIO_1ST */
1187358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_1ST_SHIFT			0
1197358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_1ST_MASK			(0xffff << TEGRA210_MBDRC_RATIO_1ST_SHIFT)
1207358a803SSameer Pujar 
1217358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_RATIO_2ND */
1227358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_2ND_SHIFT			0
1237358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_2ND_MASK			(0xffff << TEGRA210_MBDRC_RATIO_2ND_SHIFT)
1247358a803SSameer Pujar 
1257358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_RATIO_3RD */
1267358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_3RD_SHIFT			0
1277358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_3RD_MASK			(0xffff << TEGRA210_MBDRC_RATIO_3RD_SHIFT)
1287358a803SSameer Pujar 
1297358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_RATIO_4TH */
1307358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_4TH_SHIFT			0
1317358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_4TH_MASK			(0xffff << TEGRA210_MBDRC_RATIO_4TH_SHIFT)
1327358a803SSameer Pujar 
1337358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_RATIO_5TH */
1347358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_5TH_SHIFT			0
1357358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_5TH_MASK			(0xffff << TEGRA210_MBDRC_RATIO_5TH_SHIFT)
1367358a803SSameer Pujar 
1377358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_MAKEUP_GAIN */
1387358a803SSameer Pujar #define TEGRA210_MBDRC_MAKEUP_GAIN_SHIFT		0
1397358a803SSameer Pujar #define TEGRA210_MBDRC_MAKEUP_GAIN_MASK			(0x3f << TEGRA210_MBDRC_MAKEUP_GAIN_SHIFT)
1407358a803SSameer Pujar 
1417358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_INIT_GAIN */
1427358a803SSameer Pujar #define TEGRA210_MBDRC_INIT_GAIN_SHIFT			0
1437358a803SSameer Pujar #define TEGRA210_MBDRC_INIT_GAIN_MASK			(0xffffffff << TEGRA210_MBDRC_INIT_GAIN_SHIFT)
1447358a803SSameer Pujar 
1457358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_GAIN_ATTACK */
1467358a803SSameer Pujar #define TEGRA210_MBDRC_GAIN_ATTACK_SHIFT		0
1477358a803SSameer Pujar #define TEGRA210_MBDRC_GAIN_ATTACK_MASK			(0xffffffff << TEGRA210_MBDRC_GAIN_ATTACK_SHIFT)
1487358a803SSameer Pujar 
1497358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_GAIN_RELEASE */
1507358a803SSameer Pujar #define TEGRA210_MBDRC_GAIN_RELEASE_SHIFT		0
1517358a803SSameer Pujar #define TEGRA210_MBDRC_GAIN_RELEASE_MASK		(0xffffffff << TEGRA210_MBDRC_GAIN_RELEASE_SHIFT)
1527358a803SSameer Pujar 
1537358a803SSameer Pujar /* Fields for TEGRA210_MBDRC_FAST_RELEASE */
1547358a803SSameer Pujar #define TEGRA210_MBDRC_FAST_RELEASE_SHIFT		0
1557358a803SSameer Pujar #define TEGRA210_MBDRC_FAST_RELEASE_MASK		(0xffffffff << TEGRA210_MBDRC_FAST_RELEASE_SHIFT)
1567358a803SSameer Pujar 
1577358a803SSameer Pujar #define TEGRA210_MBDRC_RAM_CTRL_RW_READ			0
1587358a803SSameer Pujar #define TEGRA210_MBDRC_RAM_CTRL_RW_WRITE		(1 << 14)
1597358a803SSameer Pujar #define TEGRA210_MBDRC_RAM_CTRL_ADDR_INIT_EN		(1 << 13)
1607358a803SSameer Pujar #define TEGRA210_MBDRC_RAM_CTRL_SEQ_ACCESS_EN		(1 << 12)
1617358a803SSameer Pujar #define TEGRA210_MBDRC_RAM_CTRL_RAM_ADDR_MASK		0x1ff
1627358a803SSameer Pujar 
1637358a803SSameer Pujar /*
1647358a803SSameer Pujar  * Order and size of each structure element for following structures should not
1657358a803SSameer Pujar  * be altered size order of elements and their size are based on PEQ co-eff ram
1667358a803SSameer Pujar  * and shift ram layout.
1677358a803SSameer Pujar  */
1687358a803SSameer Pujar #define TEGRA210_MBDRC_THRESHOLD_NUM				4
1697358a803SSameer Pujar #define TEGRA210_MBDRC_RATIO_NUM				(TEGRA210_MBDRC_THRESHOLD_NUM + 1)
1707358a803SSameer Pujar #define TEGRA210_MBDRC_MAX_BIQUAD_STAGES			8
1717358a803SSameer Pujar 
1727358a803SSameer Pujar /* Order of these enums are same as the order of band specific hw registers */
1737358a803SSameer Pujar enum {
1747358a803SSameer Pujar 	MBDRC_LOW_BAND,
1757358a803SSameer Pujar 	MBDRC_MID_BAND,
1767358a803SSameer Pujar 	MBDRC_HIGH_BAND,
1777358a803SSameer Pujar 	MBDRC_NUM_BAND,
1787358a803SSameer Pujar };
1797358a803SSameer Pujar 
1807358a803SSameer Pujar struct tegra210_mbdrc_band_params {
1817358a803SSameer Pujar 	u32 band;
1827358a803SSameer Pujar 	u32 iir_stages;
1837358a803SSameer Pujar 	u32 in_attack_tc;
1847358a803SSameer Pujar 	u32 in_release_tc;
1857358a803SSameer Pujar 	u32 fast_attack_tc;
1867358a803SSameer Pujar 	u32 in_threshold[TEGRA210_MBDRC_THRESHOLD_NUM];
1877358a803SSameer Pujar 	u32 out_threshold[TEGRA210_MBDRC_THRESHOLD_NUM];
1887358a803SSameer Pujar 	u32 ratio[TEGRA210_MBDRC_RATIO_NUM];
1897358a803SSameer Pujar 	u32 makeup_gain;
1907358a803SSameer Pujar 	u32 gain_init;
1917358a803SSameer Pujar 	u32 gain_attack_tc;
1927358a803SSameer Pujar 	u32 gain_release_tc;
1937358a803SSameer Pujar 	u32 fast_release_tc;
1947358a803SSameer Pujar 	/* For biquad_params[][5] order of coeff is b0, b1, a0, a1, a2 */
1957358a803SSameer Pujar 	u32 biquad_params[TEGRA210_MBDRC_MAX_BIQUAD_STAGES * 5];
1967358a803SSameer Pujar };
1977358a803SSameer Pujar 
1987358a803SSameer Pujar struct tegra210_mbdrc_config {
1997358a803SSameer Pujar 	unsigned int mode;
2007358a803SSameer Pujar 	unsigned int rms_off;
2017358a803SSameer Pujar 	unsigned int peak_rms_mode;
202*f8dc9cd9SColin Ian King 	unsigned int filter_structure;
2037358a803SSameer Pujar 	unsigned int shift_ctrl;
2047358a803SSameer Pujar 	unsigned int frame_size;
2057358a803SSameer Pujar 	unsigned int channel_mask;
2067358a803SSameer Pujar 	unsigned int fa_factor;	/* Fast attack factor */
2077358a803SSameer Pujar 	unsigned int fr_factor;	/* Fast release factor */
2087358a803SSameer Pujar 	struct tegra210_mbdrc_band_params band_params[MBDRC_NUM_BAND];
2097358a803SSameer Pujar };
2107358a803SSameer Pujar 
2117358a803SSameer Pujar int tegra210_mbdrc_regmap_init(struct platform_device *pdev);
2127358a803SSameer Pujar int tegra210_mbdrc_component_init(struct snd_soc_component *cmpnt);
2137358a803SSameer Pujar int tegra210_mbdrc_hw_params(struct snd_soc_component *cmpnt);
2147358a803SSameer Pujar 
2157358a803SSameer Pujar #endif
216