162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * ALSA SoC CS42L73 codec driver
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright 2011 Cirrus Logic, Inc.
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Author: Georgi Vlaev <joe@nucleusys.com>
862306a36Sopenharmony_ci *	   Brian Austin <brian.austin@cirrus.com>
962306a36Sopenharmony_ci */
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#ifndef __CS42L73_H__
1262306a36Sopenharmony_ci#define __CS42L73_H__
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci/* I2C Registers */
1562306a36Sopenharmony_ci/* I2C Address: 1001010[R/W] - 10010100 = 0x94(Write); 10010101 = 0x95(Read) */
1662306a36Sopenharmony_ci#define CS42L73_CHIP_ID		0x4a
1762306a36Sopenharmony_ci#define CS42L73_DEVID_AB	0x01	/* Device ID A & B [RO]. */
1862306a36Sopenharmony_ci#define CS42L73_DEVID_CD	0x02    /* Device ID C & D [RO]. */
1962306a36Sopenharmony_ci#define CS42L73_DEVID_E		0x03    /* Device ID E [RO]. */
2062306a36Sopenharmony_ci#define CS42L73_REVID		0x05    /* Revision ID [RO]. */
2162306a36Sopenharmony_ci#define CS42L73_PWRCTL1		0x06    /* Power Control 1. */
2262306a36Sopenharmony_ci#define CS42L73_PWRCTL2		0x07    /* Power Control 2. */
2362306a36Sopenharmony_ci#define CS42L73_PWRCTL3		0x08    /* Power Control 3. */
2462306a36Sopenharmony_ci#define CS42L73_CPFCHC		0x09    /* Charge Pump Freq. Class H Ctl. */
2562306a36Sopenharmony_ci#define CS42L73_OLMBMSDC	0x0A    /* Output Load, MIC Bias, MIC2 SDT */
2662306a36Sopenharmony_ci#define CS42L73_DMMCC		0x0B    /* Digital MIC & Master Clock Ctl. */
2762306a36Sopenharmony_ci#define CS42L73_XSPC		0x0C    /* Auxiliary Serial Port (XSP) Ctl. */
2862306a36Sopenharmony_ci#define CS42L73_XSPMMCC		0x0D    /* XSP Master Mode Clocking Control. */
2962306a36Sopenharmony_ci#define CS42L73_ASPC		0x0E    /* Audio Serial Port (ASP) Control. */
3062306a36Sopenharmony_ci#define CS42L73_ASPMMCC		0x0F    /* ASP Master Mode Clocking Control. */
3162306a36Sopenharmony_ci#define CS42L73_VSPC		0x10    /* Voice Serial Port (VSP) Control. */
3262306a36Sopenharmony_ci#define CS42L73_VSPMMCC		0x11    /* VSP Master Mode Clocking Control. */
3362306a36Sopenharmony_ci#define CS42L73_VXSPFS		0x12    /* VSP & XSP Sample Rate. */
3462306a36Sopenharmony_ci#define CS42L73_MIOPC		0x13    /* Misc. Input & Output Path Control. */
3562306a36Sopenharmony_ci#define CS42L73_ADCIPC		0x14	/* ADC/IP Control. */
3662306a36Sopenharmony_ci#define CS42L73_MICAPREPGAAVOL	0x15	/* MIC 1 [A] PreAmp, PGAA Vol. */
3762306a36Sopenharmony_ci#define CS42L73_MICBPREPGABVOL	0x16	/* MIC 2 [B] PreAmp, PGAB Vol. */
3862306a36Sopenharmony_ci#define CS42L73_IPADVOL		0x17	/* Input Pat7h A Digital Volume. */
3962306a36Sopenharmony_ci#define CS42L73_IPBDVOL		0x18	/* Input Path B Digital Volume. */
4062306a36Sopenharmony_ci#define CS42L73_PBDC		0x19	/* Playback Digital Control. */
4162306a36Sopenharmony_ci#define CS42L73_HLADVOL		0x1A	/* HP/Line A Out Digital Vol. */
4262306a36Sopenharmony_ci#define CS42L73_HLBDVOL		0x1B	/* HP/Line B Out Digital Vol. */
4362306a36Sopenharmony_ci#define CS42L73_SPKDVOL		0x1C	/* Spkphone Out [A] Digital Vol. */
4462306a36Sopenharmony_ci#define CS42L73_ESLDVOL		0x1D	/* Ear/Spkphone LO [B] Digital */
4562306a36Sopenharmony_ci#define CS42L73_HPAAVOL		0x1E	/* HP A Analog Volume. */
4662306a36Sopenharmony_ci#define CS42L73_HPBAVOL		0x1F	/* HP B Analog Volume. */
4762306a36Sopenharmony_ci#define CS42L73_LOAAVOL		0x20	/* Line Out A Analog Volume. */
4862306a36Sopenharmony_ci#define CS42L73_LOBAVOL		0x21	/* Line Out B Analog Volume. */
4962306a36Sopenharmony_ci#define CS42L73_STRINV		0x22	/* Stereo Input Path Adv. Vol. */
5062306a36Sopenharmony_ci#define CS42L73_XSPINV		0x23	/* Auxiliary Port Input Advisory Vol. */
5162306a36Sopenharmony_ci#define CS42L73_ASPINV		0x24	/* Audio Port Input Advisory Vol. */
5262306a36Sopenharmony_ci#define CS42L73_VSPINV		0x25	/* Voice Port Input Advisory Vol. */
5362306a36Sopenharmony_ci#define CS42L73_LIMARATEHL	0x26	/* Lmtr Attack Rate HP/Line. */
5462306a36Sopenharmony_ci#define CS42L73_LIMRRATEHL	0x27	/* Lmtr Ctl, Rel.Rate HP/Line. */
5562306a36Sopenharmony_ci#define CS42L73_LMAXHL		0x28	/* Lmtr Thresholds HP/Line. */
5662306a36Sopenharmony_ci#define CS42L73_LIMARATESPK	0x29	/* Lmtr Attack Rate Spkphone [A]. */
5762306a36Sopenharmony_ci#define CS42L73_LIMRRATESPK	0x2A	/* Lmtr Ctl,Release Rate Spk. [A]. */
5862306a36Sopenharmony_ci#define CS42L73_LMAXSPK		0x2B	/* Lmtr Thresholds Spkphone [A]. */
5962306a36Sopenharmony_ci#define CS42L73_LIMARATEESL	0x2C	/* Lmtr Attack Rate  */
6062306a36Sopenharmony_ci#define CS42L73_LIMRRATEESL	0x2D	/* Lmtr Ctl,Release Rate */
6162306a36Sopenharmony_ci#define CS42L73_LMAXESL		0x2E	/* Lmtr Thresholds */
6262306a36Sopenharmony_ci#define CS42L73_ALCARATE	0x2F	/* ALC Enable, Attack Rate AB. */
6362306a36Sopenharmony_ci#define CS42L73_ALCRRATE	0x30	/* ALC Release Rate AB.  */
6462306a36Sopenharmony_ci#define CS42L73_ALCMINMAX	0x31	/* ALC Thresholds AB. */
6562306a36Sopenharmony_ci#define CS42L73_NGCAB		0x32	/* Noise Gate Ctl AB. */
6662306a36Sopenharmony_ci#define CS42L73_ALCNGMC		0x33	/* ALC & Noise Gate Misc Ctl. */
6762306a36Sopenharmony_ci#define CS42L73_MIXERCTL	0x34	/* Mixer Control. */
6862306a36Sopenharmony_ci#define CS42L73_HLAIPAA		0x35	/* HP/LO Left Mixer: L. */
6962306a36Sopenharmony_ci#define CS42L73_HLBIPBA		0x36	/* HP/LO Right Mixer: R.  */
7062306a36Sopenharmony_ci#define CS42L73_HLAXSPAA	0x37	/* HP/LO Left Mixer: XSP L */
7162306a36Sopenharmony_ci#define CS42L73_HLBXSPBA	0x38	/* HP/LO Right Mixer: XSP R */
7262306a36Sopenharmony_ci#define CS42L73_HLAASPAA	0x39	/* HP/LO Left Mixer: ASP L */
7362306a36Sopenharmony_ci#define CS42L73_HLBASPBA	0x3A	/* HP/LO Right Mixer: ASP R */
7462306a36Sopenharmony_ci#define CS42L73_HLAVSPMA	0x3B	/* HP/LO Left Mixer: VSP. */
7562306a36Sopenharmony_ci#define CS42L73_HLBVSPMA	0x3C	/* HP/LO Right Mixer: VSP */
7662306a36Sopenharmony_ci#define CS42L73_XSPAIPAA	0x3D	/* XSP Left Mixer: Left */
7762306a36Sopenharmony_ci#define CS42L73_XSPBIPBA	0x3E	/* XSP Rt. Mixer: Right */
7862306a36Sopenharmony_ci#define CS42L73_XSPAXSPAA	0x3F	/* XSP Left Mixer: XSP L */
7962306a36Sopenharmony_ci#define CS42L73_XSPBXSPBA	0x40	/* XSP Rt. Mixer: XSP R */
8062306a36Sopenharmony_ci#define CS42L73_XSPAASPAA	0x41	/* XSP Left Mixer: ASP L */
8162306a36Sopenharmony_ci#define CS42L73_XSPAASPBA	0x42	/* XSP Rt. Mixer: ASP R */
8262306a36Sopenharmony_ci#define CS42L73_XSPAVSPMA	0x43	/* XSP Left Mixer: VSP */
8362306a36Sopenharmony_ci#define CS42L73_XSPBVSPMA	0x44	/* XSP Rt. Mixer: VSP */
8462306a36Sopenharmony_ci#define CS42L73_ASPAIPAA	0x45	/* ASP Left Mixer: Left */
8562306a36Sopenharmony_ci#define CS42L73_ASPBIPBA	0x46	/* ASP Rt. Mixer: Right */
8662306a36Sopenharmony_ci#define CS42L73_ASPAXSPAA	0x47	/* ASP Left Mixer: XSP L */
8762306a36Sopenharmony_ci#define CS42L73_ASPBXSPBA	0x48	/* ASP Rt. Mixer: XSP R */
8862306a36Sopenharmony_ci#define CS42L73_ASPAASPAA	0x49	/* ASP Left Mixer: ASP L */
8962306a36Sopenharmony_ci#define CS42L73_ASPBASPBA	0x4A	/* ASP Rt. Mixer: ASP R */
9062306a36Sopenharmony_ci#define CS42L73_ASPAVSPMA	0x4B	/* ASP Left Mixer: VSP */
9162306a36Sopenharmony_ci#define CS42L73_ASPBVSPMA	0x4C	/* ASP Rt. Mixer: VSP */
9262306a36Sopenharmony_ci#define CS42L73_VSPAIPAA	0x4D	/* VSP Left Mixer: Left */
9362306a36Sopenharmony_ci#define CS42L73_VSPBIPBA	0x4E	/* VSP Rt. Mixer: Right */
9462306a36Sopenharmony_ci#define CS42L73_VSPAXSPAA	0x4F	/* VSP Left Mixer: XSP L */
9562306a36Sopenharmony_ci#define CS42L73_VSPBXSPBA	0x50	/* VSP Rt. Mixer: XSP R */
9662306a36Sopenharmony_ci#define CS42L73_VSPAASPAA	0x51	/* VSP Left Mixer: ASP Left */
9762306a36Sopenharmony_ci#define CS42L73_VSPBASPBA	0x52	/* VSP Rt. Mixer: ASP Right */
9862306a36Sopenharmony_ci#define CS42L73_VSPAVSPMA	0x53	/* VSP Left Mixer: VSP */
9962306a36Sopenharmony_ci#define CS42L73_VSPBVSPMA	0x54	/* VSP Rt. Mixer: VSP */
10062306a36Sopenharmony_ci#define CS42L73_MMIXCTL		0x55	/* Mono Mixer Controls. */
10162306a36Sopenharmony_ci#define CS42L73_SPKMIPMA	0x56	/* SPK Mono Mixer: In. Path */
10262306a36Sopenharmony_ci#define CS42L73_SPKMXSPA	0x57	/* SPK Mono Mixer: XSP Mono/L/R Att. */
10362306a36Sopenharmony_ci#define CS42L73_SPKMASPA	0x58	/* SPK Mono Mixer: ASP Mono/L/R Att. */
10462306a36Sopenharmony_ci#define CS42L73_SPKMVSPMA	0x59	/* SPK Mono Mixer: VSP Mono Atten. */
10562306a36Sopenharmony_ci#define CS42L73_ESLMIPMA	0x5A	/* Ear/SpLO Mono Mixer: */
10662306a36Sopenharmony_ci#define CS42L73_ESLMXSPA	0x5B	/* Ear/SpLO Mono Mixer: XSP */
10762306a36Sopenharmony_ci#define CS42L73_ESLMASPA	0x5C	/* Ear/SpLO Mono Mixer: ASP */
10862306a36Sopenharmony_ci#define CS42L73_ESLMVSPMA	0x5D	/* Ear/SpLO Mono Mixer: VSP */
10962306a36Sopenharmony_ci#define CS42L73_IM1		0x5E	/* Interrupt Mask 1.  */
11062306a36Sopenharmony_ci#define CS42L73_IM2		0x5F	/* Interrupt Mask 2. */
11162306a36Sopenharmony_ci#define CS42L73_IS1		0x60	/* Interrupt Status 1 [RO]. */
11262306a36Sopenharmony_ci#define CS42L73_IS2		0x61	/* Interrupt Status 2 [RO]. */
11362306a36Sopenharmony_ci#define CS42L73_MAX_REGISTER	0x61	/* Total Registers */
11462306a36Sopenharmony_ci/* Bitfield Definitions */
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_ci/* CS42L73_PWRCTL1 */
11762306a36Sopenharmony_ci#define CS42L73_PDN_ADCB		(1 << 7)
11862306a36Sopenharmony_ci#define CS42L73_PDN_DMICB		(1 << 6)
11962306a36Sopenharmony_ci#define CS42L73_PDN_ADCA		(1 << 5)
12062306a36Sopenharmony_ci#define CS42L73_PDN_DMICA		(1 << 4)
12162306a36Sopenharmony_ci#define CS42L73_PDN_LDO			(1 << 2)
12262306a36Sopenharmony_ci#define CS42L73_DISCHG_FILT		(1 << 1)
12362306a36Sopenharmony_ci#define CS42L73_PDN			(1 << 0)
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_ci/* CS42L73_PWRCTL2 */
12662306a36Sopenharmony_ci#define CS42L73_PDN_MIC2_BIAS		(1 << 7)
12762306a36Sopenharmony_ci#define CS42L73_PDN_MIC1_BIAS		(1 << 6)
12862306a36Sopenharmony_ci#define CS42L73_PDN_VSP			(1 << 4)
12962306a36Sopenharmony_ci#define CS42L73_PDN_ASP_SDOUT		(1 << 3)
13062306a36Sopenharmony_ci#define CS42L73_PDN_ASP_SDIN		(1 << 2)
13162306a36Sopenharmony_ci#define CS42L73_PDN_XSP_SDOUT		(1 << 1)
13262306a36Sopenharmony_ci#define CS42L73_PDN_XSP_SDIN		(1 << 0)
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ci/* CS42L73_PWRCTL3 */
13562306a36Sopenharmony_ci#define CS42L73_PDN_THMS		(1 << 5)
13662306a36Sopenharmony_ci#define CS42L73_PDN_SPKLO		(1 << 4)
13762306a36Sopenharmony_ci#define CS42L73_PDN_EAR			(1 << 3)
13862306a36Sopenharmony_ci#define CS42L73_PDN_SPK			(1 << 2)
13962306a36Sopenharmony_ci#define CS42L73_PDN_LO			(1 << 1)
14062306a36Sopenharmony_ci#define CS42L73_PDN_HP			(1 << 0)
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_ci/* Thermal Overload Detect. Requires interrupt ... */
14362306a36Sopenharmony_ci#define CS42L73_THMOVLD_150C		0
14462306a36Sopenharmony_ci#define CS42L73_THMOVLD_132C		1
14562306a36Sopenharmony_ci#define CS42L73_THMOVLD_115C		2
14662306a36Sopenharmony_ci#define CS42L73_THMOVLD_098C		3
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci#define CS42L73_CHARGEPUMP_MASK	(0xF0)
14962306a36Sopenharmony_ci
15062306a36Sopenharmony_ci/* CS42L73_ASPC, CS42L73_XSPC, CS42L73_VSPC */
15162306a36Sopenharmony_ci#define	CS42L73_SP_3ST			(1 << 7)
15262306a36Sopenharmony_ci#define CS42L73_SPDIF_I2S		(0 << 6)
15362306a36Sopenharmony_ci#define CS42L73_SPDIF_PCM		(1 << 6)
15462306a36Sopenharmony_ci#define CS42L73_PCM_MODE0		(0 << 4)
15562306a36Sopenharmony_ci#define CS42L73_PCM_MODE1		(1 << 4)
15662306a36Sopenharmony_ci#define CS42L73_PCM_MODE2		(2 << 4)
15762306a36Sopenharmony_ci#define CS42L73_PCM_MODE_MASK		(3 << 4)
15862306a36Sopenharmony_ci#define CS42L73_PCM_BIT_ORDER		(1 << 3)
15962306a36Sopenharmony_ci#define CS42L73_MCK_SCLK_64FS		(0 << 0)
16062306a36Sopenharmony_ci#define CS42L73_MCK_SCLK_MCLK		(2 << 0)
16162306a36Sopenharmony_ci#define CS42L73_MCK_SCLK_PREMCLK	(3 << 0)
16262306a36Sopenharmony_ci
16362306a36Sopenharmony_ci/* CS42L73_xSPMMCC */
16462306a36Sopenharmony_ci#define CS42L73_MS_MASTER		(1 << 7)
16562306a36Sopenharmony_ci
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_ci/* CS42L73_DMMCC */
16862306a36Sopenharmony_ci#define CS42L73_MCLKDIS			(1 << 0)
16962306a36Sopenharmony_ci#define CS42L73_MCLKSEL_MCLK2		(1 << 4)
17062306a36Sopenharmony_ci#define CS42L73_MCLKSEL_MCLK1		(0 << 4)
17162306a36Sopenharmony_ci
17262306a36Sopenharmony_ci/* CS42L73 MCLK derived from MCLK1 or MCLK2 */
17362306a36Sopenharmony_ci#define CS42L73_CLKID_MCLK1     0
17462306a36Sopenharmony_ci#define CS42L73_CLKID_MCLK2     1
17562306a36Sopenharmony_ci
17662306a36Sopenharmony_ci#define CS42L73_MCLKXDIV	0
17762306a36Sopenharmony_ci#define CS42L73_MMCCDIV         1
17862306a36Sopenharmony_ci
17962306a36Sopenharmony_ci#define CS42L73_XSP		0
18062306a36Sopenharmony_ci#define CS42L73_ASP		1
18162306a36Sopenharmony_ci#define CS42L73_VSP		2
18262306a36Sopenharmony_ci
18362306a36Sopenharmony_ci/* IS1, IM1 */
18462306a36Sopenharmony_ci#define CS42L73_MIC2_SDET		(1 << 6)
18562306a36Sopenharmony_ci#define CS42L73_THMOVLD			(1 << 4)
18662306a36Sopenharmony_ci#define CS42L73_DIGMIXOVFL		(1 << 3)
18762306a36Sopenharmony_ci#define CS42L73_IPBOVFL			(1 << 1)
18862306a36Sopenharmony_ci#define CS42L73_IPAOVFL			(1 << 0)
18962306a36Sopenharmony_ci
19062306a36Sopenharmony_ci/* Analog Softramp */
19162306a36Sopenharmony_ci#define CS42L73_ANLGOSFT		(1 << 0)
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_ci/* HP A/B Analog Mute */
19462306a36Sopenharmony_ci#define CS42L73_HPA_MUTE		(1 << 7)
19562306a36Sopenharmony_ci/* LO A/B Analog Mute	*/
19662306a36Sopenharmony_ci#define CS42L73_LOA_MUTE		(1 << 7)
19762306a36Sopenharmony_ci/* Digital Mute */
19862306a36Sopenharmony_ci#define CS42L73_HLAD_MUTE		(1 << 0)
19962306a36Sopenharmony_ci#define CS42L73_HLBD_MUTE		(1 << 1)
20062306a36Sopenharmony_ci#define CS42L73_SPKD_MUTE		(1 << 2)
20162306a36Sopenharmony_ci#define CS42L73_ESLD_MUTE		(1 << 3)
20262306a36Sopenharmony_ci
20362306a36Sopenharmony_ci/* Misc defines for codec */
20462306a36Sopenharmony_ci#define CS42L73_DEVID		0x00042A73
20562306a36Sopenharmony_ci#define CS42L73_MCLKX_MIN	5644800
20662306a36Sopenharmony_ci#define CS42L73_MCLKX_MAX	38400000
20762306a36Sopenharmony_ci
20862306a36Sopenharmony_ci#define CS42L73_SPC(id)		(CS42L73_XSPC + (id << 1))
20962306a36Sopenharmony_ci#define CS42L73_MMCC(id)	(CS42L73_XSPMMCC + (id << 1))
21062306a36Sopenharmony_ci#define CS42L73_SPFS(id)	((id == CS42L73_ASP) ? CS42L73_ASPC : CS42L73_VXSPFS)
21162306a36Sopenharmony_ci
21262306a36Sopenharmony_ci#endif	/* __CS42L73_H__ */
213