2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2006 Stephane E. Potvin <sepotvin@videotron.ca>
5 * Copyright (c) 2006 Ariff Abdullah <ariff@FreeBSD.org>
6 * Copyright (c) 2008-2012 Alexander Motin <mav@FreeBSD.org>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * Intel High Definition Audio (Audio function quirks) driver for FreeBSD.
37 #ifndef _HDAA_QUIRKS_H_
38 #define _HDAA_QUIRKS_H_
40 #define HDAA_GPIO_SHIFT(n) (n * 3)
41 #define HDAA_GPIO_MASK(n) (0x7 << (n * 3))
42 #define HDAA_GPIO_KEEP(n) (0x0 << (n * 3))
43 #define HDAA_GPIO_SET(n) (0x1 << (n * 3))
44 #define HDAA_GPIO_CLEAR(n) (0x2 << (n * 3))
45 #define HDAA_GPIO_DISABLE(n) (0x3 << (n * 3))
46 #define HDAA_GPIO_INPUT(n) (0x4 << (n * 3))
48 /* 9 - 25 = anything else */
49 #define HDAA_QUIRK_SOFTPCMVOL (1 << 9)
50 #define HDAA_QUIRK_FIXEDRATE (1 << 10)
51 #define HDAA_QUIRK_FORCESTEREO (1 << 11)
52 #define HDAA_QUIRK_EAPDINV (1 << 12)
53 #define HDAA_QUIRK_SENSEINV (1 << 14)
56 #define HDAA_QUIRK_IVREF50 (1 << 26)
57 #define HDAA_QUIRK_IVREF80 (1 << 27)
58 #define HDAA_QUIRK_IVREF100 (1 << 28)
59 #define HDAA_QUIRK_OVREF50 (1 << 29)
60 #define HDAA_QUIRK_OVREF80 (1 << 30)
61 #define HDAA_QUIRK_OVREF100 (1U << 31)
63 #define HDAA_QUIRK_IVREF (HDAA_QUIRK_IVREF50 | HDAA_QUIRK_IVREF80 | \
65 #define HDAA_QUIRK_OVREF (HDAA_QUIRK_OVREF50 | HDAA_QUIRK_OVREF80 | \
67 #define HDAA_QUIRK_VREF (HDAA_QUIRK_IVREF | HDAA_QUIRK_OVREF)
69 #define HDAA_AMP_VOL_DEFAULT (-1)
70 #define HDAA_AMP_MUTE_DEFAULT (0xffffffff)
71 #define HDAA_AMP_MUTE_NONE (0)
72 #define HDAA_AMP_MUTE_LEFT (1 << 0)
73 #define HDAA_AMP_MUTE_RIGHT (1 << 1)
74 #define HDAA_AMP_MUTE_ALL (HDAA_AMP_MUTE_LEFT | HDAA_AMP_MUTE_RIGHT)
76 #define HDAA_AMP_LEFT_MUTED(v) ((v) & (HDAA_AMP_MUTE_LEFT))
77 #define HDAA_AMP_RIGHT_MUTED(v) (((v) & HDAA_AMP_MUTE_RIGHT) >> 1)
79 /* Widget in playback receiving signal from recording. */
80 #define HDAA_ADC_MONITOR (1 << 0)
81 /* Input mixer widget needs volume control as destination. */
82 #define HDAA_IMIX_AS_DST (2 << 0)
84 #define HDAA_CTL_OUT 1
87 #define HDA_MAX_CONNS 32
88 #define HDA_MAX_NAMELEN 32
91 struct hdaa_audio_ctl;
94 struct hdaa_pcm_devinfo;
109 nid_t conns[HDA_MAX_CONNS];
110 u_char connsenable[HDA_MAX_CONNS];
111 char name[HDA_MAX_NAMELEN];
114 struct hdaa_devinfo *devinfo;
119 uint32_t supp_stream_formats;
120 uint32_t supp_pcm_size_rate;
138 struct hdaa_audio_ctl {
139 struct hdaa_widget *widget, *childwidget;
141 int index, dir, ndir;
142 int mute, step, size, offset;
143 int left, right, forcemute;
145 uint32_t ossmask; /* OSS devices that may affect control. */
146 int devleft[SOUND_MIXER_NRDEVICES]; /* Left ampl in 1/4dB. */
147 int devright[SOUND_MIXER_NRDEVICES]; /* Right ampl in 1/4dB. */
148 int devmute[SOUND_MIXER_NRDEVICES]; /* Mutes per OSS device. */
151 /* Association is a group of pins bound for some special function. */
152 struct hdaa_audio_as {
165 int location; /* Pins location, if all have the same */
166 int mixed; /* Mixed/multiplexed recording, not multichannel. */
167 struct hdaa_pcm_devinfo *pdevinfo;
170 struct hdaa_pcm_devinfo {
172 struct hdaa_devinfo *devinfo;
173 struct snd_mixer *mixer;
177 u_char left[SOUND_MIXER_NRDEVICES];
178 u_char right[SOUND_MIXER_NRDEVICES];
179 int minamp[SOUND_MIXER_NRDEVICES]; /* Minimal amps in 1/4dB. */
180 int maxamp[SOUND_MIXER_NRDEVICES]; /* Maximal amps in 1/4dB. */
184 uint32_t ossmask; /* Mask of supported OSS devices. */
185 uint32_t recsrc; /* Mask of supported OSS sources. */
189 struct hdaa_devinfo {
193 nid_t startnode, endnode;
196 uint32_t supp_stream_formats;
197 uint32_t supp_pcm_size_rate;
210 struct hdaa_widget *widget;
211 struct hdaa_audio_ctl *ctl;
212 struct hdaa_audio_as *as;
213 struct hdaa_pcm_devinfo *devs;
214 struct hdaa_chan *chans;
215 struct callout poll_jack;
220 #define HDAA_CHN_RUNNING 0x00000001
221 #define HDAA_CHN_SUSPEND 0x00000002
225 struct pcm_channel *c;
226 struct pcmchan_caps caps;
227 struct hdaa_devinfo *devinfo;
228 struct hdaa_pcm_devinfo *pdevinfo;
229 uint32_t spd, fmt, fmtlist[32], pcmrates[16];
230 uint32_t supp_stream_formats, supp_pcm_size_rate;
231 uint32_t blkcnt, blksz;
238 int channels; /* Number of audio channels. */
239 int as; /* Number of association. */
240 int asindex; /* Index within association. */
242 uint8_t stripecap; /* AND of stripecap of all ios. */
243 uint8_t stripectl; /* stripe to use to all ios. */
246 #define MINQDB(ctl) \
247 ((0 - (ctl)->offset) * ((ctl)->size + 1))
249 #define MAXQDB(ctl) \
250 (((ctl)->step - (ctl)->offset) * ((ctl)->size + 1))
252 #define RANGEQDB(ctl) \
253 ((ctl)->step * ((ctl)->size + 1))
255 #define VAL2QDB(ctl, val) \
256 (((ctl)->size + 1) * ((int)(val) - (ctl)->offset))
258 #define QDB2VAL(ctl, qdb) \
259 imax(imin((((qdb) + (ctl)->size / 2 * ((qdb) > 0 ? 1 : -1)) / \
260 ((ctl)->size + 1) + (ctl)->offset), (ctl)->step), 0)
262 #define hdaa_codec_id(devinfo) \
263 (((uint32_t)hda_get_vendor_id(devinfo->dev) << 16) + \
264 hda_get_device_id(devinfo->dev))
266 #define hdaa_card_id(devinfo) \
267 (((uint32_t)hda_get_subdevice_id(devinfo->dev) << 16) + \
268 hda_get_subvendor_id(devinfo->dev))
270 struct hdaa_widget *hdaa_widget_get(struct hdaa_devinfo *, nid_t);
271 uint32_t hdaa_widget_pin_patch(uint32_t config, const char *str);
272 uint32_t hdaa_gpio_patch(uint32_t gpio, const char *str);
274 void hdaa_patch(struct hdaa_devinfo *devinfo);
275 void hdaa_patch_direct(struct hdaa_devinfo *devinfo);