xref: /freebsd/sys/dev/sound/pci/hda/hdaa.h (revision 7431dfd4580e850375fe5478d92ec770344db098)
1 /*-7
2  * Copyright (c) 2006 Stephane E. Potvin <sepotvin@videotron.ca>
3  * Copyright (c) 2006 Ariff Abdullah <ariff@FreeBSD.org>
4  * Copyright (c) 2008-2012 Alexander Motin <mav@FreeBSD.org>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * $FreeBSD$
29  */
30 
31 /*
32  * Intel High Definition Audio (Audio function quirks) driver for FreeBSD.
33  */
34 
35 #ifndef _HDAA_QUIRKS_H_
36 #define _HDAA_QUIRKS_H_
37 
38 #define HDAA_GPIO_SHIFT(n)	(n * 3)
39 #define HDAA_GPIO_MASK(n)	(0x7 << (n * 3))
40 #define HDAA_GPIO_KEEP(n)	(0x0 << (n * 3))
41 #define HDAA_GPIO_SET(n)	(0x1 << (n * 3))
42 #define HDAA_GPIO_CLEAR(n)	(0x2 << (n * 3))
43 #define HDAA_GPIO_DISABLE(n)	(0x3 << (n * 3))
44 #define HDAA_GPIO_INPUT(n)	(0x4 << (n * 3))
45 
46 /* 9 - 25 = anything else */
47 #define HDAA_QUIRK_SOFTPCMVOL	(1 << 9)
48 #define HDAA_QUIRK_FIXEDRATE	(1 << 10)
49 #define HDAA_QUIRK_FORCESTEREO	(1 << 11)
50 #define HDAA_QUIRK_EAPDINV	(1 << 12)
51 #define HDAA_QUIRK_SENSEINV	(1 << 14)
52 
53 /* 26 - 31 = vrefs */
54 #define HDAA_QUIRK_IVREF50	(1 << 26)
55 #define HDAA_QUIRK_IVREF80	(1 << 27)
56 #define HDAA_QUIRK_IVREF100	(1 << 28)
57 #define HDAA_QUIRK_OVREF50	(1 << 29)
58 #define HDAA_QUIRK_OVREF80	(1 << 30)
59 #define HDAA_QUIRK_OVREF100	(1U << 31)
60 
61 #define HDAA_QUIRK_IVREF	(HDAA_QUIRK_IVREF50 | HDAA_QUIRK_IVREF80 | \
62 						HDAA_QUIRK_IVREF100)
63 #define HDAA_QUIRK_OVREF	(HDAA_QUIRK_OVREF50 | HDAA_QUIRK_OVREF80 | \
64 						HDAA_QUIRK_OVREF100)
65 #define HDAA_QUIRK_VREF		(HDAA_QUIRK_IVREF | HDAA_QUIRK_OVREF)
66 
67 #define HDAA_AMP_VOL_DEFAULT	(-1)
68 #define HDAA_AMP_MUTE_DEFAULT	(0xffffffff)
69 #define HDAA_AMP_MUTE_NONE	(0)
70 #define HDAA_AMP_MUTE_LEFT	(1 << 0)
71 #define HDAA_AMP_MUTE_RIGHT	(1 << 1)
72 #define HDAA_AMP_MUTE_ALL	(HDAA_AMP_MUTE_LEFT | HDAA_AMP_MUTE_RIGHT)
73 
74 #define HDAA_AMP_LEFT_MUTED(v)	((v) & (HDAA_AMP_MUTE_LEFT))
75 #define HDAA_AMP_RIGHT_MUTED(v)	(((v) & HDAA_AMP_MUTE_RIGHT) >> 1)
76 
77 /* Widget in playback receiving signal from recording. */
78 #define HDAA_ADC_MONITOR		(1 << 0)
79 /* Input mixer widget needs volume control as destination. */
80 #define HDAA_IMIX_AS_DST		(2 << 0)
81 
82 #define HDAA_CTL_OUT		1
83 #define HDAA_CTL_IN		2
84 
85 #define HDA_MAX_CONNS	32
86 #define HDA_MAX_NAMELEN	32
87 
88 struct hdaa_audio_as;
89 struct hdaa_audio_ctl;
90 struct hdaa_chan;
91 struct hdaa_devinfo;
92 struct hdaa_pcm_devinfo;
93 struct hdaa_widget;
94 
95 struct hdaa_widget {
96 	nid_t nid;
97 	int type;
98 	int enable;
99 	int nconns, selconn;
100 	int waspin;
101 	uint32_t pflags;
102 	int bindas;
103 	int bindseqmask;
104 	int ossdev;
105 	uint32_t ossmask;
106 	int unsol;
107 	nid_t conns[HDA_MAX_CONNS];
108 	u_char connsenable[HDA_MAX_CONNS];
109 	char name[HDA_MAX_NAMELEN];
110 	uint8_t	*eld;
111 	int	eld_len;
112 	struct hdaa_devinfo *devinfo;
113 	struct {
114 		uint32_t widget_cap;
115 		uint32_t outamp_cap;
116 		uint32_t inamp_cap;
117 		uint32_t supp_stream_formats;
118 		uint32_t supp_pcm_size_rate;
119 		uint32_t eapdbtl;
120 	} param;
121 	union {
122 		struct {
123 			uint32_t config;
124 			uint32_t original;
125 			uint32_t newconf;
126 			uint32_t cap;
127 			uint32_t ctrl;
128 			int	connected;
129 		} pin;
130 		struct {
131 			uint8_t	stripecap;
132 		} conv;
133 	} wclass;
134 };
135 
136 struct hdaa_audio_ctl {
137 	struct hdaa_widget *widget, *childwidget;
138 	int enable;
139 	int index, dir, ndir;
140 	int mute, step, size, offset;
141 	int left, right, forcemute;
142 	uint32_t muted;
143 	uint32_t ossmask;	/* OSS devices that may affect control. */
144 	int	devleft[SOUND_MIXER_NRDEVICES]; /* Left ampl in 1/4dB. */
145 	int	devright[SOUND_MIXER_NRDEVICES]; /* Right ampl in 1/4dB. */
146 	int	devmute[SOUND_MIXER_NRDEVICES]; /* Mutes per OSS device. */
147 };
148 
149 /* Association is a group of pins bound for some special function. */
150 struct hdaa_audio_as {
151 	u_char enable;
152 	u_char index;
153 	u_char dir;
154 	u_char pincnt;
155 	u_char fakeredir;
156 	u_char digital;
157 	uint16_t pinset;
158 	nid_t hpredir;
159 	nid_t pins[16];
160 	nid_t dacs[2][16];
161 	int num_chans;
162 	int chans[2];
163 	int location;	/* Pins location, if all have the same */
164 	int mixed;	/* Mixed/multiplexed recording, not multichannel. */
165 	struct hdaa_pcm_devinfo *pdevinfo;
166 };
167 
168 struct hdaa_pcm_devinfo {
169 	device_t dev;
170 	struct hdaa_devinfo *devinfo;
171 	struct	snd_mixer *mixer;
172 	int	index;
173 	int	registered;
174 	int	playas, recas;
175 	u_char	left[SOUND_MIXER_NRDEVICES];
176 	u_char	right[SOUND_MIXER_NRDEVICES];
177 	int	minamp[SOUND_MIXER_NRDEVICES]; /* Minimal amps in 1/4dB. */
178 	int	maxamp[SOUND_MIXER_NRDEVICES]; /* Maximal amps in 1/4dB. */
179 	int	chan_size;
180 	int	chan_blkcnt;
181 	u_char	digital;
182 	uint32_t	ossmask;	/* Mask of supported OSS devices. */
183 	uint32_t	recsrc;		/* Mask of supported OSS sources. */
184 	int		autorecsrc;
185 };
186 
187 struct hdaa_devinfo {
188 	device_t		dev;
189 	struct mtx		*lock;
190 	nid_t			nid;
191 	nid_t			startnode, endnode;
192 	uint32_t		outamp_cap;
193 	uint32_t		inamp_cap;
194 	uint32_t		supp_stream_formats;
195 	uint32_t		supp_pcm_size_rate;
196 	uint32_t		gpio_cap;
197 	uint32_t		quirks;
198 	uint32_t		newquirks;
199 	uint32_t		gpio;
200 	uint32_t		newgpio;
201 	uint32_t		gpo;
202 	uint32_t		newgpo;
203 	int			nodecnt;
204 	int			ctlcnt;
205 	int			ascnt;
206 	int			num_devs;
207 	int			num_chans;
208 	struct hdaa_widget	*widget;
209 	struct hdaa_audio_ctl	*ctl;
210 	struct hdaa_audio_as	*as;
211 	struct hdaa_pcm_devinfo	*devs;
212 	struct hdaa_chan	*chans;
213 	struct callout		poll_jack;
214 	int			poll_ival;
215 };
216 
217 #define HDAA_CHN_RUNNING	0x00000001
218 #define HDAA_CHN_SUSPEND	0x00000002
219 
220 struct hdaa_chan {
221 	struct snd_dbuf *b;
222 	struct pcm_channel *c;
223 	struct pcmchan_caps caps;
224 	struct hdaa_devinfo *devinfo;
225 	struct hdaa_pcm_devinfo *pdevinfo;
226 	uint32_t spd, fmt, fmtlist[32], pcmrates[16];
227 	uint32_t supp_stream_formats, supp_pcm_size_rate;
228 	uint32_t blkcnt, blksz;
229 	uint32_t *dmapos;
230 	uint32_t flags;
231 	int dir;
232 	int off;
233 	int sid;
234 	int bit16, bit32;
235 	int channels;	/* Number of audio channels. */
236 	int as;		/* Number of association. */
237 	int asindex;	/* Index within association. */
238 	nid_t io[16];
239 	uint8_t	stripecap;	/* AND of stripecap of all ios. */
240 	uint8_t	stripectl;	/* stripe to use to all ios. */
241 };
242 
243 #define MINQDB(ctl)							\
244 	((0 - (ctl)->offset) * ((ctl)->size + 1))
245 
246 #define MAXQDB(ctl)							\
247 	(((ctl)->step - (ctl)->offset) * ((ctl)->size + 1))
248 
249 #define RANGEQDB(ctl)							\
250 	((ctl)->step * ((ctl)->size + 1))
251 
252 #define VAL2QDB(ctl, val) 						\
253 	(((ctl)->size + 1) * ((int)(val) - (ctl)->offset))
254 
255 #define QDB2VAL(ctl, qdb) 						\
256 	imax(imin((((qdb) + (ctl)->size / 2 * ((qdb) > 0 ? 1 : -1)) /	\
257 	 ((ctl)->size + 1) + (ctl)->offset), (ctl)->step), 0)
258 
259 #define hdaa_codec_id(devinfo)						\
260 		(((uint32_t)hda_get_vendor_id(devinfo->dev) << 16) +	\
261 		hda_get_device_id(devinfo->dev))
262 
263 #define hdaa_card_id(devinfo)					\
264 		(((uint32_t)hda_get_subdevice_id(devinfo->dev) << 16) +	\
265 		hda_get_subvendor_id(devinfo->dev))
266 
267 struct hdaa_widget	*hdaa_widget_get(struct hdaa_devinfo *, nid_t);
268 uint32_t		hdaa_widget_pin_patch(uint32_t config, const char *str);
269 uint32_t		hdaa_gpio_patch(uint32_t gpio, const char *str);
270 
271 void			hdaa_patch(struct hdaa_devinfo *devinfo);
272 void			hdaa_patch_direct(struct hdaa_devinfo *devinfo);
273 
274 #endif
275