1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2006 Stephane E. Potvin <sepotvin@videotron.ca> 5 * Copyright (c) 2006 Ariff Abdullah <ariff@FreeBSD.org> 6 * Copyright (c) 2008-2012 Alexander Motin <mav@FreeBSD.org> 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31 /* 32 * Intel High Definition Audio (CODEC) driver for FreeBSD. 33 */ 34 35 #ifdef HAVE_KERNEL_OPTION_HEADERS 36 #include "opt_snd.h" 37 #endif 38 39 #include <dev/sound/pcm/sound.h> 40 41 #include <sys/ctype.h> 42 43 #include <dev/sound/pci/hda/hda_reg.h> 44 #include <dev/sound/pci/hda/hdac.h> 45 46 SND_DECLARE_FILE("$FreeBSD$"); 47 48 struct hdacc_fg { 49 device_t dev; 50 nid_t nid; 51 uint8_t type; 52 uint32_t subsystem_id; 53 }; 54 55 struct hdacc_softc { 56 device_t dev; 57 struct mtx *lock; 58 nid_t cad; 59 device_t streams[2][16]; 60 device_t tags[64]; 61 int fgcnt; 62 struct hdacc_fg *fgs; 63 }; 64 65 #define hdacc_lock(codec) snd_mtxlock((codec)->lock) 66 #define hdacc_unlock(codec) snd_mtxunlock((codec)->lock) 67 #define hdacc_lockassert(codec) snd_mtxassert((codec)->lock) 68 #define hdacc_lockowned(codec) mtx_owned((codec)->lock) 69 70 MALLOC_DEFINE(M_HDACC, "hdacc", "HDA CODEC"); 71 72 /* CODECs */ 73 static const struct { 74 uint32_t id; 75 uint16_t revid; 76 const char *name; 77 } hdacc_codecs[] = { 78 { HDA_CODEC_CS4206, 0, "Cirrus Logic CS4206" }, 79 { HDA_CODEC_CS4207, 0, "Cirrus Logic CS4207" }, 80 { HDA_CODEC_CS4210, 0, "Cirrus Logic CS4210" }, 81 { HDA_CODEC_ALC221, 0, "Realtek ALC221" }, 82 { HDA_CODEC_ALC225, 0, "Realtek ALC225" }, 83 { HDA_CODEC_ALC231, 0, "Realtek ALC231" }, 84 { HDA_CODEC_ALC233, 0, "Realtek ALC233" }, 85 { HDA_CODEC_ALC234, 0, "Realtek ALC234" }, 86 { HDA_CODEC_ALC235, 0, "Realtek ALC235" }, 87 { HDA_CODEC_ALC255, 0, "Realtek ALC255" }, 88 { HDA_CODEC_ALC256, 0, "Realtek ALC256" }, 89 { HDA_CODEC_ALC260, 0, "Realtek ALC260" }, 90 { HDA_CODEC_ALC262, 0, "Realtek ALC262" }, 91 { HDA_CODEC_ALC267, 0, "Realtek ALC267" }, 92 { HDA_CODEC_ALC268, 0, "Realtek ALC268" }, 93 { HDA_CODEC_ALC269, 0, "Realtek ALC269" }, 94 { HDA_CODEC_ALC270, 0, "Realtek ALC270" }, 95 { HDA_CODEC_ALC272, 0, "Realtek ALC272" }, 96 { HDA_CODEC_ALC273, 0, "Realtek ALC273" }, 97 { HDA_CODEC_ALC274, 0, "Realtek ALC274" }, 98 { HDA_CODEC_ALC275, 0, "Realtek ALC275" }, 99 { HDA_CODEC_ALC276, 0, "Realtek ALC276" }, 100 { HDA_CODEC_ALC292, 0, "Realtek ALC292" }, 101 { HDA_CODEC_ALC295, 0, "Realtek ALC295" }, 102 { HDA_CODEC_ALC280, 0, "Realtek ALC280" }, 103 { HDA_CODEC_ALC282, 0, "Realtek ALC282" }, 104 { HDA_CODEC_ALC283, 0, "Realtek ALC283" }, 105 { HDA_CODEC_ALC284, 0, "Realtek ALC284" }, 106 { HDA_CODEC_ALC285, 0, "Realtek ALC285" }, 107 { HDA_CODEC_ALC286, 0, "Realtek ALC286" }, 108 { HDA_CODEC_ALC288, 0, "Realtek ALC288" }, 109 { HDA_CODEC_ALC290, 0, "Realtek ALC290" }, 110 { HDA_CODEC_ALC292, 0, "Realtek ALC292" }, 111 { HDA_CODEC_ALC293, 0, "Realtek ALC293" }, 112 { HDA_CODEC_ALC294, 0, "Realtek ALC294" }, 113 { HDA_CODEC_ALC295, 0, "Realtek ALC295" }, 114 { HDA_CODEC_ALC298, 0, "Realtek ALC298" }, 115 { HDA_CODEC_ALC299, 0, "Realtek ALC299" }, 116 { HDA_CODEC_ALC660, 0, "Realtek ALC660-VD" }, 117 { HDA_CODEC_ALC662, 0x0002, "Realtek ALC662 rev2" }, 118 { HDA_CODEC_ALC662, 0, "Realtek ALC662" }, 119 { HDA_CODEC_ALC663, 0, "Realtek ALC663" }, 120 { HDA_CODEC_ALC665, 0, "Realtek ALC665" }, 121 { HDA_CODEC_ALC670, 0, "Realtek ALC670" }, 122 { HDA_CODEC_ALC671, 0, "Realtek ALC671" }, 123 { HDA_CODEC_ALC680, 0, "Realtek ALC680" }, 124 { HDA_CODEC_ALC700, 0, "Realtek ALC700" }, 125 { HDA_CODEC_ALC701, 0, "Realtek ALC701" }, 126 { HDA_CODEC_ALC703, 0, "Realtek ALC703" }, 127 { HDA_CODEC_ALC861, 0x0340, "Realtek ALC660" }, 128 { HDA_CODEC_ALC861, 0, "Realtek ALC861" }, 129 { HDA_CODEC_ALC861VD, 0, "Realtek ALC861-VD" }, 130 { HDA_CODEC_ALC880, 0, "Realtek ALC880" }, 131 { HDA_CODEC_ALC882, 0, "Realtek ALC882" }, 132 { HDA_CODEC_ALC883, 0, "Realtek ALC883" }, 133 { HDA_CODEC_ALC885, 0x0101, "Realtek ALC889A" }, 134 { HDA_CODEC_ALC885, 0x0103, "Realtek ALC889A" }, 135 { HDA_CODEC_ALC885, 0, "Realtek ALC885" }, 136 { HDA_CODEC_ALC887, 0, "Realtek ALC887" }, 137 { HDA_CODEC_ALC888, 0x0101, "Realtek ALC1200" }, 138 { HDA_CODEC_ALC888, 0, "Realtek ALC888" }, 139 { HDA_CODEC_ALC889, 0, "Realtek ALC889" }, 140 { HDA_CODEC_ALC892, 0, "Realtek ALC892" }, 141 { HDA_CODEC_ALC899, 0, "Realtek ALC899" }, 142 { HDA_CODEC_ALC1150, 0, "Realtek ALC1150" }, 143 { HDA_CODEC_ALC1220, 0, "Realtek ALC1220" }, 144 { HDA_CODEC_AD1882, 0, "Analog Devices AD1882" }, 145 { HDA_CODEC_AD1882A, 0, "Analog Devices AD1882A" }, 146 { HDA_CODEC_AD1883, 0, "Analog Devices AD1883" }, 147 { HDA_CODEC_AD1884, 0, "Analog Devices AD1884" }, 148 { HDA_CODEC_AD1884A, 0, "Analog Devices AD1884A" }, 149 { HDA_CODEC_AD1981HD, 0, "Analog Devices AD1981HD" }, 150 { HDA_CODEC_AD1983, 0, "Analog Devices AD1983" }, 151 { HDA_CODEC_AD1984, 0, "Analog Devices AD1984" }, 152 { HDA_CODEC_AD1984A, 0, "Analog Devices AD1984A" }, 153 { HDA_CODEC_AD1984B, 0, "Analog Devices AD1984B" }, 154 { HDA_CODEC_AD1986A, 0, "Analog Devices AD1986A" }, 155 { HDA_CODEC_AD1987, 0, "Analog Devices AD1987" }, 156 { HDA_CODEC_AD1988, 0, "Analog Devices AD1988A" }, 157 { HDA_CODEC_AD1988B, 0, "Analog Devices AD1988B" }, 158 { HDA_CODEC_AD1989A, 0, "Analog Devices AD1989A" }, 159 { HDA_CODEC_AD1989B, 0, "Analog Devices AD1989B" }, 160 { HDA_CODEC_CA0110, 0, "Creative CA0110-IBG" }, 161 { HDA_CODEC_CA0110_2, 0, "Creative CA0110-IBG" }, 162 { HDA_CODEC_CA0132, 0, "Creative CA0132" }, 163 { HDA_CODEC_SB0880, 0, "Creative SB0880 X-Fi" }, 164 { HDA_CODEC_CMI9880, 0, "CMedia CMI9880" }, 165 { HDA_CODEC_CMI98802, 0, "CMedia CMI9880" }, 166 { HDA_CODEC_CXD9872RDK, 0, "Sigmatel CXD9872RD/K" }, 167 { HDA_CODEC_CXD9872AKD, 0, "Sigmatel CXD9872AKD" }, 168 { HDA_CODEC_STAC9200D, 0, "Sigmatel STAC9200D" }, 169 { HDA_CODEC_STAC9204X, 0, "Sigmatel STAC9204X" }, 170 { HDA_CODEC_STAC9204D, 0, "Sigmatel STAC9204D" }, 171 { HDA_CODEC_STAC9205X, 0, "Sigmatel STAC9205X" }, 172 { HDA_CODEC_STAC9205D, 0, "Sigmatel STAC9205D" }, 173 { HDA_CODEC_STAC9220, 0, "Sigmatel STAC9220" }, 174 { HDA_CODEC_STAC9220_A1, 0, "Sigmatel STAC9220_A1" }, 175 { HDA_CODEC_STAC9220_A2, 0, "Sigmatel STAC9220_A2" }, 176 { HDA_CODEC_STAC9221, 0, "Sigmatel STAC9221" }, 177 { HDA_CODEC_STAC9221_A2, 0, "Sigmatel STAC9221_A2" }, 178 { HDA_CODEC_STAC9221D, 0, "Sigmatel STAC9221D" }, 179 { HDA_CODEC_STAC922XD, 0, "Sigmatel STAC9220D/9223D" }, 180 { HDA_CODEC_STAC9227X, 0, "Sigmatel STAC9227X" }, 181 { HDA_CODEC_STAC9227D, 0, "Sigmatel STAC9227D" }, 182 { HDA_CODEC_STAC9228X, 0, "Sigmatel STAC9228X" }, 183 { HDA_CODEC_STAC9228D, 0, "Sigmatel STAC9228D" }, 184 { HDA_CODEC_STAC9229X, 0, "Sigmatel STAC9229X" }, 185 { HDA_CODEC_STAC9229D, 0, "Sigmatel STAC9229D" }, 186 { HDA_CODEC_STAC9230X, 0, "Sigmatel STAC9230X" }, 187 { HDA_CODEC_STAC9230D, 0, "Sigmatel STAC9230D" }, 188 { HDA_CODEC_STAC9250, 0, "Sigmatel STAC9250" }, 189 { HDA_CODEC_STAC9251, 0, "Sigmatel STAC9251" }, 190 { HDA_CODEC_STAC9255, 0, "Sigmatel STAC9255" }, 191 { HDA_CODEC_STAC9255D, 0, "Sigmatel STAC9255D" }, 192 { HDA_CODEC_STAC9254, 0, "Sigmatel STAC9254" }, 193 { HDA_CODEC_STAC9254D, 0, "Sigmatel STAC9254D" }, 194 { HDA_CODEC_STAC9271X, 0, "Sigmatel STAC9271X" }, 195 { HDA_CODEC_STAC9271D, 0, "Sigmatel STAC9271D" }, 196 { HDA_CODEC_STAC9272X, 0, "Sigmatel STAC9272X" }, 197 { HDA_CODEC_STAC9272D, 0, "Sigmatel STAC9272D" }, 198 { HDA_CODEC_STAC9273X, 0, "Sigmatel STAC9273X" }, 199 { HDA_CODEC_STAC9273D, 0, "Sigmatel STAC9273D" }, 200 { HDA_CODEC_STAC9274, 0, "Sigmatel STAC9274" }, 201 { HDA_CODEC_STAC9274D, 0, "Sigmatel STAC9274D" }, 202 { HDA_CODEC_STAC9274X5NH, 0, "Sigmatel STAC9274X5NH" }, 203 { HDA_CODEC_STAC9274D5NH, 0, "Sigmatel STAC9274D5NH" }, 204 { HDA_CODEC_STAC9872AK, 0, "Sigmatel STAC9872AK" }, 205 { HDA_CODEC_IDT92HD005, 0, "IDT 92HD005" }, 206 { HDA_CODEC_IDT92HD005D, 0, "IDT 92HD005D" }, 207 { HDA_CODEC_IDT92HD206X, 0, "IDT 92HD206X" }, 208 { HDA_CODEC_IDT92HD206D, 0, "IDT 92HD206D" }, 209 { HDA_CODEC_IDT92HD66B1X5, 0, "IDT 92HD66B1X5" }, 210 { HDA_CODEC_IDT92HD66B2X5, 0, "IDT 92HD66B2X5" }, 211 { HDA_CODEC_IDT92HD66B3X5, 0, "IDT 92HD66B3X5" }, 212 { HDA_CODEC_IDT92HD66C1X5, 0, "IDT 92HD66C1X5" }, 213 { HDA_CODEC_IDT92HD66C2X5, 0, "IDT 92HD66C2X5" }, 214 { HDA_CODEC_IDT92HD66C3X5, 0, "IDT 92HD66C3X5" }, 215 { HDA_CODEC_IDT92HD66B1X3, 0, "IDT 92HD66B1X3" }, 216 { HDA_CODEC_IDT92HD66B2X3, 0, "IDT 92HD66B2X3" }, 217 { HDA_CODEC_IDT92HD66B3X3, 0, "IDT 92HD66B3X3" }, 218 { HDA_CODEC_IDT92HD66C1X3, 0, "IDT 92HD66C1X3" }, 219 { HDA_CODEC_IDT92HD66C2X3, 0, "IDT 92HD66C2X3" }, 220 { HDA_CODEC_IDT92HD66C3_65, 0, "IDT 92HD66C3_65" }, 221 { HDA_CODEC_IDT92HD700X, 0, "IDT 92HD700X" }, 222 { HDA_CODEC_IDT92HD700D, 0, "IDT 92HD700D" }, 223 { HDA_CODEC_IDT92HD71B5, 0, "IDT 92HD71B5" }, 224 { HDA_CODEC_IDT92HD71B5_2, 0, "IDT 92HD71B5" }, 225 { HDA_CODEC_IDT92HD71B6, 0, "IDT 92HD71B6" }, 226 { HDA_CODEC_IDT92HD71B6_2, 0, "IDT 92HD71B6" }, 227 { HDA_CODEC_IDT92HD71B7, 0, "IDT 92HD71B7" }, 228 { HDA_CODEC_IDT92HD71B7_2, 0, "IDT 92HD71B7" }, 229 { HDA_CODEC_IDT92HD71B8, 0, "IDT 92HD71B8" }, 230 { HDA_CODEC_IDT92HD71B8_2, 0, "IDT 92HD71B8" }, 231 { HDA_CODEC_IDT92HD73C1, 0, "IDT 92HD73C1" }, 232 { HDA_CODEC_IDT92HD73D1, 0, "IDT 92HD73D1" }, 233 { HDA_CODEC_IDT92HD73E1, 0, "IDT 92HD73E1" }, 234 { HDA_CODEC_IDT92HD75B3, 0, "IDT 92HD75B3" }, 235 { HDA_CODEC_IDT92HD75BX, 0, "IDT 92HD75BX" }, 236 { HDA_CODEC_IDT92HD81B1C, 0, "IDT 92HD81B1C" }, 237 { HDA_CODEC_IDT92HD81B1X, 0, "IDT 92HD81B1X" }, 238 { HDA_CODEC_IDT92HD83C1C, 0, "IDT 92HD83C1C" }, 239 { HDA_CODEC_IDT92HD83C1X, 0, "IDT 92HD83C1X" }, 240 { HDA_CODEC_IDT92HD87B1_3, 0, "IDT 92HD87B1/3" }, 241 { HDA_CODEC_IDT92HD87B2_4, 0, "IDT 92HD87B2/4" }, 242 { HDA_CODEC_IDT92HD89C3, 0, "IDT 92HD89C3" }, 243 { HDA_CODEC_IDT92HD89C2, 0, "IDT 92HD89C2" }, 244 { HDA_CODEC_IDT92HD89C1, 0, "IDT 92HD89C1" }, 245 { HDA_CODEC_IDT92HD89B3, 0, "IDT 92HD89B3" }, 246 { HDA_CODEC_IDT92HD89B2, 0, "IDT 92HD89B2" }, 247 { HDA_CODEC_IDT92HD89B1, 0, "IDT 92HD89B1" }, 248 { HDA_CODEC_IDT92HD89E3, 0, "IDT 92HD89E3" }, 249 { HDA_CODEC_IDT92HD89E2, 0, "IDT 92HD89E2" }, 250 { HDA_CODEC_IDT92HD89E1, 0, "IDT 92HD89E1" }, 251 { HDA_CODEC_IDT92HD89D3, 0, "IDT 92HD89D3" }, 252 { HDA_CODEC_IDT92HD89D2, 0, "IDT 92HD89D2" }, 253 { HDA_CODEC_IDT92HD89D1, 0, "IDT 92HD89D1" }, 254 { HDA_CODEC_IDT92HD89F3, 0, "IDT 92HD89F3" }, 255 { HDA_CODEC_IDT92HD89F2, 0, "IDT 92HD89F2" }, 256 { HDA_CODEC_IDT92HD89F1, 0, "IDT 92HD89F1" }, 257 { HDA_CODEC_IDT92HD90BXX, 0, "IDT 92HD90BXX" }, 258 { HDA_CODEC_IDT92HD91BXX, 0, "IDT 92HD91BXX" }, 259 { HDA_CODEC_IDT92HD93BXX, 0, "IDT 92HD93BXX" }, 260 { HDA_CODEC_IDT92HD98BXX, 0, "IDT 92HD98BXX" }, 261 { HDA_CODEC_IDT92HD99BXX, 0, "IDT 92HD99BXX" }, 262 { HDA_CODEC_CX20549, 0, "Conexant CX20549 (Venice)" }, 263 { HDA_CODEC_CX20551, 0, "Conexant CX20551 (Waikiki)" }, 264 { HDA_CODEC_CX20561, 0, "Conexant CX20561 (Hermosa)" }, 265 { HDA_CODEC_CX20582, 0, "Conexant CX20582 (Pebble)" }, 266 { HDA_CODEC_CX20583, 0, "Conexant CX20583 (Pebble HSF)" }, 267 { HDA_CODEC_CX20584, 0, "Conexant CX20584" }, 268 { HDA_CODEC_CX20585, 0, "Conexant CX20585" }, 269 { HDA_CODEC_CX20588, 0, "Conexant CX20588" }, 270 { HDA_CODEC_CX20590, 0, "Conexant CX20590" }, 271 { HDA_CODEC_CX20631, 0, "Conexant CX20631" }, 272 { HDA_CODEC_CX20632, 0, "Conexant CX20632" }, 273 { HDA_CODEC_CX20641, 0, "Conexant CX20641" }, 274 { HDA_CODEC_CX20642, 0, "Conexant CX20642" }, 275 { HDA_CODEC_CX20651, 0, "Conexant CX20651" }, 276 { HDA_CODEC_CX20652, 0, "Conexant CX20652" }, 277 { HDA_CODEC_CX20664, 0, "Conexant CX20664" }, 278 { HDA_CODEC_CX20665, 0, "Conexant CX20665" }, 279 { HDA_CODEC_CX21722, 0, "Conexant CX21722" }, 280 { HDA_CODEC_CX20722, 0, "Conexant CX20722" }, 281 { HDA_CODEC_CX21724, 0, "Conexant CX21724" }, 282 { HDA_CODEC_CX20724, 0, "Conexant CX20724" }, 283 { HDA_CODEC_CX20751, 0, "Conexant CX20751/2" }, 284 { HDA_CODEC_CX20751_2, 0, "Conexant CX20751/2" }, 285 { HDA_CODEC_CX20753, 0, "Conexant CX20753/4" }, 286 { HDA_CODEC_CX20755, 0, "Conexant CX20755" }, 287 { HDA_CODEC_CX20756, 0, "Conexant CX20756" }, 288 { HDA_CODEC_CX20757, 0, "Conexant CX20757" }, 289 { HDA_CODEC_CX20952, 0, "Conexant CX20952" }, 290 { HDA_CODEC_VT1708_8, 0, "VIA VT1708_8" }, 291 { HDA_CODEC_VT1708_9, 0, "VIA VT1708_9" }, 292 { HDA_CODEC_VT1708_A, 0, "VIA VT1708_A" }, 293 { HDA_CODEC_VT1708_B, 0, "VIA VT1708_B" }, 294 { HDA_CODEC_VT1709_0, 0, "VIA VT1709_0" }, 295 { HDA_CODEC_VT1709_1, 0, "VIA VT1709_1" }, 296 { HDA_CODEC_VT1709_2, 0, "VIA VT1709_2" }, 297 { HDA_CODEC_VT1709_3, 0, "VIA VT1709_3" }, 298 { HDA_CODEC_VT1709_4, 0, "VIA VT1709_4" }, 299 { HDA_CODEC_VT1709_5, 0, "VIA VT1709_5" }, 300 { HDA_CODEC_VT1709_6, 0, "VIA VT1709_6" }, 301 { HDA_CODEC_VT1709_7, 0, "VIA VT1709_7" }, 302 { HDA_CODEC_VT1708B_0, 0, "VIA VT1708B_0" }, 303 { HDA_CODEC_VT1708B_1, 0, "VIA VT1708B_1" }, 304 { HDA_CODEC_VT1708B_2, 0, "VIA VT1708B_2" }, 305 { HDA_CODEC_VT1708B_3, 0, "VIA VT1708B_3" }, 306 { HDA_CODEC_VT1708B_4, 0, "VIA VT1708B_4" }, 307 { HDA_CODEC_VT1708B_5, 0, "VIA VT1708B_5" }, 308 { HDA_CODEC_VT1708B_6, 0, "VIA VT1708B_6" }, 309 { HDA_CODEC_VT1708B_7, 0, "VIA VT1708B_7" }, 310 { HDA_CODEC_VT1708S_0, 0, "VIA VT1708S_0" }, 311 { HDA_CODEC_VT1708S_1, 0, "VIA VT1708S_1" }, 312 { HDA_CODEC_VT1708S_2, 0, "VIA VT1708S_2" }, 313 { HDA_CODEC_VT1708S_3, 0, "VIA VT1708S_3" }, 314 { HDA_CODEC_VT1708S_4, 0, "VIA VT1708S_4" }, 315 { HDA_CODEC_VT1708S_5, 0, "VIA VT1708S_5" }, 316 { HDA_CODEC_VT1708S_6, 0, "VIA VT1708S_6" }, 317 { HDA_CODEC_VT1708S_7, 0, "VIA VT1708S_7" }, 318 { HDA_CODEC_VT1702_0, 0, "VIA VT1702_0" }, 319 { HDA_CODEC_VT1702_1, 0, "VIA VT1702_1" }, 320 { HDA_CODEC_VT1702_2, 0, "VIA VT1702_2" }, 321 { HDA_CODEC_VT1702_3, 0, "VIA VT1702_3" }, 322 { HDA_CODEC_VT1702_4, 0, "VIA VT1702_4" }, 323 { HDA_CODEC_VT1702_5, 0, "VIA VT1702_5" }, 324 { HDA_CODEC_VT1702_6, 0, "VIA VT1702_6" }, 325 { HDA_CODEC_VT1702_7, 0, "VIA VT1702_7" }, 326 { HDA_CODEC_VT1716S_0, 0, "VIA VT1716S_0" }, 327 { HDA_CODEC_VT1716S_1, 0, "VIA VT1716S_1" }, 328 { HDA_CODEC_VT1718S_0, 0, "VIA VT1718S_0" }, 329 { HDA_CODEC_VT1718S_1, 0, "VIA VT1718S_1" }, 330 { HDA_CODEC_VT1802_0, 0, "VIA VT1802_0" }, 331 { HDA_CODEC_VT1802_1, 0, "VIA VT1802_1" }, 332 { HDA_CODEC_VT1812, 0, "VIA VT1812" }, 333 { HDA_CODEC_VT1818S, 0, "VIA VT1818S" }, 334 { HDA_CODEC_VT1828S, 0, "VIA VT1828S" }, 335 { HDA_CODEC_VT2002P_0, 0, "VIA VT2002P_0" }, 336 { HDA_CODEC_VT2002P_1, 0, "VIA VT2002P_1" }, 337 { HDA_CODEC_VT2020, 0, "VIA VT2020" }, 338 { HDA_CODEC_ATIRS600_1, 0, "ATI RS600" }, 339 { HDA_CODEC_ATIRS600_2, 0, "ATI RS600" }, 340 { HDA_CODEC_ATIRS690, 0, "ATI RS690/780" }, 341 { HDA_CODEC_ATIR6XX, 0, "ATI R6xx" }, 342 { HDA_CODEC_NVIDIAMCP67, 0, "NVIDIA MCP67" }, 343 { HDA_CODEC_NVIDIAMCP73, 0, "NVIDIA MCP73" }, 344 { HDA_CODEC_NVIDIAMCP78, 0, "NVIDIA MCP78" }, 345 { HDA_CODEC_NVIDIAMCP78_2, 0, "NVIDIA MCP78" }, 346 { HDA_CODEC_NVIDIAMCP78_3, 0, "NVIDIA MCP78" }, 347 { HDA_CODEC_NVIDIAMCP78_4, 0, "NVIDIA MCP78" }, 348 { HDA_CODEC_NVIDIAMCP7A, 0, "NVIDIA MCP7A" }, 349 { HDA_CODEC_NVIDIAGT220, 0, "NVIDIA GT220" }, 350 { HDA_CODEC_NVIDIAGT21X, 0, "NVIDIA GT21x" }, 351 { HDA_CODEC_NVIDIAMCP89, 0, "NVIDIA MCP89" }, 352 { HDA_CODEC_NVIDIAGT240, 0, "NVIDIA GT240" }, 353 { HDA_CODEC_NVIDIAGTS450, 0, "NVIDIA GTS450" }, 354 { HDA_CODEC_NVIDIAGT440, 0, "NVIDIA GT440" }, 355 { HDA_CODEC_NVIDIAGTX550, 0, "NVIDIA GTX550" }, 356 { HDA_CODEC_NVIDIAGTX570, 0, "NVIDIA GTX570" }, 357 { HDA_CODEC_NVIDIATEGRA30, 0, "NVIDIA Tegra30" }, 358 { HDA_CODEC_NVIDIATEGRA114, 0, "NVIDIA Tegra114" }, 359 { HDA_CODEC_NVIDIATEGRA124, 0, "NVIDIA Tegra124" }, 360 { HDA_CODEC_NVIDIATEGRA210, 0, "NVIDIA Tegra210" }, 361 { HDA_CODEC_INTELIP, 0, "Intel Ibex Peak" }, 362 { HDA_CODEC_INTELBL, 0, "Intel Bearlake" }, 363 { HDA_CODEC_INTELCA, 0, "Intel Cantiga" }, 364 { HDA_CODEC_INTELEL, 0, "Intel Eaglelake" }, 365 { HDA_CODEC_INTELIP2, 0, "Intel Ibex Peak" }, 366 { HDA_CODEC_INTELCPT, 0, "Intel Cougar Point" }, 367 { HDA_CODEC_INTELPPT, 0, "Intel Panther Point" }, 368 { HDA_CODEC_INTELHSW, 0, "Intel Haswell" }, 369 { HDA_CODEC_INTELBDW, 0, "Intel Broadwell" }, 370 { HDA_CODEC_INTELSKLK, 0, "Intel Skylake" }, 371 { HDA_CODEC_INTELKBLK, 0, "Intel Kabylake" }, 372 { HDA_CODEC_INTELCL, 0, "Intel Crestline" }, 373 { HDA_CODEC_SII1390, 0, "Silicon Image SiI1390" }, 374 { HDA_CODEC_SII1392, 0, "Silicon Image SiI1392" }, 375 /* Unknown CODECs */ 376 { HDA_CODEC_ADXXXX, 0, "Analog Devices" }, 377 { HDA_CODEC_AGEREXXXX, 0, "Lucent/Agere Systems" }, 378 { HDA_CODEC_ALCXXXX, 0, "Realtek" }, 379 { HDA_CODEC_ATIXXXX, 0, "ATI" }, 380 { HDA_CODEC_CAXXXX, 0, "Creative" }, 381 { HDA_CODEC_CMIXXXX, 0, "CMedia" }, 382 { HDA_CODEC_CMIXXXX2, 0, "CMedia" }, 383 { HDA_CODEC_CSXXXX, 0, "Cirrus Logic" }, 384 { HDA_CODEC_CXXXXX, 0, "Conexant" }, 385 { HDA_CODEC_CHXXXX, 0, "Chrontel" }, 386 { HDA_CODEC_IDTXXXX, 0, "IDT" }, 387 { HDA_CODEC_INTELXXXX, 0, "Intel" }, 388 { HDA_CODEC_MOTOXXXX, 0, "Motorola" }, 389 { HDA_CODEC_NVIDIAXXXX, 0, "NVIDIA" }, 390 { HDA_CODEC_SIIXXXX, 0, "Silicon Image" }, 391 { HDA_CODEC_STACXXXX, 0, "Sigmatel" }, 392 { HDA_CODEC_VTXXXX, 0, "VIA" }, 393 }; 394 395 static int 396 hdacc_suspend(device_t dev) 397 { 398 399 HDA_BOOTHVERBOSE( 400 device_printf(dev, "Suspend...\n"); 401 ); 402 bus_generic_suspend(dev); 403 HDA_BOOTHVERBOSE( 404 device_printf(dev, "Suspend done\n"); 405 ); 406 return (0); 407 } 408 409 static int 410 hdacc_resume(device_t dev) 411 { 412 413 HDA_BOOTHVERBOSE( 414 device_printf(dev, "Resume...\n"); 415 ); 416 bus_generic_resume(dev); 417 HDA_BOOTHVERBOSE( 418 device_printf(dev, "Resume done\n"); 419 ); 420 return (0); 421 } 422 423 static int 424 hdacc_probe(device_t dev) 425 { 426 uint32_t id, revid; 427 char buf[128]; 428 int i; 429 430 id = ((uint32_t)hda_get_vendor_id(dev) << 16) + hda_get_device_id(dev); 431 revid = ((uint32_t)hda_get_revision_id(dev) << 8) + hda_get_stepping_id(dev); 432 433 for (i = 0; i < nitems(hdacc_codecs); i++) { 434 if (!HDA_DEV_MATCH(hdacc_codecs[i].id, id)) 435 continue; 436 if (hdacc_codecs[i].revid != 0 && 437 hdacc_codecs[i].revid != revid) 438 continue; 439 break; 440 } 441 if (i < nitems(hdacc_codecs)) { 442 if ((hdacc_codecs[i].id & 0xffff) != 0xffff) 443 strlcpy(buf, hdacc_codecs[i].name, sizeof(buf)); 444 else 445 snprintf(buf, sizeof(buf), "%s (0x%04x)", 446 hdacc_codecs[i].name, hda_get_device_id(dev)); 447 } else 448 snprintf(buf, sizeof(buf), "Generic (0x%04x)", id); 449 strlcat(buf, " HDA CODEC", sizeof(buf)); 450 device_set_desc_copy(dev, buf); 451 return (BUS_PROBE_DEFAULT); 452 } 453 454 static int 455 hdacc_attach(device_t dev) 456 { 457 struct hdacc_softc *codec = device_get_softc(dev); 458 device_t child; 459 int cad = (intptr_t)device_get_ivars(dev); 460 uint32_t subnode; 461 int startnode; 462 int endnode; 463 int i, n; 464 465 codec->lock = HDAC_GET_MTX(device_get_parent(dev), dev); 466 codec->dev = dev; 467 codec->cad = cad; 468 469 hdacc_lock(codec); 470 subnode = hda_command(dev, 471 HDA_CMD_GET_PARAMETER(0, 0x0, HDA_PARAM_SUB_NODE_COUNT)); 472 hdacc_unlock(codec); 473 if (subnode == HDA_INVALID) 474 return (EIO); 475 codec->fgcnt = HDA_PARAM_SUB_NODE_COUNT_TOTAL(subnode); 476 startnode = HDA_PARAM_SUB_NODE_COUNT_START(subnode); 477 endnode = startnode + codec->fgcnt; 478 479 HDA_BOOTHVERBOSE( 480 device_printf(dev, 481 "Root Node at nid=0: %d subnodes %d-%d\n", 482 HDA_PARAM_SUB_NODE_COUNT_TOTAL(subnode), 483 startnode, endnode - 1); 484 ); 485 486 codec->fgs = malloc(sizeof(struct hdacc_fg) * codec->fgcnt, 487 M_HDACC, M_ZERO | M_WAITOK); 488 for (i = startnode, n = 0; i < endnode; i++, n++) { 489 codec->fgs[n].nid = i; 490 hdacc_lock(codec); 491 codec->fgs[n].type = 492 HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE(hda_command(dev, 493 HDA_CMD_GET_PARAMETER(0, i, HDA_PARAM_FCT_GRP_TYPE))); 494 codec->fgs[n].subsystem_id = hda_command(dev, 495 HDA_CMD_GET_SUBSYSTEM_ID(0, i)); 496 hdacc_unlock(codec); 497 codec->fgs[n].dev = child = device_add_child(dev, NULL, -1); 498 if (child == NULL) { 499 device_printf(dev, "Failed to add function device\n"); 500 continue; 501 } 502 device_set_ivars(child, &codec->fgs[n]); 503 } 504 505 bus_generic_attach(dev); 506 507 return (0); 508 } 509 510 static int 511 hdacc_detach(device_t dev) 512 { 513 struct hdacc_softc *codec = device_get_softc(dev); 514 int error; 515 516 error = device_delete_children(dev); 517 free(codec->fgs, M_HDACC); 518 return (error); 519 } 520 521 static int 522 hdacc_child_location_str(device_t dev, device_t child, char *buf, 523 size_t buflen) 524 { 525 struct hdacc_fg *fg = device_get_ivars(child); 526 527 snprintf(buf, buflen, "nid=%d", fg->nid); 528 return (0); 529 } 530 531 static int 532 hdacc_child_pnpinfo_str_method(device_t dev, device_t child, char *buf, 533 size_t buflen) 534 { 535 struct hdacc_fg *fg = device_get_ivars(child); 536 537 snprintf(buf, buflen, "type=0x%02x subsystem=0x%08x", 538 fg->type, fg->subsystem_id); 539 return (0); 540 } 541 542 static int 543 hdacc_print_child(device_t dev, device_t child) 544 { 545 struct hdacc_fg *fg = device_get_ivars(child); 546 int retval; 547 548 retval = bus_print_child_header(dev, child); 549 retval += printf(" at nid %d", fg->nid); 550 retval += bus_print_child_footer(dev, child); 551 552 return (retval); 553 } 554 555 static void 556 hdacc_probe_nomatch(device_t dev, device_t child) 557 { 558 struct hdacc_softc *codec = device_get_softc(dev); 559 struct hdacc_fg *fg = device_get_ivars(child); 560 561 device_printf(child, "<%s %s Function Group> at nid %d on %s " 562 "(no driver attached)\n", 563 device_get_desc(dev), 564 fg->type == HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO ? "Audio" : 565 (fg->type == HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_MODEM ? "Modem" : 566 "Unknown"), fg->nid, device_get_nameunit(dev)); 567 HDA_BOOTVERBOSE( 568 device_printf(dev, "Subsystem ID: 0x%08x\n", 569 hda_get_subsystem_id(dev)); 570 ); 571 HDA_BOOTHVERBOSE( 572 device_printf(dev, "Power down FG nid=%d to the D3 state...\n", 573 fg->nid); 574 ); 575 hdacc_lock(codec); 576 hda_command(dev, HDA_CMD_SET_POWER_STATE(0, 577 fg->nid, HDA_CMD_POWER_STATE_D3)); 578 hdacc_unlock(codec); 579 } 580 581 static int 582 hdacc_read_ivar(device_t dev, device_t child, int which, uintptr_t *result) 583 { 584 struct hdacc_fg *fg = device_get_ivars(child); 585 586 switch (which) { 587 case HDA_IVAR_NODE_ID: 588 *result = fg->nid; 589 break; 590 case HDA_IVAR_NODE_TYPE: 591 *result = fg->type; 592 break; 593 case HDA_IVAR_SUBSYSTEM_ID: 594 *result = fg->subsystem_id; 595 break; 596 default: 597 return(BUS_READ_IVAR(device_get_parent(dev), dev, 598 which, result)); 599 } 600 return (0); 601 } 602 603 static struct mtx * 604 hdacc_get_mtx(device_t dev, device_t child) 605 { 606 struct hdacc_softc *codec = device_get_softc(dev); 607 608 return (codec->lock); 609 } 610 611 static uint32_t 612 hdacc_codec_command(device_t dev, device_t child, uint32_t verb) 613 { 614 615 return (HDAC_CODEC_COMMAND(device_get_parent(dev), dev, verb)); 616 } 617 618 static int 619 hdacc_stream_alloc(device_t dev, device_t child, int dir, int format, 620 int stripe, uint32_t **dmapos) 621 { 622 struct hdacc_softc *codec = device_get_softc(dev); 623 int stream; 624 625 stream = HDAC_STREAM_ALLOC(device_get_parent(dev), dev, 626 dir, format, stripe, dmapos); 627 if (stream > 0) 628 codec->streams[dir][stream] = child; 629 return (stream); 630 } 631 632 static void 633 hdacc_stream_free(device_t dev, device_t child, int dir, int stream) 634 { 635 struct hdacc_softc *codec = device_get_softc(dev); 636 637 codec->streams[dir][stream] = NULL; 638 HDAC_STREAM_FREE(device_get_parent(dev), dev, dir, stream); 639 } 640 641 static int 642 hdacc_stream_start(device_t dev, device_t child, 643 int dir, int stream, bus_addr_t buf, int blksz, int blkcnt) 644 { 645 646 return (HDAC_STREAM_START(device_get_parent(dev), dev, 647 dir, stream, buf, blksz, blkcnt)); 648 } 649 650 static void 651 hdacc_stream_stop(device_t dev, device_t child, int dir, int stream) 652 { 653 654 HDAC_STREAM_STOP(device_get_parent(dev), dev, dir, stream); 655 } 656 657 static void 658 hdacc_stream_reset(device_t dev, device_t child, int dir, int stream) 659 { 660 661 HDAC_STREAM_RESET(device_get_parent(dev), dev, dir, stream); 662 } 663 664 static uint32_t 665 hdacc_stream_getptr(device_t dev, device_t child, int dir, int stream) 666 { 667 668 return (HDAC_STREAM_GETPTR(device_get_parent(dev), dev, dir, stream)); 669 } 670 671 static void 672 hdacc_stream_intr(device_t dev, int dir, int stream) 673 { 674 struct hdacc_softc *codec = device_get_softc(dev); 675 device_t child; 676 677 if ((child = codec->streams[dir][stream]) != NULL) 678 HDAC_STREAM_INTR(child, dir, stream); 679 } 680 681 static int 682 hdacc_unsol_alloc(device_t dev, device_t child, int wanted) 683 { 684 struct hdacc_softc *codec = device_get_softc(dev); 685 int tag; 686 687 wanted &= 0x3f; 688 tag = wanted; 689 do { 690 if (codec->tags[tag] == NULL) { 691 codec->tags[tag] = child; 692 HDAC_UNSOL_ALLOC(device_get_parent(dev), dev, tag); 693 return (tag); 694 } 695 tag++; 696 tag &= 0x3f; 697 } while (tag != wanted); 698 return (-1); 699 } 700 701 static void 702 hdacc_unsol_free(device_t dev, device_t child, int tag) 703 { 704 struct hdacc_softc *codec = device_get_softc(dev); 705 706 KASSERT(tag >= 0 && tag <= 0x3f, ("Wrong tag value %d\n", tag)); 707 codec->tags[tag] = NULL; 708 HDAC_UNSOL_FREE(device_get_parent(dev), dev, tag); 709 } 710 711 static void 712 hdacc_unsol_intr(device_t dev, uint32_t resp) 713 { 714 struct hdacc_softc *codec = device_get_softc(dev); 715 device_t child; 716 int tag; 717 718 tag = resp >> 26; 719 if ((child = codec->tags[tag]) != NULL) 720 HDAC_UNSOL_INTR(child, resp); 721 else 722 device_printf(codec->dev, "Unexpected unsolicited " 723 "response with tag %d: %08x\n", tag, resp); 724 } 725 726 static void 727 hdacc_pindump(device_t dev) 728 { 729 device_t *devlist; 730 int devcount, i; 731 732 if (device_get_children(dev, &devlist, &devcount) != 0) 733 return; 734 for (i = 0; i < devcount; i++) 735 HDAC_PINDUMP(devlist[i]); 736 free(devlist, M_TEMP); 737 } 738 739 static device_method_t hdacc_methods[] = { 740 /* device interface */ 741 DEVMETHOD(device_probe, hdacc_probe), 742 DEVMETHOD(device_attach, hdacc_attach), 743 DEVMETHOD(device_detach, hdacc_detach), 744 DEVMETHOD(device_suspend, hdacc_suspend), 745 DEVMETHOD(device_resume, hdacc_resume), 746 /* Bus interface */ 747 DEVMETHOD(bus_child_location_str, hdacc_child_location_str), 748 DEVMETHOD(bus_child_pnpinfo_str, hdacc_child_pnpinfo_str_method), 749 DEVMETHOD(bus_print_child, hdacc_print_child), 750 DEVMETHOD(bus_probe_nomatch, hdacc_probe_nomatch), 751 DEVMETHOD(bus_read_ivar, hdacc_read_ivar), 752 DEVMETHOD(hdac_get_mtx, hdacc_get_mtx), 753 DEVMETHOD(hdac_codec_command, hdacc_codec_command), 754 DEVMETHOD(hdac_stream_alloc, hdacc_stream_alloc), 755 DEVMETHOD(hdac_stream_free, hdacc_stream_free), 756 DEVMETHOD(hdac_stream_start, hdacc_stream_start), 757 DEVMETHOD(hdac_stream_stop, hdacc_stream_stop), 758 DEVMETHOD(hdac_stream_reset, hdacc_stream_reset), 759 DEVMETHOD(hdac_stream_getptr, hdacc_stream_getptr), 760 DEVMETHOD(hdac_stream_intr, hdacc_stream_intr), 761 DEVMETHOD(hdac_unsol_alloc, hdacc_unsol_alloc), 762 DEVMETHOD(hdac_unsol_free, hdacc_unsol_free), 763 DEVMETHOD(hdac_unsol_intr, hdacc_unsol_intr), 764 DEVMETHOD(hdac_pindump, hdacc_pindump), 765 DEVMETHOD_END 766 }; 767 768 static driver_t hdacc_driver = { 769 "hdacc", 770 hdacc_methods, 771 sizeof(struct hdacc_softc), 772 }; 773 774 static devclass_t hdacc_devclass; 775 776 DRIVER_MODULE(snd_hda, hdac, hdacc_driver, hdacc_devclass, NULL, NULL); 777