2 * Copyright (c) 2006 Stephane E. Potvin <sepotvin@videotron.ca>
3 * Copyright (c) 2006 Ariff Abdullah <ariff@FreeBSD.org>
4 * Copyright (c) 2008-2012 Alexander Motin <mav@FreeBSD.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * Intel High Definition Audio (Audio function) driver for FreeBSD.
33 #ifdef HAVE_KERNEL_OPTION_HEADERS
37 #include <dev/sound/pcm/sound.h>
39 #include <sys/ctype.h>
40 #include <sys/taskqueue.h>
42 #include <dev/sound/pci/hda/hdac.h>
43 #include <dev/sound/pci/hda/hdaa.h>
44 #include <dev/sound/pci/hda/hda_reg.h>
48 SND_DECLARE_FILE("$FreeBSD$");
50 #define hdaa_lock(devinfo) snd_mtxlock((devinfo)->lock)
51 #define hdaa_unlock(devinfo) snd_mtxunlock((devinfo)->lock)
52 #define hdaa_lockassert(devinfo) snd_mtxassert((devinfo)->lock)
53 #define hdaa_lockowned(devinfo) mtx_owned((devinfo)->lock)
58 } hdaa_quirks_tab[] = {
59 { "softpcmvol", HDAA_QUIRK_SOFTPCMVOL },
60 { "fixedrate", HDAA_QUIRK_FIXEDRATE },
61 { "forcestereo", HDAA_QUIRK_FORCESTEREO },
62 { "eapdinv", HDAA_QUIRK_EAPDINV },
63 { "senseinv", HDAA_QUIRK_SENSEINV },
64 { "ivref50", HDAA_QUIRK_IVREF50 },
65 { "ivref80", HDAA_QUIRK_IVREF80 },
66 { "ivref100", HDAA_QUIRK_IVREF100 },
67 { "ovref50", HDAA_QUIRK_OVREF50 },
68 { "ovref80", HDAA_QUIRK_OVREF80 },
69 { "ovref100", HDAA_QUIRK_OVREF100 },
70 { "ivref", HDAA_QUIRK_IVREF },
71 { "ovref", HDAA_QUIRK_OVREF },
72 { "vref", HDAA_QUIRK_VREF },
74 #define HDAA_QUIRKS_TAB_LEN \
75 (sizeof(hdaa_quirks_tab) / sizeof(hdaa_quirks_tab[0]))
77 #define HDA_PARSE_MAXDEPTH 10
79 MALLOC_DEFINE(M_HDAA, "hdaa", "HDA Audio");
81 const char *HDA_COLORS[16] = {"Unknown", "Black", "Grey", "Blue", "Green", "Red",
82 "Orange", "Yellow", "Purple", "Pink", "Res.A", "Res.B", "Res.C", "Res.D",
85 const char *HDA_DEVS[16] = {"Line-out", "Speaker", "Headphones", "CD",
86 "SPDIF-out", "Digital-out", "Modem-line", "Modem-handset", "Line-in",
87 "AUX", "Mic", "Telephony", "SPDIF-in", "Digital-in", "Res.E", "Other"};
89 const char *HDA_CONNS[4] = {"Jack", "None", "Fixed", "Both"};
91 const char *HDA_CONNECTORS[16] = {
92 "Unknown", "1/8", "1/4", "ATAPI", "RCA", "Optical", "Digital", "Analog",
93 "DIN", "XLR", "RJ-11", "Combo", "0xc", "0xd", "0xe", "Other" };
95 const char *HDA_LOCS[64] = {
96 "0x00", "Rear", "Front", "Left", "Right", "Top", "Bottom", "Rear-panel",
97 "Drive-bay", "0x09", "0x0a", "0x0b", "0x0c", "0x0d", "0x0e", "0x0f",
98 "Internal", "0x11", "0x12", "0x13", "0x14", "0x15", "0x16", "Riser",
99 "0x18", "Onboard", "0x1a", "0x1b", "0x1c", "0x1d", "0x1e", "0x1f",
100 "External", "Ext-Rear", "Ext-Front", "Ext-Left", "Ext-Right", "Ext-Top", "Ext-Bottom", "0x07",
101 "0x28", "0x29", "0x2a", "0x2b", "0x2c", "0x2d", "0x2e", "0x2f",
102 "Other", "0x31", "0x32", "0x33", "0x34", "0x35", "Other-Bott", "Lid-In",
103 "Lid-Out", "0x39", "0x3a", "0x3b", "0x3c", "0x3d", "0x3e", "0x3f" };
105 const char *HDA_GPIO_ACTIONS[8] = {
106 "keep", "set", "clear", "disable", "input", "0x05", "0x06", "0x07"};
108 const char *HDA_HDMI_CODING_TYPES[18] = {
109 "undefined", "LPCM", "AC-3", "MPEG1", "MP3", "MPEG2", "AAC-LC", "DTS",
110 "ATRAC", "DSD", "E-AC-3", "DTS-HD", "MLP", "DST", "WMAPro", "HE-AAC",
111 "HE-AACv2", "MPEG-Surround"
115 static uint32_t hdaa_fmt[] = {
116 SND_FORMAT(AFMT_S16_LE, 2, 0),
120 static struct pcmchan_caps hdaa_caps = {48000, 48000, hdaa_fmt, 0};
122 static const struct {
129 { 8000, 1, 0x0000, 0x0000, 0x0500 }, /* (48000 * 1) / 6 */
130 { 9600, 0, 0x0000, 0x0000, 0x0400 }, /* (48000 * 1) / 5 */
131 { 12000, 0, 0x0000, 0x0000, 0x0300 }, /* (48000 * 1) / 4 */
132 { 16000, 1, 0x0000, 0x0000, 0x0200 }, /* (48000 * 1) / 3 */
133 { 18000, 0, 0x0000, 0x1000, 0x0700 }, /* (48000 * 3) / 8 */
134 { 19200, 0, 0x0000, 0x0800, 0x0400 }, /* (48000 * 2) / 5 */
135 { 24000, 0, 0x0000, 0x0000, 0x0100 }, /* (48000 * 1) / 2 */
136 { 28800, 0, 0x0000, 0x1000, 0x0400 }, /* (48000 * 3) / 5 */
137 { 32000, 1, 0x0000, 0x0800, 0x0200 }, /* (48000 * 2) / 3 */
138 { 36000, 0, 0x0000, 0x1000, 0x0300 }, /* (48000 * 3) / 4 */
139 { 38400, 0, 0x0000, 0x1800, 0x0400 }, /* (48000 * 4) / 5 */
140 { 48000, 1, 0x0000, 0x0000, 0x0000 }, /* (48000 * 1) / 1 */
141 { 64000, 0, 0x0000, 0x1800, 0x0200 }, /* (48000 * 4) / 3 */
142 { 72000, 0, 0x0000, 0x1000, 0x0100 }, /* (48000 * 3) / 2 */
143 { 96000, 1, 0x0000, 0x0800, 0x0000 }, /* (48000 * 2) / 1 */
144 { 144000, 0, 0x0000, 0x1000, 0x0000 }, /* (48000 * 3) / 1 */
145 { 192000, 1, 0x0000, 0x1800, 0x0000 }, /* (48000 * 4) / 1 */
146 { 8820, 0, 0x4000, 0x0000, 0x0400 }, /* (44100 * 1) / 5 */
147 { 11025, 1, 0x4000, 0x0000, 0x0300 }, /* (44100 * 1) / 4 */
148 { 12600, 0, 0x4000, 0x0800, 0x0600 }, /* (44100 * 2) / 7 */
149 { 14700, 0, 0x4000, 0x0000, 0x0200 }, /* (44100 * 1) / 3 */
150 { 17640, 0, 0x4000, 0x0800, 0x0400 }, /* (44100 * 2) / 5 */
151 { 18900, 0, 0x4000, 0x1000, 0x0600 }, /* (44100 * 3) / 7 */
152 { 22050, 1, 0x4000, 0x0000, 0x0100 }, /* (44100 * 1) / 2 */
153 { 25200, 0, 0x4000, 0x1800, 0x0600 }, /* (44100 * 4) / 7 */
154 { 26460, 0, 0x4000, 0x1000, 0x0400 }, /* (44100 * 3) / 5 */
155 { 29400, 0, 0x4000, 0x0800, 0x0200 }, /* (44100 * 2) / 3 */
156 { 33075, 0, 0x4000, 0x1000, 0x0300 }, /* (44100 * 3) / 4 */
157 { 35280, 0, 0x4000, 0x1800, 0x0400 }, /* (44100 * 4) / 5 */
158 { 44100, 1, 0x4000, 0x0000, 0x0000 }, /* (44100 * 1) / 1 */
159 { 58800, 0, 0x4000, 0x1800, 0x0200 }, /* (44100 * 4) / 3 */
160 { 66150, 0, 0x4000, 0x1000, 0x0100 }, /* (44100 * 3) / 2 */
161 { 88200, 1, 0x4000, 0x0800, 0x0000 }, /* (44100 * 2) / 1 */
162 { 132300, 0, 0x4000, 0x1000, 0x0000 }, /* (44100 * 3) / 1 */
163 { 176400, 1, 0x4000, 0x1800, 0x0000 }, /* (44100 * 4) / 1 */
165 #define HDA_RATE_TAB_LEN (sizeof(hda_rate_tab) / sizeof(hda_rate_tab[0]))
167 const static char *ossnames[] = SOUND_DEVICE_NAMES;
169 /****************************************************************************
170 * Function prototypes
171 ****************************************************************************/
172 static int hdaa_pcmchannel_setup(struct hdaa_chan *);
174 static void hdaa_widget_connection_select(struct hdaa_widget *, uint8_t);
175 static void hdaa_audio_ctl_amp_set(struct hdaa_audio_ctl *,
177 static struct hdaa_audio_ctl *hdaa_audio_ctl_amp_get(struct hdaa_devinfo *,
178 nid_t, int, int, int);
179 static void hdaa_audio_ctl_amp_set_internal(struct hdaa_devinfo *,
180 nid_t, int, int, int, int, int, int);
182 static void hdaa_dump_pin_config(struct hdaa_widget *w, uint32_t conf);
185 hdaa_audio_ctl_ossmixer_mask2allname(uint32_t mask, char *buf, size_t len)
190 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
191 if (mask & (1 << i)) {
193 strlcat(buf, ", ", len);
194 strlcat(buf, ossnames[i], len);
201 static struct hdaa_audio_ctl *
202 hdaa_audio_ctl_each(struct hdaa_devinfo *devinfo, int *index)
204 if (devinfo == NULL ||
205 index == NULL || devinfo->ctl == NULL ||
206 devinfo->ctlcnt < 1 ||
207 *index < 0 || *index >= devinfo->ctlcnt)
209 return (&devinfo->ctl[(*index)++]);
212 static struct hdaa_audio_ctl *
213 hdaa_audio_ctl_amp_get(struct hdaa_devinfo *devinfo, nid_t nid, int dir,
216 struct hdaa_audio_ctl *ctl;
219 if (devinfo == NULL || devinfo->ctl == NULL)
223 while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) {
224 if (ctl->enable == 0)
226 if (ctl->widget->nid != nid)
228 if (dir && ctl->ndir != dir)
230 if (index >= 0 && ctl->ndir == HDAA_CTL_IN &&
231 ctl->dir == ctl->ndir && ctl->index != index)
234 if (found == cnt || cnt <= 0)
242 * Headphones redirection change handler.
245 hdaa_hpredir_handler(struct hdaa_widget *w)
247 struct hdaa_devinfo *devinfo = w->devinfo;
248 struct hdaa_audio_as *as = &devinfo->as[w->bindas];
249 struct hdaa_widget *w1;
250 struct hdaa_audio_ctl *ctl;
252 int j, connected = w->wclass.pin.connected;
255 device_printf((as->pdevinfo && as->pdevinfo->dev) ?
256 as->pdevinfo->dev : devinfo->dev,
257 "Redirect output to: %s\n",
258 connected ? "headphones": "main");
260 /* (Un)Mute headphone pin. */
261 ctl = hdaa_audio_ctl_amp_get(devinfo,
262 w->nid, HDAA_CTL_IN, -1, 1);
263 if (ctl != NULL && ctl->mute) {
264 /* If pin has muter - use it. */
265 val = connected ? 0 : 1;
266 if (val != ctl->forcemute) {
267 ctl->forcemute = val;
268 hdaa_audio_ctl_amp_set(ctl,
269 HDAA_AMP_MUTE_DEFAULT,
270 HDAA_AMP_VOL_DEFAULT, HDAA_AMP_VOL_DEFAULT);
273 /* If there is no muter - disable pin output. */
275 val = w->wclass.pin.ctrl |
276 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
278 val = w->wclass.pin.ctrl &
279 ~HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
280 if (val != w->wclass.pin.ctrl) {
281 w->wclass.pin.ctrl = val;
282 hda_command(devinfo->dev,
283 HDA_CMD_SET_PIN_WIDGET_CTRL(0,
284 w->nid, w->wclass.pin.ctrl));
287 /* (Un)Mute other pins. */
288 for (j = 0; j < 15; j++) {
289 if (as->pins[j] <= 0)
291 ctl = hdaa_audio_ctl_amp_get(devinfo,
292 as->pins[j], HDAA_CTL_IN, -1, 1);
293 if (ctl != NULL && ctl->mute) {
294 /* If pin has muter - use it. */
295 val = connected ? 1 : 0;
296 if (val == ctl->forcemute)
298 ctl->forcemute = val;
299 hdaa_audio_ctl_amp_set(ctl,
300 HDAA_AMP_MUTE_DEFAULT,
301 HDAA_AMP_VOL_DEFAULT, HDAA_AMP_VOL_DEFAULT);
304 /* If there is no muter - disable pin output. */
305 w1 = hdaa_widget_get(devinfo, as->pins[j]);
308 val = w1->wclass.pin.ctrl &
309 ~HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
311 val = w1->wclass.pin.ctrl |
312 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
313 if (val != w1->wclass.pin.ctrl) {
314 w1->wclass.pin.ctrl = val;
315 hda_command(devinfo->dev,
316 HDA_CMD_SET_PIN_WIDGET_CTRL(0,
317 w1->nid, w1->wclass.pin.ctrl));
324 * Recording source change handler.
327 hdaa_autorecsrc_handler(struct hdaa_audio_as *as, struct hdaa_widget *w)
329 struct hdaa_pcm_devinfo *pdevinfo = as->pdevinfo;
330 struct hdaa_devinfo *devinfo;
331 struct hdaa_widget *w1;
332 int i, mask, fullmask, prio, bestprio;
335 if (!as->mixed || pdevinfo == NULL || pdevinfo->mixer == NULL)
337 /* Don't touch anything if we asked not to. */
338 if (pdevinfo->autorecsrc == 0 ||
339 (pdevinfo->autorecsrc == 1 && w != NULL))
341 /* Don't touch anything if "mix" or "speaker" selected. */
342 if (pdevinfo->recsrc & (SOUND_MASK_IMIX | SOUND_MASK_SPEAKER))
344 /* Don't touch anything if several selected. */
345 if (ffs(pdevinfo->recsrc) != fls(pdevinfo->recsrc))
347 devinfo = pdevinfo->devinfo;
350 for (i = 0; i < 16; i++) {
351 if (as->pins[i] <= 0)
353 w1 = hdaa_widget_get(devinfo, as->pins[i]);
354 if (w1 == NULL || w1->enable == 0)
356 if (w1->wclass.pin.connected == 0)
358 prio = (w1->wclass.pin.connected == 1) ? 2 : 1;
361 if (prio > bestprio) {
365 mask |= (1 << w1->ossdev);
366 fullmask |= (1 << w1->ossdev);
370 /* Prefer newly connected input. */
371 if (w != NULL && (mask & (1 << w->ossdev)))
372 mask = (1 << w->ossdev);
373 /* Prefer previously selected input */
374 if (mask & pdevinfo->recsrc)
375 mask &= pdevinfo->recsrc;
377 if (mask & SOUND_MASK_MIC)
378 mask = SOUND_MASK_MIC;
379 /* Prefer monitor (2nd mic). */
380 if (mask & SOUND_MASK_MONITOR)
381 mask = SOUND_MASK_MONITOR;
382 /* Just take first one. */
383 mask = (1 << (ffs(mask) - 1));
385 hdaa_audio_ctl_ossmixer_mask2allname(mask, buf, sizeof(buf));
386 device_printf(pdevinfo->dev,
387 "Automatically set rec source to: %s\n", buf);
389 hdaa_unlock(devinfo);
390 mix_setrecsrc(pdevinfo->mixer, mask);
395 * Jack presence detection event handler.
398 hdaa_presence_handler(struct hdaa_widget *w)
400 struct hdaa_devinfo *devinfo = w->devinfo;
401 struct hdaa_audio_as *as;
405 if (w->enable == 0 || w->type !=
406 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
409 if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(w->wclass.pin.cap) == 0 ||
410 (HDA_CONFIG_DEFAULTCONF_MISC(w->wclass.pin.config) & 1) != 0)
413 res = hda_command(devinfo->dev, HDA_CMD_GET_PIN_SENSE(0, w->nid));
414 connected = (res & HDA_CMD_GET_PIN_SENSE_PRESENCE_DETECT) != 0;
415 if (devinfo->quirks & HDAA_QUIRK_SENSEINV)
416 connected = !connected;
417 if (connected == w->wclass.pin.connected)
419 w->wclass.pin.connected = connected;
421 device_printf(devinfo->dev,
422 "Pin sense: nid=%d sence=0x%08x (%sconnected)\n",
423 w->nid, res, !w->wclass.pin.connected ? "dis" : "");
426 as = &devinfo->as[w->bindas];
427 if (as->hpredir >= 0 && as->pins[15] == w->nid)
428 hdaa_hpredir_handler(w);
429 if (as->dir == HDAA_CTL_IN)
430 hdaa_autorecsrc_handler(as, w);
434 * Callback for poll based presence detection.
437 hdaa_jack_poll_callback(void *arg)
439 struct hdaa_devinfo *devinfo = arg;
440 struct hdaa_widget *w;
444 if (devinfo->poll_ival == 0) {
445 hdaa_unlock(devinfo);
448 for (i = 0; i < devinfo->ascnt; i++) {
449 if (devinfo->as[i].hpredir < 0)
451 w = hdaa_widget_get(devinfo, devinfo->as[i].pins[15]);
452 if (w == NULL || w->enable == 0 || w->type !=
453 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
455 hdaa_presence_handler(w);
457 callout_reset(&devinfo->poll_jack, devinfo->poll_ival,
458 hdaa_jack_poll_callback, devinfo);
459 hdaa_unlock(devinfo);
463 hdaa_eld_dump(struct hdaa_widget *w)
465 struct hdaa_devinfo *devinfo = w->devinfo;
466 device_t dev = devinfo->dev;
468 int len, mnl, i, sadc, fmt;
470 if (w->eld == NULL || w->eld_len < 4)
473 "ELD nid=%d: ELD_Ver=%u Baseline_ELD_Len=%u\n",
474 w->nid, w->eld[0] >> 3, w->eld[2]);
475 if ((w->eld[0] >> 3) != 0x02)
477 len = min(w->eld_len, (u_int)w->eld[2] * 4);
478 mnl = w->eld[4] & 0x1f;
480 "ELD nid=%d: CEA_EDID_Ver=%u MNL=%u\n",
481 w->nid, w->eld[4] >> 5, mnl);
482 sadc = w->eld[5] >> 4;
484 "ELD nid=%d: SAD_Count=%u Conn_Type=%u S_AI=%u HDCP=%u\n",
485 w->nid, sadc, (w->eld[5] >> 2) & 0x3,
486 (w->eld[5] >> 1) & 0x1, w->eld[5] & 0x1);
488 "ELD nid=%d: Aud_Synch_Delay=%ums\n",
489 w->nid, w->eld[6] * 2);
491 "ELD nid=%d: Channels=0x%b\n",
493 "\020\07RLRC\06FLRC\05RC\04RLR\03FC\02LFE\01FLR");
495 "ELD nid=%d: Port_ID=0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
496 w->nid, w->eld[8], w->eld[9], w->eld[10], w->eld[11],
497 w->eld[12], w->eld[13], w->eld[14], w->eld[15]);
499 "ELD nid=%d: Manufacturer_Name=0x%02x%02x\n",
500 w->nid, w->eld[16], w->eld[17]);
502 "ELD nid=%d: Product_Code=0x%02x%02x\n",
503 w->nid, w->eld[18], w->eld[19]);
505 "ELD nid=%d: Monitor_Name_String='%.*s'\n",
506 w->nid, mnl, &w->eld[20]);
507 for (i = 0; i < sadc; i++) {
508 sad = &w->eld[20 + mnl + i * 3];
509 fmt = (sad[0] >> 3) & 0x0f;
510 if (fmt == HDA_HDMI_CODING_TYPE_REF_CTX) {
511 fmt = (sad[2] >> 3) & 0x1f;
512 if (fmt < 1 || fmt > 3)
518 "ELD nid=%d: %s %dch freqs=0x%b",
519 w->nid, HDA_HDMI_CODING_TYPES[fmt], (sad[0] & 0x07) + 1,
520 sad[1], "\020\007192\006176\00596\00488\00348\00244\00132");
522 case HDA_HDMI_CODING_TYPE_LPCM:
523 printf(" sizes=0x%b",
524 sad[2] & 0x07, "\020\00324\00220\00116");
526 case HDA_HDMI_CODING_TYPE_AC3:
527 case HDA_HDMI_CODING_TYPE_MPEG1:
528 case HDA_HDMI_CODING_TYPE_MP3:
529 case HDA_HDMI_CODING_TYPE_MPEG2:
530 case HDA_HDMI_CODING_TYPE_AACLC:
531 case HDA_HDMI_CODING_TYPE_DTS:
532 case HDA_HDMI_CODING_TYPE_ATRAC:
533 printf(" max_bitrate=%d", sad[2] * 8000);
535 case HDA_HDMI_CODING_TYPE_WMAPRO:
536 printf(" profile=%d", sad[2] & 0x07);
544 hdaa_eld_handler(struct hdaa_widget *w)
546 struct hdaa_devinfo *devinfo = w->devinfo;
550 if (w->enable == 0 || w->type !=
551 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
554 if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(w->wclass.pin.cap) == 0 ||
555 (HDA_CONFIG_DEFAULTCONF_MISC(w->wclass.pin.config) & 1) != 0)
558 res = hda_command(devinfo->dev, HDA_CMD_GET_PIN_SENSE(0, w->nid));
559 if ((w->eld != 0) == ((res & HDA_CMD_GET_PIN_SENSE_ELD_VALID) != 0))
561 if (w->eld != NULL) {
563 free(w->eld, M_HDAA);
567 device_printf(devinfo->dev,
568 "Pin sense: nid=%d sence=0x%08x "
569 "(%sconnected, ELD %svalid)\n",
571 (res & HDA_CMD_GET_PIN_SENSE_PRESENCE_DETECT) ? "" : "dis",
572 (res & HDA_CMD_GET_PIN_SENSE_ELD_VALID) ? "" : "in");
574 if ((res & HDA_CMD_GET_PIN_SENSE_ELD_VALID) == 0)
577 res = hda_command(devinfo->dev,
578 HDA_CMD_GET_HDMI_DIP_SIZE(0, w->nid, 0x08));
579 if (res == HDA_INVALID)
581 w->eld_len = res & 0xff;
583 w->eld = malloc(w->eld_len, M_HDAA, M_ZERO | M_NOWAIT);
584 if (w->eld == NULL) {
589 for (i = 0; i < w->eld_len; i++) {
590 res = hda_command(devinfo->dev,
591 HDA_CMD_GET_HDMI_ELDD(0, w->nid, i));
592 if (res & 0x80000000)
593 w->eld[i] = res & 0xff;
601 * Pin sense initializer.
604 hdaa_sense_init(struct hdaa_devinfo *devinfo)
606 struct hdaa_audio_as *as;
607 struct hdaa_widget *w;
610 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
611 w = hdaa_widget_get(devinfo, i);
612 if (w == NULL || w->enable == 0 || w->type !=
613 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
615 if (HDA_PARAM_AUDIO_WIDGET_CAP_UNSOL_CAP(w->param.widget_cap)) {
617 w->unsol = HDAC_UNSOL_ALLOC(
618 device_get_parent(devinfo->dev),
619 devinfo->dev, w->nid);
620 hda_command(devinfo->dev,
621 HDA_CMD_SET_UNSOLICITED_RESPONSE(0, w->nid,
622 HDA_CMD_SET_UNSOLICITED_RESPONSE_ENABLE | w->unsol));
624 as = &devinfo->as[w->bindas];
625 if (as->hpredir >= 0 && as->pins[15] == w->nid) {
626 if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(w->wclass.pin.cap) == 0 ||
627 (HDA_CONFIG_DEFAULTCONF_MISC(w->wclass.pin.config) & 1) != 0) {
628 device_printf(devinfo->dev,
629 "No presence detection support at nid %d\n",
635 device_printf(devinfo->dev,
636 "Headphones redirection for "
637 "association %d nid=%d using %s.\n",
639 (w->unsol < 0) ? "polling" :
640 "unsolicited responses");
644 hdaa_presence_handler(w);
645 if (!HDA_PARAM_PIN_CAP_DP(w->wclass.pin.cap) &&
646 !HDA_PARAM_PIN_CAP_HDMI(w->wclass.pin.cap))
651 callout_reset(&devinfo->poll_jack, 1,
652 hdaa_jack_poll_callback, devinfo);
657 hdaa_sense_deinit(struct hdaa_devinfo *devinfo)
659 struct hdaa_widget *w;
662 callout_stop(&devinfo->poll_jack);
663 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
664 w = hdaa_widget_get(devinfo, i);
665 if (w == NULL || w->enable == 0 || w->type !=
666 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
670 hda_command(devinfo->dev,
671 HDA_CMD_SET_UNSOLICITED_RESPONSE(0, w->nid, 0));
673 device_get_parent(devinfo->dev), devinfo->dev,
680 hdaa_widget_pin_patch(uint32_t config, const char *str)
683 char *key, *value, *rest, *bad;
686 strlcpy(buf, str, sizeof(buf));
688 while ((key = strsep(&rest, "=")) != NULL) {
689 value = strsep(&rest, " \t");
692 ival = strtol(value, &bad, 10);
693 if (strcmp(key, "seq") == 0) {
694 config &= ~HDA_CONFIG_DEFAULTCONF_SEQUENCE_MASK;
695 config |= ((ival << HDA_CONFIG_DEFAULTCONF_SEQUENCE_SHIFT) &
696 HDA_CONFIG_DEFAULTCONF_SEQUENCE_MASK);
697 } else if (strcmp(key, "as") == 0) {
698 config &= ~HDA_CONFIG_DEFAULTCONF_ASSOCIATION_MASK;
699 config |= ((ival << HDA_CONFIG_DEFAULTCONF_ASSOCIATION_SHIFT) &
700 HDA_CONFIG_DEFAULTCONF_ASSOCIATION_MASK);
701 } else if (strcmp(key, "misc") == 0) {
702 config &= ~HDA_CONFIG_DEFAULTCONF_MISC_MASK;
703 config |= ((ival << HDA_CONFIG_DEFAULTCONF_MISC_SHIFT) &
704 HDA_CONFIG_DEFAULTCONF_MISC_MASK);
705 } else if (strcmp(key, "color") == 0) {
706 config &= ~HDA_CONFIG_DEFAULTCONF_COLOR_MASK;
708 config |= ((ival << HDA_CONFIG_DEFAULTCONF_COLOR_SHIFT) &
709 HDA_CONFIG_DEFAULTCONF_COLOR_MASK);
711 for (i = 0; i < 16; i++) {
712 if (strcasecmp(HDA_COLORS[i], value) == 0) {
713 config |= (i << HDA_CONFIG_DEFAULTCONF_COLOR_SHIFT);
717 } else if (strcmp(key, "ctype") == 0) {
718 config &= ~HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_MASK;
720 config |= ((ival << HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_SHIFT) &
721 HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_MASK);
723 for (i = 0; i < 16; i++) {
724 if (strcasecmp(HDA_CONNECTORS[i], value) == 0) {
725 config |= (i << HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_SHIFT);
729 } else if (strcmp(key, "device") == 0) {
730 config &= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
732 config |= ((ival << HDA_CONFIG_DEFAULTCONF_DEVICE_SHIFT) &
733 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK);
736 for (i = 0; i < 16; i++) {
737 if (strcasecmp(HDA_DEVS[i], value) == 0) {
738 config |= (i << HDA_CONFIG_DEFAULTCONF_DEVICE_SHIFT);
742 } else if (strcmp(key, "loc") == 0) {
743 config &= ~HDA_CONFIG_DEFAULTCONF_LOCATION_MASK;
745 config |= ((ival << HDA_CONFIG_DEFAULTCONF_LOCATION_SHIFT) &
746 HDA_CONFIG_DEFAULTCONF_LOCATION_MASK);
749 for (i = 0; i < 64; i++) {
750 if (strcasecmp(HDA_LOCS[i], value) == 0) {
751 config |= (i << HDA_CONFIG_DEFAULTCONF_LOCATION_SHIFT);
755 } else if (strcmp(key, "conn") == 0) {
756 config &= ~HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK;
758 config |= ((ival << HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_SHIFT) &
759 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK);
762 for (i = 0; i < 4; i++) {
763 if (strcasecmp(HDA_CONNS[i], value) == 0) {
764 config |= (i << HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_SHIFT);
774 hdaa_gpio_patch(uint32_t gpio, const char *str)
777 char *key, *value, *rest;
780 strlcpy(buf, str, sizeof(buf));
782 while ((key = strsep(&rest, "=")) != NULL) {
783 value = strsep(&rest, " \t");
786 ikey = strtol(key, NULL, 10);
787 if (ikey < 0 || ikey > 7)
789 for (i = 0; i < 7; i++) {
790 if (strcasecmp(HDA_GPIO_ACTIONS[i], value) == 0) {
791 gpio &= ~HDAA_GPIO_MASK(ikey);
792 gpio |= i << HDAA_GPIO_SHIFT(ikey);
801 hdaa_local_patch_pin(struct hdaa_widget *w)
803 device_t dev = w->devinfo->dev;
804 const char *res = NULL;
805 uint32_t config, orig;
808 config = orig = w->wclass.pin.config;
809 snprintf(buf, sizeof(buf), "cad%u.nid%u.config",
810 hda_get_codec_id(dev), w->nid);
811 if (resource_string_value(device_get_name(
812 device_get_parent(device_get_parent(dev))),
813 device_get_unit(device_get_parent(device_get_parent(dev))),
815 if (strncmp(res, "0x", 2) == 0) {
816 config = strtol(res + 2, NULL, 16);
818 config = hdaa_widget_pin_patch(config, res);
821 snprintf(buf, sizeof(buf), "nid%u.config", w->nid);
822 if (resource_string_value(device_get_name(dev), device_get_unit(dev),
824 if (strncmp(res, "0x", 2) == 0) {
825 config = strtol(res + 2, NULL, 16);
827 config = hdaa_widget_pin_patch(config, res);
832 device_printf(w->devinfo->dev,
833 "Patching pin config nid=%u 0x%08x -> 0x%08x\n",
834 w->nid, orig, config);
836 w->wclass.pin.newconf = w->wclass.pin.config = config;
840 hdaa_sysctl_config(SYSCTL_HANDLER_ARGS)
846 conf = *(uint32_t *)oidp->oid_arg1;
847 snprintf(buf, sizeof(buf), "0x%08x as=%d seq=%d "
848 "device=%s conn=%s ctype=%s loc=%s color=%s misc=%d",
850 HDA_CONFIG_DEFAULTCONF_ASSOCIATION(conf),
851 HDA_CONFIG_DEFAULTCONF_SEQUENCE(conf),
852 HDA_DEVS[HDA_CONFIG_DEFAULTCONF_DEVICE(conf)],
853 HDA_CONNS[HDA_CONFIG_DEFAULTCONF_CONNECTIVITY(conf)],
854 HDA_CONNECTORS[HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE(conf)],
855 HDA_LOCS[HDA_CONFIG_DEFAULTCONF_LOCATION(conf)],
856 HDA_COLORS[HDA_CONFIG_DEFAULTCONF_COLOR(conf)],
857 HDA_CONFIG_DEFAULTCONF_MISC(conf));
858 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
859 if (error != 0 || req->newptr == NULL)
861 if (strncmp(buf, "0x", 2) == 0)
862 conf = strtol(buf + 2, NULL, 16);
864 conf = hdaa_widget_pin_patch(conf, buf);
865 *(uint32_t *)oidp->oid_arg1 = conf;
870 hdaa_config_fetch(const char *str, uint32_t *on, uint32_t *off)
872 int i = 0, j, k, len, inv;
875 while (str[i] != '\0' &&
876 (str[i] == ',' || isspace(str[i]) != 0))
881 while (str[j] != '\0' &&
882 !(str[j] == ',' || isspace(str[j]) != 0))
885 if (len > 2 && strncmp(str + i, "no", 2) == 0)
889 for (k = 0; len > inv && k < HDAA_QUIRKS_TAB_LEN; k++) {
890 if (strncmp(str + i + inv,
891 hdaa_quirks_tab[k].key, len - inv) != 0)
893 if (len - inv != strlen(hdaa_quirks_tab[k].key))
896 *on |= hdaa_quirks_tab[k].value;
897 *off &= ~hdaa_quirks_tab[k].value;
899 *off |= hdaa_quirks_tab[k].value;
900 *on &= ~hdaa_quirks_tab[k].value;
909 hdaa_sysctl_quirks(SYSCTL_HANDLER_ARGS)
913 uint32_t quirks, quirks_off;
915 quirks = *(uint32_t *)oidp->oid_arg1;
917 for (i = 0; i < HDAA_QUIRKS_TAB_LEN; i++) {
918 if ((quirks & hdaa_quirks_tab[i].value) != 0)
919 n += snprintf(buf + n, sizeof(buf) - n, "%s%s",
920 n != 0 ? "," : "", hdaa_quirks_tab[i].key);
922 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
923 if (error != 0 || req->newptr == NULL)
925 if (strncmp(buf, "0x", 2) == 0)
926 quirks = strtol(buf + 2, NULL, 16);
929 hdaa_config_fetch(buf, &quirks, &quirks_off);
931 *(uint32_t *)oidp->oid_arg1 = quirks;
936 hdaa_local_patch(struct hdaa_devinfo *devinfo)
938 struct hdaa_widget *w;
939 const char *res = NULL;
940 uint32_t quirks_on = 0, quirks_off = 0, x;
943 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
944 w = hdaa_widget_get(devinfo, i);
947 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
948 hdaa_local_patch_pin(w);
951 if (resource_string_value(device_get_name(devinfo->dev),
952 device_get_unit(devinfo->dev), "config", &res) == 0) {
953 if (res != NULL && strlen(res) > 0)
954 hdaa_config_fetch(res, &quirks_on, &quirks_off);
955 devinfo->quirks |= quirks_on;
956 devinfo->quirks &= ~quirks_off;
958 if (devinfo->newquirks == -1)
959 devinfo->newquirks = devinfo->quirks;
961 devinfo->quirks = devinfo->newquirks;
963 device_printf(devinfo->dev,
964 "Config options: 0x%08x\n", devinfo->quirks);
967 if (resource_string_value(device_get_name(devinfo->dev),
968 device_get_unit(devinfo->dev), "gpio_config", &res) == 0) {
969 if (strncmp(res, "0x", 2) == 0) {
970 devinfo->gpio = strtol(res + 2, NULL, 16);
972 devinfo->gpio = hdaa_gpio_patch(devinfo->gpio, res);
975 if (devinfo->newgpio == -1)
976 devinfo->newgpio = devinfo->gpio;
978 devinfo->gpio = devinfo->newgpio;
979 if (devinfo->newgpo == -1)
980 devinfo->newgpo = devinfo->gpo;
982 devinfo->gpo = devinfo->newgpo;
984 device_printf(devinfo->dev, "GPIO config options:");
985 for (i = 0; i < 7; i++) {
986 x = (devinfo->gpio & HDAA_GPIO_MASK(i)) >> HDAA_GPIO_SHIFT(i);
988 printf(" %d=%s", i, HDA_GPIO_ACTIONS[x]);
995 hdaa_widget_connection_parse(struct hdaa_widget *w)
998 int i, j, max, ents, entnum;
1000 nid_t cnid, addcnid, prevcnid;
1004 res = hda_command(w->devinfo->dev,
1005 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_CONN_LIST_LENGTH));
1007 ents = HDA_PARAM_CONN_LIST_LENGTH_LIST_LENGTH(res);
1012 entnum = HDA_PARAM_CONN_LIST_LENGTH_LONG_FORM(res) ? 2 : 4;
1013 max = (sizeof(w->conns) / sizeof(w->conns[0])) - 1;
1016 #define CONN_RMASK(e) (1 << ((32 / (e)) - 1))
1017 #define CONN_NMASK(e) (CONN_RMASK(e) - 1)
1018 #define CONN_RESVAL(r, e, n) ((r) >> ((32 / (e)) * (n)))
1019 #define CONN_RANGE(r, e, n) (CONN_RESVAL(r, e, n) & CONN_RMASK(e))
1020 #define CONN_CNID(r, e, n) (CONN_RESVAL(r, e, n) & CONN_NMASK(e))
1022 for (i = 0; i < ents; i += entnum) {
1023 res = hda_command(w->devinfo->dev,
1024 HDA_CMD_GET_CONN_LIST_ENTRY(0, nid, i));
1025 for (j = 0; j < entnum; j++) {
1026 cnid = CONN_CNID(res, entnum, j);
1028 if (w->nconns < ents)
1029 device_printf(w->devinfo->dev,
1030 "WARNING: nid=%d has zero cnid "
1031 "entnum=%d j=%d index=%d "
1032 "entries=%d found=%d res=0x%08x\n",
1034 ents, w->nconns, res);
1038 if (cnid < w->devinfo->startnode ||
1039 cnid >= w->devinfo->endnode) {
1041 device_printf(w->devinfo->dev,
1042 "WARNING: nid=%d has cnid outside "
1043 "of the AFG range j=%d "
1044 "entnum=%d index=%d res=0x%08x\n",
1045 nid, j, entnum, i, res);
1048 if (CONN_RANGE(res, entnum, j) == 0)
1050 else if (prevcnid == 0 || prevcnid >= cnid) {
1051 device_printf(w->devinfo->dev,
1052 "WARNING: Invalid child range "
1053 "nid=%d index=%d j=%d entnum=%d "
1054 "prevcnid=%d cnid=%d res=0x%08x\n",
1055 nid, i, j, entnum, prevcnid,
1059 addcnid = prevcnid + 1;
1060 while (addcnid <= cnid) {
1061 if (w->nconns > max) {
1062 device_printf(w->devinfo->dev,
1063 "Adding %d (nid=%d): "
1064 "Max connection reached! max=%d\n",
1065 addcnid, nid, max + 1);
1068 w->connsenable[w->nconns] = 1;
1069 w->conns[w->nconns++] = addcnid++;
1080 hdaa_widget_parse(struct hdaa_widget *w)
1082 device_t dev = w->devinfo->dev;
1087 w->param.widget_cap = wcap = hda_command(dev,
1088 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_AUDIO_WIDGET_CAP));
1089 w->type = HDA_PARAM_AUDIO_WIDGET_CAP_TYPE(wcap);
1091 hdaa_widget_connection_parse(w);
1093 if (HDA_PARAM_AUDIO_WIDGET_CAP_OUT_AMP(wcap)) {
1094 if (HDA_PARAM_AUDIO_WIDGET_CAP_AMP_OVR(wcap))
1095 w->param.outamp_cap =
1097 HDA_CMD_GET_PARAMETER(0, nid,
1098 HDA_PARAM_OUTPUT_AMP_CAP));
1100 w->param.outamp_cap =
1101 w->devinfo->outamp_cap;
1103 w->param.outamp_cap = 0;
1105 if (HDA_PARAM_AUDIO_WIDGET_CAP_IN_AMP(wcap)) {
1106 if (HDA_PARAM_AUDIO_WIDGET_CAP_AMP_OVR(wcap))
1107 w->param.inamp_cap =
1109 HDA_CMD_GET_PARAMETER(0, nid,
1110 HDA_PARAM_INPUT_AMP_CAP));
1112 w->param.inamp_cap =
1113 w->devinfo->inamp_cap;
1115 w->param.inamp_cap = 0;
1117 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT ||
1118 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
1119 if (HDA_PARAM_AUDIO_WIDGET_CAP_FORMAT_OVR(wcap)) {
1120 cap = hda_command(dev,
1121 HDA_CMD_GET_PARAMETER(0, nid,
1122 HDA_PARAM_SUPP_STREAM_FORMATS));
1123 w->param.supp_stream_formats = (cap != 0) ? cap :
1124 w->devinfo->supp_stream_formats;
1125 cap = hda_command(dev,
1126 HDA_CMD_GET_PARAMETER(0, nid,
1127 HDA_PARAM_SUPP_PCM_SIZE_RATE));
1128 w->param.supp_pcm_size_rate = (cap != 0) ? cap :
1129 w->devinfo->supp_pcm_size_rate;
1131 w->param.supp_stream_formats =
1132 w->devinfo->supp_stream_formats;
1133 w->param.supp_pcm_size_rate =
1134 w->devinfo->supp_pcm_size_rate;
1136 if (HDA_PARAM_AUDIO_WIDGET_CAP_STRIPE(w->param.widget_cap)) {
1137 w->wclass.conv.stripecap = hda_command(dev,
1138 HDA_CMD_GET_STRIPE_CONTROL(0, w->nid)) >> 20;
1140 w->wclass.conv.stripecap = 1;
1142 w->param.supp_stream_formats = 0;
1143 w->param.supp_pcm_size_rate = 0;
1146 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) {
1147 w->wclass.pin.original = w->wclass.pin.newconf =
1148 w->wclass.pin.config = hda_command(dev,
1149 HDA_CMD_GET_CONFIGURATION_DEFAULT(0, w->nid));
1150 w->wclass.pin.cap = hda_command(dev,
1151 HDA_CMD_GET_PARAMETER(0, w->nid, HDA_PARAM_PIN_CAP));;
1152 w->wclass.pin.ctrl = hda_command(dev,
1153 HDA_CMD_GET_PIN_WIDGET_CTRL(0, nid));
1154 if (HDA_PARAM_PIN_CAP_EAPD_CAP(w->wclass.pin.cap)) {
1155 w->param.eapdbtl = hda_command(dev,
1156 HDA_CMD_GET_EAPD_BTL_ENABLE(0, nid));
1157 w->param.eapdbtl &= 0x7;
1158 w->param.eapdbtl |= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
1160 w->param.eapdbtl = HDA_INVALID;
1162 hdaa_unlock(w->devinfo);
1163 snprintf(buf, sizeof(buf), "nid%d_config", w->nid);
1164 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
1165 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
1166 buf, CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE,
1167 &w->wclass.pin.newconf, sizeof(&w->wclass.pin.newconf),
1168 hdaa_sysctl_config, "A", "Current pin configuration");
1169 snprintf(buf, sizeof(buf), "nid%d_original", w->nid);
1170 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
1171 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
1172 buf, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
1173 &w->wclass.pin.original, sizeof(&w->wclass.pin.original),
1174 hdaa_sysctl_config, "A", "Original pin configuration");
1175 hdaa_lock(w->devinfo);
1181 hdaa_widget_postprocess(struct hdaa_widget *w)
1185 w->type = HDA_PARAM_AUDIO_WIDGET_CAP_TYPE(w->param.widget_cap);
1187 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT:
1188 typestr = "audio output";
1190 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT:
1191 typestr = "audio input";
1193 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER:
1194 typestr = "audio mixer";
1196 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR:
1197 typestr = "audio selector";
1199 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
1202 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_POWER_WIDGET:
1203 typestr = "power widget";
1205 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_VOLUME_WIDGET:
1206 typestr = "volume widget";
1208 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET:
1209 typestr = "beep widget";
1211 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_VENDOR_WIDGET:
1212 typestr = "vendor widget";
1215 typestr = "unknown type";
1218 strlcpy(w->name, typestr, sizeof(w->name));
1220 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) {
1225 config = w->wclass.pin.config;
1226 devstr = HDA_DEVS[(config & HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) >>
1227 HDA_CONFIG_DEFAULTCONF_DEVICE_SHIFT];
1228 conn = (config & HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK) >>
1229 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_SHIFT;
1230 color = (config & HDA_CONFIG_DEFAULTCONF_COLOR_MASK) >>
1231 HDA_CONFIG_DEFAULTCONF_COLOR_SHIFT;
1232 strlcat(w->name, ": ", sizeof(w->name));
1233 strlcat(w->name, devstr, sizeof(w->name));
1234 strlcat(w->name, " (", sizeof(w->name));
1235 if (conn == 0 && color != 0 && color != 15) {
1236 strlcat(w->name, HDA_COLORS[color], sizeof(w->name));
1237 strlcat(w->name, " ", sizeof(w->name));
1239 strlcat(w->name, HDA_CONNS[conn], sizeof(w->name));
1240 strlcat(w->name, ")", sizeof(w->name));
1242 if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(w->wclass.pin.cap) == 0 ||
1243 (HDA_CONFIG_DEFAULTCONF_MISC(w->wclass.pin.config) & 1) != 0)
1244 w->wclass.pin.connected = 2;
1248 struct hdaa_widget *
1249 hdaa_widget_get(struct hdaa_devinfo *devinfo, nid_t nid)
1251 if (devinfo == NULL || devinfo->widget == NULL ||
1252 nid < devinfo->startnode || nid >= devinfo->endnode)
1254 return (&devinfo->widget[nid - devinfo->startnode]);
1258 hdaa_audio_ctl_amp_set_internal(struct hdaa_devinfo *devinfo, nid_t nid,
1259 int index, int lmute, int rmute,
1260 int left, int right, int dir)
1265 device_printf(devinfo->dev,
1266 "Setting amplifier nid=%d index=%d %s mute=%d/%d vol=%d/%d\n",
1267 nid,index,dir ? "in" : "out",lmute,rmute,left,right);
1269 if (left != right || lmute != rmute) {
1270 v = (1 << (15 - dir)) | (1 << 13) | (index << 8) |
1271 (lmute << 7) | left;
1272 hda_command(devinfo->dev,
1273 HDA_CMD_SET_AMP_GAIN_MUTE(0, nid, v));
1274 v = (1 << (15 - dir)) | (1 << 12) | (index << 8) |
1275 (rmute << 7) | right;
1277 v = (1 << (15 - dir)) | (3 << 12) | (index << 8) |
1278 (lmute << 7) | left;
1280 hda_command(devinfo->dev,
1281 HDA_CMD_SET_AMP_GAIN_MUTE(0, nid, v));
1285 hdaa_audio_ctl_amp_set(struct hdaa_audio_ctl *ctl, uint32_t mute,
1286 int left, int right)
1291 nid = ctl->widget->nid;
1293 /* Save new values if valid. */
1294 if (mute != HDAA_AMP_MUTE_DEFAULT)
1296 if (left != HDAA_AMP_VOL_DEFAULT)
1298 if (right != HDAA_AMP_VOL_DEFAULT)
1300 /* Prepare effective values */
1301 if (ctl->forcemute) {
1307 lmute = HDAA_AMP_LEFT_MUTED(ctl->muted);
1308 rmute = HDAA_AMP_RIGHT_MUTED(ctl->muted);
1312 /* Apply effective values */
1313 if (ctl->dir & HDAA_CTL_OUT)
1314 hdaa_audio_ctl_amp_set_internal(ctl->widget->devinfo, nid, ctl->index,
1315 lmute, rmute, left, right, 0);
1316 if (ctl->dir & HDAA_CTL_IN)
1317 hdaa_audio_ctl_amp_set_internal(ctl->widget->devinfo, nid, ctl->index,
1318 lmute, rmute, left, right, 1);
1322 hdaa_widget_connection_select(struct hdaa_widget *w, uint8_t index)
1324 if (w == NULL || w->nconns < 1 || index > (w->nconns - 1))
1327 device_printf(w->devinfo->dev,
1328 "Setting selector nid=%d index=%d\n", w->nid, index);
1330 hda_command(w->devinfo->dev,
1331 HDA_CMD_SET_CONNECTION_SELECT_CONTROL(0, w->nid, index));
1335 /****************************************************************************
1337 ****************************************************************************/
1340 hdaa_channel_init(kobj_t obj, void *data, struct snd_dbuf *b,
1341 struct pcm_channel *c, int dir)
1343 struct hdaa_chan *ch = data;
1344 struct hdaa_pcm_devinfo *pdevinfo = ch->pdevinfo;
1345 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
1348 if (devinfo->quirks & HDAA_QUIRK_FIXEDRATE) {
1349 ch->caps.minspeed = ch->caps.maxspeed = 48000;
1350 ch->pcmrates[0] = 48000;
1351 ch->pcmrates[1] = 0;
1356 ch->blksz = pdevinfo->chan_size / pdevinfo->chan_blkcnt;
1357 ch->blkcnt = pdevinfo->chan_blkcnt;
1358 hdaa_unlock(devinfo);
1360 if (sndbuf_alloc(ch->b, bus_get_dma_tag(devinfo->dev),
1361 hda_get_dma_nocache(devinfo->dev) ? BUS_DMA_NOCACHE : 0,
1362 pdevinfo->chan_size) != 0)
1369 hdaa_channel_setformat(kobj_t obj, void *data, uint32_t format)
1371 struct hdaa_chan *ch = data;
1374 for (i = 0; ch->caps.fmtlist[i] != 0; i++) {
1375 if (format == ch->caps.fmtlist[i]) {
1385 hdaa_channel_setspeed(kobj_t obj, void *data, uint32_t speed)
1387 struct hdaa_chan *ch = data;
1388 uint32_t spd = 0, threshold;
1391 /* First look for equal or multiple frequency. */
1392 for (i = 0; ch->pcmrates[i] != 0; i++) {
1393 spd = ch->pcmrates[i];
1394 if (speed != 0 && spd / speed * speed == spd) {
1399 /* If no match, just find nearest. */
1400 for (i = 0; ch->pcmrates[i] != 0; i++) {
1401 spd = ch->pcmrates[i];
1402 threshold = spd + ((ch->pcmrates[i + 1] != 0) ?
1403 ((ch->pcmrates[i + 1] - spd) >> 1) : 0);
1404 if (speed < threshold)
1412 hdaa_stream_format(struct hdaa_chan *ch)
1418 if (ch->fmt & AFMT_S16_LE)
1419 fmt |= ch->bit16 << 4;
1420 else if (ch->fmt & AFMT_S32_LE)
1421 fmt |= ch->bit32 << 4;
1424 for (i = 0; i < HDA_RATE_TAB_LEN; i++) {
1425 if (hda_rate_tab[i].valid && ch->spd == hda_rate_tab[i].rate) {
1426 fmt |= hda_rate_tab[i].base;
1427 fmt |= hda_rate_tab[i].mul;
1428 fmt |= hda_rate_tab[i].div;
1432 fmt |= (AFMT_CHANNEL(ch->fmt) - 1);
1438 hdaa_allowed_stripes(uint16_t fmt)
1440 static const int bits[8] = { 8, 16, 20, 24, 32, 32, 32, 32 };
1443 size = bits[(fmt >> 4) & 0x03];
1444 size *= (fmt & 0x0f) + 1;
1445 size *= ((fmt >> 11) & 0x07) + 1;
1446 return (0xffffffffU >> (32 - fls(size / 8)));
1450 hdaa_audio_setup(struct hdaa_chan *ch)
1452 struct hdaa_audio_as *as = &ch->devinfo->as[ch->as];
1453 struct hdaa_widget *w, *wp;
1454 int i, j, k, chn, cchn, totalchn, totalextchn, c;
1456 /* Mapping channel pairs to codec pins/converters. */
1457 const static uint16_t convmap[2][5] =
1458 {{ 0x0010, 0x0001, 0x0201, 0x0231, 0x0231 }, /* 5.1 */
1459 { 0x0010, 0x0001, 0x2001, 0x2031, 0x2431 }};/* 7.1 */
1460 /* Mapping formats to HDMI channel allocations. */
1461 const static uint8_t hdmica[2][8] =
1462 {{ 0x02, 0x00, 0x04, 0x08, 0x0a, 0x0e, 0x12, 0x12 }, /* x.0 */
1463 { 0x01, 0x03, 0x01, 0x03, 0x09, 0x0b, 0x0f, 0x13 }}; /* x.1 */
1464 /* Mapping formats to HDMI channels order. */
1465 const static uint32_t hdmich[2][8] =
1466 {{ 0xFFFF0F00, 0xFFFFFF10, 0xFFF2FF10, 0xFF32FF10,
1467 0xFF324F10, 0xF5324F10, 0x54326F10, 0x54326F10 }, /* x.0 */
1468 { 0xFFFFF000, 0xFFFF0100, 0xFFFFF210, 0xFFFF2310,
1469 0xFF32F410, 0xFF324510, 0xF6324510, 0x76325410 }}; /* x.1 */
1474 totalchn = AFMT_CHANNEL(ch->fmt);
1475 totalextchn = AFMT_EXTCHANNEL(ch->fmt);
1477 device_printf(ch->pdevinfo->dev,
1478 "PCMDIR_%s: Stream setup fmt=%08x (%d.%d) speed=%d\n",
1479 (ch->dir == PCMDIR_PLAY) ? "PLAY" : "REC",
1480 ch->fmt, totalchn - totalextchn, totalextchn, ch->spd);
1482 fmt = hdaa_stream_format(ch);
1484 /* Set channels to I/O converters mapping for known speaker setups. */
1485 if ((as->pinset == 0x0007 || as->pinset == 0x0013)) /* Standard 5.1 */
1487 else if (as->pinset == 0x0017) /* Standard 7.1 */
1490 dfmt = HDA_CMD_SET_DIGITAL_CONV_FMT1_DIGEN;
1491 if (ch->fmt & AFMT_AC3)
1492 dfmt |= HDA_CMD_SET_DIGITAL_CONV_FMT1_NAUDIO;
1495 for (i = 0; ch->io[i] != -1; i++) {
1496 w = hdaa_widget_get(ch->devinfo, ch->io[i]);
1500 /* If HP redirection is enabled, but failed to use same
1501 DAC, make last DAC to duplicate first one. */
1502 if (as->fakeredir && i == (as->pincnt - 1)) {
1505 /* Map channels to I/O converters, if set. */
1507 chn = (((convmap[convmapid][totalchn / 2]
1508 >> i * 4) & 0xf) - 1) * 2;
1509 if (chn < 0 || chn >= totalchn) {
1512 c = (ch->sid << 4) | chn;
1515 hda_command(ch->devinfo->dev,
1516 HDA_CMD_SET_CONV_FMT(0, ch->io[i], fmt));
1517 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) {
1518 hda_command(ch->devinfo->dev,
1519 HDA_CMD_SET_DIGITAL_CONV_FMT1(0, ch->io[i], dfmt));
1521 hda_command(ch->devinfo->dev,
1522 HDA_CMD_SET_CONV_STREAM_CHAN(0, ch->io[i], c));
1523 if (HDA_PARAM_AUDIO_WIDGET_CAP_STRIPE(w->param.widget_cap)) {
1524 hda_command(ch->devinfo->dev,
1525 HDA_CMD_SET_STRIPE_CONTROL(0, w->nid, ch->stripectl));
1527 cchn = HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap);
1528 if (cchn > 1 && chn < totalchn) {
1529 cchn = min(cchn, totalchn - chn - 1);
1530 hda_command(ch->devinfo->dev,
1531 HDA_CMD_SET_CONV_CHAN_COUNT(0, ch->io[i], cchn));
1534 device_printf(ch->pdevinfo->dev,
1535 "PCMDIR_%s: Stream setup nid=%d: "
1536 "fmt=0x%04x, dfmt=0x%04x, chan=0x%04x, "
1537 "chan_count=0x%02x, stripe=%d\n",
1538 (ch->dir == PCMDIR_PLAY) ? "PLAY" : "REC",
1539 ch->io[i], fmt, dfmt, c, cchn, ch->stripectl);
1541 for (j = 0; j < 16; j++) {
1542 if (as->dacs[ch->asindex][j] != ch->io[i])
1545 wp = hdaa_widget_get(ch->devinfo, nid);
1548 if (!HDA_PARAM_PIN_CAP_DP(wp->wclass.pin.cap) &&
1549 !HDA_PARAM_PIN_CAP_HDMI(wp->wclass.pin.cap))
1552 /* Set channel mapping. */
1553 for (k = 0; k < 8; k++) {
1554 hda_command(ch->devinfo->dev,
1555 HDA_CMD_SET_HDMI_CHAN_SLOT(0, nid,
1556 (((hdmich[totalextchn == 0 ? 0 : 1][totalchn - 1]
1557 >> (k * 4)) & 0xf) << 4) | k));
1561 * Enable High Bit Rate (HBR) Encoded Packet Type
1562 * (EPT), if supported and needed (8ch data).
1564 if (HDA_PARAM_PIN_CAP_HDMI(wp->wclass.pin.cap) &&
1565 HDA_PARAM_PIN_CAP_HBR(wp->wclass.pin.cap)) {
1566 wp->wclass.pin.ctrl &=
1567 ~HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK;
1568 if ((ch->fmt & AFMT_AC3) && (cchn == 7))
1569 wp->wclass.pin.ctrl |= 0x03;
1570 hda_command(ch->devinfo->dev,
1571 HDA_CMD_SET_PIN_WIDGET_CTRL(0, nid,
1572 wp->wclass.pin.ctrl));
1575 /* Stop audio infoframe transmission. */
1576 hda_command(ch->devinfo->dev,
1577 HDA_CMD_SET_HDMI_DIP_INDEX(0, nid, 0x00));
1578 hda_command(ch->devinfo->dev,
1579 HDA_CMD_SET_HDMI_DIP_XMIT(0, nid, 0x00));
1581 /* Clear audio infoframe buffer. */
1582 hda_command(ch->devinfo->dev,
1583 HDA_CMD_SET_HDMI_DIP_INDEX(0, nid, 0x00));
1584 for (k = 0; k < 32; k++)
1585 hda_command(ch->devinfo->dev,
1586 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x00));
1588 /* Write HDMI/DisplayPort audio infoframe. */
1589 hda_command(ch->devinfo->dev,
1590 HDA_CMD_SET_HDMI_DIP_INDEX(0, nid, 0x00));
1591 if (w->eld != NULL && w->eld_len >= 6 &&
1592 ((w->eld[5] >> 2) & 0x3) == 1) { /* DisplayPort */
1593 hda_command(ch->devinfo->dev,
1594 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x84));
1595 hda_command(ch->devinfo->dev,
1596 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x1b));
1597 hda_command(ch->devinfo->dev,
1598 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x44));
1600 hda_command(ch->devinfo->dev,
1601 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x84));
1602 hda_command(ch->devinfo->dev,
1603 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x01));
1604 hda_command(ch->devinfo->dev,
1605 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x0a));
1607 csum -= 0x84 + 0x01 + 0x0a + (totalchn - 1) +
1608 hdmica[totalextchn == 0 ? 0 : 1][totalchn - 1];
1609 hda_command(ch->devinfo->dev,
1610 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, csum));
1612 hda_command(ch->devinfo->dev,
1613 HDA_CMD_SET_HDMI_DIP_DATA(0, nid, totalchn - 1));
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, 0x00));
1618 hda_command(ch->devinfo->dev,
1619 HDA_CMD_SET_HDMI_DIP_DATA(0, nid,
1620 hdmica[totalextchn == 0 ? 0 : 1][totalchn - 1]));
1622 /* Start audio infoframe transmission. */
1623 hda_command(ch->devinfo->dev,
1624 HDA_CMD_SET_HDMI_DIP_INDEX(0, nid, 0x00));
1625 hda_command(ch->devinfo->dev,
1626 HDA_CMD_SET_HDMI_DIP_XMIT(0, nid, 0xc0));
1633 * Greatest Common Divisor.
1636 gcd(unsigned a, unsigned b)
1649 * Least Common Multiple.
1652 lcm(unsigned a, unsigned b)
1655 return ((a * b) / gcd(a, b));
1659 hdaa_channel_setfragments(kobj_t obj, void *data,
1660 uint32_t blksz, uint32_t blkcnt)
1662 struct hdaa_chan *ch = data;
1664 blksz -= blksz % lcm(HDA_DMA_ALIGNMENT, sndbuf_getalign(ch->b));
1666 if (blksz > (sndbuf_getmaxsize(ch->b) / HDA_BDL_MIN))
1667 blksz = sndbuf_getmaxsize(ch->b) / HDA_BDL_MIN;
1668 if (blksz < HDA_BLK_MIN)
1669 blksz = HDA_BLK_MIN;
1670 if (blkcnt > HDA_BDL_MAX)
1671 blkcnt = HDA_BDL_MAX;
1672 if (blkcnt < HDA_BDL_MIN)
1673 blkcnt = HDA_BDL_MIN;
1675 while ((blksz * blkcnt) > sndbuf_getmaxsize(ch->b)) {
1676 if ((blkcnt >> 1) >= HDA_BDL_MIN)
1678 else if ((blksz >> 1) >= HDA_BLK_MIN)
1684 if ((sndbuf_getblksz(ch->b) != blksz ||
1685 sndbuf_getblkcnt(ch->b) != blkcnt) &&
1686 sndbuf_resize(ch->b, blkcnt, blksz) != 0)
1687 device_printf(ch->devinfo->dev, "%s: failed blksz=%u blkcnt=%u\n",
1688 __func__, blksz, blkcnt);
1690 ch->blksz = sndbuf_getblksz(ch->b);
1691 ch->blkcnt = sndbuf_getblkcnt(ch->b);
1697 hdaa_channel_setblocksize(kobj_t obj, void *data, uint32_t blksz)
1699 struct hdaa_chan *ch = data;
1701 hdaa_channel_setfragments(obj, data, blksz, ch->pdevinfo->chan_blkcnt);
1707 hdaa_channel_stop(struct hdaa_chan *ch)
1709 struct hdaa_devinfo *devinfo = ch->devinfo;
1710 struct hdaa_widget *w;
1713 if ((ch->flags & HDAA_CHN_RUNNING) == 0)
1715 ch->flags &= ~HDAA_CHN_RUNNING;
1716 HDAC_STREAM_STOP(device_get_parent(devinfo->dev), devinfo->dev,
1717 ch->dir == PCMDIR_PLAY ? 1 : 0, ch->sid);
1718 for (i = 0; ch->io[i] != -1; i++) {
1719 w = hdaa_widget_get(ch->devinfo, ch->io[i]);
1722 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) {
1723 hda_command(devinfo->dev,
1724 HDA_CMD_SET_DIGITAL_CONV_FMT1(0, ch->io[i], 0));
1726 hda_command(devinfo->dev,
1727 HDA_CMD_SET_CONV_STREAM_CHAN(0, ch->io[i],
1730 HDAC_STREAM_FREE(device_get_parent(devinfo->dev), devinfo->dev,
1731 ch->dir == PCMDIR_PLAY ? 1 : 0, ch->sid);
1735 hdaa_channel_start(struct hdaa_chan *ch)
1737 struct hdaa_devinfo *devinfo = ch->devinfo;
1740 fmt = hdaa_stream_format(ch);
1741 ch->stripectl = fls(ch->stripecap & hdaa_allowed_stripes(fmt)) - 1;
1742 ch->sid = HDAC_STREAM_ALLOC(device_get_parent(devinfo->dev), devinfo->dev,
1743 ch->dir == PCMDIR_PLAY ? 1 : 0, fmt, ch->stripectl, &ch->dmapos);
1746 hdaa_audio_setup(ch);
1747 HDAC_STREAM_RESET(device_get_parent(devinfo->dev), devinfo->dev,
1748 ch->dir == PCMDIR_PLAY ? 1 : 0, ch->sid);
1749 HDAC_STREAM_START(device_get_parent(devinfo->dev), devinfo->dev,
1750 ch->dir == PCMDIR_PLAY ? 1 : 0, ch->sid,
1751 sndbuf_getbufaddr(ch->b), ch->blksz, ch->blkcnt);
1752 ch->flags |= HDAA_CHN_RUNNING;
1757 hdaa_channel_trigger(kobj_t obj, void *data, int go)
1759 struct hdaa_chan *ch = data;
1762 if (!PCMTRIG_COMMON(go))
1765 hdaa_lock(ch->devinfo);
1768 error = hdaa_channel_start(ch);
1772 hdaa_channel_stop(ch);
1777 hdaa_unlock(ch->devinfo);
1783 hdaa_channel_getptr(kobj_t obj, void *data)
1785 struct hdaa_chan *ch = data;
1786 struct hdaa_devinfo *devinfo = ch->devinfo;
1790 if (ch->dmapos != NULL) {
1791 ptr = *(ch->dmapos);
1793 ptr = HDAC_STREAM_GETPTR(
1794 device_get_parent(devinfo->dev), devinfo->dev,
1795 ch->dir == PCMDIR_PLAY ? 1 : 0, ch->sid);
1797 hdaa_unlock(devinfo);
1800 * Round to available space and force 128 bytes aligment.
1802 ptr %= ch->blksz * ch->blkcnt;
1803 ptr &= HDA_BLK_ALIGN;
1808 static struct pcmchan_caps *
1809 hdaa_channel_getcaps(kobj_t obj, void *data)
1811 return (&((struct hdaa_chan *)data)->caps);
1814 static kobj_method_t hdaa_channel_methods[] = {
1815 KOBJMETHOD(channel_init, hdaa_channel_init),
1816 KOBJMETHOD(channel_setformat, hdaa_channel_setformat),
1817 KOBJMETHOD(channel_setspeed, hdaa_channel_setspeed),
1818 KOBJMETHOD(channel_setblocksize, hdaa_channel_setblocksize),
1819 KOBJMETHOD(channel_setfragments, hdaa_channel_setfragments),
1820 KOBJMETHOD(channel_trigger, hdaa_channel_trigger),
1821 KOBJMETHOD(channel_getptr, hdaa_channel_getptr),
1822 KOBJMETHOD(channel_getcaps, hdaa_channel_getcaps),
1825 CHANNEL_DECLARE(hdaa_channel);
1828 hdaa_audio_ctl_ossmixer_init(struct snd_mixer *m)
1830 struct hdaa_pcm_devinfo *pdevinfo = mix_getdevinfo(m);
1831 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
1832 struct hdaa_widget *w, *cw;
1833 uint32_t mask, recmask;
1837 pdevinfo->mixer = m;
1839 /* Make sure that in case of soft volume it won't stay muted. */
1840 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
1841 pdevinfo->left[i] = 100;
1842 pdevinfo->right[i] = 100;
1845 /* Declare volume controls assigned to this association. */
1846 mask = pdevinfo->ossmask;
1847 if (pdevinfo->playas >= 0) {
1848 /* Declate EAPD as ogain control. */
1849 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
1850 w = hdaa_widget_get(devinfo, i);
1851 if (w == NULL || w->enable == 0)
1853 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX ||
1854 w->param.eapdbtl == HDA_INVALID ||
1855 w->bindas != pdevinfo->playas)
1857 mask |= SOUND_MASK_OGAIN;
1861 /* Declare soft PCM volume if needed. */
1862 if ((mask & SOUND_MASK_PCM) == 0 ||
1863 (devinfo->quirks & HDAA_QUIRK_SOFTPCMVOL) ||
1864 pdevinfo->minamp[SOUND_MIXER_PCM] ==
1865 pdevinfo->maxamp[SOUND_MIXER_PCM]) {
1866 mask |= SOUND_MASK_PCM;
1867 pcm_setflags(pdevinfo->dev, pcm_getflags(pdevinfo->dev) | SD_F_SOFTPCMVOL);
1869 device_printf(pdevinfo->dev,
1870 "Forcing Soft PCM volume\n");
1874 /* Declare master volume if needed. */
1875 if ((mask & SOUND_MASK_VOLUME) == 0) {
1876 mask |= SOUND_MASK_VOLUME;
1877 mix_setparentchild(m, SOUND_MIXER_VOLUME,
1879 mix_setrealdev(m, SOUND_MIXER_VOLUME,
1882 device_printf(pdevinfo->dev,
1883 "Forcing master volume with PCM\n");
1888 /* Declare record sources available to this association. */
1890 if (pdevinfo->recas >= 0) {
1891 for (i = 0; i < 16; i++) {
1892 if (devinfo->as[pdevinfo->recas].dacs[0][i] < 0)
1894 w = hdaa_widget_get(devinfo,
1895 devinfo->as[pdevinfo->recas].dacs[0][i]);
1896 if (w == NULL || w->enable == 0)
1898 for (j = 0; j < w->nconns; j++) {
1899 if (w->connsenable[j] == 0)
1901 cw = hdaa_widget_get(devinfo, w->conns[j]);
1902 if (cw == NULL || cw->enable == 0)
1904 if (cw->bindas != pdevinfo->recas &&
1907 recmask |= cw->ossmask;
1912 recmask &= (1 << SOUND_MIXER_NRDEVICES) - 1;
1913 mask &= (1 << SOUND_MIXER_NRDEVICES) - 1;
1914 pdevinfo->ossmask = mask;
1916 mix_setrecdevs(m, recmask);
1917 mix_setdevs(m, mask);
1919 hdaa_unlock(devinfo);
1925 * Update amplification per pdevinfo per ossdev, calculate summary coefficient
1926 * and write it to codec, update *left and *right to reflect remaining error.
1929 hdaa_audio_ctl_dev_set(struct hdaa_audio_ctl *ctl, int ossdev,
1930 int mute, int *left, int *right)
1932 int i, zleft, zright, sleft, sright, smute, lval, rval;
1934 ctl->devleft[ossdev] = *left;
1935 ctl->devright[ossdev] = *right;
1936 ctl->devmute[ossdev] = mute;
1937 smute = sleft = sright = zleft = zright = 0;
1938 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
1939 sleft += ctl->devleft[i];
1940 sright += ctl->devright[i];
1941 smute |= ctl->devmute[i];
1944 zleft += ctl->devleft[i];
1945 zright += ctl->devright[i];
1947 lval = QDB2VAL(ctl, sleft);
1948 rval = QDB2VAL(ctl, sright);
1949 hdaa_audio_ctl_amp_set(ctl, smute, lval, rval);
1950 *left -= VAL2QDB(ctl, lval) - VAL2QDB(ctl, QDB2VAL(ctl, zleft));
1951 *right -= VAL2QDB(ctl, rval) - VAL2QDB(ctl, QDB2VAL(ctl, zright));
1955 * Trace signal from source, setting volumes on the way.
1958 hdaa_audio_ctl_source_volume(struct hdaa_pcm_devinfo *pdevinfo,
1959 int ossdev, nid_t nid, int index, int mute, int left, int right, int depth)
1961 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
1962 struct hdaa_widget *w, *wc;
1963 struct hdaa_audio_ctl *ctl;
1964 int i, j, conns = 0;
1966 if (depth > HDA_PARSE_MAXDEPTH)
1969 w = hdaa_widget_get(devinfo, nid);
1970 if (w == NULL || w->enable == 0)
1973 /* Count number of active inputs. */
1975 for (j = 0; j < w->nconns; j++) {
1976 if (!w->connsenable[j])
1982 /* If this is not a first step - use input mixer.
1983 Pins have common input ctl so care must be taken. */
1984 if (depth > 0 && (conns == 1 ||
1985 w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)) {
1986 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, HDAA_CTL_IN,
1989 hdaa_audio_ctl_dev_set(ctl, ossdev, mute, &left, &right);
1992 /* If widget has own ossdev - not traverse it.
1993 It will be traversed on it's own. */
1994 if (w->ossdev >= 0 && depth > 0)
1997 /* We must not traverse pin */
1998 if ((w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT ||
1999 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) &&
2004 * If signals mixed, we can't assign controls farther.
2005 * Ignore this on depth zero. Caller must knows why.
2008 (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER ||
2009 w->selconn != index))
2012 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, HDAA_CTL_OUT, -1, 1);
2014 hdaa_audio_ctl_dev_set(ctl, ossdev, mute, &left, &right);
2016 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2017 wc = hdaa_widget_get(devinfo, i);
2018 if (wc == NULL || wc->enable == 0)
2020 for (j = 0; j < wc->nconns; j++) {
2021 if (wc->connsenable[j] && wc->conns[j] == nid) {
2022 hdaa_audio_ctl_source_volume(pdevinfo, ossdev,
2023 wc->nid, j, mute, left, right, depth + 1);
2031 * Trace signal from destination, setting volumes on the way.
2034 hdaa_audio_ctl_dest_volume(struct hdaa_pcm_devinfo *pdevinfo,
2035 int ossdev, nid_t nid, int index, int mute, int left, int right, int depth)
2037 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
2038 struct hdaa_audio_as *as = devinfo->as;
2039 struct hdaa_widget *w, *wc;
2040 struct hdaa_audio_ctl *ctl;
2041 int i, j, consumers, cleft, cright;
2043 if (depth > HDA_PARSE_MAXDEPTH)
2046 w = hdaa_widget_get(devinfo, nid);
2047 if (w == NULL || w->enable == 0)
2051 /* If this node produce output for several consumers,
2052 we can't touch it. */
2054 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2055 wc = hdaa_widget_get(devinfo, i);
2056 if (wc == NULL || wc->enable == 0)
2058 for (j = 0; j < wc->nconns; j++) {
2059 if (wc->connsenable[j] && wc->conns[j] == nid)
2063 /* The only exception is if real HP redirection is configured
2064 and this is a duplication point.
2065 XXX: Actually exception is not completely correct.
2066 XXX: Duplication point check is not perfect. */
2067 if ((consumers == 2 && (w->bindas < 0 ||
2068 as[w->bindas].hpredir < 0 || as[w->bindas].fakeredir ||
2069 (w->bindseqmask & (1 << 15)) == 0)) ||
2073 /* Else use it's output mixer. */
2074 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid,
2075 HDAA_CTL_OUT, -1, 1);
2077 hdaa_audio_ctl_dev_set(ctl, ossdev, mute, &left, &right);
2080 /* We must not traverse pin */
2081 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
2085 for (i = 0; i < w->nconns; i++) {
2086 if (w->connsenable[i] == 0)
2088 if (index >= 0 && i != index)
2092 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid,
2095 hdaa_audio_ctl_dev_set(ctl, ossdev, mute, &cleft, &cright);
2096 hdaa_audio_ctl_dest_volume(pdevinfo, ossdev, w->conns[i], -1,
2097 mute, cleft, cright, depth + 1);
2102 * Set volumes for the specified pdevinfo and ossdev.
2105 hdaa_audio_ctl_dev_volume(struct hdaa_pcm_devinfo *pdevinfo, unsigned dev)
2107 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
2108 struct hdaa_widget *w, *cw;
2114 if (pdevinfo->left[dev] == 0) {
2115 mute |= HDAA_AMP_MUTE_LEFT;
2118 lvol = ((pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]) *
2119 pdevinfo->left[dev] + 50) / 100 + pdevinfo->minamp[dev];
2120 if (pdevinfo->right[dev] == 0) {
2121 mute |= HDAA_AMP_MUTE_RIGHT;
2124 rvol = ((pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]) *
2125 pdevinfo->right[dev] + 50) / 100 + pdevinfo->minamp[dev];
2126 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2127 w = hdaa_widget_get(devinfo, i);
2128 if (w == NULL || w->enable == 0)
2130 if (w->bindas < 0 && pdevinfo->index != 0)
2132 if (w->bindas != pdevinfo->playas &&
2133 w->bindas != pdevinfo->recas)
2135 if (dev == SOUND_MIXER_RECLEV &&
2136 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
2137 hdaa_audio_ctl_dest_volume(pdevinfo, dev,
2138 w->nid, -1, mute, lvol, rvol, 0);
2141 if (dev == SOUND_MIXER_VOLUME &&
2142 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
2143 devinfo->as[w->bindas].dir == HDAA_CTL_OUT) {
2144 hdaa_audio_ctl_dest_volume(pdevinfo, dev,
2145 w->nid, -1, mute, lvol, rvol, 0);
2148 if (dev == SOUND_MIXER_IGAIN &&
2149 w->pflags & HDAA_ADC_MONITOR) {
2150 for (j = 0; j < w->nconns; j++) {
2151 if (!w->connsenable[j])
2153 cw = hdaa_widget_get(devinfo, w->conns[j]);
2154 if (cw == NULL || cw->enable == 0)
2156 if (cw->bindas == -1)
2158 if (cw->bindas >= 0 &&
2159 devinfo->as[cw->bindas].dir != HDAA_CTL_IN)
2161 hdaa_audio_ctl_dest_volume(pdevinfo, dev,
2162 w->nid, j, mute, lvol, rvol, 0);
2166 if (w->ossdev != dev)
2168 hdaa_audio_ctl_source_volume(pdevinfo, dev,
2169 w->nid, -1, mute, lvol, rvol, 0);
2170 if (dev == SOUND_MIXER_IMIX && (w->pflags & HDAA_IMIX_AS_DST))
2171 hdaa_audio_ctl_dest_volume(pdevinfo, dev,
2172 w->nid, -1, mute, lvol, rvol, 0);
2177 * OSS Mixer set method.
2180 hdaa_audio_ctl_ossmixer_set(struct snd_mixer *m, unsigned dev,
2181 unsigned left, unsigned right)
2183 struct hdaa_pcm_devinfo *pdevinfo = mix_getdevinfo(m);
2184 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
2185 struct hdaa_widget *w;
2190 /* Save new values. */
2191 pdevinfo->left[dev] = left;
2192 pdevinfo->right[dev] = right;
2194 /* 'ogain' is the special case implemented with EAPD. */
2195 if (dev == SOUND_MIXER_OGAIN) {
2198 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2199 w = hdaa_widget_get(devinfo, i);
2200 if (w == NULL || w->enable == 0)
2202 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX ||
2203 w->param.eapdbtl == HDA_INVALID)
2207 if (i >= devinfo->endnode) {
2208 hdaa_unlock(devinfo);
2211 orig = w->param.eapdbtl;
2213 w->param.eapdbtl &= ~HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
2215 w->param.eapdbtl |= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
2216 if (orig != w->param.eapdbtl) {
2219 val = w->param.eapdbtl;
2220 if (devinfo->quirks & HDAA_QUIRK_EAPDINV)
2221 val ^= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
2222 hda_command(devinfo->dev,
2223 HDA_CMD_SET_EAPD_BTL_ENABLE(0, w->nid, val));
2225 hdaa_unlock(devinfo);
2226 return (left | (left << 8));
2229 /* Recalculate all controls related to this OSS device. */
2230 hdaa_audio_ctl_dev_volume(pdevinfo, dev);
2232 hdaa_unlock(devinfo);
2233 return (left | (right << 8));
2237 * Set mixer settings to our own default values:
2238 * +20dB for mics, -10dB for analog vol, mute for igain, 0dB for others.
2241 hdaa_audio_ctl_set_defaults(struct hdaa_pcm_devinfo *pdevinfo)
2245 for (dev = 0; dev < SOUND_MIXER_NRDEVICES; dev++) {
2246 if ((pdevinfo->ossmask & (1 << dev)) == 0)
2249 /* If the value was overriden, leave it as is. */
2250 if (resource_int_value(device_get_name(pdevinfo->dev),
2251 device_get_unit(pdevinfo->dev), ossnames[dev], &vol) == 0)
2255 if (dev == SOUND_MIXER_OGAIN)
2257 else if (dev == SOUND_MIXER_IGAIN)
2259 else if (dev == SOUND_MIXER_MIC ||
2260 dev == SOUND_MIXER_MONITOR)
2261 amp = 20 * 4; /* +20dB */
2262 else if (dev == SOUND_MIXER_VOLUME && !pdevinfo->digital)
2263 amp = -10 * 4; /* -10dB */
2267 (pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]) <= 0) {
2269 } else if (vol < 0) {
2270 vol = ((amp - pdevinfo->minamp[dev]) * 100 +
2271 (pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]) / 2) /
2272 (pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]);
2273 vol = imin(imax(vol, 1), 100);
2275 mix_set(pdevinfo->mixer, dev, vol, vol);
2280 * Recursively commutate specified record source.
2283 hdaa_audio_ctl_recsel_comm(struct hdaa_pcm_devinfo *pdevinfo, uint32_t src, nid_t nid, int depth)
2285 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
2286 struct hdaa_widget *w, *cw;
2287 struct hdaa_audio_ctl *ctl;
2292 if (depth > HDA_PARSE_MAXDEPTH)
2295 w = hdaa_widget_get(devinfo, nid);
2296 if (w == NULL || w->enable == 0)
2299 for (i = 0; i < w->nconns; i++) {
2300 if (w->connsenable[i] == 0)
2302 cw = hdaa_widget_get(devinfo, w->conns[i]);
2303 if (cw == NULL || cw->enable == 0 || cw->bindas == -1)
2305 /* Call recursively to trace signal to it's source if needed. */
2306 if ((src & cw->ossmask) != 0) {
2307 if (cw->ossdev < 0) {
2308 res |= hdaa_audio_ctl_recsel_comm(pdevinfo, src,
2309 w->conns[i], depth + 1);
2314 /* We have two special cases: mixers and others (selectors). */
2315 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) {
2316 ctl = hdaa_audio_ctl_amp_get(devinfo,
2317 w->nid, HDAA_CTL_IN, i, 1);
2320 /* If we have input control on this node mute them
2321 * according to requested sources. */
2322 muted = (src & cw->ossmask) ? 0 : 1;
2323 if (muted != ctl->forcemute) {
2324 ctl->forcemute = muted;
2325 hdaa_audio_ctl_amp_set(ctl,
2326 HDAA_AMP_MUTE_DEFAULT,
2327 HDAA_AMP_VOL_DEFAULT, HDAA_AMP_VOL_DEFAULT);
2330 device_printf(pdevinfo->dev,
2331 "Recsel (%s): nid %d source %d %s\n",
2332 hdaa_audio_ctl_ossmixer_mask2allname(
2333 src, buf, sizeof(buf)),
2334 nid, i, muted?"mute":"unmute");
2339 if ((src & cw->ossmask) == 0)
2341 /* If we found requested source - select it and exit. */
2342 hdaa_widget_connection_select(w, i);
2344 device_printf(pdevinfo->dev,
2345 "Recsel (%s): nid %d source %d select\n",
2346 hdaa_audio_ctl_ossmixer_mask2allname(
2347 src, buf, sizeof(buf)),
2357 hdaa_audio_ctl_ossmixer_setrecsrc(struct snd_mixer *m, uint32_t src)
2359 struct hdaa_pcm_devinfo *pdevinfo = mix_getdevinfo(m);
2360 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
2361 struct hdaa_widget *w;
2362 struct hdaa_audio_as *as;
2363 struct hdaa_audio_ctl *ctl;
2364 struct hdaa_chan *ch;
2366 uint32_t ret = 0xffffffff;
2369 if (pdevinfo->recas < 0) {
2370 hdaa_unlock(devinfo);
2373 as = &devinfo->as[pdevinfo->recas];
2375 /* For non-mixed associations we always recording everything. */
2377 hdaa_unlock(devinfo);
2378 return (mix_getrecdevs(m));
2381 /* Commutate requested recsrc for each ADC. */
2382 for (j = 0; j < as->num_chans; j++) {
2383 ch = &devinfo->chans[as->chans[j]];
2384 for (i = 0; ch->io[i] >= 0; i++) {
2385 w = hdaa_widget_get(devinfo, ch->io[i]);
2386 if (w == NULL || w->enable == 0)
2388 ret &= hdaa_audio_ctl_recsel_comm(pdevinfo, src,
2392 if (ret == 0xffffffff)
2396 * Some controls could be shared. Reset volumes for controls
2397 * related to previously chosen devices, as they may no longer
2398 * affect the signal.
2401 while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) {
2402 if (ctl->enable == 0 ||
2403 !(ctl->ossmask & pdevinfo->recsrc))
2405 if (!((pdevinfo->playas >= 0 &&
2406 ctl->widget->bindas == pdevinfo->playas) ||
2407 (pdevinfo->recas >= 0 &&
2408 ctl->widget->bindas == pdevinfo->recas) ||
2409 (pdevinfo->index == 0 &&
2410 ctl->widget->bindas == -2)))
2412 for (j = 0; j < SOUND_MIXER_NRDEVICES; j++) {
2413 if (pdevinfo->recsrc & (1 << j)) {
2414 ctl->devleft[j] = 0;
2415 ctl->devright[j] = 0;
2416 ctl->devmute[j] = 0;
2422 * Some controls could be shared. Set volumes for controls
2423 * related to devices selected both previously and now.
2425 for (j = 0; j < SOUND_MIXER_NRDEVICES; j++) {
2426 if ((ret | pdevinfo->recsrc) & (1 << j))
2427 hdaa_audio_ctl_dev_volume(pdevinfo, j);
2430 pdevinfo->recsrc = ret;
2431 hdaa_unlock(devinfo);
2435 static kobj_method_t hdaa_audio_ctl_ossmixer_methods[] = {
2436 KOBJMETHOD(mixer_init, hdaa_audio_ctl_ossmixer_init),
2437 KOBJMETHOD(mixer_set, hdaa_audio_ctl_ossmixer_set),
2438 KOBJMETHOD(mixer_setrecsrc, hdaa_audio_ctl_ossmixer_setrecsrc),
2441 MIXER_DECLARE(hdaa_audio_ctl_ossmixer);
2444 hdaa_dump_gpi(struct hdaa_devinfo *devinfo)
2446 device_t dev = devinfo->dev;
2448 uint32_t data, wake, unsol, sticky;
2450 if (HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap) > 0) {
2451 data = hda_command(dev,
2452 HDA_CMD_GET_GPI_DATA(0, devinfo->nid));
2453 wake = hda_command(dev,
2454 HDA_CMD_GET_GPI_WAKE_ENABLE_MASK(0, devinfo->nid));
2455 unsol = hda_command(dev,
2456 HDA_CMD_GET_GPI_UNSOLICITED_ENABLE_MASK(0, devinfo->nid));
2457 sticky = hda_command(dev,
2458 HDA_CMD_GET_GPI_STICKY_MASK(0, devinfo->nid));
2459 for (i = 0; i < HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap); i++) {
2460 device_printf(dev, " GPI%d:%s%s%s state=%d", i,
2461 (sticky & (1 << i)) ? " sticky" : "",
2462 (unsol & (1 << i)) ? " unsol" : "",
2463 (wake & (1 << i)) ? " wake" : "",
2470 hdaa_dump_gpio(struct hdaa_devinfo *devinfo)
2472 device_t dev = devinfo->dev;
2474 uint32_t data, dir, enable, wake, unsol, sticky;
2476 if (HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap) > 0) {
2477 data = hda_command(dev,
2478 HDA_CMD_GET_GPIO_DATA(0, devinfo->nid));
2479 enable = hda_command(dev,
2480 HDA_CMD_GET_GPIO_ENABLE_MASK(0, devinfo->nid));
2481 dir = hda_command(dev,
2482 HDA_CMD_GET_GPIO_DIRECTION(0, devinfo->nid));
2483 wake = hda_command(dev,
2484 HDA_CMD_GET_GPIO_WAKE_ENABLE_MASK(0, devinfo->nid));
2485 unsol = hda_command(dev,
2486 HDA_CMD_GET_GPIO_UNSOLICITED_ENABLE_MASK(0, devinfo->nid));
2487 sticky = hda_command(dev,
2488 HDA_CMD_GET_GPIO_STICKY_MASK(0, devinfo->nid));
2489 for (i = 0; i < HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap); i++) {
2490 device_printf(dev, " GPIO%d: ", i);
2491 if ((enable & (1 << i)) == 0) {
2492 printf("disabled\n");
2495 if ((dir & (1 << i)) == 0) {
2496 printf("input%s%s%s",
2497 (sticky & (1 << i)) ? " sticky" : "",
2498 (unsol & (1 << i)) ? " unsol" : "",
2499 (wake & (1 << i)) ? " wake" : "");
2502 printf(" state=%d\n", (data >> i) & 1);
2508 hdaa_dump_gpo(struct hdaa_devinfo *devinfo)
2510 device_t dev = devinfo->dev;
2514 if (HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap) > 0) {
2515 data = hda_command(dev,
2516 HDA_CMD_GET_GPO_DATA(0, devinfo->nid));
2517 for (i = 0; i < HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap); i++) {
2518 device_printf(dev, " GPO%d: state=%d", i,
2525 hdaa_audio_parse(struct hdaa_devinfo *devinfo)
2527 struct hdaa_widget *w;
2534 res = hda_command(devinfo->dev,
2535 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_GPIO_COUNT));
2536 devinfo->gpio_cap = res;
2539 device_printf(devinfo->dev,
2540 "NumGPIO=%d NumGPO=%d "
2541 "NumGPI=%d GPIWake=%d GPIUnsol=%d\n",
2542 HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap),
2543 HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap),
2544 HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap),
2545 HDA_PARAM_GPIO_COUNT_GPI_WAKE(devinfo->gpio_cap),
2546 HDA_PARAM_GPIO_COUNT_GPI_UNSOL(devinfo->gpio_cap));
2547 hdaa_dump_gpi(devinfo);
2548 hdaa_dump_gpio(devinfo);
2549 hdaa_dump_gpo(devinfo);
2552 res = hda_command(devinfo->dev,
2553 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_SUPP_STREAM_FORMATS));
2554 devinfo->supp_stream_formats = res;
2556 res = hda_command(devinfo->dev,
2557 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_SUPP_PCM_SIZE_RATE));
2558 devinfo->supp_pcm_size_rate = res;
2560 res = hda_command(devinfo->dev,
2561 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_OUTPUT_AMP_CAP));
2562 devinfo->outamp_cap = res;
2564 res = hda_command(devinfo->dev,
2565 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_INPUT_AMP_CAP));
2566 devinfo->inamp_cap = res;
2568 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2569 w = hdaa_widget_get(devinfo, i);
2571 device_printf(devinfo->dev, "Ghost widget! nid=%d!\n", i);
2573 w->devinfo = devinfo;
2580 w->param.eapdbtl = HDA_INVALID;
2581 hdaa_widget_parse(w);
2587 hdaa_audio_postprocess(struct hdaa_devinfo *devinfo)
2589 struct hdaa_widget *w;
2592 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2593 w = hdaa_widget_get(devinfo, i);
2596 hdaa_widget_postprocess(w);
2601 hdaa_audio_ctl_parse(struct hdaa_devinfo *devinfo)
2603 struct hdaa_audio_ctl *ctls;
2604 struct hdaa_widget *w, *cw;
2605 int i, j, cnt, max, ocap, icap;
2606 int mute, offset, step, size;
2608 /* XXX This is redundant */
2610 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2611 w = hdaa_widget_get(devinfo, i);
2612 if (w == NULL || w->enable == 0)
2614 if (w->param.outamp_cap != 0)
2616 if (w->param.inamp_cap != 0) {
2618 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR:
2619 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER:
2620 for (j = 0; j < w->nconns; j++) {
2621 cw = hdaa_widget_get(devinfo,
2623 if (cw == NULL || cw->enable == 0)
2634 devinfo->ctlcnt = max;
2639 ctls = (struct hdaa_audio_ctl *)malloc(
2640 sizeof(*ctls) * max, M_HDAA, M_ZERO | M_NOWAIT);
2644 device_printf(devinfo->dev, "unable to allocate ctls!\n");
2645 devinfo->ctlcnt = 0;
2650 for (i = devinfo->startnode; cnt < max && i < devinfo->endnode; i++) {
2652 device_printf(devinfo->dev, "%s: Ctl overflow!\n",
2656 w = hdaa_widget_get(devinfo, i);
2657 if (w == NULL || w->enable == 0)
2659 ocap = w->param.outamp_cap;
2660 icap = w->param.inamp_cap;
2662 mute = HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(ocap);
2663 step = HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(ocap);
2664 size = HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(ocap);
2665 offset = HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(ocap);
2666 /*if (offset > step) {
2668 device_printf(devinfo->dev,
2669 "BUGGY outamp: nid=%d "
2670 "[offset=%d > step=%d]\n",
2671 w->nid, offset, step);
2675 ctls[cnt].enable = 1;
2676 ctls[cnt].widget = w;
2677 ctls[cnt].mute = mute;
2678 ctls[cnt].step = step;
2679 ctls[cnt].size = size;
2680 ctls[cnt].offset = offset;
2681 ctls[cnt].left = offset;
2682 ctls[cnt].right = offset;
2683 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX ||
2685 ctls[cnt].ndir = HDAA_CTL_IN;
2687 ctls[cnt].ndir = HDAA_CTL_OUT;
2688 ctls[cnt++].dir = HDAA_CTL_OUT;
2692 mute = HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(icap);
2693 step = HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(icap);
2694 size = HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(icap);
2695 offset = HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(icap);
2696 /*if (offset > step) {
2698 device_printf(devinfo->dev,
2699 "BUGGY inamp: nid=%d "
2700 "[offset=%d > step=%d]\n",
2701 w->nid, offset, step);
2706 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR:
2707 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER:
2708 for (j = 0; j < w->nconns; j++) {
2710 device_printf(devinfo->dev,
2711 "%s: Ctl overflow!\n",
2715 cw = hdaa_widget_get(devinfo,
2717 if (cw == NULL || cw->enable == 0)
2719 ctls[cnt].enable = 1;
2720 ctls[cnt].widget = w;
2721 ctls[cnt].childwidget = cw;
2722 ctls[cnt].index = j;
2723 ctls[cnt].mute = mute;
2724 ctls[cnt].step = step;
2725 ctls[cnt].size = size;
2726 ctls[cnt].offset = offset;
2727 ctls[cnt].left = offset;
2728 ctls[cnt].right = offset;
2729 ctls[cnt].ndir = HDAA_CTL_IN;
2730 ctls[cnt++].dir = HDAA_CTL_IN;
2735 device_printf(devinfo->dev,
2736 "%s: Ctl overflow!\n",
2740 ctls[cnt].enable = 1;
2741 ctls[cnt].widget = w;
2742 ctls[cnt].mute = mute;
2743 ctls[cnt].step = step;
2744 ctls[cnt].size = size;
2745 ctls[cnt].offset = offset;
2746 ctls[cnt].left = offset;
2747 ctls[cnt].right = offset;
2749 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
2750 ctls[cnt].ndir = HDAA_CTL_OUT;
2752 ctls[cnt].ndir = HDAA_CTL_IN;
2753 ctls[cnt++].dir = HDAA_CTL_IN;
2759 devinfo->ctl = ctls;
2763 hdaa_audio_as_parse(struct hdaa_devinfo *devinfo)
2765 struct hdaa_audio_as *as;
2766 struct hdaa_widget *w;
2767 int i, j, cnt, max, type, dir, assoc, seq, first, hpredir;
2769 /* Count present associations */
2771 for (j = 1; j < 16; j++) {
2772 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2773 w = hdaa_widget_get(devinfo, i);
2774 if (w == NULL || w->enable == 0)
2776 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
2778 if (HDA_CONFIG_DEFAULTCONF_ASSOCIATION(w->wclass.pin.config)
2782 if (j != 15) /* There could be many 1-pin assocs #15 */
2787 devinfo->ascnt = max;
2792 as = (struct hdaa_audio_as *)malloc(
2793 sizeof(*as) * max, M_HDAA, M_ZERO | M_NOWAIT);
2797 device_printf(devinfo->dev, "unable to allocate assocs!\n");
2802 for (i = 0; i < max; i++) {
2805 as[i].num_chans = 1;
2806 as[i].location = -1;
2809 /* Scan associations skipping as=0. */
2811 for (j = 1; j < 16; j++) {
2814 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2815 w = hdaa_widget_get(devinfo, i);
2816 if (w == NULL || w->enable == 0)
2818 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
2820 assoc = HDA_CONFIG_DEFAULTCONF_ASSOCIATION(w->wclass.pin.config);
2821 seq = HDA_CONFIG_DEFAULTCONF_SEQUENCE(w->wclass.pin.config);
2826 ("%s: Associations owerflow (%d of %d)",
2827 __func__, cnt, max));
2828 type = w->wclass.pin.config &
2829 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
2830 /* Get pin direction. */
2831 if (type == HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_OUT ||
2832 type == HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER ||
2833 type == HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT ||
2834 type == HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_OUT ||
2835 type == HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_OUT)
2839 /* If this is a first pin - create new association. */
2840 if (as[cnt].pincnt == 0) {
2847 /* Check association correctness. */
2848 if (as[cnt].pins[seq] != 0) {
2849 device_printf(devinfo->dev, "%s: Duplicate pin %d (%d) "
2850 "in association %d! Disabling association.\n",
2851 __func__, seq, w->nid, j);
2854 if (dir != as[cnt].dir) {
2855 device_printf(devinfo->dev, "%s: Pin %d has wrong "
2856 "direction for association %d! Disabling "
2858 __func__, w->nid, j);
2861 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) {
2862 as[cnt].digital |= 0x1;
2863 if (HDA_PARAM_PIN_CAP_HDMI(w->wclass.pin.cap))
2864 as[cnt].digital |= 0x2;
2865 if (HDA_PARAM_PIN_CAP_DP(w->wclass.pin.cap))
2866 as[cnt].digital |= 0x4;
2868 if (as[cnt].location == -1) {
2870 HDA_CONFIG_DEFAULTCONF_LOCATION(w->wclass.pin.config);
2871 } else if (as[cnt].location !=
2872 HDA_CONFIG_DEFAULTCONF_LOCATION(w->wclass.pin.config)) {
2873 as[cnt].location = -2;
2875 /* Headphones with seq=15 may mean redirection. */
2876 if (type == HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT &&
2879 as[cnt].pins[seq] = w->nid;
2881 /* Association 15 is a multiple unassociated pins. */
2885 if (j != 15 && as[cnt].pincnt > 0) {
2886 if (hpredir && as[cnt].pincnt > 1)
2887 as[cnt].hpredir = first;
2891 for (i = 0; i < max; i++) {
2892 if (as[i].dir == HDAA_CTL_IN && (as[i].pincnt == 1 ||
2893 as[i].pins[14] > 0 || as[i].pins[15] > 0))
2897 device_printf(devinfo->dev,
2898 "%d associations found:\n", max);
2899 for (i = 0; i < max; i++) {
2900 device_printf(devinfo->dev,
2901 "Association %d (%d) %s%s:\n",
2902 i, as[i].index, (as[i].dir == HDAA_CTL_IN)?"in":"out",
2903 as[i].enable?"":" (disabled)");
2904 for (j = 0; j < 16; j++) {
2905 if (as[i].pins[j] == 0)
2907 device_printf(devinfo->dev,
2908 " Pin nid=%d seq=%d\n",
2918 * Trace path from DAC to pin.
2921 hdaa_audio_trace_dac(struct hdaa_devinfo *devinfo, int as, int seq, nid_t nid,
2922 int dupseq, int min, int only, int depth)
2924 struct hdaa_widget *w;
2928 if (depth > HDA_PARSE_MAXDEPTH)
2930 w = hdaa_widget_get(devinfo, nid);
2931 if (w == NULL || w->enable == 0)
2935 device_printf(devinfo->dev,
2936 " %*stracing via nid %d\n",
2937 depth + 1, "", w->nid);
2940 /* Use only unused widgets */
2941 if (w->bindas >= 0 && w->bindas != as) {
2944 device_printf(devinfo->dev,
2945 " %*snid %d busy by association %d\n",
2946 depth + 1, "", w->nid, w->bindas);
2952 if (w->bindseqmask != 0) {
2955 device_printf(devinfo->dev,
2956 " %*snid %d busy by seqmask %x\n",
2957 depth + 1, "", w->nid, w->bindseqmask);
2963 /* If this is headphones - allow duplicate first pin. */
2964 if (w->bindseqmask != 0 &&
2965 (w->bindseqmask & (1 << dupseq)) == 0) {
2967 device_printf(devinfo->dev,
2968 " %*snid %d busy by seqmask %x\n",
2969 depth + 1, "", w->nid, w->bindseqmask);
2976 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT:
2977 /* Do not traverse input. AD1988 has digital monitor
2978 for which we are not ready. */
2980 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT:
2981 /* If we are tracing HP take only dac of first pin. */
2982 if ((only == 0 || only == w->nid) &&
2983 (w->nid >= min) && (dupseq < 0 || w->nid ==
2984 devinfo->as[as].dacs[0][dupseq]))
2987 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
2992 /* Find reachable DACs with smallest nid respecting constraints. */
2993 for (i = 0; i < w->nconns; i++) {
2994 if (w->connsenable[i] == 0)
2996 if (w->selconn != -1 && w->selconn != i)
2998 if ((ret = hdaa_audio_trace_dac(devinfo, as, seq,
2999 w->conns[i], dupseq, min, only, depth + 1)) != 0) {
3000 if (m == 0 || ret < m) {
3004 if (only || dupseq >= 0)
3008 if (im >= 0 && only && ((w->nconns > 1 &&
3009 w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) ||
3010 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR))
3016 w->bindseqmask |= (1 << seq);
3020 device_printf(devinfo->dev,
3021 " %*snid %d returned %d\n",
3022 depth + 1, "", w->nid, m);
3029 * Trace path from widget to ADC.
3032 hdaa_audio_trace_adc(struct hdaa_devinfo *devinfo, int as, int seq, nid_t nid,
3033 int mixed, int min, int only, int depth, int *length, int onlylength)
3035 struct hdaa_widget *w, *wc;
3036 int i, j, im, lm = HDA_PARSE_MAXDEPTH;
3039 if (depth > HDA_PARSE_MAXDEPTH)
3041 w = hdaa_widget_get(devinfo, nid);
3042 if (w == NULL || w->enable == 0)
3045 device_printf(devinfo->dev,
3046 " %*stracing via nid %d\n",
3047 depth + 1, "", w->nid);
3049 /* Use only unused widgets */
3050 if (w->bindas >= 0 && w->bindas != as) {
3052 device_printf(devinfo->dev,
3053 " %*snid %d busy by association %d\n",
3054 depth + 1, "", w->nid, w->bindas);
3058 if (!mixed && w->bindseqmask != 0) {
3060 device_printf(devinfo->dev,
3061 " %*snid %d busy by seqmask %x\n",
3062 depth + 1, "", w->nid, w->bindseqmask);
3067 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT:
3068 if ((only == 0 || only == w->nid) && (w->nid >= min) &&
3069 (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 != NULL &&
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, 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 < HDAA_QUIRKS_TAB_LEN; 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;
6245 "Audio Function Group at nid=%d: %d subnodes %d-%d\n",
6246 nid, devinfo->nodecnt,
6247 devinfo->startnode, devinfo->endnode - 1);
6250 if (devinfo->nodecnt > 0)
6251 devinfo->widget = (struct hdaa_widget *)malloc(
6252 sizeof(*(devinfo->widget)) * devinfo->nodecnt, M_HDAA,
6255 devinfo->widget = NULL;
6259 device_printf(dev, "Powering up...\n");
6261 hdaa_powerup(devinfo);
6263 device_printf(dev, "Parsing audio FG...\n");
6265 hdaa_audio_parse(devinfo);
6267 device_printf(dev, "Original pins configuration:\n");
6268 hdaa_dump_pin_configs(devinfo);
6270 hdaa_configure(dev);
6271 hdaa_unlock(devinfo);
6273 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6274 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6275 "config", CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE,
6276 &devinfo->newquirks, sizeof(&devinfo->newquirks),
6277 hdaa_sysctl_quirks, "A", "Configuration options");
6278 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6279 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6280 "gpi_state", CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
6281 devinfo, sizeof(devinfo),
6282 hdaa_sysctl_gpi_state, "A", "GPI state");
6283 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6284 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6285 "gpio_state", CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
6286 devinfo, sizeof(devinfo),
6287 hdaa_sysctl_gpio_state, "A", "GPIO state");
6288 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6289 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6290 "gpio_config", CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE,
6291 devinfo, sizeof(devinfo),
6292 hdaa_sysctl_gpio_config, "A", "GPIO configuration");
6293 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6294 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6295 "gpo_state", CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
6296 devinfo, sizeof(devinfo),
6297 hdaa_sysctl_gpo_state, "A", "GPO state");
6298 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6299 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6300 "gpo_config", CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE,
6301 devinfo, sizeof(devinfo),
6302 hdaa_sysctl_gpo_config, "A", "GPO configuration");
6303 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6304 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6305 "reconfig", CTLTYPE_INT | CTLFLAG_RW,
6307 hdaa_sysctl_reconfig, "I", "Reprocess configuration");
6308 bus_generic_attach(dev);
6313 hdaa_detach(device_t dev)
6315 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6318 if ((error = device_delete_children(dev)) != 0)
6322 hdaa_unconfigure(dev);
6323 devinfo->poll_ival = 0;
6324 callout_stop(&devinfo->poll_jack);
6325 hdaa_unlock(devinfo);
6326 callout_drain(&devinfo->poll_jack);
6328 free(devinfo->widget, M_HDAA);
6333 hdaa_print_child(device_t dev, device_t child)
6335 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6336 struct hdaa_pcm_devinfo *pdevinfo =
6337 (struct hdaa_pcm_devinfo *)device_get_ivars(child);
6338 struct hdaa_audio_as *as;
6339 int retval, first = 1, i;
6341 retval = bus_print_child_header(dev, child);
6342 retval += printf(" at nid ");
6343 if (pdevinfo->playas >= 0) {
6344 as = &devinfo->as[pdevinfo->playas];
6345 for (i = 0; i < 16; i++) {
6346 if (as->pins[i] <= 0)
6348 retval += printf("%s%d", first ? "" : ",", as->pins[i]);
6352 if (pdevinfo->recas >= 0) {
6353 if (pdevinfo->playas >= 0) {
6354 retval += printf(" and ");
6357 as = &devinfo->as[pdevinfo->recas];
6358 for (i = 0; i < 16; i++) {
6359 if (as->pins[i] <= 0)
6361 retval += printf("%s%d", first ? "" : ",", as->pins[i]);
6365 retval += bus_print_child_footer(dev, child);
6371 hdaa_child_location_str(device_t dev, device_t child, char *buf,
6374 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6375 struct hdaa_pcm_devinfo *pdevinfo =
6376 (struct hdaa_pcm_devinfo *)device_get_ivars(child);
6377 struct hdaa_audio_as *as;
6378 int first = 1, i, len = 0;
6380 len += snprintf(buf + len, buflen - len, "nid=");
6381 if (pdevinfo->playas >= 0) {
6382 as = &devinfo->as[pdevinfo->playas];
6383 for (i = 0; i < 16; i++) {
6384 if (as->pins[i] <= 0)
6386 len += snprintf(buf + len, buflen - len,
6387 "%s%d", first ? "" : ",", as->pins[i]);
6391 if (pdevinfo->recas >= 0) {
6392 as = &devinfo->as[pdevinfo->recas];
6393 for (i = 0; i < 16; i++) {
6394 if (as->pins[i] <= 0)
6396 len += snprintf(buf + len, buflen - len,
6397 "%s%d", first ? "" : ",", as->pins[i]);
6405 hdaa_stream_intr(device_t dev, int dir, int stream)
6407 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6408 struct hdaa_chan *ch;
6411 for (i = 0; i < devinfo->num_chans; i++) {
6412 ch = &devinfo->chans[i];
6413 if (!(ch->flags & HDAA_CHN_RUNNING))
6415 if (ch->dir == ((dir == 1) ? PCMDIR_PLAY : PCMDIR_REC) &&
6416 ch->sid == stream) {
6417 hdaa_unlock(devinfo);
6425 hdaa_unsol_intr(device_t dev, uint32_t resp)
6427 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6428 struct hdaa_widget *w;
6432 device_printf(dev, "Unsolicited response %08x\n", resp);
6435 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
6436 w = hdaa_widget_get(devinfo, i);
6437 if (w == NULL || w->enable == 0 || w->type !=
6438 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
6440 if (w->unsol != tag)
6442 if (HDA_PARAM_PIN_CAP_DP(w->wclass.pin.cap) ||
6443 HDA_PARAM_PIN_CAP_HDMI(w->wclass.pin.cap))
6444 flags = resp & 0x03;
6448 hdaa_presence_handler(w);
6450 hdaa_eld_handler(w);
6454 static device_method_t hdaa_methods[] = {
6455 /* device interface */
6456 DEVMETHOD(device_probe, hdaa_probe),
6457 DEVMETHOD(device_attach, hdaa_attach),
6458 DEVMETHOD(device_detach, hdaa_detach),
6459 DEVMETHOD(device_suspend, hdaa_suspend),
6460 DEVMETHOD(device_resume, hdaa_resume),
6462 DEVMETHOD(bus_print_child, hdaa_print_child),
6463 DEVMETHOD(bus_child_location_str, hdaa_child_location_str),
6464 DEVMETHOD(hdac_stream_intr, hdaa_stream_intr),
6465 DEVMETHOD(hdac_unsol_intr, hdaa_unsol_intr),
6466 DEVMETHOD(hdac_pindump, hdaa_pindump),
6470 static driver_t hdaa_driver = {
6473 sizeof(struct hdaa_devinfo),
6476 static devclass_t hdaa_devclass;
6478 DRIVER_MODULE(snd_hda, hdacc, hdaa_driver, hdaa_devclass, 0, 0);
6481 hdaa_chan_formula(struct hdaa_devinfo *devinfo, int asid,
6482 char *buf, int buflen)
6484 struct hdaa_audio_as *as;
6487 as = &devinfo->as[asid];
6488 c = devinfo->chans[as->chans[0]].channels;
6490 snprintf(buf, buflen, "mono");
6492 if (as->hpredir < 0)
6495 snprintf(buf, buflen, "2.0");
6496 } else if (as->pinset == 0x0003)
6497 snprintf(buf, buflen, "3.1");
6498 else if (as->pinset == 0x0005 || as->pinset == 0x0011)
6499 snprintf(buf, buflen, "4.0");
6500 else if (as->pinset == 0x0007 || as->pinset == 0x0013)
6501 snprintf(buf, buflen, "5.1");
6502 else if (as->pinset == 0x0017)
6503 snprintf(buf, buflen, "7.1");
6505 snprintf(buf, buflen, "%dch", c);
6506 if (as->hpredir >= 0)
6507 strlcat(buf, "+HP", buflen);
6511 hdaa_chan_type(struct hdaa_devinfo *devinfo, int asid)
6513 struct hdaa_audio_as *as;
6514 struct hdaa_widget *w;
6517 as = &devinfo->as[asid];
6518 for (i = 0; i < 16; i++) {
6519 w = hdaa_widget_get(devinfo, as->pins[i]);
6520 if (w == NULL || w->enable == 0 || w->type !=
6521 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
6523 t1 = HDA_CONFIG_DEFAULTCONF_DEVICE(w->wclass.pin.config);
6535 hdaa_sysctl_32bit(SYSCTL_HANDLER_ARGS)
6537 struct hdaa_audio_as *as = (struct hdaa_audio_as *)oidp->oid_arg1;
6538 struct hdaa_pcm_devinfo *pdevinfo = as->pdevinfo;
6539 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
6540 struct hdaa_chan *ch;
6544 ch = &devinfo->chans[as->chans[0]];
6545 val = (ch->bit32 == 4) ? 32 : ((ch->bit32 == 3) ? 24 :
6546 ((ch->bit32 == 2) ? 20 : 0));
6547 error = sysctl_handle_int(oidp, &val, 0, req);
6548 if (error != 0 || req->newptr == NULL)
6550 pcmcap = ch->supp_pcm_size_rate;
6551 if (val == 32 && HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(pcmcap))
6553 else if (val == 24 && HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(pcmcap))
6555 else if (val == 20 && HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(pcmcap))
6559 for (i = 1; i < as->num_chans; i++)
6560 devinfo->chans[as->chans[i]].bit32 = ch->bit32;
6565 hdaa_pcm_probe(device_t dev)
6567 struct hdaa_pcm_devinfo *pdevinfo =
6568 (struct hdaa_pcm_devinfo *)device_get_ivars(dev);
6569 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
6571 char chans1[8], chans2[8];
6573 int loc1, loc2, t1, t2;
6575 if (pdevinfo->playas >= 0)
6576 loc1 = devinfo->as[pdevinfo->playas].location;
6578 loc1 = devinfo->as[pdevinfo->recas].location;
6579 if (pdevinfo->recas >= 0)
6580 loc2 = devinfo->as[pdevinfo->recas].location;
6585 if (loc1 >= 0 && HDA_LOCS[loc1][0] == '0')
6590 if (pdevinfo->playas >= 0) {
6591 hdaa_chan_formula(devinfo, pdevinfo->playas,
6592 chans1, sizeof(chans1));
6593 t1 = hdaa_chan_type(devinfo, pdevinfo->playas);
6595 if (pdevinfo->recas >= 0) {
6596 hdaa_chan_formula(devinfo, pdevinfo->recas,
6597 chans2, sizeof(chans2));
6598 t2 = hdaa_chan_type(devinfo, pdevinfo->recas);
6600 if (chans1[0] != 0 || chans2[0] != 0) {
6601 if (chans1[0] == 0 && pdevinfo->playas >= 0)
6602 snprintf(chans1, sizeof(chans1), "2.0");
6603 else if (chans2[0] == 0 && pdevinfo->recas >= 0)
6604 snprintf(chans2, sizeof(chans2), "2.0");
6605 if (strcmp(chans1, chans2) == 0)
6614 if (pdevinfo->digital)
6616 pdesc = device_get_desc(device_get_parent(dev));
6617 snprintf(buf, sizeof(buf), "%.*s (%s%s%s%s%s%s%s%s%s)",
6618 (int)(strlen(pdesc) - 21), pdesc,
6619 loc1 >= 0 ? HDA_LOCS[loc1] : "", loc1 >= 0 ? " " : "",
6620 (pdevinfo->digital == 0x7)?"HDMI/DP":
6621 ((pdevinfo->digital == 0x5)?"DisplayPort":
6622 ((pdevinfo->digital == 0x3)?"HDMI":
6623 ((pdevinfo->digital)?"Digital":"Analog"))),
6624 chans1[0] ? " " : "", chans1,
6625 chans2[0] ? "/" : "", chans2,
6626 t1 >= 0 ? " " : "", t1 >= 0 ? HDA_DEVS[t1] : "");
6627 device_set_desc_copy(dev, buf);
6628 return (BUS_PROBE_SPECIFIC);
6632 hdaa_pcm_attach(device_t dev)
6634 struct hdaa_pcm_devinfo *pdevinfo =
6635 (struct hdaa_pcm_devinfo *)device_get_ivars(dev);
6636 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
6637 struct hdaa_audio_as *as;
6638 struct snddev_info *d;
6639 char status[SND_STATUSLEN];
6642 pdevinfo->chan_size = pcm_getbuffersize(dev,
6643 HDA_BUFSZ_MIN, HDA_BUFSZ_DEFAULT, HDA_BUFSZ_MAX);
6646 device_printf(dev, "+--------------------------------------+\n");
6647 device_printf(dev, "| DUMPING PCM Playback/Record Channels |\n");
6648 device_printf(dev, "+--------------------------------------+\n");
6649 hdaa_dump_pcmchannels(pdevinfo);
6650 device_printf(dev, "\n");
6651 device_printf(dev, "+-------------------------------+\n");
6652 device_printf(dev, "| DUMPING Playback/Record Paths |\n");
6653 device_printf(dev, "+-------------------------------+\n");
6654 hdaa_dump_dac(pdevinfo);
6655 hdaa_dump_adc(pdevinfo);
6656 hdaa_dump_mix(pdevinfo);
6657 device_printf(dev, "\n");
6658 device_printf(dev, "+-------------------------+\n");
6659 device_printf(dev, "| DUMPING Volume Controls |\n");
6660 device_printf(dev, "+-------------------------+\n");
6661 hdaa_dump_ctls(pdevinfo, "Master Volume", SOUND_MASK_VOLUME);
6662 hdaa_dump_ctls(pdevinfo, "PCM Volume", SOUND_MASK_PCM);
6663 hdaa_dump_ctls(pdevinfo, "CD Volume", SOUND_MASK_CD);
6664 hdaa_dump_ctls(pdevinfo, "Microphone Volume", SOUND_MASK_MIC);
6665 hdaa_dump_ctls(pdevinfo, "Microphone2 Volume", SOUND_MASK_MONITOR);
6666 hdaa_dump_ctls(pdevinfo, "Line-in Volume", SOUND_MASK_LINE);
6667 hdaa_dump_ctls(pdevinfo, "Speaker/Beep Volume", SOUND_MASK_SPEAKER);
6668 hdaa_dump_ctls(pdevinfo, "Recording Level", SOUND_MASK_RECLEV);
6669 hdaa_dump_ctls(pdevinfo, "Input Mix Level", SOUND_MASK_IMIX);
6670 hdaa_dump_ctls(pdevinfo, "Input Monitoring Level", SOUND_MASK_IGAIN);
6671 hdaa_dump_ctls(pdevinfo, NULL, 0);
6672 device_printf(dev, "\n");
6675 if (resource_int_value(device_get_name(dev),
6676 device_get_unit(dev), "blocksize", &i) == 0 && i > 0) {
6678 if (i < HDA_BLK_MIN)
6680 pdevinfo->chan_blkcnt = pdevinfo->chan_size / i;
6682 while (pdevinfo->chan_blkcnt >> i)
6684 pdevinfo->chan_blkcnt = 1 << (i - 1);
6685 if (pdevinfo->chan_blkcnt < HDA_BDL_MIN)
6686 pdevinfo->chan_blkcnt = HDA_BDL_MIN;
6687 else if (pdevinfo->chan_blkcnt > HDA_BDL_MAX)
6688 pdevinfo->chan_blkcnt = HDA_BDL_MAX;
6690 pdevinfo->chan_blkcnt = HDA_BDL_DEFAULT;
6693 * We don't register interrupt handler with snd_setup_intr
6694 * in pcm device. Mark pcm device as MPSAFE manually.
6696 pcm_setflags(dev, pcm_getflags(dev) | SD_F_MPSAFE);
6699 device_printf(dev, "OSS mixer initialization...\n");
6701 if (mixer_init(dev, &hdaa_audio_ctl_ossmixer_class, pdevinfo) != 0)
6702 device_printf(dev, "Can't register mixer\n");
6705 device_printf(dev, "Registering PCM channels...\n");
6707 if (pcm_register(dev, pdevinfo, (pdevinfo->playas >= 0)?1:0,
6708 (pdevinfo->recas >= 0)?1:0) != 0)
6709 device_printf(dev, "Can't register PCM\n");
6711 pdevinfo->registered++;
6713 d = device_get_softc(dev);
6714 if (pdevinfo->playas >= 0) {
6715 as = &devinfo->as[pdevinfo->playas];
6716 for (i = 0; i < as->num_chans; i++)
6717 pcm_addchan(dev, PCMDIR_PLAY, &hdaa_channel_class,
6718 &devinfo->chans[as->chans[i]]);
6719 SYSCTL_ADD_PROC(&d->play_sysctl_ctx,
6720 SYSCTL_CHILDREN(d->play_sysctl_tree), OID_AUTO,
6721 "32bit", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
6722 as, sizeof(as), hdaa_sysctl_32bit, "I",
6723 "Resolution of 32bit samples (20/24/32bit)");
6725 if (pdevinfo->recas >= 0) {
6726 as = &devinfo->as[pdevinfo->recas];
6727 for (i = 0; i < as->num_chans; i++)
6728 pcm_addchan(dev, PCMDIR_REC, &hdaa_channel_class,
6729 &devinfo->chans[as->chans[i]]);
6730 SYSCTL_ADD_PROC(&d->rec_sysctl_ctx,
6731 SYSCTL_CHILDREN(d->rec_sysctl_tree), OID_AUTO,
6732 "32bit", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
6733 as, sizeof(as), hdaa_sysctl_32bit, "I",
6734 "Resolution of 32bit samples (20/24/32bit)");
6735 pdevinfo->autorecsrc = 2;
6736 resource_int_value(device_get_name(dev), device_get_unit(dev),
6737 "rec.autosrc", &pdevinfo->autorecsrc);
6738 SYSCTL_ADD_INT(&d->rec_sysctl_ctx,
6739 SYSCTL_CHILDREN(d->rec_sysctl_tree), OID_AUTO,
6740 "autosrc", CTLTYPE_INT | CTLFLAG_RW,
6741 &pdevinfo->autorecsrc, 0,
6742 "Automatic recording source selection");
6745 if (pdevinfo->mixer != NULL) {
6746 hdaa_audio_ctl_set_defaults(pdevinfo);
6747 if (pdevinfo->recas >= 0) {
6748 as = &devinfo->as[pdevinfo->recas];
6750 hdaa_autorecsrc_handler(as, NULL);
6751 hdaa_unlock(devinfo);
6755 snprintf(status, SND_STATUSLEN, "on %s %s",
6756 device_get_nameunit(device_get_parent(dev)),
6757 PCM_KLDSTRING(snd_hda));
6758 pcm_setstatus(dev, status);
6764 hdaa_pcm_detach(device_t dev)
6766 struct hdaa_pcm_devinfo *pdevinfo =
6767 (struct hdaa_pcm_devinfo *)device_get_ivars(dev);
6770 if (pdevinfo->registered > 0) {
6771 err = pcm_unregister(dev);
6779 static device_method_t hdaa_pcm_methods[] = {
6780 /* device interface */
6781 DEVMETHOD(device_probe, hdaa_pcm_probe),
6782 DEVMETHOD(device_attach, hdaa_pcm_attach),
6783 DEVMETHOD(device_detach, hdaa_pcm_detach),
6787 static driver_t hdaa_pcm_driver = {
6793 DRIVER_MODULE(snd_hda_pcm, hdaa, hdaa_pcm_driver, pcm_devclass, 0, 0);
6794 MODULE_DEPEND(snd_hda, sound, SOUND_MINVER, SOUND_PREFVER, SOUND_MAXVER);
6795 MODULE_VERSION(snd_hda, 1);