18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci#ifndef __SOUND_WM8776_H
38c2ecf20Sopenharmony_ci#define __SOUND_WM8776_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci/*
68c2ecf20Sopenharmony_ci *   ALSA driver for ICEnsemble VT17xx
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci *   Lowlevel functions for WM8776 codec
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci *	Copyright (c) 2012 Ondrej Zary <linux@rainbow-software.org>
118c2ecf20Sopenharmony_ci */
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#define WM8776_REG_HPLVOL	0x00
148c2ecf20Sopenharmony_ci#define WM8776_REG_HPRVOL	0x01
158c2ecf20Sopenharmony_ci#define WM8776_REG_HPMASTER	0x02
168c2ecf20Sopenharmony_ci#define WM8776_HPVOL_MASK		0x17f		/* incl. update bit */
178c2ecf20Sopenharmony_ci#define WM8776_VOL_HPZCEN		(1 << 7)	/* zero cross detect */
188c2ecf20Sopenharmony_ci#define WM8776_VOL_UPDATE		(1 << 8)	/* update volume */
198c2ecf20Sopenharmony_ci#define WM8776_REG_DACLVOL	0x03
208c2ecf20Sopenharmony_ci#define WM8776_REG_DACRVOL	0x04
218c2ecf20Sopenharmony_ci#define WM8776_REG_DACMASTER	0x05
228c2ecf20Sopenharmony_ci#define WM8776_DACVOL_MASK		0x1ff		/* incl. update bit */
238c2ecf20Sopenharmony_ci#define WM8776_REG_PHASESWAP	0x06
248c2ecf20Sopenharmony_ci#define WM8776_PHASE_INVERTL		(1 << 0)
258c2ecf20Sopenharmony_ci#define WM8776_PHASE_INVERTR		(1 << 1)
268c2ecf20Sopenharmony_ci#define WM8776_REG_DACCTRL1	0x07
278c2ecf20Sopenharmony_ci#define WM8776_DAC_DZCEN		(1 << 0)
288c2ecf20Sopenharmony_ci#define WM8776_DAC_ATC			(1 << 1)
298c2ecf20Sopenharmony_ci#define WM8776_DAC_IZD			(1 << 2)
308c2ecf20Sopenharmony_ci#define WM8776_DAC_TOD			(1 << 3)
318c2ecf20Sopenharmony_ci#define WM8776_DAC_PL_MASK		0xf0
328c2ecf20Sopenharmony_ci#define WM8776_DAC_PL_LL		(1 << 4)	/* L chan: L signal */
338c2ecf20Sopenharmony_ci#define WM8776_DAC_PL_LR		(2 << 4)	/* L chan: R signal */
348c2ecf20Sopenharmony_ci#define WM8776_DAC_PL_LB		(3 << 4)	/* L chan: both */
358c2ecf20Sopenharmony_ci#define WM8776_DAC_PL_RL		(1 << 6)	/* R chan: L signal */
368c2ecf20Sopenharmony_ci#define WM8776_DAC_PL_RR		(2 << 6)	/* R chan: R signal */
378c2ecf20Sopenharmony_ci#define WM8776_DAC_PL_RB		(3 << 6)	/* R chan: both */
388c2ecf20Sopenharmony_ci#define WM8776_REG_DACMUTE	0x08
398c2ecf20Sopenharmony_ci#define WM8776_DACMUTE			(1 << 0)
408c2ecf20Sopenharmony_ci#define WM8776_REG_DACCTRL2	0x09
418c2ecf20Sopenharmony_ci#define WM8776_DAC2_DEEMPH		(1 << 0)
428c2ecf20Sopenharmony_ci#define WM8776_DAC2_ZFLAG_DISABLE	(0 << 1)
438c2ecf20Sopenharmony_ci#define WM8776_DAC2_ZFLAG_OWN		(1 << 1)
448c2ecf20Sopenharmony_ci#define WM8776_DAC2_ZFLAG_BOTH		(2 << 1)
458c2ecf20Sopenharmony_ci#define WM8776_DAC2_ZFLAG_EITHER	(3 << 1)
468c2ecf20Sopenharmony_ci#define WM8776_REG_DACIFCTRL	0x0a
478c2ecf20Sopenharmony_ci#define WM8776_FMT_RIGHTJ		(0 << 0)
488c2ecf20Sopenharmony_ci#define WM8776_FMT_LEFTJ		(1 << 0)
498c2ecf20Sopenharmony_ci#define WM8776_FMT_I2S			(2 << 0)
508c2ecf20Sopenharmony_ci#define WM8776_FMT_DSP			(3 << 0)
518c2ecf20Sopenharmony_ci#define WM8776_FMT_DSP_LATE		(1 << 2)	/* in DSP mode */
528c2ecf20Sopenharmony_ci#define WM8776_FMT_LRC_INVERTED		(1 << 2)	/* in other modes */
538c2ecf20Sopenharmony_ci#define WM8776_FMT_BCLK_INVERTED	(1 << 3)
548c2ecf20Sopenharmony_ci#define WM8776_FMT_16BIT		(0 << 4)
558c2ecf20Sopenharmony_ci#define WM8776_FMT_20BIT		(1 << 4)
568c2ecf20Sopenharmony_ci#define WM8776_FMT_24BIT		(2 << 4)
578c2ecf20Sopenharmony_ci#define WM8776_FMT_32BIT		(3 << 4)
588c2ecf20Sopenharmony_ci#define WM8776_REG_ADCIFCTRL	0x0b
598c2ecf20Sopenharmony_ci#define WM8776_FMT_ADCMCLK_INVERTED	(1 << 6)
608c2ecf20Sopenharmony_ci#define WM8776_FMT_ADCHPD		(1 << 8)
618c2ecf20Sopenharmony_ci#define WM8776_REG_MSTRCTRL	0x0c
628c2ecf20Sopenharmony_ci#define WM8776_IF_ADC256FS		(2 << 0)
638c2ecf20Sopenharmony_ci#define WM8776_IF_ADC384FS		(3 << 0)
648c2ecf20Sopenharmony_ci#define WM8776_IF_ADC512FS		(4 << 0)
658c2ecf20Sopenharmony_ci#define WM8776_IF_ADC768FS		(5 << 0)
668c2ecf20Sopenharmony_ci#define WM8776_IF_OVERSAMP64		(1 << 3)
678c2ecf20Sopenharmony_ci#define WM8776_IF_DAC128FS		(0 << 4)
688c2ecf20Sopenharmony_ci#define WM8776_IF_DAC192FS		(1 << 4)
698c2ecf20Sopenharmony_ci#define WM8776_IF_DAC256FS		(2 << 4)
708c2ecf20Sopenharmony_ci#define WM8776_IF_DAC384FS		(3 << 4)
718c2ecf20Sopenharmony_ci#define WM8776_IF_DAC512FS		(4 << 4)
728c2ecf20Sopenharmony_ci#define WM8776_IF_DAC768FS		(5 << 4)
738c2ecf20Sopenharmony_ci#define WM8776_IF_DAC_MASTER		(1 << 7)
748c2ecf20Sopenharmony_ci#define WM8776_IF_ADC_MASTER		(1 << 8)
758c2ecf20Sopenharmony_ci#define WM8776_REG_PWRDOWN	0x0d
768c2ecf20Sopenharmony_ci#define WM8776_PWR_PDWN			(1 << 0)
778c2ecf20Sopenharmony_ci#define WM8776_PWR_ADCPD		(1 << 1)
788c2ecf20Sopenharmony_ci#define WM8776_PWR_DACPD		(1 << 2)
798c2ecf20Sopenharmony_ci#define WM8776_PWR_HPPD			(1 << 3)
808c2ecf20Sopenharmony_ci#define WM8776_PWR_AINPD		(1 << 6)
818c2ecf20Sopenharmony_ci#define WM8776_REG_ADCLVOL	0x0e
828c2ecf20Sopenharmony_ci#define WM8776_REG_ADCRVOL	0x0f
838c2ecf20Sopenharmony_ci#define WM8776_ADC_GAIN_MASK		0xff
848c2ecf20Sopenharmony_ci#define WM8776_ADC_ZCEN			(1 << 8)
858c2ecf20Sopenharmony_ci#define WM8776_REG_ALCCTRL1	0x10
868c2ecf20Sopenharmony_ci#define WM8776_ALC1_LCT_MASK		0x0f	/* 0=-16dB, 1=-15dB..15=-1dB */
878c2ecf20Sopenharmony_ci#define WM8776_ALC1_MAXGAIN_MASK	0x70	/* 0,1=0dB, 2=+4dB...7=+24dB */
888c2ecf20Sopenharmony_ci#define WM8776_ALC1_LCSEL_MASK		0x180
898c2ecf20Sopenharmony_ci#define WM8776_ALC1_LCSEL_LIMITER	(0 << 7)
908c2ecf20Sopenharmony_ci#define WM8776_ALC1_LCSEL_ALCR		(1 << 7)
918c2ecf20Sopenharmony_ci#define WM8776_ALC1_LCSEL_ALCL		(2 << 7)
928c2ecf20Sopenharmony_ci#define WM8776_ALC1_LCSEL_ALCSTEREO	(3 << 7)
938c2ecf20Sopenharmony_ci#define WM8776_REG_ALCCTRL2	0x11
948c2ecf20Sopenharmony_ci#define WM8776_ALC2_HOLD_MASK		0x0f	/*0=0ms, 1=2.67ms, 2=5.33ms.. */
958c2ecf20Sopenharmony_ci#define WM8776_ALC2_ZCEN		(1 << 7)
968c2ecf20Sopenharmony_ci#define WM8776_ALC2_LCEN		(1 << 8)
978c2ecf20Sopenharmony_ci#define WM8776_REG_ALCCTRL3	0x12
988c2ecf20Sopenharmony_ci#define WM8776_ALC3_ATK_MASK		0x0f
998c2ecf20Sopenharmony_ci#define WM8776_ALC3_DCY_MASK		0xf0
1008c2ecf20Sopenharmony_ci#define WM8776_ALC3_FDECAY		(1 << 8)
1018c2ecf20Sopenharmony_ci#define WM8776_REG_NOISEGATE	0x13
1028c2ecf20Sopenharmony_ci#define WM8776_NGAT_ENABLE		(1 << 0)
1038c2ecf20Sopenharmony_ci#define WM8776_NGAT_THR_MASK		0x1c	/*0=-78dB, 1=-72dB...7=-36dB */
1048c2ecf20Sopenharmony_ci#define WM8776_REG_LIMITER	0x14
1058c2ecf20Sopenharmony_ci#define WM8776_LIM_MAXATTEN_MASK	0x0f
1068c2ecf20Sopenharmony_ci#define WM8776_LIM_TRANWIN_MASK		0x70	/*0=0us, 1=62.5us, 2=125us.. */
1078c2ecf20Sopenharmony_ci#define WM8776_REG_ADCMUX	0x15
1088c2ecf20Sopenharmony_ci#define WM8776_ADC_MUX_AIN1		(1 << 0)
1098c2ecf20Sopenharmony_ci#define WM8776_ADC_MUX_AIN2		(1 << 1)
1108c2ecf20Sopenharmony_ci#define WM8776_ADC_MUX_AIN3		(1 << 2)
1118c2ecf20Sopenharmony_ci#define WM8776_ADC_MUX_AIN4		(1 << 3)
1128c2ecf20Sopenharmony_ci#define WM8776_ADC_MUX_AIN5		(1 << 4)
1138c2ecf20Sopenharmony_ci#define WM8776_ADC_MUTER		(1 << 6)
1148c2ecf20Sopenharmony_ci#define WM8776_ADC_MUTEL		(1 << 7)
1158c2ecf20Sopenharmony_ci#define WM8776_ADC_LRBOTH		(1 << 8)
1168c2ecf20Sopenharmony_ci#define WM8776_REG_OUTMUX	0x16
1178c2ecf20Sopenharmony_ci#define WM8776_OUTMUX_DAC		(1 << 0)
1188c2ecf20Sopenharmony_ci#define WM8776_OUTMUX_AUX		(1 << 1)
1198c2ecf20Sopenharmony_ci#define WM8776_OUTMUX_BYPASS		(1 << 2)
1208c2ecf20Sopenharmony_ci#define WM8776_REG_RESET	0x17
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci#define WM8776_REG_COUNT	0x17	/* don't cache the RESET register */
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_cistruct snd_wm8776;
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_cistruct snd_wm8776_ops {
1278c2ecf20Sopenharmony_ci	void (*write)(struct snd_wm8776 *wm, u8 addr, u8 data);
1288c2ecf20Sopenharmony_ci};
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_cienum snd_wm8776_ctl_id {
1318c2ecf20Sopenharmony_ci	WM8776_CTL_DAC_VOL,
1328c2ecf20Sopenharmony_ci	WM8776_CTL_DAC_SW,
1338c2ecf20Sopenharmony_ci	WM8776_CTL_DAC_ZC_SW,
1348c2ecf20Sopenharmony_ci	WM8776_CTL_HP_VOL,
1358c2ecf20Sopenharmony_ci	WM8776_CTL_HP_SW,
1368c2ecf20Sopenharmony_ci	WM8776_CTL_HP_ZC_SW,
1378c2ecf20Sopenharmony_ci	WM8776_CTL_AUX_SW,
1388c2ecf20Sopenharmony_ci	WM8776_CTL_BYPASS_SW,
1398c2ecf20Sopenharmony_ci	WM8776_CTL_DAC_IZD_SW,
1408c2ecf20Sopenharmony_ci	WM8776_CTL_PHASE_SW,
1418c2ecf20Sopenharmony_ci	WM8776_CTL_DEEMPH_SW,
1428c2ecf20Sopenharmony_ci	WM8776_CTL_ADC_VOL,
1438c2ecf20Sopenharmony_ci	WM8776_CTL_ADC_SW,
1448c2ecf20Sopenharmony_ci	WM8776_CTL_INPUT1_SW,
1458c2ecf20Sopenharmony_ci	WM8776_CTL_INPUT2_SW,
1468c2ecf20Sopenharmony_ci	WM8776_CTL_INPUT3_SW,
1478c2ecf20Sopenharmony_ci	WM8776_CTL_INPUT4_SW,
1488c2ecf20Sopenharmony_ci	WM8776_CTL_INPUT5_SW,
1498c2ecf20Sopenharmony_ci	WM8776_CTL_AGC_SEL,
1508c2ecf20Sopenharmony_ci	WM8776_CTL_LIM_THR,
1518c2ecf20Sopenharmony_ci	WM8776_CTL_LIM_ATK,
1528c2ecf20Sopenharmony_ci	WM8776_CTL_LIM_DCY,
1538c2ecf20Sopenharmony_ci	WM8776_CTL_LIM_TRANWIN,
1548c2ecf20Sopenharmony_ci	WM8776_CTL_LIM_MAXATTN,
1558c2ecf20Sopenharmony_ci	WM8776_CTL_ALC_TGT,
1568c2ecf20Sopenharmony_ci	WM8776_CTL_ALC_ATK,
1578c2ecf20Sopenharmony_ci	WM8776_CTL_ALC_DCY,
1588c2ecf20Sopenharmony_ci	WM8776_CTL_ALC_MAXGAIN,
1598c2ecf20Sopenharmony_ci	WM8776_CTL_ALC_MAXATTN,
1608c2ecf20Sopenharmony_ci	WM8776_CTL_ALC_HLD,
1618c2ecf20Sopenharmony_ci	WM8776_CTL_NGT_SW,
1628c2ecf20Sopenharmony_ci	WM8776_CTL_NGT_THR,
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci	WM8776_CTL_COUNT,
1658c2ecf20Sopenharmony_ci};
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci#define WM8776_ENUM_MAX		16
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci#define WM8776_FLAG_STEREO	(1 << 0)
1708c2ecf20Sopenharmony_ci#define WM8776_FLAG_VOL_UPDATE	(1 << 1)
1718c2ecf20Sopenharmony_ci#define WM8776_FLAG_INVERT	(1 << 2)
1728c2ecf20Sopenharmony_ci#define WM8776_FLAG_LIM		(1 << 3)
1738c2ecf20Sopenharmony_ci#define WM8776_FLAG_ALC		(1 << 4)
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_cistruct snd_wm8776_ctl {
1768c2ecf20Sopenharmony_ci	const char *name;
1778c2ecf20Sopenharmony_ci	snd_ctl_elem_type_t type;
1788c2ecf20Sopenharmony_ci	const char *const enum_names[WM8776_ENUM_MAX];
1798c2ecf20Sopenharmony_ci	const unsigned int *tlv;
1808c2ecf20Sopenharmony_ci	u16 reg1, reg2, mask1, mask2, min, max, flags;
1818c2ecf20Sopenharmony_ci	void (*set)(struct snd_wm8776 *wm, u16 ch1, u16 ch2);
1828c2ecf20Sopenharmony_ci	void (*get)(struct snd_wm8776 *wm, u16 *ch1, u16 *ch2);
1838c2ecf20Sopenharmony_ci};
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_cienum snd_wm8776_agc_mode {
1868c2ecf20Sopenharmony_ci	WM8776_AGC_OFF,
1878c2ecf20Sopenharmony_ci	WM8776_AGC_LIM,
1888c2ecf20Sopenharmony_ci	WM8776_AGC_ALC_R,
1898c2ecf20Sopenharmony_ci	WM8776_AGC_ALC_L,
1908c2ecf20Sopenharmony_ci	WM8776_AGC_ALC_STEREO
1918c2ecf20Sopenharmony_ci};
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_cistruct snd_wm8776 {
1948c2ecf20Sopenharmony_ci	struct snd_card *card;
1958c2ecf20Sopenharmony_ci	struct snd_wm8776_ctl ctl[WM8776_CTL_COUNT];
1968c2ecf20Sopenharmony_ci	enum snd_wm8776_agc_mode agc_mode;
1978c2ecf20Sopenharmony_ci	struct snd_wm8776_ops ops;
1988c2ecf20Sopenharmony_ci	u16 regs[WM8776_REG_COUNT];	/* 9-bit registers */
1998c2ecf20Sopenharmony_ci};
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_civoid snd_wm8776_init(struct snd_wm8776 *wm);
2048c2ecf20Sopenharmony_civoid snd_wm8776_resume(struct snd_wm8776 *wm);
2058c2ecf20Sopenharmony_civoid snd_wm8776_set_power(struct snd_wm8776 *wm, u16 power);
2068c2ecf20Sopenharmony_civoid snd_wm8776_volume_restore(struct snd_wm8776 *wm);
2078c2ecf20Sopenharmony_ciint snd_wm8776_build_controls(struct snd_wm8776 *wm);
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ci#endif /* __SOUND_WM8776_H */
210