hdaa.c revision 243530
1230130Smav/*- 2230130Smav * Copyright (c) 2006 Stephane E. Potvin <sepotvin@videotron.ca> 3230130Smav * Copyright (c) 2006 Ariff Abdullah <ariff@FreeBSD.org> 4230130Smav * Copyright (c) 2008-2012 Alexander Motin <mav@FreeBSD.org> 5230130Smav * All rights reserved. 6230130Smav * 7230130Smav * Redistribution and use in source and binary forms, with or without 8230130Smav * modification, are permitted provided that the following conditions 9230130Smav * are met: 10230130Smav * 1. Redistributions of source code must retain the above copyright 11230130Smav * notice, this list of conditions and the following disclaimer. 12230130Smav * 2. Redistributions in binary form must reproduce the above copyright 13230130Smav * notice, this list of conditions and the following disclaimer in the 14230130Smav * documentation and/or other materials provided with the distribution. 15230130Smav * 16230130Smav * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17230130Smav * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18230130Smav * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19230130Smav * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20230130Smav * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21230130Smav * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22230130Smav * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23230130Smav * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24230130Smav * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25230130Smav * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26230130Smav * SUCH DAMAGE. 27230130Smav */ 28230130Smav 29230130Smav/* 30230130Smav * Intel High Definition Audio (Audio function) driver for FreeBSD. 31230130Smav */ 32230130Smav 33230130Smav#ifdef HAVE_KERNEL_OPTION_HEADERS 34230130Smav#include "opt_snd.h" 35230130Smav#endif 36230130Smav 37230130Smav#include <dev/sound/pcm/sound.h> 38230130Smav 39230130Smav#include <sys/ctype.h> 40230130Smav#include <sys/taskqueue.h> 41230130Smav 42230130Smav#include <dev/sound/pci/hda/hdac.h> 43230130Smav#include <dev/sound/pci/hda/hdaa.h> 44230130Smav#include <dev/sound/pci/hda/hda_reg.h> 45230130Smav 46230130Smav#include "mixer_if.h" 47230130Smav 48230130SmavSND_DECLARE_FILE("$FreeBSD: head/sys/dev/sound/pci/hda/hdaa.c 243530 2012-11-25 20:06:01Z mav $"); 49230130Smav 50230130Smav#define hdaa_lock(devinfo) snd_mtxlock((devinfo)->lock) 51230130Smav#define hdaa_unlock(devinfo) snd_mtxunlock((devinfo)->lock) 52230130Smav#define hdaa_lockassert(devinfo) snd_mtxassert((devinfo)->lock) 53230130Smav#define hdaa_lockowned(devinfo) mtx_owned((devinfo)->lock) 54230130Smav 55230130Smavstatic const struct { 56230130Smav char *key; 57230130Smav uint32_t value; 58230130Smav} hdaa_quirks_tab[] = { 59230130Smav { "softpcmvol", HDAA_QUIRK_SOFTPCMVOL }, 60230130Smav { "fixedrate", HDAA_QUIRK_FIXEDRATE }, 61230130Smav { "forcestereo", HDAA_QUIRK_FORCESTEREO }, 62230130Smav { "eapdinv", HDAA_QUIRK_EAPDINV }, 63230130Smav { "senseinv", HDAA_QUIRK_SENSEINV }, 64230130Smav { "ivref50", HDAA_QUIRK_IVREF50 }, 65230130Smav { "ivref80", HDAA_QUIRK_IVREF80 }, 66230130Smav { "ivref100", HDAA_QUIRK_IVREF100 }, 67230130Smav { "ovref50", HDAA_QUIRK_OVREF50 }, 68230130Smav { "ovref80", HDAA_QUIRK_OVREF80 }, 69230130Smav { "ovref100", HDAA_QUIRK_OVREF100 }, 70230130Smav { "ivref", HDAA_QUIRK_IVREF }, 71230130Smav { "ovref", HDAA_QUIRK_OVREF }, 72230130Smav { "vref", HDAA_QUIRK_VREF }, 73230130Smav}; 74230130Smav#define HDAA_QUIRKS_TAB_LEN \ 75230130Smav (sizeof(hdaa_quirks_tab) / sizeof(hdaa_quirks_tab[0])) 76230130Smav 77230130Smav#define HDA_PARSE_MAXDEPTH 10 78230130Smav 79230130SmavMALLOC_DEFINE(M_HDAA, "hdaa", "HDA Audio"); 80230130Smav 81230130Smavconst char *HDA_COLORS[16] = {"Unknown", "Black", "Grey", "Blue", "Green", "Red", 82230130Smav "Orange", "Yellow", "Purple", "Pink", "Res.A", "Res.B", "Res.C", "Res.D", 83230130Smav "White", "Other"}; 84230130Smav 85230130Smavconst char *HDA_DEVS[16] = {"Line-out", "Speaker", "Headphones", "CD", 86230130Smav "SPDIF-out", "Digital-out", "Modem-line", "Modem-handset", "Line-in", 87230130Smav "AUX", "Mic", "Telephony", "SPDIF-in", "Digital-in", "Res.E", "Other"}; 88230130Smav 89230130Smavconst char *HDA_CONNS[4] = {"Jack", "None", "Fixed", "Both"}; 90230130Smav 91230130Smavconst char *HDA_CONNECTORS[16] = { 92230130Smav "Unknown", "1/8", "1/4", "ATAPI", "RCA", "Optical", "Digital", "Analog", 93230130Smav "DIN", "XLR", "RJ-11", "Combo", "0xc", "0xd", "0xe", "Other" }; 94230130Smav 95230130Smavconst char *HDA_LOCS[64] = { 96230130Smav "0x00", "Rear", "Front", "Left", "Right", "Top", "Bottom", "Rear-panel", 97230130Smav "Drive-bay", "0x09", "0x0a", "0x0b", "0x0c", "0x0d", "0x0e", "0x0f", 98230130Smav "Internal", "0x11", "0x12", "0x13", "0x14", "0x15", "0x16", "Riser", 99230130Smav "0x18", "Onboard", "0x1a", "0x1b", "0x1c", "0x1d", "0x1e", "0x1f", 100230130Smav "External", "Ext-Rear", "Ext-Front", "Ext-Left", "Ext-Right", "Ext-Top", "Ext-Bottom", "0x07", 101230130Smav "0x28", "0x29", "0x2a", "0x2b", "0x2c", "0x2d", "0x2e", "0x2f", 102230130Smav "Other", "0x31", "0x32", "0x33", "0x34", "0x35", "Other-Bott", "Lid-In", 103230130Smav "Lid-Out", "0x39", "0x3a", "0x3b", "0x3c", "0x3d", "0x3e", "0x3f" }; 104230130Smav 105230130Smavconst char *HDA_GPIO_ACTIONS[8] = { 106230130Smav "keep", "set", "clear", "disable", "input", "0x05", "0x06", "0x07"}; 107230130Smav 108230312Smavconst char *HDA_HDMI_CODING_TYPES[18] = { 109230312Smav "undefined", "LPCM", "AC-3", "MPEG1", "MP3", "MPEG2", "AAC-LC", "DTS", 110230312Smav "ATRAC", "DSD", "E-AC-3", "DTS-HD", "MLP", "DST", "WMAPro", "HE-AAC", 111230312Smav "HE-AACv2", "MPEG-Surround" 112230312Smav}; 113230312Smav 114230130Smav/* Default */ 115230130Smavstatic uint32_t hdaa_fmt[] = { 116230130Smav SND_FORMAT(AFMT_S16_LE, 2, 0), 117230130Smav 0 118230130Smav}; 119230130Smav 120230130Smavstatic struct pcmchan_caps hdaa_caps = {48000, 48000, hdaa_fmt, 0}; 121230130Smav 122230130Smavstatic const struct { 123230130Smav uint32_t rate; 124230130Smav int valid; 125230130Smav uint16_t base; 126230130Smav uint16_t mul; 127230130Smav uint16_t div; 128230130Smav} hda_rate_tab[] = { 129230130Smav { 8000, 1, 0x0000, 0x0000, 0x0500 }, /* (48000 * 1) / 6 */ 130230130Smav { 9600, 0, 0x0000, 0x0000, 0x0400 }, /* (48000 * 1) / 5 */ 131230130Smav { 12000, 0, 0x0000, 0x0000, 0x0300 }, /* (48000 * 1) / 4 */ 132230130Smav { 16000, 1, 0x0000, 0x0000, 0x0200 }, /* (48000 * 1) / 3 */ 133230130Smav { 18000, 0, 0x0000, 0x1000, 0x0700 }, /* (48000 * 3) / 8 */ 134230130Smav { 19200, 0, 0x0000, 0x0800, 0x0400 }, /* (48000 * 2) / 5 */ 135230130Smav { 24000, 0, 0x0000, 0x0000, 0x0100 }, /* (48000 * 1) / 2 */ 136230130Smav { 28800, 0, 0x0000, 0x1000, 0x0400 }, /* (48000 * 3) / 5 */ 137230130Smav { 32000, 1, 0x0000, 0x0800, 0x0200 }, /* (48000 * 2) / 3 */ 138230130Smav { 36000, 0, 0x0000, 0x1000, 0x0300 }, /* (48000 * 3) / 4 */ 139230130Smav { 38400, 0, 0x0000, 0x1800, 0x0400 }, /* (48000 * 4) / 5 */ 140230130Smav { 48000, 1, 0x0000, 0x0000, 0x0000 }, /* (48000 * 1) / 1 */ 141230130Smav { 64000, 0, 0x0000, 0x1800, 0x0200 }, /* (48000 * 4) / 3 */ 142230130Smav { 72000, 0, 0x0000, 0x1000, 0x0100 }, /* (48000 * 3) / 2 */ 143230130Smav { 96000, 1, 0x0000, 0x0800, 0x0000 }, /* (48000 * 2) / 1 */ 144230130Smav { 144000, 0, 0x0000, 0x1000, 0x0000 }, /* (48000 * 3) / 1 */ 145230130Smav { 192000, 1, 0x0000, 0x1800, 0x0000 }, /* (48000 * 4) / 1 */ 146230130Smav { 8820, 0, 0x4000, 0x0000, 0x0400 }, /* (44100 * 1) / 5 */ 147230130Smav { 11025, 1, 0x4000, 0x0000, 0x0300 }, /* (44100 * 1) / 4 */ 148230130Smav { 12600, 0, 0x4000, 0x0800, 0x0600 }, /* (44100 * 2) / 7 */ 149230130Smav { 14700, 0, 0x4000, 0x0000, 0x0200 }, /* (44100 * 1) / 3 */ 150230130Smav { 17640, 0, 0x4000, 0x0800, 0x0400 }, /* (44100 * 2) / 5 */ 151230130Smav { 18900, 0, 0x4000, 0x1000, 0x0600 }, /* (44100 * 3) / 7 */ 152230130Smav { 22050, 1, 0x4000, 0x0000, 0x0100 }, /* (44100 * 1) / 2 */ 153230130Smav { 25200, 0, 0x4000, 0x1800, 0x0600 }, /* (44100 * 4) / 7 */ 154230130Smav { 26460, 0, 0x4000, 0x1000, 0x0400 }, /* (44100 * 3) / 5 */ 155230130Smav { 29400, 0, 0x4000, 0x0800, 0x0200 }, /* (44100 * 2) / 3 */ 156230130Smav { 33075, 0, 0x4000, 0x1000, 0x0300 }, /* (44100 * 3) / 4 */ 157230130Smav { 35280, 0, 0x4000, 0x1800, 0x0400 }, /* (44100 * 4) / 5 */ 158230130Smav { 44100, 1, 0x4000, 0x0000, 0x0000 }, /* (44100 * 1) / 1 */ 159230130Smav { 58800, 0, 0x4000, 0x1800, 0x0200 }, /* (44100 * 4) / 3 */ 160230130Smav { 66150, 0, 0x4000, 0x1000, 0x0100 }, /* (44100 * 3) / 2 */ 161230130Smav { 88200, 1, 0x4000, 0x0800, 0x0000 }, /* (44100 * 2) / 1 */ 162230130Smav { 132300, 0, 0x4000, 0x1000, 0x0000 }, /* (44100 * 3) / 1 */ 163230130Smav { 176400, 1, 0x4000, 0x1800, 0x0000 }, /* (44100 * 4) / 1 */ 164230130Smav}; 165230130Smav#define HDA_RATE_TAB_LEN (sizeof(hda_rate_tab) / sizeof(hda_rate_tab[0])) 166230130Smav 167230451Smavconst static char *ossnames[] = SOUND_DEVICE_NAMES; 168230451Smav 169230130Smav/**************************************************************************** 170230130Smav * Function prototypes 171230130Smav ****************************************************************************/ 172230130Smavstatic int hdaa_pcmchannel_setup(struct hdaa_chan *); 173230130Smav 174230130Smavstatic void hdaa_widget_connection_select(struct hdaa_widget *, uint8_t); 175230130Smavstatic void hdaa_audio_ctl_amp_set(struct hdaa_audio_ctl *, 176230130Smav uint32_t, int, int); 177230130Smavstatic struct hdaa_audio_ctl *hdaa_audio_ctl_amp_get(struct hdaa_devinfo *, 178230130Smav nid_t, int, int, int); 179230130Smavstatic void hdaa_audio_ctl_amp_set_internal(struct hdaa_devinfo *, 180230130Smav nid_t, int, int, int, int, int, int); 181230130Smav 182230130Smavstatic void hdaa_dump_pin_config(struct hdaa_widget *w, uint32_t conf); 183230130Smav 184230130Smavstatic char * 185230130Smavhdaa_audio_ctl_ossmixer_mask2allname(uint32_t mask, char *buf, size_t len) 186230130Smav{ 187230130Smav int i, first = 1; 188230130Smav 189230130Smav bzero(buf, len); 190230130Smav for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) { 191230130Smav if (mask & (1 << i)) { 192230130Smav if (first == 0) 193230130Smav strlcat(buf, ", ", len); 194230451Smav strlcat(buf, ossnames[i], len); 195230130Smav first = 0; 196230130Smav } 197230130Smav } 198230130Smav return (buf); 199230130Smav} 200230130Smav 201230130Smavstatic struct hdaa_audio_ctl * 202230130Smavhdaa_audio_ctl_each(struct hdaa_devinfo *devinfo, int *index) 203230130Smav{ 204230130Smav if (devinfo == NULL || 205230130Smav index == NULL || devinfo->ctl == NULL || 206230130Smav devinfo->ctlcnt < 1 || 207230130Smav *index < 0 || *index >= devinfo->ctlcnt) 208230130Smav return (NULL); 209230130Smav return (&devinfo->ctl[(*index)++]); 210230130Smav} 211230130Smav 212230130Smavstatic struct hdaa_audio_ctl * 213230130Smavhdaa_audio_ctl_amp_get(struct hdaa_devinfo *devinfo, nid_t nid, int dir, 214230130Smav int index, int cnt) 215230130Smav{ 216230130Smav struct hdaa_audio_ctl *ctl; 217230130Smav int i, found = 0; 218230130Smav 219230130Smav if (devinfo == NULL || devinfo->ctl == NULL) 220230130Smav return (NULL); 221230130Smav 222230130Smav i = 0; 223230130Smav while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) { 224230130Smav if (ctl->enable == 0) 225230130Smav continue; 226230130Smav if (ctl->widget->nid != nid) 227230130Smav continue; 228230130Smav if (dir && ctl->ndir != dir) 229230130Smav continue; 230230130Smav if (index >= 0 && ctl->ndir == HDAA_CTL_IN && 231230130Smav ctl->dir == ctl->ndir && ctl->index != index) 232230130Smav continue; 233230130Smav found++; 234230130Smav if (found == cnt || cnt <= 0) 235230130Smav return (ctl); 236230130Smav } 237230130Smav 238230130Smav return (NULL); 239230130Smav} 240230130Smav 241243181Smavstatic const struct matrix { 242243181Smav struct pcmchan_matrix m; 243243181Smav int analog; 244243181Smav} matrixes[] = { 245243181Smav { SND_CHN_MATRIX_MAP_1_0, 1 }, 246243181Smav { SND_CHN_MATRIX_MAP_2_0, 1 }, 247243181Smav { SND_CHN_MATRIX_MAP_2_1, 0 }, 248243181Smav { SND_CHN_MATRIX_MAP_3_0, 0 }, 249243181Smav { SND_CHN_MATRIX_MAP_3_1, 0 }, 250243181Smav { SND_CHN_MATRIX_MAP_4_0, 1 }, 251243181Smav { SND_CHN_MATRIX_MAP_4_1, 0 }, 252243181Smav { SND_CHN_MATRIX_MAP_5_0, 0 }, 253243181Smav { SND_CHN_MATRIX_MAP_5_1, 1 }, 254243181Smav { SND_CHN_MATRIX_MAP_6_0, 0 }, 255243181Smav { SND_CHN_MATRIX_MAP_6_1, 0 }, 256243181Smav { SND_CHN_MATRIX_MAP_7_0, 0 }, 257243181Smav { SND_CHN_MATRIX_MAP_7_1, 1 }, 258243181Smav}; 259243181Smav 260243181Smavstatic const char *channel_names[] = SND_CHN_T_NAMES; 261243181Smav 262230130Smav/* 263243181Smav * Connected channels change handler. 264243181Smav */ 265243181Smavstatic void 266243181Smavhdaa_channels_handler(struct hdaa_audio_as *as) 267243181Smav{ 268243181Smav struct hdaa_pcm_devinfo *pdevinfo = as->pdevinfo; 269243181Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 270243181Smav struct hdaa_chan *ch = &devinfo->chans[as->chans[0]]; 271243181Smav struct hdaa_widget *w; 272243181Smav uint8_t *eld; 273243181Smav int i, total, sub, assume, channels; 274243181Smav uint16_t cpins, upins, tpins; 275243181Smav 276243181Smav cpins = upins = 0; 277243181Smav eld = NULL; 278243181Smav for (i = 0; i < 16; i++) { 279243181Smav if (as->pins[i] <= 0) 280243181Smav continue; 281243181Smav w = hdaa_widget_get(devinfo, as->pins[i]); 282243181Smav if (w == NULL) 283243181Smav continue; 284243181Smav if (w->wclass.pin.connected == 1) 285243181Smav cpins |= (1 << i); 286243181Smav else if (w->wclass.pin.connected != 0) 287243181Smav upins |= (1 << i); 288243181Smav if (w->eld != NULL && w->eld_len >= 8) 289243181Smav eld = w->eld; 290243181Smav } 291243181Smav tpins = cpins | upins; 292243181Smav if (as->hpredir >= 0) 293243181Smav tpins &= 0x7fff; 294243181Smav if (tpins == 0) 295243181Smav tpins = as->pinset; 296243181Smav 297243181Smav total = sub = assume = channels = 0; 298243181Smav if (eld) { 299243181Smav /* Map CEA speakers to sound(4) channels. */ 300243181Smav if (eld[7] & 0x01) /* Front Left/Right */ 301243181Smav channels |= SND_CHN_T_MASK_FL | SND_CHN_T_MASK_FR; 302243181Smav if (eld[7] & 0x02) /* Low Frequency Effect */ 303243181Smav channels |= SND_CHN_T_MASK_LF; 304243181Smav if (eld[7] & 0x04) /* Front Center */ 305243181Smav channels |= SND_CHN_T_MASK_FC; 306243181Smav if (eld[7] & 0x08) { /* Rear Left/Right */ 307243181Smav /* If we have both RLR and RLRC, report RLR as side. */ 308243181Smav if (eld[7] & 0x40) /* Rear Left/Right Center */ 309243181Smav channels |= SND_CHN_T_MASK_SL | SND_CHN_T_MASK_SR; 310243181Smav else 311243181Smav channels |= SND_CHN_T_MASK_BL | SND_CHN_T_MASK_BR; 312243181Smav } 313243181Smav if (eld[7] & 0x10) /* Rear center */ 314243181Smav channels |= SND_CHN_T_MASK_BC; 315243181Smav if (eld[7] & 0x20) /* Front Left/Right Center */ 316243181Smav channels |= SND_CHN_T_MASK_FLC | SND_CHN_T_MASK_FRC; 317243181Smav if (eld[7] & 0x40) /* Rear Left/Right Center */ 318243181Smav channels |= SND_CHN_T_MASK_BL | SND_CHN_T_MASK_BR; 319243181Smav } else if (as->pinset != 0 && (tpins & 0xffe0) == 0) { 320243181Smav /* Map UAA speakers to sound(4) channels. */ 321243181Smav if (tpins & 0x0001) 322243181Smav channels |= SND_CHN_T_MASK_FL | SND_CHN_T_MASK_FR; 323243181Smav if (tpins & 0x0002) 324243181Smav channels |= SND_CHN_T_MASK_FC | SND_CHN_T_MASK_LF; 325243181Smav if (tpins & 0x0004) 326243181Smav channels |= SND_CHN_T_MASK_BL | SND_CHN_T_MASK_BR; 327243181Smav if (tpins & 0x0008) 328243181Smav channels |= SND_CHN_T_MASK_FLC | SND_CHN_T_MASK_FRC; 329243181Smav if (tpins & 0x0010) { 330243181Smav /* If there is no back pin, report side as back. */ 331243181Smav if ((as->pinset & 0x0004) == 0) 332243181Smav channels |= SND_CHN_T_MASK_BL | SND_CHN_T_MASK_BR; 333243181Smav else 334243181Smav channels |= SND_CHN_T_MASK_SL | SND_CHN_T_MASK_SR; 335243181Smav } 336243181Smav } else if (as->mixed) { 337243181Smav /* Mixed assoc can be only stereo or theoretically mono. */ 338243181Smav if (ch->channels == 1) 339243181Smav channels |= SND_CHN_T_MASK_FC; 340243181Smav else 341243181Smav channels |= SND_CHN_T_MASK_FL | SND_CHN_T_MASK_FR; 342243181Smav } 343243181Smav if (channels) { /* We have some usable channels info. */ 344243181Smav HDA_BOOTVERBOSE( 345243181Smav device_printf(pdevinfo->dev, "%s channel set is: ", 346243181Smav as->dir == HDAA_CTL_OUT ? "Playback" : "Recording"); 347243181Smav for (i = 0; i < SND_CHN_T_MAX; i++) 348243181Smav if (channels & (1 << i)) 349243181Smav printf("%s, ", channel_names[i]); 350243181Smav printf("\n"); 351243181Smav ); 352243181Smav /* Look for maximal fitting matrix. */ 353243181Smav for (i = 0; i < sizeof(matrixes) / sizeof(struct matrix); i++) { 354243181Smav if (as->pinset != 0 && matrixes[i].analog == 0) 355243181Smav continue; 356243181Smav if ((matrixes[i].m.mask & ~channels) == 0) { 357243181Smav total = matrixes[i].m.channels; 358243181Smav sub = matrixes[i].m.ext; 359243181Smav } 360243181Smav } 361243181Smav } 362243181Smav if (total == 0) { 363243181Smav assume = 1; 364243181Smav total = ch->channels; 365243181Smav sub = (total == 6 || total == 8) ? 1 : 0; 366243181Smav } 367243181Smav HDA_BOOTVERBOSE( 368243181Smav device_printf(pdevinfo->dev, 369243181Smav "%s channel matrix is: %s%d.%d (%s)\n", 370243181Smav as->dir == HDAA_CTL_OUT ? "Playback" : "Recording", 371243181Smav assume ? "unknown, assuming " : "", total - sub, sub, 372243181Smav cpins != 0 ? "connected" : 373243181Smav (upins != 0 ? "unknown" : "disconnected")); 374243181Smav ); 375243181Smav} 376243181Smav 377243181Smav/* 378230551Smav * Headphones redirection change handler. 379230130Smav */ 380230130Smavstatic void 381230551Smavhdaa_hpredir_handler(struct hdaa_widget *w) 382230130Smav{ 383230312Smav struct hdaa_devinfo *devinfo = w->devinfo; 384230551Smav struct hdaa_audio_as *as = &devinfo->as[w->bindas]; 385230312Smav struct hdaa_widget *w1; 386230130Smav struct hdaa_audio_ctl *ctl; 387230551Smav uint32_t val; 388230551Smav int j, connected = w->wclass.pin.connected; 389230130Smav 390230130Smav HDA_BOOTVERBOSE( 391230551Smav device_printf((as->pdevinfo && as->pdevinfo->dev) ? 392230551Smav as->pdevinfo->dev : devinfo->dev, 393230551Smav "Redirect output to: %s\n", 394230551Smav connected ? "headphones": "main"); 395230130Smav ); 396230130Smav /* (Un)Mute headphone pin. */ 397230130Smav ctl = hdaa_audio_ctl_amp_get(devinfo, 398230312Smav w->nid, HDAA_CTL_IN, -1, 1); 399230130Smav if (ctl != NULL && ctl->mute) { 400230130Smav /* If pin has muter - use it. */ 401230551Smav val = connected ? 0 : 1; 402230130Smav if (val != ctl->forcemute) { 403230130Smav ctl->forcemute = val; 404230130Smav hdaa_audio_ctl_amp_set(ctl, 405230130Smav HDAA_AMP_MUTE_DEFAULT, 406230130Smav HDAA_AMP_VOL_DEFAULT, HDAA_AMP_VOL_DEFAULT); 407230130Smav } 408230130Smav } else { 409230130Smav /* If there is no muter - disable pin output. */ 410230551Smav if (connected) 411230312Smav val = w->wclass.pin.ctrl | 412230312Smav HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE; 413230312Smav else 414230312Smav val = w->wclass.pin.ctrl & 415230312Smav ~HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE; 416230312Smav if (val != w->wclass.pin.ctrl) { 417230312Smav w->wclass.pin.ctrl = val; 418230312Smav hda_command(devinfo->dev, 419230312Smav HDA_CMD_SET_PIN_WIDGET_CTRL(0, 420230312Smav w->nid, w->wclass.pin.ctrl)); 421230130Smav } 422230130Smav } 423230130Smav /* (Un)Mute other pins. */ 424230130Smav for (j = 0; j < 15; j++) { 425230130Smav if (as->pins[j] <= 0) 426230130Smav continue; 427230130Smav ctl = hdaa_audio_ctl_amp_get(devinfo, 428230130Smav as->pins[j], HDAA_CTL_IN, -1, 1); 429230130Smav if (ctl != NULL && ctl->mute) { 430230130Smav /* If pin has muter - use it. */ 431230551Smav val = connected ? 1 : 0; 432230130Smav if (val == ctl->forcemute) 433230130Smav continue; 434230130Smav ctl->forcemute = val; 435230130Smav hdaa_audio_ctl_amp_set(ctl, 436230130Smav HDAA_AMP_MUTE_DEFAULT, 437230130Smav HDAA_AMP_VOL_DEFAULT, HDAA_AMP_VOL_DEFAULT); 438230130Smav continue; 439230130Smav } 440230130Smav /* If there is no muter - disable pin output. */ 441230312Smav w1 = hdaa_widget_get(devinfo, as->pins[j]); 442230551Smav if (w1 != NULL) { 443230551Smav if (connected) 444230312Smav val = w1->wclass.pin.ctrl & 445230130Smav ~HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE; 446230130Smav else 447230312Smav val = w1->wclass.pin.ctrl | 448230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE; 449230312Smav if (val != w1->wclass.pin.ctrl) { 450230312Smav w1->wclass.pin.ctrl = val; 451230130Smav hda_command(devinfo->dev, 452230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL(0, 453230312Smav w1->nid, w1->wclass.pin.ctrl)); 454230130Smav } 455230130Smav } 456230130Smav } 457230130Smav} 458230130Smav 459230130Smav/* 460230551Smav * Recording source change handler. 461230130Smav */ 462230130Smavstatic void 463230551Smavhdaa_autorecsrc_handler(struct hdaa_audio_as *as, struct hdaa_widget *w) 464230130Smav{ 465230551Smav struct hdaa_pcm_devinfo *pdevinfo = as->pdevinfo; 466230551Smav struct hdaa_devinfo *devinfo; 467230551Smav struct hdaa_widget *w1; 468230551Smav int i, mask, fullmask, prio, bestprio; 469230551Smav char buf[128]; 470230130Smav 471230551Smav if (!as->mixed || pdevinfo == NULL || pdevinfo->mixer == NULL) 472230130Smav return; 473230551Smav /* Don't touch anything if we asked not to. */ 474230551Smav if (pdevinfo->autorecsrc == 0 || 475230551Smav (pdevinfo->autorecsrc == 1 && w != NULL)) 476230551Smav return; 477230551Smav /* Don't touch anything if "mix" or "speaker" selected. */ 478230551Smav if (pdevinfo->recsrc & (SOUND_MASK_IMIX | SOUND_MASK_SPEAKER)) 479230551Smav return; 480230551Smav /* Don't touch anything if several selected. */ 481230551Smav if (ffs(pdevinfo->recsrc) != fls(pdevinfo->recsrc)) 482230551Smav return; 483230551Smav devinfo = pdevinfo->devinfo; 484230551Smav mask = fullmask = 0; 485230551Smav bestprio = 0; 486230551Smav for (i = 0; i < 16; i++) { 487230551Smav if (as->pins[i] <= 0) 488230130Smav continue; 489230551Smav w1 = hdaa_widget_get(devinfo, as->pins[i]); 490230551Smav if (w1 == NULL || w1->enable == 0) 491230312Smav continue; 492230551Smav if (w1->wclass.pin.connected == 0) 493230551Smav continue; 494230551Smav prio = (w1->wclass.pin.connected == 1) ? 2 : 1; 495230551Smav if (prio < bestprio) 496230551Smav continue; 497230551Smav if (prio > bestprio) { 498230551Smav mask = 0; 499230551Smav bestprio = prio; 500230551Smav } 501230551Smav mask |= (1 << w1->ossdev); 502230551Smav fullmask |= (1 << w1->ossdev); 503230130Smav } 504230551Smav if (mask == 0) 505230551Smav return; 506230551Smav /* Prefer newly connected input. */ 507230551Smav if (w != NULL && (mask & (1 << w->ossdev))) 508230551Smav mask = (1 << w->ossdev); 509230551Smav /* Prefer previously selected input */ 510230551Smav if (mask & pdevinfo->recsrc) 511230551Smav mask &= pdevinfo->recsrc; 512230551Smav /* Prefer mic. */ 513230551Smav if (mask & SOUND_MASK_MIC) 514230551Smav mask = SOUND_MASK_MIC; 515230551Smav /* Prefer monitor (2nd mic). */ 516230551Smav if (mask & SOUND_MASK_MONITOR) 517230551Smav mask = SOUND_MASK_MONITOR; 518230551Smav /* Just take first one. */ 519230551Smav mask = (1 << (ffs(mask) - 1)); 520230551Smav HDA_BOOTVERBOSE( 521230551Smav hdaa_audio_ctl_ossmixer_mask2allname(mask, buf, sizeof(buf)); 522230551Smav device_printf(pdevinfo->dev, 523230551Smav "Automatically set rec source to: %s\n", buf); 524230551Smav ); 525230130Smav hdaa_unlock(devinfo); 526230551Smav mix_setrecsrc(pdevinfo->mixer, mask); 527230551Smav hdaa_lock(devinfo); 528230130Smav} 529230130Smav 530230130Smav/* 531230551Smav * Jack presence detection event handler. 532230130Smav */ 533230130Smavstatic void 534230551Smavhdaa_presence_handler(struct hdaa_widget *w) 535230130Smav{ 536230551Smav struct hdaa_devinfo *devinfo = w->devinfo; 537230551Smav struct hdaa_audio_as *as; 538230551Smav uint32_t res; 539242357Smav int connected, old; 540230130Smav 541230551Smav if (w->enable == 0 || w->type != 542230551Smav HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 543230551Smav return; 544230130Smav 545230551Smav if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(w->wclass.pin.cap) == 0 || 546230551Smav (HDA_CONFIG_DEFAULTCONF_MISC(w->wclass.pin.config) & 1) != 0) 547230551Smav return; 548230551Smav 549230551Smav res = hda_command(devinfo->dev, HDA_CMD_GET_PIN_SENSE(0, w->nid)); 550230551Smav connected = (res & HDA_CMD_GET_PIN_SENSE_PRESENCE_DETECT) != 0; 551230551Smav if (devinfo->quirks & HDAA_QUIRK_SENSEINV) 552230551Smav connected = !connected; 553242357Smav old = w->wclass.pin.connected; 554242357Smav if (connected == old) 555230551Smav return; 556230551Smav w->wclass.pin.connected = connected; 557230551Smav HDA_BOOTVERBOSE( 558242357Smav if (connected || old != 2) { 559242357Smav device_printf(devinfo->dev, 560242357Smav "Pin sense: nid=%d sence=0x%08x (%sconnected)\n", 561242357Smav w->nid, res, !connected ? "dis" : ""); 562242357Smav } 563230551Smav ); 564230551Smav 565230551Smav as = &devinfo->as[w->bindas]; 566230551Smav if (as->hpredir >= 0 && as->pins[15] == w->nid) 567230551Smav hdaa_hpredir_handler(w); 568242357Smav if (as->dir == HDAA_CTL_IN && old != 2) 569230551Smav hdaa_autorecsrc_handler(as, w); 570243181Smav if (old != 2) 571243181Smav hdaa_channels_handler(as); 572230130Smav} 573230130Smav 574230551Smav/* 575230551Smav * Callback for poll based presence detection. 576230551Smav */ 577230130Smavstatic void 578230551Smavhdaa_jack_poll_callback(void *arg) 579230130Smav{ 580230551Smav struct hdaa_devinfo *devinfo = arg; 581230551Smav struct hdaa_widget *w; 582230551Smav int i; 583230130Smav 584230551Smav hdaa_lock(devinfo); 585230551Smav if (devinfo->poll_ival == 0) { 586230551Smav hdaa_unlock(devinfo); 587230551Smav return; 588230551Smav } 589230130Smav for (i = 0; i < devinfo->ascnt; i++) { 590230551Smav if (devinfo->as[i].hpredir < 0) 591230551Smav continue; 592230551Smav w = hdaa_widget_get(devinfo, devinfo->as[i].pins[15]); 593230130Smav if (w == NULL || w->enable == 0 || w->type != 594230130Smav HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 595230130Smav continue; 596230551Smav hdaa_presence_handler(w); 597230130Smav } 598230551Smav callout_reset(&devinfo->poll_jack, devinfo->poll_ival, 599230551Smav hdaa_jack_poll_callback, devinfo); 600230551Smav hdaa_unlock(devinfo); 601230130Smav} 602230130Smav 603230312Smavstatic void 604230312Smavhdaa_eld_dump(struct hdaa_widget *w) 605230312Smav{ 606230312Smav struct hdaa_devinfo *devinfo = w->devinfo; 607230312Smav device_t dev = devinfo->dev; 608230312Smav uint8_t *sad; 609230312Smav int len, mnl, i, sadc, fmt; 610230312Smav 611230312Smav if (w->eld == NULL || w->eld_len < 4) 612230312Smav return; 613230312Smav device_printf(dev, 614230312Smav "ELD nid=%d: ELD_Ver=%u Baseline_ELD_Len=%u\n", 615230312Smav w->nid, w->eld[0] >> 3, w->eld[2]); 616230312Smav if ((w->eld[0] >> 3) != 0x02) 617230312Smav return; 618230312Smav len = min(w->eld_len, (u_int)w->eld[2] * 4); 619230312Smav mnl = w->eld[4] & 0x1f; 620230312Smav device_printf(dev, 621230312Smav "ELD nid=%d: CEA_EDID_Ver=%u MNL=%u\n", 622230312Smav w->nid, w->eld[4] >> 5, mnl); 623230312Smav sadc = w->eld[5] >> 4; 624230312Smav device_printf(dev, 625230312Smav "ELD nid=%d: SAD_Count=%u Conn_Type=%u S_AI=%u HDCP=%u\n", 626230312Smav w->nid, sadc, (w->eld[5] >> 2) & 0x3, 627230312Smav (w->eld[5] >> 1) & 0x1, w->eld[5] & 0x1); 628230312Smav device_printf(dev, 629230312Smav "ELD nid=%d: Aud_Synch_Delay=%ums\n", 630230312Smav w->nid, w->eld[6] * 2); 631230312Smav device_printf(dev, 632230312Smav "ELD nid=%d: Channels=0x%b\n", 633230312Smav w->nid, w->eld[7], 634230312Smav "\020\07RLRC\06FLRC\05RC\04RLR\03FC\02LFE\01FLR"); 635230312Smav device_printf(dev, 636230312Smav "ELD nid=%d: Port_ID=0x%02x%02x%02x%02x%02x%02x%02x%02x\n", 637230312Smav w->nid, w->eld[8], w->eld[9], w->eld[10], w->eld[11], 638230312Smav w->eld[12], w->eld[13], w->eld[14], w->eld[15]); 639230312Smav device_printf(dev, 640230312Smav "ELD nid=%d: Manufacturer_Name=0x%02x%02x\n", 641230312Smav w->nid, w->eld[16], w->eld[17]); 642230312Smav device_printf(dev, 643230312Smav "ELD nid=%d: Product_Code=0x%02x%02x\n", 644230312Smav w->nid, w->eld[18], w->eld[19]); 645230312Smav device_printf(dev, 646230312Smav "ELD nid=%d: Monitor_Name_String='%.*s'\n", 647230312Smav w->nid, mnl, &w->eld[20]); 648230312Smav for (i = 0; i < sadc; i++) { 649230312Smav sad = &w->eld[20 + mnl + i * 3]; 650230312Smav fmt = (sad[0] >> 3) & 0x0f; 651230312Smav if (fmt == HDA_HDMI_CODING_TYPE_REF_CTX) { 652230312Smav fmt = (sad[2] >> 3) & 0x1f; 653230312Smav if (fmt < 1 || fmt > 3) 654230312Smav fmt = 0; 655230312Smav else 656230312Smav fmt += 14; 657230312Smav } 658230312Smav device_printf(dev, 659230312Smav "ELD nid=%d: %s %dch freqs=0x%b", 660230312Smav w->nid, HDA_HDMI_CODING_TYPES[fmt], (sad[0] & 0x07) + 1, 661230312Smav sad[1], "\020\007192\006176\00596\00488\00348\00244\00132"); 662230312Smav switch (fmt) { 663230312Smav case HDA_HDMI_CODING_TYPE_LPCM: 664230312Smav printf(" sizes=0x%b", 665230312Smav sad[2] & 0x07, "\020\00324\00220\00116"); 666230312Smav break; 667230312Smav case HDA_HDMI_CODING_TYPE_AC3: 668230312Smav case HDA_HDMI_CODING_TYPE_MPEG1: 669230312Smav case HDA_HDMI_CODING_TYPE_MP3: 670230312Smav case HDA_HDMI_CODING_TYPE_MPEG2: 671230312Smav case HDA_HDMI_CODING_TYPE_AACLC: 672230312Smav case HDA_HDMI_CODING_TYPE_DTS: 673230312Smav case HDA_HDMI_CODING_TYPE_ATRAC: 674230312Smav printf(" max_bitrate=%d", sad[2] * 8000); 675230312Smav break; 676230312Smav case HDA_HDMI_CODING_TYPE_WMAPRO: 677230312Smav printf(" profile=%d", sad[2] & 0x07); 678230312Smav break; 679230312Smav } 680230312Smav printf("\n"); 681230312Smav } 682230312Smav} 683230312Smav 684230312Smavstatic void 685230312Smavhdaa_eld_handler(struct hdaa_widget *w) 686230312Smav{ 687230312Smav struct hdaa_devinfo *devinfo = w->devinfo; 688230312Smav uint32_t res; 689230312Smav int i; 690230312Smav 691230312Smav if (w->enable == 0 || w->type != 692230312Smav HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 693230312Smav return; 694230312Smav 695230551Smav if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(w->wclass.pin.cap) == 0 || 696230551Smav (HDA_CONFIG_DEFAULTCONF_MISC(w->wclass.pin.config) & 1) != 0) 697230551Smav return; 698230551Smav 699230551Smav res = hda_command(devinfo->dev, HDA_CMD_GET_PIN_SENSE(0, w->nid)); 700230551Smav if ((w->eld != 0) == ((res & HDA_CMD_GET_PIN_SENSE_ELD_VALID) != 0)) 701230551Smav return; 702230312Smav if (w->eld != NULL) { 703230312Smav w->eld_len = 0; 704230312Smav free(w->eld, M_HDAA); 705230312Smav w->eld = NULL; 706230312Smav } 707230312Smav HDA_BOOTVERBOSE( 708230312Smav device_printf(devinfo->dev, 709230312Smav "Pin sense: nid=%d sence=0x%08x " 710230312Smav "(%sconnected, ELD %svalid)\n", 711230312Smav w->nid, res, 712230312Smav (res & HDA_CMD_GET_PIN_SENSE_PRESENCE_DETECT) ? "" : "dis", 713230312Smav (res & HDA_CMD_GET_PIN_SENSE_ELD_VALID) ? "" : "in"); 714230312Smav ); 715230312Smav if ((res & HDA_CMD_GET_PIN_SENSE_ELD_VALID) == 0) 716230312Smav return; 717230312Smav 718230312Smav res = hda_command(devinfo->dev, 719230312Smav HDA_CMD_GET_HDMI_DIP_SIZE(0, w->nid, 0x08)); 720230312Smav if (res == HDA_INVALID) 721230312Smav return; 722230312Smav w->eld_len = res & 0xff; 723230312Smav if (w->eld_len != 0) 724230312Smav w->eld = malloc(w->eld_len, M_HDAA, M_ZERO | M_NOWAIT); 725230312Smav if (w->eld == NULL) { 726230312Smav w->eld_len = 0; 727230312Smav return; 728230312Smav } 729230312Smav 730230312Smav for (i = 0; i < w->eld_len; i++) { 731230312Smav res = hda_command(devinfo->dev, 732230312Smav HDA_CMD_GET_HDMI_ELDD(0, w->nid, i)); 733230312Smav if (res & 0x80000000) 734230312Smav w->eld[i] = res & 0xff; 735230312Smav } 736230312Smav HDA_BOOTVERBOSE( 737230312Smav hdaa_eld_dump(w); 738230312Smav ); 739243181Smav hdaa_channels_handler(&devinfo->as[w->bindas]); 740230312Smav} 741230312Smav 742230551Smav/* 743230551Smav * Pin sense initializer. 744230551Smav */ 745230312Smavstatic void 746230551Smavhdaa_sense_init(struct hdaa_devinfo *devinfo) 747230312Smav{ 748230551Smav struct hdaa_audio_as *as; 749230551Smav struct hdaa_widget *w; 750230551Smav int i, poll = 0; 751230312Smav 752230312Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 753230312Smav w = hdaa_widget_get(devinfo, i); 754230551Smav if (w == NULL || w->enable == 0 || w->type != 755230312Smav HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 756230312Smav continue; 757233692Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_UNSOL_CAP(w->param.widget_cap)) { 758233692Smav if (w->unsol < 0) 759233692Smav w->unsol = HDAC_UNSOL_ALLOC( 760233692Smav device_get_parent(devinfo->dev), 761233692Smav devinfo->dev, w->nid); 762230312Smav hda_command(devinfo->dev, 763230312Smav HDA_CMD_SET_UNSOLICITED_RESPONSE(0, w->nid, 764230551Smav HDA_CMD_SET_UNSOLICITED_RESPONSE_ENABLE | w->unsol)); 765230312Smav } 766230551Smav as = &devinfo->as[w->bindas]; 767230551Smav if (as->hpredir >= 0 && as->pins[15] == w->nid) { 768230551Smav if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(w->wclass.pin.cap) == 0 || 769230551Smav (HDA_CONFIG_DEFAULTCONF_MISC(w->wclass.pin.config) & 1) != 0) { 770230551Smav device_printf(devinfo->dev, 771230551Smav "No presence detection support at nid %d\n", 772240884Smav w->nid); 773230551Smav } else { 774230551Smav if (w->unsol < 0) 775230551Smav poll = 1; 776230551Smav HDA_BOOTVERBOSE( 777230551Smav device_printf(devinfo->dev, 778230551Smav "Headphones redirection for " 779230551Smav "association %d nid=%d using %s.\n", 780230551Smav w->bindas, w->nid, 781240884Smav (w->unsol < 0) ? "polling" : 782230551Smav "unsolicited responses"); 783230551Smav ); 784230551Smav }; 785230551Smav } 786230551Smav hdaa_presence_handler(w); 787230551Smav if (!HDA_PARAM_PIN_CAP_DP(w->wclass.pin.cap) && 788230551Smav !HDA_PARAM_PIN_CAP_HDMI(w->wclass.pin.cap)) 789230551Smav continue; 790230312Smav hdaa_eld_handler(w); 791230312Smav } 792230551Smav if (poll) { 793230551Smav callout_reset(&devinfo->poll_jack, 1, 794230551Smav hdaa_jack_poll_callback, devinfo); 795230551Smav } 796230312Smav} 797230312Smav 798230312Smavstatic void 799230551Smavhdaa_sense_deinit(struct hdaa_devinfo *devinfo) 800230312Smav{ 801230312Smav struct hdaa_widget *w; 802230312Smav int i; 803230312Smav 804230551Smav callout_stop(&devinfo->poll_jack); 805230312Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 806230312Smav w = hdaa_widget_get(devinfo, i); 807230551Smav if (w == NULL || w->enable == 0 || w->type != 808230312Smav HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 809230312Smav continue; 810230312Smav if (w->unsol < 0) 811230312Smav continue; 812230312Smav hda_command(devinfo->dev, 813230312Smav HDA_CMD_SET_UNSOLICITED_RESPONSE(0, w->nid, 0)); 814230312Smav HDAC_UNSOL_FREE( 815230312Smav device_get_parent(devinfo->dev), devinfo->dev, 816230312Smav w->unsol); 817230312Smav w->unsol = -1; 818230312Smav } 819230312Smav} 820230312Smav 821230130Smavuint32_t 822230130Smavhdaa_widget_pin_patch(uint32_t config, const char *str) 823230130Smav{ 824230130Smav char buf[256]; 825230130Smav char *key, *value, *rest, *bad; 826230130Smav int ival, i; 827230130Smav 828230130Smav strlcpy(buf, str, sizeof(buf)); 829230130Smav rest = buf; 830230130Smav while ((key = strsep(&rest, "=")) != NULL) { 831230130Smav value = strsep(&rest, " \t"); 832230130Smav if (value == NULL) 833230130Smav break; 834230130Smav ival = strtol(value, &bad, 10); 835230130Smav if (strcmp(key, "seq") == 0) { 836230130Smav config &= ~HDA_CONFIG_DEFAULTCONF_SEQUENCE_MASK; 837230130Smav config |= ((ival << HDA_CONFIG_DEFAULTCONF_SEQUENCE_SHIFT) & 838230130Smav HDA_CONFIG_DEFAULTCONF_SEQUENCE_MASK); 839230130Smav } else if (strcmp(key, "as") == 0) { 840230130Smav config &= ~HDA_CONFIG_DEFAULTCONF_ASSOCIATION_MASK; 841230130Smav config |= ((ival << HDA_CONFIG_DEFAULTCONF_ASSOCIATION_SHIFT) & 842230130Smav HDA_CONFIG_DEFAULTCONF_ASSOCIATION_MASK); 843230130Smav } else if (strcmp(key, "misc") == 0) { 844230130Smav config &= ~HDA_CONFIG_DEFAULTCONF_MISC_MASK; 845230130Smav config |= ((ival << HDA_CONFIG_DEFAULTCONF_MISC_SHIFT) & 846230130Smav HDA_CONFIG_DEFAULTCONF_MISC_MASK); 847230130Smav } else if (strcmp(key, "color") == 0) { 848230130Smav config &= ~HDA_CONFIG_DEFAULTCONF_COLOR_MASK; 849230130Smav if (bad[0] == 0) { 850230130Smav config |= ((ival << HDA_CONFIG_DEFAULTCONF_COLOR_SHIFT) & 851230130Smav HDA_CONFIG_DEFAULTCONF_COLOR_MASK); 852230130Smav }; 853230130Smav for (i = 0; i < 16; i++) { 854230130Smav if (strcasecmp(HDA_COLORS[i], value) == 0) { 855230130Smav config |= (i << HDA_CONFIG_DEFAULTCONF_COLOR_SHIFT); 856230130Smav break; 857230130Smav } 858230130Smav } 859230130Smav } else if (strcmp(key, "ctype") == 0) { 860230130Smav config &= ~HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_MASK; 861230130Smav if (bad[0] == 0) { 862230130Smav config |= ((ival << HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_SHIFT) & 863230130Smav HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_MASK); 864230130Smav } 865230130Smav for (i = 0; i < 16; i++) { 866230130Smav if (strcasecmp(HDA_CONNECTORS[i], value) == 0) { 867230130Smav config |= (i << HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_SHIFT); 868230130Smav break; 869230130Smav } 870230130Smav } 871230130Smav } else if (strcmp(key, "device") == 0) { 872230130Smav config &= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK; 873230130Smav if (bad[0] == 0) { 874230130Smav config |= ((ival << HDA_CONFIG_DEFAULTCONF_DEVICE_SHIFT) & 875230130Smav HDA_CONFIG_DEFAULTCONF_DEVICE_MASK); 876230130Smav continue; 877230130Smav }; 878230130Smav for (i = 0; i < 16; i++) { 879230130Smav if (strcasecmp(HDA_DEVS[i], value) == 0) { 880230130Smav config |= (i << HDA_CONFIG_DEFAULTCONF_DEVICE_SHIFT); 881230130Smav break; 882230130Smav } 883230130Smav } 884230130Smav } else if (strcmp(key, "loc") == 0) { 885230130Smav config &= ~HDA_CONFIG_DEFAULTCONF_LOCATION_MASK; 886230130Smav if (bad[0] == 0) { 887230130Smav config |= ((ival << HDA_CONFIG_DEFAULTCONF_LOCATION_SHIFT) & 888230130Smav HDA_CONFIG_DEFAULTCONF_LOCATION_MASK); 889230130Smav continue; 890230130Smav } 891230130Smav for (i = 0; i < 64; i++) { 892230130Smav if (strcasecmp(HDA_LOCS[i], value) == 0) { 893230130Smav config |= (i << HDA_CONFIG_DEFAULTCONF_LOCATION_SHIFT); 894230130Smav break; 895230130Smav } 896230130Smav } 897230130Smav } else if (strcmp(key, "conn") == 0) { 898230130Smav config &= ~HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK; 899230130Smav if (bad[0] == 0) { 900230130Smav config |= ((ival << HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_SHIFT) & 901230130Smav HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK); 902230130Smav continue; 903230130Smav }; 904230130Smav for (i = 0; i < 4; i++) { 905230130Smav if (strcasecmp(HDA_CONNS[i], value) == 0) { 906230130Smav config |= (i << HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_SHIFT); 907230130Smav break; 908230130Smav } 909230130Smav } 910230130Smav } 911230130Smav } 912230130Smav return (config); 913230130Smav} 914230130Smav 915230130Smavuint32_t 916230130Smavhdaa_gpio_patch(uint32_t gpio, const char *str) 917230130Smav{ 918230130Smav char buf[256]; 919230130Smav char *key, *value, *rest; 920230130Smav int ikey, i; 921230130Smav 922230130Smav strlcpy(buf, str, sizeof(buf)); 923230130Smav rest = buf; 924230130Smav while ((key = strsep(&rest, "=")) != NULL) { 925230130Smav value = strsep(&rest, " \t"); 926230130Smav if (value == NULL) 927230130Smav break; 928230130Smav ikey = strtol(key, NULL, 10); 929230130Smav if (ikey < 0 || ikey > 7) 930230130Smav continue; 931230130Smav for (i = 0; i < 7; i++) { 932230130Smav if (strcasecmp(HDA_GPIO_ACTIONS[i], value) == 0) { 933230130Smav gpio &= ~HDAA_GPIO_MASK(ikey); 934230130Smav gpio |= i << HDAA_GPIO_SHIFT(ikey); 935230130Smav break; 936230130Smav } 937230130Smav } 938230130Smav } 939230130Smav return (gpio); 940230130Smav} 941230130Smav 942230130Smavstatic void 943230130Smavhdaa_local_patch_pin(struct hdaa_widget *w) 944230130Smav{ 945230130Smav device_t dev = w->devinfo->dev; 946230130Smav const char *res = NULL; 947230130Smav uint32_t config, orig; 948230130Smav char buf[32]; 949230130Smav 950230130Smav config = orig = w->wclass.pin.config; 951230130Smav snprintf(buf, sizeof(buf), "cad%u.nid%u.config", 952230130Smav hda_get_codec_id(dev), w->nid); 953230130Smav if (resource_string_value(device_get_name( 954230130Smav device_get_parent(device_get_parent(dev))), 955230130Smav device_get_unit(device_get_parent(device_get_parent(dev))), 956230130Smav buf, &res) == 0) { 957230130Smav if (strncmp(res, "0x", 2) == 0) { 958230130Smav config = strtol(res + 2, NULL, 16); 959230130Smav } else { 960230130Smav config = hdaa_widget_pin_patch(config, res); 961230130Smav } 962230130Smav } 963230130Smav snprintf(buf, sizeof(buf), "nid%u.config", w->nid); 964230130Smav if (resource_string_value(device_get_name(dev), device_get_unit(dev), 965230130Smav buf, &res) == 0) { 966230130Smav if (strncmp(res, "0x", 2) == 0) { 967230130Smav config = strtol(res + 2, NULL, 16); 968230130Smav } else { 969230130Smav config = hdaa_widget_pin_patch(config, res); 970230130Smav } 971230130Smav } 972230130Smav HDA_BOOTVERBOSE( 973230130Smav if (config != orig) 974230130Smav device_printf(w->devinfo->dev, 975230130Smav "Patching pin config nid=%u 0x%08x -> 0x%08x\n", 976230130Smav w->nid, orig, config); 977230130Smav ); 978230130Smav w->wclass.pin.newconf = w->wclass.pin.config = config; 979230130Smav} 980230130Smav 981243530Smavstatic void 982243530Smavhdaa_dump_audio_formats_sb(struct sbuf *sb, uint32_t fcap, uint32_t pcmcap) 983243530Smav{ 984243530Smav uint32_t cap; 985243530Smav 986243530Smav cap = fcap; 987243530Smav if (cap != 0) { 988243530Smav sbuf_printf(sb, " Stream cap: 0x%08x", cap); 989243530Smav if (HDA_PARAM_SUPP_STREAM_FORMATS_AC3(cap)) 990243530Smav sbuf_printf(sb, " AC3"); 991243530Smav if (HDA_PARAM_SUPP_STREAM_FORMATS_FLOAT32(cap)) 992243530Smav sbuf_printf(sb, " FLOAT32"); 993243530Smav if (HDA_PARAM_SUPP_STREAM_FORMATS_PCM(cap)) 994243530Smav sbuf_printf(sb, " PCM"); 995243530Smav sbuf_printf(sb, "\n"); 996243530Smav } 997243530Smav cap = pcmcap; 998243530Smav if (cap != 0) { 999243530Smav sbuf_printf(sb, " PCM cap: 0x%08x", cap); 1000243530Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8BIT(cap)) 1001243530Smav sbuf_printf(sb, " 8"); 1002243530Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16BIT(cap)) 1003243530Smav sbuf_printf(sb, " 16"); 1004243530Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(cap)) 1005243530Smav sbuf_printf(sb, " 20"); 1006243530Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(cap)) 1007243530Smav sbuf_printf(sb, " 24"); 1008243530Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(cap)) 1009243530Smav sbuf_printf(sb, " 32"); 1010243530Smav sbuf_printf(sb, " bits,"); 1011243530Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8KHZ(cap)) 1012243530Smav sbuf_printf(sb, " 8"); 1013243530Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_11KHZ(cap)) 1014243530Smav sbuf_printf(sb, " 11"); 1015243530Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16KHZ(cap)) 1016243530Smav sbuf_printf(sb, " 16"); 1017243530Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_22KHZ(cap)) 1018243530Smav sbuf_printf(sb, " 22"); 1019243530Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32KHZ(cap)) 1020243530Smav sbuf_printf(sb, " 32"); 1021243530Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_44KHZ(cap)) 1022243530Smav sbuf_printf(sb, " 44"); 1023243530Smav sbuf_printf(sb, " 48"); 1024243530Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_88KHZ(cap)) 1025243530Smav sbuf_printf(sb, " 88"); 1026243530Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_96KHZ(cap)) 1027243530Smav sbuf_printf(sb, " 96"); 1028243530Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_176KHZ(cap)) 1029243530Smav sbuf_printf(sb, " 176"); 1030243530Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_192KHZ(cap)) 1031243530Smav sbuf_printf(sb, " 192"); 1032243530Smav sbuf_printf(sb, " KHz\n"); 1033243530Smav } 1034243530Smav} 1035243530Smav 1036243530Smavstatic void 1037243530Smavhdaa_dump_pin_sb(struct sbuf *sb, struct hdaa_widget *w) 1038243530Smav{ 1039243530Smav uint32_t pincap, conf; 1040243530Smav 1041243530Smav pincap = w->wclass.pin.cap; 1042243530Smav 1043243530Smav sbuf_printf(sb, " Pin cap: 0x%08x", pincap); 1044243530Smav if (HDA_PARAM_PIN_CAP_IMP_SENSE_CAP(pincap)) 1045243530Smav sbuf_printf(sb, " ISC"); 1046243530Smav if (HDA_PARAM_PIN_CAP_TRIGGER_REQD(pincap)) 1047243530Smav sbuf_printf(sb, " TRQD"); 1048243530Smav if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(pincap)) 1049243530Smav sbuf_printf(sb, " PDC"); 1050243530Smav if (HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap)) 1051243530Smav sbuf_printf(sb, " HP"); 1052243530Smav if (HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap)) 1053243530Smav sbuf_printf(sb, " OUT"); 1054243530Smav if (HDA_PARAM_PIN_CAP_INPUT_CAP(pincap)) 1055243530Smav sbuf_printf(sb, " IN"); 1056243530Smav if (HDA_PARAM_PIN_CAP_BALANCED_IO_PINS(pincap)) 1057243530Smav sbuf_printf(sb, " BAL"); 1058243530Smav if (HDA_PARAM_PIN_CAP_HDMI(pincap)) 1059243530Smav sbuf_printf(sb, " HDMI"); 1060243530Smav if (HDA_PARAM_PIN_CAP_VREF_CTRL(pincap)) { 1061243530Smav sbuf_printf(sb, " VREF["); 1062243530Smav if (HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap)) 1063243530Smav sbuf_printf(sb, " 50"); 1064243530Smav if (HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap)) 1065243530Smav sbuf_printf(sb, " 80"); 1066243530Smav if (HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap)) 1067243530Smav sbuf_printf(sb, " 100"); 1068243530Smav if (HDA_PARAM_PIN_CAP_VREF_CTRL_GROUND(pincap)) 1069243530Smav sbuf_printf(sb, " GROUND"); 1070243530Smav if (HDA_PARAM_PIN_CAP_VREF_CTRL_HIZ(pincap)) 1071243530Smav sbuf_printf(sb, " HIZ"); 1072243530Smav sbuf_printf(sb, " ]"); 1073243530Smav } 1074243530Smav if (HDA_PARAM_PIN_CAP_EAPD_CAP(pincap)) 1075243530Smav sbuf_printf(sb, " EAPD"); 1076243530Smav if (HDA_PARAM_PIN_CAP_DP(pincap)) 1077243530Smav sbuf_printf(sb, " DP"); 1078243530Smav if (HDA_PARAM_PIN_CAP_HBR(pincap)) 1079243530Smav sbuf_printf(sb, " HBR"); 1080243530Smav sbuf_printf(sb, "\n"); 1081243530Smav conf = w->wclass.pin.config; 1082243530Smav sbuf_printf(sb, " Pin config: 0x%08x", conf); 1083243530Smav sbuf_printf(sb, " as=%d seq=%d " 1084243530Smav "device=%s conn=%s ctype=%s loc=%s color=%s misc=%d\n", 1085243530Smav HDA_CONFIG_DEFAULTCONF_ASSOCIATION(conf), 1086243530Smav HDA_CONFIG_DEFAULTCONF_SEQUENCE(conf), 1087243530Smav HDA_DEVS[HDA_CONFIG_DEFAULTCONF_DEVICE(conf)], 1088243530Smav HDA_CONNS[HDA_CONFIG_DEFAULTCONF_CONNECTIVITY(conf)], 1089243530Smav HDA_CONNECTORS[HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE(conf)], 1090243530Smav HDA_LOCS[HDA_CONFIG_DEFAULTCONF_LOCATION(conf)], 1091243530Smav HDA_COLORS[HDA_CONFIG_DEFAULTCONF_COLOR(conf)], 1092243530Smav HDA_CONFIG_DEFAULTCONF_MISC(conf)); 1093243530Smav sbuf_printf(sb, " Pin control: 0x%08x", w->wclass.pin.ctrl); 1094243530Smav if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE) 1095243530Smav sbuf_printf(sb, " HP"); 1096243530Smav if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE) 1097243530Smav sbuf_printf(sb, " IN"); 1098243530Smav if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE) 1099243530Smav sbuf_printf(sb, " OUT"); 1100243530Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) { 1101243530Smav if ((w->wclass.pin.ctrl & 1102243530Smav HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK) == 0x03) 1103243530Smav sbuf_printf(sb, " HBR"); 1104243530Smav else if ((w->wclass.pin.ctrl & 1105243530Smav HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK) != 0) 1106243530Smav sbuf_printf(sb, " EPTs"); 1107243530Smav } else { 1108243530Smav if ((w->wclass.pin.ctrl & 1109243530Smav HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK) != 0) 1110243530Smav sbuf_printf(sb, " VREFs"); 1111243530Smav } 1112243530Smav sbuf_printf(sb, "\n"); 1113243530Smav} 1114243530Smav 1115243530Smavstatic void 1116243530Smavhdaa_dump_amp_sb(struct sbuf *sb, uint32_t cap, char *banner) 1117243530Smav{ 1118243530Smav int offset, size, step; 1119243530Smav 1120243530Smav offset = HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(cap); 1121243530Smav size = HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(cap); 1122243530Smav step = HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(cap); 1123243530Smav sbuf_printf(sb, " %s amp: 0x%08x " 1124243530Smav "mute=%d step=%d size=%d offset=%d (%+d/%+ddB)\n", 1125243530Smav banner, cap, 1126243530Smav HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(cap), 1127243530Smav step, size, offset, 1128243530Smav ((0 - offset) * (size + 1)) / 4, 1129243530Smav ((step - offset) * (size + 1)) / 4); 1130243530Smav} 1131243530Smav 1132243530Smav 1133230130Smavstatic int 1134243530Smavhdaa_sysctl_caps(SYSCTL_HANDLER_ARGS) 1135243530Smav{ 1136243530Smav struct hdaa_devinfo *devinfo; 1137243530Smav struct hdaa_widget *w, *cw; 1138243530Smav struct sbuf sb; 1139243530Smav char buf[64]; 1140243530Smav int error, j; 1141243530Smav 1142243530Smav w = (struct hdaa_widget *)oidp->oid_arg1; 1143243530Smav devinfo = w->devinfo; 1144243530Smav sbuf_new_for_sysctl(&sb, NULL, 256, req); 1145243530Smav 1146243530Smav sbuf_printf(&sb, "%s%s\n", w->name, 1147243530Smav (w->enable == 0) ? " [DISABLED]" : ""); 1148243530Smav sbuf_printf(&sb, " Widget cap: 0x%08x", 1149243530Smav w->param.widget_cap); 1150243530Smav if (w->param.widget_cap & 0x0ee1) { 1151243530Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_LR_SWAP(w->param.widget_cap)) 1152243530Smav sbuf_printf(&sb, " LRSWAP"); 1153243530Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_POWER_CTRL(w->param.widget_cap)) 1154243530Smav sbuf_printf(&sb, " PWR"); 1155243530Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) 1156243530Smav sbuf_printf(&sb, " DIGITAL"); 1157243530Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_UNSOL_CAP(w->param.widget_cap)) 1158243530Smav sbuf_printf(&sb, " UNSOL"); 1159243530Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_PROC_WIDGET(w->param.widget_cap)) 1160243530Smav sbuf_printf(&sb, " PROC"); 1161243530Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_STRIPE(w->param.widget_cap)) 1162243530Smav sbuf_printf(&sb, " STRIPE(x%d)", 1163243530Smav 1 << (fls(w->wclass.conv.stripecap) - 1)); 1164243530Smav j = HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap); 1165243530Smav if (j == 1) 1166243530Smav sbuf_printf(&sb, " STEREO"); 1167243530Smav else if (j > 1) 1168243530Smav sbuf_printf(&sb, " %dCH", j + 1); 1169243530Smav } 1170243530Smav sbuf_printf(&sb, "\n"); 1171243530Smav if (w->bindas != -1) { 1172243530Smav sbuf_printf(&sb, " Association: %d (0x%04x)\n", 1173243530Smav w->bindas, w->bindseqmask); 1174243530Smav } 1175243530Smav if (w->ossmask != 0 || w->ossdev >= 0) { 1176243530Smav sbuf_printf(&sb, " OSS: %s", 1177243530Smav hdaa_audio_ctl_ossmixer_mask2allname(w->ossmask, buf, sizeof(buf))); 1178243530Smav if (w->ossdev >= 0) 1179243530Smav sbuf_printf(&sb, " (%s)", ossnames[w->ossdev]); 1180243530Smav sbuf_printf(&sb, "\n"); 1181243530Smav } 1182243530Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT || 1183243530Smav w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) { 1184243530Smav hdaa_dump_audio_formats_sb(&sb, 1185243530Smav w->param.supp_stream_formats, 1186243530Smav w->param.supp_pcm_size_rate); 1187243530Smav } else if (w->type == 1188243530Smav HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX || w->waspin) 1189243530Smav hdaa_dump_pin_sb(&sb, w); 1190243530Smav if (w->param.eapdbtl != HDA_INVALID) { 1191243530Smav sbuf_printf(&sb, " EAPD: 0x%08x%s%s%s\n", 1192243530Smav w->param.eapdbtl, 1193243530Smav (w->param.eapdbtl & HDA_CMD_SET_EAPD_BTL_ENABLE_LR_SWAP) ? 1194243530Smav " LRSWAP" : "", 1195243530Smav (w->param.eapdbtl & HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD) ? 1196243530Smav " EAPD" : "", 1197243530Smav (w->param.eapdbtl & HDA_CMD_SET_EAPD_BTL_ENABLE_BTL) ? 1198243530Smav " BTL" : ""); 1199243530Smav } 1200243530Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_OUT_AMP(w->param.widget_cap) && 1201243530Smav w->param.outamp_cap != 0) 1202243530Smav hdaa_dump_amp_sb(&sb, w->param.outamp_cap, "Output"); 1203243530Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_IN_AMP(w->param.widget_cap) && 1204243530Smav w->param.inamp_cap != 0) 1205243530Smav hdaa_dump_amp_sb(&sb, w->param.inamp_cap, " Input"); 1206243530Smav if (w->nconns > 0) 1207243530Smav sbuf_printf(&sb, " Connections: %d\n", w->nconns); 1208243530Smav for (j = 0; j < w->nconns; j++) { 1209243530Smav cw = hdaa_widget_get(devinfo, w->conns[j]); 1210243530Smav sbuf_printf(&sb, " + %s<- nid=%d [%s]", 1211243530Smav (w->connsenable[j] == 0)?"[DISABLED] ":"", 1212243530Smav w->conns[j], (cw == NULL) ? "GHOST!" : cw->name); 1213243530Smav if (cw == NULL) 1214243530Smav sbuf_printf(&sb, " [UNKNOWN]"); 1215243530Smav else if (cw->enable == 0) 1216243530Smav sbuf_printf(&sb, " [DISABLED]"); 1217243530Smav if (w->nconns > 1 && w->selconn == j && w->type != 1218243530Smav HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) 1219243530Smav sbuf_printf(&sb, " (selected)"); 1220243530Smav sbuf_printf(&sb, "\n"); 1221243530Smav } 1222243530Smav sbuf_trim(&sb); 1223243530Smav error = sbuf_finish(&sb); 1224243530Smav sbuf_delete(&sb); 1225243530Smav return (error); 1226243530Smav} 1227243530Smav 1228243530Smavstatic int 1229230130Smavhdaa_sysctl_config(SYSCTL_HANDLER_ARGS) 1230230130Smav{ 1231230130Smav char buf[256]; 1232230130Smav int error; 1233230130Smav uint32_t conf; 1234230130Smav 1235230130Smav conf = *(uint32_t *)oidp->oid_arg1; 1236230130Smav snprintf(buf, sizeof(buf), "0x%08x as=%d seq=%d " 1237230130Smav "device=%s conn=%s ctype=%s loc=%s color=%s misc=%d", 1238230130Smav conf, 1239230130Smav HDA_CONFIG_DEFAULTCONF_ASSOCIATION(conf), 1240230130Smav HDA_CONFIG_DEFAULTCONF_SEQUENCE(conf), 1241230130Smav HDA_DEVS[HDA_CONFIG_DEFAULTCONF_DEVICE(conf)], 1242230130Smav HDA_CONNS[HDA_CONFIG_DEFAULTCONF_CONNECTIVITY(conf)], 1243230130Smav HDA_CONNECTORS[HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE(conf)], 1244230130Smav HDA_LOCS[HDA_CONFIG_DEFAULTCONF_LOCATION(conf)], 1245230130Smav HDA_COLORS[HDA_CONFIG_DEFAULTCONF_COLOR(conf)], 1246230130Smav HDA_CONFIG_DEFAULTCONF_MISC(conf)); 1247230130Smav error = sysctl_handle_string(oidp, buf, sizeof(buf), req); 1248230130Smav if (error != 0 || req->newptr == NULL) 1249230130Smav return (error); 1250230130Smav if (strncmp(buf, "0x", 2) == 0) 1251230130Smav conf = strtol(buf + 2, NULL, 16); 1252230130Smav else 1253230130Smav conf = hdaa_widget_pin_patch(conf, buf); 1254230130Smav *(uint32_t *)oidp->oid_arg1 = conf; 1255230130Smav return (0); 1256230130Smav} 1257230130Smav 1258230130Smavstatic void 1259230130Smavhdaa_config_fetch(const char *str, uint32_t *on, uint32_t *off) 1260230130Smav{ 1261230130Smav int i = 0, j, k, len, inv; 1262230130Smav 1263230130Smav for (;;) { 1264230130Smav while (str[i] != '\0' && 1265230130Smav (str[i] == ',' || isspace(str[i]) != 0)) 1266230130Smav i++; 1267230130Smav if (str[i] == '\0') 1268230130Smav return; 1269230130Smav j = i; 1270230130Smav while (str[j] != '\0' && 1271230130Smav !(str[j] == ',' || isspace(str[j]) != 0)) 1272230130Smav j++; 1273230130Smav len = j - i; 1274230130Smav if (len > 2 && strncmp(str + i, "no", 2) == 0) 1275230130Smav inv = 2; 1276230130Smav else 1277230130Smav inv = 0; 1278230130Smav for (k = 0; len > inv && k < HDAA_QUIRKS_TAB_LEN; k++) { 1279230130Smav if (strncmp(str + i + inv, 1280230130Smav hdaa_quirks_tab[k].key, len - inv) != 0) 1281230130Smav continue; 1282230130Smav if (len - inv != strlen(hdaa_quirks_tab[k].key)) 1283230130Smav continue; 1284230130Smav if (inv == 0) { 1285230130Smav *on |= hdaa_quirks_tab[k].value; 1286230130Smav *off &= ~hdaa_quirks_tab[k].value; 1287230130Smav } else { 1288230130Smav *off |= hdaa_quirks_tab[k].value; 1289230130Smav *on &= ~hdaa_quirks_tab[k].value; 1290230130Smav } 1291230130Smav break; 1292230130Smav } 1293230130Smav i = j; 1294230130Smav } 1295230130Smav} 1296230130Smav 1297230130Smavstatic int 1298230130Smavhdaa_sysctl_quirks(SYSCTL_HANDLER_ARGS) 1299230130Smav{ 1300230130Smav char buf[256]; 1301230130Smav int error, n = 0, i; 1302230130Smav uint32_t quirks, quirks_off; 1303230130Smav 1304230130Smav quirks = *(uint32_t *)oidp->oid_arg1; 1305230130Smav buf[0] = 0; 1306230130Smav for (i = 0; i < HDAA_QUIRKS_TAB_LEN; i++) { 1307230130Smav if ((quirks & hdaa_quirks_tab[i].value) != 0) 1308230130Smav n += snprintf(buf + n, sizeof(buf) - n, "%s%s", 1309230130Smav n != 0 ? "," : "", hdaa_quirks_tab[i].key); 1310230130Smav } 1311230130Smav error = sysctl_handle_string(oidp, buf, sizeof(buf), req); 1312230130Smav if (error != 0 || req->newptr == NULL) 1313230130Smav return (error); 1314230130Smav if (strncmp(buf, "0x", 2) == 0) 1315230130Smav quirks = strtol(buf + 2, NULL, 16); 1316230130Smav else { 1317230130Smav quirks = 0; 1318230130Smav hdaa_config_fetch(buf, &quirks, &quirks_off); 1319230130Smav } 1320230130Smav *(uint32_t *)oidp->oid_arg1 = quirks; 1321230130Smav return (0); 1322230130Smav} 1323230130Smav 1324230130Smavstatic void 1325230130Smavhdaa_local_patch(struct hdaa_devinfo *devinfo) 1326230130Smav{ 1327230130Smav struct hdaa_widget *w; 1328230130Smav const char *res = NULL; 1329230130Smav uint32_t quirks_on = 0, quirks_off = 0, x; 1330230130Smav int i; 1331230130Smav 1332230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 1333230130Smav w = hdaa_widget_get(devinfo, i); 1334230130Smav if (w == NULL) 1335230130Smav continue; 1336230130Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 1337230130Smav hdaa_local_patch_pin(w); 1338230130Smav } 1339230130Smav 1340230130Smav if (resource_string_value(device_get_name(devinfo->dev), 1341230130Smav device_get_unit(devinfo->dev), "config", &res) == 0) { 1342230130Smav if (res != NULL && strlen(res) > 0) 1343230130Smav hdaa_config_fetch(res, &quirks_on, &quirks_off); 1344230130Smav devinfo->quirks |= quirks_on; 1345230130Smav devinfo->quirks &= ~quirks_off; 1346230130Smav } 1347230130Smav if (devinfo->newquirks == -1) 1348230130Smav devinfo->newquirks = devinfo->quirks; 1349230130Smav else 1350230130Smav devinfo->quirks = devinfo->newquirks; 1351230130Smav HDA_BOOTHVERBOSE( 1352230130Smav device_printf(devinfo->dev, 1353230130Smav "Config options: 0x%08x\n", devinfo->quirks); 1354230130Smav ); 1355230130Smav 1356230130Smav if (resource_string_value(device_get_name(devinfo->dev), 1357230130Smav device_get_unit(devinfo->dev), "gpio_config", &res) == 0) { 1358230130Smav if (strncmp(res, "0x", 2) == 0) { 1359230130Smav devinfo->gpio = strtol(res + 2, NULL, 16); 1360230130Smav } else { 1361230130Smav devinfo->gpio = hdaa_gpio_patch(devinfo->gpio, res); 1362230130Smav } 1363230130Smav } 1364230130Smav if (devinfo->newgpio == -1) 1365230130Smav devinfo->newgpio = devinfo->gpio; 1366230130Smav else 1367230130Smav devinfo->gpio = devinfo->newgpio; 1368230130Smav if (devinfo->newgpo == -1) 1369230130Smav devinfo->newgpo = devinfo->gpo; 1370230130Smav else 1371230130Smav devinfo->gpo = devinfo->newgpo; 1372230130Smav HDA_BOOTHVERBOSE( 1373230130Smav device_printf(devinfo->dev, "GPIO config options:"); 1374230130Smav for (i = 0; i < 7; i++) { 1375230130Smav x = (devinfo->gpio & HDAA_GPIO_MASK(i)) >> HDAA_GPIO_SHIFT(i); 1376230130Smav if (x != 0) 1377230130Smav printf(" %d=%s", i, HDA_GPIO_ACTIONS[x]); 1378230130Smav } 1379230130Smav printf("\n"); 1380230130Smav ); 1381230130Smav} 1382230130Smav 1383230130Smavstatic void 1384230130Smavhdaa_widget_connection_parse(struct hdaa_widget *w) 1385230130Smav{ 1386230130Smav uint32_t res; 1387230130Smav int i, j, max, ents, entnum; 1388230130Smav nid_t nid = w->nid; 1389230130Smav nid_t cnid, addcnid, prevcnid; 1390230130Smav 1391230130Smav w->nconns = 0; 1392230130Smav 1393230130Smav res = hda_command(w->devinfo->dev, 1394230130Smav HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_CONN_LIST_LENGTH)); 1395230130Smav 1396230130Smav ents = HDA_PARAM_CONN_LIST_LENGTH_LIST_LENGTH(res); 1397230130Smav 1398230130Smav if (ents < 1) 1399230130Smav return; 1400230130Smav 1401230130Smav entnum = HDA_PARAM_CONN_LIST_LENGTH_LONG_FORM(res) ? 2 : 4; 1402230130Smav max = (sizeof(w->conns) / sizeof(w->conns[0])) - 1; 1403230130Smav prevcnid = 0; 1404230130Smav 1405230130Smav#define CONN_RMASK(e) (1 << ((32 / (e)) - 1)) 1406230130Smav#define CONN_NMASK(e) (CONN_RMASK(e) - 1) 1407230130Smav#define CONN_RESVAL(r, e, n) ((r) >> ((32 / (e)) * (n))) 1408230130Smav#define CONN_RANGE(r, e, n) (CONN_RESVAL(r, e, n) & CONN_RMASK(e)) 1409230130Smav#define CONN_CNID(r, e, n) (CONN_RESVAL(r, e, n) & CONN_NMASK(e)) 1410230130Smav 1411230130Smav for (i = 0; i < ents; i += entnum) { 1412230130Smav res = hda_command(w->devinfo->dev, 1413230130Smav HDA_CMD_GET_CONN_LIST_ENTRY(0, nid, i)); 1414230130Smav for (j = 0; j < entnum; j++) { 1415230130Smav cnid = CONN_CNID(res, entnum, j); 1416230130Smav if (cnid == 0) { 1417230130Smav if (w->nconns < ents) 1418230130Smav device_printf(w->devinfo->dev, 1419230130Smav "WARNING: nid=%d has zero cnid " 1420230130Smav "entnum=%d j=%d index=%d " 1421230130Smav "entries=%d found=%d res=0x%08x\n", 1422230130Smav nid, entnum, j, i, 1423230130Smav ents, w->nconns, res); 1424230130Smav else 1425230130Smav goto getconns_out; 1426230130Smav } 1427230130Smav if (cnid < w->devinfo->startnode || 1428230130Smav cnid >= w->devinfo->endnode) { 1429230130Smav HDA_BOOTVERBOSE( 1430230130Smav device_printf(w->devinfo->dev, 1431230130Smav "WARNING: nid=%d has cnid outside " 1432230130Smav "of the AFG range j=%d " 1433230130Smav "entnum=%d index=%d res=0x%08x\n", 1434230130Smav nid, j, entnum, i, res); 1435230130Smav ); 1436230130Smav } 1437230130Smav if (CONN_RANGE(res, entnum, j) == 0) 1438230130Smav addcnid = cnid; 1439230130Smav else if (prevcnid == 0 || prevcnid >= cnid) { 1440230130Smav device_printf(w->devinfo->dev, 1441230130Smav "WARNING: Invalid child range " 1442230130Smav "nid=%d index=%d j=%d entnum=%d " 1443230130Smav "prevcnid=%d cnid=%d res=0x%08x\n", 1444230130Smav nid, i, j, entnum, prevcnid, 1445230130Smav cnid, res); 1446230130Smav addcnid = cnid; 1447230130Smav } else 1448230130Smav addcnid = prevcnid + 1; 1449230130Smav while (addcnid <= cnid) { 1450230130Smav if (w->nconns > max) { 1451230130Smav device_printf(w->devinfo->dev, 1452230130Smav "Adding %d (nid=%d): " 1453230130Smav "Max connection reached! max=%d\n", 1454230130Smav addcnid, nid, max + 1); 1455230130Smav goto getconns_out; 1456230130Smav } 1457230130Smav w->connsenable[w->nconns] = 1; 1458230130Smav w->conns[w->nconns++] = addcnid++; 1459230130Smav } 1460230130Smav prevcnid = cnid; 1461230130Smav } 1462230130Smav } 1463230130Smav 1464230130Smavgetconns_out: 1465230130Smav return; 1466230130Smav} 1467230130Smav 1468230130Smavstatic void 1469230130Smavhdaa_widget_parse(struct hdaa_widget *w) 1470230130Smav{ 1471230130Smav device_t dev = w->devinfo->dev; 1472230130Smav uint32_t wcap, cap; 1473230130Smav nid_t nid = w->nid; 1474230130Smav char buf[64]; 1475230130Smav 1476230130Smav w->param.widget_cap = wcap = hda_command(dev, 1477230130Smav HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_AUDIO_WIDGET_CAP)); 1478230130Smav w->type = HDA_PARAM_AUDIO_WIDGET_CAP_TYPE(wcap); 1479230130Smav 1480230130Smav hdaa_widget_connection_parse(w); 1481230130Smav 1482230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_OUT_AMP(wcap)) { 1483230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_AMP_OVR(wcap)) 1484230130Smav w->param.outamp_cap = 1485230130Smav hda_command(dev, 1486230130Smav HDA_CMD_GET_PARAMETER(0, nid, 1487230130Smav HDA_PARAM_OUTPUT_AMP_CAP)); 1488230130Smav else 1489230130Smav w->param.outamp_cap = 1490230130Smav w->devinfo->outamp_cap; 1491230130Smav } else 1492230130Smav w->param.outamp_cap = 0; 1493230130Smav 1494230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_IN_AMP(wcap)) { 1495230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_AMP_OVR(wcap)) 1496230130Smav w->param.inamp_cap = 1497230130Smav hda_command(dev, 1498230130Smav HDA_CMD_GET_PARAMETER(0, nid, 1499230130Smav HDA_PARAM_INPUT_AMP_CAP)); 1500230130Smav else 1501230130Smav w->param.inamp_cap = 1502230130Smav w->devinfo->inamp_cap; 1503230130Smav } else 1504230130Smav w->param.inamp_cap = 0; 1505230130Smav 1506230130Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT || 1507230130Smav w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) { 1508230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_FORMAT_OVR(wcap)) { 1509230130Smav cap = hda_command(dev, 1510230130Smav HDA_CMD_GET_PARAMETER(0, nid, 1511230130Smav HDA_PARAM_SUPP_STREAM_FORMATS)); 1512230130Smav w->param.supp_stream_formats = (cap != 0) ? cap : 1513230130Smav w->devinfo->supp_stream_formats; 1514230130Smav cap = hda_command(dev, 1515230130Smav HDA_CMD_GET_PARAMETER(0, nid, 1516230130Smav HDA_PARAM_SUPP_PCM_SIZE_RATE)); 1517230130Smav w->param.supp_pcm_size_rate = (cap != 0) ? cap : 1518230130Smav w->devinfo->supp_pcm_size_rate; 1519230130Smav } else { 1520230130Smav w->param.supp_stream_formats = 1521230130Smav w->devinfo->supp_stream_formats; 1522230130Smav w->param.supp_pcm_size_rate = 1523230130Smav w->devinfo->supp_pcm_size_rate; 1524230130Smav } 1525230326Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_STRIPE(w->param.widget_cap)) { 1526230326Smav w->wclass.conv.stripecap = hda_command(dev, 1527230326Smav HDA_CMD_GET_STRIPE_CONTROL(0, w->nid)) >> 20; 1528230326Smav } else 1529230326Smav w->wclass.conv.stripecap = 1; 1530230130Smav } else { 1531230130Smav w->param.supp_stream_formats = 0; 1532230130Smav w->param.supp_pcm_size_rate = 0; 1533230130Smav } 1534230130Smav 1535230130Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) { 1536230130Smav w->wclass.pin.original = w->wclass.pin.newconf = 1537230130Smav w->wclass.pin.config = hda_command(dev, 1538230130Smav HDA_CMD_GET_CONFIGURATION_DEFAULT(0, w->nid)); 1539230130Smav w->wclass.pin.cap = hda_command(dev, 1540241844Seadler HDA_CMD_GET_PARAMETER(0, w->nid, HDA_PARAM_PIN_CAP)); 1541230130Smav w->wclass.pin.ctrl = hda_command(dev, 1542230130Smav HDA_CMD_GET_PIN_WIDGET_CTRL(0, nid)); 1543242357Smav w->wclass.pin.connected = 2; 1544230130Smav if (HDA_PARAM_PIN_CAP_EAPD_CAP(w->wclass.pin.cap)) { 1545230130Smav w->param.eapdbtl = hda_command(dev, 1546230130Smav HDA_CMD_GET_EAPD_BTL_ENABLE(0, nid)); 1547230130Smav w->param.eapdbtl &= 0x7; 1548230130Smav w->param.eapdbtl |= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD; 1549230130Smav } else 1550230130Smav w->param.eapdbtl = HDA_INVALID; 1551243530Smav } 1552243530Smav w->unsol = -1; 1553230130Smav 1554243530Smav hdaa_unlock(w->devinfo); 1555243530Smav snprintf(buf, sizeof(buf), "nid%d", w->nid); 1556243530Smav SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 1557243530Smav SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, 1558243530Smav buf, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, 1559243530Smav w, sizeof(w), hdaa_sysctl_caps, "A", "Node capabilities"); 1560243530Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) { 1561230130Smav snprintf(buf, sizeof(buf), "nid%d_config", w->nid); 1562230130Smav SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 1563230130Smav SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, 1564230130Smav buf, CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE, 1565230130Smav &w->wclass.pin.newconf, sizeof(&w->wclass.pin.newconf), 1566230130Smav hdaa_sysctl_config, "A", "Current pin configuration"); 1567230130Smav snprintf(buf, sizeof(buf), "nid%d_original", w->nid); 1568230130Smav SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 1569230130Smav SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, 1570230130Smav buf, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, 1571230130Smav &w->wclass.pin.original, sizeof(&w->wclass.pin.original), 1572230130Smav hdaa_sysctl_config, "A", "Original pin configuration"); 1573230130Smav } 1574243530Smav hdaa_lock(w->devinfo); 1575230130Smav} 1576230130Smav 1577230130Smavstatic void 1578230130Smavhdaa_widget_postprocess(struct hdaa_widget *w) 1579230130Smav{ 1580230130Smav char *typestr; 1581230130Smav 1582230130Smav w->type = HDA_PARAM_AUDIO_WIDGET_CAP_TYPE(w->param.widget_cap); 1583230130Smav switch (w->type) { 1584230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT: 1585230130Smav typestr = "audio output"; 1586230130Smav break; 1587230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT: 1588230130Smav typestr = "audio input"; 1589230130Smav break; 1590230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER: 1591230130Smav typestr = "audio mixer"; 1592230130Smav break; 1593230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR: 1594230130Smav typestr = "audio selector"; 1595230130Smav break; 1596230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX: 1597230130Smav typestr = "pin"; 1598230130Smav break; 1599230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_POWER_WIDGET: 1600230130Smav typestr = "power widget"; 1601230130Smav break; 1602230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_VOLUME_WIDGET: 1603230130Smav typestr = "volume widget"; 1604230130Smav break; 1605230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET: 1606230130Smav typestr = "beep widget"; 1607230130Smav break; 1608230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_VENDOR_WIDGET: 1609230130Smav typestr = "vendor widget"; 1610230130Smav break; 1611230130Smav default: 1612230130Smav typestr = "unknown type"; 1613230130Smav break; 1614230130Smav } 1615230130Smav strlcpy(w->name, typestr, sizeof(w->name)); 1616230130Smav 1617230130Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) { 1618230130Smav uint32_t config; 1619230130Smav const char *devstr; 1620230130Smav int conn, color; 1621230130Smav 1622230130Smav config = w->wclass.pin.config; 1623230130Smav devstr = HDA_DEVS[(config & HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) >> 1624230130Smav HDA_CONFIG_DEFAULTCONF_DEVICE_SHIFT]; 1625230130Smav conn = (config & HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK) >> 1626230130Smav HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_SHIFT; 1627230130Smav color = (config & HDA_CONFIG_DEFAULTCONF_COLOR_MASK) >> 1628230130Smav HDA_CONFIG_DEFAULTCONF_COLOR_SHIFT; 1629230130Smav strlcat(w->name, ": ", sizeof(w->name)); 1630230130Smav strlcat(w->name, devstr, sizeof(w->name)); 1631230130Smav strlcat(w->name, " (", sizeof(w->name)); 1632230130Smav if (conn == 0 && color != 0 && color != 15) { 1633230130Smav strlcat(w->name, HDA_COLORS[color], sizeof(w->name)); 1634230130Smav strlcat(w->name, " ", sizeof(w->name)); 1635230130Smav } 1636230130Smav strlcat(w->name, HDA_CONNS[conn], sizeof(w->name)); 1637230130Smav strlcat(w->name, ")", sizeof(w->name)); 1638230130Smav } 1639230130Smav} 1640230130Smav 1641230130Smavstruct hdaa_widget * 1642230130Smavhdaa_widget_get(struct hdaa_devinfo *devinfo, nid_t nid) 1643230130Smav{ 1644230130Smav if (devinfo == NULL || devinfo->widget == NULL || 1645230130Smav nid < devinfo->startnode || nid >= devinfo->endnode) 1646230130Smav return (NULL); 1647230130Smav return (&devinfo->widget[nid - devinfo->startnode]); 1648230130Smav} 1649230130Smav 1650230130Smavstatic void 1651230130Smavhdaa_audio_ctl_amp_set_internal(struct hdaa_devinfo *devinfo, nid_t nid, 1652230130Smav int index, int lmute, int rmute, 1653230130Smav int left, int right, int dir) 1654230130Smav{ 1655230130Smav uint16_t v = 0; 1656230130Smav 1657230130Smav HDA_BOOTHVERBOSE( 1658230130Smav device_printf(devinfo->dev, 1659230130Smav "Setting amplifier nid=%d index=%d %s mute=%d/%d vol=%d/%d\n", 1660230130Smav nid,index,dir ? "in" : "out",lmute,rmute,left,right); 1661230130Smav ); 1662230130Smav if (left != right || lmute != rmute) { 1663230130Smav v = (1 << (15 - dir)) | (1 << 13) | (index << 8) | 1664230130Smav (lmute << 7) | left; 1665230130Smav hda_command(devinfo->dev, 1666230130Smav HDA_CMD_SET_AMP_GAIN_MUTE(0, nid, v)); 1667230130Smav v = (1 << (15 - dir)) | (1 << 12) | (index << 8) | 1668230130Smav (rmute << 7) | right; 1669230130Smav } else 1670230130Smav v = (1 << (15 - dir)) | (3 << 12) | (index << 8) | 1671230130Smav (lmute << 7) | left; 1672230130Smav 1673230130Smav hda_command(devinfo->dev, 1674230130Smav HDA_CMD_SET_AMP_GAIN_MUTE(0, nid, v)); 1675230130Smav} 1676230130Smav 1677230130Smavstatic void 1678230130Smavhdaa_audio_ctl_amp_set(struct hdaa_audio_ctl *ctl, uint32_t mute, 1679230130Smav int left, int right) 1680230130Smav{ 1681230130Smav nid_t nid; 1682230130Smav int lmute, rmute; 1683230130Smav 1684230130Smav nid = ctl->widget->nid; 1685230130Smav 1686230130Smav /* Save new values if valid. */ 1687230130Smav if (mute != HDAA_AMP_MUTE_DEFAULT) 1688230130Smav ctl->muted = mute; 1689230130Smav if (left != HDAA_AMP_VOL_DEFAULT) 1690230130Smav ctl->left = left; 1691230130Smav if (right != HDAA_AMP_VOL_DEFAULT) 1692230130Smav ctl->right = right; 1693230130Smav /* Prepare effective values */ 1694230130Smav if (ctl->forcemute) { 1695230130Smav lmute = 1; 1696230130Smav rmute = 1; 1697230130Smav left = 0; 1698230130Smav right = 0; 1699230130Smav } else { 1700230130Smav lmute = HDAA_AMP_LEFT_MUTED(ctl->muted); 1701230130Smav rmute = HDAA_AMP_RIGHT_MUTED(ctl->muted); 1702230130Smav left = ctl->left; 1703230130Smav right = ctl->right; 1704230130Smav } 1705230130Smav /* Apply effective values */ 1706230130Smav if (ctl->dir & HDAA_CTL_OUT) 1707230130Smav hdaa_audio_ctl_amp_set_internal(ctl->widget->devinfo, nid, ctl->index, 1708230130Smav lmute, rmute, left, right, 0); 1709230130Smav if (ctl->dir & HDAA_CTL_IN) 1710230130Smav hdaa_audio_ctl_amp_set_internal(ctl->widget->devinfo, nid, ctl->index, 1711230130Smav lmute, rmute, left, right, 1); 1712230130Smav} 1713230130Smav 1714230130Smavstatic void 1715230130Smavhdaa_widget_connection_select(struct hdaa_widget *w, uint8_t index) 1716230130Smav{ 1717230130Smav if (w == NULL || w->nconns < 1 || index > (w->nconns - 1)) 1718230130Smav return; 1719230130Smav HDA_BOOTHVERBOSE( 1720230130Smav device_printf(w->devinfo->dev, 1721230130Smav "Setting selector nid=%d index=%d\n", w->nid, index); 1722230130Smav ); 1723230130Smav hda_command(w->devinfo->dev, 1724230130Smav HDA_CMD_SET_CONNECTION_SELECT_CONTROL(0, w->nid, index)); 1725230130Smav w->selconn = index; 1726230130Smav} 1727230130Smav 1728230130Smav/**************************************************************************** 1729230130Smav * Device Methods 1730230130Smav ****************************************************************************/ 1731230130Smav 1732230130Smavstatic void * 1733230130Smavhdaa_channel_init(kobj_t obj, void *data, struct snd_dbuf *b, 1734230130Smav struct pcm_channel *c, int dir) 1735230130Smav{ 1736230130Smav struct hdaa_chan *ch = data; 1737230130Smav struct hdaa_pcm_devinfo *pdevinfo = ch->pdevinfo; 1738230130Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 1739230130Smav 1740230130Smav hdaa_lock(devinfo); 1741230130Smav if (devinfo->quirks & HDAA_QUIRK_FIXEDRATE) { 1742230130Smav ch->caps.minspeed = ch->caps.maxspeed = 48000; 1743230130Smav ch->pcmrates[0] = 48000; 1744230130Smav ch->pcmrates[1] = 0; 1745230130Smav } 1746230130Smav ch->dir = dir; 1747230130Smav ch->b = b; 1748230130Smav ch->c = c; 1749230130Smav ch->blksz = pdevinfo->chan_size / pdevinfo->chan_blkcnt; 1750230130Smav ch->blkcnt = pdevinfo->chan_blkcnt; 1751230130Smav hdaa_unlock(devinfo); 1752230130Smav 1753230130Smav if (sndbuf_alloc(ch->b, bus_get_dma_tag(devinfo->dev), 1754230130Smav hda_get_dma_nocache(devinfo->dev) ? BUS_DMA_NOCACHE : 0, 1755230130Smav pdevinfo->chan_size) != 0) 1756230130Smav return (NULL); 1757230130Smav 1758230130Smav return (ch); 1759230130Smav} 1760230130Smav 1761230130Smavstatic int 1762230130Smavhdaa_channel_setformat(kobj_t obj, void *data, uint32_t format) 1763230130Smav{ 1764230130Smav struct hdaa_chan *ch = data; 1765230130Smav int i; 1766230130Smav 1767230130Smav for (i = 0; ch->caps.fmtlist[i] != 0; i++) { 1768230130Smav if (format == ch->caps.fmtlist[i]) { 1769230130Smav ch->fmt = format; 1770230130Smav return (0); 1771230130Smav } 1772230130Smav } 1773230130Smav 1774230130Smav return (EINVAL); 1775230130Smav} 1776230130Smav 1777230130Smavstatic uint32_t 1778230130Smavhdaa_channel_setspeed(kobj_t obj, void *data, uint32_t speed) 1779230130Smav{ 1780230130Smav struct hdaa_chan *ch = data; 1781230130Smav uint32_t spd = 0, threshold; 1782230130Smav int i; 1783230130Smav 1784230130Smav /* First look for equal or multiple frequency. */ 1785230130Smav for (i = 0; ch->pcmrates[i] != 0; i++) { 1786230130Smav spd = ch->pcmrates[i]; 1787230130Smav if (speed != 0 && spd / speed * speed == spd) { 1788230130Smav ch->spd = spd; 1789230130Smav return (spd); 1790230130Smav } 1791230130Smav } 1792230130Smav /* If no match, just find nearest. */ 1793230130Smav for (i = 0; ch->pcmrates[i] != 0; i++) { 1794230130Smav spd = ch->pcmrates[i]; 1795230130Smav threshold = spd + ((ch->pcmrates[i + 1] != 0) ? 1796230130Smav ((ch->pcmrates[i + 1] - spd) >> 1) : 0); 1797230130Smav if (speed < threshold) 1798230130Smav break; 1799230130Smav } 1800230130Smav ch->spd = spd; 1801230130Smav return (spd); 1802230130Smav} 1803230130Smav 1804230130Smavstatic uint16_t 1805230130Smavhdaa_stream_format(struct hdaa_chan *ch) 1806230130Smav{ 1807230130Smav int i; 1808230130Smav uint16_t fmt; 1809230130Smav 1810230130Smav fmt = 0; 1811230130Smav if (ch->fmt & AFMT_S16_LE) 1812230130Smav fmt |= ch->bit16 << 4; 1813230130Smav else if (ch->fmt & AFMT_S32_LE) 1814230130Smav fmt |= ch->bit32 << 4; 1815230130Smav else 1816230130Smav fmt |= 1 << 4; 1817230130Smav for (i = 0; i < HDA_RATE_TAB_LEN; i++) { 1818230130Smav if (hda_rate_tab[i].valid && ch->spd == hda_rate_tab[i].rate) { 1819230130Smav fmt |= hda_rate_tab[i].base; 1820230130Smav fmt |= hda_rate_tab[i].mul; 1821230130Smav fmt |= hda_rate_tab[i].div; 1822230130Smav break; 1823230130Smav } 1824230130Smav } 1825230130Smav fmt |= (AFMT_CHANNEL(ch->fmt) - 1); 1826230130Smav 1827230130Smav return (fmt); 1828230130Smav} 1829230130Smav 1830230326Smavstatic int 1831230326Smavhdaa_allowed_stripes(uint16_t fmt) 1832230326Smav{ 1833230326Smav static const int bits[8] = { 8, 16, 20, 24, 32, 32, 32, 32 }; 1834230326Smav int size; 1835230326Smav 1836230326Smav size = bits[(fmt >> 4) & 0x03]; 1837230326Smav size *= (fmt & 0x0f) + 1; 1838230326Smav size *= ((fmt >> 11) & 0x07) + 1; 1839230326Smav return (0xffffffffU >> (32 - fls(size / 8))); 1840230326Smav} 1841230326Smav 1842230130Smavstatic void 1843230130Smavhdaa_audio_setup(struct hdaa_chan *ch) 1844230130Smav{ 1845230130Smav struct hdaa_audio_as *as = &ch->devinfo->as[ch->as]; 1846230312Smav struct hdaa_widget *w, *wp; 1847230312Smav int i, j, k, chn, cchn, totalchn, totalextchn, c; 1848230130Smav uint16_t fmt, dfmt; 1849230312Smav /* Mapping channel pairs to codec pins/converters. */ 1850230312Smav const static uint16_t convmap[2][5] = 1851243181Smav /* 1.0 2.0 4.0 5.1 7.1 */ 1852243181Smav {{ 0x0010, 0x0001, 0x0201, 0x0231, 0x4231 }, /* no dup. */ 1853243181Smav { 0x0010, 0x0001, 0x2201, 0x2231, 0x4231 }}; /* side dup. */ 1854230312Smav /* Mapping formats to HDMI channel allocations. */ 1855230312Smav const static uint8_t hdmica[2][8] = 1856243181Smav /* 1 2 3 4 5 6 7 8 */ 1857230312Smav {{ 0x02, 0x00, 0x04, 0x08, 0x0a, 0x0e, 0x12, 0x12 }, /* x.0 */ 1858230312Smav { 0x01, 0x03, 0x01, 0x03, 0x09, 0x0b, 0x0f, 0x13 }}; /* x.1 */ 1859230312Smav /* Mapping formats to HDMI channels order. */ 1860230312Smav const static uint32_t hdmich[2][8] = 1861243181Smav /* 1 / 5 2 / 6 3 / 7 4 / 8 */ 1862230312Smav {{ 0xFFFF0F00, 0xFFFFFF10, 0xFFF2FF10, 0xFF32FF10, 1863230312Smav 0xFF324F10, 0xF5324F10, 0x54326F10, 0x54326F10 }, /* x.0 */ 1864230312Smav { 0xFFFFF000, 0xFFFF0100, 0xFFFFF210, 0xFFFF2310, 1865230312Smav 0xFF32F410, 0xFF324510, 0xF6324510, 0x76325410 }}; /* x.1 */ 1866230312Smav int convmapid = -1; 1867230312Smav nid_t nid; 1868230312Smav uint8_t csum; 1869230130Smav 1870230130Smav totalchn = AFMT_CHANNEL(ch->fmt); 1871230312Smav totalextchn = AFMT_EXTCHANNEL(ch->fmt); 1872230130Smav HDA_BOOTHVERBOSE( 1873230130Smav device_printf(ch->pdevinfo->dev, 1874230312Smav "PCMDIR_%s: Stream setup fmt=%08x (%d.%d) speed=%d\n", 1875230130Smav (ch->dir == PCMDIR_PLAY) ? "PLAY" : "REC", 1876230312Smav ch->fmt, totalchn - totalextchn, totalextchn, ch->spd); 1877230130Smav ); 1878230130Smav fmt = hdaa_stream_format(ch); 1879230130Smav 1880230312Smav /* Set channels to I/O converters mapping for known speaker setups. */ 1881243181Smav if ((as->pinset == 0x0007 || as->pinset == 0x0013) || /* Standard 5.1 */ 1882243181Smav (as->pinset == 0x0017)) /* Standard 7.1 */ 1883243181Smav convmapid = (ch->dir == PCMDIR_PLAY); 1884230130Smav 1885230130Smav dfmt = HDA_CMD_SET_DIGITAL_CONV_FMT1_DIGEN; 1886230130Smav if (ch->fmt & AFMT_AC3) 1887230130Smav dfmt |= HDA_CMD_SET_DIGITAL_CONV_FMT1_NAUDIO; 1888230130Smav 1889230130Smav chn = 0; 1890230130Smav for (i = 0; ch->io[i] != -1; i++) { 1891230130Smav w = hdaa_widget_get(ch->devinfo, ch->io[i]); 1892230130Smav if (w == NULL) 1893230130Smav continue; 1894230130Smav 1895230130Smav /* If HP redirection is enabled, but failed to use same 1896230130Smav DAC, make last DAC to duplicate first one. */ 1897230130Smav if (as->fakeredir && i == (as->pincnt - 1)) { 1898230130Smav c = (ch->sid << 4); 1899230130Smav } else { 1900230312Smav /* Map channels to I/O converters, if set. */ 1901230312Smav if (convmapid >= 0) 1902230312Smav chn = (((convmap[convmapid][totalchn / 2] 1903230312Smav >> i * 4) & 0xf) - 1) * 2; 1904230130Smav if (chn < 0 || chn >= totalchn) { 1905230130Smav c = 0; 1906230130Smav } else { 1907230130Smav c = (ch->sid << 4) | chn; 1908230130Smav } 1909230130Smav } 1910230130Smav hda_command(ch->devinfo->dev, 1911230130Smav HDA_CMD_SET_CONV_FMT(0, ch->io[i], fmt)); 1912230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) { 1913230130Smav hda_command(ch->devinfo->dev, 1914230130Smav HDA_CMD_SET_DIGITAL_CONV_FMT1(0, ch->io[i], dfmt)); 1915230130Smav } 1916230130Smav hda_command(ch->devinfo->dev, 1917230130Smav HDA_CMD_SET_CONV_STREAM_CHAN(0, ch->io[i], c)); 1918230326Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_STRIPE(w->param.widget_cap)) { 1919230326Smav hda_command(ch->devinfo->dev, 1920230326Smav HDA_CMD_SET_STRIPE_CONTROL(0, w->nid, ch->stripectl)); 1921230326Smav } 1922230312Smav cchn = HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap); 1923230312Smav if (cchn > 1 && chn < totalchn) { 1924230312Smav cchn = min(cchn, totalchn - chn - 1); 1925230312Smav hda_command(ch->devinfo->dev, 1926230312Smav HDA_CMD_SET_CONV_CHAN_COUNT(0, ch->io[i], cchn)); 1927230312Smav } 1928230312Smav HDA_BOOTHVERBOSE( 1929230312Smav device_printf(ch->pdevinfo->dev, 1930230312Smav "PCMDIR_%s: Stream setup nid=%d: " 1931230312Smav "fmt=0x%04x, dfmt=0x%04x, chan=0x%04x, " 1932230326Smav "chan_count=0x%02x, stripe=%d\n", 1933230312Smav (ch->dir == PCMDIR_PLAY) ? "PLAY" : "REC", 1934230326Smav ch->io[i], fmt, dfmt, c, cchn, ch->stripectl); 1935230312Smav ); 1936230312Smav for (j = 0; j < 16; j++) { 1937230312Smav if (as->dacs[ch->asindex][j] != ch->io[i]) 1938230312Smav continue; 1939230312Smav nid = as->pins[j]; 1940230312Smav wp = hdaa_widget_get(ch->devinfo, nid); 1941230312Smav if (wp == NULL) 1942230312Smav continue; 1943230312Smav if (!HDA_PARAM_PIN_CAP_DP(wp->wclass.pin.cap) && 1944230312Smav !HDA_PARAM_PIN_CAP_HDMI(wp->wclass.pin.cap)) 1945230312Smav continue; 1946230312Smav 1947230312Smav /* Set channel mapping. */ 1948230312Smav for (k = 0; k < 8; k++) { 1949230312Smav hda_command(ch->devinfo->dev, 1950230312Smav HDA_CMD_SET_HDMI_CHAN_SLOT(0, nid, 1951230312Smav (((hdmich[totalextchn == 0 ? 0 : 1][totalchn - 1] 1952230312Smav >> (k * 4)) & 0xf) << 4) | k)); 1953230312Smav } 1954230312Smav 1955230511Smav /* 1956230511Smav * Enable High Bit Rate (HBR) Encoded Packet Type 1957230511Smav * (EPT), if supported and needed (8ch data). 1958230511Smav */ 1959230511Smav if (HDA_PARAM_PIN_CAP_HDMI(wp->wclass.pin.cap) && 1960230511Smav HDA_PARAM_PIN_CAP_HBR(wp->wclass.pin.cap)) { 1961230511Smav wp->wclass.pin.ctrl &= 1962230511Smav ~HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK; 1963230641Smav if ((ch->fmt & AFMT_AC3) && (cchn == 7)) 1964230511Smav wp->wclass.pin.ctrl |= 0x03; 1965230511Smav hda_command(ch->devinfo->dev, 1966230511Smav HDA_CMD_SET_PIN_WIDGET_CTRL(0, nid, 1967230511Smav wp->wclass.pin.ctrl)); 1968230511Smav } 1969230511Smav 1970230312Smav /* Stop audio infoframe transmission. */ 1971230312Smav hda_command(ch->devinfo->dev, 1972230312Smav HDA_CMD_SET_HDMI_DIP_INDEX(0, nid, 0x00)); 1973230312Smav hda_command(ch->devinfo->dev, 1974230312Smav HDA_CMD_SET_HDMI_DIP_XMIT(0, nid, 0x00)); 1975230312Smav 1976230312Smav /* Clear audio infoframe buffer. */ 1977230312Smav hda_command(ch->devinfo->dev, 1978230312Smav HDA_CMD_SET_HDMI_DIP_INDEX(0, nid, 0x00)); 1979230312Smav for (k = 0; k < 32; k++) 1980230312Smav hda_command(ch->devinfo->dev, 1981230312Smav HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x00)); 1982230312Smav 1983230312Smav /* Write HDMI/DisplayPort audio infoframe. */ 1984230312Smav hda_command(ch->devinfo->dev, 1985230312Smav HDA_CMD_SET_HDMI_DIP_INDEX(0, nid, 0x00)); 1986230312Smav if (w->eld != NULL && w->eld_len >= 6 && 1987230312Smav ((w->eld[5] >> 2) & 0x3) == 1) { /* DisplayPort */ 1988230312Smav hda_command(ch->devinfo->dev, 1989230312Smav HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x84)); 1990230312Smav hda_command(ch->devinfo->dev, 1991230312Smav HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x1b)); 1992230312Smav hda_command(ch->devinfo->dev, 1993230312Smav HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x44)); 1994230312Smav } else { /* HDMI */ 1995230312Smav hda_command(ch->devinfo->dev, 1996230312Smav HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x84)); 1997230312Smav hda_command(ch->devinfo->dev, 1998230312Smav HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x01)); 1999230312Smav hda_command(ch->devinfo->dev, 2000230312Smav HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x0a)); 2001230312Smav csum = 0; 2002230312Smav csum -= 0x84 + 0x01 + 0x0a + (totalchn - 1) + 2003230312Smav hdmica[totalextchn == 0 ? 0 : 1][totalchn - 1]; 2004230312Smav hda_command(ch->devinfo->dev, 2005230312Smav HDA_CMD_SET_HDMI_DIP_DATA(0, nid, csum)); 2006230312Smav } 2007230312Smav hda_command(ch->devinfo->dev, 2008230312Smav HDA_CMD_SET_HDMI_DIP_DATA(0, nid, totalchn - 1)); 2009230312Smav hda_command(ch->devinfo->dev, 2010230312Smav HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x00)); 2011230312Smav hda_command(ch->devinfo->dev, 2012230312Smav HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x00)); 2013230312Smav hda_command(ch->devinfo->dev, 2014230312Smav HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 2015230312Smav hdmica[totalextchn == 0 ? 0 : 1][totalchn - 1])); 2016230312Smav 2017230312Smav /* Start audio infoframe transmission. */ 2018230312Smav hda_command(ch->devinfo->dev, 2019230312Smav HDA_CMD_SET_HDMI_DIP_INDEX(0, nid, 0x00)); 2020230312Smav hda_command(ch->devinfo->dev, 2021230312Smav HDA_CMD_SET_HDMI_DIP_XMIT(0, nid, 0xc0)); 2022230312Smav } 2023230312Smav chn += cchn + 1; 2024230130Smav } 2025230130Smav} 2026230130Smav 2027230130Smav/* 2028230130Smav * Greatest Common Divisor. 2029230130Smav */ 2030230130Smavstatic unsigned 2031230130Smavgcd(unsigned a, unsigned b) 2032230130Smav{ 2033230130Smav u_int c; 2034230130Smav 2035230130Smav while (b != 0) { 2036230130Smav c = a; 2037230130Smav a = b; 2038230130Smav b = (c % b); 2039230130Smav } 2040230130Smav return (a); 2041230130Smav} 2042230130Smav 2043230130Smav/* 2044230130Smav * Least Common Multiple. 2045230130Smav */ 2046230130Smavstatic unsigned 2047230130Smavlcm(unsigned a, unsigned b) 2048230130Smav{ 2049230130Smav 2050230130Smav return ((a * b) / gcd(a, b)); 2051230130Smav} 2052230130Smav 2053230130Smavstatic int 2054230130Smavhdaa_channel_setfragments(kobj_t obj, void *data, 2055230130Smav uint32_t blksz, uint32_t blkcnt) 2056230130Smav{ 2057230130Smav struct hdaa_chan *ch = data; 2058230130Smav 2059230130Smav blksz -= blksz % lcm(HDA_DMA_ALIGNMENT, sndbuf_getalign(ch->b)); 2060230130Smav 2061230130Smav if (blksz > (sndbuf_getmaxsize(ch->b) / HDA_BDL_MIN)) 2062230130Smav blksz = sndbuf_getmaxsize(ch->b) / HDA_BDL_MIN; 2063230130Smav if (blksz < HDA_BLK_MIN) 2064230130Smav blksz = HDA_BLK_MIN; 2065230130Smav if (blkcnt > HDA_BDL_MAX) 2066230130Smav blkcnt = HDA_BDL_MAX; 2067230130Smav if (blkcnt < HDA_BDL_MIN) 2068230130Smav blkcnt = HDA_BDL_MIN; 2069230130Smav 2070230130Smav while ((blksz * blkcnt) > sndbuf_getmaxsize(ch->b)) { 2071230130Smav if ((blkcnt >> 1) >= HDA_BDL_MIN) 2072230130Smav blkcnt >>= 1; 2073230130Smav else if ((blksz >> 1) >= HDA_BLK_MIN) 2074230130Smav blksz >>= 1; 2075230130Smav else 2076230130Smav break; 2077230130Smav } 2078230130Smav 2079230130Smav if ((sndbuf_getblksz(ch->b) != blksz || 2080230130Smav sndbuf_getblkcnt(ch->b) != blkcnt) && 2081230130Smav sndbuf_resize(ch->b, blkcnt, blksz) != 0) 2082230130Smav device_printf(ch->devinfo->dev, "%s: failed blksz=%u blkcnt=%u\n", 2083230130Smav __func__, blksz, blkcnt); 2084230130Smav 2085230130Smav ch->blksz = sndbuf_getblksz(ch->b); 2086230130Smav ch->blkcnt = sndbuf_getblkcnt(ch->b); 2087230130Smav 2088230130Smav return (0); 2089230130Smav} 2090230130Smav 2091230130Smavstatic uint32_t 2092230130Smavhdaa_channel_setblocksize(kobj_t obj, void *data, uint32_t blksz) 2093230130Smav{ 2094230130Smav struct hdaa_chan *ch = data; 2095230130Smav 2096230130Smav hdaa_channel_setfragments(obj, data, blksz, ch->pdevinfo->chan_blkcnt); 2097230130Smav 2098230130Smav return (ch->blksz); 2099230130Smav} 2100230130Smav 2101230130Smavstatic void 2102230130Smavhdaa_channel_stop(struct hdaa_chan *ch) 2103230130Smav{ 2104230130Smav struct hdaa_devinfo *devinfo = ch->devinfo; 2105230130Smav struct hdaa_widget *w; 2106230130Smav int i; 2107230130Smav 2108230181Smav if ((ch->flags & HDAA_CHN_RUNNING) == 0) 2109230181Smav return; 2110230130Smav ch->flags &= ~HDAA_CHN_RUNNING; 2111230130Smav HDAC_STREAM_STOP(device_get_parent(devinfo->dev), devinfo->dev, 2112230130Smav ch->dir == PCMDIR_PLAY ? 1 : 0, ch->sid); 2113230130Smav for (i = 0; ch->io[i] != -1; i++) { 2114230130Smav w = hdaa_widget_get(ch->devinfo, ch->io[i]); 2115230130Smav if (w == NULL) 2116230130Smav continue; 2117230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) { 2118230130Smav hda_command(devinfo->dev, 2119230130Smav HDA_CMD_SET_DIGITAL_CONV_FMT1(0, ch->io[i], 0)); 2120230130Smav } 2121230130Smav hda_command(devinfo->dev, 2122230130Smav HDA_CMD_SET_CONV_STREAM_CHAN(0, ch->io[i], 2123230130Smav 0)); 2124230130Smav } 2125230130Smav HDAC_STREAM_FREE(device_get_parent(devinfo->dev), devinfo->dev, 2126230130Smav ch->dir == PCMDIR_PLAY ? 1 : 0, ch->sid); 2127230130Smav} 2128230130Smav 2129230130Smavstatic int 2130230130Smavhdaa_channel_start(struct hdaa_chan *ch) 2131230130Smav{ 2132230130Smav struct hdaa_devinfo *devinfo = ch->devinfo; 2133230326Smav uint32_t fmt; 2134230130Smav 2135230326Smav fmt = hdaa_stream_format(ch); 2136230326Smav ch->stripectl = fls(ch->stripecap & hdaa_allowed_stripes(fmt)) - 1; 2137230130Smav ch->sid = HDAC_STREAM_ALLOC(device_get_parent(devinfo->dev), devinfo->dev, 2138230326Smav ch->dir == PCMDIR_PLAY ? 1 : 0, fmt, ch->stripectl, &ch->dmapos); 2139230130Smav if (ch->sid <= 0) 2140230130Smav return (EBUSY); 2141230130Smav hdaa_audio_setup(ch); 2142230130Smav HDAC_STREAM_RESET(device_get_parent(devinfo->dev), devinfo->dev, 2143230130Smav ch->dir == PCMDIR_PLAY ? 1 : 0, ch->sid); 2144230130Smav HDAC_STREAM_START(device_get_parent(devinfo->dev), devinfo->dev, 2145230130Smav ch->dir == PCMDIR_PLAY ? 1 : 0, ch->sid, 2146230130Smav sndbuf_getbufaddr(ch->b), ch->blksz, ch->blkcnt); 2147230130Smav ch->flags |= HDAA_CHN_RUNNING; 2148230130Smav return (0); 2149230130Smav} 2150230130Smav 2151230130Smavstatic int 2152230130Smavhdaa_channel_trigger(kobj_t obj, void *data, int go) 2153230130Smav{ 2154230130Smav struct hdaa_chan *ch = data; 2155230130Smav int error = 0; 2156230130Smav 2157230130Smav if (!PCMTRIG_COMMON(go)) 2158230130Smav return (0); 2159230130Smav 2160230130Smav hdaa_lock(ch->devinfo); 2161230130Smav switch (go) { 2162230130Smav case PCMTRIG_START: 2163230130Smav error = hdaa_channel_start(ch); 2164230130Smav break; 2165230130Smav case PCMTRIG_STOP: 2166230130Smav case PCMTRIG_ABORT: 2167230130Smav hdaa_channel_stop(ch); 2168230130Smav break; 2169230130Smav default: 2170230130Smav break; 2171230130Smav } 2172230130Smav hdaa_unlock(ch->devinfo); 2173230130Smav 2174230130Smav return (error); 2175230130Smav} 2176230130Smav 2177230130Smavstatic uint32_t 2178230130Smavhdaa_channel_getptr(kobj_t obj, void *data) 2179230130Smav{ 2180230130Smav struct hdaa_chan *ch = data; 2181230130Smav struct hdaa_devinfo *devinfo = ch->devinfo; 2182230130Smav uint32_t ptr; 2183230130Smav 2184230130Smav hdaa_lock(devinfo); 2185230130Smav if (ch->dmapos != NULL) { 2186230130Smav ptr = *(ch->dmapos); 2187230130Smav } else { 2188230130Smav ptr = HDAC_STREAM_GETPTR( 2189230130Smav device_get_parent(devinfo->dev), devinfo->dev, 2190230130Smav ch->dir == PCMDIR_PLAY ? 1 : 0, ch->sid); 2191230130Smav } 2192230130Smav hdaa_unlock(devinfo); 2193230130Smav 2194230130Smav /* 2195230130Smav * Round to available space and force 128 bytes aligment. 2196230130Smav */ 2197230130Smav ptr %= ch->blksz * ch->blkcnt; 2198230130Smav ptr &= HDA_BLK_ALIGN; 2199230130Smav 2200230130Smav return (ptr); 2201230130Smav} 2202230130Smav 2203230130Smavstatic struct pcmchan_caps * 2204230130Smavhdaa_channel_getcaps(kobj_t obj, void *data) 2205230130Smav{ 2206230130Smav return (&((struct hdaa_chan *)data)->caps); 2207230130Smav} 2208230130Smav 2209230130Smavstatic kobj_method_t hdaa_channel_methods[] = { 2210230130Smav KOBJMETHOD(channel_init, hdaa_channel_init), 2211230130Smav KOBJMETHOD(channel_setformat, hdaa_channel_setformat), 2212230130Smav KOBJMETHOD(channel_setspeed, hdaa_channel_setspeed), 2213230130Smav KOBJMETHOD(channel_setblocksize, hdaa_channel_setblocksize), 2214230130Smav KOBJMETHOD(channel_setfragments, hdaa_channel_setfragments), 2215230130Smav KOBJMETHOD(channel_trigger, hdaa_channel_trigger), 2216230130Smav KOBJMETHOD(channel_getptr, hdaa_channel_getptr), 2217230130Smav KOBJMETHOD(channel_getcaps, hdaa_channel_getcaps), 2218230130Smav KOBJMETHOD_END 2219230130Smav}; 2220230130SmavCHANNEL_DECLARE(hdaa_channel); 2221230130Smav 2222230130Smavstatic int 2223230130Smavhdaa_audio_ctl_ossmixer_init(struct snd_mixer *m) 2224230130Smav{ 2225230130Smav struct hdaa_pcm_devinfo *pdevinfo = mix_getdevinfo(m); 2226230130Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 2227230130Smav struct hdaa_widget *w, *cw; 2228230130Smav uint32_t mask, recmask; 2229230451Smav int i, j; 2230230130Smav 2231230130Smav hdaa_lock(devinfo); 2232230451Smav pdevinfo->mixer = m; 2233230130Smav 2234230130Smav /* Make sure that in case of soft volume it won't stay muted. */ 2235230130Smav for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) { 2236230130Smav pdevinfo->left[i] = 100; 2237230130Smav pdevinfo->right[i] = 100; 2238230130Smav } 2239230130Smav 2240230451Smav /* Declare volume controls assigned to this association. */ 2241230451Smav mask = pdevinfo->ossmask; 2242230130Smav if (pdevinfo->playas >= 0) { 2243230451Smav /* Declate EAPD as ogain control. */ 2244230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 2245230130Smav w = hdaa_widget_get(devinfo, i); 2246230130Smav if (w == NULL || w->enable == 0) 2247230130Smav continue; 2248230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX || 2249230130Smav w->param.eapdbtl == HDA_INVALID || 2250230130Smav w->bindas != pdevinfo->playas) 2251230130Smav continue; 2252230130Smav mask |= SOUND_MASK_OGAIN; 2253230130Smav break; 2254230130Smav } 2255230130Smav 2256230451Smav /* Declare soft PCM volume if needed. */ 2257230451Smav if ((mask & SOUND_MASK_PCM) == 0 || 2258230451Smav (devinfo->quirks & HDAA_QUIRK_SOFTPCMVOL) || 2259230451Smav pdevinfo->minamp[SOUND_MIXER_PCM] == 2260230451Smav pdevinfo->maxamp[SOUND_MIXER_PCM]) { 2261230451Smav mask |= SOUND_MASK_PCM; 2262230451Smav pcm_setflags(pdevinfo->dev, pcm_getflags(pdevinfo->dev) | SD_F_SOFTPCMVOL); 2263230451Smav HDA_BOOTHVERBOSE( 2264230451Smav device_printf(pdevinfo->dev, 2265230451Smav "Forcing Soft PCM volume\n"); 2266230451Smav ); 2267230451Smav } 2268230451Smav 2269230451Smav /* Declare master volume if needed. */ 2270230451Smav if ((mask & SOUND_MASK_VOLUME) == 0) { 2271230451Smav mask |= SOUND_MASK_VOLUME; 2272230451Smav mix_setparentchild(m, SOUND_MIXER_VOLUME, 2273230451Smav SOUND_MASK_PCM); 2274230451Smav mix_setrealdev(m, SOUND_MIXER_VOLUME, 2275230451Smav SOUND_MIXER_NONE); 2276230451Smav HDA_BOOTHVERBOSE( 2277230451Smav device_printf(pdevinfo->dev, 2278230451Smav "Forcing master volume with PCM\n"); 2279230451Smav ); 2280230451Smav } 2281230130Smav } 2282230130Smav 2283230130Smav /* Declare record sources available to this association. */ 2284230451Smav recmask = 0; 2285230130Smav if (pdevinfo->recas >= 0) { 2286230130Smav for (i = 0; i < 16; i++) { 2287230130Smav if (devinfo->as[pdevinfo->recas].dacs[0][i] < 0) 2288230130Smav continue; 2289230130Smav w = hdaa_widget_get(devinfo, 2290230130Smav devinfo->as[pdevinfo->recas].dacs[0][i]); 2291230130Smav if (w == NULL || w->enable == 0) 2292230130Smav continue; 2293230130Smav for (j = 0; j < w->nconns; j++) { 2294230130Smav if (w->connsenable[j] == 0) 2295230130Smav continue; 2296230130Smav cw = hdaa_widget_get(devinfo, w->conns[j]); 2297230130Smav if (cw == NULL || cw->enable == 0) 2298230130Smav continue; 2299230130Smav if (cw->bindas != pdevinfo->recas && 2300230130Smav cw->bindas != -2) 2301230130Smav continue; 2302230130Smav recmask |= cw->ossmask; 2303230130Smav } 2304230130Smav } 2305230130Smav } 2306230130Smav 2307230451Smav recmask &= (1 << SOUND_MIXER_NRDEVICES) - 1; 2308230451Smav mask &= (1 << SOUND_MIXER_NRDEVICES) - 1; 2309230451Smav pdevinfo->ossmask = mask; 2310230451Smav 2311230451Smav mix_setrecdevs(m, recmask); 2312230451Smav mix_setdevs(m, mask); 2313230451Smav 2314230451Smav hdaa_unlock(devinfo); 2315230451Smav 2316230451Smav return (0); 2317230451Smav} 2318230451Smav 2319230451Smav/* 2320230451Smav * Update amplification per pdevinfo per ossdev, calculate summary coefficient 2321230451Smav * and write it to codec, update *left and *right to reflect remaining error. 2322230451Smav */ 2323230451Smavstatic void 2324230451Smavhdaa_audio_ctl_dev_set(struct hdaa_audio_ctl *ctl, int ossdev, 2325230451Smav int mute, int *left, int *right) 2326230451Smav{ 2327230451Smav int i, zleft, zright, sleft, sright, smute, lval, rval; 2328230451Smav 2329230451Smav ctl->devleft[ossdev] = *left; 2330230451Smav ctl->devright[ossdev] = *right; 2331230451Smav ctl->devmute[ossdev] = mute; 2332230451Smav smute = sleft = sright = zleft = zright = 0; 2333230451Smav for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) { 2334230451Smav sleft += ctl->devleft[i]; 2335230451Smav sright += ctl->devright[i]; 2336230451Smav smute |= ctl->devmute[i]; 2337230451Smav if (i == ossdev) 2338230451Smav continue; 2339230451Smav zleft += ctl->devleft[i]; 2340230451Smav zright += ctl->devright[i]; 2341230451Smav } 2342230451Smav lval = QDB2VAL(ctl, sleft); 2343230451Smav rval = QDB2VAL(ctl, sright); 2344230451Smav hdaa_audio_ctl_amp_set(ctl, smute, lval, rval); 2345230451Smav *left -= VAL2QDB(ctl, lval) - VAL2QDB(ctl, QDB2VAL(ctl, zleft)); 2346230451Smav *right -= VAL2QDB(ctl, rval) - VAL2QDB(ctl, QDB2VAL(ctl, zright)); 2347230451Smav} 2348230451Smav 2349230451Smav/* 2350230451Smav * Trace signal from source, setting volumes on the way. 2351230451Smav */ 2352230451Smavstatic void 2353230451Smavhdaa_audio_ctl_source_volume(struct hdaa_pcm_devinfo *pdevinfo, 2354230451Smav int ossdev, nid_t nid, int index, int mute, int left, int right, int depth) 2355230451Smav{ 2356230451Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 2357230451Smav struct hdaa_widget *w, *wc; 2358230451Smav struct hdaa_audio_ctl *ctl; 2359230451Smav int i, j, conns = 0; 2360230451Smav 2361230451Smav if (depth > HDA_PARSE_MAXDEPTH) 2362230451Smav return; 2363230451Smav 2364230451Smav w = hdaa_widget_get(devinfo, nid); 2365230451Smav if (w == NULL || w->enable == 0) 2366230451Smav return; 2367230451Smav 2368230451Smav /* Count number of active inputs. */ 2369230451Smav if (depth > 0) { 2370230451Smav for (j = 0; j < w->nconns; j++) { 2371230451Smav if (!w->connsenable[j]) 2372230451Smav continue; 2373230451Smav conns++; 2374230130Smav } 2375230451Smav } 2376230130Smav 2377230451Smav /* If this is not a first step - use input mixer. 2378230451Smav Pins have common input ctl so care must be taken. */ 2379230451Smav if (depth > 0 && (conns == 1 || 2380230451Smav w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)) { 2381230451Smav ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, HDAA_CTL_IN, 2382230451Smav index, 1); 2383230451Smav if (ctl) 2384230451Smav hdaa_audio_ctl_dev_set(ctl, ossdev, mute, &left, &right); 2385230451Smav } 2386230451Smav 2387230451Smav /* If widget has own ossdev - not traverse it. 2388230451Smav It will be traversed on it's own. */ 2389230451Smav if (w->ossdev >= 0 && depth > 0) 2390230451Smav return; 2391230451Smav 2392230451Smav /* We must not traverse pin */ 2393230451Smav if ((w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT || 2394230451Smav w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) && 2395230451Smav depth > 0) 2396230451Smav return; 2397230451Smav 2398230451Smav /* 2399230451Smav * If signals mixed, we can't assign controls farther. 2400230451Smav * Ignore this on depth zero. Caller must knows why. 2401230451Smav */ 2402230451Smav if (conns > 1 && 2403230451Smav (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER || 2404230451Smav w->selconn != index)) 2405230451Smav return; 2406230451Smav 2407230451Smav ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, HDAA_CTL_OUT, -1, 1); 2408230451Smav if (ctl) 2409230451Smav hdaa_audio_ctl_dev_set(ctl, ossdev, mute, &left, &right); 2410230451Smav 2411230451Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 2412230451Smav wc = hdaa_widget_get(devinfo, i); 2413230451Smav if (wc == NULL || wc->enable == 0) 2414230451Smav continue; 2415230451Smav for (j = 0; j < wc->nconns; j++) { 2416230451Smav if (wc->connsenable[j] && wc->conns[j] == nid) { 2417230451Smav hdaa_audio_ctl_source_volume(pdevinfo, ossdev, 2418230451Smav wc->nid, j, mute, left, right, depth + 1); 2419230451Smav } 2420230130Smav } 2421230130Smav } 2422230451Smav return; 2423230451Smav} 2424230130Smav 2425230451Smav/* 2426230451Smav * Trace signal from destination, setting volumes on the way. 2427230451Smav */ 2428230451Smavstatic void 2429230451Smavhdaa_audio_ctl_dest_volume(struct hdaa_pcm_devinfo *pdevinfo, 2430230451Smav int ossdev, nid_t nid, int index, int mute, int left, int right, int depth) 2431230451Smav{ 2432230451Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 2433230451Smav struct hdaa_audio_as *as = devinfo->as; 2434230451Smav struct hdaa_widget *w, *wc; 2435230451Smav struct hdaa_audio_ctl *ctl; 2436230451Smav int i, j, consumers, cleft, cright; 2437230451Smav 2438230451Smav if (depth > HDA_PARSE_MAXDEPTH) 2439230451Smav return; 2440230451Smav 2441230451Smav w = hdaa_widget_get(devinfo, nid); 2442230451Smav if (w == NULL || w->enable == 0) 2443230451Smav return; 2444230451Smav 2445230451Smav if (depth > 0) { 2446230451Smav /* If this node produce output for several consumers, 2447230451Smav we can't touch it. */ 2448230451Smav consumers = 0; 2449230451Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 2450230451Smav wc = hdaa_widget_get(devinfo, i); 2451230451Smav if (wc == NULL || wc->enable == 0) 2452230451Smav continue; 2453230451Smav for (j = 0; j < wc->nconns; j++) { 2454230451Smav if (wc->connsenable[j] && wc->conns[j] == nid) 2455230451Smav consumers++; 2456230451Smav } 2457230130Smav } 2458230451Smav /* The only exception is if real HP redirection is configured 2459230451Smav and this is a duplication point. 2460230451Smav XXX: Actually exception is not completely correct. 2461230451Smav XXX: Duplication point check is not perfect. */ 2462230451Smav if ((consumers == 2 && (w->bindas < 0 || 2463230451Smav as[w->bindas].hpredir < 0 || as[w->bindas].fakeredir || 2464230451Smav (w->bindseqmask & (1 << 15)) == 0)) || 2465230451Smav consumers > 2) 2466230451Smav return; 2467230451Smav 2468230451Smav /* Else use it's output mixer. */ 2469230451Smav ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, 2470230451Smav HDAA_CTL_OUT, -1, 1); 2471230451Smav if (ctl) 2472230451Smav hdaa_audio_ctl_dev_set(ctl, ossdev, mute, &left, &right); 2473230130Smav } 2474230130Smav 2475230451Smav /* We must not traverse pin */ 2476230451Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX && 2477230451Smav depth > 0) 2478230451Smav return; 2479230130Smav 2480230451Smav for (i = 0; i < w->nconns; i++) { 2481230451Smav if (w->connsenable[i] == 0) 2482230451Smav continue; 2483230451Smav if (index >= 0 && i != index) 2484230451Smav continue; 2485230451Smav cleft = left; 2486230451Smav cright = right; 2487230451Smav ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, 2488230451Smav HDAA_CTL_IN, i, 1); 2489230451Smav if (ctl) 2490230451Smav hdaa_audio_ctl_dev_set(ctl, ossdev, mute, &cleft, &cright); 2491230451Smav hdaa_audio_ctl_dest_volume(pdevinfo, ossdev, w->conns[i], -1, 2492230451Smav mute, cleft, cright, depth + 1); 2493230451Smav } 2494230451Smav} 2495230130Smav 2496230451Smav/* 2497230451Smav * Set volumes for the specified pdevinfo and ossdev. 2498230451Smav */ 2499230451Smavstatic void 2500230451Smavhdaa_audio_ctl_dev_volume(struct hdaa_pcm_devinfo *pdevinfo, unsigned dev) 2501230451Smav{ 2502230451Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 2503230451Smav struct hdaa_widget *w, *cw; 2504230451Smav uint32_t mute; 2505230451Smav int lvol, rvol; 2506230451Smav int i, j; 2507230130Smav 2508230451Smav mute = 0; 2509230451Smav if (pdevinfo->left[dev] == 0) { 2510230451Smav mute |= HDAA_AMP_MUTE_LEFT; 2511230451Smav lvol = -4000; 2512230451Smav } else 2513230451Smav lvol = ((pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]) * 2514230451Smav pdevinfo->left[dev] + 50) / 100 + pdevinfo->minamp[dev]; 2515230451Smav if (pdevinfo->right[dev] == 0) { 2516230451Smav mute |= HDAA_AMP_MUTE_RIGHT; 2517230451Smav rvol = -4000; 2518230451Smav } else 2519230451Smav rvol = ((pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]) * 2520230451Smav pdevinfo->right[dev] + 50) / 100 + pdevinfo->minamp[dev]; 2521230451Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 2522230451Smav w = hdaa_widget_get(devinfo, i); 2523230451Smav if (w == NULL || w->enable == 0) 2524230451Smav continue; 2525239326Smav if (w->bindas < 0) { 2526239326Smav if (pdevinfo->index != 0) 2527239326Smav continue; 2528239326Smav } else { 2529239326Smav if (w->bindas != pdevinfo->playas && 2530239326Smav w->bindas != pdevinfo->recas) 2531239326Smav continue; 2532239326Smav } 2533230451Smav if (dev == SOUND_MIXER_RECLEV && 2534230451Smav w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) { 2535230451Smav hdaa_audio_ctl_dest_volume(pdevinfo, dev, 2536230451Smav w->nid, -1, mute, lvol, rvol, 0); 2537230451Smav continue; 2538230451Smav } 2539230451Smav if (dev == SOUND_MIXER_VOLUME && 2540230451Smav w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX && 2541230451Smav devinfo->as[w->bindas].dir == HDAA_CTL_OUT) { 2542230451Smav hdaa_audio_ctl_dest_volume(pdevinfo, dev, 2543230451Smav w->nid, -1, mute, lvol, rvol, 0); 2544230451Smav continue; 2545230451Smav } 2546230451Smav if (dev == SOUND_MIXER_IGAIN && 2547230451Smav w->pflags & HDAA_ADC_MONITOR) { 2548230451Smav for (j = 0; j < w->nconns; j++) { 2549230451Smav if (!w->connsenable[j]) 2550230451Smav continue; 2551230451Smav cw = hdaa_widget_get(devinfo, w->conns[j]); 2552230451Smav if (cw == NULL || cw->enable == 0) 2553230451Smav continue; 2554230451Smav if (cw->bindas == -1) 2555230451Smav continue; 2556230451Smav if (cw->bindas >= 0 && 2557230451Smav devinfo->as[cw->bindas].dir != HDAA_CTL_IN) 2558230451Smav continue; 2559230451Smav hdaa_audio_ctl_dest_volume(pdevinfo, dev, 2560230451Smav w->nid, j, mute, lvol, rvol, 0); 2561230451Smav } 2562230451Smav continue; 2563230451Smav } 2564230451Smav if (w->ossdev != dev) 2565230451Smav continue; 2566230451Smav hdaa_audio_ctl_source_volume(pdevinfo, dev, 2567230451Smav w->nid, -1, mute, lvol, rvol, 0); 2568230451Smav if (dev == SOUND_MIXER_IMIX && (w->pflags & HDAA_IMIX_AS_DST)) 2569230451Smav hdaa_audio_ctl_dest_volume(pdevinfo, dev, 2570230451Smav w->nid, -1, mute, lvol, rvol, 0); 2571230451Smav } 2572230130Smav} 2573230130Smav 2574230451Smav/* 2575230451Smav * OSS Mixer set method. 2576230451Smav */ 2577230130Smavstatic int 2578230130Smavhdaa_audio_ctl_ossmixer_set(struct snd_mixer *m, unsigned dev, 2579230130Smav unsigned left, unsigned right) 2580230130Smav{ 2581230130Smav struct hdaa_pcm_devinfo *pdevinfo = mix_getdevinfo(m); 2582230130Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 2583230130Smav struct hdaa_widget *w; 2584230451Smav int i; 2585230130Smav 2586230130Smav hdaa_lock(devinfo); 2587230451Smav 2588230130Smav /* Save new values. */ 2589230130Smav pdevinfo->left[dev] = left; 2590230130Smav pdevinfo->right[dev] = right; 2591230130Smav 2592230130Smav /* 'ogain' is the special case implemented with EAPD. */ 2593230130Smav if (dev == SOUND_MIXER_OGAIN) { 2594230130Smav uint32_t orig; 2595230130Smav w = NULL; 2596230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 2597230130Smav w = hdaa_widget_get(devinfo, i); 2598230130Smav if (w == NULL || w->enable == 0) 2599230130Smav continue; 2600230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX || 2601230130Smav w->param.eapdbtl == HDA_INVALID) 2602230130Smav continue; 2603230130Smav break; 2604230130Smav } 2605230130Smav if (i >= devinfo->endnode) { 2606230130Smav hdaa_unlock(devinfo); 2607230130Smav return (-1); 2608230130Smav } 2609230130Smav orig = w->param.eapdbtl; 2610230130Smav if (left == 0) 2611230130Smav w->param.eapdbtl &= ~HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD; 2612230130Smav else 2613230130Smav w->param.eapdbtl |= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD; 2614230130Smav if (orig != w->param.eapdbtl) { 2615230130Smav uint32_t val; 2616230130Smav 2617230130Smav val = w->param.eapdbtl; 2618230130Smav if (devinfo->quirks & HDAA_QUIRK_EAPDINV) 2619230130Smav val ^= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD; 2620230130Smav hda_command(devinfo->dev, 2621230130Smav HDA_CMD_SET_EAPD_BTL_ENABLE(0, w->nid, val)); 2622230130Smav } 2623230130Smav hdaa_unlock(devinfo); 2624230130Smav return (left | (left << 8)); 2625230130Smav } 2626230130Smav 2627230130Smav /* Recalculate all controls related to this OSS device. */ 2628230451Smav hdaa_audio_ctl_dev_volume(pdevinfo, dev); 2629230451Smav 2630230451Smav hdaa_unlock(devinfo); 2631230451Smav return (left | (right << 8)); 2632230451Smav} 2633230451Smav 2634230451Smav/* 2635230451Smav * Set mixer settings to our own default values: 2636230451Smav * +20dB for mics, -10dB for analog vol, mute for igain, 0dB for others. 2637230451Smav */ 2638230451Smavstatic void 2639230451Smavhdaa_audio_ctl_set_defaults(struct hdaa_pcm_devinfo *pdevinfo) 2640230451Smav{ 2641230451Smav int amp, vol, dev; 2642230451Smav 2643230451Smav for (dev = 0; dev < SOUND_MIXER_NRDEVICES; dev++) { 2644230451Smav if ((pdevinfo->ossmask & (1 << dev)) == 0) 2645230130Smav continue; 2646230451Smav 2647230451Smav /* If the value was overriden, leave it as is. */ 2648230451Smav if (resource_int_value(device_get_name(pdevinfo->dev), 2649230451Smav device_get_unit(pdevinfo->dev), ossnames[dev], &vol) == 0) 2650230130Smav continue; 2651230130Smav 2652230451Smav vol = -1; 2653230451Smav if (dev == SOUND_MIXER_OGAIN) 2654230451Smav vol = 100; 2655230451Smav else if (dev == SOUND_MIXER_IGAIN) 2656230451Smav vol = 0; 2657230451Smav else if (dev == SOUND_MIXER_MIC || 2658230451Smav dev == SOUND_MIXER_MONITOR) 2659230451Smav amp = 20 * 4; /* +20dB */ 2660230451Smav else if (dev == SOUND_MIXER_VOLUME && !pdevinfo->digital) 2661230451Smav amp = -10 * 4; /* -10dB */ 2662230451Smav else 2663230451Smav amp = 0; 2664230451Smav if (vol < 0 && 2665230451Smav (pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]) <= 0) { 2666230451Smav vol = 100; 2667230451Smav } else if (vol < 0) { 2668230451Smav vol = ((amp - pdevinfo->minamp[dev]) * 100 + 2669230451Smav (pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]) / 2) / 2670230451Smav (pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]); 2671230451Smav vol = imin(imax(vol, 1), 100); 2672230130Smav } 2673230451Smav mix_set(pdevinfo->mixer, dev, vol, vol); 2674230130Smav } 2675230130Smav} 2676230130Smav 2677230130Smav/* 2678230451Smav * Recursively commutate specified record source. 2679230130Smav */ 2680230130Smavstatic uint32_t 2681230130Smavhdaa_audio_ctl_recsel_comm(struct hdaa_pcm_devinfo *pdevinfo, uint32_t src, nid_t nid, int depth) 2682230130Smav{ 2683230130Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 2684230130Smav struct hdaa_widget *w, *cw; 2685230130Smav struct hdaa_audio_ctl *ctl; 2686230130Smav char buf[64]; 2687230130Smav int i, muted; 2688230130Smav uint32_t res = 0; 2689230130Smav 2690230130Smav if (depth > HDA_PARSE_MAXDEPTH) 2691230130Smav return (0); 2692230130Smav 2693230130Smav w = hdaa_widget_get(devinfo, nid); 2694230130Smav if (w == NULL || w->enable == 0) 2695230130Smav return (0); 2696230130Smav 2697230130Smav for (i = 0; i < w->nconns; i++) { 2698230130Smav if (w->connsenable[i] == 0) 2699230130Smav continue; 2700230130Smav cw = hdaa_widget_get(devinfo, w->conns[i]); 2701230130Smav if (cw == NULL || cw->enable == 0 || cw->bindas == -1) 2702230130Smav continue; 2703230130Smav /* Call recursively to trace signal to it's source if needed. */ 2704230130Smav if ((src & cw->ossmask) != 0) { 2705230130Smav if (cw->ossdev < 0) { 2706230130Smav res |= hdaa_audio_ctl_recsel_comm(pdevinfo, src, 2707230130Smav w->conns[i], depth + 1); 2708230130Smav } else { 2709230130Smav res |= cw->ossmask; 2710230130Smav } 2711230130Smav } 2712230130Smav /* We have two special cases: mixers and others (selectors). */ 2713230130Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) { 2714230130Smav ctl = hdaa_audio_ctl_amp_get(devinfo, 2715230130Smav w->nid, HDAA_CTL_IN, i, 1); 2716230130Smav if (ctl == NULL) 2717230130Smav continue; 2718230130Smav /* If we have input control on this node mute them 2719230130Smav * according to requested sources. */ 2720230130Smav muted = (src & cw->ossmask) ? 0 : 1; 2721230130Smav if (muted != ctl->forcemute) { 2722230130Smav ctl->forcemute = muted; 2723230130Smav hdaa_audio_ctl_amp_set(ctl, 2724230130Smav HDAA_AMP_MUTE_DEFAULT, 2725230130Smav HDAA_AMP_VOL_DEFAULT, HDAA_AMP_VOL_DEFAULT); 2726230130Smav } 2727230130Smav HDA_BOOTHVERBOSE( 2728230130Smav device_printf(pdevinfo->dev, 2729230130Smav "Recsel (%s): nid %d source %d %s\n", 2730230130Smav hdaa_audio_ctl_ossmixer_mask2allname( 2731230130Smav src, buf, sizeof(buf)), 2732230130Smav nid, i, muted?"mute":"unmute"); 2733230130Smav ); 2734230130Smav } else { 2735230130Smav if (w->nconns == 1) 2736230130Smav break; 2737230130Smav if ((src & cw->ossmask) == 0) 2738230130Smav continue; 2739230130Smav /* If we found requested source - select it and exit. */ 2740230130Smav hdaa_widget_connection_select(w, i); 2741230130Smav HDA_BOOTHVERBOSE( 2742230130Smav device_printf(pdevinfo->dev, 2743230130Smav "Recsel (%s): nid %d source %d select\n", 2744230130Smav hdaa_audio_ctl_ossmixer_mask2allname( 2745230130Smav src, buf, sizeof(buf)), 2746230130Smav nid, i); 2747230130Smav ); 2748230130Smav break; 2749230130Smav } 2750230130Smav } 2751230130Smav return (res); 2752230130Smav} 2753230130Smav 2754230130Smavstatic uint32_t 2755230130Smavhdaa_audio_ctl_ossmixer_setrecsrc(struct snd_mixer *m, uint32_t src) 2756230130Smav{ 2757230130Smav struct hdaa_pcm_devinfo *pdevinfo = mix_getdevinfo(m); 2758230130Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 2759230130Smav struct hdaa_widget *w; 2760230130Smav struct hdaa_audio_as *as; 2761230451Smav struct hdaa_audio_ctl *ctl; 2762230130Smav struct hdaa_chan *ch; 2763230130Smav int i, j; 2764230130Smav uint32_t ret = 0xffffffff; 2765230130Smav 2766230130Smav hdaa_lock(devinfo); 2767230130Smav if (pdevinfo->recas < 0) { 2768230130Smav hdaa_unlock(devinfo); 2769230130Smav return (0); 2770230130Smav } 2771230130Smav as = &devinfo->as[pdevinfo->recas]; 2772230130Smav 2773230130Smav /* For non-mixed associations we always recording everything. */ 2774230130Smav if (!as->mixed) { 2775230130Smav hdaa_unlock(devinfo); 2776230130Smav return (mix_getrecdevs(m)); 2777230130Smav } 2778230130Smav 2779230130Smav /* Commutate requested recsrc for each ADC. */ 2780230130Smav for (j = 0; j < as->num_chans; j++) { 2781230130Smav ch = &devinfo->chans[as->chans[j]]; 2782230130Smav for (i = 0; ch->io[i] >= 0; i++) { 2783230130Smav w = hdaa_widget_get(devinfo, ch->io[i]); 2784230130Smav if (w == NULL || w->enable == 0) 2785230130Smav continue; 2786230130Smav ret &= hdaa_audio_ctl_recsel_comm(pdevinfo, src, 2787230130Smav ch->io[i], 0); 2788230130Smav } 2789230130Smav } 2790230451Smav if (ret == 0xffffffff) 2791230451Smav ret = 0; 2792230130Smav 2793230451Smav /* 2794230451Smav * Some controls could be shared. Reset volumes for controls 2795230451Smav * related to previously chosen devices, as they may no longer 2796230451Smav * affect the signal. 2797230451Smav */ 2798230451Smav i = 0; 2799230451Smav while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) { 2800230451Smav if (ctl->enable == 0 || 2801230451Smav !(ctl->ossmask & pdevinfo->recsrc)) 2802230451Smav continue; 2803230451Smav if (!((pdevinfo->playas >= 0 && 2804230451Smav ctl->widget->bindas == pdevinfo->playas) || 2805230451Smav (pdevinfo->recas >= 0 && 2806230451Smav ctl->widget->bindas == pdevinfo->recas) || 2807230451Smav (pdevinfo->index == 0 && 2808230451Smav ctl->widget->bindas == -2))) 2809230451Smav continue; 2810230451Smav for (j = 0; j < SOUND_MIXER_NRDEVICES; j++) { 2811230451Smav if (pdevinfo->recsrc & (1 << j)) { 2812230451Smav ctl->devleft[j] = 0; 2813230451Smav ctl->devright[j] = 0; 2814230451Smav ctl->devmute[j] = 0; 2815230451Smav } 2816230451Smav } 2817230451Smav } 2818230451Smav 2819230451Smav /* 2820230451Smav * Some controls could be shared. Set volumes for controls 2821230451Smav * related to devices selected both previously and now. 2822230451Smav */ 2823230451Smav for (j = 0; j < SOUND_MIXER_NRDEVICES; j++) { 2824230451Smav if ((ret | pdevinfo->recsrc) & (1 << j)) 2825230451Smav hdaa_audio_ctl_dev_volume(pdevinfo, j); 2826230451Smav } 2827230451Smav 2828230451Smav pdevinfo->recsrc = ret; 2829230130Smav hdaa_unlock(devinfo); 2830230451Smav return (ret); 2831230130Smav} 2832230130Smav 2833230130Smavstatic kobj_method_t hdaa_audio_ctl_ossmixer_methods[] = { 2834230130Smav KOBJMETHOD(mixer_init, hdaa_audio_ctl_ossmixer_init), 2835230130Smav KOBJMETHOD(mixer_set, hdaa_audio_ctl_ossmixer_set), 2836230130Smav KOBJMETHOD(mixer_setrecsrc, hdaa_audio_ctl_ossmixer_setrecsrc), 2837230130Smav KOBJMETHOD_END 2838230130Smav}; 2839230130SmavMIXER_DECLARE(hdaa_audio_ctl_ossmixer); 2840230130Smav 2841230130Smavstatic void 2842230130Smavhdaa_dump_gpi(struct hdaa_devinfo *devinfo) 2843230130Smav{ 2844230130Smav device_t dev = devinfo->dev; 2845230130Smav int i; 2846230130Smav uint32_t data, wake, unsol, sticky; 2847230130Smav 2848230130Smav if (HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap) > 0) { 2849230130Smav data = hda_command(dev, 2850230130Smav HDA_CMD_GET_GPI_DATA(0, devinfo->nid)); 2851230130Smav wake = hda_command(dev, 2852230130Smav HDA_CMD_GET_GPI_WAKE_ENABLE_MASK(0, devinfo->nid)); 2853230130Smav unsol = hda_command(dev, 2854230130Smav HDA_CMD_GET_GPI_UNSOLICITED_ENABLE_MASK(0, devinfo->nid)); 2855230130Smav sticky = hda_command(dev, 2856230130Smav HDA_CMD_GET_GPI_STICKY_MASK(0, devinfo->nid)); 2857230130Smav for (i = 0; i < HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap); i++) { 2858230130Smav device_printf(dev, " GPI%d:%s%s%s state=%d", i, 2859230130Smav (sticky & (1 << i)) ? " sticky" : "", 2860230130Smav (unsol & (1 << i)) ? " unsol" : "", 2861230130Smav (wake & (1 << i)) ? " wake" : "", 2862230130Smav (data >> i) & 1); 2863230130Smav } 2864230130Smav } 2865230130Smav} 2866230130Smav 2867230130Smavstatic void 2868230130Smavhdaa_dump_gpio(struct hdaa_devinfo *devinfo) 2869230130Smav{ 2870230130Smav device_t dev = devinfo->dev; 2871230130Smav int i; 2872230130Smav uint32_t data, dir, enable, wake, unsol, sticky; 2873230130Smav 2874230130Smav if (HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap) > 0) { 2875230130Smav data = hda_command(dev, 2876230130Smav HDA_CMD_GET_GPIO_DATA(0, devinfo->nid)); 2877230130Smav enable = hda_command(dev, 2878230130Smav HDA_CMD_GET_GPIO_ENABLE_MASK(0, devinfo->nid)); 2879230130Smav dir = hda_command(dev, 2880230130Smav HDA_CMD_GET_GPIO_DIRECTION(0, devinfo->nid)); 2881230130Smav wake = hda_command(dev, 2882230130Smav HDA_CMD_GET_GPIO_WAKE_ENABLE_MASK(0, devinfo->nid)); 2883230130Smav unsol = hda_command(dev, 2884230130Smav HDA_CMD_GET_GPIO_UNSOLICITED_ENABLE_MASK(0, devinfo->nid)); 2885230130Smav sticky = hda_command(dev, 2886230130Smav HDA_CMD_GET_GPIO_STICKY_MASK(0, devinfo->nid)); 2887230130Smav for (i = 0; i < HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap); i++) { 2888230130Smav device_printf(dev, " GPIO%d: ", i); 2889230130Smav if ((enable & (1 << i)) == 0) { 2890230130Smav printf("disabled\n"); 2891230130Smav continue; 2892230130Smav } 2893230130Smav if ((dir & (1 << i)) == 0) { 2894230130Smav printf("input%s%s%s", 2895230130Smav (sticky & (1 << i)) ? " sticky" : "", 2896230130Smav (unsol & (1 << i)) ? " unsol" : "", 2897230130Smav (wake & (1 << i)) ? " wake" : ""); 2898230130Smav } else 2899230130Smav printf("output"); 2900230130Smav printf(" state=%d\n", (data >> i) & 1); 2901230130Smav } 2902230130Smav } 2903230130Smav} 2904230130Smav 2905230130Smavstatic void 2906230130Smavhdaa_dump_gpo(struct hdaa_devinfo *devinfo) 2907230130Smav{ 2908230130Smav device_t dev = devinfo->dev; 2909230130Smav int i; 2910230130Smav uint32_t data; 2911230130Smav 2912230130Smav if (HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap) > 0) { 2913230130Smav data = hda_command(dev, 2914230130Smav HDA_CMD_GET_GPO_DATA(0, devinfo->nid)); 2915230130Smav for (i = 0; i < HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap); i++) { 2916230130Smav device_printf(dev, " GPO%d: state=%d", i, 2917230130Smav (data >> i) & 1); 2918230130Smav } 2919230130Smav } 2920230130Smav} 2921230130Smav 2922230130Smavstatic void 2923230130Smavhdaa_audio_parse(struct hdaa_devinfo *devinfo) 2924230130Smav{ 2925230130Smav struct hdaa_widget *w; 2926230130Smav uint32_t res; 2927230130Smav int i; 2928230130Smav nid_t nid; 2929230130Smav 2930230130Smav nid = devinfo->nid; 2931230130Smav 2932230130Smav res = hda_command(devinfo->dev, 2933230130Smav HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_GPIO_COUNT)); 2934230130Smav devinfo->gpio_cap = res; 2935230130Smav 2936230130Smav HDA_BOOTVERBOSE( 2937230130Smav device_printf(devinfo->dev, 2938230130Smav "NumGPIO=%d NumGPO=%d " 2939230130Smav "NumGPI=%d GPIWake=%d GPIUnsol=%d\n", 2940230130Smav HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap), 2941230130Smav HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap), 2942230130Smav HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap), 2943230130Smav HDA_PARAM_GPIO_COUNT_GPI_WAKE(devinfo->gpio_cap), 2944230130Smav HDA_PARAM_GPIO_COUNT_GPI_UNSOL(devinfo->gpio_cap)); 2945230130Smav hdaa_dump_gpi(devinfo); 2946230130Smav hdaa_dump_gpio(devinfo); 2947230130Smav hdaa_dump_gpo(devinfo); 2948230130Smav ); 2949230130Smav 2950230130Smav res = hda_command(devinfo->dev, 2951230130Smav HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_SUPP_STREAM_FORMATS)); 2952230130Smav devinfo->supp_stream_formats = res; 2953230130Smav 2954230130Smav res = hda_command(devinfo->dev, 2955230130Smav HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_SUPP_PCM_SIZE_RATE)); 2956230130Smav devinfo->supp_pcm_size_rate = res; 2957230130Smav 2958230130Smav res = hda_command(devinfo->dev, 2959230130Smav HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_OUTPUT_AMP_CAP)); 2960230130Smav devinfo->outamp_cap = res; 2961230130Smav 2962230130Smav res = hda_command(devinfo->dev, 2963230130Smav HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_INPUT_AMP_CAP)); 2964230130Smav devinfo->inamp_cap = res; 2965230130Smav 2966230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 2967230130Smav w = hdaa_widget_get(devinfo, i); 2968230130Smav if (w == NULL) 2969230130Smav device_printf(devinfo->dev, "Ghost widget! nid=%d!\n", i); 2970230130Smav else { 2971230130Smav w->devinfo = devinfo; 2972230130Smav w->nid = i; 2973230130Smav w->enable = 1; 2974230130Smav w->selconn = -1; 2975230130Smav w->pflags = 0; 2976230130Smav w->ossdev = -1; 2977230130Smav w->bindas = -1; 2978230130Smav w->param.eapdbtl = HDA_INVALID; 2979230130Smav hdaa_widget_parse(w); 2980230130Smav } 2981230130Smav } 2982230130Smav} 2983230130Smav 2984230130Smavstatic void 2985230130Smavhdaa_audio_postprocess(struct hdaa_devinfo *devinfo) 2986230130Smav{ 2987230130Smav struct hdaa_widget *w; 2988230130Smav int i; 2989230130Smav 2990230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 2991230130Smav w = hdaa_widget_get(devinfo, i); 2992230130Smav if (w == NULL) 2993230130Smav continue; 2994230130Smav hdaa_widget_postprocess(w); 2995230130Smav } 2996230130Smav} 2997230130Smav 2998230130Smavstatic void 2999230130Smavhdaa_audio_ctl_parse(struct hdaa_devinfo *devinfo) 3000230130Smav{ 3001230130Smav struct hdaa_audio_ctl *ctls; 3002230130Smav struct hdaa_widget *w, *cw; 3003230130Smav int i, j, cnt, max, ocap, icap; 3004230130Smav int mute, offset, step, size; 3005230130Smav 3006230130Smav /* XXX This is redundant */ 3007230130Smav max = 0; 3008230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 3009230130Smav w = hdaa_widget_get(devinfo, i); 3010230130Smav if (w == NULL || w->enable == 0) 3011230130Smav continue; 3012230130Smav if (w->param.outamp_cap != 0) 3013230130Smav max++; 3014230130Smav if (w->param.inamp_cap != 0) { 3015230130Smav switch (w->type) { 3016230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR: 3017230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER: 3018230130Smav for (j = 0; j < w->nconns; j++) { 3019230130Smav cw = hdaa_widget_get(devinfo, 3020230130Smav w->conns[j]); 3021230130Smav if (cw == NULL || cw->enable == 0) 3022230130Smav continue; 3023230130Smav max++; 3024230130Smav } 3025230130Smav break; 3026230130Smav default: 3027230130Smav max++; 3028230130Smav break; 3029230130Smav } 3030230130Smav } 3031230130Smav } 3032230130Smav devinfo->ctlcnt = max; 3033230130Smav 3034230130Smav if (max < 1) 3035230130Smav return; 3036230130Smav 3037230130Smav ctls = (struct hdaa_audio_ctl *)malloc( 3038230130Smav sizeof(*ctls) * max, M_HDAA, M_ZERO | M_NOWAIT); 3039230130Smav 3040230130Smav if (ctls == NULL) { 3041230130Smav /* Blekh! */ 3042230130Smav device_printf(devinfo->dev, "unable to allocate ctls!\n"); 3043230130Smav devinfo->ctlcnt = 0; 3044230130Smav return; 3045230130Smav } 3046230130Smav 3047230130Smav cnt = 0; 3048230130Smav for (i = devinfo->startnode; cnt < max && i < devinfo->endnode; i++) { 3049230130Smav if (cnt >= max) { 3050230130Smav device_printf(devinfo->dev, "%s: Ctl overflow!\n", 3051230130Smav __func__); 3052230130Smav break; 3053230130Smav } 3054230130Smav w = hdaa_widget_get(devinfo, i); 3055230130Smav if (w == NULL || w->enable == 0) 3056230130Smav continue; 3057230130Smav ocap = w->param.outamp_cap; 3058230130Smav icap = w->param.inamp_cap; 3059230130Smav if (ocap != 0) { 3060230130Smav mute = HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(ocap); 3061230130Smav step = HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(ocap); 3062230130Smav size = HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(ocap); 3063230130Smav offset = HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(ocap); 3064230130Smav /*if (offset > step) { 3065230130Smav HDA_BOOTVERBOSE( 3066230130Smav device_printf(devinfo->dev, 3067230130Smav "BUGGY outamp: nid=%d " 3068230130Smav "[offset=%d > step=%d]\n", 3069230130Smav w->nid, offset, step); 3070230130Smav ); 3071230130Smav offset = step; 3072230130Smav }*/ 3073230130Smav ctls[cnt].enable = 1; 3074230130Smav ctls[cnt].widget = w; 3075230130Smav ctls[cnt].mute = mute; 3076230130Smav ctls[cnt].step = step; 3077230130Smav ctls[cnt].size = size; 3078230130Smav ctls[cnt].offset = offset; 3079230130Smav ctls[cnt].left = offset; 3080230130Smav ctls[cnt].right = offset; 3081230130Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX || 3082230130Smav w->waspin) 3083230130Smav ctls[cnt].ndir = HDAA_CTL_IN; 3084230130Smav else 3085230130Smav ctls[cnt].ndir = HDAA_CTL_OUT; 3086230130Smav ctls[cnt++].dir = HDAA_CTL_OUT; 3087230130Smav } 3088230130Smav 3089230130Smav if (icap != 0) { 3090230130Smav mute = HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(icap); 3091230130Smav step = HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(icap); 3092230130Smav size = HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(icap); 3093230130Smav offset = HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(icap); 3094230130Smav /*if (offset > step) { 3095230130Smav HDA_BOOTVERBOSE( 3096230130Smav device_printf(devinfo->dev, 3097230130Smav "BUGGY inamp: nid=%d " 3098230130Smav "[offset=%d > step=%d]\n", 3099230130Smav w->nid, offset, step); 3100230130Smav ); 3101230130Smav offset = step; 3102230130Smav }*/ 3103230130Smav switch (w->type) { 3104230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR: 3105230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER: 3106230130Smav for (j = 0; j < w->nconns; j++) { 3107230130Smav if (cnt >= max) { 3108230130Smav device_printf(devinfo->dev, 3109230130Smav "%s: Ctl overflow!\n", 3110230130Smav __func__); 3111230130Smav break; 3112230130Smav } 3113230130Smav cw = hdaa_widget_get(devinfo, 3114230130Smav w->conns[j]); 3115230130Smav if (cw == NULL || cw->enable == 0) 3116230130Smav continue; 3117230130Smav ctls[cnt].enable = 1; 3118230130Smav ctls[cnt].widget = w; 3119230130Smav ctls[cnt].childwidget = cw; 3120230130Smav ctls[cnt].index = j; 3121230130Smav ctls[cnt].mute = mute; 3122230130Smav ctls[cnt].step = step; 3123230130Smav ctls[cnt].size = size; 3124230130Smav ctls[cnt].offset = offset; 3125230130Smav ctls[cnt].left = offset; 3126230130Smav ctls[cnt].right = offset; 3127230130Smav ctls[cnt].ndir = HDAA_CTL_IN; 3128230130Smav ctls[cnt++].dir = HDAA_CTL_IN; 3129230130Smav } 3130230130Smav break; 3131230130Smav default: 3132230130Smav if (cnt >= max) { 3133230130Smav device_printf(devinfo->dev, 3134230130Smav "%s: Ctl overflow!\n", 3135230130Smav __func__); 3136230130Smav break; 3137230130Smav } 3138230130Smav ctls[cnt].enable = 1; 3139230130Smav ctls[cnt].widget = w; 3140230130Smav ctls[cnt].mute = mute; 3141230130Smav ctls[cnt].step = step; 3142230130Smav ctls[cnt].size = size; 3143230130Smav ctls[cnt].offset = offset; 3144230130Smav ctls[cnt].left = offset; 3145230130Smav ctls[cnt].right = offset; 3146230130Smav if (w->type == 3147230130Smav HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 3148230130Smav ctls[cnt].ndir = HDAA_CTL_OUT; 3149230130Smav else 3150230130Smav ctls[cnt].ndir = HDAA_CTL_IN; 3151230130Smav ctls[cnt++].dir = HDAA_CTL_IN; 3152230130Smav break; 3153230130Smav } 3154230130Smav } 3155230130Smav } 3156230130Smav 3157230130Smav devinfo->ctl = ctls; 3158230130Smav} 3159230130Smav 3160230130Smavstatic void 3161230130Smavhdaa_audio_as_parse(struct hdaa_devinfo *devinfo) 3162230130Smav{ 3163230130Smav struct hdaa_audio_as *as; 3164230130Smav struct hdaa_widget *w; 3165230130Smav int i, j, cnt, max, type, dir, assoc, seq, first, hpredir; 3166230130Smav 3167230130Smav /* Count present associations */ 3168230130Smav max = 0; 3169230130Smav for (j = 1; j < 16; j++) { 3170230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 3171230130Smav w = hdaa_widget_get(devinfo, i); 3172230130Smav if (w == NULL || w->enable == 0) 3173230130Smav continue; 3174230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 3175230130Smav continue; 3176230130Smav if (HDA_CONFIG_DEFAULTCONF_ASSOCIATION(w->wclass.pin.config) 3177230130Smav != j) 3178230130Smav continue; 3179230130Smav max++; 3180230130Smav if (j != 15) /* There could be many 1-pin assocs #15 */ 3181230130Smav break; 3182230130Smav } 3183230130Smav } 3184230130Smav 3185230130Smav devinfo->ascnt = max; 3186230130Smav 3187230130Smav if (max < 1) 3188230130Smav return; 3189230130Smav 3190230130Smav as = (struct hdaa_audio_as *)malloc( 3191230130Smav sizeof(*as) * max, M_HDAA, M_ZERO | M_NOWAIT); 3192230130Smav 3193230130Smav if (as == NULL) { 3194230130Smav /* Blekh! */ 3195230130Smav device_printf(devinfo->dev, "unable to allocate assocs!\n"); 3196230130Smav devinfo->ascnt = 0; 3197230130Smav return; 3198230130Smav } 3199230130Smav 3200230130Smav for (i = 0; i < max; i++) { 3201230130Smav as[i].hpredir = -1; 3202230130Smav as[i].digital = 0; 3203230130Smav as[i].num_chans = 1; 3204230130Smav as[i].location = -1; 3205230130Smav } 3206230130Smav 3207230130Smav /* Scan associations skipping as=0. */ 3208230130Smav cnt = 0; 3209230130Smav for (j = 1; j < 16; j++) { 3210230130Smav first = 16; 3211230130Smav hpredir = 0; 3212230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 3213230130Smav w = hdaa_widget_get(devinfo, i); 3214230130Smav if (w == NULL || w->enable == 0) 3215230130Smav continue; 3216230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 3217230130Smav continue; 3218230130Smav assoc = HDA_CONFIG_DEFAULTCONF_ASSOCIATION(w->wclass.pin.config); 3219230130Smav seq = HDA_CONFIG_DEFAULTCONF_SEQUENCE(w->wclass.pin.config); 3220230130Smav if (assoc != j) { 3221230130Smav continue; 3222230130Smav } 3223230130Smav KASSERT(cnt < max, 3224230130Smav ("%s: Associations owerflow (%d of %d)", 3225230130Smav __func__, cnt, max)); 3226230130Smav type = w->wclass.pin.config & 3227230130Smav HDA_CONFIG_DEFAULTCONF_DEVICE_MASK; 3228230130Smav /* Get pin direction. */ 3229230130Smav if (type == HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_OUT || 3230230130Smav type == HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER || 3231230130Smav type == HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT || 3232230130Smav type == HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_OUT || 3233230130Smav type == HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_OUT) 3234230130Smav dir = HDAA_CTL_OUT; 3235230130Smav else 3236230130Smav dir = HDAA_CTL_IN; 3237230130Smav /* If this is a first pin - create new association. */ 3238230130Smav if (as[cnt].pincnt == 0) { 3239230130Smav as[cnt].enable = 1; 3240230130Smav as[cnt].index = j; 3241230130Smav as[cnt].dir = dir; 3242230130Smav } 3243230130Smav if (seq < first) 3244230130Smav first = seq; 3245230130Smav /* Check association correctness. */ 3246230130Smav if (as[cnt].pins[seq] != 0) { 3247230130Smav device_printf(devinfo->dev, "%s: Duplicate pin %d (%d) " 3248230130Smav "in association %d! Disabling association.\n", 3249230130Smav __func__, seq, w->nid, j); 3250230130Smav as[cnt].enable = 0; 3251230130Smav } 3252230130Smav if (dir != as[cnt].dir) { 3253230130Smav device_printf(devinfo->dev, "%s: Pin %d has wrong " 3254230130Smav "direction for association %d! Disabling " 3255230130Smav "association.\n", 3256230130Smav __func__, w->nid, j); 3257230130Smav as[cnt].enable = 0; 3258230130Smav } 3259230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) { 3260230507Smav as[cnt].digital |= 0x1; 3261230507Smav if (HDA_PARAM_PIN_CAP_HDMI(w->wclass.pin.cap)) 3262230507Smav as[cnt].digital |= 0x2; 3263230130Smav if (HDA_PARAM_PIN_CAP_DP(w->wclass.pin.cap)) 3264230507Smav as[cnt].digital |= 0x4; 3265230130Smav } 3266230130Smav if (as[cnt].location == -1) { 3267230130Smav as[cnt].location = 3268230130Smav HDA_CONFIG_DEFAULTCONF_LOCATION(w->wclass.pin.config); 3269230130Smav } else if (as[cnt].location != 3270230130Smav HDA_CONFIG_DEFAULTCONF_LOCATION(w->wclass.pin.config)) { 3271230130Smav as[cnt].location = -2; 3272230130Smav } 3273230130Smav /* Headphones with seq=15 may mean redirection. */ 3274230130Smav if (type == HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT && 3275230130Smav seq == 15) 3276230130Smav hpredir = 1; 3277230130Smav as[cnt].pins[seq] = w->nid; 3278230130Smav as[cnt].pincnt++; 3279230130Smav /* Association 15 is a multiple unassociated pins. */ 3280230130Smav if (j == 15) 3281230130Smav cnt++; 3282230130Smav } 3283230130Smav if (j != 15 && as[cnt].pincnt > 0) { 3284230130Smav if (hpredir && as[cnt].pincnt > 1) 3285230130Smav as[cnt].hpredir = first; 3286230130Smav cnt++; 3287230130Smav } 3288230130Smav } 3289230130Smav for (i = 0; i < max; i++) { 3290230130Smav if (as[i].dir == HDAA_CTL_IN && (as[i].pincnt == 1 || 3291230130Smav as[i].pins[14] > 0 || as[i].pins[15] > 0)) 3292230130Smav as[i].mixed = 1; 3293230130Smav } 3294230130Smav HDA_BOOTVERBOSE( 3295230130Smav device_printf(devinfo->dev, 3296230130Smav "%d associations found:\n", max); 3297230130Smav for (i = 0; i < max; i++) { 3298230130Smav device_printf(devinfo->dev, 3299230130Smav "Association %d (%d) %s%s:\n", 3300230130Smav i, as[i].index, (as[i].dir == HDAA_CTL_IN)?"in":"out", 3301230130Smav as[i].enable?"":" (disabled)"); 3302230130Smav for (j = 0; j < 16; j++) { 3303230130Smav if (as[i].pins[j] == 0) 3304230130Smav continue; 3305230130Smav device_printf(devinfo->dev, 3306230130Smav " Pin nid=%d seq=%d\n", 3307230130Smav as[i].pins[j], j); 3308230130Smav } 3309230130Smav } 3310230130Smav ); 3311230130Smav 3312230130Smav devinfo->as = as; 3313230130Smav} 3314230130Smav 3315230130Smav/* 3316230130Smav * Trace path from DAC to pin. 3317230130Smav */ 3318230130Smavstatic nid_t 3319230130Smavhdaa_audio_trace_dac(struct hdaa_devinfo *devinfo, int as, int seq, nid_t nid, 3320230130Smav int dupseq, int min, int only, int depth) 3321230130Smav{ 3322230130Smav struct hdaa_widget *w; 3323230130Smav int i, im = -1; 3324230130Smav nid_t m = 0, ret; 3325230130Smav 3326230130Smav if (depth > HDA_PARSE_MAXDEPTH) 3327230130Smav return (0); 3328230130Smav w = hdaa_widget_get(devinfo, nid); 3329230130Smav if (w == NULL || w->enable == 0) 3330230130Smav return (0); 3331230130Smav HDA_BOOTHVERBOSE( 3332230130Smav if (!only) { 3333230130Smav device_printf(devinfo->dev, 3334230130Smav " %*stracing via nid %d\n", 3335230130Smav depth + 1, "", w->nid); 3336230130Smav } 3337230130Smav ); 3338230130Smav /* Use only unused widgets */ 3339230130Smav if (w->bindas >= 0 && w->bindas != as) { 3340230130Smav HDA_BOOTHVERBOSE( 3341230130Smav if (!only) { 3342230130Smav device_printf(devinfo->dev, 3343230130Smav " %*snid %d busy by association %d\n", 3344230130Smav depth + 1, "", w->nid, w->bindas); 3345230130Smav } 3346230130Smav ); 3347230130Smav return (0); 3348230130Smav } 3349230130Smav if (dupseq < 0) { 3350230130Smav if (w->bindseqmask != 0) { 3351230130Smav HDA_BOOTHVERBOSE( 3352230130Smav if (!only) { 3353230130Smav device_printf(devinfo->dev, 3354230130Smav " %*snid %d busy by seqmask %x\n", 3355230130Smav depth + 1, "", w->nid, w->bindseqmask); 3356230130Smav } 3357230130Smav ); 3358230130Smav return (0); 3359230130Smav } 3360230130Smav } else { 3361230130Smav /* If this is headphones - allow duplicate first pin. */ 3362230130Smav if (w->bindseqmask != 0 && 3363230130Smav (w->bindseqmask & (1 << dupseq)) == 0) { 3364230130Smav HDA_BOOTHVERBOSE( 3365230130Smav device_printf(devinfo->dev, 3366230130Smav " %*snid %d busy by seqmask %x\n", 3367230130Smav depth + 1, "", w->nid, w->bindseqmask); 3368230130Smav ); 3369230130Smav return (0); 3370230130Smav } 3371230130Smav } 3372230130Smav 3373230130Smav switch (w->type) { 3374230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT: 3375230130Smav /* Do not traverse input. AD1988 has digital monitor 3376230130Smav for which we are not ready. */ 3377230130Smav break; 3378230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT: 3379230130Smav /* If we are tracing HP take only dac of first pin. */ 3380230130Smav if ((only == 0 || only == w->nid) && 3381230130Smav (w->nid >= min) && (dupseq < 0 || w->nid == 3382230130Smav devinfo->as[as].dacs[0][dupseq])) 3383230130Smav m = w->nid; 3384230130Smav break; 3385230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX: 3386230130Smav if (depth > 0) 3387230130Smav break; 3388230130Smav /* Fall */ 3389230130Smav default: 3390230130Smav /* Find reachable DACs with smallest nid respecting constraints. */ 3391230130Smav for (i = 0; i < w->nconns; i++) { 3392230130Smav if (w->connsenable[i] == 0) 3393230130Smav continue; 3394230130Smav if (w->selconn != -1 && w->selconn != i) 3395230130Smav continue; 3396230130Smav if ((ret = hdaa_audio_trace_dac(devinfo, as, seq, 3397230130Smav w->conns[i], dupseq, min, only, depth + 1)) != 0) { 3398230130Smav if (m == 0 || ret < m) { 3399230130Smav m = ret; 3400230130Smav im = i; 3401230130Smav } 3402230130Smav if (only || dupseq >= 0) 3403230130Smav break; 3404230130Smav } 3405230130Smav } 3406230130Smav if (im >= 0 && only && ((w->nconns > 1 && 3407230130Smav w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) || 3408230130Smav w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR)) 3409230130Smav w->selconn = im; 3410230130Smav break; 3411230130Smav } 3412230130Smav if (m && only) { 3413230130Smav w->bindas = as; 3414230130Smav w->bindseqmask |= (1 << seq); 3415230130Smav } 3416230130Smav HDA_BOOTHVERBOSE( 3417230130Smav if (!only) { 3418230130Smav device_printf(devinfo->dev, 3419230130Smav " %*snid %d returned %d\n", 3420230130Smav depth + 1, "", w->nid, m); 3421230130Smav } 3422230130Smav ); 3423230130Smav return (m); 3424230130Smav} 3425230130Smav 3426230130Smav/* 3427230130Smav * Trace path from widget to ADC. 3428230130Smav */ 3429230130Smavstatic nid_t 3430230130Smavhdaa_audio_trace_adc(struct hdaa_devinfo *devinfo, int as, int seq, nid_t nid, 3431230130Smav int mixed, int min, int only, int depth, int *length, int onlylength) 3432230130Smav{ 3433230130Smav struct hdaa_widget *w, *wc; 3434230130Smav int i, j, im, lm = HDA_PARSE_MAXDEPTH; 3435230130Smav nid_t m = 0, ret; 3436230130Smav 3437230130Smav if (depth > HDA_PARSE_MAXDEPTH) 3438230130Smav return (0); 3439230130Smav w = hdaa_widget_get(devinfo, nid); 3440230130Smav if (w == NULL || w->enable == 0) 3441230130Smav return (0); 3442230130Smav HDA_BOOTHVERBOSE( 3443230130Smav device_printf(devinfo->dev, 3444230130Smav " %*stracing via nid %d\n", 3445230130Smav depth + 1, "", w->nid); 3446230130Smav ); 3447230130Smav /* Use only unused widgets */ 3448230130Smav if (w->bindas >= 0 && w->bindas != as) { 3449230130Smav HDA_BOOTHVERBOSE( 3450230130Smav device_printf(devinfo->dev, 3451230130Smav " %*snid %d busy by association %d\n", 3452230130Smav depth + 1, "", w->nid, w->bindas); 3453230130Smav ); 3454230130Smav return (0); 3455230130Smav } 3456230130Smav if (!mixed && w->bindseqmask != 0) { 3457230130Smav HDA_BOOTHVERBOSE( 3458230130Smav device_printf(devinfo->dev, 3459230130Smav " %*snid %d busy by seqmask %x\n", 3460230130Smav depth + 1, "", w->nid, w->bindseqmask); 3461230130Smav ); 3462230130Smav return (0); 3463230130Smav } 3464230130Smav switch (w->type) { 3465230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT: 3466230130Smav if ((only == 0 || only == w->nid) && (w->nid >= min) && 3467230130Smav (onlylength == 0 || onlylength == depth)) { 3468230130Smav m = w->nid; 3469239254Smav *length = depth; 3470230130Smav } 3471230130Smav break; 3472230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX: 3473230130Smav if (depth > 0) 3474230130Smav break; 3475230130Smav /* Fall */ 3476230130Smav default: 3477230130Smav /* Try to find reachable ADCs with specified nid. */ 3478230130Smav for (j = devinfo->startnode; j < devinfo->endnode; j++) { 3479230130Smav wc = hdaa_widget_get(devinfo, j); 3480230130Smav if (wc == NULL || wc->enable == 0) 3481230130Smav continue; 3482230130Smav im = -1; 3483230130Smav for (i = 0; i < wc->nconns; i++) { 3484230130Smav if (wc->connsenable[i] == 0) 3485230130Smav continue; 3486230130Smav if (wc->conns[i] != nid) 3487230130Smav continue; 3488230130Smav if ((ret = hdaa_audio_trace_adc(devinfo, as, seq, 3489230130Smav j, mixed, min, only, depth + 1, 3490230130Smav length, onlylength)) != 0) { 3491230130Smav if (m == 0 || ret < m || 3492239254Smav (ret == m && *length < lm)) { 3493230130Smav m = ret; 3494230130Smav im = i; 3495230130Smav lm = *length; 3496239254Smav } else 3497239254Smav *length = lm; 3498230130Smav if (only) 3499230130Smav break; 3500230130Smav } 3501230130Smav } 3502230130Smav if (im >= 0 && only && ((wc->nconns > 1 && 3503230130Smav wc->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) || 3504230130Smav wc->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR)) 3505230130Smav wc->selconn = im; 3506230130Smav } 3507230130Smav break; 3508230130Smav } 3509230130Smav if (m && only) { 3510230130Smav w->bindas = as; 3511230130Smav w->bindseqmask |= (1 << seq); 3512230130Smav } 3513230130Smav HDA_BOOTHVERBOSE( 3514230130Smav device_printf(devinfo->dev, 3515230130Smav " %*snid %d returned %d\n", 3516230130Smav depth + 1, "", w->nid, m); 3517230130Smav ); 3518230130Smav return (m); 3519230130Smav} 3520230130Smav 3521230130Smav/* 3522230130Smav * Erase trace path of the specified association. 3523230130Smav */ 3524230130Smavstatic void 3525230130Smavhdaa_audio_undo_trace(struct hdaa_devinfo *devinfo, int as, int seq) 3526230130Smav{ 3527230130Smav struct hdaa_widget *w; 3528230130Smav int i; 3529230130Smav 3530230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 3531230130Smav w = hdaa_widget_get(devinfo, i); 3532230130Smav if (w == NULL || w->enable == 0) 3533230130Smav continue; 3534230130Smav if (w->bindas == as) { 3535230130Smav if (seq >= 0) { 3536230130Smav w->bindseqmask &= ~(1 << seq); 3537230130Smav if (w->bindseqmask == 0) { 3538230130Smav w->bindas = -1; 3539230130Smav w->selconn = -1; 3540230130Smav } 3541230130Smav } else { 3542230130Smav w->bindas = -1; 3543230130Smav w->bindseqmask = 0; 3544230130Smav w->selconn = -1; 3545230130Smav } 3546230130Smav } 3547230130Smav } 3548230130Smav} 3549230130Smav 3550230130Smav/* 3551230130Smav * Trace association path from DAC to output 3552230130Smav */ 3553230130Smavstatic int 3554230130Smavhdaa_audio_trace_as_out(struct hdaa_devinfo *devinfo, int as, int seq) 3555230130Smav{ 3556230130Smav struct hdaa_audio_as *ases = devinfo->as; 3557230130Smav int i, hpredir; 3558230130Smav nid_t min, res; 3559230130Smav 3560230130Smav /* Find next pin */ 3561230130Smav for (i = seq; i < 16 && ases[as].pins[i] == 0; i++) 3562230130Smav ; 3563230130Smav /* Check if there is no any left. If so - we succeeded. */ 3564230130Smav if (i == 16) 3565230130Smav return (1); 3566230130Smav 3567230130Smav hpredir = (i == 15 && ases[as].fakeredir == 0)?ases[as].hpredir:-1; 3568230130Smav min = 0; 3569230130Smav do { 3570230130Smav HDA_BOOTHVERBOSE( 3571230130Smav device_printf(devinfo->dev, 3572230130Smav " Tracing pin %d with min nid %d", 3573230130Smav ases[as].pins[i], min); 3574230130Smav if (hpredir >= 0) 3575230130Smav printf(" and hpredir %d", hpredir); 3576230130Smav printf("\n"); 3577230130Smav ); 3578230130Smav /* Trace this pin taking min nid into account. */ 3579230130Smav res = hdaa_audio_trace_dac(devinfo, as, i, 3580230130Smav ases[as].pins[i], hpredir, min, 0, 0); 3581230130Smav if (res == 0) { 3582230130Smav /* If we failed - return to previous and redo it. */ 3583230130Smav HDA_BOOTVERBOSE( 3584230130Smav device_printf(devinfo->dev, 3585230130Smav " Unable to trace pin %d seq %d with min " 3586230130Smav "nid %d", 3587230130Smav ases[as].pins[i], i, min); 3588230130Smav if (hpredir >= 0) 3589230130Smav printf(" and hpredir %d", hpredir); 3590230130Smav printf("\n"); 3591230130Smav ); 3592230130Smav return (0); 3593230130Smav } 3594230130Smav HDA_BOOTVERBOSE( 3595230130Smav device_printf(devinfo->dev, 3596230130Smav " Pin %d traced to DAC %d", 3597230130Smav ases[as].pins[i], res); 3598230130Smav if (hpredir >= 0) 3599230130Smav printf(" and hpredir %d", hpredir); 3600230130Smav if (ases[as].fakeredir) 3601230130Smav printf(" with fake redirection"); 3602230130Smav printf("\n"); 3603230130Smav ); 3604230130Smav /* Trace again to mark the path */ 3605230130Smav hdaa_audio_trace_dac(devinfo, as, i, 3606230130Smav ases[as].pins[i], hpredir, min, res, 0); 3607230130Smav ases[as].dacs[0][i] = res; 3608230130Smav /* We succeeded, so call next. */ 3609230130Smav if (hdaa_audio_trace_as_out(devinfo, as, i + 1)) 3610230130Smav return (1); 3611230130Smav /* If next failed, we should retry with next min */ 3612230130Smav hdaa_audio_undo_trace(devinfo, as, i); 3613230130Smav ases[as].dacs[0][i] = 0; 3614230130Smav min = res + 1; 3615230130Smav } while (1); 3616230130Smav} 3617230130Smav 3618230130Smav/* 3619230130Smav * Check equivalency of two DACs. 3620230130Smav */ 3621230130Smavstatic int 3622230130Smavhdaa_audio_dacs_equal(struct hdaa_widget *w1, struct hdaa_widget *w2) 3623230130Smav{ 3624230130Smav struct hdaa_devinfo *devinfo = w1->devinfo; 3625230130Smav struct hdaa_widget *w3; 3626230130Smav int i, j, c1, c2; 3627230130Smav 3628230130Smav if (memcmp(&w1->param, &w2->param, sizeof(w1->param))) 3629230130Smav return (0); 3630230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 3631230130Smav w3 = hdaa_widget_get(devinfo, i); 3632230130Smav if (w3 == NULL || w3->enable == 0) 3633230130Smav continue; 3634230130Smav if (w3->bindas != w1->bindas) 3635230130Smav continue; 3636230130Smav if (w3->nconns == 0) 3637230130Smav continue; 3638230130Smav c1 = c2 = -1; 3639230130Smav for (j = 0; j < w3->nconns; j++) { 3640230130Smav if (w3->connsenable[j] == 0) 3641230130Smav continue; 3642230130Smav if (w3->conns[j] == w1->nid) 3643230130Smav c1 = j; 3644230130Smav if (w3->conns[j] == w2->nid) 3645230130Smav c2 = j; 3646230130Smav } 3647230130Smav if (c1 < 0) 3648230130Smav continue; 3649230130Smav if (c2 < 0) 3650230130Smav return (0); 3651230130Smav if (w3->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) 3652230130Smav return (0); 3653230130Smav } 3654230130Smav return (1); 3655230130Smav} 3656230130Smav 3657230130Smav/* 3658230130Smav * Check equivalency of two ADCs. 3659230130Smav */ 3660230130Smavstatic int 3661230130Smavhdaa_audio_adcs_equal(struct hdaa_widget *w1, struct hdaa_widget *w2) 3662230130Smav{ 3663230130Smav struct hdaa_devinfo *devinfo = w1->devinfo; 3664230130Smav struct hdaa_widget *w3, *w4; 3665230130Smav int i; 3666230130Smav 3667230130Smav if (memcmp(&w1->param, &w2->param, sizeof(w1->param))) 3668230130Smav return (0); 3669230130Smav if (w1->nconns != 1 || w2->nconns != 1) 3670230130Smav return (0); 3671230130Smav if (w1->conns[0] == w2->conns[0]) 3672230130Smav return (1); 3673230130Smav w3 = hdaa_widget_get(devinfo, w1->conns[0]); 3674230130Smav if (w3 == NULL || w3->enable == 0) 3675230130Smav return (0); 3676230130Smav w4 = hdaa_widget_get(devinfo, w2->conns[0]); 3677230130Smav if (w4 == NULL || w4->enable == 0) 3678230130Smav return (0); 3679230130Smav if (w3->bindas == w4->bindas && w3->bindseqmask == w4->bindseqmask) 3680230130Smav return (1); 3681230130Smav if (w4->bindas >= 0) 3682230130Smav return (0); 3683230130Smav if (w3->type != w4->type) 3684230130Smav return (0); 3685230130Smav if (memcmp(&w3->param, &w4->param, sizeof(w3->param))) 3686230130Smav return (0); 3687230130Smav if (w3->nconns != w4->nconns) 3688230130Smav return (0); 3689230130Smav for (i = 0; i < w3->nconns; i++) { 3690230130Smav if (w3->conns[i] != w4->conns[i]) 3691230130Smav return (0); 3692230130Smav } 3693230130Smav return (1); 3694230130Smav} 3695230130Smav 3696230130Smav/* 3697230130Smav * Look for equivalent DAC/ADC to implement second channel. 3698230130Smav */ 3699230130Smavstatic void 3700230130Smavhdaa_audio_adddac(struct hdaa_devinfo *devinfo, int asid) 3701230130Smav{ 3702230130Smav struct hdaa_audio_as *as = &devinfo->as[asid]; 3703230130Smav struct hdaa_widget *w1, *w2; 3704230130Smav int i, pos; 3705230130Smav nid_t nid1, nid2; 3706230130Smav 3707230130Smav HDA_BOOTVERBOSE( 3708230130Smav device_printf(devinfo->dev, 3709230130Smav "Looking for additional %sC " 3710230130Smav "for association %d (%d)\n", 3711230130Smav (as->dir == HDAA_CTL_OUT) ? "DA" : "AD", 3712230130Smav asid, as->index); 3713230130Smav ); 3714230130Smav 3715230130Smav /* Find the exisitng DAC position and return if found more the one. */ 3716230130Smav pos = -1; 3717230130Smav for (i = 0; i < 16; i++) { 3718230130Smav if (as->dacs[0][i] <= 0) 3719230130Smav continue; 3720230130Smav if (pos >= 0 && as->dacs[0][i] != as->dacs[0][pos]) 3721230130Smav return; 3722230130Smav pos = i; 3723230130Smav } 3724230130Smav 3725230130Smav nid1 = as->dacs[0][pos]; 3726230130Smav w1 = hdaa_widget_get(devinfo, nid1); 3727230130Smav w2 = NULL; 3728230130Smav for (nid2 = devinfo->startnode; nid2 < devinfo->endnode; nid2++) { 3729230130Smav w2 = hdaa_widget_get(devinfo, nid2); 3730230130Smav if (w2 == NULL || w2->enable == 0) 3731230130Smav continue; 3732230130Smav if (w2->bindas >= 0) 3733230130Smav continue; 3734230130Smav if (w1->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT) { 3735230130Smav if (w2->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT) 3736230130Smav continue; 3737230130Smav if (hdaa_audio_dacs_equal(w1, w2)) 3738230130Smav break; 3739230130Smav } else { 3740230130Smav if (w2->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) 3741230130Smav continue; 3742230130Smav if (hdaa_audio_adcs_equal(w1, w2)) 3743230130Smav break; 3744230130Smav } 3745230130Smav } 3746230130Smav if (nid2 >= devinfo->endnode) 3747230130Smav return; 3748230130Smav w2->bindas = w1->bindas; 3749230130Smav w2->bindseqmask = w1->bindseqmask; 3750230130Smav if (w1->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) { 3751230130Smav HDA_BOOTVERBOSE( 3752230130Smav device_printf(devinfo->dev, 3753230130Smav " ADC %d considered equal to ADC %d\n", nid2, nid1); 3754230130Smav ); 3755230130Smav w1 = hdaa_widget_get(devinfo, w1->conns[0]); 3756230130Smav w2 = hdaa_widget_get(devinfo, w2->conns[0]); 3757230130Smav w2->bindas = w1->bindas; 3758230130Smav w2->bindseqmask = w1->bindseqmask; 3759230130Smav } else { 3760230130Smav HDA_BOOTVERBOSE( 3761230130Smav device_printf(devinfo->dev, 3762230130Smav " DAC %d considered equal to DAC %d\n", nid2, nid1); 3763230130Smav ); 3764230130Smav } 3765230130Smav for (i = 0; i < 16; i++) { 3766230130Smav if (as->dacs[0][i] <= 0) 3767230130Smav continue; 3768230130Smav as->dacs[as->num_chans][i] = nid2; 3769230130Smav } 3770230130Smav as->num_chans++; 3771230130Smav} 3772230130Smav 3773230130Smav/* 3774230130Smav * Trace association path from input to ADC 3775230130Smav */ 3776230130Smavstatic int 3777230130Smavhdaa_audio_trace_as_in(struct hdaa_devinfo *devinfo, int as) 3778230130Smav{ 3779230130Smav struct hdaa_audio_as *ases = devinfo->as; 3780230130Smav struct hdaa_widget *w; 3781230130Smav int i, j, k, length; 3782230130Smav 3783230130Smav for (j = devinfo->startnode; j < devinfo->endnode; j++) { 3784230130Smav w = hdaa_widget_get(devinfo, j); 3785230130Smav if (w == NULL || w->enable == 0) 3786230130Smav continue; 3787230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) 3788230130Smav continue; 3789230130Smav if (w->bindas >= 0 && w->bindas != as) 3790230130Smav continue; 3791230130Smav 3792230130Smav /* Find next pin */ 3793230130Smav for (i = 0; i < 16; i++) { 3794230130Smav if (ases[as].pins[i] == 0) 3795230130Smav continue; 3796230130Smav 3797230130Smav HDA_BOOTHVERBOSE( 3798230130Smav device_printf(devinfo->dev, 3799230130Smav " Tracing pin %d to ADC %d\n", 3800230130Smav ases[as].pins[i], j); 3801230130Smav ); 3802230130Smav /* Trace this pin taking goal into account. */ 3803230130Smav if (hdaa_audio_trace_adc(devinfo, as, i, 3804230130Smav ases[as].pins[i], 1, 0, j, 0, &length, 0) == 0) { 3805230130Smav /* If we failed - return to previous and redo it. */ 3806230130Smav HDA_BOOTVERBOSE( 3807230130Smav device_printf(devinfo->dev, 3808230130Smav " Unable to trace pin %d to ADC %d, undo traces\n", 3809230130Smav ases[as].pins[i], j); 3810230130Smav ); 3811230130Smav hdaa_audio_undo_trace(devinfo, as, -1); 3812230130Smav for (k = 0; k < 16; k++) 3813230130Smav ases[as].dacs[0][k] = 0; 3814230130Smav break; 3815230130Smav } 3816230130Smav HDA_BOOTVERBOSE( 3817230130Smav device_printf(devinfo->dev, 3818230130Smav " Pin %d traced to ADC %d\n", 3819230130Smav ases[as].pins[i], j); 3820230130Smav ); 3821230130Smav ases[as].dacs[0][i] = j; 3822230130Smav } 3823230130Smav if (i == 16) 3824230130Smav return (1); 3825230130Smav } 3826230130Smav return (0); 3827230130Smav} 3828230130Smav 3829230130Smav/* 3830230130Smav * Trace association path from input to multiple ADCs 3831230130Smav */ 3832230130Smavstatic int 3833230130Smavhdaa_audio_trace_as_in_mch(struct hdaa_devinfo *devinfo, int as, int seq) 3834230130Smav{ 3835230130Smav struct hdaa_audio_as *ases = devinfo->as; 3836230130Smav int i, length; 3837230130Smav nid_t min, res; 3838230130Smav 3839230130Smav /* Find next pin */ 3840230130Smav for (i = seq; i < 16 && ases[as].pins[i] == 0; i++) 3841230130Smav ; 3842230130Smav /* Check if there is no any left. If so - we succeeded. */ 3843230130Smav if (i == 16) 3844230130Smav return (1); 3845230130Smav 3846230130Smav min = 0; 3847230130Smav do { 3848230130Smav HDA_BOOTHVERBOSE( 3849230130Smav device_printf(devinfo->dev, 3850230130Smav " Tracing pin %d with min nid %d", 3851230130Smav ases[as].pins[i], min); 3852230130Smav printf("\n"); 3853230130Smav ); 3854230130Smav /* Trace this pin taking min nid into account. */ 3855230130Smav res = hdaa_audio_trace_adc(devinfo, as, i, 3856230130Smav ases[as].pins[i], 0, min, 0, 0, &length, 0); 3857230130Smav if (res == 0) { 3858230130Smav /* If we failed - return to previous and redo it. */ 3859230130Smav HDA_BOOTVERBOSE( 3860230130Smav device_printf(devinfo->dev, 3861230130Smav " Unable to trace pin %d seq %d with min " 3862230130Smav "nid %d", 3863230130Smav ases[as].pins[i], i, min); 3864230130Smav printf("\n"); 3865230130Smav ); 3866230130Smav return (0); 3867230130Smav } 3868230130Smav HDA_BOOTVERBOSE( 3869230130Smav device_printf(devinfo->dev, 3870230130Smav " Pin %d traced to ADC %d\n", 3871230130Smav ases[as].pins[i], res); 3872230130Smav ); 3873230130Smav /* Trace again to mark the path */ 3874230130Smav hdaa_audio_trace_adc(devinfo, as, i, 3875230130Smav ases[as].pins[i], 0, min, res, 0, &length, length); 3876230130Smav ases[as].dacs[0][i] = res; 3877230130Smav /* We succeeded, so call next. */ 3878230130Smav if (hdaa_audio_trace_as_in_mch(devinfo, as, i + 1)) 3879230130Smav return (1); 3880230130Smav /* If next failed, we should retry with next min */ 3881230130Smav hdaa_audio_undo_trace(devinfo, as, i); 3882230130Smav ases[as].dacs[0][i] = 0; 3883230130Smav min = res + 1; 3884230130Smav } while (1); 3885230130Smav} 3886230130Smav 3887230130Smav/* 3888230130Smav * Trace input monitor path from mixer to output association. 3889230130Smav */ 3890230130Smavstatic int 3891230130Smavhdaa_audio_trace_to_out(struct hdaa_devinfo *devinfo, nid_t nid, int depth) 3892230130Smav{ 3893230130Smav struct hdaa_audio_as *ases = devinfo->as; 3894230130Smav struct hdaa_widget *w, *wc; 3895230130Smav int i, j; 3896230130Smav nid_t res = 0; 3897230130Smav 3898230130Smav if (depth > HDA_PARSE_MAXDEPTH) 3899230130Smav return (0); 3900230130Smav w = hdaa_widget_get(devinfo, nid); 3901230130Smav if (w == NULL || w->enable == 0) 3902230130Smav return (0); 3903230130Smav HDA_BOOTHVERBOSE( 3904230130Smav device_printf(devinfo->dev, 3905230130Smav " %*stracing via nid %d\n", 3906230130Smav depth + 1, "", w->nid); 3907230130Smav ); 3908230130Smav /* Use only unused widgets */ 3909230130Smav if (depth > 0 && w->bindas != -1) { 3910230130Smav if (w->bindas < 0 || ases[w->bindas].dir == HDAA_CTL_OUT) { 3911230130Smav HDA_BOOTHVERBOSE( 3912230130Smav device_printf(devinfo->dev, 3913230130Smav " %*snid %d found output association %d\n", 3914230130Smav depth + 1, "", w->nid, w->bindas); 3915230130Smav ); 3916230130Smav if (w->bindas >= 0) 3917230130Smav w->pflags |= HDAA_ADC_MONITOR; 3918230130Smav return (1); 3919230130Smav } else { 3920230130Smav HDA_BOOTHVERBOSE( 3921230130Smav device_printf(devinfo->dev, 3922230130Smav " %*snid %d busy by input association %d\n", 3923230130Smav depth + 1, "", w->nid, w->bindas); 3924230130Smav ); 3925230130Smav return (0); 3926230130Smav } 3927230130Smav } 3928230130Smav 3929230130Smav switch (w->type) { 3930230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT: 3931230130Smav /* Do not traverse input. AD1988 has digital monitor 3932230130Smav for which we are not ready. */ 3933230130Smav break; 3934230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX: 3935230130Smav if (depth > 0) 3936230130Smav break; 3937230130Smav /* Fall */ 3938230130Smav default: 3939230130Smav /* Try to find reachable ADCs with specified nid. */ 3940230130Smav for (j = devinfo->startnode; j < devinfo->endnode; j++) { 3941230130Smav wc = hdaa_widget_get(devinfo, j); 3942230130Smav if (wc == NULL || wc->enable == 0) 3943230130Smav continue; 3944230130Smav for (i = 0; i < wc->nconns; i++) { 3945230130Smav if (wc->connsenable[i] == 0) 3946230130Smav continue; 3947230130Smav if (wc->conns[i] != nid) 3948230130Smav continue; 3949230130Smav if (hdaa_audio_trace_to_out(devinfo, 3950230130Smav j, depth + 1) != 0) { 3951230130Smav res = 1; 3952230130Smav if (wc->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR && 3953230130Smav wc->selconn == -1) 3954230130Smav wc->selconn = i; 3955230130Smav } 3956230130Smav } 3957230130Smav } 3958230130Smav break; 3959230130Smav } 3960230130Smav if (res && w->bindas == -1) 3961230130Smav w->bindas = -2; 3962230130Smav 3963230130Smav HDA_BOOTHVERBOSE( 3964230130Smav device_printf(devinfo->dev, 3965230130Smav " %*snid %d returned %d\n", 3966230130Smav depth + 1, "", w->nid, res); 3967230130Smav ); 3968230130Smav return (res); 3969230130Smav} 3970230130Smav 3971230130Smav/* 3972230130Smav * Trace extra associations (beeper, monitor) 3973230130Smav */ 3974230130Smavstatic void 3975230130Smavhdaa_audio_trace_as_extra(struct hdaa_devinfo *devinfo) 3976230130Smav{ 3977230130Smav struct hdaa_audio_as *as = devinfo->as; 3978230130Smav struct hdaa_widget *w; 3979230130Smav int j; 3980230130Smav 3981230130Smav /* Input monitor */ 3982230130Smav /* Find mixer associated with input, but supplying signal 3983230130Smav for output associations. Hope it will be input monitor. */ 3984230130Smav HDA_BOOTVERBOSE( 3985230130Smav device_printf(devinfo->dev, 3986230130Smav "Tracing input monitor\n"); 3987230130Smav ); 3988230130Smav for (j = devinfo->startnode; j < devinfo->endnode; j++) { 3989230130Smav w = hdaa_widget_get(devinfo, j); 3990230130Smav if (w == NULL || w->enable == 0) 3991230130Smav continue; 3992230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) 3993230130Smav continue; 3994230130Smav if (w->bindas < 0 || as[w->bindas].dir != HDAA_CTL_IN) 3995230130Smav continue; 3996230130Smav HDA_BOOTVERBOSE( 3997230130Smav device_printf(devinfo->dev, 3998230130Smav " Tracing nid %d to out\n", 3999230130Smav j); 4000230130Smav ); 4001230130Smav if (hdaa_audio_trace_to_out(devinfo, w->nid, 0)) { 4002230130Smav HDA_BOOTVERBOSE( 4003230130Smav device_printf(devinfo->dev, 4004230130Smav " nid %d is input monitor\n", 4005230130Smav w->nid); 4006230130Smav ); 4007230130Smav w->ossdev = SOUND_MIXER_IMIX; 4008230130Smav } 4009230130Smav } 4010230130Smav 4011230130Smav /* Other inputs monitor */ 4012230130Smav /* Find input pins supplying signal for output associations. 4013230130Smav Hope it will be input monitoring. */ 4014230130Smav HDA_BOOTVERBOSE( 4015230130Smav device_printf(devinfo->dev, 4016230130Smav "Tracing other input monitors\n"); 4017230130Smav ); 4018230130Smav for (j = devinfo->startnode; j < devinfo->endnode; j++) { 4019230130Smav w = hdaa_widget_get(devinfo, j); 4020230130Smav if (w == NULL || w->enable == 0) 4021230130Smav continue; 4022230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 4023230130Smav continue; 4024230130Smav if (w->bindas < 0 || as[w->bindas].dir != HDAA_CTL_IN) 4025230130Smav continue; 4026230130Smav HDA_BOOTVERBOSE( 4027230130Smav device_printf(devinfo->dev, 4028230130Smav " Tracing nid %d to out\n", 4029230130Smav j); 4030230130Smav ); 4031230130Smav if (hdaa_audio_trace_to_out(devinfo, w->nid, 0)) { 4032230130Smav HDA_BOOTVERBOSE( 4033230130Smav device_printf(devinfo->dev, 4034230130Smav " nid %d is input monitor\n", 4035230130Smav w->nid); 4036230130Smav ); 4037230130Smav } 4038230130Smav } 4039230130Smav 4040230130Smav /* Beeper */ 4041230130Smav HDA_BOOTVERBOSE( 4042230130Smav device_printf(devinfo->dev, 4043230130Smav "Tracing beeper\n"); 4044230130Smav ); 4045230130Smav for (j = devinfo->startnode; j < devinfo->endnode; j++) { 4046230130Smav w = hdaa_widget_get(devinfo, j); 4047230130Smav if (w == NULL || w->enable == 0) 4048230130Smav continue; 4049230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET) 4050230130Smav continue; 4051230130Smav HDA_BOOTHVERBOSE( 4052230130Smav device_printf(devinfo->dev, 4053230130Smav " Tracing nid %d to out\n", 4054230130Smav j); 4055230130Smav ); 4056230130Smav if (hdaa_audio_trace_to_out(devinfo, w->nid, 0)) { 4057230130Smav HDA_BOOTVERBOSE( 4058230130Smav device_printf(devinfo->dev, 4059230130Smav " nid %d traced to out\n", 4060230130Smav j); 4061230130Smav ); 4062230130Smav } 4063230130Smav w->bindas = -2; 4064230130Smav } 4065230130Smav} 4066230130Smav 4067230130Smav/* 4068230130Smav * Bind assotiations to PCM channels 4069230130Smav */ 4070230130Smavstatic void 4071230130Smavhdaa_audio_bind_as(struct hdaa_devinfo *devinfo) 4072230130Smav{ 4073230130Smav struct hdaa_audio_as *as = devinfo->as; 4074230130Smav int i, j, cnt = 0, free; 4075230130Smav 4076230130Smav for (j = 0; j < devinfo->ascnt; j++) { 4077230130Smav if (as[j].enable) 4078230130Smav cnt += as[j].num_chans; 4079230130Smav } 4080230130Smav if (devinfo->num_chans == 0) { 4081230130Smav devinfo->chans = (struct hdaa_chan *)malloc( 4082230130Smav sizeof(struct hdaa_chan) * cnt, 4083230130Smav M_HDAA, M_ZERO | M_NOWAIT); 4084230130Smav if (devinfo->chans == NULL) { 4085230130Smav device_printf(devinfo->dev, 4086230130Smav "Channels memory allocation failed!\n"); 4087230130Smav return; 4088230130Smav } 4089230130Smav } else { 4090230130Smav devinfo->chans = (struct hdaa_chan *)realloc(devinfo->chans, 4091230130Smav sizeof(struct hdaa_chan) * (devinfo->num_chans + cnt), 4092230130Smav M_HDAA, M_ZERO | M_NOWAIT); 4093230130Smav if (devinfo->chans == NULL) { 4094230130Smav devinfo->num_chans = 0; 4095230130Smav device_printf(devinfo->dev, 4096230130Smav "Channels memory allocation failed!\n"); 4097230130Smav return; 4098230130Smav } 4099230130Smav /* Fixup relative pointers after realloc */ 4100230130Smav for (j = 0; j < devinfo->num_chans; j++) 4101230130Smav devinfo->chans[j].caps.fmtlist = devinfo->chans[j].fmtlist; 4102230130Smav } 4103230130Smav free = devinfo->num_chans; 4104230130Smav devinfo->num_chans += cnt; 4105230130Smav 4106230130Smav for (j = free; j < free + cnt; j++) { 4107230130Smav devinfo->chans[j].devinfo = devinfo; 4108230130Smav devinfo->chans[j].as = -1; 4109230130Smav } 4110230130Smav 4111230130Smav /* Assign associations in order of their numbers, */ 4112230130Smav for (j = 0; j < devinfo->ascnt; j++) { 4113230130Smav if (as[j].enable == 0) 4114230130Smav continue; 4115230130Smav for (i = 0; i < as[j].num_chans; i++) { 4116230130Smav devinfo->chans[free].as = j; 4117230130Smav devinfo->chans[free].asindex = i; 4118230130Smav devinfo->chans[free].dir = 4119230130Smav (as[j].dir == HDAA_CTL_IN) ? PCMDIR_REC : PCMDIR_PLAY; 4120230130Smav hdaa_pcmchannel_setup(&devinfo->chans[free]); 4121230130Smav as[j].chans[i] = free; 4122230130Smav free++; 4123230130Smav } 4124230130Smav } 4125230130Smav} 4126230130Smav 4127230130Smavstatic void 4128230130Smavhdaa_audio_disable_nonaudio(struct hdaa_devinfo *devinfo) 4129230130Smav{ 4130230130Smav struct hdaa_widget *w; 4131230130Smav int i; 4132230130Smav 4133230130Smav /* Disable power and volume widgets. */ 4134230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 4135230130Smav w = hdaa_widget_get(devinfo, i); 4136230130Smav if (w == NULL || w->enable == 0) 4137230130Smav continue; 4138230130Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_POWER_WIDGET || 4139230130Smav w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_VOLUME_WIDGET) { 4140230130Smav w->enable = 0; 4141230130Smav HDA_BOOTHVERBOSE( 4142230130Smav device_printf(devinfo->dev, 4143230130Smav " Disabling nid %d due to it's" 4144230130Smav " non-audio type.\n", 4145230130Smav w->nid); 4146230130Smav ); 4147230130Smav } 4148230130Smav } 4149230130Smav} 4150230130Smav 4151230130Smavstatic void 4152230130Smavhdaa_audio_disable_useless(struct hdaa_devinfo *devinfo) 4153230130Smav{ 4154230130Smav struct hdaa_widget *w, *cw; 4155230130Smav struct hdaa_audio_ctl *ctl; 4156230130Smav int done, found, i, j, k; 4157230130Smav 4158230130Smav /* Disable useless pins. */ 4159230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 4160230130Smav w = hdaa_widget_get(devinfo, i); 4161230130Smav if (w == NULL || w->enable == 0) 4162230130Smav continue; 4163230130Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) { 4164230130Smav if ((w->wclass.pin.config & 4165230130Smav HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK) == 4166230130Smav HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_NONE) { 4167230130Smav w->enable = 0; 4168230130Smav HDA_BOOTHVERBOSE( 4169230130Smav device_printf(devinfo->dev, 4170230130Smav " Disabling pin nid %d due" 4171230130Smav " to None connectivity.\n", 4172230130Smav w->nid); 4173230130Smav ); 4174230130Smav } else if ((w->wclass.pin.config & 4175230130Smav HDA_CONFIG_DEFAULTCONF_ASSOCIATION_MASK) == 0) { 4176230130Smav w->enable = 0; 4177230130Smav HDA_BOOTHVERBOSE( 4178230130Smav device_printf(devinfo->dev, 4179230130Smav " Disabling unassociated" 4180230130Smav " pin nid %d.\n", 4181230130Smav w->nid); 4182230130Smav ); 4183230130Smav } 4184230130Smav } 4185230130Smav } 4186230130Smav do { 4187230130Smav done = 1; 4188230130Smav /* Disable and mute controls for disabled widgets. */ 4189230130Smav i = 0; 4190230130Smav while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) { 4191230130Smav if (ctl->enable == 0) 4192230130Smav continue; 4193230130Smav if (ctl->widget->enable == 0 || 4194230130Smav (ctl->childwidget != NULL && 4195230130Smav ctl->childwidget->enable == 0)) { 4196230130Smav ctl->forcemute = 1; 4197230130Smav ctl->muted = HDAA_AMP_MUTE_ALL; 4198230130Smav ctl->left = 0; 4199230130Smav ctl->right = 0; 4200230130Smav ctl->enable = 0; 4201230130Smav if (ctl->ndir == HDAA_CTL_IN) 4202230130Smav ctl->widget->connsenable[ctl->index] = 0; 4203230130Smav done = 0; 4204230130Smav HDA_BOOTHVERBOSE( 4205230130Smav device_printf(devinfo->dev, 4206230130Smav " Disabling ctl %d nid %d cnid %d due" 4207230130Smav " to disabled widget.\n", i, 4208230130Smav ctl->widget->nid, 4209230130Smav (ctl->childwidget != NULL)? 4210230130Smav ctl->childwidget->nid:-1); 4211230130Smav ); 4212230130Smav } 4213230130Smav } 4214230130Smav /* Disable useless widgets. */ 4215230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 4216230130Smav w = hdaa_widget_get(devinfo, i); 4217230130Smav if (w == NULL || w->enable == 0) 4218230130Smav continue; 4219230130Smav /* Disable inputs with disabled child widgets. */ 4220230130Smav for (j = 0; j < w->nconns; j++) { 4221230130Smav if (w->connsenable[j]) { 4222230130Smav cw = hdaa_widget_get(devinfo, w->conns[j]); 4223230130Smav if (cw == NULL || cw->enable == 0) { 4224230130Smav w->connsenable[j] = 0; 4225230130Smav HDA_BOOTHVERBOSE( 4226230130Smav device_printf(devinfo->dev, 4227230130Smav " Disabling nid %d connection %d due" 4228230130Smav " to disabled child widget.\n", 4229230130Smav i, j); 4230230130Smav ); 4231230130Smav } 4232230130Smav } 4233230130Smav } 4234230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR && 4235230130Smav w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) 4236230130Smav continue; 4237230130Smav /* Disable mixers and selectors without inputs. */ 4238230130Smav found = 0; 4239230130Smav for (j = 0; j < w->nconns; j++) { 4240230130Smav if (w->connsenable[j]) { 4241230130Smav found = 1; 4242230130Smav break; 4243230130Smav } 4244230130Smav } 4245230130Smav if (found == 0) { 4246230130Smav w->enable = 0; 4247230130Smav done = 0; 4248230130Smav HDA_BOOTHVERBOSE( 4249230130Smav device_printf(devinfo->dev, 4250230130Smav " Disabling nid %d due to all it's" 4251230130Smav " inputs disabled.\n", w->nid); 4252230130Smav ); 4253230130Smav } 4254230130Smav /* Disable nodes without consumers. */ 4255230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR && 4256230130Smav w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) 4257230130Smav continue; 4258230130Smav found = 0; 4259230130Smav for (k = devinfo->startnode; k < devinfo->endnode; k++) { 4260230130Smav cw = hdaa_widget_get(devinfo, k); 4261230130Smav if (cw == NULL || cw->enable == 0) 4262230130Smav continue; 4263230130Smav for (j = 0; j < cw->nconns; j++) { 4264230130Smav if (cw->connsenable[j] && cw->conns[j] == i) { 4265230130Smav found = 1; 4266230130Smav break; 4267230130Smav } 4268230130Smav } 4269230130Smav } 4270230130Smav if (found == 0) { 4271230130Smav w->enable = 0; 4272230130Smav done = 0; 4273230130Smav HDA_BOOTHVERBOSE( 4274230130Smav device_printf(devinfo->dev, 4275230130Smav " Disabling nid %d due to all it's" 4276230130Smav " consumers disabled.\n", w->nid); 4277230130Smav ); 4278230130Smav } 4279230130Smav } 4280230130Smav } while (done == 0); 4281230130Smav 4282230130Smav} 4283230130Smav 4284230130Smavstatic void 4285230130Smavhdaa_audio_disable_unas(struct hdaa_devinfo *devinfo) 4286230130Smav{ 4287230130Smav struct hdaa_audio_as *as = devinfo->as; 4288230130Smav struct hdaa_widget *w, *cw; 4289230130Smav struct hdaa_audio_ctl *ctl; 4290230130Smav int i, j, k; 4291230130Smav 4292230130Smav /* Disable unassosiated widgets. */ 4293230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 4294230130Smav w = hdaa_widget_get(devinfo, i); 4295230130Smav if (w == NULL || w->enable == 0) 4296230130Smav continue; 4297230130Smav if (w->bindas == -1) { 4298230130Smav w->enable = 0; 4299230130Smav HDA_BOOTHVERBOSE( 4300230130Smav device_printf(devinfo->dev, 4301230130Smav " Disabling unassociated nid %d.\n", 4302230130Smav w->nid); 4303230130Smav ); 4304230130Smav } 4305230130Smav } 4306230130Smav /* Disable input connections on input pin and 4307230130Smav * output on output. */ 4308230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 4309230130Smav w = hdaa_widget_get(devinfo, i); 4310230130Smav if (w == NULL || w->enable == 0) 4311230130Smav continue; 4312230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 4313230130Smav continue; 4314230130Smav if (w->bindas < 0) 4315230130Smav continue; 4316230130Smav if (as[w->bindas].dir == HDAA_CTL_IN) { 4317230130Smav for (j = 0; j < w->nconns; j++) { 4318230130Smav if (w->connsenable[j] == 0) 4319230130Smav continue; 4320230130Smav w->connsenable[j] = 0; 4321230130Smav HDA_BOOTHVERBOSE( 4322230130Smav device_printf(devinfo->dev, 4323230130Smav " Disabling connection to input pin " 4324230130Smav "nid %d conn %d.\n", 4325230130Smav i, j); 4326230130Smav ); 4327230130Smav } 4328230130Smav ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, 4329230130Smav HDAA_CTL_IN, -1, 1); 4330230130Smav if (ctl && ctl->enable) { 4331230130Smav ctl->forcemute = 1; 4332230130Smav ctl->muted = HDAA_AMP_MUTE_ALL; 4333230130Smav ctl->left = 0; 4334230130Smav ctl->right = 0; 4335230130Smav ctl->enable = 0; 4336230130Smav } 4337230130Smav } else { 4338230130Smav ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, 4339230130Smav HDAA_CTL_OUT, -1, 1); 4340230130Smav if (ctl && ctl->enable) { 4341230130Smav ctl->forcemute = 1; 4342230130Smav ctl->muted = HDAA_AMP_MUTE_ALL; 4343230130Smav ctl->left = 0; 4344230130Smav ctl->right = 0; 4345230130Smav ctl->enable = 0; 4346230130Smav } 4347230130Smav for (k = devinfo->startnode; k < devinfo->endnode; k++) { 4348230130Smav cw = hdaa_widget_get(devinfo, k); 4349230130Smav if (cw == NULL || cw->enable == 0) 4350230130Smav continue; 4351230130Smav for (j = 0; j < cw->nconns; j++) { 4352230130Smav if (cw->connsenable[j] && cw->conns[j] == i) { 4353230130Smav cw->connsenable[j] = 0; 4354230130Smav HDA_BOOTHVERBOSE( 4355230130Smav device_printf(devinfo->dev, 4356230130Smav " Disabling connection from output pin " 4357230130Smav "nid %d conn %d cnid %d.\n", 4358230130Smav k, j, i); 4359230130Smav ); 4360230130Smav if (cw->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX && 4361230130Smav cw->nconns > 1) 4362230130Smav continue; 4363230130Smav ctl = hdaa_audio_ctl_amp_get(devinfo, k, 4364230130Smav HDAA_CTL_IN, j, 1); 4365230130Smav if (ctl && ctl->enable) { 4366230130Smav ctl->forcemute = 1; 4367230130Smav ctl->muted = HDAA_AMP_MUTE_ALL; 4368230130Smav ctl->left = 0; 4369230130Smav ctl->right = 0; 4370230130Smav ctl->enable = 0; 4371230130Smav } 4372230130Smav } 4373230130Smav } 4374230130Smav } 4375230130Smav } 4376230130Smav } 4377230130Smav} 4378230130Smav 4379230130Smavstatic void 4380230130Smavhdaa_audio_disable_notselected(struct hdaa_devinfo *devinfo) 4381230130Smav{ 4382230130Smav struct hdaa_audio_as *as = devinfo->as; 4383230130Smav struct hdaa_widget *w; 4384230130Smav int i, j; 4385230130Smav 4386230130Smav /* On playback path we can safely disable all unseleted inputs. */ 4387230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 4388230130Smav w = hdaa_widget_get(devinfo, i); 4389230130Smav if (w == NULL || w->enable == 0) 4390230130Smav continue; 4391230130Smav if (w->nconns <= 1) 4392230130Smav continue; 4393230130Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) 4394230130Smav continue; 4395230130Smav if (w->bindas < 0 || as[w->bindas].dir == HDAA_CTL_IN) 4396230130Smav continue; 4397230130Smav for (j = 0; j < w->nconns; j++) { 4398230130Smav if (w->connsenable[j] == 0) 4399230130Smav continue; 4400230130Smav if (w->selconn < 0 || w->selconn == j) 4401230130Smav continue; 4402230130Smav w->connsenable[j] = 0; 4403230130Smav HDA_BOOTHVERBOSE( 4404230130Smav device_printf(devinfo->dev, 4405230130Smav " Disabling unselected connection " 4406230130Smav "nid %d conn %d.\n", 4407230130Smav i, j); 4408230130Smav ); 4409230130Smav } 4410230130Smav } 4411230130Smav} 4412230130Smav 4413230130Smavstatic void 4414230130Smavhdaa_audio_disable_crossas(struct hdaa_devinfo *devinfo) 4415230130Smav{ 4416230130Smav struct hdaa_audio_as *ases = devinfo->as; 4417230130Smav struct hdaa_widget *w, *cw; 4418230130Smav struct hdaa_audio_ctl *ctl; 4419230130Smav int i, j; 4420230130Smav 4421230130Smav /* Disable crossassociatement and unwanted crosschannel connections. */ 4422230130Smav /* ... using selectors */ 4423230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 4424230130Smav w = hdaa_widget_get(devinfo, i); 4425230130Smav if (w == NULL || w->enable == 0) 4426230130Smav continue; 4427230130Smav if (w->nconns <= 1) 4428230130Smav continue; 4429230130Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) 4430230130Smav continue; 4431230130Smav /* Allow any -> mix */ 4432230130Smav if (w->bindas == -2) 4433230130Smav continue; 4434230130Smav for (j = 0; j < w->nconns; j++) { 4435230130Smav if (w->connsenable[j] == 0) 4436230130Smav continue; 4437230130Smav cw = hdaa_widget_get(devinfo, w->conns[j]); 4438230130Smav if (cw == NULL || w->enable == 0) 4439230130Smav continue; 4440230130Smav /* Allow mix -> out. */ 4441230130Smav if (cw->bindas == -2 && w->bindas >= 0 && 4442230130Smav ases[w->bindas].dir == HDAA_CTL_OUT) 4443230130Smav continue; 4444230130Smav /* Allow mix -> mixed-in. */ 4445230130Smav if (cw->bindas == -2 && w->bindas >= 0 && 4446230130Smav ases[w->bindas].mixed) 4447230130Smav continue; 4448230130Smav /* Allow in -> mix. */ 4449230130Smav if ((w->pflags & HDAA_ADC_MONITOR) && 4450230130Smav cw->bindas >= 0 && 4451230130Smav ases[cw->bindas].dir == HDAA_CTL_IN) 4452230130Smav continue; 4453230130Smav /* Allow if have common as/seqs. */ 4454230130Smav if (w->bindas == cw->bindas && 4455230130Smav (w->bindseqmask & cw->bindseqmask) != 0) 4456230130Smav continue; 4457230130Smav w->connsenable[j] = 0; 4458230130Smav HDA_BOOTHVERBOSE( 4459230130Smav device_printf(devinfo->dev, 4460230130Smav " Disabling crossassociatement connection " 4461230130Smav "nid %d conn %d cnid %d.\n", 4462230130Smav i, j, cw->nid); 4463230130Smav ); 4464230130Smav } 4465230130Smav } 4466230130Smav /* ... using controls */ 4467230130Smav i = 0; 4468230130Smav while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) { 4469230130Smav if (ctl->enable == 0 || ctl->childwidget == NULL) 4470230130Smav continue; 4471230130Smav /* Allow any -> mix */ 4472230130Smav if (ctl->widget->bindas == -2) 4473230130Smav continue; 4474230130Smav /* Allow mix -> out. */ 4475230130Smav if (ctl->childwidget->bindas == -2 && 4476230130Smav ctl->widget->bindas >= 0 && 4477230130Smav ases[ctl->widget->bindas].dir == HDAA_CTL_OUT) 4478230130Smav continue; 4479230130Smav /* Allow mix -> mixed-in. */ 4480230130Smav if (ctl->childwidget->bindas == -2 && 4481230130Smav ctl->widget->bindas >= 0 && 4482230130Smav ases[ctl->widget->bindas].mixed) 4483230130Smav continue; 4484230130Smav /* Allow in -> mix. */ 4485230130Smav if ((ctl->widget->pflags & HDAA_ADC_MONITOR) && 4486230130Smav ctl->childwidget->bindas >= 0 && 4487230130Smav ases[ctl->childwidget->bindas].dir == HDAA_CTL_IN) 4488230130Smav continue; 4489230130Smav /* Allow if have common as/seqs. */ 4490230130Smav if (ctl->widget->bindas == ctl->childwidget->bindas && 4491230130Smav (ctl->widget->bindseqmask & ctl->childwidget->bindseqmask) != 0) 4492230130Smav continue; 4493230130Smav ctl->forcemute = 1; 4494230130Smav ctl->muted = HDAA_AMP_MUTE_ALL; 4495230130Smav ctl->left = 0; 4496230130Smav ctl->right = 0; 4497230130Smav ctl->enable = 0; 4498230130Smav if (ctl->ndir == HDAA_CTL_IN) 4499230130Smav ctl->widget->connsenable[ctl->index] = 0; 4500230130Smav HDA_BOOTHVERBOSE( 4501230130Smav device_printf(devinfo->dev, 4502230130Smav " Disabling crossassociatement connection " 4503230130Smav "ctl %d nid %d cnid %d.\n", i, 4504230130Smav ctl->widget->nid, 4505230130Smav ctl->childwidget->nid); 4506230130Smav ); 4507230130Smav } 4508230130Smav 4509230130Smav} 4510230130Smav 4511230130Smav/* 4512230451Smav * Find controls to control amplification for source and calculate possible 4513230451Smav * amplification range. 4514230130Smav */ 4515230130Smavstatic int 4516230130Smavhdaa_audio_ctl_source_amp(struct hdaa_devinfo *devinfo, nid_t nid, int index, 4517230451Smav int ossdev, int ctlable, int depth, int *minamp, int *maxamp) 4518230130Smav{ 4519230130Smav struct hdaa_widget *w, *wc; 4520230130Smav struct hdaa_audio_ctl *ctl; 4521230451Smav int i, j, conns = 0, tminamp, tmaxamp, cminamp, cmaxamp, found = 0; 4522230130Smav 4523230130Smav if (depth > HDA_PARSE_MAXDEPTH) 4524230451Smav return (found); 4525230130Smav 4526230130Smav w = hdaa_widget_get(devinfo, nid); 4527230130Smav if (w == NULL || w->enable == 0) 4528230451Smav return (found); 4529230130Smav 4530230130Smav /* Count number of active inputs. */ 4531230130Smav if (depth > 0) { 4532230130Smav for (j = 0; j < w->nconns; j++) { 4533230451Smav if (!w->connsenable[j]) 4534230451Smav continue; 4535230451Smav conns++; 4536230130Smav } 4537230130Smav } 4538230130Smav 4539230130Smav /* If this is not a first step - use input mixer. 4540230130Smav Pins have common input ctl so care must be taken. */ 4541230130Smav if (depth > 0 && ctlable && (conns == 1 || 4542230130Smav w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)) { 4543230130Smav ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, HDAA_CTL_IN, 4544230130Smav index, 1); 4545230130Smav if (ctl) { 4546230451Smav ctl->ossmask |= (1 << ossdev); 4547230451Smav found++; 4548230451Smav if (*minamp == *maxamp) { 4549230451Smav *minamp += MINQDB(ctl); 4550230451Smav *maxamp += MAXQDB(ctl); 4551230451Smav } 4552230130Smav } 4553230130Smav } 4554230130Smav 4555230130Smav /* If widget has own ossdev - not traverse it. 4556230130Smav It will be traversed on it's own. */ 4557230130Smav if (w->ossdev >= 0 && depth > 0) 4558230451Smav return (found); 4559230130Smav 4560230130Smav /* We must not traverse pin */ 4561230130Smav if ((w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT || 4562230130Smav w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) && 4563230130Smav depth > 0) 4564230451Smav return (found); 4565230130Smav 4566230130Smav /* record that this widget exports such signal, */ 4567230130Smav w->ossmask |= (1 << ossdev); 4568230130Smav 4569230451Smav /* 4570230451Smav * If signals mixed, we can't assign controls farther. 4571230130Smav * Ignore this on depth zero. Caller must knows why. 4572230130Smav */ 4573230451Smav if (conns > 1 && 4574230451Smav w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) 4575230130Smav ctlable = 0; 4576230130Smav 4577230130Smav if (ctlable) { 4578230130Smav ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, HDAA_CTL_OUT, -1, 1); 4579230130Smav if (ctl) { 4580230451Smav ctl->ossmask |= (1 << ossdev); 4581230451Smav found++; 4582230451Smav if (*minamp == *maxamp) { 4583230451Smav *minamp += MINQDB(ctl); 4584230451Smav *maxamp += MAXQDB(ctl); 4585230451Smav } 4586230130Smav } 4587230130Smav } 4588230130Smav 4589230451Smav cminamp = cmaxamp = 0; 4590230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 4591230130Smav wc = hdaa_widget_get(devinfo, i); 4592230130Smav if (wc == NULL || wc->enable == 0) 4593230130Smav continue; 4594230130Smav for (j = 0; j < wc->nconns; j++) { 4595230130Smav if (wc->connsenable[j] && wc->conns[j] == nid) { 4596230451Smav tminamp = tmaxamp = 0; 4597230451Smav found += hdaa_audio_ctl_source_amp(devinfo, 4598230451Smav wc->nid, j, ossdev, ctlable, depth + 1, 4599230451Smav &tminamp, &tmaxamp); 4600230451Smav if (cminamp == 0 && cmaxamp == 0) { 4601230451Smav cminamp = tminamp; 4602230451Smav cmaxamp = tmaxamp; 4603230451Smav } else if (tminamp != tmaxamp) { 4604230451Smav cminamp = imax(cminamp, tminamp); 4605230451Smav cmaxamp = imin(cmaxamp, tmaxamp); 4606230451Smav } 4607230130Smav } 4608230130Smav } 4609230130Smav } 4610230451Smav if (*minamp == *maxamp && cminamp < cmaxamp) { 4611230451Smav *minamp += cminamp; 4612230451Smav *maxamp += cmaxamp; 4613230451Smav } 4614230451Smav return (found); 4615230130Smav} 4616230130Smav 4617230130Smav/* 4618230451Smav * Find controls to control amplification for destination and calculate 4619230451Smav * possible amplification range. 4620230130Smav */ 4621230451Smavstatic int 4622230130Smavhdaa_audio_ctl_dest_amp(struct hdaa_devinfo *devinfo, nid_t nid, int index, 4623230451Smav int ossdev, int depth, int *minamp, int *maxamp) 4624230130Smav{ 4625230130Smav struct hdaa_audio_as *as = devinfo->as; 4626230130Smav struct hdaa_widget *w, *wc; 4627230130Smav struct hdaa_audio_ctl *ctl; 4628230451Smav int i, j, consumers, tminamp, tmaxamp, cminamp, cmaxamp, found = 0; 4629230130Smav 4630230130Smav if (depth > HDA_PARSE_MAXDEPTH) 4631230451Smav return (found); 4632230130Smav 4633230130Smav w = hdaa_widget_get(devinfo, nid); 4634230130Smav if (w == NULL || w->enable == 0) 4635230451Smav return (found); 4636230130Smav 4637230130Smav if (depth > 0) { 4638230130Smav /* If this node produce output for several consumers, 4639230130Smav we can't touch it. */ 4640230130Smav consumers = 0; 4641230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 4642230130Smav wc = hdaa_widget_get(devinfo, i); 4643230130Smav if (wc == NULL || wc->enable == 0) 4644230130Smav continue; 4645230130Smav for (j = 0; j < wc->nconns; j++) { 4646230130Smav if (wc->connsenable[j] && wc->conns[j] == nid) 4647230130Smav consumers++; 4648230130Smav } 4649230130Smav } 4650230130Smav /* The only exception is if real HP redirection is configured 4651230130Smav and this is a duplication point. 4652230130Smav XXX: Actually exception is not completely correct. 4653230130Smav XXX: Duplication point check is not perfect. */ 4654230130Smav if ((consumers == 2 && (w->bindas < 0 || 4655230130Smav as[w->bindas].hpredir < 0 || as[w->bindas].fakeredir || 4656230130Smav (w->bindseqmask & (1 << 15)) == 0)) || 4657230130Smav consumers > 2) 4658230451Smav return (found); 4659230130Smav 4660230130Smav /* Else use it's output mixer. */ 4661230130Smav ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, 4662230130Smav HDAA_CTL_OUT, -1, 1); 4663230130Smav if (ctl) { 4664230451Smav ctl->ossmask |= (1 << ossdev); 4665230451Smav found++; 4666230451Smav if (*minamp == *maxamp) { 4667230451Smav *minamp += MINQDB(ctl); 4668230451Smav *maxamp += MAXQDB(ctl); 4669230451Smav } 4670230130Smav } 4671230130Smav } 4672230130Smav 4673230130Smav /* We must not traverse pin */ 4674230130Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX && 4675230130Smav depth > 0) 4676230451Smav return (found); 4677230130Smav 4678230451Smav cminamp = cmaxamp = 0; 4679230130Smav for (i = 0; i < w->nconns; i++) { 4680230130Smav if (w->connsenable[i] == 0) 4681230130Smav continue; 4682230130Smav if (index >= 0 && i != index) 4683230130Smav continue; 4684230451Smav tminamp = tmaxamp = 0; 4685230130Smav ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, 4686230130Smav HDAA_CTL_IN, i, 1); 4687230130Smav if (ctl) { 4688230451Smav ctl->ossmask |= (1 << ossdev); 4689230451Smav found++; 4690230451Smav if (*minamp == *maxamp) { 4691230451Smav tminamp += MINQDB(ctl); 4692230451Smav tmaxamp += MAXQDB(ctl); 4693230451Smav } 4694230130Smav } 4695230451Smav found += hdaa_audio_ctl_dest_amp(devinfo, w->conns[i], -1, ossdev, 4696230451Smav depth + 1, &tminamp, &tmaxamp); 4697230451Smav if (cminamp == 0 && cmaxamp == 0) { 4698230451Smav cminamp = tminamp; 4699230451Smav cmaxamp = tmaxamp; 4700230451Smav } else if (tminamp != tmaxamp) { 4701230451Smav cminamp = imax(cminamp, tminamp); 4702230451Smav cmaxamp = imin(cmaxamp, tmaxamp); 4703230451Smav } 4704230130Smav } 4705230451Smav if (*minamp == *maxamp && cminamp < cmaxamp) { 4706230451Smav *minamp += cminamp; 4707230451Smav *maxamp += cmaxamp; 4708230451Smav } 4709230451Smav return (found); 4710230130Smav} 4711230130Smav 4712230130Smav/* 4713230130Smav * Assign OSS names to sound sources 4714230130Smav */ 4715230130Smavstatic void 4716230130Smavhdaa_audio_assign_names(struct hdaa_devinfo *devinfo) 4717230130Smav{ 4718230130Smav struct hdaa_audio_as *as = devinfo->as; 4719230130Smav struct hdaa_widget *w; 4720230130Smav int i, j; 4721230130Smav int type = -1, use, used = 0; 4722230130Smav static const int types[7][13] = { 4723230130Smav { SOUND_MIXER_LINE, SOUND_MIXER_LINE1, SOUND_MIXER_LINE2, 4724230130Smav SOUND_MIXER_LINE3, -1 }, /* line */ 4725230130Smav { SOUND_MIXER_MONITOR, SOUND_MIXER_MIC, -1 }, /* int mic */ 4726230130Smav { SOUND_MIXER_MIC, SOUND_MIXER_MONITOR, -1 }, /* ext mic */ 4727230130Smav { SOUND_MIXER_CD, -1 }, /* cd */ 4728230130Smav { SOUND_MIXER_SPEAKER, -1 }, /* speaker */ 4729230130Smav { SOUND_MIXER_DIGITAL1, SOUND_MIXER_DIGITAL2, SOUND_MIXER_DIGITAL3, 4730230130Smav -1 }, /* digital */ 4731230130Smav { SOUND_MIXER_LINE, SOUND_MIXER_LINE1, SOUND_MIXER_LINE2, 4732230130Smav SOUND_MIXER_LINE3, SOUND_MIXER_PHONEIN, SOUND_MIXER_PHONEOUT, 4733230130Smav SOUND_MIXER_VIDEO, SOUND_MIXER_RADIO, SOUND_MIXER_DIGITAL1, 4734230130Smav SOUND_MIXER_DIGITAL2, SOUND_MIXER_DIGITAL3, SOUND_MIXER_MONITOR, 4735230130Smav -1 } /* others */ 4736230130Smav }; 4737230130Smav 4738230130Smav /* Surely known names */ 4739230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 4740230130Smav w = hdaa_widget_get(devinfo, i); 4741230130Smav if (w == NULL || w->enable == 0) 4742230130Smav continue; 4743230130Smav if (w->bindas == -1) 4744230130Smav continue; 4745230130Smav use = -1; 4746230130Smav switch (w->type) { 4747230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX: 4748230130Smav if (as[w->bindas].dir == HDAA_CTL_OUT) 4749230130Smav break; 4750230130Smav type = -1; 4751230130Smav switch (w->wclass.pin.config & HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) { 4752230130Smav case HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN: 4753230130Smav type = 0; 4754230130Smav break; 4755230130Smav case HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN: 4756230130Smav if ((w->wclass.pin.config & HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK) 4757230130Smav == HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_JACK) 4758230130Smav break; 4759230130Smav type = 1; 4760230130Smav break; 4761230130Smav case HDA_CONFIG_DEFAULTCONF_DEVICE_CD: 4762230130Smav type = 3; 4763230130Smav break; 4764230130Smav case HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER: 4765230130Smav type = 4; 4766230130Smav break; 4767230130Smav case HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_IN: 4768230130Smav case HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_IN: 4769230130Smav type = 5; 4770230130Smav break; 4771230130Smav } 4772230130Smav if (type == -1) 4773230130Smav break; 4774230130Smav j = 0; 4775230130Smav while (types[type][j] >= 0 && 4776230130Smav (used & (1 << types[type][j])) != 0) { 4777230130Smav j++; 4778230130Smav } 4779230130Smav if (types[type][j] >= 0) 4780230130Smav use = types[type][j]; 4781230130Smav break; 4782230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT: 4783230130Smav use = SOUND_MIXER_PCM; 4784230130Smav break; 4785230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET: 4786230130Smav use = SOUND_MIXER_SPEAKER; 4787230130Smav break; 4788230130Smav default: 4789230130Smav break; 4790230130Smav } 4791230130Smav if (use >= 0) { 4792230130Smav w->ossdev = use; 4793230130Smav used |= (1 << use); 4794230130Smav } 4795230130Smav } 4796230130Smav /* Semi-known names */ 4797230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 4798230130Smav w = hdaa_widget_get(devinfo, i); 4799230130Smav if (w == NULL || w->enable == 0) 4800230130Smav continue; 4801230130Smav if (w->ossdev >= 0) 4802230130Smav continue; 4803230130Smav if (w->bindas == -1) 4804230130Smav continue; 4805230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 4806230130Smav continue; 4807230130Smav if (as[w->bindas].dir == HDAA_CTL_OUT) 4808230130Smav continue; 4809230130Smav type = -1; 4810230130Smav switch (w->wclass.pin.config & HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) { 4811230130Smav case HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_OUT: 4812230130Smav case HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER: 4813230130Smav case HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT: 4814230130Smav case HDA_CONFIG_DEFAULTCONF_DEVICE_AUX: 4815230130Smav type = 0; 4816230130Smav break; 4817230130Smav case HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN: 4818230130Smav type = 2; 4819230130Smav break; 4820230130Smav case HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_OUT: 4821230130Smav case HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_OUT: 4822230130Smav type = 5; 4823230130Smav break; 4824230130Smav } 4825230130Smav if (type == -1) 4826230130Smav break; 4827230130Smav j = 0; 4828230130Smav while (types[type][j] >= 0 && 4829230130Smav (used & (1 << types[type][j])) != 0) { 4830230130Smav j++; 4831230130Smav } 4832230130Smav if (types[type][j] >= 0) { 4833230130Smav w->ossdev = types[type][j]; 4834230130Smav used |= (1 << types[type][j]); 4835230130Smav } 4836230130Smav } 4837230130Smav /* Others */ 4838230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 4839230130Smav w = hdaa_widget_get(devinfo, i); 4840230130Smav if (w == NULL || w->enable == 0) 4841230130Smav continue; 4842230130Smav if (w->ossdev >= 0) 4843230130Smav continue; 4844230130Smav if (w->bindas == -1) 4845230130Smav continue; 4846230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 4847230130Smav continue; 4848230130Smav if (as[w->bindas].dir == HDAA_CTL_OUT) 4849230130Smav continue; 4850230130Smav j = 0; 4851230130Smav while (types[6][j] >= 0 && 4852230130Smav (used & (1 << types[6][j])) != 0) { 4853230130Smav j++; 4854230130Smav } 4855230130Smav if (types[6][j] >= 0) { 4856230130Smav w->ossdev = types[6][j]; 4857230130Smav used |= (1 << types[6][j]); 4858230130Smav } 4859230130Smav } 4860230130Smav} 4861230130Smav 4862230130Smavstatic void 4863230130Smavhdaa_audio_build_tree(struct hdaa_devinfo *devinfo) 4864230130Smav{ 4865230130Smav struct hdaa_audio_as *as = devinfo->as; 4866230130Smav int j, res; 4867230130Smav 4868230130Smav /* Trace all associations in order of their numbers. */ 4869230130Smav for (j = 0; j < devinfo->ascnt; j++) { 4870230130Smav if (as[j].enable == 0) 4871230130Smav continue; 4872230130Smav HDA_BOOTVERBOSE( 4873230130Smav device_printf(devinfo->dev, 4874230130Smav "Tracing association %d (%d)\n", j, as[j].index); 4875230130Smav ); 4876230130Smav if (as[j].dir == HDAA_CTL_OUT) { 4877230130Smavretry: 4878230130Smav res = hdaa_audio_trace_as_out(devinfo, j, 0); 4879230130Smav if (res == 0 && as[j].hpredir >= 0 && 4880230130Smav as[j].fakeredir == 0) { 4881230130Smav /* If CODEC can't do analog HP redirection 4882230130Smav try to make it using one more DAC. */ 4883230130Smav as[j].fakeredir = 1; 4884230130Smav goto retry; 4885230130Smav } 4886230130Smav } else if (as[j].mixed) 4887230130Smav res = hdaa_audio_trace_as_in(devinfo, j); 4888230130Smav else 4889230130Smav res = hdaa_audio_trace_as_in_mch(devinfo, j, 0); 4890230130Smav if (res) { 4891230130Smav HDA_BOOTVERBOSE( 4892230130Smav device_printf(devinfo->dev, 4893230130Smav "Association %d (%d) trace succeeded\n", 4894230130Smav j, as[j].index); 4895230130Smav ); 4896230130Smav } else { 4897230130Smav HDA_BOOTVERBOSE( 4898230130Smav device_printf(devinfo->dev, 4899230130Smav "Association %d (%d) trace failed\n", 4900230130Smav j, as[j].index); 4901230130Smav ); 4902230130Smav as[j].enable = 0; 4903230130Smav } 4904230130Smav } 4905230130Smav 4906230130Smav /* Look for additional DACs/ADCs. */ 4907230130Smav for (j = 0; j < devinfo->ascnt; j++) { 4908230130Smav if (as[j].enable == 0) 4909230130Smav continue; 4910230130Smav hdaa_audio_adddac(devinfo, j); 4911230130Smav } 4912230130Smav 4913230130Smav /* Trace mixer and beeper pseudo associations. */ 4914230130Smav hdaa_audio_trace_as_extra(devinfo); 4915230130Smav} 4916230130Smav 4917230451Smav/* 4918230451Smav * Store in pdevinfo new data about whether and how we can control signal 4919230451Smav * for OSS device to/from specified widget. 4920230451Smav */ 4921230130Smavstatic void 4922230451Smavhdaa_adjust_amp(struct hdaa_widget *w, int ossdev, 4923230451Smav int found, int minamp, int maxamp) 4924230451Smav{ 4925230451Smav struct hdaa_devinfo *devinfo = w->devinfo; 4926230451Smav struct hdaa_pcm_devinfo *pdevinfo; 4927230451Smav 4928230451Smav if (w->bindas >= 0) 4929230451Smav pdevinfo = devinfo->as[w->bindas].pdevinfo; 4930230451Smav else 4931230451Smav pdevinfo = &devinfo->devs[0]; 4932230451Smav if (found) 4933230451Smav pdevinfo->ossmask |= (1 << ossdev); 4934230451Smav if (minamp == 0 && maxamp == 0) 4935230451Smav return; 4936230451Smav if (pdevinfo->minamp[ossdev] == 0 && pdevinfo->maxamp[ossdev] == 0) { 4937230451Smav pdevinfo->minamp[ossdev] = minamp; 4938230451Smav pdevinfo->maxamp[ossdev] = maxamp; 4939230451Smav } else { 4940230451Smav pdevinfo->minamp[ossdev] = imax(pdevinfo->minamp[ossdev], minamp); 4941230451Smav pdevinfo->maxamp[ossdev] = imin(pdevinfo->maxamp[ossdev], maxamp); 4942230451Smav } 4943230451Smav} 4944230451Smav 4945230451Smav/* 4946230451Smav * Trace signals from/to all possible sources/destionstions to find possible 4947230451Smav * recording sources, OSS device control ranges and to assign controls. 4948230451Smav */ 4949230451Smavstatic void 4950230130Smavhdaa_audio_assign_mixers(struct hdaa_devinfo *devinfo) 4951230130Smav{ 4952230130Smav struct hdaa_audio_as *as = devinfo->as; 4953230130Smav struct hdaa_widget *w, *cw; 4954230451Smav int i, j, minamp, maxamp, found; 4955230130Smav 4956230130Smav /* Assign mixers to the tree. */ 4957230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 4958230130Smav w = hdaa_widget_get(devinfo, i); 4959230130Smav if (w == NULL || w->enable == 0) 4960230130Smav continue; 4961230451Smav minamp = maxamp = 0; 4962230130Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT || 4963230130Smav w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET || 4964230130Smav (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX && 4965230130Smav as[w->bindas].dir == HDAA_CTL_IN)) { 4966230130Smav if (w->ossdev < 0) 4967230130Smav continue; 4968230451Smav found = hdaa_audio_ctl_source_amp(devinfo, w->nid, -1, 4969230451Smav w->ossdev, 1, 0, &minamp, &maxamp); 4970230451Smav hdaa_adjust_amp(w, w->ossdev, found, minamp, maxamp); 4971230130Smav } else if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) { 4972230451Smav found = hdaa_audio_ctl_dest_amp(devinfo, w->nid, -1, 4973230451Smav SOUND_MIXER_RECLEV, 0, &minamp, &maxamp); 4974230451Smav hdaa_adjust_amp(w, SOUND_MIXER_RECLEV, found, minamp, maxamp); 4975230130Smav } else if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX && 4976230130Smav as[w->bindas].dir == HDAA_CTL_OUT) { 4977230451Smav found = hdaa_audio_ctl_dest_amp(devinfo, w->nid, -1, 4978230451Smav SOUND_MIXER_VOLUME, 0, &minamp, &maxamp); 4979230451Smav hdaa_adjust_amp(w, SOUND_MIXER_VOLUME, found, minamp, maxamp); 4980230130Smav } 4981230130Smav if (w->ossdev == SOUND_MIXER_IMIX) { 4982230451Smav minamp = maxamp = 0; 4983230451Smav found = hdaa_audio_ctl_source_amp(devinfo, w->nid, -1, 4984230451Smav w->ossdev, 1, 0, &minamp, &maxamp); 4985230451Smav if (minamp == maxamp) { 4986230130Smav /* If we are unable to control input monitor 4987230130Smav as source - try to control it as destination. */ 4988230451Smav found += hdaa_audio_ctl_dest_amp(devinfo, w->nid, -1, 4989230451Smav w->ossdev, 0, &minamp, &maxamp); 4990230451Smav w->pflags |= HDAA_IMIX_AS_DST; 4991230130Smav } 4992230451Smav hdaa_adjust_amp(w, w->ossdev, found, minamp, maxamp); 4993230130Smav } 4994230130Smav if (w->pflags & HDAA_ADC_MONITOR) { 4995230130Smav for (j = 0; j < w->nconns; j++) { 4996230130Smav if (!w->connsenable[j]) 4997230130Smav continue; 4998230130Smav cw = hdaa_widget_get(devinfo, w->conns[j]); 4999230130Smav if (cw == NULL || cw->enable == 0) 5000230130Smav continue; 5001230130Smav if (cw->bindas == -1) 5002230130Smav continue; 5003230130Smav if (cw->bindas >= 0 && 5004230130Smav as[cw->bindas].dir != HDAA_CTL_IN) 5005230130Smav continue; 5006230451Smav minamp = maxamp = 0; 5007230451Smav found = hdaa_audio_ctl_dest_amp(devinfo, 5008230451Smav w->nid, j, SOUND_MIXER_IGAIN, 0, 5009230451Smav &minamp, &maxamp); 5010230451Smav hdaa_adjust_amp(w, SOUND_MIXER_IGAIN, 5011230451Smav found, minamp, maxamp); 5012230130Smav } 5013230130Smav } 5014230130Smav } 5015230130Smav} 5016230130Smav 5017230130Smavstatic void 5018230130Smavhdaa_audio_prepare_pin_ctrl(struct hdaa_devinfo *devinfo) 5019230130Smav{ 5020230130Smav struct hdaa_audio_as *as = devinfo->as; 5021230130Smav struct hdaa_widget *w; 5022230130Smav uint32_t pincap; 5023230130Smav int i; 5024230130Smav 5025230130Smav for (i = 0; i < devinfo->nodecnt; i++) { 5026230130Smav w = &devinfo->widget[i]; 5027230130Smav if (w == NULL) 5028230130Smav continue; 5029230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX && 5030230130Smav w->waspin == 0) 5031230130Smav continue; 5032230130Smav 5033230130Smav pincap = w->wclass.pin.cap; 5034230130Smav 5035230130Smav /* Disable everything. */ 5036230130Smav w->wclass.pin.ctrl &= ~( 5037230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE | 5038230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE | 5039230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE | 5040230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK); 5041230130Smav 5042230130Smav if (w->enable == 0) { 5043230130Smav /* Pin is unused so left it disabled. */ 5044230130Smav continue; 5045230130Smav } else if (w->waspin) { 5046230130Smav /* Enable input for beeper input. */ 5047230130Smav w->wclass.pin.ctrl |= 5048230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE; 5049230130Smav } else if (w->bindas < 0 || as[w->bindas].enable == 0) { 5050230130Smav /* Pin is unused so left it disabled. */ 5051230130Smav continue; 5052230130Smav } else if (as[w->bindas].dir == HDAA_CTL_IN) { 5053230130Smav /* Input pin, configure for input. */ 5054230130Smav if (HDA_PARAM_PIN_CAP_INPUT_CAP(pincap)) 5055230130Smav w->wclass.pin.ctrl |= 5056230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE; 5057230130Smav 5058230130Smav if ((devinfo->quirks & HDAA_QUIRK_IVREF100) && 5059230130Smav HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap)) 5060230130Smav w->wclass.pin.ctrl |= 5061230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE( 5062230130Smav HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_100); 5063230130Smav else if ((devinfo->quirks & HDAA_QUIRK_IVREF80) && 5064230130Smav HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap)) 5065230130Smav w->wclass.pin.ctrl |= 5066230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE( 5067230130Smav HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_80); 5068230130Smav else if ((devinfo->quirks & HDAA_QUIRK_IVREF50) && 5069230130Smav HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap)) 5070230130Smav w->wclass.pin.ctrl |= 5071230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE( 5072230130Smav HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_50); 5073230130Smav } else { 5074230130Smav /* Output pin, configure for output. */ 5075230130Smav if (HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap)) 5076230130Smav w->wclass.pin.ctrl |= 5077230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE; 5078230130Smav 5079230130Smav if (HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap) && 5080230130Smav (w->wclass.pin.config & 5081230130Smav HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) == 5082230130Smav HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT) 5083230130Smav w->wclass.pin.ctrl |= 5084230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE; 5085230130Smav 5086230130Smav if ((devinfo->quirks & HDAA_QUIRK_OVREF100) && 5087230130Smav HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap)) 5088230130Smav w->wclass.pin.ctrl |= 5089230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE( 5090230130Smav HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_100); 5091230130Smav else if ((devinfo->quirks & HDAA_QUIRK_OVREF80) && 5092230130Smav HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap)) 5093230130Smav w->wclass.pin.ctrl |= 5094230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE( 5095230130Smav HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_80); 5096230130Smav else if ((devinfo->quirks & HDAA_QUIRK_OVREF50) && 5097230130Smav HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap)) 5098230130Smav w->wclass.pin.ctrl |= 5099230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE( 5100230130Smav HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_50); 5101230130Smav } 5102230130Smav } 5103230130Smav} 5104230130Smav 5105230130Smavstatic void 5106230130Smavhdaa_audio_ctl_commit(struct hdaa_devinfo *devinfo) 5107230130Smav{ 5108230130Smav struct hdaa_audio_ctl *ctl; 5109230130Smav int i, z; 5110230130Smav 5111230130Smav i = 0; 5112230130Smav while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) { 5113230130Smav if (ctl->enable == 0 || ctl->ossmask != 0) { 5114230130Smav /* Mute disabled and mixer controllable controls. 5115230130Smav * Last will be initialized by mixer_init(). 5116230130Smav * This expected to reduce click on startup. */ 5117230130Smav hdaa_audio_ctl_amp_set(ctl, HDAA_AMP_MUTE_ALL, 0, 0); 5118230130Smav continue; 5119230130Smav } 5120230130Smav /* Init fixed controls to 0dB amplification. */ 5121230130Smav z = ctl->offset; 5122230130Smav if (z > ctl->step) 5123230130Smav z = ctl->step; 5124230130Smav hdaa_audio_ctl_amp_set(ctl, HDAA_AMP_MUTE_NONE, z, z); 5125230130Smav } 5126230130Smav} 5127230130Smav 5128230130Smavstatic void 5129230130Smavhdaa_gpio_commit(struct hdaa_devinfo *devinfo) 5130230130Smav{ 5131230130Smav uint32_t gdata, gmask, gdir; 5132230130Smav int i, numgpio; 5133230130Smav 5134230130Smav numgpio = HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap); 5135230130Smav if (devinfo->gpio != 0 && numgpio != 0) { 5136230130Smav gdata = hda_command(devinfo->dev, 5137230130Smav HDA_CMD_GET_GPIO_DATA(0, devinfo->nid)); 5138230130Smav gmask = hda_command(devinfo->dev, 5139230130Smav HDA_CMD_GET_GPIO_ENABLE_MASK(0, devinfo->nid)); 5140230130Smav gdir = hda_command(devinfo->dev, 5141230130Smav HDA_CMD_GET_GPIO_DIRECTION(0, devinfo->nid)); 5142230130Smav for (i = 0; i < numgpio; i++) { 5143230130Smav if ((devinfo->gpio & HDAA_GPIO_MASK(i)) == 5144230130Smav HDAA_GPIO_SET(i)) { 5145230130Smav gdata |= (1 << i); 5146230130Smav gmask |= (1 << i); 5147230130Smav gdir |= (1 << i); 5148230130Smav } else if ((devinfo->gpio & HDAA_GPIO_MASK(i)) == 5149230130Smav HDAA_GPIO_CLEAR(i)) { 5150230130Smav gdata &= ~(1 << i); 5151230130Smav gmask |= (1 << i); 5152230130Smav gdir |= (1 << i); 5153230130Smav } else if ((devinfo->gpio & HDAA_GPIO_MASK(i)) == 5154230130Smav HDAA_GPIO_DISABLE(i)) { 5155230130Smav gmask &= ~(1 << i); 5156230130Smav } else if ((devinfo->gpio & HDAA_GPIO_MASK(i)) == 5157230130Smav HDAA_GPIO_INPUT(i)) { 5158230130Smav gmask |= (1 << i); 5159230130Smav gdir &= ~(1 << i); 5160230130Smav } 5161230130Smav } 5162230130Smav HDA_BOOTVERBOSE( 5163230130Smav device_printf(devinfo->dev, "GPIO commit\n"); 5164230130Smav ); 5165230130Smav hda_command(devinfo->dev, 5166230130Smav HDA_CMD_SET_GPIO_ENABLE_MASK(0, devinfo->nid, gmask)); 5167230130Smav hda_command(devinfo->dev, 5168230130Smav HDA_CMD_SET_GPIO_DIRECTION(0, devinfo->nid, gdir)); 5169230130Smav hda_command(devinfo->dev, 5170230130Smav HDA_CMD_SET_GPIO_DATA(0, devinfo->nid, gdata)); 5171230130Smav HDA_BOOTVERBOSE( 5172230130Smav hdaa_dump_gpio(devinfo); 5173230130Smav ); 5174230130Smav } 5175230130Smav} 5176230130Smav 5177230130Smavstatic void 5178230130Smavhdaa_gpo_commit(struct hdaa_devinfo *devinfo) 5179230130Smav{ 5180230130Smav uint32_t gdata; 5181230130Smav int i, numgpo; 5182230130Smav 5183230130Smav numgpo = HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap); 5184230130Smav if (devinfo->gpo != 0 && numgpo != 0) { 5185230130Smav gdata = hda_command(devinfo->dev, 5186230130Smav HDA_CMD_GET_GPO_DATA(0, devinfo->nid)); 5187230130Smav for (i = 0; i < numgpo; i++) { 5188230130Smav if ((devinfo->gpio & HDAA_GPIO_MASK(i)) == 5189230130Smav HDAA_GPIO_SET(i)) { 5190230130Smav gdata |= (1 << i); 5191230130Smav } else if ((devinfo->gpio & HDAA_GPIO_MASK(i)) == 5192230130Smav HDAA_GPIO_CLEAR(i)) { 5193230130Smav gdata &= ~(1 << i); 5194230130Smav } 5195230130Smav } 5196230130Smav HDA_BOOTVERBOSE( 5197230130Smav device_printf(devinfo->dev, "GPO commit\n"); 5198230130Smav ); 5199230130Smav hda_command(devinfo->dev, 5200230130Smav HDA_CMD_SET_GPO_DATA(0, devinfo->nid, gdata)); 5201230130Smav HDA_BOOTVERBOSE( 5202230130Smav hdaa_dump_gpo(devinfo); 5203230130Smav ); 5204230130Smav } 5205230130Smav} 5206230130Smav 5207230130Smavstatic void 5208230130Smavhdaa_audio_commit(struct hdaa_devinfo *devinfo) 5209230130Smav{ 5210230130Smav struct hdaa_widget *w; 5211230130Smav int i; 5212230130Smav 5213230130Smav /* Commit controls. */ 5214230130Smav hdaa_audio_ctl_commit(devinfo); 5215230130Smav 5216230130Smav /* Commit selectors, pins and EAPD. */ 5217230130Smav for (i = 0; i < devinfo->nodecnt; i++) { 5218230130Smav w = &devinfo->widget[i]; 5219230130Smav if (w == NULL) 5220230130Smav continue; 5221230130Smav if (w->selconn == -1) 5222230130Smav w->selconn = 0; 5223230130Smav if (w->nconns > 0) 5224230130Smav hdaa_widget_connection_select(w, w->selconn); 5225230130Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX || 5226230130Smav w->waspin) { 5227230130Smav hda_command(devinfo->dev, 5228230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL(0, w->nid, 5229230130Smav w->wclass.pin.ctrl)); 5230230130Smav } 5231230130Smav if (w->param.eapdbtl != HDA_INVALID) { 5232230130Smav uint32_t val; 5233230130Smav 5234230130Smav val = w->param.eapdbtl; 5235230130Smav if (devinfo->quirks & 5236230130Smav HDAA_QUIRK_EAPDINV) 5237230130Smav val ^= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD; 5238230130Smav hda_command(devinfo->dev, 5239230130Smav HDA_CMD_SET_EAPD_BTL_ENABLE(0, w->nid, 5240230130Smav val)); 5241230130Smav } 5242230130Smav } 5243230130Smav 5244230130Smav hdaa_gpio_commit(devinfo); 5245230130Smav hdaa_gpo_commit(devinfo); 5246230130Smav} 5247230130Smav 5248230130Smavstatic void 5249230130Smavhdaa_powerup(struct hdaa_devinfo *devinfo) 5250230130Smav{ 5251230130Smav int i; 5252230130Smav 5253230130Smav hda_command(devinfo->dev, 5254230130Smav HDA_CMD_SET_POWER_STATE(0, 5255230130Smav devinfo->nid, HDA_CMD_POWER_STATE_D0)); 5256230130Smav DELAY(100); 5257230130Smav 5258230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 5259230130Smav hda_command(devinfo->dev, 5260230130Smav HDA_CMD_SET_POWER_STATE(0, 5261230130Smav i, HDA_CMD_POWER_STATE_D0)); 5262230130Smav } 5263230130Smav DELAY(1000); 5264230130Smav} 5265230130Smav 5266230130Smavstatic int 5267230130Smavhdaa_pcmchannel_setup(struct hdaa_chan *ch) 5268230130Smav{ 5269230130Smav struct hdaa_devinfo *devinfo = ch->devinfo; 5270230130Smav struct hdaa_audio_as *as = devinfo->as; 5271230130Smav struct hdaa_widget *w; 5272230130Smav uint32_t cap, fmtcap, pcmcap; 5273230130Smav int i, j, ret, channels, onlystereo; 5274230130Smav uint16_t pinset; 5275230130Smav 5276230130Smav ch->caps = hdaa_caps; 5277230130Smav ch->caps.fmtlist = ch->fmtlist; 5278230130Smav ch->bit16 = 1; 5279230130Smav ch->bit32 = 0; 5280230130Smav ch->pcmrates[0] = 48000; 5281230130Smav ch->pcmrates[1] = 0; 5282230326Smav ch->stripecap = 0xff; 5283230130Smav 5284230130Smav ret = 0; 5285230130Smav channels = 0; 5286230130Smav onlystereo = 1; 5287230130Smav pinset = 0; 5288230130Smav fmtcap = devinfo->supp_stream_formats; 5289230130Smav pcmcap = devinfo->supp_pcm_size_rate; 5290230130Smav 5291230130Smav for (i = 0; i < 16; i++) { 5292230130Smav /* Check as is correct */ 5293230130Smav if (ch->as < 0) 5294230130Smav break; 5295230130Smav /* Cound only present DACs */ 5296230130Smav if (as[ch->as].dacs[ch->asindex][i] <= 0) 5297230130Smav continue; 5298230130Smav /* Ignore duplicates */ 5299230130Smav for (j = 0; j < ret; j++) { 5300230130Smav if (ch->io[j] == as[ch->as].dacs[ch->asindex][i]) 5301230130Smav break; 5302230130Smav } 5303230130Smav if (j < ret) 5304230130Smav continue; 5305230130Smav 5306230130Smav w = hdaa_widget_get(devinfo, as[ch->as].dacs[ch->asindex][i]); 5307230130Smav if (w == NULL || w->enable == 0) 5308230130Smav continue; 5309230130Smav cap = w->param.supp_stream_formats; 5310230130Smav if (!HDA_PARAM_SUPP_STREAM_FORMATS_PCM(cap) && 5311230130Smav !HDA_PARAM_SUPP_STREAM_FORMATS_AC3(cap)) 5312230130Smav continue; 5313230130Smav /* Many CODECs does not declare AC3 support on SPDIF. 5314230130Smav I don't beleave that they doesn't support it! */ 5315230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) 5316230130Smav cap |= HDA_PARAM_SUPP_STREAM_FORMATS_AC3_MASK; 5317230130Smav if (ret == 0) { 5318230130Smav fmtcap = cap; 5319230130Smav pcmcap = w->param.supp_pcm_size_rate; 5320230130Smav } else { 5321230130Smav fmtcap &= cap; 5322230130Smav pcmcap &= w->param.supp_pcm_size_rate; 5323230130Smav } 5324230130Smav ch->io[ret++] = as[ch->as].dacs[ch->asindex][i]; 5325230326Smav ch->stripecap &= w->wclass.conv.stripecap; 5326230130Smav /* Do not count redirection pin/dac channels. */ 5327230130Smav if (i == 15 && as[ch->as].hpredir >= 0) 5328230130Smav continue; 5329230130Smav channels += HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap) + 1; 5330230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap) != 1) 5331230130Smav onlystereo = 0; 5332230130Smav pinset |= (1 << i); 5333230130Smav } 5334230130Smav ch->io[ret] = -1; 5335230130Smav ch->channels = channels; 5336230130Smav 5337230130Smav if (as[ch->as].fakeredir) 5338230130Smav ret--; 5339230130Smav /* Standard speaks only about stereo pins and playback, ... */ 5340230130Smav if ((!onlystereo) || as[ch->as].mixed) 5341230130Smav pinset = 0; 5342230130Smav /* ..., but there it gives us info about speakers layout. */ 5343230130Smav as[ch->as].pinset = pinset; 5344230130Smav 5345230130Smav ch->supp_stream_formats = fmtcap; 5346230130Smav ch->supp_pcm_size_rate = pcmcap; 5347230130Smav 5348230130Smav /* 5349230130Smav * 8bit = 0 5350230130Smav * 16bit = 1 5351230130Smav * 20bit = 2 5352230130Smav * 24bit = 3 5353230130Smav * 32bit = 4 5354230130Smav */ 5355230130Smav if (ret > 0) { 5356230130Smav i = 0; 5357230130Smav if (HDA_PARAM_SUPP_STREAM_FORMATS_PCM(fmtcap)) { 5358230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16BIT(pcmcap)) 5359230130Smav ch->bit16 = 1; 5360230130Smav else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8BIT(pcmcap)) 5361230130Smav ch->bit16 = 0; 5362230488Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(pcmcap)) 5363230130Smav ch->bit32 = 3; 5364230130Smav else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(pcmcap)) 5365230130Smav ch->bit32 = 2; 5366230488Smav else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(pcmcap)) 5367230488Smav ch->bit32 = 4; 5368230130Smav if (!(devinfo->quirks & HDAA_QUIRK_FORCESTEREO)) { 5369230130Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 1, 0); 5370230130Smav if (ch->bit32) 5371230130Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 1, 0); 5372230130Smav } 5373230130Smav if (channels >= 2) { 5374230130Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 2, 0); 5375230130Smav if (ch->bit32) 5376230130Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 2, 0); 5377230130Smav } 5378230312Smav if (channels >= 3 && !onlystereo) { 5379230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 3, 0); 5380230312Smav if (ch->bit32) 5381230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 3, 0); 5382230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 3, 1); 5383230312Smav if (ch->bit32) 5384230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 3, 1); 5385230312Smav } 5386230312Smav if (channels >= 4) { 5387230130Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 4, 0); 5388230130Smav if (ch->bit32) 5389230130Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 4, 0); 5390230312Smav if (!onlystereo) { 5391230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 4, 1); 5392230312Smav if (ch->bit32) 5393230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 4, 1); 5394230312Smav } 5395230130Smav } 5396230312Smav if (channels >= 5 && !onlystereo) { 5397230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 5, 0); 5398230312Smav if (ch->bit32) 5399230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 5, 0); 5400230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 5, 1); 5401230312Smav if (ch->bit32) 5402230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 5, 1); 5403230312Smav } 5404230312Smav if (channels >= 6) { 5405230130Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 6, 1); 5406230130Smav if (ch->bit32) 5407230130Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 6, 1); 5408230312Smav if (!onlystereo) { 5409230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 6, 0); 5410230312Smav if (ch->bit32) 5411230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 6, 0); 5412230312Smav } 5413230130Smav } 5414230312Smav if (channels >= 7 && !onlystereo) { 5415230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 7, 0); 5416230312Smav if (ch->bit32) 5417230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 7, 0); 5418230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 7, 1); 5419230312Smav if (ch->bit32) 5420230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 7, 1); 5421230312Smav } 5422230312Smav if (channels >= 8) { 5423230130Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 8, 1); 5424230130Smav if (ch->bit32) 5425230130Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 8, 1); 5426230130Smav } 5427230130Smav } 5428230130Smav if (HDA_PARAM_SUPP_STREAM_FORMATS_AC3(fmtcap)) { 5429230130Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_AC3, 2, 0); 5430230513Smav if (channels >= 8) { 5431230513Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_AC3, 8, 0); 5432230513Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_AC3, 8, 1); 5433230513Smav } 5434230130Smav } 5435230130Smav ch->fmtlist[i] = 0; 5436230130Smav i = 0; 5437230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8KHZ(pcmcap)) 5438230130Smav ch->pcmrates[i++] = 8000; 5439230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_11KHZ(pcmcap)) 5440230130Smav ch->pcmrates[i++] = 11025; 5441230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16KHZ(pcmcap)) 5442230130Smav ch->pcmrates[i++] = 16000; 5443230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_22KHZ(pcmcap)) 5444230130Smav ch->pcmrates[i++] = 22050; 5445230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32KHZ(pcmcap)) 5446230130Smav ch->pcmrates[i++] = 32000; 5447230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_44KHZ(pcmcap)) 5448230130Smav ch->pcmrates[i++] = 44100; 5449230130Smav /* if (HDA_PARAM_SUPP_PCM_SIZE_RATE_48KHZ(pcmcap)) */ 5450230130Smav ch->pcmrates[i++] = 48000; 5451230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_88KHZ(pcmcap)) 5452230130Smav ch->pcmrates[i++] = 88200; 5453230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_96KHZ(pcmcap)) 5454230130Smav ch->pcmrates[i++] = 96000; 5455230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_176KHZ(pcmcap)) 5456230130Smav ch->pcmrates[i++] = 176400; 5457230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_192KHZ(pcmcap)) 5458230130Smav ch->pcmrates[i++] = 192000; 5459230130Smav /* if (HDA_PARAM_SUPP_PCM_SIZE_RATE_384KHZ(pcmcap)) */ 5460230130Smav ch->pcmrates[i] = 0; 5461230130Smav if (i > 0) { 5462230130Smav ch->caps.minspeed = ch->pcmrates[0]; 5463230130Smav ch->caps.maxspeed = ch->pcmrates[i - 1]; 5464230130Smav } 5465230130Smav } 5466230130Smav 5467230130Smav return (ret); 5468230130Smav} 5469230130Smav 5470230130Smavstatic void 5471230451Smavhdaa_prepare_pcms(struct hdaa_devinfo *devinfo) 5472230130Smav{ 5473230130Smav struct hdaa_audio_as *as = devinfo->as; 5474230130Smav int i, j, k, apdev = 0, ardev = 0, dpdev = 0, drdev = 0; 5475230130Smav 5476230130Smav for (i = 0; i < devinfo->ascnt; i++) { 5477230130Smav if (as[i].enable == 0) 5478230130Smav continue; 5479230130Smav if (as[i].dir == HDAA_CTL_IN) { 5480230130Smav if (as[i].digital) 5481230130Smav drdev++; 5482230130Smav else 5483230130Smav ardev++; 5484230130Smav } else { 5485230130Smav if (as[i].digital) 5486230130Smav dpdev++; 5487230130Smav else 5488230130Smav apdev++; 5489230130Smav } 5490230130Smav } 5491230130Smav devinfo->num_devs = 5492230130Smav max(ardev, apdev) + max(drdev, dpdev); 5493230130Smav devinfo->devs = 5494230130Smav (struct hdaa_pcm_devinfo *)malloc( 5495230130Smav devinfo->num_devs * sizeof(struct hdaa_pcm_devinfo), 5496230130Smav M_HDAA, M_ZERO | M_NOWAIT); 5497230130Smav if (devinfo->devs == NULL) { 5498230130Smav device_printf(devinfo->dev, 5499230130Smav "Unable to allocate memory for devices\n"); 5500230130Smav return; 5501230130Smav } 5502230130Smav for (i = 0; i < devinfo->num_devs; i++) { 5503230130Smav devinfo->devs[i].index = i; 5504230130Smav devinfo->devs[i].devinfo = devinfo; 5505230130Smav devinfo->devs[i].playas = -1; 5506230130Smav devinfo->devs[i].recas = -1; 5507230130Smav devinfo->devs[i].digital = 255; 5508230130Smav } 5509230130Smav for (i = 0; i < devinfo->ascnt; i++) { 5510230130Smav if (as[i].enable == 0) 5511230130Smav continue; 5512230130Smav for (j = 0; j < devinfo->num_devs; j++) { 5513230130Smav if (devinfo->devs[j].digital != 255 && 5514230130Smav (!devinfo->devs[j].digital) != 5515230130Smav (!as[i].digital)) 5516230130Smav continue; 5517230130Smav if (as[i].dir == HDAA_CTL_IN) { 5518230130Smav if (devinfo->devs[j].recas >= 0) 5519230130Smav continue; 5520230130Smav devinfo->devs[j].recas = i; 5521230130Smav } else { 5522230130Smav if (devinfo->devs[j].playas >= 0) 5523230130Smav continue; 5524230130Smav devinfo->devs[j].playas = i; 5525230130Smav } 5526230451Smav as[i].pdevinfo = &devinfo->devs[j]; 5527230130Smav for (k = 0; k < as[i].num_chans; k++) { 5528230130Smav devinfo->chans[as[i].chans[k]].pdevinfo = 5529230130Smav &devinfo->devs[j]; 5530230130Smav } 5531230130Smav devinfo->devs[j].digital = as[i].digital; 5532230130Smav break; 5533230130Smav } 5534230130Smav } 5535230451Smav} 5536230451Smav 5537230451Smavstatic void 5538230451Smavhdaa_create_pcms(struct hdaa_devinfo *devinfo) 5539230451Smav{ 5540230451Smav int i; 5541230451Smav 5542230130Smav for (i = 0; i < devinfo->num_devs; i++) { 5543230130Smav struct hdaa_pcm_devinfo *pdevinfo = &devinfo->devs[i]; 5544230130Smav 5545230130Smav pdevinfo->dev = device_add_child(devinfo->dev, "pcm", -1); 5546230130Smav device_set_ivars(pdevinfo->dev, (void *)pdevinfo); 5547230130Smav } 5548230130Smav} 5549230130Smav 5550230130Smavstatic void 5551230130Smavhdaa_dump_ctls(struct hdaa_pcm_devinfo *pdevinfo, const char *banner, uint32_t flag) 5552230130Smav{ 5553230130Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 5554230130Smav struct hdaa_audio_ctl *ctl; 5555230130Smav char buf[64]; 5556230130Smav int i, j, printed; 5557230130Smav 5558230130Smav if (flag == 0) { 5559230130Smav flag = ~(SOUND_MASK_VOLUME | SOUND_MASK_PCM | 5560230130Smav SOUND_MASK_CD | SOUND_MASK_LINE | SOUND_MASK_RECLEV | 5561230130Smav SOUND_MASK_MIC | SOUND_MASK_SPEAKER | SOUND_MASK_IGAIN | 5562230130Smav SOUND_MASK_OGAIN | SOUND_MASK_IMIX | SOUND_MASK_MONITOR); 5563230130Smav } 5564230130Smav 5565230130Smav for (j = 0; j < SOUND_MIXER_NRDEVICES; j++) { 5566230130Smav if ((flag & (1 << j)) == 0) 5567230130Smav continue; 5568230130Smav i = 0; 5569230130Smav printed = 0; 5570230130Smav while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) { 5571230130Smav if (ctl->enable == 0 || 5572230130Smav ctl->widget->enable == 0) 5573230130Smav continue; 5574230130Smav if (!((pdevinfo->playas >= 0 && 5575230130Smav ctl->widget->bindas == pdevinfo->playas) || 5576230130Smav (pdevinfo->recas >= 0 && 5577230130Smav ctl->widget->bindas == pdevinfo->recas) || 5578230130Smav (ctl->widget->bindas == -2 && pdevinfo->index == 0))) 5579230130Smav continue; 5580230130Smav if ((ctl->ossmask & (1 << j)) == 0) 5581230130Smav continue; 5582230130Smav 5583230130Smav if (printed == 0) { 5584230130Smav if (banner != NULL) { 5585230130Smav device_printf(pdevinfo->dev, "%s", banner); 5586230130Smav } else { 5587230130Smav device_printf(pdevinfo->dev, "Unknown Ctl"); 5588230130Smav } 5589230451Smav printf(" (OSS: %s)", 5590230130Smav hdaa_audio_ctl_ossmixer_mask2allname(1 << j, 5591230130Smav buf, sizeof(buf))); 5592230451Smav if (pdevinfo->ossmask & (1 << j)) { 5593230451Smav printf(": %+d/%+ddB\n", 5594230451Smav pdevinfo->minamp[j] / 4, 5595230451Smav pdevinfo->maxamp[j] / 4); 5596230451Smav } else 5597230451Smav printf("\n"); 5598230130Smav printed = 1; 5599230130Smav } 5600230130Smav device_printf(pdevinfo->dev, " +- ctl %2d (nid %3d %s", i, 5601230130Smav ctl->widget->nid, 5602230130Smav (ctl->ndir == HDAA_CTL_IN)?"in ":"out"); 5603230130Smav if (ctl->ndir == HDAA_CTL_IN && ctl->ndir == ctl->dir) 5604230130Smav printf(" %2d): ", ctl->index); 5605230130Smav else 5606230130Smav printf("): "); 5607230130Smav if (ctl->step > 0) { 5608230130Smav printf("%+d/%+ddB (%d steps)%s\n", 5609230451Smav MINQDB(ctl) / 4, 5610230451Smav MAXQDB(ctl) / 4, 5611230130Smav ctl->step + 1, 5612230130Smav ctl->mute?" + mute":""); 5613230130Smav } else 5614230130Smav printf("%s\n", ctl->mute?"mute":""); 5615230130Smav } 5616230130Smav } 5617243530Smav if (printed) 5618243530Smav device_printf(pdevinfo->dev, "\n"); 5619230130Smav} 5620230130Smav 5621230130Smavstatic void 5622230130Smavhdaa_dump_audio_formats(device_t dev, uint32_t fcap, uint32_t pcmcap) 5623230130Smav{ 5624230130Smav uint32_t cap; 5625230130Smav 5626230130Smav cap = fcap; 5627230130Smav if (cap != 0) { 5628243530Smav device_printf(dev, " Stream cap: 0x%08x", cap); 5629230130Smav if (HDA_PARAM_SUPP_STREAM_FORMATS_AC3(cap)) 5630230130Smav printf(" AC3"); 5631230130Smav if (HDA_PARAM_SUPP_STREAM_FORMATS_FLOAT32(cap)) 5632230130Smav printf(" FLOAT32"); 5633230130Smav if (HDA_PARAM_SUPP_STREAM_FORMATS_PCM(cap)) 5634230130Smav printf(" PCM"); 5635230130Smav printf("\n"); 5636230130Smav } 5637230130Smav cap = pcmcap; 5638230130Smav if (cap != 0) { 5639243530Smav device_printf(dev, " PCM cap: 0x%08x", cap); 5640230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8BIT(cap)) 5641230130Smav printf(" 8"); 5642230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16BIT(cap)) 5643230130Smav printf(" 16"); 5644230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(cap)) 5645230130Smav printf(" 20"); 5646230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(cap)) 5647230130Smav printf(" 24"); 5648230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(cap)) 5649230130Smav printf(" 32"); 5650230130Smav printf(" bits,"); 5651230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8KHZ(cap)) 5652230130Smav printf(" 8"); 5653230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_11KHZ(cap)) 5654230130Smav printf(" 11"); 5655230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16KHZ(cap)) 5656230130Smav printf(" 16"); 5657230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_22KHZ(cap)) 5658230130Smav printf(" 22"); 5659230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32KHZ(cap)) 5660230130Smav printf(" 32"); 5661230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_44KHZ(cap)) 5662230130Smav printf(" 44"); 5663230130Smav printf(" 48"); 5664230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_88KHZ(cap)) 5665230130Smav printf(" 88"); 5666230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_96KHZ(cap)) 5667230130Smav printf(" 96"); 5668230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_176KHZ(cap)) 5669230130Smav printf(" 176"); 5670230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_192KHZ(cap)) 5671230130Smav printf(" 192"); 5672230130Smav printf(" KHz\n"); 5673230130Smav } 5674230130Smav} 5675230130Smav 5676230130Smavstatic void 5677230130Smavhdaa_dump_pin(struct hdaa_widget *w) 5678230130Smav{ 5679230130Smav uint32_t pincap; 5680230130Smav 5681230130Smav pincap = w->wclass.pin.cap; 5682230130Smav 5683243530Smav device_printf(w->devinfo->dev, " Pin cap: 0x%08x", pincap); 5684230130Smav if (HDA_PARAM_PIN_CAP_IMP_SENSE_CAP(pincap)) 5685230130Smav printf(" ISC"); 5686230130Smav if (HDA_PARAM_PIN_CAP_TRIGGER_REQD(pincap)) 5687230130Smav printf(" TRQD"); 5688230130Smav if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(pincap)) 5689230130Smav printf(" PDC"); 5690230130Smav if (HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap)) 5691230130Smav printf(" HP"); 5692230130Smav if (HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap)) 5693230130Smav printf(" OUT"); 5694230130Smav if (HDA_PARAM_PIN_CAP_INPUT_CAP(pincap)) 5695230130Smav printf(" IN"); 5696230130Smav if (HDA_PARAM_PIN_CAP_BALANCED_IO_PINS(pincap)) 5697230130Smav printf(" BAL"); 5698230130Smav if (HDA_PARAM_PIN_CAP_HDMI(pincap)) 5699230130Smav printf(" HDMI"); 5700230130Smav if (HDA_PARAM_PIN_CAP_VREF_CTRL(pincap)) { 5701230130Smav printf(" VREF["); 5702230130Smav if (HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap)) 5703230130Smav printf(" 50"); 5704230130Smav if (HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap)) 5705230130Smav printf(" 80"); 5706230130Smav if (HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap)) 5707230130Smav printf(" 100"); 5708230130Smav if (HDA_PARAM_PIN_CAP_VREF_CTRL_GROUND(pincap)) 5709230130Smav printf(" GROUND"); 5710230130Smav if (HDA_PARAM_PIN_CAP_VREF_CTRL_HIZ(pincap)) 5711230130Smav printf(" HIZ"); 5712230130Smav printf(" ]"); 5713230130Smav } 5714230130Smav if (HDA_PARAM_PIN_CAP_EAPD_CAP(pincap)) 5715230130Smav printf(" EAPD"); 5716230130Smav if (HDA_PARAM_PIN_CAP_DP(pincap)) 5717230130Smav printf(" DP"); 5718230130Smav if (HDA_PARAM_PIN_CAP_HBR(pincap)) 5719230130Smav printf(" HBR"); 5720230130Smav printf("\n"); 5721230130Smav device_printf(w->devinfo->dev, " Pin config: 0x%08x\n", 5722230130Smav w->wclass.pin.config); 5723230130Smav device_printf(w->devinfo->dev, " Pin control: 0x%08x", w->wclass.pin.ctrl); 5724230130Smav if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE) 5725230130Smav printf(" HP"); 5726230130Smav if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE) 5727230130Smav printf(" IN"); 5728230130Smav if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE) 5729230130Smav printf(" OUT"); 5730230312Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) { 5731230312Smav if ((w->wclass.pin.ctrl & 5732230312Smav HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK) == 0x03) 5733230312Smav printf(" HBR"); 5734230312Smav else if ((w->wclass.pin.ctrl & 5735230312Smav HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK) != 0) 5736230312Smav printf(" EPTs"); 5737230312Smav } else { 5738230312Smav if ((w->wclass.pin.ctrl & 5739230312Smav HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK) != 0) 5740230312Smav printf(" VREFs"); 5741230312Smav } 5742230130Smav printf("\n"); 5743230130Smav} 5744230130Smav 5745230130Smavstatic void 5746230130Smavhdaa_dump_pin_config(struct hdaa_widget *w, uint32_t conf) 5747230130Smav{ 5748230130Smav 5749230130Smav device_printf(w->devinfo->dev, "%2d %08x %-2d %-2d " 5750230130Smav "%-13s %-5s %-7s %-10s %-7s %d%s\n", 5751230130Smav w->nid, conf, 5752230130Smav HDA_CONFIG_DEFAULTCONF_ASSOCIATION(conf), 5753230130Smav HDA_CONFIG_DEFAULTCONF_SEQUENCE(conf), 5754230130Smav HDA_DEVS[HDA_CONFIG_DEFAULTCONF_DEVICE(conf)], 5755230130Smav HDA_CONNS[HDA_CONFIG_DEFAULTCONF_CONNECTIVITY(conf)], 5756230130Smav HDA_CONNECTORS[HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE(conf)], 5757230130Smav HDA_LOCS[HDA_CONFIG_DEFAULTCONF_LOCATION(conf)], 5758230130Smav HDA_COLORS[HDA_CONFIG_DEFAULTCONF_COLOR(conf)], 5759230130Smav HDA_CONFIG_DEFAULTCONF_MISC(conf), 5760230130Smav (w->enable == 0)?" DISA":""); 5761230130Smav} 5762230130Smav 5763230130Smavstatic void 5764230130Smavhdaa_dump_pin_configs(struct hdaa_devinfo *devinfo) 5765230130Smav{ 5766230130Smav struct hdaa_widget *w; 5767230130Smav int i; 5768230130Smav 5769230130Smav device_printf(devinfo->dev, "nid 0x as seq " 5770230130Smav "device conn jack loc color misc\n"); 5771230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 5772230130Smav w = hdaa_widget_get(devinfo, i); 5773230130Smav if (w == NULL) 5774230130Smav continue; 5775230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 5776230130Smav continue; 5777230130Smav hdaa_dump_pin_config(w, w->wclass.pin.config); 5778230130Smav } 5779230130Smav} 5780230130Smav 5781230130Smavstatic void 5782230130Smavhdaa_dump_amp(device_t dev, uint32_t cap, char *banner) 5783230130Smav{ 5784243530Smav int offset, size, step; 5785243530Smav 5786243530Smav offset = HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(cap); 5787243530Smav size = HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(cap); 5788243530Smav step = HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(cap); 5789243530Smav device_printf(dev, " %s amp: 0x%08x " 5790243530Smav "mute=%d step=%d size=%d offset=%d (%+d/%+ddB)\n", 5791243530Smav banner, cap, 5792230130Smav HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(cap), 5793243530Smav step, size, offset, 5794243530Smav ((0 - offset) * (size + 1)) / 4, 5795243530Smav ((step - offset) * (size + 1)) / 4); 5796230130Smav} 5797230130Smav 5798230130Smavstatic void 5799230130Smavhdaa_dump_nodes(struct hdaa_devinfo *devinfo) 5800230130Smav{ 5801230130Smav struct hdaa_widget *w, *cw; 5802230130Smav char buf[64]; 5803230130Smav int i, j; 5804230130Smav 5805230130Smav device_printf(devinfo->dev, "\n"); 5806243530Smav device_printf(devinfo->dev, "Default parameters:\n"); 5807230130Smav hdaa_dump_audio_formats(devinfo->dev, 5808230130Smav devinfo->supp_stream_formats, 5809230130Smav devinfo->supp_pcm_size_rate); 5810243530Smav hdaa_dump_amp(devinfo->dev, devinfo->inamp_cap, " Input"); 5811243530Smav hdaa_dump_amp(devinfo->dev, devinfo->outamp_cap, "Output"); 5812230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 5813230130Smav w = hdaa_widget_get(devinfo, i); 5814230130Smav if (w == NULL) { 5815230130Smav device_printf(devinfo->dev, "Ghost widget nid=%d\n", i); 5816230130Smav continue; 5817230130Smav } 5818230130Smav device_printf(devinfo->dev, "\n"); 5819230130Smav device_printf(devinfo->dev, " nid: %d%s\n", w->nid, 5820230130Smav (w->enable == 0) ? " [DISABLED]" : ""); 5821230130Smav device_printf(devinfo->dev, " Name: %s\n", w->name); 5822243530Smav device_printf(devinfo->dev, " Widget cap: 0x%08x", 5823230130Smav w->param.widget_cap); 5824230130Smav if (w->param.widget_cap & 0x0ee1) { 5825230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_LR_SWAP(w->param.widget_cap)) 5826230130Smav printf(" LRSWAP"); 5827230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_POWER_CTRL(w->param.widget_cap)) 5828230130Smav printf(" PWR"); 5829230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) 5830230130Smav printf(" DIGITAL"); 5831230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_UNSOL_CAP(w->param.widget_cap)) 5832230130Smav printf(" UNSOL"); 5833230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_PROC_WIDGET(w->param.widget_cap)) 5834230130Smav printf(" PROC"); 5835230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_STRIPE(w->param.widget_cap)) 5836230326Smav printf(" STRIPE(x%d)", 5837230326Smav 1 << (fls(w->wclass.conv.stripecap) - 1)); 5838230130Smav j = HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap); 5839230130Smav if (j == 1) 5840230130Smav printf(" STEREO"); 5841230130Smav else if (j > 1) 5842230130Smav printf(" %dCH", j + 1); 5843230130Smav } 5844243530Smav printf("\n"); 5845230130Smav if (w->bindas != -1) { 5846243530Smav device_printf(devinfo->dev, " Association: %d (0x%04x)\n", 5847230130Smav w->bindas, w->bindseqmask); 5848230130Smav } 5849230130Smav if (w->ossmask != 0 || w->ossdev >= 0) { 5850230130Smav device_printf(devinfo->dev, " OSS: %s", 5851230130Smav hdaa_audio_ctl_ossmixer_mask2allname(w->ossmask, buf, sizeof(buf))); 5852230130Smav if (w->ossdev >= 0) 5853230451Smav printf(" (%s)", ossnames[w->ossdev]); 5854230130Smav printf("\n"); 5855230130Smav } 5856230130Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT || 5857230130Smav w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) { 5858230130Smav hdaa_dump_audio_formats(devinfo->dev, 5859230130Smav w->param.supp_stream_formats, 5860230130Smav w->param.supp_pcm_size_rate); 5861230130Smav } else if (w->type == 5862230130Smav HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX || w->waspin) 5863230130Smav hdaa_dump_pin(w); 5864230130Smav if (w->param.eapdbtl != HDA_INVALID) 5865230130Smav device_printf(devinfo->dev, " EAPD: 0x%08x\n", 5866230130Smav w->param.eapdbtl); 5867230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_OUT_AMP(w->param.widget_cap) && 5868230130Smav w->param.outamp_cap != 0) 5869230130Smav hdaa_dump_amp(devinfo->dev, w->param.outamp_cap, "Output"); 5870230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_IN_AMP(w->param.widget_cap) && 5871230130Smav w->param.inamp_cap != 0) 5872230130Smav hdaa_dump_amp(devinfo->dev, w->param.inamp_cap, " Input"); 5873243530Smav if (w->nconns > 0) 5874243530Smav device_printf(devinfo->dev, " Connections: %d\n", w->nconns); 5875230130Smav for (j = 0; j < w->nconns; j++) { 5876230130Smav cw = hdaa_widget_get(devinfo, w->conns[j]); 5877230130Smav device_printf(devinfo->dev, " + %s<- nid=%d [%s]", 5878230130Smav (w->connsenable[j] == 0)?"[DISABLED] ":"", 5879230130Smav w->conns[j], (cw == NULL) ? "GHOST!" : cw->name); 5880230130Smav if (cw == NULL) 5881230130Smav printf(" [UNKNOWN]"); 5882230130Smav else if (cw->enable == 0) 5883230130Smav printf(" [DISABLED]"); 5884230130Smav if (w->nconns > 1 && w->selconn == j && w->type != 5885230130Smav HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) 5886230130Smav printf(" (selected)"); 5887230130Smav printf("\n"); 5888230130Smav } 5889230130Smav } 5890230130Smav 5891230130Smav} 5892230130Smav 5893230130Smavstatic void 5894230130Smavhdaa_dump_dst_nid(struct hdaa_pcm_devinfo *pdevinfo, nid_t nid, int depth) 5895230130Smav{ 5896230130Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 5897230130Smav struct hdaa_widget *w, *cw; 5898230130Smav char buf[64]; 5899243530Smav int i; 5900230130Smav 5901230130Smav if (depth > HDA_PARSE_MAXDEPTH) 5902230130Smav return; 5903230130Smav 5904230130Smav w = hdaa_widget_get(devinfo, nid); 5905230130Smav if (w == NULL || w->enable == 0) 5906230130Smav return; 5907230130Smav 5908230130Smav if (depth == 0) 5909230130Smav device_printf(pdevinfo->dev, "%*s", 4, ""); 5910230130Smav else 5911230130Smav device_printf(pdevinfo->dev, "%*s + <- ", 4 + (depth - 1) * 7, ""); 5912230130Smav printf("nid=%d [%s]", w->nid, w->name); 5913230130Smav 5914230130Smav if (depth > 0) { 5915230130Smav if (w->ossmask == 0) { 5916230130Smav printf("\n"); 5917230130Smav return; 5918230130Smav } 5919230130Smav printf(" [src: %s]", 5920230130Smav hdaa_audio_ctl_ossmixer_mask2allname( 5921230130Smav w->ossmask, buf, sizeof(buf))); 5922230130Smav if (w->ossdev >= 0) { 5923230130Smav printf("\n"); 5924230130Smav return; 5925230130Smav } 5926230130Smav } 5927230130Smav printf("\n"); 5928230130Smav 5929230130Smav for (i = 0; i < w->nconns; i++) { 5930230130Smav if (w->connsenable[i] == 0) 5931230130Smav continue; 5932230130Smav cw = hdaa_widget_get(devinfo, w->conns[i]); 5933230130Smav if (cw == NULL || cw->enable == 0 || cw->bindas == -1) 5934230130Smav continue; 5935230130Smav hdaa_dump_dst_nid(pdevinfo, w->conns[i], depth + 1); 5936230130Smav } 5937230130Smav 5938230130Smav} 5939230130Smav 5940230130Smavstatic void 5941230130Smavhdaa_dump_dac(struct hdaa_pcm_devinfo *pdevinfo) 5942230130Smav{ 5943230130Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 5944230130Smav struct hdaa_audio_as *as; 5945230130Smav struct hdaa_widget *w; 5946243530Smav nid_t *nids; 5947243530Smav int chid, i; 5948230130Smav 5949230130Smav if (pdevinfo->playas < 0) 5950230130Smav return; 5951230130Smav 5952243530Smav device_printf(pdevinfo->dev, "Playback:\n"); 5953243530Smav 5954243530Smav chid = devinfo->as[pdevinfo->playas].chans[0]; 5955243530Smav hdaa_dump_audio_formats(pdevinfo->dev, 5956243530Smav devinfo->chans[chid].supp_stream_formats, 5957243530Smav devinfo->chans[chid].supp_pcm_size_rate); 5958243530Smav for (i = 0; i < devinfo->as[pdevinfo->playas].num_chans; i++) { 5959243530Smav chid = devinfo->as[pdevinfo->playas].chans[i]; 5960243530Smav device_printf(pdevinfo->dev, " DAC:"); 5961243530Smav for (nids = devinfo->chans[chid].io; *nids != -1; nids++) 5962243530Smav printf(" %d", *nids); 5963243530Smav printf("\n"); 5964243530Smav } 5965243530Smav 5966230130Smav as = &devinfo->as[pdevinfo->playas]; 5967230130Smav for (i = 0; i < 16; i++) { 5968230130Smav if (as->pins[i] <= 0) 5969230130Smav continue; 5970230130Smav w = hdaa_widget_get(devinfo, as->pins[i]); 5971230130Smav if (w == NULL || w->enable == 0) 5972230130Smav continue; 5973230130Smav device_printf(pdevinfo->dev, "\n"); 5974230130Smav hdaa_dump_dst_nid(pdevinfo, as->pins[i], 0); 5975230130Smav } 5976243530Smav device_printf(pdevinfo->dev, "\n"); 5977230130Smav} 5978230130Smav 5979230130Smavstatic void 5980230130Smavhdaa_dump_adc(struct hdaa_pcm_devinfo *pdevinfo) 5981230130Smav{ 5982230130Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 5983230130Smav struct hdaa_widget *w; 5984243530Smav nid_t *nids; 5985243530Smav int chid, i; 5986230130Smav 5987230130Smav if (pdevinfo->recas < 0) 5988230130Smav return; 5989230130Smav 5990243530Smav device_printf(pdevinfo->dev, "Record:\n"); 5991243530Smav 5992243530Smav chid = devinfo->as[pdevinfo->recas].chans[0]; 5993243530Smav hdaa_dump_audio_formats(pdevinfo->dev, 5994243530Smav devinfo->chans[chid].supp_stream_formats, 5995243530Smav devinfo->chans[chid].supp_pcm_size_rate); 5996243530Smav for (i = 0; i < devinfo->as[pdevinfo->recas].num_chans; i++) { 5997243530Smav chid = devinfo->as[pdevinfo->recas].chans[i]; 5998243530Smav device_printf(pdevinfo->dev, " ADC:"); 5999243530Smav for (nids = devinfo->chans[chid].io; *nids != -1; nids++) 6000243530Smav printf(" %d", *nids); 6001243530Smav printf("\n"); 6002243530Smav } 6003243530Smav 6004230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 6005230130Smav w = hdaa_widget_get(devinfo, i); 6006230130Smav if (w == NULL || w->enable == 0) 6007230130Smav continue; 6008230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) 6009230130Smav continue; 6010230130Smav if (w->bindas != pdevinfo->recas) 6011230130Smav continue; 6012230130Smav device_printf(pdevinfo->dev, "\n"); 6013230130Smav hdaa_dump_dst_nid(pdevinfo, i, 0); 6014230130Smav } 6015243530Smav device_printf(pdevinfo->dev, "\n"); 6016230130Smav} 6017230130Smav 6018230130Smavstatic void 6019230130Smavhdaa_dump_mix(struct hdaa_pcm_devinfo *pdevinfo) 6020230130Smav{ 6021230130Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 6022230130Smav struct hdaa_widget *w; 6023230130Smav int i; 6024230130Smav int printed = 0; 6025230130Smav 6026230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 6027230130Smav w = hdaa_widget_get(devinfo, i); 6028230130Smav if (w == NULL || w->enable == 0) 6029230130Smav continue; 6030230130Smav if (w->ossdev != SOUND_MIXER_IMIX) 6031230130Smav continue; 6032230451Smav if (w->bindas != pdevinfo->recas) 6033230451Smav continue; 6034230130Smav if (printed == 0) { 6035230130Smav printed = 1; 6036230130Smav device_printf(pdevinfo->dev, "Input Mix:\n"); 6037230130Smav } 6038230130Smav device_printf(pdevinfo->dev, "\n"); 6039230130Smav hdaa_dump_dst_nid(pdevinfo, i, 0); 6040230130Smav } 6041243530Smav if (printed) 6042230130Smav device_printf(pdevinfo->dev, "\n"); 6043230130Smav} 6044230130Smav 6045230130Smavstatic void 6046230130Smavhdaa_pindump(device_t dev) 6047230130Smav{ 6048230130Smav struct hdaa_devinfo *devinfo = device_get_softc(dev); 6049230130Smav struct hdaa_widget *w; 6050230130Smav uint32_t res, pincap, delay; 6051230130Smav int i; 6052230130Smav 6053230130Smav device_printf(dev, "Dumping AFG pins:\n"); 6054230130Smav device_printf(dev, "nid 0x as seq " 6055230130Smav "device conn jack loc color misc\n"); 6056230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 6057230130Smav w = hdaa_widget_get(devinfo, i); 6058230130Smav if (w == NULL || w->type != 6059230130Smav HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 6060230130Smav continue; 6061230130Smav hdaa_dump_pin_config(w, w->wclass.pin.config); 6062230130Smav pincap = w->wclass.pin.cap; 6063230130Smav device_printf(dev, " Caps: %2s %3s %2s %4s %4s", 6064230130Smav HDA_PARAM_PIN_CAP_INPUT_CAP(pincap)?"IN":"", 6065230130Smav HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap)?"OUT":"", 6066230130Smav HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap)?"HP":"", 6067230130Smav HDA_PARAM_PIN_CAP_EAPD_CAP(pincap)?"EAPD":"", 6068230130Smav HDA_PARAM_PIN_CAP_VREF_CTRL(pincap)?"VREF":""); 6069230130Smav if (HDA_PARAM_PIN_CAP_IMP_SENSE_CAP(pincap) || 6070230130Smav HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(pincap)) { 6071230130Smav if (HDA_PARAM_PIN_CAP_TRIGGER_REQD(pincap)) { 6072230130Smav delay = 0; 6073230130Smav hda_command(dev, 6074230130Smav HDA_CMD_SET_PIN_SENSE(0, w->nid, 0)); 6075230130Smav do { 6076230130Smav res = hda_command(dev, 6077230130Smav HDA_CMD_GET_PIN_SENSE(0, w->nid)); 6078230130Smav if (res != 0x7fffffff && res != 0xffffffff) 6079230130Smav break; 6080230130Smav DELAY(10); 6081230130Smav } while (++delay < 10000); 6082230130Smav } else { 6083230130Smav delay = 0; 6084230130Smav res = hda_command(dev, HDA_CMD_GET_PIN_SENSE(0, 6085230130Smav w->nid)); 6086230130Smav } 6087230312Smav printf(" Sense: 0x%08x (%sconnected%s)", res, 6088230130Smav (res & HDA_CMD_GET_PIN_SENSE_PRESENCE_DETECT) ? 6089230312Smav "" : "dis", 6090230312Smav (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap) && 6091230312Smav (res & HDA_CMD_GET_PIN_SENSE_ELD_VALID)) ? 6092230312Smav ", ELD valid" : ""); 6093230130Smav if (delay > 0) 6094230130Smav printf(" delay %dus", delay * 10); 6095230130Smav } 6096230130Smav printf("\n"); 6097230130Smav } 6098230130Smav device_printf(dev, 6099230130Smav "NumGPIO=%d NumGPO=%d NumGPI=%d GPIWake=%d GPIUnsol=%d\n", 6100230130Smav HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap), 6101230130Smav HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap), 6102230130Smav HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap), 6103230130Smav HDA_PARAM_GPIO_COUNT_GPI_WAKE(devinfo->gpio_cap), 6104230130Smav HDA_PARAM_GPIO_COUNT_GPI_UNSOL(devinfo->gpio_cap)); 6105230130Smav hdaa_dump_gpi(devinfo); 6106230130Smav hdaa_dump_gpio(devinfo); 6107230130Smav hdaa_dump_gpo(devinfo); 6108230130Smav} 6109230130Smav 6110230130Smavstatic void 6111230130Smavhdaa_configure(device_t dev) 6112230130Smav{ 6113230130Smav struct hdaa_devinfo *devinfo = device_get_softc(dev); 6114230130Smav struct hdaa_audio_ctl *ctl; 6115230130Smav int i; 6116230130Smav 6117230130Smav HDA_BOOTHVERBOSE( 6118230130Smav device_printf(dev, "Applying built-in patches...\n"); 6119230130Smav ); 6120230130Smav hdaa_patch(devinfo); 6121230130Smav HDA_BOOTHVERBOSE( 6122230130Smav device_printf(dev, "Applying local patches...\n"); 6123230130Smav ); 6124230130Smav hdaa_local_patch(devinfo); 6125230130Smav hdaa_audio_postprocess(devinfo); 6126230130Smav HDA_BOOTHVERBOSE( 6127230130Smav device_printf(dev, "Parsing Ctls...\n"); 6128230130Smav ); 6129230130Smav hdaa_audio_ctl_parse(devinfo); 6130230130Smav HDA_BOOTHVERBOSE( 6131230130Smav device_printf(dev, "Disabling nonaudio...\n"); 6132230130Smav ); 6133230130Smav hdaa_audio_disable_nonaudio(devinfo); 6134230130Smav HDA_BOOTHVERBOSE( 6135230130Smav device_printf(dev, "Disabling useless...\n"); 6136230130Smav ); 6137230130Smav hdaa_audio_disable_useless(devinfo); 6138230130Smav HDA_BOOTVERBOSE( 6139230130Smav device_printf(dev, "Patched pins configuration:\n"); 6140230130Smav hdaa_dump_pin_configs(devinfo); 6141230130Smav ); 6142230130Smav HDA_BOOTHVERBOSE( 6143230130Smav device_printf(dev, "Parsing pin associations...\n"); 6144230130Smav ); 6145230130Smav hdaa_audio_as_parse(devinfo); 6146230130Smav HDA_BOOTHVERBOSE( 6147230130Smav device_printf(dev, "Building AFG tree...\n"); 6148230130Smav ); 6149230130Smav hdaa_audio_build_tree(devinfo); 6150230130Smav HDA_BOOTHVERBOSE( 6151230130Smav device_printf(dev, "Disabling unassociated " 6152230130Smav "widgets...\n"); 6153230130Smav ); 6154230130Smav hdaa_audio_disable_unas(devinfo); 6155230130Smav HDA_BOOTHVERBOSE( 6156230130Smav device_printf(dev, "Disabling nonselected " 6157230130Smav "inputs...\n"); 6158230130Smav ); 6159230130Smav hdaa_audio_disable_notselected(devinfo); 6160230130Smav HDA_BOOTHVERBOSE( 6161230130Smav device_printf(dev, "Disabling useless...\n"); 6162230130Smav ); 6163230130Smav hdaa_audio_disable_useless(devinfo); 6164230130Smav HDA_BOOTHVERBOSE( 6165230130Smav device_printf(dev, "Disabling " 6166230130Smav "crossassociatement connections...\n"); 6167230130Smav ); 6168230130Smav hdaa_audio_disable_crossas(devinfo); 6169230130Smav HDA_BOOTHVERBOSE( 6170230130Smav device_printf(dev, "Disabling useless...\n"); 6171230130Smav ); 6172230130Smav hdaa_audio_disable_useless(devinfo); 6173230130Smav HDA_BOOTHVERBOSE( 6174230130Smav device_printf(dev, "Binding associations to channels...\n"); 6175230130Smav ); 6176230130Smav hdaa_audio_bind_as(devinfo); 6177230130Smav HDA_BOOTHVERBOSE( 6178230130Smav device_printf(dev, "Assigning names to signal sources...\n"); 6179230130Smav ); 6180230130Smav hdaa_audio_assign_names(devinfo); 6181230130Smav HDA_BOOTHVERBOSE( 6182230451Smav device_printf(dev, "Preparing PCM devices...\n"); 6183230451Smav ); 6184230451Smav hdaa_prepare_pcms(devinfo); 6185230451Smav HDA_BOOTHVERBOSE( 6186230130Smav device_printf(dev, "Assigning mixers to the tree...\n"); 6187230130Smav ); 6188230130Smav hdaa_audio_assign_mixers(devinfo); 6189230130Smav HDA_BOOTHVERBOSE( 6190230130Smav device_printf(dev, "Preparing pin controls...\n"); 6191230130Smav ); 6192230130Smav hdaa_audio_prepare_pin_ctrl(devinfo); 6193230130Smav HDA_BOOTHVERBOSE( 6194230130Smav device_printf(dev, "AFG commit...\n"); 6195230130Smav ); 6196230130Smav hdaa_audio_commit(devinfo); 6197230130Smav HDA_BOOTHVERBOSE( 6198230130Smav device_printf(dev, "Applying direct built-in patches...\n"); 6199230130Smav ); 6200230130Smav hdaa_patch_direct(devinfo); 6201230130Smav HDA_BOOTHVERBOSE( 6202230551Smav device_printf(dev, "Pin sense init...\n"); 6203230312Smav ); 6204230551Smav hdaa_sense_init(devinfo); 6205230312Smav HDA_BOOTHVERBOSE( 6206230130Smav device_printf(dev, "Creating PCM devices...\n"); 6207230130Smav ); 6208230130Smav hdaa_create_pcms(devinfo); 6209230130Smav 6210230130Smav HDA_BOOTVERBOSE( 6211230130Smav if (devinfo->quirks != 0) { 6212230130Smav device_printf(dev, "FG config/quirks:"); 6213230130Smav for (i = 0; i < HDAA_QUIRKS_TAB_LEN; i++) { 6214230130Smav if ((devinfo->quirks & 6215230130Smav hdaa_quirks_tab[i].value) == 6216230130Smav hdaa_quirks_tab[i].value) 6217230130Smav printf(" %s", hdaa_quirks_tab[i].key); 6218230130Smav } 6219230130Smav printf("\n"); 6220230130Smav } 6221243530Smav ); 6222230130Smav 6223243530Smav HDA_BOOTHVERBOSE( 6224230130Smav device_printf(dev, "\n"); 6225243530Smav device_printf(dev, "+-----------+\n"); 6226243530Smav device_printf(dev, "| HDA NODES |\n"); 6227243530Smav device_printf(dev, "+-----------+\n"); 6228230130Smav hdaa_dump_nodes(devinfo); 6229230130Smav 6230230130Smav device_printf(dev, "\n"); 6231243530Smav device_printf(dev, "+----------------+\n"); 6232243530Smav device_printf(dev, "| HDA AMPLIFIERS |\n"); 6233243530Smav device_printf(dev, "+----------------+\n"); 6234230130Smav device_printf(dev, "\n"); 6235230130Smav i = 0; 6236230130Smav while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) { 6237230130Smav device_printf(dev, "%3d: nid %3d %s (%s) index %d", i, 6238230130Smav (ctl->widget != NULL) ? ctl->widget->nid : -1, 6239230130Smav (ctl->ndir == HDAA_CTL_IN)?"in ":"out", 6240230130Smav (ctl->dir == HDAA_CTL_IN)?"in ":"out", 6241230130Smav ctl->index); 6242230130Smav if (ctl->childwidget != NULL) 6243230130Smav printf(" cnid %3d", ctl->childwidget->nid); 6244230130Smav else 6245230130Smav printf(" "); 6246230130Smav printf(" ossmask=0x%08x\n", 6247230130Smav ctl->ossmask); 6248230130Smav device_printf(dev, 6249230130Smav " mute: %d step: %3d size: %3d off: %3d%s\n", 6250230130Smav ctl->mute, ctl->step, ctl->size, ctl->offset, 6251230130Smav (ctl->enable == 0) ? " [DISABLED]" : 6252230130Smav ((ctl->ossmask == 0) ? " [UNUSED]" : "")); 6253230130Smav } 6254230130Smav device_printf(dev, "\n"); 6255230130Smav ); 6256230130Smav} 6257230130Smav 6258230130Smavstatic void 6259230130Smavhdaa_unconfigure(device_t dev) 6260230130Smav{ 6261230130Smav struct hdaa_devinfo *devinfo = device_get_softc(dev); 6262230130Smav struct hdaa_widget *w; 6263230130Smav int i, j; 6264230130Smav 6265230130Smav HDA_BOOTHVERBOSE( 6266230551Smav device_printf(dev, "Pin sense deinit...\n"); 6267230130Smav ); 6268230551Smav hdaa_sense_deinit(devinfo); 6269230130Smav free(devinfo->ctl, M_HDAA); 6270230130Smav devinfo->ctl = NULL; 6271230130Smav devinfo->ctlcnt = 0; 6272230130Smav free(devinfo->as, M_HDAA); 6273230130Smav devinfo->as = NULL; 6274230130Smav devinfo->ascnt = 0; 6275230130Smav free(devinfo->devs, M_HDAA); 6276230130Smav devinfo->devs = NULL; 6277230130Smav devinfo->num_devs = 0; 6278230130Smav free(devinfo->chans, M_HDAA); 6279230130Smav devinfo->chans = NULL; 6280230130Smav devinfo->num_chans = 0; 6281230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 6282230130Smav w = hdaa_widget_get(devinfo, i); 6283230130Smav if (w == NULL) 6284230130Smav continue; 6285230130Smav w->enable = 1; 6286230130Smav w->selconn = -1; 6287230130Smav w->pflags = 0; 6288230130Smav w->bindas = -1; 6289230130Smav w->bindseqmask = 0; 6290230130Smav w->ossdev = -1; 6291230130Smav w->ossmask = 0; 6292230130Smav for (j = 0; j < w->nconns; j++) 6293230130Smav w->connsenable[j] = 1; 6294230451Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 6295230451Smav w->wclass.pin.config = w->wclass.pin.newconf; 6296230312Smav if (w->eld != NULL) { 6297230312Smav w->eld_len = 0; 6298230312Smav free(w->eld, M_HDAA); 6299230312Smav w->eld = NULL; 6300230312Smav } 6301230130Smav } 6302230130Smav} 6303230130Smav 6304230130Smavstatic int 6305230130Smavhdaa_sysctl_gpi_state(SYSCTL_HANDLER_ARGS) 6306230130Smav{ 6307230130Smav struct hdaa_devinfo *devinfo = oidp->oid_arg1; 6308230130Smav device_t dev = devinfo->dev; 6309230130Smav char buf[256]; 6310230130Smav int n = 0, i, numgpi; 6311230130Smav uint32_t data = 0; 6312230130Smav 6313230130Smav buf[0] = 0; 6314230130Smav hdaa_lock(devinfo); 6315230130Smav numgpi = HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap); 6316230130Smav if (numgpi > 0) { 6317230130Smav data = hda_command(dev, 6318230130Smav HDA_CMD_GET_GPI_DATA(0, devinfo->nid)); 6319230130Smav } 6320230130Smav hdaa_unlock(devinfo); 6321230130Smav for (i = 0; i < numgpi; i++) { 6322230130Smav n += snprintf(buf + n, sizeof(buf) - n, "%s%d=%d", 6323230130Smav n != 0 ? " " : "", i, ((data >> i) & 1)); 6324230130Smav } 6325230130Smav return (sysctl_handle_string(oidp, buf, sizeof(buf), req)); 6326230130Smav} 6327230130Smav 6328230130Smavstatic int 6329230130Smavhdaa_sysctl_gpio_state(SYSCTL_HANDLER_ARGS) 6330230130Smav{ 6331230130Smav struct hdaa_devinfo *devinfo = oidp->oid_arg1; 6332230130Smav device_t dev = devinfo->dev; 6333230130Smav char buf[256]; 6334230130Smav int n = 0, i, numgpio; 6335230130Smav uint32_t data = 0, enable = 0, dir = 0; 6336230130Smav 6337230130Smav buf[0] = 0; 6338230130Smav hdaa_lock(devinfo); 6339230130Smav numgpio = HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap); 6340230130Smav if (numgpio > 0) { 6341230130Smav data = hda_command(dev, 6342230130Smav HDA_CMD_GET_GPIO_DATA(0, devinfo->nid)); 6343230130Smav enable = hda_command(dev, 6344230130Smav HDA_CMD_GET_GPIO_ENABLE_MASK(0, devinfo->nid)); 6345230130Smav dir = hda_command(dev, 6346230130Smav HDA_CMD_GET_GPIO_DIRECTION(0, devinfo->nid)); 6347230130Smav } 6348230130Smav hdaa_unlock(devinfo); 6349230130Smav for (i = 0; i < numgpio; i++) { 6350230130Smav n += snprintf(buf + n, sizeof(buf) - n, "%s%d=", 6351230130Smav n != 0 ? " " : "", i); 6352230130Smav if ((enable & (1 << i)) == 0) { 6353230130Smav n += snprintf(buf + n, sizeof(buf) - n, "disabled"); 6354230130Smav continue; 6355230130Smav } 6356230130Smav n += snprintf(buf + n, sizeof(buf) - n, "%sput(%d)", 6357230130Smav ((dir >> i) & 1) ? "out" : "in", ((data >> i) & 1)); 6358230130Smav } 6359230130Smav return (sysctl_handle_string(oidp, buf, sizeof(buf), req)); 6360230130Smav} 6361230130Smav 6362230130Smavstatic int 6363230130Smavhdaa_sysctl_gpio_config(SYSCTL_HANDLER_ARGS) 6364230130Smav{ 6365230130Smav struct hdaa_devinfo *devinfo = oidp->oid_arg1; 6366230130Smav char buf[256]; 6367230130Smav int error, n = 0, i, numgpio; 6368230130Smav uint32_t gpio, x; 6369230130Smav 6370230130Smav gpio = devinfo->newgpio; 6371230130Smav numgpio = HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap); 6372230130Smav buf[0] = 0; 6373230130Smav for (i = 0; i < numgpio; i++) { 6374230130Smav x = (gpio & HDAA_GPIO_MASK(i)) >> HDAA_GPIO_SHIFT(i); 6375230130Smav n += snprintf(buf + n, sizeof(buf) - n, "%s%d=%s", 6376230130Smav n != 0 ? " " : "", i, HDA_GPIO_ACTIONS[x]); 6377230130Smav } 6378230130Smav error = sysctl_handle_string(oidp, buf, sizeof(buf), req); 6379230130Smav if (error != 0 || req->newptr == NULL) 6380230130Smav return (error); 6381230130Smav if (strncmp(buf, "0x", 2) == 0) 6382230130Smav gpio = strtol(buf + 2, NULL, 16); 6383230130Smav else 6384230130Smav gpio = hdaa_gpio_patch(gpio, buf); 6385230130Smav hdaa_lock(devinfo); 6386230130Smav devinfo->newgpio = devinfo->gpio = gpio; 6387230130Smav hdaa_gpio_commit(devinfo); 6388230130Smav hdaa_unlock(devinfo); 6389230130Smav return (0); 6390230130Smav} 6391230130Smav 6392230130Smavstatic int 6393230130Smavhdaa_sysctl_gpo_state(SYSCTL_HANDLER_ARGS) 6394230130Smav{ 6395230130Smav struct hdaa_devinfo *devinfo = oidp->oid_arg1; 6396230130Smav device_t dev = devinfo->dev; 6397230130Smav char buf[256]; 6398230130Smav int n = 0, i, numgpo; 6399230130Smav uint32_t data = 0; 6400230130Smav 6401230130Smav buf[0] = 0; 6402230130Smav hdaa_lock(devinfo); 6403230130Smav numgpo = HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap); 6404230130Smav if (numgpo > 0) { 6405230130Smav data = hda_command(dev, 6406230130Smav HDA_CMD_GET_GPO_DATA(0, devinfo->nid)); 6407230130Smav } 6408230130Smav hdaa_unlock(devinfo); 6409230130Smav for (i = 0; i < numgpo; i++) { 6410230130Smav n += snprintf(buf + n, sizeof(buf) - n, "%s%d=%d", 6411230130Smav n != 0 ? " " : "", i, ((data >> i) & 1)); 6412230130Smav } 6413230130Smav return (sysctl_handle_string(oidp, buf, sizeof(buf), req)); 6414230130Smav} 6415230130Smav 6416230130Smavstatic int 6417230130Smavhdaa_sysctl_gpo_config(SYSCTL_HANDLER_ARGS) 6418230130Smav{ 6419230130Smav struct hdaa_devinfo *devinfo = oidp->oid_arg1; 6420230130Smav char buf[256]; 6421230130Smav int error, n = 0, i, numgpo; 6422230130Smav uint32_t gpo, x; 6423230130Smav 6424230130Smav gpo = devinfo->newgpo; 6425230130Smav numgpo = HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap); 6426230130Smav buf[0] = 0; 6427230130Smav for (i = 0; i < numgpo; i++) { 6428230130Smav x = (gpo & HDAA_GPIO_MASK(i)) >> HDAA_GPIO_SHIFT(i); 6429230130Smav n += snprintf(buf + n, sizeof(buf) - n, "%s%d=%s", 6430230130Smav n != 0 ? " " : "", i, HDA_GPIO_ACTIONS[x]); 6431230130Smav } 6432230130Smav error = sysctl_handle_string(oidp, buf, sizeof(buf), req); 6433230130Smav if (error != 0 || req->newptr == NULL) 6434230130Smav return (error); 6435230130Smav if (strncmp(buf, "0x", 2) == 0) 6436230130Smav gpo = strtol(buf + 2, NULL, 16); 6437230130Smav else 6438230130Smav gpo = hdaa_gpio_patch(gpo, buf); 6439230130Smav hdaa_lock(devinfo); 6440230130Smav devinfo->newgpo = devinfo->gpo = gpo; 6441230130Smav hdaa_gpo_commit(devinfo); 6442230130Smav hdaa_unlock(devinfo); 6443230130Smav return (0); 6444230130Smav} 6445230130Smav 6446230130Smavstatic int 6447230130Smavhdaa_sysctl_reconfig(SYSCTL_HANDLER_ARGS) 6448230130Smav{ 6449230130Smav device_t dev; 6450230130Smav struct hdaa_devinfo *devinfo; 6451230130Smav int error, val; 6452230130Smav 6453230130Smav dev = oidp->oid_arg1; 6454230130Smav devinfo = device_get_softc(dev); 6455230130Smav if (devinfo == NULL) 6456230130Smav return (EINVAL); 6457230130Smav val = 0; 6458230130Smav error = sysctl_handle_int(oidp, &val, 0, req); 6459230130Smav if (error != 0 || req->newptr == NULL || val == 0) 6460230130Smav return (error); 6461230130Smav 6462230130Smav HDA_BOOTHVERBOSE( 6463230130Smav device_printf(dev, "Reconfiguration...\n"); 6464230130Smav ); 6465230130Smav if ((error = device_delete_children(dev)) != 0) 6466230130Smav return (error); 6467230130Smav hdaa_lock(devinfo); 6468230130Smav hdaa_unconfigure(dev); 6469230130Smav hdaa_configure(dev); 6470230130Smav hdaa_unlock(devinfo); 6471230130Smav bus_generic_attach(dev); 6472230130Smav HDA_BOOTHVERBOSE( 6473230130Smav device_printf(dev, "Reconfiguration done\n"); 6474230130Smav ); 6475230130Smav return (0); 6476230130Smav} 6477230130Smav 6478230130Smavstatic int 6479230130Smavhdaa_suspend(device_t dev) 6480230130Smav{ 6481230130Smav struct hdaa_devinfo *devinfo = device_get_softc(dev); 6482230130Smav int i; 6483230130Smav 6484230130Smav HDA_BOOTHVERBOSE( 6485230130Smav device_printf(dev, "Suspend...\n"); 6486230130Smav ); 6487230130Smav hdaa_lock(devinfo); 6488230130Smav HDA_BOOTHVERBOSE( 6489230130Smav device_printf(dev, "Stop streams...\n"); 6490230130Smav ); 6491230130Smav for (i = 0; i < devinfo->num_chans; i++) { 6492230130Smav if (devinfo->chans[i].flags & HDAA_CHN_RUNNING) { 6493230130Smav devinfo->chans[i].flags |= HDAA_CHN_SUSPEND; 6494230130Smav hdaa_channel_stop(&devinfo->chans[i]); 6495230130Smav } 6496230130Smav } 6497230130Smav HDA_BOOTHVERBOSE( 6498230130Smav device_printf(dev, "Power down FG" 6499230130Smav " nid=%d to the D3 state...\n", 6500230130Smav devinfo->nid); 6501230130Smav ); 6502230130Smav hda_command(devinfo->dev, 6503230130Smav HDA_CMD_SET_POWER_STATE(0, 6504230130Smav devinfo->nid, HDA_CMD_POWER_STATE_D3)); 6505230130Smav callout_stop(&devinfo->poll_jack); 6506230130Smav hdaa_unlock(devinfo); 6507230130Smav callout_drain(&devinfo->poll_jack); 6508230130Smav HDA_BOOTHVERBOSE( 6509230130Smav device_printf(dev, "Suspend done\n"); 6510230130Smav ); 6511230130Smav return (0); 6512230130Smav} 6513230130Smav 6514230130Smavstatic int 6515230130Smavhdaa_resume(device_t dev) 6516230130Smav{ 6517230130Smav struct hdaa_devinfo *devinfo = device_get_softc(dev); 6518230130Smav int i; 6519230130Smav 6520230130Smav HDA_BOOTHVERBOSE( 6521230130Smav device_printf(dev, "Resume...\n"); 6522230130Smav ); 6523230130Smav hdaa_lock(devinfo); 6524230130Smav HDA_BOOTHVERBOSE( 6525230130Smav device_printf(dev, "Power up audio FG nid=%d...\n", 6526230130Smav devinfo->nid); 6527230130Smav ); 6528230130Smav hdaa_powerup(devinfo); 6529230130Smav HDA_BOOTHVERBOSE( 6530230130Smav device_printf(dev, "AFG commit...\n"); 6531230130Smav ); 6532230130Smav hdaa_audio_commit(devinfo); 6533230130Smav HDA_BOOTHVERBOSE( 6534230130Smav device_printf(dev, "Applying direct built-in patches...\n"); 6535230130Smav ); 6536230130Smav hdaa_patch_direct(devinfo); 6537230130Smav HDA_BOOTHVERBOSE( 6538230551Smav device_printf(dev, "Pin sense init...\n"); 6539230130Smav ); 6540230551Smav hdaa_sense_init(devinfo); 6541230130Smav 6542230130Smav hdaa_unlock(devinfo); 6543230130Smav for (i = 0; i < devinfo->num_devs; i++) { 6544230130Smav struct hdaa_pcm_devinfo *pdevinfo = &devinfo->devs[i]; 6545230130Smav HDA_BOOTHVERBOSE( 6546230130Smav device_printf(pdevinfo->dev, 6547230130Smav "OSS mixer reinitialization...\n"); 6548230130Smav ); 6549230130Smav if (mixer_reinit(pdevinfo->dev) == -1) 6550230130Smav device_printf(pdevinfo->dev, 6551230130Smav "unable to reinitialize the mixer\n"); 6552230130Smav } 6553230130Smav hdaa_lock(devinfo); 6554230130Smav HDA_BOOTHVERBOSE( 6555230130Smav device_printf(dev, "Start streams...\n"); 6556230130Smav ); 6557230130Smav for (i = 0; i < devinfo->num_chans; i++) { 6558230130Smav if (devinfo->chans[i].flags & HDAA_CHN_SUSPEND) { 6559230130Smav devinfo->chans[i].flags &= ~HDAA_CHN_SUSPEND; 6560230130Smav hdaa_channel_start(&devinfo->chans[i]); 6561230130Smav } 6562230130Smav } 6563230130Smav hdaa_unlock(devinfo); 6564230130Smav HDA_BOOTHVERBOSE( 6565230130Smav device_printf(dev, "Resume done\n"); 6566230130Smav ); 6567230130Smav return (0); 6568230130Smav} 6569230130Smav 6570230130Smavstatic int 6571230130Smavhdaa_probe(device_t dev) 6572230130Smav{ 6573238022Smav const char *pdesc; 6574230130Smav char buf[128]; 6575230130Smav 6576230130Smav if (hda_get_node_type(dev) != HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO) 6577230130Smav return (ENXIO); 6578238022Smav pdesc = device_get_desc(device_get_parent(dev)); 6579238022Smav snprintf(buf, sizeof(buf), "%.*s Audio Function Group", 6580238022Smav (int)(strlen(pdesc) - 10), pdesc); 6581230130Smav device_set_desc_copy(dev, buf); 6582230130Smav return (BUS_PROBE_DEFAULT); 6583230130Smav} 6584230130Smav 6585230130Smavstatic int 6586230130Smavhdaa_attach(device_t dev) 6587230130Smav{ 6588230130Smav struct hdaa_devinfo *devinfo = device_get_softc(dev); 6589230130Smav uint32_t res; 6590230130Smav nid_t nid = hda_get_node_id(dev); 6591230130Smav 6592230130Smav devinfo->dev = dev; 6593230130Smav devinfo->lock = HDAC_GET_MTX(device_get_parent(dev), dev); 6594230130Smav devinfo->nid = nid; 6595230130Smav devinfo->newquirks = -1; 6596230130Smav devinfo->newgpio = -1; 6597230130Smav devinfo->newgpo = -1; 6598230130Smav callout_init(&devinfo->poll_jack, CALLOUT_MPSAFE); 6599230130Smav devinfo->poll_ival = hz; 6600230130Smav 6601230130Smav hdaa_lock(devinfo); 6602230130Smav res = hda_command(dev, 6603230130Smav HDA_CMD_GET_PARAMETER(0 , nid, HDA_PARAM_SUB_NODE_COUNT)); 6604230130Smav hdaa_unlock(devinfo); 6605230130Smav 6606230130Smav devinfo->nodecnt = HDA_PARAM_SUB_NODE_COUNT_TOTAL(res); 6607230130Smav devinfo->startnode = HDA_PARAM_SUB_NODE_COUNT_START(res); 6608230130Smav devinfo->endnode = devinfo->startnode + devinfo->nodecnt; 6609230130Smav 6610230130Smav HDA_BOOTVERBOSE( 6611242352Smav device_printf(dev, "Subsystem ID: 0x%08x\n", 6612242352Smav hda_get_subsystem_id(dev)); 6613242352Smav ); 6614242352Smav HDA_BOOTHVERBOSE( 6615230130Smav device_printf(dev, 6616230130Smav "Audio Function Group at nid=%d: %d subnodes %d-%d\n", 6617230130Smav nid, devinfo->nodecnt, 6618230130Smav devinfo->startnode, devinfo->endnode - 1); 6619230130Smav ); 6620230130Smav 6621230130Smav if (devinfo->nodecnt > 0) 6622230130Smav devinfo->widget = (struct hdaa_widget *)malloc( 6623230130Smav sizeof(*(devinfo->widget)) * devinfo->nodecnt, M_HDAA, 6624230130Smav M_WAITOK | M_ZERO); 6625230130Smav else 6626230130Smav devinfo->widget = NULL; 6627230130Smav 6628230130Smav hdaa_lock(devinfo); 6629230130Smav HDA_BOOTHVERBOSE( 6630230130Smav device_printf(dev, "Powering up...\n"); 6631230130Smav ); 6632230130Smav hdaa_powerup(devinfo); 6633230130Smav HDA_BOOTHVERBOSE( 6634230130Smav device_printf(dev, "Parsing audio FG...\n"); 6635230130Smav ); 6636230130Smav hdaa_audio_parse(devinfo); 6637230130Smav HDA_BOOTVERBOSE( 6638230130Smav device_printf(dev, "Original pins configuration:\n"); 6639230130Smav hdaa_dump_pin_configs(devinfo); 6640230130Smav ); 6641230130Smav hdaa_configure(dev); 6642230130Smav hdaa_unlock(devinfo); 6643230130Smav 6644230130Smav SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 6645230130Smav SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, 6646230130Smav "config", CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE, 6647230130Smav &devinfo->newquirks, sizeof(&devinfo->newquirks), 6648230130Smav hdaa_sysctl_quirks, "A", "Configuration options"); 6649230130Smav SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 6650230130Smav SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, 6651230130Smav "gpi_state", CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, 6652230130Smav devinfo, sizeof(devinfo), 6653230130Smav hdaa_sysctl_gpi_state, "A", "GPI state"); 6654230130Smav SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 6655230130Smav SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, 6656230130Smav "gpio_state", CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, 6657230130Smav devinfo, sizeof(devinfo), 6658230130Smav hdaa_sysctl_gpio_state, "A", "GPIO state"); 6659230130Smav SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 6660230130Smav SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, 6661230130Smav "gpio_config", CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE, 6662230130Smav devinfo, sizeof(devinfo), 6663230130Smav hdaa_sysctl_gpio_config, "A", "GPIO configuration"); 6664230130Smav SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 6665230130Smav SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, 6666230130Smav "gpo_state", CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, 6667230130Smav devinfo, sizeof(devinfo), 6668230130Smav hdaa_sysctl_gpo_state, "A", "GPO state"); 6669230130Smav SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 6670230130Smav SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, 6671230130Smav "gpo_config", CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE, 6672230130Smav devinfo, sizeof(devinfo), 6673230130Smav hdaa_sysctl_gpo_config, "A", "GPO configuration"); 6674230130Smav SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 6675230130Smav SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, 6676230130Smav "reconfig", CTLTYPE_INT | CTLFLAG_RW, 6677230130Smav dev, sizeof(dev), 6678230130Smav hdaa_sysctl_reconfig, "I", "Reprocess configuration"); 6679230130Smav bus_generic_attach(dev); 6680230130Smav return (0); 6681230130Smav} 6682230130Smav 6683230130Smavstatic int 6684230130Smavhdaa_detach(device_t dev) 6685230130Smav{ 6686230130Smav struct hdaa_devinfo *devinfo = device_get_softc(dev); 6687230130Smav int error; 6688230130Smav 6689230130Smav if ((error = device_delete_children(dev)) != 0) 6690230130Smav return (error); 6691230130Smav 6692230130Smav hdaa_lock(devinfo); 6693230130Smav hdaa_unconfigure(dev); 6694230130Smav devinfo->poll_ival = 0; 6695230130Smav callout_stop(&devinfo->poll_jack); 6696230130Smav hdaa_unlock(devinfo); 6697230130Smav callout_drain(&devinfo->poll_jack); 6698230130Smav 6699230130Smav free(devinfo->widget, M_HDAA); 6700230130Smav return (0); 6701230130Smav} 6702230130Smav 6703230130Smavstatic int 6704230130Smavhdaa_print_child(device_t dev, device_t child) 6705230130Smav{ 6706230130Smav struct hdaa_devinfo *devinfo = device_get_softc(dev); 6707230130Smav struct hdaa_pcm_devinfo *pdevinfo = 6708230130Smav (struct hdaa_pcm_devinfo *)device_get_ivars(child); 6709230130Smav struct hdaa_audio_as *as; 6710230130Smav int retval, first = 1, i; 6711230130Smav 6712230130Smav retval = bus_print_child_header(dev, child); 6713230130Smav retval += printf(" at nid "); 6714230130Smav if (pdevinfo->playas >= 0) { 6715230130Smav as = &devinfo->as[pdevinfo->playas]; 6716230130Smav for (i = 0; i < 16; i++) { 6717230130Smav if (as->pins[i] <= 0) 6718230130Smav continue; 6719230130Smav retval += printf("%s%d", first ? "" : ",", as->pins[i]); 6720230130Smav first = 0; 6721230130Smav } 6722230130Smav } 6723230130Smav if (pdevinfo->recas >= 0) { 6724230130Smav if (pdevinfo->playas >= 0) { 6725230130Smav retval += printf(" and "); 6726230130Smav first = 1; 6727230130Smav } 6728230130Smav as = &devinfo->as[pdevinfo->recas]; 6729230130Smav for (i = 0; i < 16; i++) { 6730230130Smav if (as->pins[i] <= 0) 6731230130Smav continue; 6732230130Smav retval += printf("%s%d", first ? "" : ",", as->pins[i]); 6733230130Smav first = 0; 6734230130Smav } 6735230130Smav } 6736230130Smav retval += bus_print_child_footer(dev, child); 6737230130Smav 6738230130Smav return (retval); 6739230130Smav} 6740230130Smav 6741230130Smavstatic int 6742230130Smavhdaa_child_location_str(device_t dev, device_t child, char *buf, 6743230130Smav size_t buflen) 6744230130Smav{ 6745230130Smav struct hdaa_devinfo *devinfo = device_get_softc(dev); 6746230130Smav struct hdaa_pcm_devinfo *pdevinfo = 6747230130Smav (struct hdaa_pcm_devinfo *)device_get_ivars(child); 6748230130Smav struct hdaa_audio_as *as; 6749230130Smav int first = 1, i, len = 0; 6750230130Smav 6751230130Smav len += snprintf(buf + len, buflen - len, "nid="); 6752230130Smav if (pdevinfo->playas >= 0) { 6753230130Smav as = &devinfo->as[pdevinfo->playas]; 6754230130Smav for (i = 0; i < 16; i++) { 6755230130Smav if (as->pins[i] <= 0) 6756230130Smav continue; 6757230130Smav len += snprintf(buf + len, buflen - len, 6758230130Smav "%s%d", first ? "" : ",", as->pins[i]); 6759230130Smav first = 0; 6760230130Smav } 6761230130Smav } 6762230130Smav if (pdevinfo->recas >= 0) { 6763230130Smav as = &devinfo->as[pdevinfo->recas]; 6764230130Smav for (i = 0; i < 16; i++) { 6765230130Smav if (as->pins[i] <= 0) 6766230130Smav continue; 6767230130Smav len += snprintf(buf + len, buflen - len, 6768230130Smav "%s%d", first ? "" : ",", as->pins[i]); 6769230130Smav first = 0; 6770230130Smav } 6771230130Smav } 6772230130Smav return (0); 6773230130Smav} 6774230130Smav 6775230130Smavstatic void 6776230130Smavhdaa_stream_intr(device_t dev, int dir, int stream) 6777230130Smav{ 6778230130Smav struct hdaa_devinfo *devinfo = device_get_softc(dev); 6779230130Smav struct hdaa_chan *ch; 6780230130Smav int i; 6781230130Smav 6782230130Smav for (i = 0; i < devinfo->num_chans; i++) { 6783230130Smav ch = &devinfo->chans[i]; 6784230130Smav if (!(ch->flags & HDAA_CHN_RUNNING)) 6785230130Smav continue; 6786230130Smav if (ch->dir == ((dir == 1) ? PCMDIR_PLAY : PCMDIR_REC) && 6787230130Smav ch->sid == stream) { 6788230130Smav hdaa_unlock(devinfo); 6789230130Smav chn_intr(ch->c); 6790230130Smav hdaa_lock(devinfo); 6791230130Smav } 6792230130Smav } 6793230130Smav} 6794230130Smav 6795230130Smavstatic void 6796230130Smavhdaa_unsol_intr(device_t dev, uint32_t resp) 6797230130Smav{ 6798230130Smav struct hdaa_devinfo *devinfo = device_get_softc(dev); 6799230312Smav struct hdaa_widget *w; 6800230312Smav int i, tag, flags; 6801230130Smav 6802230312Smav HDA_BOOTHVERBOSE( 6803230312Smav device_printf(dev, "Unsolicited response %08x\n", resp); 6804230312Smav ); 6805230130Smav tag = resp >> 26; 6806230312Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 6807230312Smav w = hdaa_widget_get(devinfo, i); 6808230312Smav if (w == NULL || w->enable == 0 || w->type != 6809230312Smav HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 6810230312Smav continue; 6811230312Smav if (w->unsol != tag) 6812230312Smav continue; 6813230312Smav if (HDA_PARAM_PIN_CAP_DP(w->wclass.pin.cap) || 6814230312Smav HDA_PARAM_PIN_CAP_HDMI(w->wclass.pin.cap)) 6815230312Smav flags = resp & 0x03; 6816230312Smav else 6817230312Smav flags = 0x01; 6818230312Smav if (flags & 0x01) 6819230551Smav hdaa_presence_handler(w); 6820230312Smav if (flags & 0x02) 6821230312Smav hdaa_eld_handler(w); 6822230130Smav } 6823230130Smav} 6824230130Smav 6825230130Smavstatic device_method_t hdaa_methods[] = { 6826230130Smav /* device interface */ 6827230130Smav DEVMETHOD(device_probe, hdaa_probe), 6828230130Smav DEVMETHOD(device_attach, hdaa_attach), 6829230130Smav DEVMETHOD(device_detach, hdaa_detach), 6830230130Smav DEVMETHOD(device_suspend, hdaa_suspend), 6831230130Smav DEVMETHOD(device_resume, hdaa_resume), 6832230130Smav /* Bus interface */ 6833230130Smav DEVMETHOD(bus_print_child, hdaa_print_child), 6834230130Smav DEVMETHOD(bus_child_location_str, hdaa_child_location_str), 6835230130Smav DEVMETHOD(hdac_stream_intr, hdaa_stream_intr), 6836230130Smav DEVMETHOD(hdac_unsol_intr, hdaa_unsol_intr), 6837230130Smav DEVMETHOD(hdac_pindump, hdaa_pindump), 6838230130Smav { 0, 0 } 6839230130Smav}; 6840230130Smav 6841230130Smavstatic driver_t hdaa_driver = { 6842230130Smav "hdaa", 6843230130Smav hdaa_methods, 6844230130Smav sizeof(struct hdaa_devinfo), 6845230130Smav}; 6846230130Smav 6847230130Smavstatic devclass_t hdaa_devclass; 6848230130Smav 6849230130SmavDRIVER_MODULE(snd_hda, hdacc, hdaa_driver, hdaa_devclass, 0, 0); 6850230130Smav 6851230130Smavstatic void 6852230130Smavhdaa_chan_formula(struct hdaa_devinfo *devinfo, int asid, 6853230130Smav char *buf, int buflen) 6854230130Smav{ 6855230130Smav struct hdaa_audio_as *as; 6856230130Smav int c; 6857230130Smav 6858230130Smav as = &devinfo->as[asid]; 6859230130Smav c = devinfo->chans[as->chans[0]].channels; 6860230130Smav if (c == 1) 6861230130Smav snprintf(buf, buflen, "mono"); 6862230585Smav else if (c == 2) { 6863230585Smav if (as->hpredir < 0) 6864230585Smav buf[0] = 0; 6865230585Smav else 6866230585Smav snprintf(buf, buflen, "2.0"); 6867230585Smav } else if (as->pinset == 0x0003) 6868230130Smav snprintf(buf, buflen, "3.1"); 6869230130Smav else if (as->pinset == 0x0005 || as->pinset == 0x0011) 6870230130Smav snprintf(buf, buflen, "4.0"); 6871230130Smav else if (as->pinset == 0x0007 || as->pinset == 0x0013) 6872230130Smav snprintf(buf, buflen, "5.1"); 6873230130Smav else if (as->pinset == 0x0017) 6874230130Smav snprintf(buf, buflen, "7.1"); 6875230130Smav else 6876230130Smav snprintf(buf, buflen, "%dch", c); 6877230585Smav if (as->hpredir >= 0) 6878230585Smav strlcat(buf, "+HP", buflen); 6879230130Smav} 6880230130Smav 6881230130Smavstatic int 6882230585Smavhdaa_chan_type(struct hdaa_devinfo *devinfo, int asid) 6883230585Smav{ 6884230585Smav struct hdaa_audio_as *as; 6885230585Smav struct hdaa_widget *w; 6886230585Smav int i, t = -1, t1; 6887230585Smav 6888230585Smav as = &devinfo->as[asid]; 6889230585Smav for (i = 0; i < 16; i++) { 6890230585Smav w = hdaa_widget_get(devinfo, as->pins[i]); 6891230585Smav if (w == NULL || w->enable == 0 || w->type != 6892230585Smav HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 6893230585Smav continue; 6894230585Smav t1 = HDA_CONFIG_DEFAULTCONF_DEVICE(w->wclass.pin.config); 6895230585Smav if (t == -1) 6896230585Smav t = t1; 6897230585Smav else if (t != t1) { 6898230585Smav t = -2; 6899230585Smav break; 6900230585Smav } 6901230585Smav } 6902230585Smav return (t); 6903230585Smav} 6904230585Smav 6905230585Smavstatic int 6906230488Smavhdaa_sysctl_32bit(SYSCTL_HANDLER_ARGS) 6907230488Smav{ 6908230488Smav struct hdaa_audio_as *as = (struct hdaa_audio_as *)oidp->oid_arg1; 6909230488Smav struct hdaa_pcm_devinfo *pdevinfo = as->pdevinfo; 6910230488Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 6911230488Smav struct hdaa_chan *ch; 6912230488Smav int error, val, i; 6913230488Smav uint32_t pcmcap; 6914230488Smav 6915230488Smav ch = &devinfo->chans[as->chans[0]]; 6916230488Smav val = (ch->bit32 == 4) ? 32 : ((ch->bit32 == 3) ? 24 : 6917230488Smav ((ch->bit32 == 2) ? 20 : 0)); 6918230488Smav error = sysctl_handle_int(oidp, &val, 0, req); 6919230488Smav if (error != 0 || req->newptr == NULL) 6920230488Smav return (error); 6921230488Smav pcmcap = ch->supp_pcm_size_rate; 6922230488Smav if (val == 32 && HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(pcmcap)) 6923230488Smav ch->bit32 = 4; 6924230488Smav else if (val == 24 && HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(pcmcap)) 6925230488Smav ch->bit32 = 3; 6926230488Smav else if (val == 20 && HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(pcmcap)) 6927230488Smav ch->bit32 = 2; 6928230488Smav else 6929230488Smav return (EINVAL); 6930230488Smav for (i = 1; i < as->num_chans; i++) 6931230488Smav devinfo->chans[as->chans[i]].bit32 = ch->bit32; 6932230488Smav return (0); 6933230488Smav} 6934230488Smav 6935230488Smavstatic int 6936230130Smavhdaa_pcm_probe(device_t dev) 6937230130Smav{ 6938230130Smav struct hdaa_pcm_devinfo *pdevinfo = 6939230130Smav (struct hdaa_pcm_devinfo *)device_get_ivars(dev); 6940230130Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 6941238022Smav const char *pdesc; 6942230130Smav char chans1[8], chans2[8]; 6943230130Smav char buf[128]; 6944230585Smav int loc1, loc2, t1, t2; 6945230130Smav 6946230130Smav if (pdevinfo->playas >= 0) 6947230130Smav loc1 = devinfo->as[pdevinfo->playas].location; 6948230130Smav else 6949230130Smav loc1 = devinfo->as[pdevinfo->recas].location; 6950230130Smav if (pdevinfo->recas >= 0) 6951230130Smav loc2 = devinfo->as[pdevinfo->recas].location; 6952230130Smav else 6953230130Smav loc2 = loc1; 6954230130Smav if (loc1 != loc2) 6955230130Smav loc1 = -2; 6956230130Smav if (loc1 >= 0 && HDA_LOCS[loc1][0] == '0') 6957230130Smav loc1 = -2; 6958230130Smav chans1[0] = 0; 6959230130Smav chans2[0] = 0; 6960230585Smav t1 = t2 = -1; 6961230585Smav if (pdevinfo->playas >= 0) { 6962230130Smav hdaa_chan_formula(devinfo, pdevinfo->playas, 6963230130Smav chans1, sizeof(chans1)); 6964230585Smav t1 = hdaa_chan_type(devinfo, pdevinfo->playas); 6965230585Smav } 6966230585Smav if (pdevinfo->recas >= 0) { 6967230130Smav hdaa_chan_formula(devinfo, pdevinfo->recas, 6968230130Smav chans2, sizeof(chans2)); 6969230585Smav t2 = hdaa_chan_type(devinfo, pdevinfo->recas); 6970230585Smav } 6971230130Smav if (chans1[0] != 0 || chans2[0] != 0) { 6972230130Smav if (chans1[0] == 0 && pdevinfo->playas >= 0) 6973230130Smav snprintf(chans1, sizeof(chans1), "2.0"); 6974230130Smav else if (chans2[0] == 0 && pdevinfo->recas >= 0) 6975230130Smav snprintf(chans2, sizeof(chans2), "2.0"); 6976230130Smav if (strcmp(chans1, chans2) == 0) 6977230130Smav chans2[0] = 0; 6978230130Smav } 6979230585Smav if (t1 == -1) 6980230585Smav t1 = t2; 6981230585Smav else if (t2 == -1) 6982230585Smav t2 = t1; 6983230585Smav if (t1 != t2) 6984230585Smav t1 = -2; 6985230585Smav if (pdevinfo->digital) 6986230585Smav t1 = -2; 6987238022Smav pdesc = device_get_desc(device_get_parent(dev)); 6988238022Smav snprintf(buf, sizeof(buf), "%.*s (%s%s%s%s%s%s%s%s%s)", 6989238022Smav (int)(strlen(pdesc) - 21), pdesc, 6990230130Smav loc1 >= 0 ? HDA_LOCS[loc1] : "", loc1 >= 0 ? " " : "", 6991230507Smav (pdevinfo->digital == 0x7)?"HDMI/DP": 6992230507Smav ((pdevinfo->digital == 0x5)?"DisplayPort": 6993230507Smav ((pdevinfo->digital == 0x3)?"HDMI": 6994230507Smav ((pdevinfo->digital)?"Digital":"Analog"))), 6995230130Smav chans1[0] ? " " : "", chans1, 6996230585Smav chans2[0] ? "/" : "", chans2, 6997230585Smav t1 >= 0 ? " " : "", t1 >= 0 ? HDA_DEVS[t1] : ""); 6998230130Smav device_set_desc_copy(dev, buf); 6999230130Smav return (BUS_PROBE_SPECIFIC); 7000230130Smav} 7001230130Smav 7002230130Smavstatic int 7003230130Smavhdaa_pcm_attach(device_t dev) 7004230130Smav{ 7005230130Smav struct hdaa_pcm_devinfo *pdevinfo = 7006230130Smav (struct hdaa_pcm_devinfo *)device_get_ivars(dev); 7007230130Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 7008230130Smav struct hdaa_audio_as *as; 7009230488Smav struct snddev_info *d; 7010230130Smav char status[SND_STATUSLEN]; 7011230130Smav int i; 7012230130Smav 7013230130Smav pdevinfo->chan_size = pcm_getbuffersize(dev, 7014230130Smav HDA_BUFSZ_MIN, HDA_BUFSZ_DEFAULT, HDA_BUFSZ_MAX); 7015230130Smav 7016230130Smav HDA_BOOTVERBOSE( 7017230130Smav hdaa_dump_dac(pdevinfo); 7018230130Smav hdaa_dump_adc(pdevinfo); 7019230130Smav hdaa_dump_mix(pdevinfo); 7020230130Smav hdaa_dump_ctls(pdevinfo, "Master Volume", SOUND_MASK_VOLUME); 7021230130Smav hdaa_dump_ctls(pdevinfo, "PCM Volume", SOUND_MASK_PCM); 7022230130Smav hdaa_dump_ctls(pdevinfo, "CD Volume", SOUND_MASK_CD); 7023230130Smav hdaa_dump_ctls(pdevinfo, "Microphone Volume", SOUND_MASK_MIC); 7024230130Smav hdaa_dump_ctls(pdevinfo, "Microphone2 Volume", SOUND_MASK_MONITOR); 7025230130Smav hdaa_dump_ctls(pdevinfo, "Line-in Volume", SOUND_MASK_LINE); 7026230130Smav hdaa_dump_ctls(pdevinfo, "Speaker/Beep Volume", SOUND_MASK_SPEAKER); 7027230130Smav hdaa_dump_ctls(pdevinfo, "Recording Level", SOUND_MASK_RECLEV); 7028230130Smav hdaa_dump_ctls(pdevinfo, "Input Mix Level", SOUND_MASK_IMIX); 7029230130Smav hdaa_dump_ctls(pdevinfo, "Input Monitoring Level", SOUND_MASK_IGAIN); 7030230130Smav hdaa_dump_ctls(pdevinfo, NULL, 0); 7031230130Smav ); 7032230130Smav 7033230130Smav if (resource_int_value(device_get_name(dev), 7034230130Smav device_get_unit(dev), "blocksize", &i) == 0 && i > 0) { 7035230130Smav i &= HDA_BLK_ALIGN; 7036230130Smav if (i < HDA_BLK_MIN) 7037230130Smav i = HDA_BLK_MIN; 7038230130Smav pdevinfo->chan_blkcnt = pdevinfo->chan_size / i; 7039230130Smav i = 0; 7040230130Smav while (pdevinfo->chan_blkcnt >> i) 7041230130Smav i++; 7042230130Smav pdevinfo->chan_blkcnt = 1 << (i - 1); 7043230130Smav if (pdevinfo->chan_blkcnt < HDA_BDL_MIN) 7044230130Smav pdevinfo->chan_blkcnt = HDA_BDL_MIN; 7045230130Smav else if (pdevinfo->chan_blkcnt > HDA_BDL_MAX) 7046230130Smav pdevinfo->chan_blkcnt = HDA_BDL_MAX; 7047230130Smav } else 7048230130Smav pdevinfo->chan_blkcnt = HDA_BDL_DEFAULT; 7049230130Smav 7050230130Smav /* 7051230130Smav * We don't register interrupt handler with snd_setup_intr 7052230130Smav * in pcm device. Mark pcm device as MPSAFE manually. 7053230130Smav */ 7054230130Smav pcm_setflags(dev, pcm_getflags(dev) | SD_F_MPSAFE); 7055230130Smav 7056230130Smav HDA_BOOTHVERBOSE( 7057230130Smav device_printf(dev, "OSS mixer initialization...\n"); 7058230130Smav ); 7059230130Smav if (mixer_init(dev, &hdaa_audio_ctl_ossmixer_class, pdevinfo) != 0) 7060230130Smav device_printf(dev, "Can't register mixer\n"); 7061230130Smav 7062230130Smav HDA_BOOTHVERBOSE( 7063230130Smav device_printf(dev, "Registering PCM channels...\n"); 7064230130Smav ); 7065230130Smav if (pcm_register(dev, pdevinfo, (pdevinfo->playas >= 0)?1:0, 7066230130Smav (pdevinfo->recas >= 0)?1:0) != 0) 7067230130Smav device_printf(dev, "Can't register PCM\n"); 7068230130Smav 7069230130Smav pdevinfo->registered++; 7070230130Smav 7071230488Smav d = device_get_softc(dev); 7072230130Smav if (pdevinfo->playas >= 0) { 7073230130Smav as = &devinfo->as[pdevinfo->playas]; 7074230130Smav for (i = 0; i < as->num_chans; i++) 7075230130Smav pcm_addchan(dev, PCMDIR_PLAY, &hdaa_channel_class, 7076230130Smav &devinfo->chans[as->chans[i]]); 7077230488Smav SYSCTL_ADD_PROC(&d->play_sysctl_ctx, 7078230488Smav SYSCTL_CHILDREN(d->play_sysctl_tree), OID_AUTO, 7079230488Smav "32bit", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, 7080230488Smav as, sizeof(as), hdaa_sysctl_32bit, "I", 7081230488Smav "Resolution of 32bit samples (20/24/32bit)"); 7082230130Smav } 7083230130Smav if (pdevinfo->recas >= 0) { 7084230130Smav as = &devinfo->as[pdevinfo->recas]; 7085230130Smav for (i = 0; i < as->num_chans; i++) 7086230130Smav pcm_addchan(dev, PCMDIR_REC, &hdaa_channel_class, 7087230130Smav &devinfo->chans[as->chans[i]]); 7088230488Smav SYSCTL_ADD_PROC(&d->rec_sysctl_ctx, 7089230488Smav SYSCTL_CHILDREN(d->rec_sysctl_tree), OID_AUTO, 7090230488Smav "32bit", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, 7091230488Smav as, sizeof(as), hdaa_sysctl_32bit, "I", 7092230488Smav "Resolution of 32bit samples (20/24/32bit)"); 7093230551Smav pdevinfo->autorecsrc = 2; 7094230554Smav resource_int_value(device_get_name(dev), device_get_unit(dev), 7095230554Smav "rec.autosrc", &pdevinfo->autorecsrc); 7096230551Smav SYSCTL_ADD_INT(&d->rec_sysctl_ctx, 7097230551Smav SYSCTL_CHILDREN(d->rec_sysctl_tree), OID_AUTO, 7098230551Smav "autosrc", CTLTYPE_INT | CTLFLAG_RW, 7099230551Smav &pdevinfo->autorecsrc, 0, 7100230551Smav "Automatic recording source selection"); 7101230130Smav } 7102230130Smav 7103230551Smav if (pdevinfo->mixer != NULL) { 7104230551Smav hdaa_audio_ctl_set_defaults(pdevinfo); 7105243181Smav hdaa_lock(devinfo); 7106243181Smav if (pdevinfo->playas >= 0) { 7107243181Smav as = &devinfo->as[pdevinfo->playas]; 7108243181Smav hdaa_channels_handler(as); 7109243181Smav } 7110230551Smav if (pdevinfo->recas >= 0) { 7111230551Smav as = &devinfo->as[pdevinfo->recas]; 7112230551Smav hdaa_autorecsrc_handler(as, NULL); 7113243181Smav hdaa_channels_handler(as); 7114230551Smav } 7115243181Smav hdaa_unlock(devinfo); 7116230551Smav } 7117230551Smav 7118230130Smav snprintf(status, SND_STATUSLEN, "on %s %s", 7119230130Smav device_get_nameunit(device_get_parent(dev)), 7120230130Smav PCM_KLDSTRING(snd_hda)); 7121230130Smav pcm_setstatus(dev, status); 7122230130Smav 7123230130Smav return (0); 7124230130Smav} 7125230130Smav 7126230130Smavstatic int 7127230130Smavhdaa_pcm_detach(device_t dev) 7128230130Smav{ 7129230130Smav struct hdaa_pcm_devinfo *pdevinfo = 7130230130Smav (struct hdaa_pcm_devinfo *)device_get_ivars(dev); 7131230130Smav int err; 7132230130Smav 7133230130Smav if (pdevinfo->registered > 0) { 7134230130Smav err = pcm_unregister(dev); 7135230130Smav if (err != 0) 7136230130Smav return (err); 7137230130Smav } 7138230130Smav 7139230130Smav return (0); 7140230130Smav} 7141230130Smav 7142230130Smavstatic device_method_t hdaa_pcm_methods[] = { 7143230130Smav /* device interface */ 7144230130Smav DEVMETHOD(device_probe, hdaa_pcm_probe), 7145230130Smav DEVMETHOD(device_attach, hdaa_pcm_attach), 7146230130Smav DEVMETHOD(device_detach, hdaa_pcm_detach), 7147230130Smav { 0, 0 } 7148230130Smav}; 7149230130Smav 7150230130Smavstatic driver_t hdaa_pcm_driver = { 7151230130Smav "pcm", 7152230130Smav hdaa_pcm_methods, 7153230130Smav PCM_SOFTC_SIZE, 7154230130Smav}; 7155230130Smav 7156230130SmavDRIVER_MODULE(snd_hda_pcm, hdaa, hdaa_pcm_driver, pcm_devclass, 0, 0); 7157230130SmavMODULE_DEPEND(snd_hda, sound, SOUND_MINVER, SOUND_PREFVER, SOUND_MAXVER); 7158230130SmavMODULE_VERSION(snd_hda, 1); 7159