2 * Copyright (c) 2006 Stephane E. Potvin <sepotvin@videotron.ca>
3 * Copyright (c) 2006 Ariff Abdullah <ariff@FreeBSD.org>
4 * Copyright (c) 2008-2012 Alexander Motin <mav@FreeBSD.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * Intel High Definition Audio (Audio function) driver for FreeBSD.
33 #ifdef HAVE_KERNEL_OPTION_HEADERS
37 #include <dev/sound/pcm/sound.h>
39 #include <sys/ctype.h>
40 #include <sys/taskqueue.h>
42 #include <dev/sound/pci/hda/hdac.h>
43 #include <dev/sound/pci/hda/hdaa.h>
44 #include <dev/sound/pci/hda/hda_reg.h>
48 SND_DECLARE_FILE("$FreeBSD$");
50 #define hdaa_lock(devinfo) snd_mtxlock((devinfo)->lock)
51 #define hdaa_unlock(devinfo) snd_mtxunlock((devinfo)->lock)
52 #define hdaa_lockassert(devinfo) snd_mtxassert((devinfo)->lock)
53 #define hdaa_lockowned(devinfo) mtx_owned((devinfo)->lock)
58 } hdaa_quirks_tab[] = {
59 { "softpcmvol", HDAA_QUIRK_SOFTPCMVOL },
60 { "fixedrate", HDAA_QUIRK_FIXEDRATE },
61 { "forcestereo", HDAA_QUIRK_FORCESTEREO },
62 { "eapdinv", HDAA_QUIRK_EAPDINV },
63 { "senseinv", HDAA_QUIRK_SENSEINV },
64 { "ivref50", HDAA_QUIRK_IVREF50 },
65 { "ivref80", HDAA_QUIRK_IVREF80 },
66 { "ivref100", HDAA_QUIRK_IVREF100 },
67 { "ovref50", HDAA_QUIRK_OVREF50 },
68 { "ovref80", HDAA_QUIRK_OVREF80 },
69 { "ovref100", HDAA_QUIRK_OVREF100 },
70 { "ivref", HDAA_QUIRK_IVREF },
71 { "ovref", HDAA_QUIRK_OVREF },
72 { "vref", HDAA_QUIRK_VREF },
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 const static 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)
240 * Headphones redirection change handler.
243 hdaa_hpredir_handler(struct hdaa_widget *w)
245 struct hdaa_devinfo *devinfo = w->devinfo;
246 struct hdaa_audio_as *as = &devinfo->as[w->bindas];
247 struct hdaa_widget *w1;
248 struct hdaa_audio_ctl *ctl;
250 int j, connected = w->wclass.pin.connected;
253 device_printf((as->pdevinfo && as->pdevinfo->dev) ?
254 as->pdevinfo->dev : devinfo->dev,
255 "Redirect output to: %s\n",
256 connected ? "headphones": "main");
258 /* (Un)Mute headphone pin. */
259 ctl = hdaa_audio_ctl_amp_get(devinfo,
260 w->nid, HDAA_CTL_IN, -1, 1);
261 if (ctl != NULL && ctl->mute) {
262 /* If pin has muter - use it. */
263 val = connected ? 0 : 1;
264 if (val != ctl->forcemute) {
265 ctl->forcemute = val;
266 hdaa_audio_ctl_amp_set(ctl,
267 HDAA_AMP_MUTE_DEFAULT,
268 HDAA_AMP_VOL_DEFAULT, HDAA_AMP_VOL_DEFAULT);
271 /* If there is no muter - disable pin output. */
273 val = w->wclass.pin.ctrl |
274 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
276 val = w->wclass.pin.ctrl &
277 ~HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
278 if (val != w->wclass.pin.ctrl) {
279 w->wclass.pin.ctrl = val;
280 hda_command(devinfo->dev,
281 HDA_CMD_SET_PIN_WIDGET_CTRL(0,
282 w->nid, w->wclass.pin.ctrl));
285 /* (Un)Mute other pins. */
286 for (j = 0; j < 15; j++) {
287 if (as->pins[j] <= 0)
289 ctl = hdaa_audio_ctl_amp_get(devinfo,
290 as->pins[j], HDAA_CTL_IN, -1, 1);
291 if (ctl != NULL && ctl->mute) {
292 /* If pin has muter - use it. */
293 val = connected ? 1 : 0;
294 if (val == ctl->forcemute)
296 ctl->forcemute = val;
297 hdaa_audio_ctl_amp_set(ctl,
298 HDAA_AMP_MUTE_DEFAULT,
299 HDAA_AMP_VOL_DEFAULT, HDAA_AMP_VOL_DEFAULT);
302 /* If there is no muter - disable pin output. */
303 w1 = hdaa_widget_get(devinfo, as->pins[j]);
306 val = w1->wclass.pin.ctrl &
307 ~HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
309 val = w1->wclass.pin.ctrl |
310 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
311 if (val != w1->wclass.pin.ctrl) {
312 w1->wclass.pin.ctrl = val;
313 hda_command(devinfo->dev,
314 HDA_CMD_SET_PIN_WIDGET_CTRL(0,
315 w1->nid, w1->wclass.pin.ctrl));
322 * Recording source change handler.
325 hdaa_autorecsrc_handler(struct hdaa_audio_as *as, struct hdaa_widget *w)
327 struct hdaa_pcm_devinfo *pdevinfo = as->pdevinfo;
328 struct hdaa_devinfo *devinfo;
329 struct hdaa_widget *w1;
330 int i, mask, fullmask, prio, bestprio;
333 if (!as->mixed || pdevinfo == NULL || pdevinfo->mixer == NULL)
335 /* Don't touch anything if we asked not to. */
336 if (pdevinfo->autorecsrc == 0 ||
337 (pdevinfo->autorecsrc == 1 && w != NULL))
339 /* Don't touch anything if "mix" or "speaker" selected. */
340 if (pdevinfo->recsrc & (SOUND_MASK_IMIX | SOUND_MASK_SPEAKER))
342 /* Don't touch anything if several selected. */
343 if (ffs(pdevinfo->recsrc) != fls(pdevinfo->recsrc))
345 devinfo = pdevinfo->devinfo;
348 for (i = 0; i < 16; i++) {
349 if (as->pins[i] <= 0)
351 w1 = hdaa_widget_get(devinfo, as->pins[i]);
352 if (w1 == NULL || w1->enable == 0)
354 if (w1->wclass.pin.connected == 0)
356 prio = (w1->wclass.pin.connected == 1) ? 2 : 1;
359 if (prio > bestprio) {
363 mask |= (1 << w1->ossdev);
364 fullmask |= (1 << w1->ossdev);
368 /* Prefer newly connected input. */
369 if (w != NULL && (mask & (1 << w->ossdev)))
370 mask = (1 << w->ossdev);
371 /* Prefer previously selected input */
372 if (mask & pdevinfo->recsrc)
373 mask &= pdevinfo->recsrc;
375 if (mask & SOUND_MASK_MIC)
376 mask = SOUND_MASK_MIC;
377 /* Prefer monitor (2nd mic). */
378 if (mask & SOUND_MASK_MONITOR)
379 mask = SOUND_MASK_MONITOR;
380 /* Just take first one. */
381 mask = (1 << (ffs(mask) - 1));
383 hdaa_audio_ctl_ossmixer_mask2allname(mask, buf, sizeof(buf));
384 device_printf(pdevinfo->dev,
385 "Automatically set rec source to: %s\n", buf);
387 hdaa_unlock(devinfo);
388 mix_setrecsrc(pdevinfo->mixer, mask);
393 * Jack presence detection event handler.
396 hdaa_presence_handler(struct hdaa_widget *w)
398 struct hdaa_devinfo *devinfo = w->devinfo;
399 struct hdaa_audio_as *as;
403 if (w->enable == 0 || w->type !=
404 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
407 if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(w->wclass.pin.cap) == 0 ||
408 (HDA_CONFIG_DEFAULTCONF_MISC(w->wclass.pin.config) & 1) != 0)
411 res = hda_command(devinfo->dev, HDA_CMD_GET_PIN_SENSE(0, w->nid));
412 connected = (res & HDA_CMD_GET_PIN_SENSE_PRESENCE_DETECT) != 0;
413 if (devinfo->quirks & HDAA_QUIRK_SENSEINV)
414 connected = !connected;
415 old = w->wclass.pin.connected;
416 if (connected == old)
418 w->wclass.pin.connected = connected;
420 if (connected || old != 2) {
421 device_printf(devinfo->dev,
422 "Pin sense: nid=%d sence=0x%08x (%sconnected)\n",
423 w->nid, res, !connected ? "dis" : "");
427 as = &devinfo->as[w->bindas];
428 if (as->hpredir >= 0 && as->pins[15] == w->nid)
429 hdaa_hpredir_handler(w);
430 if (as->dir == HDAA_CTL_IN && old != 2)
431 hdaa_autorecsrc_handler(as, w);
435 * Callback for poll based presence detection.
438 hdaa_jack_poll_callback(void *arg)
440 struct hdaa_devinfo *devinfo = arg;
441 struct hdaa_widget *w;
445 if (devinfo->poll_ival == 0) {
446 hdaa_unlock(devinfo);
449 for (i = 0; i < devinfo->ascnt; i++) {
450 if (devinfo->as[i].hpredir < 0)
452 w = hdaa_widget_get(devinfo, devinfo->as[i].pins[15]);
453 if (w == NULL || w->enable == 0 || w->type !=
454 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
456 hdaa_presence_handler(w);
458 callout_reset(&devinfo->poll_jack, devinfo->poll_ival,
459 hdaa_jack_poll_callback, devinfo);
460 hdaa_unlock(devinfo);
464 hdaa_eld_dump(struct hdaa_widget *w)
466 struct hdaa_devinfo *devinfo = w->devinfo;
467 device_t dev = devinfo->dev;
469 int len, mnl, i, sadc, fmt;
471 if (w->eld == NULL || w->eld_len < 4)
474 "ELD nid=%d: ELD_Ver=%u Baseline_ELD_Len=%u\n",
475 w->nid, w->eld[0] >> 3, w->eld[2]);
476 if ((w->eld[0] >> 3) != 0x02)
478 len = min(w->eld_len, (u_int)w->eld[2] * 4);
479 mnl = w->eld[4] & 0x1f;
481 "ELD nid=%d: CEA_EDID_Ver=%u MNL=%u\n",
482 w->nid, w->eld[4] >> 5, mnl);
483 sadc = w->eld[5] >> 4;
485 "ELD nid=%d: SAD_Count=%u Conn_Type=%u S_AI=%u HDCP=%u\n",
486 w->nid, sadc, (w->eld[5] >> 2) & 0x3,
487 (w->eld[5] >> 1) & 0x1, w->eld[5] & 0x1);
489 "ELD nid=%d: Aud_Synch_Delay=%ums\n",
490 w->nid, w->eld[6] * 2);
492 "ELD nid=%d: Channels=0x%b\n",
494 "\020\07RLRC\06FLRC\05RC\04RLR\03FC\02LFE\01FLR");
496 "ELD nid=%d: Port_ID=0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
497 w->nid, w->eld[8], w->eld[9], w->eld[10], w->eld[11],
498 w->eld[12], w->eld[13], w->eld[14], w->eld[15]);
500 "ELD nid=%d: Manufacturer_Name=0x%02x%02x\n",
501 w->nid, w->eld[16], w->eld[17]);
503 "ELD nid=%d: Product_Code=0x%02x%02x\n",
504 w->nid, w->eld[18], w->eld[19]);
506 "ELD nid=%d: Monitor_Name_String='%.*s'\n",
507 w->nid, mnl, &w->eld[20]);
508 for (i = 0; i < sadc; i++) {
509 sad = &w->eld[20 + mnl + i * 3];
510 fmt = (sad[0] >> 3) & 0x0f;
511 if (fmt == HDA_HDMI_CODING_TYPE_REF_CTX) {
512 fmt = (sad[2] >> 3) & 0x1f;
513 if (fmt < 1 || fmt > 3)
519 "ELD nid=%d: %s %dch freqs=0x%b",
520 w->nid, HDA_HDMI_CODING_TYPES[fmt], (sad[0] & 0x07) + 1,
521 sad[1], "\020\007192\006176\00596\00488\00348\00244\00132");
523 case HDA_HDMI_CODING_TYPE_LPCM:
524 printf(" sizes=0x%b",
525 sad[2] & 0x07, "\020\00324\00220\00116");
527 case HDA_HDMI_CODING_TYPE_AC3:
528 case HDA_HDMI_CODING_TYPE_MPEG1:
529 case HDA_HDMI_CODING_TYPE_MP3:
530 case HDA_HDMI_CODING_TYPE_MPEG2:
531 case HDA_HDMI_CODING_TYPE_AACLC:
532 case HDA_HDMI_CODING_TYPE_DTS:
533 case HDA_HDMI_CODING_TYPE_ATRAC:
534 printf(" max_bitrate=%d", sad[2] * 8000);
536 case HDA_HDMI_CODING_TYPE_WMAPRO:
537 printf(" profile=%d", sad[2] & 0x07);
545 hdaa_eld_handler(struct hdaa_widget *w)
547 struct hdaa_devinfo *devinfo = w->devinfo;
551 if (w->enable == 0 || w->type !=
552 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
555 if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(w->wclass.pin.cap) == 0 ||
556 (HDA_CONFIG_DEFAULTCONF_MISC(w->wclass.pin.config) & 1) != 0)
559 res = hda_command(devinfo->dev, HDA_CMD_GET_PIN_SENSE(0, w->nid));
560 if ((w->eld != 0) == ((res & HDA_CMD_GET_PIN_SENSE_ELD_VALID) != 0))
562 if (w->eld != NULL) {
564 free(w->eld, M_HDAA);
568 device_printf(devinfo->dev,
569 "Pin sense: nid=%d sence=0x%08x "
570 "(%sconnected, ELD %svalid)\n",
572 (res & HDA_CMD_GET_PIN_SENSE_PRESENCE_DETECT) ? "" : "dis",
573 (res & HDA_CMD_GET_PIN_SENSE_ELD_VALID) ? "" : "in");
575 if ((res & HDA_CMD_GET_PIN_SENSE_ELD_VALID) == 0)
578 res = hda_command(devinfo->dev,
579 HDA_CMD_GET_HDMI_DIP_SIZE(0, w->nid, 0x08));
580 if (res == HDA_INVALID)
582 w->eld_len = res & 0xff;
584 w->eld = malloc(w->eld_len, M_HDAA, M_ZERO | M_NOWAIT);
585 if (w->eld == NULL) {
590 for (i = 0; i < w->eld_len; i++) {
591 res = hda_command(devinfo->dev,
592 HDA_CMD_GET_HDMI_ELDD(0, w->nid, i));
593 if (res & 0x80000000)
594 w->eld[i] = res & 0xff;
602 * Pin sense initializer.
605 hdaa_sense_init(struct hdaa_devinfo *devinfo)
607 struct hdaa_audio_as *as;
608 struct hdaa_widget *w;
611 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
612 w = hdaa_widget_get(devinfo, i);
613 if (w == NULL || w->enable == 0 || w->type !=
614 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
616 if (HDA_PARAM_AUDIO_WIDGET_CAP_UNSOL_CAP(w->param.widget_cap)) {
618 w->unsol = HDAC_UNSOL_ALLOC(
619 device_get_parent(devinfo->dev),
620 devinfo->dev, w->nid);
621 hda_command(devinfo->dev,
622 HDA_CMD_SET_UNSOLICITED_RESPONSE(0, w->nid,
623 HDA_CMD_SET_UNSOLICITED_RESPONSE_ENABLE | w->unsol));
625 as = &devinfo->as[w->bindas];
626 if (as->hpredir >= 0 && as->pins[15] == w->nid) {
627 if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(w->wclass.pin.cap) == 0 ||
628 (HDA_CONFIG_DEFAULTCONF_MISC(w->wclass.pin.config) & 1) != 0) {
629 device_printf(devinfo->dev,
630 "No presence detection support at nid %d\n",
636 device_printf(devinfo->dev,
637 "Headphones redirection for "
638 "association %d nid=%d using %s.\n",
640 (w->unsol < 0) ? "polling" :
641 "unsolicited responses");
645 hdaa_presence_handler(w);
646 if (!HDA_PARAM_PIN_CAP_DP(w->wclass.pin.cap) &&
647 !HDA_PARAM_PIN_CAP_HDMI(w->wclass.pin.cap))
652 callout_reset(&devinfo->poll_jack, 1,
653 hdaa_jack_poll_callback, devinfo);
658 hdaa_sense_deinit(struct hdaa_devinfo *devinfo)
660 struct hdaa_widget *w;
663 callout_stop(&devinfo->poll_jack);
664 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
665 w = hdaa_widget_get(devinfo, i);
666 if (w == NULL || w->enable == 0 || w->type !=
667 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
671 hda_command(devinfo->dev,
672 HDA_CMD_SET_UNSOLICITED_RESPONSE(0, w->nid, 0));
674 device_get_parent(devinfo->dev), devinfo->dev,
681 hdaa_widget_pin_patch(uint32_t config, const char *str)
684 char *key, *value, *rest, *bad;
687 strlcpy(buf, str, sizeof(buf));
689 while ((key = strsep(&rest, "=")) != NULL) {
690 value = strsep(&rest, " \t");
693 ival = strtol(value, &bad, 10);
694 if (strcmp(key, "seq") == 0) {
695 config &= ~HDA_CONFIG_DEFAULTCONF_SEQUENCE_MASK;
696 config |= ((ival << HDA_CONFIG_DEFAULTCONF_SEQUENCE_SHIFT) &
697 HDA_CONFIG_DEFAULTCONF_SEQUENCE_MASK);
698 } else if (strcmp(key, "as") == 0) {
699 config &= ~HDA_CONFIG_DEFAULTCONF_ASSOCIATION_MASK;
700 config |= ((ival << HDA_CONFIG_DEFAULTCONF_ASSOCIATION_SHIFT) &
701 HDA_CONFIG_DEFAULTCONF_ASSOCIATION_MASK);
702 } else if (strcmp(key, "misc") == 0) {
703 config &= ~HDA_CONFIG_DEFAULTCONF_MISC_MASK;
704 config |= ((ival << HDA_CONFIG_DEFAULTCONF_MISC_SHIFT) &
705 HDA_CONFIG_DEFAULTCONF_MISC_MASK);
706 } else if (strcmp(key, "color") == 0) {
707 config &= ~HDA_CONFIG_DEFAULTCONF_COLOR_MASK;
709 config |= ((ival << HDA_CONFIG_DEFAULTCONF_COLOR_SHIFT) &
710 HDA_CONFIG_DEFAULTCONF_COLOR_MASK);
712 for (i = 0; i < 16; i++) {
713 if (strcasecmp(HDA_COLORS[i], value) == 0) {
714 config |= (i << HDA_CONFIG_DEFAULTCONF_COLOR_SHIFT);
718 } else if (strcmp(key, "ctype") == 0) {
719 config &= ~HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_MASK;
721 config |= ((ival << HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_SHIFT) &
722 HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_MASK);
724 for (i = 0; i < 16; i++) {
725 if (strcasecmp(HDA_CONNECTORS[i], value) == 0) {
726 config |= (i << HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_SHIFT);
730 } else if (strcmp(key, "device") == 0) {
731 config &= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
733 config |= ((ival << HDA_CONFIG_DEFAULTCONF_DEVICE_SHIFT) &
734 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK);
737 for (i = 0; i < 16; i++) {
738 if (strcasecmp(HDA_DEVS[i], value) == 0) {
739 config |= (i << HDA_CONFIG_DEFAULTCONF_DEVICE_SHIFT);
743 } else if (strcmp(key, "loc") == 0) {
744 config &= ~HDA_CONFIG_DEFAULTCONF_LOCATION_MASK;
746 config |= ((ival << HDA_CONFIG_DEFAULTCONF_LOCATION_SHIFT) &
747 HDA_CONFIG_DEFAULTCONF_LOCATION_MASK);
750 for (i = 0; i < 64; i++) {
751 if (strcasecmp(HDA_LOCS[i], value) == 0) {
752 config |= (i << HDA_CONFIG_DEFAULTCONF_LOCATION_SHIFT);
756 } else if (strcmp(key, "conn") == 0) {
757 config &= ~HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK;
759 config |= ((ival << HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_SHIFT) &
760 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK);
763 for (i = 0; i < 4; i++) {
764 if (strcasecmp(HDA_CONNS[i], value) == 0) {
765 config |= (i << HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_SHIFT);
775 hdaa_gpio_patch(uint32_t gpio, const char *str)
778 char *key, *value, *rest;
781 strlcpy(buf, str, sizeof(buf));
783 while ((key = strsep(&rest, "=")) != NULL) {
784 value = strsep(&rest, " \t");
787 ikey = strtol(key, NULL, 10);
788 if (ikey < 0 || ikey > 7)
790 for (i = 0; i < 7; i++) {
791 if (strcasecmp(HDA_GPIO_ACTIONS[i], value) == 0) {
792 gpio &= ~HDAA_GPIO_MASK(ikey);
793 gpio |= i << HDAA_GPIO_SHIFT(ikey);
802 hdaa_local_patch_pin(struct hdaa_widget *w)
804 device_t dev = w->devinfo->dev;
805 const char *res = NULL;
806 uint32_t config, orig;
809 config = orig = w->wclass.pin.config;
810 snprintf(buf, sizeof(buf), "cad%u.nid%u.config",
811 hda_get_codec_id(dev), w->nid);
812 if (resource_string_value(device_get_name(
813 device_get_parent(device_get_parent(dev))),
814 device_get_unit(device_get_parent(device_get_parent(dev))),
816 if (strncmp(res, "0x", 2) == 0) {
817 config = strtol(res + 2, NULL, 16);
819 config = hdaa_widget_pin_patch(config, res);
822 snprintf(buf, sizeof(buf), "nid%u.config", w->nid);
823 if (resource_string_value(device_get_name(dev), device_get_unit(dev),
825 if (strncmp(res, "0x", 2) == 0) {
826 config = strtol(res + 2, NULL, 16);
828 config = hdaa_widget_pin_patch(config, res);
833 device_printf(w->devinfo->dev,
834 "Patching pin config nid=%u 0x%08x -> 0x%08x\n",
835 w->nid, orig, config);
837 w->wclass.pin.newconf = w->wclass.pin.config = config;
841 hdaa_sysctl_config(SYSCTL_HANDLER_ARGS)
847 conf = *(uint32_t *)oidp->oid_arg1;
848 snprintf(buf, sizeof(buf), "0x%08x as=%d seq=%d "
849 "device=%s conn=%s ctype=%s loc=%s color=%s misc=%d",
851 HDA_CONFIG_DEFAULTCONF_ASSOCIATION(conf),
852 HDA_CONFIG_DEFAULTCONF_SEQUENCE(conf),
853 HDA_DEVS[HDA_CONFIG_DEFAULTCONF_DEVICE(conf)],
854 HDA_CONNS[HDA_CONFIG_DEFAULTCONF_CONNECTIVITY(conf)],
855 HDA_CONNECTORS[HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE(conf)],
856 HDA_LOCS[HDA_CONFIG_DEFAULTCONF_LOCATION(conf)],
857 HDA_COLORS[HDA_CONFIG_DEFAULTCONF_COLOR(conf)],
858 HDA_CONFIG_DEFAULTCONF_MISC(conf));
859 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
860 if (error != 0 || req->newptr == NULL)
862 if (strncmp(buf, "0x", 2) == 0)
863 conf = strtol(buf + 2, NULL, 16);
865 conf = hdaa_widget_pin_patch(conf, buf);
866 *(uint32_t *)oidp->oid_arg1 = conf;
871 hdaa_config_fetch(const char *str, uint32_t *on, uint32_t *off)
873 int i = 0, j, k, len, inv;
876 while (str[i] != '\0' &&
877 (str[i] == ',' || isspace(str[i]) != 0))
882 while (str[j] != '\0' &&
883 !(str[j] == ',' || isspace(str[j]) != 0))
886 if (len > 2 && strncmp(str + i, "no", 2) == 0)
890 for (k = 0; len > inv && k < nitems(hdaa_quirks_tab); k++) {
891 if (strncmp(str + i + inv,
892 hdaa_quirks_tab[k].key, len - inv) != 0)
894 if (len - inv != strlen(hdaa_quirks_tab[k].key))
897 *on |= hdaa_quirks_tab[k].value;
898 *off &= ~hdaa_quirks_tab[k].value;
900 *off |= hdaa_quirks_tab[k].value;
901 *on &= ~hdaa_quirks_tab[k].value;
910 hdaa_sysctl_quirks(SYSCTL_HANDLER_ARGS)
914 uint32_t quirks, quirks_off;
916 quirks = *(uint32_t *)oidp->oid_arg1;
918 for (i = 0; i < nitems(hdaa_quirks_tab); i++) {
919 if ((quirks & hdaa_quirks_tab[i].value) != 0)
920 n += snprintf(buf + n, sizeof(buf) - n, "%s%s",
921 n != 0 ? "," : "", hdaa_quirks_tab[i].key);
923 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
924 if (error != 0 || req->newptr == NULL)
926 if (strncmp(buf, "0x", 2) == 0)
927 quirks = strtol(buf + 2, NULL, 16);
930 hdaa_config_fetch(buf, &quirks, &quirks_off);
932 *(uint32_t *)oidp->oid_arg1 = quirks;
937 hdaa_local_patch(struct hdaa_devinfo *devinfo)
939 struct hdaa_widget *w;
940 const char *res = NULL;
941 uint32_t quirks_on = 0, quirks_off = 0, x;
944 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
945 w = hdaa_widget_get(devinfo, i);
948 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
949 hdaa_local_patch_pin(w);
952 if (resource_string_value(device_get_name(devinfo->dev),
953 device_get_unit(devinfo->dev), "config", &res) == 0) {
954 if (res != NULL && strlen(res) > 0)
955 hdaa_config_fetch(res, &quirks_on, &quirks_off);
956 devinfo->quirks |= quirks_on;
957 devinfo->quirks &= ~quirks_off;
959 if (devinfo->newquirks == -1)
960 devinfo->newquirks = devinfo->quirks;
962 devinfo->quirks = devinfo->newquirks;
964 device_printf(devinfo->dev,
965 "Config options: 0x%08x\n", devinfo->quirks);
968 if (resource_string_value(device_get_name(devinfo->dev),
969 device_get_unit(devinfo->dev), "gpio_config", &res) == 0) {
970 if (strncmp(res, "0x", 2) == 0) {
971 devinfo->gpio = strtol(res + 2, NULL, 16);
973 devinfo->gpio = hdaa_gpio_patch(devinfo->gpio, res);
976 if (devinfo->newgpio == -1)
977 devinfo->newgpio = devinfo->gpio;
979 devinfo->gpio = devinfo->newgpio;
980 if (devinfo->newgpo == -1)
981 devinfo->newgpo = devinfo->gpo;
983 devinfo->gpo = devinfo->newgpo;
985 device_printf(devinfo->dev, "GPIO config options:");
986 for (i = 0; i < 7; i++) {
987 x = (devinfo->gpio & HDAA_GPIO_MASK(i)) >> HDAA_GPIO_SHIFT(i);
989 printf(" %d=%s", i, HDA_GPIO_ACTIONS[x]);
996 hdaa_widget_connection_parse(struct hdaa_widget *w)
999 int i, j, max, ents, entnum;
1001 nid_t cnid, addcnid, prevcnid;
1005 res = hda_command(w->devinfo->dev,
1006 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_CONN_LIST_LENGTH));
1008 ents = HDA_PARAM_CONN_LIST_LENGTH_LIST_LENGTH(res);
1013 entnum = HDA_PARAM_CONN_LIST_LENGTH_LONG_FORM(res) ? 2 : 4;
1014 max = (sizeof(w->conns) / sizeof(w->conns[0])) - 1;
1017 #define CONN_RMASK(e) (1 << ((32 / (e)) - 1))
1018 #define CONN_NMASK(e) (CONN_RMASK(e) - 1)
1019 #define CONN_RESVAL(r, e, n) ((r) >> ((32 / (e)) * (n)))
1020 #define CONN_RANGE(r, e, n) (CONN_RESVAL(r, e, n) & CONN_RMASK(e))
1021 #define CONN_CNID(r, e, n) (CONN_RESVAL(r, e, n) & CONN_NMASK(e))
1023 for (i = 0; i < ents; i += entnum) {
1024 res = hda_command(w->devinfo->dev,
1025 HDA_CMD_GET_CONN_LIST_ENTRY(0, nid, i));
1026 for (j = 0; j < entnum; j++) {
1027 cnid = CONN_CNID(res, entnum, j);
1029 if (w->nconns < ents)
1030 device_printf(w->devinfo->dev,
1031 "WARNING: nid=%d has zero cnid "
1032 "entnum=%d j=%d index=%d "
1033 "entries=%d found=%d res=0x%08x\n",
1035 ents, w->nconns, res);
1039 if (cnid < w->devinfo->startnode ||
1040 cnid >= w->devinfo->endnode) {
1042 device_printf(w->devinfo->dev,
1043 "WARNING: nid=%d has cnid outside "
1044 "of the AFG range j=%d "
1045 "entnum=%d index=%d res=0x%08x\n",
1046 nid, j, entnum, i, res);
1049 if (CONN_RANGE(res, entnum, j) == 0)
1051 else if (prevcnid == 0 || prevcnid >= cnid) {
1052 device_printf(w->devinfo->dev,
1053 "WARNING: Invalid child range "
1054 "nid=%d index=%d j=%d entnum=%d "
1055 "prevcnid=%d cnid=%d res=0x%08x\n",
1056 nid, i, j, entnum, prevcnid,
1060 addcnid = prevcnid + 1;
1061 while (addcnid <= cnid) {
1062 if (w->nconns > max) {
1063 device_printf(w->devinfo->dev,
1064 "Adding %d (nid=%d): "
1065 "Max connection reached! max=%d\n",
1066 addcnid, nid, max + 1);
1069 w->connsenable[w->nconns] = 1;
1070 w->conns[w->nconns++] = addcnid++;
1081 hdaa_widget_parse(struct hdaa_widget *w)
1083 device_t dev = w->devinfo->dev;
1088 w->param.widget_cap = wcap = hda_command(dev,
1089 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_AUDIO_WIDGET_CAP));
1090 w->type = HDA_PARAM_AUDIO_WIDGET_CAP_TYPE(wcap);
1092 hdaa_widget_connection_parse(w);
1094 if (HDA_PARAM_AUDIO_WIDGET_CAP_OUT_AMP(wcap)) {
1095 if (HDA_PARAM_AUDIO_WIDGET_CAP_AMP_OVR(wcap))
1096 w->param.outamp_cap =
1098 HDA_CMD_GET_PARAMETER(0, nid,
1099 HDA_PARAM_OUTPUT_AMP_CAP));
1101 w->param.outamp_cap =
1102 w->devinfo->outamp_cap;
1104 w->param.outamp_cap = 0;
1106 if (HDA_PARAM_AUDIO_WIDGET_CAP_IN_AMP(wcap)) {
1107 if (HDA_PARAM_AUDIO_WIDGET_CAP_AMP_OVR(wcap))
1108 w->param.inamp_cap =
1110 HDA_CMD_GET_PARAMETER(0, nid,
1111 HDA_PARAM_INPUT_AMP_CAP));
1113 w->param.inamp_cap =
1114 w->devinfo->inamp_cap;
1116 w->param.inamp_cap = 0;
1118 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT ||
1119 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
1120 if (HDA_PARAM_AUDIO_WIDGET_CAP_FORMAT_OVR(wcap)) {
1121 cap = hda_command(dev,
1122 HDA_CMD_GET_PARAMETER(0, nid,
1123 HDA_PARAM_SUPP_STREAM_FORMATS));
1124 w->param.supp_stream_formats = (cap != 0) ? cap :
1125 w->devinfo->supp_stream_formats;
1126 cap = hda_command(dev,
1127 HDA_CMD_GET_PARAMETER(0, nid,
1128 HDA_PARAM_SUPP_PCM_SIZE_RATE));
1129 w->param.supp_pcm_size_rate = (cap != 0) ? cap :
1130 w->devinfo->supp_pcm_size_rate;
1132 w->param.supp_stream_formats =
1133 w->devinfo->supp_stream_formats;
1134 w->param.supp_pcm_size_rate =
1135 w->devinfo->supp_pcm_size_rate;
1137 if (HDA_PARAM_AUDIO_WIDGET_CAP_STRIPE(w->param.widget_cap)) {
1138 w->wclass.conv.stripecap = hda_command(dev,
1139 HDA_CMD_GET_STRIPE_CONTROL(0, w->nid)) >> 20;
1141 w->wclass.conv.stripecap = 1;
1143 w->param.supp_stream_formats = 0;
1144 w->param.supp_pcm_size_rate = 0;
1147 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) {
1148 w->wclass.pin.original = w->wclass.pin.newconf =
1149 w->wclass.pin.config = hda_command(dev,
1150 HDA_CMD_GET_CONFIGURATION_DEFAULT(0, w->nid));
1151 w->wclass.pin.cap = hda_command(dev,
1152 HDA_CMD_GET_PARAMETER(0, w->nid, HDA_PARAM_PIN_CAP));
1153 w->wclass.pin.ctrl = hda_command(dev,
1154 HDA_CMD_GET_PIN_WIDGET_CTRL(0, nid));
1155 w->wclass.pin.connected = 2;
1156 if (HDA_PARAM_PIN_CAP_EAPD_CAP(w->wclass.pin.cap)) {
1157 w->param.eapdbtl = hda_command(dev,
1158 HDA_CMD_GET_EAPD_BTL_ENABLE(0, nid));
1159 w->param.eapdbtl &= 0x7;
1160 w->param.eapdbtl |= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
1162 w->param.eapdbtl = HDA_INVALID;
1164 hdaa_unlock(w->devinfo);
1165 snprintf(buf, sizeof(buf), "nid%d_config", w->nid);
1166 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
1167 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
1168 buf, CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE,
1169 &w->wclass.pin.newconf, sizeof(&w->wclass.pin.newconf),
1170 hdaa_sysctl_config, "A", "Current pin configuration");
1171 snprintf(buf, sizeof(buf), "nid%d_original", w->nid);
1172 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
1173 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
1174 buf, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
1175 &w->wclass.pin.original, sizeof(&w->wclass.pin.original),
1176 hdaa_sysctl_config, "A", "Original pin configuration");
1177 hdaa_lock(w->devinfo);
1183 hdaa_widget_postprocess(struct hdaa_widget *w)
1185 const char *typestr;
1187 w->type = HDA_PARAM_AUDIO_WIDGET_CAP_TYPE(w->param.widget_cap);
1189 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT:
1190 typestr = "audio output";
1192 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT:
1193 typestr = "audio input";
1195 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER:
1196 typestr = "audio mixer";
1198 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR:
1199 typestr = "audio selector";
1201 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
1204 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_POWER_WIDGET:
1205 typestr = "power widget";
1207 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_VOLUME_WIDGET:
1208 typestr = "volume widget";
1210 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET:
1211 typestr = "beep widget";
1213 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_VENDOR_WIDGET:
1214 typestr = "vendor widget";
1217 typestr = "unknown type";
1220 strlcpy(w->name, typestr, sizeof(w->name));
1222 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) {
1227 config = w->wclass.pin.config;
1228 devstr = HDA_DEVS[(config & HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) >>
1229 HDA_CONFIG_DEFAULTCONF_DEVICE_SHIFT];
1230 conn = (config & HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK) >>
1231 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_SHIFT;
1232 color = (config & HDA_CONFIG_DEFAULTCONF_COLOR_MASK) >>
1233 HDA_CONFIG_DEFAULTCONF_COLOR_SHIFT;
1234 strlcat(w->name, ": ", sizeof(w->name));
1235 strlcat(w->name, devstr, sizeof(w->name));
1236 strlcat(w->name, " (", sizeof(w->name));
1237 if (conn == 0 && color != 0 && color != 15) {
1238 strlcat(w->name, HDA_COLORS[color], sizeof(w->name));
1239 strlcat(w->name, " ", sizeof(w->name));
1241 strlcat(w->name, HDA_CONNS[conn], sizeof(w->name));
1242 strlcat(w->name, ")", sizeof(w->name));
1246 struct hdaa_widget *
1247 hdaa_widget_get(struct hdaa_devinfo *devinfo, nid_t nid)
1249 if (devinfo == NULL || devinfo->widget == NULL ||
1250 nid < devinfo->startnode || nid >= devinfo->endnode)
1252 return (&devinfo->widget[nid - devinfo->startnode]);
1256 hdaa_audio_ctl_amp_set_internal(struct hdaa_devinfo *devinfo, nid_t nid,
1257 int index, int lmute, int rmute,
1258 int left, int right, int dir)
1263 device_printf(devinfo->dev,
1264 "Setting amplifier nid=%d index=%d %s mute=%d/%d vol=%d/%d\n",
1265 nid,index,dir ? "in" : "out",lmute,rmute,left,right);
1267 if (left != right || lmute != rmute) {
1268 v = (1 << (15 - dir)) | (1 << 13) | (index << 8) |
1269 (lmute << 7) | left;
1270 hda_command(devinfo->dev,
1271 HDA_CMD_SET_AMP_GAIN_MUTE(0, nid, v));
1272 v = (1 << (15 - dir)) | (1 << 12) | (index << 8) |
1273 (rmute << 7) | right;
1275 v = (1 << (15 - dir)) | (3 << 12) | (index << 8) |
1276 (lmute << 7) | left;
1278 hda_command(devinfo->dev,
1279 HDA_CMD_SET_AMP_GAIN_MUTE(0, nid, v));
1283 hdaa_audio_ctl_amp_set(struct hdaa_audio_ctl *ctl, uint32_t mute,
1284 int left, int right)
1289 nid = ctl->widget->nid;
1291 /* Save new values if valid. */
1292 if (mute != HDAA_AMP_MUTE_DEFAULT)
1294 if (left != HDAA_AMP_VOL_DEFAULT)
1296 if (right != HDAA_AMP_VOL_DEFAULT)
1298 /* Prepare effective values */
1299 if (ctl->forcemute) {
1305 lmute = HDAA_AMP_LEFT_MUTED(ctl->muted);
1306 rmute = HDAA_AMP_RIGHT_MUTED(ctl->muted);
1310 /* Apply effective values */
1311 if (ctl->dir & HDAA_CTL_OUT)
1312 hdaa_audio_ctl_amp_set_internal(ctl->widget->devinfo, nid, ctl->index,
1313 lmute, rmute, left, right, 0);
1314 if (ctl->dir & HDAA_CTL_IN)
1315 hdaa_audio_ctl_amp_set_internal(ctl->widget->devinfo, nid, ctl->index,
1316 lmute, rmute, left, right, 1);
1320 hdaa_widget_connection_select(struct hdaa_widget *w, uint8_t index)
1322 if (w == NULL || w->nconns < 1 || index > (w->nconns - 1))
1325 device_printf(w->devinfo->dev,
1326 "Setting selector nid=%d index=%d\n", w->nid, index);
1328 hda_command(w->devinfo->dev,
1329 HDA_CMD_SET_CONNECTION_SELECT_CONTROL(0, w->nid, index));
1333 /****************************************************************************
1335 ****************************************************************************/
1338 hdaa_channel_init(kobj_t obj, void *data, struct snd_dbuf *b,
1339 struct pcm_channel *c, int dir)
1341 struct hdaa_chan *ch = data;
1342 struct hdaa_pcm_devinfo *pdevinfo = ch->pdevinfo;
1343 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
1346 if (devinfo->quirks & HDAA_QUIRK_FIXEDRATE) {
1347 ch->caps.minspeed = ch->caps.maxspeed = 48000;
1348 ch->pcmrates[0] = 48000;
1349 ch->pcmrates[1] = 0;
1354 ch->blksz = pdevinfo->chan_size / pdevinfo->chan_blkcnt;
1355 ch->blkcnt = pdevinfo->chan_blkcnt;
1356 hdaa_unlock(devinfo);
1358 if (sndbuf_alloc(ch->b, bus_get_dma_tag(devinfo->dev),
1359 hda_get_dma_nocache(devinfo->dev) ? BUS_DMA_NOCACHE : 0,
1360 pdevinfo->chan_size) != 0)
1367 hdaa_channel_setformat(kobj_t obj, void *data, uint32_t format)
1369 struct hdaa_chan *ch = data;
1372 for (i = 0; ch->caps.fmtlist[i] != 0; i++) {
1373 if (format == ch->caps.fmtlist[i]) {
1383 hdaa_channel_setspeed(kobj_t obj, void *data, uint32_t speed)
1385 struct hdaa_chan *ch = data;
1386 uint32_t spd = 0, threshold;
1389 /* First look for equal or multiple frequency. */
1390 for (i = 0; ch->pcmrates[i] != 0; i++) {
1391 spd = ch->pcmrates[i];
1392 if (speed != 0 && spd / speed * speed == spd) {
1397 /* If no match, just find nearest. */
1398 for (i = 0; ch->pcmrates[i] != 0; i++) {
1399 spd = ch->pcmrates[i];
1400 threshold = spd + ((ch->pcmrates[i + 1] != 0) ?
1401 ((ch->pcmrates[i + 1] - spd) >> 1) : 0);
1402 if (speed < threshold)
1410 hdaa_stream_format(struct hdaa_chan *ch)
1416 if (ch->fmt & AFMT_S16_LE)
1417 fmt |= ch->bit16 << 4;
1418 else if (ch->fmt & AFMT_S32_LE)
1419 fmt |= ch->bit32 << 4;
1422 for (i = 0; i < HDA_RATE_TAB_LEN; i++) {
1423 if (hda_rate_tab[i].valid && ch->spd == hda_rate_tab[i].rate) {
1424 fmt |= hda_rate_tab[i].base;
1425 fmt |= hda_rate_tab[i].mul;
1426 fmt |= hda_rate_tab[i].div;
1430 fmt |= (AFMT_CHANNEL(ch->fmt) - 1);
1436 hdaa_allowed_stripes(uint16_t fmt)
1438 static const int bits[8] = { 8, 16, 20, 24, 32, 32, 32, 32 };
1441 size = bits[(fmt >> 4) & 0x03];
1442 size *= (fmt & 0x0f) + 1;
1443 size *= ((fmt >> 11) & 0x07) + 1;
1444 return (0xffffffffU >> (32 - fls(size / 8)));
1448 hdaa_audio_setup(struct hdaa_chan *ch)
1450 struct hdaa_audio_as *as = &ch->devinfo->as[ch->as];
1451 struct hdaa_widget *w, *wp;
1452 int i, j, k, chn, cchn, totalchn, totalextchn, c;
1454 /* Mapping channel pairs to codec pins/converters. */
1455 const static uint16_t convmap[2][5] =
1456 {{ 0x0010, 0x0001, 0x0201, 0x0231, 0x0231 }, /* 5.1 */
1457 { 0x0010, 0x0001, 0x2001, 0x2031, 0x2431 }};/* 7.1 */
1458 /* Mapping formats to HDMI channel allocations. */
1459 const static uint8_t hdmica[2][8] =
1460 {{ 0x02, 0x00, 0x04, 0x08, 0x0a, 0x0e, 0x12, 0x12 }, /* x.0 */
1461 { 0x01, 0x03, 0x01, 0x03, 0x09, 0x0b, 0x0f, 0x13 }}; /* x.1 */
1462 /* Mapping formats to HDMI channels order. */
1463 const static uint32_t hdmich[2][8] =
1464 {{ 0xFFFF0F00, 0xFFFFFF10, 0xFFF2FF10, 0xFF32FF10,
1465 0xFF324F10, 0xF5324F10, 0x54326F10, 0x54326F10 }, /* x.0 */
1466 { 0xFFFFF000, 0xFFFF0100, 0xFFFFF210, 0xFFFF2310,
1467 0xFF32F410, 0xFF324510, 0xF6324510, 0x76325410 }}; /* x.1 */
1472 totalchn = AFMT_CHANNEL(ch->fmt);
1473 totalextchn = AFMT_EXTCHANNEL(ch->fmt);
1475 device_printf(ch->pdevinfo->dev,
1476 "PCMDIR_%s: Stream setup fmt=%08x (%d.%d) speed=%d\n",
1477 (ch->dir == PCMDIR_PLAY) ? "PLAY" : "REC",
1478 ch->fmt, totalchn - totalextchn, totalextchn, ch->spd);
1480 fmt = hdaa_stream_format(ch);
1482 /* Set channels to I/O converters mapping for known speaker setups. */
1483 if ((as->pinset == 0x0007 || as->pinset == 0x0013)) /* Standard 5.1 */
1485 else if (as->pinset == 0x0017) /* Standard 7.1 */
1488 dfmt = HDA_CMD_SET_DIGITAL_CONV_FMT1_DIGEN;
1489 if (ch->fmt & AFMT_AC3)
1490 dfmt |= HDA_CMD_SET_DIGITAL_CONV_FMT1_NAUDIO;
1493 for (i = 0; ch->io[i] != -1; i++) {
1494 w = hdaa_widget_get(ch->devinfo, ch->io[i]);
1498 /* If HP redirection is enabled, but failed to use same
1499 DAC, make last DAC to duplicate first one. */
1500 if (as->fakeredir && i == (as->pincnt - 1)) {
1503 /* Map channels to I/O converters, if set. */
1505 chn = (((convmap[convmapid][totalchn / 2]
1506 >> i * 4) & 0xf) - 1) * 2;
1507 if (chn < 0 || chn >= totalchn) {
1510 c = (ch->sid << 4) | chn;
1513 hda_command(ch->devinfo->dev,
1514 HDA_CMD_SET_CONV_FMT(0, ch->io[i], fmt));
1515 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) {
1516 hda_command(ch->devinfo->dev,
1517 HDA_CMD_SET_DIGITAL_CONV_FMT1(0, ch->io[i], dfmt));
1519 hda_command(ch->devinfo->dev,
1520 HDA_CMD_SET_CONV_STREAM_CHAN(0, ch->io[i], c));
1521 if (HDA_PARAM_AUDIO_WIDGET_CAP_STRIPE(w->param.widget_cap)) {
1522 hda_command(ch->devinfo->dev,
1523 HDA_CMD_SET_STRIPE_CONTROL(0, w->nid, ch->stripectl));
1525 cchn = HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap);
1526 if (cchn > 1 && chn < totalchn) {
1527 cchn = min(cchn, totalchn - chn - 1);
1528 hda_command(ch->devinfo->dev,
1529 HDA_CMD_SET_CONV_CHAN_COUNT(0, ch->io[i], cchn));
1532 device_printf(ch->pdevinfo->dev,
1533 "PCMDIR_%s: Stream setup nid=%d: "
1534 "fmt=0x%04x, dfmt=0x%04x, chan=0x%04x, "
1535 "chan_count=0x%02x, stripe=%d\n",
1536 (ch->dir == PCMDIR_PLAY) ? "PLAY" : "REC",
1537 ch->io[i], fmt, dfmt, c, cchn, ch->stripectl);
1539 for (j = 0; j < 16; j++) {
1540 if (as->dacs[ch->asindex][j] != ch->io[i])
1543 wp = hdaa_widget_get(ch->devinfo, nid);
1546 if (!HDA_PARAM_PIN_CAP_DP(wp->wclass.pin.cap) &&
1547 !HDA_PARAM_PIN_CAP_HDMI(wp->wclass.pin.cap))
1550 /* Set channel mapping. */
1551 for (k = 0; k < 8; k++) {
1552 hda_command(ch->devinfo->dev,
1553 HDA_CMD_SET_HDMI_CHAN_SLOT(0, nid,
1554 (((hdmich[totalextchn == 0 ? 0 : 1][totalchn - 1]
1555 >> (k * 4)) & 0xf) << 4) | k));
1559 * Enable High Bit Rate (HBR) Encoded Packet Type
1560 * (EPT), if supported and needed (8ch data).
1562 if (HDA_PARAM_PIN_CAP_HDMI(wp->wclass.pin.cap) &&
1563 HDA_PARAM_PIN_CAP_HBR(wp->wclass.pin.cap)) {
1564 wp->wclass.pin.ctrl &=
1565 ~HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK;
1566 if ((ch->fmt & AFMT_AC3) && (cchn == 7))
1567 wp->wclass.pin.ctrl |= 0x03;
1568 hda_command(ch->devinfo->dev,
1569 HDA_CMD_SET_PIN_WIDGET_CTRL(0, nid,
1570 wp->wclass.pin.ctrl));
1573 /* Stop audio infoframe transmission. */
1574 hda_command(ch->devinfo->dev,
1575 HDA_CMD_SET_HDMI_DIP_INDEX(0, nid, 0x00));
1576 hda_command(ch->devinfo->dev,
1577 HDA_CMD_SET_HDMI_DIP_XMIT(0, nid, 0x00));
1579 /* Clear audio infoframe buffer. */
1580 hda_command(ch->devinfo->dev,
1581 HDA_CMD_SET_HDMI_DIP_INDEX(0, nid, 0x00));
1582 for (k = 0; k < 32; k++)
1583 hda_command(ch->devinfo->dev,
1584 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x00));
1586 /* Write HDMI/DisplayPort audio infoframe. */
1587 hda_command(ch->devinfo->dev,
1588 HDA_CMD_SET_HDMI_DIP_INDEX(0, nid, 0x00));
1589 if (w->eld != NULL && w->eld_len >= 6 &&
1590 ((w->eld[5] >> 2) & 0x3) == 1) { /* DisplayPort */
1591 hda_command(ch->devinfo->dev,
1592 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x84));
1593 hda_command(ch->devinfo->dev,
1594 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x1b));
1595 hda_command(ch->devinfo->dev,
1596 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x44));
1598 hda_command(ch->devinfo->dev,
1599 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x84));
1600 hda_command(ch->devinfo->dev,
1601 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x01));
1602 hda_command(ch->devinfo->dev,
1603 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x0a));
1605 csum -= 0x84 + 0x01 + 0x0a + (totalchn - 1) +
1606 hdmica[totalextchn == 0 ? 0 : 1][totalchn - 1];
1607 hda_command(ch->devinfo->dev,
1608 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, csum));
1610 hda_command(ch->devinfo->dev,
1611 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, totalchn - 1));
1612 hda_command(ch->devinfo->dev,
1613 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x00));
1614 hda_command(ch->devinfo->dev,
1615 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x00));
1616 hda_command(ch->devinfo->dev,
1617 HDA_CMD_SET_HDMI_DIP_DATA(0, nid,
1618 hdmica[totalextchn == 0 ? 0 : 1][totalchn - 1]));
1620 /* Start audio infoframe transmission. */
1621 hda_command(ch->devinfo->dev,
1622 HDA_CMD_SET_HDMI_DIP_INDEX(0, nid, 0x00));
1623 hda_command(ch->devinfo->dev,
1624 HDA_CMD_SET_HDMI_DIP_XMIT(0, nid, 0xc0));
1631 * Greatest Common Divisor.
1634 gcd(unsigned a, unsigned b)
1647 * Least Common Multiple.
1650 lcm(unsigned a, unsigned b)
1653 return ((a * b) / gcd(a, b));
1657 hdaa_channel_setfragments(kobj_t obj, void *data,
1658 uint32_t blksz, uint32_t blkcnt)
1660 struct hdaa_chan *ch = data;
1662 blksz -= blksz % lcm(HDA_DMA_ALIGNMENT, sndbuf_getalign(ch->b));
1664 if (blksz > (sndbuf_getmaxsize(ch->b) / HDA_BDL_MIN))
1665 blksz = sndbuf_getmaxsize(ch->b) / HDA_BDL_MIN;
1666 if (blksz < HDA_BLK_MIN)
1667 blksz = HDA_BLK_MIN;
1668 if (blkcnt > HDA_BDL_MAX)
1669 blkcnt = HDA_BDL_MAX;
1670 if (blkcnt < HDA_BDL_MIN)
1671 blkcnt = HDA_BDL_MIN;
1673 while ((blksz * blkcnt) > sndbuf_getmaxsize(ch->b)) {
1674 if ((blkcnt >> 1) >= HDA_BDL_MIN)
1676 else if ((blksz >> 1) >= HDA_BLK_MIN)
1682 if ((sndbuf_getblksz(ch->b) != blksz ||
1683 sndbuf_getblkcnt(ch->b) != blkcnt) &&
1684 sndbuf_resize(ch->b, blkcnt, blksz) != 0)
1685 device_printf(ch->devinfo->dev, "%s: failed blksz=%u blkcnt=%u\n",
1686 __func__, blksz, blkcnt);
1688 ch->blksz = sndbuf_getblksz(ch->b);
1689 ch->blkcnt = sndbuf_getblkcnt(ch->b);
1695 hdaa_channel_setblocksize(kobj_t obj, void *data, uint32_t blksz)
1697 struct hdaa_chan *ch = data;
1699 hdaa_channel_setfragments(obj, data, blksz, ch->pdevinfo->chan_blkcnt);
1705 hdaa_channel_stop(struct hdaa_chan *ch)
1707 struct hdaa_devinfo *devinfo = ch->devinfo;
1708 struct hdaa_widget *w;
1711 if ((ch->flags & HDAA_CHN_RUNNING) == 0)
1713 ch->flags &= ~HDAA_CHN_RUNNING;
1714 HDAC_STREAM_STOP(device_get_parent(devinfo->dev), devinfo->dev,
1715 ch->dir == PCMDIR_PLAY ? 1 : 0, ch->sid);
1716 for (i = 0; ch->io[i] != -1; i++) {
1717 w = hdaa_widget_get(ch->devinfo, ch->io[i]);
1720 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) {
1721 hda_command(devinfo->dev,
1722 HDA_CMD_SET_DIGITAL_CONV_FMT1(0, ch->io[i], 0));
1724 hda_command(devinfo->dev,
1725 HDA_CMD_SET_CONV_STREAM_CHAN(0, ch->io[i],
1728 HDAC_STREAM_FREE(device_get_parent(devinfo->dev), devinfo->dev,
1729 ch->dir == PCMDIR_PLAY ? 1 : 0, ch->sid);
1733 hdaa_channel_start(struct hdaa_chan *ch)
1735 struct hdaa_devinfo *devinfo = ch->devinfo;
1738 fmt = hdaa_stream_format(ch);
1739 ch->stripectl = fls(ch->stripecap & hdaa_allowed_stripes(fmt)) - 1;
1740 ch->sid = HDAC_STREAM_ALLOC(device_get_parent(devinfo->dev), devinfo->dev,
1741 ch->dir == PCMDIR_PLAY ? 1 : 0, fmt, ch->stripectl, &ch->dmapos);
1744 hdaa_audio_setup(ch);
1745 HDAC_STREAM_RESET(device_get_parent(devinfo->dev), devinfo->dev,
1746 ch->dir == PCMDIR_PLAY ? 1 : 0, ch->sid);
1747 HDAC_STREAM_START(device_get_parent(devinfo->dev), devinfo->dev,
1748 ch->dir == PCMDIR_PLAY ? 1 : 0, ch->sid,
1749 sndbuf_getbufaddr(ch->b), ch->blksz, ch->blkcnt);
1750 ch->flags |= HDAA_CHN_RUNNING;
1755 hdaa_channel_trigger(kobj_t obj, void *data, int go)
1757 struct hdaa_chan *ch = data;
1760 if (!PCMTRIG_COMMON(go))
1763 hdaa_lock(ch->devinfo);
1766 error = hdaa_channel_start(ch);
1770 hdaa_channel_stop(ch);
1775 hdaa_unlock(ch->devinfo);
1781 hdaa_channel_getptr(kobj_t obj, void *data)
1783 struct hdaa_chan *ch = data;
1784 struct hdaa_devinfo *devinfo = ch->devinfo;
1788 if (ch->dmapos != NULL) {
1789 ptr = *(ch->dmapos);
1791 ptr = HDAC_STREAM_GETPTR(
1792 device_get_parent(devinfo->dev), devinfo->dev,
1793 ch->dir == PCMDIR_PLAY ? 1 : 0, ch->sid);
1795 hdaa_unlock(devinfo);
1798 * Round to available space and force 128 bytes aligment.
1800 ptr %= ch->blksz * ch->blkcnt;
1801 ptr &= HDA_BLK_ALIGN;
1806 static struct pcmchan_caps *
1807 hdaa_channel_getcaps(kobj_t obj, void *data)
1809 return (&((struct hdaa_chan *)data)->caps);
1812 static kobj_method_t hdaa_channel_methods[] = {
1813 KOBJMETHOD(channel_init, hdaa_channel_init),
1814 KOBJMETHOD(channel_setformat, hdaa_channel_setformat),
1815 KOBJMETHOD(channel_setspeed, hdaa_channel_setspeed),
1816 KOBJMETHOD(channel_setblocksize, hdaa_channel_setblocksize),
1817 KOBJMETHOD(channel_setfragments, hdaa_channel_setfragments),
1818 KOBJMETHOD(channel_trigger, hdaa_channel_trigger),
1819 KOBJMETHOD(channel_getptr, hdaa_channel_getptr),
1820 KOBJMETHOD(channel_getcaps, hdaa_channel_getcaps),
1823 CHANNEL_DECLARE(hdaa_channel);
1826 hdaa_audio_ctl_ossmixer_init(struct snd_mixer *m)
1828 struct hdaa_pcm_devinfo *pdevinfo = mix_getdevinfo(m);
1829 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
1830 struct hdaa_widget *w, *cw;
1831 uint32_t mask, recmask;
1835 pdevinfo->mixer = m;
1837 /* Make sure that in case of soft volume it won't stay muted. */
1838 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
1839 pdevinfo->left[i] = 100;
1840 pdevinfo->right[i] = 100;
1843 /* Declare volume controls assigned to this association. */
1844 mask = pdevinfo->ossmask;
1845 if (pdevinfo->playas >= 0) {
1846 /* Declate EAPD as ogain control. */
1847 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
1848 w = hdaa_widget_get(devinfo, i);
1849 if (w == NULL || w->enable == 0)
1851 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX ||
1852 w->param.eapdbtl == HDA_INVALID ||
1853 w->bindas != pdevinfo->playas)
1855 mask |= SOUND_MASK_OGAIN;
1859 /* Declare soft PCM volume if needed. */
1860 if ((mask & SOUND_MASK_PCM) == 0 ||
1861 (devinfo->quirks & HDAA_QUIRK_SOFTPCMVOL) ||
1862 pdevinfo->minamp[SOUND_MIXER_PCM] ==
1863 pdevinfo->maxamp[SOUND_MIXER_PCM]) {
1864 mask |= SOUND_MASK_PCM;
1865 pcm_setflags(pdevinfo->dev, pcm_getflags(pdevinfo->dev) | SD_F_SOFTPCMVOL);
1867 device_printf(pdevinfo->dev,
1868 "Forcing Soft PCM volume\n");
1872 /* Declare master volume if needed. */
1873 if ((mask & SOUND_MASK_VOLUME) == 0) {
1874 mask |= SOUND_MASK_VOLUME;
1875 mix_setparentchild(m, SOUND_MIXER_VOLUME,
1877 mix_setrealdev(m, SOUND_MIXER_VOLUME,
1880 device_printf(pdevinfo->dev,
1881 "Forcing master volume with PCM\n");
1886 /* Declare record sources available to this association. */
1888 if (pdevinfo->recas >= 0) {
1889 for (i = 0; i < 16; i++) {
1890 if (devinfo->as[pdevinfo->recas].dacs[0][i] < 0)
1892 w = hdaa_widget_get(devinfo,
1893 devinfo->as[pdevinfo->recas].dacs[0][i]);
1894 if (w == NULL || w->enable == 0)
1896 for (j = 0; j < w->nconns; j++) {
1897 if (w->connsenable[j] == 0)
1899 cw = hdaa_widget_get(devinfo, w->conns[j]);
1900 if (cw == NULL || cw->enable == 0)
1902 if (cw->bindas != pdevinfo->recas &&
1905 recmask |= cw->ossmask;
1910 recmask &= (1 << SOUND_MIXER_NRDEVICES) - 1;
1911 mask &= (1 << SOUND_MIXER_NRDEVICES) - 1;
1912 pdevinfo->ossmask = mask;
1914 mix_setrecdevs(m, recmask);
1915 mix_setdevs(m, mask);
1917 hdaa_unlock(devinfo);
1923 * Update amplification per pdevinfo per ossdev, calculate summary coefficient
1924 * and write it to codec, update *left and *right to reflect remaining error.
1927 hdaa_audio_ctl_dev_set(struct hdaa_audio_ctl *ctl, int ossdev,
1928 int mute, int *left, int *right)
1930 int i, zleft, zright, sleft, sright, smute, lval, rval;
1932 ctl->devleft[ossdev] = *left;
1933 ctl->devright[ossdev] = *right;
1934 ctl->devmute[ossdev] = mute;
1935 smute = sleft = sright = zleft = zright = 0;
1936 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
1937 sleft += ctl->devleft[i];
1938 sright += ctl->devright[i];
1939 smute |= ctl->devmute[i];
1942 zleft += ctl->devleft[i];
1943 zright += ctl->devright[i];
1945 lval = QDB2VAL(ctl, sleft);
1946 rval = QDB2VAL(ctl, sright);
1947 hdaa_audio_ctl_amp_set(ctl, smute, lval, rval);
1948 *left -= VAL2QDB(ctl, lval) - VAL2QDB(ctl, QDB2VAL(ctl, zleft));
1949 *right -= VAL2QDB(ctl, rval) - VAL2QDB(ctl, QDB2VAL(ctl, zright));
1953 * Trace signal from source, setting volumes on the way.
1956 hdaa_audio_ctl_source_volume(struct hdaa_pcm_devinfo *pdevinfo,
1957 int ossdev, nid_t nid, int index, int mute, int left, int right, int depth)
1959 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
1960 struct hdaa_widget *w, *wc;
1961 struct hdaa_audio_ctl *ctl;
1962 int i, j, conns = 0;
1964 if (depth > HDA_PARSE_MAXDEPTH)
1967 w = hdaa_widget_get(devinfo, nid);
1968 if (w == NULL || w->enable == 0)
1971 /* Count number of active inputs. */
1973 for (j = 0; j < w->nconns; j++) {
1974 if (!w->connsenable[j])
1980 /* If this is not a first step - use input mixer.
1981 Pins have common input ctl so care must be taken. */
1982 if (depth > 0 && (conns == 1 ||
1983 w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)) {
1984 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, HDAA_CTL_IN,
1987 hdaa_audio_ctl_dev_set(ctl, ossdev, mute, &left, &right);
1990 /* If widget has own ossdev - not traverse it.
1991 It will be traversed on it's own. */
1992 if (w->ossdev >= 0 && depth > 0)
1995 /* We must not traverse pin */
1996 if ((w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT ||
1997 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) &&
2002 * If signals mixed, we can't assign controls farther.
2003 * Ignore this on depth zero. Caller must knows why.
2006 (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER ||
2007 w->selconn != index))
2010 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, HDAA_CTL_OUT, -1, 1);
2012 hdaa_audio_ctl_dev_set(ctl, ossdev, mute, &left, &right);
2014 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2015 wc = hdaa_widget_get(devinfo, i);
2016 if (wc == NULL || wc->enable == 0)
2018 for (j = 0; j < wc->nconns; j++) {
2019 if (wc->connsenable[j] && wc->conns[j] == nid) {
2020 hdaa_audio_ctl_source_volume(pdevinfo, ossdev,
2021 wc->nid, j, mute, left, right, depth + 1);
2029 * Trace signal from destination, setting volumes on the way.
2032 hdaa_audio_ctl_dest_volume(struct hdaa_pcm_devinfo *pdevinfo,
2033 int ossdev, nid_t nid, int index, int mute, int left, int right, int depth)
2035 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
2036 struct hdaa_audio_as *as = devinfo->as;
2037 struct hdaa_widget *w, *wc;
2038 struct hdaa_audio_ctl *ctl;
2039 int i, j, consumers, cleft, cright;
2041 if (depth > HDA_PARSE_MAXDEPTH)
2044 w = hdaa_widget_get(devinfo, nid);
2045 if (w == NULL || w->enable == 0)
2049 /* If this node produce output for several consumers,
2050 we can't touch it. */
2052 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2053 wc = hdaa_widget_get(devinfo, i);
2054 if (wc == NULL || wc->enable == 0)
2056 for (j = 0; j < wc->nconns; j++) {
2057 if (wc->connsenable[j] && wc->conns[j] == nid)
2061 /* The only exception is if real HP redirection is configured
2062 and this is a duplication point.
2063 XXX: Actually exception is not completely correct.
2064 XXX: Duplication point check is not perfect. */
2065 if ((consumers == 2 && (w->bindas < 0 ||
2066 as[w->bindas].hpredir < 0 || as[w->bindas].fakeredir ||
2067 (w->bindseqmask & (1 << 15)) == 0)) ||
2071 /* Else use it's output mixer. */
2072 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid,
2073 HDAA_CTL_OUT, -1, 1);
2075 hdaa_audio_ctl_dev_set(ctl, ossdev, mute, &left, &right);
2078 /* We must not traverse pin */
2079 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
2083 for (i = 0; i < w->nconns; i++) {
2084 if (w->connsenable[i] == 0)
2086 if (index >= 0 && i != index)
2090 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid,
2093 hdaa_audio_ctl_dev_set(ctl, ossdev, mute, &cleft, &cright);
2094 hdaa_audio_ctl_dest_volume(pdevinfo, ossdev, w->conns[i], -1,
2095 mute, cleft, cright, depth + 1);
2100 * Set volumes for the specified pdevinfo and ossdev.
2103 hdaa_audio_ctl_dev_volume(struct hdaa_pcm_devinfo *pdevinfo, unsigned dev)
2105 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
2106 struct hdaa_widget *w, *cw;
2112 if (pdevinfo->left[dev] == 0) {
2113 mute |= HDAA_AMP_MUTE_LEFT;
2116 lvol = ((pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]) *
2117 pdevinfo->left[dev] + 50) / 100 + pdevinfo->minamp[dev];
2118 if (pdevinfo->right[dev] == 0) {
2119 mute |= HDAA_AMP_MUTE_RIGHT;
2122 rvol = ((pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]) *
2123 pdevinfo->right[dev] + 50) / 100 + pdevinfo->minamp[dev];
2124 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2125 w = hdaa_widget_get(devinfo, i);
2126 if (w == NULL || w->enable == 0)
2128 if (w->bindas < 0) {
2129 if (pdevinfo->index != 0)
2132 if (w->bindas != pdevinfo->playas &&
2133 w->bindas != pdevinfo->recas)
2136 if (dev == SOUND_MIXER_RECLEV &&
2137 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
2138 hdaa_audio_ctl_dest_volume(pdevinfo, dev,
2139 w->nid, -1, mute, lvol, rvol, 0);
2142 if (dev == SOUND_MIXER_VOLUME &&
2143 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
2144 devinfo->as[w->bindas].dir == HDAA_CTL_OUT) {
2145 hdaa_audio_ctl_dest_volume(pdevinfo, dev,
2146 w->nid, -1, mute, lvol, rvol, 0);
2149 if (dev == SOUND_MIXER_IGAIN &&
2150 w->pflags & HDAA_ADC_MONITOR) {
2151 for (j = 0; j < w->nconns; j++) {
2152 if (!w->connsenable[j])
2154 cw = hdaa_widget_get(devinfo, w->conns[j]);
2155 if (cw == NULL || cw->enable == 0)
2157 if (cw->bindas == -1)
2159 if (cw->bindas >= 0 &&
2160 devinfo->as[cw->bindas].dir != HDAA_CTL_IN)
2162 hdaa_audio_ctl_dest_volume(pdevinfo, dev,
2163 w->nid, j, mute, lvol, rvol, 0);
2167 if (w->ossdev != dev)
2169 hdaa_audio_ctl_source_volume(pdevinfo, dev,
2170 w->nid, -1, mute, lvol, rvol, 0);
2171 if (dev == SOUND_MIXER_IMIX && (w->pflags & HDAA_IMIX_AS_DST))
2172 hdaa_audio_ctl_dest_volume(pdevinfo, dev,
2173 w->nid, -1, mute, lvol, rvol, 0);
2178 * OSS Mixer set method.
2181 hdaa_audio_ctl_ossmixer_set(struct snd_mixer *m, unsigned dev,
2182 unsigned left, unsigned right)
2184 struct hdaa_pcm_devinfo *pdevinfo = mix_getdevinfo(m);
2185 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
2186 struct hdaa_widget *w;
2191 /* Save new values. */
2192 pdevinfo->left[dev] = left;
2193 pdevinfo->right[dev] = right;
2195 /* 'ogain' is the special case implemented with EAPD. */
2196 if (dev == SOUND_MIXER_OGAIN) {
2199 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2200 w = hdaa_widget_get(devinfo, i);
2201 if (w == NULL || w->enable == 0)
2203 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX ||
2204 w->param.eapdbtl == HDA_INVALID)
2208 if (i >= devinfo->endnode) {
2209 hdaa_unlock(devinfo);
2212 orig = w->param.eapdbtl;
2214 w->param.eapdbtl &= ~HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
2216 w->param.eapdbtl |= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
2217 if (orig != w->param.eapdbtl) {
2220 val = w->param.eapdbtl;
2221 if (devinfo->quirks & HDAA_QUIRK_EAPDINV)
2222 val ^= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
2223 hda_command(devinfo->dev,
2224 HDA_CMD_SET_EAPD_BTL_ENABLE(0, w->nid, val));
2226 hdaa_unlock(devinfo);
2227 return (left | (left << 8));
2230 /* Recalculate all controls related to this OSS device. */
2231 hdaa_audio_ctl_dev_volume(pdevinfo, dev);
2233 hdaa_unlock(devinfo);
2234 return (left | (right << 8));
2238 * Set mixer settings to our own default values:
2239 * +20dB for mics, -10dB for analog vol, mute for igain, 0dB for others.
2242 hdaa_audio_ctl_set_defaults(struct hdaa_pcm_devinfo *pdevinfo)
2246 for (dev = 0; dev < SOUND_MIXER_NRDEVICES; dev++) {
2247 if ((pdevinfo->ossmask & (1 << dev)) == 0)
2250 /* If the value was overriden, leave it as is. */
2251 if (resource_int_value(device_get_name(pdevinfo->dev),
2252 device_get_unit(pdevinfo->dev), ossnames[dev], &vol) == 0)
2256 if (dev == SOUND_MIXER_OGAIN)
2258 else if (dev == SOUND_MIXER_IGAIN)
2260 else if (dev == SOUND_MIXER_MIC ||
2261 dev == SOUND_MIXER_MONITOR)
2262 amp = 20 * 4; /* +20dB */
2263 else if (dev == SOUND_MIXER_VOLUME && !pdevinfo->digital)
2264 amp = -10 * 4; /* -10dB */
2268 (pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]) <= 0) {
2270 } else if (vol < 0) {
2271 vol = ((amp - pdevinfo->minamp[dev]) * 100 +
2272 (pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]) / 2) /
2273 (pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]);
2274 vol = imin(imax(vol, 1), 100);
2276 mix_set(pdevinfo->mixer, dev, vol, vol);
2281 * Recursively commutate specified record source.
2284 hdaa_audio_ctl_recsel_comm(struct hdaa_pcm_devinfo *pdevinfo, uint32_t src, nid_t nid, int depth)
2286 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
2287 struct hdaa_widget *w, *cw;
2288 struct hdaa_audio_ctl *ctl;
2293 if (depth > HDA_PARSE_MAXDEPTH)
2296 w = hdaa_widget_get(devinfo, nid);
2297 if (w == NULL || w->enable == 0)
2300 for (i = 0; i < w->nconns; i++) {
2301 if (w->connsenable[i] == 0)
2303 cw = hdaa_widget_get(devinfo, w->conns[i]);
2304 if (cw == NULL || cw->enable == 0 || cw->bindas == -1)
2306 /* Call recursively to trace signal to it's source if needed. */
2307 if ((src & cw->ossmask) != 0) {
2308 if (cw->ossdev < 0) {
2309 res |= hdaa_audio_ctl_recsel_comm(pdevinfo, src,
2310 w->conns[i], depth + 1);
2315 /* We have two special cases: mixers and others (selectors). */
2316 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) {
2317 ctl = hdaa_audio_ctl_amp_get(devinfo,
2318 w->nid, HDAA_CTL_IN, i, 1);
2321 /* If we have input control on this node mute them
2322 * according to requested sources. */
2323 muted = (src & cw->ossmask) ? 0 : 1;
2324 if (muted != ctl->forcemute) {
2325 ctl->forcemute = muted;
2326 hdaa_audio_ctl_amp_set(ctl,
2327 HDAA_AMP_MUTE_DEFAULT,
2328 HDAA_AMP_VOL_DEFAULT, HDAA_AMP_VOL_DEFAULT);
2331 device_printf(pdevinfo->dev,
2332 "Recsel (%s): nid %d source %d %s\n",
2333 hdaa_audio_ctl_ossmixer_mask2allname(
2334 src, buf, sizeof(buf)),
2335 nid, i, muted?"mute":"unmute");
2340 if ((src & cw->ossmask) == 0)
2342 /* If we found requested source - select it and exit. */
2343 hdaa_widget_connection_select(w, i);
2345 device_printf(pdevinfo->dev,
2346 "Recsel (%s): nid %d source %d select\n",
2347 hdaa_audio_ctl_ossmixer_mask2allname(
2348 src, buf, sizeof(buf)),
2358 hdaa_audio_ctl_ossmixer_setrecsrc(struct snd_mixer *m, uint32_t src)
2360 struct hdaa_pcm_devinfo *pdevinfo = mix_getdevinfo(m);
2361 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
2362 struct hdaa_widget *w;
2363 struct hdaa_audio_as *as;
2364 struct hdaa_audio_ctl *ctl;
2365 struct hdaa_chan *ch;
2367 uint32_t ret = 0xffffffff;
2370 if (pdevinfo->recas < 0) {
2371 hdaa_unlock(devinfo);
2374 as = &devinfo->as[pdevinfo->recas];
2376 /* For non-mixed associations we always recording everything. */
2378 hdaa_unlock(devinfo);
2379 return (mix_getrecdevs(m));
2382 /* Commutate requested recsrc for each ADC. */
2383 for (j = 0; j < as->num_chans; j++) {
2384 ch = &devinfo->chans[as->chans[j]];
2385 for (i = 0; ch->io[i] >= 0; i++) {
2386 w = hdaa_widget_get(devinfo, ch->io[i]);
2387 if (w == NULL || w->enable == 0)
2389 ret &= hdaa_audio_ctl_recsel_comm(pdevinfo, src,
2393 if (ret == 0xffffffff)
2397 * Some controls could be shared. Reset volumes for controls
2398 * related to previously chosen devices, as they may no longer
2399 * affect the signal.
2402 while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) {
2403 if (ctl->enable == 0 ||
2404 !(ctl->ossmask & pdevinfo->recsrc))
2406 if (!((pdevinfo->playas >= 0 &&
2407 ctl->widget->bindas == pdevinfo->playas) ||
2408 (pdevinfo->recas >= 0 &&
2409 ctl->widget->bindas == pdevinfo->recas) ||
2410 (pdevinfo->index == 0 &&
2411 ctl->widget->bindas == -2)))
2413 for (j = 0; j < SOUND_MIXER_NRDEVICES; j++) {
2414 if (pdevinfo->recsrc & (1 << j)) {
2415 ctl->devleft[j] = 0;
2416 ctl->devright[j] = 0;
2417 ctl->devmute[j] = 0;
2423 * Some controls could be shared. Set volumes for controls
2424 * related to devices selected both previously and now.
2426 for (j = 0; j < SOUND_MIXER_NRDEVICES; j++) {
2427 if ((ret | pdevinfo->recsrc) & (1 << j))
2428 hdaa_audio_ctl_dev_volume(pdevinfo, j);
2431 pdevinfo->recsrc = ret;
2432 hdaa_unlock(devinfo);
2436 static kobj_method_t hdaa_audio_ctl_ossmixer_methods[] = {
2437 KOBJMETHOD(mixer_init, hdaa_audio_ctl_ossmixer_init),
2438 KOBJMETHOD(mixer_set, hdaa_audio_ctl_ossmixer_set),
2439 KOBJMETHOD(mixer_setrecsrc, hdaa_audio_ctl_ossmixer_setrecsrc),
2442 MIXER_DECLARE(hdaa_audio_ctl_ossmixer);
2445 hdaa_dump_gpi(struct hdaa_devinfo *devinfo)
2447 device_t dev = devinfo->dev;
2449 uint32_t data, wake, unsol, sticky;
2451 if (HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap) > 0) {
2452 data = hda_command(dev,
2453 HDA_CMD_GET_GPI_DATA(0, devinfo->nid));
2454 wake = hda_command(dev,
2455 HDA_CMD_GET_GPI_WAKE_ENABLE_MASK(0, devinfo->nid));
2456 unsol = hda_command(dev,
2457 HDA_CMD_GET_GPI_UNSOLICITED_ENABLE_MASK(0, devinfo->nid));
2458 sticky = hda_command(dev,
2459 HDA_CMD_GET_GPI_STICKY_MASK(0, devinfo->nid));
2460 for (i = 0; i < HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap); i++) {
2461 device_printf(dev, " GPI%d:%s%s%s state=%d", i,
2462 (sticky & (1 << i)) ? " sticky" : "",
2463 (unsol & (1 << i)) ? " unsol" : "",
2464 (wake & (1 << i)) ? " wake" : "",
2471 hdaa_dump_gpio(struct hdaa_devinfo *devinfo)
2473 device_t dev = devinfo->dev;
2475 uint32_t data, dir, enable, wake, unsol, sticky;
2477 if (HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap) > 0) {
2478 data = hda_command(dev,
2479 HDA_CMD_GET_GPIO_DATA(0, devinfo->nid));
2480 enable = hda_command(dev,
2481 HDA_CMD_GET_GPIO_ENABLE_MASK(0, devinfo->nid));
2482 dir = hda_command(dev,
2483 HDA_CMD_GET_GPIO_DIRECTION(0, devinfo->nid));
2484 wake = hda_command(dev,
2485 HDA_CMD_GET_GPIO_WAKE_ENABLE_MASK(0, devinfo->nid));
2486 unsol = hda_command(dev,
2487 HDA_CMD_GET_GPIO_UNSOLICITED_ENABLE_MASK(0, devinfo->nid));
2488 sticky = hda_command(dev,
2489 HDA_CMD_GET_GPIO_STICKY_MASK(0, devinfo->nid));
2490 for (i = 0; i < HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap); i++) {
2491 device_printf(dev, " GPIO%d: ", i);
2492 if ((enable & (1 << i)) == 0) {
2493 printf("disabled\n");
2496 if ((dir & (1 << i)) == 0) {
2497 printf("input%s%s%s",
2498 (sticky & (1 << i)) ? " sticky" : "",
2499 (unsol & (1 << i)) ? " unsol" : "",
2500 (wake & (1 << i)) ? " wake" : "");
2503 printf(" state=%d\n", (data >> i) & 1);
2509 hdaa_dump_gpo(struct hdaa_devinfo *devinfo)
2511 device_t dev = devinfo->dev;
2515 if (HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap) > 0) {
2516 data = hda_command(dev,
2517 HDA_CMD_GET_GPO_DATA(0, devinfo->nid));
2518 for (i = 0; i < HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap); i++) {
2519 device_printf(dev, " GPO%d: state=%d", i,
2526 hdaa_audio_parse(struct hdaa_devinfo *devinfo)
2528 struct hdaa_widget *w;
2535 res = hda_command(devinfo->dev,
2536 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_GPIO_COUNT));
2537 devinfo->gpio_cap = res;
2540 device_printf(devinfo->dev,
2541 "NumGPIO=%d NumGPO=%d "
2542 "NumGPI=%d GPIWake=%d GPIUnsol=%d\n",
2543 HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap),
2544 HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap),
2545 HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap),
2546 HDA_PARAM_GPIO_COUNT_GPI_WAKE(devinfo->gpio_cap),
2547 HDA_PARAM_GPIO_COUNT_GPI_UNSOL(devinfo->gpio_cap));
2548 hdaa_dump_gpi(devinfo);
2549 hdaa_dump_gpio(devinfo);
2550 hdaa_dump_gpo(devinfo);
2553 res = hda_command(devinfo->dev,
2554 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_SUPP_STREAM_FORMATS));
2555 devinfo->supp_stream_formats = res;
2557 res = hda_command(devinfo->dev,
2558 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_SUPP_PCM_SIZE_RATE));
2559 devinfo->supp_pcm_size_rate = res;
2561 res = hda_command(devinfo->dev,
2562 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_OUTPUT_AMP_CAP));
2563 devinfo->outamp_cap = res;
2565 res = hda_command(devinfo->dev,
2566 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_INPUT_AMP_CAP));
2567 devinfo->inamp_cap = res;
2569 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2570 w = hdaa_widget_get(devinfo, i);
2572 device_printf(devinfo->dev, "Ghost widget! nid=%d!\n", i);
2574 w->devinfo = devinfo;
2581 w->param.eapdbtl = HDA_INVALID;
2582 hdaa_widget_parse(w);
2588 hdaa_audio_postprocess(struct hdaa_devinfo *devinfo)
2590 struct hdaa_widget *w;
2593 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2594 w = hdaa_widget_get(devinfo, i);
2597 hdaa_widget_postprocess(w);
2602 hdaa_audio_ctl_parse(struct hdaa_devinfo *devinfo)
2604 struct hdaa_audio_ctl *ctls;
2605 struct hdaa_widget *w, *cw;
2606 int i, j, cnt, max, ocap, icap;
2607 int mute, offset, step, size;
2609 /* XXX This is redundant */
2611 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2612 w = hdaa_widget_get(devinfo, i);
2613 if (w == NULL || w->enable == 0)
2615 if (w->param.outamp_cap != 0)
2617 if (w->param.inamp_cap != 0) {
2619 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR:
2620 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER:
2621 for (j = 0; j < w->nconns; j++) {
2622 cw = hdaa_widget_get(devinfo,
2624 if (cw == NULL || cw->enable == 0)
2635 devinfo->ctlcnt = max;
2640 ctls = (struct hdaa_audio_ctl *)malloc(
2641 sizeof(*ctls) * max, M_HDAA, M_ZERO | M_NOWAIT);
2645 device_printf(devinfo->dev, "unable to allocate ctls!\n");
2646 devinfo->ctlcnt = 0;
2651 for (i = devinfo->startnode; cnt < max && i < devinfo->endnode; i++) {
2653 device_printf(devinfo->dev, "%s: Ctl overflow!\n",
2657 w = hdaa_widget_get(devinfo, i);
2658 if (w == NULL || w->enable == 0)
2660 ocap = w->param.outamp_cap;
2661 icap = w->param.inamp_cap;
2663 mute = HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(ocap);
2664 step = HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(ocap);
2665 size = HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(ocap);
2666 offset = HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(ocap);
2667 /*if (offset > step) {
2669 device_printf(devinfo->dev,
2670 "BUGGY outamp: nid=%d "
2671 "[offset=%d > step=%d]\n",
2672 w->nid, offset, step);
2676 ctls[cnt].enable = 1;
2677 ctls[cnt].widget = w;
2678 ctls[cnt].mute = mute;
2679 ctls[cnt].step = step;
2680 ctls[cnt].size = size;
2681 ctls[cnt].offset = offset;
2682 ctls[cnt].left = offset;
2683 ctls[cnt].right = offset;
2684 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX ||
2686 ctls[cnt].ndir = HDAA_CTL_IN;
2688 ctls[cnt].ndir = HDAA_CTL_OUT;
2689 ctls[cnt++].dir = HDAA_CTL_OUT;
2693 mute = HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(icap);
2694 step = HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(icap);
2695 size = HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(icap);
2696 offset = HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(icap);
2697 /*if (offset > step) {
2699 device_printf(devinfo->dev,
2700 "BUGGY inamp: nid=%d "
2701 "[offset=%d > step=%d]\n",
2702 w->nid, offset, step);
2707 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR:
2708 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER:
2709 for (j = 0; j < w->nconns; j++) {
2711 device_printf(devinfo->dev,
2712 "%s: Ctl overflow!\n",
2716 cw = hdaa_widget_get(devinfo,
2718 if (cw == NULL || cw->enable == 0)
2720 ctls[cnt].enable = 1;
2721 ctls[cnt].widget = w;
2722 ctls[cnt].childwidget = cw;
2723 ctls[cnt].index = j;
2724 ctls[cnt].mute = mute;
2725 ctls[cnt].step = step;
2726 ctls[cnt].size = size;
2727 ctls[cnt].offset = offset;
2728 ctls[cnt].left = offset;
2729 ctls[cnt].right = offset;
2730 ctls[cnt].ndir = HDAA_CTL_IN;
2731 ctls[cnt++].dir = HDAA_CTL_IN;
2736 device_printf(devinfo->dev,
2737 "%s: Ctl overflow!\n",
2741 ctls[cnt].enable = 1;
2742 ctls[cnt].widget = w;
2743 ctls[cnt].mute = mute;
2744 ctls[cnt].step = step;
2745 ctls[cnt].size = size;
2746 ctls[cnt].offset = offset;
2747 ctls[cnt].left = offset;
2748 ctls[cnt].right = offset;
2750 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
2751 ctls[cnt].ndir = HDAA_CTL_OUT;
2753 ctls[cnt].ndir = HDAA_CTL_IN;
2754 ctls[cnt++].dir = HDAA_CTL_IN;
2760 devinfo->ctl = ctls;
2764 hdaa_audio_as_parse(struct hdaa_devinfo *devinfo)
2766 struct hdaa_audio_as *as;
2767 struct hdaa_widget *w;
2768 int i, j, cnt, max, type, dir, assoc, seq, first, hpredir;
2770 /* Count present associations */
2772 for (j = 1; j < 16; j++) {
2773 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2774 w = hdaa_widget_get(devinfo, i);
2775 if (w == NULL || w->enable == 0)
2777 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
2779 if (HDA_CONFIG_DEFAULTCONF_ASSOCIATION(w->wclass.pin.config)
2783 if (j != 15) /* There could be many 1-pin assocs #15 */
2788 devinfo->ascnt = max;
2793 as = (struct hdaa_audio_as *)malloc(
2794 sizeof(*as) * max, M_HDAA, M_ZERO | M_NOWAIT);
2798 device_printf(devinfo->dev, "unable to allocate assocs!\n");
2803 for (i = 0; i < max; i++) {
2806 as[i].num_chans = 1;
2807 as[i].location = -1;
2810 /* Scan associations skipping as=0. */
2812 for (j = 1; j < 16; j++) {
2815 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2816 w = hdaa_widget_get(devinfo, i);
2817 if (w == NULL || w->enable == 0)
2819 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
2821 assoc = HDA_CONFIG_DEFAULTCONF_ASSOCIATION(w->wclass.pin.config);
2822 seq = HDA_CONFIG_DEFAULTCONF_SEQUENCE(w->wclass.pin.config);
2827 ("%s: Associations owerflow (%d of %d)",
2828 __func__, cnt, max));
2829 type = w->wclass.pin.config &
2830 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
2831 /* Get pin direction. */
2832 if (type == HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_OUT ||
2833 type == HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER ||
2834 type == HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT ||
2835 type == HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_OUT ||
2836 type == HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_OUT)
2840 /* If this is a first pin - create new association. */
2841 if (as[cnt].pincnt == 0) {
2848 /* Check association correctness. */
2849 if (as[cnt].pins[seq] != 0) {
2850 device_printf(devinfo->dev, "%s: Duplicate pin %d (%d) "
2851 "in association %d! Disabling association.\n",
2852 __func__, seq, w->nid, j);
2855 if (dir != as[cnt].dir) {
2856 device_printf(devinfo->dev, "%s: Pin %d has wrong "
2857 "direction for association %d! Disabling "
2859 __func__, w->nid, j);
2862 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) {
2863 as[cnt].digital |= 0x1;
2864 if (HDA_PARAM_PIN_CAP_HDMI(w->wclass.pin.cap))
2865 as[cnt].digital |= 0x2;
2866 if (HDA_PARAM_PIN_CAP_DP(w->wclass.pin.cap))
2867 as[cnt].digital |= 0x4;
2869 if (as[cnt].location == -1) {
2871 HDA_CONFIG_DEFAULTCONF_LOCATION(w->wclass.pin.config);
2872 } else if (as[cnt].location !=
2873 HDA_CONFIG_DEFAULTCONF_LOCATION(w->wclass.pin.config)) {
2874 as[cnt].location = -2;
2876 /* Headphones with seq=15 may mean redirection. */
2877 if (type == HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT &&
2880 as[cnt].pins[seq] = w->nid;
2882 /* Association 15 is a multiple unassociated pins. */
2886 if (j != 15 && as[cnt].pincnt > 0) {
2887 if (hpredir && as[cnt].pincnt > 1)
2888 as[cnt].hpredir = first;
2892 for (i = 0; i < max; i++) {
2893 if (as[i].dir == HDAA_CTL_IN && (as[i].pincnt == 1 ||
2894 as[i].pins[14] > 0 || as[i].pins[15] > 0))
2898 device_printf(devinfo->dev,
2899 "%d associations found:\n", max);
2900 for (i = 0; i < max; i++) {
2901 device_printf(devinfo->dev,
2902 "Association %d (%d) %s%s:\n",
2903 i, as[i].index, (as[i].dir == HDAA_CTL_IN)?"in":"out",
2904 as[i].enable?"":" (disabled)");
2905 for (j = 0; j < 16; j++) {
2906 if (as[i].pins[j] == 0)
2908 device_printf(devinfo->dev,
2909 " Pin nid=%d seq=%d\n",
2919 * Trace path from DAC to pin.
2922 hdaa_audio_trace_dac(struct hdaa_devinfo *devinfo, int as, int seq, nid_t nid,
2923 int dupseq, int min, int only, int depth)
2925 struct hdaa_widget *w;
2929 if (depth > HDA_PARSE_MAXDEPTH)
2931 w = hdaa_widget_get(devinfo, nid);
2932 if (w == NULL || w->enable == 0)
2936 device_printf(devinfo->dev,
2937 " %*stracing via nid %d\n",
2938 depth + 1, "", w->nid);
2941 /* Use only unused widgets */
2942 if (w->bindas >= 0 && w->bindas != as) {
2945 device_printf(devinfo->dev,
2946 " %*snid %d busy by association %d\n",
2947 depth + 1, "", w->nid, w->bindas);
2953 if (w->bindseqmask != 0) {
2956 device_printf(devinfo->dev,
2957 " %*snid %d busy by seqmask %x\n",
2958 depth + 1, "", w->nid, w->bindseqmask);
2964 /* If this is headphones - allow duplicate first pin. */
2965 if (w->bindseqmask != 0 &&
2966 (w->bindseqmask & (1 << dupseq)) == 0) {
2968 device_printf(devinfo->dev,
2969 " %*snid %d busy by seqmask %x\n",
2970 depth + 1, "", w->nid, w->bindseqmask);
2977 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT:
2978 /* Do not traverse input. AD1988 has digital monitor
2979 for which we are not ready. */
2981 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT:
2982 /* If we are tracing HP take only dac of first pin. */
2983 if ((only == 0 || only == w->nid) &&
2984 (w->nid >= min) && (dupseq < 0 || w->nid ==
2985 devinfo->as[as].dacs[0][dupseq]))
2988 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
2993 /* Find reachable DACs with smallest nid respecting constraints. */
2994 for (i = 0; i < w->nconns; i++) {
2995 if (w->connsenable[i] == 0)
2997 if (w->selconn != -1 && w->selconn != i)
2999 if ((ret = hdaa_audio_trace_dac(devinfo, as, seq,
3000 w->conns[i], dupseq, min, only, depth + 1)) != 0) {
3001 if (m == 0 || ret < m) {
3005 if (only || dupseq >= 0)
3009 if (im >= 0 && only && ((w->nconns > 1 &&
3010 w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) ||
3011 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR))
3017 w->bindseqmask |= (1 << seq);
3021 device_printf(devinfo->dev,
3022 " %*snid %d returned %d\n",
3023 depth + 1, "", w->nid, m);
3030 * Trace path from widget to ADC.
3033 hdaa_audio_trace_adc(struct hdaa_devinfo *devinfo, int as, int seq, nid_t nid,
3034 int mixed, int min, int only, int depth, int *length, int onlylength)
3036 struct hdaa_widget *w, *wc;
3037 int i, j, im, lm = HDA_PARSE_MAXDEPTH;
3040 if (depth > HDA_PARSE_MAXDEPTH)
3042 w = hdaa_widget_get(devinfo, nid);
3043 if (w == NULL || w->enable == 0)
3046 device_printf(devinfo->dev,
3047 " %*stracing via nid %d\n",
3048 depth + 1, "", w->nid);
3050 /* Use only unused widgets */
3051 if (w->bindas >= 0 && w->bindas != as) {
3053 device_printf(devinfo->dev,
3054 " %*snid %d busy by association %d\n",
3055 depth + 1, "", w->nid, w->bindas);
3059 if (!mixed && w->bindseqmask != 0) {
3061 device_printf(devinfo->dev,
3062 " %*snid %d busy by seqmask %x\n",
3063 depth + 1, "", w->nid, w->bindseqmask);
3068 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT:
3069 if ((only == 0 || only == w->nid) && (w->nid >= min) &&
3070 (onlylength == 0 || onlylength == depth)) {
3075 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
3080 /* Try to find reachable ADCs with specified nid. */
3081 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
3082 wc = hdaa_widget_get(devinfo, j);
3083 if (wc == NULL || wc->enable == 0)
3086 for (i = 0; i < wc->nconns; i++) {
3087 if (wc->connsenable[i] == 0)
3089 if (wc->conns[i] != nid)
3091 if ((ret = hdaa_audio_trace_adc(devinfo, as, seq,
3092 j, mixed, min, only, depth + 1,
3093 length, onlylength)) != 0) {
3094 if (m == 0 || ret < m ||
3095 (ret == m && *length < lm)) {
3105 if (im >= 0 && only && ((wc->nconns > 1 &&
3106 wc->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) ||
3107 wc->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR))
3114 w->bindseqmask |= (1 << seq);
3117 device_printf(devinfo->dev,
3118 " %*snid %d returned %d\n",
3119 depth + 1, "", w->nid, m);
3125 * Erase trace path of the specified association.
3128 hdaa_audio_undo_trace(struct hdaa_devinfo *devinfo, int as, int seq)
3130 struct hdaa_widget *w;
3133 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3134 w = hdaa_widget_get(devinfo, i);
3135 if (w == NULL || w->enable == 0)
3137 if (w->bindas == as) {
3139 w->bindseqmask &= ~(1 << seq);
3140 if (w->bindseqmask == 0) {
3154 * Trace association path from DAC to output
3157 hdaa_audio_trace_as_out(struct hdaa_devinfo *devinfo, int as, int seq)
3159 struct hdaa_audio_as *ases = devinfo->as;
3164 for (i = seq; i < 16 && ases[as].pins[i] == 0; i++)
3166 /* Check if there is no any left. If so - we succeeded. */
3170 hpredir = (i == 15 && ases[as].fakeredir == 0)?ases[as].hpredir:-1;
3174 device_printf(devinfo->dev,
3175 " Tracing pin %d with min nid %d",
3176 ases[as].pins[i], min);
3178 printf(" and hpredir %d", hpredir);
3181 /* Trace this pin taking min nid into account. */
3182 res = hdaa_audio_trace_dac(devinfo, as, i,
3183 ases[as].pins[i], hpredir, min, 0, 0);
3185 /* If we failed - return to previous and redo it. */
3187 device_printf(devinfo->dev,
3188 " Unable to trace pin %d seq %d with min "
3190 ases[as].pins[i], i, min);
3192 printf(" and hpredir %d", hpredir);
3198 device_printf(devinfo->dev,
3199 " Pin %d traced to DAC %d",
3200 ases[as].pins[i], res);
3202 printf(" and hpredir %d", hpredir);
3203 if (ases[as].fakeredir)
3204 printf(" with fake redirection");
3207 /* Trace again to mark the path */
3208 hdaa_audio_trace_dac(devinfo, as, i,
3209 ases[as].pins[i], hpredir, min, res, 0);
3210 ases[as].dacs[0][i] = res;
3211 /* We succeeded, so call next. */
3212 if (hdaa_audio_trace_as_out(devinfo, as, i + 1))
3214 /* If next failed, we should retry with next min */
3215 hdaa_audio_undo_trace(devinfo, as, i);
3216 ases[as].dacs[0][i] = 0;
3222 * Check equivalency of two DACs.
3225 hdaa_audio_dacs_equal(struct hdaa_widget *w1, struct hdaa_widget *w2)
3227 struct hdaa_devinfo *devinfo = w1->devinfo;
3228 struct hdaa_widget *w3;
3231 if (memcmp(&w1->param, &w2->param, sizeof(w1->param)))
3233 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3234 w3 = hdaa_widget_get(devinfo, i);
3235 if (w3 == NULL || w3->enable == 0)
3237 if (w3->bindas != w1->bindas)
3239 if (w3->nconns == 0)
3242 for (j = 0; j < w3->nconns; j++) {
3243 if (w3->connsenable[j] == 0)
3245 if (w3->conns[j] == w1->nid)
3247 if (w3->conns[j] == w2->nid)
3254 if (w3->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
3261 * Check equivalency of two ADCs.
3264 hdaa_audio_adcs_equal(struct hdaa_widget *w1, struct hdaa_widget *w2)
3266 struct hdaa_devinfo *devinfo = w1->devinfo;
3267 struct hdaa_widget *w3, *w4;
3270 if (memcmp(&w1->param, &w2->param, sizeof(w1->param)))
3272 if (w1->nconns != 1 || w2->nconns != 1)
3274 if (w1->conns[0] == w2->conns[0])
3276 w3 = hdaa_widget_get(devinfo, w1->conns[0]);
3277 if (w3 == NULL || w3->enable == 0)
3279 w4 = hdaa_widget_get(devinfo, w2->conns[0]);
3280 if (w4 == NULL || w4->enable == 0)
3282 if (w3->bindas == w4->bindas && w3->bindseqmask == w4->bindseqmask)
3284 if (w4->bindas >= 0)
3286 if (w3->type != w4->type)
3288 if (memcmp(&w3->param, &w4->param, sizeof(w3->param)))
3290 if (w3->nconns != w4->nconns)
3292 for (i = 0; i < w3->nconns; i++) {
3293 if (w3->conns[i] != w4->conns[i])
3300 * Look for equivalent DAC/ADC to implement second channel.
3303 hdaa_audio_adddac(struct hdaa_devinfo *devinfo, int asid)
3305 struct hdaa_audio_as *as = &devinfo->as[asid];
3306 struct hdaa_widget *w1, *w2;
3311 device_printf(devinfo->dev,
3312 "Looking for additional %sC "
3313 "for association %d (%d)\n",
3314 (as->dir == HDAA_CTL_OUT) ? "DA" : "AD",
3318 /* Find the exisitng DAC position and return if found more the one. */
3320 for (i = 0; i < 16; i++) {
3321 if (as->dacs[0][i] <= 0)
3323 if (pos >= 0 && as->dacs[0][i] != as->dacs[0][pos])
3328 nid1 = as->dacs[0][pos];
3329 w1 = hdaa_widget_get(devinfo, nid1);
3331 for (nid2 = devinfo->startnode; nid2 < devinfo->endnode; nid2++) {
3332 w2 = hdaa_widget_get(devinfo, nid2);
3333 if (w2 == NULL || w2->enable == 0)
3335 if (w2->bindas >= 0)
3337 if (w1->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT) {
3338 if (w2->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT)
3340 if (hdaa_audio_dacs_equal(w1, w2))
3343 if (w2->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT)
3345 if (hdaa_audio_adcs_equal(w1, w2))
3349 if (nid2 >= devinfo->endnode)
3351 w2->bindas = w1->bindas;
3352 w2->bindseqmask = w1->bindseqmask;
3353 if (w1->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
3355 device_printf(devinfo->dev,
3356 " ADC %d considered equal to ADC %d\n", nid2, nid1);
3358 w1 = hdaa_widget_get(devinfo, w1->conns[0]);
3359 w2 = hdaa_widget_get(devinfo, w2->conns[0]);
3360 w2->bindas = w1->bindas;
3361 w2->bindseqmask = w1->bindseqmask;
3364 device_printf(devinfo->dev,
3365 " DAC %d considered equal to DAC %d\n", nid2, nid1);
3368 for (i = 0; i < 16; i++) {
3369 if (as->dacs[0][i] <= 0)
3371 as->dacs[as->num_chans][i] = nid2;
3377 * Trace association path from input to ADC
3380 hdaa_audio_trace_as_in(struct hdaa_devinfo *devinfo, int as)
3382 struct hdaa_audio_as *ases = devinfo->as;
3383 struct hdaa_widget *w;
3384 int i, j, k, length;
3386 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
3387 w = hdaa_widget_get(devinfo, j);
3388 if (w == NULL || w->enable == 0)
3390 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT)
3392 if (w->bindas >= 0 && w->bindas != as)
3396 for (i = 0; i < 16; i++) {
3397 if (ases[as].pins[i] == 0)
3401 device_printf(devinfo->dev,
3402 " Tracing pin %d to ADC %d\n",
3403 ases[as].pins[i], j);
3405 /* Trace this pin taking goal into account. */
3406 if (hdaa_audio_trace_adc(devinfo, as, i,
3407 ases[as].pins[i], 1, 0, j, 0, &length, 0) == 0) {
3408 /* If we failed - return to previous and redo it. */
3410 device_printf(devinfo->dev,
3411 " Unable to trace pin %d to ADC %d, undo traces\n",
3412 ases[as].pins[i], j);
3414 hdaa_audio_undo_trace(devinfo, as, -1);
3415 for (k = 0; k < 16; k++)
3416 ases[as].dacs[0][k] = 0;
3420 device_printf(devinfo->dev,
3421 " Pin %d traced to ADC %d\n",
3422 ases[as].pins[i], j);
3424 ases[as].dacs[0][i] = j;
3433 * Trace association path from input to multiple ADCs
3436 hdaa_audio_trace_as_in_mch(struct hdaa_devinfo *devinfo, int as, int seq)
3438 struct hdaa_audio_as *ases = devinfo->as;
3443 for (i = seq; i < 16 && ases[as].pins[i] == 0; i++)
3445 /* Check if there is no any left. If so - we succeeded. */
3452 device_printf(devinfo->dev,
3453 " Tracing pin %d with min nid %d",
3454 ases[as].pins[i], min);
3457 /* Trace this pin taking min nid into account. */
3458 res = hdaa_audio_trace_adc(devinfo, as, i,
3459 ases[as].pins[i], 0, min, 0, 0, &length, 0);
3461 /* If we failed - return to previous and redo it. */
3463 device_printf(devinfo->dev,
3464 " Unable to trace pin %d seq %d with min "
3466 ases[as].pins[i], i, min);
3472 device_printf(devinfo->dev,
3473 " Pin %d traced to ADC %d\n",
3474 ases[as].pins[i], res);
3476 /* Trace again to mark the path */
3477 hdaa_audio_trace_adc(devinfo, as, i,
3478 ases[as].pins[i], 0, min, res, 0, &length, length);
3479 ases[as].dacs[0][i] = res;
3480 /* We succeeded, so call next. */
3481 if (hdaa_audio_trace_as_in_mch(devinfo, as, i + 1))
3483 /* If next failed, we should retry with next min */
3484 hdaa_audio_undo_trace(devinfo, as, i);
3485 ases[as].dacs[0][i] = 0;
3491 * Trace input monitor path from mixer to output association.
3494 hdaa_audio_trace_to_out(struct hdaa_devinfo *devinfo, nid_t nid, int depth)
3496 struct hdaa_audio_as *ases = devinfo->as;
3497 struct hdaa_widget *w, *wc;
3501 if (depth > HDA_PARSE_MAXDEPTH)
3503 w = hdaa_widget_get(devinfo, nid);
3504 if (w == NULL || w->enable == 0)
3507 device_printf(devinfo->dev,
3508 " %*stracing via nid %d\n",
3509 depth + 1, "", w->nid);
3511 /* Use only unused widgets */
3512 if (depth > 0 && w->bindas != -1) {
3513 if (w->bindas < 0 || ases[w->bindas].dir == HDAA_CTL_OUT) {
3515 device_printf(devinfo->dev,
3516 " %*snid %d found output association %d\n",
3517 depth + 1, "", w->nid, w->bindas);
3520 w->pflags |= HDAA_ADC_MONITOR;
3524 device_printf(devinfo->dev,
3525 " %*snid %d busy by input association %d\n",
3526 depth + 1, "", w->nid, w->bindas);
3533 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT:
3534 /* Do not traverse input. AD1988 has digital monitor
3535 for which we are not ready. */
3537 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
3542 /* Try to find reachable ADCs with specified nid. */
3543 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
3544 wc = hdaa_widget_get(devinfo, j);
3545 if (wc == NULL || wc->enable == 0)
3547 for (i = 0; i < wc->nconns; i++) {
3548 if (wc->connsenable[i] == 0)
3550 if (wc->conns[i] != nid)
3552 if (hdaa_audio_trace_to_out(devinfo,
3553 j, depth + 1) != 0) {
3555 if (wc->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR &&
3563 if (res && w->bindas == -1)
3567 device_printf(devinfo->dev,
3568 " %*snid %d returned %d\n",
3569 depth + 1, "", w->nid, res);
3575 * Trace extra associations (beeper, monitor)
3578 hdaa_audio_trace_as_extra(struct hdaa_devinfo *devinfo)
3580 struct hdaa_audio_as *as = devinfo->as;
3581 struct hdaa_widget *w;
3585 /* Find mixer associated with input, but supplying signal
3586 for output associations. Hope it will be input monitor. */
3588 device_printf(devinfo->dev,
3589 "Tracing input monitor\n");
3591 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
3592 w = hdaa_widget_get(devinfo, j);
3593 if (w == NULL || w->enable == 0)
3595 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
3597 if (w->bindas < 0 || as[w->bindas].dir != HDAA_CTL_IN)
3600 device_printf(devinfo->dev,
3601 " Tracing nid %d to out\n",
3604 if (hdaa_audio_trace_to_out(devinfo, w->nid, 0)) {
3606 device_printf(devinfo->dev,
3607 " nid %d is input monitor\n",
3610 w->ossdev = SOUND_MIXER_IMIX;
3614 /* Other inputs monitor */
3615 /* Find input pins supplying signal for output associations.
3616 Hope it will be input monitoring. */
3618 device_printf(devinfo->dev,
3619 "Tracing other input monitors\n");
3621 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
3622 w = hdaa_widget_get(devinfo, j);
3623 if (w == NULL || w->enable == 0)
3625 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
3627 if (w->bindas < 0 || as[w->bindas].dir != HDAA_CTL_IN)
3630 device_printf(devinfo->dev,
3631 " Tracing nid %d to out\n",
3634 if (hdaa_audio_trace_to_out(devinfo, w->nid, 0)) {
3636 device_printf(devinfo->dev,
3637 " nid %d is input monitor\n",
3645 device_printf(devinfo->dev,
3646 "Tracing beeper\n");
3648 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
3649 w = hdaa_widget_get(devinfo, j);
3650 if (w == NULL || w->enable == 0)
3652 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET)
3655 device_printf(devinfo->dev,
3656 " Tracing nid %d to out\n",
3659 if (hdaa_audio_trace_to_out(devinfo, w->nid, 0)) {
3661 device_printf(devinfo->dev,
3662 " nid %d traced to out\n",
3671 * Bind assotiations to PCM channels
3674 hdaa_audio_bind_as(struct hdaa_devinfo *devinfo)
3676 struct hdaa_audio_as *as = devinfo->as;
3677 int i, j, cnt = 0, free;
3679 for (j = 0; j < devinfo->ascnt; j++) {
3681 cnt += as[j].num_chans;
3683 if (devinfo->num_chans == 0) {
3684 devinfo->chans = (struct hdaa_chan *)malloc(
3685 sizeof(struct hdaa_chan) * cnt,
3686 M_HDAA, M_ZERO | M_NOWAIT);
3687 if (devinfo->chans == NULL) {
3688 device_printf(devinfo->dev,
3689 "Channels memory allocation failed!\n");
3693 devinfo->chans = (struct hdaa_chan *)realloc(devinfo->chans,
3694 sizeof(struct hdaa_chan) * (devinfo->num_chans + cnt),
3695 M_HDAA, M_ZERO | M_NOWAIT);
3696 if (devinfo->chans == NULL) {
3697 devinfo->num_chans = 0;
3698 device_printf(devinfo->dev,
3699 "Channels memory allocation failed!\n");
3702 /* Fixup relative pointers after realloc */
3703 for (j = 0; j < devinfo->num_chans; j++)
3704 devinfo->chans[j].caps.fmtlist = devinfo->chans[j].fmtlist;
3706 free = devinfo->num_chans;
3707 devinfo->num_chans += cnt;
3709 for (j = free; j < free + cnt; j++) {
3710 devinfo->chans[j].devinfo = devinfo;
3711 devinfo->chans[j].as = -1;
3714 /* Assign associations in order of their numbers, */
3715 for (j = 0; j < devinfo->ascnt; j++) {
3716 if (as[j].enable == 0)
3718 for (i = 0; i < as[j].num_chans; i++) {
3719 devinfo->chans[free].as = j;
3720 devinfo->chans[free].asindex = i;
3721 devinfo->chans[free].dir =
3722 (as[j].dir == HDAA_CTL_IN) ? PCMDIR_REC : PCMDIR_PLAY;
3723 hdaa_pcmchannel_setup(&devinfo->chans[free]);
3724 as[j].chans[i] = free;
3731 hdaa_audio_disable_nonaudio(struct hdaa_devinfo *devinfo)
3733 struct hdaa_widget *w;
3736 /* Disable power and volume widgets. */
3737 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3738 w = hdaa_widget_get(devinfo, i);
3739 if (w == NULL || w->enable == 0)
3741 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_POWER_WIDGET ||
3742 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_VOLUME_WIDGET) {
3745 device_printf(devinfo->dev,
3746 " Disabling nid %d due to it's"
3747 " non-audio type.\n",
3755 hdaa_audio_disable_useless(struct hdaa_devinfo *devinfo)
3757 struct hdaa_widget *w, *cw;
3758 struct hdaa_audio_ctl *ctl;
3759 int done, found, i, j, k;
3761 /* Disable useless pins. */
3762 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3763 w = hdaa_widget_get(devinfo, i);
3764 if (w == NULL || w->enable == 0)
3766 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) {
3767 if ((w->wclass.pin.config &
3768 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK) ==
3769 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_NONE) {
3772 device_printf(devinfo->dev,
3773 " Disabling pin nid %d due"
3774 " to None connectivity.\n",
3777 } else if ((w->wclass.pin.config &
3778 HDA_CONFIG_DEFAULTCONF_ASSOCIATION_MASK) == 0) {
3781 device_printf(devinfo->dev,
3782 " Disabling unassociated"
3791 /* Disable and mute controls for disabled widgets. */
3793 while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) {
3794 if (ctl->enable == 0)
3796 if (ctl->widget->enable == 0 ||
3797 (ctl->childwidget != NULL &&
3798 ctl->childwidget->enable == 0)) {
3800 ctl->muted = HDAA_AMP_MUTE_ALL;
3804 if (ctl->ndir == HDAA_CTL_IN)
3805 ctl->widget->connsenable[ctl->index] = 0;
3808 device_printf(devinfo->dev,
3809 " Disabling ctl %d nid %d cnid %d due"
3810 " to disabled widget.\n", i,
3812 (ctl->childwidget != NULL)?
3813 ctl->childwidget->nid:-1);
3817 /* Disable useless widgets. */
3818 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3819 w = hdaa_widget_get(devinfo, i);
3820 if (w == NULL || w->enable == 0)
3822 /* Disable inputs with disabled child widgets. */
3823 for (j = 0; j < w->nconns; j++) {
3824 if (w->connsenable[j]) {
3825 cw = hdaa_widget_get(devinfo, w->conns[j]);
3826 if (cw == NULL || cw->enable == 0) {
3827 w->connsenable[j] = 0;
3829 device_printf(devinfo->dev,
3830 " Disabling nid %d connection %d due"
3831 " to disabled child widget.\n",
3837 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR &&
3838 w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
3840 /* Disable mixers and selectors without inputs. */
3842 for (j = 0; j < w->nconns; j++) {
3843 if (w->connsenable[j]) {
3852 device_printf(devinfo->dev,
3853 " Disabling nid %d due to all it's"
3854 " inputs disabled.\n", w->nid);
3857 /* Disable nodes without consumers. */
3858 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR &&
3859 w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
3862 for (k = devinfo->startnode; k < devinfo->endnode; k++) {
3863 cw = hdaa_widget_get(devinfo, k);
3864 if (cw == NULL || cw->enable == 0)
3866 for (j = 0; j < cw->nconns; j++) {
3867 if (cw->connsenable[j] && cw->conns[j] == i) {
3877 device_printf(devinfo->dev,
3878 " Disabling nid %d due to all it's"
3879 " consumers disabled.\n", w->nid);
3883 } while (done == 0);
3888 hdaa_audio_disable_unas(struct hdaa_devinfo *devinfo)
3890 struct hdaa_audio_as *as = devinfo->as;
3891 struct hdaa_widget *w, *cw;
3892 struct hdaa_audio_ctl *ctl;
3895 /* Disable unassosiated widgets. */
3896 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3897 w = hdaa_widget_get(devinfo, i);
3898 if (w == NULL || w->enable == 0)
3900 if (w->bindas == -1) {
3903 device_printf(devinfo->dev,
3904 " Disabling unassociated nid %d.\n",
3909 /* Disable input connections on input pin and
3910 * output on output. */
3911 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3912 w = hdaa_widget_get(devinfo, i);
3913 if (w == NULL || w->enable == 0)
3915 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
3919 if (as[w->bindas].dir == HDAA_CTL_IN) {
3920 for (j = 0; j < w->nconns; j++) {
3921 if (w->connsenable[j] == 0)
3923 w->connsenable[j] = 0;
3925 device_printf(devinfo->dev,
3926 " Disabling connection to input pin "
3927 "nid %d conn %d.\n",
3931 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid,
3932 HDAA_CTL_IN, -1, 1);
3933 if (ctl && ctl->enable) {
3935 ctl->muted = HDAA_AMP_MUTE_ALL;
3941 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid,
3942 HDAA_CTL_OUT, -1, 1);
3943 if (ctl && ctl->enable) {
3945 ctl->muted = HDAA_AMP_MUTE_ALL;
3950 for (k = devinfo->startnode; k < devinfo->endnode; k++) {
3951 cw = hdaa_widget_get(devinfo, k);
3952 if (cw == NULL || cw->enable == 0)
3954 for (j = 0; j < cw->nconns; j++) {
3955 if (cw->connsenable[j] && cw->conns[j] == i) {
3956 cw->connsenable[j] = 0;
3958 device_printf(devinfo->dev,
3959 " Disabling connection from output pin "
3960 "nid %d conn %d cnid %d.\n",
3963 if (cw->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
3966 ctl = hdaa_audio_ctl_amp_get(devinfo, k,
3968 if (ctl && ctl->enable) {
3970 ctl->muted = HDAA_AMP_MUTE_ALL;
3983 hdaa_audio_disable_notselected(struct hdaa_devinfo *devinfo)
3985 struct hdaa_audio_as *as = devinfo->as;
3986 struct hdaa_widget *w;
3989 /* On playback path we can safely disable all unseleted inputs. */
3990 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3991 w = hdaa_widget_get(devinfo, i);
3992 if (w == NULL || w->enable == 0)
3996 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
3998 if (w->bindas < 0 || as[w->bindas].dir == HDAA_CTL_IN)
4000 for (j = 0; j < w->nconns; j++) {
4001 if (w->connsenable[j] == 0)
4003 if (w->selconn < 0 || w->selconn == j)
4005 w->connsenable[j] = 0;
4007 device_printf(devinfo->dev,
4008 " Disabling unselected connection "
4009 "nid %d conn %d.\n",
4017 hdaa_audio_disable_crossas(struct hdaa_devinfo *devinfo)
4019 struct hdaa_audio_as *ases = devinfo->as;
4020 struct hdaa_widget *w, *cw;
4021 struct hdaa_audio_ctl *ctl;
4024 /* Disable crossassociatement and unwanted crosschannel connections. */
4025 /* ... using selectors */
4026 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4027 w = hdaa_widget_get(devinfo, i);
4028 if (w == NULL || w->enable == 0)
4032 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
4034 /* Allow any -> mix */
4035 if (w->bindas == -2)
4037 for (j = 0; j < w->nconns; j++) {
4038 if (w->connsenable[j] == 0)
4040 cw = hdaa_widget_get(devinfo, w->conns[j]);
4041 if (cw == NULL || w->enable == 0)
4043 /* Allow mix -> out. */
4044 if (cw->bindas == -2 && w->bindas >= 0 &&
4045 ases[w->bindas].dir == HDAA_CTL_OUT)
4047 /* Allow mix -> mixed-in. */
4048 if (cw->bindas == -2 && w->bindas >= 0 &&
4049 ases[w->bindas].mixed)
4051 /* Allow in -> mix. */
4052 if ((w->pflags & HDAA_ADC_MONITOR) &&
4054 ases[cw->bindas].dir == HDAA_CTL_IN)
4056 /* Allow if have common as/seqs. */
4057 if (w->bindas == cw->bindas &&
4058 (w->bindseqmask & cw->bindseqmask) != 0)
4060 w->connsenable[j] = 0;
4062 device_printf(devinfo->dev,
4063 " Disabling crossassociatement connection "
4064 "nid %d conn %d cnid %d.\n",
4069 /* ... using controls */
4071 while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) {
4072 if (ctl->enable == 0 || ctl->childwidget == NULL)
4074 /* Allow any -> mix */
4075 if (ctl->widget->bindas == -2)
4077 /* Allow mix -> out. */
4078 if (ctl->childwidget->bindas == -2 &&
4079 ctl->widget->bindas >= 0 &&
4080 ases[ctl->widget->bindas].dir == HDAA_CTL_OUT)
4082 /* Allow mix -> mixed-in. */
4083 if (ctl->childwidget->bindas == -2 &&
4084 ctl->widget->bindas >= 0 &&
4085 ases[ctl->widget->bindas].mixed)
4087 /* Allow in -> mix. */
4088 if ((ctl->widget->pflags & HDAA_ADC_MONITOR) &&
4089 ctl->childwidget->bindas >= 0 &&
4090 ases[ctl->childwidget->bindas].dir == HDAA_CTL_IN)
4092 /* Allow if have common as/seqs. */
4093 if (ctl->widget->bindas == ctl->childwidget->bindas &&
4094 (ctl->widget->bindseqmask & ctl->childwidget->bindseqmask) != 0)
4097 ctl->muted = HDAA_AMP_MUTE_ALL;
4101 if (ctl->ndir == HDAA_CTL_IN)
4102 ctl->widget->connsenable[ctl->index] = 0;
4104 device_printf(devinfo->dev,
4105 " Disabling crossassociatement connection "
4106 "ctl %d nid %d cnid %d.\n", i,
4108 ctl->childwidget->nid);
4115 * Find controls to control amplification for source and calculate possible
4116 * amplification range.
4119 hdaa_audio_ctl_source_amp(struct hdaa_devinfo *devinfo, nid_t nid, int index,
4120 int ossdev, int ctlable, int depth, int *minamp, int *maxamp)
4122 struct hdaa_widget *w, *wc;
4123 struct hdaa_audio_ctl *ctl;
4124 int i, j, conns = 0, tminamp, tmaxamp, cminamp, cmaxamp, found = 0;
4126 if (depth > HDA_PARSE_MAXDEPTH)
4129 w = hdaa_widget_get(devinfo, nid);
4130 if (w == NULL || w->enable == 0)
4133 /* Count number of active inputs. */
4135 for (j = 0; j < w->nconns; j++) {
4136 if (!w->connsenable[j])
4142 /* If this is not a first step - use input mixer.
4143 Pins have common input ctl so care must be taken. */
4144 if (depth > 0 && ctlable && (conns == 1 ||
4145 w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)) {
4146 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, HDAA_CTL_IN,
4149 ctl->ossmask |= (1 << ossdev);
4151 if (*minamp == *maxamp) {
4152 *minamp += MINQDB(ctl);
4153 *maxamp += MAXQDB(ctl);
4158 /* If widget has own ossdev - not traverse it.
4159 It will be traversed on it's own. */
4160 if (w->ossdev >= 0 && depth > 0)
4163 /* We must not traverse pin */
4164 if ((w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT ||
4165 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) &&
4169 /* record that this widget exports such signal, */
4170 w->ossmask |= (1 << ossdev);
4173 * If signals mixed, we can't assign controls farther.
4174 * Ignore this on depth zero. Caller must knows why.
4177 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
4181 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, HDAA_CTL_OUT, -1, 1);
4183 ctl->ossmask |= (1 << ossdev);
4185 if (*minamp == *maxamp) {
4186 *minamp += MINQDB(ctl);
4187 *maxamp += MAXQDB(ctl);
4192 cminamp = cmaxamp = 0;
4193 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4194 wc = hdaa_widget_get(devinfo, i);
4195 if (wc == NULL || wc->enable == 0)
4197 for (j = 0; j < wc->nconns; j++) {
4198 if (wc->connsenable[j] && wc->conns[j] == nid) {
4199 tminamp = tmaxamp = 0;
4200 found += hdaa_audio_ctl_source_amp(devinfo,
4201 wc->nid, j, ossdev, ctlable, depth + 1,
4202 &tminamp, &tmaxamp);
4203 if (cminamp == 0 && cmaxamp == 0) {
4206 } else if (tminamp != tmaxamp) {
4207 cminamp = imax(cminamp, tminamp);
4208 cmaxamp = imin(cmaxamp, tmaxamp);
4213 if (*minamp == *maxamp && cminamp < cmaxamp) {
4221 * Find controls to control amplification for destination and calculate
4222 * possible amplification range.
4225 hdaa_audio_ctl_dest_amp(struct hdaa_devinfo *devinfo, nid_t nid, int index,
4226 int ossdev, int depth, int *minamp, int *maxamp)
4228 struct hdaa_audio_as *as = devinfo->as;
4229 struct hdaa_widget *w, *wc;
4230 struct hdaa_audio_ctl *ctl;
4231 int i, j, consumers, tminamp, tmaxamp, cminamp, cmaxamp, found = 0;
4233 if (depth > HDA_PARSE_MAXDEPTH)
4236 w = hdaa_widget_get(devinfo, nid);
4237 if (w == NULL || w->enable == 0)
4241 /* If this node produce output for several consumers,
4242 we can't touch it. */
4244 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4245 wc = hdaa_widget_get(devinfo, i);
4246 if (wc == NULL || wc->enable == 0)
4248 for (j = 0; j < wc->nconns; j++) {
4249 if (wc->connsenable[j] && wc->conns[j] == nid)
4253 /* The only exception is if real HP redirection is configured
4254 and this is a duplication point.
4255 XXX: Actually exception is not completely correct.
4256 XXX: Duplication point check is not perfect. */
4257 if ((consumers == 2 && (w->bindas < 0 ||
4258 as[w->bindas].hpredir < 0 || as[w->bindas].fakeredir ||
4259 (w->bindseqmask & (1 << 15)) == 0)) ||
4263 /* Else use it's output mixer. */
4264 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid,
4265 HDAA_CTL_OUT, -1, 1);
4267 ctl->ossmask |= (1 << ossdev);
4269 if (*minamp == *maxamp) {
4270 *minamp += MINQDB(ctl);
4271 *maxamp += MAXQDB(ctl);
4276 /* We must not traverse pin */
4277 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
4281 cminamp = cmaxamp = 0;
4282 for (i = 0; i < w->nconns; i++) {
4283 if (w->connsenable[i] == 0)
4285 if (index >= 0 && i != index)
4287 tminamp = tmaxamp = 0;
4288 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid,
4291 ctl->ossmask |= (1 << ossdev);
4293 if (*minamp == *maxamp) {
4294 tminamp += MINQDB(ctl);
4295 tmaxamp += MAXQDB(ctl);
4298 found += hdaa_audio_ctl_dest_amp(devinfo, w->conns[i], -1, ossdev,
4299 depth + 1, &tminamp, &tmaxamp);
4300 if (cminamp == 0 && cmaxamp == 0) {
4303 } else if (tminamp != tmaxamp) {
4304 cminamp = imax(cminamp, tminamp);
4305 cmaxamp = imin(cmaxamp, tmaxamp);
4308 if (*minamp == *maxamp && cminamp < cmaxamp) {
4316 * Assign OSS names to sound sources
4319 hdaa_audio_assign_names(struct hdaa_devinfo *devinfo)
4321 struct hdaa_audio_as *as = devinfo->as;
4322 struct hdaa_widget *w;
4324 int type = -1, use, used = 0;
4325 static const int types[7][13] = {
4326 { SOUND_MIXER_LINE, SOUND_MIXER_LINE1, SOUND_MIXER_LINE2,
4327 SOUND_MIXER_LINE3, -1 }, /* line */
4328 { SOUND_MIXER_MONITOR, SOUND_MIXER_MIC, -1 }, /* int mic */
4329 { SOUND_MIXER_MIC, SOUND_MIXER_MONITOR, -1 }, /* ext mic */
4330 { SOUND_MIXER_CD, -1 }, /* cd */
4331 { SOUND_MIXER_SPEAKER, -1 }, /* speaker */
4332 { SOUND_MIXER_DIGITAL1, SOUND_MIXER_DIGITAL2, SOUND_MIXER_DIGITAL3,
4334 { SOUND_MIXER_LINE, SOUND_MIXER_LINE1, SOUND_MIXER_LINE2,
4335 SOUND_MIXER_LINE3, SOUND_MIXER_PHONEIN, SOUND_MIXER_PHONEOUT,
4336 SOUND_MIXER_VIDEO, SOUND_MIXER_RADIO, SOUND_MIXER_DIGITAL1,
4337 SOUND_MIXER_DIGITAL2, SOUND_MIXER_DIGITAL3, SOUND_MIXER_MONITOR,
4341 /* Surely known names */
4342 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4343 w = hdaa_widget_get(devinfo, i);
4344 if (w == NULL || w->enable == 0)
4346 if (w->bindas == -1)
4350 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
4351 if (as[w->bindas].dir == HDAA_CTL_OUT)
4354 switch (w->wclass.pin.config & HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) {
4355 case HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN:
4358 case HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN:
4359 if ((w->wclass.pin.config & HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK)
4360 == HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_JACK)
4364 case HDA_CONFIG_DEFAULTCONF_DEVICE_CD:
4367 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER:
4370 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_IN:
4371 case HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_IN:
4378 while (types[type][j] >= 0 &&
4379 (used & (1 << types[type][j])) != 0) {
4382 if (types[type][j] >= 0)
4383 use = types[type][j];
4385 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT:
4386 use = SOUND_MIXER_PCM;
4388 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET:
4389 use = SOUND_MIXER_SPEAKER;
4399 /* Semi-known names */
4400 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4401 w = hdaa_widget_get(devinfo, i);
4402 if (w == NULL || w->enable == 0)
4406 if (w->bindas == -1)
4408 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
4410 if (as[w->bindas].dir == HDAA_CTL_OUT)
4413 switch (w->wclass.pin.config & HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) {
4414 case HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_OUT:
4415 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER:
4416 case HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT:
4417 case HDA_CONFIG_DEFAULTCONF_DEVICE_AUX:
4420 case HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN:
4423 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_OUT:
4424 case HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_OUT:
4431 while (types[type][j] >= 0 &&
4432 (used & (1 << types[type][j])) != 0) {
4435 if (types[type][j] >= 0) {
4436 w->ossdev = types[type][j];
4437 used |= (1 << types[type][j]);
4441 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4442 w = hdaa_widget_get(devinfo, i);
4443 if (w == NULL || w->enable == 0)
4447 if (w->bindas == -1)
4449 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
4451 if (as[w->bindas].dir == HDAA_CTL_OUT)
4454 while (types[6][j] >= 0 &&
4455 (used & (1 << types[6][j])) != 0) {
4458 if (types[6][j] >= 0) {
4459 w->ossdev = types[6][j];
4460 used |= (1 << types[6][j]);
4466 hdaa_audio_build_tree(struct hdaa_devinfo *devinfo)
4468 struct hdaa_audio_as *as = devinfo->as;
4471 /* Trace all associations in order of their numbers. */
4472 for (j = 0; j < devinfo->ascnt; j++) {
4473 if (as[j].enable == 0)
4476 device_printf(devinfo->dev,
4477 "Tracing association %d (%d)\n", j, as[j].index);
4479 if (as[j].dir == HDAA_CTL_OUT) {
4481 res = hdaa_audio_trace_as_out(devinfo, j, 0);
4482 if (res == 0 && as[j].hpredir >= 0 &&
4483 as[j].fakeredir == 0) {
4484 /* If CODEC can't do analog HP redirection
4485 try to make it using one more DAC. */
4486 as[j].fakeredir = 1;
4489 } else if (as[j].mixed)
4490 res = hdaa_audio_trace_as_in(devinfo, j);
4492 res = hdaa_audio_trace_as_in_mch(devinfo, j, 0);
4495 device_printf(devinfo->dev,
4496 "Association %d (%d) trace succeeded\n",
4501 device_printf(devinfo->dev,
4502 "Association %d (%d) trace failed\n",
4509 /* Look for additional DACs/ADCs. */
4510 for (j = 0; j < devinfo->ascnt; j++) {
4511 if (as[j].enable == 0)
4513 hdaa_audio_adddac(devinfo, j);
4516 /* Trace mixer and beeper pseudo associations. */
4517 hdaa_audio_trace_as_extra(devinfo);
4521 * Store in pdevinfo new data about whether and how we can control signal
4522 * for OSS device to/from specified widget.
4525 hdaa_adjust_amp(struct hdaa_widget *w, int ossdev,
4526 int found, int minamp, int maxamp)
4528 struct hdaa_devinfo *devinfo = w->devinfo;
4529 struct hdaa_pcm_devinfo *pdevinfo;
4532 pdevinfo = devinfo->as[w->bindas].pdevinfo;
4534 pdevinfo = &devinfo->devs[0];
4536 pdevinfo->ossmask |= (1 << ossdev);
4537 if (minamp == 0 && maxamp == 0)
4539 if (pdevinfo->minamp[ossdev] == 0 && pdevinfo->maxamp[ossdev] == 0) {
4540 pdevinfo->minamp[ossdev] = minamp;
4541 pdevinfo->maxamp[ossdev] = maxamp;
4543 pdevinfo->minamp[ossdev] = imax(pdevinfo->minamp[ossdev], minamp);
4544 pdevinfo->maxamp[ossdev] = imin(pdevinfo->maxamp[ossdev], maxamp);
4549 * Trace signals from/to all possible sources/destionstions to find possible
4550 * recording sources, OSS device control ranges and to assign controls.
4553 hdaa_audio_assign_mixers(struct hdaa_devinfo *devinfo)
4555 struct hdaa_audio_as *as = devinfo->as;
4556 struct hdaa_widget *w, *cw;
4557 int i, j, minamp, maxamp, found;
4559 /* Assign mixers to the tree. */
4560 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4561 w = hdaa_widget_get(devinfo, i);
4562 if (w == NULL || w->enable == 0)
4564 minamp = maxamp = 0;
4565 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT ||
4566 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET ||
4567 (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
4568 as[w->bindas].dir == HDAA_CTL_IN)) {
4571 found = hdaa_audio_ctl_source_amp(devinfo, w->nid, -1,
4572 w->ossdev, 1, 0, &minamp, &maxamp);
4573 hdaa_adjust_amp(w, w->ossdev, found, minamp, maxamp);
4574 } else if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
4575 found = hdaa_audio_ctl_dest_amp(devinfo, w->nid, -1,
4576 SOUND_MIXER_RECLEV, 0, &minamp, &maxamp);
4577 hdaa_adjust_amp(w, SOUND_MIXER_RECLEV, found, minamp, maxamp);
4578 } else if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
4579 as[w->bindas].dir == HDAA_CTL_OUT) {
4580 found = hdaa_audio_ctl_dest_amp(devinfo, w->nid, -1,
4581 SOUND_MIXER_VOLUME, 0, &minamp, &maxamp);
4582 hdaa_adjust_amp(w, SOUND_MIXER_VOLUME, found, minamp, maxamp);
4584 if (w->ossdev == SOUND_MIXER_IMIX) {
4585 minamp = maxamp = 0;
4586 found = hdaa_audio_ctl_source_amp(devinfo, w->nid, -1,
4587 w->ossdev, 1, 0, &minamp, &maxamp);
4588 if (minamp == maxamp) {
4589 /* If we are unable to control input monitor
4590 as source - try to control it as destination. */
4591 found += hdaa_audio_ctl_dest_amp(devinfo, w->nid, -1,
4592 w->ossdev, 0, &minamp, &maxamp);
4593 w->pflags |= HDAA_IMIX_AS_DST;
4595 hdaa_adjust_amp(w, w->ossdev, found, minamp, maxamp);
4597 if (w->pflags & HDAA_ADC_MONITOR) {
4598 for (j = 0; j < w->nconns; j++) {
4599 if (!w->connsenable[j])
4601 cw = hdaa_widget_get(devinfo, w->conns[j]);
4602 if (cw == NULL || cw->enable == 0)
4604 if (cw->bindas == -1)
4606 if (cw->bindas >= 0 &&
4607 as[cw->bindas].dir != HDAA_CTL_IN)
4609 minamp = maxamp = 0;
4610 found = hdaa_audio_ctl_dest_amp(devinfo,
4611 w->nid, j, SOUND_MIXER_IGAIN, 0,
4613 hdaa_adjust_amp(w, SOUND_MIXER_IGAIN,
4614 found, minamp, maxamp);
4621 hdaa_audio_prepare_pin_ctrl(struct hdaa_devinfo *devinfo)
4623 struct hdaa_audio_as *as = devinfo->as;
4624 struct hdaa_widget *w;
4628 for (i = 0; i < devinfo->nodecnt; i++) {
4629 w = &devinfo->widget[i];
4632 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
4636 pincap = w->wclass.pin.cap;
4638 /* Disable everything. */
4639 w->wclass.pin.ctrl &= ~(
4640 HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE |
4641 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE |
4642 HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE |
4643 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK);
4645 if (w->enable == 0) {
4646 /* Pin is unused so left it disabled. */
4648 } else if (w->waspin) {
4649 /* Enable input for beeper input. */
4650 w->wclass.pin.ctrl |=
4651 HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE;
4652 } else if (w->bindas < 0 || as[w->bindas].enable == 0) {
4653 /* Pin is unused so left it disabled. */
4655 } else if (as[w->bindas].dir == HDAA_CTL_IN) {
4656 /* Input pin, configure for input. */
4657 if (HDA_PARAM_PIN_CAP_INPUT_CAP(pincap))
4658 w->wclass.pin.ctrl |=
4659 HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE;
4661 if ((devinfo->quirks & HDAA_QUIRK_IVREF100) &&
4662 HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap))
4663 w->wclass.pin.ctrl |=
4664 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
4665 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_100);
4666 else if ((devinfo->quirks & HDAA_QUIRK_IVREF80) &&
4667 HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap))
4668 w->wclass.pin.ctrl |=
4669 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
4670 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_80);
4671 else if ((devinfo->quirks & HDAA_QUIRK_IVREF50) &&
4672 HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap))
4673 w->wclass.pin.ctrl |=
4674 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
4675 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_50);
4677 /* Output pin, configure for output. */
4678 if (HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap))
4679 w->wclass.pin.ctrl |=
4680 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
4682 if (HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap) &&
4683 (w->wclass.pin.config &
4684 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) ==
4685 HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT)
4686 w->wclass.pin.ctrl |=
4687 HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE;
4689 if ((devinfo->quirks & HDAA_QUIRK_OVREF100) &&
4690 HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap))
4691 w->wclass.pin.ctrl |=
4692 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
4693 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_100);
4694 else if ((devinfo->quirks & HDAA_QUIRK_OVREF80) &&
4695 HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap))
4696 w->wclass.pin.ctrl |=
4697 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
4698 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_80);
4699 else if ((devinfo->quirks & HDAA_QUIRK_OVREF50) &&
4700 HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap))
4701 w->wclass.pin.ctrl |=
4702 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
4703 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_50);
4709 hdaa_audio_ctl_commit(struct hdaa_devinfo *devinfo)
4711 struct hdaa_audio_ctl *ctl;
4715 while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) {
4716 if (ctl->enable == 0 || ctl->ossmask != 0) {
4717 /* Mute disabled and mixer controllable controls.
4718 * Last will be initialized by mixer_init().
4719 * This expected to reduce click on startup. */
4720 hdaa_audio_ctl_amp_set(ctl, HDAA_AMP_MUTE_ALL, 0, 0);
4723 /* Init fixed controls to 0dB amplification. */
4727 hdaa_audio_ctl_amp_set(ctl, HDAA_AMP_MUTE_NONE, z, z);
4732 hdaa_gpio_commit(struct hdaa_devinfo *devinfo)
4734 uint32_t gdata, gmask, gdir;
4737 numgpio = HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap);
4738 if (devinfo->gpio != 0 && numgpio != 0) {
4739 gdata = hda_command(devinfo->dev,
4740 HDA_CMD_GET_GPIO_DATA(0, devinfo->nid));
4741 gmask = hda_command(devinfo->dev,
4742 HDA_CMD_GET_GPIO_ENABLE_MASK(0, devinfo->nid));
4743 gdir = hda_command(devinfo->dev,
4744 HDA_CMD_GET_GPIO_DIRECTION(0, devinfo->nid));
4745 for (i = 0; i < numgpio; i++) {
4746 if ((devinfo->gpio & HDAA_GPIO_MASK(i)) ==
4751 } else if ((devinfo->gpio & HDAA_GPIO_MASK(i)) ==
4752 HDAA_GPIO_CLEAR(i)) {
4756 } else if ((devinfo->gpio & HDAA_GPIO_MASK(i)) ==
4757 HDAA_GPIO_DISABLE(i)) {
4759 } else if ((devinfo->gpio & HDAA_GPIO_MASK(i)) ==
4760 HDAA_GPIO_INPUT(i)) {
4766 device_printf(devinfo->dev, "GPIO commit\n");
4768 hda_command(devinfo->dev,
4769 HDA_CMD_SET_GPIO_ENABLE_MASK(0, devinfo->nid, gmask));
4770 hda_command(devinfo->dev,
4771 HDA_CMD_SET_GPIO_DIRECTION(0, devinfo->nid, gdir));
4772 hda_command(devinfo->dev,
4773 HDA_CMD_SET_GPIO_DATA(0, devinfo->nid, gdata));
4775 hdaa_dump_gpio(devinfo);
4781 hdaa_gpo_commit(struct hdaa_devinfo *devinfo)
4786 numgpo = HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap);
4787 if (devinfo->gpo != 0 && numgpo != 0) {
4788 gdata = hda_command(devinfo->dev,
4789 HDA_CMD_GET_GPO_DATA(0, devinfo->nid));
4790 for (i = 0; i < numgpo; i++) {
4791 if ((devinfo->gpio & HDAA_GPIO_MASK(i)) ==
4794 } else if ((devinfo->gpio & HDAA_GPIO_MASK(i)) ==
4795 HDAA_GPIO_CLEAR(i)) {
4800 device_printf(devinfo->dev, "GPO commit\n");
4802 hda_command(devinfo->dev,
4803 HDA_CMD_SET_GPO_DATA(0, devinfo->nid, gdata));
4805 hdaa_dump_gpo(devinfo);
4811 hdaa_audio_commit(struct hdaa_devinfo *devinfo)
4813 struct hdaa_widget *w;
4816 /* Commit controls. */
4817 hdaa_audio_ctl_commit(devinfo);
4819 /* Commit selectors, pins and EAPD. */
4820 for (i = 0; i < devinfo->nodecnt; i++) {
4821 w = &devinfo->widget[i];
4824 if (w->selconn == -1)
4827 hdaa_widget_connection_select(w, w->selconn);
4828 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX ||
4830 hda_command(devinfo->dev,
4831 HDA_CMD_SET_PIN_WIDGET_CTRL(0, w->nid,
4832 w->wclass.pin.ctrl));
4834 if (w->param.eapdbtl != HDA_INVALID) {
4837 val = w->param.eapdbtl;
4838 if (devinfo->quirks &
4840 val ^= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
4841 hda_command(devinfo->dev,
4842 HDA_CMD_SET_EAPD_BTL_ENABLE(0, w->nid,
4847 hdaa_gpio_commit(devinfo);
4848 hdaa_gpo_commit(devinfo);
4852 hdaa_powerup(struct hdaa_devinfo *devinfo)
4856 hda_command(devinfo->dev,
4857 HDA_CMD_SET_POWER_STATE(0,
4858 devinfo->nid, HDA_CMD_POWER_STATE_D0));
4861 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4862 hda_command(devinfo->dev,
4863 HDA_CMD_SET_POWER_STATE(0,
4864 i, HDA_CMD_POWER_STATE_D0));
4870 hdaa_pcmchannel_setup(struct hdaa_chan *ch)
4872 struct hdaa_devinfo *devinfo = ch->devinfo;
4873 struct hdaa_audio_as *as = devinfo->as;
4874 struct hdaa_widget *w;
4875 uint32_t cap, fmtcap, pcmcap;
4876 int i, j, ret, channels, onlystereo;
4879 ch->caps = hdaa_caps;
4880 ch->caps.fmtlist = ch->fmtlist;
4883 ch->pcmrates[0] = 48000;
4884 ch->pcmrates[1] = 0;
4885 ch->stripecap = 0xff;
4891 fmtcap = devinfo->supp_stream_formats;
4892 pcmcap = devinfo->supp_pcm_size_rate;
4894 for (i = 0; i < 16; i++) {
4895 /* Check as is correct */
4898 /* Cound only present DACs */
4899 if (as[ch->as].dacs[ch->asindex][i] <= 0)
4901 /* Ignore duplicates */
4902 for (j = 0; j < ret; j++) {
4903 if (ch->io[j] == as[ch->as].dacs[ch->asindex][i])
4909 w = hdaa_widget_get(devinfo, as[ch->as].dacs[ch->asindex][i]);
4910 if (w == NULL || w->enable == 0)
4912 cap = w->param.supp_stream_formats;
4913 if (!HDA_PARAM_SUPP_STREAM_FORMATS_PCM(cap) &&
4914 !HDA_PARAM_SUPP_STREAM_FORMATS_AC3(cap))
4916 /* Many CODECs does not declare AC3 support on SPDIF.
4917 I don't beleave that they doesn't support it! */
4918 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap))
4919 cap |= HDA_PARAM_SUPP_STREAM_FORMATS_AC3_MASK;
4922 pcmcap = w->param.supp_pcm_size_rate;
4925 pcmcap &= w->param.supp_pcm_size_rate;
4927 ch->io[ret++] = as[ch->as].dacs[ch->asindex][i];
4928 ch->stripecap &= w->wclass.conv.stripecap;
4929 /* Do not count redirection pin/dac channels. */
4930 if (i == 15 && as[ch->as].hpredir >= 0)
4932 channels += HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap) + 1;
4933 if (HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap) != 1)
4938 ch->channels = channels;
4940 if (as[ch->as].fakeredir)
4942 /* Standard speaks only about stereo pins and playback, ... */
4943 if ((!onlystereo) || as[ch->as].mixed)
4945 /* ..., but there it gives us info about speakers layout. */
4946 as[ch->as].pinset = pinset;
4948 ch->supp_stream_formats = fmtcap;
4949 ch->supp_pcm_size_rate = pcmcap;
4960 if (HDA_PARAM_SUPP_STREAM_FORMATS_PCM(fmtcap)) {
4961 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16BIT(pcmcap))
4963 else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8BIT(pcmcap))
4965 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(pcmcap))
4967 else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(pcmcap))
4969 else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(pcmcap))
4971 if (!(devinfo->quirks & HDAA_QUIRK_FORCESTEREO)) {
4972 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 1, 0);
4974 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 1, 0);
4976 if (channels >= 2) {
4977 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 2, 0);
4979 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 2, 0);
4981 if (channels >= 3 && !onlystereo) {
4982 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 3, 0);
4984 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 3, 0);
4985 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 3, 1);
4987 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 3, 1);
4989 if (channels >= 4) {
4990 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 4, 0);
4992 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 4, 0);
4994 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 4, 1);
4996 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 4, 1);
4999 if (channels >= 5 && !onlystereo) {
5000 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 5, 0);
5002 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 5, 0);
5003 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 5, 1);
5005 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 5, 1);
5007 if (channels >= 6) {
5008 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 6, 1);
5010 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 6, 1);
5012 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 6, 0);
5014 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 6, 0);
5017 if (channels >= 7 && !onlystereo) {
5018 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 7, 0);
5020 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 7, 0);
5021 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 7, 1);
5023 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 7, 1);
5025 if (channels >= 8) {
5026 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 8, 1);
5028 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 8, 1);
5031 if (HDA_PARAM_SUPP_STREAM_FORMATS_AC3(fmtcap)) {
5032 ch->fmtlist[i++] = SND_FORMAT(AFMT_AC3, 2, 0);
5033 if (channels >= 8) {
5034 ch->fmtlist[i++] = SND_FORMAT(AFMT_AC3, 8, 0);
5035 ch->fmtlist[i++] = SND_FORMAT(AFMT_AC3, 8, 1);
5040 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8KHZ(pcmcap))
5041 ch->pcmrates[i++] = 8000;
5042 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_11KHZ(pcmcap))
5043 ch->pcmrates[i++] = 11025;
5044 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16KHZ(pcmcap))
5045 ch->pcmrates[i++] = 16000;
5046 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_22KHZ(pcmcap))
5047 ch->pcmrates[i++] = 22050;
5048 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32KHZ(pcmcap))
5049 ch->pcmrates[i++] = 32000;
5050 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_44KHZ(pcmcap))
5051 ch->pcmrates[i++] = 44100;
5052 /* if (HDA_PARAM_SUPP_PCM_SIZE_RATE_48KHZ(pcmcap)) */
5053 ch->pcmrates[i++] = 48000;
5054 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_88KHZ(pcmcap))
5055 ch->pcmrates[i++] = 88200;
5056 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_96KHZ(pcmcap))
5057 ch->pcmrates[i++] = 96000;
5058 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_176KHZ(pcmcap))
5059 ch->pcmrates[i++] = 176400;
5060 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_192KHZ(pcmcap))
5061 ch->pcmrates[i++] = 192000;
5062 /* if (HDA_PARAM_SUPP_PCM_SIZE_RATE_384KHZ(pcmcap)) */
5063 ch->pcmrates[i] = 0;
5065 ch->caps.minspeed = ch->pcmrates[0];
5066 ch->caps.maxspeed = ch->pcmrates[i - 1];
5074 hdaa_prepare_pcms(struct hdaa_devinfo *devinfo)
5076 struct hdaa_audio_as *as = devinfo->as;
5077 int i, j, k, apdev = 0, ardev = 0, dpdev = 0, drdev = 0;
5079 for (i = 0; i < devinfo->ascnt; i++) {
5080 if (as[i].enable == 0)
5082 if (as[i].dir == HDAA_CTL_IN) {
5095 max(ardev, apdev) + max(drdev, dpdev);
5097 (struct hdaa_pcm_devinfo *)malloc(
5098 devinfo->num_devs * sizeof(struct hdaa_pcm_devinfo),
5099 M_HDAA, M_ZERO | M_NOWAIT);
5100 if (devinfo->devs == NULL) {
5101 device_printf(devinfo->dev,
5102 "Unable to allocate memory for devices\n");
5105 for (i = 0; i < devinfo->num_devs; i++) {
5106 devinfo->devs[i].index = i;
5107 devinfo->devs[i].devinfo = devinfo;
5108 devinfo->devs[i].playas = -1;
5109 devinfo->devs[i].recas = -1;
5110 devinfo->devs[i].digital = 255;
5112 for (i = 0; i < devinfo->ascnt; i++) {
5113 if (as[i].enable == 0)
5115 for (j = 0; j < devinfo->num_devs; j++) {
5116 if (devinfo->devs[j].digital != 255 &&
5117 (!devinfo->devs[j].digital) !=
5120 if (as[i].dir == HDAA_CTL_IN) {
5121 if (devinfo->devs[j].recas >= 0)
5123 devinfo->devs[j].recas = i;
5125 if (devinfo->devs[j].playas >= 0)
5127 devinfo->devs[j].playas = i;
5129 as[i].pdevinfo = &devinfo->devs[j];
5130 for (k = 0; k < as[i].num_chans; k++) {
5131 devinfo->chans[as[i].chans[k]].pdevinfo =
5134 devinfo->devs[j].digital = as[i].digital;
5141 hdaa_create_pcms(struct hdaa_devinfo *devinfo)
5145 for (i = 0; i < devinfo->num_devs; i++) {
5146 struct hdaa_pcm_devinfo *pdevinfo = &devinfo->devs[i];
5148 pdevinfo->dev = device_add_child(devinfo->dev, "pcm", -1);
5149 device_set_ivars(pdevinfo->dev, (void *)pdevinfo);
5154 hdaa_dump_ctls(struct hdaa_pcm_devinfo *pdevinfo, const char *banner, uint32_t flag)
5156 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
5157 struct hdaa_audio_ctl *ctl;
5162 flag = ~(SOUND_MASK_VOLUME | SOUND_MASK_PCM |
5163 SOUND_MASK_CD | SOUND_MASK_LINE | SOUND_MASK_RECLEV |
5164 SOUND_MASK_MIC | SOUND_MASK_SPEAKER | SOUND_MASK_IGAIN |
5165 SOUND_MASK_OGAIN | SOUND_MASK_IMIX | SOUND_MASK_MONITOR);
5168 for (j = 0; j < SOUND_MIXER_NRDEVICES; j++) {
5169 if ((flag & (1 << j)) == 0)
5173 while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) {
5174 if (ctl->enable == 0 ||
5175 ctl->widget->enable == 0)
5177 if (!((pdevinfo->playas >= 0 &&
5178 ctl->widget->bindas == pdevinfo->playas) ||
5179 (pdevinfo->recas >= 0 &&
5180 ctl->widget->bindas == pdevinfo->recas) ||
5181 (ctl->widget->bindas == -2 && pdevinfo->index == 0)))
5183 if ((ctl->ossmask & (1 << j)) == 0)
5187 device_printf(pdevinfo->dev, "\n");
5188 if (banner != NULL) {
5189 device_printf(pdevinfo->dev, "%s", banner);
5191 device_printf(pdevinfo->dev, "Unknown Ctl");
5193 printf(" (OSS: %s)",
5194 hdaa_audio_ctl_ossmixer_mask2allname(1 << j,
5196 if (pdevinfo->ossmask & (1 << j)) {
5197 printf(": %+d/%+ddB\n",
5198 pdevinfo->minamp[j] / 4,
5199 pdevinfo->maxamp[j] / 4);
5202 device_printf(pdevinfo->dev, " |\n");
5205 device_printf(pdevinfo->dev, " +- ctl %2d (nid %3d %s", i,
5207 (ctl->ndir == HDAA_CTL_IN)?"in ":"out");
5208 if (ctl->ndir == HDAA_CTL_IN && ctl->ndir == ctl->dir)
5209 printf(" %2d): ", ctl->index);
5212 if (ctl->step > 0) {
5213 printf("%+d/%+ddB (%d steps)%s\n",
5217 ctl->mute?" + mute":"");
5219 printf("%s\n", ctl->mute?"mute":"");
5225 hdaa_dump_audio_formats(device_t dev, uint32_t fcap, uint32_t pcmcap)
5231 device_printf(dev, " Stream cap: 0x%08x\n", cap);
5232 device_printf(dev, " ");
5233 if (HDA_PARAM_SUPP_STREAM_FORMATS_AC3(cap))
5235 if (HDA_PARAM_SUPP_STREAM_FORMATS_FLOAT32(cap))
5237 if (HDA_PARAM_SUPP_STREAM_FORMATS_PCM(cap))
5243 device_printf(dev, " PCM cap: 0x%08x\n", cap);
5244 device_printf(dev, " ");
5245 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8BIT(cap))
5247 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16BIT(cap))
5249 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(cap))
5251 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(cap))
5253 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(cap))
5256 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8KHZ(cap))
5258 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_11KHZ(cap))
5260 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16KHZ(cap))
5262 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_22KHZ(cap))
5264 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32KHZ(cap))
5266 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_44KHZ(cap))
5269 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_88KHZ(cap))
5271 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_96KHZ(cap))
5273 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_176KHZ(cap))
5275 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_192KHZ(cap))
5282 hdaa_dump_pin(struct hdaa_widget *w)
5286 pincap = w->wclass.pin.cap;
5288 device_printf(w->devinfo->dev, " Pin cap: 0x%08x\n", pincap);
5289 device_printf(w->devinfo->dev, " ");
5290 if (HDA_PARAM_PIN_CAP_IMP_SENSE_CAP(pincap))
5292 if (HDA_PARAM_PIN_CAP_TRIGGER_REQD(pincap))
5294 if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(pincap))
5296 if (HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap))
5298 if (HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap))
5300 if (HDA_PARAM_PIN_CAP_INPUT_CAP(pincap))
5302 if (HDA_PARAM_PIN_CAP_BALANCED_IO_PINS(pincap))
5304 if (HDA_PARAM_PIN_CAP_HDMI(pincap))
5306 if (HDA_PARAM_PIN_CAP_VREF_CTRL(pincap)) {
5308 if (HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap))
5310 if (HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap))
5312 if (HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap))
5314 if (HDA_PARAM_PIN_CAP_VREF_CTRL_GROUND(pincap))
5316 if (HDA_PARAM_PIN_CAP_VREF_CTRL_HIZ(pincap))
5320 if (HDA_PARAM_PIN_CAP_EAPD_CAP(pincap))
5322 if (HDA_PARAM_PIN_CAP_DP(pincap))
5324 if (HDA_PARAM_PIN_CAP_HBR(pincap))
5327 device_printf(w->devinfo->dev, " Pin config: 0x%08x\n",
5328 w->wclass.pin.config);
5329 device_printf(w->devinfo->dev, " Pin control: 0x%08x", w->wclass.pin.ctrl);
5330 if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE)
5332 if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE)
5334 if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE)
5336 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) {
5337 if ((w->wclass.pin.ctrl &
5338 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK) == 0x03)
5340 else if ((w->wclass.pin.ctrl &
5341 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK) != 0)
5344 if ((w->wclass.pin.ctrl &
5345 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK) != 0)
5352 hdaa_dump_pin_config(struct hdaa_widget *w, uint32_t conf)
5355 device_printf(w->devinfo->dev, "%2d %08x %-2d %-2d "
5356 "%-13s %-5s %-7s %-10s %-7s %d%s\n",
5358 HDA_CONFIG_DEFAULTCONF_ASSOCIATION(conf),
5359 HDA_CONFIG_DEFAULTCONF_SEQUENCE(conf),
5360 HDA_DEVS[HDA_CONFIG_DEFAULTCONF_DEVICE(conf)],
5361 HDA_CONNS[HDA_CONFIG_DEFAULTCONF_CONNECTIVITY(conf)],
5362 HDA_CONNECTORS[HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE(conf)],
5363 HDA_LOCS[HDA_CONFIG_DEFAULTCONF_LOCATION(conf)],
5364 HDA_COLORS[HDA_CONFIG_DEFAULTCONF_COLOR(conf)],
5365 HDA_CONFIG_DEFAULTCONF_MISC(conf),
5366 (w->enable == 0)?" DISA":"");
5370 hdaa_dump_pin_configs(struct hdaa_devinfo *devinfo)
5372 struct hdaa_widget *w;
5375 device_printf(devinfo->dev, "nid 0x as seq "
5376 "device conn jack loc color misc\n");
5377 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5378 w = hdaa_widget_get(devinfo, i);
5381 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
5383 hdaa_dump_pin_config(w, w->wclass.pin.config);
5388 hdaa_dump_amp(device_t dev, uint32_t cap, const char *banner)
5390 device_printf(dev, " %s amp: 0x%08x\n", banner, cap);
5391 device_printf(dev, " "
5392 "mute=%d step=%d size=%d offset=%d\n",
5393 HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(cap),
5394 HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(cap),
5395 HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(cap),
5396 HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(cap));
5400 hdaa_dump_nodes(struct hdaa_devinfo *devinfo)
5402 struct hdaa_widget *w, *cw;
5406 device_printf(devinfo->dev, "\n");
5407 device_printf(devinfo->dev, "Default Parameter\n");
5408 device_printf(devinfo->dev, "-----------------\n");
5409 hdaa_dump_audio_formats(devinfo->dev,
5410 devinfo->supp_stream_formats,
5411 devinfo->supp_pcm_size_rate);
5412 device_printf(devinfo->dev, " IN amp: 0x%08x\n",
5413 devinfo->inamp_cap);
5414 device_printf(devinfo->dev, " OUT amp: 0x%08x\n",
5415 devinfo->outamp_cap);
5416 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5417 w = hdaa_widget_get(devinfo, i);
5419 device_printf(devinfo->dev, "Ghost widget nid=%d\n", i);
5422 device_printf(devinfo->dev, "\n");
5423 device_printf(devinfo->dev, " nid: %d%s\n", w->nid,
5424 (w->enable == 0) ? " [DISABLED]" : "");
5425 device_printf(devinfo->dev, " Name: %s\n", w->name);
5426 device_printf(devinfo->dev, " Widget cap: 0x%08x\n",
5427 w->param.widget_cap);
5428 if (w->param.widget_cap & 0x0ee1) {
5429 device_printf(devinfo->dev, " ");
5430 if (HDA_PARAM_AUDIO_WIDGET_CAP_LR_SWAP(w->param.widget_cap))
5432 if (HDA_PARAM_AUDIO_WIDGET_CAP_POWER_CTRL(w->param.widget_cap))
5434 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap))
5436 if (HDA_PARAM_AUDIO_WIDGET_CAP_UNSOL_CAP(w->param.widget_cap))
5438 if (HDA_PARAM_AUDIO_WIDGET_CAP_PROC_WIDGET(w->param.widget_cap))
5440 if (HDA_PARAM_AUDIO_WIDGET_CAP_STRIPE(w->param.widget_cap))
5441 printf(" STRIPE(x%d)",
5442 1 << (fls(w->wclass.conv.stripecap) - 1));
5443 j = HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap);
5447 printf(" %dCH", j + 1);
5450 if (w->bindas != -1) {
5451 device_printf(devinfo->dev, " Association: %d (0x%08x)\n",
5452 w->bindas, w->bindseqmask);
5454 if (w->ossmask != 0 || w->ossdev >= 0) {
5455 device_printf(devinfo->dev, " OSS: %s",
5456 hdaa_audio_ctl_ossmixer_mask2allname(w->ossmask, buf, sizeof(buf)));
5458 printf(" (%s)", ossnames[w->ossdev]);
5461 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT ||
5462 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
5463 hdaa_dump_audio_formats(devinfo->dev,
5464 w->param.supp_stream_formats,
5465 w->param.supp_pcm_size_rate);
5466 } else if (w->type ==
5467 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX || w->waspin)
5469 if (w->param.eapdbtl != HDA_INVALID)
5470 device_printf(devinfo->dev, " EAPD: 0x%08x\n",
5472 if (HDA_PARAM_AUDIO_WIDGET_CAP_OUT_AMP(w->param.widget_cap) &&
5473 w->param.outamp_cap != 0)
5474 hdaa_dump_amp(devinfo->dev, w->param.outamp_cap, "Output");
5475 if (HDA_PARAM_AUDIO_WIDGET_CAP_IN_AMP(w->param.widget_cap) &&
5476 w->param.inamp_cap != 0)
5477 hdaa_dump_amp(devinfo->dev, w->param.inamp_cap, " Input");
5478 if (w->nconns > 0) {
5479 device_printf(devinfo->dev, " connections: %d\n", w->nconns);
5480 device_printf(devinfo->dev, " |\n");
5482 for (j = 0; j < w->nconns; j++) {
5483 cw = hdaa_widget_get(devinfo, w->conns[j]);
5484 device_printf(devinfo->dev, " + %s<- nid=%d [%s]",
5485 (w->connsenable[j] == 0)?"[DISABLED] ":"",
5486 w->conns[j], (cw == NULL) ? "GHOST!" : cw->name);
5488 printf(" [UNKNOWN]");
5489 else if (cw->enable == 0)
5490 printf(" [DISABLED]");
5491 if (w->nconns > 1 && w->selconn == j && w->type !=
5492 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
5493 printf(" (selected)");
5501 hdaa_dump_dst_nid(struct hdaa_pcm_devinfo *pdevinfo, nid_t nid, int depth)
5503 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
5504 struct hdaa_widget *w, *cw;
5508 if (depth > HDA_PARSE_MAXDEPTH)
5511 w = hdaa_widget_get(devinfo, nid);
5512 if (w == NULL || w->enable == 0)
5516 device_printf(pdevinfo->dev, "%*s", 4, "");
5518 device_printf(pdevinfo->dev, "%*s + <- ", 4 + (depth - 1) * 7, "");
5519 printf("nid=%d [%s]", w->nid, w->name);
5522 if (w->ossmask == 0) {
5526 printf(" [src: %s]",
5527 hdaa_audio_ctl_ossmixer_mask2allname(
5528 w->ossmask, buf, sizeof(buf)));
5529 if (w->ossdev >= 0) {
5536 for (i = 0; i < w->nconns; i++) {
5537 if (w->connsenable[i] == 0)
5539 cw = hdaa_widget_get(devinfo, w->conns[i]);
5540 if (cw == NULL || cw->enable == 0 || cw->bindas == -1)
5543 device_printf(pdevinfo->dev, "%*s |\n", 4 + (depth) * 7, "");
5546 hdaa_dump_dst_nid(pdevinfo, w->conns[i], depth + 1);
5552 hdaa_dump_dac(struct hdaa_pcm_devinfo *pdevinfo)
5554 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
5555 struct hdaa_audio_as *as;
5556 struct hdaa_widget *w;
5559 if (pdevinfo->playas < 0)
5562 as = &devinfo->as[pdevinfo->playas];
5563 for (i = 0; i < 16; i++) {
5564 if (as->pins[i] <= 0)
5566 w = hdaa_widget_get(devinfo, as->pins[i]);
5567 if (w == NULL || w->enable == 0)
5571 device_printf(pdevinfo->dev, "\n");
5572 device_printf(pdevinfo->dev, "Playback:\n");
5574 device_printf(pdevinfo->dev, "\n");
5575 hdaa_dump_dst_nid(pdevinfo, as->pins[i], 0);
5580 hdaa_dump_adc(struct hdaa_pcm_devinfo *pdevinfo)
5582 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
5583 struct hdaa_widget *w;
5587 if (pdevinfo->recas < 0)
5590 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5591 w = hdaa_widget_get(devinfo, i);
5592 if (w == NULL || w->enable == 0)
5594 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT)
5596 if (w->bindas != pdevinfo->recas)
5600 device_printf(pdevinfo->dev, "\n");
5601 device_printf(pdevinfo->dev, "Record:\n");
5603 device_printf(pdevinfo->dev, "\n");
5604 hdaa_dump_dst_nid(pdevinfo, i, 0);
5609 hdaa_dump_mix(struct hdaa_pcm_devinfo *pdevinfo)
5611 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
5612 struct hdaa_widget *w;
5616 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5617 w = hdaa_widget_get(devinfo, i);
5618 if (w == NULL || w->enable == 0)
5620 if (w->ossdev != SOUND_MIXER_IMIX)
5622 if (w->bindas != pdevinfo->recas)
5626 device_printf(pdevinfo->dev, "\n");
5627 device_printf(pdevinfo->dev, "Input Mix:\n");
5629 device_printf(pdevinfo->dev, "\n");
5630 hdaa_dump_dst_nid(pdevinfo, i, 0);
5635 hdaa_dump_pcmchannels(struct hdaa_pcm_devinfo *pdevinfo)
5637 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
5641 if (pdevinfo->playas >= 0) {
5642 device_printf(pdevinfo->dev, "\n");
5643 device_printf(pdevinfo->dev, "Playback:\n");
5644 device_printf(pdevinfo->dev, "\n");
5645 chid = devinfo->as[pdevinfo->playas].chans[0];
5646 hdaa_dump_audio_formats(pdevinfo->dev,
5647 devinfo->chans[chid].supp_stream_formats,
5648 devinfo->chans[chid].supp_pcm_size_rate);
5649 for (i = 0; i < devinfo->as[pdevinfo->playas].num_chans; i++) {
5650 chid = devinfo->as[pdevinfo->playas].chans[i];
5651 device_printf(pdevinfo->dev, " DAC:");
5652 for (nids = devinfo->chans[chid].io; *nids != -1; nids++)
5653 printf(" %d", *nids);
5657 if (pdevinfo->recas >= 0) {
5658 device_printf(pdevinfo->dev, "\n");
5659 device_printf(pdevinfo->dev, "Record:\n");
5660 device_printf(pdevinfo->dev, "\n");
5661 chid = devinfo->as[pdevinfo->recas].chans[0];
5662 hdaa_dump_audio_formats(pdevinfo->dev,
5663 devinfo->chans[chid].supp_stream_formats,
5664 devinfo->chans[chid].supp_pcm_size_rate);
5665 for (i = 0; i < devinfo->as[pdevinfo->recas].num_chans; i++) {
5666 chid = devinfo->as[pdevinfo->recas].chans[i];
5667 device_printf(pdevinfo->dev, " DAC:");
5668 for (nids = devinfo->chans[chid].io; *nids != -1; nids++)
5669 printf(" %d", *nids);
5676 hdaa_pindump(device_t dev)
5678 struct hdaa_devinfo *devinfo = device_get_softc(dev);
5679 struct hdaa_widget *w;
5680 uint32_t res, pincap, delay;
5683 device_printf(dev, "Dumping AFG pins:\n");
5684 device_printf(dev, "nid 0x as seq "
5685 "device conn jack loc color misc\n");
5686 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5687 w = hdaa_widget_get(devinfo, i);
5688 if (w == NULL || w->type !=
5689 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
5691 hdaa_dump_pin_config(w, w->wclass.pin.config);
5692 pincap = w->wclass.pin.cap;
5693 device_printf(dev, " Caps: %2s %3s %2s %4s %4s",
5694 HDA_PARAM_PIN_CAP_INPUT_CAP(pincap)?"IN":"",
5695 HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap)?"OUT":"",
5696 HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap)?"HP":"",
5697 HDA_PARAM_PIN_CAP_EAPD_CAP(pincap)?"EAPD":"",
5698 HDA_PARAM_PIN_CAP_VREF_CTRL(pincap)?"VREF":"");
5699 if (HDA_PARAM_PIN_CAP_IMP_SENSE_CAP(pincap) ||
5700 HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(pincap)) {
5701 if (HDA_PARAM_PIN_CAP_TRIGGER_REQD(pincap)) {
5704 HDA_CMD_SET_PIN_SENSE(0, w->nid, 0));
5706 res = hda_command(dev,
5707 HDA_CMD_GET_PIN_SENSE(0, w->nid));
5708 if (res != 0x7fffffff && res != 0xffffffff)
5711 } while (++delay < 10000);
5714 res = hda_command(dev, HDA_CMD_GET_PIN_SENSE(0,
5717 printf(" Sense: 0x%08x (%sconnected%s)", res,
5718 (res & HDA_CMD_GET_PIN_SENSE_PRESENCE_DETECT) ?
5720 (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap) &&
5721 (res & HDA_CMD_GET_PIN_SENSE_ELD_VALID)) ?
5722 ", ELD valid" : "");
5724 printf(" delay %dus", delay * 10);
5729 "NumGPIO=%d NumGPO=%d NumGPI=%d GPIWake=%d GPIUnsol=%d\n",
5730 HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap),
5731 HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap),
5732 HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap),
5733 HDA_PARAM_GPIO_COUNT_GPI_WAKE(devinfo->gpio_cap),
5734 HDA_PARAM_GPIO_COUNT_GPI_UNSOL(devinfo->gpio_cap));
5735 hdaa_dump_gpi(devinfo);
5736 hdaa_dump_gpio(devinfo);
5737 hdaa_dump_gpo(devinfo);
5741 hdaa_configure(device_t dev)
5743 struct hdaa_devinfo *devinfo = device_get_softc(dev);
5744 struct hdaa_audio_ctl *ctl;
5748 device_printf(dev, "Applying built-in patches...\n");
5750 hdaa_patch(devinfo);
5752 device_printf(dev, "Applying local patches...\n");
5754 hdaa_local_patch(devinfo);
5755 hdaa_audio_postprocess(devinfo);
5757 device_printf(dev, "Parsing Ctls...\n");
5759 hdaa_audio_ctl_parse(devinfo);
5761 device_printf(dev, "Disabling nonaudio...\n");
5763 hdaa_audio_disable_nonaudio(devinfo);
5765 device_printf(dev, "Disabling useless...\n");
5767 hdaa_audio_disable_useless(devinfo);
5769 device_printf(dev, "Patched pins configuration:\n");
5770 hdaa_dump_pin_configs(devinfo);
5773 device_printf(dev, "Parsing pin associations...\n");
5775 hdaa_audio_as_parse(devinfo);
5777 device_printf(dev, "Building AFG tree...\n");
5779 hdaa_audio_build_tree(devinfo);
5781 device_printf(dev, "Disabling unassociated "
5784 hdaa_audio_disable_unas(devinfo);
5786 device_printf(dev, "Disabling nonselected "
5789 hdaa_audio_disable_notselected(devinfo);
5791 device_printf(dev, "Disabling useless...\n");
5793 hdaa_audio_disable_useless(devinfo);
5795 device_printf(dev, "Disabling "
5796 "crossassociatement connections...\n");
5798 hdaa_audio_disable_crossas(devinfo);
5800 device_printf(dev, "Disabling useless...\n");
5802 hdaa_audio_disable_useless(devinfo);
5804 device_printf(dev, "Binding associations to channels...\n");
5806 hdaa_audio_bind_as(devinfo);
5808 device_printf(dev, "Assigning names to signal sources...\n");
5810 hdaa_audio_assign_names(devinfo);
5812 device_printf(dev, "Preparing PCM devices...\n");
5814 hdaa_prepare_pcms(devinfo);
5816 device_printf(dev, "Assigning mixers to the tree...\n");
5818 hdaa_audio_assign_mixers(devinfo);
5820 device_printf(dev, "Preparing pin controls...\n");
5822 hdaa_audio_prepare_pin_ctrl(devinfo);
5824 device_printf(dev, "AFG commit...\n");
5826 hdaa_audio_commit(devinfo);
5828 device_printf(dev, "Applying direct built-in patches...\n");
5830 hdaa_patch_direct(devinfo);
5832 device_printf(dev, "Pin sense init...\n");
5834 hdaa_sense_init(devinfo);
5836 device_printf(dev, "Creating PCM devices...\n");
5838 hdaa_create_pcms(devinfo);
5841 if (devinfo->quirks != 0) {
5842 device_printf(dev, "FG config/quirks:");
5843 for (i = 0; i < nitems(hdaa_quirks_tab); i++) {
5844 if ((devinfo->quirks &
5845 hdaa_quirks_tab[i].value) ==
5846 hdaa_quirks_tab[i].value)
5847 printf(" %s", hdaa_quirks_tab[i].key);
5852 device_printf(dev, "\n");
5853 device_printf(dev, "+-------------------+\n");
5854 device_printf(dev, "| DUMPING HDA NODES |\n");
5855 device_printf(dev, "+-------------------+\n");
5856 hdaa_dump_nodes(devinfo);
5860 device_printf(dev, "\n");
5861 device_printf(dev, "+------------------------+\n");
5862 device_printf(dev, "| DUMPING HDA AMPLIFIERS |\n");
5863 device_printf(dev, "+------------------------+\n");
5864 device_printf(dev, "\n");
5866 while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) {
5867 device_printf(dev, "%3d: nid %3d %s (%s) index %d", i,
5868 (ctl->widget != NULL) ? ctl->widget->nid : -1,
5869 (ctl->ndir == HDAA_CTL_IN)?"in ":"out",
5870 (ctl->dir == HDAA_CTL_IN)?"in ":"out",
5872 if (ctl->childwidget != NULL)
5873 printf(" cnid %3d", ctl->childwidget->nid);
5876 printf(" ossmask=0x%08x\n",
5879 " mute: %d step: %3d size: %3d off: %3d%s\n",
5880 ctl->mute, ctl->step, ctl->size, ctl->offset,
5881 (ctl->enable == 0) ? " [DISABLED]" :
5882 ((ctl->ossmask == 0) ? " [UNUSED]" : ""));
5887 device_printf(dev, "\n");
5892 hdaa_unconfigure(device_t dev)
5894 struct hdaa_devinfo *devinfo = device_get_softc(dev);
5895 struct hdaa_widget *w;
5899 device_printf(dev, "Pin sense deinit...\n");
5901 hdaa_sense_deinit(devinfo);
5902 free(devinfo->ctl, M_HDAA);
5903 devinfo->ctl = NULL;
5904 devinfo->ctlcnt = 0;
5905 free(devinfo->as, M_HDAA);
5908 free(devinfo->devs, M_HDAA);
5909 devinfo->devs = NULL;
5910 devinfo->num_devs = 0;
5911 free(devinfo->chans, M_HDAA);
5912 devinfo->chans = NULL;
5913 devinfo->num_chans = 0;
5914 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5915 w = hdaa_widget_get(devinfo, i);
5925 for (j = 0; j < w->nconns; j++)
5926 w->connsenable[j] = 1;
5927 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
5928 w->wclass.pin.config = w->wclass.pin.newconf;
5929 if (w->eld != NULL) {
5931 free(w->eld, M_HDAA);
5938 hdaa_sysctl_gpi_state(SYSCTL_HANDLER_ARGS)
5940 struct hdaa_devinfo *devinfo = oidp->oid_arg1;
5941 device_t dev = devinfo->dev;
5943 int n = 0, i, numgpi;
5948 numgpi = HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap);
5950 data = hda_command(dev,
5951 HDA_CMD_GET_GPI_DATA(0, devinfo->nid));
5953 hdaa_unlock(devinfo);
5954 for (i = 0; i < numgpi; i++) {
5955 n += snprintf(buf + n, sizeof(buf) - n, "%s%d=%d",
5956 n != 0 ? " " : "", i, ((data >> i) & 1));
5958 return (sysctl_handle_string(oidp, buf, sizeof(buf), req));
5962 hdaa_sysctl_gpio_state(SYSCTL_HANDLER_ARGS)
5964 struct hdaa_devinfo *devinfo = oidp->oid_arg1;
5965 device_t dev = devinfo->dev;
5967 int n = 0, i, numgpio;
5968 uint32_t data = 0, enable = 0, dir = 0;
5972 numgpio = HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap);
5974 data = hda_command(dev,
5975 HDA_CMD_GET_GPIO_DATA(0, devinfo->nid));
5976 enable = hda_command(dev,
5977 HDA_CMD_GET_GPIO_ENABLE_MASK(0, devinfo->nid));
5978 dir = hda_command(dev,
5979 HDA_CMD_GET_GPIO_DIRECTION(0, devinfo->nid));
5981 hdaa_unlock(devinfo);
5982 for (i = 0; i < numgpio; i++) {
5983 n += snprintf(buf + n, sizeof(buf) - n, "%s%d=",
5984 n != 0 ? " " : "", i);
5985 if ((enable & (1 << i)) == 0) {
5986 n += snprintf(buf + n, sizeof(buf) - n, "disabled");
5989 n += snprintf(buf + n, sizeof(buf) - n, "%sput(%d)",
5990 ((dir >> i) & 1) ? "out" : "in", ((data >> i) & 1));
5992 return (sysctl_handle_string(oidp, buf, sizeof(buf), req));
5996 hdaa_sysctl_gpio_config(SYSCTL_HANDLER_ARGS)
5998 struct hdaa_devinfo *devinfo = oidp->oid_arg1;
6000 int error, n = 0, i, numgpio;
6003 gpio = devinfo->newgpio;
6004 numgpio = HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap);
6006 for (i = 0; i < numgpio; i++) {
6007 x = (gpio & HDAA_GPIO_MASK(i)) >> HDAA_GPIO_SHIFT(i);
6008 n += snprintf(buf + n, sizeof(buf) - n, "%s%d=%s",
6009 n != 0 ? " " : "", i, HDA_GPIO_ACTIONS[x]);
6011 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
6012 if (error != 0 || req->newptr == NULL)
6014 if (strncmp(buf, "0x", 2) == 0)
6015 gpio = strtol(buf + 2, NULL, 16);
6017 gpio = hdaa_gpio_patch(gpio, buf);
6019 devinfo->newgpio = devinfo->gpio = gpio;
6020 hdaa_gpio_commit(devinfo);
6021 hdaa_unlock(devinfo);
6026 hdaa_sysctl_gpo_state(SYSCTL_HANDLER_ARGS)
6028 struct hdaa_devinfo *devinfo = oidp->oid_arg1;
6029 device_t dev = devinfo->dev;
6031 int n = 0, i, numgpo;
6036 numgpo = HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap);
6038 data = hda_command(dev,
6039 HDA_CMD_GET_GPO_DATA(0, devinfo->nid));
6041 hdaa_unlock(devinfo);
6042 for (i = 0; i < numgpo; i++) {
6043 n += snprintf(buf + n, sizeof(buf) - n, "%s%d=%d",
6044 n != 0 ? " " : "", i, ((data >> i) & 1));
6046 return (sysctl_handle_string(oidp, buf, sizeof(buf), req));
6050 hdaa_sysctl_gpo_config(SYSCTL_HANDLER_ARGS)
6052 struct hdaa_devinfo *devinfo = oidp->oid_arg1;
6054 int error, n = 0, i, numgpo;
6057 gpo = devinfo->newgpo;
6058 numgpo = HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap);
6060 for (i = 0; i < numgpo; i++) {
6061 x = (gpo & HDAA_GPIO_MASK(i)) >> HDAA_GPIO_SHIFT(i);
6062 n += snprintf(buf + n, sizeof(buf) - n, "%s%d=%s",
6063 n != 0 ? " " : "", i, HDA_GPIO_ACTIONS[x]);
6065 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
6066 if (error != 0 || req->newptr == NULL)
6068 if (strncmp(buf, "0x", 2) == 0)
6069 gpo = strtol(buf + 2, NULL, 16);
6071 gpo = hdaa_gpio_patch(gpo, buf);
6073 devinfo->newgpo = devinfo->gpo = gpo;
6074 hdaa_gpo_commit(devinfo);
6075 hdaa_unlock(devinfo);
6080 hdaa_sysctl_reconfig(SYSCTL_HANDLER_ARGS)
6083 struct hdaa_devinfo *devinfo;
6086 dev = oidp->oid_arg1;
6087 devinfo = device_get_softc(dev);
6088 if (devinfo == NULL)
6091 error = sysctl_handle_int(oidp, &val, 0, req);
6092 if (error != 0 || req->newptr == NULL || val == 0)
6096 device_printf(dev, "Reconfiguration...\n");
6098 if ((error = device_delete_children(dev)) != 0)
6101 hdaa_unconfigure(dev);
6102 hdaa_configure(dev);
6103 hdaa_unlock(devinfo);
6104 bus_generic_attach(dev);
6106 device_printf(dev, "Reconfiguration done\n");
6112 hdaa_suspend(device_t dev)
6114 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6118 device_printf(dev, "Suspend...\n");
6122 device_printf(dev, "Stop streams...\n");
6124 for (i = 0; i < devinfo->num_chans; i++) {
6125 if (devinfo->chans[i].flags & HDAA_CHN_RUNNING) {
6126 devinfo->chans[i].flags |= HDAA_CHN_SUSPEND;
6127 hdaa_channel_stop(&devinfo->chans[i]);
6131 device_printf(dev, "Power down FG"
6132 " nid=%d to the D3 state...\n",
6135 hda_command(devinfo->dev,
6136 HDA_CMD_SET_POWER_STATE(0,
6137 devinfo->nid, HDA_CMD_POWER_STATE_D3));
6138 callout_stop(&devinfo->poll_jack);
6139 hdaa_unlock(devinfo);
6140 callout_drain(&devinfo->poll_jack);
6142 device_printf(dev, "Suspend done\n");
6148 hdaa_resume(device_t dev)
6150 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6154 device_printf(dev, "Resume...\n");
6158 device_printf(dev, "Power up audio FG nid=%d...\n",
6161 hdaa_powerup(devinfo);
6163 device_printf(dev, "AFG commit...\n");
6165 hdaa_audio_commit(devinfo);
6167 device_printf(dev, "Applying direct built-in patches...\n");
6169 hdaa_patch_direct(devinfo);
6171 device_printf(dev, "Pin sense init...\n");
6173 hdaa_sense_init(devinfo);
6175 hdaa_unlock(devinfo);
6176 for (i = 0; i < devinfo->num_devs; i++) {
6177 struct hdaa_pcm_devinfo *pdevinfo = &devinfo->devs[i];
6179 device_printf(pdevinfo->dev,
6180 "OSS mixer reinitialization...\n");
6182 if (mixer_reinit(pdevinfo->dev) == -1)
6183 device_printf(pdevinfo->dev,
6184 "unable to reinitialize the mixer\n");
6188 device_printf(dev, "Start streams...\n");
6190 for (i = 0; i < devinfo->num_chans; i++) {
6191 if (devinfo->chans[i].flags & HDAA_CHN_SUSPEND) {
6192 devinfo->chans[i].flags &= ~HDAA_CHN_SUSPEND;
6193 hdaa_channel_start(&devinfo->chans[i]);
6196 hdaa_unlock(devinfo);
6198 device_printf(dev, "Resume done\n");
6204 hdaa_probe(device_t dev)
6209 if (hda_get_node_type(dev) != HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO)
6211 pdesc = device_get_desc(device_get_parent(dev));
6212 snprintf(buf, sizeof(buf), "%.*s Audio Function Group",
6213 (int)(strlen(pdesc) - 10), pdesc);
6214 device_set_desc_copy(dev, buf);
6215 return (BUS_PROBE_DEFAULT);
6219 hdaa_attach(device_t dev)
6221 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6223 nid_t nid = hda_get_node_id(dev);
6226 devinfo->lock = HDAC_GET_MTX(device_get_parent(dev), dev);
6228 devinfo->newquirks = -1;
6229 devinfo->newgpio = -1;
6230 devinfo->newgpo = -1;
6231 callout_init(&devinfo->poll_jack, CALLOUT_MPSAFE);
6232 devinfo->poll_ival = hz;
6235 res = hda_command(dev,
6236 HDA_CMD_GET_PARAMETER(0 , nid, HDA_PARAM_SUB_NODE_COUNT));
6237 hdaa_unlock(devinfo);
6239 devinfo->nodecnt = HDA_PARAM_SUB_NODE_COUNT_TOTAL(res);
6240 devinfo->startnode = HDA_PARAM_SUB_NODE_COUNT_START(res);
6241 devinfo->endnode = devinfo->startnode + devinfo->nodecnt;
6244 device_printf(dev, "Subsystem ID: 0x%08x\n",
6245 hda_get_subsystem_id(dev));
6249 "Audio Function Group at nid=%d: %d subnodes %d-%d\n",
6250 nid, devinfo->nodecnt,
6251 devinfo->startnode, devinfo->endnode - 1);
6254 if (devinfo->nodecnt > 0)
6255 devinfo->widget = (struct hdaa_widget *)malloc(
6256 sizeof(*(devinfo->widget)) * devinfo->nodecnt, M_HDAA,
6259 devinfo->widget = NULL;
6263 device_printf(dev, "Powering up...\n");
6265 hdaa_powerup(devinfo);
6267 device_printf(dev, "Parsing audio FG...\n");
6269 hdaa_audio_parse(devinfo);
6271 device_printf(dev, "Original pins configuration:\n");
6272 hdaa_dump_pin_configs(devinfo);
6274 hdaa_configure(dev);
6275 hdaa_unlock(devinfo);
6277 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6278 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6279 "config", CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE,
6280 &devinfo->newquirks, sizeof(&devinfo->newquirks),
6281 hdaa_sysctl_quirks, "A", "Configuration options");
6282 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6283 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6284 "gpi_state", CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
6285 devinfo, sizeof(devinfo),
6286 hdaa_sysctl_gpi_state, "A", "GPI state");
6287 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6288 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6289 "gpio_state", CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
6290 devinfo, sizeof(devinfo),
6291 hdaa_sysctl_gpio_state, "A", "GPIO state");
6292 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6293 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6294 "gpio_config", CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE,
6295 devinfo, sizeof(devinfo),
6296 hdaa_sysctl_gpio_config, "A", "GPIO configuration");
6297 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6298 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6299 "gpo_state", CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
6300 devinfo, sizeof(devinfo),
6301 hdaa_sysctl_gpo_state, "A", "GPO state");
6302 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6303 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6304 "gpo_config", CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE,
6305 devinfo, sizeof(devinfo),
6306 hdaa_sysctl_gpo_config, "A", "GPO configuration");
6307 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6308 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6309 "reconfig", CTLTYPE_INT | CTLFLAG_RW,
6311 hdaa_sysctl_reconfig, "I", "Reprocess configuration");
6312 bus_generic_attach(dev);
6317 hdaa_detach(device_t dev)
6319 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6322 if ((error = device_delete_children(dev)) != 0)
6326 hdaa_unconfigure(dev);
6327 devinfo->poll_ival = 0;
6328 callout_stop(&devinfo->poll_jack);
6329 hdaa_unlock(devinfo);
6330 callout_drain(&devinfo->poll_jack);
6332 free(devinfo->widget, M_HDAA);
6337 hdaa_print_child(device_t dev, device_t child)
6339 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6340 struct hdaa_pcm_devinfo *pdevinfo =
6341 (struct hdaa_pcm_devinfo *)device_get_ivars(child);
6342 struct hdaa_audio_as *as;
6343 int retval, first = 1, i;
6345 retval = bus_print_child_header(dev, child);
6346 retval += printf(" at nid ");
6347 if (pdevinfo->playas >= 0) {
6348 as = &devinfo->as[pdevinfo->playas];
6349 for (i = 0; i < 16; i++) {
6350 if (as->pins[i] <= 0)
6352 retval += printf("%s%d", first ? "" : ",", as->pins[i]);
6356 if (pdevinfo->recas >= 0) {
6357 if (pdevinfo->playas >= 0) {
6358 retval += printf(" and ");
6361 as = &devinfo->as[pdevinfo->recas];
6362 for (i = 0; i < 16; i++) {
6363 if (as->pins[i] <= 0)
6365 retval += printf("%s%d", first ? "" : ",", as->pins[i]);
6369 retval += bus_print_child_footer(dev, child);
6375 hdaa_child_location_str(device_t dev, device_t child, char *buf,
6378 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6379 struct hdaa_pcm_devinfo *pdevinfo =
6380 (struct hdaa_pcm_devinfo *)device_get_ivars(child);
6381 struct hdaa_audio_as *as;
6382 int first = 1, i, len = 0;
6384 len += snprintf(buf + len, buflen - len, "nid=");
6385 if (pdevinfo->playas >= 0) {
6386 as = &devinfo->as[pdevinfo->playas];
6387 for (i = 0; i < 16; i++) {
6388 if (as->pins[i] <= 0)
6390 len += snprintf(buf + len, buflen - len,
6391 "%s%d", first ? "" : ",", as->pins[i]);
6395 if (pdevinfo->recas >= 0) {
6396 as = &devinfo->as[pdevinfo->recas];
6397 for (i = 0; i < 16; i++) {
6398 if (as->pins[i] <= 0)
6400 len += snprintf(buf + len, buflen - len,
6401 "%s%d", first ? "" : ",", as->pins[i]);
6409 hdaa_stream_intr(device_t dev, int dir, int stream)
6411 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6412 struct hdaa_chan *ch;
6415 for (i = 0; i < devinfo->num_chans; i++) {
6416 ch = &devinfo->chans[i];
6417 if (!(ch->flags & HDAA_CHN_RUNNING))
6419 if (ch->dir == ((dir == 1) ? PCMDIR_PLAY : PCMDIR_REC) &&
6420 ch->sid == stream) {
6421 hdaa_unlock(devinfo);
6429 hdaa_unsol_intr(device_t dev, uint32_t resp)
6431 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6432 struct hdaa_widget *w;
6436 device_printf(dev, "Unsolicited response %08x\n", resp);
6439 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
6440 w = hdaa_widget_get(devinfo, i);
6441 if (w == NULL || w->enable == 0 || w->type !=
6442 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
6444 if (w->unsol != tag)
6446 if (HDA_PARAM_PIN_CAP_DP(w->wclass.pin.cap) ||
6447 HDA_PARAM_PIN_CAP_HDMI(w->wclass.pin.cap))
6448 flags = resp & 0x03;
6452 hdaa_presence_handler(w);
6454 hdaa_eld_handler(w);
6458 static device_method_t hdaa_methods[] = {
6459 /* device interface */
6460 DEVMETHOD(device_probe, hdaa_probe),
6461 DEVMETHOD(device_attach, hdaa_attach),
6462 DEVMETHOD(device_detach, hdaa_detach),
6463 DEVMETHOD(device_suspend, hdaa_suspend),
6464 DEVMETHOD(device_resume, hdaa_resume),
6466 DEVMETHOD(bus_print_child, hdaa_print_child),
6467 DEVMETHOD(bus_child_location_str, hdaa_child_location_str),
6468 DEVMETHOD(hdac_stream_intr, hdaa_stream_intr),
6469 DEVMETHOD(hdac_unsol_intr, hdaa_unsol_intr),
6470 DEVMETHOD(hdac_pindump, hdaa_pindump),
6474 static driver_t hdaa_driver = {
6477 sizeof(struct hdaa_devinfo),
6480 static devclass_t hdaa_devclass;
6482 DRIVER_MODULE(snd_hda, hdacc, hdaa_driver, hdaa_devclass, NULL, NULL);
6485 hdaa_chan_formula(struct hdaa_devinfo *devinfo, int asid,
6486 char *buf, int buflen)
6488 struct hdaa_audio_as *as;
6491 as = &devinfo->as[asid];
6492 c = devinfo->chans[as->chans[0]].channels;
6494 snprintf(buf, buflen, "mono");
6496 if (as->hpredir < 0)
6499 snprintf(buf, buflen, "2.0");
6500 } else if (as->pinset == 0x0003)
6501 snprintf(buf, buflen, "3.1");
6502 else if (as->pinset == 0x0005 || as->pinset == 0x0011)
6503 snprintf(buf, buflen, "4.0");
6504 else if (as->pinset == 0x0007 || as->pinset == 0x0013)
6505 snprintf(buf, buflen, "5.1");
6506 else if (as->pinset == 0x0017)
6507 snprintf(buf, buflen, "7.1");
6509 snprintf(buf, buflen, "%dch", c);
6510 if (as->hpredir >= 0)
6511 strlcat(buf, "+HP", buflen);
6515 hdaa_chan_type(struct hdaa_devinfo *devinfo, int asid)
6517 struct hdaa_audio_as *as;
6518 struct hdaa_widget *w;
6521 as = &devinfo->as[asid];
6522 for (i = 0; i < 16; i++) {
6523 w = hdaa_widget_get(devinfo, as->pins[i]);
6524 if (w == NULL || w->enable == 0 || w->type !=
6525 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
6527 t1 = HDA_CONFIG_DEFAULTCONF_DEVICE(w->wclass.pin.config);
6539 hdaa_sysctl_32bit(SYSCTL_HANDLER_ARGS)
6541 struct hdaa_audio_as *as = (struct hdaa_audio_as *)oidp->oid_arg1;
6542 struct hdaa_pcm_devinfo *pdevinfo = as->pdevinfo;
6543 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
6544 struct hdaa_chan *ch;
6548 ch = &devinfo->chans[as->chans[0]];
6549 val = (ch->bit32 == 4) ? 32 : ((ch->bit32 == 3) ? 24 :
6550 ((ch->bit32 == 2) ? 20 : 0));
6551 error = sysctl_handle_int(oidp, &val, 0, req);
6552 if (error != 0 || req->newptr == NULL)
6554 pcmcap = ch->supp_pcm_size_rate;
6555 if (val == 32 && HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(pcmcap))
6557 else if (val == 24 && HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(pcmcap))
6559 else if (val == 20 && HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(pcmcap))
6563 for (i = 1; i < as->num_chans; i++)
6564 devinfo->chans[as->chans[i]].bit32 = ch->bit32;
6569 hdaa_pcm_probe(device_t dev)
6571 struct hdaa_pcm_devinfo *pdevinfo =
6572 (struct hdaa_pcm_devinfo *)device_get_ivars(dev);
6573 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
6575 char chans1[8], chans2[8];
6577 int loc1, loc2, t1, t2;
6579 if (pdevinfo->playas >= 0)
6580 loc1 = devinfo->as[pdevinfo->playas].location;
6582 loc1 = devinfo->as[pdevinfo->recas].location;
6583 if (pdevinfo->recas >= 0)
6584 loc2 = devinfo->as[pdevinfo->recas].location;
6589 if (loc1 >= 0 && HDA_LOCS[loc1][0] == '0')
6594 if (pdevinfo->playas >= 0) {
6595 hdaa_chan_formula(devinfo, pdevinfo->playas,
6596 chans1, sizeof(chans1));
6597 t1 = hdaa_chan_type(devinfo, pdevinfo->playas);
6599 if (pdevinfo->recas >= 0) {
6600 hdaa_chan_formula(devinfo, pdevinfo->recas,
6601 chans2, sizeof(chans2));
6602 t2 = hdaa_chan_type(devinfo, pdevinfo->recas);
6604 if (chans1[0] != 0 || chans2[0] != 0) {
6605 if (chans1[0] == 0 && pdevinfo->playas >= 0)
6606 snprintf(chans1, sizeof(chans1), "2.0");
6607 else if (chans2[0] == 0 && pdevinfo->recas >= 0)
6608 snprintf(chans2, sizeof(chans2), "2.0");
6609 if (strcmp(chans1, chans2) == 0)
6618 if (pdevinfo->digital)
6620 pdesc = device_get_desc(device_get_parent(dev));
6621 snprintf(buf, sizeof(buf), "%.*s (%s%s%s%s%s%s%s%s%s)",
6622 (int)(strlen(pdesc) - 21), pdesc,
6623 loc1 >= 0 ? HDA_LOCS[loc1] : "", loc1 >= 0 ? " " : "",
6624 (pdevinfo->digital == 0x7)?"HDMI/DP":
6625 ((pdevinfo->digital == 0x5)?"DisplayPort":
6626 ((pdevinfo->digital == 0x3)?"HDMI":
6627 ((pdevinfo->digital)?"Digital":"Analog"))),
6628 chans1[0] ? " " : "", chans1,
6629 chans2[0] ? "/" : "", chans2,
6630 t1 >= 0 ? " " : "", t1 >= 0 ? HDA_DEVS[t1] : "");
6631 device_set_desc_copy(dev, buf);
6632 return (BUS_PROBE_SPECIFIC);
6636 hdaa_pcm_attach(device_t dev)
6638 struct hdaa_pcm_devinfo *pdevinfo =
6639 (struct hdaa_pcm_devinfo *)device_get_ivars(dev);
6640 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
6641 struct hdaa_audio_as *as;
6642 struct snddev_info *d;
6643 char status[SND_STATUSLEN];
6646 pdevinfo->chan_size = pcm_getbuffersize(dev,
6647 HDA_BUFSZ_MIN, HDA_BUFSZ_DEFAULT, HDA_BUFSZ_MAX);
6650 device_printf(dev, "+--------------------------------------+\n");
6651 device_printf(dev, "| DUMPING PCM Playback/Record Channels |\n");
6652 device_printf(dev, "+--------------------------------------+\n");
6653 hdaa_dump_pcmchannels(pdevinfo);
6654 device_printf(dev, "\n");
6655 device_printf(dev, "+-------------------------------+\n");
6656 device_printf(dev, "| DUMPING Playback/Record Paths |\n");
6657 device_printf(dev, "+-------------------------------+\n");
6658 hdaa_dump_dac(pdevinfo);
6659 hdaa_dump_adc(pdevinfo);
6660 hdaa_dump_mix(pdevinfo);
6661 device_printf(dev, "\n");
6662 device_printf(dev, "+-------------------------+\n");
6663 device_printf(dev, "| DUMPING Volume Controls |\n");
6664 device_printf(dev, "+-------------------------+\n");
6665 hdaa_dump_ctls(pdevinfo, "Master Volume", SOUND_MASK_VOLUME);
6666 hdaa_dump_ctls(pdevinfo, "PCM Volume", SOUND_MASK_PCM);
6667 hdaa_dump_ctls(pdevinfo, "CD Volume", SOUND_MASK_CD);
6668 hdaa_dump_ctls(pdevinfo, "Microphone Volume", SOUND_MASK_MIC);
6669 hdaa_dump_ctls(pdevinfo, "Microphone2 Volume", SOUND_MASK_MONITOR);
6670 hdaa_dump_ctls(pdevinfo, "Line-in Volume", SOUND_MASK_LINE);
6671 hdaa_dump_ctls(pdevinfo, "Speaker/Beep Volume", SOUND_MASK_SPEAKER);
6672 hdaa_dump_ctls(pdevinfo, "Recording Level", SOUND_MASK_RECLEV);
6673 hdaa_dump_ctls(pdevinfo, "Input Mix Level", SOUND_MASK_IMIX);
6674 hdaa_dump_ctls(pdevinfo, "Input Monitoring Level", SOUND_MASK_IGAIN);
6675 hdaa_dump_ctls(pdevinfo, NULL, 0);
6676 device_printf(dev, "\n");
6679 if (resource_int_value(device_get_name(dev),
6680 device_get_unit(dev), "blocksize", &i) == 0 && i > 0) {
6682 if (i < HDA_BLK_MIN)
6684 pdevinfo->chan_blkcnt = pdevinfo->chan_size / i;
6686 while (pdevinfo->chan_blkcnt >> i)
6688 pdevinfo->chan_blkcnt = 1 << (i - 1);
6689 if (pdevinfo->chan_blkcnt < HDA_BDL_MIN)
6690 pdevinfo->chan_blkcnt = HDA_BDL_MIN;
6691 else if (pdevinfo->chan_blkcnt > HDA_BDL_MAX)
6692 pdevinfo->chan_blkcnt = HDA_BDL_MAX;
6694 pdevinfo->chan_blkcnt = HDA_BDL_DEFAULT;
6697 * We don't register interrupt handler with snd_setup_intr
6698 * in pcm device. Mark pcm device as MPSAFE manually.
6700 pcm_setflags(dev, pcm_getflags(dev) | SD_F_MPSAFE);
6703 device_printf(dev, "OSS mixer initialization...\n");
6705 if (mixer_init(dev, &hdaa_audio_ctl_ossmixer_class, pdevinfo) != 0)
6706 device_printf(dev, "Can't register mixer\n");
6709 device_printf(dev, "Registering PCM channels...\n");
6711 if (pcm_register(dev, pdevinfo, (pdevinfo->playas >= 0)?1:0,
6712 (pdevinfo->recas >= 0)?1:0) != 0)
6713 device_printf(dev, "Can't register PCM\n");
6715 pdevinfo->registered++;
6717 d = device_get_softc(dev);
6718 if (pdevinfo->playas >= 0) {
6719 as = &devinfo->as[pdevinfo->playas];
6720 for (i = 0; i < as->num_chans; i++)
6721 pcm_addchan(dev, PCMDIR_PLAY, &hdaa_channel_class,
6722 &devinfo->chans[as->chans[i]]);
6723 SYSCTL_ADD_PROC(&d->play_sysctl_ctx,
6724 SYSCTL_CHILDREN(d->play_sysctl_tree), OID_AUTO,
6725 "32bit", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
6726 as, sizeof(as), hdaa_sysctl_32bit, "I",
6727 "Resolution of 32bit samples (20/24/32bit)");
6729 if (pdevinfo->recas >= 0) {
6730 as = &devinfo->as[pdevinfo->recas];
6731 for (i = 0; i < as->num_chans; i++)
6732 pcm_addchan(dev, PCMDIR_REC, &hdaa_channel_class,
6733 &devinfo->chans[as->chans[i]]);
6734 SYSCTL_ADD_PROC(&d->rec_sysctl_ctx,
6735 SYSCTL_CHILDREN(d->rec_sysctl_tree), OID_AUTO,
6736 "32bit", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
6737 as, sizeof(as), hdaa_sysctl_32bit, "I",
6738 "Resolution of 32bit samples (20/24/32bit)");
6739 pdevinfo->autorecsrc = 2;
6740 resource_int_value(device_get_name(dev), device_get_unit(dev),
6741 "rec.autosrc", &pdevinfo->autorecsrc);
6742 SYSCTL_ADD_INT(&d->rec_sysctl_ctx,
6743 SYSCTL_CHILDREN(d->rec_sysctl_tree), OID_AUTO,
6744 "autosrc", CTLTYPE_INT | CTLFLAG_RW,
6745 &pdevinfo->autorecsrc, 0,
6746 "Automatic recording source selection");
6749 if (pdevinfo->mixer != NULL) {
6750 hdaa_audio_ctl_set_defaults(pdevinfo);
6751 if (pdevinfo->recas >= 0) {
6752 as = &devinfo->as[pdevinfo->recas];
6754 hdaa_autorecsrc_handler(as, NULL);
6755 hdaa_unlock(devinfo);
6759 snprintf(status, SND_STATUSLEN, "on %s %s",
6760 device_get_nameunit(device_get_parent(dev)),
6761 PCM_KLDSTRING(snd_hda));
6762 pcm_setstatus(dev, status);
6768 hdaa_pcm_detach(device_t dev)
6770 struct hdaa_pcm_devinfo *pdevinfo =
6771 (struct hdaa_pcm_devinfo *)device_get_ivars(dev);
6774 if (pdevinfo->registered > 0) {
6775 err = pcm_unregister(dev);
6783 static device_method_t hdaa_pcm_methods[] = {
6784 /* device interface */
6785 DEVMETHOD(device_probe, hdaa_pcm_probe),
6786 DEVMETHOD(device_attach, hdaa_pcm_attach),
6787 DEVMETHOD(device_detach, hdaa_pcm_detach),
6791 static driver_t hdaa_pcm_driver = {
6797 DRIVER_MODULE(snd_hda_pcm, hdaa, hdaa_pcm_driver, pcm_devclass, NULL, NULL);
6798 MODULE_DEPEND(snd_hda, sound, SOUND_MINVER, SOUND_PREFVER, SOUND_MAXVER);
6799 MODULE_VERSION(snd_hda, 1);