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>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
30 * Intel High Definition Audio (Audio function) driver for FreeBSD.
33 #ifdef HAVE_KERNEL_OPTION_HEADERS
37 #include <dev/sound/pcm/sound.h>
39 #include <sys/ctype.h>
40 #include <sys/taskqueue.h>
42 #include <dev/sound/pci/hda/hdac.h>
43 #include <dev/sound/pci/hda/hdaa.h>
44 #include <dev/sound/pci/hda/hda_reg.h>
48 SND_DECLARE_FILE("$FreeBSD$");
50 #define hdaa_lock(devinfo) snd_mtxlock((devinfo)->lock)
51 #define hdaa_unlock(devinfo) snd_mtxunlock((devinfo)->lock)
52 #define hdaa_lockassert(devinfo) snd_mtxassert((devinfo)->lock)
53 #define hdaa_lockowned(devinfo) mtx_owned((devinfo)->lock)
58 } hdaa_quirks_tab[] = {
59 { "softpcmvol", HDAA_QUIRK_SOFTPCMVOL },
60 { "fixedrate", HDAA_QUIRK_FIXEDRATE },
61 { "forcestereo", HDAA_QUIRK_FORCESTEREO },
62 { "eapdinv", HDAA_QUIRK_EAPDINV },
63 { "senseinv", HDAA_QUIRK_SENSEINV },
64 { "ivref50", HDAA_QUIRK_IVREF50 },
65 { "ivref80", HDAA_QUIRK_IVREF80 },
66 { "ivref100", HDAA_QUIRK_IVREF100 },
67 { "ovref50", HDAA_QUIRK_OVREF50 },
68 { "ovref80", HDAA_QUIRK_OVREF80 },
69 { "ovref100", HDAA_QUIRK_OVREF100 },
70 { "ivref", HDAA_QUIRK_IVREF },
71 { "ovref", HDAA_QUIRK_OVREF },
72 { "vref", HDAA_QUIRK_VREF },
74 #define HDAA_QUIRKS_TAB_LEN \
75 (sizeof(hdaa_quirks_tab) / sizeof(hdaa_quirks_tab[0]))
77 #define HDA_PARSE_MAXDEPTH 10
79 MALLOC_DEFINE(M_HDAA, "hdaa", "HDA Audio");
81 const char *HDA_COLORS[16] = {"Unknown", "Black", "Grey", "Blue", "Green", "Red",
82 "Orange", "Yellow", "Purple", "Pink", "Res.A", "Res.B", "Res.C", "Res.D",
85 const char *HDA_DEVS[16] = {"Line-out", "Speaker", "Headphones", "CD",
86 "SPDIF-out", "Digital-out", "Modem-line", "Modem-handset", "Line-in",
87 "AUX", "Mic", "Telephony", "SPDIF-in", "Digital-in", "Res.E", "Other"};
89 const char *HDA_CONNS[4] = {"Jack", "None", "Fixed", "Both"};
91 const char *HDA_CONNECTORS[16] = {
92 "Unknown", "1/8", "1/4", "ATAPI", "RCA", "Optical", "Digital", "Analog",
93 "DIN", "XLR", "RJ-11", "Combo", "0xc", "0xd", "0xe", "Other" };
95 const char *HDA_LOCS[64] = {
96 "0x00", "Rear", "Front", "Left", "Right", "Top", "Bottom", "Rear-panel",
97 "Drive-bay", "0x09", "0x0a", "0x0b", "0x0c", "0x0d", "0x0e", "0x0f",
98 "Internal", "0x11", "0x12", "0x13", "0x14", "0x15", "0x16", "Riser",
99 "0x18", "Onboard", "0x1a", "0x1b", "0x1c", "0x1d", "0x1e", "0x1f",
100 "External", "Ext-Rear", "Ext-Front", "Ext-Left", "Ext-Right", "Ext-Top", "Ext-Bottom", "0x07",
101 "0x28", "0x29", "0x2a", "0x2b", "0x2c", "0x2d", "0x2e", "0x2f",
102 "Other", "0x31", "0x32", "0x33", "0x34", "0x35", "Other-Bott", "Lid-In",
103 "Lid-Out", "0x39", "0x3a", "0x3b", "0x3c", "0x3d", "0x3e", "0x3f" };
105 const char *HDA_GPIO_ACTIONS[8] = {
106 "keep", "set", "clear", "disable", "input", "0x05", "0x06", "0x07"};
108 const char *HDA_HDMI_CODING_TYPES[18] = {
109 "undefined", "LPCM", "AC-3", "MPEG1", "MP3", "MPEG2", "AAC-LC", "DTS",
110 "ATRAC", "DSD", "E-AC-3", "DTS-HD", "MLP", "DST", "WMAPro", "HE-AAC",
111 "HE-AACv2", "MPEG-Surround"
115 static uint32_t hdaa_fmt[] = {
116 SND_FORMAT(AFMT_S16_LE, 2, 0),
120 static struct pcmchan_caps hdaa_caps = {48000, 48000, hdaa_fmt, 0};
122 static const struct {
129 { 8000, 1, 0x0000, 0x0000, 0x0500 }, /* (48000 * 1) / 6 */
130 { 9600, 0, 0x0000, 0x0000, 0x0400 }, /* (48000 * 1) / 5 */
131 { 12000, 0, 0x0000, 0x0000, 0x0300 }, /* (48000 * 1) / 4 */
132 { 16000, 1, 0x0000, 0x0000, 0x0200 }, /* (48000 * 1) / 3 */
133 { 18000, 0, 0x0000, 0x1000, 0x0700 }, /* (48000 * 3) / 8 */
134 { 19200, 0, 0x0000, 0x0800, 0x0400 }, /* (48000 * 2) / 5 */
135 { 24000, 0, 0x0000, 0x0000, 0x0100 }, /* (48000 * 1) / 2 */
136 { 28800, 0, 0x0000, 0x1000, 0x0400 }, /* (48000 * 3) / 5 */
137 { 32000, 1, 0x0000, 0x0800, 0x0200 }, /* (48000 * 2) / 3 */
138 { 36000, 0, 0x0000, 0x1000, 0x0300 }, /* (48000 * 3) / 4 */
139 { 38400, 0, 0x0000, 0x1800, 0x0400 }, /* (48000 * 4) / 5 */
140 { 48000, 1, 0x0000, 0x0000, 0x0000 }, /* (48000 * 1) / 1 */
141 { 64000, 0, 0x0000, 0x1800, 0x0200 }, /* (48000 * 4) / 3 */
142 { 72000, 0, 0x0000, 0x1000, 0x0100 }, /* (48000 * 3) / 2 */
143 { 96000, 1, 0x0000, 0x0800, 0x0000 }, /* (48000 * 2) / 1 */
144 { 144000, 0, 0x0000, 0x1000, 0x0000 }, /* (48000 * 3) / 1 */
145 { 192000, 1, 0x0000, 0x1800, 0x0000 }, /* (48000 * 4) / 1 */
146 { 8820, 0, 0x4000, 0x0000, 0x0400 }, /* (44100 * 1) / 5 */
147 { 11025, 1, 0x4000, 0x0000, 0x0300 }, /* (44100 * 1) / 4 */
148 { 12600, 0, 0x4000, 0x0800, 0x0600 }, /* (44100 * 2) / 7 */
149 { 14700, 0, 0x4000, 0x0000, 0x0200 }, /* (44100 * 1) / 3 */
150 { 17640, 0, 0x4000, 0x0800, 0x0400 }, /* (44100 * 2) / 5 */
151 { 18900, 0, 0x4000, 0x1000, 0x0600 }, /* (44100 * 3) / 7 */
152 { 22050, 1, 0x4000, 0x0000, 0x0100 }, /* (44100 * 1) / 2 */
153 { 25200, 0, 0x4000, 0x1800, 0x0600 }, /* (44100 * 4) / 7 */
154 { 26460, 0, 0x4000, 0x1000, 0x0400 }, /* (44100 * 3) / 5 */
155 { 29400, 0, 0x4000, 0x0800, 0x0200 }, /* (44100 * 2) / 3 */
156 { 33075, 0, 0x4000, 0x1000, 0x0300 }, /* (44100 * 3) / 4 */
157 { 35280, 0, 0x4000, 0x1800, 0x0400 }, /* (44100 * 4) / 5 */
158 { 44100, 1, 0x4000, 0x0000, 0x0000 }, /* (44100 * 1) / 1 */
159 { 58800, 0, 0x4000, 0x1800, 0x0200 }, /* (44100 * 4) / 3 */
160 { 66150, 0, 0x4000, 0x1000, 0x0100 }, /* (44100 * 3) / 2 */
161 { 88200, 1, 0x4000, 0x0800, 0x0000 }, /* (44100 * 2) / 1 */
162 { 132300, 0, 0x4000, 0x1000, 0x0000 }, /* (44100 * 3) / 1 */
163 { 176400, 1, 0x4000, 0x1800, 0x0000 }, /* (44100 * 4) / 1 */
165 #define HDA_RATE_TAB_LEN (sizeof(hda_rate_tab) / sizeof(hda_rate_tab[0]))
167 const static char *ossnames[] = SOUND_DEVICE_NAMES;
169 /****************************************************************************
170 * Function prototypes
171 ****************************************************************************/
172 static int hdaa_pcmchannel_setup(struct hdaa_chan *);
174 static void hdaa_widget_connection_select(struct hdaa_widget *, uint8_t);
175 static void hdaa_audio_ctl_amp_set(struct hdaa_audio_ctl *,
177 static struct hdaa_audio_ctl *hdaa_audio_ctl_amp_get(struct hdaa_devinfo *,
178 nid_t, int, int, int);
179 static void hdaa_audio_ctl_amp_set_internal(struct hdaa_devinfo *,
180 nid_t, int, int, int, int, int, int);
182 static void hdaa_dump_pin_config(struct hdaa_widget *w, uint32_t conf);
185 hdaa_audio_ctl_ossmixer_mask2allname(uint32_t mask, char *buf, size_t len)
190 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
191 if (mask & (1 << i)) {
193 strlcat(buf, ", ", len);
194 strlcat(buf, ossnames[i], len);
201 static struct hdaa_audio_ctl *
202 hdaa_audio_ctl_each(struct hdaa_devinfo *devinfo, int *index)
204 if (devinfo == NULL ||
205 index == NULL || devinfo->ctl == NULL ||
206 devinfo->ctlcnt < 1 ||
207 *index < 0 || *index >= devinfo->ctlcnt)
209 return (&devinfo->ctl[(*index)++]);
212 static struct hdaa_audio_ctl *
213 hdaa_audio_ctl_amp_get(struct hdaa_devinfo *devinfo, nid_t nid, int dir,
216 struct hdaa_audio_ctl *ctl;
219 if (devinfo == NULL || devinfo->ctl == NULL)
223 while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) {
224 if (ctl->enable == 0)
226 if (ctl->widget->nid != nid)
228 if (dir && ctl->ndir != dir)
230 if (index >= 0 && ctl->ndir == HDAA_CTL_IN &&
231 ctl->dir == ctl->ndir && ctl->index != index)
234 if (found == cnt || cnt <= 0)
241 static const struct matrix {
242 struct pcmchan_matrix m;
245 { SND_CHN_MATRIX_MAP_1_0, 1 },
246 { SND_CHN_MATRIX_MAP_2_0, 1 },
247 { SND_CHN_MATRIX_MAP_2_1, 0 },
248 { SND_CHN_MATRIX_MAP_3_0, 0 },
249 { SND_CHN_MATRIX_MAP_3_1, 0 },
250 { SND_CHN_MATRIX_MAP_4_0, 1 },
251 { SND_CHN_MATRIX_MAP_4_1, 0 },
252 { SND_CHN_MATRIX_MAP_5_0, 0 },
253 { SND_CHN_MATRIX_MAP_5_1, 1 },
254 { SND_CHN_MATRIX_MAP_6_0, 0 },
255 { SND_CHN_MATRIX_MAP_6_1, 0 },
256 { SND_CHN_MATRIX_MAP_7_0, 0 },
257 { SND_CHN_MATRIX_MAP_7_1, 1 },
260 static const char *channel_names[] = SND_CHN_T_NAMES;
263 * Connected channels change handler.
266 hdaa_channels_handler(struct hdaa_audio_as *as)
268 struct hdaa_pcm_devinfo *pdevinfo = as->pdevinfo;
269 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
270 struct hdaa_chan *ch = &devinfo->chans[as->chans[0]];
271 struct hdaa_widget *w;
273 int i, total, sub, assume, channels;
274 uint16_t cpins, upins, tpins;
278 for (i = 0; i < 16; i++) {
279 if (as->pins[i] <= 0)
281 w = hdaa_widget_get(devinfo, as->pins[i]);
284 if (w->wclass.pin.connected == 1)
286 else if (w->wclass.pin.connected != 0)
288 if (w->eld != NULL && w->eld_len >= 8)
291 tpins = cpins | upins;
292 if (as->hpredir >= 0)
297 total = sub = assume = channels = 0;
299 /* Map CEA speakers to sound(4) channels. */
300 if (eld[7] & 0x01) /* Front Left/Right */
301 channels |= SND_CHN_T_MASK_FL | SND_CHN_T_MASK_FR;
302 if (eld[7] & 0x02) /* Low Frequency Effect */
303 channels |= SND_CHN_T_MASK_LF;
304 if (eld[7] & 0x04) /* Front Center */
305 channels |= SND_CHN_T_MASK_FC;
306 if (eld[7] & 0x08) { /* Rear Left/Right */
307 /* If we have both RLR and RLRC, report RLR as side. */
308 if (eld[7] & 0x40) /* Rear Left/Right Center */
309 channels |= SND_CHN_T_MASK_SL | SND_CHN_T_MASK_SR;
311 channels |= SND_CHN_T_MASK_BL | SND_CHN_T_MASK_BR;
313 if (eld[7] & 0x10) /* Rear center */
314 channels |= SND_CHN_T_MASK_BC;
315 if (eld[7] & 0x20) /* Front Left/Right Center */
316 channels |= SND_CHN_T_MASK_FLC | SND_CHN_T_MASK_FRC;
317 if (eld[7] & 0x40) /* Rear Left/Right Center */
318 channels |= SND_CHN_T_MASK_BL | SND_CHN_T_MASK_BR;
319 } else if (as->pinset != 0 && (tpins & 0xffe0) == 0) {
320 /* Map UAA speakers to sound(4) channels. */
322 channels |= SND_CHN_T_MASK_FL | SND_CHN_T_MASK_FR;
324 channels |= SND_CHN_T_MASK_FC | SND_CHN_T_MASK_LF;
326 channels |= SND_CHN_T_MASK_BL | SND_CHN_T_MASK_BR;
328 channels |= SND_CHN_T_MASK_FLC | SND_CHN_T_MASK_FRC;
329 if (tpins & 0x0010) {
330 /* If there is no back pin, report side as back. */
331 if ((as->pinset & 0x0004) == 0)
332 channels |= SND_CHN_T_MASK_BL | SND_CHN_T_MASK_BR;
334 channels |= SND_CHN_T_MASK_SL | SND_CHN_T_MASK_SR;
336 } else if (as->mixed) {
337 /* Mixed assoc can be only stereo or theoretically mono. */
338 if (ch->channels == 1)
339 channels |= SND_CHN_T_MASK_FC;
341 channels |= SND_CHN_T_MASK_FL | SND_CHN_T_MASK_FR;
343 if (channels) { /* We have some usable channels info. */
345 device_printf(pdevinfo->dev, "%s channel set is: ",
346 as->dir == HDAA_CTL_OUT ? "Playback" : "Recording");
347 for (i = 0; i < SND_CHN_T_MAX; i++)
348 if (channels & (1 << i))
349 printf("%s, ", channel_names[i]);
352 /* Look for maximal fitting matrix. */
353 for (i = 0; i < sizeof(matrixes) / sizeof(struct matrix); i++) {
354 if (as->pinset != 0 && matrixes[i].analog == 0)
356 if ((matrixes[i].m.mask & ~channels) == 0) {
357 total = matrixes[i].m.channels;
358 sub = matrixes[i].m.ext;
364 total = ch->channels;
365 sub = (total == 6 || total == 8) ? 1 : 0;
368 device_printf(pdevinfo->dev,
369 "%s channel matrix is: %s%d.%d (%s)\n",
370 as->dir == HDAA_CTL_OUT ? "Playback" : "Recording",
371 assume ? "unknown, assuming " : "", total - sub, sub,
372 cpins != 0 ? "connected" :
373 (upins != 0 ? "unknown" : "disconnected"));
378 * Headphones redirection change handler.
381 hdaa_hpredir_handler(struct hdaa_widget *w)
383 struct hdaa_devinfo *devinfo = w->devinfo;
384 struct hdaa_audio_as *as = &devinfo->as[w->bindas];
385 struct hdaa_widget *w1;
386 struct hdaa_audio_ctl *ctl;
388 int j, connected = w->wclass.pin.connected;
391 device_printf((as->pdevinfo && as->pdevinfo->dev) ?
392 as->pdevinfo->dev : devinfo->dev,
393 "Redirect output to: %s\n",
394 connected ? "headphones": "main");
396 /* (Un)Mute headphone pin. */
397 ctl = hdaa_audio_ctl_amp_get(devinfo,
398 w->nid, HDAA_CTL_IN, -1, 1);
399 if (ctl != NULL && ctl->mute) {
400 /* If pin has muter - use it. */
401 val = connected ? 0 : 1;
402 if (val != ctl->forcemute) {
403 ctl->forcemute = val;
404 hdaa_audio_ctl_amp_set(ctl,
405 HDAA_AMP_MUTE_DEFAULT,
406 HDAA_AMP_VOL_DEFAULT, HDAA_AMP_VOL_DEFAULT);
409 /* If there is no muter - disable pin output. */
411 val = w->wclass.pin.ctrl |
412 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
414 val = w->wclass.pin.ctrl &
415 ~HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
416 if (val != w->wclass.pin.ctrl) {
417 w->wclass.pin.ctrl = val;
418 hda_command(devinfo->dev,
419 HDA_CMD_SET_PIN_WIDGET_CTRL(0,
420 w->nid, w->wclass.pin.ctrl));
423 /* (Un)Mute other pins. */
424 for (j = 0; j < 15; j++) {
425 if (as->pins[j] <= 0)
427 ctl = hdaa_audio_ctl_amp_get(devinfo,
428 as->pins[j], HDAA_CTL_IN, -1, 1);
429 if (ctl != NULL && ctl->mute) {
430 /* If pin has muter - use it. */
431 val = connected ? 1 : 0;
432 if (val == ctl->forcemute)
434 ctl->forcemute = val;
435 hdaa_audio_ctl_amp_set(ctl,
436 HDAA_AMP_MUTE_DEFAULT,
437 HDAA_AMP_VOL_DEFAULT, HDAA_AMP_VOL_DEFAULT);
440 /* If there is no muter - disable pin output. */
441 w1 = hdaa_widget_get(devinfo, as->pins[j]);
444 val = w1->wclass.pin.ctrl &
445 ~HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
447 val = w1->wclass.pin.ctrl |
448 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
449 if (val != w1->wclass.pin.ctrl) {
450 w1->wclass.pin.ctrl = val;
451 hda_command(devinfo->dev,
452 HDA_CMD_SET_PIN_WIDGET_CTRL(0,
453 w1->nid, w1->wclass.pin.ctrl));
460 * Recording source change handler.
463 hdaa_autorecsrc_handler(struct hdaa_audio_as *as, struct hdaa_widget *w)
465 struct hdaa_pcm_devinfo *pdevinfo = as->pdevinfo;
466 struct hdaa_devinfo *devinfo;
467 struct hdaa_widget *w1;
468 int i, mask, fullmask, prio, bestprio;
471 if (!as->mixed || pdevinfo == NULL || pdevinfo->mixer == NULL)
473 /* Don't touch anything if we asked not to. */
474 if (pdevinfo->autorecsrc == 0 ||
475 (pdevinfo->autorecsrc == 1 && w != NULL))
477 /* Don't touch anything if "mix" or "speaker" selected. */
478 if (pdevinfo->recsrc & (SOUND_MASK_IMIX | SOUND_MASK_SPEAKER))
480 /* Don't touch anything if several selected. */
481 if (ffs(pdevinfo->recsrc) != fls(pdevinfo->recsrc))
483 devinfo = pdevinfo->devinfo;
486 for (i = 0; i < 16; i++) {
487 if (as->pins[i] <= 0)
489 w1 = hdaa_widget_get(devinfo, as->pins[i]);
490 if (w1 == NULL || w1->enable == 0)
492 if (w1->wclass.pin.connected == 0)
494 prio = (w1->wclass.pin.connected == 1) ? 2 : 1;
497 if (prio > bestprio) {
501 mask |= (1 << w1->ossdev);
502 fullmask |= (1 << w1->ossdev);
506 /* Prefer newly connected input. */
507 if (w != NULL && (mask & (1 << w->ossdev)))
508 mask = (1 << w->ossdev);
509 /* Prefer previously selected input */
510 if (mask & pdevinfo->recsrc)
511 mask &= pdevinfo->recsrc;
513 if (mask & SOUND_MASK_MIC)
514 mask = SOUND_MASK_MIC;
515 /* Prefer monitor (2nd mic). */
516 if (mask & SOUND_MASK_MONITOR)
517 mask = SOUND_MASK_MONITOR;
518 /* Just take first one. */
519 mask = (1 << (ffs(mask) - 1));
521 hdaa_audio_ctl_ossmixer_mask2allname(mask, buf, sizeof(buf));
522 device_printf(pdevinfo->dev,
523 "Automatically set rec source to: %s\n", buf);
525 hdaa_unlock(devinfo);
526 mix_setrecsrc(pdevinfo->mixer, mask);
531 * Jack presence detection event handler.
534 hdaa_presence_handler(struct hdaa_widget *w)
536 struct hdaa_devinfo *devinfo = w->devinfo;
537 struct hdaa_audio_as *as;
541 if (w->enable == 0 || w->type !=
542 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
545 if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(w->wclass.pin.cap) == 0 ||
546 (HDA_CONFIG_DEFAULTCONF_MISC(w->wclass.pin.config) & 1) != 0)
549 res = hda_command(devinfo->dev, HDA_CMD_GET_PIN_SENSE(0, w->nid));
550 connected = (res & HDA_CMD_GET_PIN_SENSE_PRESENCE_DETECT) != 0;
551 if (devinfo->quirks & HDAA_QUIRK_SENSEINV)
552 connected = !connected;
553 old = w->wclass.pin.connected;
554 if (connected == old)
556 w->wclass.pin.connected = connected;
558 if (connected || old != 2) {
559 device_printf(devinfo->dev,
560 "Pin sense: nid=%d sense=0x%08x (%sconnected)\n",
561 w->nid, res, !connected ? "dis" : "");
565 as = &devinfo->as[w->bindas];
566 if (as->hpredir >= 0 && as->pins[15] == w->nid)
567 hdaa_hpredir_handler(w);
568 if (as->dir == HDAA_CTL_IN && old != 2)
569 hdaa_autorecsrc_handler(as, w);
571 hdaa_channels_handler(as);
575 * Callback for poll based presence detection.
578 hdaa_jack_poll_callback(void *arg)
580 struct hdaa_devinfo *devinfo = arg;
581 struct hdaa_widget *w;
585 if (devinfo->poll_ival == 0) {
586 hdaa_unlock(devinfo);
589 for (i = 0; i < devinfo->ascnt; i++) {
590 if (devinfo->as[i].hpredir < 0)
592 w = hdaa_widget_get(devinfo, devinfo->as[i].pins[15]);
593 if (w == NULL || w->enable == 0 || w->type !=
594 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
596 hdaa_presence_handler(w);
598 callout_reset(&devinfo->poll_jack, devinfo->poll_ival,
599 hdaa_jack_poll_callback, devinfo);
600 hdaa_unlock(devinfo);
604 hdaa_eld_dump(struct hdaa_widget *w)
606 struct hdaa_devinfo *devinfo = w->devinfo;
607 device_t dev = devinfo->dev;
609 int len, mnl, i, sadc, fmt;
611 if (w->eld == NULL || w->eld_len < 4)
614 "ELD nid=%d: ELD_Ver=%u Baseline_ELD_Len=%u\n",
615 w->nid, w->eld[0] >> 3, w->eld[2]);
616 if ((w->eld[0] >> 3) != 0x02)
618 len = min(w->eld_len, (u_int)w->eld[2] * 4);
619 mnl = w->eld[4] & 0x1f;
621 "ELD nid=%d: CEA_EDID_Ver=%u MNL=%u\n",
622 w->nid, w->eld[4] >> 5, mnl);
623 sadc = w->eld[5] >> 4;
625 "ELD nid=%d: SAD_Count=%u Conn_Type=%u S_AI=%u HDCP=%u\n",
626 w->nid, sadc, (w->eld[5] >> 2) & 0x3,
627 (w->eld[5] >> 1) & 0x1, w->eld[5] & 0x1);
629 "ELD nid=%d: Aud_Synch_Delay=%ums\n",
630 w->nid, w->eld[6] * 2);
632 "ELD nid=%d: Channels=0x%b\n",
634 "\020\07RLRC\06FLRC\05RC\04RLR\03FC\02LFE\01FLR");
636 "ELD nid=%d: Port_ID=0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
637 w->nid, w->eld[8], w->eld[9], w->eld[10], w->eld[11],
638 w->eld[12], w->eld[13], w->eld[14], w->eld[15]);
640 "ELD nid=%d: Manufacturer_Name=0x%02x%02x\n",
641 w->nid, w->eld[16], w->eld[17]);
643 "ELD nid=%d: Product_Code=0x%02x%02x\n",
644 w->nid, w->eld[18], w->eld[19]);
646 "ELD nid=%d: Monitor_Name_String='%.*s'\n",
647 w->nid, mnl, &w->eld[20]);
648 for (i = 0; i < sadc; i++) {
649 sad = &w->eld[20 + mnl + i * 3];
650 fmt = (sad[0] >> 3) & 0x0f;
651 if (fmt == HDA_HDMI_CODING_TYPE_REF_CTX) {
652 fmt = (sad[2] >> 3) & 0x1f;
653 if (fmt < 1 || fmt > 3)
659 "ELD nid=%d: %s %dch freqs=0x%b",
660 w->nid, HDA_HDMI_CODING_TYPES[fmt], (sad[0] & 0x07) + 1,
661 sad[1], "\020\007192\006176\00596\00488\00348\00244\00132");
663 case HDA_HDMI_CODING_TYPE_LPCM:
664 printf(" sizes=0x%b",
665 sad[2] & 0x07, "\020\00324\00220\00116");
667 case HDA_HDMI_CODING_TYPE_AC3:
668 case HDA_HDMI_CODING_TYPE_MPEG1:
669 case HDA_HDMI_CODING_TYPE_MP3:
670 case HDA_HDMI_CODING_TYPE_MPEG2:
671 case HDA_HDMI_CODING_TYPE_AACLC:
672 case HDA_HDMI_CODING_TYPE_DTS:
673 case HDA_HDMI_CODING_TYPE_ATRAC:
674 printf(" max_bitrate=%d", sad[2] * 8000);
676 case HDA_HDMI_CODING_TYPE_WMAPRO:
677 printf(" profile=%d", sad[2] & 0x07);
685 hdaa_eld_handler(struct hdaa_widget *w)
687 struct hdaa_devinfo *devinfo = w->devinfo;
691 if (w->enable == 0 || w->type !=
692 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
695 if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(w->wclass.pin.cap) == 0 ||
696 (HDA_CONFIG_DEFAULTCONF_MISC(w->wclass.pin.config) & 1) != 0)
699 res = hda_command(devinfo->dev, HDA_CMD_GET_PIN_SENSE(0, w->nid));
700 if ((w->eld != 0) == ((res & HDA_CMD_GET_PIN_SENSE_ELD_VALID) != 0))
702 if (w->eld != NULL) {
704 free(w->eld, M_HDAA);
708 device_printf(devinfo->dev,
709 "Pin sense: nid=%d sense=0x%08x "
710 "(%sconnected, ELD %svalid)\n",
712 (res & HDA_CMD_GET_PIN_SENSE_PRESENCE_DETECT) ? "" : "dis",
713 (res & HDA_CMD_GET_PIN_SENSE_ELD_VALID) ? "" : "in");
715 if ((res & HDA_CMD_GET_PIN_SENSE_ELD_VALID) == 0)
718 res = hda_command(devinfo->dev,
719 HDA_CMD_GET_HDMI_DIP_SIZE(0, w->nid, 0x08));
720 if (res == HDA_INVALID)
722 w->eld_len = res & 0xff;
724 w->eld = malloc(w->eld_len, M_HDAA, M_ZERO | M_NOWAIT);
725 if (w->eld == NULL) {
730 for (i = 0; i < w->eld_len; i++) {
731 res = hda_command(devinfo->dev,
732 HDA_CMD_GET_HDMI_ELDD(0, w->nid, i));
733 if (res & 0x80000000)
734 w->eld[i] = res & 0xff;
739 hdaa_channels_handler(&devinfo->as[w->bindas]);
743 * Pin sense initializer.
746 hdaa_sense_init(struct hdaa_devinfo *devinfo)
748 struct hdaa_audio_as *as;
749 struct hdaa_widget *w;
752 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
753 w = hdaa_widget_get(devinfo, i);
754 if (w == NULL || w->enable == 0 || w->type !=
755 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
757 if (HDA_PARAM_AUDIO_WIDGET_CAP_UNSOL_CAP(w->param.widget_cap)) {
759 w->unsol = HDAC_UNSOL_ALLOC(
760 device_get_parent(devinfo->dev),
761 devinfo->dev, w->nid);
762 hda_command(devinfo->dev,
763 HDA_CMD_SET_UNSOLICITED_RESPONSE(0, w->nid,
764 HDA_CMD_SET_UNSOLICITED_RESPONSE_ENABLE | w->unsol));
766 as = &devinfo->as[w->bindas];
767 if (as->hpredir >= 0 && as->pins[15] == w->nid) {
768 if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(w->wclass.pin.cap) == 0 ||
769 (HDA_CONFIG_DEFAULTCONF_MISC(w->wclass.pin.config) & 1) != 0) {
770 device_printf(devinfo->dev,
771 "No presence detection support at nid %d\n",
777 device_printf(devinfo->dev,
778 "Headphones redirection for "
779 "association %d nid=%d using %s.\n",
781 (w->unsol < 0) ? "polling" :
782 "unsolicited responses");
786 hdaa_presence_handler(w);
787 if (!HDA_PARAM_PIN_CAP_DP(w->wclass.pin.cap) &&
788 !HDA_PARAM_PIN_CAP_HDMI(w->wclass.pin.cap))
793 callout_reset(&devinfo->poll_jack, 1,
794 hdaa_jack_poll_callback, devinfo);
799 hdaa_sense_deinit(struct hdaa_devinfo *devinfo)
801 struct hdaa_widget *w;
804 callout_stop(&devinfo->poll_jack);
805 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
806 w = hdaa_widget_get(devinfo, i);
807 if (w == NULL || w->enable == 0 || w->type !=
808 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
812 hda_command(devinfo->dev,
813 HDA_CMD_SET_UNSOLICITED_RESPONSE(0, w->nid, 0));
815 device_get_parent(devinfo->dev), devinfo->dev,
822 hdaa_widget_pin_patch(uint32_t config, const char *str)
825 char *key, *value, *rest, *bad;
828 strlcpy(buf, str, sizeof(buf));
830 while ((key = strsep(&rest, "=")) != NULL) {
831 value = strsep(&rest, " \t");
834 ival = strtol(value, &bad, 10);
835 if (strcmp(key, "seq") == 0) {
836 config &= ~HDA_CONFIG_DEFAULTCONF_SEQUENCE_MASK;
837 config |= ((ival << HDA_CONFIG_DEFAULTCONF_SEQUENCE_SHIFT) &
838 HDA_CONFIG_DEFAULTCONF_SEQUENCE_MASK);
839 } else if (strcmp(key, "as") == 0) {
840 config &= ~HDA_CONFIG_DEFAULTCONF_ASSOCIATION_MASK;
841 config |= ((ival << HDA_CONFIG_DEFAULTCONF_ASSOCIATION_SHIFT) &
842 HDA_CONFIG_DEFAULTCONF_ASSOCIATION_MASK);
843 } else if (strcmp(key, "misc") == 0) {
844 config &= ~HDA_CONFIG_DEFAULTCONF_MISC_MASK;
845 config |= ((ival << HDA_CONFIG_DEFAULTCONF_MISC_SHIFT) &
846 HDA_CONFIG_DEFAULTCONF_MISC_MASK);
847 } else if (strcmp(key, "color") == 0) {
848 config &= ~HDA_CONFIG_DEFAULTCONF_COLOR_MASK;
850 config |= ((ival << HDA_CONFIG_DEFAULTCONF_COLOR_SHIFT) &
851 HDA_CONFIG_DEFAULTCONF_COLOR_MASK);
853 for (i = 0; i < 16; i++) {
854 if (strcasecmp(HDA_COLORS[i], value) == 0) {
855 config |= (i << HDA_CONFIG_DEFAULTCONF_COLOR_SHIFT);
859 } else if (strcmp(key, "ctype") == 0) {
860 config &= ~HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_MASK;
862 config |= ((ival << HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_SHIFT) &
863 HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_MASK);
865 for (i = 0; i < 16; i++) {
866 if (strcasecmp(HDA_CONNECTORS[i], value) == 0) {
867 config |= (i << HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_SHIFT);
871 } else if (strcmp(key, "device") == 0) {
872 config &= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
874 config |= ((ival << HDA_CONFIG_DEFAULTCONF_DEVICE_SHIFT) &
875 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK);
878 for (i = 0; i < 16; i++) {
879 if (strcasecmp(HDA_DEVS[i], value) == 0) {
880 config |= (i << HDA_CONFIG_DEFAULTCONF_DEVICE_SHIFT);
884 } else if (strcmp(key, "loc") == 0) {
885 config &= ~HDA_CONFIG_DEFAULTCONF_LOCATION_MASK;
887 config |= ((ival << HDA_CONFIG_DEFAULTCONF_LOCATION_SHIFT) &
888 HDA_CONFIG_DEFAULTCONF_LOCATION_MASK);
891 for (i = 0; i < 64; i++) {
892 if (strcasecmp(HDA_LOCS[i], value) == 0) {
893 config |= (i << HDA_CONFIG_DEFAULTCONF_LOCATION_SHIFT);
897 } else if (strcmp(key, "conn") == 0) {
898 config &= ~HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK;
900 config |= ((ival << HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_SHIFT) &
901 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK);
904 for (i = 0; i < 4; i++) {
905 if (strcasecmp(HDA_CONNS[i], value) == 0) {
906 config |= (i << HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_SHIFT);
916 hdaa_gpio_patch(uint32_t gpio, const char *str)
919 char *key, *value, *rest;
922 strlcpy(buf, str, sizeof(buf));
924 while ((key = strsep(&rest, "=")) != NULL) {
925 value = strsep(&rest, " \t");
928 ikey = strtol(key, NULL, 10);
929 if (ikey < 0 || ikey > 7)
931 for (i = 0; i < 7; i++) {
932 if (strcasecmp(HDA_GPIO_ACTIONS[i], value) == 0) {
933 gpio &= ~HDAA_GPIO_MASK(ikey);
934 gpio |= i << HDAA_GPIO_SHIFT(ikey);
943 hdaa_local_patch_pin(struct hdaa_widget *w)
945 device_t dev = w->devinfo->dev;
946 const char *res = NULL;
947 uint32_t config, orig;
950 config = orig = w->wclass.pin.config;
951 snprintf(buf, sizeof(buf), "cad%u.nid%u.config",
952 hda_get_codec_id(dev), w->nid);
953 if (resource_string_value(device_get_name(
954 device_get_parent(device_get_parent(dev))),
955 device_get_unit(device_get_parent(device_get_parent(dev))),
957 if (strncmp(res, "0x", 2) == 0) {
958 config = strtol(res + 2, NULL, 16);
960 config = hdaa_widget_pin_patch(config, res);
963 snprintf(buf, sizeof(buf), "nid%u.config", w->nid);
964 if (resource_string_value(device_get_name(dev), device_get_unit(dev),
966 if (strncmp(res, "0x", 2) == 0) {
967 config = strtol(res + 2, NULL, 16);
969 config = hdaa_widget_pin_patch(config, res);
974 device_printf(w->devinfo->dev,
975 "Patching pin config nid=%u 0x%08x -> 0x%08x\n",
976 w->nid, orig, config);
978 w->wclass.pin.newconf = w->wclass.pin.config = config;
982 hdaa_dump_audio_formats_sb(struct sbuf *sb, uint32_t fcap, uint32_t pcmcap)
988 sbuf_printf(sb, " Stream cap: 0x%08x", cap);
989 if (HDA_PARAM_SUPP_STREAM_FORMATS_AC3(cap))
990 sbuf_printf(sb, " AC3");
991 if (HDA_PARAM_SUPP_STREAM_FORMATS_FLOAT32(cap))
992 sbuf_printf(sb, " FLOAT32");
993 if (HDA_PARAM_SUPP_STREAM_FORMATS_PCM(cap))
994 sbuf_printf(sb, " PCM");
995 sbuf_printf(sb, "\n");
999 sbuf_printf(sb, " PCM cap: 0x%08x", cap);
1000 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8BIT(cap))
1001 sbuf_printf(sb, " 8");
1002 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16BIT(cap))
1003 sbuf_printf(sb, " 16");
1004 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(cap))
1005 sbuf_printf(sb, " 20");
1006 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(cap))
1007 sbuf_printf(sb, " 24");
1008 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(cap))
1009 sbuf_printf(sb, " 32");
1010 sbuf_printf(sb, " bits,");
1011 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8KHZ(cap))
1012 sbuf_printf(sb, " 8");
1013 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_11KHZ(cap))
1014 sbuf_printf(sb, " 11");
1015 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16KHZ(cap))
1016 sbuf_printf(sb, " 16");
1017 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_22KHZ(cap))
1018 sbuf_printf(sb, " 22");
1019 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32KHZ(cap))
1020 sbuf_printf(sb, " 32");
1021 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_44KHZ(cap))
1022 sbuf_printf(sb, " 44");
1023 sbuf_printf(sb, " 48");
1024 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_88KHZ(cap))
1025 sbuf_printf(sb, " 88");
1026 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_96KHZ(cap))
1027 sbuf_printf(sb, " 96");
1028 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_176KHZ(cap))
1029 sbuf_printf(sb, " 176");
1030 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_192KHZ(cap))
1031 sbuf_printf(sb, " 192");
1032 sbuf_printf(sb, " KHz\n");
1037 hdaa_dump_pin_sb(struct sbuf *sb, struct hdaa_widget *w)
1039 uint32_t pincap, conf;
1041 pincap = w->wclass.pin.cap;
1043 sbuf_printf(sb, " Pin cap: 0x%08x", pincap);
1044 if (HDA_PARAM_PIN_CAP_IMP_SENSE_CAP(pincap))
1045 sbuf_printf(sb, " ISC");
1046 if (HDA_PARAM_PIN_CAP_TRIGGER_REQD(pincap))
1047 sbuf_printf(sb, " TRQD");
1048 if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(pincap))
1049 sbuf_printf(sb, " PDC");
1050 if (HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap))
1051 sbuf_printf(sb, " HP");
1052 if (HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap))
1053 sbuf_printf(sb, " OUT");
1054 if (HDA_PARAM_PIN_CAP_INPUT_CAP(pincap))
1055 sbuf_printf(sb, " IN");
1056 if (HDA_PARAM_PIN_CAP_BALANCED_IO_PINS(pincap))
1057 sbuf_printf(sb, " BAL");
1058 if (HDA_PARAM_PIN_CAP_HDMI(pincap))
1059 sbuf_printf(sb, " HDMI");
1060 if (HDA_PARAM_PIN_CAP_VREF_CTRL(pincap)) {
1061 sbuf_printf(sb, " VREF[");
1062 if (HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap))
1063 sbuf_printf(sb, " 50");
1064 if (HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap))
1065 sbuf_printf(sb, " 80");
1066 if (HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap))
1067 sbuf_printf(sb, " 100");
1068 if (HDA_PARAM_PIN_CAP_VREF_CTRL_GROUND(pincap))
1069 sbuf_printf(sb, " GROUND");
1070 if (HDA_PARAM_PIN_CAP_VREF_CTRL_HIZ(pincap))
1071 sbuf_printf(sb, " HIZ");
1072 sbuf_printf(sb, " ]");
1074 if (HDA_PARAM_PIN_CAP_EAPD_CAP(pincap))
1075 sbuf_printf(sb, " EAPD");
1076 if (HDA_PARAM_PIN_CAP_DP(pincap))
1077 sbuf_printf(sb, " DP");
1078 if (HDA_PARAM_PIN_CAP_HBR(pincap))
1079 sbuf_printf(sb, " HBR");
1080 sbuf_printf(sb, "\n");
1081 conf = w->wclass.pin.config;
1082 sbuf_printf(sb, " Pin config: 0x%08x", conf);
1083 sbuf_printf(sb, " as=%d seq=%d "
1084 "device=%s conn=%s ctype=%s loc=%s color=%s misc=%d\n",
1085 HDA_CONFIG_DEFAULTCONF_ASSOCIATION(conf),
1086 HDA_CONFIG_DEFAULTCONF_SEQUENCE(conf),
1087 HDA_DEVS[HDA_CONFIG_DEFAULTCONF_DEVICE(conf)],
1088 HDA_CONNS[HDA_CONFIG_DEFAULTCONF_CONNECTIVITY(conf)],
1089 HDA_CONNECTORS[HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE(conf)],
1090 HDA_LOCS[HDA_CONFIG_DEFAULTCONF_LOCATION(conf)],
1091 HDA_COLORS[HDA_CONFIG_DEFAULTCONF_COLOR(conf)],
1092 HDA_CONFIG_DEFAULTCONF_MISC(conf));
1093 sbuf_printf(sb, " Pin control: 0x%08x", w->wclass.pin.ctrl);
1094 if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE)
1095 sbuf_printf(sb, " HP");
1096 if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE)
1097 sbuf_printf(sb, " IN");
1098 if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE)
1099 sbuf_printf(sb, " OUT");
1100 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) {
1101 if ((w->wclass.pin.ctrl &
1102 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK) == 0x03)
1103 sbuf_printf(sb, " HBR");
1104 else if ((w->wclass.pin.ctrl &
1105 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK) != 0)
1106 sbuf_printf(sb, " EPTs");
1108 if ((w->wclass.pin.ctrl &
1109 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK) != 0)
1110 sbuf_printf(sb, " VREFs");
1112 sbuf_printf(sb, "\n");
1116 hdaa_dump_amp_sb(struct sbuf *sb, uint32_t cap, char *banner)
1118 int offset, size, step;
1120 offset = HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(cap);
1121 size = HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(cap);
1122 step = HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(cap);
1123 sbuf_printf(sb, " %s amp: 0x%08x "
1124 "mute=%d step=%d size=%d offset=%d (%+d/%+ddB)\n",
1126 HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(cap),
1128 ((0 - offset) * (size + 1)) / 4,
1129 ((step - offset) * (size + 1)) / 4);
1134 hdaa_sysctl_caps(SYSCTL_HANDLER_ARGS)
1136 struct hdaa_devinfo *devinfo;
1137 struct hdaa_widget *w, *cw;
1142 w = (struct hdaa_widget *)oidp->oid_arg1;
1143 devinfo = w->devinfo;
1144 sbuf_new_for_sysctl(&sb, NULL, 256, req);
1146 sbuf_printf(&sb, "%s%s\n", w->name,
1147 (w->enable == 0) ? " [DISABLED]" : "");
1148 sbuf_printf(&sb, " Widget cap: 0x%08x",
1149 w->param.widget_cap);
1150 if (w->param.widget_cap & 0x0ee1) {
1151 if (HDA_PARAM_AUDIO_WIDGET_CAP_LR_SWAP(w->param.widget_cap))
1152 sbuf_printf(&sb, " LRSWAP");
1153 if (HDA_PARAM_AUDIO_WIDGET_CAP_POWER_CTRL(w->param.widget_cap))
1154 sbuf_printf(&sb, " PWR");
1155 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap))
1156 sbuf_printf(&sb, " DIGITAL");
1157 if (HDA_PARAM_AUDIO_WIDGET_CAP_UNSOL_CAP(w->param.widget_cap))
1158 sbuf_printf(&sb, " UNSOL");
1159 if (HDA_PARAM_AUDIO_WIDGET_CAP_PROC_WIDGET(w->param.widget_cap))
1160 sbuf_printf(&sb, " PROC");
1161 if (HDA_PARAM_AUDIO_WIDGET_CAP_STRIPE(w->param.widget_cap))
1162 sbuf_printf(&sb, " STRIPE(x%d)",
1163 1 << (fls(w->wclass.conv.stripecap) - 1));
1164 j = HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap);
1166 sbuf_printf(&sb, " STEREO");
1168 sbuf_printf(&sb, " %dCH", j + 1);
1170 sbuf_printf(&sb, "\n");
1171 if (w->bindas != -1) {
1172 sbuf_printf(&sb, " Association: %d (0x%04x)\n",
1173 w->bindas, w->bindseqmask);
1175 if (w->ossmask != 0 || w->ossdev >= 0) {
1176 sbuf_printf(&sb, " OSS: %s",
1177 hdaa_audio_ctl_ossmixer_mask2allname(w->ossmask, buf, sizeof(buf)));
1179 sbuf_printf(&sb, " (%s)", ossnames[w->ossdev]);
1180 sbuf_printf(&sb, "\n");
1182 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT ||
1183 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
1184 hdaa_dump_audio_formats_sb(&sb,
1185 w->param.supp_stream_formats,
1186 w->param.supp_pcm_size_rate);
1187 } else if (w->type ==
1188 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX || w->waspin)
1189 hdaa_dump_pin_sb(&sb, w);
1190 if (w->param.eapdbtl != HDA_INVALID) {
1191 sbuf_printf(&sb, " EAPD: 0x%08x%s%s%s\n",
1193 (w->param.eapdbtl & HDA_CMD_SET_EAPD_BTL_ENABLE_LR_SWAP) ?
1195 (w->param.eapdbtl & HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD) ?
1197 (w->param.eapdbtl & HDA_CMD_SET_EAPD_BTL_ENABLE_BTL) ?
1200 if (HDA_PARAM_AUDIO_WIDGET_CAP_OUT_AMP(w->param.widget_cap) &&
1201 w->param.outamp_cap != 0)
1202 hdaa_dump_amp_sb(&sb, w->param.outamp_cap, "Output");
1203 if (HDA_PARAM_AUDIO_WIDGET_CAP_IN_AMP(w->param.widget_cap) &&
1204 w->param.inamp_cap != 0)
1205 hdaa_dump_amp_sb(&sb, w->param.inamp_cap, " Input");
1207 sbuf_printf(&sb, " Connections: %d\n", w->nconns);
1208 for (j = 0; j < w->nconns; j++) {
1209 cw = hdaa_widget_get(devinfo, w->conns[j]);
1210 sbuf_printf(&sb, " + %s<- nid=%d [%s]",
1211 (w->connsenable[j] == 0)?"[DISABLED] ":"",
1212 w->conns[j], (cw == NULL) ? "GHOST!" : cw->name);
1214 sbuf_printf(&sb, " [UNKNOWN]");
1215 else if (cw->enable == 0)
1216 sbuf_printf(&sb, " [DISABLED]");
1217 if (w->nconns > 1 && w->selconn == j && w->type !=
1218 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
1219 sbuf_printf(&sb, " (selected)");
1220 sbuf_printf(&sb, "\n");
1222 error = sbuf_finish(&sb);
1228 hdaa_sysctl_config(SYSCTL_HANDLER_ARGS)
1234 conf = *(uint32_t *)oidp->oid_arg1;
1235 snprintf(buf, sizeof(buf), "0x%08x as=%d seq=%d "
1236 "device=%s conn=%s ctype=%s loc=%s color=%s misc=%d",
1238 HDA_CONFIG_DEFAULTCONF_ASSOCIATION(conf),
1239 HDA_CONFIG_DEFAULTCONF_SEQUENCE(conf),
1240 HDA_DEVS[HDA_CONFIG_DEFAULTCONF_DEVICE(conf)],
1241 HDA_CONNS[HDA_CONFIG_DEFAULTCONF_CONNECTIVITY(conf)],
1242 HDA_CONNECTORS[HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE(conf)],
1243 HDA_LOCS[HDA_CONFIG_DEFAULTCONF_LOCATION(conf)],
1244 HDA_COLORS[HDA_CONFIG_DEFAULTCONF_COLOR(conf)],
1245 HDA_CONFIG_DEFAULTCONF_MISC(conf));
1246 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
1247 if (error != 0 || req->newptr == NULL)
1249 if (strncmp(buf, "0x", 2) == 0)
1250 conf = strtol(buf + 2, NULL, 16);
1252 conf = hdaa_widget_pin_patch(conf, buf);
1253 *(uint32_t *)oidp->oid_arg1 = conf;
1258 hdaa_config_fetch(const char *str, uint32_t *on, uint32_t *off)
1260 int i = 0, j, k, len, inv;
1263 while (str[i] != '\0' &&
1264 (str[i] == ',' || isspace(str[i]) != 0))
1269 while (str[j] != '\0' &&
1270 !(str[j] == ',' || isspace(str[j]) != 0))
1273 if (len > 2 && strncmp(str + i, "no", 2) == 0)
1277 for (k = 0; len > inv && k < HDAA_QUIRKS_TAB_LEN; k++) {
1278 if (strncmp(str + i + inv,
1279 hdaa_quirks_tab[k].key, len - inv) != 0)
1281 if (len - inv != strlen(hdaa_quirks_tab[k].key))
1284 *on |= hdaa_quirks_tab[k].value;
1285 *off &= ~hdaa_quirks_tab[k].value;
1287 *off |= hdaa_quirks_tab[k].value;
1288 *on &= ~hdaa_quirks_tab[k].value;
1297 hdaa_sysctl_quirks(SYSCTL_HANDLER_ARGS)
1300 int error, n = 0, i;
1301 uint32_t quirks, quirks_off;
1303 quirks = *(uint32_t *)oidp->oid_arg1;
1305 for (i = 0; i < HDAA_QUIRKS_TAB_LEN; i++) {
1306 if ((quirks & hdaa_quirks_tab[i].value) != 0)
1307 n += snprintf(buf + n, sizeof(buf) - n, "%s%s",
1308 n != 0 ? "," : "", hdaa_quirks_tab[i].key);
1310 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
1311 if (error != 0 || req->newptr == NULL)
1313 if (strncmp(buf, "0x", 2) == 0)
1314 quirks = strtol(buf + 2, NULL, 16);
1317 hdaa_config_fetch(buf, &quirks, &quirks_off);
1319 *(uint32_t *)oidp->oid_arg1 = quirks;
1324 hdaa_local_patch(struct hdaa_devinfo *devinfo)
1326 struct hdaa_widget *w;
1327 const char *res = NULL;
1328 uint32_t quirks_on = 0, quirks_off = 0, x;
1331 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
1332 w = hdaa_widget_get(devinfo, i);
1335 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
1336 hdaa_local_patch_pin(w);
1339 if (resource_string_value(device_get_name(devinfo->dev),
1340 device_get_unit(devinfo->dev), "config", &res) == 0) {
1341 if (res != NULL && strlen(res) > 0)
1342 hdaa_config_fetch(res, &quirks_on, &quirks_off);
1343 devinfo->quirks |= quirks_on;
1344 devinfo->quirks &= ~quirks_off;
1346 if (devinfo->newquirks == -1)
1347 devinfo->newquirks = devinfo->quirks;
1349 devinfo->quirks = devinfo->newquirks;
1351 device_printf(devinfo->dev,
1352 "Config options: 0x%08x\n", devinfo->quirks);
1355 if (resource_string_value(device_get_name(devinfo->dev),
1356 device_get_unit(devinfo->dev), "gpio_config", &res) == 0) {
1357 if (strncmp(res, "0x", 2) == 0) {
1358 devinfo->gpio = strtol(res + 2, NULL, 16);
1360 devinfo->gpio = hdaa_gpio_patch(devinfo->gpio, res);
1363 if (devinfo->newgpio == -1)
1364 devinfo->newgpio = devinfo->gpio;
1366 devinfo->gpio = devinfo->newgpio;
1367 if (devinfo->newgpo == -1)
1368 devinfo->newgpo = devinfo->gpo;
1370 devinfo->gpo = devinfo->newgpo;
1372 device_printf(devinfo->dev, "GPIO config options:");
1373 for (i = 0; i < 7; i++) {
1374 x = (devinfo->gpio & HDAA_GPIO_MASK(i)) >> HDAA_GPIO_SHIFT(i);
1376 printf(" %d=%s", i, HDA_GPIO_ACTIONS[x]);
1383 hdaa_widget_connection_parse(struct hdaa_widget *w)
1386 int i, j, max, ents, entnum;
1388 nid_t cnid, addcnid, prevcnid;
1392 res = hda_command(w->devinfo->dev,
1393 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_CONN_LIST_LENGTH));
1395 ents = HDA_PARAM_CONN_LIST_LENGTH_LIST_LENGTH(res);
1400 entnum = HDA_PARAM_CONN_LIST_LENGTH_LONG_FORM(res) ? 2 : 4;
1401 max = (sizeof(w->conns) / sizeof(w->conns[0])) - 1;
1404 #define CONN_RMASK(e) (1 << ((32 / (e)) - 1))
1405 #define CONN_NMASK(e) (CONN_RMASK(e) - 1)
1406 #define CONN_RESVAL(r, e, n) ((r) >> ((32 / (e)) * (n)))
1407 #define CONN_RANGE(r, e, n) (CONN_RESVAL(r, e, n) & CONN_RMASK(e))
1408 #define CONN_CNID(r, e, n) (CONN_RESVAL(r, e, n) & CONN_NMASK(e))
1410 for (i = 0; i < ents; i += entnum) {
1411 res = hda_command(w->devinfo->dev,
1412 HDA_CMD_GET_CONN_LIST_ENTRY(0, nid, i));
1413 for (j = 0; j < entnum; j++) {
1414 cnid = CONN_CNID(res, entnum, j);
1416 if (w->nconns < ents)
1417 device_printf(w->devinfo->dev,
1418 "WARNING: nid=%d has zero cnid "
1419 "entnum=%d j=%d index=%d "
1420 "entries=%d found=%d res=0x%08x\n",
1422 ents, w->nconns, res);
1426 if (cnid < w->devinfo->startnode ||
1427 cnid >= w->devinfo->endnode) {
1429 device_printf(w->devinfo->dev,
1430 "WARNING: nid=%d has cnid outside "
1431 "of the AFG range j=%d "
1432 "entnum=%d index=%d res=0x%08x\n",
1433 nid, j, entnum, i, res);
1436 if (CONN_RANGE(res, entnum, j) == 0)
1438 else if (prevcnid == 0 || prevcnid >= cnid) {
1439 device_printf(w->devinfo->dev,
1440 "WARNING: Invalid child range "
1441 "nid=%d index=%d j=%d entnum=%d "
1442 "prevcnid=%d cnid=%d res=0x%08x\n",
1443 nid, i, j, entnum, prevcnid,
1447 addcnid = prevcnid + 1;
1448 while (addcnid <= cnid) {
1449 if (w->nconns > max) {
1450 device_printf(w->devinfo->dev,
1451 "Adding %d (nid=%d): "
1452 "Max connection reached! max=%d\n",
1453 addcnid, nid, max + 1);
1456 w->connsenable[w->nconns] = 1;
1457 w->conns[w->nconns++] = addcnid++;
1468 hdaa_widget_parse(struct hdaa_widget *w)
1470 device_t dev = w->devinfo->dev;
1475 w->param.widget_cap = wcap = hda_command(dev,
1476 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_AUDIO_WIDGET_CAP));
1477 w->type = HDA_PARAM_AUDIO_WIDGET_CAP_TYPE(wcap);
1479 hdaa_widget_connection_parse(w);
1481 if (HDA_PARAM_AUDIO_WIDGET_CAP_OUT_AMP(wcap)) {
1482 if (HDA_PARAM_AUDIO_WIDGET_CAP_AMP_OVR(wcap))
1483 w->param.outamp_cap =
1485 HDA_CMD_GET_PARAMETER(0, nid,
1486 HDA_PARAM_OUTPUT_AMP_CAP));
1488 w->param.outamp_cap =
1489 w->devinfo->outamp_cap;
1491 w->param.outamp_cap = 0;
1493 if (HDA_PARAM_AUDIO_WIDGET_CAP_IN_AMP(wcap)) {
1494 if (HDA_PARAM_AUDIO_WIDGET_CAP_AMP_OVR(wcap))
1495 w->param.inamp_cap =
1497 HDA_CMD_GET_PARAMETER(0, nid,
1498 HDA_PARAM_INPUT_AMP_CAP));
1500 w->param.inamp_cap =
1501 w->devinfo->inamp_cap;
1503 w->param.inamp_cap = 0;
1505 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT ||
1506 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
1507 if (HDA_PARAM_AUDIO_WIDGET_CAP_FORMAT_OVR(wcap)) {
1508 cap = hda_command(dev,
1509 HDA_CMD_GET_PARAMETER(0, nid,
1510 HDA_PARAM_SUPP_STREAM_FORMATS));
1511 w->param.supp_stream_formats = (cap != 0) ? cap :
1512 w->devinfo->supp_stream_formats;
1513 cap = hda_command(dev,
1514 HDA_CMD_GET_PARAMETER(0, nid,
1515 HDA_PARAM_SUPP_PCM_SIZE_RATE));
1516 w->param.supp_pcm_size_rate = (cap != 0) ? cap :
1517 w->devinfo->supp_pcm_size_rate;
1519 w->param.supp_stream_formats =
1520 w->devinfo->supp_stream_formats;
1521 w->param.supp_pcm_size_rate =
1522 w->devinfo->supp_pcm_size_rate;
1524 if (HDA_PARAM_AUDIO_WIDGET_CAP_STRIPE(w->param.widget_cap)) {
1525 w->wclass.conv.stripecap = hda_command(dev,
1526 HDA_CMD_GET_STRIPE_CONTROL(0, w->nid)) >> 20;
1528 w->wclass.conv.stripecap = 1;
1530 w->param.supp_stream_formats = 0;
1531 w->param.supp_pcm_size_rate = 0;
1534 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) {
1535 w->wclass.pin.original = w->wclass.pin.newconf =
1536 w->wclass.pin.config = hda_command(dev,
1537 HDA_CMD_GET_CONFIGURATION_DEFAULT(0, w->nid));
1538 w->wclass.pin.cap = hda_command(dev,
1539 HDA_CMD_GET_PARAMETER(0, w->nid, HDA_PARAM_PIN_CAP));
1540 w->wclass.pin.ctrl = hda_command(dev,
1541 HDA_CMD_GET_PIN_WIDGET_CTRL(0, nid));
1542 w->wclass.pin.connected = 2;
1543 if (HDA_PARAM_PIN_CAP_EAPD_CAP(w->wclass.pin.cap)) {
1544 w->param.eapdbtl = hda_command(dev,
1545 HDA_CMD_GET_EAPD_BTL_ENABLE(0, nid));
1546 w->param.eapdbtl &= 0x7;
1547 w->param.eapdbtl |= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
1549 w->param.eapdbtl = HDA_INVALID;
1553 hdaa_unlock(w->devinfo);
1554 snprintf(buf, sizeof(buf), "nid%d", w->nid);
1555 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
1556 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
1557 buf, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
1558 w, sizeof(w), hdaa_sysctl_caps, "A", "Node capabilities");
1559 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) {
1560 snprintf(buf, sizeof(buf), "nid%d_config", w->nid);
1561 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
1562 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
1563 buf, CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE,
1564 &w->wclass.pin.newconf, sizeof(&w->wclass.pin.newconf),
1565 hdaa_sysctl_config, "A", "Current pin configuration");
1566 snprintf(buf, sizeof(buf), "nid%d_original", w->nid);
1567 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
1568 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
1569 buf, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
1570 &w->wclass.pin.original, sizeof(&w->wclass.pin.original),
1571 hdaa_sysctl_config, "A", "Original pin configuration");
1573 hdaa_lock(w->devinfo);
1577 hdaa_widget_postprocess(struct hdaa_widget *w)
1581 w->type = HDA_PARAM_AUDIO_WIDGET_CAP_TYPE(w->param.widget_cap);
1583 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT:
1584 typestr = "audio output";
1586 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT:
1587 typestr = "audio input";
1589 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER:
1590 typestr = "audio mixer";
1592 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR:
1593 typestr = "audio selector";
1595 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
1598 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_POWER_WIDGET:
1599 typestr = "power widget";
1601 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_VOLUME_WIDGET:
1602 typestr = "volume widget";
1604 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET:
1605 typestr = "beep widget";
1607 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_VENDOR_WIDGET:
1608 typestr = "vendor widget";
1611 typestr = "unknown type";
1614 strlcpy(w->name, typestr, sizeof(w->name));
1616 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) {
1621 config = w->wclass.pin.config;
1622 devstr = HDA_DEVS[(config & HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) >>
1623 HDA_CONFIG_DEFAULTCONF_DEVICE_SHIFT];
1624 conn = (config & HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK) >>
1625 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_SHIFT;
1626 color = (config & HDA_CONFIG_DEFAULTCONF_COLOR_MASK) >>
1627 HDA_CONFIG_DEFAULTCONF_COLOR_SHIFT;
1628 strlcat(w->name, ": ", sizeof(w->name));
1629 strlcat(w->name, devstr, sizeof(w->name));
1630 strlcat(w->name, " (", sizeof(w->name));
1631 if (conn == 0 && color != 0 && color != 15) {
1632 strlcat(w->name, HDA_COLORS[color], sizeof(w->name));
1633 strlcat(w->name, " ", sizeof(w->name));
1635 strlcat(w->name, HDA_CONNS[conn], sizeof(w->name));
1636 strlcat(w->name, ")", sizeof(w->name));
1640 struct hdaa_widget *
1641 hdaa_widget_get(struct hdaa_devinfo *devinfo, nid_t nid)
1643 if (devinfo == NULL || devinfo->widget == NULL ||
1644 nid < devinfo->startnode || nid >= devinfo->endnode)
1646 return (&devinfo->widget[nid - devinfo->startnode]);
1650 hdaa_audio_ctl_amp_set_internal(struct hdaa_devinfo *devinfo, nid_t nid,
1651 int index, int lmute, int rmute,
1652 int left, int right, int dir)
1657 device_printf(devinfo->dev,
1658 "Setting amplifier nid=%d index=%d %s mute=%d/%d vol=%d/%d\n",
1659 nid,index,dir ? "in" : "out",lmute,rmute,left,right);
1661 if (left != right || lmute != rmute) {
1662 v = (1 << (15 - dir)) | (1 << 13) | (index << 8) |
1663 (lmute << 7) | left;
1664 hda_command(devinfo->dev,
1665 HDA_CMD_SET_AMP_GAIN_MUTE(0, nid, v));
1666 v = (1 << (15 - dir)) | (1 << 12) | (index << 8) |
1667 (rmute << 7) | right;
1669 v = (1 << (15 - dir)) | (3 << 12) | (index << 8) |
1670 (lmute << 7) | left;
1672 hda_command(devinfo->dev,
1673 HDA_CMD_SET_AMP_GAIN_MUTE(0, nid, v));
1677 hdaa_audio_ctl_amp_set(struct hdaa_audio_ctl *ctl, uint32_t mute,
1678 int left, int right)
1683 nid = ctl->widget->nid;
1685 /* Save new values if valid. */
1686 if (mute != HDAA_AMP_MUTE_DEFAULT)
1688 if (left != HDAA_AMP_VOL_DEFAULT)
1690 if (right != HDAA_AMP_VOL_DEFAULT)
1692 /* Prepare effective values */
1693 if (ctl->forcemute) {
1699 lmute = HDAA_AMP_LEFT_MUTED(ctl->muted);
1700 rmute = HDAA_AMP_RIGHT_MUTED(ctl->muted);
1704 /* Apply effective values */
1705 if (ctl->dir & HDAA_CTL_OUT)
1706 hdaa_audio_ctl_amp_set_internal(ctl->widget->devinfo, nid, ctl->index,
1707 lmute, rmute, left, right, 0);
1708 if (ctl->dir & HDAA_CTL_IN)
1709 hdaa_audio_ctl_amp_set_internal(ctl->widget->devinfo, nid, ctl->index,
1710 lmute, rmute, left, right, 1);
1714 hdaa_widget_connection_select(struct hdaa_widget *w, uint8_t index)
1716 if (w == NULL || w->nconns < 1 || index > (w->nconns - 1))
1719 device_printf(w->devinfo->dev,
1720 "Setting selector nid=%d index=%d\n", w->nid, index);
1722 hda_command(w->devinfo->dev,
1723 HDA_CMD_SET_CONNECTION_SELECT_CONTROL(0, w->nid, index));
1727 /****************************************************************************
1729 ****************************************************************************/
1732 hdaa_channel_init(kobj_t obj, void *data, struct snd_dbuf *b,
1733 struct pcm_channel *c, int dir)
1735 struct hdaa_chan *ch = data;
1736 struct hdaa_pcm_devinfo *pdevinfo = ch->pdevinfo;
1737 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
1740 if (devinfo->quirks & HDAA_QUIRK_FIXEDRATE) {
1741 ch->caps.minspeed = ch->caps.maxspeed = 48000;
1742 ch->pcmrates[0] = 48000;
1743 ch->pcmrates[1] = 0;
1748 ch->blksz = pdevinfo->chan_size / pdevinfo->chan_blkcnt;
1749 ch->blkcnt = pdevinfo->chan_blkcnt;
1750 hdaa_unlock(devinfo);
1752 if (sndbuf_alloc(ch->b, bus_get_dma_tag(devinfo->dev),
1753 hda_get_dma_nocache(devinfo->dev) ? BUS_DMA_NOCACHE : 0,
1754 pdevinfo->chan_size) != 0)
1761 hdaa_channel_setformat(kobj_t obj, void *data, uint32_t format)
1763 struct hdaa_chan *ch = data;
1766 for (i = 0; ch->caps.fmtlist[i] != 0; i++) {
1767 if (format == ch->caps.fmtlist[i]) {
1777 hdaa_channel_setspeed(kobj_t obj, void *data, uint32_t speed)
1779 struct hdaa_chan *ch = data;
1780 uint32_t spd = 0, threshold;
1783 /* First look for equal or multiple frequency. */
1784 for (i = 0; ch->pcmrates[i] != 0; i++) {
1785 spd = ch->pcmrates[i];
1786 if (speed != 0 && spd / speed * speed == spd) {
1791 /* If no match, just find nearest. */
1792 for (i = 0; ch->pcmrates[i] != 0; i++) {
1793 spd = ch->pcmrates[i];
1794 threshold = spd + ((ch->pcmrates[i + 1] != 0) ?
1795 ((ch->pcmrates[i + 1] - spd) >> 1) : 0);
1796 if (speed < threshold)
1804 hdaa_stream_format(struct hdaa_chan *ch)
1810 if (ch->fmt & AFMT_S16_LE)
1811 fmt |= ch->bit16 << 4;
1812 else if (ch->fmt & AFMT_S32_LE)
1813 fmt |= ch->bit32 << 4;
1816 for (i = 0; i < HDA_RATE_TAB_LEN; i++) {
1817 if (hda_rate_tab[i].valid && ch->spd == hda_rate_tab[i].rate) {
1818 fmt |= hda_rate_tab[i].base;
1819 fmt |= hda_rate_tab[i].mul;
1820 fmt |= hda_rate_tab[i].div;
1824 fmt |= (AFMT_CHANNEL(ch->fmt) - 1);
1830 hdaa_allowed_stripes(uint16_t fmt)
1832 static const int bits[8] = { 8, 16, 20, 24, 32, 32, 32, 32 };
1835 size = bits[(fmt >> 4) & 0x03];
1836 size *= (fmt & 0x0f) + 1;
1837 size *= ((fmt >> 11) & 0x07) + 1;
1838 return (0xffffffffU >> (32 - fls(size / 8)));
1842 hdaa_audio_setup(struct hdaa_chan *ch)
1844 struct hdaa_audio_as *as = &ch->devinfo->as[ch->as];
1845 struct hdaa_widget *w, *wp;
1846 int i, j, k, chn, cchn, totalchn, totalextchn, c;
1848 /* Mapping channel pairs to codec pins/converters. */
1849 const static uint16_t convmap[2][5] =
1850 /* 1.0 2.0 4.0 5.1 7.1 */
1851 {{ 0x0010, 0x0001, 0x0201, 0x0231, 0x4231 }, /* no dup. */
1852 { 0x0010, 0x0001, 0x2201, 0x2231, 0x4231 }}; /* side dup. */
1853 /* Mapping formats to HDMI channel allocations. */
1854 const static uint8_t hdmica[2][8] =
1855 /* 1 2 3 4 5 6 7 8 */
1856 {{ 0x02, 0x00, 0x04, 0x08, 0x0a, 0x0e, 0x12, 0x12 }, /* x.0 */
1857 { 0x01, 0x03, 0x01, 0x03, 0x09, 0x0b, 0x0f, 0x13 }}; /* x.1 */
1858 /* Mapping formats to HDMI channels order. */
1859 const static uint32_t hdmich[2][8] =
1860 /* 1 / 5 2 / 6 3 / 7 4 / 8 */
1861 {{ 0xFFFF0F00, 0xFFFFFF10, 0xFFF2FF10, 0xFF32FF10,
1862 0xFF324F10, 0xF5324F10, 0x54326F10, 0x54326F10 }, /* x.0 */
1863 { 0xFFFFF000, 0xFFFF0100, 0xFFFFF210, 0xFFFF2310,
1864 0xFF32F410, 0xFF324510, 0xF6324510, 0x76325410 }}; /* x.1 */
1869 totalchn = AFMT_CHANNEL(ch->fmt);
1870 totalextchn = AFMT_EXTCHANNEL(ch->fmt);
1872 device_printf(ch->pdevinfo->dev,
1873 "PCMDIR_%s: Stream setup fmt=%08x (%d.%d) speed=%d\n",
1874 (ch->dir == PCMDIR_PLAY) ? "PLAY" : "REC",
1875 ch->fmt, totalchn - totalextchn, totalextchn, ch->spd);
1877 fmt = hdaa_stream_format(ch);
1879 /* Set channels to I/O converters mapping for known speaker setups. */
1880 if ((as->pinset == 0x0007 || as->pinset == 0x0013) || /* Standard 5.1 */
1881 (as->pinset == 0x0017)) /* Standard 7.1 */
1882 convmapid = (ch->dir == PCMDIR_PLAY);
1884 dfmt = HDA_CMD_SET_DIGITAL_CONV_FMT1_DIGEN;
1885 if (ch->fmt & AFMT_AC3)
1886 dfmt |= HDA_CMD_SET_DIGITAL_CONV_FMT1_NAUDIO;
1889 for (i = 0; ch->io[i] != -1; i++) {
1890 w = hdaa_widget_get(ch->devinfo, ch->io[i]);
1894 /* If HP redirection is enabled, but failed to use same
1895 DAC, make last DAC to duplicate first one. */
1896 if (as->fakeredir && i == (as->pincnt - 1)) {
1899 /* Map channels to I/O converters, if set. */
1901 chn = (((convmap[convmapid][totalchn / 2]
1902 >> i * 4) & 0xf) - 1) * 2;
1903 if (chn < 0 || chn >= totalchn) {
1906 c = (ch->sid << 4) | chn;
1909 hda_command(ch->devinfo->dev,
1910 HDA_CMD_SET_CONV_FMT(0, ch->io[i], fmt));
1911 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) {
1912 hda_command(ch->devinfo->dev,
1913 HDA_CMD_SET_DIGITAL_CONV_FMT1(0, ch->io[i], dfmt));
1915 hda_command(ch->devinfo->dev,
1916 HDA_CMD_SET_CONV_STREAM_CHAN(0, ch->io[i], c));
1917 if (HDA_PARAM_AUDIO_WIDGET_CAP_STRIPE(w->param.widget_cap)) {
1918 hda_command(ch->devinfo->dev,
1919 HDA_CMD_SET_STRIPE_CONTROL(0, w->nid, ch->stripectl));
1921 cchn = HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap);
1922 if (cchn > 1 && chn < totalchn) {
1923 cchn = min(cchn, totalchn - chn - 1);
1924 hda_command(ch->devinfo->dev,
1925 HDA_CMD_SET_CONV_CHAN_COUNT(0, ch->io[i], cchn));
1928 device_printf(ch->pdevinfo->dev,
1929 "PCMDIR_%s: Stream setup nid=%d: "
1930 "fmt=0x%04x, dfmt=0x%04x, chan=0x%04x, "
1931 "chan_count=0x%02x, stripe=%d\n",
1932 (ch->dir == PCMDIR_PLAY) ? "PLAY" : "REC",
1933 ch->io[i], fmt, dfmt, c, cchn, ch->stripectl);
1935 for (j = 0; j < 16; j++) {
1936 if (as->dacs[ch->asindex][j] != ch->io[i])
1939 wp = hdaa_widget_get(ch->devinfo, nid);
1942 if (!HDA_PARAM_PIN_CAP_DP(wp->wclass.pin.cap) &&
1943 !HDA_PARAM_PIN_CAP_HDMI(wp->wclass.pin.cap))
1946 /* Set channel mapping. */
1947 for (k = 0; k < 8; k++) {
1948 hda_command(ch->devinfo->dev,
1949 HDA_CMD_SET_HDMI_CHAN_SLOT(0, nid,
1950 (((hdmich[totalextchn == 0 ? 0 : 1][totalchn - 1]
1951 >> (k * 4)) & 0xf) << 4) | k));
1955 * Enable High Bit Rate (HBR) Encoded Packet Type
1956 * (EPT), if supported and needed (8ch data).
1958 if (HDA_PARAM_PIN_CAP_HDMI(wp->wclass.pin.cap) &&
1959 HDA_PARAM_PIN_CAP_HBR(wp->wclass.pin.cap)) {
1960 wp->wclass.pin.ctrl &=
1961 ~HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK;
1962 if ((ch->fmt & AFMT_AC3) && (cchn == 7))
1963 wp->wclass.pin.ctrl |= 0x03;
1964 hda_command(ch->devinfo->dev,
1965 HDA_CMD_SET_PIN_WIDGET_CTRL(0, nid,
1966 wp->wclass.pin.ctrl));
1969 /* Stop audio infoframe transmission. */
1970 hda_command(ch->devinfo->dev,
1971 HDA_CMD_SET_HDMI_DIP_INDEX(0, nid, 0x00));
1972 hda_command(ch->devinfo->dev,
1973 HDA_CMD_SET_HDMI_DIP_XMIT(0, nid, 0x00));
1975 /* Clear audio infoframe buffer. */
1976 hda_command(ch->devinfo->dev,
1977 HDA_CMD_SET_HDMI_DIP_INDEX(0, nid, 0x00));
1978 for (k = 0; k < 32; k++)
1979 hda_command(ch->devinfo->dev,
1980 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x00));
1982 /* Write HDMI/DisplayPort audio infoframe. */
1983 hda_command(ch->devinfo->dev,
1984 HDA_CMD_SET_HDMI_DIP_INDEX(0, nid, 0x00));
1985 if (w->eld != NULL && w->eld_len >= 6 &&
1986 ((w->eld[5] >> 2) & 0x3) == 1) { /* DisplayPort */
1987 hda_command(ch->devinfo->dev,
1988 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x84));
1989 hda_command(ch->devinfo->dev,
1990 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x1b));
1991 hda_command(ch->devinfo->dev,
1992 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x44));
1994 hda_command(ch->devinfo->dev,
1995 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x84));
1996 hda_command(ch->devinfo->dev,
1997 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x01));
1998 hda_command(ch->devinfo->dev,
1999 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x0a));
2001 csum -= 0x84 + 0x01 + 0x0a + (totalchn - 1) +
2002 hdmica[totalextchn == 0 ? 0 : 1][totalchn - 1];
2003 hda_command(ch->devinfo->dev,
2004 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, csum));
2006 hda_command(ch->devinfo->dev,
2007 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, totalchn - 1));
2008 hda_command(ch->devinfo->dev,
2009 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x00));
2010 hda_command(ch->devinfo->dev,
2011 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x00));
2012 hda_command(ch->devinfo->dev,
2013 HDA_CMD_SET_HDMI_DIP_DATA(0, nid,
2014 hdmica[totalextchn == 0 ? 0 : 1][totalchn - 1]));
2016 /* Start audio infoframe transmission. */
2017 hda_command(ch->devinfo->dev,
2018 HDA_CMD_SET_HDMI_DIP_INDEX(0, nid, 0x00));
2019 hda_command(ch->devinfo->dev,
2020 HDA_CMD_SET_HDMI_DIP_XMIT(0, nid, 0xc0));
2027 * Greatest Common Divisor.
2030 gcd(unsigned a, unsigned b)
2043 * Least Common Multiple.
2046 lcm(unsigned a, unsigned b)
2049 return ((a * b) / gcd(a, b));
2053 hdaa_channel_setfragments(kobj_t obj, void *data,
2054 uint32_t blksz, uint32_t blkcnt)
2056 struct hdaa_chan *ch = data;
2058 blksz -= blksz % lcm(HDA_DMA_ALIGNMENT, sndbuf_getalign(ch->b));
2060 if (blksz > (sndbuf_getmaxsize(ch->b) / HDA_BDL_MIN))
2061 blksz = sndbuf_getmaxsize(ch->b) / HDA_BDL_MIN;
2062 if (blksz < HDA_BLK_MIN)
2063 blksz = HDA_BLK_MIN;
2064 if (blkcnt > HDA_BDL_MAX)
2065 blkcnt = HDA_BDL_MAX;
2066 if (blkcnt < HDA_BDL_MIN)
2067 blkcnt = HDA_BDL_MIN;
2069 while ((blksz * blkcnt) > sndbuf_getmaxsize(ch->b)) {
2070 if ((blkcnt >> 1) >= HDA_BDL_MIN)
2072 else if ((blksz >> 1) >= HDA_BLK_MIN)
2078 if ((sndbuf_getblksz(ch->b) != blksz ||
2079 sndbuf_getblkcnt(ch->b) != blkcnt) &&
2080 sndbuf_resize(ch->b, blkcnt, blksz) != 0)
2081 device_printf(ch->devinfo->dev, "%s: failed blksz=%u blkcnt=%u\n",
2082 __func__, blksz, blkcnt);
2084 ch->blksz = sndbuf_getblksz(ch->b);
2085 ch->blkcnt = sndbuf_getblkcnt(ch->b);
2091 hdaa_channel_setblocksize(kobj_t obj, void *data, uint32_t blksz)
2093 struct hdaa_chan *ch = data;
2095 hdaa_channel_setfragments(obj, data, blksz, ch->pdevinfo->chan_blkcnt);
2101 hdaa_channel_stop(struct hdaa_chan *ch)
2103 struct hdaa_devinfo *devinfo = ch->devinfo;
2104 struct hdaa_widget *w;
2107 if ((ch->flags & HDAA_CHN_RUNNING) == 0)
2109 ch->flags &= ~HDAA_CHN_RUNNING;
2110 HDAC_STREAM_STOP(device_get_parent(devinfo->dev), devinfo->dev,
2111 ch->dir == PCMDIR_PLAY ? 1 : 0, ch->sid);
2112 for (i = 0; ch->io[i] != -1; i++) {
2113 w = hdaa_widget_get(ch->devinfo, ch->io[i]);
2116 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) {
2117 hda_command(devinfo->dev,
2118 HDA_CMD_SET_DIGITAL_CONV_FMT1(0, ch->io[i], 0));
2120 hda_command(devinfo->dev,
2121 HDA_CMD_SET_CONV_STREAM_CHAN(0, ch->io[i],
2124 HDAC_STREAM_FREE(device_get_parent(devinfo->dev), devinfo->dev,
2125 ch->dir == PCMDIR_PLAY ? 1 : 0, ch->sid);
2129 hdaa_channel_start(struct hdaa_chan *ch)
2131 struct hdaa_devinfo *devinfo = ch->devinfo;
2134 fmt = hdaa_stream_format(ch);
2135 ch->stripectl = fls(ch->stripecap & hdaa_allowed_stripes(fmt)) - 1;
2136 ch->sid = HDAC_STREAM_ALLOC(device_get_parent(devinfo->dev), devinfo->dev,
2137 ch->dir == PCMDIR_PLAY ? 1 : 0, fmt, ch->stripectl, &ch->dmapos);
2140 hdaa_audio_setup(ch);
2141 HDAC_STREAM_RESET(device_get_parent(devinfo->dev), devinfo->dev,
2142 ch->dir == PCMDIR_PLAY ? 1 : 0, ch->sid);
2143 HDAC_STREAM_START(device_get_parent(devinfo->dev), devinfo->dev,
2144 ch->dir == PCMDIR_PLAY ? 1 : 0, ch->sid,
2145 sndbuf_getbufaddr(ch->b), ch->blksz, ch->blkcnt);
2146 ch->flags |= HDAA_CHN_RUNNING;
2151 hdaa_channel_trigger(kobj_t obj, void *data, int go)
2153 struct hdaa_chan *ch = data;
2156 if (!PCMTRIG_COMMON(go))
2159 hdaa_lock(ch->devinfo);
2162 error = hdaa_channel_start(ch);
2166 hdaa_channel_stop(ch);
2171 hdaa_unlock(ch->devinfo);
2177 hdaa_channel_getptr(kobj_t obj, void *data)
2179 struct hdaa_chan *ch = data;
2180 struct hdaa_devinfo *devinfo = ch->devinfo;
2184 if (ch->dmapos != NULL) {
2185 ptr = *(ch->dmapos);
2187 ptr = HDAC_STREAM_GETPTR(
2188 device_get_parent(devinfo->dev), devinfo->dev,
2189 ch->dir == PCMDIR_PLAY ? 1 : 0, ch->sid);
2191 hdaa_unlock(devinfo);
2194 * Round to available space and force 128 bytes aligment.
2196 ptr %= ch->blksz * ch->blkcnt;
2197 ptr &= HDA_BLK_ALIGN;
2202 static struct pcmchan_caps *
2203 hdaa_channel_getcaps(kobj_t obj, void *data)
2205 return (&((struct hdaa_chan *)data)->caps);
2208 static kobj_method_t hdaa_channel_methods[] = {
2209 KOBJMETHOD(channel_init, hdaa_channel_init),
2210 KOBJMETHOD(channel_setformat, hdaa_channel_setformat),
2211 KOBJMETHOD(channel_setspeed, hdaa_channel_setspeed),
2212 KOBJMETHOD(channel_setblocksize, hdaa_channel_setblocksize),
2213 KOBJMETHOD(channel_setfragments, hdaa_channel_setfragments),
2214 KOBJMETHOD(channel_trigger, hdaa_channel_trigger),
2215 KOBJMETHOD(channel_getptr, hdaa_channel_getptr),
2216 KOBJMETHOD(channel_getcaps, hdaa_channel_getcaps),
2219 CHANNEL_DECLARE(hdaa_channel);
2222 hdaa_audio_ctl_ossmixer_init(struct snd_mixer *m)
2224 struct hdaa_pcm_devinfo *pdevinfo = mix_getdevinfo(m);
2225 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
2226 struct hdaa_widget *w, *cw;
2227 uint32_t mask, recmask;
2231 pdevinfo->mixer = m;
2233 /* Make sure that in case of soft volume it won't stay muted. */
2234 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
2235 pdevinfo->left[i] = 100;
2236 pdevinfo->right[i] = 100;
2239 /* Declare volume controls assigned to this association. */
2240 mask = pdevinfo->ossmask;
2241 if (pdevinfo->playas >= 0) {
2242 /* Declate EAPD as ogain control. */
2243 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2244 w = hdaa_widget_get(devinfo, i);
2245 if (w == NULL || w->enable == 0)
2247 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX ||
2248 w->param.eapdbtl == HDA_INVALID ||
2249 w->bindas != pdevinfo->playas)
2251 mask |= SOUND_MASK_OGAIN;
2255 /* Declare soft PCM volume if needed. */
2256 if ((mask & SOUND_MASK_PCM) == 0 ||
2257 (devinfo->quirks & HDAA_QUIRK_SOFTPCMVOL) ||
2258 pdevinfo->minamp[SOUND_MIXER_PCM] ==
2259 pdevinfo->maxamp[SOUND_MIXER_PCM]) {
2260 mask |= SOUND_MASK_PCM;
2261 pcm_setflags(pdevinfo->dev, pcm_getflags(pdevinfo->dev) | SD_F_SOFTPCMVOL);
2263 device_printf(pdevinfo->dev,
2264 "Forcing Soft PCM volume\n");
2268 /* Declare master volume if needed. */
2269 if ((mask & SOUND_MASK_VOLUME) == 0) {
2270 mask |= SOUND_MASK_VOLUME;
2271 mix_setparentchild(m, SOUND_MIXER_VOLUME,
2273 mix_setrealdev(m, SOUND_MIXER_VOLUME,
2276 device_printf(pdevinfo->dev,
2277 "Forcing master volume with PCM\n");
2282 /* Declare record sources available to this association. */
2284 if (pdevinfo->recas >= 0) {
2285 for (i = 0; i < 16; i++) {
2286 if (devinfo->as[pdevinfo->recas].dacs[0][i] < 0)
2288 w = hdaa_widget_get(devinfo,
2289 devinfo->as[pdevinfo->recas].dacs[0][i]);
2290 if (w == NULL || w->enable == 0)
2292 for (j = 0; j < w->nconns; j++) {
2293 if (w->connsenable[j] == 0)
2295 cw = hdaa_widget_get(devinfo, w->conns[j]);
2296 if (cw == NULL || cw->enable == 0)
2298 if (cw->bindas != pdevinfo->recas &&
2301 recmask |= cw->ossmask;
2306 recmask &= (1 << SOUND_MIXER_NRDEVICES) - 1;
2307 mask &= (1 << SOUND_MIXER_NRDEVICES) - 1;
2308 pdevinfo->ossmask = mask;
2310 mix_setrecdevs(m, recmask);
2311 mix_setdevs(m, mask);
2313 hdaa_unlock(devinfo);
2319 * Update amplification per pdevinfo per ossdev, calculate summary coefficient
2320 * and write it to codec, update *left and *right to reflect remaining error.
2323 hdaa_audio_ctl_dev_set(struct hdaa_audio_ctl *ctl, int ossdev,
2324 int mute, int *left, int *right)
2326 int i, zleft, zright, sleft, sright, smute, lval, rval;
2328 ctl->devleft[ossdev] = *left;
2329 ctl->devright[ossdev] = *right;
2330 ctl->devmute[ossdev] = mute;
2331 smute = sleft = sright = zleft = zright = 0;
2332 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
2333 sleft += ctl->devleft[i];
2334 sright += ctl->devright[i];
2335 smute |= ctl->devmute[i];
2338 zleft += ctl->devleft[i];
2339 zright += ctl->devright[i];
2341 lval = QDB2VAL(ctl, sleft);
2342 rval = QDB2VAL(ctl, sright);
2343 hdaa_audio_ctl_amp_set(ctl, smute, lval, rval);
2344 *left -= VAL2QDB(ctl, lval) - VAL2QDB(ctl, QDB2VAL(ctl, zleft));
2345 *right -= VAL2QDB(ctl, rval) - VAL2QDB(ctl, QDB2VAL(ctl, zright));
2349 * Trace signal from source, setting volumes on the way.
2352 hdaa_audio_ctl_source_volume(struct hdaa_pcm_devinfo *pdevinfo,
2353 int ossdev, nid_t nid, int index, int mute, int left, int right, int depth)
2355 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
2356 struct hdaa_widget *w, *wc;
2357 struct hdaa_audio_ctl *ctl;
2358 int i, j, conns = 0;
2360 if (depth > HDA_PARSE_MAXDEPTH)
2363 w = hdaa_widget_get(devinfo, nid);
2364 if (w == NULL || w->enable == 0)
2367 /* Count number of active inputs. */
2369 for (j = 0; j < w->nconns; j++) {
2370 if (!w->connsenable[j])
2376 /* If this is not a first step - use input mixer.
2377 Pins have common input ctl so care must be taken. */
2378 if (depth > 0 && (conns == 1 ||
2379 w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)) {
2380 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, HDAA_CTL_IN,
2383 hdaa_audio_ctl_dev_set(ctl, ossdev, mute, &left, &right);
2386 /* If widget has own ossdev - not traverse it.
2387 It will be traversed on it's own. */
2388 if (w->ossdev >= 0 && depth > 0)
2391 /* We must not traverse pin */
2392 if ((w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT ||
2393 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) &&
2398 * If signals mixed, we can't assign controls farther.
2399 * Ignore this on depth zero. Caller must knows why.
2402 (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER ||
2403 w->selconn != index))
2406 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, HDAA_CTL_OUT, -1, 1);
2408 hdaa_audio_ctl_dev_set(ctl, ossdev, mute, &left, &right);
2410 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2411 wc = hdaa_widget_get(devinfo, i);
2412 if (wc == NULL || wc->enable == 0)
2414 for (j = 0; j < wc->nconns; j++) {
2415 if (wc->connsenable[j] && wc->conns[j] == nid) {
2416 hdaa_audio_ctl_source_volume(pdevinfo, ossdev,
2417 wc->nid, j, mute, left, right, depth + 1);
2425 * Trace signal from destination, setting volumes on the way.
2428 hdaa_audio_ctl_dest_volume(struct hdaa_pcm_devinfo *pdevinfo,
2429 int ossdev, nid_t nid, int index, int mute, int left, int right, int depth)
2431 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
2432 struct hdaa_audio_as *as = devinfo->as;
2433 struct hdaa_widget *w, *wc;
2434 struct hdaa_audio_ctl *ctl;
2435 int i, j, consumers, cleft, cright;
2437 if (depth > HDA_PARSE_MAXDEPTH)
2440 w = hdaa_widget_get(devinfo, nid);
2441 if (w == NULL || w->enable == 0)
2445 /* If this node produce output for several consumers,
2446 we can't touch it. */
2448 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2449 wc = hdaa_widget_get(devinfo, i);
2450 if (wc == NULL || wc->enable == 0)
2452 for (j = 0; j < wc->nconns; j++) {
2453 if (wc->connsenable[j] && wc->conns[j] == nid)
2457 /* The only exception is if real HP redirection is configured
2458 and this is a duplication point.
2459 XXX: Actually exception is not completely correct.
2460 XXX: Duplication point check is not perfect. */
2461 if ((consumers == 2 && (w->bindas < 0 ||
2462 as[w->bindas].hpredir < 0 || as[w->bindas].fakeredir ||
2463 (w->bindseqmask & (1 << 15)) == 0)) ||
2467 /* Else use it's output mixer. */
2468 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid,
2469 HDAA_CTL_OUT, -1, 1);
2471 hdaa_audio_ctl_dev_set(ctl, ossdev, mute, &left, &right);
2474 /* We must not traverse pin */
2475 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
2479 for (i = 0; i < w->nconns; i++) {
2480 if (w->connsenable[i] == 0)
2482 if (index >= 0 && i != index)
2486 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid,
2489 hdaa_audio_ctl_dev_set(ctl, ossdev, mute, &cleft, &cright);
2490 hdaa_audio_ctl_dest_volume(pdevinfo, ossdev, w->conns[i], -1,
2491 mute, cleft, cright, depth + 1);
2496 * Set volumes for the specified pdevinfo and ossdev.
2499 hdaa_audio_ctl_dev_volume(struct hdaa_pcm_devinfo *pdevinfo, unsigned dev)
2501 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
2502 struct hdaa_widget *w, *cw;
2508 if (pdevinfo->left[dev] == 0) {
2509 mute |= HDAA_AMP_MUTE_LEFT;
2512 lvol = ((pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]) *
2513 pdevinfo->left[dev] + 50) / 100 + pdevinfo->minamp[dev];
2514 if (pdevinfo->right[dev] == 0) {
2515 mute |= HDAA_AMP_MUTE_RIGHT;
2518 rvol = ((pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]) *
2519 pdevinfo->right[dev] + 50) / 100 + pdevinfo->minamp[dev];
2520 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2521 w = hdaa_widget_get(devinfo, i);
2522 if (w == NULL || w->enable == 0)
2524 if (w->bindas < 0) {
2525 if (pdevinfo->index != 0)
2528 if (w->bindas != pdevinfo->playas &&
2529 w->bindas != pdevinfo->recas)
2532 if (dev == SOUND_MIXER_RECLEV &&
2533 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
2534 hdaa_audio_ctl_dest_volume(pdevinfo, dev,
2535 w->nid, -1, mute, lvol, rvol, 0);
2538 if (dev == SOUND_MIXER_VOLUME &&
2539 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
2540 devinfo->as[w->bindas].dir == HDAA_CTL_OUT) {
2541 hdaa_audio_ctl_dest_volume(pdevinfo, dev,
2542 w->nid, -1, mute, lvol, rvol, 0);
2545 if (dev == SOUND_MIXER_IGAIN &&
2546 w->pflags & HDAA_ADC_MONITOR) {
2547 for (j = 0; j < w->nconns; j++) {
2548 if (!w->connsenable[j])
2550 cw = hdaa_widget_get(devinfo, w->conns[j]);
2551 if (cw == NULL || cw->enable == 0)
2553 if (cw->bindas == -1)
2555 if (cw->bindas >= 0 &&
2556 devinfo->as[cw->bindas].dir != HDAA_CTL_IN)
2558 hdaa_audio_ctl_dest_volume(pdevinfo, dev,
2559 w->nid, j, mute, lvol, rvol, 0);
2563 if (w->ossdev != dev)
2565 hdaa_audio_ctl_source_volume(pdevinfo, dev,
2566 w->nid, -1, mute, lvol, rvol, 0);
2567 if (dev == SOUND_MIXER_IMIX && (w->pflags & HDAA_IMIX_AS_DST))
2568 hdaa_audio_ctl_dest_volume(pdevinfo, dev,
2569 w->nid, -1, mute, lvol, rvol, 0);
2574 * OSS Mixer set method.
2577 hdaa_audio_ctl_ossmixer_set(struct snd_mixer *m, unsigned dev,
2578 unsigned left, unsigned right)
2580 struct hdaa_pcm_devinfo *pdevinfo = mix_getdevinfo(m);
2581 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
2582 struct hdaa_widget *w;
2587 /* Save new values. */
2588 pdevinfo->left[dev] = left;
2589 pdevinfo->right[dev] = right;
2591 /* 'ogain' is the special case implemented with EAPD. */
2592 if (dev == SOUND_MIXER_OGAIN) {
2595 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2596 w = hdaa_widget_get(devinfo, i);
2597 if (w == NULL || w->enable == 0)
2599 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX ||
2600 w->param.eapdbtl == HDA_INVALID)
2604 if (i >= devinfo->endnode) {
2605 hdaa_unlock(devinfo);
2608 orig = w->param.eapdbtl;
2610 w->param.eapdbtl &= ~HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
2612 w->param.eapdbtl |= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
2613 if (orig != w->param.eapdbtl) {
2616 val = w->param.eapdbtl;
2617 if (devinfo->quirks & HDAA_QUIRK_EAPDINV)
2618 val ^= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
2619 hda_command(devinfo->dev,
2620 HDA_CMD_SET_EAPD_BTL_ENABLE(0, w->nid, val));
2622 hdaa_unlock(devinfo);
2623 return (left | (left << 8));
2626 /* Recalculate all controls related to this OSS device. */
2627 hdaa_audio_ctl_dev_volume(pdevinfo, dev);
2629 hdaa_unlock(devinfo);
2630 return (left | (right << 8));
2634 * Set mixer settings to our own default values:
2635 * +20dB for mics, -10dB for analog vol, mute for igain, 0dB for others.
2638 hdaa_audio_ctl_set_defaults(struct hdaa_pcm_devinfo *pdevinfo)
2642 for (dev = 0; dev < SOUND_MIXER_NRDEVICES; dev++) {
2643 if ((pdevinfo->ossmask & (1 << dev)) == 0)
2646 /* If the value was overriden, leave it as is. */
2647 if (resource_int_value(device_get_name(pdevinfo->dev),
2648 device_get_unit(pdevinfo->dev), ossnames[dev], &vol) == 0)
2652 if (dev == SOUND_MIXER_OGAIN)
2654 else if (dev == SOUND_MIXER_IGAIN)
2656 else if (dev == SOUND_MIXER_MIC ||
2657 dev == SOUND_MIXER_MONITOR)
2658 amp = 20 * 4; /* +20dB */
2659 else if (dev == SOUND_MIXER_VOLUME && !pdevinfo->digital)
2660 amp = -10 * 4; /* -10dB */
2664 (pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]) <= 0) {
2666 } else if (vol < 0) {
2667 vol = ((amp - pdevinfo->minamp[dev]) * 100 +
2668 (pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]) / 2) /
2669 (pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]);
2670 vol = imin(imax(vol, 1), 100);
2672 mix_set(pdevinfo->mixer, dev, vol, vol);
2677 * Recursively commutate specified record source.
2680 hdaa_audio_ctl_recsel_comm(struct hdaa_pcm_devinfo *pdevinfo, uint32_t src, nid_t nid, int depth)
2682 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
2683 struct hdaa_widget *w, *cw;
2684 struct hdaa_audio_ctl *ctl;
2689 if (depth > HDA_PARSE_MAXDEPTH)
2692 w = hdaa_widget_get(devinfo, nid);
2693 if (w == NULL || w->enable == 0)
2696 for (i = 0; i < w->nconns; i++) {
2697 if (w->connsenable[i] == 0)
2699 cw = hdaa_widget_get(devinfo, w->conns[i]);
2700 if (cw == NULL || cw->enable == 0 || cw->bindas == -1)
2702 /* Call recursively to trace signal to it's source if needed. */
2703 if ((src & cw->ossmask) != 0) {
2704 if (cw->ossdev < 0) {
2705 res |= hdaa_audio_ctl_recsel_comm(pdevinfo, src,
2706 w->conns[i], depth + 1);
2711 /* We have two special cases: mixers and others (selectors). */
2712 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) {
2713 ctl = hdaa_audio_ctl_amp_get(devinfo,
2714 w->nid, HDAA_CTL_IN, i, 1);
2717 /* If we have input control on this node mute them
2718 * according to requested sources. */
2719 muted = (src & cw->ossmask) ? 0 : 1;
2720 if (muted != ctl->forcemute) {
2721 ctl->forcemute = muted;
2722 hdaa_audio_ctl_amp_set(ctl,
2723 HDAA_AMP_MUTE_DEFAULT,
2724 HDAA_AMP_VOL_DEFAULT, HDAA_AMP_VOL_DEFAULT);
2727 device_printf(pdevinfo->dev,
2728 "Recsel (%s): nid %d source %d %s\n",
2729 hdaa_audio_ctl_ossmixer_mask2allname(
2730 src, buf, sizeof(buf)),
2731 nid, i, muted?"mute":"unmute");
2736 if ((src & cw->ossmask) == 0)
2738 /* If we found requested source - select it and exit. */
2739 hdaa_widget_connection_select(w, i);
2741 device_printf(pdevinfo->dev,
2742 "Recsel (%s): nid %d source %d select\n",
2743 hdaa_audio_ctl_ossmixer_mask2allname(
2744 src, buf, sizeof(buf)),
2754 hdaa_audio_ctl_ossmixer_setrecsrc(struct snd_mixer *m, uint32_t src)
2756 struct hdaa_pcm_devinfo *pdevinfo = mix_getdevinfo(m);
2757 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
2758 struct hdaa_widget *w;
2759 struct hdaa_audio_as *as;
2760 struct hdaa_audio_ctl *ctl;
2761 struct hdaa_chan *ch;
2763 uint32_t ret = 0xffffffff;
2766 if (pdevinfo->recas < 0) {
2767 hdaa_unlock(devinfo);
2770 as = &devinfo->as[pdevinfo->recas];
2772 /* For non-mixed associations we always recording everything. */
2774 hdaa_unlock(devinfo);
2775 return (mix_getrecdevs(m));
2778 /* Commutate requested recsrc for each ADC. */
2779 for (j = 0; j < as->num_chans; j++) {
2780 ch = &devinfo->chans[as->chans[j]];
2781 for (i = 0; ch->io[i] >= 0; i++) {
2782 w = hdaa_widget_get(devinfo, ch->io[i]);
2783 if (w == NULL || w->enable == 0)
2785 ret &= hdaa_audio_ctl_recsel_comm(pdevinfo, src,
2789 if (ret == 0xffffffff)
2793 * Some controls could be shared. Reset volumes for controls
2794 * related to previously chosen devices, as they may no longer
2795 * affect the signal.
2798 while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) {
2799 if (ctl->enable == 0 ||
2800 !(ctl->ossmask & pdevinfo->recsrc))
2802 if (!((pdevinfo->playas >= 0 &&
2803 ctl->widget->bindas == pdevinfo->playas) ||
2804 (pdevinfo->recas >= 0 &&
2805 ctl->widget->bindas == pdevinfo->recas) ||
2806 (pdevinfo->index == 0 &&
2807 ctl->widget->bindas == -2)))
2809 for (j = 0; j < SOUND_MIXER_NRDEVICES; j++) {
2810 if (pdevinfo->recsrc & (1 << j)) {
2811 ctl->devleft[j] = 0;
2812 ctl->devright[j] = 0;
2813 ctl->devmute[j] = 0;
2819 * Some controls could be shared. Set volumes for controls
2820 * related to devices selected both previously and now.
2822 for (j = 0; j < SOUND_MIXER_NRDEVICES; j++) {
2823 if ((ret | pdevinfo->recsrc) & (1 << j))
2824 hdaa_audio_ctl_dev_volume(pdevinfo, j);
2827 pdevinfo->recsrc = ret;
2828 hdaa_unlock(devinfo);
2832 static kobj_method_t hdaa_audio_ctl_ossmixer_methods[] = {
2833 KOBJMETHOD(mixer_init, hdaa_audio_ctl_ossmixer_init),
2834 KOBJMETHOD(mixer_set, hdaa_audio_ctl_ossmixer_set),
2835 KOBJMETHOD(mixer_setrecsrc, hdaa_audio_ctl_ossmixer_setrecsrc),
2838 MIXER_DECLARE(hdaa_audio_ctl_ossmixer);
2841 hdaa_dump_gpi(struct hdaa_devinfo *devinfo)
2843 device_t dev = devinfo->dev;
2845 uint32_t data, wake, unsol, sticky;
2847 if (HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap) > 0) {
2848 data = hda_command(dev,
2849 HDA_CMD_GET_GPI_DATA(0, devinfo->nid));
2850 wake = hda_command(dev,
2851 HDA_CMD_GET_GPI_WAKE_ENABLE_MASK(0, devinfo->nid));
2852 unsol = hda_command(dev,
2853 HDA_CMD_GET_GPI_UNSOLICITED_ENABLE_MASK(0, devinfo->nid));
2854 sticky = hda_command(dev,
2855 HDA_CMD_GET_GPI_STICKY_MASK(0, devinfo->nid));
2856 for (i = 0; i < HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap); i++) {
2857 device_printf(dev, " GPI%d:%s%s%s state=%d", i,
2858 (sticky & (1 << i)) ? " sticky" : "",
2859 (unsol & (1 << i)) ? " unsol" : "",
2860 (wake & (1 << i)) ? " wake" : "",
2867 hdaa_dump_gpio(struct hdaa_devinfo *devinfo)
2869 device_t dev = devinfo->dev;
2871 uint32_t data, dir, enable, wake, unsol, sticky;
2873 if (HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap) > 0) {
2874 data = hda_command(dev,
2875 HDA_CMD_GET_GPIO_DATA(0, devinfo->nid));
2876 enable = hda_command(dev,
2877 HDA_CMD_GET_GPIO_ENABLE_MASK(0, devinfo->nid));
2878 dir = hda_command(dev,
2879 HDA_CMD_GET_GPIO_DIRECTION(0, devinfo->nid));
2880 wake = hda_command(dev,
2881 HDA_CMD_GET_GPIO_WAKE_ENABLE_MASK(0, devinfo->nid));
2882 unsol = hda_command(dev,
2883 HDA_CMD_GET_GPIO_UNSOLICITED_ENABLE_MASK(0, devinfo->nid));
2884 sticky = hda_command(dev,
2885 HDA_CMD_GET_GPIO_STICKY_MASK(0, devinfo->nid));
2886 for (i = 0; i < HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap); i++) {
2887 device_printf(dev, " GPIO%d: ", i);
2888 if ((enable & (1 << i)) == 0) {
2889 printf("disabled\n");
2892 if ((dir & (1 << i)) == 0) {
2893 printf("input%s%s%s",
2894 (sticky & (1 << i)) ? " sticky" : "",
2895 (unsol & (1 << i)) ? " unsol" : "",
2896 (wake & (1 << i)) ? " wake" : "");
2899 printf(" state=%d\n", (data >> i) & 1);
2905 hdaa_dump_gpo(struct hdaa_devinfo *devinfo)
2907 device_t dev = devinfo->dev;
2911 if (HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap) > 0) {
2912 data = hda_command(dev,
2913 HDA_CMD_GET_GPO_DATA(0, devinfo->nid));
2914 for (i = 0; i < HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap); i++) {
2915 device_printf(dev, " GPO%d: state=%d", i,
2922 hdaa_audio_parse(struct hdaa_devinfo *devinfo)
2924 struct hdaa_widget *w;
2931 res = hda_command(devinfo->dev,
2932 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_GPIO_COUNT));
2933 devinfo->gpio_cap = res;
2936 device_printf(devinfo->dev,
2937 "NumGPIO=%d NumGPO=%d "
2938 "NumGPI=%d GPIWake=%d GPIUnsol=%d\n",
2939 HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap),
2940 HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap),
2941 HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap),
2942 HDA_PARAM_GPIO_COUNT_GPI_WAKE(devinfo->gpio_cap),
2943 HDA_PARAM_GPIO_COUNT_GPI_UNSOL(devinfo->gpio_cap));
2944 hdaa_dump_gpi(devinfo);
2945 hdaa_dump_gpio(devinfo);
2946 hdaa_dump_gpo(devinfo);
2949 res = hda_command(devinfo->dev,
2950 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_SUPP_STREAM_FORMATS));
2951 devinfo->supp_stream_formats = res;
2953 res = hda_command(devinfo->dev,
2954 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_SUPP_PCM_SIZE_RATE));
2955 devinfo->supp_pcm_size_rate = res;
2957 res = hda_command(devinfo->dev,
2958 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_OUTPUT_AMP_CAP));
2959 devinfo->outamp_cap = res;
2961 res = hda_command(devinfo->dev,
2962 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_INPUT_AMP_CAP));
2963 devinfo->inamp_cap = res;
2965 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2966 w = hdaa_widget_get(devinfo, i);
2968 device_printf(devinfo->dev, "Ghost widget! nid=%d!\n", i);
2970 w->devinfo = devinfo;
2977 w->param.eapdbtl = HDA_INVALID;
2978 hdaa_widget_parse(w);
2984 hdaa_audio_postprocess(struct hdaa_devinfo *devinfo)
2986 struct hdaa_widget *w;
2989 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2990 w = hdaa_widget_get(devinfo, i);
2993 hdaa_widget_postprocess(w);
2998 hdaa_audio_ctl_parse(struct hdaa_devinfo *devinfo)
3000 struct hdaa_audio_ctl *ctls;
3001 struct hdaa_widget *w, *cw;
3002 int i, j, cnt, max, ocap, icap;
3003 int mute, offset, step, size;
3005 /* XXX This is redundant */
3007 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3008 w = hdaa_widget_get(devinfo, i);
3009 if (w == NULL || w->enable == 0)
3011 if (w->param.outamp_cap != 0)
3013 if (w->param.inamp_cap != 0) {
3015 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR:
3016 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER:
3017 for (j = 0; j < w->nconns; j++) {
3018 cw = hdaa_widget_get(devinfo,
3020 if (cw == NULL || cw->enable == 0)
3031 devinfo->ctlcnt = max;
3036 ctls = (struct hdaa_audio_ctl *)malloc(
3037 sizeof(*ctls) * max, M_HDAA, M_ZERO | M_NOWAIT);
3041 device_printf(devinfo->dev, "unable to allocate ctls!\n");
3042 devinfo->ctlcnt = 0;
3047 for (i = devinfo->startnode; cnt < max && i < devinfo->endnode; i++) {
3049 device_printf(devinfo->dev, "%s: Ctl overflow!\n",
3053 w = hdaa_widget_get(devinfo, i);
3054 if (w == NULL || w->enable == 0)
3056 ocap = w->param.outamp_cap;
3057 icap = w->param.inamp_cap;
3059 mute = HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(ocap);
3060 step = HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(ocap);
3061 size = HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(ocap);
3062 offset = HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(ocap);
3063 /*if (offset > step) {
3065 device_printf(devinfo->dev,
3066 "BUGGY outamp: nid=%d "
3067 "[offset=%d > step=%d]\n",
3068 w->nid, offset, step);
3072 ctls[cnt].enable = 1;
3073 ctls[cnt].widget = w;
3074 ctls[cnt].mute = mute;
3075 ctls[cnt].step = step;
3076 ctls[cnt].size = size;
3077 ctls[cnt].offset = offset;
3078 ctls[cnt].left = offset;
3079 ctls[cnt].right = offset;
3080 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX ||
3082 ctls[cnt].ndir = HDAA_CTL_IN;
3084 ctls[cnt].ndir = HDAA_CTL_OUT;
3085 ctls[cnt++].dir = HDAA_CTL_OUT;
3089 mute = HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(icap);
3090 step = HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(icap);
3091 size = HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(icap);
3092 offset = HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(icap);
3093 /*if (offset > step) {
3095 device_printf(devinfo->dev,
3096 "BUGGY inamp: nid=%d "
3097 "[offset=%d > step=%d]\n",
3098 w->nid, offset, step);
3103 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR:
3104 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER:
3105 for (j = 0; j < w->nconns; j++) {
3107 device_printf(devinfo->dev,
3108 "%s: Ctl overflow!\n",
3112 cw = hdaa_widget_get(devinfo,
3114 if (cw == NULL || cw->enable == 0)
3116 ctls[cnt].enable = 1;
3117 ctls[cnt].widget = w;
3118 ctls[cnt].childwidget = cw;
3119 ctls[cnt].index = j;
3120 ctls[cnt].mute = mute;
3121 ctls[cnt].step = step;
3122 ctls[cnt].size = size;
3123 ctls[cnt].offset = offset;
3124 ctls[cnt].left = offset;
3125 ctls[cnt].right = offset;
3126 ctls[cnt].ndir = HDAA_CTL_IN;
3127 ctls[cnt++].dir = HDAA_CTL_IN;
3132 device_printf(devinfo->dev,
3133 "%s: Ctl overflow!\n",
3137 ctls[cnt].enable = 1;
3138 ctls[cnt].widget = w;
3139 ctls[cnt].mute = mute;
3140 ctls[cnt].step = step;
3141 ctls[cnt].size = size;
3142 ctls[cnt].offset = offset;
3143 ctls[cnt].left = offset;
3144 ctls[cnt].right = offset;
3146 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
3147 ctls[cnt].ndir = HDAA_CTL_OUT;
3149 ctls[cnt].ndir = HDAA_CTL_IN;
3150 ctls[cnt++].dir = HDAA_CTL_IN;
3156 devinfo->ctl = ctls;
3160 hdaa_audio_as_parse(struct hdaa_devinfo *devinfo)
3162 struct hdaa_audio_as *as;
3163 struct hdaa_widget *w;
3164 int i, j, cnt, max, type, dir, assoc, seq, first, hpredir;
3166 /* Count present associations */
3168 for (j = 1; j < 16; j++) {
3169 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3170 w = hdaa_widget_get(devinfo, i);
3171 if (w == NULL || w->enable == 0)
3173 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
3175 if (HDA_CONFIG_DEFAULTCONF_ASSOCIATION(w->wclass.pin.config)
3179 if (j != 15) /* There could be many 1-pin assocs #15 */
3184 devinfo->ascnt = max;
3189 as = (struct hdaa_audio_as *)malloc(
3190 sizeof(*as) * max, M_HDAA, M_ZERO | M_NOWAIT);
3194 device_printf(devinfo->dev, "unable to allocate assocs!\n");
3199 for (i = 0; i < max; i++) {
3202 as[i].num_chans = 1;
3203 as[i].location = -1;
3206 /* Scan associations skipping as=0. */
3208 for (j = 1; j < 16; j++) {
3211 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3212 w = hdaa_widget_get(devinfo, i);
3213 if (w == NULL || w->enable == 0)
3215 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
3217 assoc = HDA_CONFIG_DEFAULTCONF_ASSOCIATION(w->wclass.pin.config);
3218 seq = HDA_CONFIG_DEFAULTCONF_SEQUENCE(w->wclass.pin.config);
3223 ("%s: Associations owerflow (%d of %d)",
3224 __func__, cnt, max));
3225 type = w->wclass.pin.config &
3226 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
3227 /* Get pin direction. */
3228 if (type == HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_OUT ||
3229 type == HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER ||
3230 type == HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT ||
3231 type == HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_OUT ||
3232 type == HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_OUT)
3236 /* If this is a first pin - create new association. */
3237 if (as[cnt].pincnt == 0) {
3244 /* Check association correctness. */
3245 if (as[cnt].pins[seq] != 0) {
3246 device_printf(devinfo->dev, "%s: Duplicate pin %d (%d) "
3247 "in association %d! Disabling association.\n",
3248 __func__, seq, w->nid, j);
3251 if (dir != as[cnt].dir) {
3252 device_printf(devinfo->dev, "%s: Pin %d has wrong "
3253 "direction for association %d! Disabling "
3255 __func__, w->nid, j);
3258 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) {
3259 as[cnt].digital |= 0x1;
3260 if (HDA_PARAM_PIN_CAP_HDMI(w->wclass.pin.cap))
3261 as[cnt].digital |= 0x2;
3262 if (HDA_PARAM_PIN_CAP_DP(w->wclass.pin.cap))
3263 as[cnt].digital |= 0x4;
3265 if (as[cnt].location == -1) {
3267 HDA_CONFIG_DEFAULTCONF_LOCATION(w->wclass.pin.config);
3268 } else if (as[cnt].location !=
3269 HDA_CONFIG_DEFAULTCONF_LOCATION(w->wclass.pin.config)) {
3270 as[cnt].location = -2;
3272 /* Headphones with seq=15 may mean redirection. */
3273 if (type == HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT &&
3276 as[cnt].pins[seq] = w->nid;
3278 /* Association 15 is a multiple unassociated pins. */
3282 if (j != 15 && as[cnt].pincnt > 0) {
3283 if (hpredir && as[cnt].pincnt > 1)
3284 as[cnt].hpredir = first;
3288 for (i = 0; i < max; i++) {
3289 if (as[i].dir == HDAA_CTL_IN && (as[i].pincnt == 1 ||
3290 as[i].pins[14] > 0 || as[i].pins[15] > 0))
3294 device_printf(devinfo->dev,
3295 "%d associations found:\n", max);
3296 for (i = 0; i < max; i++) {
3297 device_printf(devinfo->dev,
3298 "Association %d (%d) %s%s:\n",
3299 i, as[i].index, (as[i].dir == HDAA_CTL_IN)?"in":"out",
3300 as[i].enable?"":" (disabled)");
3301 for (j = 0; j < 16; j++) {
3302 if (as[i].pins[j] == 0)
3304 device_printf(devinfo->dev,
3305 " Pin nid=%d seq=%d\n",
3315 * Trace path from DAC to pin.
3318 hdaa_audio_trace_dac(struct hdaa_devinfo *devinfo, int as, int seq, nid_t nid,
3319 int dupseq, int min, int only, int depth)
3321 struct hdaa_widget *w;
3325 if (depth > HDA_PARSE_MAXDEPTH)
3327 w = hdaa_widget_get(devinfo, nid);
3328 if (w == NULL || w->enable == 0)
3332 device_printf(devinfo->dev,
3333 " %*stracing via nid %d\n",
3334 depth + 1, "", w->nid);
3337 /* Use only unused widgets */
3338 if (w->bindas >= 0 && w->bindas != as) {
3341 device_printf(devinfo->dev,
3342 " %*snid %d busy by association %d\n",
3343 depth + 1, "", w->nid, w->bindas);
3349 if (w->bindseqmask != 0) {
3352 device_printf(devinfo->dev,
3353 " %*snid %d busy by seqmask %x\n",
3354 depth + 1, "", w->nid, w->bindseqmask);
3360 /* If this is headphones - allow duplicate first pin. */
3361 if (w->bindseqmask != 0 &&
3362 (w->bindseqmask & (1 << dupseq)) == 0) {
3364 device_printf(devinfo->dev,
3365 " %*snid %d busy by seqmask %x\n",
3366 depth + 1, "", w->nid, w->bindseqmask);
3373 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT:
3374 /* Do not traverse input. AD1988 has digital monitor
3375 for which we are not ready. */
3377 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT:
3378 /* If we are tracing HP take only dac of first pin. */
3379 if ((only == 0 || only == w->nid) &&
3380 (w->nid >= min) && (dupseq < 0 || w->nid ==
3381 devinfo->as[as].dacs[0][dupseq]))
3384 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
3389 /* Find reachable DACs with smallest nid respecting constraints. */
3390 for (i = 0; i < w->nconns; i++) {
3391 if (w->connsenable[i] == 0)
3393 if (w->selconn != -1 && w->selconn != i)
3395 if ((ret = hdaa_audio_trace_dac(devinfo, as, seq,
3396 w->conns[i], dupseq, min, only, depth + 1)) != 0) {
3397 if (m == 0 || ret < m) {
3401 if (only || dupseq >= 0)
3405 if (im >= 0 && only && ((w->nconns > 1 &&
3406 w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) ||
3407 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR))
3413 w->bindseqmask |= (1 << seq);
3417 device_printf(devinfo->dev,
3418 " %*snid %d returned %d\n",
3419 depth + 1, "", w->nid, m);
3426 * Trace path from widget to ADC.
3429 hdaa_audio_trace_adc(struct hdaa_devinfo *devinfo, int as, int seq, nid_t nid,
3430 int mixed, int min, int only, int depth, int *length, int onlylength)
3432 struct hdaa_widget *w, *wc;
3433 int i, j, im, lm = HDA_PARSE_MAXDEPTH;
3436 if (depth > HDA_PARSE_MAXDEPTH)
3438 w = hdaa_widget_get(devinfo, nid);
3439 if (w == NULL || w->enable == 0)
3442 device_printf(devinfo->dev,
3443 " %*stracing via nid %d\n",
3444 depth + 1, "", w->nid);
3446 /* Use only unused widgets */
3447 if (w->bindas >= 0 && w->bindas != as) {
3449 device_printf(devinfo->dev,
3450 " %*snid %d busy by association %d\n",
3451 depth + 1, "", w->nid, w->bindas);
3455 if (!mixed && w->bindseqmask != 0) {
3457 device_printf(devinfo->dev,
3458 " %*snid %d busy by seqmask %x\n",
3459 depth + 1, "", w->nid, w->bindseqmask);
3464 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT:
3465 if ((only == 0 || only == w->nid) && (w->nid >= min) &&
3466 (onlylength == 0 || onlylength == depth)) {
3471 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
3476 /* Try to find reachable ADCs with specified nid. */
3477 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
3478 wc = hdaa_widget_get(devinfo, j);
3479 if (wc == NULL || wc->enable == 0)
3482 for (i = 0; i < wc->nconns; i++) {
3483 if (wc->connsenable[i] == 0)
3485 if (wc->conns[i] != nid)
3487 if ((ret = hdaa_audio_trace_adc(devinfo, as, seq,
3488 j, mixed, min, only, depth + 1,
3489 length, onlylength)) != 0) {
3490 if (m == 0 || ret < m ||
3491 (ret == m && *length < lm)) {
3501 if (im >= 0 && only && ((wc->nconns > 1 &&
3502 wc->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) ||
3503 wc->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR))
3510 w->bindseqmask |= (1 << seq);
3513 device_printf(devinfo->dev,
3514 " %*snid %d returned %d\n",
3515 depth + 1, "", w->nid, m);
3521 * Erase trace path of the specified association.
3524 hdaa_audio_undo_trace(struct hdaa_devinfo *devinfo, int as, int seq)
3526 struct hdaa_widget *w;
3529 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3530 w = hdaa_widget_get(devinfo, i);
3531 if (w == NULL || w->enable == 0)
3533 if (w->bindas == as) {
3535 w->bindseqmask &= ~(1 << seq);
3536 if (w->bindseqmask == 0) {
3550 * Trace association path from DAC to output
3553 hdaa_audio_trace_as_out(struct hdaa_devinfo *devinfo, int as, int seq)
3555 struct hdaa_audio_as *ases = devinfo->as;
3560 for (i = seq; i < 16 && ases[as].pins[i] == 0; i++)
3562 /* Check if there is no any left. If so - we succeeded. */
3566 hpredir = (i == 15 && ases[as].fakeredir == 0)?ases[as].hpredir:-1;
3570 device_printf(devinfo->dev,
3571 " Tracing pin %d with min nid %d",
3572 ases[as].pins[i], min);
3574 printf(" and hpredir %d", hpredir);
3577 /* Trace this pin taking min nid into account. */
3578 res = hdaa_audio_trace_dac(devinfo, as, i,
3579 ases[as].pins[i], hpredir, min, 0, 0);
3581 /* If we failed - return to previous and redo it. */
3583 device_printf(devinfo->dev,
3584 " Unable to trace pin %d seq %d with min "
3586 ases[as].pins[i], i, min);
3588 printf(" and hpredir %d", hpredir);
3594 device_printf(devinfo->dev,
3595 " Pin %d traced to DAC %d",
3596 ases[as].pins[i], res);
3598 printf(" and hpredir %d", hpredir);
3599 if (ases[as].fakeredir)
3600 printf(" with fake redirection");
3603 /* Trace again to mark the path */
3604 hdaa_audio_trace_dac(devinfo, as, i,
3605 ases[as].pins[i], hpredir, min, res, 0);
3606 ases[as].dacs[0][i] = res;
3607 /* We succeeded, so call next. */
3608 if (hdaa_audio_trace_as_out(devinfo, as, i + 1))
3610 /* If next failed, we should retry with next min */
3611 hdaa_audio_undo_trace(devinfo, as, i);
3612 ases[as].dacs[0][i] = 0;
3618 * Check equivalency of two DACs.
3621 hdaa_audio_dacs_equal(struct hdaa_widget *w1, struct hdaa_widget *w2)
3623 struct hdaa_devinfo *devinfo = w1->devinfo;
3624 struct hdaa_widget *w3;
3627 if (memcmp(&w1->param, &w2->param, sizeof(w1->param)))
3629 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3630 w3 = hdaa_widget_get(devinfo, i);
3631 if (w3 == NULL || w3->enable == 0)
3633 if (w3->bindas != w1->bindas)
3635 if (w3->nconns == 0)
3638 for (j = 0; j < w3->nconns; j++) {
3639 if (w3->connsenable[j] == 0)
3641 if (w3->conns[j] == w1->nid)
3643 if (w3->conns[j] == w2->nid)
3650 if (w3->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
3657 * Check equivalency of two ADCs.
3660 hdaa_audio_adcs_equal(struct hdaa_widget *w1, struct hdaa_widget *w2)
3662 struct hdaa_devinfo *devinfo = w1->devinfo;
3663 struct hdaa_widget *w3, *w4;
3666 if (memcmp(&w1->param, &w2->param, sizeof(w1->param)))
3668 if (w1->nconns != 1 || w2->nconns != 1)
3670 if (w1->conns[0] == w2->conns[0])
3672 w3 = hdaa_widget_get(devinfo, w1->conns[0]);
3673 if (w3 == NULL || w3->enable == 0)
3675 w4 = hdaa_widget_get(devinfo, w2->conns[0]);
3676 if (w4 == NULL || w4->enable == 0)
3678 if (w3->bindas == w4->bindas && w3->bindseqmask == w4->bindseqmask)
3680 if (w4->bindas >= 0)
3682 if (w3->type != w4->type)
3684 if (memcmp(&w3->param, &w4->param, sizeof(w3->param)))
3686 if (w3->nconns != w4->nconns)
3688 for (i = 0; i < w3->nconns; i++) {
3689 if (w3->conns[i] != w4->conns[i])
3696 * Look for equivalent DAC/ADC to implement second channel.
3699 hdaa_audio_adddac(struct hdaa_devinfo *devinfo, int asid)
3701 struct hdaa_audio_as *as = &devinfo->as[asid];
3702 struct hdaa_widget *w1, *w2;
3707 device_printf(devinfo->dev,
3708 "Looking for additional %sC "
3709 "for association %d (%d)\n",
3710 (as->dir == HDAA_CTL_OUT) ? "DA" : "AD",
3714 /* Find the exisitng DAC position and return if found more the one. */
3716 for (i = 0; i < 16; i++) {
3717 if (as->dacs[0][i] <= 0)
3719 if (pos >= 0 && as->dacs[0][i] != as->dacs[0][pos])
3724 nid1 = as->dacs[0][pos];
3725 w1 = hdaa_widget_get(devinfo, nid1);
3727 for (nid2 = devinfo->startnode; nid2 < devinfo->endnode; nid2++) {
3728 w2 = hdaa_widget_get(devinfo, nid2);
3729 if (w2 == NULL || w2->enable == 0)
3731 if (w2->bindas >= 0)
3733 if (w1->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT) {
3734 if (w2->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT)
3736 if (hdaa_audio_dacs_equal(w1, w2))
3739 if (w2->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT)
3741 if (hdaa_audio_adcs_equal(w1, w2))
3745 if (nid2 >= devinfo->endnode)
3747 w2->bindas = w1->bindas;
3748 w2->bindseqmask = w1->bindseqmask;
3749 if (w1->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
3751 device_printf(devinfo->dev,
3752 " ADC %d considered equal to ADC %d\n", nid2, nid1);
3754 w1 = hdaa_widget_get(devinfo, w1->conns[0]);
3755 w2 = hdaa_widget_get(devinfo, w2->conns[0]);
3756 w2->bindas = w1->bindas;
3757 w2->bindseqmask = w1->bindseqmask;
3760 device_printf(devinfo->dev,
3761 " DAC %d considered equal to DAC %d\n", nid2, nid1);
3764 for (i = 0; i < 16; i++) {
3765 if (as->dacs[0][i] <= 0)
3767 as->dacs[as->num_chans][i] = nid2;
3773 * Trace association path from input to ADC
3776 hdaa_audio_trace_as_in(struct hdaa_devinfo *devinfo, int as)
3778 struct hdaa_audio_as *ases = devinfo->as;
3779 struct hdaa_widget *w;
3780 int i, j, k, length;
3782 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
3783 w = hdaa_widget_get(devinfo, j);
3784 if (w == NULL || w->enable == 0)
3786 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT)
3788 if (w->bindas >= 0 && w->bindas != as)
3792 for (i = 0; i < 16; i++) {
3793 if (ases[as].pins[i] == 0)
3797 device_printf(devinfo->dev,
3798 " Tracing pin %d to ADC %d\n",
3799 ases[as].pins[i], j);
3801 /* Trace this pin taking goal into account. */
3802 if (hdaa_audio_trace_adc(devinfo, as, i,
3803 ases[as].pins[i], 1, 0, j, 0, &length, 0) == 0) {
3804 /* If we failed - return to previous and redo it. */
3806 device_printf(devinfo->dev,
3807 " Unable to trace pin %d to ADC %d, undo traces\n",
3808 ases[as].pins[i], j);
3810 hdaa_audio_undo_trace(devinfo, as, -1);
3811 for (k = 0; k < 16; k++)
3812 ases[as].dacs[0][k] = 0;
3816 device_printf(devinfo->dev,
3817 " Pin %d traced to ADC %d\n",
3818 ases[as].pins[i], j);
3820 ases[as].dacs[0][i] = j;
3829 * Trace association path from input to multiple ADCs
3832 hdaa_audio_trace_as_in_mch(struct hdaa_devinfo *devinfo, int as, int seq)
3834 struct hdaa_audio_as *ases = devinfo->as;
3839 for (i = seq; i < 16 && ases[as].pins[i] == 0; i++)
3841 /* Check if there is no any left. If so - we succeeded. */
3848 device_printf(devinfo->dev,
3849 " Tracing pin %d with min nid %d",
3850 ases[as].pins[i], min);
3853 /* Trace this pin taking min nid into account. */
3854 res = hdaa_audio_trace_adc(devinfo, as, i,
3855 ases[as].pins[i], 0, min, 0, 0, &length, 0);
3857 /* If we failed - return to previous and redo it. */
3859 device_printf(devinfo->dev,
3860 " Unable to trace pin %d seq %d with min "
3862 ases[as].pins[i], i, min);
3868 device_printf(devinfo->dev,
3869 " Pin %d traced to ADC %d\n",
3870 ases[as].pins[i], res);
3872 /* Trace again to mark the path */
3873 hdaa_audio_trace_adc(devinfo, as, i,
3874 ases[as].pins[i], 0, min, res, 0, &length, length);
3875 ases[as].dacs[0][i] = res;
3876 /* We succeeded, so call next. */
3877 if (hdaa_audio_trace_as_in_mch(devinfo, as, i + 1))
3879 /* If next failed, we should retry with next min */
3880 hdaa_audio_undo_trace(devinfo, as, i);
3881 ases[as].dacs[0][i] = 0;
3887 * Trace input monitor path from mixer to output association.
3890 hdaa_audio_trace_to_out(struct hdaa_devinfo *devinfo, nid_t nid, int depth)
3892 struct hdaa_audio_as *ases = devinfo->as;
3893 struct hdaa_widget *w, *wc;
3897 if (depth > HDA_PARSE_MAXDEPTH)
3899 w = hdaa_widget_get(devinfo, nid);
3900 if (w == NULL || w->enable == 0)
3903 device_printf(devinfo->dev,
3904 " %*stracing via nid %d\n",
3905 depth + 1, "", w->nid);
3907 /* Use only unused widgets */
3908 if (depth > 0 && w->bindas != -1) {
3909 if (w->bindas < 0 || ases[w->bindas].dir == HDAA_CTL_OUT) {
3911 device_printf(devinfo->dev,
3912 " %*snid %d found output association %d\n",
3913 depth + 1, "", w->nid, w->bindas);
3916 w->pflags |= HDAA_ADC_MONITOR;
3920 device_printf(devinfo->dev,
3921 " %*snid %d busy by input association %d\n",
3922 depth + 1, "", w->nid, w->bindas);
3929 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT:
3930 /* Do not traverse input. AD1988 has digital monitor
3931 for which we are not ready. */
3933 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
3938 /* Try to find reachable ADCs with specified nid. */
3939 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
3940 wc = hdaa_widget_get(devinfo, j);
3941 if (wc == NULL || wc->enable == 0)
3943 for (i = 0; i < wc->nconns; i++) {
3944 if (wc->connsenable[i] == 0)
3946 if (wc->conns[i] != nid)
3948 if (hdaa_audio_trace_to_out(devinfo,
3949 j, depth + 1) != 0) {
3951 if (wc->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR &&
3959 if (res && w->bindas == -1)
3963 device_printf(devinfo->dev,
3964 " %*snid %d returned %d\n",
3965 depth + 1, "", w->nid, res);
3971 * Trace extra associations (beeper, monitor)
3974 hdaa_audio_trace_as_extra(struct hdaa_devinfo *devinfo)
3976 struct hdaa_audio_as *as = devinfo->as;
3977 struct hdaa_widget *w;
3981 /* Find mixer associated with input, but supplying signal
3982 for output associations. Hope it will be input monitor. */
3984 device_printf(devinfo->dev,
3985 "Tracing input monitor\n");
3987 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
3988 w = hdaa_widget_get(devinfo, j);
3989 if (w == NULL || w->enable == 0)
3991 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
3993 if (w->bindas < 0 || as[w->bindas].dir != HDAA_CTL_IN)
3996 device_printf(devinfo->dev,
3997 " Tracing nid %d to out\n",
4000 if (hdaa_audio_trace_to_out(devinfo, w->nid, 0)) {
4002 device_printf(devinfo->dev,
4003 " nid %d is input monitor\n",
4006 w->ossdev = SOUND_MIXER_IMIX;
4010 /* Other inputs monitor */
4011 /* Find input pins supplying signal for output associations.
4012 Hope it will be input monitoring. */
4014 device_printf(devinfo->dev,
4015 "Tracing other input monitors\n");
4017 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
4018 w = hdaa_widget_get(devinfo, j);
4019 if (w == NULL || w->enable == 0)
4021 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
4023 if (w->bindas < 0 || as[w->bindas].dir != HDAA_CTL_IN)
4026 device_printf(devinfo->dev,
4027 " Tracing nid %d to out\n",
4030 if (hdaa_audio_trace_to_out(devinfo, w->nid, 0)) {
4032 device_printf(devinfo->dev,
4033 " nid %d is input monitor\n",
4041 device_printf(devinfo->dev,
4042 "Tracing beeper\n");
4044 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
4045 w = hdaa_widget_get(devinfo, j);
4046 if (w == NULL || w->enable == 0)
4048 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET)
4051 device_printf(devinfo->dev,
4052 " Tracing nid %d to out\n",
4055 if (hdaa_audio_trace_to_out(devinfo, w->nid, 0)) {
4057 device_printf(devinfo->dev,
4058 " nid %d traced to out\n",
4067 * Bind assotiations to PCM channels
4070 hdaa_audio_bind_as(struct hdaa_devinfo *devinfo)
4072 struct hdaa_audio_as *as = devinfo->as;
4073 int i, j, cnt = 0, free;
4075 for (j = 0; j < devinfo->ascnt; j++) {
4077 cnt += as[j].num_chans;
4079 if (devinfo->num_chans == 0) {
4080 devinfo->chans = (struct hdaa_chan *)malloc(
4081 sizeof(struct hdaa_chan) * cnt,
4082 M_HDAA, M_ZERO | M_NOWAIT);
4083 if (devinfo->chans == NULL) {
4084 device_printf(devinfo->dev,
4085 "Channels memory allocation failed!\n");
4089 devinfo->chans = (struct hdaa_chan *)realloc(devinfo->chans,
4090 sizeof(struct hdaa_chan) * (devinfo->num_chans + cnt),
4091 M_HDAA, M_ZERO | M_NOWAIT);
4092 if (devinfo->chans == NULL) {
4093 devinfo->num_chans = 0;
4094 device_printf(devinfo->dev,
4095 "Channels memory allocation failed!\n");
4098 /* Fixup relative pointers after realloc */
4099 for (j = 0; j < devinfo->num_chans; j++)
4100 devinfo->chans[j].caps.fmtlist = devinfo->chans[j].fmtlist;
4102 free = devinfo->num_chans;
4103 devinfo->num_chans += cnt;
4105 for (j = free; j < free + cnt; j++) {
4106 devinfo->chans[j].devinfo = devinfo;
4107 devinfo->chans[j].as = -1;
4110 /* Assign associations in order of their numbers, */
4111 for (j = 0; j < devinfo->ascnt; j++) {
4112 if (as[j].enable == 0)
4114 for (i = 0; i < as[j].num_chans; i++) {
4115 devinfo->chans[free].as = j;
4116 devinfo->chans[free].asindex = i;
4117 devinfo->chans[free].dir =
4118 (as[j].dir == HDAA_CTL_IN) ? PCMDIR_REC : PCMDIR_PLAY;
4119 hdaa_pcmchannel_setup(&devinfo->chans[free]);
4120 as[j].chans[i] = free;
4127 hdaa_audio_disable_nonaudio(struct hdaa_devinfo *devinfo)
4129 struct hdaa_widget *w;
4132 /* Disable power and volume widgets. */
4133 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4134 w = hdaa_widget_get(devinfo, i);
4135 if (w == NULL || w->enable == 0)
4137 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_POWER_WIDGET ||
4138 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_VOLUME_WIDGET) {
4141 device_printf(devinfo->dev,
4142 " Disabling nid %d due to it's"
4143 " non-audio type.\n",
4151 hdaa_audio_disable_useless(struct hdaa_devinfo *devinfo)
4153 struct hdaa_widget *w, *cw;
4154 struct hdaa_audio_ctl *ctl;
4155 int done, found, i, j, k;
4157 /* Disable useless pins. */
4158 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4159 w = hdaa_widget_get(devinfo, i);
4160 if (w == NULL || w->enable == 0)
4162 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) {
4163 if ((w->wclass.pin.config &
4164 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK) ==
4165 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_NONE) {
4168 device_printf(devinfo->dev,
4169 " Disabling pin nid %d due"
4170 " to None connectivity.\n",
4173 } else if ((w->wclass.pin.config &
4174 HDA_CONFIG_DEFAULTCONF_ASSOCIATION_MASK) == 0) {
4177 device_printf(devinfo->dev,
4178 " Disabling unassociated"
4187 /* Disable and mute controls for disabled widgets. */
4189 while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) {
4190 if (ctl->enable == 0)
4192 if (ctl->widget->enable == 0 ||
4193 (ctl->childwidget != NULL &&
4194 ctl->childwidget->enable == 0)) {
4196 ctl->muted = HDAA_AMP_MUTE_ALL;
4200 if (ctl->ndir == HDAA_CTL_IN)
4201 ctl->widget->connsenable[ctl->index] = 0;
4204 device_printf(devinfo->dev,
4205 " Disabling ctl %d nid %d cnid %d due"
4206 " to disabled widget.\n", i,
4208 (ctl->childwidget != NULL)?
4209 ctl->childwidget->nid:-1);
4213 /* Disable useless widgets. */
4214 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4215 w = hdaa_widget_get(devinfo, i);
4216 if (w == NULL || w->enable == 0)
4218 /* Disable inputs with disabled child widgets. */
4219 for (j = 0; j < w->nconns; j++) {
4220 if (w->connsenable[j]) {
4221 cw = hdaa_widget_get(devinfo, w->conns[j]);
4222 if (cw == NULL || cw->enable == 0) {
4223 w->connsenable[j] = 0;
4225 device_printf(devinfo->dev,
4226 " Disabling nid %d connection %d due"
4227 " to disabled child widget.\n",
4233 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR &&
4234 w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
4236 /* Disable mixers and selectors without inputs. */
4238 for (j = 0; j < w->nconns; j++) {
4239 if (w->connsenable[j]) {
4248 device_printf(devinfo->dev,
4249 " Disabling nid %d due to all it's"
4250 " inputs disabled.\n", w->nid);
4253 /* Disable nodes without consumers. */
4254 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR &&
4255 w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
4258 for (k = devinfo->startnode; k < devinfo->endnode; k++) {
4259 cw = hdaa_widget_get(devinfo, k);
4260 if (cw == NULL || cw->enable == 0)
4262 for (j = 0; j < cw->nconns; j++) {
4263 if (cw->connsenable[j] && cw->conns[j] == i) {
4273 device_printf(devinfo->dev,
4274 " Disabling nid %d due to all it's"
4275 " consumers disabled.\n", w->nid);
4279 } while (done == 0);
4284 hdaa_audio_disable_unas(struct hdaa_devinfo *devinfo)
4286 struct hdaa_audio_as *as = devinfo->as;
4287 struct hdaa_widget *w, *cw;
4288 struct hdaa_audio_ctl *ctl;
4291 /* Disable unassosiated widgets. */
4292 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4293 w = hdaa_widget_get(devinfo, i);
4294 if (w == NULL || w->enable == 0)
4296 if (w->bindas == -1) {
4299 device_printf(devinfo->dev,
4300 " Disabling unassociated nid %d.\n",
4305 /* Disable input connections on input pin and
4306 * output on output. */
4307 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4308 w = hdaa_widget_get(devinfo, i);
4309 if (w == NULL || w->enable == 0)
4311 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
4315 if (as[w->bindas].dir == HDAA_CTL_IN) {
4316 for (j = 0; j < w->nconns; j++) {
4317 if (w->connsenable[j] == 0)
4319 w->connsenable[j] = 0;
4321 device_printf(devinfo->dev,
4322 " Disabling connection to input pin "
4323 "nid %d conn %d.\n",
4327 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid,
4328 HDAA_CTL_IN, -1, 1);
4329 if (ctl && ctl->enable) {
4331 ctl->muted = HDAA_AMP_MUTE_ALL;
4337 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid,
4338 HDAA_CTL_OUT, -1, 1);
4339 if (ctl && ctl->enable) {
4341 ctl->muted = HDAA_AMP_MUTE_ALL;
4346 for (k = devinfo->startnode; k < devinfo->endnode; k++) {
4347 cw = hdaa_widget_get(devinfo, k);
4348 if (cw == NULL || cw->enable == 0)
4350 for (j = 0; j < cw->nconns; j++) {
4351 if (cw->connsenable[j] && cw->conns[j] == i) {
4352 cw->connsenable[j] = 0;
4354 device_printf(devinfo->dev,
4355 " Disabling connection from output pin "
4356 "nid %d conn %d cnid %d.\n",
4359 if (cw->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
4362 ctl = hdaa_audio_ctl_amp_get(devinfo, k,
4364 if (ctl && ctl->enable) {
4366 ctl->muted = HDAA_AMP_MUTE_ALL;
4379 hdaa_audio_disable_notselected(struct hdaa_devinfo *devinfo)
4381 struct hdaa_audio_as *as = devinfo->as;
4382 struct hdaa_widget *w;
4385 /* On playback path we can safely disable all unseleted inputs. */
4386 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4387 w = hdaa_widget_get(devinfo, i);
4388 if (w == NULL || w->enable == 0)
4392 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
4394 if (w->bindas < 0 || as[w->bindas].dir == HDAA_CTL_IN)
4396 for (j = 0; j < w->nconns; j++) {
4397 if (w->connsenable[j] == 0)
4399 if (w->selconn < 0 || w->selconn == j)
4401 w->connsenable[j] = 0;
4403 device_printf(devinfo->dev,
4404 " Disabling unselected connection "
4405 "nid %d conn %d.\n",
4413 hdaa_audio_disable_crossas(struct hdaa_devinfo *devinfo)
4415 struct hdaa_audio_as *ases = devinfo->as;
4416 struct hdaa_widget *w, *cw;
4417 struct hdaa_audio_ctl *ctl;
4420 /* Disable crossassociatement and unwanted crosschannel connections. */
4421 /* ... using selectors */
4422 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4423 w = hdaa_widget_get(devinfo, i);
4424 if (w == NULL || w->enable == 0)
4428 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
4430 /* Allow any -> mix */
4431 if (w->bindas == -2)
4433 for (j = 0; j < w->nconns; j++) {
4434 if (w->connsenable[j] == 0)
4436 cw = hdaa_widget_get(devinfo, w->conns[j]);
4437 if (cw == NULL || w->enable == 0)
4439 /* Allow mix -> out. */
4440 if (cw->bindas == -2 && w->bindas >= 0 &&
4441 ases[w->bindas].dir == HDAA_CTL_OUT)
4443 /* Allow mix -> mixed-in. */
4444 if (cw->bindas == -2 && w->bindas >= 0 &&
4445 ases[w->bindas].mixed)
4447 /* Allow in -> mix. */
4448 if ((w->pflags & HDAA_ADC_MONITOR) &&
4450 ases[cw->bindas].dir == HDAA_CTL_IN)
4452 /* Allow if have common as/seqs. */
4453 if (w->bindas == cw->bindas &&
4454 (w->bindseqmask & cw->bindseqmask) != 0)
4456 w->connsenable[j] = 0;
4458 device_printf(devinfo->dev,
4459 " Disabling crossassociatement connection "
4460 "nid %d conn %d cnid %d.\n",
4465 /* ... using controls */
4467 while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) {
4468 if (ctl->enable == 0 || ctl->childwidget == NULL)
4470 /* Allow any -> mix */
4471 if (ctl->widget->bindas == -2)
4473 /* Allow mix -> out. */
4474 if (ctl->childwidget->bindas == -2 &&
4475 ctl->widget->bindas >= 0 &&
4476 ases[ctl->widget->bindas].dir == HDAA_CTL_OUT)
4478 /* Allow mix -> mixed-in. */
4479 if (ctl->childwidget->bindas == -2 &&
4480 ctl->widget->bindas >= 0 &&
4481 ases[ctl->widget->bindas].mixed)
4483 /* Allow in -> mix. */
4484 if ((ctl->widget->pflags & HDAA_ADC_MONITOR) &&
4485 ctl->childwidget->bindas >= 0 &&
4486 ases[ctl->childwidget->bindas].dir == HDAA_CTL_IN)
4488 /* Allow if have common as/seqs. */
4489 if (ctl->widget->bindas == ctl->childwidget->bindas &&
4490 (ctl->widget->bindseqmask & ctl->childwidget->bindseqmask) != 0)
4493 ctl->muted = HDAA_AMP_MUTE_ALL;
4497 if (ctl->ndir == HDAA_CTL_IN)
4498 ctl->widget->connsenable[ctl->index] = 0;
4500 device_printf(devinfo->dev,
4501 " Disabling crossassociatement connection "
4502 "ctl %d nid %d cnid %d.\n", i,
4504 ctl->childwidget->nid);
4511 * Find controls to control amplification for source and calculate possible
4512 * amplification range.
4515 hdaa_audio_ctl_source_amp(struct hdaa_devinfo *devinfo, nid_t nid, int index,
4516 int ossdev, int ctlable, int depth, int *minamp, int *maxamp)
4518 struct hdaa_widget *w, *wc;
4519 struct hdaa_audio_ctl *ctl;
4520 int i, j, conns = 0, tminamp, tmaxamp, cminamp, cmaxamp, found = 0;
4522 if (depth > HDA_PARSE_MAXDEPTH)
4525 w = hdaa_widget_get(devinfo, nid);
4526 if (w == NULL || w->enable == 0)
4529 /* Count number of active inputs. */
4531 for (j = 0; j < w->nconns; j++) {
4532 if (!w->connsenable[j])
4538 /* If this is not a first step - use input mixer.
4539 Pins have common input ctl so care must be taken. */
4540 if (depth > 0 && ctlable && (conns == 1 ||
4541 w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)) {
4542 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, HDAA_CTL_IN,
4545 ctl->ossmask |= (1 << ossdev);
4547 if (*minamp == *maxamp) {
4548 *minamp += MINQDB(ctl);
4549 *maxamp += MAXQDB(ctl);
4554 /* If widget has own ossdev - not traverse it.
4555 It will be traversed on it's own. */
4556 if (w->ossdev >= 0 && depth > 0)
4559 /* We must not traverse pin */
4560 if ((w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT ||
4561 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) &&
4565 /* record that this widget exports such signal, */
4566 w->ossmask |= (1 << ossdev);
4569 * If signals mixed, we can't assign controls farther.
4570 * Ignore this on depth zero. Caller must knows why.
4573 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
4577 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, HDAA_CTL_OUT, -1, 1);
4579 ctl->ossmask |= (1 << ossdev);
4581 if (*minamp == *maxamp) {
4582 *minamp += MINQDB(ctl);
4583 *maxamp += MAXQDB(ctl);
4588 cminamp = cmaxamp = 0;
4589 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4590 wc = hdaa_widget_get(devinfo, i);
4591 if (wc == NULL || wc->enable == 0)
4593 for (j = 0; j < wc->nconns; j++) {
4594 if (wc->connsenable[j] && wc->conns[j] == nid) {
4595 tminamp = tmaxamp = 0;
4596 found += hdaa_audio_ctl_source_amp(devinfo,
4597 wc->nid, j, ossdev, ctlable, depth + 1,
4598 &tminamp, &tmaxamp);
4599 if (cminamp == 0 && cmaxamp == 0) {
4602 } else if (tminamp != tmaxamp) {
4603 cminamp = imax(cminamp, tminamp);
4604 cmaxamp = imin(cmaxamp, tmaxamp);
4609 if (*minamp == *maxamp && cminamp < cmaxamp) {
4617 * Find controls to control amplification for destination and calculate
4618 * possible amplification range.
4621 hdaa_audio_ctl_dest_amp(struct hdaa_devinfo *devinfo, nid_t nid, int index,
4622 int ossdev, int depth, int *minamp, int *maxamp)
4624 struct hdaa_audio_as *as = devinfo->as;
4625 struct hdaa_widget *w, *wc;
4626 struct hdaa_audio_ctl *ctl;
4627 int i, j, consumers, tminamp, tmaxamp, cminamp, cmaxamp, found = 0;
4629 if (depth > HDA_PARSE_MAXDEPTH)
4632 w = hdaa_widget_get(devinfo, nid);
4633 if (w == NULL || w->enable == 0)
4637 /* If this node produce output for several consumers,
4638 we can't touch it. */
4640 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4641 wc = hdaa_widget_get(devinfo, i);
4642 if (wc == NULL || wc->enable == 0)
4644 for (j = 0; j < wc->nconns; j++) {
4645 if (wc->connsenable[j] && wc->conns[j] == nid)
4649 /* The only exception is if real HP redirection is configured
4650 and this is a duplication point.
4651 XXX: Actually exception is not completely correct.
4652 XXX: Duplication point check is not perfect. */
4653 if ((consumers == 2 && (w->bindas < 0 ||
4654 as[w->bindas].hpredir < 0 || as[w->bindas].fakeredir ||
4655 (w->bindseqmask & (1 << 15)) == 0)) ||
4659 /* Else use it's output mixer. */
4660 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid,
4661 HDAA_CTL_OUT, -1, 1);
4663 ctl->ossmask |= (1 << ossdev);
4665 if (*minamp == *maxamp) {
4666 *minamp += MINQDB(ctl);
4667 *maxamp += MAXQDB(ctl);
4672 /* We must not traverse pin */
4673 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
4677 cminamp = cmaxamp = 0;
4678 for (i = 0; i < w->nconns; i++) {
4679 if (w->connsenable[i] == 0)
4681 if (index >= 0 && i != index)
4683 tminamp = tmaxamp = 0;
4684 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid,
4687 ctl->ossmask |= (1 << ossdev);
4689 if (*minamp == *maxamp) {
4690 tminamp += MINQDB(ctl);
4691 tmaxamp += MAXQDB(ctl);
4694 found += hdaa_audio_ctl_dest_amp(devinfo, w->conns[i], -1, ossdev,
4695 depth + 1, &tminamp, &tmaxamp);
4696 if (cminamp == 0 && cmaxamp == 0) {
4699 } else if (tminamp != tmaxamp) {
4700 cminamp = imax(cminamp, tminamp);
4701 cmaxamp = imin(cmaxamp, tmaxamp);
4704 if (*minamp == *maxamp && cminamp < cmaxamp) {
4712 * Assign OSS names to sound sources
4715 hdaa_audio_assign_names(struct hdaa_devinfo *devinfo)
4717 struct hdaa_audio_as *as = devinfo->as;
4718 struct hdaa_widget *w;
4720 int type = -1, use, used = 0;
4721 static const int types[7][13] = {
4722 { SOUND_MIXER_LINE, SOUND_MIXER_LINE1, SOUND_MIXER_LINE2,
4723 SOUND_MIXER_LINE3, -1 }, /* line */
4724 { SOUND_MIXER_MONITOR, SOUND_MIXER_MIC, -1 }, /* int mic */
4725 { SOUND_MIXER_MIC, SOUND_MIXER_MONITOR, -1 }, /* ext mic */
4726 { SOUND_MIXER_CD, -1 }, /* cd */
4727 { SOUND_MIXER_SPEAKER, -1 }, /* speaker */
4728 { SOUND_MIXER_DIGITAL1, SOUND_MIXER_DIGITAL2, SOUND_MIXER_DIGITAL3,
4730 { SOUND_MIXER_LINE, SOUND_MIXER_LINE1, SOUND_MIXER_LINE2,
4731 SOUND_MIXER_LINE3, SOUND_MIXER_PHONEIN, SOUND_MIXER_PHONEOUT,
4732 SOUND_MIXER_VIDEO, SOUND_MIXER_RADIO, SOUND_MIXER_DIGITAL1,
4733 SOUND_MIXER_DIGITAL2, SOUND_MIXER_DIGITAL3, SOUND_MIXER_MONITOR,
4737 /* Surely known names */
4738 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4739 w = hdaa_widget_get(devinfo, i);
4740 if (w == NULL || w->enable == 0)
4742 if (w->bindas == -1)
4746 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
4747 if (as[w->bindas].dir == HDAA_CTL_OUT)
4750 switch (w->wclass.pin.config & HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) {
4751 case HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN:
4754 case HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN:
4755 if ((w->wclass.pin.config & HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK)
4756 == HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_JACK)
4760 case HDA_CONFIG_DEFAULTCONF_DEVICE_CD:
4763 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER:
4766 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_IN:
4767 case HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_IN:
4774 while (types[type][j] >= 0 &&
4775 (used & (1 << types[type][j])) != 0) {
4778 if (types[type][j] >= 0)
4779 use = types[type][j];
4781 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT:
4782 use = SOUND_MIXER_PCM;
4784 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET:
4785 use = SOUND_MIXER_SPEAKER;
4795 /* Semi-known names */
4796 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4797 w = hdaa_widget_get(devinfo, i);
4798 if (w == NULL || w->enable == 0)
4802 if (w->bindas == -1)
4804 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
4806 if (as[w->bindas].dir == HDAA_CTL_OUT)
4809 switch (w->wclass.pin.config & HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) {
4810 case HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_OUT:
4811 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER:
4812 case HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT:
4813 case HDA_CONFIG_DEFAULTCONF_DEVICE_AUX:
4816 case HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN:
4819 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_OUT:
4820 case HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_OUT:
4827 while (types[type][j] >= 0 &&
4828 (used & (1 << types[type][j])) != 0) {
4831 if (types[type][j] >= 0) {
4832 w->ossdev = types[type][j];
4833 used |= (1 << types[type][j]);
4837 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4838 w = hdaa_widget_get(devinfo, i);
4839 if (w == NULL || w->enable == 0)
4843 if (w->bindas == -1)
4845 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
4847 if (as[w->bindas].dir == HDAA_CTL_OUT)
4850 while (types[6][j] >= 0 &&
4851 (used & (1 << types[6][j])) != 0) {
4854 if (types[6][j] >= 0) {
4855 w->ossdev = types[6][j];
4856 used |= (1 << types[6][j]);
4862 hdaa_audio_build_tree(struct hdaa_devinfo *devinfo)
4864 struct hdaa_audio_as *as = devinfo->as;
4867 /* Trace all associations in order of their numbers. */
4868 for (j = 0; j < devinfo->ascnt; j++) {
4869 if (as[j].enable == 0)
4872 device_printf(devinfo->dev,
4873 "Tracing association %d (%d)\n", j, as[j].index);
4875 if (as[j].dir == HDAA_CTL_OUT) {
4877 res = hdaa_audio_trace_as_out(devinfo, j, 0);
4878 if (res == 0 && as[j].hpredir >= 0 &&
4879 as[j].fakeredir == 0) {
4880 /* If CODEC can't do analog HP redirection
4881 try to make it using one more DAC. */
4882 as[j].fakeredir = 1;
4885 } else if (as[j].mixed)
4886 res = hdaa_audio_trace_as_in(devinfo, j);
4888 res = hdaa_audio_trace_as_in_mch(devinfo, j, 0);
4891 device_printf(devinfo->dev,
4892 "Association %d (%d) trace succeeded\n",
4897 device_printf(devinfo->dev,
4898 "Association %d (%d) trace failed\n",
4905 /* Look for additional DACs/ADCs. */
4906 for (j = 0; j < devinfo->ascnt; j++) {
4907 if (as[j].enable == 0)
4909 hdaa_audio_adddac(devinfo, j);
4912 /* Trace mixer and beeper pseudo associations. */
4913 hdaa_audio_trace_as_extra(devinfo);
4917 * Store in pdevinfo new data about whether and how we can control signal
4918 * for OSS device to/from specified widget.
4921 hdaa_adjust_amp(struct hdaa_widget *w, int ossdev,
4922 int found, int minamp, int maxamp)
4924 struct hdaa_devinfo *devinfo = w->devinfo;
4925 struct hdaa_pcm_devinfo *pdevinfo;
4928 pdevinfo = devinfo->as[w->bindas].pdevinfo;
4930 pdevinfo = &devinfo->devs[0];
4932 pdevinfo->ossmask |= (1 << ossdev);
4933 if (minamp == 0 && maxamp == 0)
4935 if (pdevinfo->minamp[ossdev] == 0 && pdevinfo->maxamp[ossdev] == 0) {
4936 pdevinfo->minamp[ossdev] = minamp;
4937 pdevinfo->maxamp[ossdev] = maxamp;
4939 pdevinfo->minamp[ossdev] = imax(pdevinfo->minamp[ossdev], minamp);
4940 pdevinfo->maxamp[ossdev] = imin(pdevinfo->maxamp[ossdev], maxamp);
4945 * Trace signals from/to all possible sources/destionstions to find possible
4946 * recording sources, OSS device control ranges and to assign controls.
4949 hdaa_audio_assign_mixers(struct hdaa_devinfo *devinfo)
4951 struct hdaa_audio_as *as = devinfo->as;
4952 struct hdaa_widget *w, *cw;
4953 int i, j, minamp, maxamp, found;
4955 /* Assign mixers to the tree. */
4956 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4957 w = hdaa_widget_get(devinfo, i);
4958 if (w == NULL || w->enable == 0)
4960 minamp = maxamp = 0;
4961 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT ||
4962 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET ||
4963 (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
4964 as[w->bindas].dir == HDAA_CTL_IN)) {
4967 found = hdaa_audio_ctl_source_amp(devinfo, w->nid, -1,
4968 w->ossdev, 1, 0, &minamp, &maxamp);
4969 hdaa_adjust_amp(w, w->ossdev, found, minamp, maxamp);
4970 } else if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
4971 found = hdaa_audio_ctl_dest_amp(devinfo, w->nid, -1,
4972 SOUND_MIXER_RECLEV, 0, &minamp, &maxamp);
4973 hdaa_adjust_amp(w, SOUND_MIXER_RECLEV, found, minamp, maxamp);
4974 } else if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
4975 as[w->bindas].dir == HDAA_CTL_OUT) {
4976 found = hdaa_audio_ctl_dest_amp(devinfo, w->nid, -1,
4977 SOUND_MIXER_VOLUME, 0, &minamp, &maxamp);
4978 hdaa_adjust_amp(w, SOUND_MIXER_VOLUME, found, minamp, maxamp);
4980 if (w->ossdev == SOUND_MIXER_IMIX) {
4981 minamp = maxamp = 0;
4982 found = hdaa_audio_ctl_source_amp(devinfo, w->nid, -1,
4983 w->ossdev, 1, 0, &minamp, &maxamp);
4984 if (minamp == maxamp) {
4985 /* If we are unable to control input monitor
4986 as source - try to control it as destination. */
4987 found += hdaa_audio_ctl_dest_amp(devinfo, w->nid, -1,
4988 w->ossdev, 0, &minamp, &maxamp);
4989 w->pflags |= HDAA_IMIX_AS_DST;
4991 hdaa_adjust_amp(w, w->ossdev, found, minamp, maxamp);
4993 if (w->pflags & HDAA_ADC_MONITOR) {
4994 for (j = 0; j < w->nconns; j++) {
4995 if (!w->connsenable[j])
4997 cw = hdaa_widget_get(devinfo, w->conns[j]);
4998 if (cw == NULL || cw->enable == 0)
5000 if (cw->bindas == -1)
5002 if (cw->bindas >= 0 &&
5003 as[cw->bindas].dir != HDAA_CTL_IN)
5005 minamp = maxamp = 0;
5006 found = hdaa_audio_ctl_dest_amp(devinfo,
5007 w->nid, j, SOUND_MIXER_IGAIN, 0,
5009 hdaa_adjust_amp(w, SOUND_MIXER_IGAIN,
5010 found, minamp, maxamp);
5017 hdaa_audio_prepare_pin_ctrl(struct hdaa_devinfo *devinfo)
5019 struct hdaa_audio_as *as = devinfo->as;
5020 struct hdaa_widget *w;
5024 for (i = 0; i < devinfo->nodecnt; i++) {
5025 w = &devinfo->widget[i];
5028 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
5032 pincap = w->wclass.pin.cap;
5034 /* Disable everything. */
5035 w->wclass.pin.ctrl &= ~(
5036 HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE |
5037 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE |
5038 HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE |
5039 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK);
5041 if (w->enable == 0) {
5042 /* Pin is unused so left it disabled. */
5044 } else if (w->waspin) {
5045 /* Enable input for beeper input. */
5046 w->wclass.pin.ctrl |=
5047 HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE;
5048 } else if (w->bindas < 0 || as[w->bindas].enable == 0) {
5049 /* Pin is unused so left it disabled. */
5051 } else if (as[w->bindas].dir == HDAA_CTL_IN) {
5052 /* Input pin, configure for input. */
5053 if (HDA_PARAM_PIN_CAP_INPUT_CAP(pincap))
5054 w->wclass.pin.ctrl |=
5055 HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE;
5057 if ((devinfo->quirks & HDAA_QUIRK_IVREF100) &&
5058 HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap))
5059 w->wclass.pin.ctrl |=
5060 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
5061 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_100);
5062 else if ((devinfo->quirks & HDAA_QUIRK_IVREF80) &&
5063 HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap))
5064 w->wclass.pin.ctrl |=
5065 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
5066 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_80);
5067 else if ((devinfo->quirks & HDAA_QUIRK_IVREF50) &&
5068 HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap))
5069 w->wclass.pin.ctrl |=
5070 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
5071 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_50);
5073 /* Output pin, configure for output. */
5074 if (HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap))
5075 w->wclass.pin.ctrl |=
5076 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
5078 if (HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap) &&
5079 (w->wclass.pin.config &
5080 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) ==
5081 HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT)
5082 w->wclass.pin.ctrl |=
5083 HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE;
5085 if ((devinfo->quirks & HDAA_QUIRK_OVREF100) &&
5086 HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap))
5087 w->wclass.pin.ctrl |=
5088 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
5089 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_100);
5090 else if ((devinfo->quirks & HDAA_QUIRK_OVREF80) &&
5091 HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap))
5092 w->wclass.pin.ctrl |=
5093 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
5094 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_80);
5095 else if ((devinfo->quirks & HDAA_QUIRK_OVREF50) &&
5096 HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap))
5097 w->wclass.pin.ctrl |=
5098 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
5099 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_50);
5105 hdaa_audio_ctl_commit(struct hdaa_devinfo *devinfo)
5107 struct hdaa_audio_ctl *ctl;
5111 while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) {
5112 if (ctl->enable == 0 || ctl->ossmask != 0) {
5113 /* Mute disabled and mixer controllable controls.
5114 * Last will be initialized by mixer_init().
5115 * This expected to reduce click on startup. */
5116 hdaa_audio_ctl_amp_set(ctl, HDAA_AMP_MUTE_ALL, 0, 0);
5119 /* Init fixed controls to 0dB amplification. */
5123 hdaa_audio_ctl_amp_set(ctl, HDAA_AMP_MUTE_NONE, z, z);
5128 hdaa_gpio_commit(struct hdaa_devinfo *devinfo)
5130 uint32_t gdata, gmask, gdir;
5133 numgpio = HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap);
5134 if (devinfo->gpio != 0 && numgpio != 0) {
5135 gdata = hda_command(devinfo->dev,
5136 HDA_CMD_GET_GPIO_DATA(0, devinfo->nid));
5137 gmask = hda_command(devinfo->dev,
5138 HDA_CMD_GET_GPIO_ENABLE_MASK(0, devinfo->nid));
5139 gdir = hda_command(devinfo->dev,
5140 HDA_CMD_GET_GPIO_DIRECTION(0, devinfo->nid));
5141 for (i = 0; i < numgpio; i++) {
5142 if ((devinfo->gpio & HDAA_GPIO_MASK(i)) ==
5147 } else if ((devinfo->gpio & HDAA_GPIO_MASK(i)) ==
5148 HDAA_GPIO_CLEAR(i)) {
5152 } else if ((devinfo->gpio & HDAA_GPIO_MASK(i)) ==
5153 HDAA_GPIO_DISABLE(i)) {
5155 } else if ((devinfo->gpio & HDAA_GPIO_MASK(i)) ==
5156 HDAA_GPIO_INPUT(i)) {
5162 device_printf(devinfo->dev, "GPIO commit\n");
5164 hda_command(devinfo->dev,
5165 HDA_CMD_SET_GPIO_ENABLE_MASK(0, devinfo->nid, gmask));
5166 hda_command(devinfo->dev,
5167 HDA_CMD_SET_GPIO_DIRECTION(0, devinfo->nid, gdir));
5168 hda_command(devinfo->dev,
5169 HDA_CMD_SET_GPIO_DATA(0, devinfo->nid, gdata));
5171 hdaa_dump_gpio(devinfo);
5177 hdaa_gpo_commit(struct hdaa_devinfo *devinfo)
5182 numgpo = HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap);
5183 if (devinfo->gpo != 0 && numgpo != 0) {
5184 gdata = hda_command(devinfo->dev,
5185 HDA_CMD_GET_GPO_DATA(0, devinfo->nid));
5186 for (i = 0; i < numgpo; i++) {
5187 if ((devinfo->gpio & HDAA_GPIO_MASK(i)) ==
5190 } else if ((devinfo->gpio & HDAA_GPIO_MASK(i)) ==
5191 HDAA_GPIO_CLEAR(i)) {
5196 device_printf(devinfo->dev, "GPO commit\n");
5198 hda_command(devinfo->dev,
5199 HDA_CMD_SET_GPO_DATA(0, devinfo->nid, gdata));
5201 hdaa_dump_gpo(devinfo);
5207 hdaa_audio_commit(struct hdaa_devinfo *devinfo)
5209 struct hdaa_widget *w;
5212 /* Commit controls. */
5213 hdaa_audio_ctl_commit(devinfo);
5215 /* Commit selectors, pins and EAPD. */
5216 for (i = 0; i < devinfo->nodecnt; i++) {
5217 w = &devinfo->widget[i];
5220 if (w->selconn == -1)
5223 hdaa_widget_connection_select(w, w->selconn);
5224 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX ||
5226 hda_command(devinfo->dev,
5227 HDA_CMD_SET_PIN_WIDGET_CTRL(0, w->nid,
5228 w->wclass.pin.ctrl));
5230 if (w->param.eapdbtl != HDA_INVALID) {
5233 val = w->param.eapdbtl;
5234 if (devinfo->quirks &
5236 val ^= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
5237 hda_command(devinfo->dev,
5238 HDA_CMD_SET_EAPD_BTL_ENABLE(0, w->nid,
5243 hdaa_gpio_commit(devinfo);
5244 hdaa_gpo_commit(devinfo);
5248 hdaa_powerup(struct hdaa_devinfo *devinfo)
5252 hda_command(devinfo->dev,
5253 HDA_CMD_SET_POWER_STATE(0,
5254 devinfo->nid, HDA_CMD_POWER_STATE_D0));
5257 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5258 hda_command(devinfo->dev,
5259 HDA_CMD_SET_POWER_STATE(0,
5260 i, HDA_CMD_POWER_STATE_D0));
5266 hdaa_pcmchannel_setup(struct hdaa_chan *ch)
5268 struct hdaa_devinfo *devinfo = ch->devinfo;
5269 struct hdaa_audio_as *as = devinfo->as;
5270 struct hdaa_widget *w;
5271 uint32_t cap, fmtcap, pcmcap;
5272 int i, j, ret, channels, onlystereo;
5275 ch->caps = hdaa_caps;
5276 ch->caps.fmtlist = ch->fmtlist;
5279 ch->pcmrates[0] = 48000;
5280 ch->pcmrates[1] = 0;
5281 ch->stripecap = 0xff;
5287 fmtcap = devinfo->supp_stream_formats;
5288 pcmcap = devinfo->supp_pcm_size_rate;
5290 for (i = 0; i < 16; i++) {
5291 /* Check as is correct */
5294 /* Cound only present DACs */
5295 if (as[ch->as].dacs[ch->asindex][i] <= 0)
5297 /* Ignore duplicates */
5298 for (j = 0; j < ret; j++) {
5299 if (ch->io[j] == as[ch->as].dacs[ch->asindex][i])
5305 w = hdaa_widget_get(devinfo, as[ch->as].dacs[ch->asindex][i]);
5306 if (w == NULL || w->enable == 0)
5308 cap = w->param.supp_stream_formats;
5309 if (!HDA_PARAM_SUPP_STREAM_FORMATS_PCM(cap) &&
5310 !HDA_PARAM_SUPP_STREAM_FORMATS_AC3(cap))
5312 /* Many CODECs does not declare AC3 support on SPDIF.
5313 I don't beleave that they doesn't support it! */
5314 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap))
5315 cap |= HDA_PARAM_SUPP_STREAM_FORMATS_AC3_MASK;
5318 pcmcap = w->param.supp_pcm_size_rate;
5321 pcmcap &= w->param.supp_pcm_size_rate;
5323 ch->io[ret++] = as[ch->as].dacs[ch->asindex][i];
5324 ch->stripecap &= w->wclass.conv.stripecap;
5325 /* Do not count redirection pin/dac channels. */
5326 if (i == 15 && as[ch->as].hpredir >= 0)
5328 channels += HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap) + 1;
5329 if (HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap) != 1)
5334 ch->channels = channels;
5336 if (as[ch->as].fakeredir)
5338 /* Standard speaks only about stereo pins and playback, ... */
5339 if ((!onlystereo) || as[ch->as].mixed)
5341 /* ..., but there it gives us info about speakers layout. */
5342 as[ch->as].pinset = pinset;
5344 ch->supp_stream_formats = fmtcap;
5345 ch->supp_pcm_size_rate = pcmcap;
5356 if (HDA_PARAM_SUPP_STREAM_FORMATS_PCM(fmtcap)) {
5357 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16BIT(pcmcap))
5359 else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8BIT(pcmcap))
5361 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(pcmcap))
5363 else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(pcmcap))
5365 else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(pcmcap))
5367 if (!(devinfo->quirks & HDAA_QUIRK_FORCESTEREO)) {
5368 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 1, 0);
5370 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 1, 0);
5372 if (channels >= 2) {
5373 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 2, 0);
5375 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 2, 0);
5377 if (channels >= 3 && !onlystereo) {
5378 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 3, 0);
5380 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 3, 0);
5381 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 3, 1);
5383 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 3, 1);
5385 if (channels >= 4) {
5386 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 4, 0);
5388 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 4, 0);
5390 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 4, 1);
5392 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 4, 1);
5395 if (channels >= 5 && !onlystereo) {
5396 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 5, 0);
5398 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 5, 0);
5399 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 5, 1);
5401 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 5, 1);
5403 if (channels >= 6) {
5404 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 6, 1);
5406 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 6, 1);
5408 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 6, 0);
5410 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 6, 0);
5413 if (channels >= 7 && !onlystereo) {
5414 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 7, 0);
5416 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 7, 0);
5417 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 7, 1);
5419 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 7, 1);
5421 if (channels >= 8) {
5422 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 8, 1);
5424 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 8, 1);
5427 if (HDA_PARAM_SUPP_STREAM_FORMATS_AC3(fmtcap)) {
5428 ch->fmtlist[i++] = SND_FORMAT(AFMT_AC3, 2, 0);
5429 if (channels >= 8) {
5430 ch->fmtlist[i++] = SND_FORMAT(AFMT_AC3, 8, 0);
5431 ch->fmtlist[i++] = SND_FORMAT(AFMT_AC3, 8, 1);
5436 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8KHZ(pcmcap))
5437 ch->pcmrates[i++] = 8000;
5438 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_11KHZ(pcmcap))
5439 ch->pcmrates[i++] = 11025;
5440 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16KHZ(pcmcap))
5441 ch->pcmrates[i++] = 16000;
5442 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_22KHZ(pcmcap))
5443 ch->pcmrates[i++] = 22050;
5444 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32KHZ(pcmcap))
5445 ch->pcmrates[i++] = 32000;
5446 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_44KHZ(pcmcap))
5447 ch->pcmrates[i++] = 44100;
5448 /* if (HDA_PARAM_SUPP_PCM_SIZE_RATE_48KHZ(pcmcap)) */
5449 ch->pcmrates[i++] = 48000;
5450 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_88KHZ(pcmcap))
5451 ch->pcmrates[i++] = 88200;
5452 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_96KHZ(pcmcap))
5453 ch->pcmrates[i++] = 96000;
5454 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_176KHZ(pcmcap))
5455 ch->pcmrates[i++] = 176400;
5456 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_192KHZ(pcmcap))
5457 ch->pcmrates[i++] = 192000;
5458 /* if (HDA_PARAM_SUPP_PCM_SIZE_RATE_384KHZ(pcmcap)) */
5459 ch->pcmrates[i] = 0;
5461 ch->caps.minspeed = ch->pcmrates[0];
5462 ch->caps.maxspeed = ch->pcmrates[i - 1];
5470 hdaa_prepare_pcms(struct hdaa_devinfo *devinfo)
5472 struct hdaa_audio_as *as = devinfo->as;
5473 int i, j, k, apdev = 0, ardev = 0, dpdev = 0, drdev = 0;
5475 for (i = 0; i < devinfo->ascnt; i++) {
5476 if (as[i].enable == 0)
5478 if (as[i].dir == HDAA_CTL_IN) {
5491 max(ardev, apdev) + max(drdev, dpdev);
5493 (struct hdaa_pcm_devinfo *)malloc(
5494 devinfo->num_devs * sizeof(struct hdaa_pcm_devinfo),
5495 M_HDAA, M_ZERO | M_NOWAIT);
5496 if (devinfo->devs == NULL) {
5497 device_printf(devinfo->dev,
5498 "Unable to allocate memory for devices\n");
5501 for (i = 0; i < devinfo->num_devs; i++) {
5502 devinfo->devs[i].index = i;
5503 devinfo->devs[i].devinfo = devinfo;
5504 devinfo->devs[i].playas = -1;
5505 devinfo->devs[i].recas = -1;
5506 devinfo->devs[i].digital = 255;
5508 for (i = 0; i < devinfo->ascnt; i++) {
5509 if (as[i].enable == 0)
5511 for (j = 0; j < devinfo->num_devs; j++) {
5512 if (devinfo->devs[j].digital != 255 &&
5513 (!devinfo->devs[j].digital) !=
5516 if (as[i].dir == HDAA_CTL_IN) {
5517 if (devinfo->devs[j].recas >= 0)
5519 devinfo->devs[j].recas = i;
5521 if (devinfo->devs[j].playas >= 0)
5523 devinfo->devs[j].playas = i;
5525 as[i].pdevinfo = &devinfo->devs[j];
5526 for (k = 0; k < as[i].num_chans; k++) {
5527 devinfo->chans[as[i].chans[k]].pdevinfo =
5530 devinfo->devs[j].digital = as[i].digital;
5537 hdaa_create_pcms(struct hdaa_devinfo *devinfo)
5541 for (i = 0; i < devinfo->num_devs; i++) {
5542 struct hdaa_pcm_devinfo *pdevinfo = &devinfo->devs[i];
5544 pdevinfo->dev = device_add_child(devinfo->dev, "pcm", -1);
5545 device_set_ivars(pdevinfo->dev, (void *)pdevinfo);
5550 hdaa_dump_ctls(struct hdaa_pcm_devinfo *pdevinfo, const char *banner, uint32_t flag)
5552 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
5553 struct hdaa_audio_ctl *ctl;
5555 int i, j, printed = 0;
5558 flag = ~(SOUND_MASK_VOLUME | SOUND_MASK_PCM |
5559 SOUND_MASK_CD | SOUND_MASK_LINE | SOUND_MASK_RECLEV |
5560 SOUND_MASK_MIC | SOUND_MASK_SPEAKER | SOUND_MASK_IGAIN |
5561 SOUND_MASK_OGAIN | SOUND_MASK_IMIX | SOUND_MASK_MONITOR);
5564 for (j = 0; j < SOUND_MIXER_NRDEVICES; j++) {
5565 if ((flag & (1 << j)) == 0)
5569 while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) {
5570 if (ctl->enable == 0 ||
5571 ctl->widget->enable == 0)
5573 if (!((pdevinfo->playas >= 0 &&
5574 ctl->widget->bindas == pdevinfo->playas) ||
5575 (pdevinfo->recas >= 0 &&
5576 ctl->widget->bindas == pdevinfo->recas) ||
5577 (ctl->widget->bindas == -2 && pdevinfo->index == 0)))
5579 if ((ctl->ossmask & (1 << j)) == 0)
5583 if (banner != NULL) {
5584 device_printf(pdevinfo->dev, "%s", banner);
5586 device_printf(pdevinfo->dev, "Unknown Ctl");
5588 printf(" (OSS: %s)",
5589 hdaa_audio_ctl_ossmixer_mask2allname(1 << j,
5591 if (pdevinfo->ossmask & (1 << j)) {
5592 printf(": %+d/%+ddB\n",
5593 pdevinfo->minamp[j] / 4,
5594 pdevinfo->maxamp[j] / 4);
5599 device_printf(pdevinfo->dev, " +- ctl %2d (nid %3d %s", i,
5601 (ctl->ndir == HDAA_CTL_IN)?"in ":"out");
5602 if (ctl->ndir == HDAA_CTL_IN && ctl->ndir == ctl->dir)
5603 printf(" %2d): ", ctl->index);
5606 if (ctl->step > 0) {
5607 printf("%+d/%+ddB (%d steps)%s\n",
5611 ctl->mute?" + mute":"");
5613 printf("%s\n", ctl->mute?"mute":"");
5617 device_printf(pdevinfo->dev, "\n");
5621 hdaa_dump_audio_formats(device_t dev, uint32_t fcap, uint32_t pcmcap)
5627 device_printf(dev, " Stream cap: 0x%08x", cap);
5628 if (HDA_PARAM_SUPP_STREAM_FORMATS_AC3(cap))
5630 if (HDA_PARAM_SUPP_STREAM_FORMATS_FLOAT32(cap))
5632 if (HDA_PARAM_SUPP_STREAM_FORMATS_PCM(cap))
5638 device_printf(dev, " PCM cap: 0x%08x", cap);
5639 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8BIT(cap))
5641 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16BIT(cap))
5643 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(cap))
5645 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(cap))
5647 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(cap))
5650 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8KHZ(cap))
5652 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_11KHZ(cap))
5654 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16KHZ(cap))
5656 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_22KHZ(cap))
5658 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32KHZ(cap))
5660 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_44KHZ(cap))
5663 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_88KHZ(cap))
5665 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_96KHZ(cap))
5667 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_176KHZ(cap))
5669 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_192KHZ(cap))
5676 hdaa_dump_pin(struct hdaa_widget *w)
5680 pincap = w->wclass.pin.cap;
5682 device_printf(w->devinfo->dev, " Pin cap: 0x%08x", pincap);
5683 if (HDA_PARAM_PIN_CAP_IMP_SENSE_CAP(pincap))
5685 if (HDA_PARAM_PIN_CAP_TRIGGER_REQD(pincap))
5687 if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(pincap))
5689 if (HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap))
5691 if (HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap))
5693 if (HDA_PARAM_PIN_CAP_INPUT_CAP(pincap))
5695 if (HDA_PARAM_PIN_CAP_BALANCED_IO_PINS(pincap))
5697 if (HDA_PARAM_PIN_CAP_HDMI(pincap))
5699 if (HDA_PARAM_PIN_CAP_VREF_CTRL(pincap)) {
5701 if (HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap))
5703 if (HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap))
5705 if (HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap))
5707 if (HDA_PARAM_PIN_CAP_VREF_CTRL_GROUND(pincap))
5709 if (HDA_PARAM_PIN_CAP_VREF_CTRL_HIZ(pincap))
5713 if (HDA_PARAM_PIN_CAP_EAPD_CAP(pincap))
5715 if (HDA_PARAM_PIN_CAP_DP(pincap))
5717 if (HDA_PARAM_PIN_CAP_HBR(pincap))
5720 device_printf(w->devinfo->dev, " Pin config: 0x%08x\n",
5721 w->wclass.pin.config);
5722 device_printf(w->devinfo->dev, " Pin control: 0x%08x", w->wclass.pin.ctrl);
5723 if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE)
5725 if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE)
5727 if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE)
5729 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) {
5730 if ((w->wclass.pin.ctrl &
5731 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK) == 0x03)
5733 else if ((w->wclass.pin.ctrl &
5734 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK) != 0)
5737 if ((w->wclass.pin.ctrl &
5738 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK) != 0)
5745 hdaa_dump_pin_config(struct hdaa_widget *w, uint32_t conf)
5748 device_printf(w->devinfo->dev, "%2d %08x %-2d %-2d "
5749 "%-13s %-5s %-7s %-10s %-7s %d%s\n",
5751 HDA_CONFIG_DEFAULTCONF_ASSOCIATION(conf),
5752 HDA_CONFIG_DEFAULTCONF_SEQUENCE(conf),
5753 HDA_DEVS[HDA_CONFIG_DEFAULTCONF_DEVICE(conf)],
5754 HDA_CONNS[HDA_CONFIG_DEFAULTCONF_CONNECTIVITY(conf)],
5755 HDA_CONNECTORS[HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE(conf)],
5756 HDA_LOCS[HDA_CONFIG_DEFAULTCONF_LOCATION(conf)],
5757 HDA_COLORS[HDA_CONFIG_DEFAULTCONF_COLOR(conf)],
5758 HDA_CONFIG_DEFAULTCONF_MISC(conf),
5759 (w->enable == 0)?" DISA":"");
5763 hdaa_dump_pin_configs(struct hdaa_devinfo *devinfo)
5765 struct hdaa_widget *w;
5768 device_printf(devinfo->dev, "nid 0x as seq "
5769 "device conn jack loc color misc\n");
5770 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5771 w = hdaa_widget_get(devinfo, i);
5774 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
5776 hdaa_dump_pin_config(w, w->wclass.pin.config);
5781 hdaa_dump_amp(device_t dev, uint32_t cap, char *banner)
5783 int offset, size, step;
5785 offset = HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(cap);
5786 size = HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(cap);
5787 step = HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(cap);
5788 device_printf(dev, " %s amp: 0x%08x "
5789 "mute=%d step=%d size=%d offset=%d (%+d/%+ddB)\n",
5791 HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(cap),
5793 ((0 - offset) * (size + 1)) / 4,
5794 ((step - offset) * (size + 1)) / 4);
5798 hdaa_dump_nodes(struct hdaa_devinfo *devinfo)
5800 struct hdaa_widget *w, *cw;
5804 device_printf(devinfo->dev, "\n");
5805 device_printf(devinfo->dev, "Default parameters:\n");
5806 hdaa_dump_audio_formats(devinfo->dev,
5807 devinfo->supp_stream_formats,
5808 devinfo->supp_pcm_size_rate);
5809 hdaa_dump_amp(devinfo->dev, devinfo->inamp_cap, " Input");
5810 hdaa_dump_amp(devinfo->dev, devinfo->outamp_cap, "Output");
5811 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5812 w = hdaa_widget_get(devinfo, i);
5814 device_printf(devinfo->dev, "Ghost widget nid=%d\n", i);
5817 device_printf(devinfo->dev, "\n");
5818 device_printf(devinfo->dev, " nid: %d%s\n", w->nid,
5819 (w->enable == 0) ? " [DISABLED]" : "");
5820 device_printf(devinfo->dev, " Name: %s\n", w->name);
5821 device_printf(devinfo->dev, " Widget cap: 0x%08x",
5822 w->param.widget_cap);
5823 if (w->param.widget_cap & 0x0ee1) {
5824 if (HDA_PARAM_AUDIO_WIDGET_CAP_LR_SWAP(w->param.widget_cap))
5826 if (HDA_PARAM_AUDIO_WIDGET_CAP_POWER_CTRL(w->param.widget_cap))
5828 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap))
5830 if (HDA_PARAM_AUDIO_WIDGET_CAP_UNSOL_CAP(w->param.widget_cap))
5832 if (HDA_PARAM_AUDIO_WIDGET_CAP_PROC_WIDGET(w->param.widget_cap))
5834 if (HDA_PARAM_AUDIO_WIDGET_CAP_STRIPE(w->param.widget_cap))
5835 printf(" STRIPE(x%d)",
5836 1 << (fls(w->wclass.conv.stripecap) - 1));
5837 j = HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap);
5841 printf(" %dCH", j + 1);
5844 if (w->bindas != -1) {
5845 device_printf(devinfo->dev, " Association: %d (0x%04x)\n",
5846 w->bindas, w->bindseqmask);
5848 if (w->ossmask != 0 || w->ossdev >= 0) {
5849 device_printf(devinfo->dev, " OSS: %s",
5850 hdaa_audio_ctl_ossmixer_mask2allname(w->ossmask, buf, sizeof(buf)));
5852 printf(" (%s)", ossnames[w->ossdev]);
5855 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT ||
5856 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
5857 hdaa_dump_audio_formats(devinfo->dev,
5858 w->param.supp_stream_formats,
5859 w->param.supp_pcm_size_rate);
5860 } else if (w->type ==
5861 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX || w->waspin)
5863 if (w->param.eapdbtl != HDA_INVALID)
5864 device_printf(devinfo->dev, " EAPD: 0x%08x\n",
5866 if (HDA_PARAM_AUDIO_WIDGET_CAP_OUT_AMP(w->param.widget_cap) &&
5867 w->param.outamp_cap != 0)
5868 hdaa_dump_amp(devinfo->dev, w->param.outamp_cap, "Output");
5869 if (HDA_PARAM_AUDIO_WIDGET_CAP_IN_AMP(w->param.widget_cap) &&
5870 w->param.inamp_cap != 0)
5871 hdaa_dump_amp(devinfo->dev, w->param.inamp_cap, " Input");
5873 device_printf(devinfo->dev, " Connections: %d\n", w->nconns);
5874 for (j = 0; j < w->nconns; j++) {
5875 cw = hdaa_widget_get(devinfo, w->conns[j]);
5876 device_printf(devinfo->dev, " + %s<- nid=%d [%s]",
5877 (w->connsenable[j] == 0)?"[DISABLED] ":"",
5878 w->conns[j], (cw == NULL) ? "GHOST!" : cw->name);
5880 printf(" [UNKNOWN]");
5881 else if (cw->enable == 0)
5882 printf(" [DISABLED]");
5883 if (w->nconns > 1 && w->selconn == j && w->type !=
5884 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
5885 printf(" (selected)");
5893 hdaa_dump_dst_nid(struct hdaa_pcm_devinfo *pdevinfo, nid_t nid, int depth)
5895 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
5896 struct hdaa_widget *w, *cw;
5900 if (depth > HDA_PARSE_MAXDEPTH)
5903 w = hdaa_widget_get(devinfo, nid);
5904 if (w == NULL || w->enable == 0)
5908 device_printf(pdevinfo->dev, "%*s", 4, "");
5910 device_printf(pdevinfo->dev, "%*s + <- ", 4 + (depth - 1) * 7, "");
5911 printf("nid=%d [%s]", w->nid, w->name);
5914 if (w->ossmask == 0) {
5918 printf(" [src: %s]",
5919 hdaa_audio_ctl_ossmixer_mask2allname(
5920 w->ossmask, buf, sizeof(buf)));
5921 if (w->ossdev >= 0) {
5928 for (i = 0; i < w->nconns; i++) {
5929 if (w->connsenable[i] == 0)
5931 cw = hdaa_widget_get(devinfo, w->conns[i]);
5932 if (cw == NULL || cw->enable == 0 || cw->bindas == -1)
5934 hdaa_dump_dst_nid(pdevinfo, w->conns[i], depth + 1);
5940 hdaa_dump_dac(struct hdaa_pcm_devinfo *pdevinfo)
5942 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
5943 struct hdaa_audio_as *as;
5944 struct hdaa_widget *w;
5948 if (pdevinfo->playas < 0)
5951 device_printf(pdevinfo->dev, "Playback:\n");
5953 chid = devinfo->as[pdevinfo->playas].chans[0];
5954 hdaa_dump_audio_formats(pdevinfo->dev,
5955 devinfo->chans[chid].supp_stream_formats,
5956 devinfo->chans[chid].supp_pcm_size_rate);
5957 for (i = 0; i < devinfo->as[pdevinfo->playas].num_chans; i++) {
5958 chid = devinfo->as[pdevinfo->playas].chans[i];
5959 device_printf(pdevinfo->dev, " DAC:");
5960 for (nids = devinfo->chans[chid].io; *nids != -1; nids++)
5961 printf(" %d", *nids);
5965 as = &devinfo->as[pdevinfo->playas];
5966 for (i = 0; i < 16; i++) {
5967 if (as->pins[i] <= 0)
5969 w = hdaa_widget_get(devinfo, as->pins[i]);
5970 if (w == NULL || w->enable == 0)
5972 device_printf(pdevinfo->dev, "\n");
5973 hdaa_dump_dst_nid(pdevinfo, as->pins[i], 0);
5975 device_printf(pdevinfo->dev, "\n");
5979 hdaa_dump_adc(struct hdaa_pcm_devinfo *pdevinfo)
5981 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
5982 struct hdaa_widget *w;
5986 if (pdevinfo->recas < 0)
5989 device_printf(pdevinfo->dev, "Record:\n");
5991 chid = devinfo->as[pdevinfo->recas].chans[0];
5992 hdaa_dump_audio_formats(pdevinfo->dev,
5993 devinfo->chans[chid].supp_stream_formats,
5994 devinfo->chans[chid].supp_pcm_size_rate);
5995 for (i = 0; i < devinfo->as[pdevinfo->recas].num_chans; i++) {
5996 chid = devinfo->as[pdevinfo->recas].chans[i];
5997 device_printf(pdevinfo->dev, " ADC:");
5998 for (nids = devinfo->chans[chid].io; *nids != -1; nids++)
5999 printf(" %d", *nids);
6003 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
6004 w = hdaa_widget_get(devinfo, i);
6005 if (w == NULL || w->enable == 0)
6007 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT)
6009 if (w->bindas != pdevinfo->recas)
6011 device_printf(pdevinfo->dev, "\n");
6012 hdaa_dump_dst_nid(pdevinfo, i, 0);
6014 device_printf(pdevinfo->dev, "\n");
6018 hdaa_dump_mix(struct hdaa_pcm_devinfo *pdevinfo)
6020 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
6021 struct hdaa_widget *w;
6025 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
6026 w = hdaa_widget_get(devinfo, i);
6027 if (w == NULL || w->enable == 0)
6029 if (w->ossdev != SOUND_MIXER_IMIX)
6031 if (w->bindas != pdevinfo->recas)
6035 device_printf(pdevinfo->dev, "Input Mix:\n");
6037 device_printf(pdevinfo->dev, "\n");
6038 hdaa_dump_dst_nid(pdevinfo, i, 0);
6041 device_printf(pdevinfo->dev, "\n");
6045 hdaa_pindump(device_t dev)
6047 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6048 struct hdaa_widget *w;
6049 uint32_t res, pincap, delay;
6052 device_printf(dev, "Dumping AFG pins:\n");
6053 device_printf(dev, "nid 0x as seq "
6054 "device conn jack loc color misc\n");
6055 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
6056 w = hdaa_widget_get(devinfo, i);
6057 if (w == NULL || w->type !=
6058 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
6060 hdaa_dump_pin_config(w, w->wclass.pin.config);
6061 pincap = w->wclass.pin.cap;
6062 device_printf(dev, " Caps: %2s %3s %2s %4s %4s",
6063 HDA_PARAM_PIN_CAP_INPUT_CAP(pincap)?"IN":"",
6064 HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap)?"OUT":"",
6065 HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap)?"HP":"",
6066 HDA_PARAM_PIN_CAP_EAPD_CAP(pincap)?"EAPD":"",
6067 HDA_PARAM_PIN_CAP_VREF_CTRL(pincap)?"VREF":"");
6068 if (HDA_PARAM_PIN_CAP_IMP_SENSE_CAP(pincap) ||
6069 HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(pincap)) {
6070 if (HDA_PARAM_PIN_CAP_TRIGGER_REQD(pincap)) {
6073 HDA_CMD_SET_PIN_SENSE(0, w->nid, 0));
6075 res = hda_command(dev,
6076 HDA_CMD_GET_PIN_SENSE(0, w->nid));
6077 if (res != 0x7fffffff && res != 0xffffffff)
6080 } while (++delay < 10000);
6083 res = hda_command(dev, HDA_CMD_GET_PIN_SENSE(0,
6086 printf(" Sense: 0x%08x (%sconnected%s)", res,
6087 (res & HDA_CMD_GET_PIN_SENSE_PRESENCE_DETECT) ?
6089 (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap) &&
6090 (res & HDA_CMD_GET_PIN_SENSE_ELD_VALID)) ?
6091 ", ELD valid" : "");
6093 printf(" delay %dus", delay * 10);
6098 "NumGPIO=%d NumGPO=%d NumGPI=%d GPIWake=%d GPIUnsol=%d\n",
6099 HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap),
6100 HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap),
6101 HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap),
6102 HDA_PARAM_GPIO_COUNT_GPI_WAKE(devinfo->gpio_cap),
6103 HDA_PARAM_GPIO_COUNT_GPI_UNSOL(devinfo->gpio_cap));
6104 hdaa_dump_gpi(devinfo);
6105 hdaa_dump_gpio(devinfo);
6106 hdaa_dump_gpo(devinfo);
6110 hdaa_configure(device_t dev)
6112 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6113 struct hdaa_audio_ctl *ctl;
6117 device_printf(dev, "Applying built-in patches...\n");
6119 hdaa_patch(devinfo);
6121 device_printf(dev, "Applying local patches...\n");
6123 hdaa_local_patch(devinfo);
6124 hdaa_audio_postprocess(devinfo);
6126 device_printf(dev, "Parsing Ctls...\n");
6128 hdaa_audio_ctl_parse(devinfo);
6130 device_printf(dev, "Disabling nonaudio...\n");
6132 hdaa_audio_disable_nonaudio(devinfo);
6134 device_printf(dev, "Disabling useless...\n");
6136 hdaa_audio_disable_useless(devinfo);
6138 device_printf(dev, "Patched pins configuration:\n");
6139 hdaa_dump_pin_configs(devinfo);
6142 device_printf(dev, "Parsing pin associations...\n");
6144 hdaa_audio_as_parse(devinfo);
6146 device_printf(dev, "Building AFG tree...\n");
6148 hdaa_audio_build_tree(devinfo);
6150 device_printf(dev, "Disabling unassociated "
6153 hdaa_audio_disable_unas(devinfo);
6155 device_printf(dev, "Disabling nonselected "
6158 hdaa_audio_disable_notselected(devinfo);
6160 device_printf(dev, "Disabling useless...\n");
6162 hdaa_audio_disable_useless(devinfo);
6164 device_printf(dev, "Disabling "
6165 "crossassociatement connections...\n");
6167 hdaa_audio_disable_crossas(devinfo);
6169 device_printf(dev, "Disabling useless...\n");
6171 hdaa_audio_disable_useless(devinfo);
6173 device_printf(dev, "Binding associations to channels...\n");
6175 hdaa_audio_bind_as(devinfo);
6177 device_printf(dev, "Assigning names to signal sources...\n");
6179 hdaa_audio_assign_names(devinfo);
6181 device_printf(dev, "Preparing PCM devices...\n");
6183 hdaa_prepare_pcms(devinfo);
6185 device_printf(dev, "Assigning mixers to the tree...\n");
6187 hdaa_audio_assign_mixers(devinfo);
6189 device_printf(dev, "Preparing pin controls...\n");
6191 hdaa_audio_prepare_pin_ctrl(devinfo);
6193 device_printf(dev, "AFG commit...\n");
6195 hdaa_audio_commit(devinfo);
6197 device_printf(dev, "Applying direct built-in patches...\n");
6199 hdaa_patch_direct(devinfo);
6201 device_printf(dev, "Pin sense init...\n");
6203 hdaa_sense_init(devinfo);
6205 device_printf(dev, "Creating PCM devices...\n");
6207 hdaa_create_pcms(devinfo);
6210 if (devinfo->quirks != 0) {
6211 device_printf(dev, "FG config/quirks:");
6212 for (i = 0; i < HDAA_QUIRKS_TAB_LEN; i++) {
6213 if ((devinfo->quirks &
6214 hdaa_quirks_tab[i].value) ==
6215 hdaa_quirks_tab[i].value)
6216 printf(" %s", hdaa_quirks_tab[i].key);
6223 device_printf(dev, "\n");
6224 device_printf(dev, "+-----------+\n");
6225 device_printf(dev, "| HDA NODES |\n");
6226 device_printf(dev, "+-----------+\n");
6227 hdaa_dump_nodes(devinfo);
6229 device_printf(dev, "\n");
6230 device_printf(dev, "+----------------+\n");
6231 device_printf(dev, "| HDA AMPLIFIERS |\n");
6232 device_printf(dev, "+----------------+\n");
6233 device_printf(dev, "\n");
6235 while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) {
6236 device_printf(dev, "%3d: nid %3d %s (%s) index %d", i,
6237 (ctl->widget != NULL) ? ctl->widget->nid : -1,
6238 (ctl->ndir == HDAA_CTL_IN)?"in ":"out",
6239 (ctl->dir == HDAA_CTL_IN)?"in ":"out",
6241 if (ctl->childwidget != NULL)
6242 printf(" cnid %3d", ctl->childwidget->nid);
6245 printf(" ossmask=0x%08x\n",
6248 " mute: %d step: %3d size: %3d off: %3d%s\n",
6249 ctl->mute, ctl->step, ctl->size, ctl->offset,
6250 (ctl->enable == 0) ? " [DISABLED]" :
6251 ((ctl->ossmask == 0) ? " [UNUSED]" : ""));
6253 device_printf(dev, "\n");
6258 hdaa_unconfigure(device_t dev)
6260 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6261 struct hdaa_widget *w;
6265 device_printf(dev, "Pin sense deinit...\n");
6267 hdaa_sense_deinit(devinfo);
6268 free(devinfo->ctl, M_HDAA);
6269 devinfo->ctl = NULL;
6270 devinfo->ctlcnt = 0;
6271 free(devinfo->as, M_HDAA);
6274 free(devinfo->devs, M_HDAA);
6275 devinfo->devs = NULL;
6276 devinfo->num_devs = 0;
6277 free(devinfo->chans, M_HDAA);
6278 devinfo->chans = NULL;
6279 devinfo->num_chans = 0;
6280 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
6281 w = hdaa_widget_get(devinfo, i);
6291 for (j = 0; j < w->nconns; j++)
6292 w->connsenable[j] = 1;
6293 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
6294 w->wclass.pin.config = w->wclass.pin.newconf;
6295 if (w->eld != NULL) {
6297 free(w->eld, M_HDAA);
6304 hdaa_sysctl_gpi_state(SYSCTL_HANDLER_ARGS)
6306 struct hdaa_devinfo *devinfo = oidp->oid_arg1;
6307 device_t dev = devinfo->dev;
6309 int n = 0, i, numgpi;
6314 numgpi = HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap);
6316 data = hda_command(dev,
6317 HDA_CMD_GET_GPI_DATA(0, devinfo->nid));
6319 hdaa_unlock(devinfo);
6320 for (i = 0; i < numgpi; i++) {
6321 n += snprintf(buf + n, sizeof(buf) - n, "%s%d=%d",
6322 n != 0 ? " " : "", i, ((data >> i) & 1));
6324 return (sysctl_handle_string(oidp, buf, sizeof(buf), req));
6328 hdaa_sysctl_gpio_state(SYSCTL_HANDLER_ARGS)
6330 struct hdaa_devinfo *devinfo = oidp->oid_arg1;
6331 device_t dev = devinfo->dev;
6333 int n = 0, i, numgpio;
6334 uint32_t data = 0, enable = 0, dir = 0;
6338 numgpio = HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap);
6340 data = hda_command(dev,
6341 HDA_CMD_GET_GPIO_DATA(0, devinfo->nid));
6342 enable = hda_command(dev,
6343 HDA_CMD_GET_GPIO_ENABLE_MASK(0, devinfo->nid));
6344 dir = hda_command(dev,
6345 HDA_CMD_GET_GPIO_DIRECTION(0, devinfo->nid));
6347 hdaa_unlock(devinfo);
6348 for (i = 0; i < numgpio; i++) {
6349 n += snprintf(buf + n, sizeof(buf) - n, "%s%d=",
6350 n != 0 ? " " : "", i);
6351 if ((enable & (1 << i)) == 0) {
6352 n += snprintf(buf + n, sizeof(buf) - n, "disabled");
6355 n += snprintf(buf + n, sizeof(buf) - n, "%sput(%d)",
6356 ((dir >> i) & 1) ? "out" : "in", ((data >> i) & 1));
6358 return (sysctl_handle_string(oidp, buf, sizeof(buf), req));
6362 hdaa_sysctl_gpio_config(SYSCTL_HANDLER_ARGS)
6364 struct hdaa_devinfo *devinfo = oidp->oid_arg1;
6366 int error, n = 0, i, numgpio;
6369 gpio = devinfo->newgpio;
6370 numgpio = HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap);
6372 for (i = 0; i < numgpio; i++) {
6373 x = (gpio & HDAA_GPIO_MASK(i)) >> HDAA_GPIO_SHIFT(i);
6374 n += snprintf(buf + n, sizeof(buf) - n, "%s%d=%s",
6375 n != 0 ? " " : "", i, HDA_GPIO_ACTIONS[x]);
6377 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
6378 if (error != 0 || req->newptr == NULL)
6380 if (strncmp(buf, "0x", 2) == 0)
6381 gpio = strtol(buf + 2, NULL, 16);
6383 gpio = hdaa_gpio_patch(gpio, buf);
6385 devinfo->newgpio = devinfo->gpio = gpio;
6386 hdaa_gpio_commit(devinfo);
6387 hdaa_unlock(devinfo);
6392 hdaa_sysctl_gpo_state(SYSCTL_HANDLER_ARGS)
6394 struct hdaa_devinfo *devinfo = oidp->oid_arg1;
6395 device_t dev = devinfo->dev;
6397 int n = 0, i, numgpo;
6402 numgpo = HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap);
6404 data = hda_command(dev,
6405 HDA_CMD_GET_GPO_DATA(0, devinfo->nid));
6407 hdaa_unlock(devinfo);
6408 for (i = 0; i < numgpo; i++) {
6409 n += snprintf(buf + n, sizeof(buf) - n, "%s%d=%d",
6410 n != 0 ? " " : "", i, ((data >> i) & 1));
6412 return (sysctl_handle_string(oidp, buf, sizeof(buf), req));
6416 hdaa_sysctl_gpo_config(SYSCTL_HANDLER_ARGS)
6418 struct hdaa_devinfo *devinfo = oidp->oid_arg1;
6420 int error, n = 0, i, numgpo;
6423 gpo = devinfo->newgpo;
6424 numgpo = HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap);
6426 for (i = 0; i < numgpo; i++) {
6427 x = (gpo & HDAA_GPIO_MASK(i)) >> HDAA_GPIO_SHIFT(i);
6428 n += snprintf(buf + n, sizeof(buf) - n, "%s%d=%s",
6429 n != 0 ? " " : "", i, HDA_GPIO_ACTIONS[x]);
6431 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
6432 if (error != 0 || req->newptr == NULL)
6434 if (strncmp(buf, "0x", 2) == 0)
6435 gpo = strtol(buf + 2, NULL, 16);
6437 gpo = hdaa_gpio_patch(gpo, buf);
6439 devinfo->newgpo = devinfo->gpo = gpo;
6440 hdaa_gpo_commit(devinfo);
6441 hdaa_unlock(devinfo);
6446 hdaa_sysctl_reconfig(SYSCTL_HANDLER_ARGS)
6449 struct hdaa_devinfo *devinfo;
6452 dev = oidp->oid_arg1;
6453 devinfo = device_get_softc(dev);
6454 if (devinfo == NULL)
6457 error = sysctl_handle_int(oidp, &val, 0, req);
6458 if (error != 0 || req->newptr == NULL || val == 0)
6462 device_printf(dev, "Reconfiguration...\n");
6464 if ((error = device_delete_children(dev)) != 0)
6467 hdaa_unconfigure(dev);
6468 hdaa_configure(dev);
6469 hdaa_unlock(devinfo);
6470 bus_generic_attach(dev);
6472 device_printf(dev, "Reconfiguration done\n");
6478 hdaa_suspend(device_t dev)
6480 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6484 device_printf(dev, "Suspend...\n");
6488 device_printf(dev, "Stop streams...\n");
6490 for (i = 0; i < devinfo->num_chans; i++) {
6491 if (devinfo->chans[i].flags & HDAA_CHN_RUNNING) {
6492 devinfo->chans[i].flags |= HDAA_CHN_SUSPEND;
6493 hdaa_channel_stop(&devinfo->chans[i]);
6497 device_printf(dev, "Power down FG"
6498 " nid=%d to the D3 state...\n",
6501 hda_command(devinfo->dev,
6502 HDA_CMD_SET_POWER_STATE(0,
6503 devinfo->nid, HDA_CMD_POWER_STATE_D3));
6504 callout_stop(&devinfo->poll_jack);
6505 hdaa_unlock(devinfo);
6506 callout_drain(&devinfo->poll_jack);
6508 device_printf(dev, "Suspend done\n");
6514 hdaa_resume(device_t dev)
6516 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6520 device_printf(dev, "Resume...\n");
6524 device_printf(dev, "Power up audio FG nid=%d...\n",
6527 hdaa_powerup(devinfo);
6529 device_printf(dev, "AFG commit...\n");
6531 hdaa_audio_commit(devinfo);
6533 device_printf(dev, "Applying direct built-in patches...\n");
6535 hdaa_patch_direct(devinfo);
6537 device_printf(dev, "Pin sense init...\n");
6539 hdaa_sense_init(devinfo);
6541 hdaa_unlock(devinfo);
6542 for (i = 0; i < devinfo->num_devs; i++) {
6543 struct hdaa_pcm_devinfo *pdevinfo = &devinfo->devs[i];
6545 device_printf(pdevinfo->dev,
6546 "OSS mixer reinitialization...\n");
6548 if (mixer_reinit(pdevinfo->dev) == -1)
6549 device_printf(pdevinfo->dev,
6550 "unable to reinitialize the mixer\n");
6554 device_printf(dev, "Start streams...\n");
6556 for (i = 0; i < devinfo->num_chans; i++) {
6557 if (devinfo->chans[i].flags & HDAA_CHN_SUSPEND) {
6558 devinfo->chans[i].flags &= ~HDAA_CHN_SUSPEND;
6559 hdaa_channel_start(&devinfo->chans[i]);
6562 hdaa_unlock(devinfo);
6564 device_printf(dev, "Resume done\n");
6570 hdaa_probe(device_t dev)
6575 if (hda_get_node_type(dev) != HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO)
6577 pdesc = device_get_desc(device_get_parent(dev));
6578 snprintf(buf, sizeof(buf), "%.*s Audio Function Group",
6579 (int)(strlen(pdesc) - 10), pdesc);
6580 device_set_desc_copy(dev, buf);
6581 return (BUS_PROBE_DEFAULT);
6585 hdaa_attach(device_t dev)
6587 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6589 nid_t nid = hda_get_node_id(dev);
6592 devinfo->lock = HDAC_GET_MTX(device_get_parent(dev), dev);
6594 devinfo->newquirks = -1;
6595 devinfo->newgpio = -1;
6596 devinfo->newgpo = -1;
6597 callout_init(&devinfo->poll_jack, CALLOUT_MPSAFE);
6598 devinfo->poll_ival = hz;
6601 res = hda_command(dev,
6602 HDA_CMD_GET_PARAMETER(0 , nid, HDA_PARAM_SUB_NODE_COUNT));
6603 hdaa_unlock(devinfo);
6605 devinfo->nodecnt = HDA_PARAM_SUB_NODE_COUNT_TOTAL(res);
6606 devinfo->startnode = HDA_PARAM_SUB_NODE_COUNT_START(res);
6607 devinfo->endnode = devinfo->startnode + devinfo->nodecnt;
6610 device_printf(dev, "Subsystem ID: 0x%08x\n",
6611 hda_get_subsystem_id(dev));
6615 "Audio Function Group at nid=%d: %d subnodes %d-%d\n",
6616 nid, devinfo->nodecnt,
6617 devinfo->startnode, devinfo->endnode - 1);
6620 if (devinfo->nodecnt > 0)
6621 devinfo->widget = (struct hdaa_widget *)malloc(
6622 sizeof(*(devinfo->widget)) * devinfo->nodecnt, M_HDAA,
6625 devinfo->widget = NULL;
6629 device_printf(dev, "Powering up...\n");
6631 hdaa_powerup(devinfo);
6633 device_printf(dev, "Parsing audio FG...\n");
6635 hdaa_audio_parse(devinfo);
6637 device_printf(dev, "Original pins configuration:\n");
6638 hdaa_dump_pin_configs(devinfo);
6640 hdaa_configure(dev);
6641 hdaa_unlock(devinfo);
6643 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6644 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6645 "config", CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE,
6646 &devinfo->newquirks, sizeof(&devinfo->newquirks),
6647 hdaa_sysctl_quirks, "A", "Configuration options");
6648 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6649 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6650 "gpi_state", CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
6651 devinfo, sizeof(devinfo),
6652 hdaa_sysctl_gpi_state, "A", "GPI state");
6653 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6654 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6655 "gpio_state", CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
6656 devinfo, sizeof(devinfo),
6657 hdaa_sysctl_gpio_state, "A", "GPIO state");
6658 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6659 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6660 "gpio_config", CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE,
6661 devinfo, sizeof(devinfo),
6662 hdaa_sysctl_gpio_config, "A", "GPIO configuration");
6663 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6664 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6665 "gpo_state", CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
6666 devinfo, sizeof(devinfo),
6667 hdaa_sysctl_gpo_state, "A", "GPO state");
6668 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6669 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6670 "gpo_config", CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE,
6671 devinfo, sizeof(devinfo),
6672 hdaa_sysctl_gpo_config, "A", "GPO configuration");
6673 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6674 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6675 "reconfig", CTLTYPE_INT | CTLFLAG_RW,
6677 hdaa_sysctl_reconfig, "I", "Reprocess configuration");
6678 bus_generic_attach(dev);
6683 hdaa_detach(device_t dev)
6685 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6688 if ((error = device_delete_children(dev)) != 0)
6692 hdaa_unconfigure(dev);
6693 devinfo->poll_ival = 0;
6694 callout_stop(&devinfo->poll_jack);
6695 hdaa_unlock(devinfo);
6696 callout_drain(&devinfo->poll_jack);
6698 free(devinfo->widget, M_HDAA);
6703 hdaa_print_child(device_t dev, device_t child)
6705 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6706 struct hdaa_pcm_devinfo *pdevinfo =
6707 (struct hdaa_pcm_devinfo *)device_get_ivars(child);
6708 struct hdaa_audio_as *as;
6709 int retval, first = 1, i;
6711 retval = bus_print_child_header(dev, child);
6712 retval += printf(" at nid ");
6713 if (pdevinfo->playas >= 0) {
6714 as = &devinfo->as[pdevinfo->playas];
6715 for (i = 0; i < 16; i++) {
6716 if (as->pins[i] <= 0)
6718 retval += printf("%s%d", first ? "" : ",", as->pins[i]);
6722 if (pdevinfo->recas >= 0) {
6723 if (pdevinfo->playas >= 0) {
6724 retval += printf(" and ");
6727 as = &devinfo->as[pdevinfo->recas];
6728 for (i = 0; i < 16; i++) {
6729 if (as->pins[i] <= 0)
6731 retval += printf("%s%d", first ? "" : ",", as->pins[i]);
6735 retval += bus_print_child_footer(dev, child);
6741 hdaa_child_location_str(device_t dev, device_t child, char *buf,
6744 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6745 struct hdaa_pcm_devinfo *pdevinfo =
6746 (struct hdaa_pcm_devinfo *)device_get_ivars(child);
6747 struct hdaa_audio_as *as;
6748 int first = 1, i, len = 0;
6750 len += snprintf(buf + len, buflen - len, "nid=");
6751 if (pdevinfo->playas >= 0) {
6752 as = &devinfo->as[pdevinfo->playas];
6753 for (i = 0; i < 16; i++) {
6754 if (as->pins[i] <= 0)
6756 len += snprintf(buf + len, buflen - len,
6757 "%s%d", first ? "" : ",", as->pins[i]);
6761 if (pdevinfo->recas >= 0) {
6762 as = &devinfo->as[pdevinfo->recas];
6763 for (i = 0; i < 16; i++) {
6764 if (as->pins[i] <= 0)
6766 len += snprintf(buf + len, buflen - len,
6767 "%s%d", first ? "" : ",", as->pins[i]);
6775 hdaa_stream_intr(device_t dev, int dir, int stream)
6777 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6778 struct hdaa_chan *ch;
6781 for (i = 0; i < devinfo->num_chans; i++) {
6782 ch = &devinfo->chans[i];
6783 if (!(ch->flags & HDAA_CHN_RUNNING))
6785 if (ch->dir == ((dir == 1) ? PCMDIR_PLAY : PCMDIR_REC) &&
6786 ch->sid == stream) {
6787 hdaa_unlock(devinfo);
6795 hdaa_unsol_intr(device_t dev, uint32_t resp)
6797 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6798 struct hdaa_widget *w;
6802 device_printf(dev, "Unsolicited response %08x\n", resp);
6805 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
6806 w = hdaa_widget_get(devinfo, i);
6807 if (w == NULL || w->enable == 0 || w->type !=
6808 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
6810 if (w->unsol != tag)
6812 if (HDA_PARAM_PIN_CAP_DP(w->wclass.pin.cap) ||
6813 HDA_PARAM_PIN_CAP_HDMI(w->wclass.pin.cap))
6814 flags = resp & 0x03;
6818 hdaa_presence_handler(w);
6820 hdaa_eld_handler(w);
6824 static device_method_t hdaa_methods[] = {
6825 /* device interface */
6826 DEVMETHOD(device_probe, hdaa_probe),
6827 DEVMETHOD(device_attach, hdaa_attach),
6828 DEVMETHOD(device_detach, hdaa_detach),
6829 DEVMETHOD(device_suspend, hdaa_suspend),
6830 DEVMETHOD(device_resume, hdaa_resume),
6832 DEVMETHOD(bus_print_child, hdaa_print_child),
6833 DEVMETHOD(bus_child_location_str, hdaa_child_location_str),
6834 DEVMETHOD(hdac_stream_intr, hdaa_stream_intr),
6835 DEVMETHOD(hdac_unsol_intr, hdaa_unsol_intr),
6836 DEVMETHOD(hdac_pindump, hdaa_pindump),
6840 static driver_t hdaa_driver = {
6843 sizeof(struct hdaa_devinfo),
6846 static devclass_t hdaa_devclass;
6848 DRIVER_MODULE(snd_hda, hdacc, hdaa_driver, hdaa_devclass, 0, 0);
6851 hdaa_chan_formula(struct hdaa_devinfo *devinfo, int asid,
6852 char *buf, int buflen)
6854 struct hdaa_audio_as *as;
6857 as = &devinfo->as[asid];
6858 c = devinfo->chans[as->chans[0]].channels;
6860 snprintf(buf, buflen, "mono");
6862 if (as->hpredir < 0)
6865 snprintf(buf, buflen, "2.0");
6866 } else if (as->pinset == 0x0003)
6867 snprintf(buf, buflen, "3.1");
6868 else if (as->pinset == 0x0005 || as->pinset == 0x0011)
6869 snprintf(buf, buflen, "4.0");
6870 else if (as->pinset == 0x0007 || as->pinset == 0x0013)
6871 snprintf(buf, buflen, "5.1");
6872 else if (as->pinset == 0x0017)
6873 snprintf(buf, buflen, "7.1");
6875 snprintf(buf, buflen, "%dch", c);
6876 if (as->hpredir >= 0)
6877 strlcat(buf, "+HP", buflen);
6881 hdaa_chan_type(struct hdaa_devinfo *devinfo, int asid)
6883 struct hdaa_audio_as *as;
6884 struct hdaa_widget *w;
6887 as = &devinfo->as[asid];
6888 for (i = 0; i < 16; i++) {
6889 w = hdaa_widget_get(devinfo, as->pins[i]);
6890 if (w == NULL || w->enable == 0 || w->type !=
6891 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
6893 t1 = HDA_CONFIG_DEFAULTCONF_DEVICE(w->wclass.pin.config);
6905 hdaa_sysctl_32bit(SYSCTL_HANDLER_ARGS)
6907 struct hdaa_audio_as *as = (struct hdaa_audio_as *)oidp->oid_arg1;
6908 struct hdaa_pcm_devinfo *pdevinfo = as->pdevinfo;
6909 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
6910 struct hdaa_chan *ch;
6914 ch = &devinfo->chans[as->chans[0]];
6915 val = (ch->bit32 == 4) ? 32 : ((ch->bit32 == 3) ? 24 :
6916 ((ch->bit32 == 2) ? 20 : 0));
6917 error = sysctl_handle_int(oidp, &val, 0, req);
6918 if (error != 0 || req->newptr == NULL)
6920 pcmcap = ch->supp_pcm_size_rate;
6921 if (val == 32 && HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(pcmcap))
6923 else if (val == 24 && HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(pcmcap))
6925 else if (val == 20 && HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(pcmcap))
6929 for (i = 1; i < as->num_chans; i++)
6930 devinfo->chans[as->chans[i]].bit32 = ch->bit32;
6935 hdaa_pcm_probe(device_t dev)
6937 struct hdaa_pcm_devinfo *pdevinfo =
6938 (struct hdaa_pcm_devinfo *)device_get_ivars(dev);
6939 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
6941 char chans1[8], chans2[8];
6943 int loc1, loc2, t1, t2;
6945 if (pdevinfo->playas >= 0)
6946 loc1 = devinfo->as[pdevinfo->playas].location;
6948 loc1 = devinfo->as[pdevinfo->recas].location;
6949 if (pdevinfo->recas >= 0)
6950 loc2 = devinfo->as[pdevinfo->recas].location;
6955 if (loc1 >= 0 && HDA_LOCS[loc1][0] == '0')
6960 if (pdevinfo->playas >= 0) {
6961 hdaa_chan_formula(devinfo, pdevinfo->playas,
6962 chans1, sizeof(chans1));
6963 t1 = hdaa_chan_type(devinfo, pdevinfo->playas);
6965 if (pdevinfo->recas >= 0) {
6966 hdaa_chan_formula(devinfo, pdevinfo->recas,
6967 chans2, sizeof(chans2));
6968 t2 = hdaa_chan_type(devinfo, pdevinfo->recas);
6970 if (chans1[0] != 0 || chans2[0] != 0) {
6971 if (chans1[0] == 0 && pdevinfo->playas >= 0)
6972 snprintf(chans1, sizeof(chans1), "2.0");
6973 else if (chans2[0] == 0 && pdevinfo->recas >= 0)
6974 snprintf(chans2, sizeof(chans2), "2.0");
6975 if (strcmp(chans1, chans2) == 0)
6984 if (pdevinfo->digital)
6986 pdesc = device_get_desc(device_get_parent(dev));
6987 snprintf(buf, sizeof(buf), "%.*s (%s%s%s%s%s%s%s%s%s)",
6988 (int)(strlen(pdesc) - 21), pdesc,
6989 loc1 >= 0 ? HDA_LOCS[loc1] : "", loc1 >= 0 ? " " : "",
6990 (pdevinfo->digital == 0x7)?"HDMI/DP":
6991 ((pdevinfo->digital == 0x5)?"DisplayPort":
6992 ((pdevinfo->digital == 0x3)?"HDMI":
6993 ((pdevinfo->digital)?"Digital":"Analog"))),
6994 chans1[0] ? " " : "", chans1,
6995 chans2[0] ? "/" : "", chans2,
6996 t1 >= 0 ? " " : "", t1 >= 0 ? HDA_DEVS[t1] : "");
6997 device_set_desc_copy(dev, buf);
6998 return (BUS_PROBE_SPECIFIC);
7002 hdaa_pcm_attach(device_t dev)
7004 struct hdaa_pcm_devinfo *pdevinfo =
7005 (struct hdaa_pcm_devinfo *)device_get_ivars(dev);
7006 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
7007 struct hdaa_audio_as *as;
7008 struct snddev_info *d;
7009 char status[SND_STATUSLEN];
7012 pdevinfo->chan_size = pcm_getbuffersize(dev,
7013 HDA_BUFSZ_MIN, HDA_BUFSZ_DEFAULT, HDA_BUFSZ_MAX);
7016 hdaa_dump_dac(pdevinfo);
7017 hdaa_dump_adc(pdevinfo);
7018 hdaa_dump_mix(pdevinfo);
7019 hdaa_dump_ctls(pdevinfo, "Master Volume", SOUND_MASK_VOLUME);
7020 hdaa_dump_ctls(pdevinfo, "PCM Volume", SOUND_MASK_PCM);
7021 hdaa_dump_ctls(pdevinfo, "CD Volume", SOUND_MASK_CD);
7022 hdaa_dump_ctls(pdevinfo, "Microphone Volume", SOUND_MASK_MIC);
7023 hdaa_dump_ctls(pdevinfo, "Microphone2 Volume", SOUND_MASK_MONITOR);
7024 hdaa_dump_ctls(pdevinfo, "Line-in Volume", SOUND_MASK_LINE);
7025 hdaa_dump_ctls(pdevinfo, "Speaker/Beep Volume", SOUND_MASK_SPEAKER);
7026 hdaa_dump_ctls(pdevinfo, "Recording Level", SOUND_MASK_RECLEV);
7027 hdaa_dump_ctls(pdevinfo, "Input Mix Level", SOUND_MASK_IMIX);
7028 hdaa_dump_ctls(pdevinfo, "Input Monitoring Level", SOUND_MASK_IGAIN);
7029 hdaa_dump_ctls(pdevinfo, NULL, 0);
7032 if (resource_int_value(device_get_name(dev),
7033 device_get_unit(dev), "blocksize", &i) == 0 && i > 0) {
7035 if (i < HDA_BLK_MIN)
7037 pdevinfo->chan_blkcnt = pdevinfo->chan_size / i;
7039 while (pdevinfo->chan_blkcnt >> i)
7041 pdevinfo->chan_blkcnt = 1 << (i - 1);
7042 if (pdevinfo->chan_blkcnt < HDA_BDL_MIN)
7043 pdevinfo->chan_blkcnt = HDA_BDL_MIN;
7044 else if (pdevinfo->chan_blkcnt > HDA_BDL_MAX)
7045 pdevinfo->chan_blkcnt = HDA_BDL_MAX;
7047 pdevinfo->chan_blkcnt = HDA_BDL_DEFAULT;
7050 * We don't register interrupt handler with snd_setup_intr
7051 * in pcm device. Mark pcm device as MPSAFE manually.
7053 pcm_setflags(dev, pcm_getflags(dev) | SD_F_MPSAFE);
7056 device_printf(dev, "OSS mixer initialization...\n");
7058 if (mixer_init(dev, &hdaa_audio_ctl_ossmixer_class, pdevinfo) != 0)
7059 device_printf(dev, "Can't register mixer\n");
7062 device_printf(dev, "Registering PCM channels...\n");
7064 if (pcm_register(dev, pdevinfo, (pdevinfo->playas >= 0)?1:0,
7065 (pdevinfo->recas >= 0)?1:0) != 0)
7066 device_printf(dev, "Can't register PCM\n");
7068 pdevinfo->registered++;
7070 d = device_get_softc(dev);
7071 if (pdevinfo->playas >= 0) {
7072 as = &devinfo->as[pdevinfo->playas];
7073 for (i = 0; i < as->num_chans; i++)
7074 pcm_addchan(dev, PCMDIR_PLAY, &hdaa_channel_class,
7075 &devinfo->chans[as->chans[i]]);
7076 SYSCTL_ADD_PROC(&d->play_sysctl_ctx,
7077 SYSCTL_CHILDREN(d->play_sysctl_tree), OID_AUTO,
7078 "32bit", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
7079 as, sizeof(as), hdaa_sysctl_32bit, "I",
7080 "Resolution of 32bit samples (20/24/32bit)");
7082 if (pdevinfo->recas >= 0) {
7083 as = &devinfo->as[pdevinfo->recas];
7084 for (i = 0; i < as->num_chans; i++)
7085 pcm_addchan(dev, PCMDIR_REC, &hdaa_channel_class,
7086 &devinfo->chans[as->chans[i]]);
7087 SYSCTL_ADD_PROC(&d->rec_sysctl_ctx,
7088 SYSCTL_CHILDREN(d->rec_sysctl_tree), OID_AUTO,
7089 "32bit", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
7090 as, sizeof(as), hdaa_sysctl_32bit, "I",
7091 "Resolution of 32bit samples (20/24/32bit)");
7092 pdevinfo->autorecsrc = 2;
7093 resource_int_value(device_get_name(dev), device_get_unit(dev),
7094 "rec.autosrc", &pdevinfo->autorecsrc);
7095 SYSCTL_ADD_INT(&d->rec_sysctl_ctx,
7096 SYSCTL_CHILDREN(d->rec_sysctl_tree), OID_AUTO,
7097 "autosrc", CTLTYPE_INT | CTLFLAG_RW,
7098 &pdevinfo->autorecsrc, 0,
7099 "Automatic recording source selection");
7102 if (pdevinfo->mixer != NULL) {
7103 hdaa_audio_ctl_set_defaults(pdevinfo);
7105 if (pdevinfo->playas >= 0) {
7106 as = &devinfo->as[pdevinfo->playas];
7107 hdaa_channels_handler(as);
7109 if (pdevinfo->recas >= 0) {
7110 as = &devinfo->as[pdevinfo->recas];
7111 hdaa_autorecsrc_handler(as, NULL);
7112 hdaa_channels_handler(as);
7114 hdaa_unlock(devinfo);
7117 snprintf(status, SND_STATUSLEN, "on %s %s",
7118 device_get_nameunit(device_get_parent(dev)),
7119 PCM_KLDSTRING(snd_hda));
7120 pcm_setstatus(dev, status);
7126 hdaa_pcm_detach(device_t dev)
7128 struct hdaa_pcm_devinfo *pdevinfo =
7129 (struct hdaa_pcm_devinfo *)device_get_ivars(dev);
7132 if (pdevinfo->registered > 0) {
7133 err = pcm_unregister(dev);
7141 static device_method_t hdaa_pcm_methods[] = {
7142 /* device interface */
7143 DEVMETHOD(device_probe, hdaa_pcm_probe),
7144 DEVMETHOD(device_attach, hdaa_pcm_attach),
7145 DEVMETHOD(device_detach, hdaa_pcm_detach),
7149 static driver_t hdaa_pcm_driver = {
7155 DRIVER_MODULE(snd_hda_pcm, hdaa, hdaa_pcm_driver, pcm_devclass, 0, 0);
7156 MODULE_DEPEND(snd_hda, sound, SOUND_MINVER, SOUND_PREFVER, SOUND_MAXVER);
7157 MODULE_VERSION(snd_hda, 1);