hdaa.c revision 242352
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 242352 2012-10-30 10:59:42Z 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 241230130Smav/* 242230551Smav * Headphones redirection change handler. 243230130Smav */ 244230130Smavstatic void 245230551Smavhdaa_hpredir_handler(struct hdaa_widget *w) 246230130Smav{ 247230312Smav struct hdaa_devinfo *devinfo = w->devinfo; 248230551Smav struct hdaa_audio_as *as = &devinfo->as[w->bindas]; 249230312Smav struct hdaa_widget *w1; 250230130Smav struct hdaa_audio_ctl *ctl; 251230551Smav uint32_t val; 252230551Smav int j, connected = w->wclass.pin.connected; 253230130Smav 254230130Smav HDA_BOOTVERBOSE( 255230551Smav device_printf((as->pdevinfo && as->pdevinfo->dev) ? 256230551Smav as->pdevinfo->dev : devinfo->dev, 257230551Smav "Redirect output to: %s\n", 258230551Smav connected ? "headphones": "main"); 259230130Smav ); 260230130Smav /* (Un)Mute headphone pin. */ 261230130Smav ctl = hdaa_audio_ctl_amp_get(devinfo, 262230312Smav w->nid, HDAA_CTL_IN, -1, 1); 263230130Smav if (ctl != NULL && ctl->mute) { 264230130Smav /* If pin has muter - use it. */ 265230551Smav val = connected ? 0 : 1; 266230130Smav if (val != ctl->forcemute) { 267230130Smav ctl->forcemute = val; 268230130Smav hdaa_audio_ctl_amp_set(ctl, 269230130Smav HDAA_AMP_MUTE_DEFAULT, 270230130Smav HDAA_AMP_VOL_DEFAULT, HDAA_AMP_VOL_DEFAULT); 271230130Smav } 272230130Smav } else { 273230130Smav /* If there is no muter - disable pin output. */ 274230551Smav if (connected) 275230312Smav val = w->wclass.pin.ctrl | 276230312Smav HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE; 277230312Smav else 278230312Smav val = w->wclass.pin.ctrl & 279230312Smav ~HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE; 280230312Smav if (val != w->wclass.pin.ctrl) { 281230312Smav w->wclass.pin.ctrl = val; 282230312Smav hda_command(devinfo->dev, 283230312Smav HDA_CMD_SET_PIN_WIDGET_CTRL(0, 284230312Smav w->nid, w->wclass.pin.ctrl)); 285230130Smav } 286230130Smav } 287230130Smav /* (Un)Mute other pins. */ 288230130Smav for (j = 0; j < 15; j++) { 289230130Smav if (as->pins[j] <= 0) 290230130Smav continue; 291230130Smav ctl = hdaa_audio_ctl_amp_get(devinfo, 292230130Smav as->pins[j], HDAA_CTL_IN, -1, 1); 293230130Smav if (ctl != NULL && ctl->mute) { 294230130Smav /* If pin has muter - use it. */ 295230551Smav val = connected ? 1 : 0; 296230130Smav if (val == ctl->forcemute) 297230130Smav continue; 298230130Smav ctl->forcemute = val; 299230130Smav hdaa_audio_ctl_amp_set(ctl, 300230130Smav HDAA_AMP_MUTE_DEFAULT, 301230130Smav HDAA_AMP_VOL_DEFAULT, HDAA_AMP_VOL_DEFAULT); 302230130Smav continue; 303230130Smav } 304230130Smav /* If there is no muter - disable pin output. */ 305230312Smav w1 = hdaa_widget_get(devinfo, as->pins[j]); 306230551Smav if (w1 != NULL) { 307230551Smav if (connected) 308230312Smav val = w1->wclass.pin.ctrl & 309230130Smav ~HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE; 310230130Smav else 311230312Smav val = w1->wclass.pin.ctrl | 312230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE; 313230312Smav if (val != w1->wclass.pin.ctrl) { 314230312Smav w1->wclass.pin.ctrl = val; 315230130Smav hda_command(devinfo->dev, 316230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL(0, 317230312Smav w1->nid, w1->wclass.pin.ctrl)); 318230130Smav } 319230130Smav } 320230130Smav } 321230130Smav} 322230130Smav 323230130Smav/* 324230551Smav * Recording source change handler. 325230130Smav */ 326230130Smavstatic void 327230551Smavhdaa_autorecsrc_handler(struct hdaa_audio_as *as, struct hdaa_widget *w) 328230130Smav{ 329230551Smav struct hdaa_pcm_devinfo *pdevinfo = as->pdevinfo; 330230551Smav struct hdaa_devinfo *devinfo; 331230551Smav struct hdaa_widget *w1; 332230551Smav int i, mask, fullmask, prio, bestprio; 333230551Smav char buf[128]; 334230130Smav 335230551Smav if (!as->mixed || pdevinfo == NULL || pdevinfo->mixer == NULL) 336230130Smav return; 337230551Smav /* Don't touch anything if we asked not to. */ 338230551Smav if (pdevinfo->autorecsrc == 0 || 339230551Smav (pdevinfo->autorecsrc == 1 && w != NULL)) 340230551Smav return; 341230551Smav /* Don't touch anything if "mix" or "speaker" selected. */ 342230551Smav if (pdevinfo->recsrc & (SOUND_MASK_IMIX | SOUND_MASK_SPEAKER)) 343230551Smav return; 344230551Smav /* Don't touch anything if several selected. */ 345230551Smav if (ffs(pdevinfo->recsrc) != fls(pdevinfo->recsrc)) 346230551Smav return; 347230551Smav devinfo = pdevinfo->devinfo; 348230551Smav mask = fullmask = 0; 349230551Smav bestprio = 0; 350230551Smav for (i = 0; i < 16; i++) { 351230551Smav if (as->pins[i] <= 0) 352230130Smav continue; 353230551Smav w1 = hdaa_widget_get(devinfo, as->pins[i]); 354230551Smav if (w1 == NULL || w1->enable == 0) 355230312Smav continue; 356230551Smav if (w1->wclass.pin.connected == 0) 357230551Smav continue; 358230551Smav prio = (w1->wclass.pin.connected == 1) ? 2 : 1; 359230551Smav if (prio < bestprio) 360230551Smav continue; 361230551Smav if (prio > bestprio) { 362230551Smav mask = 0; 363230551Smav bestprio = prio; 364230551Smav } 365230551Smav mask |= (1 << w1->ossdev); 366230551Smav fullmask |= (1 << w1->ossdev); 367230130Smav } 368230551Smav if (mask == 0) 369230551Smav return; 370230551Smav /* Prefer newly connected input. */ 371230551Smav if (w != NULL && (mask & (1 << w->ossdev))) 372230551Smav mask = (1 << w->ossdev); 373230551Smav /* Prefer previously selected input */ 374230551Smav if (mask & pdevinfo->recsrc) 375230551Smav mask &= pdevinfo->recsrc; 376230551Smav /* Prefer mic. */ 377230551Smav if (mask & SOUND_MASK_MIC) 378230551Smav mask = SOUND_MASK_MIC; 379230551Smav /* Prefer monitor (2nd mic). */ 380230551Smav if (mask & SOUND_MASK_MONITOR) 381230551Smav mask = SOUND_MASK_MONITOR; 382230551Smav /* Just take first one. */ 383230551Smav mask = (1 << (ffs(mask) - 1)); 384230551Smav HDA_BOOTVERBOSE( 385230551Smav hdaa_audio_ctl_ossmixer_mask2allname(mask, buf, sizeof(buf)); 386230551Smav device_printf(pdevinfo->dev, 387230551Smav "Automatically set rec source to: %s\n", buf); 388230551Smav ); 389230130Smav hdaa_unlock(devinfo); 390230551Smav mix_setrecsrc(pdevinfo->mixer, mask); 391230551Smav hdaa_lock(devinfo); 392230130Smav} 393230130Smav 394230130Smav/* 395230551Smav * Jack presence detection event handler. 396230130Smav */ 397230130Smavstatic void 398230551Smavhdaa_presence_handler(struct hdaa_widget *w) 399230130Smav{ 400230551Smav struct hdaa_devinfo *devinfo = w->devinfo; 401230551Smav struct hdaa_audio_as *as; 402230551Smav uint32_t res; 403230551Smav int connected; 404230130Smav 405230551Smav if (w->enable == 0 || w->type != 406230551Smav HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 407230551Smav return; 408230130Smav 409230551Smav if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(w->wclass.pin.cap) == 0 || 410230551Smav (HDA_CONFIG_DEFAULTCONF_MISC(w->wclass.pin.config) & 1) != 0) 411230551Smav return; 412230551Smav 413230551Smav res = hda_command(devinfo->dev, HDA_CMD_GET_PIN_SENSE(0, w->nid)); 414230551Smav connected = (res & HDA_CMD_GET_PIN_SENSE_PRESENCE_DETECT) != 0; 415230551Smav if (devinfo->quirks & HDAA_QUIRK_SENSEINV) 416230551Smav connected = !connected; 417230551Smav if (connected == w->wclass.pin.connected) 418230551Smav return; 419230551Smav w->wclass.pin.connected = connected; 420230551Smav HDA_BOOTVERBOSE( 421230551Smav device_printf(devinfo->dev, 422230551Smav "Pin sense: nid=%d sence=0x%08x (%sconnected)\n", 423230551Smav w->nid, res, !w->wclass.pin.connected ? "dis" : ""); 424230551Smav ); 425230551Smav 426230551Smav as = &devinfo->as[w->bindas]; 427230551Smav if (as->hpredir >= 0 && as->pins[15] == w->nid) 428230551Smav hdaa_hpredir_handler(w); 429230551Smav if (as->dir == HDAA_CTL_IN) 430230551Smav hdaa_autorecsrc_handler(as, w); 431230130Smav} 432230130Smav 433230551Smav/* 434230551Smav * Callback for poll based presence detection. 435230551Smav */ 436230130Smavstatic void 437230551Smavhdaa_jack_poll_callback(void *arg) 438230130Smav{ 439230551Smav struct hdaa_devinfo *devinfo = arg; 440230551Smav struct hdaa_widget *w; 441230551Smav int i; 442230130Smav 443230551Smav hdaa_lock(devinfo); 444230551Smav if (devinfo->poll_ival == 0) { 445230551Smav hdaa_unlock(devinfo); 446230551Smav return; 447230551Smav } 448230130Smav for (i = 0; i < devinfo->ascnt; i++) { 449230551Smav if (devinfo->as[i].hpredir < 0) 450230551Smav continue; 451230551Smav w = hdaa_widget_get(devinfo, devinfo->as[i].pins[15]); 452230130Smav if (w == NULL || w->enable == 0 || w->type != 453230130Smav HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 454230130Smav continue; 455230551Smav hdaa_presence_handler(w); 456230130Smav } 457230551Smav callout_reset(&devinfo->poll_jack, devinfo->poll_ival, 458230551Smav hdaa_jack_poll_callback, devinfo); 459230551Smav hdaa_unlock(devinfo); 460230130Smav} 461230130Smav 462230312Smavstatic void 463230312Smavhdaa_eld_dump(struct hdaa_widget *w) 464230312Smav{ 465230312Smav struct hdaa_devinfo *devinfo = w->devinfo; 466230312Smav device_t dev = devinfo->dev; 467230312Smav uint8_t *sad; 468230312Smav int len, mnl, i, sadc, fmt; 469230312Smav 470230312Smav if (w->eld == NULL || w->eld_len < 4) 471230312Smav return; 472230312Smav device_printf(dev, 473230312Smav "ELD nid=%d: ELD_Ver=%u Baseline_ELD_Len=%u\n", 474230312Smav w->nid, w->eld[0] >> 3, w->eld[2]); 475230312Smav if ((w->eld[0] >> 3) != 0x02) 476230312Smav return; 477230312Smav len = min(w->eld_len, (u_int)w->eld[2] * 4); 478230312Smav mnl = w->eld[4] & 0x1f; 479230312Smav device_printf(dev, 480230312Smav "ELD nid=%d: CEA_EDID_Ver=%u MNL=%u\n", 481230312Smav w->nid, w->eld[4] >> 5, mnl); 482230312Smav sadc = w->eld[5] >> 4; 483230312Smav device_printf(dev, 484230312Smav "ELD nid=%d: SAD_Count=%u Conn_Type=%u S_AI=%u HDCP=%u\n", 485230312Smav w->nid, sadc, (w->eld[5] >> 2) & 0x3, 486230312Smav (w->eld[5] >> 1) & 0x1, w->eld[5] & 0x1); 487230312Smav device_printf(dev, 488230312Smav "ELD nid=%d: Aud_Synch_Delay=%ums\n", 489230312Smav w->nid, w->eld[6] * 2); 490230312Smav device_printf(dev, 491230312Smav "ELD nid=%d: Channels=0x%b\n", 492230312Smav w->nid, w->eld[7], 493230312Smav "\020\07RLRC\06FLRC\05RC\04RLR\03FC\02LFE\01FLR"); 494230312Smav device_printf(dev, 495230312Smav "ELD nid=%d: Port_ID=0x%02x%02x%02x%02x%02x%02x%02x%02x\n", 496230312Smav w->nid, w->eld[8], w->eld[9], w->eld[10], w->eld[11], 497230312Smav w->eld[12], w->eld[13], w->eld[14], w->eld[15]); 498230312Smav device_printf(dev, 499230312Smav "ELD nid=%d: Manufacturer_Name=0x%02x%02x\n", 500230312Smav w->nid, w->eld[16], w->eld[17]); 501230312Smav device_printf(dev, 502230312Smav "ELD nid=%d: Product_Code=0x%02x%02x\n", 503230312Smav w->nid, w->eld[18], w->eld[19]); 504230312Smav device_printf(dev, 505230312Smav "ELD nid=%d: Monitor_Name_String='%.*s'\n", 506230312Smav w->nid, mnl, &w->eld[20]); 507230312Smav for (i = 0; i < sadc; i++) { 508230312Smav sad = &w->eld[20 + mnl + i * 3]; 509230312Smav fmt = (sad[0] >> 3) & 0x0f; 510230312Smav if (fmt == HDA_HDMI_CODING_TYPE_REF_CTX) { 511230312Smav fmt = (sad[2] >> 3) & 0x1f; 512230312Smav if (fmt < 1 || fmt > 3) 513230312Smav fmt = 0; 514230312Smav else 515230312Smav fmt += 14; 516230312Smav } 517230312Smav device_printf(dev, 518230312Smav "ELD nid=%d: %s %dch freqs=0x%b", 519230312Smav w->nid, HDA_HDMI_CODING_TYPES[fmt], (sad[0] & 0x07) + 1, 520230312Smav sad[1], "\020\007192\006176\00596\00488\00348\00244\00132"); 521230312Smav switch (fmt) { 522230312Smav case HDA_HDMI_CODING_TYPE_LPCM: 523230312Smav printf(" sizes=0x%b", 524230312Smav sad[2] & 0x07, "\020\00324\00220\00116"); 525230312Smav break; 526230312Smav case HDA_HDMI_CODING_TYPE_AC3: 527230312Smav case HDA_HDMI_CODING_TYPE_MPEG1: 528230312Smav case HDA_HDMI_CODING_TYPE_MP3: 529230312Smav case HDA_HDMI_CODING_TYPE_MPEG2: 530230312Smav case HDA_HDMI_CODING_TYPE_AACLC: 531230312Smav case HDA_HDMI_CODING_TYPE_DTS: 532230312Smav case HDA_HDMI_CODING_TYPE_ATRAC: 533230312Smav printf(" max_bitrate=%d", sad[2] * 8000); 534230312Smav break; 535230312Smav case HDA_HDMI_CODING_TYPE_WMAPRO: 536230312Smav printf(" profile=%d", sad[2] & 0x07); 537230312Smav break; 538230312Smav } 539230312Smav printf("\n"); 540230312Smav } 541230312Smav} 542230312Smav 543230312Smavstatic void 544230312Smavhdaa_eld_handler(struct hdaa_widget *w) 545230312Smav{ 546230312Smav struct hdaa_devinfo *devinfo = w->devinfo; 547230312Smav uint32_t res; 548230312Smav int i; 549230312Smav 550230312Smav if (w->enable == 0 || w->type != 551230312Smav HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 552230312Smav return; 553230312Smav 554230551Smav if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(w->wclass.pin.cap) == 0 || 555230551Smav (HDA_CONFIG_DEFAULTCONF_MISC(w->wclass.pin.config) & 1) != 0) 556230551Smav return; 557230551Smav 558230551Smav res = hda_command(devinfo->dev, HDA_CMD_GET_PIN_SENSE(0, w->nid)); 559230551Smav if ((w->eld != 0) == ((res & HDA_CMD_GET_PIN_SENSE_ELD_VALID) != 0)) 560230551Smav return; 561230312Smav if (w->eld != NULL) { 562230312Smav w->eld_len = 0; 563230312Smav free(w->eld, M_HDAA); 564230312Smav w->eld = NULL; 565230312Smav } 566230312Smav HDA_BOOTVERBOSE( 567230312Smav device_printf(devinfo->dev, 568230312Smav "Pin sense: nid=%d sence=0x%08x " 569230312Smav "(%sconnected, ELD %svalid)\n", 570230312Smav w->nid, res, 571230312Smav (res & HDA_CMD_GET_PIN_SENSE_PRESENCE_DETECT) ? "" : "dis", 572230312Smav (res & HDA_CMD_GET_PIN_SENSE_ELD_VALID) ? "" : "in"); 573230312Smav ); 574230312Smav if ((res & HDA_CMD_GET_PIN_SENSE_ELD_VALID) == 0) 575230312Smav return; 576230312Smav 577230312Smav res = hda_command(devinfo->dev, 578230312Smav HDA_CMD_GET_HDMI_DIP_SIZE(0, w->nid, 0x08)); 579230312Smav if (res == HDA_INVALID) 580230312Smav return; 581230312Smav w->eld_len = res & 0xff; 582230312Smav if (w->eld_len != 0) 583230312Smav w->eld = malloc(w->eld_len, M_HDAA, M_ZERO | M_NOWAIT); 584230312Smav if (w->eld == NULL) { 585230312Smav w->eld_len = 0; 586230312Smav return; 587230312Smav } 588230312Smav 589230312Smav for (i = 0; i < w->eld_len; i++) { 590230312Smav res = hda_command(devinfo->dev, 591230312Smav HDA_CMD_GET_HDMI_ELDD(0, w->nid, i)); 592230312Smav if (res & 0x80000000) 593230312Smav w->eld[i] = res & 0xff; 594230312Smav } 595230312Smav HDA_BOOTVERBOSE( 596230312Smav hdaa_eld_dump(w); 597230312Smav ); 598230312Smav} 599230312Smav 600230551Smav/* 601230551Smav * Pin sense initializer. 602230551Smav */ 603230312Smavstatic void 604230551Smavhdaa_sense_init(struct hdaa_devinfo *devinfo) 605230312Smav{ 606230551Smav struct hdaa_audio_as *as; 607230551Smav struct hdaa_widget *w; 608230551Smav int i, poll = 0; 609230312Smav 610230312Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 611230312Smav w = hdaa_widget_get(devinfo, i); 612230551Smav if (w == NULL || w->enable == 0 || w->type != 613230312Smav HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 614230312Smav continue; 615233692Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_UNSOL_CAP(w->param.widget_cap)) { 616233692Smav if (w->unsol < 0) 617233692Smav w->unsol = HDAC_UNSOL_ALLOC( 618233692Smav device_get_parent(devinfo->dev), 619233692Smav devinfo->dev, w->nid); 620230312Smav hda_command(devinfo->dev, 621230312Smav HDA_CMD_SET_UNSOLICITED_RESPONSE(0, w->nid, 622230551Smav HDA_CMD_SET_UNSOLICITED_RESPONSE_ENABLE | w->unsol)); 623230312Smav } 624230551Smav as = &devinfo->as[w->bindas]; 625230551Smav if (as->hpredir >= 0 && as->pins[15] == w->nid) { 626230551Smav if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(w->wclass.pin.cap) == 0 || 627230551Smav (HDA_CONFIG_DEFAULTCONF_MISC(w->wclass.pin.config) & 1) != 0) { 628230551Smav device_printf(devinfo->dev, 629230551Smav "No presence detection support at nid %d\n", 630240884Smav w->nid); 631230551Smav } else { 632230551Smav if (w->unsol < 0) 633230551Smav poll = 1; 634230551Smav HDA_BOOTVERBOSE( 635230551Smav device_printf(devinfo->dev, 636230551Smav "Headphones redirection for " 637230551Smav "association %d nid=%d using %s.\n", 638230551Smav w->bindas, w->nid, 639240884Smav (w->unsol < 0) ? "polling" : 640230551Smav "unsolicited responses"); 641230551Smav ); 642230551Smav }; 643230551Smav } 644230551Smav hdaa_presence_handler(w); 645230551Smav if (!HDA_PARAM_PIN_CAP_DP(w->wclass.pin.cap) && 646230551Smav !HDA_PARAM_PIN_CAP_HDMI(w->wclass.pin.cap)) 647230551Smav continue; 648230312Smav hdaa_eld_handler(w); 649230312Smav } 650230551Smav if (poll) { 651230551Smav callout_reset(&devinfo->poll_jack, 1, 652230551Smav hdaa_jack_poll_callback, devinfo); 653230551Smav } 654230312Smav} 655230312Smav 656230312Smavstatic void 657230551Smavhdaa_sense_deinit(struct hdaa_devinfo *devinfo) 658230312Smav{ 659230312Smav struct hdaa_widget *w; 660230312Smav int i; 661230312Smav 662230551Smav callout_stop(&devinfo->poll_jack); 663230312Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 664230312Smav w = hdaa_widget_get(devinfo, i); 665230551Smav if (w == NULL || w->enable == 0 || w->type != 666230312Smav HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 667230312Smav continue; 668230312Smav if (w->unsol < 0) 669230312Smav continue; 670230312Smav hda_command(devinfo->dev, 671230312Smav HDA_CMD_SET_UNSOLICITED_RESPONSE(0, w->nid, 0)); 672230312Smav HDAC_UNSOL_FREE( 673230312Smav device_get_parent(devinfo->dev), devinfo->dev, 674230312Smav w->unsol); 675230312Smav w->unsol = -1; 676230312Smav } 677230312Smav} 678230312Smav 679230130Smavuint32_t 680230130Smavhdaa_widget_pin_patch(uint32_t config, const char *str) 681230130Smav{ 682230130Smav char buf[256]; 683230130Smav char *key, *value, *rest, *bad; 684230130Smav int ival, i; 685230130Smav 686230130Smav strlcpy(buf, str, sizeof(buf)); 687230130Smav rest = buf; 688230130Smav while ((key = strsep(&rest, "=")) != NULL) { 689230130Smav value = strsep(&rest, " \t"); 690230130Smav if (value == NULL) 691230130Smav break; 692230130Smav ival = strtol(value, &bad, 10); 693230130Smav if (strcmp(key, "seq") == 0) { 694230130Smav config &= ~HDA_CONFIG_DEFAULTCONF_SEQUENCE_MASK; 695230130Smav config |= ((ival << HDA_CONFIG_DEFAULTCONF_SEQUENCE_SHIFT) & 696230130Smav HDA_CONFIG_DEFAULTCONF_SEQUENCE_MASK); 697230130Smav } else if (strcmp(key, "as") == 0) { 698230130Smav config &= ~HDA_CONFIG_DEFAULTCONF_ASSOCIATION_MASK; 699230130Smav config |= ((ival << HDA_CONFIG_DEFAULTCONF_ASSOCIATION_SHIFT) & 700230130Smav HDA_CONFIG_DEFAULTCONF_ASSOCIATION_MASK); 701230130Smav } else if (strcmp(key, "misc") == 0) { 702230130Smav config &= ~HDA_CONFIG_DEFAULTCONF_MISC_MASK; 703230130Smav config |= ((ival << HDA_CONFIG_DEFAULTCONF_MISC_SHIFT) & 704230130Smav HDA_CONFIG_DEFAULTCONF_MISC_MASK); 705230130Smav } else if (strcmp(key, "color") == 0) { 706230130Smav config &= ~HDA_CONFIG_DEFAULTCONF_COLOR_MASK; 707230130Smav if (bad[0] == 0) { 708230130Smav config |= ((ival << HDA_CONFIG_DEFAULTCONF_COLOR_SHIFT) & 709230130Smav HDA_CONFIG_DEFAULTCONF_COLOR_MASK); 710230130Smav }; 711230130Smav for (i = 0; i < 16; i++) { 712230130Smav if (strcasecmp(HDA_COLORS[i], value) == 0) { 713230130Smav config |= (i << HDA_CONFIG_DEFAULTCONF_COLOR_SHIFT); 714230130Smav break; 715230130Smav } 716230130Smav } 717230130Smav } else if (strcmp(key, "ctype") == 0) { 718230130Smav config &= ~HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_MASK; 719230130Smav if (bad[0] == 0) { 720230130Smav config |= ((ival << HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_SHIFT) & 721230130Smav HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_MASK); 722230130Smav } 723230130Smav for (i = 0; i < 16; i++) { 724230130Smav if (strcasecmp(HDA_CONNECTORS[i], value) == 0) { 725230130Smav config |= (i << HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_SHIFT); 726230130Smav break; 727230130Smav } 728230130Smav } 729230130Smav } else if (strcmp(key, "device") == 0) { 730230130Smav config &= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK; 731230130Smav if (bad[0] == 0) { 732230130Smav config |= ((ival << HDA_CONFIG_DEFAULTCONF_DEVICE_SHIFT) & 733230130Smav HDA_CONFIG_DEFAULTCONF_DEVICE_MASK); 734230130Smav continue; 735230130Smav }; 736230130Smav for (i = 0; i < 16; i++) { 737230130Smav if (strcasecmp(HDA_DEVS[i], value) == 0) { 738230130Smav config |= (i << HDA_CONFIG_DEFAULTCONF_DEVICE_SHIFT); 739230130Smav break; 740230130Smav } 741230130Smav } 742230130Smav } else if (strcmp(key, "loc") == 0) { 743230130Smav config &= ~HDA_CONFIG_DEFAULTCONF_LOCATION_MASK; 744230130Smav if (bad[0] == 0) { 745230130Smav config |= ((ival << HDA_CONFIG_DEFAULTCONF_LOCATION_SHIFT) & 746230130Smav HDA_CONFIG_DEFAULTCONF_LOCATION_MASK); 747230130Smav continue; 748230130Smav } 749230130Smav for (i = 0; i < 64; i++) { 750230130Smav if (strcasecmp(HDA_LOCS[i], value) == 0) { 751230130Smav config |= (i << HDA_CONFIG_DEFAULTCONF_LOCATION_SHIFT); 752230130Smav break; 753230130Smav } 754230130Smav } 755230130Smav } else if (strcmp(key, "conn") == 0) { 756230130Smav config &= ~HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK; 757230130Smav if (bad[0] == 0) { 758230130Smav config |= ((ival << HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_SHIFT) & 759230130Smav HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK); 760230130Smav continue; 761230130Smav }; 762230130Smav for (i = 0; i < 4; i++) { 763230130Smav if (strcasecmp(HDA_CONNS[i], value) == 0) { 764230130Smav config |= (i << HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_SHIFT); 765230130Smav break; 766230130Smav } 767230130Smav } 768230130Smav } 769230130Smav } 770230130Smav return (config); 771230130Smav} 772230130Smav 773230130Smavuint32_t 774230130Smavhdaa_gpio_patch(uint32_t gpio, const char *str) 775230130Smav{ 776230130Smav char buf[256]; 777230130Smav char *key, *value, *rest; 778230130Smav int ikey, i; 779230130Smav 780230130Smav strlcpy(buf, str, sizeof(buf)); 781230130Smav rest = buf; 782230130Smav while ((key = strsep(&rest, "=")) != NULL) { 783230130Smav value = strsep(&rest, " \t"); 784230130Smav if (value == NULL) 785230130Smav break; 786230130Smav ikey = strtol(key, NULL, 10); 787230130Smav if (ikey < 0 || ikey > 7) 788230130Smav continue; 789230130Smav for (i = 0; i < 7; i++) { 790230130Smav if (strcasecmp(HDA_GPIO_ACTIONS[i], value) == 0) { 791230130Smav gpio &= ~HDAA_GPIO_MASK(ikey); 792230130Smav gpio |= i << HDAA_GPIO_SHIFT(ikey); 793230130Smav break; 794230130Smav } 795230130Smav } 796230130Smav } 797230130Smav return (gpio); 798230130Smav} 799230130Smav 800230130Smavstatic void 801230130Smavhdaa_local_patch_pin(struct hdaa_widget *w) 802230130Smav{ 803230130Smav device_t dev = w->devinfo->dev; 804230130Smav const char *res = NULL; 805230130Smav uint32_t config, orig; 806230130Smav char buf[32]; 807230130Smav 808230130Smav config = orig = w->wclass.pin.config; 809230130Smav snprintf(buf, sizeof(buf), "cad%u.nid%u.config", 810230130Smav hda_get_codec_id(dev), w->nid); 811230130Smav if (resource_string_value(device_get_name( 812230130Smav device_get_parent(device_get_parent(dev))), 813230130Smav device_get_unit(device_get_parent(device_get_parent(dev))), 814230130Smav buf, &res) == 0) { 815230130Smav if (strncmp(res, "0x", 2) == 0) { 816230130Smav config = strtol(res + 2, NULL, 16); 817230130Smav } else { 818230130Smav config = hdaa_widget_pin_patch(config, res); 819230130Smav } 820230130Smav } 821230130Smav snprintf(buf, sizeof(buf), "nid%u.config", w->nid); 822230130Smav if (resource_string_value(device_get_name(dev), device_get_unit(dev), 823230130Smav buf, &res) == 0) { 824230130Smav if (strncmp(res, "0x", 2) == 0) { 825230130Smav config = strtol(res + 2, NULL, 16); 826230130Smav } else { 827230130Smav config = hdaa_widget_pin_patch(config, res); 828230130Smav } 829230130Smav } 830230130Smav HDA_BOOTVERBOSE( 831230130Smav if (config != orig) 832230130Smav device_printf(w->devinfo->dev, 833230130Smav "Patching pin config nid=%u 0x%08x -> 0x%08x\n", 834230130Smav w->nid, orig, config); 835230130Smav ); 836230130Smav w->wclass.pin.newconf = w->wclass.pin.config = config; 837230130Smav} 838230130Smav 839230130Smavstatic int 840230130Smavhdaa_sysctl_config(SYSCTL_HANDLER_ARGS) 841230130Smav{ 842230130Smav char buf[256]; 843230130Smav int error; 844230130Smav uint32_t conf; 845230130Smav 846230130Smav conf = *(uint32_t *)oidp->oid_arg1; 847230130Smav snprintf(buf, sizeof(buf), "0x%08x as=%d seq=%d " 848230130Smav "device=%s conn=%s ctype=%s loc=%s color=%s misc=%d", 849230130Smav conf, 850230130Smav HDA_CONFIG_DEFAULTCONF_ASSOCIATION(conf), 851230130Smav HDA_CONFIG_DEFAULTCONF_SEQUENCE(conf), 852230130Smav HDA_DEVS[HDA_CONFIG_DEFAULTCONF_DEVICE(conf)], 853230130Smav HDA_CONNS[HDA_CONFIG_DEFAULTCONF_CONNECTIVITY(conf)], 854230130Smav HDA_CONNECTORS[HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE(conf)], 855230130Smav HDA_LOCS[HDA_CONFIG_DEFAULTCONF_LOCATION(conf)], 856230130Smav HDA_COLORS[HDA_CONFIG_DEFAULTCONF_COLOR(conf)], 857230130Smav HDA_CONFIG_DEFAULTCONF_MISC(conf)); 858230130Smav error = sysctl_handle_string(oidp, buf, sizeof(buf), req); 859230130Smav if (error != 0 || req->newptr == NULL) 860230130Smav return (error); 861230130Smav if (strncmp(buf, "0x", 2) == 0) 862230130Smav conf = strtol(buf + 2, NULL, 16); 863230130Smav else 864230130Smav conf = hdaa_widget_pin_patch(conf, buf); 865230130Smav *(uint32_t *)oidp->oid_arg1 = conf; 866230130Smav return (0); 867230130Smav} 868230130Smav 869230130Smavstatic void 870230130Smavhdaa_config_fetch(const char *str, uint32_t *on, uint32_t *off) 871230130Smav{ 872230130Smav int i = 0, j, k, len, inv; 873230130Smav 874230130Smav for (;;) { 875230130Smav while (str[i] != '\0' && 876230130Smav (str[i] == ',' || isspace(str[i]) != 0)) 877230130Smav i++; 878230130Smav if (str[i] == '\0') 879230130Smav return; 880230130Smav j = i; 881230130Smav while (str[j] != '\0' && 882230130Smav !(str[j] == ',' || isspace(str[j]) != 0)) 883230130Smav j++; 884230130Smav len = j - i; 885230130Smav if (len > 2 && strncmp(str + i, "no", 2) == 0) 886230130Smav inv = 2; 887230130Smav else 888230130Smav inv = 0; 889230130Smav for (k = 0; len > inv && k < HDAA_QUIRKS_TAB_LEN; k++) { 890230130Smav if (strncmp(str + i + inv, 891230130Smav hdaa_quirks_tab[k].key, len - inv) != 0) 892230130Smav continue; 893230130Smav if (len - inv != strlen(hdaa_quirks_tab[k].key)) 894230130Smav continue; 895230130Smav if (inv == 0) { 896230130Smav *on |= hdaa_quirks_tab[k].value; 897230130Smav *off &= ~hdaa_quirks_tab[k].value; 898230130Smav } else { 899230130Smav *off |= hdaa_quirks_tab[k].value; 900230130Smav *on &= ~hdaa_quirks_tab[k].value; 901230130Smav } 902230130Smav break; 903230130Smav } 904230130Smav i = j; 905230130Smav } 906230130Smav} 907230130Smav 908230130Smavstatic int 909230130Smavhdaa_sysctl_quirks(SYSCTL_HANDLER_ARGS) 910230130Smav{ 911230130Smav char buf[256]; 912230130Smav int error, n = 0, i; 913230130Smav uint32_t quirks, quirks_off; 914230130Smav 915230130Smav quirks = *(uint32_t *)oidp->oid_arg1; 916230130Smav buf[0] = 0; 917230130Smav for (i = 0; i < HDAA_QUIRKS_TAB_LEN; i++) { 918230130Smav if ((quirks & hdaa_quirks_tab[i].value) != 0) 919230130Smav n += snprintf(buf + n, sizeof(buf) - n, "%s%s", 920230130Smav n != 0 ? "," : "", hdaa_quirks_tab[i].key); 921230130Smav } 922230130Smav error = sysctl_handle_string(oidp, buf, sizeof(buf), req); 923230130Smav if (error != 0 || req->newptr == NULL) 924230130Smav return (error); 925230130Smav if (strncmp(buf, "0x", 2) == 0) 926230130Smav quirks = strtol(buf + 2, NULL, 16); 927230130Smav else { 928230130Smav quirks = 0; 929230130Smav hdaa_config_fetch(buf, &quirks, &quirks_off); 930230130Smav } 931230130Smav *(uint32_t *)oidp->oid_arg1 = quirks; 932230130Smav return (0); 933230130Smav} 934230130Smav 935230130Smavstatic void 936230130Smavhdaa_local_patch(struct hdaa_devinfo *devinfo) 937230130Smav{ 938230130Smav struct hdaa_widget *w; 939230130Smav const char *res = NULL; 940230130Smav uint32_t quirks_on = 0, quirks_off = 0, x; 941230130Smav int i; 942230130Smav 943230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 944230130Smav w = hdaa_widget_get(devinfo, i); 945230130Smav if (w == NULL) 946230130Smav continue; 947230130Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 948230130Smav hdaa_local_patch_pin(w); 949230130Smav } 950230130Smav 951230130Smav if (resource_string_value(device_get_name(devinfo->dev), 952230130Smav device_get_unit(devinfo->dev), "config", &res) == 0) { 953230130Smav if (res != NULL && strlen(res) > 0) 954230130Smav hdaa_config_fetch(res, &quirks_on, &quirks_off); 955230130Smav devinfo->quirks |= quirks_on; 956230130Smav devinfo->quirks &= ~quirks_off; 957230130Smav } 958230130Smav if (devinfo->newquirks == -1) 959230130Smav devinfo->newquirks = devinfo->quirks; 960230130Smav else 961230130Smav devinfo->quirks = devinfo->newquirks; 962230130Smav HDA_BOOTHVERBOSE( 963230130Smav device_printf(devinfo->dev, 964230130Smav "Config options: 0x%08x\n", devinfo->quirks); 965230130Smav ); 966230130Smav 967230130Smav if (resource_string_value(device_get_name(devinfo->dev), 968230130Smav device_get_unit(devinfo->dev), "gpio_config", &res) == 0) { 969230130Smav if (strncmp(res, "0x", 2) == 0) { 970230130Smav devinfo->gpio = strtol(res + 2, NULL, 16); 971230130Smav } else { 972230130Smav devinfo->gpio = hdaa_gpio_patch(devinfo->gpio, res); 973230130Smav } 974230130Smav } 975230130Smav if (devinfo->newgpio == -1) 976230130Smav devinfo->newgpio = devinfo->gpio; 977230130Smav else 978230130Smav devinfo->gpio = devinfo->newgpio; 979230130Smav if (devinfo->newgpo == -1) 980230130Smav devinfo->newgpo = devinfo->gpo; 981230130Smav else 982230130Smav devinfo->gpo = devinfo->newgpo; 983230130Smav HDA_BOOTHVERBOSE( 984230130Smav device_printf(devinfo->dev, "GPIO config options:"); 985230130Smav for (i = 0; i < 7; i++) { 986230130Smav x = (devinfo->gpio & HDAA_GPIO_MASK(i)) >> HDAA_GPIO_SHIFT(i); 987230130Smav if (x != 0) 988230130Smav printf(" %d=%s", i, HDA_GPIO_ACTIONS[x]); 989230130Smav } 990230130Smav printf("\n"); 991230130Smav ); 992230130Smav} 993230130Smav 994230130Smavstatic void 995230130Smavhdaa_widget_connection_parse(struct hdaa_widget *w) 996230130Smav{ 997230130Smav uint32_t res; 998230130Smav int i, j, max, ents, entnum; 999230130Smav nid_t nid = w->nid; 1000230130Smav nid_t cnid, addcnid, prevcnid; 1001230130Smav 1002230130Smav w->nconns = 0; 1003230130Smav 1004230130Smav res = hda_command(w->devinfo->dev, 1005230130Smav HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_CONN_LIST_LENGTH)); 1006230130Smav 1007230130Smav ents = HDA_PARAM_CONN_LIST_LENGTH_LIST_LENGTH(res); 1008230130Smav 1009230130Smav if (ents < 1) 1010230130Smav return; 1011230130Smav 1012230130Smav entnum = HDA_PARAM_CONN_LIST_LENGTH_LONG_FORM(res) ? 2 : 4; 1013230130Smav max = (sizeof(w->conns) / sizeof(w->conns[0])) - 1; 1014230130Smav prevcnid = 0; 1015230130Smav 1016230130Smav#define CONN_RMASK(e) (1 << ((32 / (e)) - 1)) 1017230130Smav#define CONN_NMASK(e) (CONN_RMASK(e) - 1) 1018230130Smav#define CONN_RESVAL(r, e, n) ((r) >> ((32 / (e)) * (n))) 1019230130Smav#define CONN_RANGE(r, e, n) (CONN_RESVAL(r, e, n) & CONN_RMASK(e)) 1020230130Smav#define CONN_CNID(r, e, n) (CONN_RESVAL(r, e, n) & CONN_NMASK(e)) 1021230130Smav 1022230130Smav for (i = 0; i < ents; i += entnum) { 1023230130Smav res = hda_command(w->devinfo->dev, 1024230130Smav HDA_CMD_GET_CONN_LIST_ENTRY(0, nid, i)); 1025230130Smav for (j = 0; j < entnum; j++) { 1026230130Smav cnid = CONN_CNID(res, entnum, j); 1027230130Smav if (cnid == 0) { 1028230130Smav if (w->nconns < ents) 1029230130Smav device_printf(w->devinfo->dev, 1030230130Smav "WARNING: nid=%d has zero cnid " 1031230130Smav "entnum=%d j=%d index=%d " 1032230130Smav "entries=%d found=%d res=0x%08x\n", 1033230130Smav nid, entnum, j, i, 1034230130Smav ents, w->nconns, res); 1035230130Smav else 1036230130Smav goto getconns_out; 1037230130Smav } 1038230130Smav if (cnid < w->devinfo->startnode || 1039230130Smav cnid >= w->devinfo->endnode) { 1040230130Smav HDA_BOOTVERBOSE( 1041230130Smav device_printf(w->devinfo->dev, 1042230130Smav "WARNING: nid=%d has cnid outside " 1043230130Smav "of the AFG range j=%d " 1044230130Smav "entnum=%d index=%d res=0x%08x\n", 1045230130Smav nid, j, entnum, i, res); 1046230130Smav ); 1047230130Smav } 1048230130Smav if (CONN_RANGE(res, entnum, j) == 0) 1049230130Smav addcnid = cnid; 1050230130Smav else if (prevcnid == 0 || prevcnid >= cnid) { 1051230130Smav device_printf(w->devinfo->dev, 1052230130Smav "WARNING: Invalid child range " 1053230130Smav "nid=%d index=%d j=%d entnum=%d " 1054230130Smav "prevcnid=%d cnid=%d res=0x%08x\n", 1055230130Smav nid, i, j, entnum, prevcnid, 1056230130Smav cnid, res); 1057230130Smav addcnid = cnid; 1058230130Smav } else 1059230130Smav addcnid = prevcnid + 1; 1060230130Smav while (addcnid <= cnid) { 1061230130Smav if (w->nconns > max) { 1062230130Smav device_printf(w->devinfo->dev, 1063230130Smav "Adding %d (nid=%d): " 1064230130Smav "Max connection reached! max=%d\n", 1065230130Smav addcnid, nid, max + 1); 1066230130Smav goto getconns_out; 1067230130Smav } 1068230130Smav w->connsenable[w->nconns] = 1; 1069230130Smav w->conns[w->nconns++] = addcnid++; 1070230130Smav } 1071230130Smav prevcnid = cnid; 1072230130Smav } 1073230130Smav } 1074230130Smav 1075230130Smavgetconns_out: 1076230130Smav return; 1077230130Smav} 1078230130Smav 1079230130Smavstatic void 1080230130Smavhdaa_widget_parse(struct hdaa_widget *w) 1081230130Smav{ 1082230130Smav device_t dev = w->devinfo->dev; 1083230130Smav uint32_t wcap, cap; 1084230130Smav nid_t nid = w->nid; 1085230130Smav char buf[64]; 1086230130Smav 1087230130Smav w->param.widget_cap = wcap = hda_command(dev, 1088230130Smav HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_AUDIO_WIDGET_CAP)); 1089230130Smav w->type = HDA_PARAM_AUDIO_WIDGET_CAP_TYPE(wcap); 1090230130Smav 1091230130Smav hdaa_widget_connection_parse(w); 1092230130Smav 1093230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_OUT_AMP(wcap)) { 1094230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_AMP_OVR(wcap)) 1095230130Smav w->param.outamp_cap = 1096230130Smav hda_command(dev, 1097230130Smav HDA_CMD_GET_PARAMETER(0, nid, 1098230130Smav HDA_PARAM_OUTPUT_AMP_CAP)); 1099230130Smav else 1100230130Smav w->param.outamp_cap = 1101230130Smav w->devinfo->outamp_cap; 1102230130Smav } else 1103230130Smav w->param.outamp_cap = 0; 1104230130Smav 1105230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_IN_AMP(wcap)) { 1106230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_AMP_OVR(wcap)) 1107230130Smav w->param.inamp_cap = 1108230130Smav hda_command(dev, 1109230130Smav HDA_CMD_GET_PARAMETER(0, nid, 1110230130Smav HDA_PARAM_INPUT_AMP_CAP)); 1111230130Smav else 1112230130Smav w->param.inamp_cap = 1113230130Smav w->devinfo->inamp_cap; 1114230130Smav } else 1115230130Smav w->param.inamp_cap = 0; 1116230130Smav 1117230130Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT || 1118230130Smav w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) { 1119230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_FORMAT_OVR(wcap)) { 1120230130Smav cap = hda_command(dev, 1121230130Smav HDA_CMD_GET_PARAMETER(0, nid, 1122230130Smav HDA_PARAM_SUPP_STREAM_FORMATS)); 1123230130Smav w->param.supp_stream_formats = (cap != 0) ? cap : 1124230130Smav w->devinfo->supp_stream_formats; 1125230130Smav cap = hda_command(dev, 1126230130Smav HDA_CMD_GET_PARAMETER(0, nid, 1127230130Smav HDA_PARAM_SUPP_PCM_SIZE_RATE)); 1128230130Smav w->param.supp_pcm_size_rate = (cap != 0) ? cap : 1129230130Smav w->devinfo->supp_pcm_size_rate; 1130230130Smav } else { 1131230130Smav w->param.supp_stream_formats = 1132230130Smav w->devinfo->supp_stream_formats; 1133230130Smav w->param.supp_pcm_size_rate = 1134230130Smav w->devinfo->supp_pcm_size_rate; 1135230130Smav } 1136230326Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_STRIPE(w->param.widget_cap)) { 1137230326Smav w->wclass.conv.stripecap = hda_command(dev, 1138230326Smav HDA_CMD_GET_STRIPE_CONTROL(0, w->nid)) >> 20; 1139230326Smav } else 1140230326Smav w->wclass.conv.stripecap = 1; 1141230130Smav } else { 1142230130Smav w->param.supp_stream_formats = 0; 1143230130Smav w->param.supp_pcm_size_rate = 0; 1144230130Smav } 1145230130Smav 1146230130Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) { 1147230130Smav w->wclass.pin.original = w->wclass.pin.newconf = 1148230130Smav w->wclass.pin.config = hda_command(dev, 1149230130Smav HDA_CMD_GET_CONFIGURATION_DEFAULT(0, w->nid)); 1150230130Smav w->wclass.pin.cap = hda_command(dev, 1151241844Seadler HDA_CMD_GET_PARAMETER(0, w->nid, HDA_PARAM_PIN_CAP)); 1152230130Smav w->wclass.pin.ctrl = hda_command(dev, 1153230130Smav HDA_CMD_GET_PIN_WIDGET_CTRL(0, nid)); 1154230130Smav if (HDA_PARAM_PIN_CAP_EAPD_CAP(w->wclass.pin.cap)) { 1155230130Smav w->param.eapdbtl = hda_command(dev, 1156230130Smav HDA_CMD_GET_EAPD_BTL_ENABLE(0, nid)); 1157230130Smav w->param.eapdbtl &= 0x7; 1158230130Smav w->param.eapdbtl |= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD; 1159230130Smav } else 1160230130Smav w->param.eapdbtl = HDA_INVALID; 1161230130Smav 1162230130Smav hdaa_unlock(w->devinfo); 1163230130Smav snprintf(buf, sizeof(buf), "nid%d_config", w->nid); 1164230130Smav SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 1165230130Smav SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, 1166230130Smav buf, CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE, 1167230130Smav &w->wclass.pin.newconf, sizeof(&w->wclass.pin.newconf), 1168230130Smav hdaa_sysctl_config, "A", "Current pin configuration"); 1169230130Smav snprintf(buf, sizeof(buf), "nid%d_original", w->nid); 1170230130Smav SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 1171230130Smav SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, 1172230130Smav buf, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, 1173230130Smav &w->wclass.pin.original, sizeof(&w->wclass.pin.original), 1174230130Smav hdaa_sysctl_config, "A", "Original pin configuration"); 1175230130Smav hdaa_lock(w->devinfo); 1176230130Smav } 1177230312Smav w->unsol = -1; 1178230130Smav} 1179230130Smav 1180230130Smavstatic void 1181230130Smavhdaa_widget_postprocess(struct hdaa_widget *w) 1182230130Smav{ 1183230130Smav char *typestr; 1184230130Smav 1185230130Smav w->type = HDA_PARAM_AUDIO_WIDGET_CAP_TYPE(w->param.widget_cap); 1186230130Smav switch (w->type) { 1187230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT: 1188230130Smav typestr = "audio output"; 1189230130Smav break; 1190230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT: 1191230130Smav typestr = "audio input"; 1192230130Smav break; 1193230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER: 1194230130Smav typestr = "audio mixer"; 1195230130Smav break; 1196230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR: 1197230130Smav typestr = "audio selector"; 1198230130Smav break; 1199230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX: 1200230130Smav typestr = "pin"; 1201230130Smav break; 1202230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_POWER_WIDGET: 1203230130Smav typestr = "power widget"; 1204230130Smav break; 1205230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_VOLUME_WIDGET: 1206230130Smav typestr = "volume widget"; 1207230130Smav break; 1208230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET: 1209230130Smav typestr = "beep widget"; 1210230130Smav break; 1211230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_VENDOR_WIDGET: 1212230130Smav typestr = "vendor widget"; 1213230130Smav break; 1214230130Smav default: 1215230130Smav typestr = "unknown type"; 1216230130Smav break; 1217230130Smav } 1218230130Smav strlcpy(w->name, typestr, sizeof(w->name)); 1219230130Smav 1220230130Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) { 1221230130Smav uint32_t config; 1222230130Smav const char *devstr; 1223230130Smav int conn, color; 1224230130Smav 1225230130Smav config = w->wclass.pin.config; 1226230130Smav devstr = HDA_DEVS[(config & HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) >> 1227230130Smav HDA_CONFIG_DEFAULTCONF_DEVICE_SHIFT]; 1228230130Smav conn = (config & HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK) >> 1229230130Smav HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_SHIFT; 1230230130Smav color = (config & HDA_CONFIG_DEFAULTCONF_COLOR_MASK) >> 1231230130Smav HDA_CONFIG_DEFAULTCONF_COLOR_SHIFT; 1232230130Smav strlcat(w->name, ": ", sizeof(w->name)); 1233230130Smav strlcat(w->name, devstr, sizeof(w->name)); 1234230130Smav strlcat(w->name, " (", sizeof(w->name)); 1235230130Smav if (conn == 0 && color != 0 && color != 15) { 1236230130Smav strlcat(w->name, HDA_COLORS[color], sizeof(w->name)); 1237230130Smav strlcat(w->name, " ", sizeof(w->name)); 1238230130Smav } 1239230130Smav strlcat(w->name, HDA_CONNS[conn], sizeof(w->name)); 1240230130Smav strlcat(w->name, ")", sizeof(w->name)); 1241230551Smav 1242230551Smav if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(w->wclass.pin.cap) == 0 || 1243230551Smav (HDA_CONFIG_DEFAULTCONF_MISC(w->wclass.pin.config) & 1) != 0) 1244230551Smav w->wclass.pin.connected = 2; 1245230130Smav } 1246230130Smav} 1247230130Smav 1248230130Smavstruct hdaa_widget * 1249230130Smavhdaa_widget_get(struct hdaa_devinfo *devinfo, nid_t nid) 1250230130Smav{ 1251230130Smav if (devinfo == NULL || devinfo->widget == NULL || 1252230130Smav nid < devinfo->startnode || nid >= devinfo->endnode) 1253230130Smav return (NULL); 1254230130Smav return (&devinfo->widget[nid - devinfo->startnode]); 1255230130Smav} 1256230130Smav 1257230130Smavstatic void 1258230130Smavhdaa_audio_ctl_amp_set_internal(struct hdaa_devinfo *devinfo, nid_t nid, 1259230130Smav int index, int lmute, int rmute, 1260230130Smav int left, int right, int dir) 1261230130Smav{ 1262230130Smav uint16_t v = 0; 1263230130Smav 1264230130Smav HDA_BOOTHVERBOSE( 1265230130Smav device_printf(devinfo->dev, 1266230130Smav "Setting amplifier nid=%d index=%d %s mute=%d/%d vol=%d/%d\n", 1267230130Smav nid,index,dir ? "in" : "out",lmute,rmute,left,right); 1268230130Smav ); 1269230130Smav if (left != right || lmute != rmute) { 1270230130Smav v = (1 << (15 - dir)) | (1 << 13) | (index << 8) | 1271230130Smav (lmute << 7) | left; 1272230130Smav hda_command(devinfo->dev, 1273230130Smav HDA_CMD_SET_AMP_GAIN_MUTE(0, nid, v)); 1274230130Smav v = (1 << (15 - dir)) | (1 << 12) | (index << 8) | 1275230130Smav (rmute << 7) | right; 1276230130Smav } else 1277230130Smav v = (1 << (15 - dir)) | (3 << 12) | (index << 8) | 1278230130Smav (lmute << 7) | left; 1279230130Smav 1280230130Smav hda_command(devinfo->dev, 1281230130Smav HDA_CMD_SET_AMP_GAIN_MUTE(0, nid, v)); 1282230130Smav} 1283230130Smav 1284230130Smavstatic void 1285230130Smavhdaa_audio_ctl_amp_set(struct hdaa_audio_ctl *ctl, uint32_t mute, 1286230130Smav int left, int right) 1287230130Smav{ 1288230130Smav nid_t nid; 1289230130Smav int lmute, rmute; 1290230130Smav 1291230130Smav nid = ctl->widget->nid; 1292230130Smav 1293230130Smav /* Save new values if valid. */ 1294230130Smav if (mute != HDAA_AMP_MUTE_DEFAULT) 1295230130Smav ctl->muted = mute; 1296230130Smav if (left != HDAA_AMP_VOL_DEFAULT) 1297230130Smav ctl->left = left; 1298230130Smav if (right != HDAA_AMP_VOL_DEFAULT) 1299230130Smav ctl->right = right; 1300230130Smav /* Prepare effective values */ 1301230130Smav if (ctl->forcemute) { 1302230130Smav lmute = 1; 1303230130Smav rmute = 1; 1304230130Smav left = 0; 1305230130Smav right = 0; 1306230130Smav } else { 1307230130Smav lmute = HDAA_AMP_LEFT_MUTED(ctl->muted); 1308230130Smav rmute = HDAA_AMP_RIGHT_MUTED(ctl->muted); 1309230130Smav left = ctl->left; 1310230130Smav right = ctl->right; 1311230130Smav } 1312230130Smav /* Apply effective values */ 1313230130Smav if (ctl->dir & HDAA_CTL_OUT) 1314230130Smav hdaa_audio_ctl_amp_set_internal(ctl->widget->devinfo, nid, ctl->index, 1315230130Smav lmute, rmute, left, right, 0); 1316230130Smav if (ctl->dir & HDAA_CTL_IN) 1317230130Smav hdaa_audio_ctl_amp_set_internal(ctl->widget->devinfo, nid, ctl->index, 1318230130Smav lmute, rmute, left, right, 1); 1319230130Smav} 1320230130Smav 1321230130Smavstatic void 1322230130Smavhdaa_widget_connection_select(struct hdaa_widget *w, uint8_t index) 1323230130Smav{ 1324230130Smav if (w == NULL || w->nconns < 1 || index > (w->nconns - 1)) 1325230130Smav return; 1326230130Smav HDA_BOOTHVERBOSE( 1327230130Smav device_printf(w->devinfo->dev, 1328230130Smav "Setting selector nid=%d index=%d\n", w->nid, index); 1329230130Smav ); 1330230130Smav hda_command(w->devinfo->dev, 1331230130Smav HDA_CMD_SET_CONNECTION_SELECT_CONTROL(0, w->nid, index)); 1332230130Smav w->selconn = index; 1333230130Smav} 1334230130Smav 1335230130Smav/**************************************************************************** 1336230130Smav * Device Methods 1337230130Smav ****************************************************************************/ 1338230130Smav 1339230130Smavstatic void * 1340230130Smavhdaa_channel_init(kobj_t obj, void *data, struct snd_dbuf *b, 1341230130Smav struct pcm_channel *c, int dir) 1342230130Smav{ 1343230130Smav struct hdaa_chan *ch = data; 1344230130Smav struct hdaa_pcm_devinfo *pdevinfo = ch->pdevinfo; 1345230130Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 1346230130Smav 1347230130Smav hdaa_lock(devinfo); 1348230130Smav if (devinfo->quirks & HDAA_QUIRK_FIXEDRATE) { 1349230130Smav ch->caps.minspeed = ch->caps.maxspeed = 48000; 1350230130Smav ch->pcmrates[0] = 48000; 1351230130Smav ch->pcmrates[1] = 0; 1352230130Smav } 1353230130Smav ch->dir = dir; 1354230130Smav ch->b = b; 1355230130Smav ch->c = c; 1356230130Smav ch->blksz = pdevinfo->chan_size / pdevinfo->chan_blkcnt; 1357230130Smav ch->blkcnt = pdevinfo->chan_blkcnt; 1358230130Smav hdaa_unlock(devinfo); 1359230130Smav 1360230130Smav if (sndbuf_alloc(ch->b, bus_get_dma_tag(devinfo->dev), 1361230130Smav hda_get_dma_nocache(devinfo->dev) ? BUS_DMA_NOCACHE : 0, 1362230130Smav pdevinfo->chan_size) != 0) 1363230130Smav return (NULL); 1364230130Smav 1365230130Smav return (ch); 1366230130Smav} 1367230130Smav 1368230130Smavstatic int 1369230130Smavhdaa_channel_setformat(kobj_t obj, void *data, uint32_t format) 1370230130Smav{ 1371230130Smav struct hdaa_chan *ch = data; 1372230130Smav int i; 1373230130Smav 1374230130Smav for (i = 0; ch->caps.fmtlist[i] != 0; i++) { 1375230130Smav if (format == ch->caps.fmtlist[i]) { 1376230130Smav ch->fmt = format; 1377230130Smav return (0); 1378230130Smav } 1379230130Smav } 1380230130Smav 1381230130Smav return (EINVAL); 1382230130Smav} 1383230130Smav 1384230130Smavstatic uint32_t 1385230130Smavhdaa_channel_setspeed(kobj_t obj, void *data, uint32_t speed) 1386230130Smav{ 1387230130Smav struct hdaa_chan *ch = data; 1388230130Smav uint32_t spd = 0, threshold; 1389230130Smav int i; 1390230130Smav 1391230130Smav /* First look for equal or multiple frequency. */ 1392230130Smav for (i = 0; ch->pcmrates[i] != 0; i++) { 1393230130Smav spd = ch->pcmrates[i]; 1394230130Smav if (speed != 0 && spd / speed * speed == spd) { 1395230130Smav ch->spd = spd; 1396230130Smav return (spd); 1397230130Smav } 1398230130Smav } 1399230130Smav /* If no match, just find nearest. */ 1400230130Smav for (i = 0; ch->pcmrates[i] != 0; i++) { 1401230130Smav spd = ch->pcmrates[i]; 1402230130Smav threshold = spd + ((ch->pcmrates[i + 1] != 0) ? 1403230130Smav ((ch->pcmrates[i + 1] - spd) >> 1) : 0); 1404230130Smav if (speed < threshold) 1405230130Smav break; 1406230130Smav } 1407230130Smav ch->spd = spd; 1408230130Smav return (spd); 1409230130Smav} 1410230130Smav 1411230130Smavstatic uint16_t 1412230130Smavhdaa_stream_format(struct hdaa_chan *ch) 1413230130Smav{ 1414230130Smav int i; 1415230130Smav uint16_t fmt; 1416230130Smav 1417230130Smav fmt = 0; 1418230130Smav if (ch->fmt & AFMT_S16_LE) 1419230130Smav fmt |= ch->bit16 << 4; 1420230130Smav else if (ch->fmt & AFMT_S32_LE) 1421230130Smav fmt |= ch->bit32 << 4; 1422230130Smav else 1423230130Smav fmt |= 1 << 4; 1424230130Smav for (i = 0; i < HDA_RATE_TAB_LEN; i++) { 1425230130Smav if (hda_rate_tab[i].valid && ch->spd == hda_rate_tab[i].rate) { 1426230130Smav fmt |= hda_rate_tab[i].base; 1427230130Smav fmt |= hda_rate_tab[i].mul; 1428230130Smav fmt |= hda_rate_tab[i].div; 1429230130Smav break; 1430230130Smav } 1431230130Smav } 1432230130Smav fmt |= (AFMT_CHANNEL(ch->fmt) - 1); 1433230130Smav 1434230130Smav return (fmt); 1435230130Smav} 1436230130Smav 1437230326Smavstatic int 1438230326Smavhdaa_allowed_stripes(uint16_t fmt) 1439230326Smav{ 1440230326Smav static const int bits[8] = { 8, 16, 20, 24, 32, 32, 32, 32 }; 1441230326Smav int size; 1442230326Smav 1443230326Smav size = bits[(fmt >> 4) & 0x03]; 1444230326Smav size *= (fmt & 0x0f) + 1; 1445230326Smav size *= ((fmt >> 11) & 0x07) + 1; 1446230326Smav return (0xffffffffU >> (32 - fls(size / 8))); 1447230326Smav} 1448230326Smav 1449230130Smavstatic void 1450230130Smavhdaa_audio_setup(struct hdaa_chan *ch) 1451230130Smav{ 1452230130Smav struct hdaa_audio_as *as = &ch->devinfo->as[ch->as]; 1453230312Smav struct hdaa_widget *w, *wp; 1454230312Smav int i, j, k, chn, cchn, totalchn, totalextchn, c; 1455230130Smav uint16_t fmt, dfmt; 1456230312Smav /* Mapping channel pairs to codec pins/converters. */ 1457230312Smav const static uint16_t convmap[2][5] = 1458230312Smav {{ 0x0010, 0x0001, 0x0201, 0x0231, 0x0231 }, /* 5.1 */ 1459230312Smav { 0x0010, 0x0001, 0x2001, 0x2031, 0x2431 }};/* 7.1 */ 1460230312Smav /* Mapping formats to HDMI channel allocations. */ 1461230312Smav const static uint8_t hdmica[2][8] = 1462230312Smav {{ 0x02, 0x00, 0x04, 0x08, 0x0a, 0x0e, 0x12, 0x12 }, /* x.0 */ 1463230312Smav { 0x01, 0x03, 0x01, 0x03, 0x09, 0x0b, 0x0f, 0x13 }}; /* x.1 */ 1464230312Smav /* Mapping formats to HDMI channels order. */ 1465230312Smav const static uint32_t hdmich[2][8] = 1466230312Smav {{ 0xFFFF0F00, 0xFFFFFF10, 0xFFF2FF10, 0xFF32FF10, 1467230312Smav 0xFF324F10, 0xF5324F10, 0x54326F10, 0x54326F10 }, /* x.0 */ 1468230312Smav { 0xFFFFF000, 0xFFFF0100, 0xFFFFF210, 0xFFFF2310, 1469230312Smav 0xFF32F410, 0xFF324510, 0xF6324510, 0x76325410 }}; /* x.1 */ 1470230312Smav int convmapid = -1; 1471230312Smav nid_t nid; 1472230312Smav uint8_t csum; 1473230130Smav 1474230130Smav totalchn = AFMT_CHANNEL(ch->fmt); 1475230312Smav totalextchn = AFMT_EXTCHANNEL(ch->fmt); 1476230130Smav HDA_BOOTHVERBOSE( 1477230130Smav device_printf(ch->pdevinfo->dev, 1478230312Smav "PCMDIR_%s: Stream setup fmt=%08x (%d.%d) speed=%d\n", 1479230130Smav (ch->dir == PCMDIR_PLAY) ? "PLAY" : "REC", 1480230312Smav ch->fmt, totalchn - totalextchn, totalextchn, ch->spd); 1481230130Smav ); 1482230130Smav fmt = hdaa_stream_format(ch); 1483230130Smav 1484230312Smav /* Set channels to I/O converters mapping for known speaker setups. */ 1485230130Smav if ((as->pinset == 0x0007 || as->pinset == 0x0013)) /* Standard 5.1 */ 1486230312Smav convmapid = 0; 1487230130Smav else if (as->pinset == 0x0017) /* Standard 7.1 */ 1488230312Smav convmapid = 1; 1489230130Smav 1490230130Smav dfmt = HDA_CMD_SET_DIGITAL_CONV_FMT1_DIGEN; 1491230130Smav if (ch->fmt & AFMT_AC3) 1492230130Smav dfmt |= HDA_CMD_SET_DIGITAL_CONV_FMT1_NAUDIO; 1493230130Smav 1494230130Smav chn = 0; 1495230130Smav for (i = 0; ch->io[i] != -1; i++) { 1496230130Smav w = hdaa_widget_get(ch->devinfo, ch->io[i]); 1497230130Smav if (w == NULL) 1498230130Smav continue; 1499230130Smav 1500230130Smav /* If HP redirection is enabled, but failed to use same 1501230130Smav DAC, make last DAC to duplicate first one. */ 1502230130Smav if (as->fakeredir && i == (as->pincnt - 1)) { 1503230130Smav c = (ch->sid << 4); 1504230130Smav } else { 1505230312Smav /* Map channels to I/O converters, if set. */ 1506230312Smav if (convmapid >= 0) 1507230312Smav chn = (((convmap[convmapid][totalchn / 2] 1508230312Smav >> i * 4) & 0xf) - 1) * 2; 1509230130Smav if (chn < 0 || chn >= totalchn) { 1510230130Smav c = 0; 1511230130Smav } else { 1512230130Smav c = (ch->sid << 4) | chn; 1513230130Smav } 1514230130Smav } 1515230130Smav hda_command(ch->devinfo->dev, 1516230130Smav HDA_CMD_SET_CONV_FMT(0, ch->io[i], fmt)); 1517230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) { 1518230130Smav hda_command(ch->devinfo->dev, 1519230130Smav HDA_CMD_SET_DIGITAL_CONV_FMT1(0, ch->io[i], dfmt)); 1520230130Smav } 1521230130Smav hda_command(ch->devinfo->dev, 1522230130Smav HDA_CMD_SET_CONV_STREAM_CHAN(0, ch->io[i], c)); 1523230326Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_STRIPE(w->param.widget_cap)) { 1524230326Smav hda_command(ch->devinfo->dev, 1525230326Smav HDA_CMD_SET_STRIPE_CONTROL(0, w->nid, ch->stripectl)); 1526230326Smav } 1527230312Smav cchn = HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap); 1528230312Smav if (cchn > 1 && chn < totalchn) { 1529230312Smav cchn = min(cchn, totalchn - chn - 1); 1530230312Smav hda_command(ch->devinfo->dev, 1531230312Smav HDA_CMD_SET_CONV_CHAN_COUNT(0, ch->io[i], cchn)); 1532230312Smav } 1533230312Smav HDA_BOOTHVERBOSE( 1534230312Smav device_printf(ch->pdevinfo->dev, 1535230312Smav "PCMDIR_%s: Stream setup nid=%d: " 1536230312Smav "fmt=0x%04x, dfmt=0x%04x, chan=0x%04x, " 1537230326Smav "chan_count=0x%02x, stripe=%d\n", 1538230312Smav (ch->dir == PCMDIR_PLAY) ? "PLAY" : "REC", 1539230326Smav ch->io[i], fmt, dfmt, c, cchn, ch->stripectl); 1540230312Smav ); 1541230312Smav for (j = 0; j < 16; j++) { 1542230312Smav if (as->dacs[ch->asindex][j] != ch->io[i]) 1543230312Smav continue; 1544230312Smav nid = as->pins[j]; 1545230312Smav wp = hdaa_widget_get(ch->devinfo, nid); 1546230312Smav if (wp == NULL) 1547230312Smav continue; 1548230312Smav if (!HDA_PARAM_PIN_CAP_DP(wp->wclass.pin.cap) && 1549230312Smav !HDA_PARAM_PIN_CAP_HDMI(wp->wclass.pin.cap)) 1550230312Smav continue; 1551230312Smav 1552230312Smav /* Set channel mapping. */ 1553230312Smav for (k = 0; k < 8; k++) { 1554230312Smav hda_command(ch->devinfo->dev, 1555230312Smav HDA_CMD_SET_HDMI_CHAN_SLOT(0, nid, 1556230312Smav (((hdmich[totalextchn == 0 ? 0 : 1][totalchn - 1] 1557230312Smav >> (k * 4)) & 0xf) << 4) | k)); 1558230312Smav } 1559230312Smav 1560230511Smav /* 1561230511Smav * Enable High Bit Rate (HBR) Encoded Packet Type 1562230511Smav * (EPT), if supported and needed (8ch data). 1563230511Smav */ 1564230511Smav if (HDA_PARAM_PIN_CAP_HDMI(wp->wclass.pin.cap) && 1565230511Smav HDA_PARAM_PIN_CAP_HBR(wp->wclass.pin.cap)) { 1566230511Smav wp->wclass.pin.ctrl &= 1567230511Smav ~HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK; 1568230641Smav if ((ch->fmt & AFMT_AC3) && (cchn == 7)) 1569230511Smav wp->wclass.pin.ctrl |= 0x03; 1570230511Smav hda_command(ch->devinfo->dev, 1571230511Smav HDA_CMD_SET_PIN_WIDGET_CTRL(0, nid, 1572230511Smav wp->wclass.pin.ctrl)); 1573230511Smav } 1574230511Smav 1575230312Smav /* Stop audio infoframe transmission. */ 1576230312Smav hda_command(ch->devinfo->dev, 1577230312Smav HDA_CMD_SET_HDMI_DIP_INDEX(0, nid, 0x00)); 1578230312Smav hda_command(ch->devinfo->dev, 1579230312Smav HDA_CMD_SET_HDMI_DIP_XMIT(0, nid, 0x00)); 1580230312Smav 1581230312Smav /* Clear audio infoframe buffer. */ 1582230312Smav hda_command(ch->devinfo->dev, 1583230312Smav HDA_CMD_SET_HDMI_DIP_INDEX(0, nid, 0x00)); 1584230312Smav for (k = 0; k < 32; k++) 1585230312Smav hda_command(ch->devinfo->dev, 1586230312Smav HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x00)); 1587230312Smav 1588230312Smav /* Write HDMI/DisplayPort audio infoframe. */ 1589230312Smav hda_command(ch->devinfo->dev, 1590230312Smav HDA_CMD_SET_HDMI_DIP_INDEX(0, nid, 0x00)); 1591230312Smav if (w->eld != NULL && w->eld_len >= 6 && 1592230312Smav ((w->eld[5] >> 2) & 0x3) == 1) { /* DisplayPort */ 1593230312Smav hda_command(ch->devinfo->dev, 1594230312Smav HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x84)); 1595230312Smav hda_command(ch->devinfo->dev, 1596230312Smav HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x1b)); 1597230312Smav hda_command(ch->devinfo->dev, 1598230312Smav HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x44)); 1599230312Smav } else { /* HDMI */ 1600230312Smav hda_command(ch->devinfo->dev, 1601230312Smav HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x84)); 1602230312Smav hda_command(ch->devinfo->dev, 1603230312Smav HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x01)); 1604230312Smav hda_command(ch->devinfo->dev, 1605230312Smav HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x0a)); 1606230312Smav csum = 0; 1607230312Smav csum -= 0x84 + 0x01 + 0x0a + (totalchn - 1) + 1608230312Smav hdmica[totalextchn == 0 ? 0 : 1][totalchn - 1]; 1609230312Smav hda_command(ch->devinfo->dev, 1610230312Smav HDA_CMD_SET_HDMI_DIP_DATA(0, nid, csum)); 1611230312Smav } 1612230312Smav hda_command(ch->devinfo->dev, 1613230312Smav HDA_CMD_SET_HDMI_DIP_DATA(0, nid, totalchn - 1)); 1614230312Smav hda_command(ch->devinfo->dev, 1615230312Smav HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x00)); 1616230312Smav hda_command(ch->devinfo->dev, 1617230312Smav HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 0x00)); 1618230312Smav hda_command(ch->devinfo->dev, 1619230312Smav HDA_CMD_SET_HDMI_DIP_DATA(0, nid, 1620230312Smav hdmica[totalextchn == 0 ? 0 : 1][totalchn - 1])); 1621230312Smav 1622230312Smav /* Start audio infoframe transmission. */ 1623230312Smav hda_command(ch->devinfo->dev, 1624230312Smav HDA_CMD_SET_HDMI_DIP_INDEX(0, nid, 0x00)); 1625230312Smav hda_command(ch->devinfo->dev, 1626230312Smav HDA_CMD_SET_HDMI_DIP_XMIT(0, nid, 0xc0)); 1627230312Smav } 1628230312Smav chn += cchn + 1; 1629230130Smav } 1630230130Smav} 1631230130Smav 1632230130Smav/* 1633230130Smav * Greatest Common Divisor. 1634230130Smav */ 1635230130Smavstatic unsigned 1636230130Smavgcd(unsigned a, unsigned b) 1637230130Smav{ 1638230130Smav u_int c; 1639230130Smav 1640230130Smav while (b != 0) { 1641230130Smav c = a; 1642230130Smav a = b; 1643230130Smav b = (c % b); 1644230130Smav } 1645230130Smav return (a); 1646230130Smav} 1647230130Smav 1648230130Smav/* 1649230130Smav * Least Common Multiple. 1650230130Smav */ 1651230130Smavstatic unsigned 1652230130Smavlcm(unsigned a, unsigned b) 1653230130Smav{ 1654230130Smav 1655230130Smav return ((a * b) / gcd(a, b)); 1656230130Smav} 1657230130Smav 1658230130Smavstatic int 1659230130Smavhdaa_channel_setfragments(kobj_t obj, void *data, 1660230130Smav uint32_t blksz, uint32_t blkcnt) 1661230130Smav{ 1662230130Smav struct hdaa_chan *ch = data; 1663230130Smav 1664230130Smav blksz -= blksz % lcm(HDA_DMA_ALIGNMENT, sndbuf_getalign(ch->b)); 1665230130Smav 1666230130Smav if (blksz > (sndbuf_getmaxsize(ch->b) / HDA_BDL_MIN)) 1667230130Smav blksz = sndbuf_getmaxsize(ch->b) / HDA_BDL_MIN; 1668230130Smav if (blksz < HDA_BLK_MIN) 1669230130Smav blksz = HDA_BLK_MIN; 1670230130Smav if (blkcnt > HDA_BDL_MAX) 1671230130Smav blkcnt = HDA_BDL_MAX; 1672230130Smav if (blkcnt < HDA_BDL_MIN) 1673230130Smav blkcnt = HDA_BDL_MIN; 1674230130Smav 1675230130Smav while ((blksz * blkcnt) > sndbuf_getmaxsize(ch->b)) { 1676230130Smav if ((blkcnt >> 1) >= HDA_BDL_MIN) 1677230130Smav blkcnt >>= 1; 1678230130Smav else if ((blksz >> 1) >= HDA_BLK_MIN) 1679230130Smav blksz >>= 1; 1680230130Smav else 1681230130Smav break; 1682230130Smav } 1683230130Smav 1684230130Smav if ((sndbuf_getblksz(ch->b) != blksz || 1685230130Smav sndbuf_getblkcnt(ch->b) != blkcnt) && 1686230130Smav sndbuf_resize(ch->b, blkcnt, blksz) != 0) 1687230130Smav device_printf(ch->devinfo->dev, "%s: failed blksz=%u blkcnt=%u\n", 1688230130Smav __func__, blksz, blkcnt); 1689230130Smav 1690230130Smav ch->blksz = sndbuf_getblksz(ch->b); 1691230130Smav ch->blkcnt = sndbuf_getblkcnt(ch->b); 1692230130Smav 1693230130Smav return (0); 1694230130Smav} 1695230130Smav 1696230130Smavstatic uint32_t 1697230130Smavhdaa_channel_setblocksize(kobj_t obj, void *data, uint32_t blksz) 1698230130Smav{ 1699230130Smav struct hdaa_chan *ch = data; 1700230130Smav 1701230130Smav hdaa_channel_setfragments(obj, data, blksz, ch->pdevinfo->chan_blkcnt); 1702230130Smav 1703230130Smav return (ch->blksz); 1704230130Smav} 1705230130Smav 1706230130Smavstatic void 1707230130Smavhdaa_channel_stop(struct hdaa_chan *ch) 1708230130Smav{ 1709230130Smav struct hdaa_devinfo *devinfo = ch->devinfo; 1710230130Smav struct hdaa_widget *w; 1711230130Smav int i; 1712230130Smav 1713230181Smav if ((ch->flags & HDAA_CHN_RUNNING) == 0) 1714230181Smav return; 1715230130Smav ch->flags &= ~HDAA_CHN_RUNNING; 1716230130Smav HDAC_STREAM_STOP(device_get_parent(devinfo->dev), devinfo->dev, 1717230130Smav ch->dir == PCMDIR_PLAY ? 1 : 0, ch->sid); 1718230130Smav for (i = 0; ch->io[i] != -1; i++) { 1719230130Smav w = hdaa_widget_get(ch->devinfo, ch->io[i]); 1720230130Smav if (w == NULL) 1721230130Smav continue; 1722230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) { 1723230130Smav hda_command(devinfo->dev, 1724230130Smav HDA_CMD_SET_DIGITAL_CONV_FMT1(0, ch->io[i], 0)); 1725230130Smav } 1726230130Smav hda_command(devinfo->dev, 1727230130Smav HDA_CMD_SET_CONV_STREAM_CHAN(0, ch->io[i], 1728230130Smav 0)); 1729230130Smav } 1730230130Smav HDAC_STREAM_FREE(device_get_parent(devinfo->dev), devinfo->dev, 1731230130Smav ch->dir == PCMDIR_PLAY ? 1 : 0, ch->sid); 1732230130Smav} 1733230130Smav 1734230130Smavstatic int 1735230130Smavhdaa_channel_start(struct hdaa_chan *ch) 1736230130Smav{ 1737230130Smav struct hdaa_devinfo *devinfo = ch->devinfo; 1738230326Smav uint32_t fmt; 1739230130Smav 1740230326Smav fmt = hdaa_stream_format(ch); 1741230326Smav ch->stripectl = fls(ch->stripecap & hdaa_allowed_stripes(fmt)) - 1; 1742230130Smav ch->sid = HDAC_STREAM_ALLOC(device_get_parent(devinfo->dev), devinfo->dev, 1743230326Smav ch->dir == PCMDIR_PLAY ? 1 : 0, fmt, ch->stripectl, &ch->dmapos); 1744230130Smav if (ch->sid <= 0) 1745230130Smav return (EBUSY); 1746230130Smav hdaa_audio_setup(ch); 1747230130Smav HDAC_STREAM_RESET(device_get_parent(devinfo->dev), devinfo->dev, 1748230130Smav ch->dir == PCMDIR_PLAY ? 1 : 0, ch->sid); 1749230130Smav HDAC_STREAM_START(device_get_parent(devinfo->dev), devinfo->dev, 1750230130Smav ch->dir == PCMDIR_PLAY ? 1 : 0, ch->sid, 1751230130Smav sndbuf_getbufaddr(ch->b), ch->blksz, ch->blkcnt); 1752230130Smav ch->flags |= HDAA_CHN_RUNNING; 1753230130Smav return (0); 1754230130Smav} 1755230130Smav 1756230130Smavstatic int 1757230130Smavhdaa_channel_trigger(kobj_t obj, void *data, int go) 1758230130Smav{ 1759230130Smav struct hdaa_chan *ch = data; 1760230130Smav int error = 0; 1761230130Smav 1762230130Smav if (!PCMTRIG_COMMON(go)) 1763230130Smav return (0); 1764230130Smav 1765230130Smav hdaa_lock(ch->devinfo); 1766230130Smav switch (go) { 1767230130Smav case PCMTRIG_START: 1768230130Smav error = hdaa_channel_start(ch); 1769230130Smav break; 1770230130Smav case PCMTRIG_STOP: 1771230130Smav case PCMTRIG_ABORT: 1772230130Smav hdaa_channel_stop(ch); 1773230130Smav break; 1774230130Smav default: 1775230130Smav break; 1776230130Smav } 1777230130Smav hdaa_unlock(ch->devinfo); 1778230130Smav 1779230130Smav return (error); 1780230130Smav} 1781230130Smav 1782230130Smavstatic uint32_t 1783230130Smavhdaa_channel_getptr(kobj_t obj, void *data) 1784230130Smav{ 1785230130Smav struct hdaa_chan *ch = data; 1786230130Smav struct hdaa_devinfo *devinfo = ch->devinfo; 1787230130Smav uint32_t ptr; 1788230130Smav 1789230130Smav hdaa_lock(devinfo); 1790230130Smav if (ch->dmapos != NULL) { 1791230130Smav ptr = *(ch->dmapos); 1792230130Smav } else { 1793230130Smav ptr = HDAC_STREAM_GETPTR( 1794230130Smav device_get_parent(devinfo->dev), devinfo->dev, 1795230130Smav ch->dir == PCMDIR_PLAY ? 1 : 0, ch->sid); 1796230130Smav } 1797230130Smav hdaa_unlock(devinfo); 1798230130Smav 1799230130Smav /* 1800230130Smav * Round to available space and force 128 bytes aligment. 1801230130Smav */ 1802230130Smav ptr %= ch->blksz * ch->blkcnt; 1803230130Smav ptr &= HDA_BLK_ALIGN; 1804230130Smav 1805230130Smav return (ptr); 1806230130Smav} 1807230130Smav 1808230130Smavstatic struct pcmchan_caps * 1809230130Smavhdaa_channel_getcaps(kobj_t obj, void *data) 1810230130Smav{ 1811230130Smav return (&((struct hdaa_chan *)data)->caps); 1812230130Smav} 1813230130Smav 1814230130Smavstatic kobj_method_t hdaa_channel_methods[] = { 1815230130Smav KOBJMETHOD(channel_init, hdaa_channel_init), 1816230130Smav KOBJMETHOD(channel_setformat, hdaa_channel_setformat), 1817230130Smav KOBJMETHOD(channel_setspeed, hdaa_channel_setspeed), 1818230130Smav KOBJMETHOD(channel_setblocksize, hdaa_channel_setblocksize), 1819230130Smav KOBJMETHOD(channel_setfragments, hdaa_channel_setfragments), 1820230130Smav KOBJMETHOD(channel_trigger, hdaa_channel_trigger), 1821230130Smav KOBJMETHOD(channel_getptr, hdaa_channel_getptr), 1822230130Smav KOBJMETHOD(channel_getcaps, hdaa_channel_getcaps), 1823230130Smav KOBJMETHOD_END 1824230130Smav}; 1825230130SmavCHANNEL_DECLARE(hdaa_channel); 1826230130Smav 1827230130Smavstatic int 1828230130Smavhdaa_audio_ctl_ossmixer_init(struct snd_mixer *m) 1829230130Smav{ 1830230130Smav struct hdaa_pcm_devinfo *pdevinfo = mix_getdevinfo(m); 1831230130Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 1832230130Smav struct hdaa_widget *w, *cw; 1833230130Smav uint32_t mask, recmask; 1834230451Smav int i, j; 1835230130Smav 1836230130Smav hdaa_lock(devinfo); 1837230451Smav pdevinfo->mixer = m; 1838230130Smav 1839230130Smav /* Make sure that in case of soft volume it won't stay muted. */ 1840230130Smav for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) { 1841230130Smav pdevinfo->left[i] = 100; 1842230130Smav pdevinfo->right[i] = 100; 1843230130Smav } 1844230130Smav 1845230451Smav /* Declare volume controls assigned to this association. */ 1846230451Smav mask = pdevinfo->ossmask; 1847230130Smav if (pdevinfo->playas >= 0) { 1848230451Smav /* Declate EAPD as ogain control. */ 1849230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 1850230130Smav w = hdaa_widget_get(devinfo, i); 1851230130Smav if (w == NULL || w->enable == 0) 1852230130Smav continue; 1853230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX || 1854230130Smav w->param.eapdbtl == HDA_INVALID || 1855230130Smav w->bindas != pdevinfo->playas) 1856230130Smav continue; 1857230130Smav mask |= SOUND_MASK_OGAIN; 1858230130Smav break; 1859230130Smav } 1860230130Smav 1861230451Smav /* Declare soft PCM volume if needed. */ 1862230451Smav if ((mask & SOUND_MASK_PCM) == 0 || 1863230451Smav (devinfo->quirks & HDAA_QUIRK_SOFTPCMVOL) || 1864230451Smav pdevinfo->minamp[SOUND_MIXER_PCM] == 1865230451Smav pdevinfo->maxamp[SOUND_MIXER_PCM]) { 1866230451Smav mask |= SOUND_MASK_PCM; 1867230451Smav pcm_setflags(pdevinfo->dev, pcm_getflags(pdevinfo->dev) | SD_F_SOFTPCMVOL); 1868230451Smav HDA_BOOTHVERBOSE( 1869230451Smav device_printf(pdevinfo->dev, 1870230451Smav "Forcing Soft PCM volume\n"); 1871230451Smav ); 1872230451Smav } 1873230451Smav 1874230451Smav /* Declare master volume if needed. */ 1875230451Smav if ((mask & SOUND_MASK_VOLUME) == 0) { 1876230451Smav mask |= SOUND_MASK_VOLUME; 1877230451Smav mix_setparentchild(m, SOUND_MIXER_VOLUME, 1878230451Smav SOUND_MASK_PCM); 1879230451Smav mix_setrealdev(m, SOUND_MIXER_VOLUME, 1880230451Smav SOUND_MIXER_NONE); 1881230451Smav HDA_BOOTHVERBOSE( 1882230451Smav device_printf(pdevinfo->dev, 1883230451Smav "Forcing master volume with PCM\n"); 1884230451Smav ); 1885230451Smav } 1886230130Smav } 1887230130Smav 1888230130Smav /* Declare record sources available to this association. */ 1889230451Smav recmask = 0; 1890230130Smav if (pdevinfo->recas >= 0) { 1891230130Smav for (i = 0; i < 16; i++) { 1892230130Smav if (devinfo->as[pdevinfo->recas].dacs[0][i] < 0) 1893230130Smav continue; 1894230130Smav w = hdaa_widget_get(devinfo, 1895230130Smav devinfo->as[pdevinfo->recas].dacs[0][i]); 1896230130Smav if (w == NULL || w->enable == 0) 1897230130Smav continue; 1898230130Smav for (j = 0; j < w->nconns; j++) { 1899230130Smav if (w->connsenable[j] == 0) 1900230130Smav continue; 1901230130Smav cw = hdaa_widget_get(devinfo, w->conns[j]); 1902230130Smav if (cw == NULL || cw->enable == 0) 1903230130Smav continue; 1904230130Smav if (cw->bindas != pdevinfo->recas && 1905230130Smav cw->bindas != -2) 1906230130Smav continue; 1907230130Smav recmask |= cw->ossmask; 1908230130Smav } 1909230130Smav } 1910230130Smav } 1911230130Smav 1912230451Smav recmask &= (1 << SOUND_MIXER_NRDEVICES) - 1; 1913230451Smav mask &= (1 << SOUND_MIXER_NRDEVICES) - 1; 1914230451Smav pdevinfo->ossmask = mask; 1915230451Smav 1916230451Smav mix_setrecdevs(m, recmask); 1917230451Smav mix_setdevs(m, mask); 1918230451Smav 1919230451Smav hdaa_unlock(devinfo); 1920230451Smav 1921230451Smav return (0); 1922230451Smav} 1923230451Smav 1924230451Smav/* 1925230451Smav * Update amplification per pdevinfo per ossdev, calculate summary coefficient 1926230451Smav * and write it to codec, update *left and *right to reflect remaining error. 1927230451Smav */ 1928230451Smavstatic void 1929230451Smavhdaa_audio_ctl_dev_set(struct hdaa_audio_ctl *ctl, int ossdev, 1930230451Smav int mute, int *left, int *right) 1931230451Smav{ 1932230451Smav int i, zleft, zright, sleft, sright, smute, lval, rval; 1933230451Smav 1934230451Smav ctl->devleft[ossdev] = *left; 1935230451Smav ctl->devright[ossdev] = *right; 1936230451Smav ctl->devmute[ossdev] = mute; 1937230451Smav smute = sleft = sright = zleft = zright = 0; 1938230451Smav for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) { 1939230451Smav sleft += ctl->devleft[i]; 1940230451Smav sright += ctl->devright[i]; 1941230451Smav smute |= ctl->devmute[i]; 1942230451Smav if (i == ossdev) 1943230451Smav continue; 1944230451Smav zleft += ctl->devleft[i]; 1945230451Smav zright += ctl->devright[i]; 1946230451Smav } 1947230451Smav lval = QDB2VAL(ctl, sleft); 1948230451Smav rval = QDB2VAL(ctl, sright); 1949230451Smav hdaa_audio_ctl_amp_set(ctl, smute, lval, rval); 1950230451Smav *left -= VAL2QDB(ctl, lval) - VAL2QDB(ctl, QDB2VAL(ctl, zleft)); 1951230451Smav *right -= VAL2QDB(ctl, rval) - VAL2QDB(ctl, QDB2VAL(ctl, zright)); 1952230451Smav} 1953230451Smav 1954230451Smav/* 1955230451Smav * Trace signal from source, setting volumes on the way. 1956230451Smav */ 1957230451Smavstatic void 1958230451Smavhdaa_audio_ctl_source_volume(struct hdaa_pcm_devinfo *pdevinfo, 1959230451Smav int ossdev, nid_t nid, int index, int mute, int left, int right, int depth) 1960230451Smav{ 1961230451Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 1962230451Smav struct hdaa_widget *w, *wc; 1963230451Smav struct hdaa_audio_ctl *ctl; 1964230451Smav int i, j, conns = 0; 1965230451Smav 1966230451Smav if (depth > HDA_PARSE_MAXDEPTH) 1967230451Smav return; 1968230451Smav 1969230451Smav w = hdaa_widget_get(devinfo, nid); 1970230451Smav if (w == NULL || w->enable == 0) 1971230451Smav return; 1972230451Smav 1973230451Smav /* Count number of active inputs. */ 1974230451Smav if (depth > 0) { 1975230451Smav for (j = 0; j < w->nconns; j++) { 1976230451Smav if (!w->connsenable[j]) 1977230451Smav continue; 1978230451Smav conns++; 1979230130Smav } 1980230451Smav } 1981230130Smav 1982230451Smav /* If this is not a first step - use input mixer. 1983230451Smav Pins have common input ctl so care must be taken. */ 1984230451Smav if (depth > 0 && (conns == 1 || 1985230451Smav w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)) { 1986230451Smav ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, HDAA_CTL_IN, 1987230451Smav index, 1); 1988230451Smav if (ctl) 1989230451Smav hdaa_audio_ctl_dev_set(ctl, ossdev, mute, &left, &right); 1990230451Smav } 1991230451Smav 1992230451Smav /* If widget has own ossdev - not traverse it. 1993230451Smav It will be traversed on it's own. */ 1994230451Smav if (w->ossdev >= 0 && depth > 0) 1995230451Smav return; 1996230451Smav 1997230451Smav /* We must not traverse pin */ 1998230451Smav if ((w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT || 1999230451Smav w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) && 2000230451Smav depth > 0) 2001230451Smav return; 2002230451Smav 2003230451Smav /* 2004230451Smav * If signals mixed, we can't assign controls farther. 2005230451Smav * Ignore this on depth zero. Caller must knows why. 2006230451Smav */ 2007230451Smav if (conns > 1 && 2008230451Smav (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER || 2009230451Smav w->selconn != index)) 2010230451Smav return; 2011230451Smav 2012230451Smav ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, HDAA_CTL_OUT, -1, 1); 2013230451Smav if (ctl) 2014230451Smav hdaa_audio_ctl_dev_set(ctl, ossdev, mute, &left, &right); 2015230451Smav 2016230451Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 2017230451Smav wc = hdaa_widget_get(devinfo, i); 2018230451Smav if (wc == NULL || wc->enable == 0) 2019230451Smav continue; 2020230451Smav for (j = 0; j < wc->nconns; j++) { 2021230451Smav if (wc->connsenable[j] && wc->conns[j] == nid) { 2022230451Smav hdaa_audio_ctl_source_volume(pdevinfo, ossdev, 2023230451Smav wc->nid, j, mute, left, right, depth + 1); 2024230451Smav } 2025230130Smav } 2026230130Smav } 2027230451Smav return; 2028230451Smav} 2029230130Smav 2030230451Smav/* 2031230451Smav * Trace signal from destination, setting volumes on the way. 2032230451Smav */ 2033230451Smavstatic void 2034230451Smavhdaa_audio_ctl_dest_volume(struct hdaa_pcm_devinfo *pdevinfo, 2035230451Smav int ossdev, nid_t nid, int index, int mute, int left, int right, int depth) 2036230451Smav{ 2037230451Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 2038230451Smav struct hdaa_audio_as *as = devinfo->as; 2039230451Smav struct hdaa_widget *w, *wc; 2040230451Smav struct hdaa_audio_ctl *ctl; 2041230451Smav int i, j, consumers, cleft, cright; 2042230451Smav 2043230451Smav if (depth > HDA_PARSE_MAXDEPTH) 2044230451Smav return; 2045230451Smav 2046230451Smav w = hdaa_widget_get(devinfo, nid); 2047230451Smav if (w == NULL || w->enable == 0) 2048230451Smav return; 2049230451Smav 2050230451Smav if (depth > 0) { 2051230451Smav /* If this node produce output for several consumers, 2052230451Smav we can't touch it. */ 2053230451Smav consumers = 0; 2054230451Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 2055230451Smav wc = hdaa_widget_get(devinfo, i); 2056230451Smav if (wc == NULL || wc->enable == 0) 2057230451Smav continue; 2058230451Smav for (j = 0; j < wc->nconns; j++) { 2059230451Smav if (wc->connsenable[j] && wc->conns[j] == nid) 2060230451Smav consumers++; 2061230451Smav } 2062230130Smav } 2063230451Smav /* The only exception is if real HP redirection is configured 2064230451Smav and this is a duplication point. 2065230451Smav XXX: Actually exception is not completely correct. 2066230451Smav XXX: Duplication point check is not perfect. */ 2067230451Smav if ((consumers == 2 && (w->bindas < 0 || 2068230451Smav as[w->bindas].hpredir < 0 || as[w->bindas].fakeredir || 2069230451Smav (w->bindseqmask & (1 << 15)) == 0)) || 2070230451Smav consumers > 2) 2071230451Smav return; 2072230451Smav 2073230451Smav /* Else use it's output mixer. */ 2074230451Smav ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, 2075230451Smav HDAA_CTL_OUT, -1, 1); 2076230451Smav if (ctl) 2077230451Smav hdaa_audio_ctl_dev_set(ctl, ossdev, mute, &left, &right); 2078230130Smav } 2079230130Smav 2080230451Smav /* We must not traverse pin */ 2081230451Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX && 2082230451Smav depth > 0) 2083230451Smav return; 2084230130Smav 2085230451Smav for (i = 0; i < w->nconns; i++) { 2086230451Smav if (w->connsenable[i] == 0) 2087230451Smav continue; 2088230451Smav if (index >= 0 && i != index) 2089230451Smav continue; 2090230451Smav cleft = left; 2091230451Smav cright = right; 2092230451Smav ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, 2093230451Smav HDAA_CTL_IN, i, 1); 2094230451Smav if (ctl) 2095230451Smav hdaa_audio_ctl_dev_set(ctl, ossdev, mute, &cleft, &cright); 2096230451Smav hdaa_audio_ctl_dest_volume(pdevinfo, ossdev, w->conns[i], -1, 2097230451Smav mute, cleft, cright, depth + 1); 2098230451Smav } 2099230451Smav} 2100230130Smav 2101230451Smav/* 2102230451Smav * Set volumes for the specified pdevinfo and ossdev. 2103230451Smav */ 2104230451Smavstatic void 2105230451Smavhdaa_audio_ctl_dev_volume(struct hdaa_pcm_devinfo *pdevinfo, unsigned dev) 2106230451Smav{ 2107230451Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 2108230451Smav struct hdaa_widget *w, *cw; 2109230451Smav uint32_t mute; 2110230451Smav int lvol, rvol; 2111230451Smav int i, j; 2112230130Smav 2113230451Smav mute = 0; 2114230451Smav if (pdevinfo->left[dev] == 0) { 2115230451Smav mute |= HDAA_AMP_MUTE_LEFT; 2116230451Smav lvol = -4000; 2117230451Smav } else 2118230451Smav lvol = ((pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]) * 2119230451Smav pdevinfo->left[dev] + 50) / 100 + pdevinfo->minamp[dev]; 2120230451Smav if (pdevinfo->right[dev] == 0) { 2121230451Smav mute |= HDAA_AMP_MUTE_RIGHT; 2122230451Smav rvol = -4000; 2123230451Smav } else 2124230451Smav rvol = ((pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]) * 2125230451Smav pdevinfo->right[dev] + 50) / 100 + pdevinfo->minamp[dev]; 2126230451Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 2127230451Smav w = hdaa_widget_get(devinfo, i); 2128230451Smav if (w == NULL || w->enable == 0) 2129230451Smav continue; 2130239326Smav if (w->bindas < 0) { 2131239326Smav if (pdevinfo->index != 0) 2132239326Smav continue; 2133239326Smav } else { 2134239326Smav if (w->bindas != pdevinfo->playas && 2135239326Smav w->bindas != pdevinfo->recas) 2136239326Smav continue; 2137239326Smav } 2138230451Smav if (dev == SOUND_MIXER_RECLEV && 2139230451Smav w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) { 2140230451Smav hdaa_audio_ctl_dest_volume(pdevinfo, dev, 2141230451Smav w->nid, -1, mute, lvol, rvol, 0); 2142230451Smav continue; 2143230451Smav } 2144230451Smav if (dev == SOUND_MIXER_VOLUME && 2145230451Smav w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX && 2146230451Smav devinfo->as[w->bindas].dir == HDAA_CTL_OUT) { 2147230451Smav hdaa_audio_ctl_dest_volume(pdevinfo, dev, 2148230451Smav w->nid, -1, mute, lvol, rvol, 0); 2149230451Smav continue; 2150230451Smav } 2151230451Smav if (dev == SOUND_MIXER_IGAIN && 2152230451Smav w->pflags & HDAA_ADC_MONITOR) { 2153230451Smav for (j = 0; j < w->nconns; j++) { 2154230451Smav if (!w->connsenable[j]) 2155230451Smav continue; 2156230451Smav cw = hdaa_widget_get(devinfo, w->conns[j]); 2157230451Smav if (cw == NULL || cw->enable == 0) 2158230451Smav continue; 2159230451Smav if (cw->bindas == -1) 2160230451Smav continue; 2161230451Smav if (cw->bindas >= 0 && 2162230451Smav devinfo->as[cw->bindas].dir != HDAA_CTL_IN) 2163230451Smav continue; 2164230451Smav hdaa_audio_ctl_dest_volume(pdevinfo, dev, 2165230451Smav w->nid, j, mute, lvol, rvol, 0); 2166230451Smav } 2167230451Smav continue; 2168230451Smav } 2169230451Smav if (w->ossdev != dev) 2170230451Smav continue; 2171230451Smav hdaa_audio_ctl_source_volume(pdevinfo, dev, 2172230451Smav w->nid, -1, mute, lvol, rvol, 0); 2173230451Smav if (dev == SOUND_MIXER_IMIX && (w->pflags & HDAA_IMIX_AS_DST)) 2174230451Smav hdaa_audio_ctl_dest_volume(pdevinfo, dev, 2175230451Smav w->nid, -1, mute, lvol, rvol, 0); 2176230451Smav } 2177230130Smav} 2178230130Smav 2179230451Smav/* 2180230451Smav * OSS Mixer set method. 2181230451Smav */ 2182230130Smavstatic int 2183230130Smavhdaa_audio_ctl_ossmixer_set(struct snd_mixer *m, unsigned dev, 2184230130Smav unsigned left, unsigned right) 2185230130Smav{ 2186230130Smav struct hdaa_pcm_devinfo *pdevinfo = mix_getdevinfo(m); 2187230130Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 2188230130Smav struct hdaa_widget *w; 2189230451Smav int i; 2190230130Smav 2191230130Smav hdaa_lock(devinfo); 2192230451Smav 2193230130Smav /* Save new values. */ 2194230130Smav pdevinfo->left[dev] = left; 2195230130Smav pdevinfo->right[dev] = right; 2196230130Smav 2197230130Smav /* 'ogain' is the special case implemented with EAPD. */ 2198230130Smav if (dev == SOUND_MIXER_OGAIN) { 2199230130Smav uint32_t orig; 2200230130Smav w = NULL; 2201230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 2202230130Smav w = hdaa_widget_get(devinfo, i); 2203230130Smav if (w == NULL || w->enable == 0) 2204230130Smav continue; 2205230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX || 2206230130Smav w->param.eapdbtl == HDA_INVALID) 2207230130Smav continue; 2208230130Smav break; 2209230130Smav } 2210230130Smav if (i >= devinfo->endnode) { 2211230130Smav hdaa_unlock(devinfo); 2212230130Smav return (-1); 2213230130Smav } 2214230130Smav orig = w->param.eapdbtl; 2215230130Smav if (left == 0) 2216230130Smav w->param.eapdbtl &= ~HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD; 2217230130Smav else 2218230130Smav w->param.eapdbtl |= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD; 2219230130Smav if (orig != w->param.eapdbtl) { 2220230130Smav uint32_t val; 2221230130Smav 2222230130Smav val = w->param.eapdbtl; 2223230130Smav if (devinfo->quirks & HDAA_QUIRK_EAPDINV) 2224230130Smav val ^= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD; 2225230130Smav hda_command(devinfo->dev, 2226230130Smav HDA_CMD_SET_EAPD_BTL_ENABLE(0, w->nid, val)); 2227230130Smav } 2228230130Smav hdaa_unlock(devinfo); 2229230130Smav return (left | (left << 8)); 2230230130Smav } 2231230130Smav 2232230130Smav /* Recalculate all controls related to this OSS device. */ 2233230451Smav hdaa_audio_ctl_dev_volume(pdevinfo, dev); 2234230451Smav 2235230451Smav hdaa_unlock(devinfo); 2236230451Smav return (left | (right << 8)); 2237230451Smav} 2238230451Smav 2239230451Smav/* 2240230451Smav * Set mixer settings to our own default values: 2241230451Smav * +20dB for mics, -10dB for analog vol, mute for igain, 0dB for others. 2242230451Smav */ 2243230451Smavstatic void 2244230451Smavhdaa_audio_ctl_set_defaults(struct hdaa_pcm_devinfo *pdevinfo) 2245230451Smav{ 2246230451Smav int amp, vol, dev; 2247230451Smav 2248230451Smav for (dev = 0; dev < SOUND_MIXER_NRDEVICES; dev++) { 2249230451Smav if ((pdevinfo->ossmask & (1 << dev)) == 0) 2250230130Smav continue; 2251230451Smav 2252230451Smav /* If the value was overriden, leave it as is. */ 2253230451Smav if (resource_int_value(device_get_name(pdevinfo->dev), 2254230451Smav device_get_unit(pdevinfo->dev), ossnames[dev], &vol) == 0) 2255230130Smav continue; 2256230130Smav 2257230451Smav vol = -1; 2258230451Smav if (dev == SOUND_MIXER_OGAIN) 2259230451Smav vol = 100; 2260230451Smav else if (dev == SOUND_MIXER_IGAIN) 2261230451Smav vol = 0; 2262230451Smav else if (dev == SOUND_MIXER_MIC || 2263230451Smav dev == SOUND_MIXER_MONITOR) 2264230451Smav amp = 20 * 4; /* +20dB */ 2265230451Smav else if (dev == SOUND_MIXER_VOLUME && !pdevinfo->digital) 2266230451Smav amp = -10 * 4; /* -10dB */ 2267230451Smav else 2268230451Smav amp = 0; 2269230451Smav if (vol < 0 && 2270230451Smav (pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]) <= 0) { 2271230451Smav vol = 100; 2272230451Smav } else if (vol < 0) { 2273230451Smav vol = ((amp - pdevinfo->minamp[dev]) * 100 + 2274230451Smav (pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]) / 2) / 2275230451Smav (pdevinfo->maxamp[dev] - pdevinfo->minamp[dev]); 2276230451Smav vol = imin(imax(vol, 1), 100); 2277230130Smav } 2278230451Smav mix_set(pdevinfo->mixer, dev, vol, vol); 2279230130Smav } 2280230130Smav} 2281230130Smav 2282230130Smav/* 2283230451Smav * Recursively commutate specified record source. 2284230130Smav */ 2285230130Smavstatic uint32_t 2286230130Smavhdaa_audio_ctl_recsel_comm(struct hdaa_pcm_devinfo *pdevinfo, uint32_t src, nid_t nid, int depth) 2287230130Smav{ 2288230130Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 2289230130Smav struct hdaa_widget *w, *cw; 2290230130Smav struct hdaa_audio_ctl *ctl; 2291230130Smav char buf[64]; 2292230130Smav int i, muted; 2293230130Smav uint32_t res = 0; 2294230130Smav 2295230130Smav if (depth > HDA_PARSE_MAXDEPTH) 2296230130Smav return (0); 2297230130Smav 2298230130Smav w = hdaa_widget_get(devinfo, nid); 2299230130Smav if (w == NULL || w->enable == 0) 2300230130Smav return (0); 2301230130Smav 2302230130Smav for (i = 0; i < w->nconns; i++) { 2303230130Smav if (w->connsenable[i] == 0) 2304230130Smav continue; 2305230130Smav cw = hdaa_widget_get(devinfo, w->conns[i]); 2306230130Smav if (cw == NULL || cw->enable == 0 || cw->bindas == -1) 2307230130Smav continue; 2308230130Smav /* Call recursively to trace signal to it's source if needed. */ 2309230130Smav if ((src & cw->ossmask) != 0) { 2310230130Smav if (cw->ossdev < 0) { 2311230130Smav res |= hdaa_audio_ctl_recsel_comm(pdevinfo, src, 2312230130Smav w->conns[i], depth + 1); 2313230130Smav } else { 2314230130Smav res |= cw->ossmask; 2315230130Smav } 2316230130Smav } 2317230130Smav /* We have two special cases: mixers and others (selectors). */ 2318230130Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) { 2319230130Smav ctl = hdaa_audio_ctl_amp_get(devinfo, 2320230130Smav w->nid, HDAA_CTL_IN, i, 1); 2321230130Smav if (ctl == NULL) 2322230130Smav continue; 2323230130Smav /* If we have input control on this node mute them 2324230130Smav * according to requested sources. */ 2325230130Smav muted = (src & cw->ossmask) ? 0 : 1; 2326230130Smav if (muted != ctl->forcemute) { 2327230130Smav ctl->forcemute = muted; 2328230130Smav hdaa_audio_ctl_amp_set(ctl, 2329230130Smav HDAA_AMP_MUTE_DEFAULT, 2330230130Smav HDAA_AMP_VOL_DEFAULT, HDAA_AMP_VOL_DEFAULT); 2331230130Smav } 2332230130Smav HDA_BOOTHVERBOSE( 2333230130Smav device_printf(pdevinfo->dev, 2334230130Smav "Recsel (%s): nid %d source %d %s\n", 2335230130Smav hdaa_audio_ctl_ossmixer_mask2allname( 2336230130Smav src, buf, sizeof(buf)), 2337230130Smav nid, i, muted?"mute":"unmute"); 2338230130Smav ); 2339230130Smav } else { 2340230130Smav if (w->nconns == 1) 2341230130Smav break; 2342230130Smav if ((src & cw->ossmask) == 0) 2343230130Smav continue; 2344230130Smav /* If we found requested source - select it and exit. */ 2345230130Smav hdaa_widget_connection_select(w, i); 2346230130Smav HDA_BOOTHVERBOSE( 2347230130Smav device_printf(pdevinfo->dev, 2348230130Smav "Recsel (%s): nid %d source %d select\n", 2349230130Smav hdaa_audio_ctl_ossmixer_mask2allname( 2350230130Smav src, buf, sizeof(buf)), 2351230130Smav nid, i); 2352230130Smav ); 2353230130Smav break; 2354230130Smav } 2355230130Smav } 2356230130Smav return (res); 2357230130Smav} 2358230130Smav 2359230130Smavstatic uint32_t 2360230130Smavhdaa_audio_ctl_ossmixer_setrecsrc(struct snd_mixer *m, uint32_t src) 2361230130Smav{ 2362230130Smav struct hdaa_pcm_devinfo *pdevinfo = mix_getdevinfo(m); 2363230130Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 2364230130Smav struct hdaa_widget *w; 2365230130Smav struct hdaa_audio_as *as; 2366230451Smav struct hdaa_audio_ctl *ctl; 2367230130Smav struct hdaa_chan *ch; 2368230130Smav int i, j; 2369230130Smav uint32_t ret = 0xffffffff; 2370230130Smav 2371230130Smav hdaa_lock(devinfo); 2372230130Smav if (pdevinfo->recas < 0) { 2373230130Smav hdaa_unlock(devinfo); 2374230130Smav return (0); 2375230130Smav } 2376230130Smav as = &devinfo->as[pdevinfo->recas]; 2377230130Smav 2378230130Smav /* For non-mixed associations we always recording everything. */ 2379230130Smav if (!as->mixed) { 2380230130Smav hdaa_unlock(devinfo); 2381230130Smav return (mix_getrecdevs(m)); 2382230130Smav } 2383230130Smav 2384230130Smav /* Commutate requested recsrc for each ADC. */ 2385230130Smav for (j = 0; j < as->num_chans; j++) { 2386230130Smav ch = &devinfo->chans[as->chans[j]]; 2387230130Smav for (i = 0; ch->io[i] >= 0; i++) { 2388230130Smav w = hdaa_widget_get(devinfo, ch->io[i]); 2389230130Smav if (w == NULL || w->enable == 0) 2390230130Smav continue; 2391230130Smav ret &= hdaa_audio_ctl_recsel_comm(pdevinfo, src, 2392230130Smav ch->io[i], 0); 2393230130Smav } 2394230130Smav } 2395230451Smav if (ret == 0xffffffff) 2396230451Smav ret = 0; 2397230130Smav 2398230451Smav /* 2399230451Smav * Some controls could be shared. Reset volumes for controls 2400230451Smav * related to previously chosen devices, as they may no longer 2401230451Smav * affect the signal. 2402230451Smav */ 2403230451Smav i = 0; 2404230451Smav while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) { 2405230451Smav if (ctl->enable == 0 || 2406230451Smav !(ctl->ossmask & pdevinfo->recsrc)) 2407230451Smav continue; 2408230451Smav if (!((pdevinfo->playas >= 0 && 2409230451Smav ctl->widget->bindas == pdevinfo->playas) || 2410230451Smav (pdevinfo->recas >= 0 && 2411230451Smav ctl->widget->bindas == pdevinfo->recas) || 2412230451Smav (pdevinfo->index == 0 && 2413230451Smav ctl->widget->bindas == -2))) 2414230451Smav continue; 2415230451Smav for (j = 0; j < SOUND_MIXER_NRDEVICES; j++) { 2416230451Smav if (pdevinfo->recsrc & (1 << j)) { 2417230451Smav ctl->devleft[j] = 0; 2418230451Smav ctl->devright[j] = 0; 2419230451Smav ctl->devmute[j] = 0; 2420230451Smav } 2421230451Smav } 2422230451Smav } 2423230451Smav 2424230451Smav /* 2425230451Smav * Some controls could be shared. Set volumes for controls 2426230451Smav * related to devices selected both previously and now. 2427230451Smav */ 2428230451Smav for (j = 0; j < SOUND_MIXER_NRDEVICES; j++) { 2429230451Smav if ((ret | pdevinfo->recsrc) & (1 << j)) 2430230451Smav hdaa_audio_ctl_dev_volume(pdevinfo, j); 2431230451Smav } 2432230451Smav 2433230451Smav pdevinfo->recsrc = ret; 2434230130Smav hdaa_unlock(devinfo); 2435230451Smav return (ret); 2436230130Smav} 2437230130Smav 2438230130Smavstatic kobj_method_t hdaa_audio_ctl_ossmixer_methods[] = { 2439230130Smav KOBJMETHOD(mixer_init, hdaa_audio_ctl_ossmixer_init), 2440230130Smav KOBJMETHOD(mixer_set, hdaa_audio_ctl_ossmixer_set), 2441230130Smav KOBJMETHOD(mixer_setrecsrc, hdaa_audio_ctl_ossmixer_setrecsrc), 2442230130Smav KOBJMETHOD_END 2443230130Smav}; 2444230130SmavMIXER_DECLARE(hdaa_audio_ctl_ossmixer); 2445230130Smav 2446230130Smavstatic void 2447230130Smavhdaa_dump_gpi(struct hdaa_devinfo *devinfo) 2448230130Smav{ 2449230130Smav device_t dev = devinfo->dev; 2450230130Smav int i; 2451230130Smav uint32_t data, wake, unsol, sticky; 2452230130Smav 2453230130Smav if (HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap) > 0) { 2454230130Smav data = hda_command(dev, 2455230130Smav HDA_CMD_GET_GPI_DATA(0, devinfo->nid)); 2456230130Smav wake = hda_command(dev, 2457230130Smav HDA_CMD_GET_GPI_WAKE_ENABLE_MASK(0, devinfo->nid)); 2458230130Smav unsol = hda_command(dev, 2459230130Smav HDA_CMD_GET_GPI_UNSOLICITED_ENABLE_MASK(0, devinfo->nid)); 2460230130Smav sticky = hda_command(dev, 2461230130Smav HDA_CMD_GET_GPI_STICKY_MASK(0, devinfo->nid)); 2462230130Smav for (i = 0; i < HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap); i++) { 2463230130Smav device_printf(dev, " GPI%d:%s%s%s state=%d", i, 2464230130Smav (sticky & (1 << i)) ? " sticky" : "", 2465230130Smav (unsol & (1 << i)) ? " unsol" : "", 2466230130Smav (wake & (1 << i)) ? " wake" : "", 2467230130Smav (data >> i) & 1); 2468230130Smav } 2469230130Smav } 2470230130Smav} 2471230130Smav 2472230130Smavstatic void 2473230130Smavhdaa_dump_gpio(struct hdaa_devinfo *devinfo) 2474230130Smav{ 2475230130Smav device_t dev = devinfo->dev; 2476230130Smav int i; 2477230130Smav uint32_t data, dir, enable, wake, unsol, sticky; 2478230130Smav 2479230130Smav if (HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap) > 0) { 2480230130Smav data = hda_command(dev, 2481230130Smav HDA_CMD_GET_GPIO_DATA(0, devinfo->nid)); 2482230130Smav enable = hda_command(dev, 2483230130Smav HDA_CMD_GET_GPIO_ENABLE_MASK(0, devinfo->nid)); 2484230130Smav dir = hda_command(dev, 2485230130Smav HDA_CMD_GET_GPIO_DIRECTION(0, devinfo->nid)); 2486230130Smav wake = hda_command(dev, 2487230130Smav HDA_CMD_GET_GPIO_WAKE_ENABLE_MASK(0, devinfo->nid)); 2488230130Smav unsol = hda_command(dev, 2489230130Smav HDA_CMD_GET_GPIO_UNSOLICITED_ENABLE_MASK(0, devinfo->nid)); 2490230130Smav sticky = hda_command(dev, 2491230130Smav HDA_CMD_GET_GPIO_STICKY_MASK(0, devinfo->nid)); 2492230130Smav for (i = 0; i < HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap); i++) { 2493230130Smav device_printf(dev, " GPIO%d: ", i); 2494230130Smav if ((enable & (1 << i)) == 0) { 2495230130Smav printf("disabled\n"); 2496230130Smav continue; 2497230130Smav } 2498230130Smav if ((dir & (1 << i)) == 0) { 2499230130Smav printf("input%s%s%s", 2500230130Smav (sticky & (1 << i)) ? " sticky" : "", 2501230130Smav (unsol & (1 << i)) ? " unsol" : "", 2502230130Smav (wake & (1 << i)) ? " wake" : ""); 2503230130Smav } else 2504230130Smav printf("output"); 2505230130Smav printf(" state=%d\n", (data >> i) & 1); 2506230130Smav } 2507230130Smav } 2508230130Smav} 2509230130Smav 2510230130Smavstatic void 2511230130Smavhdaa_dump_gpo(struct hdaa_devinfo *devinfo) 2512230130Smav{ 2513230130Smav device_t dev = devinfo->dev; 2514230130Smav int i; 2515230130Smav uint32_t data; 2516230130Smav 2517230130Smav if (HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap) > 0) { 2518230130Smav data = hda_command(dev, 2519230130Smav HDA_CMD_GET_GPO_DATA(0, devinfo->nid)); 2520230130Smav for (i = 0; i < HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap); i++) { 2521230130Smav device_printf(dev, " GPO%d: state=%d", i, 2522230130Smav (data >> i) & 1); 2523230130Smav } 2524230130Smav } 2525230130Smav} 2526230130Smav 2527230130Smavstatic void 2528230130Smavhdaa_audio_parse(struct hdaa_devinfo *devinfo) 2529230130Smav{ 2530230130Smav struct hdaa_widget *w; 2531230130Smav uint32_t res; 2532230130Smav int i; 2533230130Smav nid_t nid; 2534230130Smav 2535230130Smav nid = devinfo->nid; 2536230130Smav 2537230130Smav res = hda_command(devinfo->dev, 2538230130Smav HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_GPIO_COUNT)); 2539230130Smav devinfo->gpio_cap = res; 2540230130Smav 2541230130Smav HDA_BOOTVERBOSE( 2542230130Smav device_printf(devinfo->dev, 2543230130Smav "NumGPIO=%d NumGPO=%d " 2544230130Smav "NumGPI=%d GPIWake=%d GPIUnsol=%d\n", 2545230130Smav HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap), 2546230130Smav HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap), 2547230130Smav HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap), 2548230130Smav HDA_PARAM_GPIO_COUNT_GPI_WAKE(devinfo->gpio_cap), 2549230130Smav HDA_PARAM_GPIO_COUNT_GPI_UNSOL(devinfo->gpio_cap)); 2550230130Smav hdaa_dump_gpi(devinfo); 2551230130Smav hdaa_dump_gpio(devinfo); 2552230130Smav hdaa_dump_gpo(devinfo); 2553230130Smav ); 2554230130Smav 2555230130Smav res = hda_command(devinfo->dev, 2556230130Smav HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_SUPP_STREAM_FORMATS)); 2557230130Smav devinfo->supp_stream_formats = res; 2558230130Smav 2559230130Smav res = hda_command(devinfo->dev, 2560230130Smav HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_SUPP_PCM_SIZE_RATE)); 2561230130Smav devinfo->supp_pcm_size_rate = res; 2562230130Smav 2563230130Smav res = hda_command(devinfo->dev, 2564230130Smav HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_OUTPUT_AMP_CAP)); 2565230130Smav devinfo->outamp_cap = res; 2566230130Smav 2567230130Smav res = hda_command(devinfo->dev, 2568230130Smav HDA_CMD_GET_PARAMETER(0, nid, HDA_PARAM_INPUT_AMP_CAP)); 2569230130Smav devinfo->inamp_cap = res; 2570230130Smav 2571230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 2572230130Smav w = hdaa_widget_get(devinfo, i); 2573230130Smav if (w == NULL) 2574230130Smav device_printf(devinfo->dev, "Ghost widget! nid=%d!\n", i); 2575230130Smav else { 2576230130Smav w->devinfo = devinfo; 2577230130Smav w->nid = i; 2578230130Smav w->enable = 1; 2579230130Smav w->selconn = -1; 2580230130Smav w->pflags = 0; 2581230130Smav w->ossdev = -1; 2582230130Smav w->bindas = -1; 2583230130Smav w->param.eapdbtl = HDA_INVALID; 2584230130Smav hdaa_widget_parse(w); 2585230130Smav } 2586230130Smav } 2587230130Smav} 2588230130Smav 2589230130Smavstatic void 2590230130Smavhdaa_audio_postprocess(struct hdaa_devinfo *devinfo) 2591230130Smav{ 2592230130Smav struct hdaa_widget *w; 2593230130Smav int i; 2594230130Smav 2595230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 2596230130Smav w = hdaa_widget_get(devinfo, i); 2597230130Smav if (w == NULL) 2598230130Smav continue; 2599230130Smav hdaa_widget_postprocess(w); 2600230130Smav } 2601230130Smav} 2602230130Smav 2603230130Smavstatic void 2604230130Smavhdaa_audio_ctl_parse(struct hdaa_devinfo *devinfo) 2605230130Smav{ 2606230130Smav struct hdaa_audio_ctl *ctls; 2607230130Smav struct hdaa_widget *w, *cw; 2608230130Smav int i, j, cnt, max, ocap, icap; 2609230130Smav int mute, offset, step, size; 2610230130Smav 2611230130Smav /* XXX This is redundant */ 2612230130Smav max = 0; 2613230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 2614230130Smav w = hdaa_widget_get(devinfo, i); 2615230130Smav if (w == NULL || w->enable == 0) 2616230130Smav continue; 2617230130Smav if (w->param.outamp_cap != 0) 2618230130Smav max++; 2619230130Smav if (w->param.inamp_cap != 0) { 2620230130Smav switch (w->type) { 2621230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR: 2622230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER: 2623230130Smav for (j = 0; j < w->nconns; j++) { 2624230130Smav cw = hdaa_widget_get(devinfo, 2625230130Smav w->conns[j]); 2626230130Smav if (cw == NULL || cw->enable == 0) 2627230130Smav continue; 2628230130Smav max++; 2629230130Smav } 2630230130Smav break; 2631230130Smav default: 2632230130Smav max++; 2633230130Smav break; 2634230130Smav } 2635230130Smav } 2636230130Smav } 2637230130Smav devinfo->ctlcnt = max; 2638230130Smav 2639230130Smav if (max < 1) 2640230130Smav return; 2641230130Smav 2642230130Smav ctls = (struct hdaa_audio_ctl *)malloc( 2643230130Smav sizeof(*ctls) * max, M_HDAA, M_ZERO | M_NOWAIT); 2644230130Smav 2645230130Smav if (ctls == NULL) { 2646230130Smav /* Blekh! */ 2647230130Smav device_printf(devinfo->dev, "unable to allocate ctls!\n"); 2648230130Smav devinfo->ctlcnt = 0; 2649230130Smav return; 2650230130Smav } 2651230130Smav 2652230130Smav cnt = 0; 2653230130Smav for (i = devinfo->startnode; cnt < max && i < devinfo->endnode; i++) { 2654230130Smav if (cnt >= max) { 2655230130Smav device_printf(devinfo->dev, "%s: Ctl overflow!\n", 2656230130Smav __func__); 2657230130Smav break; 2658230130Smav } 2659230130Smav w = hdaa_widget_get(devinfo, i); 2660230130Smav if (w == NULL || w->enable == 0) 2661230130Smav continue; 2662230130Smav ocap = w->param.outamp_cap; 2663230130Smav icap = w->param.inamp_cap; 2664230130Smav if (ocap != 0) { 2665230130Smav mute = HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(ocap); 2666230130Smav step = HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(ocap); 2667230130Smav size = HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(ocap); 2668230130Smav offset = HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(ocap); 2669230130Smav /*if (offset > step) { 2670230130Smav HDA_BOOTVERBOSE( 2671230130Smav device_printf(devinfo->dev, 2672230130Smav "BUGGY outamp: nid=%d " 2673230130Smav "[offset=%d > step=%d]\n", 2674230130Smav w->nid, offset, step); 2675230130Smav ); 2676230130Smav offset = step; 2677230130Smav }*/ 2678230130Smav ctls[cnt].enable = 1; 2679230130Smav ctls[cnt].widget = w; 2680230130Smav ctls[cnt].mute = mute; 2681230130Smav ctls[cnt].step = step; 2682230130Smav ctls[cnt].size = size; 2683230130Smav ctls[cnt].offset = offset; 2684230130Smav ctls[cnt].left = offset; 2685230130Smav ctls[cnt].right = offset; 2686230130Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX || 2687230130Smav w->waspin) 2688230130Smav ctls[cnt].ndir = HDAA_CTL_IN; 2689230130Smav else 2690230130Smav ctls[cnt].ndir = HDAA_CTL_OUT; 2691230130Smav ctls[cnt++].dir = HDAA_CTL_OUT; 2692230130Smav } 2693230130Smav 2694230130Smav if (icap != 0) { 2695230130Smav mute = HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(icap); 2696230130Smav step = HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(icap); 2697230130Smav size = HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(icap); 2698230130Smav offset = HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(icap); 2699230130Smav /*if (offset > step) { 2700230130Smav HDA_BOOTVERBOSE( 2701230130Smav device_printf(devinfo->dev, 2702230130Smav "BUGGY inamp: nid=%d " 2703230130Smav "[offset=%d > step=%d]\n", 2704230130Smav w->nid, offset, step); 2705230130Smav ); 2706230130Smav offset = step; 2707230130Smav }*/ 2708230130Smav switch (w->type) { 2709230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR: 2710230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER: 2711230130Smav for (j = 0; j < w->nconns; j++) { 2712230130Smav if (cnt >= max) { 2713230130Smav device_printf(devinfo->dev, 2714230130Smav "%s: Ctl overflow!\n", 2715230130Smav __func__); 2716230130Smav break; 2717230130Smav } 2718230130Smav cw = hdaa_widget_get(devinfo, 2719230130Smav w->conns[j]); 2720230130Smav if (cw == NULL || cw->enable == 0) 2721230130Smav continue; 2722230130Smav ctls[cnt].enable = 1; 2723230130Smav ctls[cnt].widget = w; 2724230130Smav ctls[cnt].childwidget = cw; 2725230130Smav ctls[cnt].index = j; 2726230130Smav ctls[cnt].mute = mute; 2727230130Smav ctls[cnt].step = step; 2728230130Smav ctls[cnt].size = size; 2729230130Smav ctls[cnt].offset = offset; 2730230130Smav ctls[cnt].left = offset; 2731230130Smav ctls[cnt].right = offset; 2732230130Smav ctls[cnt].ndir = HDAA_CTL_IN; 2733230130Smav ctls[cnt++].dir = HDAA_CTL_IN; 2734230130Smav } 2735230130Smav break; 2736230130Smav default: 2737230130Smav if (cnt >= max) { 2738230130Smav device_printf(devinfo->dev, 2739230130Smav "%s: Ctl overflow!\n", 2740230130Smav __func__); 2741230130Smav break; 2742230130Smav } 2743230130Smav ctls[cnt].enable = 1; 2744230130Smav ctls[cnt].widget = w; 2745230130Smav ctls[cnt].mute = mute; 2746230130Smav ctls[cnt].step = step; 2747230130Smav ctls[cnt].size = size; 2748230130Smav ctls[cnt].offset = offset; 2749230130Smav ctls[cnt].left = offset; 2750230130Smav ctls[cnt].right = offset; 2751230130Smav if (w->type == 2752230130Smav HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 2753230130Smav ctls[cnt].ndir = HDAA_CTL_OUT; 2754230130Smav else 2755230130Smav ctls[cnt].ndir = HDAA_CTL_IN; 2756230130Smav ctls[cnt++].dir = HDAA_CTL_IN; 2757230130Smav break; 2758230130Smav } 2759230130Smav } 2760230130Smav } 2761230130Smav 2762230130Smav devinfo->ctl = ctls; 2763230130Smav} 2764230130Smav 2765230130Smavstatic void 2766230130Smavhdaa_audio_as_parse(struct hdaa_devinfo *devinfo) 2767230130Smav{ 2768230130Smav struct hdaa_audio_as *as; 2769230130Smav struct hdaa_widget *w; 2770230130Smav int i, j, cnt, max, type, dir, assoc, seq, first, hpredir; 2771230130Smav 2772230130Smav /* Count present associations */ 2773230130Smav max = 0; 2774230130Smav for (j = 1; j < 16; j++) { 2775230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 2776230130Smav w = hdaa_widget_get(devinfo, i); 2777230130Smav if (w == NULL || w->enable == 0) 2778230130Smav continue; 2779230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 2780230130Smav continue; 2781230130Smav if (HDA_CONFIG_DEFAULTCONF_ASSOCIATION(w->wclass.pin.config) 2782230130Smav != j) 2783230130Smav continue; 2784230130Smav max++; 2785230130Smav if (j != 15) /* There could be many 1-pin assocs #15 */ 2786230130Smav break; 2787230130Smav } 2788230130Smav } 2789230130Smav 2790230130Smav devinfo->ascnt = max; 2791230130Smav 2792230130Smav if (max < 1) 2793230130Smav return; 2794230130Smav 2795230130Smav as = (struct hdaa_audio_as *)malloc( 2796230130Smav sizeof(*as) * max, M_HDAA, M_ZERO | M_NOWAIT); 2797230130Smav 2798230130Smav if (as == NULL) { 2799230130Smav /* Blekh! */ 2800230130Smav device_printf(devinfo->dev, "unable to allocate assocs!\n"); 2801230130Smav devinfo->ascnt = 0; 2802230130Smav return; 2803230130Smav } 2804230130Smav 2805230130Smav for (i = 0; i < max; i++) { 2806230130Smav as[i].hpredir = -1; 2807230130Smav as[i].digital = 0; 2808230130Smav as[i].num_chans = 1; 2809230130Smav as[i].location = -1; 2810230130Smav } 2811230130Smav 2812230130Smav /* Scan associations skipping as=0. */ 2813230130Smav cnt = 0; 2814230130Smav for (j = 1; j < 16; j++) { 2815230130Smav first = 16; 2816230130Smav hpredir = 0; 2817230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 2818230130Smav w = hdaa_widget_get(devinfo, i); 2819230130Smav if (w == NULL || w->enable == 0) 2820230130Smav continue; 2821230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 2822230130Smav continue; 2823230130Smav assoc = HDA_CONFIG_DEFAULTCONF_ASSOCIATION(w->wclass.pin.config); 2824230130Smav seq = HDA_CONFIG_DEFAULTCONF_SEQUENCE(w->wclass.pin.config); 2825230130Smav if (assoc != j) { 2826230130Smav continue; 2827230130Smav } 2828230130Smav KASSERT(cnt < max, 2829230130Smav ("%s: Associations owerflow (%d of %d)", 2830230130Smav __func__, cnt, max)); 2831230130Smav type = w->wclass.pin.config & 2832230130Smav HDA_CONFIG_DEFAULTCONF_DEVICE_MASK; 2833230130Smav /* Get pin direction. */ 2834230130Smav if (type == HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_OUT || 2835230130Smav type == HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER || 2836230130Smav type == HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT || 2837230130Smav type == HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_OUT || 2838230130Smav type == HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_OUT) 2839230130Smav dir = HDAA_CTL_OUT; 2840230130Smav else 2841230130Smav dir = HDAA_CTL_IN; 2842230130Smav /* If this is a first pin - create new association. */ 2843230130Smav if (as[cnt].pincnt == 0) { 2844230130Smav as[cnt].enable = 1; 2845230130Smav as[cnt].index = j; 2846230130Smav as[cnt].dir = dir; 2847230130Smav } 2848230130Smav if (seq < first) 2849230130Smav first = seq; 2850230130Smav /* Check association correctness. */ 2851230130Smav if (as[cnt].pins[seq] != 0) { 2852230130Smav device_printf(devinfo->dev, "%s: Duplicate pin %d (%d) " 2853230130Smav "in association %d! Disabling association.\n", 2854230130Smav __func__, seq, w->nid, j); 2855230130Smav as[cnt].enable = 0; 2856230130Smav } 2857230130Smav if (dir != as[cnt].dir) { 2858230130Smav device_printf(devinfo->dev, "%s: Pin %d has wrong " 2859230130Smav "direction for association %d! Disabling " 2860230130Smav "association.\n", 2861230130Smav __func__, w->nid, j); 2862230130Smav as[cnt].enable = 0; 2863230130Smav } 2864230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) { 2865230507Smav as[cnt].digital |= 0x1; 2866230507Smav if (HDA_PARAM_PIN_CAP_HDMI(w->wclass.pin.cap)) 2867230507Smav as[cnt].digital |= 0x2; 2868230130Smav if (HDA_PARAM_PIN_CAP_DP(w->wclass.pin.cap)) 2869230507Smav as[cnt].digital |= 0x4; 2870230130Smav } 2871230130Smav if (as[cnt].location == -1) { 2872230130Smav as[cnt].location = 2873230130Smav HDA_CONFIG_DEFAULTCONF_LOCATION(w->wclass.pin.config); 2874230130Smav } else if (as[cnt].location != 2875230130Smav HDA_CONFIG_DEFAULTCONF_LOCATION(w->wclass.pin.config)) { 2876230130Smav as[cnt].location = -2; 2877230130Smav } 2878230130Smav /* Headphones with seq=15 may mean redirection. */ 2879230130Smav if (type == HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT && 2880230130Smav seq == 15) 2881230130Smav hpredir = 1; 2882230130Smav as[cnt].pins[seq] = w->nid; 2883230130Smav as[cnt].pincnt++; 2884230130Smav /* Association 15 is a multiple unassociated pins. */ 2885230130Smav if (j == 15) 2886230130Smav cnt++; 2887230130Smav } 2888230130Smav if (j != 15 && as[cnt].pincnt > 0) { 2889230130Smav if (hpredir && as[cnt].pincnt > 1) 2890230130Smav as[cnt].hpredir = first; 2891230130Smav cnt++; 2892230130Smav } 2893230130Smav } 2894230130Smav for (i = 0; i < max; i++) { 2895230130Smav if (as[i].dir == HDAA_CTL_IN && (as[i].pincnt == 1 || 2896230130Smav as[i].pins[14] > 0 || as[i].pins[15] > 0)) 2897230130Smav as[i].mixed = 1; 2898230130Smav } 2899230130Smav HDA_BOOTVERBOSE( 2900230130Smav device_printf(devinfo->dev, 2901230130Smav "%d associations found:\n", max); 2902230130Smav for (i = 0; i < max; i++) { 2903230130Smav device_printf(devinfo->dev, 2904230130Smav "Association %d (%d) %s%s:\n", 2905230130Smav i, as[i].index, (as[i].dir == HDAA_CTL_IN)?"in":"out", 2906230130Smav as[i].enable?"":" (disabled)"); 2907230130Smav for (j = 0; j < 16; j++) { 2908230130Smav if (as[i].pins[j] == 0) 2909230130Smav continue; 2910230130Smav device_printf(devinfo->dev, 2911230130Smav " Pin nid=%d seq=%d\n", 2912230130Smav as[i].pins[j], j); 2913230130Smav } 2914230130Smav } 2915230130Smav ); 2916230130Smav 2917230130Smav devinfo->as = as; 2918230130Smav} 2919230130Smav 2920230130Smav/* 2921230130Smav * Trace path from DAC to pin. 2922230130Smav */ 2923230130Smavstatic nid_t 2924230130Smavhdaa_audio_trace_dac(struct hdaa_devinfo *devinfo, int as, int seq, nid_t nid, 2925230130Smav int dupseq, int min, int only, int depth) 2926230130Smav{ 2927230130Smav struct hdaa_widget *w; 2928230130Smav int i, im = -1; 2929230130Smav nid_t m = 0, ret; 2930230130Smav 2931230130Smav if (depth > HDA_PARSE_MAXDEPTH) 2932230130Smav return (0); 2933230130Smav w = hdaa_widget_get(devinfo, nid); 2934230130Smav if (w == NULL || w->enable == 0) 2935230130Smav return (0); 2936230130Smav HDA_BOOTHVERBOSE( 2937230130Smav if (!only) { 2938230130Smav device_printf(devinfo->dev, 2939230130Smav " %*stracing via nid %d\n", 2940230130Smav depth + 1, "", w->nid); 2941230130Smav } 2942230130Smav ); 2943230130Smav /* Use only unused widgets */ 2944230130Smav if (w->bindas >= 0 && w->bindas != as) { 2945230130Smav HDA_BOOTHVERBOSE( 2946230130Smav if (!only) { 2947230130Smav device_printf(devinfo->dev, 2948230130Smav " %*snid %d busy by association %d\n", 2949230130Smav depth + 1, "", w->nid, w->bindas); 2950230130Smav } 2951230130Smav ); 2952230130Smav return (0); 2953230130Smav } 2954230130Smav if (dupseq < 0) { 2955230130Smav if (w->bindseqmask != 0) { 2956230130Smav HDA_BOOTHVERBOSE( 2957230130Smav if (!only) { 2958230130Smav device_printf(devinfo->dev, 2959230130Smav " %*snid %d busy by seqmask %x\n", 2960230130Smav depth + 1, "", w->nid, w->bindseqmask); 2961230130Smav } 2962230130Smav ); 2963230130Smav return (0); 2964230130Smav } 2965230130Smav } else { 2966230130Smav /* If this is headphones - allow duplicate first pin. */ 2967230130Smav if (w->bindseqmask != 0 && 2968230130Smav (w->bindseqmask & (1 << dupseq)) == 0) { 2969230130Smav HDA_BOOTHVERBOSE( 2970230130Smav device_printf(devinfo->dev, 2971230130Smav " %*snid %d busy by seqmask %x\n", 2972230130Smav depth + 1, "", w->nid, w->bindseqmask); 2973230130Smav ); 2974230130Smav return (0); 2975230130Smav } 2976230130Smav } 2977230130Smav 2978230130Smav switch (w->type) { 2979230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT: 2980230130Smav /* Do not traverse input. AD1988 has digital monitor 2981230130Smav for which we are not ready. */ 2982230130Smav break; 2983230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT: 2984230130Smav /* If we are tracing HP take only dac of first pin. */ 2985230130Smav if ((only == 0 || only == w->nid) && 2986230130Smav (w->nid >= min) && (dupseq < 0 || w->nid == 2987230130Smav devinfo->as[as].dacs[0][dupseq])) 2988230130Smav m = w->nid; 2989230130Smav break; 2990230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX: 2991230130Smav if (depth > 0) 2992230130Smav break; 2993230130Smav /* Fall */ 2994230130Smav default: 2995230130Smav /* Find reachable DACs with smallest nid respecting constraints. */ 2996230130Smav for (i = 0; i < w->nconns; i++) { 2997230130Smav if (w->connsenable[i] == 0) 2998230130Smav continue; 2999230130Smav if (w->selconn != -1 && w->selconn != i) 3000230130Smav continue; 3001230130Smav if ((ret = hdaa_audio_trace_dac(devinfo, as, seq, 3002230130Smav w->conns[i], dupseq, min, only, depth + 1)) != 0) { 3003230130Smav if (m == 0 || ret < m) { 3004230130Smav m = ret; 3005230130Smav im = i; 3006230130Smav } 3007230130Smav if (only || dupseq >= 0) 3008230130Smav break; 3009230130Smav } 3010230130Smav } 3011230130Smav if (im >= 0 && only && ((w->nconns > 1 && 3012230130Smav w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) || 3013230130Smav w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR)) 3014230130Smav w->selconn = im; 3015230130Smav break; 3016230130Smav } 3017230130Smav if (m && only) { 3018230130Smav w->bindas = as; 3019230130Smav w->bindseqmask |= (1 << seq); 3020230130Smav } 3021230130Smav HDA_BOOTHVERBOSE( 3022230130Smav if (!only) { 3023230130Smav device_printf(devinfo->dev, 3024230130Smav " %*snid %d returned %d\n", 3025230130Smav depth + 1, "", w->nid, m); 3026230130Smav } 3027230130Smav ); 3028230130Smav return (m); 3029230130Smav} 3030230130Smav 3031230130Smav/* 3032230130Smav * Trace path from widget to ADC. 3033230130Smav */ 3034230130Smavstatic nid_t 3035230130Smavhdaa_audio_trace_adc(struct hdaa_devinfo *devinfo, int as, int seq, nid_t nid, 3036230130Smav int mixed, int min, int only, int depth, int *length, int onlylength) 3037230130Smav{ 3038230130Smav struct hdaa_widget *w, *wc; 3039230130Smav int i, j, im, lm = HDA_PARSE_MAXDEPTH; 3040230130Smav nid_t m = 0, ret; 3041230130Smav 3042230130Smav if (depth > HDA_PARSE_MAXDEPTH) 3043230130Smav return (0); 3044230130Smav w = hdaa_widget_get(devinfo, nid); 3045230130Smav if (w == NULL || w->enable == 0) 3046230130Smav return (0); 3047230130Smav HDA_BOOTHVERBOSE( 3048230130Smav device_printf(devinfo->dev, 3049230130Smav " %*stracing via nid %d\n", 3050230130Smav depth + 1, "", w->nid); 3051230130Smav ); 3052230130Smav /* Use only unused widgets */ 3053230130Smav if (w->bindas >= 0 && w->bindas != as) { 3054230130Smav HDA_BOOTHVERBOSE( 3055230130Smav device_printf(devinfo->dev, 3056230130Smav " %*snid %d busy by association %d\n", 3057230130Smav depth + 1, "", w->nid, w->bindas); 3058230130Smav ); 3059230130Smav return (0); 3060230130Smav } 3061230130Smav if (!mixed && w->bindseqmask != 0) { 3062230130Smav HDA_BOOTHVERBOSE( 3063230130Smav device_printf(devinfo->dev, 3064230130Smav " %*snid %d busy by seqmask %x\n", 3065230130Smav depth + 1, "", w->nid, w->bindseqmask); 3066230130Smav ); 3067230130Smav return (0); 3068230130Smav } 3069230130Smav switch (w->type) { 3070230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT: 3071230130Smav if ((only == 0 || only == w->nid) && (w->nid >= min) && 3072230130Smav (onlylength == 0 || onlylength == depth)) { 3073230130Smav m = w->nid; 3074239254Smav *length = depth; 3075230130Smav } 3076230130Smav break; 3077230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX: 3078230130Smav if (depth > 0) 3079230130Smav break; 3080230130Smav /* Fall */ 3081230130Smav default: 3082230130Smav /* Try to find reachable ADCs with specified nid. */ 3083230130Smav for (j = devinfo->startnode; j < devinfo->endnode; j++) { 3084230130Smav wc = hdaa_widget_get(devinfo, j); 3085230130Smav if (wc == NULL || wc->enable == 0) 3086230130Smav continue; 3087230130Smav im = -1; 3088230130Smav for (i = 0; i < wc->nconns; i++) { 3089230130Smav if (wc->connsenable[i] == 0) 3090230130Smav continue; 3091230130Smav if (wc->conns[i] != nid) 3092230130Smav continue; 3093230130Smav if ((ret = hdaa_audio_trace_adc(devinfo, as, seq, 3094230130Smav j, mixed, min, only, depth + 1, 3095230130Smav length, onlylength)) != 0) { 3096230130Smav if (m == 0 || ret < m || 3097239254Smav (ret == m && *length < lm)) { 3098230130Smav m = ret; 3099230130Smav im = i; 3100230130Smav lm = *length; 3101239254Smav } else 3102239254Smav *length = lm; 3103230130Smav if (only) 3104230130Smav break; 3105230130Smav } 3106230130Smav } 3107230130Smav if (im >= 0 && only && ((wc->nconns > 1 && 3108230130Smav wc->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) || 3109230130Smav wc->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR)) 3110230130Smav wc->selconn = im; 3111230130Smav } 3112230130Smav break; 3113230130Smav } 3114230130Smav if (m && only) { 3115230130Smav w->bindas = as; 3116230130Smav w->bindseqmask |= (1 << seq); 3117230130Smav } 3118230130Smav HDA_BOOTHVERBOSE( 3119230130Smav device_printf(devinfo->dev, 3120230130Smav " %*snid %d returned %d\n", 3121230130Smav depth + 1, "", w->nid, m); 3122230130Smav ); 3123230130Smav return (m); 3124230130Smav} 3125230130Smav 3126230130Smav/* 3127230130Smav * Erase trace path of the specified association. 3128230130Smav */ 3129230130Smavstatic void 3130230130Smavhdaa_audio_undo_trace(struct hdaa_devinfo *devinfo, int as, int seq) 3131230130Smav{ 3132230130Smav struct hdaa_widget *w; 3133230130Smav int i; 3134230130Smav 3135230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 3136230130Smav w = hdaa_widget_get(devinfo, i); 3137230130Smav if (w == NULL || w->enable == 0) 3138230130Smav continue; 3139230130Smav if (w->bindas == as) { 3140230130Smav if (seq >= 0) { 3141230130Smav w->bindseqmask &= ~(1 << seq); 3142230130Smav if (w->bindseqmask == 0) { 3143230130Smav w->bindas = -1; 3144230130Smav w->selconn = -1; 3145230130Smav } 3146230130Smav } else { 3147230130Smav w->bindas = -1; 3148230130Smav w->bindseqmask = 0; 3149230130Smav w->selconn = -1; 3150230130Smav } 3151230130Smav } 3152230130Smav } 3153230130Smav} 3154230130Smav 3155230130Smav/* 3156230130Smav * Trace association path from DAC to output 3157230130Smav */ 3158230130Smavstatic int 3159230130Smavhdaa_audio_trace_as_out(struct hdaa_devinfo *devinfo, int as, int seq) 3160230130Smav{ 3161230130Smav struct hdaa_audio_as *ases = devinfo->as; 3162230130Smav int i, hpredir; 3163230130Smav nid_t min, res; 3164230130Smav 3165230130Smav /* Find next pin */ 3166230130Smav for (i = seq; i < 16 && ases[as].pins[i] == 0; i++) 3167230130Smav ; 3168230130Smav /* Check if there is no any left. If so - we succeeded. */ 3169230130Smav if (i == 16) 3170230130Smav return (1); 3171230130Smav 3172230130Smav hpredir = (i == 15 && ases[as].fakeredir == 0)?ases[as].hpredir:-1; 3173230130Smav min = 0; 3174230130Smav do { 3175230130Smav HDA_BOOTHVERBOSE( 3176230130Smav device_printf(devinfo->dev, 3177230130Smav " Tracing pin %d with min nid %d", 3178230130Smav ases[as].pins[i], min); 3179230130Smav if (hpredir >= 0) 3180230130Smav printf(" and hpredir %d", hpredir); 3181230130Smav printf("\n"); 3182230130Smav ); 3183230130Smav /* Trace this pin taking min nid into account. */ 3184230130Smav res = hdaa_audio_trace_dac(devinfo, as, i, 3185230130Smav ases[as].pins[i], hpredir, min, 0, 0); 3186230130Smav if (res == 0) { 3187230130Smav /* If we failed - return to previous and redo it. */ 3188230130Smav HDA_BOOTVERBOSE( 3189230130Smav device_printf(devinfo->dev, 3190230130Smav " Unable to trace pin %d seq %d with min " 3191230130Smav "nid %d", 3192230130Smav ases[as].pins[i], i, min); 3193230130Smav if (hpredir >= 0) 3194230130Smav printf(" and hpredir %d", hpredir); 3195230130Smav printf("\n"); 3196230130Smav ); 3197230130Smav return (0); 3198230130Smav } 3199230130Smav HDA_BOOTVERBOSE( 3200230130Smav device_printf(devinfo->dev, 3201230130Smav " Pin %d traced to DAC %d", 3202230130Smav ases[as].pins[i], res); 3203230130Smav if (hpredir >= 0) 3204230130Smav printf(" and hpredir %d", hpredir); 3205230130Smav if (ases[as].fakeredir) 3206230130Smav printf(" with fake redirection"); 3207230130Smav printf("\n"); 3208230130Smav ); 3209230130Smav /* Trace again to mark the path */ 3210230130Smav hdaa_audio_trace_dac(devinfo, as, i, 3211230130Smav ases[as].pins[i], hpredir, min, res, 0); 3212230130Smav ases[as].dacs[0][i] = res; 3213230130Smav /* We succeeded, so call next. */ 3214230130Smav if (hdaa_audio_trace_as_out(devinfo, as, i + 1)) 3215230130Smav return (1); 3216230130Smav /* If next failed, we should retry with next min */ 3217230130Smav hdaa_audio_undo_trace(devinfo, as, i); 3218230130Smav ases[as].dacs[0][i] = 0; 3219230130Smav min = res + 1; 3220230130Smav } while (1); 3221230130Smav} 3222230130Smav 3223230130Smav/* 3224230130Smav * Check equivalency of two DACs. 3225230130Smav */ 3226230130Smavstatic int 3227230130Smavhdaa_audio_dacs_equal(struct hdaa_widget *w1, struct hdaa_widget *w2) 3228230130Smav{ 3229230130Smav struct hdaa_devinfo *devinfo = w1->devinfo; 3230230130Smav struct hdaa_widget *w3; 3231230130Smav int i, j, c1, c2; 3232230130Smav 3233230130Smav if (memcmp(&w1->param, &w2->param, sizeof(w1->param))) 3234230130Smav return (0); 3235230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 3236230130Smav w3 = hdaa_widget_get(devinfo, i); 3237230130Smav if (w3 == NULL || w3->enable == 0) 3238230130Smav continue; 3239230130Smav if (w3->bindas != w1->bindas) 3240230130Smav continue; 3241230130Smav if (w3->nconns == 0) 3242230130Smav continue; 3243230130Smav c1 = c2 = -1; 3244230130Smav for (j = 0; j < w3->nconns; j++) { 3245230130Smav if (w3->connsenable[j] == 0) 3246230130Smav continue; 3247230130Smav if (w3->conns[j] == w1->nid) 3248230130Smav c1 = j; 3249230130Smav if (w3->conns[j] == w2->nid) 3250230130Smav c2 = j; 3251230130Smav } 3252230130Smav if (c1 < 0) 3253230130Smav continue; 3254230130Smav if (c2 < 0) 3255230130Smav return (0); 3256230130Smav if (w3->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) 3257230130Smav return (0); 3258230130Smav } 3259230130Smav return (1); 3260230130Smav} 3261230130Smav 3262230130Smav/* 3263230130Smav * Check equivalency of two ADCs. 3264230130Smav */ 3265230130Smavstatic int 3266230130Smavhdaa_audio_adcs_equal(struct hdaa_widget *w1, struct hdaa_widget *w2) 3267230130Smav{ 3268230130Smav struct hdaa_devinfo *devinfo = w1->devinfo; 3269230130Smav struct hdaa_widget *w3, *w4; 3270230130Smav int i; 3271230130Smav 3272230130Smav if (memcmp(&w1->param, &w2->param, sizeof(w1->param))) 3273230130Smav return (0); 3274230130Smav if (w1->nconns != 1 || w2->nconns != 1) 3275230130Smav return (0); 3276230130Smav if (w1->conns[0] == w2->conns[0]) 3277230130Smav return (1); 3278230130Smav w3 = hdaa_widget_get(devinfo, w1->conns[0]); 3279230130Smav if (w3 == NULL || w3->enable == 0) 3280230130Smav return (0); 3281230130Smav w4 = hdaa_widget_get(devinfo, w2->conns[0]); 3282230130Smav if (w4 == NULL || w4->enable == 0) 3283230130Smav return (0); 3284230130Smav if (w3->bindas == w4->bindas && w3->bindseqmask == w4->bindseqmask) 3285230130Smav return (1); 3286230130Smav if (w4->bindas >= 0) 3287230130Smav return (0); 3288230130Smav if (w3->type != w4->type) 3289230130Smav return (0); 3290230130Smav if (memcmp(&w3->param, &w4->param, sizeof(w3->param))) 3291230130Smav return (0); 3292230130Smav if (w3->nconns != w4->nconns) 3293230130Smav return (0); 3294230130Smav for (i = 0; i < w3->nconns; i++) { 3295230130Smav if (w3->conns[i] != w4->conns[i]) 3296230130Smav return (0); 3297230130Smav } 3298230130Smav return (1); 3299230130Smav} 3300230130Smav 3301230130Smav/* 3302230130Smav * Look for equivalent DAC/ADC to implement second channel. 3303230130Smav */ 3304230130Smavstatic void 3305230130Smavhdaa_audio_adddac(struct hdaa_devinfo *devinfo, int asid) 3306230130Smav{ 3307230130Smav struct hdaa_audio_as *as = &devinfo->as[asid]; 3308230130Smav struct hdaa_widget *w1, *w2; 3309230130Smav int i, pos; 3310230130Smav nid_t nid1, nid2; 3311230130Smav 3312230130Smav HDA_BOOTVERBOSE( 3313230130Smav device_printf(devinfo->dev, 3314230130Smav "Looking for additional %sC " 3315230130Smav "for association %d (%d)\n", 3316230130Smav (as->dir == HDAA_CTL_OUT) ? "DA" : "AD", 3317230130Smav asid, as->index); 3318230130Smav ); 3319230130Smav 3320230130Smav /* Find the exisitng DAC position and return if found more the one. */ 3321230130Smav pos = -1; 3322230130Smav for (i = 0; i < 16; i++) { 3323230130Smav if (as->dacs[0][i] <= 0) 3324230130Smav continue; 3325230130Smav if (pos >= 0 && as->dacs[0][i] != as->dacs[0][pos]) 3326230130Smav return; 3327230130Smav pos = i; 3328230130Smav } 3329230130Smav 3330230130Smav nid1 = as->dacs[0][pos]; 3331230130Smav w1 = hdaa_widget_get(devinfo, nid1); 3332230130Smav w2 = NULL; 3333230130Smav for (nid2 = devinfo->startnode; nid2 < devinfo->endnode; nid2++) { 3334230130Smav w2 = hdaa_widget_get(devinfo, nid2); 3335230130Smav if (w2 == NULL || w2->enable == 0) 3336230130Smav continue; 3337230130Smav if (w2->bindas >= 0) 3338230130Smav continue; 3339230130Smav if (w1->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT) { 3340230130Smav if (w2->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT) 3341230130Smav continue; 3342230130Smav if (hdaa_audio_dacs_equal(w1, w2)) 3343230130Smav break; 3344230130Smav } else { 3345230130Smav if (w2->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) 3346230130Smav continue; 3347230130Smav if (hdaa_audio_adcs_equal(w1, w2)) 3348230130Smav break; 3349230130Smav } 3350230130Smav } 3351230130Smav if (nid2 >= devinfo->endnode) 3352230130Smav return; 3353230130Smav w2->bindas = w1->bindas; 3354230130Smav w2->bindseqmask = w1->bindseqmask; 3355230130Smav if (w1->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) { 3356230130Smav HDA_BOOTVERBOSE( 3357230130Smav device_printf(devinfo->dev, 3358230130Smav " ADC %d considered equal to ADC %d\n", nid2, nid1); 3359230130Smav ); 3360230130Smav w1 = hdaa_widget_get(devinfo, w1->conns[0]); 3361230130Smav w2 = hdaa_widget_get(devinfo, w2->conns[0]); 3362230130Smav w2->bindas = w1->bindas; 3363230130Smav w2->bindseqmask = w1->bindseqmask; 3364230130Smav } else { 3365230130Smav HDA_BOOTVERBOSE( 3366230130Smav device_printf(devinfo->dev, 3367230130Smav " DAC %d considered equal to DAC %d\n", nid2, nid1); 3368230130Smav ); 3369230130Smav } 3370230130Smav for (i = 0; i < 16; i++) { 3371230130Smav if (as->dacs[0][i] <= 0) 3372230130Smav continue; 3373230130Smav as->dacs[as->num_chans][i] = nid2; 3374230130Smav } 3375230130Smav as->num_chans++; 3376230130Smav} 3377230130Smav 3378230130Smav/* 3379230130Smav * Trace association path from input to ADC 3380230130Smav */ 3381230130Smavstatic int 3382230130Smavhdaa_audio_trace_as_in(struct hdaa_devinfo *devinfo, int as) 3383230130Smav{ 3384230130Smav struct hdaa_audio_as *ases = devinfo->as; 3385230130Smav struct hdaa_widget *w; 3386230130Smav int i, j, k, length; 3387230130Smav 3388230130Smav for (j = devinfo->startnode; j < devinfo->endnode; j++) { 3389230130Smav w = hdaa_widget_get(devinfo, j); 3390230130Smav if (w == NULL || w->enable == 0) 3391230130Smav continue; 3392230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) 3393230130Smav continue; 3394230130Smav if (w->bindas >= 0 && w->bindas != as) 3395230130Smav continue; 3396230130Smav 3397230130Smav /* Find next pin */ 3398230130Smav for (i = 0; i < 16; i++) { 3399230130Smav if (ases[as].pins[i] == 0) 3400230130Smav continue; 3401230130Smav 3402230130Smav HDA_BOOTHVERBOSE( 3403230130Smav device_printf(devinfo->dev, 3404230130Smav " Tracing pin %d to ADC %d\n", 3405230130Smav ases[as].pins[i], j); 3406230130Smav ); 3407230130Smav /* Trace this pin taking goal into account. */ 3408230130Smav if (hdaa_audio_trace_adc(devinfo, as, i, 3409230130Smav ases[as].pins[i], 1, 0, j, 0, &length, 0) == 0) { 3410230130Smav /* If we failed - return to previous and redo it. */ 3411230130Smav HDA_BOOTVERBOSE( 3412230130Smav device_printf(devinfo->dev, 3413230130Smav " Unable to trace pin %d to ADC %d, undo traces\n", 3414230130Smav ases[as].pins[i], j); 3415230130Smav ); 3416230130Smav hdaa_audio_undo_trace(devinfo, as, -1); 3417230130Smav for (k = 0; k < 16; k++) 3418230130Smav ases[as].dacs[0][k] = 0; 3419230130Smav break; 3420230130Smav } 3421230130Smav HDA_BOOTVERBOSE( 3422230130Smav device_printf(devinfo->dev, 3423230130Smav " Pin %d traced to ADC %d\n", 3424230130Smav ases[as].pins[i], j); 3425230130Smav ); 3426230130Smav ases[as].dacs[0][i] = j; 3427230130Smav } 3428230130Smav if (i == 16) 3429230130Smav return (1); 3430230130Smav } 3431230130Smav return (0); 3432230130Smav} 3433230130Smav 3434230130Smav/* 3435230130Smav * Trace association path from input to multiple ADCs 3436230130Smav */ 3437230130Smavstatic int 3438230130Smavhdaa_audio_trace_as_in_mch(struct hdaa_devinfo *devinfo, int as, int seq) 3439230130Smav{ 3440230130Smav struct hdaa_audio_as *ases = devinfo->as; 3441230130Smav int i, length; 3442230130Smav nid_t min, res; 3443230130Smav 3444230130Smav /* Find next pin */ 3445230130Smav for (i = seq; i < 16 && ases[as].pins[i] == 0; i++) 3446230130Smav ; 3447230130Smav /* Check if there is no any left. If so - we succeeded. */ 3448230130Smav if (i == 16) 3449230130Smav return (1); 3450230130Smav 3451230130Smav min = 0; 3452230130Smav do { 3453230130Smav HDA_BOOTHVERBOSE( 3454230130Smav device_printf(devinfo->dev, 3455230130Smav " Tracing pin %d with min nid %d", 3456230130Smav ases[as].pins[i], min); 3457230130Smav printf("\n"); 3458230130Smav ); 3459230130Smav /* Trace this pin taking min nid into account. */ 3460230130Smav res = hdaa_audio_trace_adc(devinfo, as, i, 3461230130Smav ases[as].pins[i], 0, min, 0, 0, &length, 0); 3462230130Smav if (res == 0) { 3463230130Smav /* If we failed - return to previous and redo it. */ 3464230130Smav HDA_BOOTVERBOSE( 3465230130Smav device_printf(devinfo->dev, 3466230130Smav " Unable to trace pin %d seq %d with min " 3467230130Smav "nid %d", 3468230130Smav ases[as].pins[i], i, min); 3469230130Smav printf("\n"); 3470230130Smav ); 3471230130Smav return (0); 3472230130Smav } 3473230130Smav HDA_BOOTVERBOSE( 3474230130Smav device_printf(devinfo->dev, 3475230130Smav " Pin %d traced to ADC %d\n", 3476230130Smav ases[as].pins[i], res); 3477230130Smav ); 3478230130Smav /* Trace again to mark the path */ 3479230130Smav hdaa_audio_trace_adc(devinfo, as, i, 3480230130Smav ases[as].pins[i], 0, min, res, 0, &length, length); 3481230130Smav ases[as].dacs[0][i] = res; 3482230130Smav /* We succeeded, so call next. */ 3483230130Smav if (hdaa_audio_trace_as_in_mch(devinfo, as, i + 1)) 3484230130Smav return (1); 3485230130Smav /* If next failed, we should retry with next min */ 3486230130Smav hdaa_audio_undo_trace(devinfo, as, i); 3487230130Smav ases[as].dacs[0][i] = 0; 3488230130Smav min = res + 1; 3489230130Smav } while (1); 3490230130Smav} 3491230130Smav 3492230130Smav/* 3493230130Smav * Trace input monitor path from mixer to output association. 3494230130Smav */ 3495230130Smavstatic int 3496230130Smavhdaa_audio_trace_to_out(struct hdaa_devinfo *devinfo, nid_t nid, int depth) 3497230130Smav{ 3498230130Smav struct hdaa_audio_as *ases = devinfo->as; 3499230130Smav struct hdaa_widget *w, *wc; 3500230130Smav int i, j; 3501230130Smav nid_t res = 0; 3502230130Smav 3503230130Smav if (depth > HDA_PARSE_MAXDEPTH) 3504230130Smav return (0); 3505230130Smav w = hdaa_widget_get(devinfo, nid); 3506230130Smav if (w == NULL || w->enable == 0) 3507230130Smav return (0); 3508230130Smav HDA_BOOTHVERBOSE( 3509230130Smav device_printf(devinfo->dev, 3510230130Smav " %*stracing via nid %d\n", 3511230130Smav depth + 1, "", w->nid); 3512230130Smav ); 3513230130Smav /* Use only unused widgets */ 3514230130Smav if (depth > 0 && w->bindas != -1) { 3515230130Smav if (w->bindas < 0 || ases[w->bindas].dir == HDAA_CTL_OUT) { 3516230130Smav HDA_BOOTHVERBOSE( 3517230130Smav device_printf(devinfo->dev, 3518230130Smav " %*snid %d found output association %d\n", 3519230130Smav depth + 1, "", w->nid, w->bindas); 3520230130Smav ); 3521230130Smav if (w->bindas >= 0) 3522230130Smav w->pflags |= HDAA_ADC_MONITOR; 3523230130Smav return (1); 3524230130Smav } else { 3525230130Smav HDA_BOOTHVERBOSE( 3526230130Smav device_printf(devinfo->dev, 3527230130Smav " %*snid %d busy by input association %d\n", 3528230130Smav depth + 1, "", w->nid, w->bindas); 3529230130Smav ); 3530230130Smav return (0); 3531230130Smav } 3532230130Smav } 3533230130Smav 3534230130Smav switch (w->type) { 3535230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT: 3536230130Smav /* Do not traverse input. AD1988 has digital monitor 3537230130Smav for which we are not ready. */ 3538230130Smav break; 3539230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX: 3540230130Smav if (depth > 0) 3541230130Smav break; 3542230130Smav /* Fall */ 3543230130Smav default: 3544230130Smav /* Try to find reachable ADCs with specified nid. */ 3545230130Smav for (j = devinfo->startnode; j < devinfo->endnode; j++) { 3546230130Smav wc = hdaa_widget_get(devinfo, j); 3547230130Smav if (wc == NULL || wc->enable == 0) 3548230130Smav continue; 3549230130Smav for (i = 0; i < wc->nconns; i++) { 3550230130Smav if (wc->connsenable[i] == 0) 3551230130Smav continue; 3552230130Smav if (wc->conns[i] != nid) 3553230130Smav continue; 3554230130Smav if (hdaa_audio_trace_to_out(devinfo, 3555230130Smav j, depth + 1) != 0) { 3556230130Smav res = 1; 3557230130Smav if (wc->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR && 3558230130Smav wc->selconn == -1) 3559230130Smav wc->selconn = i; 3560230130Smav } 3561230130Smav } 3562230130Smav } 3563230130Smav break; 3564230130Smav } 3565230130Smav if (res && w->bindas == -1) 3566230130Smav w->bindas = -2; 3567230130Smav 3568230130Smav HDA_BOOTHVERBOSE( 3569230130Smav device_printf(devinfo->dev, 3570230130Smav " %*snid %d returned %d\n", 3571230130Smav depth + 1, "", w->nid, res); 3572230130Smav ); 3573230130Smav return (res); 3574230130Smav} 3575230130Smav 3576230130Smav/* 3577230130Smav * Trace extra associations (beeper, monitor) 3578230130Smav */ 3579230130Smavstatic void 3580230130Smavhdaa_audio_trace_as_extra(struct hdaa_devinfo *devinfo) 3581230130Smav{ 3582230130Smav struct hdaa_audio_as *as = devinfo->as; 3583230130Smav struct hdaa_widget *w; 3584230130Smav int j; 3585230130Smav 3586230130Smav /* Input monitor */ 3587230130Smav /* Find mixer associated with input, but supplying signal 3588230130Smav for output associations. Hope it will be input monitor. */ 3589230130Smav HDA_BOOTVERBOSE( 3590230130Smav device_printf(devinfo->dev, 3591230130Smav "Tracing input monitor\n"); 3592230130Smav ); 3593230130Smav for (j = devinfo->startnode; j < devinfo->endnode; j++) { 3594230130Smav w = hdaa_widget_get(devinfo, j); 3595230130Smav if (w == NULL || w->enable == 0) 3596230130Smav continue; 3597230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) 3598230130Smav continue; 3599230130Smav if (w->bindas < 0 || as[w->bindas].dir != HDAA_CTL_IN) 3600230130Smav continue; 3601230130Smav HDA_BOOTVERBOSE( 3602230130Smav device_printf(devinfo->dev, 3603230130Smav " Tracing nid %d to out\n", 3604230130Smav j); 3605230130Smav ); 3606230130Smav if (hdaa_audio_trace_to_out(devinfo, w->nid, 0)) { 3607230130Smav HDA_BOOTVERBOSE( 3608230130Smav device_printf(devinfo->dev, 3609230130Smav " nid %d is input monitor\n", 3610230130Smav w->nid); 3611230130Smav ); 3612230130Smav w->ossdev = SOUND_MIXER_IMIX; 3613230130Smav } 3614230130Smav } 3615230130Smav 3616230130Smav /* Other inputs monitor */ 3617230130Smav /* Find input pins supplying signal for output associations. 3618230130Smav Hope it will be input monitoring. */ 3619230130Smav HDA_BOOTVERBOSE( 3620230130Smav device_printf(devinfo->dev, 3621230130Smav "Tracing other input monitors\n"); 3622230130Smav ); 3623230130Smav for (j = devinfo->startnode; j < devinfo->endnode; j++) { 3624230130Smav w = hdaa_widget_get(devinfo, j); 3625230130Smav if (w == NULL || w->enable == 0) 3626230130Smav continue; 3627230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 3628230130Smav continue; 3629230130Smav if (w->bindas < 0 || as[w->bindas].dir != HDAA_CTL_IN) 3630230130Smav continue; 3631230130Smav HDA_BOOTVERBOSE( 3632230130Smav device_printf(devinfo->dev, 3633230130Smav " Tracing nid %d to out\n", 3634230130Smav j); 3635230130Smav ); 3636230130Smav if (hdaa_audio_trace_to_out(devinfo, w->nid, 0)) { 3637230130Smav HDA_BOOTVERBOSE( 3638230130Smav device_printf(devinfo->dev, 3639230130Smav " nid %d is input monitor\n", 3640230130Smav w->nid); 3641230130Smav ); 3642230130Smav } 3643230130Smav } 3644230130Smav 3645230130Smav /* Beeper */ 3646230130Smav HDA_BOOTVERBOSE( 3647230130Smav device_printf(devinfo->dev, 3648230130Smav "Tracing beeper\n"); 3649230130Smav ); 3650230130Smav for (j = devinfo->startnode; j < devinfo->endnode; j++) { 3651230130Smav w = hdaa_widget_get(devinfo, j); 3652230130Smav if (w == NULL || w->enable == 0) 3653230130Smav continue; 3654230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET) 3655230130Smav continue; 3656230130Smav HDA_BOOTHVERBOSE( 3657230130Smav device_printf(devinfo->dev, 3658230130Smav " Tracing nid %d to out\n", 3659230130Smav j); 3660230130Smav ); 3661230130Smav if (hdaa_audio_trace_to_out(devinfo, w->nid, 0)) { 3662230130Smav HDA_BOOTVERBOSE( 3663230130Smav device_printf(devinfo->dev, 3664230130Smav " nid %d traced to out\n", 3665230130Smav j); 3666230130Smav ); 3667230130Smav } 3668230130Smav w->bindas = -2; 3669230130Smav } 3670230130Smav} 3671230130Smav 3672230130Smav/* 3673230130Smav * Bind assotiations to PCM channels 3674230130Smav */ 3675230130Smavstatic void 3676230130Smavhdaa_audio_bind_as(struct hdaa_devinfo *devinfo) 3677230130Smav{ 3678230130Smav struct hdaa_audio_as *as = devinfo->as; 3679230130Smav int i, j, cnt = 0, free; 3680230130Smav 3681230130Smav for (j = 0; j < devinfo->ascnt; j++) { 3682230130Smav if (as[j].enable) 3683230130Smav cnt += as[j].num_chans; 3684230130Smav } 3685230130Smav if (devinfo->num_chans == 0) { 3686230130Smav devinfo->chans = (struct hdaa_chan *)malloc( 3687230130Smav sizeof(struct hdaa_chan) * cnt, 3688230130Smav M_HDAA, M_ZERO | M_NOWAIT); 3689230130Smav if (devinfo->chans == NULL) { 3690230130Smav device_printf(devinfo->dev, 3691230130Smav "Channels memory allocation failed!\n"); 3692230130Smav return; 3693230130Smav } 3694230130Smav } else { 3695230130Smav devinfo->chans = (struct hdaa_chan *)realloc(devinfo->chans, 3696230130Smav sizeof(struct hdaa_chan) * (devinfo->num_chans + cnt), 3697230130Smav M_HDAA, M_ZERO | M_NOWAIT); 3698230130Smav if (devinfo->chans == NULL) { 3699230130Smav devinfo->num_chans = 0; 3700230130Smav device_printf(devinfo->dev, 3701230130Smav "Channels memory allocation failed!\n"); 3702230130Smav return; 3703230130Smav } 3704230130Smav /* Fixup relative pointers after realloc */ 3705230130Smav for (j = 0; j < devinfo->num_chans; j++) 3706230130Smav devinfo->chans[j].caps.fmtlist = devinfo->chans[j].fmtlist; 3707230130Smav } 3708230130Smav free = devinfo->num_chans; 3709230130Smav devinfo->num_chans += cnt; 3710230130Smav 3711230130Smav for (j = free; j < free + cnt; j++) { 3712230130Smav devinfo->chans[j].devinfo = devinfo; 3713230130Smav devinfo->chans[j].as = -1; 3714230130Smav } 3715230130Smav 3716230130Smav /* Assign associations in order of their numbers, */ 3717230130Smav for (j = 0; j < devinfo->ascnt; j++) { 3718230130Smav if (as[j].enable == 0) 3719230130Smav continue; 3720230130Smav for (i = 0; i < as[j].num_chans; i++) { 3721230130Smav devinfo->chans[free].as = j; 3722230130Smav devinfo->chans[free].asindex = i; 3723230130Smav devinfo->chans[free].dir = 3724230130Smav (as[j].dir == HDAA_CTL_IN) ? PCMDIR_REC : PCMDIR_PLAY; 3725230130Smav hdaa_pcmchannel_setup(&devinfo->chans[free]); 3726230130Smav as[j].chans[i] = free; 3727230130Smav free++; 3728230130Smav } 3729230130Smav } 3730230130Smav} 3731230130Smav 3732230130Smavstatic void 3733230130Smavhdaa_audio_disable_nonaudio(struct hdaa_devinfo *devinfo) 3734230130Smav{ 3735230130Smav struct hdaa_widget *w; 3736230130Smav int i; 3737230130Smav 3738230130Smav /* Disable power and volume widgets. */ 3739230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 3740230130Smav w = hdaa_widget_get(devinfo, i); 3741230130Smav if (w == NULL || w->enable == 0) 3742230130Smav continue; 3743230130Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_POWER_WIDGET || 3744230130Smav w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_VOLUME_WIDGET) { 3745230130Smav w->enable = 0; 3746230130Smav HDA_BOOTHVERBOSE( 3747230130Smav device_printf(devinfo->dev, 3748230130Smav " Disabling nid %d due to it's" 3749230130Smav " non-audio type.\n", 3750230130Smav w->nid); 3751230130Smav ); 3752230130Smav } 3753230130Smav } 3754230130Smav} 3755230130Smav 3756230130Smavstatic void 3757230130Smavhdaa_audio_disable_useless(struct hdaa_devinfo *devinfo) 3758230130Smav{ 3759230130Smav struct hdaa_widget *w, *cw; 3760230130Smav struct hdaa_audio_ctl *ctl; 3761230130Smav int done, found, i, j, k; 3762230130Smav 3763230130Smav /* Disable useless pins. */ 3764230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 3765230130Smav w = hdaa_widget_get(devinfo, i); 3766230130Smav if (w == NULL || w->enable == 0) 3767230130Smav continue; 3768230130Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) { 3769230130Smav if ((w->wclass.pin.config & 3770230130Smav HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK) == 3771230130Smav HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_NONE) { 3772230130Smav w->enable = 0; 3773230130Smav HDA_BOOTHVERBOSE( 3774230130Smav device_printf(devinfo->dev, 3775230130Smav " Disabling pin nid %d due" 3776230130Smav " to None connectivity.\n", 3777230130Smav w->nid); 3778230130Smav ); 3779230130Smav } else if ((w->wclass.pin.config & 3780230130Smav HDA_CONFIG_DEFAULTCONF_ASSOCIATION_MASK) == 0) { 3781230130Smav w->enable = 0; 3782230130Smav HDA_BOOTHVERBOSE( 3783230130Smav device_printf(devinfo->dev, 3784230130Smav " Disabling unassociated" 3785230130Smav " pin nid %d.\n", 3786230130Smav w->nid); 3787230130Smav ); 3788230130Smav } 3789230130Smav } 3790230130Smav } 3791230130Smav do { 3792230130Smav done = 1; 3793230130Smav /* Disable and mute controls for disabled widgets. */ 3794230130Smav i = 0; 3795230130Smav while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) { 3796230130Smav if (ctl->enable == 0) 3797230130Smav continue; 3798230130Smav if (ctl->widget->enable == 0 || 3799230130Smav (ctl->childwidget != NULL && 3800230130Smav ctl->childwidget->enable == 0)) { 3801230130Smav ctl->forcemute = 1; 3802230130Smav ctl->muted = HDAA_AMP_MUTE_ALL; 3803230130Smav ctl->left = 0; 3804230130Smav ctl->right = 0; 3805230130Smav ctl->enable = 0; 3806230130Smav if (ctl->ndir == HDAA_CTL_IN) 3807230130Smav ctl->widget->connsenable[ctl->index] = 0; 3808230130Smav done = 0; 3809230130Smav HDA_BOOTHVERBOSE( 3810230130Smav device_printf(devinfo->dev, 3811230130Smav " Disabling ctl %d nid %d cnid %d due" 3812230130Smav " to disabled widget.\n", i, 3813230130Smav ctl->widget->nid, 3814230130Smav (ctl->childwidget != NULL)? 3815230130Smav ctl->childwidget->nid:-1); 3816230130Smav ); 3817230130Smav } 3818230130Smav } 3819230130Smav /* Disable useless widgets. */ 3820230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 3821230130Smav w = hdaa_widget_get(devinfo, i); 3822230130Smav if (w == NULL || w->enable == 0) 3823230130Smav continue; 3824230130Smav /* Disable inputs with disabled child widgets. */ 3825230130Smav for (j = 0; j < w->nconns; j++) { 3826230130Smav if (w->connsenable[j]) { 3827230130Smav cw = hdaa_widget_get(devinfo, w->conns[j]); 3828230130Smav if (cw == NULL || cw->enable == 0) { 3829230130Smav w->connsenable[j] = 0; 3830230130Smav HDA_BOOTHVERBOSE( 3831230130Smav device_printf(devinfo->dev, 3832230130Smav " Disabling nid %d connection %d due" 3833230130Smav " to disabled child widget.\n", 3834230130Smav i, j); 3835230130Smav ); 3836230130Smav } 3837230130Smav } 3838230130Smav } 3839230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR && 3840230130Smav w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) 3841230130Smav continue; 3842230130Smav /* Disable mixers and selectors without inputs. */ 3843230130Smav found = 0; 3844230130Smav for (j = 0; j < w->nconns; j++) { 3845230130Smav if (w->connsenable[j]) { 3846230130Smav found = 1; 3847230130Smav break; 3848230130Smav } 3849230130Smav } 3850230130Smav if (found == 0) { 3851230130Smav w->enable = 0; 3852230130Smav done = 0; 3853230130Smav HDA_BOOTHVERBOSE( 3854230130Smav device_printf(devinfo->dev, 3855230130Smav " Disabling nid %d due to all it's" 3856230130Smav " inputs disabled.\n", w->nid); 3857230130Smav ); 3858230130Smav } 3859230130Smav /* Disable nodes without consumers. */ 3860230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR && 3861230130Smav w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) 3862230130Smav continue; 3863230130Smav found = 0; 3864230130Smav for (k = devinfo->startnode; k < devinfo->endnode; k++) { 3865230130Smav cw = hdaa_widget_get(devinfo, k); 3866230130Smav if (cw == NULL || cw->enable == 0) 3867230130Smav continue; 3868230130Smav for (j = 0; j < cw->nconns; j++) { 3869230130Smav if (cw->connsenable[j] && cw->conns[j] == i) { 3870230130Smav found = 1; 3871230130Smav break; 3872230130Smav } 3873230130Smav } 3874230130Smav } 3875230130Smav if (found == 0) { 3876230130Smav w->enable = 0; 3877230130Smav done = 0; 3878230130Smav HDA_BOOTHVERBOSE( 3879230130Smav device_printf(devinfo->dev, 3880230130Smav " Disabling nid %d due to all it's" 3881230130Smav " consumers disabled.\n", w->nid); 3882230130Smav ); 3883230130Smav } 3884230130Smav } 3885230130Smav } while (done == 0); 3886230130Smav 3887230130Smav} 3888230130Smav 3889230130Smavstatic void 3890230130Smavhdaa_audio_disable_unas(struct hdaa_devinfo *devinfo) 3891230130Smav{ 3892230130Smav struct hdaa_audio_as *as = devinfo->as; 3893230130Smav struct hdaa_widget *w, *cw; 3894230130Smav struct hdaa_audio_ctl *ctl; 3895230130Smav int i, j, k; 3896230130Smav 3897230130Smav /* Disable unassosiated widgets. */ 3898230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 3899230130Smav w = hdaa_widget_get(devinfo, i); 3900230130Smav if (w == NULL || w->enable == 0) 3901230130Smav continue; 3902230130Smav if (w->bindas == -1) { 3903230130Smav w->enable = 0; 3904230130Smav HDA_BOOTHVERBOSE( 3905230130Smav device_printf(devinfo->dev, 3906230130Smav " Disabling unassociated nid %d.\n", 3907230130Smav w->nid); 3908230130Smav ); 3909230130Smav } 3910230130Smav } 3911230130Smav /* Disable input connections on input pin and 3912230130Smav * output on output. */ 3913230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 3914230130Smav w = hdaa_widget_get(devinfo, i); 3915230130Smav if (w == NULL || w->enable == 0) 3916230130Smav continue; 3917230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 3918230130Smav continue; 3919230130Smav if (w->bindas < 0) 3920230130Smav continue; 3921230130Smav if (as[w->bindas].dir == HDAA_CTL_IN) { 3922230130Smav for (j = 0; j < w->nconns; j++) { 3923230130Smav if (w->connsenable[j] == 0) 3924230130Smav continue; 3925230130Smav w->connsenable[j] = 0; 3926230130Smav HDA_BOOTHVERBOSE( 3927230130Smav device_printf(devinfo->dev, 3928230130Smav " Disabling connection to input pin " 3929230130Smav "nid %d conn %d.\n", 3930230130Smav i, j); 3931230130Smav ); 3932230130Smav } 3933230130Smav ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, 3934230130Smav HDAA_CTL_IN, -1, 1); 3935230130Smav if (ctl && ctl->enable) { 3936230130Smav ctl->forcemute = 1; 3937230130Smav ctl->muted = HDAA_AMP_MUTE_ALL; 3938230130Smav ctl->left = 0; 3939230130Smav ctl->right = 0; 3940230130Smav ctl->enable = 0; 3941230130Smav } 3942230130Smav } else { 3943230130Smav ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, 3944230130Smav HDAA_CTL_OUT, -1, 1); 3945230130Smav if (ctl && ctl->enable) { 3946230130Smav ctl->forcemute = 1; 3947230130Smav ctl->muted = HDAA_AMP_MUTE_ALL; 3948230130Smav ctl->left = 0; 3949230130Smav ctl->right = 0; 3950230130Smav ctl->enable = 0; 3951230130Smav } 3952230130Smav for (k = devinfo->startnode; k < devinfo->endnode; k++) { 3953230130Smav cw = hdaa_widget_get(devinfo, k); 3954230130Smav if (cw == NULL || cw->enable == 0) 3955230130Smav continue; 3956230130Smav for (j = 0; j < cw->nconns; j++) { 3957230130Smav if (cw->connsenable[j] && cw->conns[j] == i) { 3958230130Smav cw->connsenable[j] = 0; 3959230130Smav HDA_BOOTHVERBOSE( 3960230130Smav device_printf(devinfo->dev, 3961230130Smav " Disabling connection from output pin " 3962230130Smav "nid %d conn %d cnid %d.\n", 3963230130Smav k, j, i); 3964230130Smav ); 3965230130Smav if (cw->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX && 3966230130Smav cw->nconns > 1) 3967230130Smav continue; 3968230130Smav ctl = hdaa_audio_ctl_amp_get(devinfo, k, 3969230130Smav HDAA_CTL_IN, j, 1); 3970230130Smav if (ctl && ctl->enable) { 3971230130Smav ctl->forcemute = 1; 3972230130Smav ctl->muted = HDAA_AMP_MUTE_ALL; 3973230130Smav ctl->left = 0; 3974230130Smav ctl->right = 0; 3975230130Smav ctl->enable = 0; 3976230130Smav } 3977230130Smav } 3978230130Smav } 3979230130Smav } 3980230130Smav } 3981230130Smav } 3982230130Smav} 3983230130Smav 3984230130Smavstatic void 3985230130Smavhdaa_audio_disable_notselected(struct hdaa_devinfo *devinfo) 3986230130Smav{ 3987230130Smav struct hdaa_audio_as *as = devinfo->as; 3988230130Smav struct hdaa_widget *w; 3989230130Smav int i, j; 3990230130Smav 3991230130Smav /* On playback path we can safely disable all unseleted inputs. */ 3992230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 3993230130Smav w = hdaa_widget_get(devinfo, i); 3994230130Smav if (w == NULL || w->enable == 0) 3995230130Smav continue; 3996230130Smav if (w->nconns <= 1) 3997230130Smav continue; 3998230130Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) 3999230130Smav continue; 4000230130Smav if (w->bindas < 0 || as[w->bindas].dir == HDAA_CTL_IN) 4001230130Smav continue; 4002230130Smav for (j = 0; j < w->nconns; j++) { 4003230130Smav if (w->connsenable[j] == 0) 4004230130Smav continue; 4005230130Smav if (w->selconn < 0 || w->selconn == j) 4006230130Smav continue; 4007230130Smav w->connsenable[j] = 0; 4008230130Smav HDA_BOOTHVERBOSE( 4009230130Smav device_printf(devinfo->dev, 4010230130Smav " Disabling unselected connection " 4011230130Smav "nid %d conn %d.\n", 4012230130Smav i, j); 4013230130Smav ); 4014230130Smav } 4015230130Smav } 4016230130Smav} 4017230130Smav 4018230130Smavstatic void 4019230130Smavhdaa_audio_disable_crossas(struct hdaa_devinfo *devinfo) 4020230130Smav{ 4021230130Smav struct hdaa_audio_as *ases = devinfo->as; 4022230130Smav struct hdaa_widget *w, *cw; 4023230130Smav struct hdaa_audio_ctl *ctl; 4024230130Smav int i, j; 4025230130Smav 4026230130Smav /* Disable crossassociatement and unwanted crosschannel connections. */ 4027230130Smav /* ... using selectors */ 4028230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 4029230130Smav w = hdaa_widget_get(devinfo, i); 4030230130Smav if (w == NULL || w->enable == 0) 4031230130Smav continue; 4032230130Smav if (w->nconns <= 1) 4033230130Smav continue; 4034230130Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) 4035230130Smav continue; 4036230130Smav /* Allow any -> mix */ 4037230130Smav if (w->bindas == -2) 4038230130Smav continue; 4039230130Smav for (j = 0; j < w->nconns; j++) { 4040230130Smav if (w->connsenable[j] == 0) 4041230130Smav continue; 4042230130Smav cw = hdaa_widget_get(devinfo, w->conns[j]); 4043230130Smav if (cw == NULL || w->enable == 0) 4044230130Smav continue; 4045230130Smav /* Allow mix -> out. */ 4046230130Smav if (cw->bindas == -2 && w->bindas >= 0 && 4047230130Smav ases[w->bindas].dir == HDAA_CTL_OUT) 4048230130Smav continue; 4049230130Smav /* Allow mix -> mixed-in. */ 4050230130Smav if (cw->bindas == -2 && w->bindas >= 0 && 4051230130Smav ases[w->bindas].mixed) 4052230130Smav continue; 4053230130Smav /* Allow in -> mix. */ 4054230130Smav if ((w->pflags & HDAA_ADC_MONITOR) && 4055230130Smav cw->bindas >= 0 && 4056230130Smav ases[cw->bindas].dir == HDAA_CTL_IN) 4057230130Smav continue; 4058230130Smav /* Allow if have common as/seqs. */ 4059230130Smav if (w->bindas == cw->bindas && 4060230130Smav (w->bindseqmask & cw->bindseqmask) != 0) 4061230130Smav continue; 4062230130Smav w->connsenable[j] = 0; 4063230130Smav HDA_BOOTHVERBOSE( 4064230130Smav device_printf(devinfo->dev, 4065230130Smav " Disabling crossassociatement connection " 4066230130Smav "nid %d conn %d cnid %d.\n", 4067230130Smav i, j, cw->nid); 4068230130Smav ); 4069230130Smav } 4070230130Smav } 4071230130Smav /* ... using controls */ 4072230130Smav i = 0; 4073230130Smav while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) { 4074230130Smav if (ctl->enable == 0 || ctl->childwidget == NULL) 4075230130Smav continue; 4076230130Smav /* Allow any -> mix */ 4077230130Smav if (ctl->widget->bindas == -2) 4078230130Smav continue; 4079230130Smav /* Allow mix -> out. */ 4080230130Smav if (ctl->childwidget->bindas == -2 && 4081230130Smav ctl->widget->bindas >= 0 && 4082230130Smav ases[ctl->widget->bindas].dir == HDAA_CTL_OUT) 4083230130Smav continue; 4084230130Smav /* Allow mix -> mixed-in. */ 4085230130Smav if (ctl->childwidget->bindas == -2 && 4086230130Smav ctl->widget->bindas >= 0 && 4087230130Smav ases[ctl->widget->bindas].mixed) 4088230130Smav continue; 4089230130Smav /* Allow in -> mix. */ 4090230130Smav if ((ctl->widget->pflags & HDAA_ADC_MONITOR) && 4091230130Smav ctl->childwidget->bindas >= 0 && 4092230130Smav ases[ctl->childwidget->bindas].dir == HDAA_CTL_IN) 4093230130Smav continue; 4094230130Smav /* Allow if have common as/seqs. */ 4095230130Smav if (ctl->widget->bindas == ctl->childwidget->bindas && 4096230130Smav (ctl->widget->bindseqmask & ctl->childwidget->bindseqmask) != 0) 4097230130Smav continue; 4098230130Smav ctl->forcemute = 1; 4099230130Smav ctl->muted = HDAA_AMP_MUTE_ALL; 4100230130Smav ctl->left = 0; 4101230130Smav ctl->right = 0; 4102230130Smav ctl->enable = 0; 4103230130Smav if (ctl->ndir == HDAA_CTL_IN) 4104230130Smav ctl->widget->connsenable[ctl->index] = 0; 4105230130Smav HDA_BOOTHVERBOSE( 4106230130Smav device_printf(devinfo->dev, 4107230130Smav " Disabling crossassociatement connection " 4108230130Smav "ctl %d nid %d cnid %d.\n", i, 4109230130Smav ctl->widget->nid, 4110230130Smav ctl->childwidget->nid); 4111230130Smav ); 4112230130Smav } 4113230130Smav 4114230130Smav} 4115230130Smav 4116230130Smav/* 4117230451Smav * Find controls to control amplification for source and calculate possible 4118230451Smav * amplification range. 4119230130Smav */ 4120230130Smavstatic int 4121230130Smavhdaa_audio_ctl_source_amp(struct hdaa_devinfo *devinfo, nid_t nid, int index, 4122230451Smav int ossdev, int ctlable, int depth, int *minamp, int *maxamp) 4123230130Smav{ 4124230130Smav struct hdaa_widget *w, *wc; 4125230130Smav struct hdaa_audio_ctl *ctl; 4126230451Smav int i, j, conns = 0, tminamp, tmaxamp, cminamp, cmaxamp, found = 0; 4127230130Smav 4128230130Smav if (depth > HDA_PARSE_MAXDEPTH) 4129230451Smav return (found); 4130230130Smav 4131230130Smav w = hdaa_widget_get(devinfo, nid); 4132230130Smav if (w == NULL || w->enable == 0) 4133230451Smav return (found); 4134230130Smav 4135230130Smav /* Count number of active inputs. */ 4136230130Smav if (depth > 0) { 4137230130Smav for (j = 0; j < w->nconns; j++) { 4138230451Smav if (!w->connsenable[j]) 4139230451Smav continue; 4140230451Smav conns++; 4141230130Smav } 4142230130Smav } 4143230130Smav 4144230130Smav /* If this is not a first step - use input mixer. 4145230130Smav Pins have common input ctl so care must be taken. */ 4146230130Smav if (depth > 0 && ctlable && (conns == 1 || 4147230130Smav w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)) { 4148230130Smav ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, HDAA_CTL_IN, 4149230130Smav index, 1); 4150230130Smav if (ctl) { 4151230451Smav ctl->ossmask |= (1 << ossdev); 4152230451Smav found++; 4153230451Smav if (*minamp == *maxamp) { 4154230451Smav *minamp += MINQDB(ctl); 4155230451Smav *maxamp += MAXQDB(ctl); 4156230451Smav } 4157230130Smav } 4158230130Smav } 4159230130Smav 4160230130Smav /* If widget has own ossdev - not traverse it. 4161230130Smav It will be traversed on it's own. */ 4162230130Smav if (w->ossdev >= 0 && depth > 0) 4163230451Smav return (found); 4164230130Smav 4165230130Smav /* We must not traverse pin */ 4166230130Smav if ((w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT || 4167230130Smav w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) && 4168230130Smav depth > 0) 4169230451Smav return (found); 4170230130Smav 4171230130Smav /* record that this widget exports such signal, */ 4172230130Smav w->ossmask |= (1 << ossdev); 4173230130Smav 4174230451Smav /* 4175230451Smav * If signals mixed, we can't assign controls farther. 4176230130Smav * Ignore this on depth zero. Caller must knows why. 4177230130Smav */ 4178230451Smav if (conns > 1 && 4179230451Smav w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) 4180230130Smav ctlable = 0; 4181230130Smav 4182230130Smav if (ctlable) { 4183230130Smav ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, HDAA_CTL_OUT, -1, 1); 4184230130Smav if (ctl) { 4185230451Smav ctl->ossmask |= (1 << ossdev); 4186230451Smav found++; 4187230451Smav if (*minamp == *maxamp) { 4188230451Smav *minamp += MINQDB(ctl); 4189230451Smav *maxamp += MAXQDB(ctl); 4190230451Smav } 4191230130Smav } 4192230130Smav } 4193230130Smav 4194230451Smav cminamp = cmaxamp = 0; 4195230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 4196230130Smav wc = hdaa_widget_get(devinfo, i); 4197230130Smav if (wc == NULL || wc->enable == 0) 4198230130Smav continue; 4199230130Smav for (j = 0; j < wc->nconns; j++) { 4200230130Smav if (wc->connsenable[j] && wc->conns[j] == nid) { 4201230451Smav tminamp = tmaxamp = 0; 4202230451Smav found += hdaa_audio_ctl_source_amp(devinfo, 4203230451Smav wc->nid, j, ossdev, ctlable, depth + 1, 4204230451Smav &tminamp, &tmaxamp); 4205230451Smav if (cminamp == 0 && cmaxamp == 0) { 4206230451Smav cminamp = tminamp; 4207230451Smav cmaxamp = tmaxamp; 4208230451Smav } else if (tminamp != tmaxamp) { 4209230451Smav cminamp = imax(cminamp, tminamp); 4210230451Smav cmaxamp = imin(cmaxamp, tmaxamp); 4211230451Smav } 4212230130Smav } 4213230130Smav } 4214230130Smav } 4215230451Smav if (*minamp == *maxamp && cminamp < cmaxamp) { 4216230451Smav *minamp += cminamp; 4217230451Smav *maxamp += cmaxamp; 4218230451Smav } 4219230451Smav return (found); 4220230130Smav} 4221230130Smav 4222230130Smav/* 4223230451Smav * Find controls to control amplification for destination and calculate 4224230451Smav * possible amplification range. 4225230130Smav */ 4226230451Smavstatic int 4227230130Smavhdaa_audio_ctl_dest_amp(struct hdaa_devinfo *devinfo, nid_t nid, int index, 4228230451Smav int ossdev, int depth, int *minamp, int *maxamp) 4229230130Smav{ 4230230130Smav struct hdaa_audio_as *as = devinfo->as; 4231230130Smav struct hdaa_widget *w, *wc; 4232230130Smav struct hdaa_audio_ctl *ctl; 4233230451Smav int i, j, consumers, tminamp, tmaxamp, cminamp, cmaxamp, found = 0; 4234230130Smav 4235230130Smav if (depth > HDA_PARSE_MAXDEPTH) 4236230451Smav return (found); 4237230130Smav 4238230130Smav w = hdaa_widget_get(devinfo, nid); 4239230130Smav if (w == NULL || w->enable == 0) 4240230451Smav return (found); 4241230130Smav 4242230130Smav if (depth > 0) { 4243230130Smav /* If this node produce output for several consumers, 4244230130Smav we can't touch it. */ 4245230130Smav consumers = 0; 4246230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 4247230130Smav wc = hdaa_widget_get(devinfo, i); 4248230130Smav if (wc == NULL || wc->enable == 0) 4249230130Smav continue; 4250230130Smav for (j = 0; j < wc->nconns; j++) { 4251230130Smav if (wc->connsenable[j] && wc->conns[j] == nid) 4252230130Smav consumers++; 4253230130Smav } 4254230130Smav } 4255230130Smav /* The only exception is if real HP redirection is configured 4256230130Smav and this is a duplication point. 4257230130Smav XXX: Actually exception is not completely correct. 4258230130Smav XXX: Duplication point check is not perfect. */ 4259230130Smav if ((consumers == 2 && (w->bindas < 0 || 4260230130Smav as[w->bindas].hpredir < 0 || as[w->bindas].fakeredir || 4261230130Smav (w->bindseqmask & (1 << 15)) == 0)) || 4262230130Smav consumers > 2) 4263230451Smav return (found); 4264230130Smav 4265230130Smav /* Else use it's output mixer. */ 4266230130Smav ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, 4267230130Smav HDAA_CTL_OUT, -1, 1); 4268230130Smav if (ctl) { 4269230451Smav ctl->ossmask |= (1 << ossdev); 4270230451Smav found++; 4271230451Smav if (*minamp == *maxamp) { 4272230451Smav *minamp += MINQDB(ctl); 4273230451Smav *maxamp += MAXQDB(ctl); 4274230451Smav } 4275230130Smav } 4276230130Smav } 4277230130Smav 4278230130Smav /* We must not traverse pin */ 4279230130Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX && 4280230130Smav depth > 0) 4281230451Smav return (found); 4282230130Smav 4283230451Smav cminamp = cmaxamp = 0; 4284230130Smav for (i = 0; i < w->nconns; i++) { 4285230130Smav if (w->connsenable[i] == 0) 4286230130Smav continue; 4287230130Smav if (index >= 0 && i != index) 4288230130Smav continue; 4289230451Smav tminamp = tmaxamp = 0; 4290230130Smav ctl = hdaa_audio_ctl_amp_get(devinfo, w->nid, 4291230130Smav HDAA_CTL_IN, i, 1); 4292230130Smav if (ctl) { 4293230451Smav ctl->ossmask |= (1 << ossdev); 4294230451Smav found++; 4295230451Smav if (*minamp == *maxamp) { 4296230451Smav tminamp += MINQDB(ctl); 4297230451Smav tmaxamp += MAXQDB(ctl); 4298230451Smav } 4299230130Smav } 4300230451Smav found += hdaa_audio_ctl_dest_amp(devinfo, w->conns[i], -1, ossdev, 4301230451Smav depth + 1, &tminamp, &tmaxamp); 4302230451Smav if (cminamp == 0 && cmaxamp == 0) { 4303230451Smav cminamp = tminamp; 4304230451Smav cmaxamp = tmaxamp; 4305230451Smav } else if (tminamp != tmaxamp) { 4306230451Smav cminamp = imax(cminamp, tminamp); 4307230451Smav cmaxamp = imin(cmaxamp, tmaxamp); 4308230451Smav } 4309230130Smav } 4310230451Smav if (*minamp == *maxamp && cminamp < cmaxamp) { 4311230451Smav *minamp += cminamp; 4312230451Smav *maxamp += cmaxamp; 4313230451Smav } 4314230451Smav return (found); 4315230130Smav} 4316230130Smav 4317230130Smav/* 4318230130Smav * Assign OSS names to sound sources 4319230130Smav */ 4320230130Smavstatic void 4321230130Smavhdaa_audio_assign_names(struct hdaa_devinfo *devinfo) 4322230130Smav{ 4323230130Smav struct hdaa_audio_as *as = devinfo->as; 4324230130Smav struct hdaa_widget *w; 4325230130Smav int i, j; 4326230130Smav int type = -1, use, used = 0; 4327230130Smav static const int types[7][13] = { 4328230130Smav { SOUND_MIXER_LINE, SOUND_MIXER_LINE1, SOUND_MIXER_LINE2, 4329230130Smav SOUND_MIXER_LINE3, -1 }, /* line */ 4330230130Smav { SOUND_MIXER_MONITOR, SOUND_MIXER_MIC, -1 }, /* int mic */ 4331230130Smav { SOUND_MIXER_MIC, SOUND_MIXER_MONITOR, -1 }, /* ext mic */ 4332230130Smav { SOUND_MIXER_CD, -1 }, /* cd */ 4333230130Smav { SOUND_MIXER_SPEAKER, -1 }, /* speaker */ 4334230130Smav { SOUND_MIXER_DIGITAL1, SOUND_MIXER_DIGITAL2, SOUND_MIXER_DIGITAL3, 4335230130Smav -1 }, /* digital */ 4336230130Smav { SOUND_MIXER_LINE, SOUND_MIXER_LINE1, SOUND_MIXER_LINE2, 4337230130Smav SOUND_MIXER_LINE3, SOUND_MIXER_PHONEIN, SOUND_MIXER_PHONEOUT, 4338230130Smav SOUND_MIXER_VIDEO, SOUND_MIXER_RADIO, SOUND_MIXER_DIGITAL1, 4339230130Smav SOUND_MIXER_DIGITAL2, SOUND_MIXER_DIGITAL3, SOUND_MIXER_MONITOR, 4340230130Smav -1 } /* others */ 4341230130Smav }; 4342230130Smav 4343230130Smav /* Surely known names */ 4344230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 4345230130Smav w = hdaa_widget_get(devinfo, i); 4346230130Smav if (w == NULL || w->enable == 0) 4347230130Smav continue; 4348230130Smav if (w->bindas == -1) 4349230130Smav continue; 4350230130Smav use = -1; 4351230130Smav switch (w->type) { 4352230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX: 4353230130Smav if (as[w->bindas].dir == HDAA_CTL_OUT) 4354230130Smav break; 4355230130Smav type = -1; 4356230130Smav switch (w->wclass.pin.config & HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) { 4357230130Smav case HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN: 4358230130Smav type = 0; 4359230130Smav break; 4360230130Smav case HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN: 4361230130Smav if ((w->wclass.pin.config & HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK) 4362230130Smav == HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_JACK) 4363230130Smav break; 4364230130Smav type = 1; 4365230130Smav break; 4366230130Smav case HDA_CONFIG_DEFAULTCONF_DEVICE_CD: 4367230130Smav type = 3; 4368230130Smav break; 4369230130Smav case HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER: 4370230130Smav type = 4; 4371230130Smav break; 4372230130Smav case HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_IN: 4373230130Smav case HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_IN: 4374230130Smav type = 5; 4375230130Smav break; 4376230130Smav } 4377230130Smav if (type == -1) 4378230130Smav break; 4379230130Smav j = 0; 4380230130Smav while (types[type][j] >= 0 && 4381230130Smav (used & (1 << types[type][j])) != 0) { 4382230130Smav j++; 4383230130Smav } 4384230130Smav if (types[type][j] >= 0) 4385230130Smav use = types[type][j]; 4386230130Smav break; 4387230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT: 4388230130Smav use = SOUND_MIXER_PCM; 4389230130Smav break; 4390230130Smav case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET: 4391230130Smav use = SOUND_MIXER_SPEAKER; 4392230130Smav break; 4393230130Smav default: 4394230130Smav break; 4395230130Smav } 4396230130Smav if (use >= 0) { 4397230130Smav w->ossdev = use; 4398230130Smav used |= (1 << use); 4399230130Smav } 4400230130Smav } 4401230130Smav /* Semi-known names */ 4402230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 4403230130Smav w = hdaa_widget_get(devinfo, i); 4404230130Smav if (w == NULL || w->enable == 0) 4405230130Smav continue; 4406230130Smav if (w->ossdev >= 0) 4407230130Smav continue; 4408230130Smav if (w->bindas == -1) 4409230130Smav continue; 4410230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 4411230130Smav continue; 4412230130Smav if (as[w->bindas].dir == HDAA_CTL_OUT) 4413230130Smav continue; 4414230130Smav type = -1; 4415230130Smav switch (w->wclass.pin.config & HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) { 4416230130Smav case HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_OUT: 4417230130Smav case HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER: 4418230130Smav case HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT: 4419230130Smav case HDA_CONFIG_DEFAULTCONF_DEVICE_AUX: 4420230130Smav type = 0; 4421230130Smav break; 4422230130Smav case HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN: 4423230130Smav type = 2; 4424230130Smav break; 4425230130Smav case HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_OUT: 4426230130Smav case HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_OUT: 4427230130Smav type = 5; 4428230130Smav break; 4429230130Smav } 4430230130Smav if (type == -1) 4431230130Smav break; 4432230130Smav j = 0; 4433230130Smav while (types[type][j] >= 0 && 4434230130Smav (used & (1 << types[type][j])) != 0) { 4435230130Smav j++; 4436230130Smav } 4437230130Smav if (types[type][j] >= 0) { 4438230130Smav w->ossdev = types[type][j]; 4439230130Smav used |= (1 << types[type][j]); 4440230130Smav } 4441230130Smav } 4442230130Smav /* Others */ 4443230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 4444230130Smav w = hdaa_widget_get(devinfo, i); 4445230130Smav if (w == NULL || w->enable == 0) 4446230130Smav continue; 4447230130Smav if (w->ossdev >= 0) 4448230130Smav continue; 4449230130Smav if (w->bindas == -1) 4450230130Smav continue; 4451230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 4452230130Smav continue; 4453230130Smav if (as[w->bindas].dir == HDAA_CTL_OUT) 4454230130Smav continue; 4455230130Smav j = 0; 4456230130Smav while (types[6][j] >= 0 && 4457230130Smav (used & (1 << types[6][j])) != 0) { 4458230130Smav j++; 4459230130Smav } 4460230130Smav if (types[6][j] >= 0) { 4461230130Smav w->ossdev = types[6][j]; 4462230130Smav used |= (1 << types[6][j]); 4463230130Smav } 4464230130Smav } 4465230130Smav} 4466230130Smav 4467230130Smavstatic void 4468230130Smavhdaa_audio_build_tree(struct hdaa_devinfo *devinfo) 4469230130Smav{ 4470230130Smav struct hdaa_audio_as *as = devinfo->as; 4471230130Smav int j, res; 4472230130Smav 4473230130Smav /* Trace all associations in order of their numbers. */ 4474230130Smav for (j = 0; j < devinfo->ascnt; j++) { 4475230130Smav if (as[j].enable == 0) 4476230130Smav continue; 4477230130Smav HDA_BOOTVERBOSE( 4478230130Smav device_printf(devinfo->dev, 4479230130Smav "Tracing association %d (%d)\n", j, as[j].index); 4480230130Smav ); 4481230130Smav if (as[j].dir == HDAA_CTL_OUT) { 4482230130Smavretry: 4483230130Smav res = hdaa_audio_trace_as_out(devinfo, j, 0); 4484230130Smav if (res == 0 && as[j].hpredir >= 0 && 4485230130Smav as[j].fakeredir == 0) { 4486230130Smav /* If CODEC can't do analog HP redirection 4487230130Smav try to make it using one more DAC. */ 4488230130Smav as[j].fakeredir = 1; 4489230130Smav goto retry; 4490230130Smav } 4491230130Smav } else if (as[j].mixed) 4492230130Smav res = hdaa_audio_trace_as_in(devinfo, j); 4493230130Smav else 4494230130Smav res = hdaa_audio_trace_as_in_mch(devinfo, j, 0); 4495230130Smav if (res) { 4496230130Smav HDA_BOOTVERBOSE( 4497230130Smav device_printf(devinfo->dev, 4498230130Smav "Association %d (%d) trace succeeded\n", 4499230130Smav j, as[j].index); 4500230130Smav ); 4501230130Smav } else { 4502230130Smav HDA_BOOTVERBOSE( 4503230130Smav device_printf(devinfo->dev, 4504230130Smav "Association %d (%d) trace failed\n", 4505230130Smav j, as[j].index); 4506230130Smav ); 4507230130Smav as[j].enable = 0; 4508230130Smav } 4509230130Smav } 4510230130Smav 4511230130Smav /* Look for additional DACs/ADCs. */ 4512230130Smav for (j = 0; j < devinfo->ascnt; j++) { 4513230130Smav if (as[j].enable == 0) 4514230130Smav continue; 4515230130Smav hdaa_audio_adddac(devinfo, j); 4516230130Smav } 4517230130Smav 4518230130Smav /* Trace mixer and beeper pseudo associations. */ 4519230130Smav hdaa_audio_trace_as_extra(devinfo); 4520230130Smav} 4521230130Smav 4522230451Smav/* 4523230451Smav * Store in pdevinfo new data about whether and how we can control signal 4524230451Smav * for OSS device to/from specified widget. 4525230451Smav */ 4526230130Smavstatic void 4527230451Smavhdaa_adjust_amp(struct hdaa_widget *w, int ossdev, 4528230451Smav int found, int minamp, int maxamp) 4529230451Smav{ 4530230451Smav struct hdaa_devinfo *devinfo = w->devinfo; 4531230451Smav struct hdaa_pcm_devinfo *pdevinfo; 4532230451Smav 4533230451Smav if (w->bindas >= 0) 4534230451Smav pdevinfo = devinfo->as[w->bindas].pdevinfo; 4535230451Smav else 4536230451Smav pdevinfo = &devinfo->devs[0]; 4537230451Smav if (found) 4538230451Smav pdevinfo->ossmask |= (1 << ossdev); 4539230451Smav if (minamp == 0 && maxamp == 0) 4540230451Smav return; 4541230451Smav if (pdevinfo->minamp[ossdev] == 0 && pdevinfo->maxamp[ossdev] == 0) { 4542230451Smav pdevinfo->minamp[ossdev] = minamp; 4543230451Smav pdevinfo->maxamp[ossdev] = maxamp; 4544230451Smav } else { 4545230451Smav pdevinfo->minamp[ossdev] = imax(pdevinfo->minamp[ossdev], minamp); 4546230451Smav pdevinfo->maxamp[ossdev] = imin(pdevinfo->maxamp[ossdev], maxamp); 4547230451Smav } 4548230451Smav} 4549230451Smav 4550230451Smav/* 4551230451Smav * Trace signals from/to all possible sources/destionstions to find possible 4552230451Smav * recording sources, OSS device control ranges and to assign controls. 4553230451Smav */ 4554230451Smavstatic void 4555230130Smavhdaa_audio_assign_mixers(struct hdaa_devinfo *devinfo) 4556230130Smav{ 4557230130Smav struct hdaa_audio_as *as = devinfo->as; 4558230130Smav struct hdaa_widget *w, *cw; 4559230451Smav int i, j, minamp, maxamp, found; 4560230130Smav 4561230130Smav /* Assign mixers to the tree. */ 4562230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 4563230130Smav w = hdaa_widget_get(devinfo, i); 4564230130Smav if (w == NULL || w->enable == 0) 4565230130Smav continue; 4566230451Smav minamp = maxamp = 0; 4567230130Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT || 4568230130Smav w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET || 4569230130Smav (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX && 4570230130Smav as[w->bindas].dir == HDAA_CTL_IN)) { 4571230130Smav if (w->ossdev < 0) 4572230130Smav continue; 4573230451Smav found = hdaa_audio_ctl_source_amp(devinfo, w->nid, -1, 4574230451Smav w->ossdev, 1, 0, &minamp, &maxamp); 4575230451Smav hdaa_adjust_amp(w, w->ossdev, found, minamp, maxamp); 4576230130Smav } else if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) { 4577230451Smav found = hdaa_audio_ctl_dest_amp(devinfo, w->nid, -1, 4578230451Smav SOUND_MIXER_RECLEV, 0, &minamp, &maxamp); 4579230451Smav hdaa_adjust_amp(w, SOUND_MIXER_RECLEV, found, minamp, maxamp); 4580230130Smav } else if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX && 4581230130Smav as[w->bindas].dir == HDAA_CTL_OUT) { 4582230451Smav found = hdaa_audio_ctl_dest_amp(devinfo, w->nid, -1, 4583230451Smav SOUND_MIXER_VOLUME, 0, &minamp, &maxamp); 4584230451Smav hdaa_adjust_amp(w, SOUND_MIXER_VOLUME, found, minamp, maxamp); 4585230130Smav } 4586230130Smav if (w->ossdev == SOUND_MIXER_IMIX) { 4587230451Smav minamp = maxamp = 0; 4588230451Smav found = hdaa_audio_ctl_source_amp(devinfo, w->nid, -1, 4589230451Smav w->ossdev, 1, 0, &minamp, &maxamp); 4590230451Smav if (minamp == maxamp) { 4591230130Smav /* If we are unable to control input monitor 4592230130Smav as source - try to control it as destination. */ 4593230451Smav found += hdaa_audio_ctl_dest_amp(devinfo, w->nid, -1, 4594230451Smav w->ossdev, 0, &minamp, &maxamp); 4595230451Smav w->pflags |= HDAA_IMIX_AS_DST; 4596230130Smav } 4597230451Smav hdaa_adjust_amp(w, w->ossdev, found, minamp, maxamp); 4598230130Smav } 4599230130Smav if (w->pflags & HDAA_ADC_MONITOR) { 4600230130Smav for (j = 0; j < w->nconns; j++) { 4601230130Smav if (!w->connsenable[j]) 4602230130Smav continue; 4603230130Smav cw = hdaa_widget_get(devinfo, w->conns[j]); 4604230130Smav if (cw == NULL || cw->enable == 0) 4605230130Smav continue; 4606230130Smav if (cw->bindas == -1) 4607230130Smav continue; 4608230130Smav if (cw->bindas >= 0 && 4609230130Smav as[cw->bindas].dir != HDAA_CTL_IN) 4610230130Smav continue; 4611230451Smav minamp = maxamp = 0; 4612230451Smav found = hdaa_audio_ctl_dest_amp(devinfo, 4613230451Smav w->nid, j, SOUND_MIXER_IGAIN, 0, 4614230451Smav &minamp, &maxamp); 4615230451Smav hdaa_adjust_amp(w, SOUND_MIXER_IGAIN, 4616230451Smav found, minamp, maxamp); 4617230130Smav } 4618230130Smav } 4619230130Smav } 4620230130Smav} 4621230130Smav 4622230130Smavstatic void 4623230130Smavhdaa_audio_prepare_pin_ctrl(struct hdaa_devinfo *devinfo) 4624230130Smav{ 4625230130Smav struct hdaa_audio_as *as = devinfo->as; 4626230130Smav struct hdaa_widget *w; 4627230130Smav uint32_t pincap; 4628230130Smav int i; 4629230130Smav 4630230130Smav for (i = 0; i < devinfo->nodecnt; i++) { 4631230130Smav w = &devinfo->widget[i]; 4632230130Smav if (w == NULL) 4633230130Smav continue; 4634230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX && 4635230130Smav w->waspin == 0) 4636230130Smav continue; 4637230130Smav 4638230130Smav pincap = w->wclass.pin.cap; 4639230130Smav 4640230130Smav /* Disable everything. */ 4641230130Smav w->wclass.pin.ctrl &= ~( 4642230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE | 4643230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE | 4644230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE | 4645230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK); 4646230130Smav 4647230130Smav if (w->enable == 0) { 4648230130Smav /* Pin is unused so left it disabled. */ 4649230130Smav continue; 4650230130Smav } else if (w->waspin) { 4651230130Smav /* Enable input for beeper input. */ 4652230130Smav w->wclass.pin.ctrl |= 4653230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE; 4654230130Smav } else if (w->bindas < 0 || as[w->bindas].enable == 0) { 4655230130Smav /* Pin is unused so left it disabled. */ 4656230130Smav continue; 4657230130Smav } else if (as[w->bindas].dir == HDAA_CTL_IN) { 4658230130Smav /* Input pin, configure for input. */ 4659230130Smav if (HDA_PARAM_PIN_CAP_INPUT_CAP(pincap)) 4660230130Smav w->wclass.pin.ctrl |= 4661230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE; 4662230130Smav 4663230130Smav if ((devinfo->quirks & HDAA_QUIRK_IVREF100) && 4664230130Smav HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap)) 4665230130Smav w->wclass.pin.ctrl |= 4666230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE( 4667230130Smav HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_100); 4668230130Smav else if ((devinfo->quirks & HDAA_QUIRK_IVREF80) && 4669230130Smav HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap)) 4670230130Smav w->wclass.pin.ctrl |= 4671230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE( 4672230130Smav HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_80); 4673230130Smav else if ((devinfo->quirks & HDAA_QUIRK_IVREF50) && 4674230130Smav HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap)) 4675230130Smav w->wclass.pin.ctrl |= 4676230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE( 4677230130Smav HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_50); 4678230130Smav } else { 4679230130Smav /* Output pin, configure for output. */ 4680230130Smav if (HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap)) 4681230130Smav w->wclass.pin.ctrl |= 4682230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE; 4683230130Smav 4684230130Smav if (HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap) && 4685230130Smav (w->wclass.pin.config & 4686230130Smav HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) == 4687230130Smav HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT) 4688230130Smav w->wclass.pin.ctrl |= 4689230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE; 4690230130Smav 4691230130Smav if ((devinfo->quirks & HDAA_QUIRK_OVREF100) && 4692230130Smav HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap)) 4693230130Smav w->wclass.pin.ctrl |= 4694230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE( 4695230130Smav HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_100); 4696230130Smav else if ((devinfo->quirks & HDAA_QUIRK_OVREF80) && 4697230130Smav HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap)) 4698230130Smav w->wclass.pin.ctrl |= 4699230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE( 4700230130Smav HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_80); 4701230130Smav else if ((devinfo->quirks & HDAA_QUIRK_OVREF50) && 4702230130Smav HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap)) 4703230130Smav w->wclass.pin.ctrl |= 4704230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE( 4705230130Smav HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_50); 4706230130Smav } 4707230130Smav } 4708230130Smav} 4709230130Smav 4710230130Smavstatic void 4711230130Smavhdaa_audio_ctl_commit(struct hdaa_devinfo *devinfo) 4712230130Smav{ 4713230130Smav struct hdaa_audio_ctl *ctl; 4714230130Smav int i, z; 4715230130Smav 4716230130Smav i = 0; 4717230130Smav while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) { 4718230130Smav if (ctl->enable == 0 || ctl->ossmask != 0) { 4719230130Smav /* Mute disabled and mixer controllable controls. 4720230130Smav * Last will be initialized by mixer_init(). 4721230130Smav * This expected to reduce click on startup. */ 4722230130Smav hdaa_audio_ctl_amp_set(ctl, HDAA_AMP_MUTE_ALL, 0, 0); 4723230130Smav continue; 4724230130Smav } 4725230130Smav /* Init fixed controls to 0dB amplification. */ 4726230130Smav z = ctl->offset; 4727230130Smav if (z > ctl->step) 4728230130Smav z = ctl->step; 4729230130Smav hdaa_audio_ctl_amp_set(ctl, HDAA_AMP_MUTE_NONE, z, z); 4730230130Smav } 4731230130Smav} 4732230130Smav 4733230130Smavstatic void 4734230130Smavhdaa_gpio_commit(struct hdaa_devinfo *devinfo) 4735230130Smav{ 4736230130Smav uint32_t gdata, gmask, gdir; 4737230130Smav int i, numgpio; 4738230130Smav 4739230130Smav numgpio = HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap); 4740230130Smav if (devinfo->gpio != 0 && numgpio != 0) { 4741230130Smav gdata = hda_command(devinfo->dev, 4742230130Smav HDA_CMD_GET_GPIO_DATA(0, devinfo->nid)); 4743230130Smav gmask = hda_command(devinfo->dev, 4744230130Smav HDA_CMD_GET_GPIO_ENABLE_MASK(0, devinfo->nid)); 4745230130Smav gdir = hda_command(devinfo->dev, 4746230130Smav HDA_CMD_GET_GPIO_DIRECTION(0, devinfo->nid)); 4747230130Smav for (i = 0; i < numgpio; i++) { 4748230130Smav if ((devinfo->gpio & HDAA_GPIO_MASK(i)) == 4749230130Smav HDAA_GPIO_SET(i)) { 4750230130Smav gdata |= (1 << i); 4751230130Smav gmask |= (1 << i); 4752230130Smav gdir |= (1 << i); 4753230130Smav } else if ((devinfo->gpio & HDAA_GPIO_MASK(i)) == 4754230130Smav HDAA_GPIO_CLEAR(i)) { 4755230130Smav gdata &= ~(1 << i); 4756230130Smav gmask |= (1 << i); 4757230130Smav gdir |= (1 << i); 4758230130Smav } else if ((devinfo->gpio & HDAA_GPIO_MASK(i)) == 4759230130Smav HDAA_GPIO_DISABLE(i)) { 4760230130Smav gmask &= ~(1 << i); 4761230130Smav } else if ((devinfo->gpio & HDAA_GPIO_MASK(i)) == 4762230130Smav HDAA_GPIO_INPUT(i)) { 4763230130Smav gmask |= (1 << i); 4764230130Smav gdir &= ~(1 << i); 4765230130Smav } 4766230130Smav } 4767230130Smav HDA_BOOTVERBOSE( 4768230130Smav device_printf(devinfo->dev, "GPIO commit\n"); 4769230130Smav ); 4770230130Smav hda_command(devinfo->dev, 4771230130Smav HDA_CMD_SET_GPIO_ENABLE_MASK(0, devinfo->nid, gmask)); 4772230130Smav hda_command(devinfo->dev, 4773230130Smav HDA_CMD_SET_GPIO_DIRECTION(0, devinfo->nid, gdir)); 4774230130Smav hda_command(devinfo->dev, 4775230130Smav HDA_CMD_SET_GPIO_DATA(0, devinfo->nid, gdata)); 4776230130Smav HDA_BOOTVERBOSE( 4777230130Smav hdaa_dump_gpio(devinfo); 4778230130Smav ); 4779230130Smav } 4780230130Smav} 4781230130Smav 4782230130Smavstatic void 4783230130Smavhdaa_gpo_commit(struct hdaa_devinfo *devinfo) 4784230130Smav{ 4785230130Smav uint32_t gdata; 4786230130Smav int i, numgpo; 4787230130Smav 4788230130Smav numgpo = HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap); 4789230130Smav if (devinfo->gpo != 0 && numgpo != 0) { 4790230130Smav gdata = hda_command(devinfo->dev, 4791230130Smav HDA_CMD_GET_GPO_DATA(0, devinfo->nid)); 4792230130Smav for (i = 0; i < numgpo; i++) { 4793230130Smav if ((devinfo->gpio & HDAA_GPIO_MASK(i)) == 4794230130Smav HDAA_GPIO_SET(i)) { 4795230130Smav gdata |= (1 << i); 4796230130Smav } else if ((devinfo->gpio & HDAA_GPIO_MASK(i)) == 4797230130Smav HDAA_GPIO_CLEAR(i)) { 4798230130Smav gdata &= ~(1 << i); 4799230130Smav } 4800230130Smav } 4801230130Smav HDA_BOOTVERBOSE( 4802230130Smav device_printf(devinfo->dev, "GPO commit\n"); 4803230130Smav ); 4804230130Smav hda_command(devinfo->dev, 4805230130Smav HDA_CMD_SET_GPO_DATA(0, devinfo->nid, gdata)); 4806230130Smav HDA_BOOTVERBOSE( 4807230130Smav hdaa_dump_gpo(devinfo); 4808230130Smav ); 4809230130Smav } 4810230130Smav} 4811230130Smav 4812230130Smavstatic void 4813230130Smavhdaa_audio_commit(struct hdaa_devinfo *devinfo) 4814230130Smav{ 4815230130Smav struct hdaa_widget *w; 4816230130Smav int i; 4817230130Smav 4818230130Smav /* Commit controls. */ 4819230130Smav hdaa_audio_ctl_commit(devinfo); 4820230130Smav 4821230130Smav /* Commit selectors, pins and EAPD. */ 4822230130Smav for (i = 0; i < devinfo->nodecnt; i++) { 4823230130Smav w = &devinfo->widget[i]; 4824230130Smav if (w == NULL) 4825230130Smav continue; 4826230130Smav if (w->selconn == -1) 4827230130Smav w->selconn = 0; 4828230130Smav if (w->nconns > 0) 4829230130Smav hdaa_widget_connection_select(w, w->selconn); 4830230130Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX || 4831230130Smav w->waspin) { 4832230130Smav hda_command(devinfo->dev, 4833230130Smav HDA_CMD_SET_PIN_WIDGET_CTRL(0, w->nid, 4834230130Smav w->wclass.pin.ctrl)); 4835230130Smav } 4836230130Smav if (w->param.eapdbtl != HDA_INVALID) { 4837230130Smav uint32_t val; 4838230130Smav 4839230130Smav val = w->param.eapdbtl; 4840230130Smav if (devinfo->quirks & 4841230130Smav HDAA_QUIRK_EAPDINV) 4842230130Smav val ^= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD; 4843230130Smav hda_command(devinfo->dev, 4844230130Smav HDA_CMD_SET_EAPD_BTL_ENABLE(0, w->nid, 4845230130Smav val)); 4846230130Smav } 4847230130Smav } 4848230130Smav 4849230130Smav hdaa_gpio_commit(devinfo); 4850230130Smav hdaa_gpo_commit(devinfo); 4851230130Smav} 4852230130Smav 4853230130Smavstatic void 4854230130Smavhdaa_powerup(struct hdaa_devinfo *devinfo) 4855230130Smav{ 4856230130Smav int i; 4857230130Smav 4858230130Smav hda_command(devinfo->dev, 4859230130Smav HDA_CMD_SET_POWER_STATE(0, 4860230130Smav devinfo->nid, HDA_CMD_POWER_STATE_D0)); 4861230130Smav DELAY(100); 4862230130Smav 4863230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 4864230130Smav hda_command(devinfo->dev, 4865230130Smav HDA_CMD_SET_POWER_STATE(0, 4866230130Smav i, HDA_CMD_POWER_STATE_D0)); 4867230130Smav } 4868230130Smav DELAY(1000); 4869230130Smav} 4870230130Smav 4871230130Smavstatic int 4872230130Smavhdaa_pcmchannel_setup(struct hdaa_chan *ch) 4873230130Smav{ 4874230130Smav struct hdaa_devinfo *devinfo = ch->devinfo; 4875230130Smav struct hdaa_audio_as *as = devinfo->as; 4876230130Smav struct hdaa_widget *w; 4877230130Smav uint32_t cap, fmtcap, pcmcap; 4878230130Smav int i, j, ret, channels, onlystereo; 4879230130Smav uint16_t pinset; 4880230130Smav 4881230130Smav ch->caps = hdaa_caps; 4882230130Smav ch->caps.fmtlist = ch->fmtlist; 4883230130Smav ch->bit16 = 1; 4884230130Smav ch->bit32 = 0; 4885230130Smav ch->pcmrates[0] = 48000; 4886230130Smav ch->pcmrates[1] = 0; 4887230326Smav ch->stripecap = 0xff; 4888230130Smav 4889230130Smav ret = 0; 4890230130Smav channels = 0; 4891230130Smav onlystereo = 1; 4892230130Smav pinset = 0; 4893230130Smav fmtcap = devinfo->supp_stream_formats; 4894230130Smav pcmcap = devinfo->supp_pcm_size_rate; 4895230130Smav 4896230130Smav for (i = 0; i < 16; i++) { 4897230130Smav /* Check as is correct */ 4898230130Smav if (ch->as < 0) 4899230130Smav break; 4900230130Smav /* Cound only present DACs */ 4901230130Smav if (as[ch->as].dacs[ch->asindex][i] <= 0) 4902230130Smav continue; 4903230130Smav /* Ignore duplicates */ 4904230130Smav for (j = 0; j < ret; j++) { 4905230130Smav if (ch->io[j] == as[ch->as].dacs[ch->asindex][i]) 4906230130Smav break; 4907230130Smav } 4908230130Smav if (j < ret) 4909230130Smav continue; 4910230130Smav 4911230130Smav w = hdaa_widget_get(devinfo, as[ch->as].dacs[ch->asindex][i]); 4912230130Smav if (w == NULL || w->enable == 0) 4913230130Smav continue; 4914230130Smav cap = w->param.supp_stream_formats; 4915230130Smav if (!HDA_PARAM_SUPP_STREAM_FORMATS_PCM(cap) && 4916230130Smav !HDA_PARAM_SUPP_STREAM_FORMATS_AC3(cap)) 4917230130Smav continue; 4918230130Smav /* Many CODECs does not declare AC3 support on SPDIF. 4919230130Smav I don't beleave that they doesn't support it! */ 4920230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) 4921230130Smav cap |= HDA_PARAM_SUPP_STREAM_FORMATS_AC3_MASK; 4922230130Smav if (ret == 0) { 4923230130Smav fmtcap = cap; 4924230130Smav pcmcap = w->param.supp_pcm_size_rate; 4925230130Smav } else { 4926230130Smav fmtcap &= cap; 4927230130Smav pcmcap &= w->param.supp_pcm_size_rate; 4928230130Smav } 4929230130Smav ch->io[ret++] = as[ch->as].dacs[ch->asindex][i]; 4930230326Smav ch->stripecap &= w->wclass.conv.stripecap; 4931230130Smav /* Do not count redirection pin/dac channels. */ 4932230130Smav if (i == 15 && as[ch->as].hpredir >= 0) 4933230130Smav continue; 4934230130Smav channels += HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap) + 1; 4935230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap) != 1) 4936230130Smav onlystereo = 0; 4937230130Smav pinset |= (1 << i); 4938230130Smav } 4939230130Smav ch->io[ret] = -1; 4940230130Smav ch->channels = channels; 4941230130Smav 4942230130Smav if (as[ch->as].fakeredir) 4943230130Smav ret--; 4944230130Smav /* Standard speaks only about stereo pins and playback, ... */ 4945230130Smav if ((!onlystereo) || as[ch->as].mixed) 4946230130Smav pinset = 0; 4947230130Smav /* ..., but there it gives us info about speakers layout. */ 4948230130Smav as[ch->as].pinset = pinset; 4949230130Smav 4950230130Smav ch->supp_stream_formats = fmtcap; 4951230130Smav ch->supp_pcm_size_rate = pcmcap; 4952230130Smav 4953230130Smav /* 4954230130Smav * 8bit = 0 4955230130Smav * 16bit = 1 4956230130Smav * 20bit = 2 4957230130Smav * 24bit = 3 4958230130Smav * 32bit = 4 4959230130Smav */ 4960230130Smav if (ret > 0) { 4961230130Smav i = 0; 4962230130Smav if (HDA_PARAM_SUPP_STREAM_FORMATS_PCM(fmtcap)) { 4963230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16BIT(pcmcap)) 4964230130Smav ch->bit16 = 1; 4965230130Smav else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8BIT(pcmcap)) 4966230130Smav ch->bit16 = 0; 4967230488Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(pcmcap)) 4968230130Smav ch->bit32 = 3; 4969230130Smav else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(pcmcap)) 4970230130Smav ch->bit32 = 2; 4971230488Smav else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(pcmcap)) 4972230488Smav ch->bit32 = 4; 4973230130Smav if (!(devinfo->quirks & HDAA_QUIRK_FORCESTEREO)) { 4974230130Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 1, 0); 4975230130Smav if (ch->bit32) 4976230130Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 1, 0); 4977230130Smav } 4978230130Smav if (channels >= 2) { 4979230130Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 2, 0); 4980230130Smav if (ch->bit32) 4981230130Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 2, 0); 4982230130Smav } 4983230312Smav if (channels >= 3 && !onlystereo) { 4984230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 3, 0); 4985230312Smav if (ch->bit32) 4986230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 3, 0); 4987230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 3, 1); 4988230312Smav if (ch->bit32) 4989230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 3, 1); 4990230312Smav } 4991230312Smav if (channels >= 4) { 4992230130Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 4, 0); 4993230130Smav if (ch->bit32) 4994230130Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 4, 0); 4995230312Smav if (!onlystereo) { 4996230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 4, 1); 4997230312Smav if (ch->bit32) 4998230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 4, 1); 4999230312Smav } 5000230130Smav } 5001230312Smav if (channels >= 5 && !onlystereo) { 5002230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 5, 0); 5003230312Smav if (ch->bit32) 5004230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 5, 0); 5005230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 5, 1); 5006230312Smav if (ch->bit32) 5007230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 5, 1); 5008230312Smav } 5009230312Smav if (channels >= 6) { 5010230130Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 6, 1); 5011230130Smav if (ch->bit32) 5012230130Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 6, 1); 5013230312Smav if (!onlystereo) { 5014230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 6, 0); 5015230312Smav if (ch->bit32) 5016230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 6, 0); 5017230312Smav } 5018230130Smav } 5019230312Smav if (channels >= 7 && !onlystereo) { 5020230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 7, 0); 5021230312Smav if (ch->bit32) 5022230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 7, 0); 5023230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 7, 1); 5024230312Smav if (ch->bit32) 5025230312Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 7, 1); 5026230312Smav } 5027230312Smav if (channels >= 8) { 5028230130Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 8, 1); 5029230130Smav if (ch->bit32) 5030230130Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 8, 1); 5031230130Smav } 5032230130Smav } 5033230130Smav if (HDA_PARAM_SUPP_STREAM_FORMATS_AC3(fmtcap)) { 5034230130Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_AC3, 2, 0); 5035230513Smav if (channels >= 8) { 5036230513Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_AC3, 8, 0); 5037230513Smav ch->fmtlist[i++] = SND_FORMAT(AFMT_AC3, 8, 1); 5038230513Smav } 5039230130Smav } 5040230130Smav ch->fmtlist[i] = 0; 5041230130Smav i = 0; 5042230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8KHZ(pcmcap)) 5043230130Smav ch->pcmrates[i++] = 8000; 5044230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_11KHZ(pcmcap)) 5045230130Smav ch->pcmrates[i++] = 11025; 5046230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16KHZ(pcmcap)) 5047230130Smav ch->pcmrates[i++] = 16000; 5048230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_22KHZ(pcmcap)) 5049230130Smav ch->pcmrates[i++] = 22050; 5050230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32KHZ(pcmcap)) 5051230130Smav ch->pcmrates[i++] = 32000; 5052230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_44KHZ(pcmcap)) 5053230130Smav ch->pcmrates[i++] = 44100; 5054230130Smav /* if (HDA_PARAM_SUPP_PCM_SIZE_RATE_48KHZ(pcmcap)) */ 5055230130Smav ch->pcmrates[i++] = 48000; 5056230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_88KHZ(pcmcap)) 5057230130Smav ch->pcmrates[i++] = 88200; 5058230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_96KHZ(pcmcap)) 5059230130Smav ch->pcmrates[i++] = 96000; 5060230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_176KHZ(pcmcap)) 5061230130Smav ch->pcmrates[i++] = 176400; 5062230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_192KHZ(pcmcap)) 5063230130Smav ch->pcmrates[i++] = 192000; 5064230130Smav /* if (HDA_PARAM_SUPP_PCM_SIZE_RATE_384KHZ(pcmcap)) */ 5065230130Smav ch->pcmrates[i] = 0; 5066230130Smav if (i > 0) { 5067230130Smav ch->caps.minspeed = ch->pcmrates[0]; 5068230130Smav ch->caps.maxspeed = ch->pcmrates[i - 1]; 5069230130Smav } 5070230130Smav } 5071230130Smav 5072230130Smav return (ret); 5073230130Smav} 5074230130Smav 5075230130Smavstatic void 5076230451Smavhdaa_prepare_pcms(struct hdaa_devinfo *devinfo) 5077230130Smav{ 5078230130Smav struct hdaa_audio_as *as = devinfo->as; 5079230130Smav int i, j, k, apdev = 0, ardev = 0, dpdev = 0, drdev = 0; 5080230130Smav 5081230130Smav for (i = 0; i < devinfo->ascnt; i++) { 5082230130Smav if (as[i].enable == 0) 5083230130Smav continue; 5084230130Smav if (as[i].dir == HDAA_CTL_IN) { 5085230130Smav if (as[i].digital) 5086230130Smav drdev++; 5087230130Smav else 5088230130Smav ardev++; 5089230130Smav } else { 5090230130Smav if (as[i].digital) 5091230130Smav dpdev++; 5092230130Smav else 5093230130Smav apdev++; 5094230130Smav } 5095230130Smav } 5096230130Smav devinfo->num_devs = 5097230130Smav max(ardev, apdev) + max(drdev, dpdev); 5098230130Smav devinfo->devs = 5099230130Smav (struct hdaa_pcm_devinfo *)malloc( 5100230130Smav devinfo->num_devs * sizeof(struct hdaa_pcm_devinfo), 5101230130Smav M_HDAA, M_ZERO | M_NOWAIT); 5102230130Smav if (devinfo->devs == NULL) { 5103230130Smav device_printf(devinfo->dev, 5104230130Smav "Unable to allocate memory for devices\n"); 5105230130Smav return; 5106230130Smav } 5107230130Smav for (i = 0; i < devinfo->num_devs; i++) { 5108230130Smav devinfo->devs[i].index = i; 5109230130Smav devinfo->devs[i].devinfo = devinfo; 5110230130Smav devinfo->devs[i].playas = -1; 5111230130Smav devinfo->devs[i].recas = -1; 5112230130Smav devinfo->devs[i].digital = 255; 5113230130Smav } 5114230130Smav for (i = 0; i < devinfo->ascnt; i++) { 5115230130Smav if (as[i].enable == 0) 5116230130Smav continue; 5117230130Smav for (j = 0; j < devinfo->num_devs; j++) { 5118230130Smav if (devinfo->devs[j].digital != 255 && 5119230130Smav (!devinfo->devs[j].digital) != 5120230130Smav (!as[i].digital)) 5121230130Smav continue; 5122230130Smav if (as[i].dir == HDAA_CTL_IN) { 5123230130Smav if (devinfo->devs[j].recas >= 0) 5124230130Smav continue; 5125230130Smav devinfo->devs[j].recas = i; 5126230130Smav } else { 5127230130Smav if (devinfo->devs[j].playas >= 0) 5128230130Smav continue; 5129230130Smav devinfo->devs[j].playas = i; 5130230130Smav } 5131230451Smav as[i].pdevinfo = &devinfo->devs[j]; 5132230130Smav for (k = 0; k < as[i].num_chans; k++) { 5133230130Smav devinfo->chans[as[i].chans[k]].pdevinfo = 5134230130Smav &devinfo->devs[j]; 5135230130Smav } 5136230130Smav devinfo->devs[j].digital = as[i].digital; 5137230130Smav break; 5138230130Smav } 5139230130Smav } 5140230451Smav} 5141230451Smav 5142230451Smavstatic void 5143230451Smavhdaa_create_pcms(struct hdaa_devinfo *devinfo) 5144230451Smav{ 5145230451Smav int i; 5146230451Smav 5147230130Smav for (i = 0; i < devinfo->num_devs; i++) { 5148230130Smav struct hdaa_pcm_devinfo *pdevinfo = &devinfo->devs[i]; 5149230130Smav 5150230130Smav pdevinfo->dev = device_add_child(devinfo->dev, "pcm", -1); 5151230130Smav device_set_ivars(pdevinfo->dev, (void *)pdevinfo); 5152230130Smav } 5153230130Smav} 5154230130Smav 5155230130Smavstatic void 5156230130Smavhdaa_dump_ctls(struct hdaa_pcm_devinfo *pdevinfo, const char *banner, uint32_t flag) 5157230130Smav{ 5158230130Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 5159230130Smav struct hdaa_audio_ctl *ctl; 5160230130Smav char buf[64]; 5161230130Smav int i, j, printed; 5162230130Smav 5163230130Smav if (flag == 0) { 5164230130Smav flag = ~(SOUND_MASK_VOLUME | SOUND_MASK_PCM | 5165230130Smav SOUND_MASK_CD | SOUND_MASK_LINE | SOUND_MASK_RECLEV | 5166230130Smav SOUND_MASK_MIC | SOUND_MASK_SPEAKER | SOUND_MASK_IGAIN | 5167230130Smav SOUND_MASK_OGAIN | SOUND_MASK_IMIX | SOUND_MASK_MONITOR); 5168230130Smav } 5169230130Smav 5170230130Smav for (j = 0; j < SOUND_MIXER_NRDEVICES; j++) { 5171230130Smav if ((flag & (1 << j)) == 0) 5172230130Smav continue; 5173230130Smav i = 0; 5174230130Smav printed = 0; 5175230130Smav while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) { 5176230130Smav if (ctl->enable == 0 || 5177230130Smav ctl->widget->enable == 0) 5178230130Smav continue; 5179230130Smav if (!((pdevinfo->playas >= 0 && 5180230130Smav ctl->widget->bindas == pdevinfo->playas) || 5181230130Smav (pdevinfo->recas >= 0 && 5182230130Smav ctl->widget->bindas == pdevinfo->recas) || 5183230130Smav (ctl->widget->bindas == -2 && pdevinfo->index == 0))) 5184230130Smav continue; 5185230130Smav if ((ctl->ossmask & (1 << j)) == 0) 5186230130Smav continue; 5187230130Smav 5188230130Smav if (printed == 0) { 5189230130Smav device_printf(pdevinfo->dev, "\n"); 5190230130Smav if (banner != NULL) { 5191230130Smav device_printf(pdevinfo->dev, "%s", banner); 5192230130Smav } else { 5193230130Smav device_printf(pdevinfo->dev, "Unknown Ctl"); 5194230130Smav } 5195230451Smav printf(" (OSS: %s)", 5196230130Smav hdaa_audio_ctl_ossmixer_mask2allname(1 << j, 5197230130Smav buf, sizeof(buf))); 5198230451Smav if (pdevinfo->ossmask & (1 << j)) { 5199230451Smav printf(": %+d/%+ddB\n", 5200230451Smav pdevinfo->minamp[j] / 4, 5201230451Smav pdevinfo->maxamp[j] / 4); 5202230451Smav } else 5203230451Smav printf("\n"); 5204230130Smav device_printf(pdevinfo->dev, " |\n"); 5205230130Smav printed = 1; 5206230130Smav } 5207230130Smav device_printf(pdevinfo->dev, " +- ctl %2d (nid %3d %s", i, 5208230130Smav ctl->widget->nid, 5209230130Smav (ctl->ndir == HDAA_CTL_IN)?"in ":"out"); 5210230130Smav if (ctl->ndir == HDAA_CTL_IN && ctl->ndir == ctl->dir) 5211230130Smav printf(" %2d): ", ctl->index); 5212230130Smav else 5213230130Smav printf("): "); 5214230130Smav if (ctl->step > 0) { 5215230130Smav printf("%+d/%+ddB (%d steps)%s\n", 5216230451Smav MINQDB(ctl) / 4, 5217230451Smav MAXQDB(ctl) / 4, 5218230130Smav ctl->step + 1, 5219230130Smav ctl->mute?" + mute":""); 5220230130Smav } else 5221230130Smav printf("%s\n", ctl->mute?"mute":""); 5222230130Smav } 5223230130Smav } 5224230130Smav} 5225230130Smav 5226230130Smavstatic void 5227230130Smavhdaa_dump_audio_formats(device_t dev, uint32_t fcap, uint32_t pcmcap) 5228230130Smav{ 5229230130Smav uint32_t cap; 5230230130Smav 5231230130Smav cap = fcap; 5232230130Smav if (cap != 0) { 5233230130Smav device_printf(dev, " Stream cap: 0x%08x\n", cap); 5234230130Smav device_printf(dev, " "); 5235230130Smav if (HDA_PARAM_SUPP_STREAM_FORMATS_AC3(cap)) 5236230130Smav printf(" AC3"); 5237230130Smav if (HDA_PARAM_SUPP_STREAM_FORMATS_FLOAT32(cap)) 5238230130Smav printf(" FLOAT32"); 5239230130Smav if (HDA_PARAM_SUPP_STREAM_FORMATS_PCM(cap)) 5240230130Smav printf(" PCM"); 5241230130Smav printf("\n"); 5242230130Smav } 5243230130Smav cap = pcmcap; 5244230130Smav if (cap != 0) { 5245230130Smav device_printf(dev, " PCM cap: 0x%08x\n", cap); 5246230130Smav device_printf(dev, " "); 5247230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8BIT(cap)) 5248230130Smav printf(" 8"); 5249230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16BIT(cap)) 5250230130Smav printf(" 16"); 5251230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(cap)) 5252230130Smav printf(" 20"); 5253230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(cap)) 5254230130Smav printf(" 24"); 5255230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(cap)) 5256230130Smav printf(" 32"); 5257230130Smav printf(" bits,"); 5258230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8KHZ(cap)) 5259230130Smav printf(" 8"); 5260230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_11KHZ(cap)) 5261230130Smav printf(" 11"); 5262230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16KHZ(cap)) 5263230130Smav printf(" 16"); 5264230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_22KHZ(cap)) 5265230130Smav printf(" 22"); 5266230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32KHZ(cap)) 5267230130Smav printf(" 32"); 5268230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_44KHZ(cap)) 5269230130Smav printf(" 44"); 5270230130Smav printf(" 48"); 5271230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_88KHZ(cap)) 5272230130Smav printf(" 88"); 5273230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_96KHZ(cap)) 5274230130Smav printf(" 96"); 5275230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_176KHZ(cap)) 5276230130Smav printf(" 176"); 5277230130Smav if (HDA_PARAM_SUPP_PCM_SIZE_RATE_192KHZ(cap)) 5278230130Smav printf(" 192"); 5279230130Smav printf(" KHz\n"); 5280230130Smav } 5281230130Smav} 5282230130Smav 5283230130Smavstatic void 5284230130Smavhdaa_dump_pin(struct hdaa_widget *w) 5285230130Smav{ 5286230130Smav uint32_t pincap; 5287230130Smav 5288230130Smav pincap = w->wclass.pin.cap; 5289230130Smav 5290230130Smav device_printf(w->devinfo->dev, " Pin cap: 0x%08x\n", pincap); 5291230130Smav device_printf(w->devinfo->dev, " "); 5292230130Smav if (HDA_PARAM_PIN_CAP_IMP_SENSE_CAP(pincap)) 5293230130Smav printf(" ISC"); 5294230130Smav if (HDA_PARAM_PIN_CAP_TRIGGER_REQD(pincap)) 5295230130Smav printf(" TRQD"); 5296230130Smav if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(pincap)) 5297230130Smav printf(" PDC"); 5298230130Smav if (HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap)) 5299230130Smav printf(" HP"); 5300230130Smav if (HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap)) 5301230130Smav printf(" OUT"); 5302230130Smav if (HDA_PARAM_PIN_CAP_INPUT_CAP(pincap)) 5303230130Smav printf(" IN"); 5304230130Smav if (HDA_PARAM_PIN_CAP_BALANCED_IO_PINS(pincap)) 5305230130Smav printf(" BAL"); 5306230130Smav if (HDA_PARAM_PIN_CAP_HDMI(pincap)) 5307230130Smav printf(" HDMI"); 5308230130Smav if (HDA_PARAM_PIN_CAP_VREF_CTRL(pincap)) { 5309230130Smav printf(" VREF["); 5310230130Smav if (HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap)) 5311230130Smav printf(" 50"); 5312230130Smav if (HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap)) 5313230130Smav printf(" 80"); 5314230130Smav if (HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap)) 5315230130Smav printf(" 100"); 5316230130Smav if (HDA_PARAM_PIN_CAP_VREF_CTRL_GROUND(pincap)) 5317230130Smav printf(" GROUND"); 5318230130Smav if (HDA_PARAM_PIN_CAP_VREF_CTRL_HIZ(pincap)) 5319230130Smav printf(" HIZ"); 5320230130Smav printf(" ]"); 5321230130Smav } 5322230130Smav if (HDA_PARAM_PIN_CAP_EAPD_CAP(pincap)) 5323230130Smav printf(" EAPD"); 5324230130Smav if (HDA_PARAM_PIN_CAP_DP(pincap)) 5325230130Smav printf(" DP"); 5326230130Smav if (HDA_PARAM_PIN_CAP_HBR(pincap)) 5327230130Smav printf(" HBR"); 5328230130Smav printf("\n"); 5329230130Smav device_printf(w->devinfo->dev, " Pin config: 0x%08x\n", 5330230130Smav w->wclass.pin.config); 5331230130Smav device_printf(w->devinfo->dev, " Pin control: 0x%08x", w->wclass.pin.ctrl); 5332230130Smav if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE) 5333230130Smav printf(" HP"); 5334230130Smav if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE) 5335230130Smav printf(" IN"); 5336230130Smav if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE) 5337230130Smav printf(" OUT"); 5338230312Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) { 5339230312Smav if ((w->wclass.pin.ctrl & 5340230312Smav HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK) == 0x03) 5341230312Smav printf(" HBR"); 5342230312Smav else if ((w->wclass.pin.ctrl & 5343230312Smav HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK) != 0) 5344230312Smav printf(" EPTs"); 5345230312Smav } else { 5346230312Smav if ((w->wclass.pin.ctrl & 5347230312Smav HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK) != 0) 5348230312Smav printf(" VREFs"); 5349230312Smav } 5350230130Smav printf("\n"); 5351230130Smav} 5352230130Smav 5353230130Smavstatic void 5354230130Smavhdaa_dump_pin_config(struct hdaa_widget *w, uint32_t conf) 5355230130Smav{ 5356230130Smav 5357230130Smav device_printf(w->devinfo->dev, "%2d %08x %-2d %-2d " 5358230130Smav "%-13s %-5s %-7s %-10s %-7s %d%s\n", 5359230130Smav w->nid, conf, 5360230130Smav HDA_CONFIG_DEFAULTCONF_ASSOCIATION(conf), 5361230130Smav HDA_CONFIG_DEFAULTCONF_SEQUENCE(conf), 5362230130Smav HDA_DEVS[HDA_CONFIG_DEFAULTCONF_DEVICE(conf)], 5363230130Smav HDA_CONNS[HDA_CONFIG_DEFAULTCONF_CONNECTIVITY(conf)], 5364230130Smav HDA_CONNECTORS[HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE(conf)], 5365230130Smav HDA_LOCS[HDA_CONFIG_DEFAULTCONF_LOCATION(conf)], 5366230130Smav HDA_COLORS[HDA_CONFIG_DEFAULTCONF_COLOR(conf)], 5367230130Smav HDA_CONFIG_DEFAULTCONF_MISC(conf), 5368230130Smav (w->enable == 0)?" DISA":""); 5369230130Smav} 5370230130Smav 5371230130Smavstatic void 5372230130Smavhdaa_dump_pin_configs(struct hdaa_devinfo *devinfo) 5373230130Smav{ 5374230130Smav struct hdaa_widget *w; 5375230130Smav int i; 5376230130Smav 5377230130Smav device_printf(devinfo->dev, "nid 0x as seq " 5378230130Smav "device conn jack loc color misc\n"); 5379230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 5380230130Smav w = hdaa_widget_get(devinfo, i); 5381230130Smav if (w == NULL) 5382230130Smav continue; 5383230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 5384230130Smav continue; 5385230130Smav hdaa_dump_pin_config(w, w->wclass.pin.config); 5386230130Smav } 5387230130Smav} 5388230130Smav 5389230130Smavstatic void 5390230130Smavhdaa_dump_amp(device_t dev, uint32_t cap, char *banner) 5391230130Smav{ 5392230130Smav device_printf(dev, " %s amp: 0x%08x\n", banner, cap); 5393230130Smav device_printf(dev, " " 5394230130Smav "mute=%d step=%d size=%d offset=%d\n", 5395230130Smav HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(cap), 5396230130Smav HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(cap), 5397230130Smav HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(cap), 5398230130Smav HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(cap)); 5399230130Smav} 5400230130Smav 5401230130Smavstatic void 5402230130Smavhdaa_dump_nodes(struct hdaa_devinfo *devinfo) 5403230130Smav{ 5404230130Smav struct hdaa_widget *w, *cw; 5405230130Smav char buf[64]; 5406230130Smav int i, j; 5407230130Smav 5408230130Smav device_printf(devinfo->dev, "\n"); 5409230130Smav device_printf(devinfo->dev, "Default Parameter\n"); 5410230130Smav device_printf(devinfo->dev, "-----------------\n"); 5411230130Smav hdaa_dump_audio_formats(devinfo->dev, 5412230130Smav devinfo->supp_stream_formats, 5413230130Smav devinfo->supp_pcm_size_rate); 5414230130Smav device_printf(devinfo->dev, " IN amp: 0x%08x\n", 5415230130Smav devinfo->inamp_cap); 5416230130Smav device_printf(devinfo->dev, " OUT amp: 0x%08x\n", 5417230130Smav devinfo->outamp_cap); 5418230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 5419230130Smav w = hdaa_widget_get(devinfo, i); 5420230130Smav if (w == NULL) { 5421230130Smav device_printf(devinfo->dev, "Ghost widget nid=%d\n", i); 5422230130Smav continue; 5423230130Smav } 5424230130Smav device_printf(devinfo->dev, "\n"); 5425230130Smav device_printf(devinfo->dev, " nid: %d%s\n", w->nid, 5426230130Smav (w->enable == 0) ? " [DISABLED]" : ""); 5427230130Smav device_printf(devinfo->dev, " Name: %s\n", w->name); 5428230130Smav device_printf(devinfo->dev, " Widget cap: 0x%08x\n", 5429230130Smav w->param.widget_cap); 5430230130Smav if (w->param.widget_cap & 0x0ee1) { 5431230130Smav device_printf(devinfo->dev, " "); 5432230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_LR_SWAP(w->param.widget_cap)) 5433230130Smav printf(" LRSWAP"); 5434230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_POWER_CTRL(w->param.widget_cap)) 5435230130Smav printf(" PWR"); 5436230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) 5437230130Smav printf(" DIGITAL"); 5438230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_UNSOL_CAP(w->param.widget_cap)) 5439230130Smav printf(" UNSOL"); 5440230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_PROC_WIDGET(w->param.widget_cap)) 5441230130Smav printf(" PROC"); 5442230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_STRIPE(w->param.widget_cap)) 5443230326Smav printf(" STRIPE(x%d)", 5444230326Smav 1 << (fls(w->wclass.conv.stripecap) - 1)); 5445230130Smav j = HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap); 5446230130Smav if (j == 1) 5447230130Smav printf(" STEREO"); 5448230130Smav else if (j > 1) 5449230130Smav printf(" %dCH", j + 1); 5450230130Smav printf("\n"); 5451230130Smav } 5452230130Smav if (w->bindas != -1) { 5453230130Smav device_printf(devinfo->dev, " Association: %d (0x%08x)\n", 5454230130Smav w->bindas, w->bindseqmask); 5455230130Smav } 5456230130Smav if (w->ossmask != 0 || w->ossdev >= 0) { 5457230130Smav device_printf(devinfo->dev, " OSS: %s", 5458230130Smav hdaa_audio_ctl_ossmixer_mask2allname(w->ossmask, buf, sizeof(buf))); 5459230130Smav if (w->ossdev >= 0) 5460230451Smav printf(" (%s)", ossnames[w->ossdev]); 5461230130Smav printf("\n"); 5462230130Smav } 5463230130Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT || 5464230130Smav w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) { 5465230130Smav hdaa_dump_audio_formats(devinfo->dev, 5466230130Smav w->param.supp_stream_formats, 5467230130Smav w->param.supp_pcm_size_rate); 5468230130Smav } else if (w->type == 5469230130Smav HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX || w->waspin) 5470230130Smav hdaa_dump_pin(w); 5471230130Smav if (w->param.eapdbtl != HDA_INVALID) 5472230130Smav device_printf(devinfo->dev, " EAPD: 0x%08x\n", 5473230130Smav w->param.eapdbtl); 5474230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_OUT_AMP(w->param.widget_cap) && 5475230130Smav w->param.outamp_cap != 0) 5476230130Smav hdaa_dump_amp(devinfo->dev, w->param.outamp_cap, "Output"); 5477230130Smav if (HDA_PARAM_AUDIO_WIDGET_CAP_IN_AMP(w->param.widget_cap) && 5478230130Smav w->param.inamp_cap != 0) 5479230130Smav hdaa_dump_amp(devinfo->dev, w->param.inamp_cap, " Input"); 5480230130Smav if (w->nconns > 0) { 5481230130Smav device_printf(devinfo->dev, " connections: %d\n", w->nconns); 5482230130Smav device_printf(devinfo->dev, " |\n"); 5483230130Smav } 5484230130Smav for (j = 0; j < w->nconns; j++) { 5485230130Smav cw = hdaa_widget_get(devinfo, w->conns[j]); 5486230130Smav device_printf(devinfo->dev, " + %s<- nid=%d [%s]", 5487230130Smav (w->connsenable[j] == 0)?"[DISABLED] ":"", 5488230130Smav w->conns[j], (cw == NULL) ? "GHOST!" : cw->name); 5489230130Smav if (cw == NULL) 5490230130Smav printf(" [UNKNOWN]"); 5491230130Smav else if (cw->enable == 0) 5492230130Smav printf(" [DISABLED]"); 5493230130Smav if (w->nconns > 1 && w->selconn == j && w->type != 5494230130Smav HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) 5495230130Smav printf(" (selected)"); 5496230130Smav printf("\n"); 5497230130Smav } 5498230130Smav } 5499230130Smav 5500230130Smav} 5501230130Smav 5502230130Smavstatic void 5503230130Smavhdaa_dump_dst_nid(struct hdaa_pcm_devinfo *pdevinfo, nid_t nid, int depth) 5504230130Smav{ 5505230130Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 5506230130Smav struct hdaa_widget *w, *cw; 5507230130Smav char buf[64]; 5508230130Smav int i, printed = 0; 5509230130Smav 5510230130Smav if (depth > HDA_PARSE_MAXDEPTH) 5511230130Smav return; 5512230130Smav 5513230130Smav w = hdaa_widget_get(devinfo, nid); 5514230130Smav if (w == NULL || w->enable == 0) 5515230130Smav return; 5516230130Smav 5517230130Smav if (depth == 0) 5518230130Smav device_printf(pdevinfo->dev, "%*s", 4, ""); 5519230130Smav else 5520230130Smav device_printf(pdevinfo->dev, "%*s + <- ", 4 + (depth - 1) * 7, ""); 5521230130Smav printf("nid=%d [%s]", w->nid, w->name); 5522230130Smav 5523230130Smav if (depth > 0) { 5524230130Smav if (w->ossmask == 0) { 5525230130Smav printf("\n"); 5526230130Smav return; 5527230130Smav } 5528230130Smav printf(" [src: %s]", 5529230130Smav hdaa_audio_ctl_ossmixer_mask2allname( 5530230130Smav w->ossmask, buf, sizeof(buf))); 5531230130Smav if (w->ossdev >= 0) { 5532230130Smav printf("\n"); 5533230130Smav return; 5534230130Smav } 5535230130Smav } 5536230130Smav printf("\n"); 5537230130Smav 5538230130Smav for (i = 0; i < w->nconns; i++) { 5539230130Smav if (w->connsenable[i] == 0) 5540230130Smav continue; 5541230130Smav cw = hdaa_widget_get(devinfo, w->conns[i]); 5542230130Smav if (cw == NULL || cw->enable == 0 || cw->bindas == -1) 5543230130Smav continue; 5544230130Smav if (printed == 0) { 5545230130Smav device_printf(pdevinfo->dev, "%*s |\n", 4 + (depth) * 7, ""); 5546230130Smav printed = 1; 5547230130Smav } 5548230130Smav hdaa_dump_dst_nid(pdevinfo, w->conns[i], depth + 1); 5549230130Smav } 5550230130Smav 5551230130Smav} 5552230130Smav 5553230130Smavstatic void 5554230130Smavhdaa_dump_dac(struct hdaa_pcm_devinfo *pdevinfo) 5555230130Smav{ 5556230130Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 5557230130Smav struct hdaa_audio_as *as; 5558230130Smav struct hdaa_widget *w; 5559230130Smav int i, printed = 0; 5560230130Smav 5561230130Smav if (pdevinfo->playas < 0) 5562230130Smav return; 5563230130Smav 5564230130Smav as = &devinfo->as[pdevinfo->playas]; 5565230130Smav for (i = 0; i < 16; i++) { 5566230130Smav if (as->pins[i] <= 0) 5567230130Smav continue; 5568230130Smav w = hdaa_widget_get(devinfo, as->pins[i]); 5569230130Smav if (w == NULL || w->enable == 0) 5570230130Smav continue; 5571230130Smav if (printed == 0) { 5572230130Smav printed = 1; 5573230130Smav device_printf(pdevinfo->dev, "\n"); 5574230130Smav device_printf(pdevinfo->dev, "Playback:\n"); 5575230130Smav } 5576230130Smav device_printf(pdevinfo->dev, "\n"); 5577230130Smav hdaa_dump_dst_nid(pdevinfo, as->pins[i], 0); 5578230130Smav } 5579230130Smav} 5580230130Smav 5581230130Smavstatic void 5582230130Smavhdaa_dump_adc(struct hdaa_pcm_devinfo *pdevinfo) 5583230130Smav{ 5584230130Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 5585230130Smav struct hdaa_widget *w; 5586230130Smav int i; 5587230130Smav int printed = 0; 5588230130Smav 5589230130Smav if (pdevinfo->recas < 0) 5590230130Smav return; 5591230130Smav 5592230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 5593230130Smav w = hdaa_widget_get(devinfo, i); 5594230130Smav if (w == NULL || w->enable == 0) 5595230130Smav continue; 5596230130Smav if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) 5597230130Smav continue; 5598230130Smav if (w->bindas != pdevinfo->recas) 5599230130Smav continue; 5600230130Smav if (printed == 0) { 5601230130Smav printed = 1; 5602230130Smav device_printf(pdevinfo->dev, "\n"); 5603230130Smav device_printf(pdevinfo->dev, "Record:\n"); 5604230130Smav } 5605230130Smav device_printf(pdevinfo->dev, "\n"); 5606230130Smav hdaa_dump_dst_nid(pdevinfo, i, 0); 5607230130Smav } 5608230130Smav} 5609230130Smav 5610230130Smavstatic void 5611230130Smavhdaa_dump_mix(struct hdaa_pcm_devinfo *pdevinfo) 5612230130Smav{ 5613230130Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 5614230130Smav struct hdaa_widget *w; 5615230130Smav int i; 5616230130Smav int printed = 0; 5617230130Smav 5618230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 5619230130Smav w = hdaa_widget_get(devinfo, i); 5620230130Smav if (w == NULL || w->enable == 0) 5621230130Smav continue; 5622230130Smav if (w->ossdev != SOUND_MIXER_IMIX) 5623230130Smav continue; 5624230451Smav if (w->bindas != pdevinfo->recas) 5625230451Smav continue; 5626230130Smav if (printed == 0) { 5627230130Smav printed = 1; 5628230130Smav device_printf(pdevinfo->dev, "\n"); 5629230130Smav device_printf(pdevinfo->dev, "Input Mix:\n"); 5630230130Smav } 5631230130Smav device_printf(pdevinfo->dev, "\n"); 5632230130Smav hdaa_dump_dst_nid(pdevinfo, i, 0); 5633230130Smav } 5634230130Smav} 5635230130Smav 5636230130Smavstatic void 5637230130Smavhdaa_dump_pcmchannels(struct hdaa_pcm_devinfo *pdevinfo) 5638230130Smav{ 5639230130Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 5640230130Smav nid_t *nids; 5641230130Smav int chid, i; 5642230130Smav 5643230130Smav if (pdevinfo->playas >= 0) { 5644230130Smav device_printf(pdevinfo->dev, "\n"); 5645230130Smav device_printf(pdevinfo->dev, "Playback:\n"); 5646230130Smav device_printf(pdevinfo->dev, "\n"); 5647230130Smav chid = devinfo->as[pdevinfo->playas].chans[0]; 5648230130Smav hdaa_dump_audio_formats(pdevinfo->dev, 5649230130Smav devinfo->chans[chid].supp_stream_formats, 5650230130Smav devinfo->chans[chid].supp_pcm_size_rate); 5651230130Smav for (i = 0; i < devinfo->as[pdevinfo->playas].num_chans; i++) { 5652230130Smav chid = devinfo->as[pdevinfo->playas].chans[i]; 5653230130Smav device_printf(pdevinfo->dev, " DAC:"); 5654230130Smav for (nids = devinfo->chans[chid].io; *nids != -1; nids++) 5655230130Smav printf(" %d", *nids); 5656230130Smav printf("\n"); 5657230130Smav } 5658230130Smav } 5659230130Smav if (pdevinfo->recas >= 0) { 5660230130Smav device_printf(pdevinfo->dev, "\n"); 5661230130Smav device_printf(pdevinfo->dev, "Record:\n"); 5662230130Smav device_printf(pdevinfo->dev, "\n"); 5663230130Smav chid = devinfo->as[pdevinfo->recas].chans[0]; 5664230130Smav hdaa_dump_audio_formats(pdevinfo->dev, 5665230130Smav devinfo->chans[chid].supp_stream_formats, 5666230130Smav devinfo->chans[chid].supp_pcm_size_rate); 5667230130Smav for (i = 0; i < devinfo->as[pdevinfo->recas].num_chans; i++) { 5668230130Smav chid = devinfo->as[pdevinfo->recas].chans[i]; 5669230130Smav device_printf(pdevinfo->dev, " DAC:"); 5670230130Smav for (nids = devinfo->chans[chid].io; *nids != -1; nids++) 5671230130Smav printf(" %d", *nids); 5672230130Smav printf("\n"); 5673230130Smav } 5674230130Smav } 5675230130Smav} 5676230130Smav 5677230130Smavstatic void 5678230130Smavhdaa_pindump(device_t dev) 5679230130Smav{ 5680230130Smav struct hdaa_devinfo *devinfo = device_get_softc(dev); 5681230130Smav struct hdaa_widget *w; 5682230130Smav uint32_t res, pincap, delay; 5683230130Smav int i; 5684230130Smav 5685230130Smav device_printf(dev, "Dumping AFG pins:\n"); 5686230130Smav device_printf(dev, "nid 0x as seq " 5687230130Smav "device conn jack loc color misc\n"); 5688230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 5689230130Smav w = hdaa_widget_get(devinfo, i); 5690230130Smav if (w == NULL || w->type != 5691230130Smav HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 5692230130Smav continue; 5693230130Smav hdaa_dump_pin_config(w, w->wclass.pin.config); 5694230130Smav pincap = w->wclass.pin.cap; 5695230130Smav device_printf(dev, " Caps: %2s %3s %2s %4s %4s", 5696230130Smav HDA_PARAM_PIN_CAP_INPUT_CAP(pincap)?"IN":"", 5697230130Smav HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap)?"OUT":"", 5698230130Smav HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap)?"HP":"", 5699230130Smav HDA_PARAM_PIN_CAP_EAPD_CAP(pincap)?"EAPD":"", 5700230130Smav HDA_PARAM_PIN_CAP_VREF_CTRL(pincap)?"VREF":""); 5701230130Smav if (HDA_PARAM_PIN_CAP_IMP_SENSE_CAP(pincap) || 5702230130Smav HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(pincap)) { 5703230130Smav if (HDA_PARAM_PIN_CAP_TRIGGER_REQD(pincap)) { 5704230130Smav delay = 0; 5705230130Smav hda_command(dev, 5706230130Smav HDA_CMD_SET_PIN_SENSE(0, w->nid, 0)); 5707230130Smav do { 5708230130Smav res = hda_command(dev, 5709230130Smav HDA_CMD_GET_PIN_SENSE(0, w->nid)); 5710230130Smav if (res != 0x7fffffff && res != 0xffffffff) 5711230130Smav break; 5712230130Smav DELAY(10); 5713230130Smav } while (++delay < 10000); 5714230130Smav } else { 5715230130Smav delay = 0; 5716230130Smav res = hda_command(dev, HDA_CMD_GET_PIN_SENSE(0, 5717230130Smav w->nid)); 5718230130Smav } 5719230312Smav printf(" Sense: 0x%08x (%sconnected%s)", res, 5720230130Smav (res & HDA_CMD_GET_PIN_SENSE_PRESENCE_DETECT) ? 5721230312Smav "" : "dis", 5722230312Smav (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap) && 5723230312Smav (res & HDA_CMD_GET_PIN_SENSE_ELD_VALID)) ? 5724230312Smav ", ELD valid" : ""); 5725230130Smav if (delay > 0) 5726230130Smav printf(" delay %dus", delay * 10); 5727230130Smav } 5728230130Smav printf("\n"); 5729230130Smav } 5730230130Smav device_printf(dev, 5731230130Smav "NumGPIO=%d NumGPO=%d NumGPI=%d GPIWake=%d GPIUnsol=%d\n", 5732230130Smav HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap), 5733230130Smav HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap), 5734230130Smav HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap), 5735230130Smav HDA_PARAM_GPIO_COUNT_GPI_WAKE(devinfo->gpio_cap), 5736230130Smav HDA_PARAM_GPIO_COUNT_GPI_UNSOL(devinfo->gpio_cap)); 5737230130Smav hdaa_dump_gpi(devinfo); 5738230130Smav hdaa_dump_gpio(devinfo); 5739230130Smav hdaa_dump_gpo(devinfo); 5740230130Smav} 5741230130Smav 5742230130Smavstatic void 5743230130Smavhdaa_configure(device_t dev) 5744230130Smav{ 5745230130Smav struct hdaa_devinfo *devinfo = device_get_softc(dev); 5746230130Smav struct hdaa_audio_ctl *ctl; 5747230130Smav int i; 5748230130Smav 5749230130Smav HDA_BOOTHVERBOSE( 5750230130Smav device_printf(dev, "Applying built-in patches...\n"); 5751230130Smav ); 5752230130Smav hdaa_patch(devinfo); 5753230130Smav HDA_BOOTHVERBOSE( 5754230130Smav device_printf(dev, "Applying local patches...\n"); 5755230130Smav ); 5756230130Smav hdaa_local_patch(devinfo); 5757230130Smav hdaa_audio_postprocess(devinfo); 5758230130Smav HDA_BOOTHVERBOSE( 5759230130Smav device_printf(dev, "Parsing Ctls...\n"); 5760230130Smav ); 5761230130Smav hdaa_audio_ctl_parse(devinfo); 5762230130Smav HDA_BOOTHVERBOSE( 5763230130Smav device_printf(dev, "Disabling nonaudio...\n"); 5764230130Smav ); 5765230130Smav hdaa_audio_disable_nonaudio(devinfo); 5766230130Smav HDA_BOOTHVERBOSE( 5767230130Smav device_printf(dev, "Disabling useless...\n"); 5768230130Smav ); 5769230130Smav hdaa_audio_disable_useless(devinfo); 5770230130Smav HDA_BOOTVERBOSE( 5771230130Smav device_printf(dev, "Patched pins configuration:\n"); 5772230130Smav hdaa_dump_pin_configs(devinfo); 5773230130Smav ); 5774230130Smav HDA_BOOTHVERBOSE( 5775230130Smav device_printf(dev, "Parsing pin associations...\n"); 5776230130Smav ); 5777230130Smav hdaa_audio_as_parse(devinfo); 5778230130Smav HDA_BOOTHVERBOSE( 5779230130Smav device_printf(dev, "Building AFG tree...\n"); 5780230130Smav ); 5781230130Smav hdaa_audio_build_tree(devinfo); 5782230130Smav HDA_BOOTHVERBOSE( 5783230130Smav device_printf(dev, "Disabling unassociated " 5784230130Smav "widgets...\n"); 5785230130Smav ); 5786230130Smav hdaa_audio_disable_unas(devinfo); 5787230130Smav HDA_BOOTHVERBOSE( 5788230130Smav device_printf(dev, "Disabling nonselected " 5789230130Smav "inputs...\n"); 5790230130Smav ); 5791230130Smav hdaa_audio_disable_notselected(devinfo); 5792230130Smav HDA_BOOTHVERBOSE( 5793230130Smav device_printf(dev, "Disabling useless...\n"); 5794230130Smav ); 5795230130Smav hdaa_audio_disable_useless(devinfo); 5796230130Smav HDA_BOOTHVERBOSE( 5797230130Smav device_printf(dev, "Disabling " 5798230130Smav "crossassociatement connections...\n"); 5799230130Smav ); 5800230130Smav hdaa_audio_disable_crossas(devinfo); 5801230130Smav HDA_BOOTHVERBOSE( 5802230130Smav device_printf(dev, "Disabling useless...\n"); 5803230130Smav ); 5804230130Smav hdaa_audio_disable_useless(devinfo); 5805230130Smav HDA_BOOTHVERBOSE( 5806230130Smav device_printf(dev, "Binding associations to channels...\n"); 5807230130Smav ); 5808230130Smav hdaa_audio_bind_as(devinfo); 5809230130Smav HDA_BOOTHVERBOSE( 5810230130Smav device_printf(dev, "Assigning names to signal sources...\n"); 5811230130Smav ); 5812230130Smav hdaa_audio_assign_names(devinfo); 5813230130Smav HDA_BOOTHVERBOSE( 5814230451Smav device_printf(dev, "Preparing PCM devices...\n"); 5815230451Smav ); 5816230451Smav hdaa_prepare_pcms(devinfo); 5817230451Smav HDA_BOOTHVERBOSE( 5818230130Smav device_printf(dev, "Assigning mixers to the tree...\n"); 5819230130Smav ); 5820230130Smav hdaa_audio_assign_mixers(devinfo); 5821230130Smav HDA_BOOTHVERBOSE( 5822230130Smav device_printf(dev, "Preparing pin controls...\n"); 5823230130Smav ); 5824230130Smav hdaa_audio_prepare_pin_ctrl(devinfo); 5825230130Smav HDA_BOOTHVERBOSE( 5826230130Smav device_printf(dev, "AFG commit...\n"); 5827230130Smav ); 5828230130Smav hdaa_audio_commit(devinfo); 5829230130Smav HDA_BOOTHVERBOSE( 5830230130Smav device_printf(dev, "Applying direct built-in patches...\n"); 5831230130Smav ); 5832230130Smav hdaa_patch_direct(devinfo); 5833230130Smav HDA_BOOTHVERBOSE( 5834230551Smav device_printf(dev, "Pin sense init...\n"); 5835230312Smav ); 5836230551Smav hdaa_sense_init(devinfo); 5837230312Smav HDA_BOOTHVERBOSE( 5838230130Smav device_printf(dev, "Creating PCM devices...\n"); 5839230130Smav ); 5840230130Smav hdaa_create_pcms(devinfo); 5841230130Smav 5842230130Smav HDA_BOOTVERBOSE( 5843230130Smav if (devinfo->quirks != 0) { 5844230130Smav device_printf(dev, "FG config/quirks:"); 5845230130Smav for (i = 0; i < HDAA_QUIRKS_TAB_LEN; i++) { 5846230130Smav if ((devinfo->quirks & 5847230130Smav hdaa_quirks_tab[i].value) == 5848230130Smav hdaa_quirks_tab[i].value) 5849230130Smav printf(" %s", hdaa_quirks_tab[i].key); 5850230130Smav } 5851230130Smav printf("\n"); 5852230130Smav } 5853230130Smav 5854230130Smav device_printf(dev, "\n"); 5855230130Smav device_printf(dev, "+-------------------+\n"); 5856230130Smav device_printf(dev, "| DUMPING HDA NODES |\n"); 5857230130Smav device_printf(dev, "+-------------------+\n"); 5858230130Smav hdaa_dump_nodes(devinfo); 5859230130Smav ); 5860230130Smav 5861230130Smav HDA_BOOTHVERBOSE( 5862230130Smav device_printf(dev, "\n"); 5863230130Smav device_printf(dev, "+------------------------+\n"); 5864230130Smav device_printf(dev, "| DUMPING HDA AMPLIFIERS |\n"); 5865230130Smav device_printf(dev, "+------------------------+\n"); 5866230130Smav device_printf(dev, "\n"); 5867230130Smav i = 0; 5868230130Smav while ((ctl = hdaa_audio_ctl_each(devinfo, &i)) != NULL) { 5869230130Smav device_printf(dev, "%3d: nid %3d %s (%s) index %d", i, 5870230130Smav (ctl->widget != NULL) ? ctl->widget->nid : -1, 5871230130Smav (ctl->ndir == HDAA_CTL_IN)?"in ":"out", 5872230130Smav (ctl->dir == HDAA_CTL_IN)?"in ":"out", 5873230130Smav ctl->index); 5874230130Smav if (ctl->childwidget != NULL) 5875230130Smav printf(" cnid %3d", ctl->childwidget->nid); 5876230130Smav else 5877230130Smav printf(" "); 5878230130Smav printf(" ossmask=0x%08x\n", 5879230130Smav ctl->ossmask); 5880230130Smav device_printf(dev, 5881230130Smav " mute: %d step: %3d size: %3d off: %3d%s\n", 5882230130Smav ctl->mute, ctl->step, ctl->size, ctl->offset, 5883230130Smav (ctl->enable == 0) ? " [DISABLED]" : 5884230130Smav ((ctl->ossmask == 0) ? " [UNUSED]" : "")); 5885230130Smav } 5886230130Smav ); 5887230130Smav 5888230130Smav HDA_BOOTVERBOSE( 5889230130Smav device_printf(dev, "\n"); 5890230130Smav ); 5891230130Smav} 5892230130Smav 5893230130Smavstatic void 5894230130Smavhdaa_unconfigure(device_t dev) 5895230130Smav{ 5896230130Smav struct hdaa_devinfo *devinfo = device_get_softc(dev); 5897230130Smav struct hdaa_widget *w; 5898230130Smav int i, j; 5899230130Smav 5900230130Smav HDA_BOOTHVERBOSE( 5901230551Smav device_printf(dev, "Pin sense deinit...\n"); 5902230130Smav ); 5903230551Smav hdaa_sense_deinit(devinfo); 5904230130Smav free(devinfo->ctl, M_HDAA); 5905230130Smav devinfo->ctl = NULL; 5906230130Smav devinfo->ctlcnt = 0; 5907230130Smav free(devinfo->as, M_HDAA); 5908230130Smav devinfo->as = NULL; 5909230130Smav devinfo->ascnt = 0; 5910230130Smav free(devinfo->devs, M_HDAA); 5911230130Smav devinfo->devs = NULL; 5912230130Smav devinfo->num_devs = 0; 5913230130Smav free(devinfo->chans, M_HDAA); 5914230130Smav devinfo->chans = NULL; 5915230130Smav devinfo->num_chans = 0; 5916230130Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 5917230130Smav w = hdaa_widget_get(devinfo, i); 5918230130Smav if (w == NULL) 5919230130Smav continue; 5920230130Smav w->enable = 1; 5921230130Smav w->selconn = -1; 5922230130Smav w->pflags = 0; 5923230130Smav w->bindas = -1; 5924230130Smav w->bindseqmask = 0; 5925230130Smav w->ossdev = -1; 5926230130Smav w->ossmask = 0; 5927230130Smav for (j = 0; j < w->nconns; j++) 5928230130Smav w->connsenable[j] = 1; 5929230451Smav if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 5930230451Smav w->wclass.pin.config = w->wclass.pin.newconf; 5931230312Smav if (w->eld != NULL) { 5932230312Smav w->eld_len = 0; 5933230312Smav free(w->eld, M_HDAA); 5934230312Smav w->eld = NULL; 5935230312Smav } 5936230130Smav } 5937230130Smav} 5938230130Smav 5939230130Smavstatic int 5940230130Smavhdaa_sysctl_gpi_state(SYSCTL_HANDLER_ARGS) 5941230130Smav{ 5942230130Smav struct hdaa_devinfo *devinfo = oidp->oid_arg1; 5943230130Smav device_t dev = devinfo->dev; 5944230130Smav char buf[256]; 5945230130Smav int n = 0, i, numgpi; 5946230130Smav uint32_t data = 0; 5947230130Smav 5948230130Smav buf[0] = 0; 5949230130Smav hdaa_lock(devinfo); 5950230130Smav numgpi = HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->gpio_cap); 5951230130Smav if (numgpi > 0) { 5952230130Smav data = hda_command(dev, 5953230130Smav HDA_CMD_GET_GPI_DATA(0, devinfo->nid)); 5954230130Smav } 5955230130Smav hdaa_unlock(devinfo); 5956230130Smav for (i = 0; i < numgpi; i++) { 5957230130Smav n += snprintf(buf + n, sizeof(buf) - n, "%s%d=%d", 5958230130Smav n != 0 ? " " : "", i, ((data >> i) & 1)); 5959230130Smav } 5960230130Smav return (sysctl_handle_string(oidp, buf, sizeof(buf), req)); 5961230130Smav} 5962230130Smav 5963230130Smavstatic int 5964230130Smavhdaa_sysctl_gpio_state(SYSCTL_HANDLER_ARGS) 5965230130Smav{ 5966230130Smav struct hdaa_devinfo *devinfo = oidp->oid_arg1; 5967230130Smav device_t dev = devinfo->dev; 5968230130Smav char buf[256]; 5969230130Smav int n = 0, i, numgpio; 5970230130Smav uint32_t data = 0, enable = 0, dir = 0; 5971230130Smav 5972230130Smav buf[0] = 0; 5973230130Smav hdaa_lock(devinfo); 5974230130Smav numgpio = HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap); 5975230130Smav if (numgpio > 0) { 5976230130Smav data = hda_command(dev, 5977230130Smav HDA_CMD_GET_GPIO_DATA(0, devinfo->nid)); 5978230130Smav enable = hda_command(dev, 5979230130Smav HDA_CMD_GET_GPIO_ENABLE_MASK(0, devinfo->nid)); 5980230130Smav dir = hda_command(dev, 5981230130Smav HDA_CMD_GET_GPIO_DIRECTION(0, devinfo->nid)); 5982230130Smav } 5983230130Smav hdaa_unlock(devinfo); 5984230130Smav for (i = 0; i < numgpio; i++) { 5985230130Smav n += snprintf(buf + n, sizeof(buf) - n, "%s%d=", 5986230130Smav n != 0 ? " " : "", i); 5987230130Smav if ((enable & (1 << i)) == 0) { 5988230130Smav n += snprintf(buf + n, sizeof(buf) - n, "disabled"); 5989230130Smav continue; 5990230130Smav } 5991230130Smav n += snprintf(buf + n, sizeof(buf) - n, "%sput(%d)", 5992230130Smav ((dir >> i) & 1) ? "out" : "in", ((data >> i) & 1)); 5993230130Smav } 5994230130Smav return (sysctl_handle_string(oidp, buf, sizeof(buf), req)); 5995230130Smav} 5996230130Smav 5997230130Smavstatic int 5998230130Smavhdaa_sysctl_gpio_config(SYSCTL_HANDLER_ARGS) 5999230130Smav{ 6000230130Smav struct hdaa_devinfo *devinfo = oidp->oid_arg1; 6001230130Smav char buf[256]; 6002230130Smav int error, n = 0, i, numgpio; 6003230130Smav uint32_t gpio, x; 6004230130Smav 6005230130Smav gpio = devinfo->newgpio; 6006230130Smav numgpio = HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->gpio_cap); 6007230130Smav buf[0] = 0; 6008230130Smav for (i = 0; i < numgpio; i++) { 6009230130Smav x = (gpio & HDAA_GPIO_MASK(i)) >> HDAA_GPIO_SHIFT(i); 6010230130Smav n += snprintf(buf + n, sizeof(buf) - n, "%s%d=%s", 6011230130Smav n != 0 ? " " : "", i, HDA_GPIO_ACTIONS[x]); 6012230130Smav } 6013230130Smav error = sysctl_handle_string(oidp, buf, sizeof(buf), req); 6014230130Smav if (error != 0 || req->newptr == NULL) 6015230130Smav return (error); 6016230130Smav if (strncmp(buf, "0x", 2) == 0) 6017230130Smav gpio = strtol(buf + 2, NULL, 16); 6018230130Smav else 6019230130Smav gpio = hdaa_gpio_patch(gpio, buf); 6020230130Smav hdaa_lock(devinfo); 6021230130Smav devinfo->newgpio = devinfo->gpio = gpio; 6022230130Smav hdaa_gpio_commit(devinfo); 6023230130Smav hdaa_unlock(devinfo); 6024230130Smav return (0); 6025230130Smav} 6026230130Smav 6027230130Smavstatic int 6028230130Smavhdaa_sysctl_gpo_state(SYSCTL_HANDLER_ARGS) 6029230130Smav{ 6030230130Smav struct hdaa_devinfo *devinfo = oidp->oid_arg1; 6031230130Smav device_t dev = devinfo->dev; 6032230130Smav char buf[256]; 6033230130Smav int n = 0, i, numgpo; 6034230130Smav uint32_t data = 0; 6035230130Smav 6036230130Smav buf[0] = 0; 6037230130Smav hdaa_lock(devinfo); 6038230130Smav numgpo = HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap); 6039230130Smav if (numgpo > 0) { 6040230130Smav data = hda_command(dev, 6041230130Smav HDA_CMD_GET_GPO_DATA(0, devinfo->nid)); 6042230130Smav } 6043230130Smav hdaa_unlock(devinfo); 6044230130Smav for (i = 0; i < numgpo; i++) { 6045230130Smav n += snprintf(buf + n, sizeof(buf) - n, "%s%d=%d", 6046230130Smav n != 0 ? " " : "", i, ((data >> i) & 1)); 6047230130Smav } 6048230130Smav return (sysctl_handle_string(oidp, buf, sizeof(buf), req)); 6049230130Smav} 6050230130Smav 6051230130Smavstatic int 6052230130Smavhdaa_sysctl_gpo_config(SYSCTL_HANDLER_ARGS) 6053230130Smav{ 6054230130Smav struct hdaa_devinfo *devinfo = oidp->oid_arg1; 6055230130Smav char buf[256]; 6056230130Smav int error, n = 0, i, numgpo; 6057230130Smav uint32_t gpo, x; 6058230130Smav 6059230130Smav gpo = devinfo->newgpo; 6060230130Smav numgpo = HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->gpio_cap); 6061230130Smav buf[0] = 0; 6062230130Smav for (i = 0; i < numgpo; i++) { 6063230130Smav x = (gpo & HDAA_GPIO_MASK(i)) >> HDAA_GPIO_SHIFT(i); 6064230130Smav n += snprintf(buf + n, sizeof(buf) - n, "%s%d=%s", 6065230130Smav n != 0 ? " " : "", i, HDA_GPIO_ACTIONS[x]); 6066230130Smav } 6067230130Smav error = sysctl_handle_string(oidp, buf, sizeof(buf), req); 6068230130Smav if (error != 0 || req->newptr == NULL) 6069230130Smav return (error); 6070230130Smav if (strncmp(buf, "0x", 2) == 0) 6071230130Smav gpo = strtol(buf + 2, NULL, 16); 6072230130Smav else 6073230130Smav gpo = hdaa_gpio_patch(gpo, buf); 6074230130Smav hdaa_lock(devinfo); 6075230130Smav devinfo->newgpo = devinfo->gpo = gpo; 6076230130Smav hdaa_gpo_commit(devinfo); 6077230130Smav hdaa_unlock(devinfo); 6078230130Smav return (0); 6079230130Smav} 6080230130Smav 6081230130Smavstatic int 6082230130Smavhdaa_sysctl_reconfig(SYSCTL_HANDLER_ARGS) 6083230130Smav{ 6084230130Smav device_t dev; 6085230130Smav struct hdaa_devinfo *devinfo; 6086230130Smav int error, val; 6087230130Smav 6088230130Smav dev = oidp->oid_arg1; 6089230130Smav devinfo = device_get_softc(dev); 6090230130Smav if (devinfo == NULL) 6091230130Smav return (EINVAL); 6092230130Smav val = 0; 6093230130Smav error = sysctl_handle_int(oidp, &val, 0, req); 6094230130Smav if (error != 0 || req->newptr == NULL || val == 0) 6095230130Smav return (error); 6096230130Smav 6097230130Smav HDA_BOOTHVERBOSE( 6098230130Smav device_printf(dev, "Reconfiguration...\n"); 6099230130Smav ); 6100230130Smav if ((error = device_delete_children(dev)) != 0) 6101230130Smav return (error); 6102230130Smav hdaa_lock(devinfo); 6103230130Smav hdaa_unconfigure(dev); 6104230130Smav hdaa_configure(dev); 6105230130Smav hdaa_unlock(devinfo); 6106230130Smav bus_generic_attach(dev); 6107230130Smav HDA_BOOTHVERBOSE( 6108230130Smav device_printf(dev, "Reconfiguration done\n"); 6109230130Smav ); 6110230130Smav return (0); 6111230130Smav} 6112230130Smav 6113230130Smavstatic int 6114230130Smavhdaa_suspend(device_t dev) 6115230130Smav{ 6116230130Smav struct hdaa_devinfo *devinfo = device_get_softc(dev); 6117230130Smav int i; 6118230130Smav 6119230130Smav HDA_BOOTHVERBOSE( 6120230130Smav device_printf(dev, "Suspend...\n"); 6121230130Smav ); 6122230130Smav hdaa_lock(devinfo); 6123230130Smav HDA_BOOTHVERBOSE( 6124230130Smav device_printf(dev, "Stop streams...\n"); 6125230130Smav ); 6126230130Smav for (i = 0; i < devinfo->num_chans; i++) { 6127230130Smav if (devinfo->chans[i].flags & HDAA_CHN_RUNNING) { 6128230130Smav devinfo->chans[i].flags |= HDAA_CHN_SUSPEND; 6129230130Smav hdaa_channel_stop(&devinfo->chans[i]); 6130230130Smav } 6131230130Smav } 6132230130Smav HDA_BOOTHVERBOSE( 6133230130Smav device_printf(dev, "Power down FG" 6134230130Smav " nid=%d to the D3 state...\n", 6135230130Smav devinfo->nid); 6136230130Smav ); 6137230130Smav hda_command(devinfo->dev, 6138230130Smav HDA_CMD_SET_POWER_STATE(0, 6139230130Smav devinfo->nid, HDA_CMD_POWER_STATE_D3)); 6140230130Smav callout_stop(&devinfo->poll_jack); 6141230130Smav hdaa_unlock(devinfo); 6142230130Smav callout_drain(&devinfo->poll_jack); 6143230130Smav HDA_BOOTHVERBOSE( 6144230130Smav device_printf(dev, "Suspend done\n"); 6145230130Smav ); 6146230130Smav return (0); 6147230130Smav} 6148230130Smav 6149230130Smavstatic int 6150230130Smavhdaa_resume(device_t dev) 6151230130Smav{ 6152230130Smav struct hdaa_devinfo *devinfo = device_get_softc(dev); 6153230130Smav int i; 6154230130Smav 6155230130Smav HDA_BOOTHVERBOSE( 6156230130Smav device_printf(dev, "Resume...\n"); 6157230130Smav ); 6158230130Smav hdaa_lock(devinfo); 6159230130Smav HDA_BOOTHVERBOSE( 6160230130Smav device_printf(dev, "Power up audio FG nid=%d...\n", 6161230130Smav devinfo->nid); 6162230130Smav ); 6163230130Smav hdaa_powerup(devinfo); 6164230130Smav HDA_BOOTHVERBOSE( 6165230130Smav device_printf(dev, "AFG commit...\n"); 6166230130Smav ); 6167230130Smav hdaa_audio_commit(devinfo); 6168230130Smav HDA_BOOTHVERBOSE( 6169230130Smav device_printf(dev, "Applying direct built-in patches...\n"); 6170230130Smav ); 6171230130Smav hdaa_patch_direct(devinfo); 6172230130Smav HDA_BOOTHVERBOSE( 6173230551Smav device_printf(dev, "Pin sense init...\n"); 6174230130Smav ); 6175230551Smav hdaa_sense_init(devinfo); 6176230130Smav 6177230130Smav hdaa_unlock(devinfo); 6178230130Smav for (i = 0; i < devinfo->num_devs; i++) { 6179230130Smav struct hdaa_pcm_devinfo *pdevinfo = &devinfo->devs[i]; 6180230130Smav HDA_BOOTHVERBOSE( 6181230130Smav device_printf(pdevinfo->dev, 6182230130Smav "OSS mixer reinitialization...\n"); 6183230130Smav ); 6184230130Smav if (mixer_reinit(pdevinfo->dev) == -1) 6185230130Smav device_printf(pdevinfo->dev, 6186230130Smav "unable to reinitialize the mixer\n"); 6187230130Smav } 6188230130Smav hdaa_lock(devinfo); 6189230130Smav HDA_BOOTHVERBOSE( 6190230130Smav device_printf(dev, "Start streams...\n"); 6191230130Smav ); 6192230130Smav for (i = 0; i < devinfo->num_chans; i++) { 6193230130Smav if (devinfo->chans[i].flags & HDAA_CHN_SUSPEND) { 6194230130Smav devinfo->chans[i].flags &= ~HDAA_CHN_SUSPEND; 6195230130Smav hdaa_channel_start(&devinfo->chans[i]); 6196230130Smav } 6197230130Smav } 6198230130Smav hdaa_unlock(devinfo); 6199230130Smav HDA_BOOTHVERBOSE( 6200230130Smav device_printf(dev, "Resume done\n"); 6201230130Smav ); 6202230130Smav return (0); 6203230130Smav} 6204230130Smav 6205230130Smavstatic int 6206230130Smavhdaa_probe(device_t dev) 6207230130Smav{ 6208238022Smav const char *pdesc; 6209230130Smav char buf[128]; 6210230130Smav 6211230130Smav if (hda_get_node_type(dev) != HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO) 6212230130Smav return (ENXIO); 6213238022Smav pdesc = device_get_desc(device_get_parent(dev)); 6214238022Smav snprintf(buf, sizeof(buf), "%.*s Audio Function Group", 6215238022Smav (int)(strlen(pdesc) - 10), pdesc); 6216230130Smav device_set_desc_copy(dev, buf); 6217230130Smav return (BUS_PROBE_DEFAULT); 6218230130Smav} 6219230130Smav 6220230130Smavstatic int 6221230130Smavhdaa_attach(device_t dev) 6222230130Smav{ 6223230130Smav struct hdaa_devinfo *devinfo = device_get_softc(dev); 6224230130Smav uint32_t res; 6225230130Smav nid_t nid = hda_get_node_id(dev); 6226230130Smav 6227230130Smav devinfo->dev = dev; 6228230130Smav devinfo->lock = HDAC_GET_MTX(device_get_parent(dev), dev); 6229230130Smav devinfo->nid = nid; 6230230130Smav devinfo->newquirks = -1; 6231230130Smav devinfo->newgpio = -1; 6232230130Smav devinfo->newgpo = -1; 6233230130Smav callout_init(&devinfo->poll_jack, CALLOUT_MPSAFE); 6234230130Smav devinfo->poll_ival = hz; 6235230130Smav 6236230130Smav hdaa_lock(devinfo); 6237230130Smav res = hda_command(dev, 6238230130Smav HDA_CMD_GET_PARAMETER(0 , nid, HDA_PARAM_SUB_NODE_COUNT)); 6239230130Smav hdaa_unlock(devinfo); 6240230130Smav 6241230130Smav devinfo->nodecnt = HDA_PARAM_SUB_NODE_COUNT_TOTAL(res); 6242230130Smav devinfo->startnode = HDA_PARAM_SUB_NODE_COUNT_START(res); 6243230130Smav devinfo->endnode = devinfo->startnode + devinfo->nodecnt; 6244230130Smav 6245230130Smav HDA_BOOTVERBOSE( 6246242352Smav device_printf(dev, "Subsystem ID: 0x%08x\n", 6247242352Smav hda_get_subsystem_id(dev)); 6248242352Smav ); 6249242352Smav HDA_BOOTHVERBOSE( 6250230130Smav device_printf(dev, 6251230130Smav "Audio Function Group at nid=%d: %d subnodes %d-%d\n", 6252230130Smav nid, devinfo->nodecnt, 6253230130Smav devinfo->startnode, devinfo->endnode - 1); 6254230130Smav ); 6255230130Smav 6256230130Smav if (devinfo->nodecnt > 0) 6257230130Smav devinfo->widget = (struct hdaa_widget *)malloc( 6258230130Smav sizeof(*(devinfo->widget)) * devinfo->nodecnt, M_HDAA, 6259230130Smav M_WAITOK | M_ZERO); 6260230130Smav else 6261230130Smav devinfo->widget = NULL; 6262230130Smav 6263230130Smav hdaa_lock(devinfo); 6264230130Smav HDA_BOOTHVERBOSE( 6265230130Smav device_printf(dev, "Powering up...\n"); 6266230130Smav ); 6267230130Smav hdaa_powerup(devinfo); 6268230130Smav HDA_BOOTHVERBOSE( 6269230130Smav device_printf(dev, "Parsing audio FG...\n"); 6270230130Smav ); 6271230130Smav hdaa_audio_parse(devinfo); 6272230130Smav HDA_BOOTVERBOSE( 6273230130Smav device_printf(dev, "Original pins configuration:\n"); 6274230130Smav hdaa_dump_pin_configs(devinfo); 6275230130Smav ); 6276230130Smav hdaa_configure(dev); 6277230130Smav hdaa_unlock(devinfo); 6278230130Smav 6279230130Smav SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 6280230130Smav SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, 6281230130Smav "config", CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE, 6282230130Smav &devinfo->newquirks, sizeof(&devinfo->newquirks), 6283230130Smav hdaa_sysctl_quirks, "A", "Configuration options"); 6284230130Smav SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 6285230130Smav SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, 6286230130Smav "gpi_state", CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, 6287230130Smav devinfo, sizeof(devinfo), 6288230130Smav hdaa_sysctl_gpi_state, "A", "GPI state"); 6289230130Smav SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 6290230130Smav SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, 6291230130Smav "gpio_state", CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, 6292230130Smav devinfo, sizeof(devinfo), 6293230130Smav hdaa_sysctl_gpio_state, "A", "GPIO state"); 6294230130Smav SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 6295230130Smav SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, 6296230130Smav "gpio_config", CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE, 6297230130Smav devinfo, sizeof(devinfo), 6298230130Smav hdaa_sysctl_gpio_config, "A", "GPIO configuration"); 6299230130Smav SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 6300230130Smav SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, 6301230130Smav "gpo_state", CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, 6302230130Smav devinfo, sizeof(devinfo), 6303230130Smav hdaa_sysctl_gpo_state, "A", "GPO state"); 6304230130Smav SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 6305230130Smav SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, 6306230130Smav "gpo_config", CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE, 6307230130Smav devinfo, sizeof(devinfo), 6308230130Smav hdaa_sysctl_gpo_config, "A", "GPO configuration"); 6309230130Smav SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 6310230130Smav SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, 6311230130Smav "reconfig", CTLTYPE_INT | CTLFLAG_RW, 6312230130Smav dev, sizeof(dev), 6313230130Smav hdaa_sysctl_reconfig, "I", "Reprocess configuration"); 6314230130Smav bus_generic_attach(dev); 6315230130Smav return (0); 6316230130Smav} 6317230130Smav 6318230130Smavstatic int 6319230130Smavhdaa_detach(device_t dev) 6320230130Smav{ 6321230130Smav struct hdaa_devinfo *devinfo = device_get_softc(dev); 6322230130Smav int error; 6323230130Smav 6324230130Smav if ((error = device_delete_children(dev)) != 0) 6325230130Smav return (error); 6326230130Smav 6327230130Smav hdaa_lock(devinfo); 6328230130Smav hdaa_unconfigure(dev); 6329230130Smav devinfo->poll_ival = 0; 6330230130Smav callout_stop(&devinfo->poll_jack); 6331230130Smav hdaa_unlock(devinfo); 6332230130Smav callout_drain(&devinfo->poll_jack); 6333230130Smav 6334230130Smav free(devinfo->widget, M_HDAA); 6335230130Smav return (0); 6336230130Smav} 6337230130Smav 6338230130Smavstatic int 6339230130Smavhdaa_print_child(device_t dev, device_t child) 6340230130Smav{ 6341230130Smav struct hdaa_devinfo *devinfo = device_get_softc(dev); 6342230130Smav struct hdaa_pcm_devinfo *pdevinfo = 6343230130Smav (struct hdaa_pcm_devinfo *)device_get_ivars(child); 6344230130Smav struct hdaa_audio_as *as; 6345230130Smav int retval, first = 1, i; 6346230130Smav 6347230130Smav retval = bus_print_child_header(dev, child); 6348230130Smav retval += printf(" at nid "); 6349230130Smav if (pdevinfo->playas >= 0) { 6350230130Smav as = &devinfo->as[pdevinfo->playas]; 6351230130Smav for (i = 0; i < 16; i++) { 6352230130Smav if (as->pins[i] <= 0) 6353230130Smav continue; 6354230130Smav retval += printf("%s%d", first ? "" : ",", as->pins[i]); 6355230130Smav first = 0; 6356230130Smav } 6357230130Smav } 6358230130Smav if (pdevinfo->recas >= 0) { 6359230130Smav if (pdevinfo->playas >= 0) { 6360230130Smav retval += printf(" and "); 6361230130Smav first = 1; 6362230130Smav } 6363230130Smav as = &devinfo->as[pdevinfo->recas]; 6364230130Smav for (i = 0; i < 16; i++) { 6365230130Smav if (as->pins[i] <= 0) 6366230130Smav continue; 6367230130Smav retval += printf("%s%d", first ? "" : ",", as->pins[i]); 6368230130Smav first = 0; 6369230130Smav } 6370230130Smav } 6371230130Smav retval += bus_print_child_footer(dev, child); 6372230130Smav 6373230130Smav return (retval); 6374230130Smav} 6375230130Smav 6376230130Smavstatic int 6377230130Smavhdaa_child_location_str(device_t dev, device_t child, char *buf, 6378230130Smav size_t buflen) 6379230130Smav{ 6380230130Smav struct hdaa_devinfo *devinfo = device_get_softc(dev); 6381230130Smav struct hdaa_pcm_devinfo *pdevinfo = 6382230130Smav (struct hdaa_pcm_devinfo *)device_get_ivars(child); 6383230130Smav struct hdaa_audio_as *as; 6384230130Smav int first = 1, i, len = 0; 6385230130Smav 6386230130Smav len += snprintf(buf + len, buflen - len, "nid="); 6387230130Smav if (pdevinfo->playas >= 0) { 6388230130Smav as = &devinfo->as[pdevinfo->playas]; 6389230130Smav for (i = 0; i < 16; i++) { 6390230130Smav if (as->pins[i] <= 0) 6391230130Smav continue; 6392230130Smav len += snprintf(buf + len, buflen - len, 6393230130Smav "%s%d", first ? "" : ",", as->pins[i]); 6394230130Smav first = 0; 6395230130Smav } 6396230130Smav } 6397230130Smav if (pdevinfo->recas >= 0) { 6398230130Smav as = &devinfo->as[pdevinfo->recas]; 6399230130Smav for (i = 0; i < 16; i++) { 6400230130Smav if (as->pins[i] <= 0) 6401230130Smav continue; 6402230130Smav len += snprintf(buf + len, buflen - len, 6403230130Smav "%s%d", first ? "" : ",", as->pins[i]); 6404230130Smav first = 0; 6405230130Smav } 6406230130Smav } 6407230130Smav return (0); 6408230130Smav} 6409230130Smav 6410230130Smavstatic void 6411230130Smavhdaa_stream_intr(device_t dev, int dir, int stream) 6412230130Smav{ 6413230130Smav struct hdaa_devinfo *devinfo = device_get_softc(dev); 6414230130Smav struct hdaa_chan *ch; 6415230130Smav int i; 6416230130Smav 6417230130Smav for (i = 0; i < devinfo->num_chans; i++) { 6418230130Smav ch = &devinfo->chans[i]; 6419230130Smav if (!(ch->flags & HDAA_CHN_RUNNING)) 6420230130Smav continue; 6421230130Smav if (ch->dir == ((dir == 1) ? PCMDIR_PLAY : PCMDIR_REC) && 6422230130Smav ch->sid == stream) { 6423230130Smav hdaa_unlock(devinfo); 6424230130Smav chn_intr(ch->c); 6425230130Smav hdaa_lock(devinfo); 6426230130Smav } 6427230130Smav } 6428230130Smav} 6429230130Smav 6430230130Smavstatic void 6431230130Smavhdaa_unsol_intr(device_t dev, uint32_t resp) 6432230130Smav{ 6433230130Smav struct hdaa_devinfo *devinfo = device_get_softc(dev); 6434230312Smav struct hdaa_widget *w; 6435230312Smav int i, tag, flags; 6436230130Smav 6437230312Smav HDA_BOOTHVERBOSE( 6438230312Smav device_printf(dev, "Unsolicited response %08x\n", resp); 6439230312Smav ); 6440230130Smav tag = resp >> 26; 6441230312Smav for (i = devinfo->startnode; i < devinfo->endnode; i++) { 6442230312Smav w = hdaa_widget_get(devinfo, i); 6443230312Smav if (w == NULL || w->enable == 0 || w->type != 6444230312Smav HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 6445230312Smav continue; 6446230312Smav if (w->unsol != tag) 6447230312Smav continue; 6448230312Smav if (HDA_PARAM_PIN_CAP_DP(w->wclass.pin.cap) || 6449230312Smav HDA_PARAM_PIN_CAP_HDMI(w->wclass.pin.cap)) 6450230312Smav flags = resp & 0x03; 6451230312Smav else 6452230312Smav flags = 0x01; 6453230312Smav if (flags & 0x01) 6454230551Smav hdaa_presence_handler(w); 6455230312Smav if (flags & 0x02) 6456230312Smav hdaa_eld_handler(w); 6457230130Smav } 6458230130Smav} 6459230130Smav 6460230130Smavstatic device_method_t hdaa_methods[] = { 6461230130Smav /* device interface */ 6462230130Smav DEVMETHOD(device_probe, hdaa_probe), 6463230130Smav DEVMETHOD(device_attach, hdaa_attach), 6464230130Smav DEVMETHOD(device_detach, hdaa_detach), 6465230130Smav DEVMETHOD(device_suspend, hdaa_suspend), 6466230130Smav DEVMETHOD(device_resume, hdaa_resume), 6467230130Smav /* Bus interface */ 6468230130Smav DEVMETHOD(bus_print_child, hdaa_print_child), 6469230130Smav DEVMETHOD(bus_child_location_str, hdaa_child_location_str), 6470230130Smav DEVMETHOD(hdac_stream_intr, hdaa_stream_intr), 6471230130Smav DEVMETHOD(hdac_unsol_intr, hdaa_unsol_intr), 6472230130Smav DEVMETHOD(hdac_pindump, hdaa_pindump), 6473230130Smav { 0, 0 } 6474230130Smav}; 6475230130Smav 6476230130Smavstatic driver_t hdaa_driver = { 6477230130Smav "hdaa", 6478230130Smav hdaa_methods, 6479230130Smav sizeof(struct hdaa_devinfo), 6480230130Smav}; 6481230130Smav 6482230130Smavstatic devclass_t hdaa_devclass; 6483230130Smav 6484230130SmavDRIVER_MODULE(snd_hda, hdacc, hdaa_driver, hdaa_devclass, 0, 0); 6485230130Smav 6486230130Smavstatic void 6487230130Smavhdaa_chan_formula(struct hdaa_devinfo *devinfo, int asid, 6488230130Smav char *buf, int buflen) 6489230130Smav{ 6490230130Smav struct hdaa_audio_as *as; 6491230130Smav int c; 6492230130Smav 6493230130Smav as = &devinfo->as[asid]; 6494230130Smav c = devinfo->chans[as->chans[0]].channels; 6495230130Smav if (c == 1) 6496230130Smav snprintf(buf, buflen, "mono"); 6497230585Smav else if (c == 2) { 6498230585Smav if (as->hpredir < 0) 6499230585Smav buf[0] = 0; 6500230585Smav else 6501230585Smav snprintf(buf, buflen, "2.0"); 6502230585Smav } else if (as->pinset == 0x0003) 6503230130Smav snprintf(buf, buflen, "3.1"); 6504230130Smav else if (as->pinset == 0x0005 || as->pinset == 0x0011) 6505230130Smav snprintf(buf, buflen, "4.0"); 6506230130Smav else if (as->pinset == 0x0007 || as->pinset == 0x0013) 6507230130Smav snprintf(buf, buflen, "5.1"); 6508230130Smav else if (as->pinset == 0x0017) 6509230130Smav snprintf(buf, buflen, "7.1"); 6510230130Smav else 6511230130Smav snprintf(buf, buflen, "%dch", c); 6512230585Smav if (as->hpredir >= 0) 6513230585Smav strlcat(buf, "+HP", buflen); 6514230130Smav} 6515230130Smav 6516230130Smavstatic int 6517230585Smavhdaa_chan_type(struct hdaa_devinfo *devinfo, int asid) 6518230585Smav{ 6519230585Smav struct hdaa_audio_as *as; 6520230585Smav struct hdaa_widget *w; 6521230585Smav int i, t = -1, t1; 6522230585Smav 6523230585Smav as = &devinfo->as[asid]; 6524230585Smav for (i = 0; i < 16; i++) { 6525230585Smav w = hdaa_widget_get(devinfo, as->pins[i]); 6526230585Smav if (w == NULL || w->enable == 0 || w->type != 6527230585Smav HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) 6528230585Smav continue; 6529230585Smav t1 = HDA_CONFIG_DEFAULTCONF_DEVICE(w->wclass.pin.config); 6530230585Smav if (t == -1) 6531230585Smav t = t1; 6532230585Smav else if (t != t1) { 6533230585Smav t = -2; 6534230585Smav break; 6535230585Smav } 6536230585Smav } 6537230585Smav return (t); 6538230585Smav} 6539230585Smav 6540230585Smavstatic int 6541230488Smavhdaa_sysctl_32bit(SYSCTL_HANDLER_ARGS) 6542230488Smav{ 6543230488Smav struct hdaa_audio_as *as = (struct hdaa_audio_as *)oidp->oid_arg1; 6544230488Smav struct hdaa_pcm_devinfo *pdevinfo = as->pdevinfo; 6545230488Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 6546230488Smav struct hdaa_chan *ch; 6547230488Smav int error, val, i; 6548230488Smav uint32_t pcmcap; 6549230488Smav 6550230488Smav ch = &devinfo->chans[as->chans[0]]; 6551230488Smav val = (ch->bit32 == 4) ? 32 : ((ch->bit32 == 3) ? 24 : 6552230488Smav ((ch->bit32 == 2) ? 20 : 0)); 6553230488Smav error = sysctl_handle_int(oidp, &val, 0, req); 6554230488Smav if (error != 0 || req->newptr == NULL) 6555230488Smav return (error); 6556230488Smav pcmcap = ch->supp_pcm_size_rate; 6557230488Smav if (val == 32 && HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(pcmcap)) 6558230488Smav ch->bit32 = 4; 6559230488Smav else if (val == 24 && HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(pcmcap)) 6560230488Smav ch->bit32 = 3; 6561230488Smav else if (val == 20 && HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(pcmcap)) 6562230488Smav ch->bit32 = 2; 6563230488Smav else 6564230488Smav return (EINVAL); 6565230488Smav for (i = 1; i < as->num_chans; i++) 6566230488Smav devinfo->chans[as->chans[i]].bit32 = ch->bit32; 6567230488Smav return (0); 6568230488Smav} 6569230488Smav 6570230488Smavstatic int 6571230130Smavhdaa_pcm_probe(device_t dev) 6572230130Smav{ 6573230130Smav struct hdaa_pcm_devinfo *pdevinfo = 6574230130Smav (struct hdaa_pcm_devinfo *)device_get_ivars(dev); 6575230130Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 6576238022Smav const char *pdesc; 6577230130Smav char chans1[8], chans2[8]; 6578230130Smav char buf[128]; 6579230585Smav int loc1, loc2, t1, t2; 6580230130Smav 6581230130Smav if (pdevinfo->playas >= 0) 6582230130Smav loc1 = devinfo->as[pdevinfo->playas].location; 6583230130Smav else 6584230130Smav loc1 = devinfo->as[pdevinfo->recas].location; 6585230130Smav if (pdevinfo->recas >= 0) 6586230130Smav loc2 = devinfo->as[pdevinfo->recas].location; 6587230130Smav else 6588230130Smav loc2 = loc1; 6589230130Smav if (loc1 != loc2) 6590230130Smav loc1 = -2; 6591230130Smav if (loc1 >= 0 && HDA_LOCS[loc1][0] == '0') 6592230130Smav loc1 = -2; 6593230130Smav chans1[0] = 0; 6594230130Smav chans2[0] = 0; 6595230585Smav t1 = t2 = -1; 6596230585Smav if (pdevinfo->playas >= 0) { 6597230130Smav hdaa_chan_formula(devinfo, pdevinfo->playas, 6598230130Smav chans1, sizeof(chans1)); 6599230585Smav t1 = hdaa_chan_type(devinfo, pdevinfo->playas); 6600230585Smav } 6601230585Smav if (pdevinfo->recas >= 0) { 6602230130Smav hdaa_chan_formula(devinfo, pdevinfo->recas, 6603230130Smav chans2, sizeof(chans2)); 6604230585Smav t2 = hdaa_chan_type(devinfo, pdevinfo->recas); 6605230585Smav } 6606230130Smav if (chans1[0] != 0 || chans2[0] != 0) { 6607230130Smav if (chans1[0] == 0 && pdevinfo->playas >= 0) 6608230130Smav snprintf(chans1, sizeof(chans1), "2.0"); 6609230130Smav else if (chans2[0] == 0 && pdevinfo->recas >= 0) 6610230130Smav snprintf(chans2, sizeof(chans2), "2.0"); 6611230130Smav if (strcmp(chans1, chans2) == 0) 6612230130Smav chans2[0] = 0; 6613230130Smav } 6614230585Smav if (t1 == -1) 6615230585Smav t1 = t2; 6616230585Smav else if (t2 == -1) 6617230585Smav t2 = t1; 6618230585Smav if (t1 != t2) 6619230585Smav t1 = -2; 6620230585Smav if (pdevinfo->digital) 6621230585Smav t1 = -2; 6622238022Smav pdesc = device_get_desc(device_get_parent(dev)); 6623238022Smav snprintf(buf, sizeof(buf), "%.*s (%s%s%s%s%s%s%s%s%s)", 6624238022Smav (int)(strlen(pdesc) - 21), pdesc, 6625230130Smav loc1 >= 0 ? HDA_LOCS[loc1] : "", loc1 >= 0 ? " " : "", 6626230507Smav (pdevinfo->digital == 0x7)?"HDMI/DP": 6627230507Smav ((pdevinfo->digital == 0x5)?"DisplayPort": 6628230507Smav ((pdevinfo->digital == 0x3)?"HDMI": 6629230507Smav ((pdevinfo->digital)?"Digital":"Analog"))), 6630230130Smav chans1[0] ? " " : "", chans1, 6631230585Smav chans2[0] ? "/" : "", chans2, 6632230585Smav t1 >= 0 ? " " : "", t1 >= 0 ? HDA_DEVS[t1] : ""); 6633230130Smav device_set_desc_copy(dev, buf); 6634230130Smav return (BUS_PROBE_SPECIFIC); 6635230130Smav} 6636230130Smav 6637230130Smavstatic int 6638230130Smavhdaa_pcm_attach(device_t dev) 6639230130Smav{ 6640230130Smav struct hdaa_pcm_devinfo *pdevinfo = 6641230130Smav (struct hdaa_pcm_devinfo *)device_get_ivars(dev); 6642230130Smav struct hdaa_devinfo *devinfo = pdevinfo->devinfo; 6643230130Smav struct hdaa_audio_as *as; 6644230488Smav struct snddev_info *d; 6645230130Smav char status[SND_STATUSLEN]; 6646230130Smav int i; 6647230130Smav 6648230130Smav pdevinfo->chan_size = pcm_getbuffersize(dev, 6649230130Smav HDA_BUFSZ_MIN, HDA_BUFSZ_DEFAULT, HDA_BUFSZ_MAX); 6650230130Smav 6651230130Smav HDA_BOOTVERBOSE( 6652230130Smav device_printf(dev, "+--------------------------------------+\n"); 6653230130Smav device_printf(dev, "| DUMPING PCM Playback/Record Channels |\n"); 6654230130Smav device_printf(dev, "+--------------------------------------+\n"); 6655230130Smav hdaa_dump_pcmchannels(pdevinfo); 6656230130Smav device_printf(dev, "\n"); 6657230130Smav device_printf(dev, "+-------------------------------+\n"); 6658230130Smav device_printf(dev, "| DUMPING Playback/Record Paths |\n"); 6659230130Smav device_printf(dev, "+-------------------------------+\n"); 6660230130Smav hdaa_dump_dac(pdevinfo); 6661230130Smav hdaa_dump_adc(pdevinfo); 6662230130Smav hdaa_dump_mix(pdevinfo); 6663230130Smav device_printf(dev, "\n"); 6664230130Smav device_printf(dev, "+-------------------------+\n"); 6665230130Smav device_printf(dev, "| DUMPING Volume Controls |\n"); 6666230130Smav device_printf(dev, "+-------------------------+\n"); 6667230130Smav hdaa_dump_ctls(pdevinfo, "Master Volume", SOUND_MASK_VOLUME); 6668230130Smav hdaa_dump_ctls(pdevinfo, "PCM Volume", SOUND_MASK_PCM); 6669230130Smav hdaa_dump_ctls(pdevinfo, "CD Volume", SOUND_MASK_CD); 6670230130Smav hdaa_dump_ctls(pdevinfo, "Microphone Volume", SOUND_MASK_MIC); 6671230130Smav hdaa_dump_ctls(pdevinfo, "Microphone2 Volume", SOUND_MASK_MONITOR); 6672230130Smav hdaa_dump_ctls(pdevinfo, "Line-in Volume", SOUND_MASK_LINE); 6673230130Smav hdaa_dump_ctls(pdevinfo, "Speaker/Beep Volume", SOUND_MASK_SPEAKER); 6674230130Smav hdaa_dump_ctls(pdevinfo, "Recording Level", SOUND_MASK_RECLEV); 6675230130Smav hdaa_dump_ctls(pdevinfo, "Input Mix Level", SOUND_MASK_IMIX); 6676230130Smav hdaa_dump_ctls(pdevinfo, "Input Monitoring Level", SOUND_MASK_IGAIN); 6677230130Smav hdaa_dump_ctls(pdevinfo, NULL, 0); 6678230130Smav device_printf(dev, "\n"); 6679230130Smav ); 6680230130Smav 6681230130Smav if (resource_int_value(device_get_name(dev), 6682230130Smav device_get_unit(dev), "blocksize", &i) == 0 && i > 0) { 6683230130Smav i &= HDA_BLK_ALIGN; 6684230130Smav if (i < HDA_BLK_MIN) 6685230130Smav i = HDA_BLK_MIN; 6686230130Smav pdevinfo->chan_blkcnt = pdevinfo->chan_size / i; 6687230130Smav i = 0; 6688230130Smav while (pdevinfo->chan_blkcnt >> i) 6689230130Smav i++; 6690230130Smav pdevinfo->chan_blkcnt = 1 << (i - 1); 6691230130Smav if (pdevinfo->chan_blkcnt < HDA_BDL_MIN) 6692230130Smav pdevinfo->chan_blkcnt = HDA_BDL_MIN; 6693230130Smav else if (pdevinfo->chan_blkcnt > HDA_BDL_MAX) 6694230130Smav pdevinfo->chan_blkcnt = HDA_BDL_MAX; 6695230130Smav } else 6696230130Smav pdevinfo->chan_blkcnt = HDA_BDL_DEFAULT; 6697230130Smav 6698230130Smav /* 6699230130Smav * We don't register interrupt handler with snd_setup_intr 6700230130Smav * in pcm device. Mark pcm device as MPSAFE manually. 6701230130Smav */ 6702230130Smav pcm_setflags(dev, pcm_getflags(dev) | SD_F_MPSAFE); 6703230130Smav 6704230130Smav HDA_BOOTHVERBOSE( 6705230130Smav device_printf(dev, "OSS mixer initialization...\n"); 6706230130Smav ); 6707230130Smav if (mixer_init(dev, &hdaa_audio_ctl_ossmixer_class, pdevinfo) != 0) 6708230130Smav device_printf(dev, "Can't register mixer\n"); 6709230130Smav 6710230130Smav HDA_BOOTHVERBOSE( 6711230130Smav device_printf(dev, "Registering PCM channels...\n"); 6712230130Smav ); 6713230130Smav if (pcm_register(dev, pdevinfo, (pdevinfo->playas >= 0)?1:0, 6714230130Smav (pdevinfo->recas >= 0)?1:0) != 0) 6715230130Smav device_printf(dev, "Can't register PCM\n"); 6716230130Smav 6717230130Smav pdevinfo->registered++; 6718230130Smav 6719230488Smav d = device_get_softc(dev); 6720230130Smav if (pdevinfo->playas >= 0) { 6721230130Smav as = &devinfo->as[pdevinfo->playas]; 6722230130Smav for (i = 0; i < as->num_chans; i++) 6723230130Smav pcm_addchan(dev, PCMDIR_PLAY, &hdaa_channel_class, 6724230130Smav &devinfo->chans[as->chans[i]]); 6725230488Smav SYSCTL_ADD_PROC(&d->play_sysctl_ctx, 6726230488Smav SYSCTL_CHILDREN(d->play_sysctl_tree), OID_AUTO, 6727230488Smav "32bit", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, 6728230488Smav as, sizeof(as), hdaa_sysctl_32bit, "I", 6729230488Smav "Resolution of 32bit samples (20/24/32bit)"); 6730230130Smav } 6731230130Smav if (pdevinfo->recas >= 0) { 6732230130Smav as = &devinfo->as[pdevinfo->recas]; 6733230130Smav for (i = 0; i < as->num_chans; i++) 6734230130Smav pcm_addchan(dev, PCMDIR_REC, &hdaa_channel_class, 6735230130Smav &devinfo->chans[as->chans[i]]); 6736230488Smav SYSCTL_ADD_PROC(&d->rec_sysctl_ctx, 6737230488Smav SYSCTL_CHILDREN(d->rec_sysctl_tree), OID_AUTO, 6738230488Smav "32bit", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, 6739230488Smav as, sizeof(as), hdaa_sysctl_32bit, "I", 6740230488Smav "Resolution of 32bit samples (20/24/32bit)"); 6741230551Smav pdevinfo->autorecsrc = 2; 6742230554Smav resource_int_value(device_get_name(dev), device_get_unit(dev), 6743230554Smav "rec.autosrc", &pdevinfo->autorecsrc); 6744230551Smav SYSCTL_ADD_INT(&d->rec_sysctl_ctx, 6745230551Smav SYSCTL_CHILDREN(d->rec_sysctl_tree), OID_AUTO, 6746230551Smav "autosrc", CTLTYPE_INT | CTLFLAG_RW, 6747230551Smav &pdevinfo->autorecsrc, 0, 6748230551Smav "Automatic recording source selection"); 6749230130Smav } 6750230130Smav 6751230551Smav if (pdevinfo->mixer != NULL) { 6752230551Smav hdaa_audio_ctl_set_defaults(pdevinfo); 6753230551Smav if (pdevinfo->recas >= 0) { 6754230551Smav as = &devinfo->as[pdevinfo->recas]; 6755230551Smav hdaa_lock(devinfo); 6756230551Smav hdaa_autorecsrc_handler(as, NULL); 6757230551Smav hdaa_unlock(devinfo); 6758230551Smav } 6759230551Smav } 6760230551Smav 6761230130Smav snprintf(status, SND_STATUSLEN, "on %s %s", 6762230130Smav device_get_nameunit(device_get_parent(dev)), 6763230130Smav PCM_KLDSTRING(snd_hda)); 6764230130Smav pcm_setstatus(dev, status); 6765230130Smav 6766230130Smav return (0); 6767230130Smav} 6768230130Smav 6769230130Smavstatic int 6770230130Smavhdaa_pcm_detach(device_t dev) 6771230130Smav{ 6772230130Smav struct hdaa_pcm_devinfo *pdevinfo = 6773230130Smav (struct hdaa_pcm_devinfo *)device_get_ivars(dev); 6774230130Smav int err; 6775230130Smav 6776230130Smav if (pdevinfo->registered > 0) { 6777230130Smav err = pcm_unregister(dev); 6778230130Smav if (err != 0) 6779230130Smav return (err); 6780230130Smav } 6781230130Smav 6782230130Smav return (0); 6783230130Smav} 6784230130Smav 6785230130Smavstatic device_method_t hdaa_pcm_methods[] = { 6786230130Smav /* device interface */ 6787230130Smav DEVMETHOD(device_probe, hdaa_pcm_probe), 6788230130Smav DEVMETHOD(device_attach, hdaa_pcm_attach), 6789230130Smav DEVMETHOD(device_detach, hdaa_pcm_detach), 6790230130Smav { 0, 0 } 6791230130Smav}; 6792230130Smav 6793230130Smavstatic driver_t hdaa_pcm_driver = { 6794230130Smav "pcm", 6795230130Smav hdaa_pcm_methods, 6796230130Smav PCM_SOFTC_SIZE, 6797230130Smav}; 6798230130Smav 6799230130SmavDRIVER_MODULE(snd_hda_pcm, hdaa, hdaa_pcm_driver, pcm_devclass, 0, 0); 6800230130SmavMODULE_DEPEND(snd_hda, sound, SOUND_MINVER, SOUND_PREFVER, SOUND_MAXVER); 6801230130SmavMODULE_VERSION(snd_hda, 1); 6802