162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * cs42l52.h -- CS42L52 ALSA SoC audio driver
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright 2012 CirrusLogic, Inc.
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Author: Georgi Vlaev <joe@nucleusys.com>
862306a36Sopenharmony_ci * Author: Brian Austin <brian.austin@cirrus.com>
962306a36Sopenharmony_ci */
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#ifndef __CS42L52_H__
1262306a36Sopenharmony_ci#define __CS42L52_H__
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci#define CS42L52_NAME				"CS42L52"
1562306a36Sopenharmony_ci#define CS42L52_DEFAULT_CLK			12000000
1662306a36Sopenharmony_ci#define CS42L52_MIN_CLK				11000000
1762306a36Sopenharmony_ci#define CS42L52_MAX_CLK				27000000
1862306a36Sopenharmony_ci#define CS42L52_DEFAULT_FORMAT			SNDRV_PCM_FMTBIT_S16_LE
1962306a36Sopenharmony_ci#define CS42L52_DEFAULT_MAX_CHANS		2
2062306a36Sopenharmony_ci#define CS42L52_SYSCLK				1
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci#define CS42L52_CHIP_SWICTH			(1 << 17)
2362306a36Sopenharmony_ci#define CS42L52_ALL_IN_ONE			(1 << 16)
2462306a36Sopenharmony_ci#define CS42L52_CHIP_ONE			0x00
2562306a36Sopenharmony_ci#define CS42L52_CHIP_TWO			0x01
2662306a36Sopenharmony_ci#define CS42L52_CHIP_THR			0x02
2762306a36Sopenharmony_ci#define CS42L52_CHIP_MASK			0x0f
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci#define CS42L52_FIX_BITS_CTL			0x00
3062306a36Sopenharmony_ci#define CS42L52_CHIP				0x01
3162306a36Sopenharmony_ci#define CS42L52_CHIP_ID				0xE0
3262306a36Sopenharmony_ci#define CS42L52_CHIP_ID_MASK			0xF8
3362306a36Sopenharmony_ci#define CS42L52_CHIP_REV_A0			0x00
3462306a36Sopenharmony_ci#define CS42L52_CHIP_REV_A1			0x01
3562306a36Sopenharmony_ci#define CS42L52_CHIP_REV_B0			0x02
3662306a36Sopenharmony_ci#define CS42L52_CHIP_REV_MASK			0x07
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci#define CS42L52_PWRCTL1				0x02
3962306a36Sopenharmony_ci#define CS42L52_PWRCTL1_PDN_ALL			0x9F
4062306a36Sopenharmony_ci#define CS42L52_PWRCTL1_PDN_CHRG		0x80
4162306a36Sopenharmony_ci#define CS42L52_PWRCTL1_PDN_PGAB		0x10
4262306a36Sopenharmony_ci#define CS42L52_PWRCTL1_PDN_PGAA		0x08
4362306a36Sopenharmony_ci#define CS42L52_PWRCTL1_PDN_ADCB		0x04
4462306a36Sopenharmony_ci#define CS42L52_PWRCTL1_PDN_ADCA		0x02
4562306a36Sopenharmony_ci#define CS42L52_PWRCTL1_PDN_CODEC		0x01
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci#define CS42L52_PWRCTL2				0x03
4862306a36Sopenharmony_ci#define CS42L52_PWRCTL2_OVRDB			(1 << 4)
4962306a36Sopenharmony_ci#define CS42L52_PWRCTL2_OVRDA			(1 << 3)
5062306a36Sopenharmony_ci#define	CS42L52_PWRCTL2_PDN_MICB		(1 << 2)
5162306a36Sopenharmony_ci#define CS42L52_PWRCTL2_PDN_MICB_SHIFT		2
5262306a36Sopenharmony_ci#define CS42L52_PWRCTL2_PDN_MICA		(1 << 1)
5362306a36Sopenharmony_ci#define CS42L52_PWRCTL2_PDN_MICA_SHIFT		1
5462306a36Sopenharmony_ci#define CS42L52_PWRCTL2_PDN_MICBIAS		(1 << 0)
5562306a36Sopenharmony_ci#define CS42L52_PWRCTL2_PDN_MICBIAS_SHIFT	0
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci#define CS42L52_PWRCTL3				0x04
5862306a36Sopenharmony_ci#define CS42L52_PWRCTL3_HPB_PDN_SHIFT		6
5962306a36Sopenharmony_ci#define CS42L52_PWRCTL3_HPB_ON_LOW		0x00
6062306a36Sopenharmony_ci#define CS42L52_PWRCTL3_HPB_ON_HIGH		0x01
6162306a36Sopenharmony_ci#define CS42L52_PWRCTL3_HPB_ALWAYS_ON		0x02
6262306a36Sopenharmony_ci#define CS42L52_PWRCTL3_HPB_ALWAYS_OFF		0x03
6362306a36Sopenharmony_ci#define CS42L52_PWRCTL3_HPA_PDN_SHIFT		4
6462306a36Sopenharmony_ci#define CS42L52_PWRCTL3_HPA_ON_LOW		0x00
6562306a36Sopenharmony_ci#define CS42L52_PWRCTL3_HPA_ON_HIGH		0x01
6662306a36Sopenharmony_ci#define CS42L52_PWRCTL3_HPA_ALWAYS_ON		0x02
6762306a36Sopenharmony_ci#define CS42L52_PWRCTL3_HPA_ALWAYS_OFF		0x03
6862306a36Sopenharmony_ci#define CS42L52_PWRCTL3_SPKB_PDN_SHIFT		2
6962306a36Sopenharmony_ci#define CS42L52_PWRCTL3_SPKB_ON_LOW		0x00
7062306a36Sopenharmony_ci#define CS42L52_PWRCTL3_SPKB_ON_HIGH		0x01
7162306a36Sopenharmony_ci#define CS42L52_PWRCTL3_SPKB_ALWAYS_ON		0x02
7262306a36Sopenharmony_ci#define CS42L52_PWRCTL3_PDN_SPKB		(1 << 2)
7362306a36Sopenharmony_ci#define CS42L52_PWRCTL3_PDN_SPKA		(1 << 0)
7462306a36Sopenharmony_ci#define CS42L52_PWRCTL3_SPKA_PDN_SHIFT		0
7562306a36Sopenharmony_ci#define CS42L52_PWRCTL3_SPKA_ON_LOW		0x00
7662306a36Sopenharmony_ci#define CS42L52_PWRCTL3_SPKA_ON_HIGH		0x01
7762306a36Sopenharmony_ci#define CS42L52_PWRCTL3_SPKA_ALWAYS_ON		0x02
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ci#define CS42L52_DEFAULT_OUTPUT_STATE		0x05
8062306a36Sopenharmony_ci#define CS42L52_PWRCTL3_CONF_MASK		0x03
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci#define CS42L52_CLK_CTL				0x05
8362306a36Sopenharmony_ci#define CLK_AUTODECT_ENABLE			(1 << 7)
8462306a36Sopenharmony_ci#define CLK_SPEED_SHIFT				5
8562306a36Sopenharmony_ci#define CLK_DS_MODE				0x00
8662306a36Sopenharmony_ci#define CLK_SS_MODE				0x01
8762306a36Sopenharmony_ci#define CLK_HS_MODE				0x02
8862306a36Sopenharmony_ci#define CLK_QS_MODE				0x03
8962306a36Sopenharmony_ci#define CLK_32K_SR_SHIFT			4
9062306a36Sopenharmony_ci#define CLK_32K					0x01
9162306a36Sopenharmony_ci#define CLK_NO_32K				0x00
9262306a36Sopenharmony_ci#define CLK_27M_MCLK_SHIFT			3
9362306a36Sopenharmony_ci#define CLK_27M_MCLK				0x01
9462306a36Sopenharmony_ci#define CLK_NO_27M				0x00
9562306a36Sopenharmony_ci#define CLK_RATIO_SHIFT				1
9662306a36Sopenharmony_ci#define CLK_R_128				0x00
9762306a36Sopenharmony_ci#define CLK_R_125				0x01
9862306a36Sopenharmony_ci#define CLK_R_132				0x02
9962306a36Sopenharmony_ci#define CLK_R_136				0x03
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci#define CS42L52_IFACE_CTL1			0x06
10262306a36Sopenharmony_ci#define CS42L52_IFACE_CTL1_MASTER		(1 << 7)
10362306a36Sopenharmony_ci#define CS42L52_IFACE_CTL1_SLAVE		(0 << 7)
10462306a36Sopenharmony_ci#define CS42L52_IFACE_CTL1_INV_SCLK		(1 << 6)
10562306a36Sopenharmony_ci#define CS42L52_IFACE_CTL1_ADC_FMT_I2S		(1 << 5)
10662306a36Sopenharmony_ci#define CS42L52_IFACE_CTL1_ADC_FMT_LEFT_J	(0 << 5)
10762306a36Sopenharmony_ci#define CS42L52_IFACE_CTL1_DSP_MODE_EN		(1 << 4)
10862306a36Sopenharmony_ci#define CS42L52_IFACE_CTL1_DAC_FMT_LEFT_J	(0 << 2)
10962306a36Sopenharmony_ci#define CS42L52_IFACE_CTL1_DAC_FMT_I2S		(1 << 2)
11062306a36Sopenharmony_ci#define CS42L52_IFACE_CTL1_DAC_FMT_RIGHT_J	(2 << 2)
11162306a36Sopenharmony_ci#define CS42L52_IFACE_CTL1_WL_32BIT		(0x00)
11262306a36Sopenharmony_ci#define CS42L52_IFACE_CTL1_WL_24BIT		(0x01)
11362306a36Sopenharmony_ci#define CS42L52_IFACE_CTL1_WL_20BIT		(0x02)
11462306a36Sopenharmony_ci#define CS42L52_IFACE_CTL1_WL_16BIT		(0x03)
11562306a36Sopenharmony_ci#define CS42L52_IFACE_CTL1_WL_MASK		0xFFFF
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ci#define CS42L52_IFACE_CTL2			0x07
11862306a36Sopenharmony_ci#define CS42L52_IFACE_CTL2_SC_MC_EQ		(1 << 6)
11962306a36Sopenharmony_ci#define CS42L52_IFACE_CTL2_LOOPBACK		(1 << 5)
12062306a36Sopenharmony_ci#define CS42L52_IFACE_CTL2_S_MODE_OUTPUT_EN	(0 << 4)
12162306a36Sopenharmony_ci#define CS42L52_IFACE_CTL2_S_MODE_OUTPUT_HIZ	(1 << 4)
12262306a36Sopenharmony_ci#define CS42L52_IFACE_CTL2_HP_SW_INV		(1 << 3)
12362306a36Sopenharmony_ci#define CS42L52_IFACE_CTL2_BIAS_LVL		0x07
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_ci#define CS42L52_ADC_PGA_A			0x08
12662306a36Sopenharmony_ci#define CS42L52_ADC_PGA_B			0x09
12762306a36Sopenharmony_ci#define CS42L52_ADC_SEL_SHIFT			5
12862306a36Sopenharmony_ci#define CS42L52_ADC_SEL_AIN1			0x00
12962306a36Sopenharmony_ci#define CS42L52_ADC_SEL_AIN2			0x01
13062306a36Sopenharmony_ci#define CS42L52_ADC_SEL_AIN3			0x02
13162306a36Sopenharmony_ci#define CS42L52_ADC_SEL_AIN4			0x03
13262306a36Sopenharmony_ci#define CS42L52_ADC_SEL_PGA			0x04
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ci#define CS42L52_ANALOG_HPF_CTL			0x0A
13562306a36Sopenharmony_ci#define CS42L52_HPF_CTL_ANLGSFTB		(1 << 3)
13662306a36Sopenharmony_ci#define CS42L52_HPF_CTL_ANLGSFTA                (1 << 0)
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ci#define CS42L52_ADC_HPF_FREQ			0x0B
13962306a36Sopenharmony_ci#define CS42L52_ADC_MISC_CTL			0x0C
14062306a36Sopenharmony_ci#define CS42L52_ADC_MISC_CTL_SOURCE_DSP		(1 << 6)
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_ci#define CS42L52_PB_CTL1				0x0D
14362306a36Sopenharmony_ci#define CS42L52_PB_CTL1_HP_GAIN_SHIFT		5
14462306a36Sopenharmony_ci#define CS42L52_PB_CTL1_HP_GAIN_03959		0x00
14562306a36Sopenharmony_ci#define CS42L52_PB_CTL1_HP_GAIN_04571		0x01
14662306a36Sopenharmony_ci#define CS42L52_PB_CTL1_HP_GAIN_05111		0x02
14762306a36Sopenharmony_ci#define CS42L52_PB_CTL1_HP_GAIN_06047		0x03
14862306a36Sopenharmony_ci#define CS42L52_PB_CTL1_HP_GAIN_07099		0x04
14962306a36Sopenharmony_ci#define CS42L52_PB_CTL1_HP_GAIN_08399		0x05
15062306a36Sopenharmony_ci#define CS42L52_PB_CTL1_HP_GAIN_10000		0x06
15162306a36Sopenharmony_ci#define CS42L52_PB_CTL1_HP_GAIN_11430		0x07
15262306a36Sopenharmony_ci#define CS42L52_PB_CTL1_INV_PCMB		(1 << 3)
15362306a36Sopenharmony_ci#define CS42L52_PB_CTL1_INV_PCMA		(1 << 2)
15462306a36Sopenharmony_ci#define CS42L52_PB_CTL1_MSTB_MUTE		(1 << 1)
15562306a36Sopenharmony_ci#define CS42L52_PB_CTL1_MSTA_MUTE		(1 << 0)
15662306a36Sopenharmony_ci#define CS42L52_PB_CTL1_MUTE_MASK		0x03
15762306a36Sopenharmony_ci#define CS42L52_PB_CTL1_MUTE			3
15862306a36Sopenharmony_ci#define CS42L52_PB_CTL1_UNMUTE			0
15962306a36Sopenharmony_ci
16062306a36Sopenharmony_ci#define CS42L52_MISC_CTL			0x0E
16162306a36Sopenharmony_ci#define CS42L52_MISC_CTL_DEEMPH			(1 << 2)
16262306a36Sopenharmony_ci#define CS42L52_MISC_CTL_DIGSFT			(1 << 1)
16362306a36Sopenharmony_ci#define CS42L52_MISC_CTL_DIGZC			(1 << 0)
16462306a36Sopenharmony_ci
16562306a36Sopenharmony_ci#define CS42L52_PB_CTL2				0x0F
16662306a36Sopenharmony_ci#define CS42L52_PB_CTL2_HPB_MUTE		(1 << 7)
16762306a36Sopenharmony_ci#define CS42L52_PB_CTL2_HPA_MUTE		(1 << 6)
16862306a36Sopenharmony_ci#define CS42L52_PB_CTL2_SPKB_MUTE		(1 << 5)
16962306a36Sopenharmony_ci#define CS42L52_PB_CTL2_SPKA_MUTE		(1 << 4)
17062306a36Sopenharmony_ci#define CS42L52_PB_CTL2_SPK_SWAP		(1 << 2)
17162306a36Sopenharmony_ci#define CS42L52_PB_CTL2_SPK_MONO		(1 << 1)
17262306a36Sopenharmony_ci#define CS42L52_PB_CTL2_SPK_MUTE50		(1 << 0)
17362306a36Sopenharmony_ci
17462306a36Sopenharmony_ci#define	CS42L52_MICA_CTL			0x10
17562306a36Sopenharmony_ci#define CS42L52_MICB_CTL			0x11
17662306a36Sopenharmony_ci#define	CS42L52_MIC_CTL_MIC_SEL_MASK		0xBF
17762306a36Sopenharmony_ci#define	CS42L52_MIC_CTL_MIC_SEL_SHIFT		6
17862306a36Sopenharmony_ci#define CS42L52_MIC_CTL_TYPE_MASK		0x20
17962306a36Sopenharmony_ci#define CS42L52_MIC_CTL_TYPE_SHIFT		5
18062306a36Sopenharmony_ci
18162306a36Sopenharmony_ci
18262306a36Sopenharmony_ci#define CS42L52_PGAA_CTL			0x12
18362306a36Sopenharmony_ci#define CS42L52_PGAB_CTL			0x13
18462306a36Sopenharmony_ci#define CS42L52_PGAX_CTL_VOL_12DB		24
18562306a36Sopenharmony_ci#define CS42L52_PGAX_CTL_VOL_6DB		12 /*step size 0.5db*/
18662306a36Sopenharmony_ci
18762306a36Sopenharmony_ci#define CS42L52_PASSTHRUA_VOL			0x14
18862306a36Sopenharmony_ci#define CS42L52_PASSTHRUB_VOL			0x15
18962306a36Sopenharmony_ci
19062306a36Sopenharmony_ci#define CS42L52_ADCA_VOL			0x16
19162306a36Sopenharmony_ci#define CS42L52_ADCB_VOL			0x17
19262306a36Sopenharmony_ci#define CS42L52_ADCX_VOL_24DB			24 /*step size 1db*/
19362306a36Sopenharmony_ci#define CS42L52_ADCX_VOL_12DB			12
19462306a36Sopenharmony_ci#define CS42L52_ADCX_VOL_6DB			6
19562306a36Sopenharmony_ci
19662306a36Sopenharmony_ci#define CS42L52_ADCA_MIXER_VOL			0x18
19762306a36Sopenharmony_ci#define CS42L52_ADCB_MIXER_VOL			0x19
19862306a36Sopenharmony_ci#define CS42L52_ADC_MIXER_VOL_12DB		0x18
19962306a36Sopenharmony_ci
20062306a36Sopenharmony_ci#define CS42L52_PCMA_MIXER_VOL			0x1A
20162306a36Sopenharmony_ci#define CS42L52_PCMB_MIXER_VOL			0x1B
20262306a36Sopenharmony_ci
20362306a36Sopenharmony_ci#define CS42L52_BEEP_FREQ			0x1C
20462306a36Sopenharmony_ci#define CS42L52_BEEP_VOL			0x1D
20562306a36Sopenharmony_ci#define CS42L52_BEEP_TONE_CTL			0x1E
20662306a36Sopenharmony_ci#define CS42L52_BEEP_RATE_SHIFT			4
20762306a36Sopenharmony_ci#define CS42L52_BEEP_RATE_MASK			0x0F
20862306a36Sopenharmony_ci
20962306a36Sopenharmony_ci#define CS42L52_TONE_CTL			0x1F
21062306a36Sopenharmony_ci#define CS42L52_BEEP_EN_MASK			0x3F
21162306a36Sopenharmony_ci
21262306a36Sopenharmony_ci#define CS42L52_MASTERA_VOL			0x20
21362306a36Sopenharmony_ci#define CS42L52_MASTERB_VOL			0x21
21462306a36Sopenharmony_ci
21562306a36Sopenharmony_ci#define CS42L52_HPA_VOL				0x22
21662306a36Sopenharmony_ci#define CS42L52_HPB_VOL				0x23
21762306a36Sopenharmony_ci#define CS42L52_DEFAULT_HP_VOL			0xF0
21862306a36Sopenharmony_ci
21962306a36Sopenharmony_ci#define CS42L52_SPKA_VOL			0x24
22062306a36Sopenharmony_ci#define CS42L52_SPKB_VOL			0x25
22162306a36Sopenharmony_ci#define CS42L52_DEFAULT_SPK_VOL			0xF0
22262306a36Sopenharmony_ci
22362306a36Sopenharmony_ci#define CS42L52_ADC_PCM_MIXER			0x26
22462306a36Sopenharmony_ci
22562306a36Sopenharmony_ci#define CS42L52_LIMITER_CTL1			0x27
22662306a36Sopenharmony_ci#define CS42L52_LIMITER_CTL2			0x28
22762306a36Sopenharmony_ci#define CS42L52_LIMITER_AT_RATE			0x29
22862306a36Sopenharmony_ci
22962306a36Sopenharmony_ci#define CS42L52_ALC_CTL				0x2A
23062306a36Sopenharmony_ci#define CS42L52_ALC_CTL_ALCB_ENABLE_SHIFT	7
23162306a36Sopenharmony_ci#define CS42L52_ALC_CTL_ALCA_ENABLE_SHIFT	6
23262306a36Sopenharmony_ci#define CS42L52_ALC_CTL_FASTEST_ATTACK		0
23362306a36Sopenharmony_ci
23462306a36Sopenharmony_ci#define CS42L52_ALC_RATE			0x2B
23562306a36Sopenharmony_ci#define CS42L52_ALC_SLOWEST_RELEASE		0x3F
23662306a36Sopenharmony_ci
23762306a36Sopenharmony_ci#define CS42L52_ALC_THRESHOLD			0x2C
23862306a36Sopenharmony_ci#define CS42L52_ALC_MAX_RATE_SHIFT		5
23962306a36Sopenharmony_ci#define CS42L52_ALC_MIN_RATE_SHIFT		2
24062306a36Sopenharmony_ci#define CS42L52_ALC_RATE_0DB			0
24162306a36Sopenharmony_ci#define CS42L52_ALC_RATE_3DB			1
24262306a36Sopenharmony_ci#define CS42L52_ALC_RATE_6DB			2
24362306a36Sopenharmony_ci
24462306a36Sopenharmony_ci#define CS42L52_NOISE_GATE_CTL			0x2D
24562306a36Sopenharmony_ci#define CS42L52_NG_ENABLE_SHIFT			6
24662306a36Sopenharmony_ci#define CS42L52_NG_THRESHOLD_SHIFT		2
24762306a36Sopenharmony_ci#define CS42L52_NG_MIN_70DB			2
24862306a36Sopenharmony_ci#define CS42L52_NG_DELAY_SHIFT			0
24962306a36Sopenharmony_ci#define CS42L52_NG_DELAY_100MS			1
25062306a36Sopenharmony_ci
25162306a36Sopenharmony_ci#define CS42L52_CLK_STATUS			0x2E
25262306a36Sopenharmony_ci#define CS42L52_BATT_COMPEN			0x2F
25362306a36Sopenharmony_ci
25462306a36Sopenharmony_ci#define CS42L52_BATT_LEVEL			0x30
25562306a36Sopenharmony_ci#define CS42L52_SPK_STATUS			0x31
25662306a36Sopenharmony_ci#define CS42L52_SPK_STATUS_PIN_SHIFT		3
25762306a36Sopenharmony_ci#define CS42L52_SPK_STATUS_PIN_HIGH		1
25862306a36Sopenharmony_ci
25962306a36Sopenharmony_ci#define CS42L52_TEM_CTL				0x32
26062306a36Sopenharmony_ci#define CS42L52_TEM_CTL_SET			0x80
26162306a36Sopenharmony_ci#define CS42L52_THE_FOLDBACK			0x33
26262306a36Sopenharmony_ci#define CS42L52_CHARGE_PUMP			0x34
26362306a36Sopenharmony_ci#define CS42L52_CHARGE_PUMP_MASK		0xF0
26462306a36Sopenharmony_ci#define CS42L52_CHARGE_PUMP_SHIFT		4
26562306a36Sopenharmony_ci#define CS42L52_FIX_BITS1			0x3E
26662306a36Sopenharmony_ci#define CS42L52_FIX_BITS2			0x47
26762306a36Sopenharmony_ci
26862306a36Sopenharmony_ci#define CS42L52_MAX_REGISTER			0x47
26962306a36Sopenharmony_ci
27062306a36Sopenharmony_ci#endif
271