18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci#ifndef __SOUND_WM8766_H
38c2ecf20Sopenharmony_ci#define __SOUND_WM8766_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci/*
68c2ecf20Sopenharmony_ci *   ALSA driver for ICEnsemble VT17xx
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci *   Lowlevel functions for WM8766 codec
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci *	Copyright (c) 2012 Ondrej Zary <linux@rainbow-software.org>
118c2ecf20Sopenharmony_ci */
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#define WM8766_REG_DACL1	0x00
148c2ecf20Sopenharmony_ci#define WM8766_REG_DACR1	0x01
158c2ecf20Sopenharmony_ci#define WM8766_VOL_MASK			0x1ff		/* incl. update bit */
168c2ecf20Sopenharmony_ci#define WM8766_VOL_UPDATE		(1 << 8)	/* update volume */
178c2ecf20Sopenharmony_ci#define WM8766_REG_DACCTRL1	0x02
188c2ecf20Sopenharmony_ci#define WM8766_DAC_MUTEALL		(1 << 0)
198c2ecf20Sopenharmony_ci#define WM8766_DAC_DEEMPALL		(1 << 1)
208c2ecf20Sopenharmony_ci#define WM8766_DAC_PDWN			(1 << 2)
218c2ecf20Sopenharmony_ci#define WM8766_DAC_ATC			(1 << 3)
228c2ecf20Sopenharmony_ci#define WM8766_DAC_IZD			(1 << 4)
238c2ecf20Sopenharmony_ci#define WM8766_DAC_PL_MASK		0x1e0
248c2ecf20Sopenharmony_ci#define WM8766_DAC_PL_LL		(1 << 5)	/* L chan: L signal */
258c2ecf20Sopenharmony_ci#define WM8766_DAC_PL_LR		(2 << 5)	/* L chan: R signal */
268c2ecf20Sopenharmony_ci#define WM8766_DAC_PL_LB		(3 << 5)	/* L chan: both */
278c2ecf20Sopenharmony_ci#define WM8766_DAC_PL_RL		(1 << 7)	/* R chan: L signal */
288c2ecf20Sopenharmony_ci#define WM8766_DAC_PL_RR		(2 << 7)	/* R chan: R signal */
298c2ecf20Sopenharmony_ci#define WM8766_DAC_PL_RB		(3 << 7)	/* R chan: both */
308c2ecf20Sopenharmony_ci#define WM8766_REG_IFCTRL	0x03
318c2ecf20Sopenharmony_ci#define WM8766_IF_FMT_RIGHTJ		(0 << 0)
328c2ecf20Sopenharmony_ci#define WM8766_IF_FMT_LEFTJ		(1 << 0)
338c2ecf20Sopenharmony_ci#define WM8766_IF_FMT_I2S		(2 << 0)
348c2ecf20Sopenharmony_ci#define WM8766_IF_FMT_DSP		(3 << 0)
358c2ecf20Sopenharmony_ci#define WM8766_IF_DSP_LATE		(1 << 2)	/* in DSP mode */
368c2ecf20Sopenharmony_ci#define WM8766_IF_LRC_INVERTED		(1 << 2)	/* in other modes */
378c2ecf20Sopenharmony_ci#define WM8766_IF_BCLK_INVERTED		(1 << 3)
388c2ecf20Sopenharmony_ci#define WM8766_IF_IWL_16BIT		(0 << 4)
398c2ecf20Sopenharmony_ci#define WM8766_IF_IWL_20BIT		(1 << 4)
408c2ecf20Sopenharmony_ci#define WM8766_IF_IWL_24BIT		(2 << 4)
418c2ecf20Sopenharmony_ci#define WM8766_IF_IWL_32BIT		(3 << 4)
428c2ecf20Sopenharmony_ci#define WM8766_IF_MASK			0x3f
438c2ecf20Sopenharmony_ci#define WM8766_PHASE_INVERT1		(1 << 6)
448c2ecf20Sopenharmony_ci#define WM8766_PHASE_INVERT2		(1 << 7)
458c2ecf20Sopenharmony_ci#define WM8766_PHASE_INVERT3		(1 << 8)
468c2ecf20Sopenharmony_ci#define WM8766_REG_DACL2	0x04
478c2ecf20Sopenharmony_ci#define WM8766_REG_DACR2	0x05
488c2ecf20Sopenharmony_ci#define WM8766_REG_DACL3	0x06
498c2ecf20Sopenharmony_ci#define WM8766_REG_DACR3	0x07
508c2ecf20Sopenharmony_ci#define WM8766_REG_MASTDA	0x08
518c2ecf20Sopenharmony_ci#define WM8766_REG_DACCTRL2	0x09
528c2ecf20Sopenharmony_ci#define WM8766_DAC2_ZCD			(1 << 0)
538c2ecf20Sopenharmony_ci#define WM8766_DAC2_ZFLAG_ALL		(0 << 1)
548c2ecf20Sopenharmony_ci#define WM8766_DAC2_ZFLAG_1		(1 << 1)
558c2ecf20Sopenharmony_ci#define WM8766_DAC2_ZFLAG_2		(2 << 1)
568c2ecf20Sopenharmony_ci#define WM8766_DAC2_ZFLAG_3		(3 << 1)
578c2ecf20Sopenharmony_ci#define WM8766_DAC2_MUTE1		(1 << 3)
588c2ecf20Sopenharmony_ci#define WM8766_DAC2_MUTE2		(1 << 4)
598c2ecf20Sopenharmony_ci#define WM8766_DAC2_MUTE3		(1 << 5)
608c2ecf20Sopenharmony_ci#define WM8766_DAC2_DEEMP1		(1 << 6)
618c2ecf20Sopenharmony_ci#define WM8766_DAC2_DEEMP2		(1 << 7)
628c2ecf20Sopenharmony_ci#define WM8766_DAC2_DEEMP3		(1 << 8)
638c2ecf20Sopenharmony_ci#define WM8766_REG_DACCTRL3	0x0a
648c2ecf20Sopenharmony_ci#define WM8766_DAC3_DACPD1		(1 << 1)
658c2ecf20Sopenharmony_ci#define WM8766_DAC3_DACPD2		(1 << 2)
668c2ecf20Sopenharmony_ci#define WM8766_DAC3_DACPD3		(1 << 3)
678c2ecf20Sopenharmony_ci#define WM8766_DAC3_PWRDNALL		(1 << 4)
688c2ecf20Sopenharmony_ci#define WM8766_DAC3_POWER_MASK		0x1e
698c2ecf20Sopenharmony_ci#define WM8766_DAC3_MASTER		(1 << 5)
708c2ecf20Sopenharmony_ci#define WM8766_DAC3_DAC128FS		(0 << 6)
718c2ecf20Sopenharmony_ci#define WM8766_DAC3_DAC192FS		(1 << 6)
728c2ecf20Sopenharmony_ci#define WM8766_DAC3_DAC256FS		(2 << 6)
738c2ecf20Sopenharmony_ci#define WM8766_DAC3_DAC384FS		(3 << 6)
748c2ecf20Sopenharmony_ci#define WM8766_DAC3_DAC512FS		(4 << 6)
758c2ecf20Sopenharmony_ci#define WM8766_DAC3_DAC768FS		(5 << 6)
768c2ecf20Sopenharmony_ci#define WM8766_DAC3_MSTR_MASK		0x1e0
778c2ecf20Sopenharmony_ci#define WM8766_REG_MUTE1	0x0c
788c2ecf20Sopenharmony_ci#define WM8766_MUTE1_MPD		(1 << 6)
798c2ecf20Sopenharmony_ci#define WM8766_REG_MUTE2	0x0f
808c2ecf20Sopenharmony_ci#define WM8766_MUTE2_MPD		(1 << 5)
818c2ecf20Sopenharmony_ci#define WM8766_REG_RESET	0x1f
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci#define WM8766_REG_COUNT	0x10	/* don't cache the RESET register */
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_cistruct snd_wm8766;
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_cistruct snd_wm8766_ops {
888c2ecf20Sopenharmony_ci	void (*write)(struct snd_wm8766 *wm, u16 addr, u16 data);
898c2ecf20Sopenharmony_ci};
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_cienum snd_wm8766_ctl_id {
928c2ecf20Sopenharmony_ci	WM8766_CTL_CH1_VOL,
938c2ecf20Sopenharmony_ci	WM8766_CTL_CH2_VOL,
948c2ecf20Sopenharmony_ci	WM8766_CTL_CH3_VOL,
958c2ecf20Sopenharmony_ci	WM8766_CTL_CH1_SW,
968c2ecf20Sopenharmony_ci	WM8766_CTL_CH2_SW,
978c2ecf20Sopenharmony_ci	WM8766_CTL_CH3_SW,
988c2ecf20Sopenharmony_ci	WM8766_CTL_PHASE1_SW,
998c2ecf20Sopenharmony_ci	WM8766_CTL_PHASE2_SW,
1008c2ecf20Sopenharmony_ci	WM8766_CTL_PHASE3_SW,
1018c2ecf20Sopenharmony_ci	WM8766_CTL_DEEMPH1_SW,
1028c2ecf20Sopenharmony_ci	WM8766_CTL_DEEMPH2_SW,
1038c2ecf20Sopenharmony_ci	WM8766_CTL_DEEMPH3_SW,
1048c2ecf20Sopenharmony_ci	WM8766_CTL_IZD_SW,
1058c2ecf20Sopenharmony_ci	WM8766_CTL_ZC_SW,
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci	WM8766_CTL_COUNT,
1088c2ecf20Sopenharmony_ci};
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci#define WM8766_ENUM_MAX		16
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci#define WM8766_FLAG_STEREO	(1 << 0)
1138c2ecf20Sopenharmony_ci#define WM8766_FLAG_VOL_UPDATE	(1 << 1)
1148c2ecf20Sopenharmony_ci#define WM8766_FLAG_INVERT	(1 << 2)
1158c2ecf20Sopenharmony_ci#define WM8766_FLAG_LIM		(1 << 3)
1168c2ecf20Sopenharmony_ci#define WM8766_FLAG_ALC		(1 << 4)
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_cistruct snd_wm8766_ctl {
1198c2ecf20Sopenharmony_ci	struct snd_kcontrol *kctl;
1208c2ecf20Sopenharmony_ci	const char *name;
1218c2ecf20Sopenharmony_ci	snd_ctl_elem_type_t type;
1228c2ecf20Sopenharmony_ci	const char *const enum_names[WM8766_ENUM_MAX];
1238c2ecf20Sopenharmony_ci	const unsigned int *tlv;
1248c2ecf20Sopenharmony_ci	u16 reg1, reg2, mask1, mask2, min, max, flags;
1258c2ecf20Sopenharmony_ci	void (*set)(struct snd_wm8766 *wm, u16 ch1, u16 ch2);
1268c2ecf20Sopenharmony_ci	void (*get)(struct snd_wm8766 *wm, u16 *ch1, u16 *ch2);
1278c2ecf20Sopenharmony_ci};
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_cienum snd_wm8766_agc_mode { WM8766_AGC_OFF, WM8766_AGC_LIM, WM8766_AGC_ALC };
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_cistruct snd_wm8766 {
1328c2ecf20Sopenharmony_ci	struct snd_card *card;
1338c2ecf20Sopenharmony_ci	struct snd_wm8766_ctl ctl[WM8766_CTL_COUNT];
1348c2ecf20Sopenharmony_ci	enum snd_wm8766_agc_mode agc_mode;
1358c2ecf20Sopenharmony_ci	struct snd_wm8766_ops ops;
1368c2ecf20Sopenharmony_ci	u16 regs[WM8766_REG_COUNT];	/* 9-bit registers */
1378c2ecf20Sopenharmony_ci};
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_civoid snd_wm8766_init(struct snd_wm8766 *wm);
1428c2ecf20Sopenharmony_civoid snd_wm8766_resume(struct snd_wm8766 *wm);
1438c2ecf20Sopenharmony_civoid snd_wm8766_set_if(struct snd_wm8766 *wm, u16 dac);
1448c2ecf20Sopenharmony_civoid snd_wm8766_volume_restore(struct snd_wm8766 *wm);
1458c2ecf20Sopenharmony_ciint snd_wm8766_build_controls(struct snd_wm8766 *wm);
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci#endif /* __SOUND_WM8766_H */
148