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: head/sys/dev/sound/pci/hda/hdaa.c 273377 2014-10-21 07:31:21Z hselasky $");
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 },
75 #define HDA_PARSE_MAXDEPTH 10
77 MALLOC_DEFINE(M_HDAA, "hdaa", "HDA Audio");
79 static const char *HDA_COLORS[16] = {"Unknown", "Black", "Grey", "Blue",
80 "Green", "Red", "Orange", "Yellow", "Purple", "Pink", "Res.A", "Res.B",
81 "Res.C", "Res.D", "White", "Other"};
83 static const char *HDA_DEVS[16] = {"Line-out", "Speaker", "Headphones", "CD",
84 "SPDIF-out", "Digital-out", "Modem-line", "Modem-handset", "Line-in",
85 "AUX", "Mic", "Telephony", "SPDIF-in", "Digital-in", "Res.E", "Other"};
87 static const char *HDA_CONNS[4] = {"Jack", "None", "Fixed", "Both"};
89 static const char *HDA_CONNECTORS[16] = {
90 "Unknown", "1/8", "1/4", "ATAPI", "RCA", "Optical", "Digital", "Analog",
91 "DIN", "XLR", "RJ-11", "Combo", "0xc", "0xd", "0xe", "Other" };
93 static const char *HDA_LOCS[64] = {
94 "0x00", "Rear", "Front", "Left", "Right", "Top", "Bottom", "Rear-panel",
95 "Drive-bay", "0x09", "0x0a", "0x0b", "0x0c", "0x0d", "0x0e", "0x0f",
96 "Internal", "0x11", "0x12", "0x13", "0x14", "0x15", "0x16", "Riser",
97 "0x18", "Onboard", "0x1a", "0x1b", "0x1c", "0x1d", "0x1e", "0x1f",
98 "External", "Ext-Rear", "Ext-Front", "Ext-Left", "Ext-Right", "Ext-Top", "Ext-Bottom", "0x07",
99 "0x28", "0x29", "0x2a", "0x2b", "0x2c", "0x2d", "0x2e", "0x2f",
100 "Other", "0x31", "0x32", "0x33", "0x34", "0x35", "Other-Bott", "Lid-In",
101 "Lid-Out", "0x39", "0x3a", "0x3b", "0x3c", "0x3d", "0x3e", "0x3f" };
103 static const char *HDA_GPIO_ACTIONS[8] = {
104 "keep", "set", "clear", "disable", "input", "0x05", "0x06", "0x07"};
106 static const char *HDA_HDMI_CODING_TYPES[18] = {
107 "undefined", "LPCM", "AC-3", "MPEG1", "MP3", "MPEG2", "AAC-LC", "DTS",
108 "ATRAC", "DSD", "E-AC-3", "DTS-HD", "MLP", "DST", "WMAPro", "HE-AAC",
109 "HE-AACv2", "MPEG-Surround"
113 static uint32_t hdaa_fmt[] = {
114 SND_FORMAT(AFMT_S16_LE, 2, 0),
118 static struct pcmchan_caps hdaa_caps = {48000, 48000, hdaa_fmt, 0};
120 static const struct {
127 { 8000, 1, 0x0000, 0x0000, 0x0500 }, /* (48000 * 1) / 6 */
128 { 9600, 0, 0x0000, 0x0000, 0x0400 }, /* (48000 * 1) / 5 */
129 { 12000, 0, 0x0000, 0x0000, 0x0300 }, /* (48000 * 1) / 4 */
130 { 16000, 1, 0x0000, 0x0000, 0x0200 }, /* (48000 * 1) / 3 */
131 { 18000, 0, 0x0000, 0x1000, 0x0700 }, /* (48000 * 3) / 8 */
132 { 19200, 0, 0x0000, 0x0800, 0x0400 }, /* (48000 * 2) / 5 */
133 { 24000, 0, 0x0000, 0x0000, 0x0100 }, /* (48000 * 1) / 2 */
134 { 28800, 0, 0x0000, 0x1000, 0x0400 }, /* (48000 * 3) / 5 */
135 { 32000, 1, 0x0000, 0x0800, 0x0200 }, /* (48000 * 2) / 3 */
136 { 36000, 0, 0x0000, 0x1000, 0x0300 }, /* (48000 * 3) / 4 */
137 { 38400, 0, 0x0000, 0x1800, 0x0400 }, /* (48000 * 4) / 5 */
138 { 48000, 1, 0x0000, 0x0000, 0x0000 }, /* (48000 * 1) / 1 */
139 { 64000, 0, 0x0000, 0x1800, 0x0200 }, /* (48000 * 4) / 3 */
140 { 72000, 0, 0x0000, 0x1000, 0x0100 }, /* (48000 * 3) / 2 */
141 { 96000, 1, 0x0000, 0x0800, 0x0000 }, /* (48000 * 2) / 1 */
142 { 144000, 0, 0x0000, 0x1000, 0x0000 }, /* (48000 * 3) / 1 */
143 { 192000, 1, 0x0000, 0x1800, 0x0000 }, /* (48000 * 4) / 1 */
144 { 8820, 0, 0x4000, 0x0000, 0x0400 }, /* (44100 * 1) / 5 */
145 { 11025, 1, 0x4000, 0x0000, 0x0300 }, /* (44100 * 1) / 4 */
146 { 12600, 0, 0x4000, 0x0800, 0x0600 }, /* (44100 * 2) / 7 */
147 { 14700, 0, 0x4000, 0x0000, 0x0200 }, /* (44100 * 1) / 3 */
148 { 17640, 0, 0x4000, 0x0800, 0x0400 }, /* (44100 * 2) / 5 */
149 { 18900, 0, 0x4000, 0x1000, 0x0600 }, /* (44100 * 3) / 7 */
150 { 22050, 1, 0x4000, 0x0000, 0x0100 }, /* (44100 * 1) / 2 */
151 { 25200, 0, 0x4000, 0x1800, 0x0600 }, /* (44100 * 4) / 7 */
152 { 26460, 0, 0x4000, 0x1000, 0x0400 }, /* (44100 * 3) / 5 */
153 { 29400, 0, 0x4000, 0x0800, 0x0200 }, /* (44100 * 2) / 3 */
154 { 33075, 0, 0x4000, 0x1000, 0x0300 }, /* (44100 * 3) / 4 */
155 { 35280, 0, 0x4000, 0x1800, 0x0400 }, /* (44100 * 4) / 5 */
156 { 44100, 1, 0x4000, 0x0000, 0x0000 }, /* (44100 * 1) / 1 */
157 { 58800, 0, 0x4000, 0x1800, 0x0200 }, /* (44100 * 4) / 3 */
158 { 66150, 0, 0x4000, 0x1000, 0x0100 }, /* (44100 * 3) / 2 */
159 { 88200, 1, 0x4000, 0x0800, 0x0000 }, /* (44100 * 2) / 1 */
160 { 132300, 0, 0x4000, 0x1000, 0x0000 }, /* (44100 * 3) / 1 */
161 { 176400, 1, 0x4000, 0x1800, 0x0000 }, /* (44100 * 4) / 1 */
163 #define HDA_RATE_TAB_LEN (sizeof(hda_rate_tab) / sizeof(hda_rate_tab[0]))
165 static const char *ossnames[] = SOUND_DEVICE_NAMES;
167 /****************************************************************************
168 * Function prototypes
169 ****************************************************************************/
170 static int hdaa_pcmchannel_setup(struct hdaa_chan *);
172 static void hdaa_widget_connection_select(struct hdaa_widget *, uint8_t);
173 static void hdaa_audio_ctl_amp_set(struct hdaa_audio_ctl *,
175 static struct hdaa_audio_ctl *hdaa_audio_ctl_amp_get(struct hdaa_devinfo *,
176 nid_t, int, int, int);
177 static void hdaa_audio_ctl_amp_set_internal(struct hdaa_devinfo *,
178 nid_t, int, int, int, int, int, int);
180 static void hdaa_dump_pin_config(struct hdaa_widget *w, uint32_t conf);
183 hdaa_audio_ctl_ossmixer_mask2allname(uint32_t mask, char *buf, size_t len)
188 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
189 if (mask & (1 << i)) {
191 strlcat(buf, ", ", len);
192 strlcat(buf, ossnames[i], len);
199 static struct hdaa_audio_ctl *
200 hdaa_audio_ctl_each(struct hdaa_devinfo *devinfo, int *index)
202 if (devinfo == NULL ||
203 index == NULL || devinfo->ctl == NULL ||
204 devinfo->ctlcnt < 1 ||
205 *index < 0 || *index >= devinfo->ctlcnt)
207 return (&devinfo->ctl[(*index)++]);
210 static struct hdaa_audio_ctl *
211 hdaa_audio_ctl_amp_get(struct hdaa_devinfo *devinfo, nid_t nid, int dir,
214 struct hdaa_audio_ctl *ctl;
217 if (devinfo == NULL || devinfo->ctl == NULL)
221 while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) {
222 if (ctl->enable == 0)
224 if (ctl->widget->nid != nid)
226 if (dir && ctl->ndir != dir)
228 if (index >= 0 && ctl->ndir == HDAA_CTL_IN &&
229 ctl->dir == ctl->ndir && ctl->index != index)
232 if (found == cnt || cnt <= 0)
239 static const struct matrix {
240 struct pcmchan_matrix m;
243 { SND_CHN_MATRIX_MAP_1_0, 1 },
244 { SND_CHN_MATRIX_MAP_2_0, 1 },
245 { SND_CHN_MATRIX_MAP_2_1, 0 },
246 { SND_CHN_MATRIX_MAP_3_0, 0 },
247 { SND_CHN_MATRIX_MAP_3_1, 0 },
248 { SND_CHN_MATRIX_MAP_4_0, 1 },
249 { SND_CHN_MATRIX_MAP_4_1, 0 },
250 { SND_CHN_MATRIX_MAP_5_0, 0 },
251 { SND_CHN_MATRIX_MAP_5_1, 1 },
252 { SND_CHN_MATRIX_MAP_6_0, 0 },
253 { SND_CHN_MATRIX_MAP_6_1, 0 },
254 { SND_CHN_MATRIX_MAP_7_0, 0 },
255 { SND_CHN_MATRIX_MAP_7_1, 1 },
258 static const char *channel_names[] = SND_CHN_T_NAMES;
261 * Connected channels change handler.
264 hdaa_channels_handler(struct hdaa_audio_as *as)
266 struct hdaa_pcm_devinfo *pdevinfo = as->pdevinfo;
267 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
268 struct hdaa_chan *ch = &devinfo->chans[as->chans[0]];
269 struct hdaa_widget *w;
271 int i, total, sub, assume, channels;
272 uint16_t cpins, upins, tpins;
276 for (i = 0; i < 16; i++) {
277 if (as->pins[i] <= 0)
279 w = hdaa_widget_get(devinfo, as->pins[i]);
282 if (w->wclass.pin.connected == 1)
284 else if (w->wclass.pin.connected != 0)
286 if (w->eld != NULL && w->eld_len >= 8)
289 tpins = cpins | upins;
290 if (as->hpredir >= 0)
295 total = sub = assume = channels = 0;
297 /* Map CEA speakers to sound(4) channels. */
298 if (eld[7] & 0x01) /* Front Left/Right */
299 channels |= SND_CHN_T_MASK_FL | SND_CHN_T_MASK_FR;
300 if (eld[7] & 0x02) /* Low Frequency Effect */
301 channels |= SND_CHN_T_MASK_LF;
302 if (eld[7] & 0x04) /* Front Center */
303 channels |= SND_CHN_T_MASK_FC;
304 if (eld[7] & 0x08) { /* Rear Left/Right */
305 /* If we have both RLR and RLRC, report RLR as side. */
306 if (eld[7] & 0x40) /* Rear Left/Right Center */
307 channels |= SND_CHN_T_MASK_SL | SND_CHN_T_MASK_SR;
309 channels |= SND_CHN_T_MASK_BL | SND_CHN_T_MASK_BR;
311 if (eld[7] & 0x10) /* Rear center */
312 channels |= SND_CHN_T_MASK_BC;
313 if (eld[7] & 0x20) /* Front Left/Right Center */
314 channels |= SND_CHN_T_MASK_FLC | SND_CHN_T_MASK_FRC;
315 if (eld[7] & 0x40) /* Rear Left/Right Center */
316 channels |= SND_CHN_T_MASK_BL | SND_CHN_T_MASK_BR;
317 } else if (as->pinset != 0 && (tpins & 0xffe0) == 0) {
318 /* Map UAA speakers to sound(4) channels. */
320 channels |= SND_CHN_T_MASK_FL | SND_CHN_T_MASK_FR;
322 channels |= SND_CHN_T_MASK_FC | SND_CHN_T_MASK_LF;
324 channels |= SND_CHN_T_MASK_BL | SND_CHN_T_MASK_BR;
326 channels |= SND_CHN_T_MASK_FLC | SND_CHN_T_MASK_FRC;
327 if (tpins & 0x0010) {
328 /* If there is no back pin, report side as back. */
329 if ((as->pinset & 0x0004) == 0)
330 channels |= SND_CHN_T_MASK_BL | SND_CHN_T_MASK_BR;
332 channels |= SND_CHN_T_MASK_SL | SND_CHN_T_MASK_SR;
334 } else if (as->mixed) {
335 /* Mixed assoc can be only stereo or theoretically mono. */
336 if (ch->channels == 1)
337 channels |= SND_CHN_T_MASK_FC;
339 channels |= SND_CHN_T_MASK_FL | SND_CHN_T_MASK_FR;
341 if (channels) { /* We have some usable channels info. */
343 device_printf(pdevinfo->dev, "%s channel set is: ",
344 as->dir == HDAA_CTL_OUT ? "Playback" : "Recording");
345 for (i = 0; i < SND_CHN_T_MAX; i++)
346 if (channels & (1 << i))
347 kprintf("%s, ", channel_names[i]);
350 /* Look for maximal fitting matrix. */
351 for (i = 0; i < sizeof(matrixes) / sizeof(struct matrix); i++) {
352 if (as->pinset != 0 && matrixes[i].analog == 0)
354 if ((matrixes[i].m.mask & ~channels) == 0) {
355 total = matrixes[i].m.channels;
356 sub = matrixes[i].m.ext;
362 total = ch->channels;
363 sub = (total == 6 || total == 8) ? 1 : 0;
366 device_printf(pdevinfo->dev,
367 "%s channel matrix is: %s%d.%d (%s)\n",
368 as->dir == HDAA_CTL_OUT ? "Playback" : "Recording",
369 assume ? "unknown, assuming " : "", total - sub, sub,
370 cpins != 0 ? "connected" :
371 (upins != 0 ? "unknown" : "disconnected"));
376 * Headphones redirection change handler.
379 hdaa_hpredir_handler(struct hdaa_widget *w)
381 struct hdaa_devinfo *devinfo = w->devinfo;
382 struct hdaa_audio_as *as = &devinfo->as[w->bindas];
383 struct hdaa_widget *w1;
384 struct hdaa_audio_ctl *ctl;
386 int j, connected = w->wclass.pin.connected;
389 for (j = 0; j < w->nconns; j++) {
390 if (w->conns[j] == w->senseredir && connected)
392 else if (w->conns[j] != w->senseredir && !connected)
396 hdaa_widget_connection_select(w, j);
400 device_printf((as->pdevinfo && as->pdevinfo->dev) ?
401 as->pdevinfo->dev : devinfo->dev,
402 "Redirect output to: %s\n",
403 connected ? "headphones": "main");
405 /* (Un)Mute headphone pin. */
406 ctl = hdaa_audio_ctl_amp_get(devinfo,
407 w->nid, HDAA_CTL_IN, -1, 1);
408 if (ctl != NULL && ctl->mute) {
409 /* If pin has muter - use it. */
410 val = connected ? 0 : 1;
411 if (val != ctl->forcemute) {
412 ctl->forcemute = val;
413 hdaa_audio_ctl_amp_set(ctl,
414 HDAA_AMP_MUTE_DEFAULT,
415 HDAA_AMP_VOL_DEFAULT, HDAA_AMP_VOL_DEFAULT);
418 /* If there is no muter - disable pin output. */
420 val = w->wclass.pin.ctrl |
421 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
423 val = w->wclass.pin.ctrl &
424 ~HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
425 if (val != w->wclass.pin.ctrl) {
426 w->wclass.pin.ctrl = val;
427 hda_command(devinfo->dev,
428 HDA_CMD_SET_PIN_WIDGET_CTRL(0,
429 w->nid, w->wclass.pin.ctrl));
432 /* (Un)Mute other pins. */
433 for (j = 0; j < 15; j++) {
434 if (as->pins[j] <= 0)
436 w1 = hdaa_widget_get(devinfo, as->pins[j]);
441 * When senseredir is set (typically in hdaa_patches.c) in
442 * a microphone nid it specifies which mux nid is being
445 if (w->senseredir && w1) {
448 for (k = 0; k < w1->nconns; k++) {
449 if (w1->conns[k] == w->senseredir && connected)
451 else if (w1->conns[k] != w->senseredir && !connected)
455 hdaa_widget_connection_select(w1, k);
458 ctl = hdaa_audio_ctl_amp_get(devinfo,
459 as->pins[j], HDAA_CTL_IN, -1, 1);
460 if (ctl != NULL && ctl->mute) {
461 /* If pin has muter - use it. */
462 val = connected ? 1 : 0;
463 if (val == ctl->forcemute)
465 ctl->forcemute = val;
466 hdaa_audio_ctl_amp_set(ctl,
467 HDAA_AMP_MUTE_DEFAULT,
468 HDAA_AMP_VOL_DEFAULT, HDAA_AMP_VOL_DEFAULT);
471 /* If there is no muter - disable pin output. */
474 val = w1->wclass.pin.ctrl &
475 ~HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
477 val = w1->wclass.pin.ctrl |
478 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
479 if (val != w1->wclass.pin.ctrl) {
480 w1->wclass.pin.ctrl = val;
481 hda_command(devinfo->dev,
482 HDA_CMD_SET_PIN_WIDGET_CTRL(0,
483 w1->nid, w1->wclass.pin.ctrl));
490 * Recording source change handler.
493 hdaa_autorecsrc_handler(struct hdaa_audio_as *as, struct hdaa_widget *w)
495 struct hdaa_pcm_devinfo *pdevinfo = as->pdevinfo;
496 struct hdaa_devinfo *devinfo;
497 struct hdaa_widget *w1;
498 int i, mask, fullmask, prio, bestprio;
501 if (!as->mixed || pdevinfo == NULL || pdevinfo->mixer == NULL)
503 /* Don't touch anything if we asked not to. */
504 if (pdevinfo->autorecsrc == 0 ||
505 (pdevinfo->autorecsrc == 1 && w != NULL))
507 /* Don't touch anything if "mix" or "speaker" selected. */
508 if (pdevinfo->recsrc & (SOUND_MASK_IMIX | SOUND_MASK_SPEAKER))
510 /* Don't touch anything if several selected. */
511 if (ffs(pdevinfo->recsrc) != fls(pdevinfo->recsrc))
513 devinfo = pdevinfo->devinfo;
516 for (i = 0; i < 16; i++) {
517 if (as->pins[i] <= 0)
519 w1 = hdaa_widget_get(devinfo, as->pins[i]);
520 if (w1 == NULL || w1->enable == 0)
522 if (w1->wclass.pin.connected == 0)
524 prio = (w1->wclass.pin.connected == 1) ? 2 : 1;
527 if (prio > bestprio) {
531 mask |= (1 << w1->ossdev);
532 fullmask |= (1 << w1->ossdev);
536 /* Prefer newly connected input. */
537 if (w != NULL && (mask & (1 << w->ossdev)))
538 mask = (1 << w->ossdev);
539 /* Prefer previously selected input */
540 if (mask & pdevinfo->recsrc)
541 mask &= pdevinfo->recsrc;
543 if (mask & SOUND_MASK_MIC)
544 mask = SOUND_MASK_MIC;
545 /* Prefer monitor (2nd mic). */
546 if (mask & SOUND_MASK_MONITOR)
547 mask = SOUND_MASK_MONITOR;
548 /* Just take first one. */
549 mask = (1 << (ffs(mask) - 1));
551 hdaa_audio_ctl_ossmixer_mask2allname(mask, buf, sizeof(buf));
552 device_printf(pdevinfo->dev,
553 "Automatically set rec source to: %s\n", buf);
555 hdaa_unlock(devinfo);
556 mix_setrecsrc(pdevinfo->mixer, mask);
561 * Jack presence detection event handler.
564 hdaa_presence_handler(struct hdaa_widget *w)
566 struct hdaa_devinfo *devinfo = w->devinfo;
567 struct hdaa_audio_as *as;
571 if (w->enable == 0 || w->type !=
572 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
575 if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(w->wclass.pin.cap) == 0 ||
576 (HDA_CONFIG_DEFAULTCONF_MISC(w->wclass.pin.config) & 1) != 0)
579 res = hda_command(devinfo->dev, HDA_CMD_GET_PIN_SENSE(0, w->nid));
580 connected = (res & HDA_CMD_GET_PIN_SENSE_PRESENCE_DETECT) != 0;
581 if (devinfo->quirks & HDAA_QUIRK_SENSEINV)
582 connected = !connected;
583 old = w->wclass.pin.connected;
584 if (connected == old)
586 w->wclass.pin.connected = connected;
588 if (connected || old != 2) {
589 device_printf(devinfo->dev,
590 "Pin sense: nid=%d sense=0x%08x (%sconnected)\n",
591 w->nid, res, !connected ? "dis" : "");
595 as = &devinfo->as[w->bindas];
597 hdaa_hpredir_handler(w);
598 else if (as->hpredir >= 0 && as->pins[15] == w->nid)
599 hdaa_hpredir_handler(w);
601 if (as->dir == HDAA_CTL_IN && old != 2)
602 hdaa_autorecsrc_handler(as, w);
604 hdaa_channels_handler(as);
608 * Callback for poll based presence detection.
611 hdaa_jack_poll_callback(void *arg)
613 struct hdaa_devinfo *devinfo = arg;
614 struct hdaa_widget *w;
618 if (devinfo->poll_ival == 0) {
619 hdaa_unlock(devinfo);
622 for (i = 0; i < devinfo->ascnt; i++) {
623 if (devinfo->as[i].hpredir < 0)
625 w = hdaa_widget_get(devinfo, devinfo->as[i].pins[15]);
626 if (w == NULL || w->enable == 0 || w->type !=
627 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
629 hdaa_presence_handler(w);
631 callout_reset(&devinfo->poll_jack, devinfo->poll_ival,
632 hdaa_jack_poll_callback, devinfo);
633 hdaa_unlock(devinfo);
637 hdaa_eld_dump(struct hdaa_widget *w)
639 struct hdaa_devinfo *devinfo = w->devinfo;
640 device_t dev = devinfo->dev;
642 int len, mnl, i, sadc, fmt;
644 if (w->eld == NULL || w->eld_len < 4)
647 "ELD nid=%d: ELD_Ver=%u Baseline_ELD_Len=%u\n",
648 w->nid, w->eld[0] >> 3, w->eld[2]);
649 if ((w->eld[0] >> 3) != 0x02)
651 len = min(w->eld_len, (u_int)w->eld[2] * 4);
652 mnl = w->eld[4] & 0x1f;
654 "ELD nid=%d: CEA_EDID_Ver=%u MNL=%u\n",
655 w->nid, w->eld[4] >> 5, mnl);
656 sadc = w->eld[5] >> 4;
658 "ELD nid=%d: SAD_Count=%u Conn_Type=%u S_AI=%u HDCP=%u\n",
659 w->nid, sadc, (w->eld[5] >> 2) & 0x3,
660 (w->eld[5] >> 1) & 0x1, w->eld[5] & 0x1);
662 "ELD nid=%d: Aud_Synch_Delay=%ums\n",
663 w->nid, w->eld[6] * 2);
665 "ELD nid=%d: Channels=0x%b\n",
667 "\020\07RLRC\06FLRC\05RC\04RLR\03FC\02LFE\01FLR");
669 "ELD nid=%d: Port_ID=0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
670 w->nid, w->eld[8], w->eld[9], w->eld[10], w->eld[11],
671 w->eld[12], w->eld[13], w->eld[14], w->eld[15]);
673 "ELD nid=%d: Manufacturer_Name=0x%02x%02x\n",
674 w->nid, w->eld[16], w->eld[17]);
676 "ELD nid=%d: Product_Code=0x%02x%02x\n",
677 w->nid, w->eld[18], w->eld[19]);
679 "ELD nid=%d: Monitor_Name_String='%.*s'\n",
680 w->nid, mnl, &w->eld[20]);
681 for (i = 0; i < sadc; i++) {
682 sad = &w->eld[20 + mnl + i * 3];
683 fmt = (sad[0] >> 3) & 0x0f;
684 if (fmt == HDA_HDMI_CODING_TYPE_REF_CTX) {
685 fmt = (sad[2] >> 3) & 0x1f;
686 if (fmt < 1 || fmt > 3)
692 "ELD nid=%d: %s %dch freqs=0x%b",
693 w->nid, HDA_HDMI_CODING_TYPES[fmt], (sad[0] & 0x07) + 1,
694 sad[1], "\020\007192\006176\00596\00488\00348\00244\00132");
696 case HDA_HDMI_CODING_TYPE_LPCM:
697 kprintf(" sizes=0x%b",
698 sad[2] & 0x07, "\020\00324\00220\00116");
700 case HDA_HDMI_CODING_TYPE_AC3:
701 case HDA_HDMI_CODING_TYPE_MPEG1:
702 case HDA_HDMI_CODING_TYPE_MP3:
703 case HDA_HDMI_CODING_TYPE_MPEG2:
704 case HDA_HDMI_CODING_TYPE_AACLC:
705 case HDA_HDMI_CODING_TYPE_DTS:
706 case HDA_HDMI_CODING_TYPE_ATRAC:
707 kprintf(" max_bitrate=%d", sad[2] * 8000);
709 case HDA_HDMI_CODING_TYPE_WMAPRO:
710 kprintf(" profile=%d", sad[2] & 0x07);
718 hdaa_eld_handler(struct hdaa_widget *w)
720 struct hdaa_devinfo *devinfo = w->devinfo;
724 if (w->enable == 0 || w->type !=
725 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
728 if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(w->wclass.pin.cap) == 0 ||
729 (HDA_CONFIG_DEFAULTCONF_MISC(w->wclass.pin.config) & 1) != 0)
732 res = hda_command(devinfo->dev, HDA_CMD_GET_PIN_SENSE(0, w->nid));
733 if ((w->eld != 0) == ((res & HDA_CMD_GET_PIN_SENSE_ELD_VALID) != 0))
735 if (w->eld != NULL) {
737 kfree(w->eld, M_HDAA);
741 device_printf(devinfo->dev,
742 "Pin sense: nid=%d sense=0x%08x "
743 "(%sconnected, ELD %svalid)\n",
745 (res & HDA_CMD_GET_PIN_SENSE_PRESENCE_DETECT) ? "" : "dis",
746 (res & HDA_CMD_GET_PIN_SENSE_ELD_VALID) ? "" : "in");
748 if ((res & HDA_CMD_GET_PIN_SENSE_ELD_VALID) == 0)
751 res = hda_command(devinfo->dev,
752 HDA_CMD_GET_HDMI_DIP_SIZE(0, w->nid, 0x08));
753 if (res == HDA_INVALID)
755 w->eld_len = res & 0xff;
757 w->eld = kmalloc(w->eld_len, M_HDAA, M_ZERO | M_WAITOK);
758 if (w->eld == NULL) {
763 for (i = 0; i < w->eld_len; i++) {
764 res = hda_command(devinfo->dev,
765 HDA_CMD_GET_HDMI_ELDD(0, w->nid, i));
766 if (res & 0x80000000)
767 w->eld[i] = res & 0xff;
772 hdaa_channels_handler(&devinfo->as[w->bindas]);
776 * Pin sense initializer.
779 hdaa_sense_init(struct hdaa_devinfo *devinfo)
781 struct hdaa_audio_as *as;
782 struct hdaa_widget *w;
785 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
786 w = hdaa_widget_get(devinfo, i);
787 if (w == NULL || w->enable == 0 || w->type !=
788 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
790 if (HDA_PARAM_AUDIO_WIDGET_CAP_UNSOL_CAP(w->param.widget_cap)) {
792 w->unsol = HDAC_UNSOL_ALLOC(
793 device_get_parent(devinfo->dev),
794 devinfo->dev, w->nid);
795 hda_command(devinfo->dev,
796 HDA_CMD_SET_UNSOLICITED_RESPONSE(0, w->nid,
797 HDA_CMD_SET_UNSOLICITED_RESPONSE_ENABLE | w->unsol));
799 as = &devinfo->as[w->bindas];
800 if (as->hpredir >= 0 && as->pins[15] == w->nid) {
801 if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(w->wclass.pin.cap) == 0 ||
802 (HDA_CONFIG_DEFAULTCONF_MISC(w->wclass.pin.config) & 1) != 0) {
803 device_printf(devinfo->dev,
804 "No presence detection support at nid %d\n",
810 device_printf(devinfo->dev,
811 "Headphones redirection for "
812 "association %d nid=%d using %s.\n",
814 (w->unsol < 0) ? "polling" :
815 "unsolicited responses");
819 hdaa_presence_handler(w);
820 if (!HDA_PARAM_PIN_CAP_DP(w->wclass.pin.cap) &&
821 !HDA_PARAM_PIN_CAP_HDMI(w->wclass.pin.cap))
826 callout_reset(&devinfo->poll_jack, 1,
827 hdaa_jack_poll_callback, devinfo);
832 hdaa_sense_deinit(struct hdaa_devinfo *devinfo)
834 struct hdaa_widget *w;
837 callout_stop(&devinfo->poll_jack);
838 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
839 w = hdaa_widget_get(devinfo, i);
840 if (w == NULL || w->enable == 0 || w->type !=
841 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
845 hda_command(devinfo->dev,
846 HDA_CMD_SET_UNSOLICITED_RESPONSE(0, w->nid, 0));
848 device_get_parent(devinfo->dev), devinfo->dev,
855 hdaa_widget_pin_patch(uint32_t config, const char *str)
858 char *key, *value, *rest, *bad;
861 strlcpy(buf, str, sizeof(buf));
863 while ((key = strsep(&rest, "=")) != NULL) {
864 value = strsep(&rest, " \t");
867 ival = strtol(value, &bad, 10);
868 if (strcmp(key, "seq") == 0) {
869 config &= ~HDA_CONFIG_DEFAULTCONF_SEQUENCE_MASK;
870 config |= ((ival << HDA_CONFIG_DEFAULTCONF_SEQUENCE_SHIFT) &
871 HDA_CONFIG_DEFAULTCONF_SEQUENCE_MASK);
872 } else if (strcmp(key, "as") == 0) {
873 config &= ~HDA_CONFIG_DEFAULTCONF_ASSOCIATION_MASK;
874 config |= ((ival << HDA_CONFIG_DEFAULTCONF_ASSOCIATION_SHIFT) &
875 HDA_CONFIG_DEFAULTCONF_ASSOCIATION_MASK);
876 } else if (strcmp(key, "misc") == 0) {
877 config &= ~HDA_CONFIG_DEFAULTCONF_MISC_MASK;
878 config |= ((ival << HDA_CONFIG_DEFAULTCONF_MISC_SHIFT) &
879 HDA_CONFIG_DEFAULTCONF_MISC_MASK);
880 } else if (strcmp(key, "color") == 0) {
881 config &= ~HDA_CONFIG_DEFAULTCONF_COLOR_MASK;
883 config |= ((ival << HDA_CONFIG_DEFAULTCONF_COLOR_SHIFT) &
884 HDA_CONFIG_DEFAULTCONF_COLOR_MASK);
886 for (i = 0; i < 16; i++) {
887 if (strcasecmp(HDA_COLORS[i], value) == 0) {
888 config |= (i << HDA_CONFIG_DEFAULTCONF_COLOR_SHIFT);
892 } else if (strcmp(key, "ctype") == 0) {
893 config &= ~HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_MASK;
895 config |= ((ival << HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_SHIFT) &
896 HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_MASK);
898 for (i = 0; i < 16; i++) {
899 if (strcasecmp(HDA_CONNECTORS[i], value) == 0) {
900 config |= (i << HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_SHIFT);
904 } else if (strcmp(key, "device") == 0) {
905 config &= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
907 config |= ((ival << HDA_CONFIG_DEFAULTCONF_DEVICE_SHIFT) &
908 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK);
911 for (i = 0; i < 16; i++) {
912 if (strcasecmp(HDA_DEVS[i], value) == 0) {
913 config |= (i << HDA_CONFIG_DEFAULTCONF_DEVICE_SHIFT);
917 } else if (strcmp(key, "loc") == 0) {
918 config &= ~HDA_CONFIG_DEFAULTCONF_LOCATION_MASK;
920 config |= ((ival << HDA_CONFIG_DEFAULTCONF_LOCATION_SHIFT) &
921 HDA_CONFIG_DEFAULTCONF_LOCATION_MASK);
924 for (i = 0; i < 64; i++) {
925 if (strcasecmp(HDA_LOCS[i], value) == 0) {
926 config |= (i << HDA_CONFIG_DEFAULTCONF_LOCATION_SHIFT);
930 } else if (strcmp(key, "conn") == 0) {
931 config &= ~HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK;
933 config |= ((ival << HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_SHIFT) &
934 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK);
937 for (i = 0; i < 4; i++) {
938 if (strcasecmp(HDA_CONNS[i], value) == 0) {
939 config |= (i << HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_SHIFT);
949 hdaa_gpio_patch(uint32_t gpio, const char *str)
952 char *key, *value, *rest;
955 strlcpy(buf, str, sizeof(buf));
957 while ((key = strsep(&rest, "=")) != NULL) {
958 value = strsep(&rest, " \t");
961 ikey = strtol(key, NULL, 10);
962 if (ikey < 0 || ikey > 7)
964 for (i = 0; i < 7; i++) {
965 if (strcasecmp(HDA_GPIO_ACTIONS[i], value) == 0) {
966 gpio &= ~HDAA_GPIO_MASK(ikey);
967 gpio |= i << HDAA_GPIO_SHIFT(ikey);
976 hdaa_local_patch_pin(struct hdaa_widget *w)
978 device_t dev = w->devinfo->dev;
979 const char *res = NULL;
980 uint32_t config, orig;
983 config = orig = w->wclass.pin.config;
984 ksnprintf(buf, sizeof(buf), "cad%u.nid%u.config",
985 hda_get_codec_id(dev), w->nid);
986 if (resource_string_value(device_get_name(
987 device_get_parent(device_get_parent(dev))),
988 device_get_unit(device_get_parent(device_get_parent(dev))),
990 if (strncmp(res, "0x", 2) == 0) {
991 config = strtol(res + 2, NULL, 16);
993 config = hdaa_widget_pin_patch(config, res);
996 ksnprintf(buf, sizeof(buf), "nid%u.config", w->nid);
997 if (resource_string_value(device_get_name(dev), device_get_unit(dev),
999 if (strncmp(res, "0x", 2) == 0) {
1000 config = strtol(res + 2, NULL, 16);
1002 config = hdaa_widget_pin_patch(config, res);
1007 device_printf(w->devinfo->dev,
1008 "Patching pin config nid=%u 0x%08x -> 0x%08x\n",
1009 w->nid, orig, config);
1011 w->wclass.pin.newconf = w->wclass.pin.config = config;
1015 hdaa_dump_audio_formats_sb(struct sbuf *sb, uint32_t fcap, uint32_t pcmcap)
1021 sbuf_printf(sb, " Stream cap: 0x%08x", cap);
1022 if (HDA_PARAM_SUPP_STREAM_FORMATS_AC3(cap))
1023 sbuf_printf(sb, " AC3");
1024 if (HDA_PARAM_SUPP_STREAM_FORMATS_FLOAT32(cap))
1025 sbuf_printf(sb, " FLOAT32");
1026 if (HDA_PARAM_SUPP_STREAM_FORMATS_PCM(cap))
1027 sbuf_printf(sb, " PCM");
1028 sbuf_printf(sb, "\n");
1032 sbuf_printf(sb, " PCM cap: 0x%08x", cap);
1033 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8BIT(cap))
1034 sbuf_printf(sb, " 8");
1035 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16BIT(cap))
1036 sbuf_printf(sb, " 16");
1037 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(cap))
1038 sbuf_printf(sb, " 20");
1039 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(cap))
1040 sbuf_printf(sb, " 24");
1041 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(cap))
1042 sbuf_printf(sb, " 32");
1043 sbuf_printf(sb, " bits,");
1044 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8KHZ(cap))
1045 sbuf_printf(sb, " 8");
1046 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_11KHZ(cap))
1047 sbuf_printf(sb, " 11");
1048 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16KHZ(cap))
1049 sbuf_printf(sb, " 16");
1050 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_22KHZ(cap))
1051 sbuf_printf(sb, " 22");
1052 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32KHZ(cap))
1053 sbuf_printf(sb, " 32");
1054 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_44KHZ(cap))
1055 sbuf_printf(sb, " 44");
1056 sbuf_printf(sb, " 48");
1057 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_88KHZ(cap))
1058 sbuf_printf(sb, " 88");
1059 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_96KHZ(cap))
1060 sbuf_printf(sb, " 96");
1061 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_176KHZ(cap))
1062 sbuf_printf(sb, " 176");
1063 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_192KHZ(cap))
1064 sbuf_printf(sb, " 192");
1065 sbuf_printf(sb, " KHz\n");
1070 hdaa_dump_pin_sb(struct sbuf *sb, struct hdaa_widget *w)
1072 uint32_t pincap, conf;
1074 pincap = w->wclass.pin.cap;
1076 sbuf_printf(sb, " Pin cap: 0x%08x", pincap);
1077 if (HDA_PARAM_PIN_CAP_IMP_SENSE_CAP(pincap))
1078 sbuf_printf(sb, " ISC");
1079 if (HDA_PARAM_PIN_CAP_TRIGGER_REQD(pincap))
1080 sbuf_printf(sb, " TRQD");
1081 if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(pincap))
1082 sbuf_printf(sb, " PDC");
1083 if (HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap))
1084 sbuf_printf(sb, " HP");
1085 if (HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap))
1086 sbuf_printf(sb, " OUT");
1087 if (HDA_PARAM_PIN_CAP_INPUT_CAP(pincap))
1088 sbuf_printf(sb, " IN");
1089 if (HDA_PARAM_PIN_CAP_BALANCED_IO_PINS(pincap))
1090 sbuf_printf(sb, " BAL");
1091 if (HDA_PARAM_PIN_CAP_HDMI(pincap))
1092 sbuf_printf(sb, " HDMI");
1093 if (HDA_PARAM_PIN_CAP_VREF_CTRL(pincap)) {
1094 sbuf_printf(sb, " VREF[");
1095 if (HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap))
1096 sbuf_printf(sb, " 50");
1097 if (HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap))
1098 sbuf_printf(sb, " 80");
1099 if (HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap))
1100 sbuf_printf(sb, " 100");
1101 if (HDA_PARAM_PIN_CAP_VREF_CTRL_GROUND(pincap))
1102 sbuf_printf(sb, " GROUND");
1103 if (HDA_PARAM_PIN_CAP_VREF_CTRL_HIZ(pincap))
1104 sbuf_printf(sb, " HIZ");
1105 sbuf_printf(sb, " ]");
1107 if (HDA_PARAM_PIN_CAP_EAPD_CAP(pincap))
1108 sbuf_printf(sb, " EAPD");
1109 if (HDA_PARAM_PIN_CAP_DP(pincap))
1110 sbuf_printf(sb, " DP");
1111 if (HDA_PARAM_PIN_CAP_HBR(pincap))
1112 sbuf_printf(sb, " HBR");
1113 sbuf_printf(sb, "\n");
1114 conf = w->wclass.pin.config;
1115 sbuf_printf(sb, " Pin config: 0x%08x", conf);
1116 sbuf_printf(sb, " as=%d seq=%d "
1117 "device=%s conn=%s ctype=%s loc=%s color=%s misc=%d\n",
1118 HDA_CONFIG_DEFAULTCONF_ASSOCIATION(conf),
1119 HDA_CONFIG_DEFAULTCONF_SEQUENCE(conf),
1120 HDA_DEVS[HDA_CONFIG_DEFAULTCONF_DEVICE(conf)],
1121 HDA_CONNS[HDA_CONFIG_DEFAULTCONF_CONNECTIVITY(conf)],
1122 HDA_CONNECTORS[HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE(conf)],
1123 HDA_LOCS[HDA_CONFIG_DEFAULTCONF_LOCATION(conf)],
1124 HDA_COLORS[HDA_CONFIG_DEFAULTCONF_COLOR(conf)],
1125 HDA_CONFIG_DEFAULTCONF_MISC(conf));
1126 sbuf_printf(sb, " Pin control: 0x%08x", w->wclass.pin.ctrl);
1127 if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE)
1128 sbuf_printf(sb, " HP");
1129 if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE)
1130 sbuf_printf(sb, " IN");
1131 if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE)
1132 sbuf_printf(sb, " OUT");
1133 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) {
1134 if ((w->wclass.pin.ctrl &
1135 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK) == 0x03)
1136 sbuf_printf(sb, " HBR");
1137 else if ((w->wclass.pin.ctrl &
1138 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK) != 0)
1139 sbuf_printf(sb, " EPTs");
1141 if ((w->wclass.pin.ctrl &
1142 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK) != 0)
1143 sbuf_printf(sb, " VREFs");
1145 sbuf_printf(sb, "\n");
1149 hdaa_dump_amp_sb(struct sbuf *sb, uint32_t cap, const char *banner)
1151 int offset, size, step;
1153 offset = HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(cap);
1154 size = HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(cap);
1155 step = HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(cap);
1156 sbuf_printf(sb, " %s amp: 0x%08x "
1157 "mute=%d step=%d size=%d offset=%d (%+d/%+ddB)\n",
1159 HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(cap),
1161 ((0 - offset) * (size + 1)) / 4,
1162 ((step - offset) * (size + 1)) / 4);
1167 hdaa_sysctl_caps(SYSCTL_HANDLER_ARGS)
1169 struct hdaa_devinfo *devinfo;
1170 struct hdaa_widget *w, *cw;
1175 w = (struct hdaa_widget *)oidp->oid_arg1;
1176 devinfo = w->devinfo;
1177 sbuf_new_for_sysctl(&sb, NULL, 256, req);
1179 sbuf_printf(&sb, "%s%s\n", w->name,
1180 (w->enable == 0) ? " [DISABLED]" : "");
1181 sbuf_printf(&sb, " Widget cap: 0x%08x",
1182 w->param.widget_cap);
1183 if (w->param.widget_cap & 0x0ee1) {
1184 if (HDA_PARAM_AUDIO_WIDGET_CAP_LR_SWAP(w->param.widget_cap))
1185 sbuf_printf(&sb, " LRSWAP");
1186 if (HDA_PARAM_AUDIO_WIDGET_CAP_POWER_CTRL(w->param.widget_cap))
1187 sbuf_printf(&sb, " PWR");
1188 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap))
1189 sbuf_printf(&sb, " DIGITAL");
1190 if (HDA_PARAM_AUDIO_WIDGET_CAP_UNSOL_CAP(w->param.widget_cap))
1191 sbuf_printf(&sb, " UNSOL");
1192 if (HDA_PARAM_AUDIO_WIDGET_CAP_PROC_WIDGET(w->param.widget_cap))
1193 sbuf_printf(&sb, " PROC");
1194 if (HDA_PARAM_AUDIO_WIDGET_CAP_STRIPE(w->param.widget_cap))
1195 sbuf_printf(&sb, " STRIPE(x%d)",
1196 1 << (fls(w->wclass.conv.stripecap) - 1));
1197 j = HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap);
1199 sbuf_printf(&sb, " STEREO");
1201 sbuf_printf(&sb, " %dCH", j + 1);
1203 sbuf_printf(&sb, "\n");
1204 if (w->bindas != -1) {
1205 sbuf_printf(&sb, " Association: %d (0x%04x)\n",
1206 w->bindas, w->bindseqmask);
1208 if (w->ossmask != 0 || w->ossdev >= 0) {
1209 sbuf_printf(&sb, " OSS: %s",
1210 hdaa_audio_ctl_ossmixer_mask2allname(w->ossmask, buf, sizeof(buf)));
1212 sbuf_printf(&sb, " (%s)", ossnames[w->ossdev]);
1213 sbuf_printf(&sb, "\n");
1215 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT ||
1216 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
1217 hdaa_dump_audio_formats_sb(&sb,
1218 w->param.supp_stream_formats,
1219 w->param.supp_pcm_size_rate);
1220 } else if (w->type ==
1221 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX || w->waspin)
1222 hdaa_dump_pin_sb(&sb, w);
1223 if (w->param.eapdbtl != HDA_INVALID) {
1224 sbuf_printf(&sb, " EAPD: 0x%08x%s%s%s\n",
1226 (w->param.eapdbtl & HDA_CMD_SET_EAPD_BTL_ENABLE_LR_SWAP) ?
1228 (w->param.eapdbtl & HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD) ?
1230 (w->param.eapdbtl & HDA_CMD_SET_EAPD_BTL_ENABLE_BTL) ?
1233 if (HDA_PARAM_AUDIO_WIDGET_CAP_OUT_AMP(w->param.widget_cap) &&
1234 w->param.outamp_cap != 0)
1235 hdaa_dump_amp_sb(&sb, w->param.outamp_cap, "Output");
1236 if (HDA_PARAM_AUDIO_WIDGET_CAP_IN_AMP(w->param.widget_cap) &&
1237 w->param.inamp_cap != 0)
1238 hdaa_dump_amp_sb(&sb, w->param.inamp_cap, " Input");
1240 sbuf_printf(&sb, " Connections: %d\n", w->nconns);
1241 for (j = 0; j < w->nconns; j++) {
1242 cw = hdaa_widget_get(devinfo, w->conns[j]);
1243 sbuf_printf(&sb, " + %s<- nid=%d [%s]",
1244 (w->connsenable[j] == 0)?"[DISABLED] ":"",
1245 w->conns[j], (cw == NULL) ? "GHOST!" : cw->name);
1247 sbuf_printf(&sb, " [UNKNOWN]");
1248 else if (cw->enable == 0)
1249 sbuf_printf(&sb, " [DISABLED]");
1250 if (w->nconns > 1 && w->selconn == j && w->type !=
1251 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
1252 sbuf_printf(&sb, " (selected)");
1253 sbuf_printf(&sb, "\n");
1255 error = sbuf_finish(&sb);
1261 hdaa_sysctl_config(SYSCTL_HANDLER_ARGS)
1267 conf = *(uint32_t *)oidp->oid_arg1;
1268 ksnprintf(buf, sizeof(buf), "0x%08x as=%d seq=%d "
1269 "device=%s conn=%s ctype=%s loc=%s color=%s misc=%d",
1271 HDA_CONFIG_DEFAULTCONF_ASSOCIATION(conf),
1272 HDA_CONFIG_DEFAULTCONF_SEQUENCE(conf),
1273 HDA_DEVS[HDA_CONFIG_DEFAULTCONF_DEVICE(conf)],
1274 HDA_CONNS[HDA_CONFIG_DEFAULTCONF_CONNECTIVITY(conf)],
1275 HDA_CONNECTORS[HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE(conf)],
1276 HDA_LOCS[HDA_CONFIG_DEFAULTCONF_LOCATION(conf)],
1277 HDA_COLORS[HDA_CONFIG_DEFAULTCONF_COLOR(conf)],
1278 HDA_CONFIG_DEFAULTCONF_MISC(conf));
1279 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
1280 if (error != 0 || req->newptr == NULL)
1282 if (strncmp(buf, "0x", 2) == 0)
1283 conf = strtol(buf + 2, NULL, 16);
1285 conf = hdaa_widget_pin_patch(conf, buf);
1286 *(uint32_t *)oidp->oid_arg1 = conf;
1291 hdaa_config_fetch(const char *str, uint32_t *on, uint32_t *off)
1293 int i = 0, j, k, len, inv;
1296 while (str[i] != '\0' &&
1297 (str[i] == ',' || isspace(str[i]) != 0))
1302 while (str[j] != '\0' &&
1303 !(str[j] == ',' || isspace(str[j]) != 0))
1306 if (len > 2 && strncmp(str + i, "no", 2) == 0)
1310 for (k = 0; len > inv && k < nitems(hdaa_quirks_tab); k++) {
1311 if (strncmp(str + i + inv,
1312 hdaa_quirks_tab[k].key, len - inv) != 0)
1314 if (len - inv != strlen(hdaa_quirks_tab[k].key))
1317 *on |= hdaa_quirks_tab[k].value;
1318 *off &= ~hdaa_quirks_tab[k].value;
1320 *off |= hdaa_quirks_tab[k].value;
1321 *on &= ~hdaa_quirks_tab[k].value;
1330 hdaa_sysctl_quirks(SYSCTL_HANDLER_ARGS)
1333 int error, n = 0, i;
1334 uint32_t quirks, quirks_off;
1336 quirks = *(uint32_t *)oidp->oid_arg1;
1338 for (i = 0; i < nitems(hdaa_quirks_tab); i++) {
1339 if ((quirks & hdaa_quirks_tab[i].value) != 0)
1340 n += ksnprintf(buf + n, sizeof(buf) - n, "%s%s",
1341 n != 0 ? "," : "", hdaa_quirks_tab[i].key);
1343 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
1344 if (error != 0 || req->newptr == NULL)
1346 if (strncmp(buf, "0x", 2) == 0)
1347 quirks = strtol(buf + 2, NULL, 16);
1350 hdaa_config_fetch(buf, &quirks, &quirks_off);
1352 *(uint32_t *)oidp->oid_arg1 = quirks;
1357 hdaa_local_patch(struct hdaa_devinfo *devinfo)
1359 struct hdaa_widget *w;
1360 const char *res = NULL;
1361 uint32_t quirks_on = 0, quirks_off = 0, x;
1364 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
1365 w = hdaa_widget_get(devinfo, i);
1368 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
1369 hdaa_local_patch_pin(w);
1372 if (resource_string_value(device_get_name(devinfo->dev),
1373 device_get_unit(devinfo->dev), "config", &res) == 0) {
1374 if (res != NULL && strlen(res) > 0)
1375 hdaa_config_fetch(res, &quirks_on, &quirks_off);
1376 devinfo->quirks |= quirks_on;
1377 devinfo->quirks &= ~quirks_off;
1379 if (devinfo->newquirks == -1)
1380 devinfo->newquirks = devinfo->quirks;
1382 devinfo->quirks = devinfo->newquirks;
1384 device_printf(devinfo->dev,
1385 "Config options: 0x%08x\n", devinfo->quirks);
1388 if (resource_string_value(device_get_name(devinfo->dev),
1389 device_get_unit(devinfo->dev), "gpio_config", &res) == 0) {
1390 if (strncmp(res, "0x", 2) == 0) {
1391 devinfo->gpio = strtol(res + 2, NULL, 16);
1393 devinfo->gpio = hdaa_gpio_patch(devinfo->gpio, res);
1396 if (devinfo->newgpio == -1)
1397 devinfo->newgpio = devinfo->gpio;
1399 devinfo->gpio = devinfo->newgpio;
1400 if (devinfo->newgpo == -1)
1401 devinfo->newgpo = devinfo->gpo;
1403 devinfo->gpo = devinfo->newgpo;
1405 device_printf(devinfo->dev, "GPIO config options:");
1406 for (i = 0; i < 7; i++) {
1407 x = (devinfo->gpio & HDAA_GPIO_MASK(i)) >> HDAA_GPIO_SHIFT(i);
1409 kprintf(" %d=%s", i, HDA_GPIO_ACTIONS[x]);
1416 hdaa_widget_connection_parse(struct hdaa_widget *w)
1419 int i, j, max, ents, entnum;
1421 nid_t cnid, addcnid, prevcnid;
1425 res = hda_command(w->devinfo->dev,
1426 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_CONN_LIST_LENGTH));
1428 ents = HDA_PARAM_CONN_LIST_LENGTH_LIST_LENGTH(res);
1433 entnum = HDA_PARAM_CONN_LIST_LENGTH_LONG_FORM(res) ? 2 : 4;
1434 max = (sizeof(w->conns) / sizeof(w->conns[0])) - 1;
1437 #define CONN_RMASK(e) (1 << ((32 / (e)) - 1))
1438 #define CONN_NMASK(e) (CONN_RMASK(e) - 1)
1439 #define CONN_RESVAL(r, e, n) ((r) >> ((32 / (e)) * (n)))
1440 #define CONN_RANGE(r, e, n) (CONN_RESVAL(r, e, n) & CONN_RMASK(e))
1441 #define CONN_CNID(r, e, n) (CONN_RESVAL(r, e, n) & CONN_NMASK(e))
1443 for (i = 0; i < ents; i += entnum) {
1444 res = hda_command(w->devinfo->dev,
1445 HDA_CMD_GET_CONN_LIST_ENTRY(0, nid, i));
1446 for (j = 0; j < entnum; j++) {
1447 cnid = CONN_CNID(res, entnum, j);
1449 if (w->nconns < ents)
1450 device_printf(w->devinfo->dev,
1451 "WARNING: nid=%d has zero cnid "
1452 "entnum=%d j=%d index=%d "
1453 "entries=%d found=%d res=0x%08x\n",
1455 ents, w->nconns, res);
1459 if (cnid < w->devinfo->startnode ||
1460 cnid >= w->devinfo->endnode) {
1462 device_printf(w->devinfo->dev,
1463 "WARNING: nid=%d has cnid outside "
1464 "of the AFG range j=%d "
1465 "entnum=%d index=%d res=0x%08x\n",
1466 nid, j, entnum, i, res);
1469 if (CONN_RANGE(res, entnum, j) == 0)
1471 else if (prevcnid == 0 || prevcnid >= cnid) {
1472 device_printf(w->devinfo->dev,
1473 "WARNING: Invalid child range "
1474 "nid=%d index=%d j=%d entnum=%d "
1475 "prevcnid=%d cnid=%d res=0x%08x\n",
1476 nid, i, j, entnum, prevcnid,
1480 addcnid = prevcnid + 1;
1481 while (addcnid <= cnid) {
1482 if (w->nconns > max) {
1483 device_printf(w->devinfo->dev,
1484 "Adding %d (nid=%d): "
1485 "Max connection reached! max=%d\n",
1486 addcnid, nid, max + 1);
1489 w->connsenable[w->nconns] = 1;
1490 w->conns[w->nconns++] = addcnid++;
1501 hdaa_widget_parse(struct hdaa_widget *w)
1503 device_t dev = w->devinfo->dev;
1508 w->param.widget_cap = wcap = hda_command(dev,
1509 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_AUDIO_WIDGET_CAP));
1510 w->type = HDA_PARAM_AUDIO_WIDGET_CAP_TYPE(wcap);
1512 hdaa_widget_connection_parse(w);
1514 if (HDA_PARAM_AUDIO_WIDGET_CAP_OUT_AMP(wcap)) {
1515 if (HDA_PARAM_AUDIO_WIDGET_CAP_AMP_OVR(wcap))
1516 w->param.outamp_cap =
1518 HDA_CMD_GET_PARAMETER(0, nid,
1519 HDA_PARAM_OUTPUT_AMP_CAP));
1521 w->param.outamp_cap =
1522 w->devinfo->outamp_cap;
1524 w->param.outamp_cap = 0;
1526 if (HDA_PARAM_AUDIO_WIDGET_CAP_IN_AMP(wcap)) {
1527 if (HDA_PARAM_AUDIO_WIDGET_CAP_AMP_OVR(wcap))
1528 w->param.inamp_cap =
1530 HDA_CMD_GET_PARAMETER(0, nid,
1531 HDA_PARAM_INPUT_AMP_CAP));
1533 w->param.inamp_cap =
1534 w->devinfo->inamp_cap;
1536 w->param.inamp_cap = 0;
1538 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT ||
1539 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
1540 if (HDA_PARAM_AUDIO_WIDGET_CAP_FORMAT_OVR(wcap)) {
1541 cap = hda_command(dev,
1542 HDA_CMD_GET_PARAMETER(0, nid,
1543 HDA_PARAM_SUPP_STREAM_FORMATS));
1544 w->param.supp_stream_formats = (cap != 0) ? cap :
1545 w->devinfo->supp_stream_formats;
1546 cap = hda_command(dev,
1547 HDA_CMD_GET_PARAMETER(0, nid,
1548 HDA_PARAM_SUPP_PCM_SIZE_RATE));
1549 w->param.supp_pcm_size_rate = (cap != 0) ? cap :
1550 w->devinfo->supp_pcm_size_rate;
1552 w->param.supp_stream_formats =
1553 w->devinfo->supp_stream_formats;
1554 w->param.supp_pcm_size_rate =
1555 w->devinfo->supp_pcm_size_rate;
1557 if (HDA_PARAM_AUDIO_WIDGET_CAP_STRIPE(w->param.widget_cap)) {
1558 w->wclass.conv.stripecap = hda_command(dev,
1559 HDA_CMD_GET_STRIPE_CONTROL(0, w->nid)) >> 20;
1561 w->wclass.conv.stripecap = 1;
1563 w->param.supp_stream_formats = 0;
1564 w->param.supp_pcm_size_rate = 0;
1567 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) {
1568 w->wclass.pin.original = w->wclass.pin.newconf =
1569 w->wclass.pin.config = hda_command(dev,
1570 HDA_CMD_GET_CONFIGURATION_DEFAULT(0, w->nid));
1571 w->wclass.pin.cap = hda_command(dev,
1572 HDA_CMD_GET_PARAMETER(0, w->nid, HDA_PARAM_PIN_CAP));
1573 w->wclass.pin.ctrl = hda_command(dev,
1574 HDA_CMD_GET_PIN_WIDGET_CTRL(0, nid));
1575 w->wclass.pin.connected = 2;
1576 if (HDA_PARAM_PIN_CAP_EAPD_CAP(w->wclass.pin.cap)) {
1577 w->param.eapdbtl = hda_command(dev,
1578 HDA_CMD_GET_EAPD_BTL_ENABLE(0, nid));
1579 w->param.eapdbtl &= 0x7;
1580 w->param.eapdbtl |= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
1582 w->param.eapdbtl = HDA_INVALID;
1586 hdaa_unlock(w->devinfo);
1587 ksnprintf(buf, sizeof(buf), "nid%d", w->nid);
1588 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
1589 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
1590 buf, CTLTYPE_STRING | CTLFLAG_RD,
1591 w, sizeof(w), hdaa_sysctl_caps, "A", "Node capabilities");
1592 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) {
1593 ksnprintf(buf, sizeof(buf), "nid%d_config", w->nid);
1594 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
1595 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
1596 buf, CTLTYPE_STRING | CTLFLAG_RW,
1597 &w->wclass.pin.newconf, sizeof(&w->wclass.pin.newconf),
1598 hdaa_sysctl_config, "A", "Current pin configuration");
1599 ksnprintf(buf, sizeof(buf), "nid%d_original", w->nid);
1600 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
1601 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
1602 buf, CTLTYPE_STRING | CTLFLAG_RD,
1603 &w->wclass.pin.original, sizeof(&w->wclass.pin.original),
1604 hdaa_sysctl_config, "A", "Original pin configuration");
1606 hdaa_lock(w->devinfo);
1610 hdaa_widget_postprocess(struct hdaa_widget *w)
1612 const char *typestr;
1614 w->type = HDA_PARAM_AUDIO_WIDGET_CAP_TYPE(w->param.widget_cap);
1616 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT:
1617 typestr = "audio output";
1619 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT:
1620 typestr = "audio input";
1622 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER:
1623 typestr = "audio mixer";
1625 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR:
1626 typestr = "audio selector";
1628 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
1631 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_POWER_WIDGET:
1632 typestr = "power widget";
1634 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_VOLUME_WIDGET:
1635 typestr = "volume widget";
1637 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET:
1638 typestr = "beep widget";
1640 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_VENDOR_WIDGET:
1641 typestr = "vendor widget";
1644 typestr = "unknown type";
1647 strlcpy(w->name, typestr, sizeof(w->name));
1649 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) {
1654 config = w->wclass.pin.config;
1655 devstr = HDA_DEVS[(config & HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) >>
1656 HDA_CONFIG_DEFAULTCONF_DEVICE_SHIFT];
1657 conn = (config & HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK) >>
1658 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_SHIFT;
1659 color = (config & HDA_CONFIG_DEFAULTCONF_COLOR_MASK) >>
1660 HDA_CONFIG_DEFAULTCONF_COLOR_SHIFT;
1661 strlcat(w->name, ": ", sizeof(w->name));
1662 strlcat(w->name, devstr, sizeof(w->name));
1663 strlcat(w->name, " (", sizeof(w->name));
1664 if (conn == 0 && color != 0 && color != 15) {
1665 strlcat(w->name, HDA_COLORS[color], sizeof(w->name));
1666 strlcat(w->name, " ", sizeof(w->name));
1668 strlcat(w->name, HDA_CONNS[conn], sizeof(w->name));
1669 strlcat(w->name, ")", sizeof(w->name));
1673 struct hdaa_widget *
1674 hdaa_widget_get(struct hdaa_devinfo *devinfo, nid_t nid)
1676 if (devinfo == NULL || devinfo->widget == NULL ||
1677 nid < devinfo->startnode || nid >= devinfo->endnode)
1679 return (&devinfo->widget[nid - devinfo->startnode]);
1683 hdaa_audio_ctl_amp_set_internal(struct hdaa_devinfo *devinfo, nid_t nid,
1684 int index, int lmute, int rmute,
1685 int left, int right, int dir)
1690 device_printf(devinfo->dev,
1691 "Setting amplifier nid=%d index=%d %s mute=%d/%d vol=%d/%d\n",
1692 nid,index,dir ? "in" : "out",lmute,rmute,left,right);
1694 if (left != right || lmute != rmute) {
1695 v = (1 << (15 - dir)) | (1 << 13) | (index << 8) |
1696 (lmute << 7) | left;
1697 hda_command(devinfo->dev,
1698 HDA_CMD_SET_AMP_GAIN_MUTE(0, nid, v));
1699 v = (1 << (15 - dir)) | (1 << 12) | (index << 8) |
1700 (rmute << 7) | right;
1702 v = (1 << (15 - dir)) | (3 << 12) | (index << 8) |
1703 (lmute << 7) | left;
1705 hda_command(devinfo->dev,
1706 HDA_CMD_SET_AMP_GAIN_MUTE(0, nid, v));
1710 hdaa_audio_ctl_amp_set(struct hdaa_audio_ctl *ctl, uint32_t mute,
1711 int left, int right)
1716 nid = ctl->widget->nid;
1718 /* Save new values if valid. */
1719 if (mute != HDAA_AMP_MUTE_DEFAULT)
1721 if (left != HDAA_AMP_VOL_DEFAULT)
1723 if (right != HDAA_AMP_VOL_DEFAULT)
1725 /* Prepare effective values */
1726 if (ctl->forcemute) {
1732 lmute = HDAA_AMP_LEFT_MUTED(ctl->muted);
1733 rmute = HDAA_AMP_RIGHT_MUTED(ctl->muted);
1737 /* Apply effective values */
1738 if (ctl->dir & HDAA_CTL_OUT)
1739 hdaa_audio_ctl_amp_set_internal(ctl->widget->devinfo, nid, ctl->index,
1740 lmute, rmute, left, right, 0);
1741 if (ctl->dir & HDAA_CTL_IN)
1742 hdaa_audio_ctl_amp_set_internal(ctl->widget->devinfo, nid, ctl->index,
1743 lmute, rmute, left, right, 1);
1747 hdaa_widget_connection_select(struct hdaa_widget *w, uint8_t index)
1749 if (w == NULL || w->nconns < 1 || index > (w->nconns - 1))
1752 device_printf(w->devinfo->dev,
1753 "Setting selector nid=%d index=%d\n", w->nid, index);
1755 hda_command(w->devinfo->dev,
1756 HDA_CMD_SET_CONNECTION_SELECT_CONTROL(0, w->nid, index));
1760 /****************************************************************************
1762 ****************************************************************************/
1765 hdaa_channel_init(kobj_t obj, void *data, struct snd_dbuf *b,
1766 struct pcm_channel *c, int dir)
1768 struct hdaa_chan *ch = data;
1769 struct hdaa_pcm_devinfo *pdevinfo = ch->pdevinfo;
1770 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
1773 if (devinfo->quirks & HDAA_QUIRK_FIXEDRATE) {
1774 ch->caps.minspeed = ch->caps.maxspeed = 48000;
1775 ch->pcmrates[0] = 48000;
1776 ch->pcmrates[1] = 0;
1781 ch->blksz = pdevinfo->chan_size / pdevinfo->chan_blkcnt;
1782 ch->blkcnt = pdevinfo->chan_blkcnt;
1783 hdaa_unlock(devinfo);
1785 if (sndbuf_alloc(ch->b, bus_get_dma_tag(devinfo->dev),
1786 hda_get_dma_nocache(devinfo->dev) ? BUS_DMA_NOCACHE : 0,
1787 pdevinfo->chan_size) != 0)
1794 hdaa_channel_setformat(kobj_t obj, void *data, uint32_t format)
1796 struct hdaa_chan *ch = data;
1799 for (i = 0; ch->caps.fmtlist[i] != 0; i++) {
1800 if (format == ch->caps.fmtlist[i]) {
1810 hdaa_channel_setspeed(kobj_t obj, void *data, uint32_t speed)
1812 struct hdaa_chan *ch = data;
1813 uint32_t spd = 0, threshold;
1816 /* First look for equal or multiple frequency. */
1817 for (i = 0; ch->pcmrates[i] != 0; i++) {
1818 spd = ch->pcmrates[i];
1819 if (speed != 0 && spd / speed * speed == spd) {
1824 /* If no match, just find nearest. */
1825 for (i = 0; ch->pcmrates[i] != 0; i++) {
1826 spd = ch->pcmrates[i];
1827 threshold = spd + ((ch->pcmrates[i + 1] != 0) ?
1828 ((ch->pcmrates[i + 1] - spd) >> 1) : 0);
1829 if (speed < threshold)
1837 hdaa_stream_format(struct hdaa_chan *ch)
1843 if (ch->fmt & AFMT_S16_LE)
1844 fmt |= ch->bit16 << 4;
1845 else if (ch->fmt & AFMT_S32_LE)
1846 fmt |= ch->bit32 << 4;
1849 for (i = 0; i < HDA_RATE_TAB_LEN; i++) {
1850 if (hda_rate_tab[i].valid && ch->spd == hda_rate_tab[i].rate) {
1851 fmt |= hda_rate_tab[i].base;
1852 fmt |= hda_rate_tab[i].mul;
1853 fmt |= hda_rate_tab[i].div;
1857 fmt |= (AFMT_CHANNEL(ch->fmt) - 1);
1863 hdaa_allowed_stripes(uint16_t fmt)
1865 static const int bits[8] = { 8, 16, 20, 24, 32, 32, 32, 32 };
1868 size = bits[(fmt >> 4) & 0x03];
1869 size *= (fmt & 0x0f) + 1;
1870 size *= ((fmt >> 11) & 0x07) + 1;
1871 return (0xffffffffU >> (32 - fls(size / 8)));
1875 hdaa_audio_setup(struct hdaa_chan *ch)
1877 struct hdaa_audio_as *as = &ch->devinfo->as[ch->as];
1878 struct hdaa_widget *w, *wp;
1879 int i, j, k, chn, cchn, totalchn, totalextchn, c;
1881 /* Mapping channel pairs to codec pins/converters. */
1882 static const uint16_t convmap[2][5] =
1883 /* 1.0 2.0 4.0 5.1 7.1 */
1884 {{ 0x0010, 0x0001, 0x0201, 0x0231, 0x4231 }, /* no dup. */
1885 { 0x0010, 0x0001, 0x2201, 0x2231, 0x4231 }}; /* side dup. */
1886 /* Mapping formats to HDMI channel allocations. */
1887 static const uint8_t hdmica[2][8] =
1888 /* 1 2 3 4 5 6 7 8 */
1889 {{ 0x02, 0x00, 0x04, 0x08, 0x0a, 0x0e, 0x12, 0x12 }, /* x.0 */
1890 { 0x01, 0x03, 0x01, 0x03, 0x09, 0x0b, 0x0f, 0x13 }}; /* x.1 */
1891 /* Mapping formats to HDMI channels order. */
1892 static const uint32_t hdmich[2][8] =
1893 /* 1 / 5 2 / 6 3 / 7 4 / 8 */
1894 {{ 0xFFFF0F00, 0xFFFFFF10, 0xFFF2FF10, 0xFF32FF10,
1895 0xFF324F10, 0xF5324F10, 0x54326F10, 0x54326F10 }, /* x.0 */
1896 { 0xFFFFF000, 0xFFFF0100, 0xFFFFF210, 0xFFFF2310,
1897 0xFF32F410, 0xFF324510, 0xF6324510, 0x76325410 }}; /* x.1 */
1902 totalchn = AFMT_CHANNEL(ch->fmt);
1903 totalextchn = AFMT_EXTCHANNEL(ch->fmt);
1905 device_printf(ch->pdevinfo->dev,
1906 "PCMDIR_%s: Stream setup fmt=%08x (%d.%d) speed=%d\n",
1907 (ch->dir == PCMDIR_PLAY) ? "PLAY" : "REC",
1908 ch->fmt, totalchn - totalextchn, totalextchn, ch->spd);
1910 fmt = hdaa_stream_format(ch);
1912 /* Set channels to I/O converters mapping for known speaker setups. */
1913 if ((as->pinset == 0x0007 || as->pinset == 0x0013) || /* Standard 5.1 */
1914 (as->pinset == 0x0017)) /* Standard 7.1 */
1915 convmapid = (ch->dir == PCMDIR_PLAY);
1917 dfmt = HDA_CMD_SET_DIGITAL_CONV_FMT1_DIGEN;
1918 if (ch->fmt & AFMT_AC3)
1919 dfmt |= HDA_CMD_SET_DIGITAL_CONV_FMT1_NAUDIO;
1922 for (i = 0; ch->io[i] != -1; i++) {
1923 w = hdaa_widget_get(ch->devinfo, ch->io[i]);
1927 /* If HP redirection is enabled, but failed to use same
1928 DAC, make last DAC to duplicate first one. */
1929 if (as->fakeredir && i == (as->pincnt - 1)) {
1932 /* Map channels to I/O converters, if set. */
1934 chn = (((convmap[convmapid][totalchn / 2]
1935 >> i * 4) & 0xf) - 1) * 2;
1936 if (chn < 0 || chn >= totalchn) {
1939 c = (ch->sid << 4) | chn;
1942 hda_command(ch->devinfo->dev,
1943 HDA_CMD_SET_CONV_FMT(0, ch->io[i], fmt));
1944 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) {
1945 hda_command(ch->devinfo->dev,
1946 HDA_CMD_SET_DIGITAL_CONV_FMT1(0, ch->io[i], dfmt));
1948 hda_command(ch->devinfo->dev,
1949 HDA_CMD_SET_CONV_STREAM_CHAN(0, ch->io[i], c));
1950 if (HDA_PARAM_AUDIO_WIDGET_CAP_STRIPE(w->param.widget_cap)) {
1951 hda_command(ch->devinfo->dev,
1952 HDA_CMD_SET_STRIPE_CONTROL(0, w->nid, ch->stripectl));
1954 cchn = HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap);
1955 if (cchn > 1 && chn < totalchn) {
1956 cchn = min(cchn, totalchn - chn - 1);
1957 hda_command(ch->devinfo->dev,
1958 HDA_CMD_SET_CONV_CHAN_COUNT(0, ch->io[i], cchn));
1961 device_printf(ch->pdevinfo->dev,
1962 "PCMDIR_%s: Stream setup nid=%d: "
1963 "fmt=0x%04x, dfmt=0x%04x, chan=0x%04x, "
1964 "chan_count=0x%02x, stripe=%d\n",
1965 (ch->dir == PCMDIR_PLAY) ? "PLAY" : "REC",
1966 ch->io[i], fmt, dfmt, c, cchn, ch->stripectl);
1968 for (j = 0; j < 16; j++) {
1969 if (as->dacs[ch->asindex][j] != ch->io[i])
1972 wp = hdaa_widget_get(ch->devinfo, nid);
1975 if (!HDA_PARAM_PIN_CAP_DP(wp->wclass.pin.cap) &&
1976 !HDA_PARAM_PIN_CAP_HDMI(wp->wclass.pin.cap))
1979 /* Set channel mapping. */
1980 for (k = 0; k < 8; k++) {
1981 hda_command(ch->devinfo->dev,
1982 HDA_CMD_SET_HDMI_CHAN_SLOT(0, nid,
1983 (((hdmich[totalextchn == 0 ? 0 : 1][totalchn - 1]
1984 >> (k * 4)) & 0xf) << 4) | k));
1988 * Enable High Bit Rate (HBR) Encoded Packet Type
1989 * (EPT), if supported and needed (8ch data).
1991 if (HDA_PARAM_PIN_CAP_HDMI(wp->wclass.pin.cap) &&
1992 HDA_PARAM_PIN_CAP_HBR(wp->wclass.pin.cap)) {
1993 wp->wclass.pin.ctrl &=
1994 ~HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK;
1995 if ((ch->fmt & AFMT_AC3) && (cchn == 7))
1996 wp->wclass.pin.ctrl |= 0x03;
1997 hda_command(ch->devinfo->dev,
1998 HDA_CMD_SET_PIN_WIDGET_CTRL(0, nid,
1999 wp->wclass.pin.ctrl));
2002 /* Stop audio infoframe transmission. */
2003 hda_command(ch->devinfo->dev,
2004 HDA_CMD_SET_HDMI_DIP_INDEX(0, nid, 0x00));
2005 hda_command(ch->devinfo->dev,
2006 HDA_CMD_SET_HDMI_DIP_XMIT(0, nid, 0x00));
2008 /* Clear audio infoframe buffer. */
2009 hda_command(ch->devinfo->dev,
2010 HDA_CMD_SET_HDMI_DIP_INDEX(0, nid, 0x00));
2011 for (k = 0; k < 32; k++)
2012 hda_command(ch->devinfo->dev,
2013 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x00));
2015 /* Write HDMI/DisplayPort audio infoframe. */
2016 hda_command(ch->devinfo->dev,
2017 HDA_CMD_SET_HDMI_DIP_INDEX(0, nid, 0x00));
2018 if (w->eld != NULL && w->eld_len >= 6 &&
2019 ((w->eld[5] >> 2) & 0x3) == 1) { /* DisplayPort */
2020 hda_command(ch->devinfo->dev,
2021 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x84));
2022 hda_command(ch->devinfo->dev,
2023 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x1b));
2024 hda_command(ch->devinfo->dev,
2025 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x44));
2027 hda_command(ch->devinfo->dev,
2028 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x84));
2029 hda_command(ch->devinfo->dev,
2030 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x01));
2031 hda_command(ch->devinfo->dev,
2032 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x0a));
2034 csum -= 0x84 + 0x01 + 0x0a + (totalchn - 1) +
2035 hdmica[totalextchn == 0 ? 0 : 1][totalchn - 1];
2036 hda_command(ch->devinfo->dev,
2037 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, csum));
2039 hda_command(ch->devinfo->dev,
2040 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, totalchn - 1));
2041 hda_command(ch->devinfo->dev,
2042 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x00));
2043 hda_command(ch->devinfo->dev,
2044 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x00));
2045 hda_command(ch->devinfo->dev,
2046 HDA_CMD_SET_HDMI_DIP_DATA(0, nid,
2047 hdmica[totalextchn == 0 ? 0 : 1][totalchn - 1]));
2049 /* Start audio infoframe transmission. */
2050 hda_command(ch->devinfo->dev,
2051 HDA_CMD_SET_HDMI_DIP_INDEX(0, nid, 0x00));
2052 hda_command(ch->devinfo->dev,
2053 HDA_CMD_SET_HDMI_DIP_XMIT(0, nid, 0xc0));
2060 * Greatest Common Divisor.
2063 gcd(unsigned a, unsigned b)
2076 * Least Common Multiple.
2079 lcm(unsigned a, unsigned b)
2082 return ((a * b) / gcd(a, b));
2086 hdaa_channel_setfragments(kobj_t obj, void *data,
2087 uint32_t blksz, uint32_t blkcnt)
2089 struct hdaa_chan *ch = data;
2091 blksz -= blksz % lcm(HDA_DMA_ALIGNMENT, sndbuf_getalign(ch->b));
2093 if (blksz > (sndbuf_getmaxsize(ch->b) / HDA_BDL_MIN))
2094 blksz = sndbuf_getmaxsize(ch->b) / HDA_BDL_MIN;
2095 if (blksz < HDA_BLK_MIN)
2096 blksz = HDA_BLK_MIN;
2097 if (blkcnt > HDA_BDL_MAX)
2098 blkcnt = HDA_BDL_MAX;
2099 if (blkcnt < HDA_BDL_MIN)
2100 blkcnt = HDA_BDL_MIN;
2102 while ((blksz * blkcnt) > sndbuf_getmaxsize(ch->b)) {
2103 if ((blkcnt >> 1) >= HDA_BDL_MIN)
2105 else if ((blksz >> 1) >= HDA_BLK_MIN)
2111 if ((sndbuf_getblksz(ch->b) != blksz ||
2112 sndbuf_getblkcnt(ch->b) != blkcnt) &&
2113 sndbuf_resize(ch->b, blkcnt, blksz) != 0)
2114 device_printf(ch->devinfo->dev, "%s: failed blksz=%u blkcnt=%u\n",
2115 __func__, blksz, blkcnt);
2117 ch->blksz = sndbuf_getblksz(ch->b);
2118 ch->blkcnt = sndbuf_getblkcnt(ch->b);
2124 hdaa_channel_setblocksize(kobj_t obj, void *data, uint32_t blksz)
2126 struct hdaa_chan *ch = data;
2128 hdaa_channel_setfragments(obj, data, blksz, ch->pdevinfo->chan_blkcnt);
2134 hdaa_channel_stop(struct hdaa_chan *ch)
2136 struct hdaa_devinfo *devinfo = ch->devinfo;
2137 struct hdaa_widget *w;
2140 if ((ch->flags & HDAA_CHN_RUNNING) == 0)
2142 ch->flags &= ~HDAA_CHN_RUNNING;
2143 HDAC_STREAM_STOP(device_get_parent(devinfo->dev), devinfo->dev,
2144 ch->dir == PCMDIR_PLAY ? 1 : 0, ch->sid);
2145 for (i = 0; ch->io[i] != -1; i++) {
2146 w = hdaa_widget_get(ch->devinfo, ch->io[i]);
2149 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) {
2150 hda_command(devinfo->dev,
2151 HDA_CMD_SET_DIGITAL_CONV_FMT1(0, ch->io[i], 0));
2153 hda_command(devinfo->dev,
2154 HDA_CMD_SET_CONV_STREAM_CHAN(0, ch->io[i],
2157 HDAC_STREAM_FREE(device_get_parent(devinfo->dev), devinfo->dev,
2158 ch->dir == PCMDIR_PLAY ? 1 : 0, ch->sid);
2162 hdaa_channel_start(struct hdaa_chan *ch)
2164 struct hdaa_devinfo *devinfo = ch->devinfo;
2167 fmt = hdaa_stream_format(ch);
2168 ch->stripectl = fls(ch->stripecap & hdaa_allowed_stripes(fmt)) - 1;
2169 ch->sid = HDAC_STREAM_ALLOC(device_get_parent(devinfo->dev), devinfo->dev,
2170 ch->dir == PCMDIR_PLAY ? 1 : 0, fmt, ch->stripectl, &ch->dmapos);
2173 hdaa_audio_setup(ch);
2174 HDAC_STREAM_RESET(device_get_parent(devinfo->dev), devinfo->dev,
2175 ch->dir == PCMDIR_PLAY ? 1 : 0, ch->sid);
2176 HDAC_STREAM_START(device_get_parent(devinfo->dev), devinfo->dev,
2177 ch->dir == PCMDIR_PLAY ? 1 : 0, ch->sid,
2178 sndbuf_getbufaddr(ch->b), ch->blksz, ch->blkcnt);
2179 ch->flags |= HDAA_CHN_RUNNING;
2184 hdaa_channel_trigger(kobj_t obj, void *data, int go)
2186 struct hdaa_chan *ch = data;
2189 if (!PCMTRIG_COMMON(go))
2192 hdaa_lock(ch->devinfo);
2195 error = hdaa_channel_start(ch);
2199 hdaa_channel_stop(ch);
2204 hdaa_unlock(ch->devinfo);
2210 hdaa_channel_getptr(kobj_t obj, void *data)
2212 struct hdaa_chan *ch = data;
2213 struct hdaa_devinfo *devinfo = ch->devinfo;
2217 if (ch->dmapos != NULL) {
2218 ptr = *(ch->dmapos);
2220 ptr = HDAC_STREAM_GETPTR(
2221 device_get_parent(devinfo->dev), devinfo->dev,
2222 ch->dir == PCMDIR_PLAY ? 1 : 0, ch->sid);
2224 hdaa_unlock(devinfo);
2227 * Round to available space and force 128 bytes aligment.
2229 ptr %= ch->blksz * ch->blkcnt;
2230 ptr &= HDA_BLK_ALIGN;
2235 static struct pcmchan_caps *
2236 hdaa_channel_getcaps(kobj_t obj, void *data)
2238 return (&((struct hdaa_chan *)data)->caps);
2241 static kobj_method_t hdaa_channel_methods[] = {
2242 KOBJMETHOD(channel_init, hdaa_channel_init),
2243 KOBJMETHOD(channel_setformat, hdaa_channel_setformat),
2244 KOBJMETHOD(channel_setspeed, hdaa_channel_setspeed),
2245 KOBJMETHOD(channel_setblocksize, hdaa_channel_setblocksize),
2246 KOBJMETHOD(channel_setfragments, hdaa_channel_setfragments),
2247 KOBJMETHOD(channel_trigger, hdaa_channel_trigger),
2248 KOBJMETHOD(channel_getptr, hdaa_channel_getptr),
2249 KOBJMETHOD(channel_getcaps, hdaa_channel_getcaps),
2252 CHANNEL_DECLARE(hdaa_channel);
2255 hdaa_audio_ctl_ossmixer_init(struct snd_mixer *m)
2257 struct hdaa_pcm_devinfo *pdevinfo = mix_getdevinfo(m);
2258 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
2259 struct hdaa_widget *w, *cw;
2260 uint32_t mask, recmask;
2264 pdevinfo->mixer = m;
2266 /* Make sure that in case of soft volume it won't stay muted. */
2267 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
2268 pdevinfo->left[i] = 100;
2269 pdevinfo->right[i] = 100;
2272 /* Declare volume controls assigned to this association. */
2273 mask = pdevinfo->ossmask;
2274 if (pdevinfo->playas >= 0) {
2275 /* Declate EAPD as ogain control. */
2276 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2277 w = hdaa_widget_get(devinfo, i);
2278 if (w == NULL || w->enable == 0)
2280 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX ||
2281 w->param.eapdbtl == HDA_INVALID ||
2282 w->bindas != pdevinfo->playas)
2284 mask |= SOUND_MASK_OGAIN;
2288 /* Declare soft PCM volume if needed. */
2289 if ((mask & SOUND_MASK_PCM) == 0 ||
2290 (devinfo->quirks & HDAA_QUIRK_SOFTPCMVOL) ||
2291 pdevinfo->minamp[SOUND_MIXER_PCM] ==
2292 pdevinfo->maxamp[SOUND_MIXER_PCM]) {
2293 mask |= SOUND_MASK_PCM;
2294 pcm_setflags(pdevinfo->dev, pcm_getflags(pdevinfo->dev) | SD_F_SOFTPCMVOL);
2296 device_printf(pdevinfo->dev,
2297 "Forcing Soft PCM volume\n");
2301 /* Declare master volume if needed. */
2302 if ((mask & SOUND_MASK_VOLUME) == 0) {
2303 mask |= SOUND_MASK_VOLUME;
2304 mix_setparentchild(m, SOUND_MIXER_VOLUME,
2306 mix_setrealdev(m, SOUND_MIXER_VOLUME,
2309 device_printf(pdevinfo->dev,
2310 "Forcing master volume with PCM\n");
2315 /* Declare record sources available to this association. */
2317 if (pdevinfo->recas >= 0) {
2318 for (i = 0; i < 16; i++) {
2319 if (devinfo->as[pdevinfo->recas].dacs[0][i] < 0)
2321 w = hdaa_widget_get(devinfo,
2322 devinfo->as[pdevinfo->recas].dacs[0][i]);
2323 if (w == NULL || w->enable == 0)
2325 for (j = 0; j < w->nconns; j++) {
2326 if (w->connsenable[j] == 0)
2328 cw = hdaa_widget_get(devinfo, w->conns[j]);
2329 if (cw == NULL || cw->enable == 0)
2331 if (cw->bindas != pdevinfo->recas &&
2334 recmask |= cw->ossmask;
2339 recmask &= (1 << SOUND_MIXER_NRDEVICES) - 1;
2340 mask &= (1 << SOUND_MIXER_NRDEVICES) - 1;
2341 pdevinfo->ossmask = mask;
2343 mix_setrecdevs(m, recmask);
2344 mix_setdevs(m, mask);
2346 hdaa_unlock(devinfo);
2352 * Update amplification per pdevinfo per ossdev, calculate summary coefficient
2353 * and write it to codec, update *left and *right to reflect remaining error.
2356 hdaa_audio_ctl_dev_set(struct hdaa_audio_ctl *ctl, int ossdev,
2357 int mute, int *left, int *right)
2359 int i, zleft, zright, sleft, sright, smute, lval, rval;
2361 ctl->devleft[ossdev] = *left;
2362 ctl->devright[ossdev] = *right;
2363 ctl->devmute[ossdev] = mute;
2364 smute = sleft = sright = zleft = zright = 0;
2365 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
2366 sleft += ctl->devleft[i];
2367 sright += ctl->devright[i];
2368 smute |= ctl->devmute[i];
2371 zleft += ctl->devleft[i];
2372 zright += ctl->devright[i];
2374 lval = QDB2VAL(ctl, sleft);
2375 rval = QDB2VAL(ctl, sright);
2376 hdaa_audio_ctl_amp_set(ctl, smute, lval, rval);
2377 *left -= VAL2QDB(ctl, lval) - VAL2QDB(ctl, QDB2VAL(ctl, zleft));
2378 *right -= VAL2QDB(ctl, rval) - VAL2QDB(ctl, QDB2VAL(ctl, zright));
2382 * Trace signal from source, setting volumes on the way.
2385 hdaa_audio_ctl_source_volume(struct hdaa_pcm_devinfo *pdevinfo,
2386 int ossdev, nid_t nid, int index, int mute, int left, int right, int depth)
2388 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
2389 struct hdaa_widget *w, *wc;
2390 struct hdaa_audio_ctl *ctl;
2391 int i, j, conns = 0;
2393 if (depth > HDA_PARSE_MAXDEPTH)
2396 w = hdaa_widget_get(devinfo, nid);
2397 if (w == NULL || w->enable == 0)
2400 /* Count number of active inputs. */
2402 for (j = 0; j < w->nconns; j++) {
2403 if (!w->connsenable[j])
2409 /* If this is not a first step - use input mixer.
2410 Pins have common input ctl so care must be taken. */
2411 if (depth > 0 && (conns == 1 ||
2412 w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)) {
2413 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, HDAA_CTL_IN,
2416 hdaa_audio_ctl_dev_set(ctl, ossdev, mute, &left, &right);
2419 /* If widget has own ossdev - not traverse it.
2420 It will be traversed on it's own. */
2421 if (w->ossdev >= 0 && depth > 0)
2424 /* We must not traverse pin */
2425 if ((w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT ||
2426 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) &&
2431 * If signals mixed, we can't assign controls farther.
2432 * Ignore this on depth zero. Caller must knows why.
2435 (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER ||
2436 w->selconn != index))
2439 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, HDAA_CTL_OUT, -1, 1);
2441 hdaa_audio_ctl_dev_set(ctl, ossdev, mute, &left, &right);
2443 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2444 wc = hdaa_widget_get(devinfo, i);
2445 if (wc == NULL || wc->enable == 0)
2447 for (j = 0; j < wc->nconns; j++) {
2448 if (wc->connsenable[j] && wc->conns[j] == nid) {
2449 hdaa_audio_ctl_source_volume(pdevinfo, ossdev,
2450 wc->nid, j, mute, left, right, depth + 1);
2458 * Trace signal from destination, setting volumes on the way.
2461 hdaa_audio_ctl_dest_volume(struct hdaa_pcm_devinfo *pdevinfo,
2462 int ossdev, nid_t nid, int index, int mute, int left, int right, int depth)
2464 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
2465 struct hdaa_audio_as *as = devinfo->as;
2466 struct hdaa_widget *w, *wc;
2467 struct hdaa_audio_ctl *ctl;
2468 int i, j, consumers, cleft, cright;
2470 if (depth > HDA_PARSE_MAXDEPTH)
2473 w = hdaa_widget_get(devinfo, nid);
2474 if (w == NULL || w->enable == 0)
2478 /* If this node produce output for several consumers,
2479 we can't touch it. */
2481 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2482 wc = hdaa_widget_get(devinfo, i);
2483 if (wc == NULL || wc->enable == 0)
2485 for (j = 0; j < wc->nconns; j++) {
2486 if (wc->connsenable[j] && wc->conns[j] == nid)
2490 /* The only exception is if real HP redirection is configured
2491 and this is a duplication point.
2492 XXX: Actually exception is not completely correct.
2493 XXX: Duplication point check is not perfect. */
2494 if ((consumers == 2 && (w->bindas < 0 ||
2495 as[w->bindas].hpredir < 0 || as[w->bindas].fakeredir ||
2496 (w->bindseqmask & (1 << 15)) == 0)) ||
2500 /* Else use it's output mixer. */
2501 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid,
2502 HDAA_CTL_OUT, -1, 1);
2504 hdaa_audio_ctl_dev_set(ctl, ossdev, mute, &left, &right);
2507 /* We must not traverse pin */
2508 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
2512 for (i = 0; i < w->nconns; i++) {
2513 if (w->connsenable[i] == 0)
2515 if (index >= 0 && i != index)
2519 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid,
2522 hdaa_audio_ctl_dev_set(ctl, ossdev, mute, &cleft, &cright);
2523 hdaa_audio_ctl_dest_volume(pdevinfo, ossdev, w->conns[i], -1,
2524 mute, cleft, cright, depth + 1);
2529 * Set volumes for the specified pdevinfo and ossdev.
2532 hdaa_audio_ctl_dev_volume(struct hdaa_pcm_devinfo *pdevinfo, unsigned dev)
2534 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
2535 struct hdaa_widget *w, *cw;
2541 if (pdevinfo->left[dev] == 0) {
2542 mute |= HDAA_AMP_MUTE_LEFT;
2545 lvol = ((pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]) *
2546 pdevinfo->left[dev] + 50) / 100 + pdevinfo->minamp[dev];
2547 if (pdevinfo->right[dev] == 0) {
2548 mute |= HDAA_AMP_MUTE_RIGHT;
2551 rvol = ((pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]) *
2552 pdevinfo->right[dev] + 50) / 100 + pdevinfo->minamp[dev];
2553 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2554 w = hdaa_widget_get(devinfo, i);
2555 if (w == NULL || w->enable == 0)
2557 if (w->bindas < 0) {
2558 if (pdevinfo->index != 0)
2561 if (w->bindas != pdevinfo->playas &&
2562 w->bindas != pdevinfo->recas)
2565 if (dev == SOUND_MIXER_RECLEV &&
2566 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
2567 hdaa_audio_ctl_dest_volume(pdevinfo, dev,
2568 w->nid, -1, mute, lvol, rvol, 0);
2571 if (dev == SOUND_MIXER_VOLUME &&
2572 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
2573 devinfo->as[w->bindas].dir == HDAA_CTL_OUT) {
2574 hdaa_audio_ctl_dest_volume(pdevinfo, dev,
2575 w->nid, -1, mute, lvol, rvol, 0);
2578 if (dev == SOUND_MIXER_IGAIN &&
2579 w->pflags & HDAA_ADC_MONITOR) {
2580 for (j = 0; j < w->nconns; j++) {
2581 if (!w->connsenable[j])
2583 cw = hdaa_widget_get(devinfo, w->conns[j]);
2584 if (cw == NULL || cw->enable == 0)
2586 if (cw->bindas == -1)
2588 if (cw->bindas >= 0 &&
2589 devinfo->as[cw->bindas].dir != HDAA_CTL_IN)
2591 hdaa_audio_ctl_dest_volume(pdevinfo, dev,
2592 w->nid, j, mute, lvol, rvol, 0);
2596 if (w->ossdev != dev)
2598 hdaa_audio_ctl_source_volume(pdevinfo, dev,
2599 w->nid, -1, mute, lvol, rvol, 0);
2600 if (dev == SOUND_MIXER_IMIX && (w->pflags & HDAA_IMIX_AS_DST))
2601 hdaa_audio_ctl_dest_volume(pdevinfo, dev,
2602 w->nid, -1, mute, lvol, rvol, 0);
2607 * OSS Mixer set method.
2610 hdaa_audio_ctl_ossmixer_set(struct snd_mixer *m, unsigned dev,
2611 unsigned left, unsigned right)
2613 struct hdaa_pcm_devinfo *pdevinfo = mix_getdevinfo(m);
2614 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
2615 struct hdaa_widget *w;
2620 /* Save new values. */
2621 pdevinfo->left[dev] = left;
2622 pdevinfo->right[dev] = right;
2624 /* 'ogain' is the special case implemented with EAPD. */
2625 if (dev == SOUND_MIXER_OGAIN) {
2628 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2629 w = hdaa_widget_get(devinfo, i);
2630 if (w == NULL || w->enable == 0)
2632 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX ||
2633 w->param.eapdbtl == HDA_INVALID)
2637 if (i >= devinfo->endnode) {
2638 hdaa_unlock(devinfo);
2641 orig = w->param.eapdbtl;
2643 w->param.eapdbtl &= ~HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
2645 w->param.eapdbtl |= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
2646 if (orig != w->param.eapdbtl) {
2649 val = w->param.eapdbtl;
2650 if (devinfo->quirks & HDAA_QUIRK_EAPDINV)
2651 val ^= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
2652 hda_command(devinfo->dev,
2653 HDA_CMD_SET_EAPD_BTL_ENABLE(0, w->nid, val));
2655 hdaa_unlock(devinfo);
2656 return (left | (left << 8));
2659 /* Recalculate all controls related to this OSS device. */
2660 hdaa_audio_ctl_dev_volume(pdevinfo, dev);
2662 hdaa_unlock(devinfo);
2663 return (left | (right << 8));
2667 * Set mixer settings to our own default values:
2668 * +20dB for mics, -10dB for analog vol, mute for igain, 0dB for others.
2671 hdaa_audio_ctl_set_defaults(struct hdaa_pcm_devinfo *pdevinfo)
2675 for (dev = 0; dev < SOUND_MIXER_NRDEVICES; dev++) {
2676 if ((pdevinfo->ossmask & (1 << dev)) == 0)
2679 /* If the value was overriden, leave it as is. */
2680 if (resource_int_value(device_get_name(pdevinfo->dev),
2681 device_get_unit(pdevinfo->dev), ossnames[dev], &vol) == 0)
2685 if (dev == SOUND_MIXER_OGAIN)
2687 else if (dev == SOUND_MIXER_IGAIN)
2689 else if (dev == SOUND_MIXER_MIC ||
2690 dev == SOUND_MIXER_MONITOR)
2691 amp = 20 * 4; /* +20dB */
2692 else if (dev == SOUND_MIXER_VOLUME && !pdevinfo->digital)
2693 amp = -10 * 4; /* -10dB */
2697 (pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]) <= 0) {
2699 } else if (vol < 0) {
2700 vol = ((amp - pdevinfo->minamp[dev]) * 100 +
2701 (pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]) / 2) /
2702 (pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]);
2703 vol = imin(imax(vol, 1), 100);
2705 mix_set(pdevinfo->mixer, dev, vol, vol);
2710 * Recursively commutate specified record source.
2713 hdaa_audio_ctl_recsel_comm(struct hdaa_pcm_devinfo *pdevinfo, uint32_t src, nid_t nid, int depth)
2715 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
2716 struct hdaa_widget *w, *cw;
2717 struct hdaa_audio_ctl *ctl;
2722 if (depth > HDA_PARSE_MAXDEPTH)
2725 w = hdaa_widget_get(devinfo, nid);
2726 if (w == NULL || w->enable == 0)
2729 for (i = 0; i < w->nconns; i++) {
2730 if (w->connsenable[i] == 0)
2732 cw = hdaa_widget_get(devinfo, w->conns[i]);
2733 if (cw == NULL || cw->enable == 0 || cw->bindas == -1)
2735 /* Call recursively to trace signal to it's source if needed. */
2736 if ((src & cw->ossmask) != 0) {
2737 if (cw->ossdev < 0) {
2738 res |= hdaa_audio_ctl_recsel_comm(pdevinfo, src,
2739 w->conns[i], depth + 1);
2744 /* We have two special cases: mixers and others (selectors). */
2745 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) {
2746 ctl = hdaa_audio_ctl_amp_get(devinfo,
2747 w->nid, HDAA_CTL_IN, i, 1);
2750 /* If we have input control on this node mute them
2751 * according to requested sources. */
2752 muted = (src & cw->ossmask) ? 0 : 1;
2753 if (muted != ctl->forcemute) {
2754 ctl->forcemute = muted;
2755 hdaa_audio_ctl_amp_set(ctl,
2756 HDAA_AMP_MUTE_DEFAULT,
2757 HDAA_AMP_VOL_DEFAULT, HDAA_AMP_VOL_DEFAULT);
2760 device_printf(pdevinfo->dev,
2761 "Recsel (%s): nid %d source %d %s\n",
2762 hdaa_audio_ctl_ossmixer_mask2allname(
2763 src, buf, sizeof(buf)),
2764 nid, i, muted?"mute":"unmute");
2769 if ((src & cw->ossmask) == 0)
2771 /* If we found requested source - select it and exit. */
2772 hdaa_widget_connection_select(w, i);
2774 device_printf(pdevinfo->dev,
2775 "Recsel (%s): nid %d source %d select\n",
2776 hdaa_audio_ctl_ossmixer_mask2allname(
2777 src, buf, sizeof(buf)),
2787 hdaa_audio_ctl_ossmixer_setrecsrc(struct snd_mixer *m, uint32_t src)
2789 struct hdaa_pcm_devinfo *pdevinfo = mix_getdevinfo(m);
2790 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
2791 struct hdaa_widget *w;
2792 struct hdaa_audio_as *as;
2793 struct hdaa_audio_ctl *ctl;
2794 struct hdaa_chan *ch;
2796 uint32_t ret = 0xffffffff;
2799 if (pdevinfo->recas < 0) {
2800 hdaa_unlock(devinfo);
2803 as = &devinfo->as[pdevinfo->recas];
2805 /* For non-mixed associations we always recording everything. */
2807 hdaa_unlock(devinfo);
2808 return (mix_getrecdevs(m));
2811 /* Commutate requested recsrc for each ADC. */
2812 for (j = 0; j < as->num_chans; j++) {
2813 ch = &devinfo->chans[as->chans[j]];
2814 for (i = 0; ch->io[i] >= 0; i++) {
2815 w = hdaa_widget_get(devinfo, ch->io[i]);
2816 if (w == NULL || w->enable == 0)
2818 ret &= hdaa_audio_ctl_recsel_comm(pdevinfo, src,
2822 if (ret == 0xffffffff)
2826 * Some controls could be shared. Reset volumes for controls
2827 * related to previously chosen devices, as they may no longer
2828 * affect the signal.
2831 while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) {
2832 if (ctl->enable == 0 ||
2833 !(ctl->ossmask & pdevinfo->recsrc))
2835 if (!((pdevinfo->playas >= 0 &&
2836 ctl->widget->bindas == pdevinfo->playas) ||
2837 (pdevinfo->recas >= 0 &&
2838 ctl->widget->bindas == pdevinfo->recas) ||
2839 (pdevinfo->index == 0 &&
2840 ctl->widget->bindas == -2)))
2842 for (j = 0; j < SOUND_MIXER_NRDEVICES; j++) {
2843 if (pdevinfo->recsrc & (1 << j)) {
2844 ctl->devleft[j] = 0;
2845 ctl->devright[j] = 0;
2846 ctl->devmute[j] = 0;
2852 * Some controls could be shared. Set volumes for controls
2853 * related to devices selected both previously and now.
2855 for (j = 0; j < SOUND_MIXER_NRDEVICES; j++) {
2856 if ((ret | pdevinfo->recsrc) & (1 << j))
2857 hdaa_audio_ctl_dev_volume(pdevinfo, j);
2860 pdevinfo->recsrc = ret;
2861 hdaa_unlock(devinfo);
2865 static kobj_method_t hdaa_audio_ctl_ossmixer_methods[] = {
2866 KOBJMETHOD(mixer_init, hdaa_audio_ctl_ossmixer_init),
2867 KOBJMETHOD(mixer_set, hdaa_audio_ctl_ossmixer_set),
2868 KOBJMETHOD(mixer_setrecsrc, hdaa_audio_ctl_ossmixer_setrecsrc),
2871 MIXER_DECLARE(hdaa_audio_ctl_ossmixer);
2874 hdaa_dump_gpi(struct hdaa_devinfo *devinfo)
2876 device_t dev = devinfo->dev;
2878 uint32_t data, wake, unsol, sticky;
2880 if (HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap) > 0) {
2881 data = hda_command(dev,
2882 HDA_CMD_GET_GPI_DATA(0, devinfo->nid));
2883 wake = hda_command(dev,
2884 HDA_CMD_GET_GPI_WAKE_ENABLE_MASK(0, devinfo->nid));
2885 unsol = hda_command(dev,
2886 HDA_CMD_GET_GPI_UNSOLICITED_ENABLE_MASK(0, devinfo->nid));
2887 sticky = hda_command(dev,
2888 HDA_CMD_GET_GPI_STICKY_MASK(0, devinfo->nid));
2889 for (i = 0; i < HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap); i++) {
2890 device_printf(dev, " GPI%d:%s%s%s state=%d", i,
2891 (sticky & (1 << i)) ? " sticky" : "",
2892 (unsol & (1 << i)) ? " unsol" : "",
2893 (wake & (1 << i)) ? " wake" : "",
2900 hdaa_dump_gpio(struct hdaa_devinfo *devinfo)
2902 device_t dev = devinfo->dev;
2904 uint32_t data, dir, enable, wake, unsol, sticky;
2906 if (HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap) > 0) {
2907 data = hda_command(dev,
2908 HDA_CMD_GET_GPIO_DATA(0, devinfo->nid));
2909 enable = hda_command(dev,
2910 HDA_CMD_GET_GPIO_ENABLE_MASK(0, devinfo->nid));
2911 dir = hda_command(dev,
2912 HDA_CMD_GET_GPIO_DIRECTION(0, devinfo->nid));
2913 wake = hda_command(dev,
2914 HDA_CMD_GET_GPIO_WAKE_ENABLE_MASK(0, devinfo->nid));
2915 unsol = hda_command(dev,
2916 HDA_CMD_GET_GPIO_UNSOLICITED_ENABLE_MASK(0, devinfo->nid));
2917 sticky = hda_command(dev,
2918 HDA_CMD_GET_GPIO_STICKY_MASK(0, devinfo->nid));
2919 for (i = 0; i < HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap); i++) {
2920 device_printf(dev, " GPIO%d: ", i);
2921 if ((enable & (1 << i)) == 0) {
2922 kprintf("disabled\n");
2925 if ((dir & (1 << i)) == 0) {
2926 kprintf("input%s%s%s",
2927 (sticky & (1 << i)) ? " sticky" : "",
2928 (unsol & (1 << i)) ? " unsol" : "",
2929 (wake & (1 << i)) ? " wake" : "");
2932 kprintf(" state=%d\n", (data >> i) & 1);
2938 hdaa_dump_gpo(struct hdaa_devinfo *devinfo)
2940 device_t dev = devinfo->dev;
2944 if (HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap) > 0) {
2945 data = hda_command(dev,
2946 HDA_CMD_GET_GPO_DATA(0, devinfo->nid));
2947 for (i = 0; i < HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap); i++) {
2948 device_printf(dev, " GPO%d: state=%d", i,
2955 hdaa_audio_parse(struct hdaa_devinfo *devinfo)
2957 struct hdaa_widget *w;
2964 res = hda_command(devinfo->dev,
2965 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_GPIO_COUNT));
2966 devinfo->gpio_cap = res;
2969 device_printf(devinfo->dev,
2970 "NumGPIO=%d NumGPO=%d "
2971 "NumGPI=%d GPIWake=%d GPIUnsol=%d\n",
2972 HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap),
2973 HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap),
2974 HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap),
2975 HDA_PARAM_GPIO_COUNT_GPI_WAKE(devinfo->gpio_cap),
2976 HDA_PARAM_GPIO_COUNT_GPI_UNSOL(devinfo->gpio_cap));
2977 hdaa_dump_gpi(devinfo);
2978 hdaa_dump_gpio(devinfo);
2979 hdaa_dump_gpo(devinfo);
2982 res = hda_command(devinfo->dev,
2983 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_SUPP_STREAM_FORMATS));
2984 devinfo->supp_stream_formats = res;
2986 res = hda_command(devinfo->dev,
2987 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_SUPP_PCM_SIZE_RATE));
2988 devinfo->supp_pcm_size_rate = res;
2990 res = hda_command(devinfo->dev,
2991 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_OUTPUT_AMP_CAP));
2992 devinfo->outamp_cap = res;
2994 res = hda_command(devinfo->dev,
2995 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_INPUT_AMP_CAP));
2996 devinfo->inamp_cap = res;
2998 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2999 w = hdaa_widget_get(devinfo, i);
3001 device_printf(devinfo->dev, "Ghost widget! nid=%d!\n", i);
3003 w->devinfo = devinfo;
3010 w->param.eapdbtl = HDA_INVALID;
3011 hdaa_widget_parse(w);
3017 hdaa_audio_postprocess(struct hdaa_devinfo *devinfo)
3019 struct hdaa_widget *w;
3022 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3023 w = hdaa_widget_get(devinfo, i);
3026 hdaa_widget_postprocess(w);
3031 hdaa_audio_ctl_parse(struct hdaa_devinfo *devinfo)
3033 struct hdaa_audio_ctl *ctls;
3034 struct hdaa_widget *w, *cw;
3035 int i, j, cnt, max, ocap, icap;
3036 int mute, offset, step, size;
3038 /* XXX This is redundant */
3040 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3041 w = hdaa_widget_get(devinfo, i);
3042 if (w == NULL || w->enable == 0)
3044 if (w->param.outamp_cap != 0)
3046 if (w->param.inamp_cap != 0) {
3048 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR:
3049 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER:
3050 for (j = 0; j < w->nconns; j++) {
3051 cw = hdaa_widget_get(devinfo,
3053 if (cw == NULL || cw->enable == 0)
3064 devinfo->ctlcnt = max;
3069 ctls = (struct hdaa_audio_ctl *)kmalloc(
3070 sizeof(*ctls) * max, M_HDAA, M_ZERO | M_WAITOK);
3074 device_printf(devinfo->dev, "unable to allocate ctls!\n");
3075 devinfo->ctlcnt = 0;
3080 for (i = devinfo->startnode; cnt < max && i < devinfo->endnode; i++) {
3082 device_printf(devinfo->dev, "%s: Ctl overflow!\n",
3086 w = hdaa_widget_get(devinfo, i);
3087 if (w == NULL || w->enable == 0)
3089 ocap = w->param.outamp_cap;
3090 icap = w->param.inamp_cap;
3092 mute = HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(ocap);
3093 step = HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(ocap);
3094 size = HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(ocap);
3095 offset = HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(ocap);
3096 /*if (offset > step) {
3098 device_printf(devinfo->dev,
3099 "BUGGY outamp: nid=%d "
3100 "[offset=%d > step=%d]\n",
3101 w->nid, offset, step);
3105 ctls[cnt].enable = 1;
3106 ctls[cnt].widget = w;
3107 ctls[cnt].mute = mute;
3108 ctls[cnt].step = step;
3109 ctls[cnt].size = size;
3110 ctls[cnt].offset = offset;
3111 ctls[cnt].left = offset;
3112 ctls[cnt].right = offset;
3113 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX ||
3115 ctls[cnt].ndir = HDAA_CTL_IN;
3117 ctls[cnt].ndir = HDAA_CTL_OUT;
3118 ctls[cnt++].dir = HDAA_CTL_OUT;
3122 mute = HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(icap);
3123 step = HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(icap);
3124 size = HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(icap);
3125 offset = HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(icap);
3126 /*if (offset > step) {
3128 device_printf(devinfo->dev,
3129 "BUGGY inamp: nid=%d "
3130 "[offset=%d > step=%d]\n",
3131 w->nid, offset, step);
3136 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR:
3137 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER:
3138 for (j = 0; j < w->nconns; j++) {
3140 device_printf(devinfo->dev,
3141 "%s: Ctl overflow!\n",
3145 cw = hdaa_widget_get(devinfo,
3147 if (cw == NULL || cw->enable == 0)
3149 ctls[cnt].enable = 1;
3150 ctls[cnt].widget = w;
3151 ctls[cnt].childwidget = cw;
3152 ctls[cnt].index = j;
3153 ctls[cnt].mute = mute;
3154 ctls[cnt].step = step;
3155 ctls[cnt].size = size;
3156 ctls[cnt].offset = offset;
3157 ctls[cnt].left = offset;
3158 ctls[cnt].right = offset;
3159 ctls[cnt].ndir = HDAA_CTL_IN;
3160 ctls[cnt++].dir = HDAA_CTL_IN;
3165 device_printf(devinfo->dev,
3166 "%s: Ctl overflow!\n",
3170 ctls[cnt].enable = 1;
3171 ctls[cnt].widget = w;
3172 ctls[cnt].mute = mute;
3173 ctls[cnt].step = step;
3174 ctls[cnt].size = size;
3175 ctls[cnt].offset = offset;
3176 ctls[cnt].left = offset;
3177 ctls[cnt].right = offset;
3179 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
3180 ctls[cnt].ndir = HDAA_CTL_OUT;
3182 ctls[cnt].ndir = HDAA_CTL_IN;
3183 ctls[cnt++].dir = HDAA_CTL_IN;
3189 devinfo->ctl = ctls;
3193 hdaa_audio_as_parse(struct hdaa_devinfo *devinfo)
3195 struct hdaa_audio_as *as;
3196 struct hdaa_widget *w;
3197 int i, j, cnt, max, type, dir, assoc, seq, first, hpredir;
3199 /* Count present associations */
3201 for (j = 1; j < 16; j++) {
3202 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3203 w = hdaa_widget_get(devinfo, i);
3204 if (w == NULL || w->enable == 0)
3206 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
3208 if (HDA_CONFIG_DEFAULTCONF_ASSOCIATION(w->wclass.pin.config)
3212 if (j != 15) /* There could be many 1-pin assocs #15 */
3217 devinfo->ascnt = max;
3222 as = (struct hdaa_audio_as *)kmalloc(
3223 sizeof(*as) * max, M_HDAA, M_ZERO | M_WAITOK);
3227 device_printf(devinfo->dev, "unable to allocate assocs!\n");
3232 for (i = 0; i < max; i++) {
3235 as[i].num_chans = 1;
3236 as[i].location = -1;
3239 /* Scan associations skipping as=0. */
3241 for (j = 1; j < 16; j++) {
3244 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3245 w = hdaa_widget_get(devinfo, i);
3246 if (w == NULL || w->enable == 0)
3248 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
3250 assoc = HDA_CONFIG_DEFAULTCONF_ASSOCIATION(w->wclass.pin.config);
3251 seq = HDA_CONFIG_DEFAULTCONF_SEQUENCE(w->wclass.pin.config);
3256 ("%s: Associations owerflow (%d of %d)",
3257 __func__, cnt, max));
3258 type = w->wclass.pin.config &
3259 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
3260 /* Get pin direction. */
3261 if (type == HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_OUT ||
3262 type == HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER ||
3263 type == HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT ||
3264 type == HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_OUT ||
3265 type == HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_OUT)
3269 /* If this is a first pin - create new association. */
3270 if (as[cnt].pincnt == 0) {
3277 /* Check association correctness. */
3278 if (as[cnt].pins[seq] != 0) {
3279 device_printf(devinfo->dev, "%s: Duplicate pin %d (%d) "
3280 "in association %d! Disabling association.\n",
3281 __func__, seq, w->nid, j);
3284 if (dir != as[cnt].dir) {
3285 device_printf(devinfo->dev, "%s: Pin %d has wrong "
3286 "direction for association %d! Disabling "
3288 __func__, w->nid, j);
3291 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) {
3292 as[cnt].digital |= 0x1;
3293 if (HDA_PARAM_PIN_CAP_HDMI(w->wclass.pin.cap))
3294 as[cnt].digital |= 0x2;
3295 if (HDA_PARAM_PIN_CAP_DP(w->wclass.pin.cap))
3296 as[cnt].digital |= 0x4;
3298 if (as[cnt].location == -1) {
3300 HDA_CONFIG_DEFAULTCONF_LOCATION(w->wclass.pin.config);
3301 } else if (as[cnt].location !=
3302 HDA_CONFIG_DEFAULTCONF_LOCATION(w->wclass.pin.config)) {
3303 as[cnt].location = -2;
3305 /* Headphones with seq=15 may mean redirection. */
3306 if (type == HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT &&
3309 as[cnt].pins[seq] = w->nid;
3311 /* Association 15 is a multiple unassociated pins. */
3315 if (j != 15 && as[cnt].pincnt > 0) {
3316 if (hpredir && as[cnt].pincnt > 1)
3317 as[cnt].hpredir = first;
3321 for (i = 0; i < max; i++) {
3322 if (as[i].dir == HDAA_CTL_IN && (as[i].pincnt == 1 ||
3323 as[i].pins[14] > 0 || as[i].pins[15] > 0))
3327 device_printf(devinfo->dev,
3328 "%d associations found:\n", max);
3329 for (i = 0; i < max; i++) {
3330 device_printf(devinfo->dev,
3331 "Association %d (%d) %s%s:\n",
3332 i, as[i].index, (as[i].dir == HDAA_CTL_IN)?"in":"out",
3333 as[i].enable?"":" (disabled)");
3334 for (j = 0; j < 16; j++) {
3335 if (as[i].pins[j] == 0)
3337 device_printf(devinfo->dev,
3338 " Pin nid=%d seq=%d\n",
3348 * Trace path from DAC to pin.
3351 hdaa_audio_trace_dac(struct hdaa_devinfo *devinfo, int as, int seq, nid_t nid,
3352 int dupseq, int min, int only, int depth)
3354 struct hdaa_widget *w;
3358 if (depth > HDA_PARSE_MAXDEPTH)
3360 w = hdaa_widget_get(devinfo, nid);
3361 if (w == NULL || w->enable == 0)
3365 device_printf(devinfo->dev,
3366 " %*stracing via nid %d\n",
3367 depth + 1, "", w->nid);
3370 /* Use only unused widgets */
3371 if (w->bindas >= 0 && w->bindas != as) {
3374 device_printf(devinfo->dev,
3375 " %*snid %d busy by association %d\n",
3376 depth + 1, "", w->nid, w->bindas);
3382 if (w->bindseqmask != 0) {
3385 device_printf(devinfo->dev,
3386 " %*snid %d busy by seqmask %x\n",
3387 depth + 1, "", w->nid, w->bindseqmask);
3393 /* If this is headphones - allow duplicate first pin. */
3394 if (w->bindseqmask != 0 &&
3395 (w->bindseqmask & (1 << dupseq)) == 0) {
3397 device_printf(devinfo->dev,
3398 " %*snid %d busy by seqmask %x\n",
3399 depth + 1, "", w->nid, w->bindseqmask);
3406 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT:
3407 /* Do not traverse input. AD1988 has digital monitor
3408 for which we are not ready. */
3410 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT:
3411 /* If we are tracing HP take only dac of first pin. */
3412 if ((only == 0 || only == w->nid) &&
3413 (w->nid >= min) && (dupseq < 0 || w->nid ==
3414 devinfo->as[as].dacs[0][dupseq]))
3417 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
3422 /* Find reachable DACs with smallest nid respecting constraints. */
3423 for (i = 0; i < w->nconns; i++) {
3424 if (w->connsenable[i] == 0)
3426 if (w->selconn != -1 && w->selconn != i)
3428 if ((ret = hdaa_audio_trace_dac(devinfo, as, seq,
3429 w->conns[i], dupseq, min, only, depth + 1)) != 0) {
3430 if (m == 0 || ret < m) {
3434 if (only || dupseq >= 0)
3438 if (im >= 0 && only && ((w->nconns > 1 &&
3439 w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) ||
3440 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR))
3446 w->bindseqmask |= (1 << seq);
3450 device_printf(devinfo->dev,
3451 " %*snid %d returned %d\n",
3452 depth + 1, "", w->nid, m);
3459 * Trace path from widget to ADC.
3462 hdaa_audio_trace_adc(struct hdaa_devinfo *devinfo, int as, int seq, nid_t nid,
3463 int mixed, int min, int only, int depth, int *length, int onlylength)
3465 struct hdaa_widget *w, *wc;
3466 int i, j, im, lm = HDA_PARSE_MAXDEPTH;
3469 if (depth > HDA_PARSE_MAXDEPTH)
3471 w = hdaa_widget_get(devinfo, nid);
3472 if (w == NULL || w->enable == 0)
3475 device_printf(devinfo->dev,
3476 " %*stracing via nid %d\n",
3477 depth + 1, "", w->nid);
3479 /* Use only unused widgets */
3480 if (w->bindas >= 0 && w->bindas != as) {
3482 device_printf(devinfo->dev,
3483 " %*snid %d busy by association %d\n",
3484 depth + 1, "", w->nid, w->bindas);
3488 if (!mixed && w->bindseqmask != 0) {
3490 device_printf(devinfo->dev,
3491 " %*snid %d busy by seqmask %x\n",
3492 depth + 1, "", w->nid, w->bindseqmask);
3497 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT:
3498 if ((only == 0 || only == w->nid) && (w->nid >= min) &&
3499 (onlylength == 0 || onlylength == depth)) {
3504 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
3509 /* Try to find reachable ADCs with specified nid. */
3510 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
3511 wc = hdaa_widget_get(devinfo, j);
3512 if (wc == NULL || wc->enable == 0)
3515 for (i = 0; i < wc->nconns; i++) {
3516 if (wc->connsenable[i] == 0)
3518 if (wc->conns[i] != nid)
3520 if ((ret = hdaa_audio_trace_adc(devinfo, as, seq,
3521 j, mixed, min, only, depth + 1,
3522 length, onlylength)) != 0) {
3523 if (m == 0 || ret < m ||
3524 (ret == m && *length < lm)) {
3534 if (im >= 0 && only && ((wc->nconns > 1 &&
3535 wc->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) ||
3536 wc->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR))
3543 w->bindseqmask |= (1 << seq);
3546 device_printf(devinfo->dev,
3547 " %*snid %d returned %d\n",
3548 depth + 1, "", w->nid, m);
3554 * Erase trace path of the specified association.
3557 hdaa_audio_undo_trace(struct hdaa_devinfo *devinfo, int as, int seq)
3559 struct hdaa_widget *w;
3562 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3563 w = hdaa_widget_get(devinfo, i);
3564 if (w == NULL || w->enable == 0)
3566 if (w->bindas == as) {
3568 w->bindseqmask &= ~(1 << seq);
3569 if (w->bindseqmask == 0) {
3583 * Trace association path from DAC to output
3586 hdaa_audio_trace_as_out(struct hdaa_devinfo *devinfo, int as, int seq)
3588 struct hdaa_audio_as *ases = devinfo->as;
3593 for (i = seq; i < 16 && ases[as].pins[i] == 0; i++)
3595 /* Check if there is no any left. If so - we succeeded. */
3599 hpredir = (i == 15 && ases[as].fakeredir == 0)?ases[as].hpredir:-1;
3603 device_printf(devinfo->dev,
3604 " Tracing pin %d with min nid %d",
3605 ases[as].pins[i], min);
3607 kprintf(" and hpredir %d", hpredir);
3610 /* Trace this pin taking min nid into account. */
3611 res = hdaa_audio_trace_dac(devinfo, as, i,
3612 ases[as].pins[i], hpredir, min, 0, 0);
3614 /* If we failed - return to previous and redo it. */
3616 device_printf(devinfo->dev,
3617 " Unable to trace pin %d seq %d with min "
3619 ases[as].pins[i], i, min);
3621 kprintf(" and hpredir %d", hpredir);
3627 device_printf(devinfo->dev,
3628 " Pin %d traced to DAC %d",
3629 ases[as].pins[i], res);
3631 kprintf(" and hpredir %d", hpredir);
3632 if (ases[as].fakeredir)
3633 kprintf(" with fake redirection");
3636 /* Trace again to mark the path */
3637 hdaa_audio_trace_dac(devinfo, as, i,
3638 ases[as].pins[i], hpredir, min, res, 0);
3639 ases[as].dacs[0][i] = res;
3640 /* We succeeded, so call next. */
3641 if (hdaa_audio_trace_as_out(devinfo, as, i + 1))
3643 /* If next failed, we should retry with next min */
3644 hdaa_audio_undo_trace(devinfo, as, i);
3645 ases[as].dacs[0][i] = 0;
3651 * Check equivalency of two DACs.
3654 hdaa_audio_dacs_equal(struct hdaa_widget *w1, struct hdaa_widget *w2)
3656 struct hdaa_devinfo *devinfo = w1->devinfo;
3657 struct hdaa_widget *w3;
3660 if (memcmp(&w1->param, &w2->param, sizeof(w1->param)))
3662 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3663 w3 = hdaa_widget_get(devinfo, i);
3664 if (w3 == NULL || w3->enable == 0)
3666 if (w3->bindas != w1->bindas)
3668 if (w3->nconns == 0)
3671 for (j = 0; j < w3->nconns; j++) {
3672 if (w3->connsenable[j] == 0)
3674 if (w3->conns[j] == w1->nid)
3676 if (w3->conns[j] == w2->nid)
3683 if (w3->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
3690 * Check equivalency of two ADCs.
3693 hdaa_audio_adcs_equal(struct hdaa_widget *w1, struct hdaa_widget *w2)
3695 struct hdaa_devinfo *devinfo = w1->devinfo;
3696 struct hdaa_widget *w3, *w4;
3699 if (memcmp(&w1->param, &w2->param, sizeof(w1->param)))
3701 if (w1->nconns != 1 || w2->nconns != 1)
3703 if (w1->conns[0] == w2->conns[0])
3705 w3 = hdaa_widget_get(devinfo, w1->conns[0]);
3706 if (w3 == NULL || w3->enable == 0)
3708 w4 = hdaa_widget_get(devinfo, w2->conns[0]);
3709 if (w4 == NULL || w4->enable == 0)
3711 if (w3->bindas == w4->bindas && w3->bindseqmask == w4->bindseqmask)
3713 if (w4->bindas >= 0)
3715 if (w3->type != w4->type)
3717 if (memcmp(&w3->param, &w4->param, sizeof(w3->param)))
3719 if (w3->nconns != w4->nconns)
3721 for (i = 0; i < w3->nconns; i++) {
3722 if (w3->conns[i] != w4->conns[i])
3729 * Look for equivalent DAC/ADC to implement second channel.
3732 hdaa_audio_adddac(struct hdaa_devinfo *devinfo, int asid)
3734 struct hdaa_audio_as *as = &devinfo->as[asid];
3735 struct hdaa_widget *w1, *w2;
3740 device_printf(devinfo->dev,
3741 "Looking for additional %sC "
3742 "for association %d (%d)\n",
3743 (as->dir == HDAA_CTL_OUT) ? "DA" : "AD",
3747 /* Find the exisitng DAC position and return if found more the one. */
3749 for (i = 0; i < 16; i++) {
3750 if (as->dacs[0][i] <= 0)
3752 if (pos >= 0 && as->dacs[0][i] != as->dacs[0][pos])
3757 nid1 = as->dacs[0][pos];
3758 w1 = hdaa_widget_get(devinfo, nid1);
3760 for (nid2 = devinfo->startnode; nid2 < devinfo->endnode; nid2++) {
3761 w2 = hdaa_widget_get(devinfo, nid2);
3762 if (w2 == NULL || w2->enable == 0)
3764 if (w2->bindas >= 0)
3766 if (w1->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT) {
3767 if (w2->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT)
3769 if (hdaa_audio_dacs_equal(w1, w2))
3772 if (w2->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT)
3774 if (hdaa_audio_adcs_equal(w1, w2))
3778 if (nid2 >= devinfo->endnode)
3780 w2->bindas = w1->bindas;
3781 w2->bindseqmask = w1->bindseqmask;
3782 if (w1->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
3784 device_printf(devinfo->dev,
3785 " ADC %d considered equal to ADC %d\n", nid2, nid1);
3787 w1 = hdaa_widget_get(devinfo, w1->conns[0]);
3788 w2 = hdaa_widget_get(devinfo, w2->conns[0]);
3789 w2->bindas = w1->bindas;
3790 w2->bindseqmask = w1->bindseqmask;
3793 device_printf(devinfo->dev,
3794 " DAC %d considered equal to DAC %d\n", nid2, nid1);
3797 for (i = 0; i < 16; i++) {
3798 if (as->dacs[0][i] <= 0)
3800 as->dacs[as->num_chans][i] = nid2;
3806 * Trace association path from input to ADC
3809 hdaa_audio_trace_as_in(struct hdaa_devinfo *devinfo, int as)
3811 struct hdaa_audio_as *ases = devinfo->as;
3812 struct hdaa_widget *w;
3813 int i, j, k, length;
3815 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
3816 w = hdaa_widget_get(devinfo, j);
3817 if (w == NULL || w->enable == 0)
3819 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT)
3821 if (w->bindas >= 0 && w->bindas != as)
3825 for (i = 0; i < 16; i++) {
3826 if (ases[as].pins[i] == 0)
3830 device_printf(devinfo->dev,
3831 " Tracing pin %d to ADC %d\n",
3832 ases[as].pins[i], j);
3834 /* Trace this pin taking goal into account. */
3835 if (hdaa_audio_trace_adc(devinfo, as, i,
3836 ases[as].pins[i], 1, 0, j, 0, &length, 0) == 0) {
3837 /* If we failed - return to previous and redo it. */
3839 device_printf(devinfo->dev,
3840 " Unable to trace pin %d to ADC %d, undo traces\n",
3841 ases[as].pins[i], j);
3843 hdaa_audio_undo_trace(devinfo, as, -1);
3844 for (k = 0; k < 16; k++)
3845 ases[as].dacs[0][k] = 0;
3849 device_printf(devinfo->dev,
3850 " Pin %d traced to ADC %d\n",
3851 ases[as].pins[i], j);
3853 ases[as].dacs[0][i] = j;
3862 * Trace association path from input to multiple ADCs
3865 hdaa_audio_trace_as_in_mch(struct hdaa_devinfo *devinfo, int as, int seq)
3867 struct hdaa_audio_as *ases = devinfo->as;
3872 for (i = seq; i < 16 && ases[as].pins[i] == 0; i++)
3874 /* Check if there is no any left. If so - we succeeded. */
3881 device_printf(devinfo->dev,
3882 " Tracing pin %d with min nid %d",
3883 ases[as].pins[i], min);
3886 /* Trace this pin taking min nid into account. */
3887 res = hdaa_audio_trace_adc(devinfo, as, i,
3888 ases[as].pins[i], 0, min, 0, 0, &length, 0);
3890 /* If we failed - return to previous and redo it. */
3892 device_printf(devinfo->dev,
3893 " Unable to trace pin %d seq %d with min "
3895 ases[as].pins[i], i, min);
3901 device_printf(devinfo->dev,
3902 " Pin %d traced to ADC %d\n",
3903 ases[as].pins[i], res);
3905 /* Trace again to mark the path */
3906 hdaa_audio_trace_adc(devinfo, as, i,
3907 ases[as].pins[i], 0, min, res, 0, &length, length);
3908 ases[as].dacs[0][i] = res;
3909 /* We succeeded, so call next. */
3910 if (hdaa_audio_trace_as_in_mch(devinfo, as, i + 1))
3912 /* If next failed, we should retry with next min */
3913 hdaa_audio_undo_trace(devinfo, as, i);
3914 ases[as].dacs[0][i] = 0;
3920 * Trace input monitor path from mixer to output association.
3923 hdaa_audio_trace_to_out(struct hdaa_devinfo *devinfo, nid_t nid, int depth)
3925 struct hdaa_audio_as *ases = devinfo->as;
3926 struct hdaa_widget *w, *wc;
3930 if (depth > HDA_PARSE_MAXDEPTH)
3932 w = hdaa_widget_get(devinfo, nid);
3933 if (w == NULL || w->enable == 0)
3936 device_printf(devinfo->dev,
3937 " %*stracing via nid %d\n",
3938 depth + 1, "", w->nid);
3940 /* Use only unused widgets */
3941 if (depth > 0 && w->bindas != -1) {
3942 if (w->bindas < 0 || ases[w->bindas].dir == HDAA_CTL_OUT) {
3944 device_printf(devinfo->dev,
3945 " %*snid %d found output association %d\n",
3946 depth + 1, "", w->nid, w->bindas);
3949 w->pflags |= HDAA_ADC_MONITOR;
3953 device_printf(devinfo->dev,
3954 " %*snid %d busy by input association %d\n",
3955 depth + 1, "", w->nid, w->bindas);
3962 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT:
3963 /* Do not traverse input. AD1988 has digital monitor
3964 for which we are not ready. */
3966 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
3971 /* Try to find reachable ADCs with specified nid. */
3972 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
3973 wc = hdaa_widget_get(devinfo, j);
3974 if (wc == NULL || wc->enable == 0)
3976 for (i = 0; i < wc->nconns; i++) {
3977 if (wc->connsenable[i] == 0)
3979 if (wc->conns[i] != nid)
3981 if (hdaa_audio_trace_to_out(devinfo,
3982 j, depth + 1) != 0) {
3984 if (wc->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR &&
3992 if (res && w->bindas == -1)
3996 device_printf(devinfo->dev,
3997 " %*snid %d returned %d\n",
3998 depth + 1, "", w->nid, res);
4004 * Trace extra associations (beeper, monitor)
4007 hdaa_audio_trace_as_extra(struct hdaa_devinfo *devinfo)
4009 struct hdaa_audio_as *as = devinfo->as;
4010 struct hdaa_widget *w;
4014 /* Find mixer associated with input, but supplying signal
4015 for output associations. Hope it will be input monitor. */
4017 device_printf(devinfo->dev,
4018 "Tracing input monitor\n");
4020 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
4021 w = hdaa_widget_get(devinfo, j);
4022 if (w == NULL || w->enable == 0)
4024 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
4026 if (w->bindas < 0 || as[w->bindas].dir != HDAA_CTL_IN)
4029 device_printf(devinfo->dev,
4030 " Tracing nid %d to out\n",
4033 if (hdaa_audio_trace_to_out(devinfo, w->nid, 0)) {
4035 device_printf(devinfo->dev,
4036 " nid %d is input monitor\n",
4039 w->ossdev = SOUND_MIXER_IMIX;
4043 /* Other inputs monitor */
4044 /* Find input pins supplying signal for output associations.
4045 Hope it will be input monitoring. */
4047 device_printf(devinfo->dev,
4048 "Tracing other input monitors\n");
4050 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
4051 w = hdaa_widget_get(devinfo, j);
4052 if (w == NULL || w->enable == 0)
4054 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
4056 if (w->bindas < 0 || as[w->bindas].dir != HDAA_CTL_IN)
4059 device_printf(devinfo->dev,
4060 " Tracing nid %d to out\n",
4063 if (hdaa_audio_trace_to_out(devinfo, w->nid, 0)) {
4065 device_printf(devinfo->dev,
4066 " nid %d is input monitor\n",
4074 device_printf(devinfo->dev,
4075 "Tracing beeper\n");
4077 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
4078 w = hdaa_widget_get(devinfo, j);
4079 if (w == NULL || w->enable == 0)
4081 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET)
4084 device_printf(devinfo->dev,
4085 " Tracing nid %d to out\n",
4088 if (hdaa_audio_trace_to_out(devinfo, w->nid, 0)) {
4090 device_printf(devinfo->dev,
4091 " nid %d traced to out\n",
4100 * Bind assotiations to PCM channels
4103 hdaa_audio_bind_as(struct hdaa_devinfo *devinfo)
4105 struct hdaa_audio_as *as = devinfo->as;
4106 int i, j, cnt = 0, free;
4108 for (j = 0; j < devinfo->ascnt; j++) {
4110 cnt += as[j].num_chans;
4112 if (devinfo->num_chans == 0) {
4113 devinfo->chans = (struct hdaa_chan *)kmalloc(
4114 sizeof(struct hdaa_chan) * cnt,
4115 M_HDAA, M_ZERO | M_WAITOK);
4116 if (devinfo->chans == NULL) {
4117 device_printf(devinfo->dev,
4118 "Channels memory allocation failed!\n");
4122 devinfo->chans = (struct hdaa_chan *)krealloc(devinfo->chans,
4123 sizeof(struct hdaa_chan) * (devinfo->num_chans + cnt),
4124 M_HDAA, M_ZERO | M_WAITOK);
4125 if (devinfo->chans == NULL) {
4126 devinfo->num_chans = 0;
4127 device_printf(devinfo->dev,
4128 "Channels memory allocation failed!\n");
4131 /* Fixup relative pointers after realloc */
4132 for (j = 0; j < devinfo->num_chans; j++)
4133 devinfo->chans[j].caps.fmtlist = devinfo->chans[j].fmtlist;
4135 free = devinfo->num_chans;
4136 devinfo->num_chans += cnt;
4138 for (j = free; j < free + cnt; j++) {
4139 devinfo->chans[j].devinfo = devinfo;
4140 devinfo->chans[j].as = -1;
4143 /* Assign associations in order of their numbers, */
4144 for (j = 0; j < devinfo->ascnt; j++) {
4145 if (as[j].enable == 0)
4147 for (i = 0; i < as[j].num_chans; i++) {
4148 devinfo->chans[free].as = j;
4149 devinfo->chans[free].asindex = i;
4150 devinfo->chans[free].dir =
4151 (as[j].dir == HDAA_CTL_IN) ? PCMDIR_REC : PCMDIR_PLAY;
4152 hdaa_pcmchannel_setup(&devinfo->chans[free]);
4153 as[j].chans[i] = free;
4160 hdaa_audio_disable_nonaudio(struct hdaa_devinfo *devinfo)
4162 struct hdaa_widget *w;
4165 /* Disable power and volume widgets. */
4166 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4167 w = hdaa_widget_get(devinfo, i);
4168 if (w == NULL || w->enable == 0)
4170 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_POWER_WIDGET ||
4171 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_VOLUME_WIDGET) {
4174 device_printf(devinfo->dev,
4175 " Disabling nid %d due to it's"
4176 " non-audio type.\n",
4184 hdaa_audio_disable_useless(struct hdaa_devinfo *devinfo)
4186 struct hdaa_widget *w, *cw;
4187 struct hdaa_audio_ctl *ctl;
4188 int done, found, i, j, k;
4190 /* Disable useless pins. */
4191 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4192 w = hdaa_widget_get(devinfo, i);
4193 if (w == NULL || w->enable == 0)
4195 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) {
4196 if ((w->wclass.pin.config &
4197 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK) ==
4198 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_NONE) {
4201 device_printf(devinfo->dev,
4202 " Disabling pin nid %d due"
4203 " to None connectivity.\n",
4206 } else if ((w->wclass.pin.config &
4207 HDA_CONFIG_DEFAULTCONF_ASSOCIATION_MASK) == 0) {
4210 device_printf(devinfo->dev,
4211 " Disabling unassociated"
4220 /* Disable and mute controls for disabled widgets. */
4222 while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) {
4223 if (ctl->enable == 0)
4225 if (ctl->widget->enable == 0 ||
4226 (ctl->childwidget != NULL &&
4227 ctl->childwidget->enable == 0)) {
4229 ctl->muted = HDAA_AMP_MUTE_ALL;
4233 if (ctl->ndir == HDAA_CTL_IN)
4234 ctl->widget->connsenable[ctl->index] = 0;
4237 device_printf(devinfo->dev,
4238 " Disabling ctl %d nid %d cnid %d due"
4239 " to disabled widget.\n", i,
4241 (ctl->childwidget != NULL)?
4242 ctl->childwidget->nid:-1);
4246 /* Disable useless widgets. */
4247 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4248 w = hdaa_widget_get(devinfo, i);
4249 if (w == NULL || w->enable == 0)
4251 /* Disable inputs with disabled child widgets. */
4252 for (j = 0; j < w->nconns; j++) {
4253 if (w->connsenable[j]) {
4254 cw = hdaa_widget_get(devinfo, w->conns[j]);
4255 if (cw == NULL || cw->enable == 0) {
4256 w->connsenable[j] = 0;
4258 device_printf(devinfo->dev,
4259 " Disabling nid %d connection %d due"
4260 " to disabled child widget.\n",
4266 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR &&
4267 w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
4269 /* Disable mixers and selectors without inputs. */
4271 for (j = 0; j < w->nconns; j++) {
4272 if (w->connsenable[j]) {
4281 device_printf(devinfo->dev,
4282 " Disabling nid %d due to all it's"
4283 " inputs disabled.\n", w->nid);
4286 /* Disable nodes without consumers. */
4287 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR &&
4288 w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
4291 for (k = devinfo->startnode; k < devinfo->endnode; k++) {
4292 cw = hdaa_widget_get(devinfo, k);
4293 if (cw == NULL || cw->enable == 0)
4295 for (j = 0; j < cw->nconns; j++) {
4296 if (cw->connsenable[j] && cw->conns[j] == i) {
4306 device_printf(devinfo->dev,
4307 " Disabling nid %d due to all it's"
4308 " consumers disabled.\n", w->nid);
4312 } while (done == 0);
4317 hdaa_audio_disable_unas(struct hdaa_devinfo *devinfo)
4319 struct hdaa_audio_as *as = devinfo->as;
4320 struct hdaa_widget *w, *cw;
4321 struct hdaa_audio_ctl *ctl;
4324 /* Disable unassosiated widgets. */
4325 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4326 w = hdaa_widget_get(devinfo, i);
4327 if (w == NULL || w->enable == 0)
4329 if (w->bindas == -1) {
4332 device_printf(devinfo->dev,
4333 " Disabling unassociated nid %d.\n",
4338 /* Disable input connections on input pin and
4339 * output on output. */
4340 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4341 w = hdaa_widget_get(devinfo, i);
4342 if (w == NULL || w->enable == 0)
4344 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
4348 if (as[w->bindas].dir == HDAA_CTL_IN) {
4349 for (j = 0; j < w->nconns; j++) {
4350 if (w->connsenable[j] == 0)
4352 w->connsenable[j] = 0;
4354 device_printf(devinfo->dev,
4355 " Disabling connection to input pin "
4356 "nid %d conn %d.\n",
4360 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid,
4361 HDAA_CTL_IN, -1, 1);
4362 if (ctl && ctl->enable) {
4364 ctl->muted = HDAA_AMP_MUTE_ALL;
4370 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid,
4371 HDAA_CTL_OUT, -1, 1);
4372 if (ctl && ctl->enable) {
4374 ctl->muted = HDAA_AMP_MUTE_ALL;
4379 for (k = devinfo->startnode; k < devinfo->endnode; k++) {
4380 cw = hdaa_widget_get(devinfo, k);
4381 if (cw == NULL || cw->enable == 0)
4383 for (j = 0; j < cw->nconns; j++) {
4384 if (cw->connsenable[j] && cw->conns[j] == i) {
4385 cw->connsenable[j] = 0;
4387 device_printf(devinfo->dev,
4388 " Disabling connection from output pin "
4389 "nid %d conn %d cnid %d.\n",
4392 if (cw->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
4395 ctl = hdaa_audio_ctl_amp_get(devinfo, k,
4397 if (ctl && ctl->enable) {
4399 ctl->muted = HDAA_AMP_MUTE_ALL;
4412 hdaa_audio_disable_notselected(struct hdaa_devinfo *devinfo)
4414 struct hdaa_audio_as *as = devinfo->as;
4415 struct hdaa_widget *w;
4418 /* On playback path we can safely disable all unseleted inputs. */
4419 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4420 w = hdaa_widget_get(devinfo, i);
4421 if (w == NULL || w->enable == 0)
4425 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
4427 if (w->bindas < 0 || as[w->bindas].dir == HDAA_CTL_IN)
4429 for (j = 0; j < w->nconns; j++) {
4430 if (w->connsenable[j] == 0)
4432 if (w->selconn < 0 || w->selconn == j)
4434 w->connsenable[j] = 0;
4436 device_printf(devinfo->dev,
4437 " Disabling unselected connection "
4438 "nid %d conn %d.\n",
4446 hdaa_audio_disable_crossas(struct hdaa_devinfo *devinfo)
4448 struct hdaa_audio_as *ases = devinfo->as;
4449 struct hdaa_widget *w, *cw;
4450 struct hdaa_audio_ctl *ctl;
4453 /* Disable crossassociatement and unwanted crosschannel connections. */
4454 /* ... using selectors */
4455 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4456 w = hdaa_widget_get(devinfo, i);
4457 if (w == NULL || w->enable == 0)
4461 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
4463 /* Allow any -> mix */
4464 if (w->bindas == -2)
4466 for (j = 0; j < w->nconns; j++) {
4467 if (w->connsenable[j] == 0)
4469 cw = hdaa_widget_get(devinfo, w->conns[j]);
4470 if (cw == NULL || w->enable == 0)
4472 /* Allow mix -> out. */
4473 if (cw->bindas == -2 && w->bindas >= 0 &&
4474 ases[w->bindas].dir == HDAA_CTL_OUT)
4476 /* Allow mix -> mixed-in. */
4477 if (cw->bindas == -2 && w->bindas >= 0 &&
4478 ases[w->bindas].mixed)
4480 /* Allow in -> mix. */
4481 if ((w->pflags & HDAA_ADC_MONITOR) &&
4483 ases[cw->bindas].dir == HDAA_CTL_IN)
4485 /* Allow if have common as/seqs. */
4486 if (w->bindas == cw->bindas &&
4487 (w->bindseqmask & cw->bindseqmask) != 0)
4489 w->connsenable[j] = 0;
4491 device_printf(devinfo->dev,
4492 " Disabling crossassociatement connection "
4493 "nid %d conn %d cnid %d.\n",
4498 /* ... using controls */
4500 while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) {
4501 if (ctl->enable == 0 || ctl->childwidget == NULL)
4503 /* Allow any -> mix */
4504 if (ctl->widget->bindas == -2)
4506 /* Allow mix -> out. */
4507 if (ctl->childwidget->bindas == -2 &&
4508 ctl->widget->bindas >= 0 &&
4509 ases[ctl->widget->bindas].dir == HDAA_CTL_OUT)
4511 /* Allow mix -> mixed-in. */
4512 if (ctl->childwidget->bindas == -2 &&
4513 ctl->widget->bindas >= 0 &&
4514 ases[ctl->widget->bindas].mixed)
4516 /* Allow in -> mix. */
4517 if ((ctl->widget->pflags & HDAA_ADC_MONITOR) &&
4518 ctl->childwidget->bindas >= 0 &&
4519 ases[ctl->childwidget->bindas].dir == HDAA_CTL_IN)
4521 /* Allow if have common as/seqs. */
4522 if (ctl->widget->bindas == ctl->childwidget->bindas &&
4523 (ctl->widget->bindseqmask & ctl->childwidget->bindseqmask) != 0)
4526 ctl->muted = HDAA_AMP_MUTE_ALL;
4530 if (ctl->ndir == HDAA_CTL_IN)
4531 ctl->widget->connsenable[ctl->index] = 0;
4533 device_printf(devinfo->dev,
4534 " Disabling crossassociatement connection "
4535 "ctl %d nid %d cnid %d.\n", i,
4537 ctl->childwidget->nid);
4544 * Find controls to control amplification for source and calculate possible
4545 * amplification range.
4548 hdaa_audio_ctl_source_amp(struct hdaa_devinfo *devinfo, nid_t nid, int index,
4549 int ossdev, int ctlable, int depth, int *minamp, int *maxamp)
4551 struct hdaa_widget *w, *wc;
4552 struct hdaa_audio_ctl *ctl;
4553 int i, j, conns = 0, tminamp, tmaxamp, cminamp, cmaxamp, found = 0;
4555 if (depth > HDA_PARSE_MAXDEPTH)
4558 w = hdaa_widget_get(devinfo, nid);
4559 if (w == NULL || w->enable == 0)
4562 /* Count number of active inputs. */
4564 for (j = 0; j < w->nconns; j++) {
4565 if (!w->connsenable[j])
4571 /* If this is not a first step - use input mixer.
4572 Pins have common input ctl so care must be taken. */
4573 if (depth > 0 && ctlable && (conns == 1 ||
4574 w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)) {
4575 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, HDAA_CTL_IN,
4578 ctl->ossmask |= (1 << ossdev);
4580 if (*minamp == *maxamp) {
4581 *minamp += MINQDB(ctl);
4582 *maxamp += MAXQDB(ctl);
4587 /* If widget has own ossdev - not traverse it.
4588 It will be traversed on it's own. */
4589 if (w->ossdev >= 0 && depth > 0)
4592 /* We must not traverse pin */
4593 if ((w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT ||
4594 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) &&
4598 /* record that this widget exports such signal, */
4599 w->ossmask |= (1 << ossdev);
4602 * If signals mixed, we can't assign controls farther.
4603 * Ignore this on depth zero. Caller must knows why.
4606 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
4610 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, HDAA_CTL_OUT, -1, 1);
4612 ctl->ossmask |= (1 << ossdev);
4614 if (*minamp == *maxamp) {
4615 *minamp += MINQDB(ctl);
4616 *maxamp += MAXQDB(ctl);
4621 cminamp = cmaxamp = 0;
4622 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4623 wc = hdaa_widget_get(devinfo, i);
4624 if (wc == NULL || wc->enable == 0)
4626 for (j = 0; j < wc->nconns; j++) {
4627 if (wc->connsenable[j] && wc->conns[j] == nid) {
4628 tminamp = tmaxamp = 0;
4629 found += hdaa_audio_ctl_source_amp(devinfo,
4630 wc->nid, j, ossdev, ctlable, depth + 1,
4631 &tminamp, &tmaxamp);
4632 if (cminamp == 0 && cmaxamp == 0) {
4635 } else if (tminamp != tmaxamp) {
4636 cminamp = imax(cminamp, tminamp);
4637 cmaxamp = imin(cmaxamp, tmaxamp);
4642 if (*minamp == *maxamp && cminamp < cmaxamp) {
4650 * Find controls to control amplification for destination and calculate
4651 * possible amplification range.
4654 hdaa_audio_ctl_dest_amp(struct hdaa_devinfo *devinfo, nid_t nid, int index,
4655 int ossdev, int depth, int *minamp, int *maxamp)
4657 struct hdaa_audio_as *as = devinfo->as;
4658 struct hdaa_widget *w, *wc;
4659 struct hdaa_audio_ctl *ctl;
4660 int i, j, consumers, tminamp, tmaxamp, cminamp, cmaxamp, found = 0;
4662 if (depth > HDA_PARSE_MAXDEPTH)
4665 w = hdaa_widget_get(devinfo, nid);
4666 if (w == NULL || w->enable == 0)
4670 /* If this node produce output for several consumers,
4671 we can't touch it. */
4673 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4674 wc = hdaa_widget_get(devinfo, i);
4675 if (wc == NULL || wc->enable == 0)
4677 for (j = 0; j < wc->nconns; j++) {
4678 if (wc->connsenable[j] && wc->conns[j] == nid)
4682 /* The only exception is if real HP redirection is configured
4683 and this is a duplication point.
4684 XXX: Actually exception is not completely correct.
4685 XXX: Duplication point check is not perfect. */
4686 if ((consumers == 2 && (w->bindas < 0 ||
4687 as[w->bindas].hpredir < 0 || as[w->bindas].fakeredir ||
4688 (w->bindseqmask & (1 << 15)) == 0)) ||
4692 /* Else use it's output mixer. */
4693 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid,
4694 HDAA_CTL_OUT, -1, 1);
4696 ctl->ossmask |= (1 << ossdev);
4698 if (*minamp == *maxamp) {
4699 *minamp += MINQDB(ctl);
4700 *maxamp += MAXQDB(ctl);
4705 /* We must not traverse pin */
4706 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
4710 cminamp = cmaxamp = 0;
4711 for (i = 0; i < w->nconns; i++) {
4712 if (w->connsenable[i] == 0)
4714 if (index >= 0 && i != index)
4716 tminamp = tmaxamp = 0;
4717 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid,
4720 ctl->ossmask |= (1 << ossdev);
4722 if (*minamp == *maxamp) {
4723 tminamp += MINQDB(ctl);
4724 tmaxamp += MAXQDB(ctl);
4727 found += hdaa_audio_ctl_dest_amp(devinfo, w->conns[i], -1, ossdev,
4728 depth + 1, &tminamp, &tmaxamp);
4729 if (cminamp == 0 && cmaxamp == 0) {
4732 } else if (tminamp != tmaxamp) {
4733 cminamp = imax(cminamp, tminamp);
4734 cmaxamp = imin(cmaxamp, tmaxamp);
4737 if (*minamp == *maxamp && cminamp < cmaxamp) {
4745 * Assign OSS names to sound sources
4748 hdaa_audio_assign_names(struct hdaa_devinfo *devinfo)
4750 struct hdaa_audio_as *as = devinfo->as;
4751 struct hdaa_widget *w;
4753 int type = -1, use, used = 0;
4754 static const int types[7][13] = {
4755 { SOUND_MIXER_LINE, SOUND_MIXER_LINE1, SOUND_MIXER_LINE2,
4756 SOUND_MIXER_LINE3, -1 }, /* line */
4757 { SOUND_MIXER_MONITOR, SOUND_MIXER_MIC, -1 }, /* int mic */
4758 { SOUND_MIXER_MIC, SOUND_MIXER_MONITOR, -1 }, /* ext mic */
4759 { SOUND_MIXER_CD, -1 }, /* cd */
4760 { SOUND_MIXER_SPEAKER, -1 }, /* speaker */
4761 { SOUND_MIXER_DIGITAL1, SOUND_MIXER_DIGITAL2, SOUND_MIXER_DIGITAL3,
4763 { SOUND_MIXER_LINE, SOUND_MIXER_LINE1, SOUND_MIXER_LINE2,
4764 SOUND_MIXER_LINE3, SOUND_MIXER_PHONEIN, SOUND_MIXER_PHONEOUT,
4765 SOUND_MIXER_VIDEO, SOUND_MIXER_RADIO, SOUND_MIXER_DIGITAL1,
4766 SOUND_MIXER_DIGITAL2, SOUND_MIXER_DIGITAL3, SOUND_MIXER_MONITOR,
4770 /* Surely known names */
4771 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4772 w = hdaa_widget_get(devinfo, i);
4773 if (w == NULL || w->enable == 0)
4775 if (w->bindas == -1)
4779 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
4780 if (as[w->bindas].dir == HDAA_CTL_OUT)
4783 switch (w->wclass.pin.config & HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) {
4784 case HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN:
4787 case HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN:
4788 if ((w->wclass.pin.config & HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK)
4789 == HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_JACK)
4793 case HDA_CONFIG_DEFAULTCONF_DEVICE_CD:
4796 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER:
4799 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_IN:
4800 case HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_IN:
4807 while (types[type][j] >= 0 &&
4808 (used & (1 << types[type][j])) != 0) {
4811 if (types[type][j] >= 0)
4812 use = types[type][j];
4814 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT:
4815 use = SOUND_MIXER_PCM;
4817 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET:
4818 use = SOUND_MIXER_SPEAKER;
4828 /* Semi-known names */
4829 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4830 w = hdaa_widget_get(devinfo, i);
4831 if (w == NULL || w->enable == 0)
4835 if (w->bindas == -1)
4837 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
4839 if (as[w->bindas].dir == HDAA_CTL_OUT)
4842 switch (w->wclass.pin.config & HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) {
4843 case HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_OUT:
4844 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER:
4845 case HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT:
4846 case HDA_CONFIG_DEFAULTCONF_DEVICE_AUX:
4849 case HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN:
4852 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_OUT:
4853 case HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_OUT:
4860 while (types[type][j] >= 0 &&
4861 (used & (1 << types[type][j])) != 0) {
4864 if (types[type][j] >= 0) {
4865 w->ossdev = types[type][j];
4866 used |= (1 << types[type][j]);
4870 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4871 w = hdaa_widget_get(devinfo, i);
4872 if (w == NULL || w->enable == 0)
4876 if (w->bindas == -1)
4878 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
4880 if (as[w->bindas].dir == HDAA_CTL_OUT)
4883 while (types[6][j] >= 0 &&
4884 (used & (1 << types[6][j])) != 0) {
4887 if (types[6][j] >= 0) {
4888 w->ossdev = types[6][j];
4889 used |= (1 << types[6][j]);
4895 hdaa_audio_build_tree(struct hdaa_devinfo *devinfo)
4897 struct hdaa_audio_as *as = devinfo->as;
4900 /* Trace all associations in order of their numbers. */
4901 for (j = 0; j < devinfo->ascnt; j++) {
4902 if (as[j].enable == 0)
4905 device_printf(devinfo->dev,
4906 "Tracing association %d (%d)\n", j, as[j].index);
4908 if (as[j].dir == HDAA_CTL_OUT) {
4910 res = hdaa_audio_trace_as_out(devinfo, j, 0);
4911 if (res == 0 && as[j].hpredir >= 0 &&
4912 as[j].fakeredir == 0) {
4913 /* If CODEC can't do analog HP redirection
4914 try to make it using one more DAC. */
4915 as[j].fakeredir = 1;
4918 } else if (as[j].mixed)
4919 res = hdaa_audio_trace_as_in(devinfo, j);
4921 res = hdaa_audio_trace_as_in_mch(devinfo, j, 0);
4924 device_printf(devinfo->dev,
4925 "Association %d (%d) trace succeeded\n",
4930 device_printf(devinfo->dev,
4931 "Association %d (%d) trace failed\n",
4938 /* Look for additional DACs/ADCs. */
4939 for (j = 0; j < devinfo->ascnt; j++) {
4940 if (as[j].enable == 0)
4942 hdaa_audio_adddac(devinfo, j);
4945 /* Trace mixer and beeper pseudo associations. */
4946 hdaa_audio_trace_as_extra(devinfo);
4950 * Store in pdevinfo new data about whether and how we can control signal
4951 * for OSS device to/from specified widget.
4954 hdaa_adjust_amp(struct hdaa_widget *w, int ossdev,
4955 int found, int minamp, int maxamp)
4957 struct hdaa_devinfo *devinfo = w->devinfo;
4958 struct hdaa_pcm_devinfo *pdevinfo;
4961 pdevinfo = devinfo->as[w->bindas].pdevinfo;
4963 pdevinfo = &devinfo->devs[0];
4965 pdevinfo->ossmask |= (1 << ossdev);
4966 if (minamp == 0 && maxamp == 0)
4968 if (pdevinfo->minamp[ossdev] == 0 && pdevinfo->maxamp[ossdev] == 0) {
4969 pdevinfo->minamp[ossdev] = minamp;
4970 pdevinfo->maxamp[ossdev] = maxamp;
4972 pdevinfo->minamp[ossdev] = imax(pdevinfo->minamp[ossdev], minamp);
4973 pdevinfo->maxamp[ossdev] = imin(pdevinfo->maxamp[ossdev], maxamp);
4978 * Trace signals from/to all possible sources/destionstions to find possible
4979 * recording sources, OSS device control ranges and to assign controls.
4982 hdaa_audio_assign_mixers(struct hdaa_devinfo *devinfo)
4984 struct hdaa_audio_as *as = devinfo->as;
4985 struct hdaa_widget *w, *cw;
4986 int i, j, minamp, maxamp, found;
4988 /* Assign mixers to the tree. */
4989 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4990 w = hdaa_widget_get(devinfo, i);
4991 if (w == NULL || w->enable == 0)
4993 minamp = maxamp = 0;
4994 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT ||
4995 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET ||
4996 (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
4997 as[w->bindas].dir == HDAA_CTL_IN)) {
5000 found = hdaa_audio_ctl_source_amp(devinfo, w->nid, -1,
5001 w->ossdev, 1, 0, &minamp, &maxamp);
5002 hdaa_adjust_amp(w, w->ossdev, found, minamp, maxamp);
5003 } else if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
5004 found = hdaa_audio_ctl_dest_amp(devinfo, w->nid, -1,
5005 SOUND_MIXER_RECLEV, 0, &minamp, &maxamp);
5006 hdaa_adjust_amp(w, SOUND_MIXER_RECLEV, found, minamp, maxamp);
5007 } else if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
5008 as[w->bindas].dir == HDAA_CTL_OUT) {
5009 found = hdaa_audio_ctl_dest_amp(devinfo, w->nid, -1,
5010 SOUND_MIXER_VOLUME, 0, &minamp, &maxamp);
5011 hdaa_adjust_amp(w, SOUND_MIXER_VOLUME, found, minamp, maxamp);
5013 if (w->ossdev == SOUND_MIXER_IMIX) {
5014 minamp = maxamp = 0;
5015 found = hdaa_audio_ctl_source_amp(devinfo, w->nid, -1,
5016 w->ossdev, 1, 0, &minamp, &maxamp);
5017 if (minamp == maxamp) {
5018 /* If we are unable to control input monitor
5019 as source - try to control it as destination. */
5020 found += hdaa_audio_ctl_dest_amp(devinfo, w->nid, -1,
5021 w->ossdev, 0, &minamp, &maxamp);
5022 w->pflags |= HDAA_IMIX_AS_DST;
5024 hdaa_adjust_amp(w, w->ossdev, found, minamp, maxamp);
5026 if (w->pflags & HDAA_ADC_MONITOR) {
5027 for (j = 0; j < w->nconns; j++) {
5028 if (!w->connsenable[j])
5030 cw = hdaa_widget_get(devinfo, w->conns[j]);
5031 if (cw == NULL || cw->enable == 0)
5033 if (cw->bindas == -1)
5035 if (cw->bindas >= 0 &&
5036 as[cw->bindas].dir != HDAA_CTL_IN)
5038 minamp = maxamp = 0;
5039 found = hdaa_audio_ctl_dest_amp(devinfo,
5040 w->nid, j, SOUND_MIXER_IGAIN, 0,
5042 hdaa_adjust_amp(w, SOUND_MIXER_IGAIN,
5043 found, minamp, maxamp);
5050 hdaa_audio_prepare_pin_ctrl(struct hdaa_devinfo *devinfo)
5052 struct hdaa_audio_as *as = devinfo->as;
5053 struct hdaa_widget *w;
5057 for (i = 0; i < devinfo->nodecnt; i++) {
5058 w = &devinfo->widget[i];
5061 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
5065 pincap = w->wclass.pin.cap;
5067 /* Disable everything. */
5068 w->wclass.pin.ctrl &= ~(
5069 HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE |
5070 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE |
5071 HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE |
5072 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK);
5074 if (w->enable == 0) {
5075 /* Pin is unused so left it disabled. */
5077 } else if (w->waspin) {
5078 /* Enable input for beeper input. */
5079 w->wclass.pin.ctrl |=
5080 HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE;
5081 } else if (w->bindas < 0 || as[w->bindas].enable == 0) {
5082 /* Pin is unused so left it disabled. */
5084 } else if (as[w->bindas].dir == HDAA_CTL_IN) {
5085 /* Input pin, configure for input. */
5086 if (HDA_PARAM_PIN_CAP_INPUT_CAP(pincap))
5087 w->wclass.pin.ctrl |=
5088 HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE;
5090 if ((devinfo->quirks & HDAA_QUIRK_IVREF100) &&
5091 HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap))
5092 w->wclass.pin.ctrl |=
5093 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
5094 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_100);
5095 else if ((devinfo->quirks & HDAA_QUIRK_IVREF80) &&
5096 HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap))
5097 w->wclass.pin.ctrl |=
5098 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
5099 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_80);
5100 else if ((devinfo->quirks & HDAA_QUIRK_IVREF50) &&
5101 HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap))
5102 w->wclass.pin.ctrl |=
5103 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
5104 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_50);
5106 /* Output pin, configure for output. */
5107 if (HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap))
5108 w->wclass.pin.ctrl |=
5109 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
5111 if (HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap) &&
5112 (w->wclass.pin.config &
5113 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) ==
5114 HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT)
5115 w->wclass.pin.ctrl |=
5116 HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE;
5118 if ((devinfo->quirks & HDAA_QUIRK_OVREF100) &&
5119 HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap))
5120 w->wclass.pin.ctrl |=
5121 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
5122 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_100);
5123 else if ((devinfo->quirks & HDAA_QUIRK_OVREF80) &&
5124 HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap))
5125 w->wclass.pin.ctrl |=
5126 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
5127 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_80);
5128 else if ((devinfo->quirks & HDAA_QUIRK_OVREF50) &&
5129 HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap))
5130 w->wclass.pin.ctrl |=
5131 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
5132 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_50);
5138 hdaa_audio_ctl_commit(struct hdaa_devinfo *devinfo)
5140 struct hdaa_audio_ctl *ctl;
5144 while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) {
5145 if (ctl->enable == 0 || ctl->ossmask != 0) {
5146 /* Mute disabled and mixer controllable controls.
5147 * Last will be initialized by mixer_init().
5148 * This expected to reduce click on startup. */
5149 hdaa_audio_ctl_amp_set(ctl, HDAA_AMP_MUTE_ALL, 0, 0);
5152 /* Init fixed controls to 0dB amplification. */
5156 hdaa_audio_ctl_amp_set(ctl, HDAA_AMP_MUTE_NONE, z, z);
5161 hdaa_gpio_commit(struct hdaa_devinfo *devinfo)
5163 uint32_t gdata, gmask, gdir;
5166 numgpio = HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap);
5167 if (devinfo->gpio != 0 && numgpio != 0) {
5168 gdata = hda_command(devinfo->dev,
5169 HDA_CMD_GET_GPIO_DATA(0, devinfo->nid));
5170 gmask = hda_command(devinfo->dev,
5171 HDA_CMD_GET_GPIO_ENABLE_MASK(0, devinfo->nid));
5172 gdir = hda_command(devinfo->dev,
5173 HDA_CMD_GET_GPIO_DIRECTION(0, devinfo->nid));
5174 for (i = 0; i < numgpio; i++) {
5175 if ((devinfo->gpio & HDAA_GPIO_MASK(i)) ==
5180 } else if ((devinfo->gpio & HDAA_GPIO_MASK(i)) ==
5181 HDAA_GPIO_CLEAR(i)) {
5185 } else if ((devinfo->gpio & HDAA_GPIO_MASK(i)) ==
5186 HDAA_GPIO_DISABLE(i)) {
5188 } else if ((devinfo->gpio & HDAA_GPIO_MASK(i)) ==
5189 HDAA_GPIO_INPUT(i)) {
5195 device_printf(devinfo->dev, "GPIO commit\n");
5197 hda_command(devinfo->dev,
5198 HDA_CMD_SET_GPIO_ENABLE_MASK(0, devinfo->nid, gmask));
5199 hda_command(devinfo->dev,
5200 HDA_CMD_SET_GPIO_DIRECTION(0, devinfo->nid, gdir));
5201 hda_command(devinfo->dev,
5202 HDA_CMD_SET_GPIO_DATA(0, devinfo->nid, gdata));
5204 hdaa_dump_gpio(devinfo);
5210 hdaa_gpo_commit(struct hdaa_devinfo *devinfo)
5215 numgpo = HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap);
5216 if (devinfo->gpo != 0 && numgpo != 0) {
5217 gdata = hda_command(devinfo->dev,
5218 HDA_CMD_GET_GPO_DATA(0, devinfo->nid));
5219 for (i = 0; i < numgpo; i++) {
5220 if ((devinfo->gpio & HDAA_GPIO_MASK(i)) ==
5223 } else if ((devinfo->gpio & HDAA_GPIO_MASK(i)) ==
5224 HDAA_GPIO_CLEAR(i)) {
5229 device_printf(devinfo->dev, "GPO commit\n");
5231 hda_command(devinfo->dev,
5232 HDA_CMD_SET_GPO_DATA(0, devinfo->nid, gdata));
5234 hdaa_dump_gpo(devinfo);
5240 hdaa_audio_commit(struct hdaa_devinfo *devinfo)
5242 struct hdaa_widget *w;
5245 /* Commit controls. */
5246 hdaa_audio_ctl_commit(devinfo);
5248 /* Commit selectors, pins and EAPD. */
5249 for (i = 0; i < devinfo->nodecnt; i++) {
5250 w = &devinfo->widget[i];
5253 if (w->selconn == -1)
5256 hdaa_widget_connection_select(w, w->selconn);
5257 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX ||
5259 hda_command(devinfo->dev,
5260 HDA_CMD_SET_PIN_WIDGET_CTRL(0, w->nid,
5261 w->wclass.pin.ctrl));
5263 if (w->param.eapdbtl != HDA_INVALID) {
5266 val = w->param.eapdbtl;
5267 if (devinfo->quirks &
5269 val ^= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
5270 hda_command(devinfo->dev,
5271 HDA_CMD_SET_EAPD_BTL_ENABLE(0, w->nid,
5276 hdaa_gpio_commit(devinfo);
5277 hdaa_gpo_commit(devinfo);
5281 hdaa_powerup(struct hdaa_devinfo *devinfo)
5285 hda_command(devinfo->dev,
5286 HDA_CMD_SET_POWER_STATE(0,
5287 devinfo->nid, HDA_CMD_POWER_STATE_D0));
5290 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5291 hda_command(devinfo->dev,
5292 HDA_CMD_SET_POWER_STATE(0,
5293 i, HDA_CMD_POWER_STATE_D0));
5299 hdaa_pcmchannel_setup(struct hdaa_chan *ch)
5301 struct hdaa_devinfo *devinfo = ch->devinfo;
5302 struct hdaa_audio_as *as = devinfo->as;
5303 struct hdaa_widget *w;
5304 uint32_t cap, fmtcap, pcmcap;
5305 int i, j, ret, channels, onlystereo;
5308 ch->caps = hdaa_caps;
5309 ch->caps.fmtlist = ch->fmtlist;
5312 ch->pcmrates[0] = 48000;
5313 ch->pcmrates[1] = 0;
5314 ch->stripecap = 0xff;
5320 fmtcap = devinfo->supp_stream_formats;
5321 pcmcap = devinfo->supp_pcm_size_rate;
5323 for (i = 0; i < 16; i++) {
5324 /* Check as is correct */
5327 /* Cound only present DACs */
5328 if (as[ch->as].dacs[ch->asindex][i] <= 0)
5330 /* Ignore duplicates */
5331 for (j = 0; j < ret; j++) {
5332 if (ch->io[j] == as[ch->as].dacs[ch->asindex][i])
5338 w = hdaa_widget_get(devinfo, as[ch->as].dacs[ch->asindex][i]);
5339 if (w == NULL || w->enable == 0)
5341 cap = w->param.supp_stream_formats;
5342 if (!HDA_PARAM_SUPP_STREAM_FORMATS_PCM(cap) &&
5343 !HDA_PARAM_SUPP_STREAM_FORMATS_AC3(cap))
5345 /* Many CODECs does not declare AC3 support on SPDIF.
5346 I don't beleave that they doesn't support it! */
5347 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap))
5348 cap |= HDA_PARAM_SUPP_STREAM_FORMATS_AC3_MASK;
5351 pcmcap = w->param.supp_pcm_size_rate;
5354 pcmcap &= w->param.supp_pcm_size_rate;
5356 ch->io[ret++] = as[ch->as].dacs[ch->asindex][i];
5357 ch->stripecap &= w->wclass.conv.stripecap;
5358 /* Do not count redirection pin/dac channels. */
5359 if (i == 15 && as[ch->as].hpredir >= 0)
5361 channels += HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap) + 1;
5362 if (HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap) != 1)
5367 ch->channels = channels;
5369 if (as[ch->as].fakeredir)
5371 /* Standard speaks only about stereo pins and playback, ... */
5372 if ((!onlystereo) || as[ch->as].mixed)
5374 /* ..., but there it gives us info about speakers layout. */
5375 as[ch->as].pinset = pinset;
5377 ch->supp_stream_formats = fmtcap;
5378 ch->supp_pcm_size_rate = pcmcap;
5389 if (HDA_PARAM_SUPP_STREAM_FORMATS_PCM(fmtcap)) {
5390 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16BIT(pcmcap))
5392 else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8BIT(pcmcap))
5394 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(pcmcap))
5396 else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(pcmcap))
5398 else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(pcmcap))
5400 if (!(devinfo->quirks & HDAA_QUIRK_FORCESTEREO)) {
5401 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 1, 0);
5403 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 1, 0);
5405 if (channels >= 2) {
5406 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 2, 0);
5408 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 2, 0);
5410 if (channels >= 3 && !onlystereo) {
5411 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 3, 0);
5413 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 3, 0);
5414 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 3, 1);
5416 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 3, 1);
5418 if (channels >= 4) {
5419 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 4, 0);
5421 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 4, 0);
5423 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 4, 1);
5425 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 4, 1);
5428 if (channels >= 5 && !onlystereo) {
5429 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 5, 0);
5431 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 5, 0);
5432 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 5, 1);
5434 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 5, 1);
5436 if (channels >= 6) {
5437 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 6, 1);
5439 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 6, 1);
5441 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 6, 0);
5443 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 6, 0);
5446 if (channels >= 7 && !onlystereo) {
5447 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 7, 0);
5449 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 7, 0);
5450 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 7, 1);
5452 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 7, 1);
5454 if (channels >= 8) {
5455 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 8, 1);
5457 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 8, 1);
5460 if (HDA_PARAM_SUPP_STREAM_FORMATS_AC3(fmtcap)) {
5461 ch->fmtlist[i++] = SND_FORMAT(AFMT_AC3, 2, 0);
5462 if (channels >= 8) {
5463 ch->fmtlist[i++] = SND_FORMAT(AFMT_AC3, 8, 0);
5464 ch->fmtlist[i++] = SND_FORMAT(AFMT_AC3, 8, 1);
5469 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8KHZ(pcmcap))
5470 ch->pcmrates[i++] = 8000;
5471 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_11KHZ(pcmcap))
5472 ch->pcmrates[i++] = 11025;
5473 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16KHZ(pcmcap))
5474 ch->pcmrates[i++] = 16000;
5475 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_22KHZ(pcmcap))
5476 ch->pcmrates[i++] = 22050;
5477 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32KHZ(pcmcap))
5478 ch->pcmrates[i++] = 32000;
5479 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_44KHZ(pcmcap))
5480 ch->pcmrates[i++] = 44100;
5481 /* if (HDA_PARAM_SUPP_PCM_SIZE_RATE_48KHZ(pcmcap)) */
5482 ch->pcmrates[i++] = 48000;
5483 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_88KHZ(pcmcap))
5484 ch->pcmrates[i++] = 88200;
5485 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_96KHZ(pcmcap))
5486 ch->pcmrates[i++] = 96000;
5487 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_176KHZ(pcmcap))
5488 ch->pcmrates[i++] = 176400;
5489 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_192KHZ(pcmcap))
5490 ch->pcmrates[i++] = 192000;
5491 /* if (HDA_PARAM_SUPP_PCM_SIZE_RATE_384KHZ(pcmcap)) */
5492 ch->pcmrates[i] = 0;
5494 ch->caps.minspeed = ch->pcmrates[0];
5495 ch->caps.maxspeed = ch->pcmrates[i - 1];
5503 hdaa_prepare_pcms(struct hdaa_devinfo *devinfo)
5505 struct hdaa_audio_as *as = devinfo->as;
5506 int i, j, k, apdev = 0, ardev = 0, dpdev = 0, drdev = 0;
5508 for (i = 0; i < devinfo->ascnt; i++) {
5509 if (as[i].enable == 0)
5511 if (as[i].dir == HDAA_CTL_IN) {
5524 max(ardev, apdev) + max(drdev, dpdev);
5526 (struct hdaa_pcm_devinfo *)kmalloc(
5527 devinfo->num_devs * sizeof(struct hdaa_pcm_devinfo),
5528 M_HDAA, M_ZERO | M_WAITOK);
5529 if (devinfo->devs == NULL) {
5530 device_printf(devinfo->dev,
5531 "Unable to allocate memory for devices\n");
5534 for (i = 0; i < devinfo->num_devs; i++) {
5535 devinfo->devs[i].index = i;
5536 devinfo->devs[i].devinfo = devinfo;
5537 devinfo->devs[i].playas = -1;
5538 devinfo->devs[i].recas = -1;
5539 devinfo->devs[i].digital = 255;
5541 for (i = 0; i < devinfo->ascnt; i++) {
5542 if (as[i].enable == 0)
5544 for (j = 0; j < devinfo->num_devs; j++) {
5545 if (devinfo->devs[j].digital != 255 &&
5546 (!devinfo->devs[j].digital) !=
5549 if (as[i].dir == HDAA_CTL_IN) {
5550 if (devinfo->devs[j].recas >= 0)
5552 devinfo->devs[j].recas = i;
5554 if (devinfo->devs[j].playas >= 0)
5556 devinfo->devs[j].playas = i;
5558 as[i].pdevinfo = &devinfo->devs[j];
5559 for (k = 0; k < as[i].num_chans; k++) {
5560 devinfo->chans[as[i].chans[k]].pdevinfo =
5563 devinfo->devs[j].digital = as[i].digital;
5570 hdaa_create_pcms(struct hdaa_devinfo *devinfo)
5574 for (i = 0; i < devinfo->num_devs; i++) {
5575 struct hdaa_pcm_devinfo *pdevinfo = &devinfo->devs[i];
5577 pdevinfo->dev = device_add_child(devinfo->dev, "pcm", -1);
5578 device_set_ivars(pdevinfo->dev, (void *)pdevinfo);
5583 hdaa_dump_ctls(struct hdaa_pcm_devinfo *pdevinfo, const char *banner, uint32_t flag)
5585 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
5586 struct hdaa_audio_ctl *ctl;
5588 int i, j, printed = 0;
5591 flag = ~(SOUND_MASK_VOLUME | SOUND_MASK_PCM |
5592 SOUND_MASK_CD | SOUND_MASK_LINE | SOUND_MASK_RECLEV |
5593 SOUND_MASK_MIC | SOUND_MASK_SPEAKER | SOUND_MASK_IGAIN |
5594 SOUND_MASK_OGAIN | SOUND_MASK_IMIX | SOUND_MASK_MONITOR);
5597 for (j = 0; j < SOUND_MIXER_NRDEVICES; j++) {
5598 if ((flag & (1 << j)) == 0)
5602 while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) {
5603 if (ctl->enable == 0 ||
5604 ctl->widget->enable == 0)
5606 if (!((pdevinfo->playas >= 0 &&
5607 ctl->widget->bindas == pdevinfo->playas) ||
5608 (pdevinfo->recas >= 0 &&
5609 ctl->widget->bindas == pdevinfo->recas) ||
5610 (ctl->widget->bindas == -2 && pdevinfo->index == 0)))
5612 if ((ctl->ossmask & (1 << j)) == 0)
5616 if (banner != NULL) {
5617 device_printf(pdevinfo->dev, "%s", banner);
5619 device_printf(pdevinfo->dev, "Unknown Ctl");
5621 kprintf(" (OSS: %s)",
5622 hdaa_audio_ctl_ossmixer_mask2allname(1 << j,
5624 if (pdevinfo->ossmask & (1 << j)) {
5625 kprintf(": %+d/%+ddB\n",
5626 pdevinfo->minamp[j] / 4,
5627 pdevinfo->maxamp[j] / 4);
5632 device_printf(pdevinfo->dev, " +- ctl %2d (nid %3d %s", i,
5634 (ctl->ndir == HDAA_CTL_IN)?"in ":"out");
5635 if (ctl->ndir == HDAA_CTL_IN && ctl->ndir == ctl->dir)
5636 kprintf(" %2d): ", ctl->index);
5639 if (ctl->step > 0) {
5640 kprintf("%+d/%+ddB (%d steps)%s\n",
5644 ctl->mute?" + mute":"");
5646 kprintf("%s\n", ctl->mute?"mute":"");
5650 device_printf(pdevinfo->dev, "\n");
5654 hdaa_dump_audio_formats(device_t dev, uint32_t fcap, uint32_t pcmcap)
5660 device_printf(dev, " Stream cap: 0x%08x", cap);
5661 if (HDA_PARAM_SUPP_STREAM_FORMATS_AC3(cap))
5663 if (HDA_PARAM_SUPP_STREAM_FORMATS_FLOAT32(cap))
5664 kprintf(" FLOAT32");
5665 if (HDA_PARAM_SUPP_STREAM_FORMATS_PCM(cap))
5671 device_printf(dev, " PCM cap: 0x%08x", cap);
5672 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8BIT(cap))
5674 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16BIT(cap))
5676 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(cap))
5678 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(cap))
5680 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(cap))
5683 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8KHZ(cap))
5685 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_11KHZ(cap))
5687 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16KHZ(cap))
5689 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_22KHZ(cap))
5691 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32KHZ(cap))
5693 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_44KHZ(cap))
5696 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_88KHZ(cap))
5698 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_96KHZ(cap))
5700 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_176KHZ(cap))
5702 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_192KHZ(cap))
5709 hdaa_dump_pin(struct hdaa_widget *w)
5713 pincap = w->wclass.pin.cap;
5715 device_printf(w->devinfo->dev, " Pin cap: 0x%08x", pincap);
5716 if (HDA_PARAM_PIN_CAP_IMP_SENSE_CAP(pincap))
5718 if (HDA_PARAM_PIN_CAP_TRIGGER_REQD(pincap))
5720 if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(pincap))
5722 if (HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap))
5724 if (HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap))
5726 if (HDA_PARAM_PIN_CAP_INPUT_CAP(pincap))
5728 if (HDA_PARAM_PIN_CAP_BALANCED_IO_PINS(pincap))
5730 if (HDA_PARAM_PIN_CAP_HDMI(pincap))
5732 if (HDA_PARAM_PIN_CAP_VREF_CTRL(pincap)) {
5734 if (HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap))
5736 if (HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap))
5738 if (HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap))
5740 if (HDA_PARAM_PIN_CAP_VREF_CTRL_GROUND(pincap))
5742 if (HDA_PARAM_PIN_CAP_VREF_CTRL_HIZ(pincap))
5746 if (HDA_PARAM_PIN_CAP_EAPD_CAP(pincap))
5748 if (HDA_PARAM_PIN_CAP_DP(pincap))
5750 if (HDA_PARAM_PIN_CAP_HBR(pincap))
5753 device_printf(w->devinfo->dev, " Pin config: 0x%08x\n",
5754 w->wclass.pin.config);
5755 device_printf(w->devinfo->dev, " Pin control: 0x%08x", w->wclass.pin.ctrl);
5756 if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE)
5758 if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE)
5760 if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE)
5762 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) {
5763 if ((w->wclass.pin.ctrl &
5764 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK) == 0x03)
5766 else if ((w->wclass.pin.ctrl &
5767 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK) != 0)
5770 if ((w->wclass.pin.ctrl &
5771 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK) != 0)
5778 hdaa_dump_pin_config(struct hdaa_widget *w, uint32_t conf)
5781 device_printf(w->devinfo->dev, "%2d %08x %-2d %-2d "
5782 "%-13s %-5s %-7s %-10s %-7s %d%s\n",
5784 HDA_CONFIG_DEFAULTCONF_ASSOCIATION(conf),
5785 HDA_CONFIG_DEFAULTCONF_SEQUENCE(conf),
5786 HDA_DEVS[HDA_CONFIG_DEFAULTCONF_DEVICE(conf)],
5787 HDA_CONNS[HDA_CONFIG_DEFAULTCONF_CONNECTIVITY(conf)],
5788 HDA_CONNECTORS[HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE(conf)],
5789 HDA_LOCS[HDA_CONFIG_DEFAULTCONF_LOCATION(conf)],
5790 HDA_COLORS[HDA_CONFIG_DEFAULTCONF_COLOR(conf)],
5791 HDA_CONFIG_DEFAULTCONF_MISC(conf),
5792 (w->enable == 0)?" DISA":"");
5796 hdaa_dump_pin_configs(struct hdaa_devinfo *devinfo)
5798 struct hdaa_widget *w;
5801 device_printf(devinfo->dev, "nid 0x as seq "
5802 "device conn jack loc color misc\n");
5803 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5804 w = hdaa_widget_get(devinfo, i);
5807 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
5809 hdaa_dump_pin_config(w, w->wclass.pin.config);
5814 hdaa_dump_amp(device_t dev, uint32_t cap, const char *banner)
5816 int offset, size, step;
5818 offset = HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(cap);
5819 size = HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(cap);
5820 step = HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(cap);
5821 device_printf(dev, " %s amp: 0x%08x "
5822 "mute=%d step=%d size=%d offset=%d (%+d/%+ddB)\n",
5824 HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(cap),
5826 ((0 - offset) * (size + 1)) / 4,
5827 ((step - offset) * (size + 1)) / 4);
5831 hdaa_dump_nodes(struct hdaa_devinfo *devinfo)
5833 struct hdaa_widget *w, *cw;
5837 device_printf(devinfo->dev, "\n");
5838 device_printf(devinfo->dev, "Default parameters:\n");
5839 hdaa_dump_audio_formats(devinfo->dev,
5840 devinfo->supp_stream_formats,
5841 devinfo->supp_pcm_size_rate);
5842 hdaa_dump_amp(devinfo->dev, devinfo->inamp_cap, " Input");
5843 hdaa_dump_amp(devinfo->dev, devinfo->outamp_cap, "Output");
5844 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5845 w = hdaa_widget_get(devinfo, i);
5847 device_printf(devinfo->dev, "Ghost widget nid=%d\n", i);
5850 device_printf(devinfo->dev, "\n");
5851 device_printf(devinfo->dev, " nid: %d%s\n", w->nid,
5852 (w->enable == 0) ? " [DISABLED]" : "");
5853 device_printf(devinfo->dev, " Name: %s\n", w->name);
5854 device_printf(devinfo->dev, " Widget cap: 0x%08x",
5855 w->param.widget_cap);
5856 if (w->param.widget_cap & 0x0ee1) {
5857 if (HDA_PARAM_AUDIO_WIDGET_CAP_LR_SWAP(w->param.widget_cap))
5859 if (HDA_PARAM_AUDIO_WIDGET_CAP_POWER_CTRL(w->param.widget_cap))
5861 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap))
5862 kprintf(" DIGITAL");
5863 if (HDA_PARAM_AUDIO_WIDGET_CAP_UNSOL_CAP(w->param.widget_cap))
5865 if (HDA_PARAM_AUDIO_WIDGET_CAP_PROC_WIDGET(w->param.widget_cap))
5867 if (HDA_PARAM_AUDIO_WIDGET_CAP_STRIPE(w->param.widget_cap))
5868 kprintf(" STRIPE(x%d)",
5869 1 << (fls(w->wclass.conv.stripecap) - 1));
5870 j = HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap);
5874 kprintf(" %dCH", j + 1);
5877 if (w->bindas != -1) {
5878 device_printf(devinfo->dev, " Association: %d (0x%04x)\n",
5879 w->bindas, w->bindseqmask);
5881 if (w->ossmask != 0 || w->ossdev >= 0) {
5882 device_printf(devinfo->dev, " OSS: %s",
5883 hdaa_audio_ctl_ossmixer_mask2allname(w->ossmask, buf, sizeof(buf)));
5885 kprintf(" (%s)", ossnames[w->ossdev]);
5888 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT ||
5889 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
5890 hdaa_dump_audio_formats(devinfo->dev,
5891 w->param.supp_stream_formats,
5892 w->param.supp_pcm_size_rate);
5893 } else if (w->type ==
5894 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX || w->waspin)
5896 if (w->param.eapdbtl != HDA_INVALID)
5897 device_printf(devinfo->dev, " EAPD: 0x%08x\n",
5899 if (HDA_PARAM_AUDIO_WIDGET_CAP_OUT_AMP(w->param.widget_cap) &&
5900 w->param.outamp_cap != 0)
5901 hdaa_dump_amp(devinfo->dev, w->param.outamp_cap, "Output");
5902 if (HDA_PARAM_AUDIO_WIDGET_CAP_IN_AMP(w->param.widget_cap) &&
5903 w->param.inamp_cap != 0)
5904 hdaa_dump_amp(devinfo->dev, w->param.inamp_cap, " Input");
5906 device_printf(devinfo->dev, " Connections: %d\n", w->nconns);
5907 for (j = 0; j < w->nconns; j++) {
5908 cw = hdaa_widget_get(devinfo, w->conns[j]);
5909 device_printf(devinfo->dev, " + %s<- nid=%d [%s]",
5910 (w->connsenable[j] == 0)?"[DISABLED] ":"",
5911 w->conns[j], (cw == NULL) ? "GHOST!" : cw->name);
5913 kprintf(" [UNKNOWN]");
5914 else if (cw->enable == 0)
5915 kprintf(" [DISABLED]");
5916 if (w->nconns > 1 && w->selconn == j && w->type !=
5917 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
5918 kprintf(" (selected)");
5926 hdaa_dump_dst_nid(struct hdaa_pcm_devinfo *pdevinfo, nid_t nid, int depth)
5928 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
5929 struct hdaa_widget *w, *cw;
5933 if (depth > HDA_PARSE_MAXDEPTH)
5936 w = hdaa_widget_get(devinfo, nid);
5937 if (w == NULL || w->enable == 0)
5941 device_printf(pdevinfo->dev, "%*s", 4, "");
5943 device_printf(pdevinfo->dev, "%*s + <- ", 4 + (depth - 1) * 7, "");
5944 kprintf("nid=%d [%s]", w->nid, w->name);
5947 if (w->ossmask == 0) {
5951 kprintf(" [src: %s]",
5952 hdaa_audio_ctl_ossmixer_mask2allname(
5953 w->ossmask, buf, sizeof(buf)));
5954 if (w->ossdev >= 0) {
5961 for (i = 0; i < w->nconns; i++) {
5962 if (w->connsenable[i] == 0)
5964 cw = hdaa_widget_get(devinfo, w->conns[i]);
5965 if (cw == NULL || cw->enable == 0 || cw->bindas == -1)
5967 hdaa_dump_dst_nid(pdevinfo, w->conns[i], depth + 1);
5973 hdaa_dump_dac(struct hdaa_pcm_devinfo *pdevinfo)
5975 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
5976 struct hdaa_audio_as *as;
5977 struct hdaa_widget *w;
5981 if (pdevinfo->playas < 0)
5984 device_printf(pdevinfo->dev, "Playback:\n");
5986 chid = devinfo->as[pdevinfo->playas].chans[0];
5987 hdaa_dump_audio_formats(pdevinfo->dev,
5988 devinfo->chans[chid].supp_stream_formats,
5989 devinfo->chans[chid].supp_pcm_size_rate);
5990 for (i = 0; i < devinfo->as[pdevinfo->playas].num_chans; i++) {
5991 chid = devinfo->as[pdevinfo->playas].chans[i];
5992 device_printf(pdevinfo->dev, " DAC:");
5993 for (nids = devinfo->chans[chid].io; *nids != -1; nids++)
5994 kprintf(" %d", *nids);
5998 as = &devinfo->as[pdevinfo->playas];
5999 for (i = 0; i < 16; i++) {
6000 if (as->pins[i] <= 0)
6002 w = hdaa_widget_get(devinfo, as->pins[i]);
6003 if (w == NULL || w->enable == 0)
6005 device_printf(pdevinfo->dev, "\n");
6006 hdaa_dump_dst_nid(pdevinfo, as->pins[i], 0);
6008 device_printf(pdevinfo->dev, "\n");
6012 hdaa_dump_adc(struct hdaa_pcm_devinfo *pdevinfo)
6014 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
6015 struct hdaa_widget *w;
6019 if (pdevinfo->recas < 0)
6022 device_printf(pdevinfo->dev, "Record:\n");
6024 chid = devinfo->as[pdevinfo->recas].chans[0];
6025 hdaa_dump_audio_formats(pdevinfo->dev,
6026 devinfo->chans[chid].supp_stream_formats,
6027 devinfo->chans[chid].supp_pcm_size_rate);
6028 for (i = 0; i < devinfo->as[pdevinfo->recas].num_chans; i++) {
6029 chid = devinfo->as[pdevinfo->recas].chans[i];
6030 device_printf(pdevinfo->dev, " ADC:");
6031 for (nids = devinfo->chans[chid].io; *nids != -1; nids++)
6032 kprintf(" %d", *nids);
6036 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
6037 w = hdaa_widget_get(devinfo, i);
6038 if (w == NULL || w->enable == 0)
6040 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT)
6042 if (w->bindas != pdevinfo->recas)
6044 device_printf(pdevinfo->dev, "\n");
6045 hdaa_dump_dst_nid(pdevinfo, i, 0);
6047 device_printf(pdevinfo->dev, "\n");
6051 hdaa_dump_mix(struct hdaa_pcm_devinfo *pdevinfo)
6053 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
6054 struct hdaa_widget *w;
6058 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
6059 w = hdaa_widget_get(devinfo, i);
6060 if (w == NULL || w->enable == 0)
6062 if (w->ossdev != SOUND_MIXER_IMIX)
6064 if (w->bindas != pdevinfo->recas)
6068 device_printf(pdevinfo->dev, "Input Mix:\n");
6070 device_printf(pdevinfo->dev, "\n");
6071 hdaa_dump_dst_nid(pdevinfo, i, 0);
6074 device_printf(pdevinfo->dev, "\n");
6078 hdaa_pindump(device_t dev)
6080 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6081 struct hdaa_widget *w;
6082 uint32_t res, pincap, delay;
6085 device_printf(dev, "Dumping AFG pins:\n");
6086 device_printf(dev, "nid 0x as seq "
6087 "device conn jack loc color misc\n");
6088 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
6089 w = hdaa_widget_get(devinfo, i);
6090 if (w == NULL || w->type !=
6091 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
6093 hdaa_dump_pin_config(w, w->wclass.pin.config);
6094 pincap = w->wclass.pin.cap;
6095 device_printf(dev, " Caps: %2s %3s %2s %4s %4s",
6096 HDA_PARAM_PIN_CAP_INPUT_CAP(pincap)?"IN":"",
6097 HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap)?"OUT":"",
6098 HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap)?"HP":"",
6099 HDA_PARAM_PIN_CAP_EAPD_CAP(pincap)?"EAPD":"",
6100 HDA_PARAM_PIN_CAP_VREF_CTRL(pincap)?"VREF":"");
6101 if (HDA_PARAM_PIN_CAP_IMP_SENSE_CAP(pincap) ||
6102 HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(pincap)) {
6103 if (HDA_PARAM_PIN_CAP_TRIGGER_REQD(pincap)) {
6106 HDA_CMD_SET_PIN_SENSE(0, w->nid, 0));
6108 res = hda_command(dev,
6109 HDA_CMD_GET_PIN_SENSE(0, w->nid));
6110 if (res != 0x7fffffff && res != 0xffffffff)
6113 } while (++delay < 10000);
6116 res = hda_command(dev, HDA_CMD_GET_PIN_SENSE(0,
6119 kprintf(" Sense: 0x%08x (%sconnected%s)", res,
6120 (res & HDA_CMD_GET_PIN_SENSE_PRESENCE_DETECT) ?
6122 (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap) &&
6123 (res & HDA_CMD_GET_PIN_SENSE_ELD_VALID)) ?
6124 ", ELD valid" : "");
6126 kprintf(" delay %dus", delay * 10);
6131 "NumGPIO=%d NumGPO=%d NumGPI=%d GPIWake=%d GPIUnsol=%d\n",
6132 HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap),
6133 HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap),
6134 HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap),
6135 HDA_PARAM_GPIO_COUNT_GPI_WAKE(devinfo->gpio_cap),
6136 HDA_PARAM_GPIO_COUNT_GPI_UNSOL(devinfo->gpio_cap));
6137 hdaa_dump_gpi(devinfo);
6138 hdaa_dump_gpio(devinfo);
6139 hdaa_dump_gpo(devinfo);
6143 hdaa_configure(device_t dev)
6145 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6146 struct hdaa_audio_ctl *ctl;
6150 device_printf(dev, "Applying built-in patches...\n");
6152 hdaa_patch(devinfo);
6154 device_printf(dev, "Applying local patches...\n");
6156 hdaa_local_patch(devinfo);
6157 hdaa_audio_postprocess(devinfo);
6159 device_printf(dev, "Parsing Ctls...\n");
6161 hdaa_audio_ctl_parse(devinfo);
6163 device_printf(dev, "Disabling nonaudio...\n");
6165 hdaa_audio_disable_nonaudio(devinfo);
6167 device_printf(dev, "Disabling useless...\n");
6169 hdaa_audio_disable_useless(devinfo);
6171 device_printf(dev, "Patched pins configuration:\n");
6172 hdaa_dump_pin_configs(devinfo);
6175 device_printf(dev, "Parsing pin associations...\n");
6177 hdaa_audio_as_parse(devinfo);
6179 device_printf(dev, "Building AFG tree...\n");
6181 hdaa_audio_build_tree(devinfo);
6183 device_printf(dev, "Disabling unassociated "
6186 hdaa_audio_disable_unas(devinfo);
6188 device_printf(dev, "Disabling nonselected "
6191 hdaa_audio_disable_notselected(devinfo);
6193 device_printf(dev, "Disabling useless...\n");
6195 hdaa_audio_disable_useless(devinfo);
6197 device_printf(dev, "Disabling "
6198 "crossassociatement connections...\n");
6200 hdaa_audio_disable_crossas(devinfo);
6202 device_printf(dev, "Disabling useless...\n");
6204 hdaa_audio_disable_useless(devinfo);
6206 device_printf(dev, "Binding associations to channels...\n");
6208 hdaa_audio_bind_as(devinfo);
6210 device_printf(dev, "Assigning names to signal sources...\n");
6212 hdaa_audio_assign_names(devinfo);
6214 device_printf(dev, "Preparing PCM devices...\n");
6216 hdaa_prepare_pcms(devinfo);
6218 device_printf(dev, "Assigning mixers to the tree...\n");
6220 hdaa_audio_assign_mixers(devinfo);
6222 device_printf(dev, "Preparing pin controls...\n");
6224 hdaa_audio_prepare_pin_ctrl(devinfo);
6226 device_printf(dev, "AFG commit...\n");
6228 hdaa_audio_commit(devinfo);
6230 device_printf(dev, "Applying direct built-in patches...\n");
6232 hdaa_patch_direct(devinfo);
6234 device_printf(dev, "Pin sense init...\n");
6236 hdaa_sense_init(devinfo);
6238 device_printf(dev, "Creating PCM devices...\n");
6240 hdaa_create_pcms(devinfo);
6243 if (devinfo->quirks != 0) {
6244 device_printf(dev, "FG config/quirks:");
6245 for (i = 0; i < nitems(hdaa_quirks_tab); i++) {
6246 if ((devinfo->quirks &
6247 hdaa_quirks_tab[i].value) ==
6248 hdaa_quirks_tab[i].value)
6249 kprintf(" %s", hdaa_quirks_tab[i].key);
6256 device_printf(dev, "\n");
6257 device_printf(dev, "+-----------+\n");
6258 device_printf(dev, "| HDA NODES |\n");
6259 device_printf(dev, "+-----------+\n");
6260 hdaa_dump_nodes(devinfo);
6262 device_printf(dev, "\n");
6263 device_printf(dev, "+----------------+\n");
6264 device_printf(dev, "| HDA AMPLIFIERS |\n");
6265 device_printf(dev, "+----------------+\n");
6266 device_printf(dev, "\n");
6268 while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) {
6269 device_printf(dev, "%3d: nid %3d %s (%s) index %d", i,
6270 (ctl->widget != NULL) ? ctl->widget->nid : -1,
6271 (ctl->ndir == HDAA_CTL_IN)?"in ":"out",
6272 (ctl->dir == HDAA_CTL_IN)?"in ":"out",
6274 if (ctl->childwidget != NULL)
6275 kprintf(" cnid %3d", ctl->childwidget->nid);
6278 kprintf(" ossmask=0x%08x\n",
6281 " mute: %d step: %3d size: %3d off: %3d%s\n",
6282 ctl->mute, ctl->step, ctl->size, ctl->offset,
6283 (ctl->enable == 0) ? " [DISABLED]" :
6284 ((ctl->ossmask == 0) ? " [UNUSED]" : ""));
6286 device_printf(dev, "\n");
6291 hdaa_unconfigure(device_t dev)
6293 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6294 struct hdaa_widget *w;
6298 device_printf(dev, "Pin sense deinit...\n");
6300 hdaa_sense_deinit(devinfo);
6301 kfree(devinfo->ctl, M_HDAA);
6302 devinfo->ctl = NULL;
6303 devinfo->ctlcnt = 0;
6304 kfree(devinfo->as, M_HDAA);
6307 kfree(devinfo->devs, M_HDAA);
6308 devinfo->devs = NULL;
6309 devinfo->num_devs = 0;
6310 kfree(devinfo->chans, M_HDAA);
6311 devinfo->chans = NULL;
6312 devinfo->num_chans = 0;
6313 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
6314 w = hdaa_widget_get(devinfo, i);
6324 for (j = 0; j < w->nconns; j++)
6325 w->connsenable[j] = 1;
6326 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
6327 w->wclass.pin.config = w->wclass.pin.newconf;
6328 if (w->eld != NULL) {
6330 kfree(w->eld, M_HDAA);
6337 hdaa_sysctl_gpi_state(SYSCTL_HANDLER_ARGS)
6339 struct hdaa_devinfo *devinfo = oidp->oid_arg1;
6340 device_t dev = devinfo->dev;
6342 int n = 0, i, numgpi;
6347 numgpi = HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap);
6349 data = hda_command(dev,
6350 HDA_CMD_GET_GPI_DATA(0, devinfo->nid));
6352 hdaa_unlock(devinfo);
6353 for (i = 0; i < numgpi; i++) {
6354 n += ksnprintf(buf + n, sizeof(buf) - n, "%s%d=%d",
6355 n != 0 ? " " : "", i, ((data >> i) & 1));
6357 return (sysctl_handle_string(oidp, buf, sizeof(buf), req));
6361 hdaa_sysctl_gpio_state(SYSCTL_HANDLER_ARGS)
6363 struct hdaa_devinfo *devinfo = oidp->oid_arg1;
6364 device_t dev = devinfo->dev;
6366 int n = 0, i, numgpio;
6367 uint32_t data = 0, enable = 0, dir = 0;
6371 numgpio = HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap);
6373 data = hda_command(dev,
6374 HDA_CMD_GET_GPIO_DATA(0, devinfo->nid));
6375 enable = hda_command(dev,
6376 HDA_CMD_GET_GPIO_ENABLE_MASK(0, devinfo->nid));
6377 dir = hda_command(dev,
6378 HDA_CMD_GET_GPIO_DIRECTION(0, devinfo->nid));
6380 hdaa_unlock(devinfo);
6381 for (i = 0; i < numgpio; i++) {
6382 n += ksnprintf(buf + n, sizeof(buf) - n, "%s%d=",
6383 n != 0 ? " " : "", i);
6384 if ((enable & (1 << i)) == 0) {
6385 n += ksnprintf(buf + n, sizeof(buf) - n, "disabled");
6388 n += ksnprintf(buf + n, sizeof(buf) - n, "%sput(%d)",
6389 ((dir >> i) & 1) ? "out" : "in", ((data >> i) & 1));
6391 return (sysctl_handle_string(oidp, buf, sizeof(buf), req));
6395 hdaa_sysctl_gpio_config(SYSCTL_HANDLER_ARGS)
6397 struct hdaa_devinfo *devinfo = oidp->oid_arg1;
6399 int error, n = 0, i, numgpio;
6402 gpio = devinfo->newgpio;
6403 numgpio = HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap);
6405 for (i = 0; i < numgpio; i++) {
6406 x = (gpio & HDAA_GPIO_MASK(i)) >> HDAA_GPIO_SHIFT(i);
6407 n += ksnprintf(buf + n, sizeof(buf) - n, "%s%d=%s",
6408 n != 0 ? " " : "", i, HDA_GPIO_ACTIONS[x]);
6410 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
6411 if (error != 0 || req->newptr == NULL)
6413 if (strncmp(buf, "0x", 2) == 0)
6414 gpio = strtol(buf + 2, NULL, 16);
6416 gpio = hdaa_gpio_patch(gpio, buf);
6418 devinfo->newgpio = devinfo->gpio = gpio;
6419 hdaa_gpio_commit(devinfo);
6420 hdaa_unlock(devinfo);
6425 hdaa_sysctl_gpo_state(SYSCTL_HANDLER_ARGS)
6427 struct hdaa_devinfo *devinfo = oidp->oid_arg1;
6428 device_t dev = devinfo->dev;
6430 int n = 0, i, numgpo;
6435 numgpo = HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap);
6437 data = hda_command(dev,
6438 HDA_CMD_GET_GPO_DATA(0, devinfo->nid));
6440 hdaa_unlock(devinfo);
6441 for (i = 0; i < numgpo; i++) {
6442 n += ksnprintf(buf + n, sizeof(buf) - n, "%s%d=%d",
6443 n != 0 ? " " : "", i, ((data >> i) & 1));
6445 return (sysctl_handle_string(oidp, buf, sizeof(buf), req));
6449 hdaa_sysctl_gpo_config(SYSCTL_HANDLER_ARGS)
6451 struct hdaa_devinfo *devinfo = oidp->oid_arg1;
6453 int error, n = 0, i, numgpo;
6456 gpo = devinfo->newgpo;
6457 numgpo = HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap);
6459 for (i = 0; i < numgpo; i++) {
6460 x = (gpo & HDAA_GPIO_MASK(i)) >> HDAA_GPIO_SHIFT(i);
6461 n += ksnprintf(buf + n, sizeof(buf) - n, "%s%d=%s",
6462 n != 0 ? " " : "", i, HDA_GPIO_ACTIONS[x]);
6464 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
6465 if (error != 0 || req->newptr == NULL)
6467 if (strncmp(buf, "0x", 2) == 0)
6468 gpo = strtol(buf + 2, NULL, 16);
6470 gpo = hdaa_gpio_patch(gpo, buf);
6472 devinfo->newgpo = devinfo->gpo = gpo;
6473 hdaa_gpo_commit(devinfo);
6474 hdaa_unlock(devinfo);
6479 hdaa_sysctl_reconfig(SYSCTL_HANDLER_ARGS)
6482 struct hdaa_devinfo *devinfo;
6485 dev = oidp->oid_arg1;
6486 devinfo = device_get_softc(dev);
6487 if (devinfo == NULL)
6490 error = sysctl_handle_int(oidp, &val, 0, req);
6491 if (error != 0 || req->newptr == NULL || val == 0)
6495 device_printf(dev, "Reconfiguration...\n");
6497 if ((error = device_delete_children(dev)) != 0)
6500 hdaa_unconfigure(dev);
6501 hdaa_configure(dev);
6502 hdaa_unlock(devinfo);
6503 bus_generic_attach(dev);
6505 device_printf(dev, "Reconfiguration done\n");
6511 hdaa_suspend(device_t dev)
6513 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6517 device_printf(dev, "Suspend...\n");
6521 device_printf(dev, "Stop streams...\n");
6523 for (i = 0; i < devinfo->num_chans; i++) {
6524 if (devinfo->chans[i].flags & HDAA_CHN_RUNNING) {
6525 devinfo->chans[i].flags |= HDAA_CHN_SUSPEND;
6526 hdaa_channel_stop(&devinfo->chans[i]);
6530 device_printf(dev, "Power down FG"
6531 " nid=%d to the D3 state...\n",
6534 hda_command(devinfo->dev,
6535 HDA_CMD_SET_POWER_STATE(0,
6536 devinfo->nid, HDA_CMD_POWER_STATE_D3));
6537 callout_stop(&devinfo->poll_jack);
6538 hdaa_unlock(devinfo);
6539 callout_drain(&devinfo->poll_jack);
6541 device_printf(dev, "Suspend done\n");
6547 hdaa_resume(device_t dev)
6549 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6553 device_printf(dev, "Resume...\n");
6557 device_printf(dev, "Power up audio FG nid=%d...\n",
6560 hdaa_powerup(devinfo);
6562 device_printf(dev, "AFG commit...\n");
6564 hdaa_audio_commit(devinfo);
6566 device_printf(dev, "Applying direct built-in patches...\n");
6568 hdaa_patch_direct(devinfo);
6570 device_printf(dev, "Pin sense init...\n");
6572 hdaa_sense_init(devinfo);
6574 hdaa_unlock(devinfo);
6575 for (i = 0; i < devinfo->num_devs; i++) {
6576 struct hdaa_pcm_devinfo *pdevinfo = &devinfo->devs[i];
6578 device_printf(pdevinfo->dev,
6579 "OSS mixer reinitialization...\n");
6581 if (mixer_reinit(pdevinfo->dev) == -1)
6582 device_printf(pdevinfo->dev,
6583 "unable to reinitialize the mixer\n");
6587 device_printf(dev, "Start streams...\n");
6589 for (i = 0; i < devinfo->num_chans; i++) {
6590 if (devinfo->chans[i].flags & HDAA_CHN_SUSPEND) {
6591 devinfo->chans[i].flags &= ~HDAA_CHN_SUSPEND;
6592 hdaa_channel_start(&devinfo->chans[i]);
6595 hdaa_unlock(devinfo);
6597 device_printf(dev, "Resume done\n");
6603 hdaa_probe(device_t dev)
6608 if (hda_get_node_type(dev) != HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO)
6610 pdesc = device_get_desc(device_get_parent(dev));
6611 ksnprintf(buf, sizeof(buf), "%.*s Audio Function Group",
6612 (int)(strlen(pdesc) - 10), pdesc);
6613 device_set_desc_copy(dev, buf);
6614 return (BUS_PROBE_DEFAULT);
6618 hdaa_attach(device_t dev)
6620 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6622 nid_t nid = hda_get_node_id(dev);
6625 devinfo->lock = HDAC_GET_MTX(device_get_parent(dev), dev);
6627 devinfo->newquirks = -1;
6628 devinfo->newgpio = -1;
6629 devinfo->newgpo = -1;
6630 callout_init_mp(&devinfo->poll_jack);
6631 devinfo->poll_ival = hz;
6634 res = hda_command(dev,
6635 HDA_CMD_GET_PARAMETER(0 , nid, HDA_PARAM_SUB_NODE_COUNT));
6636 hdaa_unlock(devinfo);
6638 devinfo->nodecnt = HDA_PARAM_SUB_NODE_COUNT_TOTAL(res);
6639 devinfo->startnode = HDA_PARAM_SUB_NODE_COUNT_START(res);
6640 devinfo->endnode = devinfo->startnode + devinfo->nodecnt;
6643 device_printf(dev, "Subsystem ID: 0x%08x\n",
6644 hda_get_subsystem_id(dev));
6648 "Audio Function Group at nid=%d: %d subnodes %d-%d\n",
6649 nid, devinfo->nodecnt,
6650 devinfo->startnode, devinfo->endnode - 1);
6653 if (devinfo->nodecnt > 0)
6654 devinfo->widget = (struct hdaa_widget *)kmalloc(
6655 sizeof(*(devinfo->widget)) * devinfo->nodecnt, M_HDAA,
6658 devinfo->widget = NULL;
6662 device_printf(dev, "Powering up...\n");
6664 hdaa_powerup(devinfo);
6666 device_printf(dev, "Parsing audio FG...\n");
6668 hdaa_audio_parse(devinfo);
6670 device_printf(dev, "Original pins configuration:\n");
6671 hdaa_dump_pin_configs(devinfo);
6673 hdaa_configure(dev);
6674 hdaa_unlock(devinfo);
6676 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6677 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6678 "config", CTLTYPE_STRING | CTLFLAG_RW,
6679 &devinfo->newquirks, sizeof(&devinfo->newquirks),
6680 hdaa_sysctl_quirks, "A", "Configuration options");
6681 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6682 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6683 "gpi_state", CTLTYPE_STRING | CTLFLAG_RD,
6684 devinfo, sizeof(devinfo),
6685 hdaa_sysctl_gpi_state, "A", "GPI state");
6686 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6687 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6688 "gpio_state", CTLTYPE_STRING | CTLFLAG_RD,
6689 devinfo, sizeof(devinfo),
6690 hdaa_sysctl_gpio_state, "A", "GPIO state");
6691 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6692 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6693 "gpio_config", CTLTYPE_STRING | CTLFLAG_RW,
6694 devinfo, sizeof(devinfo),
6695 hdaa_sysctl_gpio_config, "A", "GPIO configuration");
6696 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6697 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6698 "gpo_state", CTLTYPE_STRING | CTLFLAG_RD,
6699 devinfo, sizeof(devinfo),
6700 hdaa_sysctl_gpo_state, "A", "GPO state");
6701 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6702 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6703 "gpo_config", CTLTYPE_STRING | CTLFLAG_RW,
6704 devinfo, sizeof(devinfo),
6705 hdaa_sysctl_gpo_config, "A", "GPO configuration");
6706 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6707 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6708 "reconfig", CTLTYPE_INT | CTLFLAG_RW,
6710 hdaa_sysctl_reconfig, "I", "Reprocess configuration");
6711 bus_generic_attach(dev);
6716 hdaa_detach(device_t dev)
6718 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6721 if ((error = device_delete_children(dev)) != 0)
6725 hdaa_unconfigure(dev);
6726 devinfo->poll_ival = 0;
6727 callout_stop(&devinfo->poll_jack);
6728 hdaa_unlock(devinfo);
6729 callout_drain(&devinfo->poll_jack);
6731 kfree(devinfo->widget, M_HDAA);
6736 hdaa_print_child(device_t dev, device_t child)
6738 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6739 struct hdaa_pcm_devinfo *pdevinfo =
6740 (struct hdaa_pcm_devinfo *)device_get_ivars(child);
6741 struct hdaa_audio_as *as;
6742 int retval, first = 1, i;
6744 retval = bus_print_child_header(dev, child);
6745 retval += kprintf(" at nid ");
6746 if (pdevinfo->playas >= 0) {
6747 as = &devinfo->as[pdevinfo->playas];
6748 for (i = 0; i < 16; i++) {
6749 if (as->pins[i] <= 0)
6751 retval += kprintf("%s%d", first ? "" : ",", as->pins[i]);
6755 if (pdevinfo->recas >= 0) {
6756 if (pdevinfo->playas >= 0) {
6757 retval += kprintf(" and ");
6760 as = &devinfo->as[pdevinfo->recas];
6761 for (i = 0; i < 16; i++) {
6762 if (as->pins[i] <= 0)
6764 retval += kprintf("%s%d", first ? "" : ",", as->pins[i]);
6768 retval += bus_print_child_footer(dev, child);
6774 hdaa_child_location_str(device_t dev, device_t child, char *buf,
6777 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6778 struct hdaa_pcm_devinfo *pdevinfo =
6779 (struct hdaa_pcm_devinfo *)device_get_ivars(child);
6780 struct hdaa_audio_as *as;
6781 int first = 1, i, len = 0;
6783 len += ksnprintf(buf + len, buflen - len, "nid=");
6784 if (pdevinfo->playas >= 0) {
6785 as = &devinfo->as[pdevinfo->playas];
6786 for (i = 0; i < 16; i++) {
6787 if (as->pins[i] <= 0)
6789 len += ksnprintf(buf + len, buflen - len,
6790 "%s%d", first ? "" : ",", as->pins[i]);
6794 if (pdevinfo->recas >= 0) {
6795 as = &devinfo->as[pdevinfo->recas];
6796 for (i = 0; i < 16; i++) {
6797 if (as->pins[i] <= 0)
6799 len += ksnprintf(buf + len, buflen - len,
6800 "%s%d", first ? "" : ",", as->pins[i]);
6808 hdaa_stream_intr(device_t dev, int dir, int stream)
6810 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6811 struct hdaa_chan *ch;
6814 for (i = 0; i < devinfo->num_chans; i++) {
6815 ch = &devinfo->chans[i];
6816 if (!(ch->flags & HDAA_CHN_RUNNING))
6818 if (ch->dir == ((dir == 1) ? PCMDIR_PLAY : PCMDIR_REC) &&
6819 ch->sid == stream) {
6820 hdaa_unlock(devinfo);
6828 hdaa_unsol_intr(device_t dev, uint32_t resp)
6830 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6831 struct hdaa_widget *w;
6835 device_printf(dev, "Unsolicited response %08x\n", resp);
6838 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
6839 w = hdaa_widget_get(devinfo, i);
6840 if (w == NULL || w->enable == 0 || w->type !=
6841 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
6843 if (w->unsol != tag)
6845 if (HDA_PARAM_PIN_CAP_DP(w->wclass.pin.cap) ||
6846 HDA_PARAM_PIN_CAP_HDMI(w->wclass.pin.cap))
6847 flags = resp & 0x03;
6851 hdaa_presence_handler(w);
6853 hdaa_eld_handler(w);
6857 static device_method_t hdaa_methods[] = {
6858 /* device interface */
6859 DEVMETHOD(device_probe, hdaa_probe),
6860 DEVMETHOD(device_attach, hdaa_attach),
6861 DEVMETHOD(device_detach, hdaa_detach),
6862 DEVMETHOD(device_suspend, hdaa_suspend),
6863 DEVMETHOD(device_resume, hdaa_resume),
6865 DEVMETHOD(bus_print_child, hdaa_print_child),
6866 DEVMETHOD(bus_child_location_str, hdaa_child_location_str),
6867 DEVMETHOD(hdac_stream_intr, hdaa_stream_intr),
6868 DEVMETHOD(hdac_unsol_intr, hdaa_unsol_intr),
6869 DEVMETHOD(hdac_pindump, hdaa_pindump),
6873 static driver_t hdaa_driver = {
6876 sizeof(struct hdaa_devinfo),
6879 static devclass_t hdaa_devclass;
6881 DRIVER_MODULE(snd_hda, hdacc, hdaa_driver, hdaa_devclass, NULL, NULL);
6884 hdaa_chan_formula(struct hdaa_devinfo *devinfo, int asid,
6885 char *buf, int buflen)
6887 struct hdaa_audio_as *as;
6890 as = &devinfo->as[asid];
6891 c = devinfo->chans[as->chans[0]].channels;
6893 ksnprintf(buf, buflen, "mono");
6895 if (as->hpredir < 0)
6898 ksnprintf(buf, buflen, "2.0");
6899 } else if (as->pinset == 0x0003)
6900 ksnprintf(buf, buflen, "3.1");
6901 else if (as->pinset == 0x0005 || as->pinset == 0x0011)
6902 ksnprintf(buf, buflen, "4.0");
6903 else if (as->pinset == 0x0007 || as->pinset == 0x0013)
6904 ksnprintf(buf, buflen, "5.1");
6905 else if (as->pinset == 0x0017)
6906 ksnprintf(buf, buflen, "7.1");
6908 ksnprintf(buf, buflen, "%dch", c);
6909 if (as->hpredir >= 0)
6910 strlcat(buf, "+HP", buflen);
6914 hdaa_chan_type(struct hdaa_devinfo *devinfo, int asid)
6916 struct hdaa_audio_as *as;
6917 struct hdaa_widget *w;
6920 as = &devinfo->as[asid];
6921 for (i = 0; i < 16; i++) {
6922 w = hdaa_widget_get(devinfo, as->pins[i]);
6923 if (w == NULL || w->enable == 0 || w->type !=
6924 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
6926 t1 = HDA_CONFIG_DEFAULTCONF_DEVICE(w->wclass.pin.config);
6938 hdaa_sysctl_32bit(SYSCTL_HANDLER_ARGS)
6940 struct hdaa_audio_as *as = (struct hdaa_audio_as *)oidp->oid_arg1;
6941 struct hdaa_pcm_devinfo *pdevinfo = as->pdevinfo;
6942 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
6943 struct hdaa_chan *ch;
6947 ch = &devinfo->chans[as->chans[0]];
6948 val = (ch->bit32 == 4) ? 32 : ((ch->bit32 == 3) ? 24 :
6949 ((ch->bit32 == 2) ? 20 : 0));
6950 error = sysctl_handle_int(oidp, &val, 0, req);
6951 if (error != 0 || req->newptr == NULL)
6953 pcmcap = ch->supp_pcm_size_rate;
6954 if (val == 32 && HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(pcmcap))
6956 else if (val == 24 && HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(pcmcap))
6958 else if (val == 20 && HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(pcmcap))
6962 for (i = 1; i < as->num_chans; i++)
6963 devinfo->chans[as->chans[i]].bit32 = ch->bit32;
6968 hdaa_pcm_probe(device_t dev)
6970 struct hdaa_pcm_devinfo *pdevinfo =
6971 (struct hdaa_pcm_devinfo *)device_get_ivars(dev);
6972 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
6974 char chans1[8], chans2[8];
6976 int loc1, loc2, t1, t2;
6978 if (pdevinfo->playas >= 0)
6979 loc1 = devinfo->as[pdevinfo->playas].location;
6981 loc1 = devinfo->as[pdevinfo->recas].location;
6982 if (pdevinfo->recas >= 0)
6983 loc2 = devinfo->as[pdevinfo->recas].location;
6988 if (loc1 >= 0 && HDA_LOCS[loc1][0] == '0')
6993 if (pdevinfo->playas >= 0) {
6994 hdaa_chan_formula(devinfo, pdevinfo->playas,
6995 chans1, sizeof(chans1));
6996 t1 = hdaa_chan_type(devinfo, pdevinfo->playas);
6998 if (pdevinfo->recas >= 0) {
6999 hdaa_chan_formula(devinfo, pdevinfo->recas,
7000 chans2, sizeof(chans2));
7001 t2 = hdaa_chan_type(devinfo, pdevinfo->recas);
7003 if (chans1[0] != 0 || chans2[0] != 0) {
7004 if (chans1[0] == 0 && pdevinfo->playas >= 0)
7005 ksnprintf(chans1, sizeof(chans1), "2.0");
7006 else if (chans2[0] == 0 && pdevinfo->recas >= 0)
7007 ksnprintf(chans2, sizeof(chans2), "2.0");
7008 if (strcmp(chans1, chans2) == 0)
7017 if (pdevinfo->digital)
7019 pdesc = device_get_desc(device_get_parent(dev));
7020 ksnprintf(buf, sizeof(buf), "%.*s (%s%s%s%s%s%s%s%s%s)",
7021 (int)(strlen(pdesc) - 21), pdesc,
7022 loc1 >= 0 ? HDA_LOCS[loc1] : "", loc1 >= 0 ? " " : "",
7023 (pdevinfo->digital == 0x7)?"HDMI/DP":
7024 ((pdevinfo->digital == 0x5)?"DisplayPort":
7025 ((pdevinfo->digital == 0x3)?"HDMI":
7026 ((pdevinfo->digital)?"Digital":"Analog"))),
7027 chans1[0] ? " " : "", chans1,
7028 chans2[0] ? "/" : "", chans2,
7029 t1 >= 0 ? " " : "", t1 >= 0 ? HDA_DEVS[t1] : "");
7030 device_set_desc_copy(dev, buf);
7031 return (BUS_PROBE_SPECIFIC);
7035 hdaa_pcm_attach(device_t dev)
7037 struct hdaa_pcm_devinfo *pdevinfo =
7038 (struct hdaa_pcm_devinfo *)device_get_ivars(dev);
7039 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
7040 struct hdaa_audio_as *as;
7041 struct snddev_info *d;
7042 char status[SND_STATUSLEN];
7045 pdevinfo->chan_size = pcm_getbuffersize(dev,
7046 HDA_BUFSZ_MIN, HDA_BUFSZ_DEFAULT, HDA_BUFSZ_MAX);
7049 hdaa_dump_dac(pdevinfo);
7050 hdaa_dump_adc(pdevinfo);
7051 hdaa_dump_mix(pdevinfo);
7052 hdaa_dump_ctls(pdevinfo, "Master Volume", SOUND_MASK_VOLUME);
7053 hdaa_dump_ctls(pdevinfo, "PCM Volume", SOUND_MASK_PCM);
7054 hdaa_dump_ctls(pdevinfo, "CD Volume", SOUND_MASK_CD);
7055 hdaa_dump_ctls(pdevinfo, "Microphone Volume", SOUND_MASK_MIC);
7056 hdaa_dump_ctls(pdevinfo, "Microphone2 Volume", SOUND_MASK_MONITOR);
7057 hdaa_dump_ctls(pdevinfo, "Line-in Volume", SOUND_MASK_LINE);
7058 hdaa_dump_ctls(pdevinfo, "Speaker/Beep Volume", SOUND_MASK_SPEAKER);
7059 hdaa_dump_ctls(pdevinfo, "Recording Level", SOUND_MASK_RECLEV);
7060 hdaa_dump_ctls(pdevinfo, "Input Mix Level", SOUND_MASK_IMIX);
7061 hdaa_dump_ctls(pdevinfo, "Input Monitoring Level", SOUND_MASK_IGAIN);
7062 hdaa_dump_ctls(pdevinfo, NULL, 0);
7065 if (resource_int_value(device_get_name(dev),
7066 device_get_unit(dev), "blocksize", &i) == 0 && i > 0) {
7068 if (i < HDA_BLK_MIN)
7070 pdevinfo->chan_blkcnt = pdevinfo->chan_size / i;
7072 while (pdevinfo->chan_blkcnt >> i)
7074 pdevinfo->chan_blkcnt = 1 << (i - 1);
7075 if (pdevinfo->chan_blkcnt < HDA_BDL_MIN)
7076 pdevinfo->chan_blkcnt = HDA_BDL_MIN;
7077 else if (pdevinfo->chan_blkcnt > HDA_BDL_MAX)
7078 pdevinfo->chan_blkcnt = HDA_BDL_MAX;
7080 pdevinfo->chan_blkcnt = HDA_BDL_DEFAULT;
7083 * We don't register interrupt handler with snd_setup_intr
7084 * in pcm device. Mark pcm device as MPSAFE manually.
7086 pcm_setflags(dev, pcm_getflags(dev) | SD_F_MPSAFE);
7089 device_printf(dev, "OSS mixer initialization...\n");
7091 if (mixer_init(dev, &hdaa_audio_ctl_ossmixer_class, pdevinfo) != 0)
7092 device_printf(dev, "Can't register mixer\n");
7095 device_printf(dev, "Registering PCM channels...\n");
7097 if (pcm_register(dev, pdevinfo, (pdevinfo->playas >= 0)?1:0,
7098 (pdevinfo->recas >= 0)?1:0) != 0)
7099 device_printf(dev, "Can't register PCM\n");
7101 pdevinfo->registered++;
7103 d = device_get_softc(dev);
7104 if (pdevinfo->playas >= 0) {
7105 as = &devinfo->as[pdevinfo->playas];
7106 for (i = 0; i < as->num_chans; i++)
7107 pcm_addchan(dev, PCMDIR_PLAY, &hdaa_channel_class,
7108 &devinfo->chans[as->chans[i]]);
7109 SYSCTL_ADD_PROC(&d->play_sysctl_ctx,
7110 SYSCTL_CHILDREN(d->play_sysctl_tree), OID_AUTO,
7111 "32bit", CTLTYPE_INT | CTLFLAG_RW,
7112 as, sizeof(as), hdaa_sysctl_32bit, "I",
7113 "Resolution of 32bit samples (20/24/32bit)");
7115 if (pdevinfo->recas >= 0) {
7116 as = &devinfo->as[pdevinfo->recas];
7117 for (i = 0; i < as->num_chans; i++)
7118 pcm_addchan(dev, PCMDIR_REC, &hdaa_channel_class,
7119 &devinfo->chans[as->chans[i]]);
7120 SYSCTL_ADD_PROC(&d->rec_sysctl_ctx,
7121 SYSCTL_CHILDREN(d->rec_sysctl_tree), OID_AUTO,
7122 "32bit", CTLTYPE_INT | CTLFLAG_RW,
7123 as, sizeof(as), hdaa_sysctl_32bit, "I",
7124 "Resolution of 32bit samples (20/24/32bit)");
7125 pdevinfo->autorecsrc = 2;
7126 resource_int_value(device_get_name(dev), device_get_unit(dev),
7127 "rec.autosrc", &pdevinfo->autorecsrc);
7128 SYSCTL_ADD_INT(&d->rec_sysctl_ctx,
7129 SYSCTL_CHILDREN(d->rec_sysctl_tree), OID_AUTO,
7130 "autosrc", CTLFLAG_RW,
7131 &pdevinfo->autorecsrc, 0,
7132 "Automatic recording source selection");
7135 if (pdevinfo->mixer != NULL) {
7136 hdaa_audio_ctl_set_defaults(pdevinfo);
7138 if (pdevinfo->playas >= 0) {
7139 as = &devinfo->as[pdevinfo->playas];
7140 hdaa_channels_handler(as);
7142 if (pdevinfo->recas >= 0) {
7143 as = &devinfo->as[pdevinfo->recas];
7144 hdaa_autorecsrc_handler(as, NULL);
7145 hdaa_channels_handler(as);
7147 hdaa_unlock(devinfo);
7150 ksnprintf(status, SND_STATUSLEN, "on %s %s",
7151 device_get_nameunit(device_get_parent(dev)),
7152 PCM_KLDSTRING(snd_hda));
7153 pcm_setstatus(dev, status);
7159 hdaa_pcm_detach(device_t dev)
7161 struct hdaa_pcm_devinfo *pdevinfo =
7162 (struct hdaa_pcm_devinfo *)device_get_ivars(dev);
7165 if (pdevinfo->registered > 0) {
7166 err = pcm_unregister(dev);
7174 static device_method_t hdaa_pcm_methods[] = {
7175 /* device interface */
7176 DEVMETHOD(device_probe, hdaa_pcm_probe),
7177 DEVMETHOD(device_attach, hdaa_pcm_attach),
7178 DEVMETHOD(device_detach, hdaa_pcm_detach),
7182 static driver_t hdaa_pcm_driver = {
7188 DRIVER_MODULE(snd_hda_pcm, hdaa, hdaa_pcm_driver, pcm_devclass, NULL, NULL);
7189 MODULE_DEPEND(snd_hda, sound, SOUND_MINVER, SOUND_PREFVER, SOUND_MAXVER);
7190 MODULE_VERSION(snd_hda, 1);