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 old = w->wclass.pin.connected;
418 if (connected == old)
420 w->wclass.pin.connected = connected;
422 if (connected || old != 2) {
423 device_printf(devinfo->dev,
424 "Pin sense: nid=%d sence=0x%08x (%sconnected)\n",
425 w->nid, res, !connected ? "dis" : "");
429 as = &devinfo->as[w->bindas];
430 if (as->hpredir >= 0 && as->pins[15] == w->nid)
431 hdaa_hpredir_handler(w);
432 if (as->dir == HDAA_CTL_IN && old != 2)
433 hdaa_autorecsrc_handler(as, w);
437 * Callback for poll based presence detection.
440 hdaa_jack_poll_callback(void *arg)
442 struct hdaa_devinfo *devinfo = arg;
443 struct hdaa_widget *w;
447 if (devinfo->poll_ival == 0) {
448 hdaa_unlock(devinfo);
451 for (i = 0; i < devinfo->ascnt; i++) {
452 if (devinfo->as[i].hpredir < 0)
454 w = hdaa_widget_get(devinfo, devinfo->as[i].pins[15]);
455 if (w == NULL || w->enable == 0 || w->type !=
456 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
458 hdaa_presence_handler(w);
460 callout_reset(&devinfo->poll_jack, devinfo->poll_ival,
461 hdaa_jack_poll_callback, devinfo);
462 hdaa_unlock(devinfo);
466 hdaa_eld_dump(struct hdaa_widget *w)
468 struct hdaa_devinfo *devinfo = w->devinfo;
469 device_t dev = devinfo->dev;
471 int len, mnl, i, sadc, fmt;
473 if (w->eld == NULL || w->eld_len < 4)
476 "ELD nid=%d: ELD_Ver=%u Baseline_ELD_Len=%u\n",
477 w->nid, w->eld[0] >> 3, w->eld[2]);
478 if ((w->eld[0] >> 3) != 0x02)
480 len = min(w->eld_len, (u_int)w->eld[2] * 4);
481 mnl = w->eld[4] & 0x1f;
483 "ELD nid=%d: CEA_EDID_Ver=%u MNL=%u\n",
484 w->nid, w->eld[4] >> 5, mnl);
485 sadc = w->eld[5] >> 4;
487 "ELD nid=%d: SAD_Count=%u Conn_Type=%u S_AI=%u HDCP=%u\n",
488 w->nid, sadc, (w->eld[5] >> 2) & 0x3,
489 (w->eld[5] >> 1) & 0x1, w->eld[5] & 0x1);
491 "ELD nid=%d: Aud_Synch_Delay=%ums\n",
492 w->nid, w->eld[6] * 2);
494 "ELD nid=%d: Channels=0x%b\n",
496 "\020\07RLRC\06FLRC\05RC\04RLR\03FC\02LFE\01FLR");
498 "ELD nid=%d: Port_ID=0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
499 w->nid, w->eld[8], w->eld[9], w->eld[10], w->eld[11],
500 w->eld[12], w->eld[13], w->eld[14], w->eld[15]);
502 "ELD nid=%d: Manufacturer_Name=0x%02x%02x\n",
503 w->nid, w->eld[16], w->eld[17]);
505 "ELD nid=%d: Product_Code=0x%02x%02x\n",
506 w->nid, w->eld[18], w->eld[19]);
508 "ELD nid=%d: Monitor_Name_String='%.*s'\n",
509 w->nid, mnl, &w->eld[20]);
510 for (i = 0; i < sadc; i++) {
511 sad = &w->eld[20 + mnl + i * 3];
512 fmt = (sad[0] >> 3) & 0x0f;
513 if (fmt == HDA_HDMI_CODING_TYPE_REF_CTX) {
514 fmt = (sad[2] >> 3) & 0x1f;
515 if (fmt < 1 || fmt > 3)
521 "ELD nid=%d: %s %dch freqs=0x%b",
522 w->nid, HDA_HDMI_CODING_TYPES[fmt], (sad[0] & 0x07) + 1,
523 sad[1], "\020\007192\006176\00596\00488\00348\00244\00132");
525 case HDA_HDMI_CODING_TYPE_LPCM:
526 printf(" sizes=0x%b",
527 sad[2] & 0x07, "\020\00324\00220\00116");
529 case HDA_HDMI_CODING_TYPE_AC3:
530 case HDA_HDMI_CODING_TYPE_MPEG1:
531 case HDA_HDMI_CODING_TYPE_MP3:
532 case HDA_HDMI_CODING_TYPE_MPEG2:
533 case HDA_HDMI_CODING_TYPE_AACLC:
534 case HDA_HDMI_CODING_TYPE_DTS:
535 case HDA_HDMI_CODING_TYPE_ATRAC:
536 printf(" max_bitrate=%d", sad[2] * 8000);
538 case HDA_HDMI_CODING_TYPE_WMAPRO:
539 printf(" profile=%d", sad[2] & 0x07);
547 hdaa_eld_handler(struct hdaa_widget *w)
549 struct hdaa_devinfo *devinfo = w->devinfo;
553 if (w->enable == 0 || w->type !=
554 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
557 if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(w->wclass.pin.cap) == 0 ||
558 (HDA_CONFIG_DEFAULTCONF_MISC(w->wclass.pin.config) & 1) != 0)
561 res = hda_command(devinfo->dev, HDA_CMD_GET_PIN_SENSE(0, w->nid));
562 if ((w->eld != 0) == ((res & HDA_CMD_GET_PIN_SENSE_ELD_VALID) != 0))
564 if (w->eld != NULL) {
566 free(w->eld, M_HDAA);
570 device_printf(devinfo->dev,
571 "Pin sense: nid=%d sence=0x%08x "
572 "(%sconnected, ELD %svalid)\n",
574 (res & HDA_CMD_GET_PIN_SENSE_PRESENCE_DETECT) ? "" : "dis",
575 (res & HDA_CMD_GET_PIN_SENSE_ELD_VALID) ? "" : "in");
577 if ((res & HDA_CMD_GET_PIN_SENSE_ELD_VALID) == 0)
580 res = hda_command(devinfo->dev,
581 HDA_CMD_GET_HDMI_DIP_SIZE(0, w->nid, 0x08));
582 if (res == HDA_INVALID)
584 w->eld_len = res & 0xff;
586 w->eld = malloc(w->eld_len, M_HDAA, M_ZERO | M_NOWAIT);
587 if (w->eld == NULL) {
592 for (i = 0; i < w->eld_len; i++) {
593 res = hda_command(devinfo->dev,
594 HDA_CMD_GET_HDMI_ELDD(0, w->nid, i));
595 if (res & 0x80000000)
596 w->eld[i] = res & 0xff;
604 * Pin sense initializer.
607 hdaa_sense_init(struct hdaa_devinfo *devinfo)
609 struct hdaa_audio_as *as;
610 struct hdaa_widget *w;
613 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
614 w = hdaa_widget_get(devinfo, i);
615 if (w == NULL || w->enable == 0 || w->type !=
616 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
618 if (HDA_PARAM_AUDIO_WIDGET_CAP_UNSOL_CAP(w->param.widget_cap)) {
620 w->unsol = HDAC_UNSOL_ALLOC(
621 device_get_parent(devinfo->dev),
622 devinfo->dev, w->nid);
623 hda_command(devinfo->dev,
624 HDA_CMD_SET_UNSOLICITED_RESPONSE(0, w->nid,
625 HDA_CMD_SET_UNSOLICITED_RESPONSE_ENABLE | w->unsol));
627 as = &devinfo->as[w->bindas];
628 if (as->hpredir >= 0 && as->pins[15] == w->nid) {
629 if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(w->wclass.pin.cap) == 0 ||
630 (HDA_CONFIG_DEFAULTCONF_MISC(w->wclass.pin.config) & 1) != 0) {
631 device_printf(devinfo->dev,
632 "No presence detection support at nid %d\n",
638 device_printf(devinfo->dev,
639 "Headphones redirection for "
640 "association %d nid=%d using %s.\n",
642 (w->unsol < 0) ? "polling" :
643 "unsolicited responses");
647 hdaa_presence_handler(w);
648 if (!HDA_PARAM_PIN_CAP_DP(w->wclass.pin.cap) &&
649 !HDA_PARAM_PIN_CAP_HDMI(w->wclass.pin.cap))
654 callout_reset(&devinfo->poll_jack, 1,
655 hdaa_jack_poll_callback, devinfo);
660 hdaa_sense_deinit(struct hdaa_devinfo *devinfo)
662 struct hdaa_widget *w;
665 callout_stop(&devinfo->poll_jack);
666 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
667 w = hdaa_widget_get(devinfo, i);
668 if (w == NULL || w->enable == 0 || w->type !=
669 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
673 hda_command(devinfo->dev,
674 HDA_CMD_SET_UNSOLICITED_RESPONSE(0, w->nid, 0));
676 device_get_parent(devinfo->dev), devinfo->dev,
683 hdaa_widget_pin_patch(uint32_t config, const char *str)
686 char *key, *value, *rest, *bad;
689 strlcpy(buf, str, sizeof(buf));
691 while ((key = strsep(&rest, "=")) != NULL) {
692 value = strsep(&rest, " \t");
695 ival = strtol(value, &bad, 10);
696 if (strcmp(key, "seq") == 0) {
697 config &= ~HDA_CONFIG_DEFAULTCONF_SEQUENCE_MASK;
698 config |= ((ival << HDA_CONFIG_DEFAULTCONF_SEQUENCE_SHIFT) &
699 HDA_CONFIG_DEFAULTCONF_SEQUENCE_MASK);
700 } else if (strcmp(key, "as") == 0) {
701 config &= ~HDA_CONFIG_DEFAULTCONF_ASSOCIATION_MASK;
702 config |= ((ival << HDA_CONFIG_DEFAULTCONF_ASSOCIATION_SHIFT) &
703 HDA_CONFIG_DEFAULTCONF_ASSOCIATION_MASK);
704 } else if (strcmp(key, "misc") == 0) {
705 config &= ~HDA_CONFIG_DEFAULTCONF_MISC_MASK;
706 config |= ((ival << HDA_CONFIG_DEFAULTCONF_MISC_SHIFT) &
707 HDA_CONFIG_DEFAULTCONF_MISC_MASK);
708 } else if (strcmp(key, "color") == 0) {
709 config &= ~HDA_CONFIG_DEFAULTCONF_COLOR_MASK;
711 config |= ((ival << HDA_CONFIG_DEFAULTCONF_COLOR_SHIFT) &
712 HDA_CONFIG_DEFAULTCONF_COLOR_MASK);
714 for (i = 0; i < 16; i++) {
715 if (strcasecmp(HDA_COLORS[i], value) == 0) {
716 config |= (i << HDA_CONFIG_DEFAULTCONF_COLOR_SHIFT);
720 } else if (strcmp(key, "ctype") == 0) {
721 config &= ~HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_MASK;
723 config |= ((ival << HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_SHIFT) &
724 HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_MASK);
726 for (i = 0; i < 16; i++) {
727 if (strcasecmp(HDA_CONNECTORS[i], value) == 0) {
728 config |= (i << HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_SHIFT);
732 } else if (strcmp(key, "device") == 0) {
733 config &= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
735 config |= ((ival << HDA_CONFIG_DEFAULTCONF_DEVICE_SHIFT) &
736 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK);
739 for (i = 0; i < 16; i++) {
740 if (strcasecmp(HDA_DEVS[i], value) == 0) {
741 config |= (i << HDA_CONFIG_DEFAULTCONF_DEVICE_SHIFT);
745 } else if (strcmp(key, "loc") == 0) {
746 config &= ~HDA_CONFIG_DEFAULTCONF_LOCATION_MASK;
748 config |= ((ival << HDA_CONFIG_DEFAULTCONF_LOCATION_SHIFT) &
749 HDA_CONFIG_DEFAULTCONF_LOCATION_MASK);
752 for (i = 0; i < 64; i++) {
753 if (strcasecmp(HDA_LOCS[i], value) == 0) {
754 config |= (i << HDA_CONFIG_DEFAULTCONF_LOCATION_SHIFT);
758 } else if (strcmp(key, "conn") == 0) {
759 config &= ~HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK;
761 config |= ((ival << HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_SHIFT) &
762 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK);
765 for (i = 0; i < 4; i++) {
766 if (strcasecmp(HDA_CONNS[i], value) == 0) {
767 config |= (i << HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_SHIFT);
777 hdaa_gpio_patch(uint32_t gpio, const char *str)
780 char *key, *value, *rest;
783 strlcpy(buf, str, sizeof(buf));
785 while ((key = strsep(&rest, "=")) != NULL) {
786 value = strsep(&rest, " \t");
789 ikey = strtol(key, NULL, 10);
790 if (ikey < 0 || ikey > 7)
792 for (i = 0; i < 7; i++) {
793 if (strcasecmp(HDA_GPIO_ACTIONS[i], value) == 0) {
794 gpio &= ~HDAA_GPIO_MASK(ikey);
795 gpio |= i << HDAA_GPIO_SHIFT(ikey);
804 hdaa_local_patch_pin(struct hdaa_widget *w)
806 device_t dev = w->devinfo->dev;
807 const char *res = NULL;
808 uint32_t config, orig;
811 config = orig = w->wclass.pin.config;
812 snprintf(buf, sizeof(buf), "cad%u.nid%u.config",
813 hda_get_codec_id(dev), w->nid);
814 if (resource_string_value(device_get_name(
815 device_get_parent(device_get_parent(dev))),
816 device_get_unit(device_get_parent(device_get_parent(dev))),
818 if (strncmp(res, "0x", 2) == 0) {
819 config = strtol(res + 2, NULL, 16);
821 config = hdaa_widget_pin_patch(config, res);
824 snprintf(buf, sizeof(buf), "nid%u.config", w->nid);
825 if (resource_string_value(device_get_name(dev), device_get_unit(dev),
827 if (strncmp(res, "0x", 2) == 0) {
828 config = strtol(res + 2, NULL, 16);
830 config = hdaa_widget_pin_patch(config, res);
835 device_printf(w->devinfo->dev,
836 "Patching pin config nid=%u 0x%08x -> 0x%08x\n",
837 w->nid, orig, config);
839 w->wclass.pin.newconf = w->wclass.pin.config = config;
843 hdaa_sysctl_config(SYSCTL_HANDLER_ARGS)
849 conf = *(uint32_t *)oidp->oid_arg1;
850 snprintf(buf, sizeof(buf), "0x%08x as=%d seq=%d "
851 "device=%s conn=%s ctype=%s loc=%s color=%s misc=%d",
853 HDA_CONFIG_DEFAULTCONF_ASSOCIATION(conf),
854 HDA_CONFIG_DEFAULTCONF_SEQUENCE(conf),
855 HDA_DEVS[HDA_CONFIG_DEFAULTCONF_DEVICE(conf)],
856 HDA_CONNS[HDA_CONFIG_DEFAULTCONF_CONNECTIVITY(conf)],
857 HDA_CONNECTORS[HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE(conf)],
858 HDA_LOCS[HDA_CONFIG_DEFAULTCONF_LOCATION(conf)],
859 HDA_COLORS[HDA_CONFIG_DEFAULTCONF_COLOR(conf)],
860 HDA_CONFIG_DEFAULTCONF_MISC(conf));
861 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
862 if (error != 0 || req->newptr == NULL)
864 if (strncmp(buf, "0x", 2) == 0)
865 conf = strtol(buf + 2, NULL, 16);
867 conf = hdaa_widget_pin_patch(conf, buf);
868 *(uint32_t *)oidp->oid_arg1 = conf;
873 hdaa_config_fetch(const char *str, uint32_t *on, uint32_t *off)
875 int i = 0, j, k, len, inv;
878 while (str[i] != '\0' &&
879 (str[i] == ',' || isspace(str[i]) != 0))
884 while (str[j] != '\0' &&
885 !(str[j] == ',' || isspace(str[j]) != 0))
888 if (len > 2 && strncmp(str + i, "no", 2) == 0)
892 for (k = 0; len > inv && k < HDAA_QUIRKS_TAB_LEN; k++) {
893 if (strncmp(str + i + inv,
894 hdaa_quirks_tab[k].key, len - inv) != 0)
896 if (len - inv != strlen(hdaa_quirks_tab[k].key))
899 *on |= hdaa_quirks_tab[k].value;
900 *off &= ~hdaa_quirks_tab[k].value;
902 *off |= hdaa_quirks_tab[k].value;
903 *on &= ~hdaa_quirks_tab[k].value;
912 hdaa_sysctl_quirks(SYSCTL_HANDLER_ARGS)
916 uint32_t quirks, quirks_off;
918 quirks = *(uint32_t *)oidp->oid_arg1;
920 for (i = 0; i < HDAA_QUIRKS_TAB_LEN; i++) {
921 if ((quirks & hdaa_quirks_tab[i].value) != 0)
922 n += snprintf(buf + n, sizeof(buf) - n, "%s%s",
923 n != 0 ? "," : "", hdaa_quirks_tab[i].key);
925 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
926 if (error != 0 || req->newptr == NULL)
928 if (strncmp(buf, "0x", 2) == 0)
929 quirks = strtol(buf + 2, NULL, 16);
932 hdaa_config_fetch(buf, &quirks, &quirks_off);
934 *(uint32_t *)oidp->oid_arg1 = quirks;
939 hdaa_local_patch(struct hdaa_devinfo *devinfo)
941 struct hdaa_widget *w;
942 const char *res = NULL;
943 uint32_t quirks_on = 0, quirks_off = 0, x;
946 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
947 w = hdaa_widget_get(devinfo, i);
950 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
951 hdaa_local_patch_pin(w);
954 if (resource_string_value(device_get_name(devinfo->dev),
955 device_get_unit(devinfo->dev), "config", &res) == 0) {
956 if (res != NULL && strlen(res) > 0)
957 hdaa_config_fetch(res, &quirks_on, &quirks_off);
958 devinfo->quirks |= quirks_on;
959 devinfo->quirks &= ~quirks_off;
961 if (devinfo->newquirks == -1)
962 devinfo->newquirks = devinfo->quirks;
964 devinfo->quirks = devinfo->newquirks;
966 device_printf(devinfo->dev,
967 "Config options: 0x%08x\n", devinfo->quirks);
970 if (resource_string_value(device_get_name(devinfo->dev),
971 device_get_unit(devinfo->dev), "gpio_config", &res) == 0) {
972 if (strncmp(res, "0x", 2) == 0) {
973 devinfo->gpio = strtol(res + 2, NULL, 16);
975 devinfo->gpio = hdaa_gpio_patch(devinfo->gpio, res);
978 if (devinfo->newgpio == -1)
979 devinfo->newgpio = devinfo->gpio;
981 devinfo->gpio = devinfo->newgpio;
982 if (devinfo->newgpo == -1)
983 devinfo->newgpo = devinfo->gpo;
985 devinfo->gpo = devinfo->newgpo;
987 device_printf(devinfo->dev, "GPIO config options:");
988 for (i = 0; i < 7; i++) {
989 x = (devinfo->gpio & HDAA_GPIO_MASK(i)) >> HDAA_GPIO_SHIFT(i);
991 printf(" %d=%s", i, HDA_GPIO_ACTIONS[x]);
998 hdaa_widget_connection_parse(struct hdaa_widget *w)
1001 int i, j, max, ents, entnum;
1003 nid_t cnid, addcnid, prevcnid;
1007 res = hda_command(w->devinfo->dev,
1008 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_CONN_LIST_LENGTH));
1010 ents = HDA_PARAM_CONN_LIST_LENGTH_LIST_LENGTH(res);
1015 entnum = HDA_PARAM_CONN_LIST_LENGTH_LONG_FORM(res) ? 2 : 4;
1016 max = (sizeof(w->conns) / sizeof(w->conns[0])) - 1;
1019 #define CONN_RMASK(e) (1 << ((32 / (e)) - 1))
1020 #define CONN_NMASK(e) (CONN_RMASK(e) - 1)
1021 #define CONN_RESVAL(r, e, n) ((r) >> ((32 / (e)) * (n)))
1022 #define CONN_RANGE(r, e, n) (CONN_RESVAL(r, e, n) & CONN_RMASK(e))
1023 #define CONN_CNID(r, e, n) (CONN_RESVAL(r, e, n) & CONN_NMASK(e))
1025 for (i = 0; i < ents; i += entnum) {
1026 res = hda_command(w->devinfo->dev,
1027 HDA_CMD_GET_CONN_LIST_ENTRY(0, nid, i));
1028 for (j = 0; j < entnum; j++) {
1029 cnid = CONN_CNID(res, entnum, j);
1031 if (w->nconns < ents)
1032 device_printf(w->devinfo->dev,
1033 "WARNING: nid=%d has zero cnid "
1034 "entnum=%d j=%d index=%d "
1035 "entries=%d found=%d res=0x%08x\n",
1037 ents, w->nconns, res);
1041 if (cnid < w->devinfo->startnode ||
1042 cnid >= w->devinfo->endnode) {
1044 device_printf(w->devinfo->dev,
1045 "WARNING: nid=%d has cnid outside "
1046 "of the AFG range j=%d "
1047 "entnum=%d index=%d res=0x%08x\n",
1048 nid, j, entnum, i, res);
1051 if (CONN_RANGE(res, entnum, j) == 0)
1053 else if (prevcnid == 0 || prevcnid >= cnid) {
1054 device_printf(w->devinfo->dev,
1055 "WARNING: Invalid child range "
1056 "nid=%d index=%d j=%d entnum=%d "
1057 "prevcnid=%d cnid=%d res=0x%08x\n",
1058 nid, i, j, entnum, prevcnid,
1062 addcnid = prevcnid + 1;
1063 while (addcnid <= cnid) {
1064 if (w->nconns > max) {
1065 device_printf(w->devinfo->dev,
1066 "Adding %d (nid=%d): "
1067 "Max connection reached! max=%d\n",
1068 addcnid, nid, max + 1);
1071 w->connsenable[w->nconns] = 1;
1072 w->conns[w->nconns++] = addcnid++;
1083 hdaa_widget_parse(struct hdaa_widget *w)
1085 device_t dev = w->devinfo->dev;
1090 w->param.widget_cap = wcap = hda_command(dev,
1091 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_AUDIO_WIDGET_CAP));
1092 w->type = HDA_PARAM_AUDIO_WIDGET_CAP_TYPE(wcap);
1094 hdaa_widget_connection_parse(w);
1096 if (HDA_PARAM_AUDIO_WIDGET_CAP_OUT_AMP(wcap)) {
1097 if (HDA_PARAM_AUDIO_WIDGET_CAP_AMP_OVR(wcap))
1098 w->param.outamp_cap =
1100 HDA_CMD_GET_PARAMETER(0, nid,
1101 HDA_PARAM_OUTPUT_AMP_CAP));
1103 w->param.outamp_cap =
1104 w->devinfo->outamp_cap;
1106 w->param.outamp_cap = 0;
1108 if (HDA_PARAM_AUDIO_WIDGET_CAP_IN_AMP(wcap)) {
1109 if (HDA_PARAM_AUDIO_WIDGET_CAP_AMP_OVR(wcap))
1110 w->param.inamp_cap =
1112 HDA_CMD_GET_PARAMETER(0, nid,
1113 HDA_PARAM_INPUT_AMP_CAP));
1115 w->param.inamp_cap =
1116 w->devinfo->inamp_cap;
1118 w->param.inamp_cap = 0;
1120 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT ||
1121 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
1122 if (HDA_PARAM_AUDIO_WIDGET_CAP_FORMAT_OVR(wcap)) {
1123 cap = hda_command(dev,
1124 HDA_CMD_GET_PARAMETER(0, nid,
1125 HDA_PARAM_SUPP_STREAM_FORMATS));
1126 w->param.supp_stream_formats = (cap != 0) ? cap :
1127 w->devinfo->supp_stream_formats;
1128 cap = hda_command(dev,
1129 HDA_CMD_GET_PARAMETER(0, nid,
1130 HDA_PARAM_SUPP_PCM_SIZE_RATE));
1131 w->param.supp_pcm_size_rate = (cap != 0) ? cap :
1132 w->devinfo->supp_pcm_size_rate;
1134 w->param.supp_stream_formats =
1135 w->devinfo->supp_stream_formats;
1136 w->param.supp_pcm_size_rate =
1137 w->devinfo->supp_pcm_size_rate;
1139 if (HDA_PARAM_AUDIO_WIDGET_CAP_STRIPE(w->param.widget_cap)) {
1140 w->wclass.conv.stripecap = hda_command(dev,
1141 HDA_CMD_GET_STRIPE_CONTROL(0, w->nid)) >> 20;
1143 w->wclass.conv.stripecap = 1;
1145 w->param.supp_stream_formats = 0;
1146 w->param.supp_pcm_size_rate = 0;
1149 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) {
1150 w->wclass.pin.original = w->wclass.pin.newconf =
1151 w->wclass.pin.config = hda_command(dev,
1152 HDA_CMD_GET_CONFIGURATION_DEFAULT(0, w->nid));
1153 w->wclass.pin.cap = hda_command(dev,
1154 HDA_CMD_GET_PARAMETER(0, w->nid, HDA_PARAM_PIN_CAP));
1155 w->wclass.pin.ctrl = hda_command(dev,
1156 HDA_CMD_GET_PIN_WIDGET_CTRL(0, nid));
1157 w->wclass.pin.connected = 2;
1158 if (HDA_PARAM_PIN_CAP_EAPD_CAP(w->wclass.pin.cap)) {
1159 w->param.eapdbtl = hda_command(dev,
1160 HDA_CMD_GET_EAPD_BTL_ENABLE(0, nid));
1161 w->param.eapdbtl &= 0x7;
1162 w->param.eapdbtl |= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
1164 w->param.eapdbtl = HDA_INVALID;
1166 hdaa_unlock(w->devinfo);
1167 snprintf(buf, sizeof(buf), "nid%d_config", w->nid);
1168 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
1169 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
1170 buf, CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE,
1171 &w->wclass.pin.newconf, sizeof(&w->wclass.pin.newconf),
1172 hdaa_sysctl_config, "A", "Current pin configuration");
1173 snprintf(buf, sizeof(buf), "nid%d_original", w->nid);
1174 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
1175 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
1176 buf, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
1177 &w->wclass.pin.original, sizeof(&w->wclass.pin.original),
1178 hdaa_sysctl_config, "A", "Original pin configuration");
1179 hdaa_lock(w->devinfo);
1185 hdaa_widget_postprocess(struct hdaa_widget *w)
1189 w->type = HDA_PARAM_AUDIO_WIDGET_CAP_TYPE(w->param.widget_cap);
1191 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT:
1192 typestr = "audio output";
1194 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT:
1195 typestr = "audio input";
1197 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER:
1198 typestr = "audio mixer";
1200 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR:
1201 typestr = "audio selector";
1203 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
1206 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_POWER_WIDGET:
1207 typestr = "power widget";
1209 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_VOLUME_WIDGET:
1210 typestr = "volume widget";
1212 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET:
1213 typestr = "beep widget";
1215 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_VENDOR_WIDGET:
1216 typestr = "vendor widget";
1219 typestr = "unknown type";
1222 strlcpy(w->name, typestr, sizeof(w->name));
1224 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) {
1229 config = w->wclass.pin.config;
1230 devstr = HDA_DEVS[(config & HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) >>
1231 HDA_CONFIG_DEFAULTCONF_DEVICE_SHIFT];
1232 conn = (config & HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK) >>
1233 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_SHIFT;
1234 color = (config & HDA_CONFIG_DEFAULTCONF_COLOR_MASK) >>
1235 HDA_CONFIG_DEFAULTCONF_COLOR_SHIFT;
1236 strlcat(w->name, ": ", sizeof(w->name));
1237 strlcat(w->name, devstr, sizeof(w->name));
1238 strlcat(w->name, " (", sizeof(w->name));
1239 if (conn == 0 && color != 0 && color != 15) {
1240 strlcat(w->name, HDA_COLORS[color], sizeof(w->name));
1241 strlcat(w->name, " ", sizeof(w->name));
1243 strlcat(w->name, HDA_CONNS[conn], sizeof(w->name));
1244 strlcat(w->name, ")", sizeof(w->name));
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) {
2131 if (pdevinfo->index != 0)
2134 if (w->bindas != pdevinfo->playas &&
2135 w->bindas != pdevinfo->recas)
2138 if (dev == SOUND_MIXER_RECLEV &&
2139 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
2140 hdaa_audio_ctl_dest_volume(pdevinfo, dev,
2141 w->nid, -1, mute, lvol, rvol, 0);
2144 if (dev == SOUND_MIXER_VOLUME &&
2145 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
2146 devinfo->as[w->bindas].dir == HDAA_CTL_OUT) {
2147 hdaa_audio_ctl_dest_volume(pdevinfo, dev,
2148 w->nid, -1, mute, lvol, rvol, 0);
2151 if (dev == SOUND_MIXER_IGAIN &&
2152 w->pflags & HDAA_ADC_MONITOR) {
2153 for (j = 0; j < w->nconns; j++) {
2154 if (!w->connsenable[j])
2156 cw = hdaa_widget_get(devinfo, w->conns[j]);
2157 if (cw == NULL || cw->enable == 0)
2159 if (cw->bindas == -1)
2161 if (cw->bindas >= 0 &&
2162 devinfo->as[cw->bindas].dir != HDAA_CTL_IN)
2164 hdaa_audio_ctl_dest_volume(pdevinfo, dev,
2165 w->nid, j, mute, lvol, rvol, 0);
2169 if (w->ossdev != dev)
2171 hdaa_audio_ctl_source_volume(pdevinfo, dev,
2172 w->nid, -1, mute, lvol, rvol, 0);
2173 if (dev == SOUND_MIXER_IMIX && (w->pflags & HDAA_IMIX_AS_DST))
2174 hdaa_audio_ctl_dest_volume(pdevinfo, dev,
2175 w->nid, -1, mute, lvol, rvol, 0);
2180 * OSS Mixer set method.
2183 hdaa_audio_ctl_ossmixer_set(struct snd_mixer *m, unsigned dev,
2184 unsigned left, unsigned right)
2186 struct hdaa_pcm_devinfo *pdevinfo = mix_getdevinfo(m);
2187 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
2188 struct hdaa_widget *w;
2193 /* Save new values. */
2194 pdevinfo->left[dev] = left;
2195 pdevinfo->right[dev] = right;
2197 /* 'ogain' is the special case implemented with EAPD. */
2198 if (dev == SOUND_MIXER_OGAIN) {
2201 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2202 w = hdaa_widget_get(devinfo, i);
2203 if (w == NULL || w->enable == 0)
2205 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX ||
2206 w->param.eapdbtl == HDA_INVALID)
2210 if (i >= devinfo->endnode) {
2211 hdaa_unlock(devinfo);
2214 orig = w->param.eapdbtl;
2216 w->param.eapdbtl &= ~HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
2218 w->param.eapdbtl |= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
2219 if (orig != w->param.eapdbtl) {
2222 val = w->param.eapdbtl;
2223 if (devinfo->quirks & HDAA_QUIRK_EAPDINV)
2224 val ^= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
2225 hda_command(devinfo->dev,
2226 HDA_CMD_SET_EAPD_BTL_ENABLE(0, w->nid, val));
2228 hdaa_unlock(devinfo);
2229 return (left | (left << 8));
2232 /* Recalculate all controls related to this OSS device. */
2233 hdaa_audio_ctl_dev_volume(pdevinfo, dev);
2235 hdaa_unlock(devinfo);
2236 return (left | (right << 8));
2240 * Set mixer settings to our own default values:
2241 * +20dB for mics, -10dB for analog vol, mute for igain, 0dB for others.
2244 hdaa_audio_ctl_set_defaults(struct hdaa_pcm_devinfo *pdevinfo)
2248 for (dev = 0; dev < SOUND_MIXER_NRDEVICES; dev++) {
2249 if ((pdevinfo->ossmask & (1 << dev)) == 0)
2252 /* If the value was overriden, leave it as is. */
2253 if (resource_int_value(device_get_name(pdevinfo->dev),
2254 device_get_unit(pdevinfo->dev), ossnames[dev], &vol) == 0)
2258 if (dev == SOUND_MIXER_OGAIN)
2260 else if (dev == SOUND_MIXER_IGAIN)
2262 else if (dev == SOUND_MIXER_MIC ||
2263 dev == SOUND_MIXER_MONITOR)
2264 amp = 20 * 4; /* +20dB */
2265 else if (dev == SOUND_MIXER_VOLUME && !pdevinfo->digital)
2266 amp = -10 * 4; /* -10dB */
2270 (pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]) <= 0) {
2272 } else if (vol < 0) {
2273 vol = ((amp - pdevinfo->minamp[dev]) * 100 +
2274 (pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]) / 2) /
2275 (pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]);
2276 vol = imin(imax(vol, 1), 100);
2278 mix_set(pdevinfo->mixer, dev, vol, vol);
2283 * Recursively commutate specified record source.
2286 hdaa_audio_ctl_recsel_comm(struct hdaa_pcm_devinfo *pdevinfo, uint32_t src, nid_t nid, int depth)
2288 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
2289 struct hdaa_widget *w, *cw;
2290 struct hdaa_audio_ctl *ctl;
2295 if (depth > HDA_PARSE_MAXDEPTH)
2298 w = hdaa_widget_get(devinfo, nid);
2299 if (w == NULL || w->enable == 0)
2302 for (i = 0; i < w->nconns; i++) {
2303 if (w->connsenable[i] == 0)
2305 cw = hdaa_widget_get(devinfo, w->conns[i]);
2306 if (cw == NULL || cw->enable == 0 || cw->bindas == -1)
2308 /* Call recursively to trace signal to it's source if needed. */
2309 if ((src & cw->ossmask) != 0) {
2310 if (cw->ossdev < 0) {
2311 res |= hdaa_audio_ctl_recsel_comm(pdevinfo, src,
2312 w->conns[i], depth + 1);
2317 /* We have two special cases: mixers and others (selectors). */
2318 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) {
2319 ctl = hdaa_audio_ctl_amp_get(devinfo,
2320 w->nid, HDAA_CTL_IN, i, 1);
2323 /* If we have input control on this node mute them
2324 * according to requested sources. */
2325 muted = (src & cw->ossmask) ? 0 : 1;
2326 if (muted != ctl->forcemute) {
2327 ctl->forcemute = muted;
2328 hdaa_audio_ctl_amp_set(ctl,
2329 HDAA_AMP_MUTE_DEFAULT,
2330 HDAA_AMP_VOL_DEFAULT, HDAA_AMP_VOL_DEFAULT);
2333 device_printf(pdevinfo->dev,
2334 "Recsel (%s): nid %d source %d %s\n",
2335 hdaa_audio_ctl_ossmixer_mask2allname(
2336 src, buf, sizeof(buf)),
2337 nid, i, muted?"mute":"unmute");
2342 if ((src & cw->ossmask) == 0)
2344 /* If we found requested source - select it and exit. */
2345 hdaa_widget_connection_select(w, i);
2347 device_printf(pdevinfo->dev,
2348 "Recsel (%s): nid %d source %d select\n",
2349 hdaa_audio_ctl_ossmixer_mask2allname(
2350 src, buf, sizeof(buf)),
2360 hdaa_audio_ctl_ossmixer_setrecsrc(struct snd_mixer *m, uint32_t src)
2362 struct hdaa_pcm_devinfo *pdevinfo = mix_getdevinfo(m);
2363 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
2364 struct hdaa_widget *w;
2365 struct hdaa_audio_as *as;
2366 struct hdaa_audio_ctl *ctl;
2367 struct hdaa_chan *ch;
2369 uint32_t ret = 0xffffffff;
2372 if (pdevinfo->recas < 0) {
2373 hdaa_unlock(devinfo);
2376 as = &devinfo->as[pdevinfo->recas];
2378 /* For non-mixed associations we always recording everything. */
2380 hdaa_unlock(devinfo);
2381 return (mix_getrecdevs(m));
2384 /* Commutate requested recsrc for each ADC. */
2385 for (j = 0; j < as->num_chans; j++) {
2386 ch = &devinfo->chans[as->chans[j]];
2387 for (i = 0; ch->io[i] >= 0; i++) {
2388 w = hdaa_widget_get(devinfo, ch->io[i]);
2389 if (w == NULL || w->enable == 0)
2391 ret &= hdaa_audio_ctl_recsel_comm(pdevinfo, src,
2395 if (ret == 0xffffffff)
2399 * Some controls could be shared. Reset volumes for controls
2400 * related to previously chosen devices, as they may no longer
2401 * affect the signal.
2404 while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) {
2405 if (ctl->enable == 0 ||
2406 !(ctl->ossmask & pdevinfo->recsrc))
2408 if (!((pdevinfo->playas >= 0 &&
2409 ctl->widget->bindas == pdevinfo->playas) ||
2410 (pdevinfo->recas >= 0 &&
2411 ctl->widget->bindas == pdevinfo->recas) ||
2412 (pdevinfo->index == 0 &&
2413 ctl->widget->bindas == -2)))
2415 for (j = 0; j < SOUND_MIXER_NRDEVICES; j++) {
2416 if (pdevinfo->recsrc & (1 << j)) {
2417 ctl->devleft[j] = 0;
2418 ctl->devright[j] = 0;
2419 ctl->devmute[j] = 0;
2425 * Some controls could be shared. Set volumes for controls
2426 * related to devices selected both previously and now.
2428 for (j = 0; j < SOUND_MIXER_NRDEVICES; j++) {
2429 if ((ret | pdevinfo->recsrc) & (1 << j))
2430 hdaa_audio_ctl_dev_volume(pdevinfo, j);
2433 pdevinfo->recsrc = ret;
2434 hdaa_unlock(devinfo);
2438 static kobj_method_t hdaa_audio_ctl_ossmixer_methods[] = {
2439 KOBJMETHOD(mixer_init, hdaa_audio_ctl_ossmixer_init),
2440 KOBJMETHOD(mixer_set, hdaa_audio_ctl_ossmixer_set),
2441 KOBJMETHOD(mixer_setrecsrc, hdaa_audio_ctl_ossmixer_setrecsrc),
2444 MIXER_DECLARE(hdaa_audio_ctl_ossmixer);
2447 hdaa_dump_gpi(struct hdaa_devinfo *devinfo)
2449 device_t dev = devinfo->dev;
2451 uint32_t data, wake, unsol, sticky;
2453 if (HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap) > 0) {
2454 data = hda_command(dev,
2455 HDA_CMD_GET_GPI_DATA(0, devinfo->nid));
2456 wake = hda_command(dev,
2457 HDA_CMD_GET_GPI_WAKE_ENABLE_MASK(0, devinfo->nid));
2458 unsol = hda_command(dev,
2459 HDA_CMD_GET_GPI_UNSOLICITED_ENABLE_MASK(0, devinfo->nid));
2460 sticky = hda_command(dev,
2461 HDA_CMD_GET_GPI_STICKY_MASK(0, devinfo->nid));
2462 for (i = 0; i < HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap); i++) {
2463 device_printf(dev, " GPI%d:%s%s%s state=%d", i,
2464 (sticky & (1 << i)) ? " sticky" : "",
2465 (unsol & (1 << i)) ? " unsol" : "",
2466 (wake & (1 << i)) ? " wake" : "",
2473 hdaa_dump_gpio(struct hdaa_devinfo *devinfo)
2475 device_t dev = devinfo->dev;
2477 uint32_t data, dir, enable, wake, unsol, sticky;
2479 if (HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap) > 0) {
2480 data = hda_command(dev,
2481 HDA_CMD_GET_GPIO_DATA(0, devinfo->nid));
2482 enable = hda_command(dev,
2483 HDA_CMD_GET_GPIO_ENABLE_MASK(0, devinfo->nid));
2484 dir = hda_command(dev,
2485 HDA_CMD_GET_GPIO_DIRECTION(0, devinfo->nid));
2486 wake = hda_command(dev,
2487 HDA_CMD_GET_GPIO_WAKE_ENABLE_MASK(0, devinfo->nid));
2488 unsol = hda_command(dev,
2489 HDA_CMD_GET_GPIO_UNSOLICITED_ENABLE_MASK(0, devinfo->nid));
2490 sticky = hda_command(dev,
2491 HDA_CMD_GET_GPIO_STICKY_MASK(0, devinfo->nid));
2492 for (i = 0; i < HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap); i++) {
2493 device_printf(dev, " GPIO%d: ", i);
2494 if ((enable & (1 << i)) == 0) {
2495 printf("disabled\n");
2498 if ((dir & (1 << i)) == 0) {
2499 printf("input%s%s%s",
2500 (sticky & (1 << i)) ? " sticky" : "",
2501 (unsol & (1 << i)) ? " unsol" : "",
2502 (wake & (1 << i)) ? " wake" : "");
2505 printf(" state=%d\n", (data >> i) & 1);
2511 hdaa_dump_gpo(struct hdaa_devinfo *devinfo)
2513 device_t dev = devinfo->dev;
2517 if (HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap) > 0) {
2518 data = hda_command(dev,
2519 HDA_CMD_GET_GPO_DATA(0, devinfo->nid));
2520 for (i = 0; i < HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap); i++) {
2521 device_printf(dev, " GPO%d: state=%d", i,
2528 hdaa_audio_parse(struct hdaa_devinfo *devinfo)
2530 struct hdaa_widget *w;
2537 res = hda_command(devinfo->dev,
2538 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_GPIO_COUNT));
2539 devinfo->gpio_cap = res;
2542 device_printf(devinfo->dev,
2543 "NumGPIO=%d NumGPO=%d "
2544 "NumGPI=%d GPIWake=%d GPIUnsol=%d\n",
2545 HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap),
2546 HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap),
2547 HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap),
2548 HDA_PARAM_GPIO_COUNT_GPI_WAKE(devinfo->gpio_cap),
2549 HDA_PARAM_GPIO_COUNT_GPI_UNSOL(devinfo->gpio_cap));
2550 hdaa_dump_gpi(devinfo);
2551 hdaa_dump_gpio(devinfo);
2552 hdaa_dump_gpo(devinfo);
2555 res = hda_command(devinfo->dev,
2556 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_SUPP_STREAM_FORMATS));
2557 devinfo->supp_stream_formats = res;
2559 res = hda_command(devinfo->dev,
2560 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_SUPP_PCM_SIZE_RATE));
2561 devinfo->supp_pcm_size_rate = res;
2563 res = hda_command(devinfo->dev,
2564 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_OUTPUT_AMP_CAP));
2565 devinfo->outamp_cap = res;
2567 res = hda_command(devinfo->dev,
2568 HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_INPUT_AMP_CAP));
2569 devinfo->inamp_cap = res;
2571 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2572 w = hdaa_widget_get(devinfo, i);
2574 device_printf(devinfo->dev, "Ghost widget! nid=%d!\n", i);
2576 w->devinfo = devinfo;
2583 w->param.eapdbtl = HDA_INVALID;
2584 hdaa_widget_parse(w);
2590 hdaa_audio_postprocess(struct hdaa_devinfo *devinfo)
2592 struct hdaa_widget *w;
2595 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2596 w = hdaa_widget_get(devinfo, i);
2599 hdaa_widget_postprocess(w);
2604 hdaa_audio_ctl_parse(struct hdaa_devinfo *devinfo)
2606 struct hdaa_audio_ctl *ctls;
2607 struct hdaa_widget *w, *cw;
2608 int i, j, cnt, max, ocap, icap;
2609 int mute, offset, step, size;
2611 /* XXX This is redundant */
2613 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2614 w = hdaa_widget_get(devinfo, i);
2615 if (w == NULL || w->enable == 0)
2617 if (w->param.outamp_cap != 0)
2619 if (w->param.inamp_cap != 0) {
2621 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR:
2622 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER:
2623 for (j = 0; j < w->nconns; j++) {
2624 cw = hdaa_widget_get(devinfo,
2626 if (cw == NULL || cw->enable == 0)
2637 devinfo->ctlcnt = max;
2642 ctls = (struct hdaa_audio_ctl *)malloc(
2643 sizeof(*ctls) * max, M_HDAA, M_ZERO | M_NOWAIT);
2647 device_printf(devinfo->dev, "unable to allocate ctls!\n");
2648 devinfo->ctlcnt = 0;
2653 for (i = devinfo->startnode; cnt < max && i < devinfo->endnode; i++) {
2655 device_printf(devinfo->dev, "%s: Ctl overflow!\n",
2659 w = hdaa_widget_get(devinfo, i);
2660 if (w == NULL || w->enable == 0)
2662 ocap = w->param.outamp_cap;
2663 icap = w->param.inamp_cap;
2665 mute = HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(ocap);
2666 step = HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(ocap);
2667 size = HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(ocap);
2668 offset = HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(ocap);
2669 /*if (offset > step) {
2671 device_printf(devinfo->dev,
2672 "BUGGY outamp: nid=%d "
2673 "[offset=%d > step=%d]\n",
2674 w->nid, offset, step);
2678 ctls[cnt].enable = 1;
2679 ctls[cnt].widget = w;
2680 ctls[cnt].mute = mute;
2681 ctls[cnt].step = step;
2682 ctls[cnt].size = size;
2683 ctls[cnt].offset = offset;
2684 ctls[cnt].left = offset;
2685 ctls[cnt].right = offset;
2686 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX ||
2688 ctls[cnt].ndir = HDAA_CTL_IN;
2690 ctls[cnt].ndir = HDAA_CTL_OUT;
2691 ctls[cnt++].dir = HDAA_CTL_OUT;
2695 mute = HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(icap);
2696 step = HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(icap);
2697 size = HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(icap);
2698 offset = HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(icap);
2699 /*if (offset > step) {
2701 device_printf(devinfo->dev,
2702 "BUGGY inamp: nid=%d "
2703 "[offset=%d > step=%d]\n",
2704 w->nid, offset, step);
2709 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR:
2710 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER:
2711 for (j = 0; j < w->nconns; j++) {
2713 device_printf(devinfo->dev,
2714 "%s: Ctl overflow!\n",
2718 cw = hdaa_widget_get(devinfo,
2720 if (cw == NULL || cw->enable == 0)
2722 ctls[cnt].enable = 1;
2723 ctls[cnt].widget = w;
2724 ctls[cnt].childwidget = cw;
2725 ctls[cnt].index = j;
2726 ctls[cnt].mute = mute;
2727 ctls[cnt].step = step;
2728 ctls[cnt].size = size;
2729 ctls[cnt].offset = offset;
2730 ctls[cnt].left = offset;
2731 ctls[cnt].right = offset;
2732 ctls[cnt].ndir = HDAA_CTL_IN;
2733 ctls[cnt++].dir = HDAA_CTL_IN;
2738 device_printf(devinfo->dev,
2739 "%s: Ctl overflow!\n",
2743 ctls[cnt].enable = 1;
2744 ctls[cnt].widget = w;
2745 ctls[cnt].mute = mute;
2746 ctls[cnt].step = step;
2747 ctls[cnt].size = size;
2748 ctls[cnt].offset = offset;
2749 ctls[cnt].left = offset;
2750 ctls[cnt].right = offset;
2752 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
2753 ctls[cnt].ndir = HDAA_CTL_OUT;
2755 ctls[cnt].ndir = HDAA_CTL_IN;
2756 ctls[cnt++].dir = HDAA_CTL_IN;
2762 devinfo->ctl = ctls;
2766 hdaa_audio_as_parse(struct hdaa_devinfo *devinfo)
2768 struct hdaa_audio_as *as;
2769 struct hdaa_widget *w;
2770 int i, j, cnt, max, type, dir, assoc, seq, first, hpredir;
2772 /* Count present associations */
2774 for (j = 1; j < 16; j++) {
2775 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2776 w = hdaa_widget_get(devinfo, i);
2777 if (w == NULL || w->enable == 0)
2779 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
2781 if (HDA_CONFIG_DEFAULTCONF_ASSOCIATION(w->wclass.pin.config)
2785 if (j != 15) /* There could be many 1-pin assocs #15 */
2790 devinfo->ascnt = max;
2795 as = (struct hdaa_audio_as *)malloc(
2796 sizeof(*as) * max, M_HDAA, M_ZERO | M_NOWAIT);
2800 device_printf(devinfo->dev, "unable to allocate assocs!\n");
2805 for (i = 0; i < max; i++) {
2808 as[i].num_chans = 1;
2809 as[i].location = -1;
2812 /* Scan associations skipping as=0. */
2814 for (j = 1; j < 16; j++) {
2817 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
2818 w = hdaa_widget_get(devinfo, i);
2819 if (w == NULL || w->enable == 0)
2821 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
2823 assoc = HDA_CONFIG_DEFAULTCONF_ASSOCIATION(w->wclass.pin.config);
2824 seq = HDA_CONFIG_DEFAULTCONF_SEQUENCE(w->wclass.pin.config);
2829 ("%s: Associations owerflow (%d of %d)",
2830 __func__, cnt, max));
2831 type = w->wclass.pin.config &
2832 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
2833 /* Get pin direction. */
2834 if (type == HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_OUT ||
2835 type == HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER ||
2836 type == HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT ||
2837 type == HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_OUT ||
2838 type == HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_OUT)
2842 /* If this is a first pin - create new association. */
2843 if (as[cnt].pincnt == 0) {
2850 /* Check association correctness. */
2851 if (as[cnt].pins[seq] != 0) {
2852 device_printf(devinfo->dev, "%s: Duplicate pin %d (%d) "
2853 "in association %d! Disabling association.\n",
2854 __func__, seq, w->nid, j);
2857 if (dir != as[cnt].dir) {
2858 device_printf(devinfo->dev, "%s: Pin %d has wrong "
2859 "direction for association %d! Disabling "
2861 __func__, w->nid, j);
2864 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) {
2865 as[cnt].digital |= 0x1;
2866 if (HDA_PARAM_PIN_CAP_HDMI(w->wclass.pin.cap))
2867 as[cnt].digital |= 0x2;
2868 if (HDA_PARAM_PIN_CAP_DP(w->wclass.pin.cap))
2869 as[cnt].digital |= 0x4;
2871 if (as[cnt].location == -1) {
2873 HDA_CONFIG_DEFAULTCONF_LOCATION(w->wclass.pin.config);
2874 } else if (as[cnt].location !=
2875 HDA_CONFIG_DEFAULTCONF_LOCATION(w->wclass.pin.config)) {
2876 as[cnt].location = -2;
2878 /* Headphones with seq=15 may mean redirection. */
2879 if (type == HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT &&
2882 as[cnt].pins[seq] = w->nid;
2884 /* Association 15 is a multiple unassociated pins. */
2888 if (j != 15 && as[cnt].pincnt > 0) {
2889 if (hpredir && as[cnt].pincnt > 1)
2890 as[cnt].hpredir = first;
2894 for (i = 0; i < max; i++) {
2895 if (as[i].dir == HDAA_CTL_IN && (as[i].pincnt == 1 ||
2896 as[i].pins[14] > 0 || as[i].pins[15] > 0))
2900 device_printf(devinfo->dev,
2901 "%d associations found:\n", max);
2902 for (i = 0; i < max; i++) {
2903 device_printf(devinfo->dev,
2904 "Association %d (%d) %s%s:\n",
2905 i, as[i].index, (as[i].dir == HDAA_CTL_IN)?"in":"out",
2906 as[i].enable?"":" (disabled)");
2907 for (j = 0; j < 16; j++) {
2908 if (as[i].pins[j] == 0)
2910 device_printf(devinfo->dev,
2911 " Pin nid=%d seq=%d\n",
2921 * Trace path from DAC to pin.
2924 hdaa_audio_trace_dac(struct hdaa_devinfo *devinfo, int as, int seq, nid_t nid,
2925 int dupseq, int min, int only, int depth)
2927 struct hdaa_widget *w;
2931 if (depth > HDA_PARSE_MAXDEPTH)
2933 w = hdaa_widget_get(devinfo, nid);
2934 if (w == NULL || w->enable == 0)
2938 device_printf(devinfo->dev,
2939 " %*stracing via nid %d\n",
2940 depth + 1, "", w->nid);
2943 /* Use only unused widgets */
2944 if (w->bindas >= 0 && w->bindas != as) {
2947 device_printf(devinfo->dev,
2948 " %*snid %d busy by association %d\n",
2949 depth + 1, "", w->nid, w->bindas);
2955 if (w->bindseqmask != 0) {
2958 device_printf(devinfo->dev,
2959 " %*snid %d busy by seqmask %x\n",
2960 depth + 1, "", w->nid, w->bindseqmask);
2966 /* If this is headphones - allow duplicate first pin. */
2967 if (w->bindseqmask != 0 &&
2968 (w->bindseqmask & (1 << dupseq)) == 0) {
2970 device_printf(devinfo->dev,
2971 " %*snid %d busy by seqmask %x\n",
2972 depth + 1, "", w->nid, w->bindseqmask);
2979 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT:
2980 /* Do not traverse input. AD1988 has digital monitor
2981 for which we are not ready. */
2983 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT:
2984 /* If we are tracing HP take only dac of first pin. */
2985 if ((only == 0 || only == w->nid) &&
2986 (w->nid >= min) && (dupseq < 0 || w->nid ==
2987 devinfo->as[as].dacs[0][dupseq]))
2990 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
2995 /* Find reachable DACs with smallest nid respecting constraints. */
2996 for (i = 0; i < w->nconns; i++) {
2997 if (w->connsenable[i] == 0)
2999 if (w->selconn != -1 && w->selconn != i)
3001 if ((ret = hdaa_audio_trace_dac(devinfo, as, seq,
3002 w->conns[i], dupseq, min, only, depth + 1)) != 0) {
3003 if (m == 0 || ret < m) {
3007 if (only || dupseq >= 0)
3011 if (im >= 0 && only && ((w->nconns > 1 &&
3012 w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) ||
3013 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR))
3019 w->bindseqmask |= (1 << seq);
3023 device_printf(devinfo->dev,
3024 " %*snid %d returned %d\n",
3025 depth + 1, "", w->nid, m);
3032 * Trace path from widget to ADC.
3035 hdaa_audio_trace_adc(struct hdaa_devinfo *devinfo, int as, int seq, nid_t nid,
3036 int mixed, int min, int only, int depth, int *length, int onlylength)
3038 struct hdaa_widget *w, *wc;
3039 int i, j, im, lm = HDA_PARSE_MAXDEPTH;
3042 if (depth > HDA_PARSE_MAXDEPTH)
3044 w = hdaa_widget_get(devinfo, nid);
3045 if (w == NULL || w->enable == 0)
3048 device_printf(devinfo->dev,
3049 " %*stracing via nid %d\n",
3050 depth + 1, "", w->nid);
3052 /* Use only unused widgets */
3053 if (w->bindas >= 0 && w->bindas != as) {
3055 device_printf(devinfo->dev,
3056 " %*snid %d busy by association %d\n",
3057 depth + 1, "", w->nid, w->bindas);
3061 if (!mixed && w->bindseqmask != 0) {
3063 device_printf(devinfo->dev,
3064 " %*snid %d busy by seqmask %x\n",
3065 depth + 1, "", w->nid, w->bindseqmask);
3070 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT:
3071 if ((only == 0 || only == w->nid) && (w->nid >= min) &&
3072 (onlylength == 0 || onlylength == depth)) {
3077 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
3082 /* Try to find reachable ADCs with specified nid. */
3083 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
3084 wc = hdaa_widget_get(devinfo, j);
3085 if (wc == NULL || wc->enable == 0)
3088 for (i = 0; i < wc->nconns; i++) {
3089 if (wc->connsenable[i] == 0)
3091 if (wc->conns[i] != nid)
3093 if ((ret = hdaa_audio_trace_adc(devinfo, as, seq,
3094 j, mixed, min, only, depth + 1,
3095 length, onlylength)) != 0) {
3096 if (m == 0 || ret < m ||
3097 (ret == m && *length < lm)) {
3107 if (im >= 0 && only && ((wc->nconns > 1 &&
3108 wc->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) ||
3109 wc->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR))
3116 w->bindseqmask |= (1 << seq);
3119 device_printf(devinfo->dev,
3120 " %*snid %d returned %d\n",
3121 depth + 1, "", w->nid, m);
3127 * Erase trace path of the specified association.
3130 hdaa_audio_undo_trace(struct hdaa_devinfo *devinfo, int as, int seq)
3132 struct hdaa_widget *w;
3135 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3136 w = hdaa_widget_get(devinfo, i);
3137 if (w == NULL || w->enable == 0)
3139 if (w->bindas == as) {
3141 w->bindseqmask &= ~(1 << seq);
3142 if (w->bindseqmask == 0) {
3156 * Trace association path from DAC to output
3159 hdaa_audio_trace_as_out(struct hdaa_devinfo *devinfo, int as, int seq)
3161 struct hdaa_audio_as *ases = devinfo->as;
3166 for (i = seq; i < 16 && ases[as].pins[i] == 0; i++)
3168 /* Check if there is no any left. If so - we succeeded. */
3172 hpredir = (i == 15 && ases[as].fakeredir == 0)?ases[as].hpredir:-1;
3176 device_printf(devinfo->dev,
3177 " Tracing pin %d with min nid %d",
3178 ases[as].pins[i], min);
3180 printf(" and hpredir %d", hpredir);
3183 /* Trace this pin taking min nid into account. */
3184 res = hdaa_audio_trace_dac(devinfo, as, i,
3185 ases[as].pins[i], hpredir, min, 0, 0);
3187 /* If we failed - return to previous and redo it. */
3189 device_printf(devinfo->dev,
3190 " Unable to trace pin %d seq %d with min "
3192 ases[as].pins[i], i, min);
3194 printf(" and hpredir %d", hpredir);
3200 device_printf(devinfo->dev,
3201 " Pin %d traced to DAC %d",
3202 ases[as].pins[i], res);
3204 printf(" and hpredir %d", hpredir);
3205 if (ases[as].fakeredir)
3206 printf(" with fake redirection");
3209 /* Trace again to mark the path */
3210 hdaa_audio_trace_dac(devinfo, as, i,
3211 ases[as].pins[i], hpredir, min, res, 0);
3212 ases[as].dacs[0][i] = res;
3213 /* We succeeded, so call next. */
3214 if (hdaa_audio_trace_as_out(devinfo, as, i + 1))
3216 /* If next failed, we should retry with next min */
3217 hdaa_audio_undo_trace(devinfo, as, i);
3218 ases[as].dacs[0][i] = 0;
3224 * Check equivalency of two DACs.
3227 hdaa_audio_dacs_equal(struct hdaa_widget *w1, struct hdaa_widget *w2)
3229 struct hdaa_devinfo *devinfo = w1->devinfo;
3230 struct hdaa_widget *w3;
3233 if (memcmp(&w1->param, &w2->param, sizeof(w1->param)))
3235 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3236 w3 = hdaa_widget_get(devinfo, i);
3237 if (w3 == NULL || w3->enable == 0)
3239 if (w3->bindas != w1->bindas)
3241 if (w3->nconns == 0)
3244 for (j = 0; j < w3->nconns; j++) {
3245 if (w3->connsenable[j] == 0)
3247 if (w3->conns[j] == w1->nid)
3249 if (w3->conns[j] == w2->nid)
3256 if (w3->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
3263 * Check equivalency of two ADCs.
3266 hdaa_audio_adcs_equal(struct hdaa_widget *w1, struct hdaa_widget *w2)
3268 struct hdaa_devinfo *devinfo = w1->devinfo;
3269 struct hdaa_widget *w3, *w4;
3272 if (memcmp(&w1->param, &w2->param, sizeof(w1->param)))
3274 if (w1->nconns != 1 || w2->nconns != 1)
3276 if (w1->conns[0] == w2->conns[0])
3278 w3 = hdaa_widget_get(devinfo, w1->conns[0]);
3279 if (w3 == NULL || w3->enable == 0)
3281 w4 = hdaa_widget_get(devinfo, w2->conns[0]);
3282 if (w4 == NULL || w4->enable == 0)
3284 if (w3->bindas == w4->bindas && w3->bindseqmask == w4->bindseqmask)
3286 if (w4->bindas >= 0)
3288 if (w3->type != w4->type)
3290 if (memcmp(&w3->param, &w4->param, sizeof(w3->param)))
3292 if (w3->nconns != w4->nconns)
3294 for (i = 0; i < w3->nconns; i++) {
3295 if (w3->conns[i] != w4->conns[i])
3302 * Look for equivalent DAC/ADC to implement second channel.
3305 hdaa_audio_adddac(struct hdaa_devinfo *devinfo, int asid)
3307 struct hdaa_audio_as *as = &devinfo->as[asid];
3308 struct hdaa_widget *w1, *w2;
3313 device_printf(devinfo->dev,
3314 "Looking for additional %sC "
3315 "for association %d (%d)\n",
3316 (as->dir == HDAA_CTL_OUT) ? "DA" : "AD",
3320 /* Find the exisitng DAC position and return if found more the one. */
3322 for (i = 0; i < 16; i++) {
3323 if (as->dacs[0][i] <= 0)
3325 if (pos >= 0 && as->dacs[0][i] != as->dacs[0][pos])
3330 nid1 = as->dacs[0][pos];
3331 w1 = hdaa_widget_get(devinfo, nid1);
3333 for (nid2 = devinfo->startnode; nid2 < devinfo->endnode; nid2++) {
3334 w2 = hdaa_widget_get(devinfo, nid2);
3335 if (w2 == NULL || w2->enable == 0)
3337 if (w2->bindas >= 0)
3339 if (w1->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT) {
3340 if (w2->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT)
3342 if (hdaa_audio_dacs_equal(w1, w2))
3345 if (w2->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT)
3347 if (hdaa_audio_adcs_equal(w1, w2))
3351 if (nid2 >= devinfo->endnode)
3353 w2->bindas = w1->bindas;
3354 w2->bindseqmask = w1->bindseqmask;
3355 if (w1->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
3357 device_printf(devinfo->dev,
3358 " ADC %d considered equal to ADC %d\n", nid2, nid1);
3360 w1 = hdaa_widget_get(devinfo, w1->conns[0]);
3361 w2 = hdaa_widget_get(devinfo, w2->conns[0]);
3362 w2->bindas = w1->bindas;
3363 w2->bindseqmask = w1->bindseqmask;
3366 device_printf(devinfo->dev,
3367 " DAC %d considered equal to DAC %d\n", nid2, nid1);
3370 for (i = 0; i < 16; i++) {
3371 if (as->dacs[0][i] <= 0)
3373 as->dacs[as->num_chans][i] = nid2;
3379 * Trace association path from input to ADC
3382 hdaa_audio_trace_as_in(struct hdaa_devinfo *devinfo, int as)
3384 struct hdaa_audio_as *ases = devinfo->as;
3385 struct hdaa_widget *w;
3386 int i, j, k, length;
3388 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
3389 w = hdaa_widget_get(devinfo, j);
3390 if (w == NULL || w->enable == 0)
3392 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT)
3394 if (w->bindas >= 0 && w->bindas != as)
3398 for (i = 0; i < 16; i++) {
3399 if (ases[as].pins[i] == 0)
3403 device_printf(devinfo->dev,
3404 " Tracing pin %d to ADC %d\n",
3405 ases[as].pins[i], j);
3407 /* Trace this pin taking goal into account. */
3408 if (hdaa_audio_trace_adc(devinfo, as, i,
3409 ases[as].pins[i], 1, 0, j, 0, &length, 0) == 0) {
3410 /* If we failed - return to previous and redo it. */
3412 device_printf(devinfo->dev,
3413 " Unable to trace pin %d to ADC %d, undo traces\n",
3414 ases[as].pins[i], j);
3416 hdaa_audio_undo_trace(devinfo, as, -1);
3417 for (k = 0; k < 16; k++)
3418 ases[as].dacs[0][k] = 0;
3422 device_printf(devinfo->dev,
3423 " Pin %d traced to ADC %d\n",
3424 ases[as].pins[i], j);
3426 ases[as].dacs[0][i] = j;
3435 * Trace association path from input to multiple ADCs
3438 hdaa_audio_trace_as_in_mch(struct hdaa_devinfo *devinfo, int as, int seq)
3440 struct hdaa_audio_as *ases = devinfo->as;
3445 for (i = seq; i < 16 && ases[as].pins[i] == 0; i++)
3447 /* Check if there is no any left. If so - we succeeded. */
3454 device_printf(devinfo->dev,
3455 " Tracing pin %d with min nid %d",
3456 ases[as].pins[i], min);
3459 /* Trace this pin taking min nid into account. */
3460 res = hdaa_audio_trace_adc(devinfo, as, i,
3461 ases[as].pins[i], 0, min, 0, 0, &length, 0);
3463 /* If we failed - return to previous and redo it. */
3465 device_printf(devinfo->dev,
3466 " Unable to trace pin %d seq %d with min "
3468 ases[as].pins[i], i, min);
3474 device_printf(devinfo->dev,
3475 " Pin %d traced to ADC %d\n",
3476 ases[as].pins[i], res);
3478 /* Trace again to mark the path */
3479 hdaa_audio_trace_adc(devinfo, as, i,
3480 ases[as].pins[i], 0, min, res, 0, &length, length);
3481 ases[as].dacs[0][i] = res;
3482 /* We succeeded, so call next. */
3483 if (hdaa_audio_trace_as_in_mch(devinfo, as, i + 1))
3485 /* If next failed, we should retry with next min */
3486 hdaa_audio_undo_trace(devinfo, as, i);
3487 ases[as].dacs[0][i] = 0;
3493 * Trace input monitor path from mixer to output association.
3496 hdaa_audio_trace_to_out(struct hdaa_devinfo *devinfo, nid_t nid, int depth)
3498 struct hdaa_audio_as *ases = devinfo->as;
3499 struct hdaa_widget *w, *wc;
3503 if (depth > HDA_PARSE_MAXDEPTH)
3505 w = hdaa_widget_get(devinfo, nid);
3506 if (w == NULL || w->enable == 0)
3509 device_printf(devinfo->dev,
3510 " %*stracing via nid %d\n",
3511 depth + 1, "", w->nid);
3513 /* Use only unused widgets */
3514 if (depth > 0 && w->bindas != -1) {
3515 if (w->bindas < 0 || ases[w->bindas].dir == HDAA_CTL_OUT) {
3517 device_printf(devinfo->dev,
3518 " %*snid %d found output association %d\n",
3519 depth + 1, "", w->nid, w->bindas);
3522 w->pflags |= HDAA_ADC_MONITOR;
3526 device_printf(devinfo->dev,
3527 " %*snid %d busy by input association %d\n",
3528 depth + 1, "", w->nid, w->bindas);
3535 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT:
3536 /* Do not traverse input. AD1988 has digital monitor
3537 for which we are not ready. */
3539 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
3544 /* Try to find reachable ADCs with specified nid. */
3545 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
3546 wc = hdaa_widget_get(devinfo, j);
3547 if (wc == NULL || wc->enable == 0)
3549 for (i = 0; i < wc->nconns; i++) {
3550 if (wc->connsenable[i] == 0)
3552 if (wc->conns[i] != nid)
3554 if (hdaa_audio_trace_to_out(devinfo,
3555 j, depth + 1) != 0) {
3557 if (wc->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR &&
3565 if (res && w->bindas == -1)
3569 device_printf(devinfo->dev,
3570 " %*snid %d returned %d\n",
3571 depth + 1, "", w->nid, res);
3577 * Trace extra associations (beeper, monitor)
3580 hdaa_audio_trace_as_extra(struct hdaa_devinfo *devinfo)
3582 struct hdaa_audio_as *as = devinfo->as;
3583 struct hdaa_widget *w;
3587 /* Find mixer associated with input, but supplying signal
3588 for output associations. Hope it will be input monitor. */
3590 device_printf(devinfo->dev,
3591 "Tracing input monitor\n");
3593 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
3594 w = hdaa_widget_get(devinfo, j);
3595 if (w == NULL || w->enable == 0)
3597 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
3599 if (w->bindas < 0 || as[w->bindas].dir != HDAA_CTL_IN)
3602 device_printf(devinfo->dev,
3603 " Tracing nid %d to out\n",
3606 if (hdaa_audio_trace_to_out(devinfo, w->nid, 0)) {
3608 device_printf(devinfo->dev,
3609 " nid %d is input monitor\n",
3612 w->ossdev = SOUND_MIXER_IMIX;
3616 /* Other inputs monitor */
3617 /* Find input pins supplying signal for output associations.
3618 Hope it will be input monitoring. */
3620 device_printf(devinfo->dev,
3621 "Tracing other input monitors\n");
3623 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
3624 w = hdaa_widget_get(devinfo, j);
3625 if (w == NULL || w->enable == 0)
3627 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
3629 if (w->bindas < 0 || as[w->bindas].dir != HDAA_CTL_IN)
3632 device_printf(devinfo->dev,
3633 " Tracing nid %d to out\n",
3636 if (hdaa_audio_trace_to_out(devinfo, w->nid, 0)) {
3638 device_printf(devinfo->dev,
3639 " nid %d is input monitor\n",
3647 device_printf(devinfo->dev,
3648 "Tracing beeper\n");
3650 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
3651 w = hdaa_widget_get(devinfo, j);
3652 if (w == NULL || w->enable == 0)
3654 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET)
3657 device_printf(devinfo->dev,
3658 " Tracing nid %d to out\n",
3661 if (hdaa_audio_trace_to_out(devinfo, w->nid, 0)) {
3663 device_printf(devinfo->dev,
3664 " nid %d traced to out\n",
3673 * Bind assotiations to PCM channels
3676 hdaa_audio_bind_as(struct hdaa_devinfo *devinfo)
3678 struct hdaa_audio_as *as = devinfo->as;
3679 int i, j, cnt = 0, free;
3681 for (j = 0; j < devinfo->ascnt; j++) {
3683 cnt += as[j].num_chans;
3685 if (devinfo->num_chans == 0) {
3686 devinfo->chans = (struct hdaa_chan *)malloc(
3687 sizeof(struct hdaa_chan) * cnt,
3688 M_HDAA, M_ZERO | M_NOWAIT);
3689 if (devinfo->chans == NULL) {
3690 device_printf(devinfo->dev,
3691 "Channels memory allocation failed!\n");
3695 devinfo->chans = (struct hdaa_chan *)realloc(devinfo->chans,
3696 sizeof(struct hdaa_chan) * (devinfo->num_chans + cnt),
3697 M_HDAA, M_ZERO | M_NOWAIT);
3698 if (devinfo->chans == NULL) {
3699 devinfo->num_chans = 0;
3700 device_printf(devinfo->dev,
3701 "Channels memory allocation failed!\n");
3704 /* Fixup relative pointers after realloc */
3705 for (j = 0; j < devinfo->num_chans; j++)
3706 devinfo->chans[j].caps.fmtlist = devinfo->chans[j].fmtlist;
3708 free = devinfo->num_chans;
3709 devinfo->num_chans += cnt;
3711 for (j = free; j < free + cnt; j++) {
3712 devinfo->chans[j].devinfo = devinfo;
3713 devinfo->chans[j].as = -1;
3716 /* Assign associations in order of their numbers, */
3717 for (j = 0; j < devinfo->ascnt; j++) {
3718 if (as[j].enable == 0)
3720 for (i = 0; i < as[j].num_chans; i++) {
3721 devinfo->chans[free].as = j;
3722 devinfo->chans[free].asindex = i;
3723 devinfo->chans[free].dir =
3724 (as[j].dir == HDAA_CTL_IN) ? PCMDIR_REC : PCMDIR_PLAY;
3725 hdaa_pcmchannel_setup(&devinfo->chans[free]);
3726 as[j].chans[i] = free;
3733 hdaa_audio_disable_nonaudio(struct hdaa_devinfo *devinfo)
3735 struct hdaa_widget *w;
3738 /* Disable power and volume widgets. */
3739 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3740 w = hdaa_widget_get(devinfo, i);
3741 if (w == NULL || w->enable == 0)
3743 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_POWER_WIDGET ||
3744 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_VOLUME_WIDGET) {
3747 device_printf(devinfo->dev,
3748 " Disabling nid %d due to it's"
3749 " non-audio type.\n",
3757 hdaa_audio_disable_useless(struct hdaa_devinfo *devinfo)
3759 struct hdaa_widget *w, *cw;
3760 struct hdaa_audio_ctl *ctl;
3761 int done, found, i, j, k;
3763 /* Disable useless pins. */
3764 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3765 w = hdaa_widget_get(devinfo, i);
3766 if (w == NULL || w->enable == 0)
3768 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) {
3769 if ((w->wclass.pin.config &
3770 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK) ==
3771 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_NONE) {
3774 device_printf(devinfo->dev,
3775 " Disabling pin nid %d due"
3776 " to None connectivity.\n",
3779 } else if ((w->wclass.pin.config &
3780 HDA_CONFIG_DEFAULTCONF_ASSOCIATION_MASK) == 0) {
3783 device_printf(devinfo->dev,
3784 " Disabling unassociated"
3793 /* Disable and mute controls for disabled widgets. */
3795 while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) {
3796 if (ctl->enable == 0)
3798 if (ctl->widget->enable == 0 ||
3799 (ctl->childwidget != NULL &&
3800 ctl->childwidget->enable == 0)) {
3802 ctl->muted = HDAA_AMP_MUTE_ALL;
3806 if (ctl->ndir == HDAA_CTL_IN)
3807 ctl->widget->connsenable[ctl->index] = 0;
3810 device_printf(devinfo->dev,
3811 " Disabling ctl %d nid %d cnid %d due"
3812 " to disabled widget.\n", i,
3814 (ctl->childwidget != NULL)?
3815 ctl->childwidget->nid:-1);
3819 /* Disable useless widgets. */
3820 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3821 w = hdaa_widget_get(devinfo, i);
3822 if (w == NULL || w->enable == 0)
3824 /* Disable inputs with disabled child widgets. */
3825 for (j = 0; j < w->nconns; j++) {
3826 if (w->connsenable[j]) {
3827 cw = hdaa_widget_get(devinfo, w->conns[j]);
3828 if (cw == NULL || cw->enable == 0) {
3829 w->connsenable[j] = 0;
3831 device_printf(devinfo->dev,
3832 " Disabling nid %d connection %d due"
3833 " to disabled child widget.\n",
3839 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR &&
3840 w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
3842 /* Disable mixers and selectors without inputs. */
3844 for (j = 0; j < w->nconns; j++) {
3845 if (w->connsenable[j]) {
3854 device_printf(devinfo->dev,
3855 " Disabling nid %d due to all it's"
3856 " inputs disabled.\n", w->nid);
3859 /* Disable nodes without consumers. */
3860 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR &&
3861 w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
3864 for (k = devinfo->startnode; k < devinfo->endnode; k++) {
3865 cw = hdaa_widget_get(devinfo, k);
3866 if (cw == NULL || cw->enable == 0)
3868 for (j = 0; j < cw->nconns; j++) {
3869 if (cw->connsenable[j] && cw->conns[j] == i) {
3879 device_printf(devinfo->dev,
3880 " Disabling nid %d due to all it's"
3881 " consumers disabled.\n", w->nid);
3885 } while (done == 0);
3890 hdaa_audio_disable_unas(struct hdaa_devinfo *devinfo)
3892 struct hdaa_audio_as *as = devinfo->as;
3893 struct hdaa_widget *w, *cw;
3894 struct hdaa_audio_ctl *ctl;
3897 /* Disable unassosiated widgets. */
3898 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3899 w = hdaa_widget_get(devinfo, i);
3900 if (w == NULL || w->enable == 0)
3902 if (w->bindas == -1) {
3905 device_printf(devinfo->dev,
3906 " Disabling unassociated nid %d.\n",
3911 /* Disable input connections on input pin and
3912 * output on output. */
3913 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3914 w = hdaa_widget_get(devinfo, i);
3915 if (w == NULL || w->enable == 0)
3917 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
3921 if (as[w->bindas].dir == HDAA_CTL_IN) {
3922 for (j = 0; j < w->nconns; j++) {
3923 if (w->connsenable[j] == 0)
3925 w->connsenable[j] = 0;
3927 device_printf(devinfo->dev,
3928 " Disabling connection to input pin "
3929 "nid %d conn %d.\n",
3933 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid,
3934 HDAA_CTL_IN, -1, 1);
3935 if (ctl && ctl->enable) {
3937 ctl->muted = HDAA_AMP_MUTE_ALL;
3943 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid,
3944 HDAA_CTL_OUT, -1, 1);
3945 if (ctl && ctl->enable) {
3947 ctl->muted = HDAA_AMP_MUTE_ALL;
3952 for (k = devinfo->startnode; k < devinfo->endnode; k++) {
3953 cw = hdaa_widget_get(devinfo, k);
3954 if (cw == NULL || cw->enable == 0)
3956 for (j = 0; j < cw->nconns; j++) {
3957 if (cw->connsenable[j] && cw->conns[j] == i) {
3958 cw->connsenable[j] = 0;
3960 device_printf(devinfo->dev,
3961 " Disabling connection from output pin "
3962 "nid %d conn %d cnid %d.\n",
3965 if (cw->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
3968 ctl = hdaa_audio_ctl_amp_get(devinfo, k,
3970 if (ctl && ctl->enable) {
3972 ctl->muted = HDAA_AMP_MUTE_ALL;
3985 hdaa_audio_disable_notselected(struct hdaa_devinfo *devinfo)
3987 struct hdaa_audio_as *as = devinfo->as;
3988 struct hdaa_widget *w;
3991 /* On playback path we can safely disable all unseleted inputs. */
3992 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3993 w = hdaa_widget_get(devinfo, i);
3994 if (w == NULL || w->enable == 0)
3998 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
4000 if (w->bindas < 0 || as[w->bindas].dir == HDAA_CTL_IN)
4002 for (j = 0; j < w->nconns; j++) {
4003 if (w->connsenable[j] == 0)
4005 if (w->selconn < 0 || w->selconn == j)
4007 w->connsenable[j] = 0;
4009 device_printf(devinfo->dev,
4010 " Disabling unselected connection "
4011 "nid %d conn %d.\n",
4019 hdaa_audio_disable_crossas(struct hdaa_devinfo *devinfo)
4021 struct hdaa_audio_as *ases = devinfo->as;
4022 struct hdaa_widget *w, *cw;
4023 struct hdaa_audio_ctl *ctl;
4026 /* Disable crossassociatement and unwanted crosschannel connections. */
4027 /* ... using selectors */
4028 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4029 w = hdaa_widget_get(devinfo, i);
4030 if (w == NULL || w->enable == 0)
4034 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
4036 /* Allow any -> mix */
4037 if (w->bindas == -2)
4039 for (j = 0; j < w->nconns; j++) {
4040 if (w->connsenable[j] == 0)
4042 cw = hdaa_widget_get(devinfo, w->conns[j]);
4043 if (cw == NULL || w->enable == 0)
4045 /* Allow mix -> out. */
4046 if (cw->bindas == -2 && w->bindas >= 0 &&
4047 ases[w->bindas].dir == HDAA_CTL_OUT)
4049 /* Allow mix -> mixed-in. */
4050 if (cw->bindas == -2 && w->bindas >= 0 &&
4051 ases[w->bindas].mixed)
4053 /* Allow in -> mix. */
4054 if ((w->pflags & HDAA_ADC_MONITOR) &&
4056 ases[cw->bindas].dir == HDAA_CTL_IN)
4058 /* Allow if have common as/seqs. */
4059 if (w->bindas == cw->bindas &&
4060 (w->bindseqmask & cw->bindseqmask) != 0)
4062 w->connsenable[j] = 0;
4064 device_printf(devinfo->dev,
4065 " Disabling crossassociatement connection "
4066 "nid %d conn %d cnid %d.\n",
4071 /* ... using controls */
4073 while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) {
4074 if (ctl->enable == 0 || ctl->childwidget == NULL)
4076 /* Allow any -> mix */
4077 if (ctl->widget->bindas == -2)
4079 /* Allow mix -> out. */
4080 if (ctl->childwidget->bindas == -2 &&
4081 ctl->widget->bindas >= 0 &&
4082 ases[ctl->widget->bindas].dir == HDAA_CTL_OUT)
4084 /* Allow mix -> mixed-in. */
4085 if (ctl->childwidget->bindas == -2 &&
4086 ctl->widget->bindas >= 0 &&
4087 ases[ctl->widget->bindas].mixed)
4089 /* Allow in -> mix. */
4090 if ((ctl->widget->pflags & HDAA_ADC_MONITOR) &&
4091 ctl->childwidget->bindas >= 0 &&
4092 ases[ctl->childwidget->bindas].dir == HDAA_CTL_IN)
4094 /* Allow if have common as/seqs. */
4095 if (ctl->widget->bindas == ctl->childwidget->bindas &&
4096 (ctl->widget->bindseqmask & ctl->childwidget->bindseqmask) != 0)
4099 ctl->muted = HDAA_AMP_MUTE_ALL;
4103 if (ctl->ndir == HDAA_CTL_IN)
4104 ctl->widget->connsenable[ctl->index] = 0;
4106 device_printf(devinfo->dev,
4107 " Disabling crossassociatement connection "
4108 "ctl %d nid %d cnid %d.\n", i,
4110 ctl->childwidget->nid);
4117 * Find controls to control amplification for source and calculate possible
4118 * amplification range.
4121 hdaa_audio_ctl_source_amp(struct hdaa_devinfo *devinfo, nid_t nid, int index,
4122 int ossdev, int ctlable, int depth, int *minamp, int *maxamp)
4124 struct hdaa_widget *w, *wc;
4125 struct hdaa_audio_ctl *ctl;
4126 int i, j, conns = 0, tminamp, tmaxamp, cminamp, cmaxamp, found = 0;
4128 if (depth > HDA_PARSE_MAXDEPTH)
4131 w = hdaa_widget_get(devinfo, nid);
4132 if (w == NULL || w->enable == 0)
4135 /* Count number of active inputs. */
4137 for (j = 0; j < w->nconns; j++) {
4138 if (!w->connsenable[j])
4144 /* If this is not a first step - use input mixer.
4145 Pins have common input ctl so care must be taken. */
4146 if (depth > 0 && ctlable && (conns == 1 ||
4147 w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)) {
4148 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, HDAA_CTL_IN,
4151 ctl->ossmask |= (1 << ossdev);
4153 if (*minamp == *maxamp) {
4154 *minamp += MINQDB(ctl);
4155 *maxamp += MAXQDB(ctl);
4160 /* If widget has own ossdev - not traverse it.
4161 It will be traversed on it's own. */
4162 if (w->ossdev >= 0 && depth > 0)
4165 /* We must not traverse pin */
4166 if ((w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT ||
4167 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) &&
4171 /* record that this widget exports such signal, */
4172 w->ossmask |= (1 << ossdev);
4175 * If signals mixed, we can't assign controls farther.
4176 * Ignore this on depth zero. Caller must knows why.
4179 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
4183 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, HDAA_CTL_OUT, -1, 1);
4185 ctl->ossmask |= (1 << ossdev);
4187 if (*minamp == *maxamp) {
4188 *minamp += MINQDB(ctl);
4189 *maxamp += MAXQDB(ctl);
4194 cminamp = cmaxamp = 0;
4195 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4196 wc = hdaa_widget_get(devinfo, i);
4197 if (wc == NULL || wc->enable == 0)
4199 for (j = 0; j < wc->nconns; j++) {
4200 if (wc->connsenable[j] && wc->conns[j] == nid) {
4201 tminamp = tmaxamp = 0;
4202 found += hdaa_audio_ctl_source_amp(devinfo,
4203 wc->nid, j, ossdev, ctlable, depth + 1,
4204 &tminamp, &tmaxamp);
4205 if (cminamp == 0 && cmaxamp == 0) {
4208 } else if (tminamp != tmaxamp) {
4209 cminamp = imax(cminamp, tminamp);
4210 cmaxamp = imin(cmaxamp, tmaxamp);
4215 if (*minamp == *maxamp && cminamp < cmaxamp) {
4223 * Find controls to control amplification for destination and calculate
4224 * possible amplification range.
4227 hdaa_audio_ctl_dest_amp(struct hdaa_devinfo *devinfo, nid_t nid, int index,
4228 int ossdev, int depth, int *minamp, int *maxamp)
4230 struct hdaa_audio_as *as = devinfo->as;
4231 struct hdaa_widget *w, *wc;
4232 struct hdaa_audio_ctl *ctl;
4233 int i, j, consumers, tminamp, tmaxamp, cminamp, cmaxamp, found = 0;
4235 if (depth > HDA_PARSE_MAXDEPTH)
4238 w = hdaa_widget_get(devinfo, nid);
4239 if (w == NULL || w->enable == 0)
4243 /* If this node produce output for several consumers,
4244 we can't touch it. */
4246 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4247 wc = hdaa_widget_get(devinfo, i);
4248 if (wc == NULL || wc->enable == 0)
4250 for (j = 0; j < wc->nconns; j++) {
4251 if (wc->connsenable[j] && wc->conns[j] == nid)
4255 /* The only exception is if real HP redirection is configured
4256 and this is a duplication point.
4257 XXX: Actually exception is not completely correct.
4258 XXX: Duplication point check is not perfect. */
4259 if ((consumers == 2 && (w->bindas < 0 ||
4260 as[w->bindas].hpredir < 0 || as[w->bindas].fakeredir ||
4261 (w->bindseqmask & (1 << 15)) == 0)) ||
4265 /* Else use it's output mixer. */
4266 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid,
4267 HDAA_CTL_OUT, -1, 1);
4269 ctl->ossmask |= (1 << ossdev);
4271 if (*minamp == *maxamp) {
4272 *minamp += MINQDB(ctl);
4273 *maxamp += MAXQDB(ctl);
4278 /* We must not traverse pin */
4279 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
4283 cminamp = cmaxamp = 0;
4284 for (i = 0; i < w->nconns; i++) {
4285 if (w->connsenable[i] == 0)
4287 if (index >= 0 && i != index)
4289 tminamp = tmaxamp = 0;
4290 ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid,
4293 ctl->ossmask |= (1 << ossdev);
4295 if (*minamp == *maxamp) {
4296 tminamp += MINQDB(ctl);
4297 tmaxamp += MAXQDB(ctl);
4300 found += hdaa_audio_ctl_dest_amp(devinfo, w->conns[i], -1, ossdev,
4301 depth + 1, &tminamp, &tmaxamp);
4302 if (cminamp == 0 && cmaxamp == 0) {
4305 } else if (tminamp != tmaxamp) {
4306 cminamp = imax(cminamp, tminamp);
4307 cmaxamp = imin(cmaxamp, tmaxamp);
4310 if (*minamp == *maxamp && cminamp < cmaxamp) {
4318 * Assign OSS names to sound sources
4321 hdaa_audio_assign_names(struct hdaa_devinfo *devinfo)
4323 struct hdaa_audio_as *as = devinfo->as;
4324 struct hdaa_widget *w;
4326 int type = -1, use, used = 0;
4327 static const int types[7][13] = {
4328 { SOUND_MIXER_LINE, SOUND_MIXER_LINE1, SOUND_MIXER_LINE2,
4329 SOUND_MIXER_LINE3, -1 }, /* line */
4330 { SOUND_MIXER_MONITOR, SOUND_MIXER_MIC, -1 }, /* int mic */
4331 { SOUND_MIXER_MIC, SOUND_MIXER_MONITOR, -1 }, /* ext mic */
4332 { SOUND_MIXER_CD, -1 }, /* cd */
4333 { SOUND_MIXER_SPEAKER, -1 }, /* speaker */
4334 { SOUND_MIXER_DIGITAL1, SOUND_MIXER_DIGITAL2, SOUND_MIXER_DIGITAL3,
4336 { SOUND_MIXER_LINE, SOUND_MIXER_LINE1, SOUND_MIXER_LINE2,
4337 SOUND_MIXER_LINE3, SOUND_MIXER_PHONEIN, SOUND_MIXER_PHONEOUT,
4338 SOUND_MIXER_VIDEO, SOUND_MIXER_RADIO, SOUND_MIXER_DIGITAL1,
4339 SOUND_MIXER_DIGITAL2, SOUND_MIXER_DIGITAL3, SOUND_MIXER_MONITOR,
4343 /* Surely known names */
4344 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4345 w = hdaa_widget_get(devinfo, i);
4346 if (w == NULL || w->enable == 0)
4348 if (w->bindas == -1)
4352 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
4353 if (as[w->bindas].dir == HDAA_CTL_OUT)
4356 switch (w->wclass.pin.config & HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) {
4357 case HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN:
4360 case HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN:
4361 if ((w->wclass.pin.config & HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK)
4362 == HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_JACK)
4366 case HDA_CONFIG_DEFAULTCONF_DEVICE_CD:
4369 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER:
4372 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_IN:
4373 case HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_IN:
4380 while (types[type][j] >= 0 &&
4381 (used & (1 << types[type][j])) != 0) {
4384 if (types[type][j] >= 0)
4385 use = types[type][j];
4387 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT:
4388 use = SOUND_MIXER_PCM;
4390 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET:
4391 use = SOUND_MIXER_SPEAKER;
4401 /* Semi-known names */
4402 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4403 w = hdaa_widget_get(devinfo, i);
4404 if (w == NULL || w->enable == 0)
4408 if (w->bindas == -1)
4410 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
4412 if (as[w->bindas].dir == HDAA_CTL_OUT)
4415 switch (w->wclass.pin.config & HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) {
4416 case HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_OUT:
4417 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER:
4418 case HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT:
4419 case HDA_CONFIG_DEFAULTCONF_DEVICE_AUX:
4422 case HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN:
4425 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_OUT:
4426 case HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_OUT:
4433 while (types[type][j] >= 0 &&
4434 (used & (1 << types[type][j])) != 0) {
4437 if (types[type][j] >= 0) {
4438 w->ossdev = types[type][j];
4439 used |= (1 << types[type][j]);
4443 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4444 w = hdaa_widget_get(devinfo, i);
4445 if (w == NULL || w->enable == 0)
4449 if (w->bindas == -1)
4451 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
4453 if (as[w->bindas].dir == HDAA_CTL_OUT)
4456 while (types[6][j] >= 0 &&
4457 (used & (1 << types[6][j])) != 0) {
4460 if (types[6][j] >= 0) {
4461 w->ossdev = types[6][j];
4462 used |= (1 << types[6][j]);
4468 hdaa_audio_build_tree(struct hdaa_devinfo *devinfo)
4470 struct hdaa_audio_as *as = devinfo->as;
4473 /* Trace all associations in order of their numbers. */
4474 for (j = 0; j < devinfo->ascnt; j++) {
4475 if (as[j].enable == 0)
4478 device_printf(devinfo->dev,
4479 "Tracing association %d (%d)\n", j, as[j].index);
4481 if (as[j].dir == HDAA_CTL_OUT) {
4483 res = hdaa_audio_trace_as_out(devinfo, j, 0);
4484 if (res == 0 && as[j].hpredir >= 0 &&
4485 as[j].fakeredir == 0) {
4486 /* If CODEC can't do analog HP redirection
4487 try to make it using one more DAC. */
4488 as[j].fakeredir = 1;
4491 } else if (as[j].mixed)
4492 res = hdaa_audio_trace_as_in(devinfo, j);
4494 res = hdaa_audio_trace_as_in_mch(devinfo, j, 0);
4497 device_printf(devinfo->dev,
4498 "Association %d (%d) trace succeeded\n",
4503 device_printf(devinfo->dev,
4504 "Association %d (%d) trace failed\n",
4511 /* Look for additional DACs/ADCs. */
4512 for (j = 0; j < devinfo->ascnt; j++) {
4513 if (as[j].enable == 0)
4515 hdaa_audio_adddac(devinfo, j);
4518 /* Trace mixer and beeper pseudo associations. */
4519 hdaa_audio_trace_as_extra(devinfo);
4523 * Store in pdevinfo new data about whether and how we can control signal
4524 * for OSS device to/from specified widget.
4527 hdaa_adjust_amp(struct hdaa_widget *w, int ossdev,
4528 int found, int minamp, int maxamp)
4530 struct hdaa_devinfo *devinfo = w->devinfo;
4531 struct hdaa_pcm_devinfo *pdevinfo;
4534 pdevinfo = devinfo->as[w->bindas].pdevinfo;
4536 pdevinfo = &devinfo->devs[0];
4538 pdevinfo->ossmask |= (1 << ossdev);
4539 if (minamp == 0 && maxamp == 0)
4541 if (pdevinfo->minamp[ossdev] == 0 && pdevinfo->maxamp[ossdev] == 0) {
4542 pdevinfo->minamp[ossdev] = minamp;
4543 pdevinfo->maxamp[ossdev] = maxamp;
4545 pdevinfo->minamp[ossdev] = imax(pdevinfo->minamp[ossdev], minamp);
4546 pdevinfo->maxamp[ossdev] = imin(pdevinfo->maxamp[ossdev], maxamp);
4551 * Trace signals from/to all possible sources/destionstions to find possible
4552 * recording sources, OSS device control ranges and to assign controls.
4555 hdaa_audio_assign_mixers(struct hdaa_devinfo *devinfo)
4557 struct hdaa_audio_as *as = devinfo->as;
4558 struct hdaa_widget *w, *cw;
4559 int i, j, minamp, maxamp, found;
4561 /* Assign mixers to the tree. */
4562 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4563 w = hdaa_widget_get(devinfo, i);
4564 if (w == NULL || w->enable == 0)
4566 minamp = maxamp = 0;
4567 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT ||
4568 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET ||
4569 (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
4570 as[w->bindas].dir == HDAA_CTL_IN)) {
4573 found = hdaa_audio_ctl_source_amp(devinfo, w->nid, -1,
4574 w->ossdev, 1, 0, &minamp, &maxamp);
4575 hdaa_adjust_amp(w, w->ossdev, found, minamp, maxamp);
4576 } else if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
4577 found = hdaa_audio_ctl_dest_amp(devinfo, w->nid, -1,
4578 SOUND_MIXER_RECLEV, 0, &minamp, &maxamp);
4579 hdaa_adjust_amp(w, SOUND_MIXER_RECLEV, found, minamp, maxamp);
4580 } else if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
4581 as[w->bindas].dir == HDAA_CTL_OUT) {
4582 found = hdaa_audio_ctl_dest_amp(devinfo, w->nid, -1,
4583 SOUND_MIXER_VOLUME, 0, &minamp, &maxamp);
4584 hdaa_adjust_amp(w, SOUND_MIXER_VOLUME, found, minamp, maxamp);
4586 if (w->ossdev == SOUND_MIXER_IMIX) {
4587 minamp = maxamp = 0;
4588 found = hdaa_audio_ctl_source_amp(devinfo, w->nid, -1,
4589 w->ossdev, 1, 0, &minamp, &maxamp);
4590 if (minamp == maxamp) {
4591 /* If we are unable to control input monitor
4592 as source - try to control it as destination. */
4593 found += hdaa_audio_ctl_dest_amp(devinfo, w->nid, -1,
4594 w->ossdev, 0, &minamp, &maxamp);
4595 w->pflags |= HDAA_IMIX_AS_DST;
4597 hdaa_adjust_amp(w, w->ossdev, found, minamp, maxamp);
4599 if (w->pflags & HDAA_ADC_MONITOR) {
4600 for (j = 0; j < w->nconns; j++) {
4601 if (!w->connsenable[j])
4603 cw = hdaa_widget_get(devinfo, w->conns[j]);
4604 if (cw == NULL || cw->enable == 0)
4606 if (cw->bindas == -1)
4608 if (cw->bindas >= 0 &&
4609 as[cw->bindas].dir != HDAA_CTL_IN)
4611 minamp = maxamp = 0;
4612 found = hdaa_audio_ctl_dest_amp(devinfo,
4613 w->nid, j, SOUND_MIXER_IGAIN, 0,
4615 hdaa_adjust_amp(w, SOUND_MIXER_IGAIN,
4616 found, minamp, maxamp);
4623 hdaa_audio_prepare_pin_ctrl(struct hdaa_devinfo *devinfo)
4625 struct hdaa_audio_as *as = devinfo->as;
4626 struct hdaa_widget *w;
4630 for (i = 0; i < devinfo->nodecnt; i++) {
4631 w = &devinfo->widget[i];
4634 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
4638 pincap = w->wclass.pin.cap;
4640 /* Disable everything. */
4641 w->wclass.pin.ctrl &= ~(
4642 HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE |
4643 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE |
4644 HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE |
4645 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK);
4647 if (w->enable == 0) {
4648 /* Pin is unused so left it disabled. */
4650 } else if (w->waspin) {
4651 /* Enable input for beeper input. */
4652 w->wclass.pin.ctrl |=
4653 HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE;
4654 } else if (w->bindas < 0 || as[w->bindas].enable == 0) {
4655 /* Pin is unused so left it disabled. */
4657 } else if (as[w->bindas].dir == HDAA_CTL_IN) {
4658 /* Input pin, configure for input. */
4659 if (HDA_PARAM_PIN_CAP_INPUT_CAP(pincap))
4660 w->wclass.pin.ctrl |=
4661 HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE;
4663 if ((devinfo->quirks & HDAA_QUIRK_IVREF100) &&
4664 HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap))
4665 w->wclass.pin.ctrl |=
4666 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
4667 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_100);
4668 else if ((devinfo->quirks & HDAA_QUIRK_IVREF80) &&
4669 HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap))
4670 w->wclass.pin.ctrl |=
4671 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
4672 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_80);
4673 else if ((devinfo->quirks & HDAA_QUIRK_IVREF50) &&
4674 HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap))
4675 w->wclass.pin.ctrl |=
4676 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
4677 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_50);
4679 /* Output pin, configure for output. */
4680 if (HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap))
4681 w->wclass.pin.ctrl |=
4682 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
4684 if (HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap) &&
4685 (w->wclass.pin.config &
4686 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) ==
4687 HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT)
4688 w->wclass.pin.ctrl |=
4689 HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE;
4691 if ((devinfo->quirks & HDAA_QUIRK_OVREF100) &&
4692 HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap))
4693 w->wclass.pin.ctrl |=
4694 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
4695 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_100);
4696 else if ((devinfo->quirks & HDAA_QUIRK_OVREF80) &&
4697 HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap))
4698 w->wclass.pin.ctrl |=
4699 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
4700 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_80);
4701 else if ((devinfo->quirks & HDAA_QUIRK_OVREF50) &&
4702 HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap))
4703 w->wclass.pin.ctrl |=
4704 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
4705 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_50);
4711 hdaa_audio_ctl_commit(struct hdaa_devinfo *devinfo)
4713 struct hdaa_audio_ctl *ctl;
4717 while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) {
4718 if (ctl->enable == 0 || ctl->ossmask != 0) {
4719 /* Mute disabled and mixer controllable controls.
4720 * Last will be initialized by mixer_init().
4721 * This expected to reduce click on startup. */
4722 hdaa_audio_ctl_amp_set(ctl, HDAA_AMP_MUTE_ALL, 0, 0);
4725 /* Init fixed controls to 0dB amplification. */
4729 hdaa_audio_ctl_amp_set(ctl, HDAA_AMP_MUTE_NONE, z, z);
4734 hdaa_gpio_commit(struct hdaa_devinfo *devinfo)
4736 uint32_t gdata, gmask, gdir;
4739 numgpio = HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap);
4740 if (devinfo->gpio != 0 && numgpio != 0) {
4741 gdata = hda_command(devinfo->dev,
4742 HDA_CMD_GET_GPIO_DATA(0, devinfo->nid));
4743 gmask = hda_command(devinfo->dev,
4744 HDA_CMD_GET_GPIO_ENABLE_MASK(0, devinfo->nid));
4745 gdir = hda_command(devinfo->dev,
4746 HDA_CMD_GET_GPIO_DIRECTION(0, devinfo->nid));
4747 for (i = 0; i < numgpio; i++) {
4748 if ((devinfo->gpio & HDAA_GPIO_MASK(i)) ==
4753 } else if ((devinfo->gpio & HDAA_GPIO_MASK(i)) ==
4754 HDAA_GPIO_CLEAR(i)) {
4758 } else if ((devinfo->gpio & HDAA_GPIO_MASK(i)) ==
4759 HDAA_GPIO_DISABLE(i)) {
4761 } else if ((devinfo->gpio & HDAA_GPIO_MASK(i)) ==
4762 HDAA_GPIO_INPUT(i)) {
4768 device_printf(devinfo->dev, "GPIO commit\n");
4770 hda_command(devinfo->dev,
4771 HDA_CMD_SET_GPIO_ENABLE_MASK(0, devinfo->nid, gmask));
4772 hda_command(devinfo->dev,
4773 HDA_CMD_SET_GPIO_DIRECTION(0, devinfo->nid, gdir));
4774 hda_command(devinfo->dev,
4775 HDA_CMD_SET_GPIO_DATA(0, devinfo->nid, gdata));
4777 hdaa_dump_gpio(devinfo);
4783 hdaa_gpo_commit(struct hdaa_devinfo *devinfo)
4788 numgpo = HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap);
4789 if (devinfo->gpo != 0 && numgpo != 0) {
4790 gdata = hda_command(devinfo->dev,
4791 HDA_CMD_GET_GPO_DATA(0, devinfo->nid));
4792 for (i = 0; i < numgpo; i++) {
4793 if ((devinfo->gpio & HDAA_GPIO_MASK(i)) ==
4796 } else if ((devinfo->gpio & HDAA_GPIO_MASK(i)) ==
4797 HDAA_GPIO_CLEAR(i)) {
4802 device_printf(devinfo->dev, "GPO commit\n");
4804 hda_command(devinfo->dev,
4805 HDA_CMD_SET_GPO_DATA(0, devinfo->nid, gdata));
4807 hdaa_dump_gpo(devinfo);
4813 hdaa_audio_commit(struct hdaa_devinfo *devinfo)
4815 struct hdaa_widget *w;
4818 /* Commit controls. */
4819 hdaa_audio_ctl_commit(devinfo);
4821 /* Commit selectors, pins and EAPD. */
4822 for (i = 0; i < devinfo->nodecnt; i++) {
4823 w = &devinfo->widget[i];
4826 if (w->selconn == -1)
4829 hdaa_widget_connection_select(w, w->selconn);
4830 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX ||
4832 hda_command(devinfo->dev,
4833 HDA_CMD_SET_PIN_WIDGET_CTRL(0, w->nid,
4834 w->wclass.pin.ctrl));
4836 if (w->param.eapdbtl != HDA_INVALID) {
4839 val = w->param.eapdbtl;
4840 if (devinfo->quirks &
4842 val ^= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
4843 hda_command(devinfo->dev,
4844 HDA_CMD_SET_EAPD_BTL_ENABLE(0, w->nid,
4849 hdaa_gpio_commit(devinfo);
4850 hdaa_gpo_commit(devinfo);
4854 hdaa_powerup(struct hdaa_devinfo *devinfo)
4858 hda_command(devinfo->dev,
4859 HDA_CMD_SET_POWER_STATE(0,
4860 devinfo->nid, HDA_CMD_POWER_STATE_D0));
4863 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4864 hda_command(devinfo->dev,
4865 HDA_CMD_SET_POWER_STATE(0,
4866 i, HDA_CMD_POWER_STATE_D0));
4872 hdaa_pcmchannel_setup(struct hdaa_chan *ch)
4874 struct hdaa_devinfo *devinfo = ch->devinfo;
4875 struct hdaa_audio_as *as = devinfo->as;
4876 struct hdaa_widget *w;
4877 uint32_t cap, fmtcap, pcmcap;
4878 int i, j, ret, channels, onlystereo;
4881 ch->caps = hdaa_caps;
4882 ch->caps.fmtlist = ch->fmtlist;
4885 ch->pcmrates[0] = 48000;
4886 ch->pcmrates[1] = 0;
4887 ch->stripecap = 0xff;
4893 fmtcap = devinfo->supp_stream_formats;
4894 pcmcap = devinfo->supp_pcm_size_rate;
4896 for (i = 0; i < 16; i++) {
4897 /* Check as is correct */
4900 /* Cound only present DACs */
4901 if (as[ch->as].dacs[ch->asindex][i] <= 0)
4903 /* Ignore duplicates */
4904 for (j = 0; j < ret; j++) {
4905 if (ch->io[j] == as[ch->as].dacs[ch->asindex][i])
4911 w = hdaa_widget_get(devinfo, as[ch->as].dacs[ch->asindex][i]);
4912 if (w == NULL || w->enable == 0)
4914 cap = w->param.supp_stream_formats;
4915 if (!HDA_PARAM_SUPP_STREAM_FORMATS_PCM(cap) &&
4916 !HDA_PARAM_SUPP_STREAM_FORMATS_AC3(cap))
4918 /* Many CODECs does not declare AC3 support on SPDIF.
4919 I don't beleave that they doesn't support it! */
4920 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap))
4921 cap |= HDA_PARAM_SUPP_STREAM_FORMATS_AC3_MASK;
4924 pcmcap = w->param.supp_pcm_size_rate;
4927 pcmcap &= w->param.supp_pcm_size_rate;
4929 ch->io[ret++] = as[ch->as].dacs[ch->asindex][i];
4930 ch->stripecap &= w->wclass.conv.stripecap;
4931 /* Do not count redirection pin/dac channels. */
4932 if (i == 15 && as[ch->as].hpredir >= 0)
4934 channels += HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap) + 1;
4935 if (HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap) != 1)
4940 ch->channels = channels;
4942 if (as[ch->as].fakeredir)
4944 /* Standard speaks only about stereo pins and playback, ... */
4945 if ((!onlystereo) || as[ch->as].mixed)
4947 /* ..., but there it gives us info about speakers layout. */
4948 as[ch->as].pinset = pinset;
4950 ch->supp_stream_formats = fmtcap;
4951 ch->supp_pcm_size_rate = pcmcap;
4962 if (HDA_PARAM_SUPP_STREAM_FORMATS_PCM(fmtcap)) {
4963 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16BIT(pcmcap))
4965 else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8BIT(pcmcap))
4967 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(pcmcap))
4969 else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(pcmcap))
4971 else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(pcmcap))
4973 if (!(devinfo->quirks & HDAA_QUIRK_FORCESTEREO)) {
4974 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 1, 0);
4976 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 1, 0);
4978 if (channels >= 2) {
4979 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 2, 0);
4981 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 2, 0);
4983 if (channels >= 3 && !onlystereo) {
4984 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 3, 0);
4986 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 3, 0);
4987 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 3, 1);
4989 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 3, 1);
4991 if (channels >= 4) {
4992 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 4, 0);
4994 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 4, 0);
4996 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 4, 1);
4998 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 4, 1);
5001 if (channels >= 5 && !onlystereo) {
5002 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 5, 0);
5004 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 5, 0);
5005 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 5, 1);
5007 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 5, 1);
5009 if (channels >= 6) {
5010 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 6, 1);
5012 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 6, 1);
5014 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 6, 0);
5016 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 6, 0);
5019 if (channels >= 7 && !onlystereo) {
5020 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 7, 0);
5022 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 7, 0);
5023 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 7, 1);
5025 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 7, 1);
5027 if (channels >= 8) {
5028 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 8, 1);
5030 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 8, 1);
5033 if (HDA_PARAM_SUPP_STREAM_FORMATS_AC3(fmtcap)) {
5034 ch->fmtlist[i++] = SND_FORMAT(AFMT_AC3, 2, 0);
5035 if (channels >= 8) {
5036 ch->fmtlist[i++] = SND_FORMAT(AFMT_AC3, 8, 0);
5037 ch->fmtlist[i++] = SND_FORMAT(AFMT_AC3, 8, 1);
5042 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8KHZ(pcmcap))
5043 ch->pcmrates[i++] = 8000;
5044 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_11KHZ(pcmcap))
5045 ch->pcmrates[i++] = 11025;
5046 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16KHZ(pcmcap))
5047 ch->pcmrates[i++] = 16000;
5048 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_22KHZ(pcmcap))
5049 ch->pcmrates[i++] = 22050;
5050 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32KHZ(pcmcap))
5051 ch->pcmrates[i++] = 32000;
5052 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_44KHZ(pcmcap))
5053 ch->pcmrates[i++] = 44100;
5054 /* if (HDA_PARAM_SUPP_PCM_SIZE_RATE_48KHZ(pcmcap)) */
5055 ch->pcmrates[i++] = 48000;
5056 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_88KHZ(pcmcap))
5057 ch->pcmrates[i++] = 88200;
5058 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_96KHZ(pcmcap))
5059 ch->pcmrates[i++] = 96000;
5060 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_176KHZ(pcmcap))
5061 ch->pcmrates[i++] = 176400;
5062 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_192KHZ(pcmcap))
5063 ch->pcmrates[i++] = 192000;
5064 /* if (HDA_PARAM_SUPP_PCM_SIZE_RATE_384KHZ(pcmcap)) */
5065 ch->pcmrates[i] = 0;
5067 ch->caps.minspeed = ch->pcmrates[0];
5068 ch->caps.maxspeed = ch->pcmrates[i - 1];
5076 hdaa_prepare_pcms(struct hdaa_devinfo *devinfo)
5078 struct hdaa_audio_as *as = devinfo->as;
5079 int i, j, k, apdev = 0, ardev = 0, dpdev = 0, drdev = 0;
5081 for (i = 0; i < devinfo->ascnt; i++) {
5082 if (as[i].enable == 0)
5084 if (as[i].dir == HDAA_CTL_IN) {
5097 max(ardev, apdev) + max(drdev, dpdev);
5099 (struct hdaa_pcm_devinfo *)malloc(
5100 devinfo->num_devs * sizeof(struct hdaa_pcm_devinfo),
5101 M_HDAA, M_ZERO | M_NOWAIT);
5102 if (devinfo->devs == NULL) {
5103 device_printf(devinfo->dev,
5104 "Unable to allocate memory for devices\n");
5107 for (i = 0; i < devinfo->num_devs; i++) {
5108 devinfo->devs[i].index = i;
5109 devinfo->devs[i].devinfo = devinfo;
5110 devinfo->devs[i].playas = -1;
5111 devinfo->devs[i].recas = -1;
5112 devinfo->devs[i].digital = 255;
5114 for (i = 0; i < devinfo->ascnt; i++) {
5115 if (as[i].enable == 0)
5117 for (j = 0; j < devinfo->num_devs; j++) {
5118 if (devinfo->devs[j].digital != 255 &&
5119 (!devinfo->devs[j].digital) !=
5122 if (as[i].dir == HDAA_CTL_IN) {
5123 if (devinfo->devs[j].recas >= 0)
5125 devinfo->devs[j].recas = i;
5127 if (devinfo->devs[j].playas >= 0)
5129 devinfo->devs[j].playas = i;
5131 as[i].pdevinfo = &devinfo->devs[j];
5132 for (k = 0; k < as[i].num_chans; k++) {
5133 devinfo->chans[as[i].chans[k]].pdevinfo =
5136 devinfo->devs[j].digital = as[i].digital;
5143 hdaa_create_pcms(struct hdaa_devinfo *devinfo)
5147 for (i = 0; i < devinfo->num_devs; i++) {
5148 struct hdaa_pcm_devinfo *pdevinfo = &devinfo->devs[i];
5150 pdevinfo->dev = device_add_child(devinfo->dev, "pcm", -1);
5151 device_set_ivars(pdevinfo->dev, (void *)pdevinfo);
5156 hdaa_dump_ctls(struct hdaa_pcm_devinfo *pdevinfo, const char *banner, uint32_t flag)
5158 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
5159 struct hdaa_audio_ctl *ctl;
5164 flag = ~(SOUND_MASK_VOLUME | SOUND_MASK_PCM |
5165 SOUND_MASK_CD | SOUND_MASK_LINE | SOUND_MASK_RECLEV |
5166 SOUND_MASK_MIC | SOUND_MASK_SPEAKER | SOUND_MASK_IGAIN |
5167 SOUND_MASK_OGAIN | SOUND_MASK_IMIX | SOUND_MASK_MONITOR);
5170 for (j = 0; j < SOUND_MIXER_NRDEVICES; j++) {
5171 if ((flag & (1 << j)) == 0)
5175 while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) {
5176 if (ctl->enable == 0 ||
5177 ctl->widget->enable == 0)
5179 if (!((pdevinfo->playas >= 0 &&
5180 ctl->widget->bindas == pdevinfo->playas) ||
5181 (pdevinfo->recas >= 0 &&
5182 ctl->widget->bindas == pdevinfo->recas) ||
5183 (ctl->widget->bindas == -2 && pdevinfo->index == 0)))
5185 if ((ctl->ossmask & (1 << j)) == 0)
5189 device_printf(pdevinfo->dev, "\n");
5190 if (banner != NULL) {
5191 device_printf(pdevinfo->dev, "%s", banner);
5193 device_printf(pdevinfo->dev, "Unknown Ctl");
5195 printf(" (OSS: %s)",
5196 hdaa_audio_ctl_ossmixer_mask2allname(1 << j,
5198 if (pdevinfo->ossmask & (1 << j)) {
5199 printf(": %+d/%+ddB\n",
5200 pdevinfo->minamp[j] / 4,
5201 pdevinfo->maxamp[j] / 4);
5204 device_printf(pdevinfo->dev, " |\n");
5207 device_printf(pdevinfo->dev, " +- ctl %2d (nid %3d %s", i,
5209 (ctl->ndir == HDAA_CTL_IN)?"in ":"out");
5210 if (ctl->ndir == HDAA_CTL_IN && ctl->ndir == ctl->dir)
5211 printf(" %2d): ", ctl->index);
5214 if (ctl->step > 0) {
5215 printf("%+d/%+ddB (%d steps)%s\n",
5219 ctl->mute?" + mute":"");
5221 printf("%s\n", ctl->mute?"mute":"");
5227 hdaa_dump_audio_formats(device_t dev, uint32_t fcap, uint32_t pcmcap)
5233 device_printf(dev, " Stream cap: 0x%08x\n", cap);
5234 device_printf(dev, " ");
5235 if (HDA_PARAM_SUPP_STREAM_FORMATS_AC3(cap))
5237 if (HDA_PARAM_SUPP_STREAM_FORMATS_FLOAT32(cap))
5239 if (HDA_PARAM_SUPP_STREAM_FORMATS_PCM(cap))
5245 device_printf(dev, " PCM cap: 0x%08x\n", cap);
5246 device_printf(dev, " ");
5247 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8BIT(cap))
5249 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16BIT(cap))
5251 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(cap))
5253 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(cap))
5255 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(cap))
5258 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8KHZ(cap))
5260 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_11KHZ(cap))
5262 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16KHZ(cap))
5264 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_22KHZ(cap))
5266 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32KHZ(cap))
5268 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_44KHZ(cap))
5271 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_88KHZ(cap))
5273 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_96KHZ(cap))
5275 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_176KHZ(cap))
5277 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_192KHZ(cap))
5284 hdaa_dump_pin(struct hdaa_widget *w)
5288 pincap = w->wclass.pin.cap;
5290 device_printf(w->devinfo->dev, " Pin cap: 0x%08x\n", pincap);
5291 device_printf(w->devinfo->dev, " ");
5292 if (HDA_PARAM_PIN_CAP_IMP_SENSE_CAP(pincap))
5294 if (HDA_PARAM_PIN_CAP_TRIGGER_REQD(pincap))
5296 if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(pincap))
5298 if (HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap))
5300 if (HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap))
5302 if (HDA_PARAM_PIN_CAP_INPUT_CAP(pincap))
5304 if (HDA_PARAM_PIN_CAP_BALANCED_IO_PINS(pincap))
5306 if (HDA_PARAM_PIN_CAP_HDMI(pincap))
5308 if (HDA_PARAM_PIN_CAP_VREF_CTRL(pincap)) {
5310 if (HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap))
5312 if (HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap))
5314 if (HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap))
5316 if (HDA_PARAM_PIN_CAP_VREF_CTRL_GROUND(pincap))
5318 if (HDA_PARAM_PIN_CAP_VREF_CTRL_HIZ(pincap))
5322 if (HDA_PARAM_PIN_CAP_EAPD_CAP(pincap))
5324 if (HDA_PARAM_PIN_CAP_DP(pincap))
5326 if (HDA_PARAM_PIN_CAP_HBR(pincap))
5329 device_printf(w->devinfo->dev, " Pin config: 0x%08x\n",
5330 w->wclass.pin.config);
5331 device_printf(w->devinfo->dev, " Pin control: 0x%08x", w->wclass.pin.ctrl);
5332 if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE)
5334 if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE)
5336 if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE)
5338 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) {
5339 if ((w->wclass.pin.ctrl &
5340 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK) == 0x03)
5342 else if ((w->wclass.pin.ctrl &
5343 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK) != 0)
5346 if ((w->wclass.pin.ctrl &
5347 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK) != 0)
5354 hdaa_dump_pin_config(struct hdaa_widget *w, uint32_t conf)
5357 device_printf(w->devinfo->dev, "%2d %08x %-2d %-2d "
5358 "%-13s %-5s %-7s %-10s %-7s %d%s\n",
5360 HDA_CONFIG_DEFAULTCONF_ASSOCIATION(conf),
5361 HDA_CONFIG_DEFAULTCONF_SEQUENCE(conf),
5362 HDA_DEVS[HDA_CONFIG_DEFAULTCONF_DEVICE(conf)],
5363 HDA_CONNS[HDA_CONFIG_DEFAULTCONF_CONNECTIVITY(conf)],
5364 HDA_CONNECTORS[HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE(conf)],
5365 HDA_LOCS[HDA_CONFIG_DEFAULTCONF_LOCATION(conf)],
5366 HDA_COLORS[HDA_CONFIG_DEFAULTCONF_COLOR(conf)],
5367 HDA_CONFIG_DEFAULTCONF_MISC(conf),
5368 (w->enable == 0)?" DISA":"");
5372 hdaa_dump_pin_configs(struct hdaa_devinfo *devinfo)
5374 struct hdaa_widget *w;
5377 device_printf(devinfo->dev, "nid 0x as seq "
5378 "device conn jack loc color misc\n");
5379 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5380 w = hdaa_widget_get(devinfo, i);
5383 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
5385 hdaa_dump_pin_config(w, w->wclass.pin.config);
5390 hdaa_dump_amp(device_t dev, uint32_t cap, char *banner)
5392 device_printf(dev, " %s amp: 0x%08x\n", banner, cap);
5393 device_printf(dev, " "
5394 "mute=%d step=%d size=%d offset=%d\n",
5395 HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(cap),
5396 HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(cap),
5397 HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(cap),
5398 HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(cap));
5402 hdaa_dump_nodes(struct hdaa_devinfo *devinfo)
5404 struct hdaa_widget *w, *cw;
5408 device_printf(devinfo->dev, "\n");
5409 device_printf(devinfo->dev, "Default Parameter\n");
5410 device_printf(devinfo->dev, "-----------------\n");
5411 hdaa_dump_audio_formats(devinfo->dev,
5412 devinfo->supp_stream_formats,
5413 devinfo->supp_pcm_size_rate);
5414 device_printf(devinfo->dev, " IN amp: 0x%08x\n",
5415 devinfo->inamp_cap);
5416 device_printf(devinfo->dev, " OUT amp: 0x%08x\n",
5417 devinfo->outamp_cap);
5418 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5419 w = hdaa_widget_get(devinfo, i);
5421 device_printf(devinfo->dev, "Ghost widget nid=%d\n", i);
5424 device_printf(devinfo->dev, "\n");
5425 device_printf(devinfo->dev, " nid: %d%s\n", w->nid,
5426 (w->enable == 0) ? " [DISABLED]" : "");
5427 device_printf(devinfo->dev, " Name: %s\n", w->name);
5428 device_printf(devinfo->dev, " Widget cap: 0x%08x\n",
5429 w->param.widget_cap);
5430 if (w->param.widget_cap & 0x0ee1) {
5431 device_printf(devinfo->dev, " ");
5432 if (HDA_PARAM_AUDIO_WIDGET_CAP_LR_SWAP(w->param.widget_cap))
5434 if (HDA_PARAM_AUDIO_WIDGET_CAP_POWER_CTRL(w->param.widget_cap))
5436 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap))
5438 if (HDA_PARAM_AUDIO_WIDGET_CAP_UNSOL_CAP(w->param.widget_cap))
5440 if (HDA_PARAM_AUDIO_WIDGET_CAP_PROC_WIDGET(w->param.widget_cap))
5442 if (HDA_PARAM_AUDIO_WIDGET_CAP_STRIPE(w->param.widget_cap))
5443 printf(" STRIPE(x%d)",
5444 1 << (fls(w->wclass.conv.stripecap) - 1));
5445 j = HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap);
5449 printf(" %dCH", j + 1);
5452 if (w->bindas != -1) {
5453 device_printf(devinfo->dev, " Association: %d (0x%08x)\n",
5454 w->bindas, w->bindseqmask);
5456 if (w->ossmask != 0 || w->ossdev >= 0) {
5457 device_printf(devinfo->dev, " OSS: %s",
5458 hdaa_audio_ctl_ossmixer_mask2allname(w->ossmask, buf, sizeof(buf)));
5460 printf(" (%s)", ossnames[w->ossdev]);
5463 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT ||
5464 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
5465 hdaa_dump_audio_formats(devinfo->dev,
5466 w->param.supp_stream_formats,
5467 w->param.supp_pcm_size_rate);
5468 } else if (w->type ==
5469 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX || w->waspin)
5471 if (w->param.eapdbtl != HDA_INVALID)
5472 device_printf(devinfo->dev, " EAPD: 0x%08x\n",
5474 if (HDA_PARAM_AUDIO_WIDGET_CAP_OUT_AMP(w->param.widget_cap) &&
5475 w->param.outamp_cap != 0)
5476 hdaa_dump_amp(devinfo->dev, w->param.outamp_cap, "Output");
5477 if (HDA_PARAM_AUDIO_WIDGET_CAP_IN_AMP(w->param.widget_cap) &&
5478 w->param.inamp_cap != 0)
5479 hdaa_dump_amp(devinfo->dev, w->param.inamp_cap, " Input");
5480 if (w->nconns > 0) {
5481 device_printf(devinfo->dev, " connections: %d\n", w->nconns);
5482 device_printf(devinfo->dev, " |\n");
5484 for (j = 0; j < w->nconns; j++) {
5485 cw = hdaa_widget_get(devinfo, w->conns[j]);
5486 device_printf(devinfo->dev, " + %s<- nid=%d [%s]",
5487 (w->connsenable[j] == 0)?"[DISABLED] ":"",
5488 w->conns[j], (cw == NULL) ? "GHOST!" : cw->name);
5490 printf(" [UNKNOWN]");
5491 else if (cw->enable == 0)
5492 printf(" [DISABLED]");
5493 if (w->nconns > 1 && w->selconn == j && w->type !=
5494 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
5495 printf(" (selected)");
5503 hdaa_dump_dst_nid(struct hdaa_pcm_devinfo *pdevinfo, nid_t nid, int depth)
5505 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
5506 struct hdaa_widget *w, *cw;
5510 if (depth > HDA_PARSE_MAXDEPTH)
5513 w = hdaa_widget_get(devinfo, nid);
5514 if (w == NULL || w->enable == 0)
5518 device_printf(pdevinfo->dev, "%*s", 4, "");
5520 device_printf(pdevinfo->dev, "%*s + <- ", 4 + (depth - 1) * 7, "");
5521 printf("nid=%d [%s]", w->nid, w->name);
5524 if (w->ossmask == 0) {
5528 printf(" [src: %s]",
5529 hdaa_audio_ctl_ossmixer_mask2allname(
5530 w->ossmask, buf, sizeof(buf)));
5531 if (w->ossdev >= 0) {
5538 for (i = 0; i < w->nconns; i++) {
5539 if (w->connsenable[i] == 0)
5541 cw = hdaa_widget_get(devinfo, w->conns[i]);
5542 if (cw == NULL || cw->enable == 0 || cw->bindas == -1)
5545 device_printf(pdevinfo->dev, "%*s |\n", 4 + (depth) * 7, "");
5548 hdaa_dump_dst_nid(pdevinfo, w->conns[i], depth + 1);
5554 hdaa_dump_dac(struct hdaa_pcm_devinfo *pdevinfo)
5556 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
5557 struct hdaa_audio_as *as;
5558 struct hdaa_widget *w;
5561 if (pdevinfo->playas < 0)
5564 as = &devinfo->as[pdevinfo->playas];
5565 for (i = 0; i < 16; i++) {
5566 if (as->pins[i] <= 0)
5568 w = hdaa_widget_get(devinfo, as->pins[i]);
5569 if (w == NULL || w->enable == 0)
5573 device_printf(pdevinfo->dev, "\n");
5574 device_printf(pdevinfo->dev, "Playback:\n");
5576 device_printf(pdevinfo->dev, "\n");
5577 hdaa_dump_dst_nid(pdevinfo, as->pins[i], 0);
5582 hdaa_dump_adc(struct hdaa_pcm_devinfo *pdevinfo)
5584 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
5585 struct hdaa_widget *w;
5589 if (pdevinfo->recas < 0)
5592 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5593 w = hdaa_widget_get(devinfo, i);
5594 if (w == NULL || w->enable == 0)
5596 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT)
5598 if (w->bindas != pdevinfo->recas)
5602 device_printf(pdevinfo->dev, "\n");
5603 device_printf(pdevinfo->dev, "Record:\n");
5605 device_printf(pdevinfo->dev, "\n");
5606 hdaa_dump_dst_nid(pdevinfo, i, 0);
5611 hdaa_dump_mix(struct hdaa_pcm_devinfo *pdevinfo)
5613 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
5614 struct hdaa_widget *w;
5618 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5619 w = hdaa_widget_get(devinfo, i);
5620 if (w == NULL || w->enable == 0)
5622 if (w->ossdev != SOUND_MIXER_IMIX)
5624 if (w->bindas != pdevinfo->recas)
5628 device_printf(pdevinfo->dev, "\n");
5629 device_printf(pdevinfo->dev, "Input Mix:\n");
5631 device_printf(pdevinfo->dev, "\n");
5632 hdaa_dump_dst_nid(pdevinfo, i, 0);
5637 hdaa_dump_pcmchannels(struct hdaa_pcm_devinfo *pdevinfo)
5639 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
5643 if (pdevinfo->playas >= 0) {
5644 device_printf(pdevinfo->dev, "\n");
5645 device_printf(pdevinfo->dev, "Playback:\n");
5646 device_printf(pdevinfo->dev, "\n");
5647 chid = devinfo->as[pdevinfo->playas].chans[0];
5648 hdaa_dump_audio_formats(pdevinfo->dev,
5649 devinfo->chans[chid].supp_stream_formats,
5650 devinfo->chans[chid].supp_pcm_size_rate);
5651 for (i = 0; i < devinfo->as[pdevinfo->playas].num_chans; i++) {
5652 chid = devinfo->as[pdevinfo->playas].chans[i];
5653 device_printf(pdevinfo->dev, " DAC:");
5654 for (nids = devinfo->chans[chid].io; *nids != -1; nids++)
5655 printf(" %d", *nids);
5659 if (pdevinfo->recas >= 0) {
5660 device_printf(pdevinfo->dev, "\n");
5661 device_printf(pdevinfo->dev, "Record:\n");
5662 device_printf(pdevinfo->dev, "\n");
5663 chid = devinfo->as[pdevinfo->recas].chans[0];
5664 hdaa_dump_audio_formats(pdevinfo->dev,
5665 devinfo->chans[chid].supp_stream_formats,
5666 devinfo->chans[chid].supp_pcm_size_rate);
5667 for (i = 0; i < devinfo->as[pdevinfo->recas].num_chans; i++) {
5668 chid = devinfo->as[pdevinfo->recas].chans[i];
5669 device_printf(pdevinfo->dev, " DAC:");
5670 for (nids = devinfo->chans[chid].io; *nids != -1; nids++)
5671 printf(" %d", *nids);
5678 hdaa_pindump(device_t dev)
5680 struct hdaa_devinfo *devinfo = device_get_softc(dev);
5681 struct hdaa_widget *w;
5682 uint32_t res, pincap, delay;
5685 device_printf(dev, "Dumping AFG pins:\n");
5686 device_printf(dev, "nid 0x as seq "
5687 "device conn jack loc color misc\n");
5688 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5689 w = hdaa_widget_get(devinfo, i);
5690 if (w == NULL || w->type !=
5691 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
5693 hdaa_dump_pin_config(w, w->wclass.pin.config);
5694 pincap = w->wclass.pin.cap;
5695 device_printf(dev, " Caps: %2s %3s %2s %4s %4s",
5696 HDA_PARAM_PIN_CAP_INPUT_CAP(pincap)?"IN":"",
5697 HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap)?"OUT":"",
5698 HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap)?"HP":"",
5699 HDA_PARAM_PIN_CAP_EAPD_CAP(pincap)?"EAPD":"",
5700 HDA_PARAM_PIN_CAP_VREF_CTRL(pincap)?"VREF":"");
5701 if (HDA_PARAM_PIN_CAP_IMP_SENSE_CAP(pincap) ||
5702 HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(pincap)) {
5703 if (HDA_PARAM_PIN_CAP_TRIGGER_REQD(pincap)) {
5706 HDA_CMD_SET_PIN_SENSE(0, w->nid, 0));
5708 res = hda_command(dev,
5709 HDA_CMD_GET_PIN_SENSE(0, w->nid));
5710 if (res != 0x7fffffff && res != 0xffffffff)
5713 } while (++delay < 10000);
5716 res = hda_command(dev, HDA_CMD_GET_PIN_SENSE(0,
5719 printf(" Sense: 0x%08x (%sconnected%s)", res,
5720 (res & HDA_CMD_GET_PIN_SENSE_PRESENCE_DETECT) ?
5722 (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap) &&
5723 (res & HDA_CMD_GET_PIN_SENSE_ELD_VALID)) ?
5724 ", ELD valid" : "");
5726 printf(" delay %dus", delay * 10);
5731 "NumGPIO=%d NumGPO=%d NumGPI=%d GPIWake=%d GPIUnsol=%d\n",
5732 HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap),
5733 HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap),
5734 HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap),
5735 HDA_PARAM_GPIO_COUNT_GPI_WAKE(devinfo->gpio_cap),
5736 HDA_PARAM_GPIO_COUNT_GPI_UNSOL(devinfo->gpio_cap));
5737 hdaa_dump_gpi(devinfo);
5738 hdaa_dump_gpio(devinfo);
5739 hdaa_dump_gpo(devinfo);
5743 hdaa_configure(device_t dev)
5745 struct hdaa_devinfo *devinfo = device_get_softc(dev);
5746 struct hdaa_audio_ctl *ctl;
5750 device_printf(dev, "Applying built-in patches...\n");
5752 hdaa_patch(devinfo);
5754 device_printf(dev, "Applying local patches...\n");
5756 hdaa_local_patch(devinfo);
5757 hdaa_audio_postprocess(devinfo);
5759 device_printf(dev, "Parsing Ctls...\n");
5761 hdaa_audio_ctl_parse(devinfo);
5763 device_printf(dev, "Disabling nonaudio...\n");
5765 hdaa_audio_disable_nonaudio(devinfo);
5767 device_printf(dev, "Disabling useless...\n");
5769 hdaa_audio_disable_useless(devinfo);
5771 device_printf(dev, "Patched pins configuration:\n");
5772 hdaa_dump_pin_configs(devinfo);
5775 device_printf(dev, "Parsing pin associations...\n");
5777 hdaa_audio_as_parse(devinfo);
5779 device_printf(dev, "Building AFG tree...\n");
5781 hdaa_audio_build_tree(devinfo);
5783 device_printf(dev, "Disabling unassociated "
5786 hdaa_audio_disable_unas(devinfo);
5788 device_printf(dev, "Disabling nonselected "
5791 hdaa_audio_disable_notselected(devinfo);
5793 device_printf(dev, "Disabling useless...\n");
5795 hdaa_audio_disable_useless(devinfo);
5797 device_printf(dev, "Disabling "
5798 "crossassociatement connections...\n");
5800 hdaa_audio_disable_crossas(devinfo);
5802 device_printf(dev, "Disabling useless...\n");
5804 hdaa_audio_disable_useless(devinfo);
5806 device_printf(dev, "Binding associations to channels...\n");
5808 hdaa_audio_bind_as(devinfo);
5810 device_printf(dev, "Assigning names to signal sources...\n");
5812 hdaa_audio_assign_names(devinfo);
5814 device_printf(dev, "Preparing PCM devices...\n");
5816 hdaa_prepare_pcms(devinfo);
5818 device_printf(dev, "Assigning mixers to the tree...\n");
5820 hdaa_audio_assign_mixers(devinfo);
5822 device_printf(dev, "Preparing pin controls...\n");
5824 hdaa_audio_prepare_pin_ctrl(devinfo);
5826 device_printf(dev, "AFG commit...\n");
5828 hdaa_audio_commit(devinfo);
5830 device_printf(dev, "Applying direct built-in patches...\n");
5832 hdaa_patch_direct(devinfo);
5834 device_printf(dev, "Pin sense init...\n");
5836 hdaa_sense_init(devinfo);
5838 device_printf(dev, "Creating PCM devices...\n");
5840 hdaa_create_pcms(devinfo);
5843 if (devinfo->quirks != 0) {
5844 device_printf(dev, "FG config/quirks:");
5845 for (i = 0; i < HDAA_QUIRKS_TAB_LEN; i++) {
5846 if ((devinfo->quirks &
5847 hdaa_quirks_tab[i].value) ==
5848 hdaa_quirks_tab[i].value)
5849 printf(" %s", hdaa_quirks_tab[i].key);
5854 device_printf(dev, "\n");
5855 device_printf(dev, "+-------------------+\n");
5856 device_printf(dev, "| DUMPING HDA NODES |\n");
5857 device_printf(dev, "+-------------------+\n");
5858 hdaa_dump_nodes(devinfo);
5862 device_printf(dev, "\n");
5863 device_printf(dev, "+------------------------+\n");
5864 device_printf(dev, "| DUMPING HDA AMPLIFIERS |\n");
5865 device_printf(dev, "+------------------------+\n");
5866 device_printf(dev, "\n");
5868 while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) {
5869 device_printf(dev, "%3d: nid %3d %s (%s) index %d", i,
5870 (ctl->widget != NULL) ? ctl->widget->nid : -1,
5871 (ctl->ndir == HDAA_CTL_IN)?"in ":"out",
5872 (ctl->dir == HDAA_CTL_IN)?"in ":"out",
5874 if (ctl->childwidget != NULL)
5875 printf(" cnid %3d", ctl->childwidget->nid);
5878 printf(" ossmask=0x%08x\n",
5881 " mute: %d step: %3d size: %3d off: %3d%s\n",
5882 ctl->mute, ctl->step, ctl->size, ctl->offset,
5883 (ctl->enable == 0) ? " [DISABLED]" :
5884 ((ctl->ossmask == 0) ? " [UNUSED]" : ""));
5889 device_printf(dev, "\n");
5894 hdaa_unconfigure(device_t dev)
5896 struct hdaa_devinfo *devinfo = device_get_softc(dev);
5897 struct hdaa_widget *w;
5901 device_printf(dev, "Pin sense deinit...\n");
5903 hdaa_sense_deinit(devinfo);
5904 free(devinfo->ctl, M_HDAA);
5905 devinfo->ctl = NULL;
5906 devinfo->ctlcnt = 0;
5907 free(devinfo->as, M_HDAA);
5910 free(devinfo->devs, M_HDAA);
5911 devinfo->devs = NULL;
5912 devinfo->num_devs = 0;
5913 free(devinfo->chans, M_HDAA);
5914 devinfo->chans = NULL;
5915 devinfo->num_chans = 0;
5916 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5917 w = hdaa_widget_get(devinfo, i);
5927 for (j = 0; j < w->nconns; j++)
5928 w->connsenable[j] = 1;
5929 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
5930 w->wclass.pin.config = w->wclass.pin.newconf;
5931 if (w->eld != NULL) {
5933 free(w->eld, M_HDAA);
5940 hdaa_sysctl_gpi_state(SYSCTL_HANDLER_ARGS)
5942 struct hdaa_devinfo *devinfo = oidp->oid_arg1;
5943 device_t dev = devinfo->dev;
5945 int n = 0, i, numgpi;
5950 numgpi = HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap);
5952 data = hda_command(dev,
5953 HDA_CMD_GET_GPI_DATA(0, devinfo->nid));
5955 hdaa_unlock(devinfo);
5956 for (i = 0; i < numgpi; i++) {
5957 n += snprintf(buf + n, sizeof(buf) - n, "%s%d=%d",
5958 n != 0 ? " " : "", i, ((data >> i) & 1));
5960 return (sysctl_handle_string(oidp, buf, sizeof(buf), req));
5964 hdaa_sysctl_gpio_state(SYSCTL_HANDLER_ARGS)
5966 struct hdaa_devinfo *devinfo = oidp->oid_arg1;
5967 device_t dev = devinfo->dev;
5969 int n = 0, i, numgpio;
5970 uint32_t data = 0, enable = 0, dir = 0;
5974 numgpio = HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap);
5976 data = hda_command(dev,
5977 HDA_CMD_GET_GPIO_DATA(0, devinfo->nid));
5978 enable = hda_command(dev,
5979 HDA_CMD_GET_GPIO_ENABLE_MASK(0, devinfo->nid));
5980 dir = hda_command(dev,
5981 HDA_CMD_GET_GPIO_DIRECTION(0, devinfo->nid));
5983 hdaa_unlock(devinfo);
5984 for (i = 0; i < numgpio; i++) {
5985 n += snprintf(buf + n, sizeof(buf) - n, "%s%d=",
5986 n != 0 ? " " : "", i);
5987 if ((enable & (1 << i)) == 0) {
5988 n += snprintf(buf + n, sizeof(buf) - n, "disabled");
5991 n += snprintf(buf + n, sizeof(buf) - n, "%sput(%d)",
5992 ((dir >> i) & 1) ? "out" : "in", ((data >> i) & 1));
5994 return (sysctl_handle_string(oidp, buf, sizeof(buf), req));
5998 hdaa_sysctl_gpio_config(SYSCTL_HANDLER_ARGS)
6000 struct hdaa_devinfo *devinfo = oidp->oid_arg1;
6002 int error, n = 0, i, numgpio;
6005 gpio = devinfo->newgpio;
6006 numgpio = HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap);
6008 for (i = 0; i < numgpio; i++) {
6009 x = (gpio & HDAA_GPIO_MASK(i)) >> HDAA_GPIO_SHIFT(i);
6010 n += snprintf(buf + n, sizeof(buf) - n, "%s%d=%s",
6011 n != 0 ? " " : "", i, HDA_GPIO_ACTIONS[x]);
6013 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
6014 if (error != 0 || req->newptr == NULL)
6016 if (strncmp(buf, "0x", 2) == 0)
6017 gpio = strtol(buf + 2, NULL, 16);
6019 gpio = hdaa_gpio_patch(gpio, buf);
6021 devinfo->newgpio = devinfo->gpio = gpio;
6022 hdaa_gpio_commit(devinfo);
6023 hdaa_unlock(devinfo);
6028 hdaa_sysctl_gpo_state(SYSCTL_HANDLER_ARGS)
6030 struct hdaa_devinfo *devinfo = oidp->oid_arg1;
6031 device_t dev = devinfo->dev;
6033 int n = 0, i, numgpo;
6038 numgpo = HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap);
6040 data = hda_command(dev,
6041 HDA_CMD_GET_GPO_DATA(0, devinfo->nid));
6043 hdaa_unlock(devinfo);
6044 for (i = 0; i < numgpo; i++) {
6045 n += snprintf(buf + n, sizeof(buf) - n, "%s%d=%d",
6046 n != 0 ? " " : "", i, ((data >> i) & 1));
6048 return (sysctl_handle_string(oidp, buf, sizeof(buf), req));
6052 hdaa_sysctl_gpo_config(SYSCTL_HANDLER_ARGS)
6054 struct hdaa_devinfo *devinfo = oidp->oid_arg1;
6056 int error, n = 0, i, numgpo;
6059 gpo = devinfo->newgpo;
6060 numgpo = HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap);
6062 for (i = 0; i < numgpo; i++) {
6063 x = (gpo & HDAA_GPIO_MASK(i)) >> HDAA_GPIO_SHIFT(i);
6064 n += snprintf(buf + n, sizeof(buf) - n, "%s%d=%s",
6065 n != 0 ? " " : "", i, HDA_GPIO_ACTIONS[x]);
6067 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
6068 if (error != 0 || req->newptr == NULL)
6070 if (strncmp(buf, "0x", 2) == 0)
6071 gpo = strtol(buf + 2, NULL, 16);
6073 gpo = hdaa_gpio_patch(gpo, buf);
6075 devinfo->newgpo = devinfo->gpo = gpo;
6076 hdaa_gpo_commit(devinfo);
6077 hdaa_unlock(devinfo);
6082 hdaa_sysctl_reconfig(SYSCTL_HANDLER_ARGS)
6085 struct hdaa_devinfo *devinfo;
6088 dev = oidp->oid_arg1;
6089 devinfo = device_get_softc(dev);
6090 if (devinfo == NULL)
6093 error = sysctl_handle_int(oidp, &val, 0, req);
6094 if (error != 0 || req->newptr == NULL || val == 0)
6098 device_printf(dev, "Reconfiguration...\n");
6100 if ((error = device_delete_children(dev)) != 0)
6103 hdaa_unconfigure(dev);
6104 hdaa_configure(dev);
6105 hdaa_unlock(devinfo);
6106 bus_generic_attach(dev);
6108 device_printf(dev, "Reconfiguration done\n");
6114 hdaa_suspend(device_t dev)
6116 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6120 device_printf(dev, "Suspend...\n");
6124 device_printf(dev, "Stop streams...\n");
6126 for (i = 0; i < devinfo->num_chans; i++) {
6127 if (devinfo->chans[i].flags & HDAA_CHN_RUNNING) {
6128 devinfo->chans[i].flags |= HDAA_CHN_SUSPEND;
6129 hdaa_channel_stop(&devinfo->chans[i]);
6133 device_printf(dev, "Power down FG"
6134 " nid=%d to the D3 state...\n",
6137 hda_command(devinfo->dev,
6138 HDA_CMD_SET_POWER_STATE(0,
6139 devinfo->nid, HDA_CMD_POWER_STATE_D3));
6140 callout_stop(&devinfo->poll_jack);
6141 hdaa_unlock(devinfo);
6142 callout_drain(&devinfo->poll_jack);
6144 device_printf(dev, "Suspend done\n");
6150 hdaa_resume(device_t dev)
6152 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6156 device_printf(dev, "Resume...\n");
6160 device_printf(dev, "Power up audio FG nid=%d...\n",
6163 hdaa_powerup(devinfo);
6165 device_printf(dev, "AFG commit...\n");
6167 hdaa_audio_commit(devinfo);
6169 device_printf(dev, "Applying direct built-in patches...\n");
6171 hdaa_patch_direct(devinfo);
6173 device_printf(dev, "Pin sense init...\n");
6175 hdaa_sense_init(devinfo);
6177 hdaa_unlock(devinfo);
6178 for (i = 0; i < devinfo->num_devs; i++) {
6179 struct hdaa_pcm_devinfo *pdevinfo = &devinfo->devs[i];
6181 device_printf(pdevinfo->dev,
6182 "OSS mixer reinitialization...\n");
6184 if (mixer_reinit(pdevinfo->dev) == -1)
6185 device_printf(pdevinfo->dev,
6186 "unable to reinitialize the mixer\n");
6190 device_printf(dev, "Start streams...\n");
6192 for (i = 0; i < devinfo->num_chans; i++) {
6193 if (devinfo->chans[i].flags & HDAA_CHN_SUSPEND) {
6194 devinfo->chans[i].flags &= ~HDAA_CHN_SUSPEND;
6195 hdaa_channel_start(&devinfo->chans[i]);
6198 hdaa_unlock(devinfo);
6200 device_printf(dev, "Resume done\n");
6206 hdaa_probe(device_t dev)
6211 if (hda_get_node_type(dev) != HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO)
6213 pdesc = device_get_desc(device_get_parent(dev));
6214 snprintf(buf, sizeof(buf), "%.*s Audio Function Group",
6215 (int)(strlen(pdesc) - 10), pdesc);
6216 device_set_desc_copy(dev, buf);
6217 return (BUS_PROBE_DEFAULT);
6221 hdaa_attach(device_t dev)
6223 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6225 nid_t nid = hda_get_node_id(dev);
6228 devinfo->lock = HDAC_GET_MTX(device_get_parent(dev), dev);
6230 devinfo->newquirks = -1;
6231 devinfo->newgpio = -1;
6232 devinfo->newgpo = -1;
6233 callout_init(&devinfo->poll_jack, CALLOUT_MPSAFE);
6234 devinfo->poll_ival = hz;
6237 res = hda_command(dev,
6238 HDA_CMD_GET_PARAMETER(0 , nid, HDA_PARAM_SUB_NODE_COUNT));
6239 hdaa_unlock(devinfo);
6241 devinfo->nodecnt = HDA_PARAM_SUB_NODE_COUNT_TOTAL(res);
6242 devinfo->startnode = HDA_PARAM_SUB_NODE_COUNT_START(res);
6243 devinfo->endnode = devinfo->startnode + devinfo->nodecnt;
6246 device_printf(dev, "Subsystem ID: 0x%08x\n",
6247 hda_get_subsystem_id(dev));
6251 "Audio Function Group at nid=%d: %d subnodes %d-%d\n",
6252 nid, devinfo->nodecnt,
6253 devinfo->startnode, devinfo->endnode - 1);
6256 if (devinfo->nodecnt > 0)
6257 devinfo->widget = (struct hdaa_widget *)malloc(
6258 sizeof(*(devinfo->widget)) * devinfo->nodecnt, M_HDAA,
6261 devinfo->widget = NULL;
6265 device_printf(dev, "Powering up...\n");
6267 hdaa_powerup(devinfo);
6269 device_printf(dev, "Parsing audio FG...\n");
6271 hdaa_audio_parse(devinfo);
6273 device_printf(dev, "Original pins configuration:\n");
6274 hdaa_dump_pin_configs(devinfo);
6276 hdaa_configure(dev);
6277 hdaa_unlock(devinfo);
6279 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6280 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6281 "config", CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE,
6282 &devinfo->newquirks, sizeof(&devinfo->newquirks),
6283 hdaa_sysctl_quirks, "A", "Configuration options");
6284 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6285 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6286 "gpi_state", CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
6287 devinfo, sizeof(devinfo),
6288 hdaa_sysctl_gpi_state, "A", "GPI state");
6289 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6290 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6291 "gpio_state", CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
6292 devinfo, sizeof(devinfo),
6293 hdaa_sysctl_gpio_state, "A", "GPIO state");
6294 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6295 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6296 "gpio_config", CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE,
6297 devinfo, sizeof(devinfo),
6298 hdaa_sysctl_gpio_config, "A", "GPIO configuration");
6299 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6300 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6301 "gpo_state", CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
6302 devinfo, sizeof(devinfo),
6303 hdaa_sysctl_gpo_state, "A", "GPO state");
6304 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6305 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6306 "gpo_config", CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE,
6307 devinfo, sizeof(devinfo),
6308 hdaa_sysctl_gpo_config, "A", "GPO configuration");
6309 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
6310 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
6311 "reconfig", CTLTYPE_INT | CTLFLAG_RW,
6313 hdaa_sysctl_reconfig, "I", "Reprocess configuration");
6314 bus_generic_attach(dev);
6319 hdaa_detach(device_t dev)
6321 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6324 if ((error = device_delete_children(dev)) != 0)
6328 hdaa_unconfigure(dev);
6329 devinfo->poll_ival = 0;
6330 callout_stop(&devinfo->poll_jack);
6331 hdaa_unlock(devinfo);
6332 callout_drain(&devinfo->poll_jack);
6334 free(devinfo->widget, M_HDAA);
6339 hdaa_print_child(device_t dev, device_t child)
6341 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6342 struct hdaa_pcm_devinfo *pdevinfo =
6343 (struct hdaa_pcm_devinfo *)device_get_ivars(child);
6344 struct hdaa_audio_as *as;
6345 int retval, first = 1, i;
6347 retval = bus_print_child_header(dev, child);
6348 retval += printf(" at nid ");
6349 if (pdevinfo->playas >= 0) {
6350 as = &devinfo->as[pdevinfo->playas];
6351 for (i = 0; i < 16; i++) {
6352 if (as->pins[i] <= 0)
6354 retval += printf("%s%d", first ? "" : ",", as->pins[i]);
6358 if (pdevinfo->recas >= 0) {
6359 if (pdevinfo->playas >= 0) {
6360 retval += printf(" and ");
6363 as = &devinfo->as[pdevinfo->recas];
6364 for (i = 0; i < 16; i++) {
6365 if (as->pins[i] <= 0)
6367 retval += printf("%s%d", first ? "" : ",", as->pins[i]);
6371 retval += bus_print_child_footer(dev, child);
6377 hdaa_child_location_str(device_t dev, device_t child, char *buf,
6380 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6381 struct hdaa_pcm_devinfo *pdevinfo =
6382 (struct hdaa_pcm_devinfo *)device_get_ivars(child);
6383 struct hdaa_audio_as *as;
6384 int first = 1, i, len = 0;
6386 len += snprintf(buf + len, buflen - len, "nid=");
6387 if (pdevinfo->playas >= 0) {
6388 as = &devinfo->as[pdevinfo->playas];
6389 for (i = 0; i < 16; i++) {
6390 if (as->pins[i] <= 0)
6392 len += snprintf(buf + len, buflen - len,
6393 "%s%d", first ? "" : ",", as->pins[i]);
6397 if (pdevinfo->recas >= 0) {
6398 as = &devinfo->as[pdevinfo->recas];
6399 for (i = 0; i < 16; i++) {
6400 if (as->pins[i] <= 0)
6402 len += snprintf(buf + len, buflen - len,
6403 "%s%d", first ? "" : ",", as->pins[i]);
6411 hdaa_stream_intr(device_t dev, int dir, int stream)
6413 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6414 struct hdaa_chan *ch;
6417 for (i = 0; i < devinfo->num_chans; i++) {
6418 ch = &devinfo->chans[i];
6419 if (!(ch->flags & HDAA_CHN_RUNNING))
6421 if (ch->dir == ((dir == 1) ? PCMDIR_PLAY : PCMDIR_REC) &&
6422 ch->sid == stream) {
6423 hdaa_unlock(devinfo);
6431 hdaa_unsol_intr(device_t dev, uint32_t resp)
6433 struct hdaa_devinfo *devinfo = device_get_softc(dev);
6434 struct hdaa_widget *w;
6438 device_printf(dev, "Unsolicited response %08x\n", resp);
6441 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
6442 w = hdaa_widget_get(devinfo, i);
6443 if (w == NULL || w->enable == 0 || w->type !=
6444 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
6446 if (w->unsol != tag)
6448 if (HDA_PARAM_PIN_CAP_DP(w->wclass.pin.cap) ||
6449 HDA_PARAM_PIN_CAP_HDMI(w->wclass.pin.cap))
6450 flags = resp & 0x03;
6454 hdaa_presence_handler(w);
6456 hdaa_eld_handler(w);
6460 static device_method_t hdaa_methods[] = {
6461 /* device interface */
6462 DEVMETHOD(device_probe, hdaa_probe),
6463 DEVMETHOD(device_attach, hdaa_attach),
6464 DEVMETHOD(device_detach, hdaa_detach),
6465 DEVMETHOD(device_suspend, hdaa_suspend),
6466 DEVMETHOD(device_resume, hdaa_resume),
6468 DEVMETHOD(bus_print_child, hdaa_print_child),
6469 DEVMETHOD(bus_child_location_str, hdaa_child_location_str),
6470 DEVMETHOD(hdac_stream_intr, hdaa_stream_intr),
6471 DEVMETHOD(hdac_unsol_intr, hdaa_unsol_intr),
6472 DEVMETHOD(hdac_pindump, hdaa_pindump),
6476 static driver_t hdaa_driver = {
6479 sizeof(struct hdaa_devinfo),
6482 static devclass_t hdaa_devclass;
6484 DRIVER_MODULE(snd_hda, hdacc, hdaa_driver, hdaa_devclass, 0, 0);
6487 hdaa_chan_formula(struct hdaa_devinfo *devinfo, int asid,
6488 char *buf, int buflen)
6490 struct hdaa_audio_as *as;
6493 as = &devinfo->as[asid];
6494 c = devinfo->chans[as->chans[0]].channels;
6496 snprintf(buf, buflen, "mono");
6498 if (as->hpredir < 0)
6501 snprintf(buf, buflen, "2.0");
6502 } else if (as->pinset == 0x0003)
6503 snprintf(buf, buflen, "3.1");
6504 else if (as->pinset == 0x0005 || as->pinset == 0x0011)
6505 snprintf(buf, buflen, "4.0");
6506 else if (as->pinset == 0x0007 || as->pinset == 0x0013)
6507 snprintf(buf, buflen, "5.1");
6508 else if (as->pinset == 0x0017)
6509 snprintf(buf, buflen, "7.1");
6511 snprintf(buf, buflen, "%dch", c);
6512 if (as->hpredir >= 0)
6513 strlcat(buf, "+HP", buflen);
6517 hdaa_chan_type(struct hdaa_devinfo *devinfo, int asid)
6519 struct hdaa_audio_as *as;
6520 struct hdaa_widget *w;
6523 as = &devinfo->as[asid];
6524 for (i = 0; i < 16; i++) {
6525 w = hdaa_widget_get(devinfo, as->pins[i]);
6526 if (w == NULL || w->enable == 0 || w->type !=
6527 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
6529 t1 = HDA_CONFIG_DEFAULTCONF_DEVICE(w->wclass.pin.config);
6541 hdaa_sysctl_32bit(SYSCTL_HANDLER_ARGS)
6543 struct hdaa_audio_as *as = (struct hdaa_audio_as *)oidp->oid_arg1;
6544 struct hdaa_pcm_devinfo *pdevinfo = as->pdevinfo;
6545 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
6546 struct hdaa_chan *ch;
6550 ch = &devinfo->chans[as->chans[0]];
6551 val = (ch->bit32 == 4) ? 32 : ((ch->bit32 == 3) ? 24 :
6552 ((ch->bit32 == 2) ? 20 : 0));
6553 error = sysctl_handle_int(oidp, &val, 0, req);
6554 if (error != 0 || req->newptr == NULL)
6556 pcmcap = ch->supp_pcm_size_rate;
6557 if (val == 32 && HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(pcmcap))
6559 else if (val == 24 && HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(pcmcap))
6561 else if (val == 20 && HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(pcmcap))
6565 for (i = 1; i < as->num_chans; i++)
6566 devinfo->chans[as->chans[i]].bit32 = ch->bit32;
6571 hdaa_pcm_probe(device_t dev)
6573 struct hdaa_pcm_devinfo *pdevinfo =
6574 (struct hdaa_pcm_devinfo *)device_get_ivars(dev);
6575 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
6577 char chans1[8], chans2[8];
6579 int loc1, loc2, t1, t2;
6581 if (pdevinfo->playas >= 0)
6582 loc1 = devinfo->as[pdevinfo->playas].location;
6584 loc1 = devinfo->as[pdevinfo->recas].location;
6585 if (pdevinfo->recas >= 0)
6586 loc2 = devinfo->as[pdevinfo->recas].location;
6591 if (loc1 >= 0 && HDA_LOCS[loc1][0] == '0')
6596 if (pdevinfo->playas >= 0) {
6597 hdaa_chan_formula(devinfo, pdevinfo->playas,
6598 chans1, sizeof(chans1));
6599 t1 = hdaa_chan_type(devinfo, pdevinfo->playas);
6601 if (pdevinfo->recas >= 0) {
6602 hdaa_chan_formula(devinfo, pdevinfo->recas,
6603 chans2, sizeof(chans2));
6604 t2 = hdaa_chan_type(devinfo, pdevinfo->recas);
6606 if (chans1[0] != 0 || chans2[0] != 0) {
6607 if (chans1[0] == 0 && pdevinfo->playas >= 0)
6608 snprintf(chans1, sizeof(chans1), "2.0");
6609 else if (chans2[0] == 0 && pdevinfo->recas >= 0)
6610 snprintf(chans2, sizeof(chans2), "2.0");
6611 if (strcmp(chans1, chans2) == 0)
6620 if (pdevinfo->digital)
6622 pdesc = device_get_desc(device_get_parent(dev));
6623 snprintf(buf, sizeof(buf), "%.*s (%s%s%s%s%s%s%s%s%s)",
6624 (int)(strlen(pdesc) - 21), pdesc,
6625 loc1 >= 0 ? HDA_LOCS[loc1] : "", loc1 >= 0 ? " " : "",
6626 (pdevinfo->digital == 0x7)?"HDMI/DP":
6627 ((pdevinfo->digital == 0x5)?"DisplayPort":
6628 ((pdevinfo->digital == 0x3)?"HDMI":
6629 ((pdevinfo->digital)?"Digital":"Analog"))),
6630 chans1[0] ? " " : "", chans1,
6631 chans2[0] ? "/" : "", chans2,
6632 t1 >= 0 ? " " : "", t1 >= 0 ? HDA_DEVS[t1] : "");
6633 device_set_desc_copy(dev, buf);
6634 return (BUS_PROBE_SPECIFIC);
6638 hdaa_pcm_attach(device_t dev)
6640 struct hdaa_pcm_devinfo *pdevinfo =
6641 (struct hdaa_pcm_devinfo *)device_get_ivars(dev);
6642 struct hdaa_devinfo *devinfo = pdevinfo->devinfo;
6643 struct hdaa_audio_as *as;
6644 struct snddev_info *d;
6645 char status[SND_STATUSLEN];
6648 pdevinfo->chan_size = pcm_getbuffersize(dev,
6649 HDA_BUFSZ_MIN, HDA_BUFSZ_DEFAULT, HDA_BUFSZ_MAX);
6652 device_printf(dev, "+--------------------------------------+\n");
6653 device_printf(dev, "| DUMPING PCM Playback/Record Channels |\n");
6654 device_printf(dev, "+--------------------------------------+\n");
6655 hdaa_dump_pcmchannels(pdevinfo);
6656 device_printf(dev, "\n");
6657 device_printf(dev, "+-------------------------------+\n");
6658 device_printf(dev, "| DUMPING Playback/Record Paths |\n");
6659 device_printf(dev, "+-------------------------------+\n");
6660 hdaa_dump_dac(pdevinfo);
6661 hdaa_dump_adc(pdevinfo);
6662 hdaa_dump_mix(pdevinfo);
6663 device_printf(dev, "\n");
6664 device_printf(dev, "+-------------------------+\n");
6665 device_printf(dev, "| DUMPING Volume Controls |\n");
6666 device_printf(dev, "+-------------------------+\n");
6667 hdaa_dump_ctls(pdevinfo, "Master Volume", SOUND_MASK_VOLUME);
6668 hdaa_dump_ctls(pdevinfo, "PCM Volume", SOUND_MASK_PCM);
6669 hdaa_dump_ctls(pdevinfo, "CD Volume", SOUND_MASK_CD);
6670 hdaa_dump_ctls(pdevinfo, "Microphone Volume", SOUND_MASK_MIC);
6671 hdaa_dump_ctls(pdevinfo, "Microphone2 Volume", SOUND_MASK_MONITOR);
6672 hdaa_dump_ctls(pdevinfo, "Line-in Volume", SOUND_MASK_LINE);
6673 hdaa_dump_ctls(pdevinfo, "Speaker/Beep Volume", SOUND_MASK_SPEAKER);
6674 hdaa_dump_ctls(pdevinfo, "Recording Level", SOUND_MASK_RECLEV);
6675 hdaa_dump_ctls(pdevinfo, "Input Mix Level", SOUND_MASK_IMIX);
6676 hdaa_dump_ctls(pdevinfo, "Input Monitoring Level", SOUND_MASK_IGAIN);
6677 hdaa_dump_ctls(pdevinfo, NULL, 0);
6678 device_printf(dev, "\n");
6681 if (resource_int_value(device_get_name(dev),
6682 device_get_unit(dev), "blocksize", &i) == 0 && i > 0) {
6684 if (i < HDA_BLK_MIN)
6686 pdevinfo->chan_blkcnt = pdevinfo->chan_size / i;
6688 while (pdevinfo->chan_blkcnt >> i)
6690 pdevinfo->chan_blkcnt = 1 << (i - 1);
6691 if (pdevinfo->chan_blkcnt < HDA_BDL_MIN)
6692 pdevinfo->chan_blkcnt = HDA_BDL_MIN;
6693 else if (pdevinfo->chan_blkcnt > HDA_BDL_MAX)
6694 pdevinfo->chan_blkcnt = HDA_BDL_MAX;
6696 pdevinfo->chan_blkcnt = HDA_BDL_DEFAULT;
6699 * We don't register interrupt handler with snd_setup_intr
6700 * in pcm device. Mark pcm device as MPSAFE manually.
6702 pcm_setflags(dev, pcm_getflags(dev) | SD_F_MPSAFE);
6705 device_printf(dev, "OSS mixer initialization...\n");
6707 if (mixer_init(dev, &hdaa_audio_ctl_ossmixer_class, pdevinfo) != 0)
6708 device_printf(dev, "Can't register mixer\n");
6711 device_printf(dev, "Registering PCM channels...\n");
6713 if (pcm_register(dev, pdevinfo, (pdevinfo->playas >= 0)?1:0,
6714 (pdevinfo->recas >= 0)?1:0) != 0)
6715 device_printf(dev, "Can't register PCM\n");
6717 pdevinfo->registered++;
6719 d = device_get_softc(dev);
6720 if (pdevinfo->playas >= 0) {
6721 as = &devinfo->as[pdevinfo->playas];
6722 for (i = 0; i < as->num_chans; i++)
6723 pcm_addchan(dev, PCMDIR_PLAY, &hdaa_channel_class,
6724 &devinfo->chans[as->chans[i]]);
6725 SYSCTL_ADD_PROC(&d->play_sysctl_ctx,
6726 SYSCTL_CHILDREN(d->play_sysctl_tree), OID_AUTO,
6727 "32bit", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
6728 as, sizeof(as), hdaa_sysctl_32bit, "I",
6729 "Resolution of 32bit samples (20/24/32bit)");
6731 if (pdevinfo->recas >= 0) {
6732 as = &devinfo->as[pdevinfo->recas];
6733 for (i = 0; i < as->num_chans; i++)
6734 pcm_addchan(dev, PCMDIR_REC, &hdaa_channel_class,
6735 &devinfo->chans[as->chans[i]]);
6736 SYSCTL_ADD_PROC(&d->rec_sysctl_ctx,
6737 SYSCTL_CHILDREN(d->rec_sysctl_tree), OID_AUTO,
6738 "32bit", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
6739 as, sizeof(as), hdaa_sysctl_32bit, "I",
6740 "Resolution of 32bit samples (20/24/32bit)");
6741 pdevinfo->autorecsrc = 2;
6742 resource_int_value(device_get_name(dev), device_get_unit(dev),
6743 "rec.autosrc", &pdevinfo->autorecsrc);
6744 SYSCTL_ADD_INT(&d->rec_sysctl_ctx,
6745 SYSCTL_CHILDREN(d->rec_sysctl_tree), OID_AUTO,
6746 "autosrc", CTLTYPE_INT | CTLFLAG_RW,
6747 &pdevinfo->autorecsrc, 0,
6748 "Automatic recording source selection");
6751 if (pdevinfo->mixer != NULL) {
6752 hdaa_audio_ctl_set_defaults(pdevinfo);
6753 if (pdevinfo->recas >= 0) {
6754 as = &devinfo->as[pdevinfo->recas];
6756 hdaa_autorecsrc_handler(as, NULL);
6757 hdaa_unlock(devinfo);
6761 snprintf(status, SND_STATUSLEN, "on %s %s",
6762 device_get_nameunit(device_get_parent(dev)),
6763 PCM_KLDSTRING(snd_hda));
6764 pcm_setstatus(dev, status);
6770 hdaa_pcm_detach(device_t dev)
6772 struct hdaa_pcm_devinfo *pdevinfo =
6773 (struct hdaa_pcm_devinfo *)device_get_ivars(dev);
6776 if (pdevinfo->registered > 0) {
6777 err = pcm_unregister(dev);
6785 static device_method_t hdaa_pcm_methods[] = {
6786 /* device interface */
6787 DEVMETHOD(device_probe, hdaa_pcm_probe),
6788 DEVMETHOD(device_attach, hdaa_pcm_attach),
6789 DEVMETHOD(device_detach, hdaa_pcm_detach),
6793 static driver_t hdaa_pcm_driver = {
6799 DRIVER_MODULE(snd_hda_pcm, hdaa, hdaa_pcm_driver, pcm_devclass, 0, 0);
6800 MODULE_DEPEND(snd_hda, sound, SOUND_MINVER, SOUND_PREFVER, SOUND_MAXVER);
6801 MODULE_VERSION(snd_hda, 1);