18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * cs42l51.h
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * ASoC Driver for Cirrus Logic CS42L51 codecs
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Copyright (c) 2010 Arnaud Patard <apatard@mandriva.com>
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci#ifndef _CS42L51_H
108c2ecf20Sopenharmony_ci#define _CS42L51_H
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_cistruct device;
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ciextern const struct regmap_config cs42l51_regmap;
158c2ecf20Sopenharmony_ciint cs42l51_probe(struct device *dev, struct regmap *regmap);
168c2ecf20Sopenharmony_ciint cs42l51_remove(struct device *dev);
178c2ecf20Sopenharmony_ciint __maybe_unused cs42l51_suspend(struct device *dev);
188c2ecf20Sopenharmony_ciint __maybe_unused cs42l51_resume(struct device *dev);
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#define CS42L51_CHIP_ID			0x1B
218c2ecf20Sopenharmony_ci#define CS42L51_CHIP_REV_A		0x00
228c2ecf20Sopenharmony_ci#define CS42L51_CHIP_REV_B		0x01
238c2ecf20Sopenharmony_ci#define CS42L51_CHIP_REV_MASK		0x07
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#define CS42L51_CHIP_REV_ID		0x01
268c2ecf20Sopenharmony_ci#define CS42L51_MK_CHIP_REV(a, b)	((a)<<3|(b))
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#define CS42L51_POWER_CTL1		0x02
298c2ecf20Sopenharmony_ci#define CS42L51_POWER_CTL1_PDN_DACB	(1<<6)
308c2ecf20Sopenharmony_ci#define CS42L51_POWER_CTL1_PDN_DACA	(1<<5)
318c2ecf20Sopenharmony_ci#define CS42L51_POWER_CTL1_PDN_PGAB	(1<<4)
328c2ecf20Sopenharmony_ci#define CS42L51_POWER_CTL1_PDN_PGAA	(1<<3)
338c2ecf20Sopenharmony_ci#define CS42L51_POWER_CTL1_PDN_ADCB	(1<<2)
348c2ecf20Sopenharmony_ci#define CS42L51_POWER_CTL1_PDN_ADCA	(1<<1)
358c2ecf20Sopenharmony_ci#define CS42L51_POWER_CTL1_PDN		(1<<0)
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci#define CS42L51_MIC_POWER_CTL		0x03
388c2ecf20Sopenharmony_ci#define CS42L51_MIC_POWER_CTL_AUTO	(1<<7)
398c2ecf20Sopenharmony_ci#define CS42L51_MIC_POWER_CTL_SPEED(x)	(((x)&3)<<5)
408c2ecf20Sopenharmony_ci#define CS42L51_QSM_MODE		3
418c2ecf20Sopenharmony_ci#define CS42L51_HSM_MODE		2
428c2ecf20Sopenharmony_ci#define	CS42L51_SSM_MODE		1
438c2ecf20Sopenharmony_ci#define CS42L51_DSM_MODE		0
448c2ecf20Sopenharmony_ci#define CS42L51_MIC_POWER_CTL_3ST_SP	(1<<4)
458c2ecf20Sopenharmony_ci#define CS42L51_MIC_POWER_CTL_PDN_MICB	(1<<3)
468c2ecf20Sopenharmony_ci#define CS42L51_MIC_POWER_CTL_PDN_MICA	(1<<2)
478c2ecf20Sopenharmony_ci#define CS42L51_MIC_POWER_CTL_PDN_BIAS	(1<<1)
488c2ecf20Sopenharmony_ci#define CS42L51_MIC_POWER_CTL_MCLK_DIV2	(1<<0)
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci#define CS42L51_INTF_CTL		0x04
518c2ecf20Sopenharmony_ci#define CS42L51_INTF_CTL_LOOPBACK	(1<<7)
528c2ecf20Sopenharmony_ci#define CS42L51_INTF_CTL_MASTER		(1<<6)
538c2ecf20Sopenharmony_ci#define CS42L51_INTF_CTL_DAC_FORMAT(x)	(((x)&7)<<3)
548c2ecf20Sopenharmony_ci#define CS42L51_DAC_DIF_LJ24		0x00
558c2ecf20Sopenharmony_ci#define CS42L51_DAC_DIF_I2S		0x01
568c2ecf20Sopenharmony_ci#define CS42L51_DAC_DIF_RJ24		0x02
578c2ecf20Sopenharmony_ci#define CS42L51_DAC_DIF_RJ20		0x03
588c2ecf20Sopenharmony_ci#define CS42L51_DAC_DIF_RJ18		0x04
598c2ecf20Sopenharmony_ci#define CS42L51_DAC_DIF_RJ16		0x05
608c2ecf20Sopenharmony_ci#define CS42L51_INTF_CTL_ADC_I2S	(1<<2)
618c2ecf20Sopenharmony_ci#define CS42L51_INTF_CTL_DIGMIX		(1<<1)
628c2ecf20Sopenharmony_ci#define CS42L51_INTF_CTL_MICMIX		(1<<0)
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci#define CS42L51_MIC_CTL			0x05
658c2ecf20Sopenharmony_ci#define CS42L51_MIC_CTL_ADC_SNGVOL	(1<<7)
668c2ecf20Sopenharmony_ci#define CS42L51_MIC_CTL_ADCD_DBOOST	(1<<6)
678c2ecf20Sopenharmony_ci#define CS42L51_MIC_CTL_ADCA_DBOOST	(1<<5)
688c2ecf20Sopenharmony_ci#define CS42L51_MIC_CTL_MICBIAS_SEL	(1<<4)
698c2ecf20Sopenharmony_ci#define CS42L51_MIC_CTL_MICBIAS_LVL(x)	(((x)&3)<<2)
708c2ecf20Sopenharmony_ci#define CS42L51_MIC_CTL_MICB_BOOST	(1<<1)
718c2ecf20Sopenharmony_ci#define CS42L51_MIC_CTL_MICA_BOOST	(1<<0)
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci#define CS42L51_ADC_CTL			0x06
748c2ecf20Sopenharmony_ci#define CS42L51_ADC_CTL_ADCB_HPFEN	(1<<7)
758c2ecf20Sopenharmony_ci#define CS42L51_ADC_CTL_ADCB_HPFRZ	(1<<6)
768c2ecf20Sopenharmony_ci#define CS42L51_ADC_CTL_ADCA_HPFEN	(1<<5)
778c2ecf20Sopenharmony_ci#define CS42L51_ADC_CTL_ADCA_HPFRZ	(1<<4)
788c2ecf20Sopenharmony_ci#define CS42L51_ADC_CTL_SOFTB		(1<<3)
798c2ecf20Sopenharmony_ci#define CS42L51_ADC_CTL_ZCROSSB		(1<<2)
808c2ecf20Sopenharmony_ci#define CS42L51_ADC_CTL_SOFTA		(1<<1)
818c2ecf20Sopenharmony_ci#define CS42L51_ADC_CTL_ZCROSSA		(1<<0)
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci#define CS42L51_ADC_INPUT		0x07
848c2ecf20Sopenharmony_ci#define CS42L51_ADC_INPUT_AINB_MUX(x)	(((x)&3)<<6)
858c2ecf20Sopenharmony_ci#define CS42L51_ADC_INPUT_AINA_MUX(x)	(((x)&3)<<4)
868c2ecf20Sopenharmony_ci#define CS42L51_ADC_INPUT_INV_ADCB	(1<<3)
878c2ecf20Sopenharmony_ci#define CS42L51_ADC_INPUT_INV_ADCA	(1<<2)
888c2ecf20Sopenharmony_ci#define CS42L51_ADC_INPUT_ADCB_MUTE	(1<<1)
898c2ecf20Sopenharmony_ci#define CS42L51_ADC_INPUT_ADCA_MUTE	(1<<0)
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci#define CS42L51_DAC_OUT_CTL		0x08
928c2ecf20Sopenharmony_ci#define CS42L51_DAC_OUT_CTL_HP_GAIN(x)	(((x)&7)<<5)
938c2ecf20Sopenharmony_ci#define CS42L51_DAC_OUT_CTL_DAC_SNGVOL	(1<<4)
948c2ecf20Sopenharmony_ci#define CS42L51_DAC_OUT_CTL_INV_PCMB	(1<<3)
958c2ecf20Sopenharmony_ci#define CS42L51_DAC_OUT_CTL_INV_PCMA	(1<<2)
968c2ecf20Sopenharmony_ci#define CS42L51_DAC_OUT_CTL_DACB_MUTE	(1<<1)
978c2ecf20Sopenharmony_ci#define CS42L51_DAC_OUT_CTL_DACA_MUTE	(1<<0)
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci#define CS42L51_DAC_CTL			0x09
1008c2ecf20Sopenharmony_ci#define CS42L51_DAC_CTL_DATA_SEL(x)	(((x)&3)<<6)
1018c2ecf20Sopenharmony_ci#define CS42L51_DAC_CTL_FREEZE		(1<<5)
1028c2ecf20Sopenharmony_ci#define CS42L51_DAC_CTL_DEEMPH		(1<<3)
1038c2ecf20Sopenharmony_ci#define CS42L51_DAC_CTL_AMUTE		(1<<2)
1048c2ecf20Sopenharmony_ci#define CS42L51_DAC_CTL_DACSZ(x)	(((x)&3)<<0)
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci#define CS42L51_ALC_PGA_CTL		0x0A
1078c2ecf20Sopenharmony_ci#define CS42L51_ALC_PGB_CTL		0x0B
1088c2ecf20Sopenharmony_ci#define CS42L51_ALC_PGX_ALCX_SRDIS	(1<<7)
1098c2ecf20Sopenharmony_ci#define CS42L51_ALC_PGX_ALCX_ZCDIS	(1<<6)
1108c2ecf20Sopenharmony_ci#define CS42L51_ALC_PGX_PGX_VOL(x)	(((x)&0x1f)<<0)
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci#define CS42L51_ADCA_ATT		0x0C
1138c2ecf20Sopenharmony_ci#define CS42L51_ADCB_ATT		0x0D
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci#define CS42L51_ADCA_VOL		0x0E
1168c2ecf20Sopenharmony_ci#define CS42L51_ADCB_VOL		0x0F
1178c2ecf20Sopenharmony_ci#define CS42L51_PCMA_VOL		0x10
1188c2ecf20Sopenharmony_ci#define CS42L51_PCMB_VOL		0x11
1198c2ecf20Sopenharmony_ci#define CS42L51_MIX_MUTE_ADCMIX		(1<<7)
1208c2ecf20Sopenharmony_ci#define CS42L51_MIX_VOLUME(x)		(((x)&0x7f)<<0)
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci#define CS42L51_BEEP_FREQ		0x12
1238c2ecf20Sopenharmony_ci#define CS42L51_BEEP_VOL		0x13
1248c2ecf20Sopenharmony_ci#define CS42L51_BEEP_CONF		0x14
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci#define CS42L51_TONE_CTL		0x15
1278c2ecf20Sopenharmony_ci#define CS42L51_TONE_CTL_TREB(x)	(((x)&0xf)<<4)
1288c2ecf20Sopenharmony_ci#define CS42L51_TONE_CTL_BASS(x)	(((x)&0xf)<<0)
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci#define CS42L51_AOUTA_VOL		0x16
1318c2ecf20Sopenharmony_ci#define CS42L51_AOUTB_VOL		0x17
1328c2ecf20Sopenharmony_ci#define CS42L51_PCM_MIXER		0x18
1338c2ecf20Sopenharmony_ci#define CS42L51_LIMIT_THRES_DIS		0x19
1348c2ecf20Sopenharmony_ci#define CS42L51_LIMIT_REL		0x1A
1358c2ecf20Sopenharmony_ci#define CS42L51_LIMIT_ATT		0x1B
1368c2ecf20Sopenharmony_ci#define CS42L51_ALC_EN			0x1C
1378c2ecf20Sopenharmony_ci#define CS42L51_ALC_REL			0x1D
1388c2ecf20Sopenharmony_ci#define CS42L51_ALC_THRES		0x1E
1398c2ecf20Sopenharmony_ci#define CS42L51_NOISE_CONF		0x1F
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci#define CS42L51_STATUS			0x20
1428c2ecf20Sopenharmony_ci#define CS42L51_STATUS_SP_CLKERR	(1<<6)
1438c2ecf20Sopenharmony_ci#define CS42L51_STATUS_SPEA_OVFL	(1<<5)
1448c2ecf20Sopenharmony_ci#define CS42L51_STATUS_SPEB_OVFL	(1<<4)
1458c2ecf20Sopenharmony_ci#define CS42L51_STATUS_PCMA_OVFL	(1<<3)
1468c2ecf20Sopenharmony_ci#define CS42L51_STATUS_PCMB_OVFL	(1<<2)
1478c2ecf20Sopenharmony_ci#define CS42L51_STATUS_ADCA_OVFL	(1<<1)
1488c2ecf20Sopenharmony_ci#define CS42L51_STATUS_ADCB_OVFL	(1<<0)
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci#define CS42L51_CHARGE_FREQ		0x21
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci#define CS42L51_FIRSTREG	0x01
1538c2ecf20Sopenharmony_ci/*
1548c2ecf20Sopenharmony_ci * Hack: with register 0x21, it makes 33 registers. Looks like someone in the
1558c2ecf20Sopenharmony_ci * i2c layer doesn't like i2c smbus block read of 33 regs. Workaround by using
1568c2ecf20Sopenharmony_ci * 32 regs
1578c2ecf20Sopenharmony_ci */
1588c2ecf20Sopenharmony_ci#define CS42L51_LASTREG		0x20
1598c2ecf20Sopenharmony_ci#define CS42L51_NUMREGS		(CS42L51_LASTREG - CS42L51_FIRSTREG + 1)
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci#endif
162