xref: /openbmc/linux/sound/pci/ice1712/wm8766.h (revision 45d44e5a945296693b392ea807768329c1a80af6)
1*45d44e5aSOndrej Zary #ifndef __SOUND_WM8766_H
2*45d44e5aSOndrej Zary #define __SOUND_WM8766_H
3*45d44e5aSOndrej Zary 
4*45d44e5aSOndrej Zary /*
5*45d44e5aSOndrej Zary  *   ALSA driver for ICEnsemble VT17xx
6*45d44e5aSOndrej Zary  *
7*45d44e5aSOndrej Zary  *   Lowlevel functions for WM8766 codec
8*45d44e5aSOndrej Zary  *
9*45d44e5aSOndrej Zary  *	Copyright (c) 2012 Ondrej Zary <linux@rainbow-software.org>
10*45d44e5aSOndrej Zary  *
11*45d44e5aSOndrej Zary  *   This program is free software; you can redistribute it and/or modify
12*45d44e5aSOndrej Zary  *   it under the terms of the GNU General Public License as published by
13*45d44e5aSOndrej Zary  *   the Free Software Foundation; either version 2 of the License, or
14*45d44e5aSOndrej Zary  *   (at your option) any later version.
15*45d44e5aSOndrej Zary  *
16*45d44e5aSOndrej Zary  *   This program is distributed in the hope that it will be useful,
17*45d44e5aSOndrej Zary  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
18*45d44e5aSOndrej Zary  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19*45d44e5aSOndrej Zary  *   GNU General Public License for more details.
20*45d44e5aSOndrej Zary  *
21*45d44e5aSOndrej Zary  *   You should have received a copy of the GNU General Public License
22*45d44e5aSOndrej Zary  *   along with this program; if not, write to the Free Software
23*45d44e5aSOndrej Zary  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24*45d44e5aSOndrej Zary  *
25*45d44e5aSOndrej Zary  */
26*45d44e5aSOndrej Zary 
27*45d44e5aSOndrej Zary #define WM8766_REG_DACL1	0x00
28*45d44e5aSOndrej Zary #define WM8766_REG_DACR1	0x01
29*45d44e5aSOndrej Zary #define WM8766_VOL_MASK			0x1ff		/* incl. update bit */
30*45d44e5aSOndrej Zary #define WM8766_VOL_UPDATE		(1 << 8)	/* update volume */
31*45d44e5aSOndrej Zary #define WM8766_REG_DACCTRL1	0x02
32*45d44e5aSOndrej Zary #define WM8766_DAC_MUTEALL		(1 << 0)
33*45d44e5aSOndrej Zary #define WM8766_DAC_DEEMPALL		(1 << 1)
34*45d44e5aSOndrej Zary #define WM8766_DAC_PDWN			(1 << 2)
35*45d44e5aSOndrej Zary #define WM8766_DAC_ATC			(1 << 3)
36*45d44e5aSOndrej Zary #define WM8766_DAC_IZD			(1 << 4)
37*45d44e5aSOndrej Zary #define WM8766_DAC_PL_MASK		0x1e0
38*45d44e5aSOndrej Zary #define WM8766_DAC_PL_LL		(1 << 5)	/* L chan: L signal */
39*45d44e5aSOndrej Zary #define WM8766_DAC_PL_LR		(2 << 5)	/* L chan: R signal */
40*45d44e5aSOndrej Zary #define WM8766_DAC_PL_LB		(3 << 5)	/* L chan: both */
41*45d44e5aSOndrej Zary #define WM8766_DAC_PL_RL		(1 << 7)	/* R chan: L signal */
42*45d44e5aSOndrej Zary #define WM8766_DAC_PL_RR		(2 << 7)	/* R chan: R signal */
43*45d44e5aSOndrej Zary #define WM8766_DAC_PL_RB		(3 << 7)	/* R chan: both */
44*45d44e5aSOndrej Zary #define WM8766_REG_IFCTRL	0x03
45*45d44e5aSOndrej Zary #define WM8766_IF_FMT_RIGHTJ		(0 << 0)
46*45d44e5aSOndrej Zary #define WM8766_IF_FMT_LEFTJ		(1 << 0)
47*45d44e5aSOndrej Zary #define WM8766_IF_FMT_I2S		(2 << 0)
48*45d44e5aSOndrej Zary #define WM8766_IF_FMT_DSP		(3 << 0)
49*45d44e5aSOndrej Zary #define WM8766_IF_DSP_LATE		(1 << 2)	/* in DSP mode */
50*45d44e5aSOndrej Zary #define WM8766_IF_LRC_INVERTED		(1 << 2)	/* in other modes */
51*45d44e5aSOndrej Zary #define WM8766_IF_BCLK_INVERTED		(1 << 3)
52*45d44e5aSOndrej Zary #define WM8766_IF_IWL_16BIT		(0 << 4)
53*45d44e5aSOndrej Zary #define WM8766_IF_IWL_20BIT		(1 << 4)
54*45d44e5aSOndrej Zary #define WM8766_IF_IWL_24BIT		(2 << 4)
55*45d44e5aSOndrej Zary #define WM8766_IF_IWL_32BIT		(3 << 4)
56*45d44e5aSOndrej Zary #define WM8766_IF_MASK			0x3f
57*45d44e5aSOndrej Zary #define WM8766_PHASE_INVERT1		(1 << 6)
58*45d44e5aSOndrej Zary #define WM8766_PHASE_INVERT2		(1 << 7)
59*45d44e5aSOndrej Zary #define WM8766_PHASE_INVERT3		(1 << 8)
60*45d44e5aSOndrej Zary #define WM8766_REG_DACL2	0x04
61*45d44e5aSOndrej Zary #define WM8766_REG_DACR2	0x05
62*45d44e5aSOndrej Zary #define WM8766_REG_DACL3	0x06
63*45d44e5aSOndrej Zary #define WM8766_REG_DACR3	0x07
64*45d44e5aSOndrej Zary #define WM8766_REG_MASTDA	0x08
65*45d44e5aSOndrej Zary #define WM8766_REG_DACCTRL2	0x09
66*45d44e5aSOndrej Zary #define WM8766_DAC2_ZCD			(1 << 0)
67*45d44e5aSOndrej Zary #define WM8766_DAC2_ZFLAG_ALL		(0 << 1)
68*45d44e5aSOndrej Zary #define WM8766_DAC2_ZFLAG_1		(1 << 1)
69*45d44e5aSOndrej Zary #define WM8766_DAC2_ZFLAG_2		(2 << 1)
70*45d44e5aSOndrej Zary #define WM8766_DAC2_ZFLAG_3		(3 << 1)
71*45d44e5aSOndrej Zary #define WM8766_DAC2_MUTE1		(1 << 3)
72*45d44e5aSOndrej Zary #define WM8766_DAC2_MUTE2		(1 << 4)
73*45d44e5aSOndrej Zary #define WM8766_DAC2_MUTE3		(1 << 5)
74*45d44e5aSOndrej Zary #define WM8766_DAC2_DEEMP1		(1 << 6)
75*45d44e5aSOndrej Zary #define WM8766_DAC2_DEEMP2		(1 << 7)
76*45d44e5aSOndrej Zary #define WM8766_DAC2_DEEMP3		(1 << 8)
77*45d44e5aSOndrej Zary #define WM8766_REG_DACCTRL3	0x0a
78*45d44e5aSOndrej Zary #define WM8766_DAC3_DACPD1		(1 << 1)
79*45d44e5aSOndrej Zary #define WM8766_DAC3_DACPD2		(1 << 2)
80*45d44e5aSOndrej Zary #define WM8766_DAC3_DACPD3		(1 << 3)
81*45d44e5aSOndrej Zary #define WM8766_DAC3_PWRDNALL		(1 << 4)
82*45d44e5aSOndrej Zary #define WM8766_DAC3_POWER_MASK		0x1e
83*45d44e5aSOndrej Zary #define WM8766_DAC3_MASTER		(1 << 5)
84*45d44e5aSOndrej Zary #define WM8766_DAC3_DAC128FS		(0 << 6)
85*45d44e5aSOndrej Zary #define WM8766_DAC3_DAC192FS		(1 << 6)
86*45d44e5aSOndrej Zary #define WM8766_DAC3_DAC256FS		(2 << 6)
87*45d44e5aSOndrej Zary #define WM8766_DAC3_DAC384FS		(3 << 6)
88*45d44e5aSOndrej Zary #define WM8766_DAC3_DAC512FS		(4 << 6)
89*45d44e5aSOndrej Zary #define WM8766_DAC3_DAC768FS		(5 << 6)
90*45d44e5aSOndrej Zary #define WM8766_DAC3_MSTR_MASK		0x1e0
91*45d44e5aSOndrej Zary #define WM8766_REG_MUTE1	0x0c
92*45d44e5aSOndrej Zary #define WM8766_MUTE1_MPD		(1 << 6)
93*45d44e5aSOndrej Zary #define WM8766_REG_MUTE2	0x0f
94*45d44e5aSOndrej Zary #define WM8766_MUTE2_MPD		(1 << 5)
95*45d44e5aSOndrej Zary #define WM8766_REG_RESET	0x1f
96*45d44e5aSOndrej Zary 
97*45d44e5aSOndrej Zary #define WM8766_REG_COUNT	0x10	/* don't cache the RESET register */
98*45d44e5aSOndrej Zary 
99*45d44e5aSOndrej Zary struct snd_wm8766;
100*45d44e5aSOndrej Zary 
101*45d44e5aSOndrej Zary struct snd_wm8766_ops {
102*45d44e5aSOndrej Zary 	void (*write)(struct snd_wm8766 *wm, u16 addr, u16 data);
103*45d44e5aSOndrej Zary };
104*45d44e5aSOndrej Zary 
105*45d44e5aSOndrej Zary enum snd_wm8766_ctl_id {
106*45d44e5aSOndrej Zary 	WM8766_CTL_CH1_VOL,
107*45d44e5aSOndrej Zary 	WM8766_CTL_CH2_VOL,
108*45d44e5aSOndrej Zary 	WM8766_CTL_CH3_VOL,
109*45d44e5aSOndrej Zary 	WM8766_CTL_CH1_SW,
110*45d44e5aSOndrej Zary 	WM8766_CTL_CH2_SW,
111*45d44e5aSOndrej Zary 	WM8766_CTL_CH3_SW,
112*45d44e5aSOndrej Zary 	WM8766_CTL_PHASE1_SW,
113*45d44e5aSOndrej Zary 	WM8766_CTL_PHASE2_SW,
114*45d44e5aSOndrej Zary 	WM8766_CTL_PHASE3_SW,
115*45d44e5aSOndrej Zary 	WM8766_CTL_DEEMPH1_SW,
116*45d44e5aSOndrej Zary 	WM8766_CTL_DEEMPH2_SW,
117*45d44e5aSOndrej Zary 	WM8766_CTL_DEEMPH3_SW,
118*45d44e5aSOndrej Zary 	WM8766_CTL_IZD_SW,
119*45d44e5aSOndrej Zary 	WM8766_CTL_ZC_SW,
120*45d44e5aSOndrej Zary 
121*45d44e5aSOndrej Zary 	WM8766_CTL_COUNT,
122*45d44e5aSOndrej Zary };
123*45d44e5aSOndrej Zary 
124*45d44e5aSOndrej Zary #define WM8766_ENUM_MAX		16
125*45d44e5aSOndrej Zary 
126*45d44e5aSOndrej Zary #define WM8766_FLAG_STEREO	(1 << 0)
127*45d44e5aSOndrej Zary #define WM8766_FLAG_VOL_UPDATE	(1 << 1)
128*45d44e5aSOndrej Zary #define WM8766_FLAG_INVERT	(1 << 2)
129*45d44e5aSOndrej Zary #define WM8766_FLAG_LIM		(1 << 3)
130*45d44e5aSOndrej Zary #define WM8766_FLAG_ALC		(1 << 4)
131*45d44e5aSOndrej Zary 
132*45d44e5aSOndrej Zary struct snd_wm8766_ctl {
133*45d44e5aSOndrej Zary 	struct snd_kcontrol *kctl;
134*45d44e5aSOndrej Zary 	char *name;
135*45d44e5aSOndrej Zary 	snd_ctl_elem_type_t type;
136*45d44e5aSOndrej Zary 	const char *const enum_names[WM8766_ENUM_MAX];
137*45d44e5aSOndrej Zary 	const unsigned int *tlv;
138*45d44e5aSOndrej Zary 	u16 reg1, reg2, mask1, mask2, min, max, flags;
139*45d44e5aSOndrej Zary 	void (*set)(struct snd_wm8766 *wm, u16 ch1, u16 ch2);
140*45d44e5aSOndrej Zary 	void (*get)(struct snd_wm8766 *wm, u16 *ch1, u16 *ch2);
141*45d44e5aSOndrej Zary };
142*45d44e5aSOndrej Zary 
143*45d44e5aSOndrej Zary enum snd_wm8766_agc_mode { WM8766_AGC_OFF, WM8766_AGC_LIM, WM8766_AGC_ALC };
144*45d44e5aSOndrej Zary 
145*45d44e5aSOndrej Zary struct snd_wm8766 {
146*45d44e5aSOndrej Zary 	struct snd_card *card;
147*45d44e5aSOndrej Zary 	struct snd_wm8766_ctl ctl[WM8766_CTL_COUNT];
148*45d44e5aSOndrej Zary 	enum snd_wm8766_agc_mode agc_mode;
149*45d44e5aSOndrej Zary 	struct snd_wm8766_ops ops;
150*45d44e5aSOndrej Zary 	u16 regs[WM8766_REG_COUNT];	/* 9-bit registers */
151*45d44e5aSOndrej Zary };
152*45d44e5aSOndrej Zary 
153*45d44e5aSOndrej Zary 
154*45d44e5aSOndrej Zary 
155*45d44e5aSOndrej Zary void snd_wm8766_init(struct snd_wm8766 *wm);
156*45d44e5aSOndrej Zary void snd_wm8766_resume(struct snd_wm8766 *wm);
157*45d44e5aSOndrej Zary void snd_wm8766_set_if(struct snd_wm8766 *wm, u16 dac);
158*45d44e5aSOndrej Zary void snd_wm8766_set_master_mode(struct snd_wm8766 *wm, u16 mode);
159*45d44e5aSOndrej Zary void snd_wm8766_set_power(struct snd_wm8766 *wm, u16 power);
160*45d44e5aSOndrej Zary void snd_wm8766_volume_restore(struct snd_wm8766 *wm);
161*45d44e5aSOndrej Zary int snd_wm8766_build_controls(struct snd_wm8766 *wm);
162*45d44e5aSOndrej Zary 
163*45d44e5aSOndrej Zary #endif /* __SOUND_WM8766_H */
164