2 * Copyright (c) 2006 Stephane E. Potvin <sepotvin@videotron.ca>
3 * Copyright (c) 2006 Ariff Abdullah <ariff@FreeBSD.org>
4 * Copyright (c) 2008 Alexander Motin <mav@FreeBSD.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * Intel High Definition Audio (Controller) driver for FreeBSD. Be advised
31 * that this driver still in its early stage, and possible of rewrite are
32 * pretty much guaranteed. There are supposedly several distinct parent/child
33 * busses to make this "perfect", but as for now and for the sake of
34 * simplicity, everything is gobble up within single source.
37 * 1) HDA Controller support
38 * 2) HDA Codecs support, which may include
41 * 3) Widget parser - the real magic of why this driver works on so
42 * many hardwares with minimal vendor specific quirk. The original
43 * parser was written using Ruby and can be found at
44 * http://people.freebsd.org/~ariff/HDA/parser.rb . This crude
45 * ruby parser take the verbose dmesg dump as its input. Refer to
46 * http://www.microsoft.com/whdc/device/audio/default.mspx for various
47 * interesting documents, especially UAA (Universal Audio Architecture).
48 * 4) Possible vendor specific support.
49 * (snd_hda_intel, snd_hda_ati, etc..)
51 * Thanks to Ahmad Ubaidah Omar @ Defenxis Sdn. Bhd. for the
52 * Compaq V3000 with Conexant HDA.
54 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
56 * * This driver is a collaborative effort made by: *
58 * * Stephane E. Potvin <sepotvin@videotron.ca> *
59 * * Andrea Bittau <a.bittau@cs.ucl.ac.uk> *
60 * * Wesley Morgan <morganw@chemikals.org> *
61 * * Daniel Eischen <deischen@FreeBSD.org> *
62 * * Maxime Guillaud <bsd-ports@mguillaud.net> *
63 * * Ariff Abdullah <ariff@FreeBSD.org> *
64 * * Alexander Motin <mav@FreeBSD.org> *
66 * * ....and various people from freebsd-multimedia@FreeBSD.org *
68 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
71 #ifdef HAVE_KERNEL_OPTION_HEADERS
75 #include <dev/sound/pcm/sound.h>
76 #include <dev/pci/pcireg.h>
77 #include <dev/pci/pcivar.h>
79 #include <sys/ctype.h>
80 #include <sys/taskqueue.h>
82 #include <dev/sound/pci/hda/hdac_private.h>
83 #include <dev/sound/pci/hda/hdac_reg.h>
84 #include <dev/sound/pci/hda/hda_reg.h>
85 #include <dev/sound/pci/hda/hdac.h>
89 #define HDA_DRV_TEST_REV "20100226_0142"
91 SND_DECLARE_FILE("$FreeBSD$");
93 #define HDA_BOOTVERBOSE(stmt) do { \
94 if (bootverbose != 0 || snd_verbose > 3) { \
99 #define HDA_BOOTHVERBOSE(stmt) do { \
100 if (snd_verbose > 3) { \
106 #undef HDAC_INTR_EXTRA
107 #define HDAC_INTR_EXTRA 1
110 #define hdac_lock(sc) snd_mtxlock((sc)->lock)
111 #define hdac_unlock(sc) snd_mtxunlock((sc)->lock)
112 #define hdac_lockassert(sc) snd_mtxassert((sc)->lock)
113 #define hdac_lockowned(sc) mtx_owned((sc)->lock)
115 #define HDA_FLAG_MATCH(fl, v) (((fl) & (v)) == (v))
116 #define HDA_DEV_MATCH(fl, v) ((fl) == (v) || \
117 (fl) == 0xffffffff || \
118 (((fl) & 0xffff0000) == 0xffff0000 && \
119 ((fl) & 0x0000ffff) == ((v) & 0x0000ffff)) || \
120 (((fl) & 0x0000ffff) == 0x0000ffff && \
121 ((fl) & 0xffff0000) == ((v) & 0xffff0000)))
122 #define HDA_MATCH_ALL 0xffffffff
123 #define HDAC_INVALID 0xffffffff
125 /* Default controller / jack sense poll: 250ms */
126 #define HDAC_POLL_INTERVAL max(hz >> 2, 1)
129 * Make room for possible 4096 playback/record channels, in 100 years to come.
131 #define HDAC_TRIGGER_NONE 0x00000000
132 #define HDAC_TRIGGER_PLAY 0x00000fff
133 #define HDAC_TRIGGER_REC 0x00fff000
134 #define HDAC_TRIGGER_UNSOL 0x80000000
136 #define HDA_MODEL_CONSTRUCT(vendor, model) \
137 (((uint32_t)(model) << 16) | ((vendor##_VENDORID) & 0xffff))
139 /* Controller models */
142 #define INTEL_VENDORID 0x8086
143 #define HDA_INTEL_82801F HDA_MODEL_CONSTRUCT(INTEL, 0x2668)
144 #define HDA_INTEL_63XXESB HDA_MODEL_CONSTRUCT(INTEL, 0x269a)
145 #define HDA_INTEL_82801G HDA_MODEL_CONSTRUCT(INTEL, 0x27d8)
146 #define HDA_INTEL_82801H HDA_MODEL_CONSTRUCT(INTEL, 0x284b)
147 #define HDA_INTEL_82801I HDA_MODEL_CONSTRUCT(INTEL, 0x293e)
148 #define HDA_INTEL_82801JI HDA_MODEL_CONSTRUCT(INTEL, 0x3a3e)
149 #define HDA_INTEL_82801JD HDA_MODEL_CONSTRUCT(INTEL, 0x3a6e)
150 #define HDA_INTEL_PCH HDA_MODEL_CONSTRUCT(INTEL, 0x3b56)
151 #define HDA_INTEL_SCH HDA_MODEL_CONSTRUCT(INTEL, 0x811b)
152 #define HDA_INTEL_ALL HDA_MODEL_CONSTRUCT(INTEL, 0xffff)
155 #define NVIDIA_VENDORID 0x10de
156 #define HDA_NVIDIA_MCP51 HDA_MODEL_CONSTRUCT(NVIDIA, 0x026c)
157 #define HDA_NVIDIA_MCP55 HDA_MODEL_CONSTRUCT(NVIDIA, 0x0371)
158 #define HDA_NVIDIA_MCP61_1 HDA_MODEL_CONSTRUCT(NVIDIA, 0x03e4)
159 #define HDA_NVIDIA_MCP61_2 HDA_MODEL_CONSTRUCT(NVIDIA, 0x03f0)
160 #define HDA_NVIDIA_MCP65_1 HDA_MODEL_CONSTRUCT(NVIDIA, 0x044a)
161 #define HDA_NVIDIA_MCP65_2 HDA_MODEL_CONSTRUCT(NVIDIA, 0x044b)
162 #define HDA_NVIDIA_MCP67_1 HDA_MODEL_CONSTRUCT(NVIDIA, 0x055c)
163 #define HDA_NVIDIA_MCP67_2 HDA_MODEL_CONSTRUCT(NVIDIA, 0x055d)
164 #define HDA_NVIDIA_MCP78_1 HDA_MODEL_CONSTRUCT(NVIDIA, 0x0774)
165 #define HDA_NVIDIA_MCP78_2 HDA_MODEL_CONSTRUCT(NVIDIA, 0x0775)
166 #define HDA_NVIDIA_MCP78_3 HDA_MODEL_CONSTRUCT(NVIDIA, 0x0776)
167 #define HDA_NVIDIA_MCP78_4 HDA_MODEL_CONSTRUCT(NVIDIA, 0x0777)
168 #define HDA_NVIDIA_MCP73_1 HDA_MODEL_CONSTRUCT(NVIDIA, 0x07fc)
169 #define HDA_NVIDIA_MCP73_2 HDA_MODEL_CONSTRUCT(NVIDIA, 0x07fd)
170 #define HDA_NVIDIA_MCP79_1 HDA_MODEL_CONSTRUCT(NVIDIA, 0x0ac0)
171 #define HDA_NVIDIA_MCP79_2 HDA_MODEL_CONSTRUCT(NVIDIA, 0x0ac1)
172 #define HDA_NVIDIA_MCP79_3 HDA_MODEL_CONSTRUCT(NVIDIA, 0x0ac2)
173 #define HDA_NVIDIA_MCP79_4 HDA_MODEL_CONSTRUCT(NVIDIA, 0x0ac3)
174 #define HDA_NVIDIA_MCP89_1 HDA_MODEL_CONSTRUCT(NVIDIA, 0x0d94)
175 #define HDA_NVIDIA_MCP89_2 HDA_MODEL_CONSTRUCT(NVIDIA, 0x0d95)
176 #define HDA_NVIDIA_MCP89_3 HDA_MODEL_CONSTRUCT(NVIDIA, 0x0d96)
177 #define HDA_NVIDIA_MCP89_4 HDA_MODEL_CONSTRUCT(NVIDIA, 0x0d97)
178 #define HDA_NVIDIA_ALL HDA_MODEL_CONSTRUCT(NVIDIA, 0xffff)
181 #define ATI_VENDORID 0x1002
182 #define HDA_ATI_SB450 HDA_MODEL_CONSTRUCT(ATI, 0x437b)
183 #define HDA_ATI_SB600 HDA_MODEL_CONSTRUCT(ATI, 0x4383)
184 #define HDA_ATI_RS600 HDA_MODEL_CONSTRUCT(ATI, 0x793b)
185 #define HDA_ATI_RS690 HDA_MODEL_CONSTRUCT(ATI, 0x7919)
186 #define HDA_ATI_RS780 HDA_MODEL_CONSTRUCT(ATI, 0x960f)
187 #define HDA_ATI_R600 HDA_MODEL_CONSTRUCT(ATI, 0xaa00)
188 #define HDA_ATI_RV630 HDA_MODEL_CONSTRUCT(ATI, 0xaa08)
189 #define HDA_ATI_RV610 HDA_MODEL_CONSTRUCT(ATI, 0xaa10)
190 #define HDA_ATI_RV670 HDA_MODEL_CONSTRUCT(ATI, 0xaa18)
191 #define HDA_ATI_RV635 HDA_MODEL_CONSTRUCT(ATI, 0xaa20)
192 #define HDA_ATI_RV620 HDA_MODEL_CONSTRUCT(ATI, 0xaa28)
193 #define HDA_ATI_RV770 HDA_MODEL_CONSTRUCT(ATI, 0xaa30)
194 #define HDA_ATI_RV730 HDA_MODEL_CONSTRUCT(ATI, 0xaa38)
195 #define HDA_ATI_RV710 HDA_MODEL_CONSTRUCT(ATI, 0xaa40)
196 #define HDA_ATI_RV740 HDA_MODEL_CONSTRUCT(ATI, 0xaa48)
197 #define HDA_ATI_ALL HDA_MODEL_CONSTRUCT(ATI, 0xffff)
200 #define VIA_VENDORID 0x1106
201 #define HDA_VIA_VT82XX HDA_MODEL_CONSTRUCT(VIA, 0x3288)
202 #define HDA_VIA_ALL HDA_MODEL_CONSTRUCT(VIA, 0xffff)
205 #define SIS_VENDORID 0x1039
206 #define HDA_SIS_966 HDA_MODEL_CONSTRUCT(SIS, 0x7502)
207 #define HDA_SIS_ALL HDA_MODEL_CONSTRUCT(SIS, 0xffff)
210 #define ULI_VENDORID 0x10b9
211 #define HDA_ULI_M5461 HDA_MODEL_CONSTRUCT(ULI, 0x5461)
212 #define HDA_ULI_ALL HDA_MODEL_CONSTRUCT(ULI, 0xffff)
217 #define INTEL_D101GGC_SUBVENDOR HDA_MODEL_CONSTRUCT(INTEL, 0xd600)
220 #define HP_VENDORID 0x103c
221 #define HP_V3000_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x30b5)
222 #define HP_NX7400_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x30a2)
223 #define HP_NX6310_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x30aa)
224 #define HP_NX6325_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x30b0)
225 #define HP_XW4300_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x3013)
226 #define HP_3010_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x3010)
227 #define HP_DV5000_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x30a5)
228 #define HP_DC7700S_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x2801)
229 #define HP_DC7700_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x2802)
230 #define HP_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0xffff)
231 /* What is wrong with XN 2563 anyway? (Got the picture ?) */
232 #define HP_NX6325_SUBVENDORX 0x103c30b0
235 #define DELL_VENDORID 0x1028
236 #define DELL_D630_SUBVENDOR HDA_MODEL_CONSTRUCT(DELL, 0x01f9)
237 #define DELL_D820_SUBVENDOR HDA_MODEL_CONSTRUCT(DELL, 0x01cc)
238 #define DELL_V1400_SUBVENDOR HDA_MODEL_CONSTRUCT(DELL, 0x0227)
239 #define DELL_V1500_SUBVENDOR HDA_MODEL_CONSTRUCT(DELL, 0x0228)
240 #define DELL_I1300_SUBVENDOR HDA_MODEL_CONSTRUCT(DELL, 0x01c9)
241 #define DELL_XPSM1210_SUBVENDOR HDA_MODEL_CONSTRUCT(DELL, 0x01d7)
242 #define DELL_OPLX745_SUBVENDOR HDA_MODEL_CONSTRUCT(DELL, 0x01da)
243 #define DELL_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(DELL, 0xffff)
246 #define CLEVO_VENDORID 0x1558
247 #define CLEVO_D900T_SUBVENDOR HDA_MODEL_CONSTRUCT(CLEVO, 0x0900)
248 #define CLEVO_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(CLEVO, 0xffff)
251 #define ACER_VENDORID 0x1025
252 #define ACER_A5050_SUBVENDOR HDA_MODEL_CONSTRUCT(ACER, 0x010f)
253 #define ACER_A4520_SUBVENDOR HDA_MODEL_CONSTRUCT(ACER, 0x0127)
254 #define ACER_A4710_SUBVENDOR HDA_MODEL_CONSTRUCT(ACER, 0x012f)
255 #define ACER_A4715_SUBVENDOR HDA_MODEL_CONSTRUCT(ACER, 0x0133)
256 #define ACER_3681WXM_SUBVENDOR HDA_MODEL_CONSTRUCT(ACER, 0x0110)
257 #define ACER_T6292_SUBVENDOR HDA_MODEL_CONSTRUCT(ACER, 0x011b)
258 #define ACER_T5320_SUBVENDOR HDA_MODEL_CONSTRUCT(ACER, 0x011f)
259 #define ACER_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(ACER, 0xffff)
262 #define ASUS_VENDORID 0x1043
263 #define ASUS_A8X_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x1153)
264 #define ASUS_U5F_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x1263)
265 #define ASUS_W6F_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x1263)
266 #define ASUS_A7M_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x1323)
267 #define ASUS_F3JC_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x1338)
268 #define ASUS_G2K_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x1339)
269 #define ASUS_A7T_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x13c2)
270 #define ASUS_W2J_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x1971)
271 #define ASUS_M5200_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x1993)
272 #define ASUS_P5PL2_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x817f)
273 #define ASUS_P1AH2_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x81cb)
274 #define ASUS_M2NPVMX_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x81cb)
275 #define ASUS_M2V_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x81e7)
276 #define ASUS_P5BWD_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x81ec)
277 #define ASUS_M2N_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x8234)
278 #define ASUS_A8NVMCSM_SUBVENDOR HDA_MODEL_CONSTRUCT(NVIDIA, 0xcb84)
279 #define ASUS_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0xffff)
282 #define IBM_VENDORID 0x1014
283 #define IBM_M52_SUBVENDOR HDA_MODEL_CONSTRUCT(IBM, 0x02f6)
284 #define IBM_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(IBM, 0xffff)
287 #define LENOVO_VENDORID 0x17aa
288 #define LENOVO_3KN100_SUBVENDOR HDA_MODEL_CONSTRUCT(LENOVO, 0x2066)
289 #define LENOVO_3KN200_SUBVENDOR HDA_MODEL_CONSTRUCT(LENOVO, 0x384e)
290 #define LENOVO_TCA55_SUBVENDOR HDA_MODEL_CONSTRUCT(LENOVO, 0x1015)
291 #define LENOVO_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(LENOVO, 0xffff)
294 #define SAMSUNG_VENDORID 0x144d
295 #define SAMSUNG_Q1_SUBVENDOR HDA_MODEL_CONSTRUCT(SAMSUNG, 0xc027)
296 #define SAMSUNG_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(SAMSUNG, 0xffff)
299 #define MEDION_VENDORID 0x161f
300 #define MEDION_MD95257_SUBVENDOR HDA_MODEL_CONSTRUCT(MEDION, 0x203d)
301 #define MEDION_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(MEDION, 0xffff)
303 /* Apple Computer Inc. */
304 #define APPLE_VENDORID 0x106b
305 #define APPLE_MB3_SUBVENDOR HDA_MODEL_CONSTRUCT(APPLE, 0x00a1)
308 #define SONY_VENDORID 0x104d
309 #define SONY_S5_SUBVENDOR HDA_MODEL_CONSTRUCT(SONY, 0x81cc)
310 #define SONY_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(SONY, 0xffff)
313 * Apple Intel MacXXXX seems using Sigmatel codec/vendor id
314 * instead of their own, which is beyond my comprehension
315 * (see HDA_CODEC_STAC9221 below).
317 #define APPLE_INTEL_MAC 0x76808384
318 #define APPLE_MACBOOKPRO55 0xcb7910de
321 #define LG_VENDORID 0x1854
322 #define LG_LW20_SUBVENDOR HDA_MODEL_CONSTRUCT(LG, 0x0018)
323 #define LG_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(LG, 0xffff)
325 /* Fujitsu Siemens */
326 #define FS_VENDORID 0x1734
327 #define FS_PA1510_SUBVENDOR HDA_MODEL_CONSTRUCT(FS, 0x10b8)
328 #define FS_SI1848_SUBVENDOR HDA_MODEL_CONSTRUCT(FS, 0x10cd)
329 #define FS_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(FS, 0xffff)
331 /* Fujitsu Limited */
332 #define FL_VENDORID 0x10cf
333 #define FL_S7020D_SUBVENDOR HDA_MODEL_CONSTRUCT(FL, 0x1326)
334 #define FL_U1010_SUBVENDOR HDA_MODEL_CONSTRUCT(FL, 0x142d)
335 #define FL_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(FL, 0xffff)
338 #define TOSHIBA_VENDORID 0x1179
339 #define TOSHIBA_U200_SUBVENDOR HDA_MODEL_CONSTRUCT(TOSHIBA, 0x0001)
340 #define TOSHIBA_A135_SUBVENDOR HDA_MODEL_CONSTRUCT(TOSHIBA, 0xff01)
341 #define TOSHIBA_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(TOSHIBA, 0xffff)
343 /* Micro-Star International (MSI) */
344 #define MSI_VENDORID 0x1462
345 #define MSI_MS1034_SUBVENDOR HDA_MODEL_CONSTRUCT(MSI, 0x0349)
346 #define MSI_MS034A_SUBVENDOR HDA_MODEL_CONSTRUCT(MSI, 0x034a)
347 #define MSI_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(MSI, 0xffff)
349 /* Giga-Byte Technology */
350 #define GB_VENDORID 0x1458
351 #define GB_G33S2H_SUBVENDOR HDA_MODEL_CONSTRUCT(GB, 0xa022)
352 #define GP_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(GB, 0xffff)
355 #define UNIWILL_VENDORID 0x1584
356 #define UNIWILL_9075_SUBVENDOR HDA_MODEL_CONSTRUCT(UNIWILL, 0x9075)
357 #define UNIWILL_9080_SUBVENDOR HDA_MODEL_CONSTRUCT(UNIWILL, 0x9080)
360 /* Misc constants.. */
361 #define HDA_AMP_VOL_DEFAULT (-1)
362 #define HDA_AMP_MUTE_DEFAULT (0xffffffff)
363 #define HDA_AMP_MUTE_NONE (0)
364 #define HDA_AMP_MUTE_LEFT (1 << 0)
365 #define HDA_AMP_MUTE_RIGHT (1 << 1)
366 #define HDA_AMP_MUTE_ALL (HDA_AMP_MUTE_LEFT | HDA_AMP_MUTE_RIGHT)
368 #define HDA_AMP_LEFT_MUTED(v) ((v) & (HDA_AMP_MUTE_LEFT))
369 #define HDA_AMP_RIGHT_MUTED(v) (((v) & HDA_AMP_MUTE_RIGHT) >> 1)
371 #define HDA_ADC_MONITOR (1 << 0)
373 #define HDA_CTL_OUT 1
376 #define HDA_GPIO_MAX 8
377 /* 0 - 7 = GPIO , 8 = Flush */
378 #define HDA_QUIRK_GPIO0 (1 << 0)
379 #define HDA_QUIRK_GPIO1 (1 << 1)
380 #define HDA_QUIRK_GPIO2 (1 << 2)
381 #define HDA_QUIRK_GPIO3 (1 << 3)
382 #define HDA_QUIRK_GPIO4 (1 << 4)
383 #define HDA_QUIRK_GPIO5 (1 << 5)
384 #define HDA_QUIRK_GPIO6 (1 << 6)
385 #define HDA_QUIRK_GPIO7 (1 << 7)
386 #define HDA_QUIRK_GPIOFLUSH (1 << 8)
388 /* 9 - 25 = anything else */
389 #define HDA_QUIRK_SOFTPCMVOL (1 << 9)
390 #define HDA_QUIRK_FIXEDRATE (1 << 10)
391 #define HDA_QUIRK_FORCESTEREO (1 << 11)
392 #define HDA_QUIRK_EAPDINV (1 << 12)
393 #define HDA_QUIRK_DMAPOS (1 << 13)
394 #define HDA_QUIRK_SENSEINV (1 << 14)
396 /* 26 - 31 = vrefs */
397 #define HDA_QUIRK_IVREF50 (1 << 26)
398 #define HDA_QUIRK_IVREF80 (1 << 27)
399 #define HDA_QUIRK_IVREF100 (1 << 28)
400 #define HDA_QUIRK_OVREF50 (1 << 29)
401 #define HDA_QUIRK_OVREF80 (1 << 30)
402 #define HDA_QUIRK_OVREF100 (1 << 31)
404 #define HDA_QUIRK_IVREF (HDA_QUIRK_IVREF50 | HDA_QUIRK_IVREF80 | \
406 #define HDA_QUIRK_OVREF (HDA_QUIRK_OVREF50 | HDA_QUIRK_OVREF80 | \
408 #define HDA_QUIRK_VREF (HDA_QUIRK_IVREF | HDA_QUIRK_OVREF)
410 #if __FreeBSD_version < 600000
411 #define taskqueue_drain(...)
414 static const struct {
417 } hdac_quirks_tab[] = {
418 { "gpio0", HDA_QUIRK_GPIO0 },
419 { "gpio1", HDA_QUIRK_GPIO1 },
420 { "gpio2", HDA_QUIRK_GPIO2 },
421 { "gpio3", HDA_QUIRK_GPIO3 },
422 { "gpio4", HDA_QUIRK_GPIO4 },
423 { "gpio5", HDA_QUIRK_GPIO5 },
424 { "gpio6", HDA_QUIRK_GPIO6 },
425 { "gpio7", HDA_QUIRK_GPIO7 },
426 { "gpioflush", HDA_QUIRK_GPIOFLUSH },
427 { "softpcmvol", HDA_QUIRK_SOFTPCMVOL },
428 { "fixedrate", HDA_QUIRK_FIXEDRATE },
429 { "forcestereo", HDA_QUIRK_FORCESTEREO },
430 { "eapdinv", HDA_QUIRK_EAPDINV },
431 { "dmapos", HDA_QUIRK_DMAPOS },
432 { "senseinv", HDA_QUIRK_SENSEINV },
433 { "ivref50", HDA_QUIRK_IVREF50 },
434 { "ivref80", HDA_QUIRK_IVREF80 },
435 { "ivref100", HDA_QUIRK_IVREF100 },
436 { "ovref50", HDA_QUIRK_OVREF50 },
437 { "ovref80", HDA_QUIRK_OVREF80 },
438 { "ovref100", HDA_QUIRK_OVREF100 },
439 { "ivref", HDA_QUIRK_IVREF },
440 { "ovref", HDA_QUIRK_OVREF },
441 { "vref", HDA_QUIRK_VREF },
443 #define HDAC_QUIRKS_TAB_LEN \
444 (sizeof(hdac_quirks_tab) / sizeof(hdac_quirks_tab[0]))
446 #define HDA_BDL_MIN 2
447 #define HDA_BDL_MAX 256
448 #define HDA_BDL_DEFAULT HDA_BDL_MIN
450 #define HDA_BLK_MIN HDAC_DMA_ALIGNMENT
451 #define HDA_BLK_ALIGN (~(HDA_BLK_MIN - 1))
453 #define HDA_BUFSZ_MIN 4096
454 #define HDA_BUFSZ_MAX 65536
455 #define HDA_BUFSZ_DEFAULT 16384
457 #define HDA_PARSE_MAXDEPTH 10
459 #define HDAC_UNSOLTAG_EVENT_HP 0x00
461 MALLOC_DEFINE(M_HDAC, "hdac", "High Definition Audio Controller");
463 const char *HDA_COLORS[16] = {"Unknown", "Black", "Grey", "Blue", "Green", "Red",
464 "Orange", "Yellow", "Purple", "Pink", "Res.A", "Res.B", "Res.C", "Res.D",
467 const char *HDA_DEVS[16] = {"Line-out", "Speaker", "Headphones", "CD",
468 "SPDIF-out", "Digital-out", "Modem-line", "Modem-handset", "Line-in",
469 "AUX", "Mic", "Telephony", "SPDIF-in", "Digital-in", "Res.E", "Other"};
471 const char *HDA_CONNS[4] = {"Jack", "None", "Fixed", "Both"};
474 static uint32_t hdac_fmt[] = {
475 SND_FORMAT(AFMT_S16_LE, 2, 0),
479 static struct pcmchan_caps hdac_caps = {48000, 48000, hdac_fmt, 0};
481 #define HDAC_NO_MSI 1
482 #define HDAC_NO_64BIT 2
484 static const struct {
489 { HDA_INTEL_82801F, "Intel 82801F", 0 },
490 { HDA_INTEL_63XXESB, "Intel 631x/632xESB", 0 },
491 { HDA_INTEL_82801G, "Intel 82801G", 0 },
492 { HDA_INTEL_82801H, "Intel 82801H", 0 },
493 { HDA_INTEL_82801I, "Intel 82801I", 0 },
494 { HDA_INTEL_82801JI, "Intel 82801JI", 0 },
495 { HDA_INTEL_82801JD, "Intel 82801JD", 0 },
496 { HDA_INTEL_PCH, "Intel PCH", 0 },
497 { HDA_INTEL_SCH, "Intel SCH", 0 },
498 { HDA_NVIDIA_MCP51, "NVidia MCP51", HDAC_NO_MSI },
499 { HDA_NVIDIA_MCP55, "NVidia MCP55", HDAC_NO_MSI },
500 { HDA_NVIDIA_MCP61_1, "NVidia MCP61", 0 },
501 { HDA_NVIDIA_MCP61_2, "NVidia MCP61", 0 },
502 { HDA_NVIDIA_MCP65_1, "NVidia MCP65", 0 },
503 { HDA_NVIDIA_MCP65_2, "NVidia MCP65", 0 },
504 { HDA_NVIDIA_MCP67_1, "NVidia MCP67", 0 },
505 { HDA_NVIDIA_MCP67_2, "NVidia MCP67", 0 },
506 { HDA_NVIDIA_MCP73_1, "NVidia MCP73", 0 },
507 { HDA_NVIDIA_MCP73_2, "NVidia MCP73", 0 },
508 { HDA_NVIDIA_MCP78_1, "NVidia MCP78", HDAC_NO_64BIT },
509 { HDA_NVIDIA_MCP78_2, "NVidia MCP78", HDAC_NO_64BIT },
510 { HDA_NVIDIA_MCP78_3, "NVidia MCP78", HDAC_NO_64BIT },
511 { HDA_NVIDIA_MCP78_4, "NVidia MCP78", HDAC_NO_64BIT },
512 { HDA_NVIDIA_MCP79_1, "NVidia MCP79", 0 },
513 { HDA_NVIDIA_MCP79_2, "NVidia MCP79", 0 },
514 { HDA_NVIDIA_MCP79_3, "NVidia MCP79", 0 },
515 { HDA_NVIDIA_MCP79_4, "NVidia MCP79", 0 },
516 { HDA_NVIDIA_MCP89_1, "NVidia MCP89", 0 },
517 { HDA_NVIDIA_MCP89_2, "NVidia MCP89", 0 },
518 { HDA_NVIDIA_MCP89_3, "NVidia MCP89", 0 },
519 { HDA_NVIDIA_MCP89_4, "NVidia MCP89", 0 },
520 { HDA_ATI_SB450, "ATI SB450", 0 },
521 { HDA_ATI_SB600, "ATI SB600", 0 },
522 { HDA_ATI_RS600, "ATI RS600", 0 },
523 { HDA_ATI_RS690, "ATI RS690", 0 },
524 { HDA_ATI_RS780, "ATI RS780", 0 },
525 { HDA_ATI_R600, "ATI R600", 0 },
526 { HDA_ATI_RV610, "ATI RV610", 0 },
527 { HDA_ATI_RV620, "ATI RV620", 0 },
528 { HDA_ATI_RV630, "ATI RV630", 0 },
529 { HDA_ATI_RV635, "ATI RV635", 0 },
530 { HDA_ATI_RV710, "ATI RV710", 0 },
531 { HDA_ATI_RV730, "ATI RV730", 0 },
532 { HDA_ATI_RV740, "ATI RV740", 0 },
533 { HDA_ATI_RV770, "ATI RV770", 0 },
534 { HDA_VIA_VT82XX, "VIA VT8251/8237A",0 },
535 { HDA_SIS_966, "SiS 966", 0 },
536 { HDA_ULI_M5461, "ULI M5461", 0 },
538 { HDA_INTEL_ALL, "Intel (Unknown)" },
539 { HDA_NVIDIA_ALL, "NVidia (Unknown)" },
540 { HDA_ATI_ALL, "ATI (Unknown)" },
541 { HDA_VIA_ALL, "VIA (Unknown)" },
542 { HDA_SIS_ALL, "SiS (Unknown)" },
543 { HDA_ULI_ALL, "ULI (Unknown)" },
545 #define HDAC_DEVICES_LEN (sizeof(hdac_devices) / sizeof(hdac_devices[0]))
547 static const struct {
552 } hdac_pcie_snoop[] = {
553 { INTEL_VENDORID, 0x00, 0x00, 0x00 },
554 { ATI_VENDORID, 0x42, 0xf8, 0x02 },
555 { NVIDIA_VENDORID, 0x4e, 0xf0, 0x0f },
557 #define HDAC_PCIESNOOP_LEN \
558 (sizeof(hdac_pcie_snoop) / sizeof(hdac_pcie_snoop[0]))
560 static const struct {
567 { 8000, 1, 0x0000, 0x0000, 0x0500 }, /* (48000 * 1) / 6 */
568 { 9600, 0, 0x0000, 0x0000, 0x0400 }, /* (48000 * 1) / 5 */
569 { 12000, 0, 0x0000, 0x0000, 0x0300 }, /* (48000 * 1) / 4 */
570 { 16000, 1, 0x0000, 0x0000, 0x0200 }, /* (48000 * 1) / 3 */
571 { 18000, 0, 0x0000, 0x1000, 0x0700 }, /* (48000 * 3) / 8 */
572 { 19200, 0, 0x0000, 0x0800, 0x0400 }, /* (48000 * 2) / 5 */
573 { 24000, 0, 0x0000, 0x0000, 0x0100 }, /* (48000 * 1) / 2 */
574 { 28800, 0, 0x0000, 0x1000, 0x0400 }, /* (48000 * 3) / 5 */
575 { 32000, 1, 0x0000, 0x0800, 0x0200 }, /* (48000 * 2) / 3 */
576 { 36000, 0, 0x0000, 0x1000, 0x0300 }, /* (48000 * 3) / 4 */
577 { 38400, 0, 0x0000, 0x1800, 0x0400 }, /* (48000 * 4) / 5 */
578 { 48000, 1, 0x0000, 0x0000, 0x0000 }, /* (48000 * 1) / 1 */
579 { 64000, 0, 0x0000, 0x1800, 0x0200 }, /* (48000 * 4) / 3 */
580 { 72000, 0, 0x0000, 0x1000, 0x0100 }, /* (48000 * 3) / 2 */
581 { 96000, 1, 0x0000, 0x0800, 0x0000 }, /* (48000 * 2) / 1 */
582 { 144000, 0, 0x0000, 0x1000, 0x0000 }, /* (48000 * 3) / 1 */
583 { 192000, 1, 0x0000, 0x1800, 0x0000 }, /* (48000 * 4) / 1 */
584 { 8820, 0, 0x4000, 0x0000, 0x0400 }, /* (44100 * 1) / 5 */
585 { 11025, 1, 0x4000, 0x0000, 0x0300 }, /* (44100 * 1) / 4 */
586 { 12600, 0, 0x4000, 0x0800, 0x0600 }, /* (44100 * 2) / 7 */
587 { 14700, 0, 0x4000, 0x0000, 0x0200 }, /* (44100 * 1) / 3 */
588 { 17640, 0, 0x4000, 0x0800, 0x0400 }, /* (44100 * 2) / 5 */
589 { 18900, 0, 0x4000, 0x1000, 0x0600 }, /* (44100 * 3) / 7 */
590 { 22050, 1, 0x4000, 0x0000, 0x0100 }, /* (44100 * 1) / 2 */
591 { 25200, 0, 0x4000, 0x1800, 0x0600 }, /* (44100 * 4) / 7 */
592 { 26460, 0, 0x4000, 0x1000, 0x0400 }, /* (44100 * 3) / 5 */
593 { 29400, 0, 0x4000, 0x0800, 0x0200 }, /* (44100 * 2) / 3 */
594 { 33075, 0, 0x4000, 0x1000, 0x0300 }, /* (44100 * 3) / 4 */
595 { 35280, 0, 0x4000, 0x1800, 0x0400 }, /* (44100 * 4) / 5 */
596 { 44100, 1, 0x4000, 0x0000, 0x0000 }, /* (44100 * 1) / 1 */
597 { 58800, 0, 0x4000, 0x1800, 0x0200 }, /* (44100 * 4) / 3 */
598 { 66150, 0, 0x4000, 0x1000, 0x0100 }, /* (44100 * 3) / 2 */
599 { 88200, 1, 0x4000, 0x0800, 0x0000 }, /* (44100 * 2) / 1 */
600 { 132300, 0, 0x4000, 0x1000, 0x0000 }, /* (44100 * 3) / 1 */
601 { 176400, 1, 0x4000, 0x1800, 0x0000 }, /* (44100 * 4) / 1 */
603 #define HDA_RATE_TAB_LEN (sizeof(hda_rate_tab) / sizeof(hda_rate_tab[0]))
605 /* All codecs you can eat... */
606 #define HDA_CODEC_CONSTRUCT(vendor, id) \
607 (((uint32_t)(vendor##_VENDORID) << 16) | ((id) & 0xffff))
610 #define CIRRUSLOGIC_VENDORID 0x1013
611 #define HDA_CODEC_CS4206 HDA_CODEC_CONSTRUCT(CIRRUSLOGIC, 0x4206)
612 #define HDA_CODEC_CS4207 HDA_CODEC_CONSTRUCT(CIRRUSLOGIC, 0x4207)
613 #define HDA_CODEC_CSXXXX HDA_CODEC_CONSTRUCT(CIRRUSLOGIC, 0xffff)
616 #define REALTEK_VENDORID 0x10ec
617 #define HDA_CODEC_ALC260 HDA_CODEC_CONSTRUCT(REALTEK, 0x0260)
618 #define HDA_CODEC_ALC262 HDA_CODEC_CONSTRUCT(REALTEK, 0x0262)
619 #define HDA_CODEC_ALC267 HDA_CODEC_CONSTRUCT(REALTEK, 0x0267)
620 #define HDA_CODEC_ALC268 HDA_CODEC_CONSTRUCT(REALTEK, 0x0268)
621 #define HDA_CODEC_ALC269 HDA_CODEC_CONSTRUCT(REALTEK, 0x0269)
622 #define HDA_CODEC_ALC270 HDA_CODEC_CONSTRUCT(REALTEK, 0x0270)
623 #define HDA_CODEC_ALC272 HDA_CODEC_CONSTRUCT(REALTEK, 0x0272)
624 #define HDA_CODEC_ALC273 HDA_CODEC_CONSTRUCT(REALTEK, 0x0273)
625 #define HDA_CODEC_ALC275 HDA_CODEC_CONSTRUCT(REALTEK, 0x0275)
626 #define HDA_CODEC_ALC660 HDA_CODEC_CONSTRUCT(REALTEK, 0x0660)
627 #define HDA_CODEC_ALC662 HDA_CODEC_CONSTRUCT(REALTEK, 0x0662)
628 #define HDA_CODEC_ALC663 HDA_CODEC_CONSTRUCT(REALTEK, 0x0663)
629 #define HDA_CODEC_ALC665 HDA_CODEC_CONSTRUCT(REALTEK, 0x0665)
630 #define HDA_CODEC_ALC861 HDA_CODEC_CONSTRUCT(REALTEK, 0x0861)
631 #define HDA_CODEC_ALC861VD HDA_CODEC_CONSTRUCT(REALTEK, 0x0862)
632 #define HDA_CODEC_ALC880 HDA_CODEC_CONSTRUCT(REALTEK, 0x0880)
633 #define HDA_CODEC_ALC882 HDA_CODEC_CONSTRUCT(REALTEK, 0x0882)
634 #define HDA_CODEC_ALC883 HDA_CODEC_CONSTRUCT(REALTEK, 0x0883)
635 #define HDA_CODEC_ALC885 HDA_CODEC_CONSTRUCT(REALTEK, 0x0885)
636 #define HDA_CODEC_ALC887 HDA_CODEC_CONSTRUCT(REALTEK, 0x0887)
637 #define HDA_CODEC_ALC888 HDA_CODEC_CONSTRUCT(REALTEK, 0x0888)
638 #define HDA_CODEC_ALC889 HDA_CODEC_CONSTRUCT(REALTEK, 0x0889)
639 #define HDA_CODEC_ALC892 HDA_CODEC_CONSTRUCT(REALTEK, 0x0892)
640 #define HDA_CODEC_ALCXXXX HDA_CODEC_CONSTRUCT(REALTEK, 0xffff)
643 #define ANALOGDEVICES_VENDORID 0x11d4
644 #define HDA_CODEC_AD1884A HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0x184a)
645 #define HDA_CODEC_AD1882 HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0x1882)
646 #define HDA_CODEC_AD1883 HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0x1883)
647 #define HDA_CODEC_AD1884 HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0x1884)
648 #define HDA_CODEC_AD1984A HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0x194a)
649 #define HDA_CODEC_AD1984B HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0x194b)
650 #define HDA_CODEC_AD1981HD HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0x1981)
651 #define HDA_CODEC_AD1983 HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0x1983)
652 #define HDA_CODEC_AD1984 HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0x1984)
653 #define HDA_CODEC_AD1986A HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0x1986)
654 #define HDA_CODEC_AD1987 HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0x1987)
655 #define HDA_CODEC_AD1988 HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0x1988)
656 #define HDA_CODEC_AD1988B HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0x198b)
657 #define HDA_CODEC_AD1882A HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0x882a)
658 #define HDA_CODEC_AD1989B HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0x989b)
659 #define HDA_CODEC_ADXXXX HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0xffff)
662 #define CMEDIA_VENDORID 0x434d
663 #define HDA_CODEC_CMI9880 HDA_CODEC_CONSTRUCT(CMEDIA, 0x4980)
664 #define HDA_CODEC_CMIXXXX HDA_CODEC_CONSTRUCT(CMEDIA, 0xffff)
667 #define SIGMATEL_VENDORID 0x8384
668 #define HDA_CODEC_STAC9230X HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7612)
669 #define HDA_CODEC_STAC9230D HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7613)
670 #define HDA_CODEC_STAC9229X HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7614)
671 #define HDA_CODEC_STAC9229D HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7615)
672 #define HDA_CODEC_STAC9228X HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7616)
673 #define HDA_CODEC_STAC9228D HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7617)
674 #define HDA_CODEC_STAC9227X HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7618)
675 #define HDA_CODEC_STAC9227D HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7619)
676 #define HDA_CODEC_STAC9274 HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7620)
677 #define HDA_CODEC_STAC9274D HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7621)
678 #define HDA_CODEC_STAC9273X HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7622)
679 #define HDA_CODEC_STAC9273D HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7623)
680 #define HDA_CODEC_STAC9272X HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7624)
681 #define HDA_CODEC_STAC9272D HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7625)
682 #define HDA_CODEC_STAC9271X HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7626)
683 #define HDA_CODEC_STAC9271D HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7627)
684 #define HDA_CODEC_STAC9274X5NH HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7628)
685 #define HDA_CODEC_STAC9274D5NH HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7629)
686 #define HDA_CODEC_STAC9250 HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7634)
687 #define HDA_CODEC_STAC9251 HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7636)
688 #define HDA_CODEC_IDT92HD700X HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7638)
689 #define HDA_CODEC_IDT92HD700D HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7639)
690 #define HDA_CODEC_IDT92HD206X HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7645)
691 #define HDA_CODEC_IDT92HD206D HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7646)
692 #define HDA_CODEC_CXD9872RDK HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7661)
693 #define HDA_CODEC_STAC9872AK HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7662)
694 #define HDA_CODEC_CXD9872AKD HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7664)
695 #define HDA_CODEC_STAC9221 HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7680)
696 #define HDA_CODEC_STAC922XD HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7681)
697 #define HDA_CODEC_STAC9221_A2 HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7682)
698 #define HDA_CODEC_STAC9221D HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7683)
699 #define HDA_CODEC_STAC9220 HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7690)
700 #define HDA_CODEC_STAC9200D HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7691)
701 #define HDA_CODEC_IDT92HD005 HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7698)
702 #define HDA_CODEC_IDT92HD005D HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7699)
703 #define HDA_CODEC_STAC9205X HDA_CODEC_CONSTRUCT(SIGMATEL, 0x76a0)
704 #define HDA_CODEC_STAC9205D HDA_CODEC_CONSTRUCT(SIGMATEL, 0x76a1)
705 #define HDA_CODEC_STAC9204X HDA_CODEC_CONSTRUCT(SIGMATEL, 0x76a2)
706 #define HDA_CODEC_STAC9204D HDA_CODEC_CONSTRUCT(SIGMATEL, 0x76a3)
707 #define HDA_CODEC_STAC9220_A2 HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7880)
708 #define HDA_CODEC_STAC9220_A1 HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7882)
709 #define HDA_CODEC_STACXXXX HDA_CODEC_CONSTRUCT(SIGMATEL, 0xffff)
712 #define IDT_VENDORID 0x111d
713 #define HDA_CODEC_IDT92HD75BX HDA_CODEC_CONSTRUCT(IDT, 0x7603)
714 #define HDA_CODEC_IDT92HD83C1X HDA_CODEC_CONSTRUCT(IDT, 0x7604)
715 #define HDA_CODEC_IDT92HD81B1X HDA_CODEC_CONSTRUCT(IDT, 0x7605)
716 #define HDA_CODEC_IDT92HD75B3 HDA_CODEC_CONSTRUCT(IDT, 0x7608)
717 #define HDA_CODEC_IDT92HD73D1 HDA_CODEC_CONSTRUCT(IDT, 0x7674)
718 #define HDA_CODEC_IDT92HD73C1 HDA_CODEC_CONSTRUCT(IDT, 0x7675)
719 #define HDA_CODEC_IDT92HD73E1 HDA_CODEC_CONSTRUCT(IDT, 0x7676)
720 #define HDA_CODEC_IDT92HD71B8 HDA_CODEC_CONSTRUCT(IDT, 0x76b0)
721 #define HDA_CODEC_IDT92HD71B7 HDA_CODEC_CONSTRUCT(IDT, 0x76b2)
722 #define HDA_CODEC_IDT92HD71B5 HDA_CODEC_CONSTRUCT(IDT, 0x76b6)
723 #define HDA_CODEC_IDT92HD83C1C HDA_CODEC_CONSTRUCT(IDT, 0x76d4)
724 #define HDA_CODEC_IDT92HD81B1C HDA_CODEC_CONSTRUCT(IDT, 0x76d5)
725 #define HDA_CODEC_IDTXXXX HDA_CODEC_CONSTRUCT(IDT, 0xffff)
728 #define SII_VENDORID 0x1095
729 #define HDA_CODEC_SII1390 HDA_CODEC_CONSTRUCT(SII, 0x1390)
730 #define HDA_CODEC_SII1392 HDA_CODEC_CONSTRUCT(SII, 0x1392)
731 #define HDA_CODEC_SIIXXXX HDA_CODEC_CONSTRUCT(SII, 0xffff)
734 #define AGERE_VENDORID 0x11c1
735 #define HDA_CODEC_AGEREXXXX HDA_CODEC_CONSTRUCT(AGERE, 0xffff)
738 #define CONEXANT_VENDORID 0x14f1
739 #define HDA_CODEC_CX20549 HDA_CODEC_CONSTRUCT(CONEXANT, 0x5045)
740 #define HDA_CODEC_CX20551 HDA_CODEC_CONSTRUCT(CONEXANT, 0x5047)
741 #define HDA_CODEC_CX20561 HDA_CODEC_CONSTRUCT(CONEXANT, 0x5051)
742 #define HDA_CODEC_CX20582 HDA_CODEC_CONSTRUCT(CONEXANT, 0x5066)
743 #define HDA_CODEC_CX20583 HDA_CODEC_CONSTRUCT(CONEXANT, 0x5067)
744 #define HDA_CODEC_CXXXXX HDA_CODEC_CONSTRUCT(CONEXANT, 0xffff)
747 #define HDA_CODEC_VT1708_8 HDA_CODEC_CONSTRUCT(VIA, 0x1708)
748 #define HDA_CODEC_VT1708_9 HDA_CODEC_CONSTRUCT(VIA, 0x1709)
749 #define HDA_CODEC_VT1708_A HDA_CODEC_CONSTRUCT(VIA, 0x170a)
750 #define HDA_CODEC_VT1708_B HDA_CODEC_CONSTRUCT(VIA, 0x170b)
751 #define HDA_CODEC_VT1709_0 HDA_CODEC_CONSTRUCT(VIA, 0xe710)
752 #define HDA_CODEC_VT1709_1 HDA_CODEC_CONSTRUCT(VIA, 0xe711)
753 #define HDA_CODEC_VT1709_2 HDA_CODEC_CONSTRUCT(VIA, 0xe712)
754 #define HDA_CODEC_VT1709_3 HDA_CODEC_CONSTRUCT(VIA, 0xe713)
755 #define HDA_CODEC_VT1709_4 HDA_CODEC_CONSTRUCT(VIA, 0xe714)
756 #define HDA_CODEC_VT1709_5 HDA_CODEC_CONSTRUCT(VIA, 0xe715)
757 #define HDA_CODEC_VT1709_6 HDA_CODEC_CONSTRUCT(VIA, 0xe716)
758 #define HDA_CODEC_VT1709_7 HDA_CODEC_CONSTRUCT(VIA, 0xe717)
759 #define HDA_CODEC_VT1708B_0 HDA_CODEC_CONSTRUCT(VIA, 0xe720)
760 #define HDA_CODEC_VT1708B_1 HDA_CODEC_CONSTRUCT(VIA, 0xe721)
761 #define HDA_CODEC_VT1708B_2 HDA_CODEC_CONSTRUCT(VIA, 0xe722)
762 #define HDA_CODEC_VT1708B_3 HDA_CODEC_CONSTRUCT(VIA, 0xe723)
763 #define HDA_CODEC_VT1708B_4 HDA_CODEC_CONSTRUCT(VIA, 0xe724)
764 #define HDA_CODEC_VT1708B_5 HDA_CODEC_CONSTRUCT(VIA, 0xe725)
765 #define HDA_CODEC_VT1708B_6 HDA_CODEC_CONSTRUCT(VIA, 0xe726)
766 #define HDA_CODEC_VT1708B_7 HDA_CODEC_CONSTRUCT(VIA, 0xe727)
767 #define HDA_CODEC_VT1708S_0 HDA_CODEC_CONSTRUCT(VIA, 0x0397)
768 #define HDA_CODEC_VT1708S_1 HDA_CODEC_CONSTRUCT(VIA, 0x1397)
769 #define HDA_CODEC_VT1708S_2 HDA_CODEC_CONSTRUCT(VIA, 0x2397)
770 #define HDA_CODEC_VT1708S_3 HDA_CODEC_CONSTRUCT(VIA, 0x3397)
771 #define HDA_CODEC_VT1708S_4 HDA_CODEC_CONSTRUCT(VIA, 0x4397)
772 #define HDA_CODEC_VT1708S_5 HDA_CODEC_CONSTRUCT(VIA, 0x5397)
773 #define HDA_CODEC_VT1708S_6 HDA_CODEC_CONSTRUCT(VIA, 0x6397)
774 #define HDA_CODEC_VT1708S_7 HDA_CODEC_CONSTRUCT(VIA, 0x7397)
775 #define HDA_CODEC_VT1702_0 HDA_CODEC_CONSTRUCT(VIA, 0x0398)
776 #define HDA_CODEC_VT1702_1 HDA_CODEC_CONSTRUCT(VIA, 0x1398)
777 #define HDA_CODEC_VT1702_2 HDA_CODEC_CONSTRUCT(VIA, 0x2398)
778 #define HDA_CODEC_VT1702_3 HDA_CODEC_CONSTRUCT(VIA, 0x3398)
779 #define HDA_CODEC_VT1702_4 HDA_CODEC_CONSTRUCT(VIA, 0x4398)
780 #define HDA_CODEC_VT1702_5 HDA_CODEC_CONSTRUCT(VIA, 0x5398)
781 #define HDA_CODEC_VT1702_6 HDA_CODEC_CONSTRUCT(VIA, 0x6398)
782 #define HDA_CODEC_VT1702_7 HDA_CODEC_CONSTRUCT(VIA, 0x7398)
783 #define HDA_CODEC_VT1716S_0 HDA_CODEC_CONSTRUCT(VIA, 0x0433)
784 #define HDA_CODEC_VT1716S_1 HDA_CODEC_CONSTRUCT(VIA, 0xa721)
785 #define HDA_CODEC_VT1718S_0 HDA_CODEC_CONSTRUCT(VIA, 0x0428)
786 #define HDA_CODEC_VT1718S_1 HDA_CODEC_CONSTRUCT(VIA, 0x4428)
787 #define HDA_CODEC_VT1812 HDA_CODEC_CONSTRUCT(VIA, 0x0448)
788 #define HDA_CODEC_VT1818S HDA_CODEC_CONSTRUCT(VIA, 0x0440)
789 #define HDA_CODEC_VT1828S HDA_CODEC_CONSTRUCT(VIA, 0x4441)
790 #define HDA_CODEC_VT2002P_0 HDA_CODEC_CONSTRUCT(VIA, 0x0438)
791 #define HDA_CODEC_VT2002P_1 HDA_CODEC_CONSTRUCT(VIA, 0x4438)
792 #define HDA_CODEC_VT2020 HDA_CODEC_CONSTRUCT(VIA, 0x0441)
793 #define HDA_CODEC_VTXXXX HDA_CODEC_CONSTRUCT(VIA, 0xffff)
796 #define HDA_CODEC_ATIRS600_1 HDA_CODEC_CONSTRUCT(ATI, 0x793c)
797 #define HDA_CODEC_ATIRS600_2 HDA_CODEC_CONSTRUCT(ATI, 0x7919)
798 #define HDA_CODEC_ATIRS690 HDA_CODEC_CONSTRUCT(ATI, 0x791a)
799 #define HDA_CODEC_ATIR6XX HDA_CODEC_CONSTRUCT(ATI, 0xaa01)
800 #define HDA_CODEC_ATIXXXX HDA_CODEC_CONSTRUCT(ATI, 0xffff)
803 #define HDA_CODEC_NVIDIAMCP78 HDA_CODEC_CONSTRUCT(NVIDIA, 0x0002)
804 #define HDA_CODEC_NVIDIAMCP78_2 HDA_CODEC_CONSTRUCT(NVIDIA, 0x0006)
805 #define HDA_CODEC_NVIDIAMCP7A HDA_CODEC_CONSTRUCT(NVIDIA, 0x0007)
806 #define HDA_CODEC_NVIDIAMCP67 HDA_CODEC_CONSTRUCT(NVIDIA, 0x0067)
807 #define HDA_CODEC_NVIDIAMCP73 HDA_CODEC_CONSTRUCT(NVIDIA, 0x8001)
808 #define HDA_CODEC_NVIDIAXXXX HDA_CODEC_CONSTRUCT(NVIDIA, 0xffff)
811 #define HDA_CODEC_INTELG45_1 HDA_CODEC_CONSTRUCT(INTEL, 0x2801)
812 #define HDA_CODEC_INTELG45_2 HDA_CODEC_CONSTRUCT(INTEL, 0x2802)
813 #define HDA_CODEC_INTELG45_3 HDA_CODEC_CONSTRUCT(INTEL, 0x2803)
814 #define HDA_CODEC_INTELG45_4 HDA_CODEC_CONSTRUCT(INTEL, 0x2804)
815 #define HDA_CODEC_INTELG45_5 HDA_CODEC_CONSTRUCT(INTEL, 0x29fb)
816 #define HDA_CODEC_INTELQ57 HDA_CODEC_CONSTRUCT(INTEL, 0x0054)
817 #define HDA_CODEC_INTELXXXX HDA_CODEC_CONSTRUCT(INTEL, 0xffff)
820 static const struct {
824 { HDA_CODEC_CS4206, "Cirrus Logic CS4206" },
825 { HDA_CODEC_CS4207, "Cirrus Logic CS4207" },
826 { HDA_CODEC_ALC260, "Realtek ALC260" },
827 { HDA_CODEC_ALC262, "Realtek ALC262" },
828 { HDA_CODEC_ALC267, "Realtek ALC267" },
829 { HDA_CODEC_ALC268, "Realtek ALC268" },
830 { HDA_CODEC_ALC269, "Realtek ALC269" },
831 { HDA_CODEC_ALC270, "Realtek ALC270" },
832 { HDA_CODEC_ALC272, "Realtek ALC272" },
833 { HDA_CODEC_ALC273, "Realtek ALC273" },
834 { HDA_CODEC_ALC275, "Realtek ALC275" },
835 { HDA_CODEC_ALC660, "Realtek ALC660" },
836 { HDA_CODEC_ALC662, "Realtek ALC662" },
837 { HDA_CODEC_ALC663, "Realtek ALC663" },
838 { HDA_CODEC_ALC665, "Realtek ALC665" },
839 { HDA_CODEC_ALC861, "Realtek ALC861" },
840 { HDA_CODEC_ALC861VD, "Realtek ALC861-VD" },
841 { HDA_CODEC_ALC880, "Realtek ALC880" },
842 { HDA_CODEC_ALC882, "Realtek ALC882" },
843 { HDA_CODEC_ALC883, "Realtek ALC883" },
844 { HDA_CODEC_ALC885, "Realtek ALC885" },
845 { HDA_CODEC_ALC887, "Realtek ALC887" },
846 { HDA_CODEC_ALC888, "Realtek ALC888" },
847 { HDA_CODEC_ALC889, "Realtek ALC889" },
848 { HDA_CODEC_ALC892, "Realtek ALC892" },
849 { HDA_CODEC_AD1882, "Analog Devices AD1882" },
850 { HDA_CODEC_AD1882A, "Analog Devices AD1882A" },
851 { HDA_CODEC_AD1883, "Analog Devices AD1883" },
852 { HDA_CODEC_AD1884, "Analog Devices AD1884" },
853 { HDA_CODEC_AD1884A, "Analog Devices AD1884A" },
854 { HDA_CODEC_AD1981HD, "Analog Devices AD1981HD" },
855 { HDA_CODEC_AD1983, "Analog Devices AD1983" },
856 { HDA_CODEC_AD1984, "Analog Devices AD1984" },
857 { HDA_CODEC_AD1984A, "Analog Devices AD1984A" },
858 { HDA_CODEC_AD1984B, "Analog Devices AD1984B" },
859 { HDA_CODEC_AD1986A, "Analog Devices AD1986A" },
860 { HDA_CODEC_AD1987, "Analog Devices AD1987" },
861 { HDA_CODEC_AD1988, "Analog Devices AD1988A" },
862 { HDA_CODEC_AD1988B, "Analog Devices AD1988B" },
863 { HDA_CODEC_AD1989B, "Analog Devices AD1989B" },
864 { HDA_CODEC_CMI9880, "CMedia CMI9880" },
865 { HDA_CODEC_CXD9872RDK, "Sigmatel CXD9872RD/K" },
866 { HDA_CODEC_CXD9872AKD, "Sigmatel CXD9872AKD" },
867 { HDA_CODEC_STAC9200D, "Sigmatel STAC9200D" },
868 { HDA_CODEC_STAC9204X, "Sigmatel STAC9204X" },
869 { HDA_CODEC_STAC9204D, "Sigmatel STAC9204D" },
870 { HDA_CODEC_STAC9205X, "Sigmatel STAC9205X" },
871 { HDA_CODEC_STAC9205D, "Sigmatel STAC9205D" },
872 { HDA_CODEC_STAC9220, "Sigmatel STAC9220" },
873 { HDA_CODEC_STAC9220_A1, "Sigmatel STAC9220_A1" },
874 { HDA_CODEC_STAC9220_A2, "Sigmatel STAC9220_A2" },
875 { HDA_CODEC_STAC9221, "Sigmatel STAC9221" },
876 { HDA_CODEC_STAC9221_A2, "Sigmatel STAC9221_A2" },
877 { HDA_CODEC_STAC9221D, "Sigmatel STAC9221D" },
878 { HDA_CODEC_STAC922XD, "Sigmatel STAC9220D/9223D" },
879 { HDA_CODEC_STAC9227X, "Sigmatel STAC9227X" },
880 { HDA_CODEC_STAC9227D, "Sigmatel STAC9227D" },
881 { HDA_CODEC_STAC9228X, "Sigmatel STAC9228X" },
882 { HDA_CODEC_STAC9228D, "Sigmatel STAC9228D" },
883 { HDA_CODEC_STAC9229X, "Sigmatel STAC9229X" },
884 { HDA_CODEC_STAC9229D, "Sigmatel STAC9229D" },
885 { HDA_CODEC_STAC9230X, "Sigmatel STAC9230X" },
886 { HDA_CODEC_STAC9230D, "Sigmatel STAC9230D" },
887 { HDA_CODEC_STAC9250, "Sigmatel STAC9250" },
888 { HDA_CODEC_STAC9251, "Sigmatel STAC9251" },
889 { HDA_CODEC_STAC9271X, "Sigmatel STAC9271X" },
890 { HDA_CODEC_STAC9271D, "Sigmatel STAC9271D" },
891 { HDA_CODEC_STAC9272X, "Sigmatel STAC9272X" },
892 { HDA_CODEC_STAC9272D, "Sigmatel STAC9272D" },
893 { HDA_CODEC_STAC9273X, "Sigmatel STAC9273X" },
894 { HDA_CODEC_STAC9273D, "Sigmatel STAC9273D" },
895 { HDA_CODEC_STAC9274, "Sigmatel STAC9274" },
896 { HDA_CODEC_STAC9274D, "Sigmatel STAC9274D" },
897 { HDA_CODEC_STAC9274X5NH, "Sigmatel STAC9274X5NH" },
898 { HDA_CODEC_STAC9274D5NH, "Sigmatel STAC9274D5NH" },
899 { HDA_CODEC_STAC9872AK, "Sigmatel STAC9872AK" },
900 { HDA_CODEC_IDT92HD005, "IDT 92HD005" },
901 { HDA_CODEC_IDT92HD005D, "IDT 92HD005D" },
902 { HDA_CODEC_IDT92HD206X, "IDT 92HD206X" },
903 { HDA_CODEC_IDT92HD206D, "IDT 92HD206D" },
904 { HDA_CODEC_IDT92HD700X, "IDT 92HD700X" },
905 { HDA_CODEC_IDT92HD700D, "IDT 92HD700D" },
906 { HDA_CODEC_IDT92HD71B5, "IDT 92HD71B5" },
907 { HDA_CODEC_IDT92HD71B7, "IDT 92HD71B7" },
908 { HDA_CODEC_IDT92HD71B8, "IDT 92HD71B8" },
909 { HDA_CODEC_IDT92HD73C1, "IDT 92HD73C1" },
910 { HDA_CODEC_IDT92HD73D1, "IDT 92HD73D1" },
911 { HDA_CODEC_IDT92HD73E1, "IDT 92HD73E1" },
912 { HDA_CODEC_IDT92HD75B3, "IDT 92HD75B3" },
913 { HDA_CODEC_IDT92HD75BX, "IDT 92HD75BX" },
914 { HDA_CODEC_IDT92HD81B1C, "IDT 92HD81B1C" },
915 { HDA_CODEC_IDT92HD81B1X, "IDT 92HD81B1X" },
916 { HDA_CODEC_IDT92HD83C1C, "IDT 92HD83C1C" },
917 { HDA_CODEC_IDT92HD83C1X, "IDT 92HD83C1X" },
918 { HDA_CODEC_CX20549, "Conexant CX20549 (Venice)" },
919 { HDA_CODEC_CX20551, "Conexant CX20551 (Waikiki)" },
920 { HDA_CODEC_CX20561, "Conexant CX20561 (Hermosa)" },
921 { HDA_CODEC_CX20582, "Conexant CX20582 (Pebble)" },
922 { HDA_CODEC_CX20583, "Conexant CX20583 (Pebble HSF)" },
923 { HDA_CODEC_VT1708_8, "VIA VT1708_8" },
924 { HDA_CODEC_VT1708_9, "VIA VT1708_9" },
925 { HDA_CODEC_VT1708_A, "VIA VT1708_A" },
926 { HDA_CODEC_VT1708_B, "VIA VT1708_B" },
927 { HDA_CODEC_VT1709_0, "VIA VT1709_0" },
928 { HDA_CODEC_VT1709_1, "VIA VT1709_1" },
929 { HDA_CODEC_VT1709_2, "VIA VT1709_2" },
930 { HDA_CODEC_VT1709_3, "VIA VT1709_3" },
931 { HDA_CODEC_VT1709_4, "VIA VT1709_4" },
932 { HDA_CODEC_VT1709_5, "VIA VT1709_5" },
933 { HDA_CODEC_VT1709_6, "VIA VT1709_6" },
934 { HDA_CODEC_VT1709_7, "VIA VT1709_7" },
935 { HDA_CODEC_VT1708B_0, "VIA VT1708B_0" },
936 { HDA_CODEC_VT1708B_1, "VIA VT1708B_1" },
937 { HDA_CODEC_VT1708B_2, "VIA VT1708B_2" },
938 { HDA_CODEC_VT1708B_3, "VIA VT1708B_3" },
939 { HDA_CODEC_VT1708B_4, "VIA VT1708B_4" },
940 { HDA_CODEC_VT1708B_5, "VIA VT1708B_5" },
941 { HDA_CODEC_VT1708B_6, "VIA VT1708B_6" },
942 { HDA_CODEC_VT1708B_7, "VIA VT1708B_7" },
943 { HDA_CODEC_VT1708S_0, "VIA VT1708S_0" },
944 { HDA_CODEC_VT1708S_1, "VIA VT1708S_1" },
945 { HDA_CODEC_VT1708S_2, "VIA VT1708S_2" },
946 { HDA_CODEC_VT1708S_3, "VIA VT1708S_3" },
947 { HDA_CODEC_VT1708S_4, "VIA VT1708S_4" },
948 { HDA_CODEC_VT1708S_5, "VIA VT1708S_5" },
949 { HDA_CODEC_VT1708S_6, "VIA VT1708S_6" },
950 { HDA_CODEC_VT1708S_7, "VIA VT1708S_7" },
951 { HDA_CODEC_VT1702_0, "VIA VT1702_0" },
952 { HDA_CODEC_VT1702_1, "VIA VT1702_1" },
953 { HDA_CODEC_VT1702_2, "VIA VT1702_2" },
954 { HDA_CODEC_VT1702_3, "VIA VT1702_3" },
955 { HDA_CODEC_VT1702_4, "VIA VT1702_4" },
956 { HDA_CODEC_VT1702_5, "VIA VT1702_5" },
957 { HDA_CODEC_VT1702_6, "VIA VT1702_6" },
958 { HDA_CODEC_VT1702_7, "VIA VT1702_7" },
959 { HDA_CODEC_VT1716S_0, "VIA VT1716S_0" },
960 { HDA_CODEC_VT1716S_1, "VIA VT1716S_1" },
961 { HDA_CODEC_VT1718S_0, "VIA VT1718S_0" },
962 { HDA_CODEC_VT1718S_1, "VIA VT1718S_1" },
963 { HDA_CODEC_VT1812, "VIA VT1812" },
964 { HDA_CODEC_VT1818S, "VIA VT1818S" },
965 { HDA_CODEC_VT1828S, "VIA VT1828S" },
966 { HDA_CODEC_VT2002P_0, "VIA VT2002P_0" },
967 { HDA_CODEC_VT2002P_1, "VIA VT2002P_1" },
968 { HDA_CODEC_VT2020, "VIA VT2020" },
969 { HDA_CODEC_ATIRS600_1,"ATI RS600 HDMI" },
970 { HDA_CODEC_ATIRS600_2,"ATI RS600 HDMI" },
971 { HDA_CODEC_ATIRS690, "ATI RS690/780 HDMI" },
972 { HDA_CODEC_ATIR6XX, "ATI R6xx HDMI" },
973 { HDA_CODEC_NVIDIAMCP67, "NVidia MCP67 HDMI" },
974 { HDA_CODEC_NVIDIAMCP73, "NVidia MCP73 HDMI" },
975 { HDA_CODEC_NVIDIAMCP78, "NVidia MCP78 HDMI" },
976 { HDA_CODEC_NVIDIAMCP78_2, "NVidia MCP78 HDMI" },
977 { HDA_CODEC_NVIDIAMCP7A, "NVidia MCP7A HDMI" },
978 { HDA_CODEC_INTELG45_1, "Intel G45 HDMI" },
979 { HDA_CODEC_INTELG45_2, "Intel G45 HDMI" },
980 { HDA_CODEC_INTELG45_3, "Intel G45 HDMI" },
981 { HDA_CODEC_INTELG45_4, "Intel G45 HDMI" },
982 { HDA_CODEC_INTELG45_5, "Intel G45 HDMI" },
983 { HDA_CODEC_INTELQ57, "Intel Q57 HDMI" },
984 { HDA_CODEC_SII1390, "Silicon Image SiI1390 HDMI" },
985 { HDA_CODEC_SII1392, "Silicon Image SiI1392 HDMI" },
987 { HDA_CODEC_ALCXXXX, "Realtek (Unknown)" },
988 { HDA_CODEC_ADXXXX, "Analog Devices (Unknown)" },
989 { HDA_CODEC_CSXXXX, "Cirrus Logic (Unknown)" },
990 { HDA_CODEC_CMIXXXX, "CMedia (Unknown)" },
991 { HDA_CODEC_STACXXXX, "Sigmatel (Unknown)" },
992 { HDA_CODEC_SIIXXXX, "Silicon Image (Unknown)" },
993 { HDA_CODEC_AGEREXXXX, "Lucent/Agere Systems (Unknown)" },
994 { HDA_CODEC_CXXXXX, "Conexant (Unknown)" },
995 { HDA_CODEC_VTXXXX, "VIA (Unknown)" },
996 { HDA_CODEC_ATIXXXX, "ATI (Unknown)" },
997 { HDA_CODEC_NVIDIAXXXX,"NVidia (Unknown)" },
998 { HDA_CODEC_INTELXXXX, "Intel (Unknown)" },
999 { HDA_CODEC_IDTXXXX, "IDT (Unknown)" },
1001 #define HDAC_CODECS_LEN (sizeof(hdac_codecs) / sizeof(hdac_codecs[0]))
1004 /****************************************************************************
1005 * Function prototypes
1006 ****************************************************************************/
1007 static void hdac_intr_handler(void *);
1008 static int hdac_reset(struct hdac_softc *, int);
1009 static int hdac_get_capabilities(struct hdac_softc *);
1010 static void hdac_dma_cb(void *, bus_dma_segment_t *, int, int);
1011 static int hdac_dma_alloc(struct hdac_softc *,
1012 struct hdac_dma *, bus_size_t);
1013 static void hdac_dma_free(struct hdac_softc *, struct hdac_dma *);
1014 static int hdac_mem_alloc(struct hdac_softc *);
1015 static void hdac_mem_free(struct hdac_softc *);
1016 static int hdac_irq_alloc(struct hdac_softc *);
1017 static void hdac_irq_free(struct hdac_softc *);
1018 static void hdac_corb_init(struct hdac_softc *);
1019 static void hdac_rirb_init(struct hdac_softc *);
1020 static void hdac_corb_start(struct hdac_softc *);
1021 static void hdac_rirb_start(struct hdac_softc *);
1022 static void hdac_scan_codecs(struct hdac_softc *);
1023 static void hdac_probe_codec(struct hdac_codec *);
1024 static void hdac_probe_function(struct hdac_codec *, nid_t);
1025 static int hdac_pcmchannel_setup(struct hdac_chan *);
1027 static void hdac_attach2(void *);
1029 static uint32_t hdac_command_sendone_internal(struct hdac_softc *,
1031 static void hdac_command_send_internal(struct hdac_softc *,
1032 struct hdac_command_list *, int);
1034 static int hdac_probe(device_t);
1035 static int hdac_attach(device_t);
1036 static int hdac_detach(device_t);
1037 static int hdac_suspend(device_t);
1038 static int hdac_resume(device_t);
1039 static void hdac_widget_connection_select(struct hdac_widget *, uint8_t);
1040 static void hdac_audio_ctl_amp_set(struct hdac_audio_ctl *,
1041 uint32_t, int, int);
1042 static struct hdac_audio_ctl *hdac_audio_ctl_amp_get(struct hdac_devinfo *,
1043 nid_t, int, int, int);
1044 static void hdac_audio_ctl_amp_set_internal(struct hdac_softc *,
1045 nid_t, nid_t, int, int, int, int, int, int);
1046 static struct hdac_widget *hdac_widget_get(struct hdac_devinfo *, nid_t);
1048 static int hdac_rirb_flush(struct hdac_softc *sc);
1049 static int hdac_unsolq_flush(struct hdac_softc *sc);
1051 static void hdac_dump_pin_config(struct hdac_widget *w, uint32_t conf);
1053 #define hdac_command(a1, a2, a3) \
1054 hdac_command_sendone_internal(a1, a2, a3)
1056 #define hdac_codec_id(c) \
1057 ((uint32_t)((c == NULL) ? 0x00000000 : \
1058 ((((uint32_t)(c)->vendor_id & 0x0000ffff) << 16) | \
1059 ((uint32_t)(c)->device_id & 0x0000ffff))))
1062 hdac_codec_name(struct hdac_codec *codec)
1067 id = hdac_codec_id(codec);
1069 for (i = 0; i < HDAC_CODECS_LEN; i++) {
1070 if (HDA_DEV_MATCH(hdac_codecs[i].id, id))
1071 return (hdac_codecs[i].name);
1074 return ((id == 0x00000000) ? "NULL Codec" : "Unknown Codec");
1078 hdac_audio_ctl_ossmixer_mask2allname(uint32_t mask, char *buf, size_t len)
1080 static char *ossname[] = SOUND_DEVICE_NAMES;
1084 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
1085 if (mask & (1 << i)) {
1087 strlcat(buf, ", ", len);
1088 strlcat(buf, ossname[i], len);
1095 static struct hdac_audio_ctl *
1096 hdac_audio_ctl_each(struct hdac_devinfo *devinfo, int *index)
1098 if (devinfo == NULL ||
1099 devinfo->node_type != HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO ||
1100 index == NULL || devinfo->function.audio.ctl == NULL ||
1101 devinfo->function.audio.ctlcnt < 1 ||
1102 *index < 0 || *index >= devinfo->function.audio.ctlcnt)
1104 return (&devinfo->function.audio.ctl[(*index)++]);
1107 static struct hdac_audio_ctl *
1108 hdac_audio_ctl_amp_get(struct hdac_devinfo *devinfo, nid_t nid, int dir,
1111 struct hdac_audio_ctl *ctl;
1114 if (devinfo == NULL || devinfo->function.audio.ctl == NULL)
1118 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) {
1119 if (ctl->enable == 0)
1121 if (ctl->widget->nid != nid)
1123 if (dir && ctl->ndir != dir)
1125 if (index >= 0 && ctl->ndir == HDA_CTL_IN &&
1126 ctl->dir == ctl->ndir && ctl->index != index)
1129 if (found == cnt || cnt <= 0)
1137 * Jack detection (Speaker/HP redirection) event handler.
1140 hdac_hp_switch_handler(struct hdac_devinfo *devinfo)
1142 struct hdac_audio_as *as;
1143 struct hdac_softc *sc;
1144 struct hdac_widget *w;
1145 struct hdac_audio_ctl *ctl;
1150 if (devinfo == NULL || devinfo->codec == NULL ||
1151 devinfo->codec->sc == NULL)
1154 sc = devinfo->codec->sc;
1155 cad = devinfo->codec->cad;
1156 as = devinfo->function.audio.as;
1157 for (i = 0; i < devinfo->function.audio.ascnt; i++) {
1158 if (as[i].hpredir < 0)
1161 w = hdac_widget_get(devinfo, as[i].pins[15]);
1162 if (w == NULL || w->enable == 0 || w->type !=
1163 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
1166 res = hdac_command(sc,
1167 HDA_CMD_GET_PIN_SENSE(cad, as[i].pins[15]), cad);
1170 device_printf(sc->dev,
1171 "Pin sense: nid=%d res=0x%08x\n",
1172 as[i].pins[15], res);
1175 res = HDA_CMD_GET_PIN_SENSE_PRESENCE_DETECT(res);
1176 if (devinfo->function.audio.quirks & HDA_QUIRK_SENSEINV)
1179 /* (Un)Mute headphone pin. */
1180 ctl = hdac_audio_ctl_amp_get(devinfo,
1181 as[i].pins[15], HDA_CTL_IN, -1, 1);
1182 if (ctl != NULL && ctl->mute) {
1183 /* If pin has muter - use it. */
1184 val = (res != 0) ? 0 : 1;
1185 if (val != ctl->forcemute) {
1186 ctl->forcemute = val;
1187 hdac_audio_ctl_amp_set(ctl,
1188 HDA_AMP_MUTE_DEFAULT,
1189 HDA_AMP_VOL_DEFAULT, HDA_AMP_VOL_DEFAULT);
1192 /* If there is no muter - disable pin output. */
1193 w = hdac_widget_get(devinfo, as[i].pins[15]);
1194 if (w != NULL && w->type ==
1195 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) {
1197 val = w->wclass.pin.ctrl |
1198 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
1200 val = w->wclass.pin.ctrl &
1201 ~HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
1202 if (val != w->wclass.pin.ctrl) {
1203 w->wclass.pin.ctrl = val;
1205 HDA_CMD_SET_PIN_WIDGET_CTRL(cad,
1206 w->nid, w->wclass.pin.ctrl), cad);
1210 /* (Un)Mute other pins. */
1211 for (j = 0; j < 15; j++) {
1212 if (as[i].pins[j] <= 0)
1214 ctl = hdac_audio_ctl_amp_get(devinfo,
1215 as[i].pins[j], HDA_CTL_IN, -1, 1);
1216 if (ctl != NULL && ctl->mute) {
1217 /* If pin has muter - use it. */
1218 val = (res != 0) ? 1 : 0;
1219 if (val == ctl->forcemute)
1221 ctl->forcemute = val;
1222 hdac_audio_ctl_amp_set(ctl,
1223 HDA_AMP_MUTE_DEFAULT,
1224 HDA_AMP_VOL_DEFAULT, HDA_AMP_VOL_DEFAULT);
1227 /* If there is no muter - disable pin output. */
1228 w = hdac_widget_get(devinfo, as[i].pins[j]);
1229 if (w != NULL && w->type ==
1230 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) {
1232 val = w->wclass.pin.ctrl &
1233 ~HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
1235 val = w->wclass.pin.ctrl |
1236 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
1237 if (val != w->wclass.pin.ctrl) {
1238 w->wclass.pin.ctrl = val;
1240 HDA_CMD_SET_PIN_WIDGET_CTRL(cad,
1241 w->nid, w->wclass.pin.ctrl), cad);
1249 * Callback for poll based jack detection.
1252 hdac_jack_poll_callback(void *arg)
1254 struct hdac_devinfo *devinfo = arg;
1255 struct hdac_softc *sc;
1257 if (devinfo == NULL || devinfo->codec == NULL ||
1258 devinfo->codec->sc == NULL)
1260 sc = devinfo->codec->sc;
1262 if (sc->poll_ival == 0) {
1266 hdac_hp_switch_handler(devinfo);
1267 callout_reset(&sc->poll_jack, sc->poll_ival,
1268 hdac_jack_poll_callback, devinfo);
1273 * Jack detection initializer.
1276 hdac_hp_switch_init(struct hdac_devinfo *devinfo)
1278 struct hdac_softc *sc = devinfo->codec->sc;
1279 struct hdac_audio_as *as = devinfo->function.audio.as;
1280 struct hdac_widget *w;
1282 int i, enable = 0, poll = 0;
1285 id = hdac_codec_id(devinfo->codec);
1286 cad = devinfo->codec->cad;
1287 for (i = 0; i < devinfo->function.audio.ascnt; i++) {
1288 if (as[i].hpredir < 0)
1291 w = hdac_widget_get(devinfo, as[i].pins[15]);
1292 if (w == NULL || w->enable == 0 || w->type !=
1293 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
1295 if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(w->wclass.pin.cap) == 0 ||
1296 (HDA_CONFIG_DEFAULTCONF_MISC(w->wclass.pin.config) & 1) != 0) {
1297 device_printf(sc->dev,
1298 "No jack detection support at pin %d\n",
1303 if (HDA_PARAM_AUDIO_WIDGET_CAP_UNSOL_CAP(w->param.widget_cap)) {
1305 HDA_CMD_SET_UNSOLICITED_RESPONSE(cad, w->nid,
1306 HDA_CMD_SET_UNSOLICITED_RESPONSE_ENABLE |
1307 HDAC_UNSOLTAG_EVENT_HP), cad);
1311 device_printf(sc->dev,
1312 "Enabling headphone/speaker "
1313 "audio routing switching:\n");
1314 device_printf(sc->dev, "\tas=%d sense nid=%d [%s]\n",
1315 i, w->nid, (poll != 0) ? "POLL" : "UNSOL");
1319 hdac_hp_switch_handler(devinfo);
1321 callout_reset(&sc->poll_jack, 1,
1322 hdac_jack_poll_callback, devinfo);
1328 * Unsolicited messages handler.
1331 hdac_unsolicited_handler(struct hdac_codec *codec, uint32_t tag)
1333 struct hdac_softc *sc;
1334 struct hdac_devinfo *devinfo = NULL;
1337 if (codec == NULL || codec->sc == NULL)
1343 device_printf(sc->dev, "Unsol Tag: 0x%08x\n", tag);
1346 for (i = 0; i < codec->num_fgs; i++) {
1347 if (codec->fgs[i].node_type ==
1348 HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO) {
1349 devinfo = &codec->fgs[i];
1354 if (devinfo == NULL)
1358 case HDAC_UNSOLTAG_EVENT_HP:
1359 hdac_hp_switch_handler(devinfo);
1362 device_printf(sc->dev, "Unknown unsol tag: 0x%08x!\n", tag);
1368 hdac_stream_intr(struct hdac_softc *sc, struct hdac_chan *ch)
1370 /* XXX to be removed */
1371 #ifdef HDAC_INTR_EXTRA
1375 if (!(ch->flags & HDAC_CHN_RUNNING))
1378 /* XXX to be removed */
1379 #ifdef HDAC_INTR_EXTRA
1380 res = HDAC_READ_1(&sc->mem, ch->off + HDAC_SDSTS);
1383 /* XXX to be removed */
1384 #ifdef HDAC_INTR_EXTRA
1386 if (res & (HDAC_SDSTS_DESE | HDAC_SDSTS_FIFOE))
1387 device_printf(ch->pdevinfo->dev,
1388 "PCMDIR_%s intr triggered beyond stream boundary:"
1390 (ch->dir == PCMDIR_PLAY) ? "PLAY" : "REC", res);
1394 HDAC_WRITE_1(&sc->mem, ch->off + HDAC_SDSTS,
1395 HDAC_SDSTS_DESE | HDAC_SDSTS_FIFOE | HDAC_SDSTS_BCIS );
1397 /* XXX to be removed */
1398 #ifdef HDAC_INTR_EXTRA
1399 if (res & HDAC_SDSTS_BCIS) {
1402 /* XXX to be removed */
1403 #ifdef HDAC_INTR_EXTRA
1410 /****************************************************************************
1411 * void hdac_intr_handler(void *)
1413 * Interrupt handler. Processes interrupts received from the hdac.
1414 ****************************************************************************/
1416 hdac_intr_handler(void *context)
1418 struct hdac_softc *sc;
1421 struct hdac_rirb *rirb_base;
1425 sc = (struct hdac_softc *)context;
1428 if (sc->polling != 0) {
1433 /* Do we have anything to do? */
1434 intsts = HDAC_READ_4(&sc->mem, HDAC_INTSTS);
1435 if (!HDA_FLAG_MATCH(intsts, HDAC_INTSTS_GIS)) {
1442 /* Was this a controller interrupt? */
1443 if (HDA_FLAG_MATCH(intsts, HDAC_INTSTS_CIS)) {
1444 rirb_base = (struct hdac_rirb *)sc->rirb_dma.dma_vaddr;
1445 rirbsts = HDAC_READ_1(&sc->mem, HDAC_RIRBSTS);
1446 /* Get as many responses that we can */
1447 while (HDA_FLAG_MATCH(rirbsts, HDAC_RIRBSTS_RINTFL)) {
1448 HDAC_WRITE_1(&sc->mem,
1449 HDAC_RIRBSTS, HDAC_RIRBSTS_RINTFL);
1450 if (hdac_rirb_flush(sc) != 0)
1451 trigger |= HDAC_TRIGGER_UNSOL;
1452 rirbsts = HDAC_READ_1(&sc->mem, HDAC_RIRBSTS);
1454 /* XXX to be removed */
1455 /* Clear interrupt and exit */
1456 #ifdef HDAC_INTR_EXTRA
1457 HDAC_WRITE_4(&sc->mem, HDAC_INTSTS, HDAC_INTSTS_CIS);
1461 if (intsts & HDAC_INTSTS_SIS_MASK) {
1462 for (i = 0; i < sc->num_chans; i++) {
1463 if ((intsts & (1 << (sc->chans[i].off >> 5))) &&
1464 hdac_stream_intr(sc, &sc->chans[i]) != 0)
1465 trigger |= (1 << i);
1467 /* XXX to be removed */
1468 #ifdef HDAC_INTR_EXTRA
1469 HDAC_WRITE_4(&sc->mem, HDAC_INTSTS, intsts &
1470 HDAC_INTSTS_SIS_MASK);
1476 for (i = 0; i < sc->num_chans; i++) {
1477 if (trigger & (1 << i))
1478 chn_intr(sc->chans[i].c);
1480 if (trigger & HDAC_TRIGGER_UNSOL)
1481 taskqueue_enqueue(taskqueue_thread, &sc->unsolq_task);
1484 /****************************************************************************
1485 * int hdac_reset(hdac_softc *, int)
1487 * Reset the hdac to a quiescent and known state.
1488 ****************************************************************************/
1490 hdac_reset(struct hdac_softc *sc, int wakeup)
1496 * Stop all Streams DMA engine
1498 for (i = 0; i < sc->num_iss; i++)
1499 HDAC_WRITE_4(&sc->mem, HDAC_ISDCTL(sc, i), 0x0);
1500 for (i = 0; i < sc->num_oss; i++)
1501 HDAC_WRITE_4(&sc->mem, HDAC_OSDCTL(sc, i), 0x0);
1502 for (i = 0; i < sc->num_bss; i++)
1503 HDAC_WRITE_4(&sc->mem, HDAC_BSDCTL(sc, i), 0x0);
1506 * Stop Control DMA engines.
1508 HDAC_WRITE_1(&sc->mem, HDAC_CORBCTL, 0x0);
1509 HDAC_WRITE_1(&sc->mem, HDAC_RIRBCTL, 0x0);
1512 * Reset DMA position buffer.
1514 HDAC_WRITE_4(&sc->mem, HDAC_DPIBLBASE, 0x0);
1515 HDAC_WRITE_4(&sc->mem, HDAC_DPIBUBASE, 0x0);
1518 * Reset the controller. The reset must remain asserted for
1519 * a minimum of 100us.
1521 gctl = HDAC_READ_4(&sc->mem, HDAC_GCTL);
1522 HDAC_WRITE_4(&sc->mem, HDAC_GCTL, gctl & ~HDAC_GCTL_CRST);
1525 gctl = HDAC_READ_4(&sc->mem, HDAC_GCTL);
1526 if (!(gctl & HDAC_GCTL_CRST))
1530 if (gctl & HDAC_GCTL_CRST) {
1531 device_printf(sc->dev, "Unable to put hdac in reset\n");
1535 /* If wakeup is not requested - leave the controller in reset state. */
1540 gctl = HDAC_READ_4(&sc->mem, HDAC_GCTL);
1541 HDAC_WRITE_4(&sc->mem, HDAC_GCTL, gctl | HDAC_GCTL_CRST);
1544 gctl = HDAC_READ_4(&sc->mem, HDAC_GCTL);
1545 if (gctl & HDAC_GCTL_CRST)
1549 if (!(gctl & HDAC_GCTL_CRST)) {
1550 device_printf(sc->dev, "Device stuck in reset\n");
1555 * Wait for codecs to finish their own reset sequence. The delay here
1556 * should be of 250us but for some reasons, on it's not enough on my
1557 * computer. Let's use twice as much as necessary to make sure that
1558 * it's reset properly.
1566 /****************************************************************************
1567 * int hdac_get_capabilities(struct hdac_softc *);
1569 * Retreive the general capabilities of the hdac;
1570 * Number of Input Streams
1571 * Number of Output Streams
1572 * Number of bidirectional Streams
1574 * CORB and RIRB sizes
1575 ****************************************************************************/
1577 hdac_get_capabilities(struct hdac_softc *sc)
1580 uint8_t corbsize, rirbsize;
1582 gcap = HDAC_READ_2(&sc->mem, HDAC_GCAP);
1583 sc->num_iss = HDAC_GCAP_ISS(gcap);
1584 sc->num_oss = HDAC_GCAP_OSS(gcap);
1585 sc->num_bss = HDAC_GCAP_BSS(gcap);
1586 sc->num_sdo = HDAC_GCAP_NSDO(gcap);
1587 sc->support_64bit = HDA_FLAG_MATCH(gcap, HDAC_GCAP_64OK);
1589 corbsize = HDAC_READ_1(&sc->mem, HDAC_CORBSIZE);
1590 if ((corbsize & HDAC_CORBSIZE_CORBSZCAP_256) ==
1591 HDAC_CORBSIZE_CORBSZCAP_256)
1592 sc->corb_size = 256;
1593 else if ((corbsize & HDAC_CORBSIZE_CORBSZCAP_16) ==
1594 HDAC_CORBSIZE_CORBSZCAP_16)
1596 else if ((corbsize & HDAC_CORBSIZE_CORBSZCAP_2) ==
1597 HDAC_CORBSIZE_CORBSZCAP_2)
1600 device_printf(sc->dev, "%s: Invalid corb size (%x)\n",
1601 __func__, corbsize);
1605 rirbsize = HDAC_READ_1(&sc->mem, HDAC_RIRBSIZE);
1606 if ((rirbsize & HDAC_RIRBSIZE_RIRBSZCAP_256) ==
1607 HDAC_RIRBSIZE_RIRBSZCAP_256)
1608 sc->rirb_size = 256;
1609 else if ((rirbsize & HDAC_RIRBSIZE_RIRBSZCAP_16) ==
1610 HDAC_RIRBSIZE_RIRBSZCAP_16)
1612 else if ((rirbsize & HDAC_RIRBSIZE_RIRBSZCAP_2) ==
1613 HDAC_RIRBSIZE_RIRBSZCAP_2)
1616 device_printf(sc->dev, "%s: Invalid rirb size (%x)\n",
1617 __func__, rirbsize);
1622 device_printf(sc->dev, "Caps: OSS %d, ISS %d, BSS %d, "
1623 "NSDO %d%s, CORB %d, RIRB %d\n",
1624 sc->num_oss, sc->num_iss, sc->num_bss, 1 << sc->num_sdo,
1625 sc->support_64bit ? ", 64bit" : "",
1626 sc->corb_size, sc->rirb_size);
1633 /****************************************************************************
1636 * This function is called by bus_dmamap_load when the mapping has been
1637 * established. We just record the physical address of the mapping into
1638 * the struct hdac_dma passed in.
1639 ****************************************************************************/
1641 hdac_dma_cb(void *callback_arg, bus_dma_segment_t *segs, int nseg, int error)
1643 struct hdac_dma *dma;
1646 dma = (struct hdac_dma *)callback_arg;
1647 dma->dma_paddr = segs[0].ds_addr;
1652 /****************************************************************************
1653 * int hdac_dma_alloc
1655 * This function allocate and setup a dma region (struct hdac_dma).
1656 * It must be freed by a corresponding hdac_dma_free.
1657 ****************************************************************************/
1659 hdac_dma_alloc(struct hdac_softc *sc, struct hdac_dma *dma, bus_size_t size)
1664 roundsz = roundup2(size, HDAC_DMA_ALIGNMENT);
1665 bzero(dma, sizeof(*dma));
1670 result = bus_dma_tag_create(
1671 bus_get_dma_tag(sc->dev), /* parent */
1672 HDAC_DMA_ALIGNMENT, /* alignment */
1674 (sc->support_64bit) ? BUS_SPACE_MAXADDR :
1675 BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
1676 BUS_SPACE_MAXADDR, /* highaddr */
1677 NULL, /* filtfunc */
1678 NULL, /* fistfuncarg */
1679 roundsz, /* maxsize */
1681 roundsz, /* maxsegsz */
1683 NULL, /* lockfunc */
1684 NULL, /* lockfuncarg */
1685 &dma->dma_tag); /* dmat */
1687 device_printf(sc->dev, "%s: bus_dma_tag_create failed (%x)\n",
1689 goto hdac_dma_alloc_fail;
1693 * Allocate DMA memory
1695 result = bus_dmamem_alloc(dma->dma_tag, (void **)&dma->dma_vaddr,
1696 BUS_DMA_NOWAIT | BUS_DMA_ZERO |
1697 ((sc->flags & HDAC_F_DMA_NOCACHE) ? BUS_DMA_NOCACHE : 0),
1700 device_printf(sc->dev, "%s: bus_dmamem_alloc failed (%x)\n",
1702 goto hdac_dma_alloc_fail;
1705 dma->dma_size = roundsz;
1710 result = bus_dmamap_load(dma->dma_tag, dma->dma_map,
1711 (void *)dma->dma_vaddr, roundsz, hdac_dma_cb, (void *)dma, 0);
1712 if (result != 0 || dma->dma_paddr == 0) {
1715 device_printf(sc->dev, "%s: bus_dmamem_load failed (%x)\n",
1717 goto hdac_dma_alloc_fail;
1721 device_printf(sc->dev, "%s: size=%ju -> roundsz=%ju\n",
1722 __func__, (uintmax_t)size, (uintmax_t)roundsz);
1727 hdac_dma_alloc_fail:
1728 hdac_dma_free(sc, dma);
1734 /****************************************************************************
1735 * void hdac_dma_free(struct hdac_softc *, struct hdac_dma *)
1737 * Free a struct dhac_dma that has been previously allocated via the
1738 * hdac_dma_alloc function.
1739 ****************************************************************************/
1741 hdac_dma_free(struct hdac_softc *sc, struct hdac_dma *dma)
1743 if (dma->dma_map != NULL) {
1746 bus_dmamap_sync(dma->dma_tag, dma->dma_map,
1747 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
1749 bus_dmamap_unload(dma->dma_tag, dma->dma_map);
1751 if (dma->dma_vaddr != NULL) {
1752 bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
1753 dma->dma_vaddr = NULL;
1755 dma->dma_map = NULL;
1756 if (dma->dma_tag != NULL) {
1757 bus_dma_tag_destroy(dma->dma_tag);
1758 dma->dma_tag = NULL;
1763 /****************************************************************************
1764 * int hdac_mem_alloc(struct hdac_softc *)
1766 * Allocate all the bus resources necessary to speak with the physical
1768 ****************************************************************************/
1770 hdac_mem_alloc(struct hdac_softc *sc)
1772 struct hdac_mem *mem;
1775 mem->mem_rid = PCIR_BAR(0);
1776 mem->mem_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY,
1777 &mem->mem_rid, RF_ACTIVE);
1778 if (mem->mem_res == NULL) {
1779 device_printf(sc->dev,
1780 "%s: Unable to allocate memory resource\n", __func__);
1783 mem->mem_tag = rman_get_bustag(mem->mem_res);
1784 mem->mem_handle = rman_get_bushandle(mem->mem_res);
1789 /****************************************************************************
1790 * void hdac_mem_free(struct hdac_softc *)
1792 * Free up resources previously allocated by hdac_mem_alloc.
1793 ****************************************************************************/
1795 hdac_mem_free(struct hdac_softc *sc)
1797 struct hdac_mem *mem;
1800 if (mem->mem_res != NULL)
1801 bus_release_resource(sc->dev, SYS_RES_MEMORY, mem->mem_rid,
1803 mem->mem_res = NULL;
1806 /****************************************************************************
1807 * int hdac_irq_alloc(struct hdac_softc *)
1809 * Allocate and setup the resources necessary for interrupt handling.
1810 ****************************************************************************/
1812 hdac_irq_alloc(struct hdac_softc *sc)
1814 struct hdac_irq *irq;
1820 if ((sc->flags & HDAC_F_MSI) &&
1821 (result = pci_msi_count(sc->dev)) == 1 &&
1822 pci_alloc_msi(sc->dev, &result) == 0)
1825 sc->flags &= ~HDAC_F_MSI;
1827 irq->irq_res = bus_alloc_resource_any(sc->dev, SYS_RES_IRQ,
1828 &irq->irq_rid, RF_SHAREABLE | RF_ACTIVE);
1829 if (irq->irq_res == NULL) {
1830 device_printf(sc->dev, "%s: Unable to allocate irq\n",
1832 goto hdac_irq_alloc_fail;
1834 result = bus_setup_intr(sc->dev, irq->irq_res, INTR_MPSAFE | INTR_TYPE_AV,
1835 NULL, hdac_intr_handler, sc, &irq->irq_handle);
1837 device_printf(sc->dev,
1838 "%s: Unable to setup interrupt handler (%x)\n",
1840 goto hdac_irq_alloc_fail;
1845 hdac_irq_alloc_fail:
1851 /****************************************************************************
1852 * void hdac_irq_free(struct hdac_softc *)
1854 * Free up resources previously allocated by hdac_irq_alloc.
1855 ****************************************************************************/
1857 hdac_irq_free(struct hdac_softc *sc)
1859 struct hdac_irq *irq;
1862 if (irq->irq_res != NULL && irq->irq_handle != NULL)
1863 bus_teardown_intr(sc->dev, irq->irq_res, irq->irq_handle);
1864 if (irq->irq_res != NULL)
1865 bus_release_resource(sc->dev, SYS_RES_IRQ, irq->irq_rid,
1867 if (irq->irq_rid == 0x1)
1868 pci_release_msi(sc->dev);
1869 irq->irq_handle = NULL;
1870 irq->irq_res = NULL;
1874 /****************************************************************************
1875 * void hdac_corb_init(struct hdac_softc *)
1877 * Initialize the corb registers for operations but do not start it up yet.
1878 * The CORB engine must not be running when this function is called.
1879 ****************************************************************************/
1881 hdac_corb_init(struct hdac_softc *sc)
1886 /* Setup the CORB size. */
1887 switch (sc->corb_size) {
1889 corbsize = HDAC_CORBSIZE_CORBSIZE(HDAC_CORBSIZE_CORBSIZE_256);
1892 corbsize = HDAC_CORBSIZE_CORBSIZE(HDAC_CORBSIZE_CORBSIZE_16);
1895 corbsize = HDAC_CORBSIZE_CORBSIZE(HDAC_CORBSIZE_CORBSIZE_2);
1898 panic("%s: Invalid CORB size (%x)\n", __func__, sc->corb_size);
1900 HDAC_WRITE_1(&sc->mem, HDAC_CORBSIZE, corbsize);
1902 /* Setup the CORB Address in the hdac */
1903 corbpaddr = (uint64_t)sc->corb_dma.dma_paddr;
1904 HDAC_WRITE_4(&sc->mem, HDAC_CORBLBASE, (uint32_t)corbpaddr);
1905 HDAC_WRITE_4(&sc->mem, HDAC_CORBUBASE, (uint32_t)(corbpaddr >> 32));
1907 /* Set the WP and RP */
1909 HDAC_WRITE_2(&sc->mem, HDAC_CORBWP, sc->corb_wp);
1910 HDAC_WRITE_2(&sc->mem, HDAC_CORBRP, HDAC_CORBRP_CORBRPRST);
1912 * The HDA specification indicates that the CORBRPRST bit will always
1913 * read as zero. Unfortunately, it seems that at least the 82801G
1914 * doesn't reset the bit to zero, which stalls the corb engine.
1915 * manually reset the bit to zero before continuing.
1917 HDAC_WRITE_2(&sc->mem, HDAC_CORBRP, 0x0);
1919 /* Enable CORB error reporting */
1921 HDAC_WRITE_1(&sc->mem, HDAC_CORBCTL, HDAC_CORBCTL_CMEIE);
1925 /****************************************************************************
1926 * void hdac_rirb_init(struct hdac_softc *)
1928 * Initialize the rirb registers for operations but do not start it up yet.
1929 * The RIRB engine must not be running when this function is called.
1930 ****************************************************************************/
1932 hdac_rirb_init(struct hdac_softc *sc)
1937 /* Setup the RIRB size. */
1938 switch (sc->rirb_size) {
1940 rirbsize = HDAC_RIRBSIZE_RIRBSIZE(HDAC_RIRBSIZE_RIRBSIZE_256);
1943 rirbsize = HDAC_RIRBSIZE_RIRBSIZE(HDAC_RIRBSIZE_RIRBSIZE_16);
1946 rirbsize = HDAC_RIRBSIZE_RIRBSIZE(HDAC_RIRBSIZE_RIRBSIZE_2);
1949 panic("%s: Invalid RIRB size (%x)\n", __func__, sc->rirb_size);
1951 HDAC_WRITE_1(&sc->mem, HDAC_RIRBSIZE, rirbsize);
1953 /* Setup the RIRB Address in the hdac */
1954 rirbpaddr = (uint64_t)sc->rirb_dma.dma_paddr;
1955 HDAC_WRITE_4(&sc->mem, HDAC_RIRBLBASE, (uint32_t)rirbpaddr);
1956 HDAC_WRITE_4(&sc->mem, HDAC_RIRBUBASE, (uint32_t)(rirbpaddr >> 32));
1958 /* Setup the WP and RP */
1960 HDAC_WRITE_2(&sc->mem, HDAC_RIRBWP, HDAC_RIRBWP_RIRBWPRST);
1962 /* Setup the interrupt threshold */
1963 HDAC_WRITE_2(&sc->mem, HDAC_RINTCNT, sc->rirb_size / 2);
1965 /* Enable Overrun and response received reporting */
1967 HDAC_WRITE_1(&sc->mem, HDAC_RIRBCTL,
1968 HDAC_RIRBCTL_RIRBOIC | HDAC_RIRBCTL_RINTCTL);
1970 HDAC_WRITE_1(&sc->mem, HDAC_RIRBCTL, HDAC_RIRBCTL_RINTCTL);
1975 * Make sure that the Host CPU cache doesn't contain any dirty
1976 * cache lines that falls in the rirb. If I understood correctly, it
1977 * should be sufficient to do this only once as the rirb is purely
1978 * read-only from now on.
1980 bus_dmamap_sync(sc->rirb_dma.dma_tag, sc->rirb_dma.dma_map,
1981 BUS_DMASYNC_PREREAD);
1985 /****************************************************************************
1986 * void hdac_corb_start(hdac_softc *)
1988 * Startup the corb DMA engine
1989 ****************************************************************************/
1991 hdac_corb_start(struct hdac_softc *sc)
1995 corbctl = HDAC_READ_1(&sc->mem, HDAC_CORBCTL);
1996 corbctl |= HDAC_CORBCTL_CORBRUN;
1997 HDAC_WRITE_1(&sc->mem, HDAC_CORBCTL, corbctl);
2000 /****************************************************************************
2001 * void hdac_rirb_start(hdac_softc *)
2003 * Startup the rirb DMA engine
2004 ****************************************************************************/
2006 hdac_rirb_start(struct hdac_softc *sc)
2010 rirbctl = HDAC_READ_1(&sc->mem, HDAC_RIRBCTL);
2011 rirbctl |= HDAC_RIRBCTL_RIRBDMAEN;
2012 HDAC_WRITE_1(&sc->mem, HDAC_RIRBCTL, rirbctl);
2016 /****************************************************************************
2017 * void hdac_scan_codecs(struct hdac_softc *, int)
2019 * Scan the bus for available codecs, starting with num.
2020 ****************************************************************************/
2022 hdac_scan_codecs(struct hdac_softc *sc)
2024 struct hdac_codec *codec;
2028 statests = HDAC_READ_2(&sc->mem, HDAC_STATESTS);
2029 for (i = 0; i < HDAC_CODEC_MAX; i++) {
2030 if (HDAC_STATESTS_SDIWAKE(statests, i)) {
2031 /* We have found a codec. */
2032 codec = (struct hdac_codec *)malloc(sizeof(*codec),
2033 M_HDAC, M_ZERO | M_NOWAIT);
2034 if (codec == NULL) {
2035 device_printf(sc->dev,
2036 "Unable to allocate memory for codec\n");
2039 codec->commands = NULL;
2040 codec->responses_received = 0;
2041 codec->verbs_sent = 0;
2044 sc->codecs[i] = codec;
2045 hdac_probe_codec(codec);
2048 /* All codecs have been probed, now try to attach drivers to them */
2049 /* bus_generic_attach(sc->dev); */
2052 /****************************************************************************
2053 * void hdac_probe_codec(struct hdac_softc *, int)
2055 * Probe a the given codec_id for available function groups.
2056 ****************************************************************************/
2058 hdac_probe_codec(struct hdac_codec *codec)
2060 struct hdac_softc *sc = codec->sc;
2061 uint32_t vendorid, revisionid, subnode;
2065 nid_t cad = codec->cad;
2068 device_printf(sc->dev, "Probing codec #%d...\n", cad);
2070 vendorid = hdac_command(sc,
2071 HDA_CMD_GET_PARAMETER(cad, 0x0, HDA_PARAM_VENDOR_ID),
2073 revisionid = hdac_command(sc,
2074 HDA_CMD_GET_PARAMETER(cad, 0x0, HDA_PARAM_REVISION_ID),
2076 codec->vendor_id = HDA_PARAM_VENDOR_ID_VENDOR_ID(vendorid);
2077 codec->device_id = HDA_PARAM_VENDOR_ID_DEVICE_ID(vendorid);
2078 codec->revision_id = HDA_PARAM_REVISION_ID_REVISION_ID(revisionid);
2079 codec->stepping_id = HDA_PARAM_REVISION_ID_STEPPING_ID(revisionid);
2081 if (vendorid == HDAC_INVALID && revisionid == HDAC_INVALID) {
2082 device_printf(sc->dev, "Codec #%d is not responding!"
2083 " Probing aborted.\n", cad);
2087 device_printf(sc->dev, "HDA Codec #%d: %s\n",
2088 cad, hdac_codec_name(codec));
2090 device_printf(sc->dev, " HDA Codec ID: 0x%08x\n",
2091 hdac_codec_id(codec));
2092 device_printf(sc->dev, " Vendor: 0x%04x\n",
2094 device_printf(sc->dev, " Device: 0x%04x\n",
2096 device_printf(sc->dev, " Revision: 0x%02x\n",
2097 codec->revision_id);
2098 device_printf(sc->dev, " Stepping: 0x%02x\n",
2099 codec->stepping_id);
2100 device_printf(sc->dev, "PCI Subvendor: 0x%08x\n",
2103 subnode = hdac_command(sc,
2104 HDA_CMD_GET_PARAMETER(cad, 0x0, HDA_PARAM_SUB_NODE_COUNT),
2106 startnode = HDA_PARAM_SUB_NODE_COUNT_START(subnode);
2107 endnode = startnode + HDA_PARAM_SUB_NODE_COUNT_TOTAL(subnode);
2110 device_printf(sc->dev, "\tstartnode=%d endnode=%d\n",
2111 startnode, endnode);
2114 codec->fgs = (struct hdac_devinfo *)malloc(sizeof(struct hdac_devinfo) *
2115 (endnode - startnode), M_HDAC, M_NOWAIT | M_ZERO);
2116 if (codec->fgs == NULL) {
2117 device_printf(sc->dev, "%s: Unable to allocate function groups\n",
2122 for (i = startnode; i < endnode; i++)
2123 hdac_probe_function(codec, i);
2128 * Probe codec function and add it to the list.
2131 hdac_probe_function(struct hdac_codec *codec, nid_t nid)
2133 struct hdac_softc *sc = codec->sc;
2134 struct hdac_devinfo *devinfo = &codec->fgs[codec->num_fgs];
2135 uint32_t fctgrptype;
2137 nid_t cad = codec->cad;
2139 fctgrptype = HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE(hdac_command(sc,
2140 HDA_CMD_GET_PARAMETER(cad, nid, HDA_PARAM_FCT_GRP_TYPE), cad));
2143 devinfo->node_type = fctgrptype;
2144 devinfo->codec = codec;
2146 res = hdac_command(sc,
2147 HDA_CMD_GET_PARAMETER(cad , nid, HDA_PARAM_SUB_NODE_COUNT), cad);
2149 devinfo->nodecnt = HDA_PARAM_SUB_NODE_COUNT_TOTAL(res);
2150 devinfo->startnode = HDA_PARAM_SUB_NODE_COUNT_START(res);
2151 devinfo->endnode = devinfo->startnode + devinfo->nodecnt;
2154 device_printf(sc->dev,
2155 "\tFound %s FG nid=%d startnode=%d endnode=%d total=%d\n",
2156 (fctgrptype == HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO) ? "audio":
2157 (fctgrptype == HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_MODEM) ? "modem":
2158 "unknown", nid, devinfo->startnode, devinfo->endnode,
2162 if (devinfo->nodecnt > 0)
2163 devinfo->widget = (struct hdac_widget *)malloc(
2164 sizeof(*(devinfo->widget)) * devinfo->nodecnt, M_HDAC,
2167 devinfo->widget = NULL;
2169 if (devinfo->widget == NULL) {
2170 device_printf(sc->dev, "unable to allocate widgets!\n");
2171 devinfo->endnode = devinfo->startnode;
2172 devinfo->nodecnt = 0;
2180 hdac_widget_connection_parse(struct hdac_widget *w)
2182 struct hdac_softc *sc = w->devinfo->codec->sc;
2184 int i, j, max, ents, entnum;
2185 nid_t cad = w->devinfo->codec->cad;
2187 nid_t cnid, addcnid, prevcnid;
2191 res = hdac_command(sc,
2192 HDA_CMD_GET_PARAMETER(cad, nid, HDA_PARAM_CONN_LIST_LENGTH), cad);
2194 ents = HDA_PARAM_CONN_LIST_LENGTH_LIST_LENGTH(res);
2199 entnum = HDA_PARAM_CONN_LIST_LENGTH_LONG_FORM(res) ? 2 : 4;
2200 max = (sizeof(w->conns) / sizeof(w->conns[0])) - 1;
2203 #define CONN_RMASK(e) (1 << ((32 / (e)) - 1))
2204 #define CONN_NMASK(e) (CONN_RMASK(e) - 1)
2205 #define CONN_RESVAL(r, e, n) ((r) >> ((32 / (e)) * (n)))
2206 #define CONN_RANGE(r, e, n) (CONN_RESVAL(r, e, n) & CONN_RMASK(e))
2207 #define CONN_CNID(r, e, n) (CONN_RESVAL(r, e, n) & CONN_NMASK(e))
2209 for (i = 0; i < ents; i += entnum) {
2210 res = hdac_command(sc,
2211 HDA_CMD_GET_CONN_LIST_ENTRY(cad, nid, i), cad);
2212 for (j = 0; j < entnum; j++) {
2213 cnid = CONN_CNID(res, entnum, j);
2215 if (w->nconns < ents)
2216 device_printf(sc->dev,
2217 "%s: nid=%d WARNING: zero cnid "
2218 "entnum=%d j=%d index=%d "
2219 "entries=%d found=%d res=0x%08x\n",
2220 __func__, nid, entnum, j, i,
2221 ents, w->nconns, res);
2225 if (cnid < w->devinfo->startnode ||
2226 cnid >= w->devinfo->endnode) {
2228 device_printf(sc->dev,
2229 "GHOST: nid=%d j=%d "
2230 "entnum=%d index=%d res=0x%08x\n",
2231 nid, j, entnum, i, res);
2234 if (CONN_RANGE(res, entnum, j) == 0)
2236 else if (prevcnid == 0 || prevcnid >= cnid) {
2237 device_printf(sc->dev,
2238 "%s: WARNING: Invalid child range "
2239 "nid=%d index=%d j=%d entnum=%d "
2240 "prevcnid=%d cnid=%d res=0x%08x\n",
2241 __func__, nid, i, j, entnum, prevcnid,
2245 addcnid = prevcnid + 1;
2246 while (addcnid <= cnid) {
2247 if (w->nconns > max) {
2248 device_printf(sc->dev,
2249 "Adding %d (nid=%d): "
2250 "Max connection reached! max=%d\n",
2251 addcnid, nid, max + 1);
2254 w->connsenable[w->nconns] = 1;
2255 w->conns[w->nconns++] = addcnid++;
2266 hdac_widget_pin_patch(uint32_t config, const char *str)
2269 char *key, *value, *rest, *bad;
2272 strlcpy(buf, str, sizeof(buf));
2274 while ((key = strsep(&rest, "=")) != NULL) {
2275 value = strsep(&rest, " \t");
2278 ival = strtol(value, &bad, 10);
2279 if (strcmp(key, "seq") == 0) {
2280 config &= ~HDA_CONFIG_DEFAULTCONF_SEQUENCE_MASK;
2281 config |= ((ival << HDA_CONFIG_DEFAULTCONF_SEQUENCE_SHIFT) &
2282 HDA_CONFIG_DEFAULTCONF_SEQUENCE_MASK);
2283 } else if (strcmp(key, "as") == 0) {
2284 config &= ~HDA_CONFIG_DEFAULTCONF_ASSOCIATION_MASK;
2285 config |= ((ival << HDA_CONFIG_DEFAULTCONF_ASSOCIATION_SHIFT) &
2286 HDA_CONFIG_DEFAULTCONF_ASSOCIATION_MASK);
2287 } else if (strcmp(key, "misc") == 0) {
2288 config &= ~HDA_CONFIG_DEFAULTCONF_MISC_MASK;
2289 config |= ((ival << HDA_CONFIG_DEFAULTCONF_MISC_SHIFT) &
2290 HDA_CONFIG_DEFAULTCONF_MISC_MASK);
2291 } else if (strcmp(key, "color") == 0) {
2292 config &= ~HDA_CONFIG_DEFAULTCONF_COLOR_MASK;
2294 config |= ((ival << HDA_CONFIG_DEFAULTCONF_COLOR_SHIFT) &
2295 HDA_CONFIG_DEFAULTCONF_COLOR_MASK);
2297 for (i = 0; i < 16; i++) {
2298 if (strcasecmp(HDA_COLORS[i], value) == 0) {
2299 config |= (i << HDA_CONFIG_DEFAULTCONF_COLOR_SHIFT);
2303 } else if (strcmp(key, "ctype") == 0) {
2304 config &= ~HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_MASK;
2305 config |= ((ival << HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_SHIFT) &
2306 HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE_MASK);
2307 } else if (strcmp(key, "device") == 0) {
2308 config &= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
2310 config |= ((ival << HDA_CONFIG_DEFAULTCONF_DEVICE_SHIFT) &
2311 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK);
2314 for (i = 0; i < 16; i++) {
2315 if (strcasecmp(HDA_DEVS[i], value) == 0) {
2316 config |= (i << HDA_CONFIG_DEFAULTCONF_DEVICE_SHIFT);
2320 } else if (strcmp(key, "loc") == 0) {
2321 config &= ~HDA_CONFIG_DEFAULTCONF_LOCATION_MASK;
2322 config |= ((ival << HDA_CONFIG_DEFAULTCONF_LOCATION_SHIFT) &
2323 HDA_CONFIG_DEFAULTCONF_LOCATION_MASK);
2324 } else if (strcmp(key, "conn") == 0) {
2325 config &= ~HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK;
2327 config |= ((ival << HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_SHIFT) &
2328 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK);
2331 for (i = 0; i < 4; i++) {
2332 if (strcasecmp(HDA_CONNS[i], value) == 0) {
2333 config |= (i << HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_SHIFT);
2343 hdac_widget_pin_getconfig(struct hdac_widget *w)
2345 struct hdac_softc *sc;
2346 uint32_t config, orig, id;
2349 const char *res = NULL, *patch = NULL;
2351 sc = w->devinfo->codec->sc;
2352 cad = w->devinfo->codec->cad;
2354 id = hdac_codec_id(w->devinfo->codec);
2356 config = hdac_command(sc,
2357 HDA_CMD_GET_CONFIGURATION_DEFAULT(cad, nid),
2362 hdac_dump_pin_config(w, orig);
2365 /* XXX: Old patches require complete review.
2366 * Now they may create more problem then solve due to
2367 * incorrect associations.
2369 if (id == HDA_CODEC_ALC880 && sc->pci_subvendor == LG_LW20_SUBVENDOR) {
2372 config &= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
2373 config |= HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN;
2376 config &= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
2377 config |= HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT;
2382 } else if (id == HDA_CODEC_ALC880 &&
2383 (sc->pci_subvendor == CLEVO_D900T_SUBVENDOR ||
2384 sc->pci_subvendor == ASUS_M5200_SUBVENDOR)) {
2390 config &= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
2391 config |= HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN;
2393 case 25: /* XXX MIC2 */
2394 config &= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
2395 config |= HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN;
2397 case 26: /* LINE1 */
2398 config &= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
2399 config |= HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN;
2401 case 27: /* XXX LINE2 */
2402 config &= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
2403 config |= HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN;
2406 config &= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
2407 config |= HDA_CONFIG_DEFAULTCONF_DEVICE_CD;
2410 } else if (id == HDA_CODEC_ALC883 &&
2411 (sc->pci_subvendor == MSI_MS034A_SUBVENDOR ||
2412 HDA_DEV_MATCH(ACER_ALL_SUBVENDOR, sc->pci_subvendor))) {
2415 config &= ~(HDA_CONFIG_DEFAULTCONF_DEVICE_MASK |
2416 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK);
2417 config |= (HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN |
2418 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_FIXED);
2421 config &= ~(HDA_CONFIG_DEFAULTCONF_DEVICE_MASK |
2422 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK);
2423 config |= (HDA_CONFIG_DEFAULTCONF_DEVICE_CD |
2424 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_FIXED);
2427 } else if (id == HDA_CODEC_CX20549 && sc->pci_subvendor ==
2428 HP_V3000_SUBVENDOR) {
2431 config &= ~HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK;
2432 config |= HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_NONE;
2435 config &= ~(HDA_CONFIG_DEFAULTCONF_DEVICE_MASK |
2436 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK);
2437 config |= (HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN |
2438 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_FIXED);
2441 config &= ~(HDA_CONFIG_DEFAULTCONF_DEVICE_MASK |
2442 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK);
2443 config |= (HDA_CONFIG_DEFAULTCONF_DEVICE_CD |
2444 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_FIXED);
2447 } else if (id == HDA_CODEC_CX20551 && sc->pci_subvendor ==
2448 HP_DV5000_SUBVENDOR) {
2452 config &= ~HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK;
2453 config |= HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_NONE;
2456 } else if (id == HDA_CODEC_ALC861 && sc->pci_subvendor ==
2457 ASUS_W6F_SUBVENDOR) {
2460 config &= ~(HDA_CONFIG_DEFAULTCONF_DEVICE_MASK |
2461 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK);
2462 config |= (HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_OUT |
2463 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_FIXED);
2470 config &= ~(HDA_CONFIG_DEFAULTCONF_DEVICE_MASK |
2471 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK);
2472 config |= (HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN |
2473 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_FIXED);
2476 config &= ~(HDA_CONFIG_DEFAULTCONF_DEVICE_MASK |
2477 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK);
2478 config |= (HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT |
2479 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_JACK);
2482 } else if (id == HDA_CODEC_ALC861 && sc->pci_subvendor ==
2483 UNIWILL_9075_SUBVENDOR) {
2486 config &= ~(HDA_CONFIG_DEFAULTCONF_DEVICE_MASK |
2487 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK);
2488 config |= (HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT |
2489 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_JACK);
2495 if (id == HDA_CODEC_AD1986A &&
2496 (sc->pci_subvendor == ASUS_M2NPVMX_SUBVENDOR ||
2497 sc->pci_subvendor == ASUS_A8NVMCSM_SUBVENDOR ||
2498 sc->pci_subvendor == ASUS_P5PL2_SUBVENDOR)) {
2500 case 26: /* Headphones with redirection */
2501 patch = "as=1 seq=15";
2503 case 28: /* 5.1 out => 2.0 out + 1 input */
2504 patch = "device=Line-in as=8 seq=1";
2506 case 29: /* Can't use this as input, as the only available mic
2507 * preamplifier is busy by front panel mic (nid 31).
2508 * If you want to use this rear connector as mic input,
2509 * you have to disable the front panel one. */
2512 case 31: /* Lot of inputs configured with as=15 and unusable */
2513 patch = "as=8 seq=3";
2516 patch = "as=8 seq=4";
2519 patch = "as=8 seq=5";
2522 patch = "as=8 seq=6";
2525 } else if (id == HDA_CODEC_ALC260 &&
2526 HDA_DEV_MATCH(SONY_S5_SUBVENDOR, sc->pci_subvendor)) {
2529 patch = "seq=15 device=Headphones";
2532 } else if (id == HDA_CODEC_ALC268) {
2533 if (sc->pci_subvendor == ACER_T5320_SUBVENDOR) {
2535 case 20: /* Headphones Jack */
2536 patch = "as=1 seq=15";
2543 config = hdac_widget_pin_patch(config, patch);
2545 snprintf(buf, sizeof(buf), "cad%u.nid%u.config", cad, nid);
2546 if (resource_string_value(device_get_name(sc->dev),
2547 device_get_unit(sc->dev), buf, &res) == 0) {
2548 if (strncmp(res, "0x", 2) == 0) {
2549 config = strtol(res + 2, NULL, 16);
2551 config = hdac_widget_pin_patch(config, res);
2557 device_printf(sc->dev,
2558 "Patching pin config nid=%u 0x%08x -> 0x%08x\n",
2566 hdac_widget_pin_getcaps(struct hdac_widget *w)
2568 struct hdac_softc *sc;
2569 uint32_t caps, orig, id;
2572 sc = w->devinfo->codec->sc;
2573 cad = w->devinfo->codec->cad;
2575 id = hdac_codec_id(w->devinfo->codec);
2577 caps = hdac_command(sc,
2578 HDA_CMD_GET_PARAMETER(cad, nid, HDA_PARAM_PIN_CAP), cad);
2583 device_printf(sc->dev,
2584 "Patching pin caps nid=%u 0x%08x -> 0x%08x\n",
2592 hdac_widget_pin_parse(struct hdac_widget *w)
2594 struct hdac_softc *sc = w->devinfo->codec->sc;
2595 uint32_t config, pincap;
2597 nid_t cad = w->devinfo->codec->cad;
2601 config = hdac_widget_pin_getconfig(w);
2602 w->wclass.pin.config = config;
2604 pincap = hdac_widget_pin_getcaps(w);
2605 w->wclass.pin.cap = pincap;
2607 w->wclass.pin.ctrl = hdac_command(sc,
2608 HDA_CMD_GET_PIN_WIDGET_CTRL(cad, nid), cad);
2610 if (HDA_PARAM_PIN_CAP_EAPD_CAP(pincap)) {
2611 w->param.eapdbtl = hdac_command(sc,
2612 HDA_CMD_GET_EAPD_BTL_ENABLE(cad, nid), cad);
2613 w->param.eapdbtl &= 0x7;
2614 w->param.eapdbtl |= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
2616 w->param.eapdbtl = HDAC_INVALID;
2618 devstr = HDA_DEVS[(config & HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) >>
2619 HDA_CONFIG_DEFAULTCONF_DEVICE_SHIFT];
2621 conn = (config & HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK) >>
2622 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_SHIFT;
2623 color = (config & HDA_CONFIG_DEFAULTCONF_COLOR_MASK) >>
2624 HDA_CONFIG_DEFAULTCONF_COLOR_SHIFT;
2626 strlcat(w->name, ": ", sizeof(w->name));
2627 strlcat(w->name, devstr, sizeof(w->name));
2628 strlcat(w->name, " (", sizeof(w->name));
2629 if (conn == 0 && color != 0 && color != 15) {
2630 strlcat(w->name, HDA_COLORS[color], sizeof(w->name));
2631 strlcat(w->name, " ", sizeof(w->name));
2633 strlcat(w->name, HDA_CONNS[conn], sizeof(w->name));
2634 strlcat(w->name, ")", sizeof(w->name));
2638 hdac_widget_getcaps(struct hdac_widget *w, int *waspin)
2640 struct hdac_softc *sc;
2641 uint32_t caps, orig, id;
2642 nid_t cad, nid, beeper = -1;
2644 sc = w->devinfo->codec->sc;
2645 cad = w->devinfo->codec->cad;
2647 id = hdac_codec_id(w->devinfo->codec);
2649 caps = hdac_command(sc,
2650 HDA_CMD_GET_PARAMETER(cad, nid, HDA_PARAM_AUDIO_WIDGET_CAP),
2654 /* On some codecs beeper is an input pin, but it is not recordable
2655 alone. Also most of BIOSes does not declare beeper pin.
2656 Change beeper pin node type to beeper to help parser. */
2659 case HDA_CODEC_AD1882:
2660 case HDA_CODEC_AD1883:
2661 case HDA_CODEC_AD1984:
2662 case HDA_CODEC_AD1984A:
2663 case HDA_CODEC_AD1984B:
2664 case HDA_CODEC_AD1987:
2665 case HDA_CODEC_AD1988:
2666 case HDA_CODEC_AD1988B:
2667 case HDA_CODEC_AD1989B:
2670 case HDA_CODEC_ALC260:
2673 case HDA_CODEC_ALC262:
2674 case HDA_CODEC_ALC268:
2675 case HDA_CODEC_ALC880:
2676 case HDA_CODEC_ALC882:
2677 case HDA_CODEC_ALC883:
2678 case HDA_CODEC_ALC885:
2679 case HDA_CODEC_ALC888:
2680 case HDA_CODEC_ALC889:
2684 if (nid == beeper) {
2685 caps &= ~HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_MASK;
2686 caps |= HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET <<
2687 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_SHIFT;
2693 device_printf(sc->dev,
2694 "Patching widget caps nid=%u 0x%08x -> 0x%08x\n",
2703 hdac_widget_parse(struct hdac_widget *w)
2705 struct hdac_softc *sc = w->devinfo->codec->sc;
2708 nid_t cad = w->devinfo->codec->cad;
2711 wcap = hdac_widget_getcaps(w, &w->waspin);
2713 w->param.widget_cap = wcap;
2714 w->type = HDA_PARAM_AUDIO_WIDGET_CAP_TYPE(wcap);
2717 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT:
2718 typestr = "audio output";
2720 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT:
2721 typestr = "audio input";
2723 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER:
2724 typestr = "audio mixer";
2726 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR:
2727 typestr = "audio selector";
2729 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
2732 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_POWER_WIDGET:
2733 typestr = "power widget";
2735 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_VOLUME_WIDGET:
2736 typestr = "volume widget";
2738 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET:
2739 typestr = "beep widget";
2741 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_VENDOR_WIDGET:
2742 typestr = "vendor widget";
2745 typestr = "unknown type";
2749 strlcpy(w->name, typestr, sizeof(w->name));
2751 hdac_widget_connection_parse(w);
2753 if (HDA_PARAM_AUDIO_WIDGET_CAP_OUT_AMP(wcap)) {
2754 if (HDA_PARAM_AUDIO_WIDGET_CAP_AMP_OVR(wcap))
2755 w->param.outamp_cap =
2757 HDA_CMD_GET_PARAMETER(cad, nid,
2758 HDA_PARAM_OUTPUT_AMP_CAP), cad);
2760 w->param.outamp_cap =
2761 w->devinfo->function.audio.outamp_cap;
2763 w->param.outamp_cap = 0;
2765 if (HDA_PARAM_AUDIO_WIDGET_CAP_IN_AMP(wcap)) {
2766 if (HDA_PARAM_AUDIO_WIDGET_CAP_AMP_OVR(wcap))
2767 w->param.inamp_cap =
2769 HDA_CMD_GET_PARAMETER(cad, nid,
2770 HDA_PARAM_INPUT_AMP_CAP), cad);
2772 w->param.inamp_cap =
2773 w->devinfo->function.audio.inamp_cap;
2775 w->param.inamp_cap = 0;
2777 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT ||
2778 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
2779 if (HDA_PARAM_AUDIO_WIDGET_CAP_FORMAT_OVR(wcap)) {
2780 cap = hdac_command(sc,
2781 HDA_CMD_GET_PARAMETER(cad, nid,
2782 HDA_PARAM_SUPP_STREAM_FORMATS), cad);
2783 w->param.supp_stream_formats = (cap != 0) ? cap :
2784 w->devinfo->function.audio.supp_stream_formats;
2785 cap = hdac_command(sc,
2786 HDA_CMD_GET_PARAMETER(cad, nid,
2787 HDA_PARAM_SUPP_PCM_SIZE_RATE), cad);
2788 w->param.supp_pcm_size_rate = (cap != 0) ? cap :
2789 w->devinfo->function.audio.supp_pcm_size_rate;
2791 w->param.supp_stream_formats =
2792 w->devinfo->function.audio.supp_stream_formats;
2793 w->param.supp_pcm_size_rate =
2794 w->devinfo->function.audio.supp_pcm_size_rate;
2797 w->param.supp_stream_formats = 0;
2798 w->param.supp_pcm_size_rate = 0;
2801 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
2802 hdac_widget_pin_parse(w);
2805 static struct hdac_widget *
2806 hdac_widget_get(struct hdac_devinfo *devinfo, nid_t nid)
2808 if (devinfo == NULL || devinfo->widget == NULL ||
2809 nid < devinfo->startnode || nid >= devinfo->endnode)
2811 return (&devinfo->widget[nid - devinfo->startnode]);
2815 hda_poll_channel(struct hdac_chan *ch)
2818 volatile uint32_t ptr;
2820 if (!(ch->flags & HDAC_CHN_RUNNING))
2823 sz = ch->blksz * ch->blkcnt;
2824 if (ch->dmapos != NULL)
2825 ptr = *(ch->dmapos);
2827 ptr = HDAC_READ_4(&ch->devinfo->codec->sc->mem,
2828 ch->off + HDAC_SDLPIB);
2831 ptr &= ~(ch->blksz - 1);
2832 delta = (sz + ptr - ch->prevptr) % sz;
2834 if (delta < ch->blksz)
2843 hda_poll_callback(void *arg)
2845 struct hdac_softc *sc = arg;
2853 if (sc->polling == 0) {
2859 for (i = 0; i < sc->num_chans; i++) {
2860 if ((sc->chans[i].flags & HDAC_CHN_RUNNING) == 0)
2863 if (hda_poll_channel(&sc->chans[i]))
2864 trigger |= (1 << i);
2869 callout_reset(&sc->poll_hda, sc->poll_ticks,
2870 hda_poll_callback, sc);
2874 for (i = 0; i < sc->num_chans; i++) {
2875 if (trigger & (1 << i))
2876 chn_intr(sc->chans[i].c);
2881 hdac_rirb_flush(struct hdac_softc *sc)
2883 struct hdac_rirb *rirb_base, *rirb;
2884 struct hdac_codec *codec;
2885 struct hdac_command_list *commands;
2891 rirb_base = (struct hdac_rirb *)sc->rirb_dma.dma_vaddr;
2892 rirbwp = HDAC_READ_1(&sc->mem, HDAC_RIRBWP);
2894 bus_dmamap_sync(sc->rirb_dma.dma_tag, sc->rirb_dma.dma_map,
2895 BUS_DMASYNC_POSTREAD);
2900 while (sc->rirb_rp != rirbwp) {
2902 sc->rirb_rp %= sc->rirb_size;
2903 rirb = &rirb_base[sc->rirb_rp];
2904 cad = HDAC_RIRB_RESPONSE_EX_SDATA_IN(rirb->response_ex);
2905 if (cad < 0 || cad >= HDAC_CODEC_MAX ||
2906 sc->codecs[cad] == NULL)
2908 resp = rirb->response;
2909 codec = sc->codecs[cad];
2910 commands = codec->commands;
2911 if (rirb->response_ex & HDAC_RIRB_RESPONSE_EX_UNSOLICITED) {
2912 sc->unsolq[sc->unsolq_wp++] = (cad << 16) |
2913 ((resp >> 26) & 0xffff);
2914 sc->unsolq_wp %= HDAC_UNSOLQ_MAX;
2915 } else if (commands != NULL && commands->num_commands > 0 &&
2916 codec->responses_received < commands->num_commands)
2917 commands->responses[codec->responses_received++] =
2926 hdac_unsolq_flush(struct hdac_softc *sc)
2932 if (sc->unsolq_st == HDAC_UNSOLQ_READY) {
2933 sc->unsolq_st = HDAC_UNSOLQ_BUSY;
2934 while (sc->unsolq_rp != sc->unsolq_wp) {
2935 cad = sc->unsolq[sc->unsolq_rp] >> 16;
2936 tag = sc->unsolq[sc->unsolq_rp++] & 0xffff;
2937 sc->unsolq_rp %= HDAC_UNSOLQ_MAX;
2938 hdac_unsolicited_handler(sc->codecs[cad], tag);
2941 sc->unsolq_st = HDAC_UNSOLQ_READY;
2948 hdac_poll_callback(void *arg)
2950 struct hdac_softc *sc = arg;
2955 if (sc->polling == 0 || sc->poll_ival == 0) {
2959 if (hdac_rirb_flush(sc) != 0)
2960 hdac_unsolq_flush(sc);
2961 callout_reset(&sc->poll_hdac, sc->poll_ival, hdac_poll_callback, sc);
2966 hdac_poll_reinit(struct hdac_softc *sc)
2968 int i, pollticks, min = 1000000;
2969 struct hdac_chan *ch;
2971 for (i = 0; i < sc->num_chans; i++) {
2972 if ((sc->chans[i].flags & HDAC_CHN_RUNNING) == 0)
2975 pollticks = ((uint64_t)hz * ch->blksz) /
2976 ((uint64_t)sndbuf_getalign(ch->b) * sndbuf_getspd(ch->b));
2980 if (pollticks < 1) {
2982 device_printf(sc->dev,
2983 "%s: pollticks=%d < 1 !\n",
2984 __func__, pollticks);
2988 if (min > pollticks)
2992 device_printf(sc->dev,
2993 "%s: pollticks %d -> %d\n",
2994 __func__, sc->poll_ticks, min);
2996 sc->poll_ticks = min;
2998 callout_stop(&sc->poll_hda);
3000 callout_reset(&sc->poll_hda, 1, hda_poll_callback, sc);
3004 hdac_stream_stop(struct hdac_chan *ch)
3006 struct hdac_softc *sc = ch->devinfo->codec->sc;
3009 ctl = HDAC_READ_1(&sc->mem, ch->off + HDAC_SDCTL0);
3010 ctl &= ~(HDAC_SDCTL_IOCE | HDAC_SDCTL_FEIE | HDAC_SDCTL_DEIE |
3012 HDAC_WRITE_1(&sc->mem, ch->off + HDAC_SDCTL0, ctl);
3014 ch->flags &= ~HDAC_CHN_RUNNING;
3016 if (sc->polling != 0)
3017 hdac_poll_reinit(sc);
3019 ctl = HDAC_READ_4(&sc->mem, HDAC_INTCTL);
3020 ctl &= ~(1 << (ch->off >> 5));
3021 HDAC_WRITE_4(&sc->mem, HDAC_INTCTL, ctl);
3025 hdac_stream_start(struct hdac_chan *ch)
3027 struct hdac_softc *sc = ch->devinfo->codec->sc;
3030 ch->flags |= HDAC_CHN_RUNNING;
3032 if (sc->polling != 0)
3033 hdac_poll_reinit(sc);
3035 ctl = HDAC_READ_4(&sc->mem, HDAC_INTCTL);
3036 ctl |= 1 << (ch->off >> 5);
3037 HDAC_WRITE_4(&sc->mem, HDAC_INTCTL, ctl);
3039 ctl = HDAC_READ_1(&sc->mem, ch->off + HDAC_SDCTL0);
3040 ctl |= HDAC_SDCTL_IOCE | HDAC_SDCTL_FEIE | HDAC_SDCTL_DEIE |
3042 HDAC_WRITE_1(&sc->mem, ch->off + HDAC_SDCTL0, ctl);
3046 hdac_stream_reset(struct hdac_chan *ch)
3048 struct hdac_softc *sc = ch->devinfo->codec->sc;
3053 ctl = HDAC_READ_1(&sc->mem, ch->off + HDAC_SDCTL0);
3054 ctl |= HDAC_SDCTL_SRST;
3055 HDAC_WRITE_1(&sc->mem, ch->off + HDAC_SDCTL0, ctl);
3057 ctl = HDAC_READ_1(&sc->mem, ch->off + HDAC_SDCTL0);
3058 if (ctl & HDAC_SDCTL_SRST)
3062 if (!(ctl & HDAC_SDCTL_SRST)) {
3063 device_printf(sc->dev, "timeout in reset\n");
3065 ctl &= ~HDAC_SDCTL_SRST;
3066 HDAC_WRITE_1(&sc->mem, ch->off + HDAC_SDCTL0, ctl);
3069 ctl = HDAC_READ_1(&sc->mem, ch->off + HDAC_SDCTL0);
3070 if (!(ctl & HDAC_SDCTL_SRST))
3074 if (ctl & HDAC_SDCTL_SRST)
3075 device_printf(sc->dev, "can't reset!\n");
3079 hdac_stream_setid(struct hdac_chan *ch)
3081 struct hdac_softc *sc = ch->devinfo->codec->sc;
3084 ctl = HDAC_READ_1(&sc->mem, ch->off + HDAC_SDCTL2);
3085 ctl &= ~HDAC_SDCTL2_STRM_MASK;
3086 ctl |= ch->sid << HDAC_SDCTL2_STRM_SHIFT;
3087 HDAC_WRITE_1(&sc->mem, ch->off + HDAC_SDCTL2, ctl);
3091 hdac_bdl_setup(struct hdac_chan *ch)
3093 struct hdac_softc *sc = ch->devinfo->codec->sc;
3094 struct hdac_bdle *bdle;
3096 uint32_t blksz, blkcnt;
3099 addr = (uint64_t)sndbuf_getbufaddr(ch->b);
3100 bdle = (struct hdac_bdle *)ch->bdl_dma.dma_vaddr;
3103 blkcnt = ch->blkcnt;
3105 for (i = 0; i < blkcnt; i++, bdle++) {
3106 bdle->addrl = (uint32_t)addr;
3107 bdle->addrh = (uint32_t)(addr >> 32);
3113 HDAC_WRITE_4(&sc->mem, ch->off + HDAC_SDCBL, blksz * blkcnt);
3114 HDAC_WRITE_2(&sc->mem, ch->off + HDAC_SDLVI, blkcnt - 1);
3115 addr = ch->bdl_dma.dma_paddr;
3116 HDAC_WRITE_4(&sc->mem, ch->off + HDAC_SDBDPL, (uint32_t)addr);
3117 HDAC_WRITE_4(&sc->mem, ch->off + HDAC_SDBDPU, (uint32_t)(addr >> 32));
3118 if (ch->dmapos != NULL &&
3119 !(HDAC_READ_4(&sc->mem, HDAC_DPIBLBASE) & 0x00000001)) {
3120 addr = sc->pos_dma.dma_paddr;
3121 HDAC_WRITE_4(&sc->mem, HDAC_DPIBLBASE,
3122 ((uint32_t)addr & HDAC_DPLBASE_DPLBASE_MASK) | 0x00000001);
3123 HDAC_WRITE_4(&sc->mem, HDAC_DPIBUBASE, (uint32_t)(addr >> 32));
3128 hdac_bdl_alloc(struct hdac_chan *ch)
3130 struct hdac_softc *sc = ch->devinfo->codec->sc;
3133 rc = hdac_dma_alloc(sc, &ch->bdl_dma,
3134 sizeof(struct hdac_bdle) * HDA_BDL_MAX);
3136 device_printf(sc->dev, "can't alloc bdl\n");
3144 hdac_audio_ctl_amp_set_internal(struct hdac_softc *sc, nid_t cad, nid_t nid,
3145 int index, int lmute, int rmute,
3146 int left, int right, int dir)
3153 if (left != right || lmute != rmute) {
3154 v = (1 << (15 - dir)) | (1 << 13) | (index << 8) |
3155 (lmute << 7) | left;
3157 HDA_CMD_SET_AMP_GAIN_MUTE(cad, nid, v), cad);
3158 v = (1 << (15 - dir)) | (1 << 12) | (index << 8) |
3159 (rmute << 7) | right;
3161 v = (1 << (15 - dir)) | (3 << 12) | (index << 8) |
3162 (lmute << 7) | left;
3165 HDA_CMD_SET_AMP_GAIN_MUTE(cad, nid, v), cad);
3169 hdac_audio_ctl_amp_set(struct hdac_audio_ctl *ctl, uint32_t mute,
3170 int left, int right)
3172 struct hdac_softc *sc;
3176 sc = ctl->widget->devinfo->codec->sc;
3177 cad = ctl->widget->devinfo->codec->cad;
3178 nid = ctl->widget->nid;
3180 /* Save new values if valid. */
3181 if (mute != HDA_AMP_MUTE_DEFAULT)
3183 if (left != HDA_AMP_VOL_DEFAULT)
3185 if (right != HDA_AMP_VOL_DEFAULT)
3187 /* Prepare effective values */
3188 if (ctl->forcemute) {
3194 lmute = HDA_AMP_LEFT_MUTED(ctl->muted);
3195 rmute = HDA_AMP_RIGHT_MUTED(ctl->muted);
3199 /* Apply effective values */
3200 if (ctl->dir & HDA_CTL_OUT)
3201 hdac_audio_ctl_amp_set_internal(sc, cad, nid, ctl->index,
3202 lmute, rmute, left, right, 0);
3203 if (ctl->dir & HDA_CTL_IN)
3204 hdac_audio_ctl_amp_set_internal(sc, cad, nid, ctl->index,
3205 lmute, rmute, left, right, 1);
3209 hdac_widget_connection_select(struct hdac_widget *w, uint8_t index)
3211 if (w == NULL || w->nconns < 1 || index > (w->nconns - 1))
3213 hdac_command(w->devinfo->codec->sc,
3214 HDA_CMD_SET_CONNECTION_SELECT_CONTROL(w->devinfo->codec->cad,
3215 w->nid, index), w->devinfo->codec->cad);
3220 /****************************************************************************
3221 * uint32_t hdac_command_sendone_internal
3223 * Wrapper function that sends only one command to a given codec
3224 ****************************************************************************/
3226 hdac_command_sendone_internal(struct hdac_softc *sc, uint32_t verb, nid_t cad)
3228 struct hdac_command_list cl;
3229 uint32_t response = HDAC_INVALID;
3231 if (!hdac_lockowned(sc))
3232 device_printf(sc->dev, "WARNING!!!! mtx not owned!!!!\n");
3233 cl.num_commands = 1;
3235 cl.responses = &response;
3237 hdac_command_send_internal(sc, &cl, cad);
3242 /****************************************************************************
3243 * hdac_command_send_internal
3245 * Send a command list to the codec via the corb. We queue as much verbs as
3246 * we can and msleep on the codec. When the interrupt get the responses
3247 * back from the rirb, it will wake us up so we can queue the remaining verbs
3249 ****************************************************************************/
3251 hdac_command_send_internal(struct hdac_softc *sc,
3252 struct hdac_command_list *commands, nid_t cad)
3254 struct hdac_codec *codec;
3259 struct hdac_rirb *rirb_base;
3261 if (sc == NULL || sc->codecs[cad] == NULL || commands == NULL ||
3262 commands->num_commands < 1)
3265 codec = sc->codecs[cad];
3266 codec->commands = commands;
3267 codec->responses_received = 0;
3268 codec->verbs_sent = 0;
3269 corb = (uint32_t *)sc->corb_dma.dma_vaddr;
3270 rirb_base = (struct hdac_rirb *)sc->rirb_dma.dma_vaddr;
3273 if (codec->verbs_sent != commands->num_commands) {
3274 /* Queue as many verbs as possible */
3275 corbrp = HDAC_READ_2(&sc->mem, HDAC_CORBRP);
3277 bus_dmamap_sync(sc->corb_dma.dma_tag,
3278 sc->corb_dma.dma_map, BUS_DMASYNC_PREWRITE);
3280 while (codec->verbs_sent != commands->num_commands &&
3281 ((sc->corb_wp + 1) % sc->corb_size) != corbrp) {
3283 sc->corb_wp %= sc->corb_size;
3285 commands->verbs[codec->verbs_sent++];
3288 /* Send the verbs to the codecs */
3290 bus_dmamap_sync(sc->corb_dma.dma_tag,
3291 sc->corb_dma.dma_map, BUS_DMASYNC_POSTWRITE);
3293 HDAC_WRITE_2(&sc->mem, HDAC_CORBWP, sc->corb_wp);
3297 while (hdac_rirb_flush(sc) == 0 && --timeout)
3299 } while ((codec->verbs_sent != commands->num_commands ||
3300 codec->responses_received != commands->num_commands) && --retry);
3303 device_printf(sc->dev,
3304 "%s: TIMEOUT numcmd=%d, sent=%d, received=%d\n",
3305 __func__, commands->num_commands, codec->verbs_sent,
3306 codec->responses_received);
3308 codec->commands = NULL;
3309 codec->responses_received = 0;
3310 codec->verbs_sent = 0;
3312 hdac_unsolq_flush(sc);
3316 /****************************************************************************
3318 ****************************************************************************/
3320 /****************************************************************************
3321 * int hdac_probe(device_t)
3323 * Probe for the presence of an hdac. If none is found, check for a generic
3324 * match using the subclass of the device.
3325 ****************************************************************************/
3327 hdac_probe(device_t dev)
3331 uint16_t class, subclass;
3334 model = (uint32_t)pci_get_device(dev) << 16;
3335 model |= (uint32_t)pci_get_vendor(dev) & 0x0000ffff;
3336 class = pci_get_class(dev);
3337 subclass = pci_get_subclass(dev);
3339 bzero(desc, sizeof(desc));
3341 for (i = 0; i < HDAC_DEVICES_LEN; i++) {
3342 if (hdac_devices[i].model == model) {
3343 strlcpy(desc, hdac_devices[i].desc, sizeof(desc));
3344 result = BUS_PROBE_DEFAULT;
3347 if (HDA_DEV_MATCH(hdac_devices[i].model, model) &&
3348 class == PCIC_MULTIMEDIA &&
3349 subclass == PCIS_MULTIMEDIA_HDA) {
3350 strlcpy(desc, hdac_devices[i].desc, sizeof(desc));
3351 result = BUS_PROBE_GENERIC;
3355 if (result == ENXIO && class == PCIC_MULTIMEDIA &&
3356 subclass == PCIS_MULTIMEDIA_HDA) {
3357 strlcpy(desc, "Generic", sizeof(desc));
3358 result = BUS_PROBE_GENERIC;
3360 if (result != ENXIO) {
3361 strlcat(desc, " High Definition Audio Controller",
3363 device_set_desc_copy(dev, desc);
3370 hdac_channel_init(kobj_t obj, void *data, struct snd_dbuf *b,
3371 struct pcm_channel *c, int dir)
3373 struct hdac_pcm_devinfo *pdevinfo = data;
3374 struct hdac_devinfo *devinfo = pdevinfo->devinfo;
3375 struct hdac_softc *sc = devinfo->codec->sc;
3376 struct hdac_chan *ch;
3377 int i, ord = 0, chid;
3381 chid = (dir == PCMDIR_PLAY)?pdevinfo->play:pdevinfo->rec;
3382 ch = &sc->chans[chid];
3383 for (i = 0; i < sc->num_chans && i < chid; i++) {
3384 if (ch->dir == sc->chans[i].dir)
3387 if (dir == PCMDIR_PLAY) {
3388 ch->off = (sc->num_iss + ord) << 5;
3393 if (devinfo->function.audio.quirks & HDA_QUIRK_FIXEDRATE) {
3394 ch->caps.minspeed = ch->caps.maxspeed = 48000;
3395 ch->pcmrates[0] = 48000;
3396 ch->pcmrates[1] = 0;
3398 if (sc->pos_dma.dma_vaddr != NULL)
3399 ch->dmapos = (uint32_t *)(sc->pos_dma.dma_vaddr +
3400 (sc->streamcnt * 8));
3403 ch->sid = ++sc->streamcnt;
3407 ch->blksz = pdevinfo->chan_size / pdevinfo->chan_blkcnt;
3408 ch->blkcnt = pdevinfo->chan_blkcnt;
3411 if (hdac_bdl_alloc(ch) != 0) {
3416 if (sndbuf_alloc(ch->b, sc->chan_dmat,
3417 (sc->flags & HDAC_F_DMA_NOCACHE) ? BUS_DMA_NOCACHE : 0,
3418 pdevinfo->chan_size) != 0)
3425 hdac_channel_setformat(kobj_t obj, void *data, uint32_t format)
3427 struct hdac_chan *ch = data;
3430 for (i = 0; ch->caps.fmtlist[i] != 0; i++) {
3431 if (format == ch->caps.fmtlist[i]) {
3441 hdac_channel_setspeed(kobj_t obj, void *data, uint32_t speed)
3443 struct hdac_chan *ch = data;
3444 uint32_t spd = 0, threshold;
3447 for (i = 0; ch->pcmrates[i] != 0; i++) {
3448 spd = ch->pcmrates[i];
3449 threshold = spd + ((ch->pcmrates[i + 1] != 0) ?
3450 ((ch->pcmrates[i + 1] - spd) >> 1) : 0);
3451 if (speed < threshold)
3455 if (spd == 0) /* impossible */
3464 hdac_stream_setup(struct hdac_chan *ch)
3466 struct hdac_softc *sc = ch->devinfo->codec->sc;
3467 struct hdac_audio_as *as = &ch->devinfo->function.audio.as[ch->as];
3468 struct hdac_widget *w;
3469 int i, chn, totalchn, c;
3470 nid_t cad = ch->devinfo->codec->cad;
3472 uint16_t chmap[2][5] = {{ 0x0010, 0x0001, 0x0201, 0x0231, 0x0231 }, /* 5.1 */
3473 { 0x0010, 0x0001, 0x2001, 0x2031, 0x2431 }};/* 7.1 */
3476 totalchn = AFMT_CHANNEL(ch->fmt);
3478 device_printf(ch->pdevinfo->dev,
3479 "PCMDIR_%s: Stream setup fmt=%08x speed=%d\n",
3480 (ch->dir == PCMDIR_PLAY) ? "PLAY" : "REC",
3484 if (ch->fmt & AFMT_S16_LE)
3485 fmt |= ch->bit16 << 4;
3486 else if (ch->fmt & AFMT_S32_LE)
3487 fmt |= ch->bit32 << 4;
3490 for (i = 0; i < HDA_RATE_TAB_LEN; i++) {
3491 if (hda_rate_tab[i].valid && ch->spd == hda_rate_tab[i].rate) {
3492 fmt |= hda_rate_tab[i].base;
3493 fmt |= hda_rate_tab[i].mul;
3494 fmt |= hda_rate_tab[i].div;
3498 fmt |= (totalchn - 1);
3500 /* Set channel mapping for known speaker setups. */
3501 if (as->pinset == 0x0007 || as->pinset == 0x0013) /* Standard 5.1 */
3503 else if (as->pinset == 0x0017) /* Standard 7.1 */
3506 HDAC_WRITE_2(&sc->mem, ch->off + HDAC_SDFMT, fmt);
3508 dfmt = HDA_CMD_SET_DIGITAL_CONV_FMT1_DIGEN;
3509 if (ch->fmt & AFMT_AC3)
3510 dfmt |= HDA_CMD_SET_DIGITAL_CONV_FMT1_NAUDIO;
3513 for (i = 0; ch->io[i] != -1; i++) {
3514 w = hdac_widget_get(ch->devinfo, ch->io[i]);
3518 /* If HP redirection is enabled, but failed to use same
3519 DAC, make last DAC to duplicate first one. */
3520 if (as->fakeredir && i == (as->pincnt - 1)) {
3523 if (map >= 0) /* Map known speaker setups. */
3524 chn = (((chmap[map][totalchn / 2] >> i * 4) &
3526 if (chn < 0 || chn >= totalchn) {
3529 c = (ch->sid << 4) | chn;
3533 device_printf(ch->pdevinfo->dev,
3534 "PCMDIR_%s: Stream setup nid=%d: "
3535 "fmt=0x%04x, dfmt=0x%04x, chan=0x%04x\n",
3536 (ch->dir == PCMDIR_PLAY) ? "PLAY" : "REC",
3537 ch->io[i], fmt, dfmt, c);
3540 HDA_CMD_SET_CONV_FMT(cad, ch->io[i], fmt), cad);
3541 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) {
3543 HDA_CMD_SET_DIGITAL_CONV_FMT1(cad, ch->io[i], dfmt),
3547 HDA_CMD_SET_CONV_STREAM_CHAN(cad, ch->io[i], c), cad);
3550 HDA_CMD_SET_CONV_CHAN_COUNT(cad, ch->io[i], 1), cad);
3552 HDA_CMD_SET_HDMI_CHAN_SLOT(cad, ch->io[i], 0x00), cad);
3554 HDA_CMD_SET_HDMI_CHAN_SLOT(cad, ch->io[i], 0x11), cad);
3556 chn += HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap) + 1;
3561 * Greatest Common Divisor.
3564 gcd(unsigned a, unsigned b)
3577 * Least Common Multiple.
3580 lcm(unsigned a, unsigned b)
3583 return ((a * b) / gcd(a, b));
3587 hdac_channel_setfragments(kobj_t obj, void *data,
3588 uint32_t blksz, uint32_t blkcnt)
3590 struct hdac_chan *ch = data;
3591 struct hdac_softc *sc = ch->devinfo->codec->sc;
3593 blksz -= blksz % lcm(HDAC_DMA_ALIGNMENT, sndbuf_getalign(ch->b));
3595 if (blksz > (sndbuf_getmaxsize(ch->b) / HDA_BDL_MIN))
3596 blksz = sndbuf_getmaxsize(ch->b) / HDA_BDL_MIN;
3597 if (blksz < HDA_BLK_MIN)
3598 blksz = HDA_BLK_MIN;
3599 if (blkcnt > HDA_BDL_MAX)
3600 blkcnt = HDA_BDL_MAX;
3601 if (blkcnt < HDA_BDL_MIN)
3602 blkcnt = HDA_BDL_MIN;
3604 while ((blksz * blkcnt) > sndbuf_getmaxsize(ch->b)) {
3605 if ((blkcnt >> 1) >= HDA_BDL_MIN)
3607 else if ((blksz >> 1) >= HDA_BLK_MIN)
3613 if ((sndbuf_getblksz(ch->b) != blksz ||
3614 sndbuf_getblkcnt(ch->b) != blkcnt) &&
3615 sndbuf_resize(ch->b, blkcnt, blksz) != 0)
3616 device_printf(sc->dev, "%s: failed blksz=%u blkcnt=%u\n",
3617 __func__, blksz, blkcnt);
3619 ch->blksz = sndbuf_getblksz(ch->b);
3620 ch->blkcnt = sndbuf_getblkcnt(ch->b);
3626 hdac_channel_setblocksize(kobj_t obj, void *data, uint32_t blksz)
3628 struct hdac_chan *ch = data;
3630 hdac_channel_setfragments(obj, data, blksz, ch->pdevinfo->chan_blkcnt);
3636 hdac_channel_stop(struct hdac_softc *sc, struct hdac_chan *ch)
3638 struct hdac_devinfo *devinfo = ch->devinfo;
3639 struct hdac_widget *w;
3640 nid_t cad = devinfo->codec->cad;
3643 hdac_stream_stop(ch);
3645 for (i = 0; ch->io[i] != -1; i++) {
3646 w = hdac_widget_get(ch->devinfo, ch->io[i]);
3649 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) {
3651 HDA_CMD_SET_DIGITAL_CONV_FMT1(cad, ch->io[i], 0),
3655 HDA_CMD_SET_CONV_STREAM_CHAN(cad, ch->io[i],
3661 hdac_channel_start(struct hdac_softc *sc, struct hdac_chan *ch)
3665 hdac_stream_stop(ch);
3666 hdac_stream_reset(ch);
3668 hdac_stream_setid(ch);
3669 hdac_stream_setup(ch);
3670 hdac_stream_start(ch);
3674 hdac_channel_trigger(kobj_t obj, void *data, int go)
3676 struct hdac_chan *ch = data;
3677 struct hdac_softc *sc = ch->devinfo->codec->sc;
3679 if (!PCMTRIG_COMMON(go))
3685 hdac_channel_start(sc, ch);
3689 hdac_channel_stop(sc, ch);
3700 hdac_channel_getptr(kobj_t obj, void *data)
3702 struct hdac_chan *ch = data;
3703 struct hdac_softc *sc = ch->devinfo->codec->sc;
3707 if (sc->polling != 0)
3709 else if (ch->dmapos != NULL)
3710 ptr = *(ch->dmapos);
3712 ptr = HDAC_READ_4(&sc->mem, ch->off + HDAC_SDLPIB);
3716 * Round to available space and force 128 bytes aligment.
3718 ptr %= ch->blksz * ch->blkcnt;
3719 ptr &= HDA_BLK_ALIGN;
3724 static struct pcmchan_caps *
3725 hdac_channel_getcaps(kobj_t obj, void *data)
3727 return (&((struct hdac_chan *)data)->caps);
3730 static kobj_method_t hdac_channel_methods[] = {
3731 KOBJMETHOD(channel_init, hdac_channel_init),
3732 KOBJMETHOD(channel_setformat, hdac_channel_setformat),
3733 KOBJMETHOD(channel_setspeed, hdac_channel_setspeed),
3734 KOBJMETHOD(channel_setblocksize, hdac_channel_setblocksize),
3735 KOBJMETHOD(channel_setfragments, hdac_channel_setfragments),
3736 KOBJMETHOD(channel_trigger, hdac_channel_trigger),
3737 KOBJMETHOD(channel_getptr, hdac_channel_getptr),
3738 KOBJMETHOD(channel_getcaps, hdac_channel_getcaps),
3741 CHANNEL_DECLARE(hdac_channel);
3744 hdac_audio_ctl_ossmixer_init(struct snd_mixer *m)
3746 struct hdac_pcm_devinfo *pdevinfo = mix_getdevinfo(m);
3747 struct hdac_devinfo *devinfo = pdevinfo->devinfo;
3748 struct hdac_softc *sc = devinfo->codec->sc;
3749 struct hdac_widget *w, *cw;
3750 struct hdac_audio_ctl *ctl;
3751 uint32_t mask, recmask, id;
3752 int i, j, softpcmvol;
3756 /* Make sure that in case of soft volume it won't stay muted. */
3757 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
3758 pdevinfo->left[i] = 100;
3759 pdevinfo->right[i] = 100;
3764 id = hdac_codec_id(devinfo->codec);
3766 /* Declate EAPD as ogain control. */
3767 if (pdevinfo->play >= 0) {
3768 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3769 w = hdac_widget_get(devinfo, i);
3770 if (w == NULL || w->enable == 0)
3772 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX ||
3773 w->param.eapdbtl == HDAC_INVALID ||
3774 w->bindas != sc->chans[pdevinfo->play].as)
3776 mask |= SOUND_MASK_OGAIN;
3781 /* Declare volume controls assigned to this association. */
3784 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) {
3785 if (ctl->enable == 0)
3787 if ((pdevinfo->play >= 0 &&
3788 ctl->widget->bindas == sc->chans[pdevinfo->play].as) ||
3789 (pdevinfo->rec >= 0 &&
3790 ctl->widget->bindas == sc->chans[pdevinfo->rec].as) ||
3791 (ctl->widget->bindas == -2 && pdevinfo->index == 0))
3792 mask |= ctl->ossmask;
3795 /* Declare record sources available to this association. */
3796 if (pdevinfo->rec >= 0) {
3797 struct hdac_chan *ch = &sc->chans[pdevinfo->rec];
3798 for (i = 0; ch->io[i] != -1; i++) {
3799 w = hdac_widget_get(devinfo, ch->io[i]);
3800 if (w == NULL || w->enable == 0)
3802 for (j = 0; j < w->nconns; j++) {
3803 if (w->connsenable[j] == 0)
3805 cw = hdac_widget_get(devinfo, w->conns[j]);
3806 if (cw == NULL || cw->enable == 0)
3808 if (cw->bindas != sc->chans[pdevinfo->rec].as &&
3811 recmask |= cw->ossmask;
3816 /* Declare soft PCM volume if needed. */
3817 if (pdevinfo->play >= 0) {
3819 if ((mask & SOUND_MASK_PCM) == 0 ||
3820 (devinfo->function.audio.quirks & HDA_QUIRK_SOFTPCMVOL)) {
3822 mask |= SOUND_MASK_PCM;
3826 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) {
3827 if (ctl->enable == 0)
3829 if (ctl->widget->bindas != sc->chans[pdevinfo->play].as &&
3830 (ctl->widget->bindas != -2 || pdevinfo->index != 0))
3832 if (!(ctl->ossmask & SOUND_MASK_PCM))
3839 if (softpcmvol == 1 || ctl == NULL) {
3840 pcm_setflags(pdevinfo->dev, pcm_getflags(pdevinfo->dev) | SD_F_SOFTPCMVOL);
3842 device_printf(pdevinfo->dev,
3843 "%s Soft PCM volume\n",
3844 (softpcmvol == 1) ? "Forcing" : "Enabling");
3849 /* Declare master volume if needed. */
3850 if (pdevinfo->play >= 0) {
3851 if ((mask & (SOUND_MASK_VOLUME | SOUND_MASK_PCM)) ==
3853 mask |= SOUND_MASK_VOLUME;
3854 mix_setparentchild(m, SOUND_MIXER_VOLUME,
3856 mix_setrealdev(m, SOUND_MIXER_VOLUME,
3859 device_printf(pdevinfo->dev,
3860 "Forcing master volume with PCM\n");
3865 recmask &= (1 << SOUND_MIXER_NRDEVICES) - 1;
3866 mask &= (1 << SOUND_MIXER_NRDEVICES) - 1;
3868 mix_setrecdevs(m, recmask);
3869 mix_setdevs(m, mask);
3877 hdac_audio_ctl_ossmixer_set(struct snd_mixer *m, unsigned dev,
3878 unsigned left, unsigned right)
3880 struct hdac_pcm_devinfo *pdevinfo = mix_getdevinfo(m);
3881 struct hdac_devinfo *devinfo = pdevinfo->devinfo;
3882 struct hdac_softc *sc = devinfo->codec->sc;
3883 struct hdac_widget *w;
3884 struct hdac_audio_ctl *ctl;
3890 /* Save new values. */
3891 pdevinfo->left[dev] = left;
3892 pdevinfo->right[dev] = right;
3894 /* 'ogain' is the special case implemented with EAPD. */
3895 if (dev == SOUND_MIXER_OGAIN) {
3898 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3899 w = hdac_widget_get(devinfo, i);
3900 if (w == NULL || w->enable == 0)
3902 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX ||
3903 w->param.eapdbtl == HDAC_INVALID)
3907 if (i >= devinfo->endnode) {
3911 orig = w->param.eapdbtl;
3913 w->param.eapdbtl &= ~HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
3915 w->param.eapdbtl |= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
3916 if (orig != w->param.eapdbtl) {
3919 val = w->param.eapdbtl;
3920 if (devinfo->function.audio.quirks & HDA_QUIRK_EAPDINV)
3921 val ^= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
3923 HDA_CMD_SET_EAPD_BTL_ENABLE(devinfo->codec->cad,
3924 w->nid, val), devinfo->codec->cad);
3927 return (left | (left << 8));
3930 /* Recalculate all controls related to this OSS device. */
3932 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) {
3933 if (ctl->enable == 0 ||
3934 !(ctl->ossmask & (1 << dev)))
3936 if (!((pdevinfo->play >= 0 &&
3937 ctl->widget->bindas == sc->chans[pdevinfo->play].as) ||
3938 (pdevinfo->rec >= 0 &&
3939 ctl->widget->bindas == sc->chans[pdevinfo->rec].as) ||
3940 ctl->widget->bindas == -2))
3945 for (j = 0; j < SOUND_MIXER_NRDEVICES; j++) {
3946 if (ctl->ossmask & (1 << j)) {
3947 lvol = lvol * pdevinfo->left[j] / 100;
3948 rvol = rvol * pdevinfo->right[j] / 100;
3951 mute = (lvol == 0) ? HDA_AMP_MUTE_LEFT : 0;
3952 mute |= (rvol == 0) ? HDA_AMP_MUTE_RIGHT : 0;
3953 lvol = (lvol * ctl->step + 50) / 100;
3954 rvol = (rvol * ctl->step + 50) / 100;
3955 hdac_audio_ctl_amp_set(ctl, mute, lvol, rvol);
3959 return (left | (right << 8));
3963 * Commutate specified record source.
3966 hdac_audio_ctl_recsel_comm(struct hdac_pcm_devinfo *pdevinfo, uint32_t src, nid_t nid, int depth)
3968 struct hdac_devinfo *devinfo = pdevinfo->devinfo;
3969 struct hdac_widget *w, *cw;
3970 struct hdac_audio_ctl *ctl;
3975 if (depth > HDA_PARSE_MAXDEPTH)
3978 w = hdac_widget_get(devinfo, nid);
3979 if (w == NULL || w->enable == 0)
3982 for (i = 0; i < w->nconns; i++) {
3983 if (w->connsenable[i] == 0)
3985 cw = hdac_widget_get(devinfo, w->conns[i]);
3986 if (cw == NULL || cw->enable == 0 || cw->bindas == -1)
3988 /* Call recursively to trace signal to it's source if needed. */
3989 if ((src & cw->ossmask) != 0) {
3990 if (cw->ossdev < 0) {
3991 res |= hdac_audio_ctl_recsel_comm(pdevinfo, src,
3992 w->conns[i], depth + 1);
3997 /* We have two special cases: mixers and others (selectors). */
3998 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) {
3999 ctl = hdac_audio_ctl_amp_get(devinfo,
4000 w->nid, HDA_CTL_IN, i, 1);
4003 /* If we have input control on this node mute them
4004 * according to requested sources. */
4005 muted = (src & cw->ossmask) ? 0 : 1;
4006 if (muted != ctl->forcemute) {
4007 ctl->forcemute = muted;
4008 hdac_audio_ctl_amp_set(ctl,
4009 HDA_AMP_MUTE_DEFAULT,
4010 HDA_AMP_VOL_DEFAULT, HDA_AMP_VOL_DEFAULT);
4013 device_printf(pdevinfo->dev,
4014 "Recsel (%s): nid %d source %d %s\n",
4015 hdac_audio_ctl_ossmixer_mask2allname(
4016 src, buf, sizeof(buf)),
4017 nid, i, muted?"mute":"unmute");
4022 if ((src & cw->ossmask) == 0)
4024 /* If we found requested source - select it and exit. */
4025 hdac_widget_connection_select(w, i);
4027 device_printf(pdevinfo->dev,
4028 "Recsel (%s): nid %d source %d select\n",
4029 hdac_audio_ctl_ossmixer_mask2allname(
4030 src, buf, sizeof(buf)),
4040 hdac_audio_ctl_ossmixer_setrecsrc(struct snd_mixer *m, uint32_t src)
4042 struct hdac_pcm_devinfo *pdevinfo = mix_getdevinfo(m);
4043 struct hdac_devinfo *devinfo = pdevinfo->devinfo;
4044 struct hdac_widget *w;
4045 struct hdac_softc *sc = devinfo->codec->sc;
4046 struct hdac_chan *ch;
4048 uint32_t ret = 0xffffffff;
4052 /* Commutate requested recsrc for each ADC. */
4053 ch = &sc->chans[pdevinfo->rec];
4054 for (i = 0; ch->io[i] != -1; i++) {
4055 w = hdac_widget_get(devinfo, ch->io[i]);
4056 if (w == NULL || w->enable == 0)
4058 ret &= hdac_audio_ctl_recsel_comm(pdevinfo, src, ch->io[i], 0);
4063 return ((ret == 0xffffffff)? 0 : ret);
4066 static kobj_method_t hdac_audio_ctl_ossmixer_methods[] = {
4067 KOBJMETHOD(mixer_init, hdac_audio_ctl_ossmixer_init),
4068 KOBJMETHOD(mixer_set, hdac_audio_ctl_ossmixer_set),
4069 KOBJMETHOD(mixer_setrecsrc, hdac_audio_ctl_ossmixer_setrecsrc),
4072 MIXER_DECLARE(hdac_audio_ctl_ossmixer);
4075 hdac_unsolq_task(void *context, int pending)
4077 struct hdac_softc *sc;
4079 sc = (struct hdac_softc *)context;
4082 hdac_unsolq_flush(sc);
4086 /****************************************************************************
4087 * int hdac_attach(device_t)
4089 * Attach the device into the kernel. Interrupts usually won't be enabled
4090 * when this function is called. Setup everything that doesn't require
4091 * interrupts and defer probing of codecs until interrupts are enabled.
4092 ****************************************************************************/
4094 hdac_attach(device_t dev)
4096 struct hdac_softc *sc;
4100 uint16_t class, subclass;
4104 device_printf(dev, "HDA Driver Revision: %s\n", HDA_DRV_TEST_REV);
4106 model = (uint32_t)pci_get_device(dev) << 16;
4107 model |= (uint32_t)pci_get_vendor(dev) & 0x0000ffff;
4108 class = pci_get_class(dev);
4109 subclass = pci_get_subclass(dev);
4111 for (i = 0; i < HDAC_DEVICES_LEN; i++) {
4112 if (hdac_devices[i].model == model) {
4116 if (HDA_DEV_MATCH(hdac_devices[i].model, model) &&
4117 class == PCIC_MULTIMEDIA &&
4118 subclass == PCIS_MULTIMEDIA_HDA) {
4124 sc = device_get_softc(dev);
4125 sc->lock = snd_mtxcreate(device_get_nameunit(dev), HDAC_MTX_NAME);
4127 sc->pci_subvendor = (uint32_t)pci_get_subdevice(sc->dev) << 16;
4128 sc->pci_subvendor |= (uint32_t)pci_get_subvendor(sc->dev) & 0x0000ffff;
4129 vendor = pci_get_vendor(dev);
4131 if (sc->pci_subvendor == HP_NX6325_SUBVENDORX) {
4132 /* Screw nx6325 - subdevice/subvendor swapped */
4133 sc->pci_subvendor = HP_NX6325_SUBVENDOR;
4136 callout_init(&sc->poll_hda, CALLOUT_MPSAFE);
4137 callout_init(&sc->poll_hdac, CALLOUT_MPSAFE);
4138 callout_init(&sc->poll_jack, CALLOUT_MPSAFE);
4140 TASK_INIT(&sc->unsolq_task, 0, hdac_unsolq_task, sc);
4142 sc->poll_ticks = 1000000;
4143 sc->poll_ival = HDAC_POLL_INTERVAL;
4144 if (resource_int_value(device_get_name(dev),
4145 device_get_unit(dev), "polling", &i) == 0 && i != 0)
4151 for (i = 0; i < HDAC_CODEC_MAX; i++)
4152 sc->codecs[i] = NULL;
4154 pci_enable_busmaster(dev);
4156 if (vendor == INTEL_VENDORID) {
4158 v = pci_read_config(dev, 0x44, 1);
4159 pci_write_config(dev, 0x44, v & 0xf8, 1);
4161 device_printf(dev, "TCSEL: 0x%02d -> 0x%02d\n", v,
4162 pci_read_config(dev, 0x44, 1));
4166 if (devid >= 0 && (hdac_devices[devid].flags & HDAC_NO_MSI))
4167 sc->flags &= ~HDAC_F_MSI;
4169 sc->flags |= HDAC_F_MSI;
4170 if (resource_int_value(device_get_name(dev),
4171 device_get_unit(dev), "msi", &i) == 0) {
4173 sc->flags &= ~HDAC_F_MSI;
4175 sc->flags |= HDAC_F_MSI;
4178 #if defined(__i386__) || defined(__amd64__)
4179 sc->flags |= HDAC_F_DMA_NOCACHE;
4181 if (resource_int_value(device_get_name(dev),
4182 device_get_unit(dev), "snoop", &i) == 0 && i != 0) {
4184 sc->flags &= ~HDAC_F_DMA_NOCACHE;
4187 * Try to enable PCIe snoop to avoid messing around with
4188 * uncacheable DMA attribute. Since PCIe snoop register
4189 * config is pretty much vendor specific, there are no
4190 * general solutions on how to enable it, forcing us (even
4191 * Microsoft) to enable uncacheable or write combined DMA
4194 * http://msdn2.microsoft.com/en-us/library/ms790324.aspx
4196 for (i = 0; i < HDAC_PCIESNOOP_LEN; i++) {
4197 if (hdac_pcie_snoop[i].vendor != vendor)
4199 sc->flags &= ~HDAC_F_DMA_NOCACHE;
4200 if (hdac_pcie_snoop[i].reg == 0x00)
4202 v = pci_read_config(dev, hdac_pcie_snoop[i].reg, 1);
4203 if ((v & hdac_pcie_snoop[i].enable) ==
4204 hdac_pcie_snoop[i].enable)
4206 v &= hdac_pcie_snoop[i].mask;
4207 v |= hdac_pcie_snoop[i].enable;
4208 pci_write_config(dev, hdac_pcie_snoop[i].reg, v, 1);
4209 v = pci_read_config(dev, hdac_pcie_snoop[i].reg, 1);
4210 if ((v & hdac_pcie_snoop[i].enable) !=
4211 hdac_pcie_snoop[i].enable) {
4214 "WARNING: Failed to enable PCIe "
4217 #if defined(__i386__) || defined(__amd64__)
4218 sc->flags |= HDAC_F_DMA_NOCACHE;
4223 #if defined(__i386__) || defined(__amd64__)
4228 device_printf(dev, "DMA Coherency: %s / vendor=0x%04x\n",
4229 (sc->flags & HDAC_F_DMA_NOCACHE) ?
4230 "Uncacheable" : "PCIe snoop", vendor);
4233 /* Allocate resources */
4234 result = hdac_mem_alloc(sc);
4236 goto hdac_attach_fail;
4237 result = hdac_irq_alloc(sc);
4239 goto hdac_attach_fail;
4241 /* Get Capabilities */
4242 result = hdac_get_capabilities(sc);
4244 goto hdac_attach_fail;
4246 if (devid >= 0 && (hdac_devices[devid].flags & HDAC_NO_64BIT))
4247 sc->support_64bit = 0;
4249 /* Allocate CORB and RIRB dma memory */
4250 result = hdac_dma_alloc(sc, &sc->corb_dma,
4251 sc->corb_size * sizeof(uint32_t));
4253 goto hdac_attach_fail;
4254 result = hdac_dma_alloc(sc, &sc->rirb_dma,
4255 sc->rirb_size * sizeof(struct hdac_rirb));
4257 goto hdac_attach_fail;
4259 result = bus_dma_tag_create(
4260 bus_get_dma_tag(sc->dev), /* parent */
4261 HDAC_DMA_ALIGNMENT, /* alignment */
4263 (sc->support_64bit) ? BUS_SPACE_MAXADDR :
4264 BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
4265 BUS_SPACE_MAXADDR, /* highaddr */
4266 NULL, /* filtfunc */
4267 NULL, /* fistfuncarg */
4268 HDA_BUFSZ_MAX, /* maxsize */
4270 HDA_BUFSZ_MAX, /* maxsegsz */
4272 NULL, /* lockfunc */
4273 NULL, /* lockfuncarg */
4274 &sc->chan_dmat); /* dmat */
4276 device_printf(dev, "%s: bus_dma_tag_create failed (%x)\n",
4278 goto hdac_attach_fail;
4281 /* Quiesce everything */
4283 device_printf(dev, "Reset controller...\n");
4287 /* Initialize the CORB and RIRB */
4291 /* Defer remaining of initialization until interrupts are enabled */
4292 sc->intrhook.ich_func = hdac_attach2;
4293 sc->intrhook.ich_arg = (void *)sc;
4294 if (cold == 0 || config_intrhook_establish(&sc->intrhook) != 0) {
4295 sc->intrhook.ich_func = NULL;
4296 hdac_attach2((void *)sc);
4303 hdac_dma_free(sc, &sc->rirb_dma);
4304 hdac_dma_free(sc, &sc->corb_dma);
4306 snd_mtxfree(sc->lock);
4312 hdac_audio_parse(struct hdac_devinfo *devinfo)
4314 struct hdac_codec *codec = devinfo->codec;
4315 struct hdac_softc *sc = codec->sc;
4316 struct hdac_widget *w;
4321 cad = devinfo->codec->cad;
4324 res = hdac_command(sc,
4325 HDA_CMD_GET_PARAMETER(cad , nid, HDA_PARAM_GPIO_COUNT), cad);
4326 devinfo->function.audio.gpio = res;
4329 device_printf(sc->dev, "GPIO: 0x%08x "
4330 "NumGPIO=%d NumGPO=%d "
4331 "NumGPI=%d GPIWake=%d GPIUnsol=%d\n",
4332 devinfo->function.audio.gpio,
4333 HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->function.audio.gpio),
4334 HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->function.audio.gpio),
4335 HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->function.audio.gpio),
4336 HDA_PARAM_GPIO_COUNT_GPI_WAKE(devinfo->function.audio.gpio),
4337 HDA_PARAM_GPIO_COUNT_GPI_UNSOL(devinfo->function.audio.gpio));
4340 res = hdac_command(sc,
4341 HDA_CMD_GET_PARAMETER(cad, nid, HDA_PARAM_SUPP_STREAM_FORMATS),
4343 devinfo->function.audio.supp_stream_formats = res;
4345 res = hdac_command(sc,
4346 HDA_CMD_GET_PARAMETER(cad, nid, HDA_PARAM_SUPP_PCM_SIZE_RATE),
4348 devinfo->function.audio.supp_pcm_size_rate = res;
4350 res = hdac_command(sc,
4351 HDA_CMD_GET_PARAMETER(cad, nid, HDA_PARAM_OUTPUT_AMP_CAP),
4353 devinfo->function.audio.outamp_cap = res;
4355 res = hdac_command(sc,
4356 HDA_CMD_GET_PARAMETER(cad, nid, HDA_PARAM_INPUT_AMP_CAP),
4358 devinfo->function.audio.inamp_cap = res;
4360 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4361 w = hdac_widget_get(devinfo, i);
4363 device_printf(sc->dev, "Ghost widget! nid=%d!\n", i);
4365 w->devinfo = devinfo;
4372 w->param.eapdbtl = HDAC_INVALID;
4373 hdac_widget_parse(w);
4379 hdac_audio_ctl_parse(struct hdac_devinfo *devinfo)
4381 struct hdac_softc *sc = devinfo->codec->sc;
4382 struct hdac_audio_ctl *ctls;
4383 struct hdac_widget *w, *cw;
4384 int i, j, cnt, max, ocap, icap;
4385 int mute, offset, step, size;
4387 /* XXX This is redundant */
4389 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4390 w = hdac_widget_get(devinfo, i);
4391 if (w == NULL || w->enable == 0)
4393 if (w->param.outamp_cap != 0)
4395 if (w->param.inamp_cap != 0) {
4397 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR:
4398 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER:
4399 for (j = 0; j < w->nconns; j++) {
4400 cw = hdac_widget_get(devinfo,
4402 if (cw == NULL || cw->enable == 0)
4414 devinfo->function.audio.ctlcnt = max;
4419 ctls = (struct hdac_audio_ctl *)malloc(
4420 sizeof(*ctls) * max, M_HDAC, M_ZERO | M_NOWAIT);
4424 device_printf(sc->dev, "unable to allocate ctls!\n");
4425 devinfo->function.audio.ctlcnt = 0;
4430 for (i = devinfo->startnode; cnt < max && i < devinfo->endnode; i++) {
4432 device_printf(sc->dev, "%s: Ctl overflow!\n",
4436 w = hdac_widget_get(devinfo, i);
4437 if (w == NULL || w->enable == 0)
4439 ocap = w->param.outamp_cap;
4440 icap = w->param.inamp_cap;
4442 mute = HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(ocap);
4443 step = HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(ocap);
4444 size = HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(ocap);
4445 offset = HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(ocap);
4446 /*if (offset > step) {
4448 device_printf(sc->dev,
4449 "BUGGY outamp: nid=%d "
4450 "[offset=%d > step=%d]\n",
4451 w->nid, offset, step);
4455 ctls[cnt].enable = 1;
4456 ctls[cnt].widget = w;
4457 ctls[cnt].mute = mute;
4458 ctls[cnt].step = step;
4459 ctls[cnt].size = size;
4460 ctls[cnt].offset = offset;
4461 ctls[cnt].left = offset;
4462 ctls[cnt].right = offset;
4463 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX ||
4465 ctls[cnt].ndir = HDA_CTL_IN;
4467 ctls[cnt].ndir = HDA_CTL_OUT;
4468 ctls[cnt++].dir = HDA_CTL_OUT;
4472 mute = HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(icap);
4473 step = HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(icap);
4474 size = HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(icap);
4475 offset = HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(icap);
4476 /*if (offset > step) {
4478 device_printf(sc->dev,
4479 "BUGGY inamp: nid=%d "
4480 "[offset=%d > step=%d]\n",
4481 w->nid, offset, step);
4486 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR:
4487 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER:
4488 for (j = 0; j < w->nconns; j++) {
4490 device_printf(sc->dev,
4491 "%s: Ctl overflow!\n",
4495 cw = hdac_widget_get(devinfo,
4497 if (cw == NULL || cw->enable == 0)
4499 ctls[cnt].enable = 1;
4500 ctls[cnt].widget = w;
4501 ctls[cnt].childwidget = cw;
4502 ctls[cnt].index = j;
4503 ctls[cnt].mute = mute;
4504 ctls[cnt].step = step;
4505 ctls[cnt].size = size;
4506 ctls[cnt].offset = offset;
4507 ctls[cnt].left = offset;
4508 ctls[cnt].right = offset;
4509 ctls[cnt].ndir = HDA_CTL_IN;
4510 ctls[cnt++].dir = HDA_CTL_IN;
4515 device_printf(sc->dev,
4516 "%s: Ctl overflow!\n",
4520 ctls[cnt].enable = 1;
4521 ctls[cnt].widget = w;
4522 ctls[cnt].mute = mute;
4523 ctls[cnt].step = step;
4524 ctls[cnt].size = size;
4525 ctls[cnt].offset = offset;
4526 ctls[cnt].left = offset;
4527 ctls[cnt].right = offset;
4529 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
4530 ctls[cnt].ndir = HDA_CTL_OUT;
4532 ctls[cnt].ndir = HDA_CTL_IN;
4533 ctls[cnt++].dir = HDA_CTL_IN;
4539 devinfo->function.audio.ctl = ctls;
4543 hdac_audio_as_parse(struct hdac_devinfo *devinfo)
4545 struct hdac_softc *sc = devinfo->codec->sc;
4546 struct hdac_audio_as *as;
4547 struct hdac_widget *w;
4548 int i, j, cnt, max, type, dir, assoc, seq, first, hpredir;
4550 /* Count present associations */
4552 for (j = 1; j < 16; j++) {
4553 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4554 w = hdac_widget_get(devinfo, i);
4555 if (w == NULL || w->enable == 0)
4557 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
4559 if (HDA_CONFIG_DEFAULTCONF_ASSOCIATION(w->wclass.pin.config)
4563 if (j != 15) /* There could be many 1-pin assocs #15 */
4568 devinfo->function.audio.ascnt = max;
4573 as = (struct hdac_audio_as *)malloc(
4574 sizeof(*as) * max, M_HDAC, M_ZERO | M_NOWAIT);
4578 device_printf(sc->dev, "unable to allocate assocs!\n");
4579 devinfo->function.audio.ascnt = 0;
4583 for (i = 0; i < max; i++) {
4589 /* Scan associations skipping as=0. */
4591 for (j = 1; j < 16; j++) {
4594 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4595 w = hdac_widget_get(devinfo, i);
4596 if (w == NULL || w->enable == 0)
4598 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
4600 assoc = HDA_CONFIG_DEFAULTCONF_ASSOCIATION(w->wclass.pin.config);
4601 seq = HDA_CONFIG_DEFAULTCONF_SEQUENCE(w->wclass.pin.config);
4606 ("%s: Associations owerflow (%d of %d)",
4607 __func__, cnt, max));
4608 type = w->wclass.pin.config &
4609 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
4610 /* Get pin direction. */
4611 if (type == HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_OUT ||
4612 type == HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER ||
4613 type == HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT ||
4614 type == HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_OUT ||
4615 type == HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_OUT)
4619 /* If this is a first pin - create new association. */
4620 if (as[cnt].pincnt == 0) {
4627 /* Check association correctness. */
4628 if (as[cnt].pins[seq] != 0) {
4629 device_printf(sc->dev, "%s: Duplicate pin %d (%d) "
4630 "in association %d! Disabling association.\n",
4631 __func__, seq, w->nid, j);
4634 if (dir != as[cnt].dir) {
4635 device_printf(sc->dev, "%s: Pin %d has wrong "
4636 "direction for association %d! Disabling "
4638 __func__, w->nid, j);
4641 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) {
4642 if (HDA_PARAM_PIN_CAP_DP(w->wclass.pin.cap))
4643 as[cnt].digital = 3;
4644 else if (HDA_PARAM_PIN_CAP_HDMI(w->wclass.pin.cap))
4645 as[cnt].digital = 2;
4647 as[cnt].digital = 1;
4649 /* Headphones with seq=15 may mean redirection. */
4650 if (type == HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT &&
4653 as[cnt].pins[seq] = w->nid;
4655 /* Association 15 is a multiple unassociated pins. */
4659 if (j != 15 && as[cnt].pincnt > 0) {
4660 if (hpredir && as[cnt].pincnt > 1)
4661 as[cnt].hpredir = first;
4666 device_printf(sc->dev,
4667 "%d associations found:\n", max);
4668 for (i = 0; i < max; i++) {
4669 device_printf(sc->dev,
4670 "Association %d (%d) %s%s:\n",
4671 i, as[i].index, (as[i].dir == HDA_CTL_IN)?"in":"out",
4672 as[i].enable?"":" (disabled)");
4673 for (j = 0; j < 16; j++) {
4674 if (as[i].pins[j] == 0)
4676 device_printf(sc->dev,
4677 " Pin nid=%d seq=%d\n",
4683 devinfo->function.audio.as = as;
4686 static const struct {
4689 uint32_t set, unset;
4692 * XXX Force stereo quirk. Monoural recording / playback
4693 * on few codecs (especially ALC880) seems broken or
4694 * perhaps unsupported.
4696 { HDA_MATCH_ALL, HDA_MATCH_ALL,
4697 HDA_QUIRK_FORCESTEREO | HDA_QUIRK_IVREF, 0 },
4698 { ACER_ALL_SUBVENDOR, HDA_MATCH_ALL,
4699 HDA_QUIRK_GPIO0, 0 },
4700 { ASUS_G2K_SUBVENDOR, HDA_CODEC_ALC660,
4701 HDA_QUIRK_GPIO0, 0 },
4702 { ASUS_M5200_SUBVENDOR, HDA_CODEC_ALC880,
4703 HDA_QUIRK_GPIO0, 0 },
4704 { ASUS_A7M_SUBVENDOR, HDA_CODEC_ALC880,
4705 HDA_QUIRK_GPIO0, 0 },
4706 { ASUS_A7T_SUBVENDOR, HDA_CODEC_ALC882,
4707 HDA_QUIRK_GPIO0, 0 },
4708 { ASUS_W2J_SUBVENDOR, HDA_CODEC_ALC882,
4709 HDA_QUIRK_GPIO0, 0 },
4710 { ASUS_U5F_SUBVENDOR, HDA_CODEC_AD1986A,
4711 HDA_QUIRK_EAPDINV, 0 },
4712 { ASUS_A8X_SUBVENDOR, HDA_CODEC_AD1986A,
4713 HDA_QUIRK_EAPDINV, 0 },
4714 { ASUS_F3JC_SUBVENDOR, HDA_CODEC_ALC861,
4715 HDA_QUIRK_OVREF, 0 },
4716 { UNIWILL_9075_SUBVENDOR, HDA_CODEC_ALC861,
4717 HDA_QUIRK_OVREF, 0 },
4718 /*{ ASUS_M2N_SUBVENDOR, HDA_CODEC_AD1988,
4719 HDA_QUIRK_IVREF80, HDA_QUIRK_IVREF50 | HDA_QUIRK_IVREF100 },*/
4720 { MEDION_MD95257_SUBVENDOR, HDA_CODEC_ALC880,
4721 HDA_QUIRK_GPIO1, 0 },
4722 { LENOVO_3KN100_SUBVENDOR, HDA_CODEC_AD1986A,
4723 HDA_QUIRK_EAPDINV | HDA_QUIRK_SENSEINV, 0 },
4724 { SAMSUNG_Q1_SUBVENDOR, HDA_CODEC_AD1986A,
4725 HDA_QUIRK_EAPDINV, 0 },
4726 { APPLE_MB3_SUBVENDOR, HDA_CODEC_ALC885,
4727 HDA_QUIRK_GPIO0 | HDA_QUIRK_OVREF50, 0},
4728 { APPLE_INTEL_MAC, HDA_CODEC_STAC9221,
4729 HDA_QUIRK_GPIO0 | HDA_QUIRK_GPIO1, 0 },
4730 { APPLE_MACBOOKPRO55, HDA_CODEC_CS4206,
4731 HDA_QUIRK_GPIO1 | HDA_QUIRK_GPIO3, 0 },
4732 { DELL_D630_SUBVENDOR, HDA_CODEC_STAC9205X,
4733 HDA_QUIRK_GPIO0, 0 },
4734 { DELL_V1400_SUBVENDOR, HDA_CODEC_STAC9228X,
4735 HDA_QUIRK_GPIO2, 0 },
4736 { DELL_V1500_SUBVENDOR, HDA_CODEC_STAC9205X,
4737 HDA_QUIRK_GPIO0, 0 },
4738 { HDA_MATCH_ALL, HDA_CODEC_AD1988,
4739 HDA_QUIRK_IVREF80, HDA_QUIRK_IVREF50 | HDA_QUIRK_IVREF100 },
4740 { HDA_MATCH_ALL, HDA_CODEC_AD1988B,
4741 HDA_QUIRK_IVREF80, HDA_QUIRK_IVREF50 | HDA_QUIRK_IVREF100 },
4742 { HDA_MATCH_ALL, HDA_CODEC_CX20549,
4743 0, HDA_QUIRK_FORCESTEREO }
4745 #define HDAC_QUIRKS_LEN (sizeof(hdac_quirks) / sizeof(hdac_quirks[0]))
4748 hdac_vendor_patch_parse(struct hdac_devinfo *devinfo)
4750 struct hdac_widget *w;
4751 uint32_t id, subvendor;
4754 id = hdac_codec_id(devinfo->codec);
4755 subvendor = devinfo->codec->sc->pci_subvendor;
4760 for (i = 0; i < HDAC_QUIRKS_LEN; i++) {
4761 if (!(HDA_DEV_MATCH(hdac_quirks[i].model, subvendor) &&
4762 HDA_DEV_MATCH(hdac_quirks[i].id, id)))
4764 if (hdac_quirks[i].set != 0)
4765 devinfo->function.audio.quirks |=
4767 if (hdac_quirks[i].unset != 0)
4768 devinfo->function.audio.quirks &=
4769 ~(hdac_quirks[i].unset);
4773 case HDA_CODEC_AD1983:
4775 * This codec has several possible usages, but none
4776 * fit the parser best. Help parser to choose better.
4778 /* Disable direct unmixed playback to get pcm volume. */
4779 w = hdac_widget_get(devinfo, 5);
4781 w->connsenable[0] = 0;
4782 w = hdac_widget_get(devinfo, 6);
4784 w->connsenable[0] = 0;
4785 w = hdac_widget_get(devinfo, 11);
4787 w->connsenable[0] = 0;
4788 /* Disable mic and line selectors. */
4789 w = hdac_widget_get(devinfo, 12);
4791 w->connsenable[1] = 0;
4792 w = hdac_widget_get(devinfo, 13);
4794 w->connsenable[1] = 0;
4795 /* Disable recording from mono playback mix. */
4796 w = hdac_widget_get(devinfo, 20);
4798 w->connsenable[3] = 0;
4800 case HDA_CODEC_AD1986A:
4802 * This codec has overcomplicated input mixing.
4803 * Make some cleaning there.
4805 /* Disable input mono mixer. Not needed and not supported. */
4806 w = hdac_widget_get(devinfo, 43);
4809 /* Disable any with any input mixing mesh. Use separately. */
4810 w = hdac_widget_get(devinfo, 39);
4813 w = hdac_widget_get(devinfo, 40);
4816 w = hdac_widget_get(devinfo, 41);
4819 w = hdac_widget_get(devinfo, 42);
4822 /* Disable duplicate mixer node connector. */
4823 w = hdac_widget_get(devinfo, 15);
4825 w->connsenable[3] = 0;
4826 /* There is only one mic preamplifier, use it effectively. */
4827 w = hdac_widget_get(devinfo, 31);
4829 if ((w->wclass.pin.config &
4830 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) ==
4831 HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN) {
4832 w = hdac_widget_get(devinfo, 16);
4834 w->connsenable[2] = 0;
4836 w = hdac_widget_get(devinfo, 15);
4838 w->connsenable[0] = 0;
4841 w = hdac_widget_get(devinfo, 32);
4843 if ((w->wclass.pin.config &
4844 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) ==
4845 HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN) {
4846 w = hdac_widget_get(devinfo, 16);
4848 w->connsenable[0] = 0;
4850 w = hdac_widget_get(devinfo, 15);
4852 w->connsenable[1] = 0;
4856 if (subvendor == ASUS_A8X_SUBVENDOR) {
4858 * This is just plain ridiculous.. There
4859 * are several A8 series that share the same
4860 * pci id but works differently (EAPD).
4862 w = hdac_widget_get(devinfo, 26);
4863 if (w != NULL && w->type ==
4864 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
4865 (w->wclass.pin.config &
4866 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK) !=
4867 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_NONE)
4868 devinfo->function.audio.quirks &=
4872 case HDA_CODEC_AD1981HD:
4874 * This codec has very unusual design with several
4875 * points inappropriate for the present parser.
4877 /* Disable recording from mono playback mix. */
4878 w = hdac_widget_get(devinfo, 21);
4880 w->connsenable[3] = 0;
4881 /* Disable rear to front mic mixer, use separately. */
4882 w = hdac_widget_get(devinfo, 31);
4885 /* Disable direct playback, use mixer. */
4886 w = hdac_widget_get(devinfo, 5);
4888 w->connsenable[0] = 0;
4889 w = hdac_widget_get(devinfo, 6);
4891 w->connsenable[0] = 0;
4892 w = hdac_widget_get(devinfo, 9);
4894 w->connsenable[0] = 0;
4895 w = hdac_widget_get(devinfo, 24);
4897 w->connsenable[0] = 0;
4903 * Trace path from DAC to pin.
4906 hdac_audio_trace_dac(struct hdac_devinfo *devinfo, int as, int seq, nid_t nid,
4907 int dupseq, int min, int only, int depth)
4909 struct hdac_widget *w;
4913 if (depth > HDA_PARSE_MAXDEPTH)
4915 w = hdac_widget_get(devinfo, nid);
4916 if (w == NULL || w->enable == 0)
4920 device_printf(devinfo->codec->sc->dev,
4921 " %*stracing via nid %d\n",
4922 depth + 1, "", w->nid);
4925 /* Use only unused widgets */
4926 if (w->bindas >= 0 && w->bindas != as) {
4929 device_printf(devinfo->codec->sc->dev,
4930 " %*snid %d busy by association %d\n",
4931 depth + 1, "", w->nid, w->bindas);
4937 if (w->bindseqmask != 0) {
4940 device_printf(devinfo->codec->sc->dev,
4941 " %*snid %d busy by seqmask %x\n",
4942 depth + 1, "", w->nid, w->bindseqmask);
4948 /* If this is headphones - allow duplicate first pin. */
4949 if (w->bindseqmask != 0 &&
4950 (w->bindseqmask & (1 << dupseq)) == 0) {
4952 device_printf(devinfo->codec->sc->dev,
4953 " %*snid %d busy by seqmask %x\n",
4954 depth + 1, "", w->nid, w->bindseqmask);
4961 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT:
4962 /* Do not traverse input. AD1988 has digital monitor
4963 for which we are not ready. */
4965 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT:
4966 /* If we are tracing HP take only dac of first pin. */
4967 if ((only == 0 || only == w->nid) &&
4968 (w->nid >= min) && (dupseq < 0 || w->nid ==
4969 devinfo->function.audio.as[as].dacs[dupseq]))
4972 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
4977 /* Find reachable DACs with smallest nid respecting constraints. */
4978 for (i = 0; i < w->nconns; i++) {
4979 if (w->connsenable[i] == 0)
4981 if (w->selconn != -1 && w->selconn != i)
4983 if ((ret = hdac_audio_trace_dac(devinfo, as, seq,
4984 w->conns[i], dupseq, min, only, depth + 1)) != 0) {
4985 if (m == 0 || ret < m) {
4989 if (only || dupseq >= 0)
4993 if (m && only && ((w->nconns > 1 &&
4994 w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) ||
4995 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR))
5001 w->bindseqmask |= (1 << seq);
5005 device_printf(devinfo->codec->sc->dev,
5006 " %*snid %d returned %d\n",
5007 depth + 1, "", w->nid, m);
5014 * Trace path from widget to ADC.
5017 hdac_audio_trace_adc(struct hdac_devinfo *devinfo, int as, int seq, nid_t nid,
5018 int only, int depth)
5020 struct hdac_widget *w, *wc;
5024 if (depth > HDA_PARSE_MAXDEPTH)
5026 w = hdac_widget_get(devinfo, nid);
5027 if (w == NULL || w->enable == 0)
5030 device_printf(devinfo->codec->sc->dev,
5031 " %*stracing via nid %d\n",
5032 depth + 1, "", w->nid);
5034 /* Use only unused widgets */
5035 if (w->bindas >= 0 && w->bindas != as) {
5037 device_printf(devinfo->codec->sc->dev,
5038 " %*snid %d busy by association %d\n",
5039 depth + 1, "", w->nid, w->bindas);
5045 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT:
5046 /* If we are tracing HP take only dac of first pin. */
5050 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
5055 /* Try to find reachable ADCs with specified nid. */
5056 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
5057 wc = hdac_widget_get(devinfo, j);
5058 if (wc == NULL || wc->enable == 0)
5060 for (i = 0; i < wc->nconns; i++) {
5061 if (wc->connsenable[i] == 0)
5063 if (wc->conns[i] != nid)
5065 if (hdac_audio_trace_adc(devinfo, as, seq,
5066 j, only, depth + 1) != 0) {
5068 if (((wc->nconns > 1 &&
5069 wc->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) ||
5070 wc->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR) &&
5080 w->bindseqmask |= (1 << seq);
5083 device_printf(devinfo->codec->sc->dev,
5084 " %*snid %d returned %d\n",
5085 depth + 1, "", w->nid, res);
5091 * Erase trace path of the specified association.
5094 hdac_audio_undo_trace(struct hdac_devinfo *devinfo, int as, int seq)
5096 struct hdac_widget *w;
5099 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5100 w = hdac_widget_get(devinfo, i);
5101 if (w == NULL || w->enable == 0)
5103 if (w->bindas == as) {
5105 w->bindseqmask &= ~(1 << seq);
5106 if (w->bindseqmask == 0) {
5120 * Trace association path from DAC to output
5123 hdac_audio_trace_as_out(struct hdac_devinfo *devinfo, int as, int seq)
5125 struct hdac_audio_as *ases = devinfo->function.audio.as;
5130 for (i = seq; i < 16 && ases[as].pins[i] == 0; i++)
5132 /* Check if there is no any left. If so - we succeeded. */
5136 hpredir = (i == 15 && ases[as].fakeredir == 0)?ases[as].hpredir:-1;
5141 device_printf(devinfo->codec->sc->dev,
5142 " Tracing pin %d with min nid %d",
5143 ases[as].pins[i], min);
5145 printf(" and hpredir %d", hpredir);
5148 /* Trace this pin taking min nid into account. */
5149 res = hdac_audio_trace_dac(devinfo, as, i,
5150 ases[as].pins[i], hpredir, min, 0, 0);
5152 /* If we failed - return to previous and redo it. */
5154 device_printf(devinfo->codec->sc->dev,
5155 " Unable to trace pin %d seq %d with min "
5157 ases[as].pins[i], i, min);
5159 printf(" and hpredir %d", hpredir);
5165 device_printf(devinfo->codec->sc->dev,
5166 " Pin %d traced to DAC %d",
5167 ases[as].pins[i], res);
5169 printf(" and hpredir %d", hpredir);
5170 if (ases[as].fakeredir)
5171 printf(" with fake redirection");
5174 /* Trace again to mark the path */
5175 hdac_audio_trace_dac(devinfo, as, i,
5176 ases[as].pins[i], hpredir, min, res, 0);
5177 ases[as].dacs[i] = res;
5178 /* We succeeded, so call next. */
5179 if (hdac_audio_trace_as_out(devinfo, as, i + 1))
5181 /* If next failed, we should retry with next min */
5182 hdac_audio_undo_trace(devinfo, as, i);
5183 ases[as].dacs[i] = 0;
5189 * Trace association path from input to ADC
5192 hdac_audio_trace_as_in(struct hdac_devinfo *devinfo, int as)
5194 struct hdac_audio_as *ases = devinfo->function.audio.as;
5195 struct hdac_widget *w;
5198 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
5199 w = hdac_widget_get(devinfo, j);
5200 if (w == NULL || w->enable == 0)
5202 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT)
5204 if (w->bindas >= 0 && w->bindas != as)
5208 for (i = 0; i < 16; i++) {
5209 if (ases[as].pins[i] == 0)
5213 device_printf(devinfo->codec->sc->dev,
5214 " Tracing pin %d to ADC %d\n",
5215 ases[as].pins[i], j);
5217 /* Trace this pin taking goal into account. */
5218 if (hdac_audio_trace_adc(devinfo, as, i,
5219 ases[as].pins[i], j, 0) == 0) {
5220 /* If we failed - return to previous and redo it. */
5222 device_printf(devinfo->codec->sc->dev,
5223 " Unable to trace pin %d to ADC %d, undo traces\n",
5224 ases[as].pins[i], j);
5226 hdac_audio_undo_trace(devinfo, as, -1);
5227 for (k = 0; k < 16; k++)
5228 ases[as].dacs[k] = 0;
5232 device_printf(devinfo->codec->sc->dev,
5233 " Pin %d traced to ADC %d\n",
5234 ases[as].pins[i], j);
5236 ases[as].dacs[i] = j;
5245 * Trace input monitor path from mixer to output association.
5248 hdac_audio_trace_to_out(struct hdac_devinfo *devinfo, nid_t nid, int depth)
5250 struct hdac_audio_as *ases = devinfo->function.audio.as;
5251 struct hdac_widget *w, *wc;
5255 if (depth > HDA_PARSE_MAXDEPTH)
5257 w = hdac_widget_get(devinfo, nid);
5258 if (w == NULL || w->enable == 0)
5261 device_printf(devinfo->codec->sc->dev,
5262 " %*stracing via nid %d\n",
5263 depth + 1, "", w->nid);
5265 /* Use only unused widgets */
5266 if (depth > 0 && w->bindas != -1) {
5267 if (w->bindas < 0 || ases[w->bindas].dir == HDA_CTL_OUT) {
5269 device_printf(devinfo->codec->sc->dev,
5270 " %*snid %d found output association %d\n",
5271 depth + 1, "", w->nid, w->bindas);
5274 w->pflags |= HDA_ADC_MONITOR;
5278 device_printf(devinfo->codec->sc->dev,
5279 " %*snid %d busy by input association %d\n",
5280 depth + 1, "", w->nid, w->bindas);
5287 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT:
5288 /* Do not traverse input. AD1988 has digital monitor
5289 for which we are not ready. */
5291 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
5296 /* Try to find reachable ADCs with specified nid. */
5297 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
5298 wc = hdac_widget_get(devinfo, j);
5299 if (wc == NULL || wc->enable == 0)
5301 for (i = 0; i < wc->nconns; i++) {
5302 if (wc->connsenable[i] == 0)
5304 if (wc->conns[i] != nid)
5306 if (hdac_audio_trace_to_out(devinfo,
5307 j, depth + 1) != 0) {
5309 if (wc->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR &&
5317 if (res && w->bindas == -1)
5321 device_printf(devinfo->codec->sc->dev,
5322 " %*snid %d returned %d\n",
5323 depth + 1, "", w->nid, res);
5329 * Trace extra associations (beeper, monitor)
5332 hdac_audio_trace_as_extra(struct hdac_devinfo *devinfo)
5334 struct hdac_audio_as *as = devinfo->function.audio.as;
5335 struct hdac_widget *w;
5339 /* Find mixer associated with input, but supplying signal
5340 for output associations. Hope it will be input monitor. */
5342 device_printf(devinfo->codec->sc->dev,
5343 "Tracing input monitor\n");
5345 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
5346 w = hdac_widget_get(devinfo, j);
5347 if (w == NULL || w->enable == 0)
5349 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
5351 if (w->bindas < 0 || as[w->bindas].dir != HDA_CTL_IN)
5354 device_printf(devinfo->codec->sc->dev,
5355 " Tracing nid %d to out\n",
5358 if (hdac_audio_trace_to_out(devinfo, w->nid, 0)) {
5360 device_printf(devinfo->codec->sc->dev,
5361 " nid %d is input monitor\n",
5364 w->ossdev = SOUND_MIXER_IMIX;
5368 /* Other inputs monitor */
5369 /* Find input pins supplying signal for output associations.
5370 Hope it will be input monitoring. */
5372 device_printf(devinfo->codec->sc->dev,
5373 "Tracing other input monitors\n");
5375 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
5376 w = hdac_widget_get(devinfo, j);
5377 if (w == NULL || w->enable == 0)
5379 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
5381 if (w->bindas < 0 || as[w->bindas].dir != HDA_CTL_IN)
5384 device_printf(devinfo->codec->sc->dev,
5385 " Tracing nid %d to out\n",
5388 if (hdac_audio_trace_to_out(devinfo, w->nid, 0)) {
5390 device_printf(devinfo->codec->sc->dev,
5391 " nid %d is input monitor\n",
5399 device_printf(devinfo->codec->sc->dev,
5400 "Tracing beeper\n");
5402 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
5403 w = hdac_widget_get(devinfo, j);
5404 if (w == NULL || w->enable == 0)
5406 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET)
5409 device_printf(devinfo->codec->sc->dev,
5410 " Tracing nid %d to out\n",
5413 if (hdac_audio_trace_to_out(devinfo, w->nid, 0)) {
5415 device_printf(devinfo->codec->sc->dev,
5416 " nid %d traced to out\n",
5425 * Bind assotiations to PCM channels
5428 hdac_audio_bind_as(struct hdac_devinfo *devinfo)
5430 struct hdac_softc *sc = devinfo->codec->sc;
5431 struct hdac_audio_as *as = devinfo->function.audio.as;
5432 int j, cnt = 0, free;
5434 for (j = 0; j < devinfo->function.audio.ascnt; j++) {
5438 if (sc->num_chans == 0) {
5439 sc->chans = (struct hdac_chan *)malloc(
5440 sizeof(struct hdac_chan) * cnt,
5441 M_HDAC, M_ZERO | M_NOWAIT);
5442 if (sc->chans == NULL) {
5443 device_printf(sc->dev,
5444 "Channels memory allocation failed!\n");
5448 sc->chans = (struct hdac_chan *)realloc(sc->chans,
5449 sizeof(struct hdac_chan) * (sc->num_chans + cnt),
5450 M_HDAC, M_ZERO | M_NOWAIT);
5451 if (sc->chans == NULL) {
5453 device_printf(sc->dev,
5454 "Channels memory allocation failed!\n");
5457 /* Fixup relative pointers after realloc */
5458 for (j = 0; j < sc->num_chans; j++)
5459 sc->chans[j].caps.fmtlist = sc->chans[j].fmtlist;
5461 free = sc->num_chans;
5462 sc->num_chans += cnt;
5464 for (j = free; j < free + cnt; j++) {
5465 sc->chans[j].devinfo = devinfo;
5466 sc->chans[j].as = -1;
5469 /* Assign associations in order of their numbers, */
5470 for (j = 0; j < devinfo->function.audio.ascnt; j++) {
5471 if (as[j].enable == 0)
5475 sc->chans[free].as = j;
5476 sc->chans[free].dir =
5477 (as[j].dir == HDA_CTL_IN) ? PCMDIR_REC : PCMDIR_PLAY;
5478 hdac_pcmchannel_setup(&sc->chans[free]);
5484 hdac_audio_disable_nonaudio(struct hdac_devinfo *devinfo)
5486 struct hdac_widget *w;
5489 /* Disable power and volume widgets. */
5490 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5491 w = hdac_widget_get(devinfo, i);
5492 if (w == NULL || w->enable == 0)
5494 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_POWER_WIDGET ||
5495 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_VOLUME_WIDGET) {
5498 device_printf(devinfo->codec->sc->dev,
5499 " Disabling nid %d due to it's"
5500 " non-audio type.\n",
5508 hdac_audio_disable_useless(struct hdac_devinfo *devinfo)
5510 struct hdac_widget *w, *cw;
5511 struct hdac_audio_ctl *ctl;
5512 int done, found, i, j, k;
5514 /* Disable useless pins. */
5515 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5516 w = hdac_widget_get(devinfo, i);
5517 if (w == NULL || w->enable == 0)
5519 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) {
5520 if ((w->wclass.pin.config &
5521 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK) ==
5522 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_NONE) {
5525 device_printf(devinfo->codec->sc->dev,
5526 " Disabling pin nid %d due"
5527 " to None connectivity.\n",
5530 } else if ((w->wclass.pin.config &
5531 HDA_CONFIG_DEFAULTCONF_ASSOCIATION_MASK) == 0) {
5534 device_printf(devinfo->codec->sc->dev,
5535 " Disabling unassociated"
5544 /* Disable and mute controls for disabled widgets. */
5546 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) {
5547 if (ctl->enable == 0)
5549 if (ctl->widget->enable == 0 ||
5550 (ctl->childwidget != NULL &&
5551 ctl->childwidget->enable == 0)) {
5553 ctl->muted = HDA_AMP_MUTE_ALL;
5557 if (ctl->ndir == HDA_CTL_IN)
5558 ctl->widget->connsenable[ctl->index] = 0;
5561 device_printf(devinfo->codec->sc->dev,
5562 " Disabling ctl %d nid %d cnid %d due"
5563 " to disabled widget.\n", i,
5565 (ctl->childwidget != NULL)?
5566 ctl->childwidget->nid:-1);
5570 /* Disable useless widgets. */
5571 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5572 w = hdac_widget_get(devinfo, i);
5573 if (w == NULL || w->enable == 0)
5575 /* Disable inputs with disabled child widgets. */
5576 for (j = 0; j < w->nconns; j++) {
5577 if (w->connsenable[j]) {
5578 cw = hdac_widget_get(devinfo, w->conns[j]);
5579 if (cw == NULL || cw->enable == 0) {
5580 w->connsenable[j] = 0;
5582 device_printf(devinfo->codec->sc->dev,
5583 " Disabling nid %d connection %d due"
5584 " to disabled child widget.\n",
5590 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR &&
5591 w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
5593 /* Disable mixers and selectors without inputs. */
5595 for (j = 0; j < w->nconns; j++) {
5596 if (w->connsenable[j]) {
5605 device_printf(devinfo->codec->sc->dev,
5606 " Disabling nid %d due to all it's"
5607 " inputs disabled.\n", w->nid);
5610 /* Disable nodes without consumers. */
5611 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR &&
5612 w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
5615 for (k = devinfo->startnode; k < devinfo->endnode; k++) {
5616 cw = hdac_widget_get(devinfo, k);
5617 if (cw == NULL || cw->enable == 0)
5619 for (j = 0; j < cw->nconns; j++) {
5620 if (cw->connsenable[j] && cw->conns[j] == i) {
5630 device_printf(devinfo->codec->sc->dev,
5631 " Disabling nid %d due to all it's"
5632 " consumers disabled.\n", w->nid);
5636 } while (done == 0);
5641 hdac_audio_disable_unas(struct hdac_devinfo *devinfo)
5643 struct hdac_audio_as *as = devinfo->function.audio.as;
5644 struct hdac_widget *w, *cw;
5645 struct hdac_audio_ctl *ctl;
5648 /* Disable unassosiated widgets. */
5649 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5650 w = hdac_widget_get(devinfo, i);
5651 if (w == NULL || w->enable == 0)
5653 if (w->bindas == -1) {
5656 device_printf(devinfo->codec->sc->dev,
5657 " Disabling unassociated nid %d.\n",
5662 /* Disable input connections on input pin and
5663 * output on output. */
5664 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5665 w = hdac_widget_get(devinfo, i);
5666 if (w == NULL || w->enable == 0)
5668 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
5672 if (as[w->bindas].dir == HDA_CTL_IN) {
5673 for (j = 0; j < w->nconns; j++) {
5674 if (w->connsenable[j] == 0)
5676 w->connsenable[j] = 0;
5678 device_printf(devinfo->codec->sc->dev,
5679 " Disabling connection to input pin "
5680 "nid %d conn %d.\n",
5684 ctl = hdac_audio_ctl_amp_get(devinfo, w->nid,
5686 if (ctl && ctl->enable) {
5688 ctl->muted = HDA_AMP_MUTE_ALL;
5694 ctl = hdac_audio_ctl_amp_get(devinfo, w->nid,
5695 HDA_CTL_OUT, -1, 1);
5696 if (ctl && ctl->enable) {
5698 ctl->muted = HDA_AMP_MUTE_ALL;
5703 for (k = devinfo->startnode; k < devinfo->endnode; k++) {
5704 cw = hdac_widget_get(devinfo, k);
5705 if (cw == NULL || cw->enable == 0)
5707 for (j = 0; j < cw->nconns; j++) {
5708 if (cw->connsenable[j] && cw->conns[j] == i) {
5709 cw->connsenable[j] = 0;
5711 device_printf(devinfo->codec->sc->dev,
5712 " Disabling connection from output pin "
5713 "nid %d conn %d cnid %d.\n",
5716 if (cw->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
5719 ctl = hdac_audio_ctl_amp_get(devinfo, k,
5721 if (ctl && ctl->enable) {
5723 ctl->muted = HDA_AMP_MUTE_ALL;
5736 hdac_audio_disable_notselected(struct hdac_devinfo *devinfo)
5738 struct hdac_audio_as *as = devinfo->function.audio.as;
5739 struct hdac_widget *w;
5742 /* On playback path we can safely disable all unseleted inputs. */
5743 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5744 w = hdac_widget_get(devinfo, i);
5745 if (w == NULL || w->enable == 0)
5749 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
5751 if (w->bindas < 0 || as[w->bindas].dir == HDA_CTL_IN)
5753 for (j = 0; j < w->nconns; j++) {
5754 if (w->connsenable[j] == 0)
5756 if (w->selconn < 0 || w->selconn == j)
5758 w->connsenable[j] = 0;
5760 device_printf(devinfo->codec->sc->dev,
5761 " Disabling unselected connection "
5762 "nid %d conn %d.\n",
5770 hdac_audio_disable_crossas(struct hdac_devinfo *devinfo)
5772 struct hdac_audio_as *ases = devinfo->function.audio.as;
5773 struct hdac_widget *w, *cw;
5774 struct hdac_audio_ctl *ctl;
5777 /* Disable crossassociatement and unwanted crosschannel connections. */
5778 /* ... using selectors */
5779 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5780 w = hdac_widget_get(devinfo, i);
5781 if (w == NULL || w->enable == 0)
5785 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
5787 if (w->bindas == -2)
5789 for (j = 0; j < w->nconns; j++) {
5790 if (w->connsenable[j] == 0)
5792 cw = hdac_widget_get(devinfo, w->conns[j]);
5793 if (cw == NULL || w->enable == 0)
5795 if (cw->bindas == -2 ||
5796 ((w->pflags & HDA_ADC_MONITOR) &&
5798 ases[cw->bindas].dir == HDA_CTL_IN))
5800 if (w->bindas == cw->bindas &&
5801 (w->bindseqmask & cw->bindseqmask) != 0)
5803 w->connsenable[j] = 0;
5805 device_printf(devinfo->codec->sc->dev,
5806 " Disabling crossassociatement connection "
5807 "nid %d conn %d cnid %d.\n",
5812 /* ... using controls */
5814 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) {
5815 if (ctl->enable == 0 || ctl->childwidget == NULL)
5817 if (ctl->widget->bindas == -2)
5819 if (ctl->childwidget->bindas == -2 ||
5820 ((ctl->widget->pflags & HDA_ADC_MONITOR) &&
5821 ctl->childwidget->bindas >= 0 &&
5822 ases[ctl->childwidget->bindas].dir == HDA_CTL_IN))
5824 if (ctl->widget->bindas != ctl->childwidget->bindas ||
5825 (ctl->widget->bindseqmask & ctl->childwidget->bindseqmask) == 0) {
5827 ctl->muted = HDA_AMP_MUTE_ALL;
5831 if (ctl->ndir == HDA_CTL_IN)
5832 ctl->widget->connsenable[ctl->index] = 0;
5834 device_printf(devinfo->codec->sc->dev,
5835 " Disabling crossassociatement connection "
5836 "ctl %d nid %d cnid %d.\n", i,
5838 ctl->childwidget->nid);
5845 #define HDA_CTL_GIVE(ctl) ((ctl)->step?1:0)
5848 * Find controls to control amplification for source.
5851 hdac_audio_ctl_source_amp(struct hdac_devinfo *devinfo, nid_t nid, int index,
5852 int ossdev, int ctlable, int depth, int need)
5854 struct hdac_widget *w, *wc;
5855 struct hdac_audio_ctl *ctl;
5856 int i, j, conns = 0, rneed;
5858 if (depth > HDA_PARSE_MAXDEPTH)
5861 w = hdac_widget_get(devinfo, nid);
5862 if (w == NULL || w->enable == 0)
5865 /* Count number of active inputs. */
5867 for (j = 0; j < w->nconns; j++) {
5868 if (w->connsenable[j])
5873 /* If this is not a first step - use input mixer.
5874 Pins have common input ctl so care must be taken. */
5875 if (depth > 0 && ctlable && (conns == 1 ||
5876 w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)) {
5877 ctl = hdac_audio_ctl_amp_get(devinfo, w->nid, HDA_CTL_IN,
5880 if (HDA_CTL_GIVE(ctl) & need)
5881 ctl->ossmask |= (1 << ossdev);
5883 ctl->possmask |= (1 << ossdev);
5884 need &= ~HDA_CTL_GIVE(ctl);
5888 /* If widget has own ossdev - not traverse it.
5889 It will be traversed on it's own. */
5890 if (w->ossdev >= 0 && depth > 0)
5893 /* We must not traverse pin */
5894 if ((w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT ||
5895 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) &&
5899 /* record that this widget exports such signal, */
5900 w->ossmask |= (1 << ossdev);
5902 /* If signals mixed, we can't assign controls farther.
5903 * Ignore this on depth zero. Caller must knows why.
5904 * Ignore this for static selectors if this input selected.
5910 ctl = hdac_audio_ctl_amp_get(devinfo, w->nid, HDA_CTL_OUT, -1, 1);
5912 if (HDA_CTL_GIVE(ctl) & need)
5913 ctl->ossmask |= (1 << ossdev);
5915 ctl->possmask |= (1 << ossdev);
5916 need &= ~HDA_CTL_GIVE(ctl);
5921 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5922 wc = hdac_widget_get(devinfo, i);
5923 if (wc == NULL || wc->enable == 0)
5925 for (j = 0; j < wc->nconns; j++) {
5926 if (wc->connsenable[j] && wc->conns[j] == nid) {
5927 rneed |= hdac_audio_ctl_source_amp(devinfo,
5928 wc->nid, j, ossdev, ctlable, depth + 1, need);
5938 * Find controls to control amplification for destination.
5941 hdac_audio_ctl_dest_amp(struct hdac_devinfo *devinfo, nid_t nid, int index,
5942 int ossdev, int depth, int need)
5944 struct hdac_audio_as *as = devinfo->function.audio.as;
5945 struct hdac_widget *w, *wc;
5946 struct hdac_audio_ctl *ctl;
5947 int i, j, consumers;
5949 if (depth > HDA_PARSE_MAXDEPTH)
5952 w = hdac_widget_get(devinfo, nid);
5953 if (w == NULL || w->enable == 0)
5957 /* If this node produce output for several consumers,
5958 we can't touch it. */
5960 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5961 wc = hdac_widget_get(devinfo, i);
5962 if (wc == NULL || wc->enable == 0)
5964 for (j = 0; j < wc->nconns; j++) {
5965 if (wc->connsenable[j] && wc->conns[j] == nid)
5969 /* The only exception is if real HP redirection is configured
5970 and this is a duplication point.
5971 XXX: Actually exception is not completely correct.
5972 XXX: Duplication point check is not perfect. */
5973 if ((consumers == 2 && (w->bindas < 0 ||
5974 as[w->bindas].hpredir < 0 || as[w->bindas].fakeredir ||
5975 (w->bindseqmask & (1 << 15)) == 0)) ||
5979 /* Else use it's output mixer. */
5980 ctl = hdac_audio_ctl_amp_get(devinfo, w->nid,
5981 HDA_CTL_OUT, -1, 1);
5983 if (HDA_CTL_GIVE(ctl) & need)
5984 ctl->ossmask |= (1 << ossdev);
5986 ctl->possmask |= (1 << ossdev);
5987 need &= ~HDA_CTL_GIVE(ctl);
5991 /* We must not traverse pin */
5992 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
5996 for (i = 0; i < w->nconns; i++) {
5998 if (w->connsenable[i] == 0)
6000 if (index >= 0 && i != index)
6002 ctl = hdac_audio_ctl_amp_get(devinfo, w->nid,
6005 if (HDA_CTL_GIVE(ctl) & tneed)
6006 ctl->ossmask |= (1 << ossdev);
6008 ctl->possmask |= (1 << ossdev);
6009 tneed &= ~HDA_CTL_GIVE(ctl);
6011 hdac_audio_ctl_dest_amp(devinfo, w->conns[i], -1, ossdev,
6017 * Assign OSS names to sound sources
6020 hdac_audio_assign_names(struct hdac_devinfo *devinfo)
6022 struct hdac_audio_as *as = devinfo->function.audio.as;
6023 struct hdac_widget *w;
6025 int type = -1, use, used = 0;
6026 static const int types[7][13] = {
6027 { SOUND_MIXER_LINE, SOUND_MIXER_LINE1, SOUND_MIXER_LINE2,
6028 SOUND_MIXER_LINE3, -1 }, /* line */
6029 { SOUND_MIXER_MONITOR, SOUND_MIXER_MIC, -1 }, /* int mic */
6030 { SOUND_MIXER_MIC, SOUND_MIXER_MONITOR, -1 }, /* ext mic */
6031 { SOUND_MIXER_CD, -1 }, /* cd */
6032 { SOUND_MIXER_SPEAKER, -1 }, /* speaker */
6033 { SOUND_MIXER_DIGITAL1, SOUND_MIXER_DIGITAL2, SOUND_MIXER_DIGITAL3,
6035 { SOUND_MIXER_LINE, SOUND_MIXER_LINE1, SOUND_MIXER_LINE2,
6036 SOUND_MIXER_LINE3, SOUND_MIXER_PHONEIN, SOUND_MIXER_PHONEOUT,
6037 SOUND_MIXER_VIDEO, SOUND_MIXER_RADIO, SOUND_MIXER_DIGITAL1,
6038 SOUND_MIXER_DIGITAL2, SOUND_MIXER_DIGITAL3, SOUND_MIXER_MONITOR,
6042 /* Surely known names */
6043 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
6044 w = hdac_widget_get(devinfo, i);
6045 if (w == NULL || w->enable == 0)
6047 if (w->bindas == -1)
6051 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
6052 if (as[w->bindas].dir == HDA_CTL_OUT)
6055 switch (w->wclass.pin.config & HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) {
6056 case HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN:
6059 case HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN:
6060 if ((w->wclass.pin.config & HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK)
6061 == HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_JACK)
6065 case HDA_CONFIG_DEFAULTCONF_DEVICE_CD:
6068 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER:
6071 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_IN:
6072 case HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_IN:
6079 while (types[type][j] >= 0 &&
6080 (used & (1 << types[type][j])) != 0) {
6083 if (types[type][j] >= 0)
6084 use = types[type][j];
6086 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT:
6087 use = SOUND_MIXER_PCM;
6089 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET:
6090 use = SOUND_MIXER_SPEAKER;
6100 /* Semi-known names */
6101 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
6102 w = hdac_widget_get(devinfo, i);
6103 if (w == NULL || w->enable == 0)
6107 if (w->bindas == -1)
6109 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
6111 if (as[w->bindas].dir == HDA_CTL_OUT)
6114 switch (w->wclass.pin.config & HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) {
6115 case HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_OUT:
6116 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER:
6117 case HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT:
6118 case HDA_CONFIG_DEFAULTCONF_DEVICE_AUX:
6121 case HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN:
6124 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_OUT:
6125 case HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_OUT:
6132 while (types[type][j] >= 0 &&
6133 (used & (1 << types[type][j])) != 0) {
6136 if (types[type][j] >= 0) {
6137 w->ossdev = types[type][j];
6138 used |= (1 << types[type][j]);
6142 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
6143 w = hdac_widget_get(devinfo, i);
6144 if (w == NULL || w->enable == 0)
6148 if (w->bindas == -1)
6150 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
6152 if (as[w->bindas].dir == HDA_CTL_OUT)
6155 while (types[6][j] >= 0 &&
6156 (used & (1 << types[6][j])) != 0) {
6159 if (types[6][j] >= 0) {
6160 w->ossdev = types[6][j];
6161 used |= (1 << types[6][j]);
6167 hdac_audio_build_tree(struct hdac_devinfo *devinfo)
6169 struct hdac_audio_as *as = devinfo->function.audio.as;
6172 /* Trace all associations in order of their numbers, */
6173 for (j = 0; j < devinfo->function.audio.ascnt; j++) {
6174 if (as[j].enable == 0)
6177 device_printf(devinfo->codec->sc->dev,
6178 "Tracing association %d (%d)\n", j, as[j].index);
6180 if (as[j].dir == HDA_CTL_OUT) {
6182 res = hdac_audio_trace_as_out(devinfo, j, 0);
6183 if (res == 0 && as[j].hpredir >= 0 &&
6184 as[j].fakeredir == 0) {
6185 /* If codec can't do analog HP redirection
6186 try to make it using one more DAC. */
6187 as[j].fakeredir = 1;
6191 res = hdac_audio_trace_as_in(devinfo, j);
6195 device_printf(devinfo->codec->sc->dev,
6196 "Association %d (%d) trace succeeded\n",
6201 device_printf(devinfo->codec->sc->dev,
6202 "Association %d (%d) trace failed\n",
6209 /* Trace mixer and beeper pseudo associations. */
6210 hdac_audio_trace_as_extra(devinfo);
6214 hdac_audio_assign_mixers(struct hdac_devinfo *devinfo)
6216 struct hdac_audio_as *as = devinfo->function.audio.as;
6217 struct hdac_audio_ctl *ctl;
6218 struct hdac_widget *w, *cw;
6221 /* Assign mixers to the tree. */
6222 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
6223 w = hdac_widget_get(devinfo, i);
6224 if (w == NULL || w->enable == 0)
6226 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT ||
6227 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET ||
6228 (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
6229 as[w->bindas].dir == HDA_CTL_IN)) {
6232 hdac_audio_ctl_source_amp(devinfo, w->nid, -1,
6233 w->ossdev, 1, 0, 1);
6234 } else if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
6235 hdac_audio_ctl_dest_amp(devinfo, w->nid, -1,
6236 SOUND_MIXER_RECLEV, 0, 1);
6237 } else if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
6238 as[w->bindas].dir == HDA_CTL_OUT) {
6239 hdac_audio_ctl_dest_amp(devinfo, w->nid, -1,
6240 SOUND_MIXER_VOLUME, 0, 1);
6242 if (w->ossdev == SOUND_MIXER_IMIX) {
6243 if (hdac_audio_ctl_source_amp(devinfo, w->nid, -1,
6244 w->ossdev, 1, 0, 1)) {
6245 /* If we are unable to control input monitor
6246 as source - try to control it as destination. */
6247 hdac_audio_ctl_dest_amp(devinfo, w->nid, -1,
6251 if (w->pflags & HDA_ADC_MONITOR) {
6252 for (j = 0; j < w->nconns; j++) {
6253 if (!w->connsenable[j])
6255 cw = hdac_widget_get(devinfo, w->conns[j]);
6256 if (cw == NULL || cw->enable == 0)
6258 if (cw->bindas == -1)
6260 if (cw->bindas >= 0 &&
6261 as[cw->bindas].dir != HDA_CTL_IN)
6263 hdac_audio_ctl_dest_amp(devinfo,
6264 w->nid, j, SOUND_MIXER_IGAIN, 0, 1);
6268 /* Treat unrequired as possible. */
6270 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) {
6271 if (ctl->ossmask == 0)
6272 ctl->ossmask = ctl->possmask;
6277 hdac_audio_prepare_pin_ctrl(struct hdac_devinfo *devinfo)
6279 struct hdac_audio_as *as = devinfo->function.audio.as;
6280 struct hdac_widget *w;
6284 for (i = 0; i < devinfo->nodecnt; i++) {
6285 w = &devinfo->widget[i];
6288 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
6291 pincap = w->wclass.pin.cap;
6293 /* Disable everything. */
6294 w->wclass.pin.ctrl &= ~(
6295 HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE |
6296 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE |
6297 HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE |
6298 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK);
6300 if (w->enable == 0 ||
6301 w->bindas < 0 || as[w->bindas].enable == 0) {
6302 /* Pin is unused so left it disabled. */
6304 } else if (as[w->bindas].dir == HDA_CTL_IN) {
6305 /* Input pin, configure for input. */
6306 if (HDA_PARAM_PIN_CAP_INPUT_CAP(pincap))
6307 w->wclass.pin.ctrl |=
6308 HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE;
6310 if ((devinfo->function.audio.quirks & HDA_QUIRK_IVREF100) &&
6311 HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap))
6312 w->wclass.pin.ctrl |=
6313 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
6314 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_100);
6315 else if ((devinfo->function.audio.quirks & HDA_QUIRK_IVREF80) &&
6316 HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap))
6317 w->wclass.pin.ctrl |=
6318 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
6319 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_80);
6320 else if ((devinfo->function.audio.quirks & HDA_QUIRK_IVREF50) &&
6321 HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap))
6322 w->wclass.pin.ctrl |=
6323 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
6324 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_50);
6326 /* Output pin, configure for output. */
6327 if (HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap))
6328 w->wclass.pin.ctrl |=
6329 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
6331 if (HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap) &&
6332 (w->wclass.pin.config &
6333 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) ==
6334 HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT)
6335 w->wclass.pin.ctrl |=
6336 HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE;
6338 if ((devinfo->function.audio.quirks & HDA_QUIRK_OVREF100) &&
6339 HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap))
6340 w->wclass.pin.ctrl |=
6341 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
6342 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_100);
6343 else if ((devinfo->function.audio.quirks & HDA_QUIRK_OVREF80) &&
6344 HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap))
6345 w->wclass.pin.ctrl |=
6346 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
6347 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_80);
6348 else if ((devinfo->function.audio.quirks & HDA_QUIRK_OVREF50) &&
6349 HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap))
6350 w->wclass.pin.ctrl |=
6351 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
6352 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_50);
6358 hdac_audio_ctl_commit(struct hdac_devinfo *devinfo)
6360 struct hdac_audio_ctl *ctl;
6364 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) {
6365 if (ctl->enable == 0 || ctl->ossmask != 0) {
6366 /* Mute disabled and mixer controllable controls.
6367 * Last will be initialized by mixer_init().
6368 * This expected to reduce click on startup. */
6369 hdac_audio_ctl_amp_set(ctl, HDA_AMP_MUTE_ALL, 0, 0);
6372 /* Init fixed controls to 0dB amplification. */
6376 hdac_audio_ctl_amp_set(ctl, HDA_AMP_MUTE_NONE, z, z);
6381 hdac_audio_commit(struct hdac_devinfo *devinfo)
6383 struct hdac_softc *sc = devinfo->codec->sc;
6384 struct hdac_widget *w;
6386 uint32_t gdata, gmask, gdir;
6387 int commitgpio, numgpio;
6390 cad = devinfo->codec->cad;
6392 if (sc->pci_subvendor == APPLE_INTEL_MAC)
6393 hdac_command(sc, HDA_CMD_12BIT(cad, devinfo->nid,
6396 /* Commit controls. */
6397 hdac_audio_ctl_commit(devinfo);
6399 /* Commit selectors, pins and EAPD. */
6400 for (i = 0; i < devinfo->nodecnt; i++) {
6401 w = &devinfo->widget[i];
6404 if (w->selconn == -1)
6407 hdac_widget_connection_select(w, w->selconn);
6408 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) {
6410 HDA_CMD_SET_PIN_WIDGET_CTRL(cad, w->nid,
6411 w->wclass.pin.ctrl), cad);
6413 if (w->param.eapdbtl != HDAC_INVALID) {
6416 val = w->param.eapdbtl;
6417 if (devinfo->function.audio.quirks &
6419 val ^= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
6421 HDA_CMD_SET_EAPD_BTL_ENABLE(cad, w->nid,
6431 numgpio = HDA_PARAM_GPIO_COUNT_NUM_GPIO(
6432 devinfo->function.audio.gpio);
6434 if (devinfo->function.audio.quirks & HDA_QUIRK_GPIOFLUSH)
6435 commitgpio = (numgpio > 0) ? 1 : 0;
6437 for (i = 0; i < numgpio && i < HDA_GPIO_MAX; i++) {
6438 if (!(devinfo->function.audio.quirks &
6441 if (commitgpio == 0) {
6444 gdata = hdac_command(sc,
6445 HDA_CMD_GET_GPIO_DATA(cad,
6446 devinfo->nid), cad);
6447 gmask = hdac_command(sc,
6448 HDA_CMD_GET_GPIO_ENABLE_MASK(cad,
6449 devinfo->nid), cad);
6450 gdir = hdac_command(sc,
6451 HDA_CMD_GET_GPIO_DIRECTION(cad,
6452 devinfo->nid), cad);
6453 device_printf(sc->dev,
6454 "GPIO init: data=0x%08x "
6455 "mask=0x%08x dir=0x%08x\n",
6456 gdata, gmask, gdir);
6468 if (commitgpio != 0) {
6470 device_printf(sc->dev,
6471 "GPIO commit: data=0x%08x mask=0x%08x "
6473 gdata, gmask, gdir);
6476 HDA_CMD_SET_GPIO_ENABLE_MASK(cad, devinfo->nid,
6479 HDA_CMD_SET_GPIO_DIRECTION(cad, devinfo->nid,
6482 HDA_CMD_SET_GPIO_DATA(cad, devinfo->nid,
6488 hdac_powerup(struct hdac_devinfo *devinfo)
6490 struct hdac_softc *sc = devinfo->codec->sc;
6491 nid_t cad = devinfo->codec->cad;
6495 HDA_CMD_SET_POWER_STATE(cad,
6496 devinfo->nid, HDA_CMD_POWER_STATE_D0),
6500 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
6502 HDA_CMD_SET_POWER_STATE(cad,
6503 i, HDA_CMD_POWER_STATE_D0),
6510 hdac_pcmchannel_setup(struct hdac_chan *ch)
6512 struct hdac_devinfo *devinfo = ch->devinfo;
6513 struct hdac_audio_as *as = devinfo->function.audio.as;
6514 struct hdac_widget *w;
6515 uint32_t cap, fmtcap, pcmcap;
6516 int i, j, ret, channels, onlystereo;
6519 ch->caps = hdac_caps;
6520 ch->caps.fmtlist = ch->fmtlist;
6523 ch->pcmrates[0] = 48000;
6524 ch->pcmrates[1] = 0;
6530 fmtcap = devinfo->function.audio.supp_stream_formats;
6531 pcmcap = devinfo->function.audio.supp_pcm_size_rate;
6533 for (i = 0; i < 16; i++) {
6534 /* Check as is correct */
6537 /* Cound only present DACs */
6538 if (as[ch->as].dacs[i] <= 0)
6540 /* Ignore duplicates */
6541 for (j = 0; j < ret; j++) {
6542 if (ch->io[j] == as[ch->as].dacs[i])
6548 w = hdac_widget_get(devinfo, as[ch->as].dacs[i]);
6549 if (w == NULL || w->enable == 0)
6551 cap = w->param.supp_stream_formats;
6552 if (!HDA_PARAM_SUPP_STREAM_FORMATS_PCM(cap) &&
6553 !HDA_PARAM_SUPP_STREAM_FORMATS_AC3(cap))
6555 /* Many CODECs does not declare AC3 support on SPDIF.
6556 I don't beleave that they doesn't support it! */
6557 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap))
6558 cap |= HDA_PARAM_SUPP_STREAM_FORMATS_AC3_MASK;
6561 pcmcap = w->param.supp_pcm_size_rate;
6564 pcmcap &= w->param.supp_pcm_size_rate;
6566 ch->io[ret++] = as[ch->as].dacs[i];
6567 /* Do not count redirection pin/dac channels. */
6568 if (i == 15 && as[ch->as].hpredir >= 0)
6570 channels += HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap) + 1;
6571 if (HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap) != 1)
6577 if (as[ch->as].fakeredir)
6579 /* Standard speaks only about stereo pins and playback, ... */
6580 if ((!onlystereo) || as[ch->as].dir != HDA_CTL_OUT)
6582 /* ..., but there it gives us info about speakers layout. */
6583 as[ch->as].pinset = pinset;
6585 ch->supp_stream_formats = fmtcap;
6586 ch->supp_pcm_size_rate = pcmcap;
6597 if (HDA_PARAM_SUPP_STREAM_FORMATS_PCM(fmtcap)) {
6598 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16BIT(pcmcap))
6600 else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8BIT(pcmcap))
6602 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(pcmcap))
6604 else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(pcmcap))
6606 else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(pcmcap))
6608 if (!(devinfo->function.audio.quirks & HDA_QUIRK_FORCESTEREO)) {
6609 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 1, 0);
6611 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 1, 0);
6613 if (channels >= 2) {
6614 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 2, 0);
6616 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 2, 0);
6618 if (channels == 4 || /* Any 4-channel */
6619 pinset == 0x0007 || /* 5.1 */
6620 pinset == 0x0013 || /* 5.1 */
6621 pinset == 0x0017) { /* 7.1 */
6622 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 4, 0);
6624 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 4, 0);
6626 if (channels == 6 || /* Any 6-channel */
6627 pinset == 0x0017) { /* 7.1 */
6628 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 6, 1);
6630 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 6, 1);
6632 if (channels == 8) { /* Any 8-channel */
6633 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 8, 1);
6635 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 8, 1);
6638 if (HDA_PARAM_SUPP_STREAM_FORMATS_AC3(fmtcap)) {
6639 ch->fmtlist[i++] = SND_FORMAT(AFMT_AC3, 2, 0);
6643 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8KHZ(pcmcap))
6644 ch->pcmrates[i++] = 8000;
6645 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_11KHZ(pcmcap))
6646 ch->pcmrates[i++] = 11025;
6647 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16KHZ(pcmcap))
6648 ch->pcmrates[i++] = 16000;
6649 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_22KHZ(pcmcap))
6650 ch->pcmrates[i++] = 22050;
6651 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32KHZ(pcmcap))
6652 ch->pcmrates[i++] = 32000;
6653 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_44KHZ(pcmcap))
6654 ch->pcmrates[i++] = 44100;
6655 /* if (HDA_PARAM_SUPP_PCM_SIZE_RATE_48KHZ(pcmcap)) */
6656 ch->pcmrates[i++] = 48000;
6657 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_88KHZ(pcmcap))
6658 ch->pcmrates[i++] = 88200;
6659 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_96KHZ(pcmcap))
6660 ch->pcmrates[i++] = 96000;
6661 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_176KHZ(pcmcap))
6662 ch->pcmrates[i++] = 176400;
6663 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_192KHZ(pcmcap))
6664 ch->pcmrates[i++] = 192000;
6665 /* if (HDA_PARAM_SUPP_PCM_SIZE_RATE_384KHZ(pcmcap)) */
6666 ch->pcmrates[i] = 0;
6668 ch->caps.minspeed = ch->pcmrates[0];
6669 ch->caps.maxspeed = ch->pcmrates[i - 1];
6677 hdac_create_pcms(struct hdac_devinfo *devinfo)
6679 struct hdac_softc *sc = devinfo->codec->sc;
6680 struct hdac_audio_as *as = devinfo->function.audio.as;
6681 int i, j, apdev = 0, ardev = 0, dpdev = 0, drdev = 0;
6683 for (i = 0; i < devinfo->function.audio.ascnt; i++) {
6684 if (as[i].enable == 0)
6686 if (as[i].dir == HDA_CTL_IN) {
6698 devinfo->function.audio.num_devs =
6699 max(ardev, apdev) + max(drdev, dpdev);
6700 devinfo->function.audio.devs =
6701 (struct hdac_pcm_devinfo *)malloc(
6702 devinfo->function.audio.num_devs * sizeof(struct hdac_pcm_devinfo),
6703 M_HDAC, M_ZERO | M_NOWAIT);
6704 if (devinfo->function.audio.devs == NULL) {
6705 device_printf(sc->dev,
6706 "Unable to allocate memory for devices\n");
6709 for (i = 0; i < devinfo->function.audio.num_devs; i++) {
6710 devinfo->function.audio.devs[i].index = i;
6711 devinfo->function.audio.devs[i].devinfo = devinfo;
6712 devinfo->function.audio.devs[i].play = -1;
6713 devinfo->function.audio.devs[i].rec = -1;
6714 devinfo->function.audio.devs[i].digital = 255;
6716 for (i = 0; i < devinfo->function.audio.ascnt; i++) {
6717 if (as[i].enable == 0)
6719 for (j = 0; j < devinfo->function.audio.num_devs; j++) {
6720 if (devinfo->function.audio.devs[j].digital != 255 &&
6721 (!devinfo->function.audio.devs[j].digital) !=
6724 if (as[i].dir == HDA_CTL_IN) {
6725 if (devinfo->function.audio.devs[j].rec >= 0)
6727 devinfo->function.audio.devs[j].rec
6730 if (devinfo->function.audio.devs[j].play >= 0)
6732 devinfo->function.audio.devs[j].play
6735 sc->chans[as[i].chan].pdevinfo =
6736 &devinfo->function.audio.devs[j];
6737 devinfo->function.audio.devs[j].digital =
6742 for (i = 0; i < devinfo->function.audio.num_devs; i++) {
6743 struct hdac_pcm_devinfo *pdevinfo =
6744 &devinfo->function.audio.devs[i];
6746 device_add_child(sc->dev, "pcm", -1);
6747 device_set_ivars(pdevinfo->dev,
6753 hdac_dump_ctls(struct hdac_pcm_devinfo *pdevinfo, const char *banner, uint32_t flag)
6755 struct hdac_devinfo *devinfo = pdevinfo->devinfo;
6756 struct hdac_audio_ctl *ctl;
6757 struct hdac_softc *sc = devinfo->codec->sc;
6762 flag = ~(SOUND_MASK_VOLUME | SOUND_MASK_PCM |
6763 SOUND_MASK_CD | SOUND_MASK_LINE | SOUND_MASK_RECLEV |
6764 SOUND_MASK_MIC | SOUND_MASK_SPEAKER | SOUND_MASK_IGAIN |
6765 SOUND_MASK_OGAIN | SOUND_MASK_IMIX | SOUND_MASK_MONITOR);
6768 for (j = 0; j < SOUND_MIXER_NRDEVICES; j++) {
6769 if ((flag & (1 << j)) == 0)
6773 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) {
6774 if (ctl->enable == 0 ||
6775 ctl->widget->enable == 0)
6777 if (!((pdevinfo->play >= 0 &&
6778 ctl->widget->bindas == sc->chans[pdevinfo->play].as) ||
6779 (pdevinfo->rec >= 0 &&
6780 ctl->widget->bindas == sc->chans[pdevinfo->rec].as) ||
6781 (ctl->widget->bindas == -2 && pdevinfo->index == 0)))
6783 if ((ctl->ossmask & (1 << j)) == 0)
6787 device_printf(pdevinfo->dev, "\n");
6788 if (banner != NULL) {
6789 device_printf(pdevinfo->dev, "%s", banner);
6791 device_printf(pdevinfo->dev, "Unknown Ctl");
6793 printf(" (OSS: %s)\n",
6794 hdac_audio_ctl_ossmixer_mask2allname(1 << j,
6796 device_printf(pdevinfo->dev, " |\n");
6799 device_printf(pdevinfo->dev, " +- ctl %2d (nid %3d %s", i,
6801 (ctl->ndir == HDA_CTL_IN)?"in ":"out");
6802 if (ctl->ndir == HDA_CTL_IN && ctl->ndir == ctl->dir)
6803 printf(" %2d): ", ctl->index);
6806 if (ctl->step > 0) {
6807 printf("%+d/%+ddB (%d steps)%s\n",
6808 (0 - ctl->offset) * (ctl->size + 1) / 4,
6809 (ctl->step - ctl->offset) * (ctl->size + 1) / 4,
6811 ctl->mute?" + mute":"");
6813 printf("%s\n", ctl->mute?"mute":"");
6819 hdac_dump_audio_formats(device_t dev, uint32_t fcap, uint32_t pcmcap)
6825 device_printf(dev, " Stream cap: 0x%08x\n", cap);
6826 device_printf(dev, " ");
6827 if (HDA_PARAM_SUPP_STREAM_FORMATS_AC3(cap))
6829 if (HDA_PARAM_SUPP_STREAM_FORMATS_FLOAT32(cap))
6831 if (HDA_PARAM_SUPP_STREAM_FORMATS_PCM(cap))
6837 device_printf(dev, " PCM cap: 0x%08x\n", cap);
6838 device_printf(dev, " ");
6839 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8BIT(cap))
6841 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16BIT(cap))
6843 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(cap))
6845 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(cap))
6847 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(cap))
6850 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8KHZ(cap))
6852 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_11KHZ(cap))
6854 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16KHZ(cap))
6856 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_22KHZ(cap))
6858 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32KHZ(cap))
6860 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_44KHZ(cap))
6863 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_88KHZ(cap))
6865 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_96KHZ(cap))
6867 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_176KHZ(cap))
6869 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_192KHZ(cap))
6876 hdac_dump_pin(struct hdac_softc *sc, struct hdac_widget *w)
6880 pincap = w->wclass.pin.cap;
6882 device_printf(sc->dev, " Pin cap: 0x%08x\n", pincap);
6883 device_printf(sc->dev, " ");
6884 if (HDA_PARAM_PIN_CAP_IMP_SENSE_CAP(pincap))
6886 if (HDA_PARAM_PIN_CAP_TRIGGER_REQD(pincap))
6888 if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(pincap))
6890 if (HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap))
6892 if (HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap))
6894 if (HDA_PARAM_PIN_CAP_INPUT_CAP(pincap))
6896 if (HDA_PARAM_PIN_CAP_BALANCED_IO_PINS(pincap))
6898 if (HDA_PARAM_PIN_CAP_HDMI(pincap))
6900 if (HDA_PARAM_PIN_CAP_VREF_CTRL(pincap)) {
6902 if (HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap))
6904 if (HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap))
6906 if (HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap))
6908 if (HDA_PARAM_PIN_CAP_VREF_CTRL_GROUND(pincap))
6910 if (HDA_PARAM_PIN_CAP_VREF_CTRL_HIZ(pincap))
6914 if (HDA_PARAM_PIN_CAP_EAPD_CAP(pincap))
6916 if (HDA_PARAM_PIN_CAP_DP(pincap))
6918 if (HDA_PARAM_PIN_CAP_HBR(pincap))
6921 device_printf(sc->dev, " Pin config: 0x%08x\n",
6922 w->wclass.pin.config);
6923 device_printf(sc->dev, " Pin control: 0x%08x", w->wclass.pin.ctrl);
6924 if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE)
6926 if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE)
6928 if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE)
6930 if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK)
6936 hdac_dump_pin_config(struct hdac_widget *w, uint32_t conf)
6938 struct hdac_softc *sc = w->devinfo->codec->sc;
6940 device_printf(sc->dev, " nid %d 0x%08x as %2d seq %2d %13s %5s "
6941 "jack %2d loc %2d color %7s misc %d%s\n",
6943 HDA_CONFIG_DEFAULTCONF_ASSOCIATION(conf),
6944 HDA_CONFIG_DEFAULTCONF_SEQUENCE(conf),
6945 HDA_DEVS[HDA_CONFIG_DEFAULTCONF_DEVICE(conf)],
6946 HDA_CONNS[HDA_CONFIG_DEFAULTCONF_CONNECTIVITY(conf)],
6947 HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE(conf),
6948 HDA_CONFIG_DEFAULTCONF_LOCATION(conf),
6949 HDA_COLORS[HDA_CONFIG_DEFAULTCONF_COLOR(conf)],
6950 HDA_CONFIG_DEFAULTCONF_MISC(conf),
6951 (w->enable == 0)?" [DISABLED]":"");
6955 hdac_dump_pin_configs(struct hdac_devinfo *devinfo)
6957 struct hdac_widget *w;
6960 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
6961 w = hdac_widget_get(devinfo, i);
6964 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
6966 hdac_dump_pin_config(w, w->wclass.pin.config);
6971 hdac_dump_amp(struct hdac_softc *sc, uint32_t cap, char *banner)
6973 device_printf(sc->dev, " %s amp: 0x%08x\n", banner, cap);
6974 device_printf(sc->dev, " "
6975 "mute=%d step=%d size=%d offset=%d\n",
6976 HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(cap),
6977 HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(cap),
6978 HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(cap),
6979 HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(cap));
6983 hdac_dump_nodes(struct hdac_devinfo *devinfo)
6985 struct hdac_softc *sc = devinfo->codec->sc;
6986 static char *ossname[] = SOUND_DEVICE_NAMES;
6987 struct hdac_widget *w, *cw;
6991 device_printf(sc->dev, "\n");
6992 device_printf(sc->dev, "Default Parameter\n");
6993 device_printf(sc->dev, "-----------------\n");
6994 hdac_dump_audio_formats(sc->dev,
6995 devinfo->function.audio.supp_stream_formats,
6996 devinfo->function.audio.supp_pcm_size_rate);
6997 device_printf(sc->dev, " IN amp: 0x%08x\n",
6998 devinfo->function.audio.inamp_cap);
6999 device_printf(sc->dev, " OUT amp: 0x%08x\n",
7000 devinfo->function.audio.outamp_cap);
7001 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
7002 w = hdac_widget_get(devinfo, i);
7004 device_printf(sc->dev, "Ghost widget nid=%d\n", i);
7007 device_printf(sc->dev, "\n");
7008 device_printf(sc->dev, " nid: %d%s\n", w->nid,
7009 (w->enable == 0) ? " [DISABLED]" : "");
7010 device_printf(sc->dev, " Name: %s\n", w->name);
7011 device_printf(sc->dev, " Widget cap: 0x%08x\n",
7012 w->param.widget_cap);
7013 if (w->param.widget_cap & 0x0ee1) {
7014 device_printf(sc->dev, " ");
7015 if (HDA_PARAM_AUDIO_WIDGET_CAP_LR_SWAP(w->param.widget_cap))
7017 if (HDA_PARAM_AUDIO_WIDGET_CAP_POWER_CTRL(w->param.widget_cap))
7019 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap))
7021 if (HDA_PARAM_AUDIO_WIDGET_CAP_UNSOL_CAP(w->param.widget_cap))
7023 if (HDA_PARAM_AUDIO_WIDGET_CAP_PROC_WIDGET(w->param.widget_cap))
7025 if (HDA_PARAM_AUDIO_WIDGET_CAP_STRIPE(w->param.widget_cap))
7027 j = HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap);
7031 printf(" %dCH", j + 1);
7034 if (w->bindas != -1) {
7035 device_printf(sc->dev, " Association: %d (0x%08x)\n",
7036 w->bindas, w->bindseqmask);
7038 if (w->ossmask != 0 || w->ossdev >= 0) {
7039 device_printf(sc->dev, " OSS: %s",
7040 hdac_audio_ctl_ossmixer_mask2allname(w->ossmask, buf, sizeof(buf)));
7042 printf(" (%s)", ossname[w->ossdev]);
7045 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT ||
7046 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
7047 hdac_dump_audio_formats(sc->dev,
7048 w->param.supp_stream_formats,
7049 w->param.supp_pcm_size_rate);
7050 } else if (w->type ==
7051 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
7052 hdac_dump_pin(sc, w);
7053 if (w->param.eapdbtl != HDAC_INVALID)
7054 device_printf(sc->dev, " EAPD: 0x%08x\n",
7056 if (HDA_PARAM_AUDIO_WIDGET_CAP_OUT_AMP(w->param.widget_cap) &&
7057 w->param.outamp_cap != 0)
7058 hdac_dump_amp(sc, w->param.outamp_cap, "Output");
7059 if (HDA_PARAM_AUDIO_WIDGET_CAP_IN_AMP(w->param.widget_cap) &&
7060 w->param.inamp_cap != 0)
7061 hdac_dump_amp(sc, w->param.inamp_cap, " Input");
7062 if (w->nconns > 0) {
7063 device_printf(sc->dev, " connections: %d\n", w->nconns);
7064 device_printf(sc->dev, " |\n");
7066 for (j = 0; j < w->nconns; j++) {
7067 cw = hdac_widget_get(devinfo, w->conns[j]);
7068 device_printf(sc->dev, " + %s<- nid=%d [%s]",
7069 (w->connsenable[j] == 0)?"[DISABLED] ":"",
7070 w->conns[j], (cw == NULL) ? "GHOST!" : cw->name);
7072 printf(" [UNKNOWN]");
7073 else if (cw->enable == 0)
7074 printf(" [DISABLED]");
7075 if (w->nconns > 1 && w->selconn == j && w->type !=
7076 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
7077 printf(" (selected)");
7085 hdac_dump_dst_nid(struct hdac_pcm_devinfo *pdevinfo, nid_t nid, int depth)
7087 struct hdac_devinfo *devinfo = pdevinfo->devinfo;
7088 struct hdac_widget *w, *cw;
7092 if (depth > HDA_PARSE_MAXDEPTH)
7095 w = hdac_widget_get(devinfo, nid);
7096 if (w == NULL || w->enable == 0)
7100 device_printf(pdevinfo->dev, "%*s", 4, "");
7102 device_printf(pdevinfo->dev, "%*s + <- ", 4 + (depth - 1) * 7, "");
7103 printf("nid=%d [%s]", w->nid, w->name);
7106 if (w->ossmask == 0) {
7110 printf(" [src: %s]",
7111 hdac_audio_ctl_ossmixer_mask2allname(
7112 w->ossmask, buf, sizeof(buf)));
7113 if (w->ossdev >= 0) {
7120 for (i = 0; i < w->nconns; i++) {
7121 if (w->connsenable[i] == 0)
7123 cw = hdac_widget_get(devinfo, w->conns[i]);
7124 if (cw == NULL || cw->enable == 0 || cw->bindas == -1)
7127 device_printf(pdevinfo->dev, "%*s |\n", 4 + (depth) * 7, "");
7130 hdac_dump_dst_nid(pdevinfo, w->conns[i], depth + 1);
7136 hdac_dump_dac(struct hdac_pcm_devinfo *pdevinfo)
7138 struct hdac_devinfo *devinfo = pdevinfo->devinfo;
7139 struct hdac_softc *sc = devinfo->codec->sc;
7140 struct hdac_audio_as *as;
7141 struct hdac_widget *w;
7144 if (pdevinfo->play < 0)
7147 as = &devinfo->function.audio.as[sc->chans[pdevinfo->play].as];
7148 for (i = 0; i < 16; i++) {
7149 if (as->pins[i] <= 0)
7151 w = hdac_widget_get(devinfo, as->pins[i]);
7152 if (w == NULL || w->enable == 0)
7156 device_printf(pdevinfo->dev, "\n");
7157 device_printf(pdevinfo->dev, "Playback:\n");
7159 device_printf(pdevinfo->dev, "\n");
7160 hdac_dump_dst_nid(pdevinfo, as->pins[i], 0);
7165 hdac_dump_adc(struct hdac_pcm_devinfo *pdevinfo)
7167 struct hdac_devinfo *devinfo = pdevinfo->devinfo;
7168 struct hdac_softc *sc = devinfo->codec->sc;
7169 struct hdac_widget *w;
7173 if (pdevinfo->rec < 0)
7176 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
7177 w = hdac_widget_get(devinfo, i);
7178 if (w == NULL || w->enable == 0)
7180 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT)
7182 if (w->bindas != sc->chans[pdevinfo->rec].as)
7186 device_printf(pdevinfo->dev, "\n");
7187 device_printf(pdevinfo->dev, "Record:\n");
7189 device_printf(pdevinfo->dev, "\n");
7190 hdac_dump_dst_nid(pdevinfo, i, 0);
7195 hdac_dump_mix(struct hdac_pcm_devinfo *pdevinfo)
7197 struct hdac_devinfo *devinfo = pdevinfo->devinfo;
7198 struct hdac_widget *w;
7202 if (pdevinfo->index != 0)
7205 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
7206 w = hdac_widget_get(devinfo, i);
7207 if (w == NULL || w->enable == 0)
7209 if (w->ossdev != SOUND_MIXER_IMIX)
7213 device_printf(pdevinfo->dev, "\n");
7214 device_printf(pdevinfo->dev, "Input Mix:\n");
7216 device_printf(pdevinfo->dev, "\n");
7217 hdac_dump_dst_nid(pdevinfo, i, 0);
7222 hdac_dump_pcmchannels(struct hdac_pcm_devinfo *pdevinfo)
7224 struct hdac_softc *sc = pdevinfo->devinfo->codec->sc;
7228 if (pdevinfo->play >= 0) {
7230 device_printf(pdevinfo->dev, "\n");
7231 device_printf(pdevinfo->dev, "Playback:\n");
7232 device_printf(pdevinfo->dev, "\n");
7233 hdac_dump_audio_formats(pdevinfo->dev, sc->chans[i].supp_stream_formats,
7234 sc->chans[i].supp_pcm_size_rate);
7235 device_printf(pdevinfo->dev, " DAC:");
7236 for (nids = sc->chans[i].io; *nids != -1; nids++)
7237 printf(" %d", *nids);
7240 if (pdevinfo->rec >= 0) {
7242 device_printf(pdevinfo->dev, "\n");
7243 device_printf(pdevinfo->dev, "Record:\n");
7244 device_printf(pdevinfo->dev, "\n");
7245 hdac_dump_audio_formats(pdevinfo->dev, sc->chans[i].supp_stream_formats,
7246 sc->chans[i].supp_pcm_size_rate);
7247 device_printf(pdevinfo->dev, " ADC:");
7248 for (nids = sc->chans[i].io; *nids != -1; nids++)
7249 printf(" %d", *nids);
7255 hdac_release_resources(struct hdac_softc *sc)
7265 callout_stop(&sc->poll_hda);
7266 callout_stop(&sc->poll_hdac);
7267 callout_stop(&sc->poll_jack);
7270 taskqueue_drain(taskqueue_thread, &sc->unsolq_task);
7271 callout_drain(&sc->poll_hda);
7272 callout_drain(&sc->poll_hdac);
7273 callout_drain(&sc->poll_jack);
7277 for (i = 0; i < HDAC_CODEC_MAX; i++) {
7278 if (sc->codecs[i] == NULL)
7280 for (j = 0; j < sc->codecs[i]->num_fgs; j++) {
7281 free(sc->codecs[i]->fgs[j].widget, M_HDAC);
7282 if (sc->codecs[i]->fgs[j].node_type ==
7283 HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO) {
7284 free(sc->codecs[i]->fgs[j].function.audio.ctl,
7286 free(sc->codecs[i]->fgs[j].function.audio.as,
7288 free(sc->codecs[i]->fgs[j].function.audio.devs,
7292 free(sc->codecs[i]->fgs, M_HDAC);
7293 free(sc->codecs[i], M_HDAC);
7294 sc->codecs[i] = NULL;
7297 hdac_dma_free(sc, &sc->pos_dma);
7298 hdac_dma_free(sc, &sc->rirb_dma);
7299 hdac_dma_free(sc, &sc->corb_dma);
7300 for (i = 0; i < sc->num_chans; i++) {
7301 if (sc->chans[i].blkcnt > 0)
7302 hdac_dma_free(sc, &sc->chans[i].bdl_dma);
7304 free(sc->chans, M_HDAC);
7305 if (sc->chan_dmat != NULL) {
7306 bus_dma_tag_destroy(sc->chan_dmat);
7307 sc->chan_dmat = NULL;
7310 snd_mtxfree(sc->lock);
7313 /* This function surely going to make its way into upper level someday. */
7315 hdac_config_fetch(struct hdac_softc *sc, uint32_t *on, uint32_t *off)
7317 const char *res = NULL;
7318 int i = 0, j, k, len, inv;
7326 if (resource_string_value(device_get_name(sc->dev),
7327 device_get_unit(sc->dev), "config", &res) != 0)
7329 if (!(res != NULL && strlen(res) > 0))
7332 device_printf(sc->dev, "HDA Config:");
7335 while (res[i] != '\0' &&
7336 (res[i] == ',' || isspace(res[i]) != 0))
7338 if (res[i] == '\0') {
7345 while (res[j] != '\0' &&
7346 !(res[j] == ',' || isspace(res[j]) != 0))
7349 if (len > 2 && strncmp(res + i, "no", 2) == 0)
7353 for (k = 0; len > inv && k < HDAC_QUIRKS_TAB_LEN; k++) {
7354 if (strncmp(res + i + inv,
7355 hdac_quirks_tab[k].key, len - inv) != 0)
7357 if (len - inv != strlen(hdac_quirks_tab[k].key))
7360 printf(" %s%s", (inv != 0) ? "no" : "",
7361 hdac_quirks_tab[k].key);
7363 if (inv == 0 && on != NULL)
7364 *on |= hdac_quirks_tab[k].value;
7365 else if (inv != 0 && off != NULL)
7366 *off |= hdac_quirks_tab[k].value;
7374 sysctl_hdac_polling(SYSCTL_HANDLER_ARGS)
7376 struct hdac_softc *sc;
7381 dev = oidp->oid_arg1;
7382 sc = device_get_softc(dev);
7388 err = sysctl_handle_int(oidp, &val, 0, req);
7390 if (err != 0 || req->newptr == NULL)
7392 if (val < 0 || val > 1)
7396 if (val != sc->polling) {
7398 callout_stop(&sc->poll_hda);
7399 callout_stop(&sc->poll_hdac);
7401 callout_drain(&sc->poll_hda);
7402 callout_drain(&sc->poll_hdac);
7405 ctl = HDAC_READ_4(&sc->mem, HDAC_INTCTL);
7406 ctl |= HDAC_INTCTL_GIE;
7407 HDAC_WRITE_4(&sc->mem, HDAC_INTCTL, ctl);
7409 ctl = HDAC_READ_4(&sc->mem, HDAC_INTCTL);
7410 ctl &= ~HDAC_INTCTL_GIE;
7411 HDAC_WRITE_4(&sc->mem, HDAC_INTCTL, ctl);
7413 taskqueue_drain(taskqueue_thread, &sc->unsolq_task);
7416 hdac_poll_reinit(sc);
7417 callout_reset(&sc->poll_hdac, 1, hdac_poll_callback, sc);
7426 sysctl_hdac_polling_interval(SYSCTL_HANDLER_ARGS)
7428 struct hdac_softc *sc;
7432 dev = oidp->oid_arg1;
7433 sc = device_get_softc(dev);
7437 val = ((uint64_t)sc->poll_ival * 1000) / hz;
7439 err = sysctl_handle_int(oidp, &val, 0, req);
7441 if (err != 0 || req->newptr == NULL)
7448 val = ((uint64_t)val * hz) / 1000;
7455 sc->poll_ival = val;
7462 sysctl_hdac_pindump(SYSCTL_HANDLER_ARGS)
7464 struct hdac_softc *sc;
7465 struct hdac_codec *codec;
7466 struct hdac_devinfo *devinfo;
7467 struct hdac_widget *w;
7469 uint32_t res, pincap, delay;
7470 int codec_index, fg_index;
7474 dev = oidp->oid_arg1;
7475 sc = device_get_softc(dev);
7479 err = sysctl_handle_int(oidp, &val, 0, req);
7480 if (err != 0 || req->newptr == NULL || val == 0)
7483 /* XXX: Temporary. For debugging. */
7487 } else if (val == 101) {
7493 for (codec_index = 0; codec_index < HDAC_CODEC_MAX; codec_index++) {
7494 codec = sc->codecs[codec_index];
7498 for (fg_index = 0; fg_index < codec->num_fgs; fg_index++) {
7499 devinfo = &codec->fgs[fg_index];
7500 if (devinfo->node_type !=
7501 HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO)
7504 device_printf(dev, "Dumping AFG cad=%d nid=%d pins:\n",
7505 codec_index, devinfo->nid);
7506 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
7507 w = hdac_widget_get(devinfo, i);
7508 if (w == NULL || w->type !=
7509 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
7511 hdac_dump_pin_config(w, w->wclass.pin.config);
7512 pincap = w->wclass.pin.cap;
7513 device_printf(dev, " Caps: %2s %3s %2s %4s %4s",
7514 HDA_PARAM_PIN_CAP_INPUT_CAP(pincap)?"IN":"",
7515 HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap)?"OUT":"",
7516 HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap)?"HP":"",
7517 HDA_PARAM_PIN_CAP_EAPD_CAP(pincap)?"EAPD":"",
7518 HDA_PARAM_PIN_CAP_VREF_CTRL(pincap)?"VREF":"");
7519 if (HDA_PARAM_PIN_CAP_IMP_SENSE_CAP(pincap) ||
7520 HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(pincap)) {
7521 if (HDA_PARAM_PIN_CAP_TRIGGER_REQD(pincap)) {
7524 HDA_CMD_SET_PIN_SENSE(cad, w->nid, 0), cad);
7526 res = hdac_command(sc,
7527 HDA_CMD_GET_PIN_SENSE(cad, w->nid), cad);
7528 if (res != 0x7fffffff && res != 0xffffffff)
7531 } while (++delay < 10000);
7534 res = hdac_command(sc, HDA_CMD_GET_PIN_SENSE(cad,
7537 printf(" Sense: 0x%08x", res);
7539 printf(" delay %dus", delay * 10);
7544 "NumGPIO=%d NumGPO=%d NumGPI=%d GPIWake=%d GPIUnsol=%d\n",
7545 HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->function.audio.gpio),
7546 HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->function.audio.gpio),
7547 HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->function.audio.gpio),
7548 HDA_PARAM_GPIO_COUNT_GPI_WAKE(devinfo->function.audio.gpio),
7549 HDA_PARAM_GPIO_COUNT_GPI_UNSOL(devinfo->function.audio.gpio));
7550 if (HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->function.audio.gpio) > 0) {
7551 device_printf(dev, " GPI:");
7552 res = hdac_command(sc,
7553 HDA_CMD_GET_GPI_DATA(cad, devinfo->nid), cad);
7554 printf(" data=0x%08x", res);
7555 res = hdac_command(sc,
7556 HDA_CMD_GET_GPI_WAKE_ENABLE_MASK(cad, devinfo->nid),
7558 printf(" wake=0x%08x", res);
7559 res = hdac_command(sc,
7560 HDA_CMD_GET_GPI_UNSOLICITED_ENABLE_MASK(cad, devinfo->nid),
7562 printf(" unsol=0x%08x", res);
7563 res = hdac_command(sc,
7564 HDA_CMD_GET_GPI_STICKY_MASK(cad, devinfo->nid), cad);
7565 printf(" sticky=0x%08x\n", res);
7567 if (HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->function.audio.gpio) > 0) {
7568 device_printf(dev, " GPO:");
7569 res = hdac_command(sc,
7570 HDA_CMD_GET_GPO_DATA(cad, devinfo->nid), cad);
7571 printf(" data=0x%08x\n", res);
7573 if (HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->function.audio.gpio) > 0) {
7574 device_printf(dev, "GPIO:");
7575 res = hdac_command(sc,
7576 HDA_CMD_GET_GPIO_DATA(cad, devinfo->nid), cad);
7577 printf(" data=0x%08x", res);
7578 res = hdac_command(sc,
7579 HDA_CMD_GET_GPIO_ENABLE_MASK(cad, devinfo->nid), cad);
7580 printf(" enable=0x%08x", res);
7581 res = hdac_command(sc,
7582 HDA_CMD_GET_GPIO_DIRECTION(cad, devinfo->nid), cad);
7583 printf(" direction=0x%08x\n", res);
7584 res = hdac_command(sc,
7585 HDA_CMD_GET_GPIO_WAKE_ENABLE_MASK(cad, devinfo->nid), cad);
7586 device_printf(dev, " wake=0x%08x", res);
7587 res = hdac_command(sc,
7588 HDA_CMD_GET_GPIO_UNSOLICITED_ENABLE_MASK(cad, devinfo->nid),
7590 printf(" unsol=0x%08x", res);
7591 res = hdac_command(sc,
7592 HDA_CMD_GET_GPIO_STICKY_MASK(cad, devinfo->nid), cad);
7593 printf(" sticky=0x%08x\n", res);
7602 hdac_attach2(void *arg)
7604 struct hdac_codec *codec;
7605 struct hdac_softc *sc;
7606 struct hdac_audio_ctl *ctl;
7607 uint32_t quirks_on, quirks_off;
7608 int codec_index, fg_index;
7609 int i, dmaalloc = 0;
7610 struct hdac_devinfo *devinfo;
7612 sc = (struct hdac_softc *)arg;
7614 hdac_config_fetch(sc, &quirks_on, &quirks_off);
7617 device_printf(sc->dev, "HDA Config: on=0x%08x off=0x%08x\n",
7618 quirks_on, quirks_off);
7623 /* Remove ourselves from the config hooks */
7624 if (sc->intrhook.ich_func != NULL) {
7625 config_intrhook_disestablish(&sc->intrhook);
7626 sc->intrhook.ich_func = NULL;
7629 /* Start the corb and rirb engines */
7631 device_printf(sc->dev, "Starting CORB Engine...\n");
7633 hdac_corb_start(sc);
7635 device_printf(sc->dev, "Starting RIRB Engine...\n");
7637 hdac_rirb_start(sc);
7640 device_printf(sc->dev,
7641 "Enabling controller interrupt...\n");
7643 HDAC_WRITE_4(&sc->mem, HDAC_GCTL, HDAC_READ_4(&sc->mem, HDAC_GCTL) |
7645 if (sc->polling == 0) {
7646 HDAC_WRITE_4(&sc->mem, HDAC_INTCTL,
7647 HDAC_INTCTL_CIE | HDAC_INTCTL_GIE);
7649 callout_reset(&sc->poll_hdac, 1, hdac_poll_callback, sc);
7654 device_printf(sc->dev,
7655 "Scanning HDA codecs ...\n");
7657 hdac_scan_codecs(sc);
7659 for (codec_index = 0; codec_index < HDAC_CODEC_MAX; codec_index++) {
7660 codec = sc->codecs[codec_index];
7663 for (fg_index = 0; fg_index < codec->num_fgs; fg_index++) {
7664 devinfo = &codec->fgs[fg_index];
7666 device_printf(sc->dev, "\n");
7667 device_printf(sc->dev,
7668 "Processing %s FG cad=%d nid=%d...\n",
7669 (devinfo->node_type == HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO) ? "audio":
7670 (devinfo->node_type == HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_MODEM) ? "modem":
7672 devinfo->codec->cad, devinfo->nid);
7674 if (devinfo->node_type !=
7675 HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO) {
7677 device_printf(sc->dev,
7678 "Powering down...\n");
7681 HDA_CMD_SET_POWER_STATE(codec->cad,
7682 devinfo->nid, HDA_CMD_POWER_STATE_D3),
7688 device_printf(sc->dev, "Powering up...\n");
7690 hdac_powerup(devinfo);
7692 device_printf(sc->dev, "Parsing audio FG...\n");
7694 hdac_audio_parse(devinfo);
7696 device_printf(sc->dev, "Parsing Ctls...\n");
7698 hdac_audio_ctl_parse(devinfo);
7700 device_printf(sc->dev, "Parsing vendor patch...\n");
7702 hdac_vendor_patch_parse(devinfo);
7703 devinfo->function.audio.quirks |= quirks_on;
7704 devinfo->function.audio.quirks &= ~quirks_off;
7707 device_printf(sc->dev, "Disabling nonaudio...\n");
7709 hdac_audio_disable_nonaudio(devinfo);
7711 device_printf(sc->dev, "Disabling useless...\n");
7713 hdac_audio_disable_useless(devinfo);
7715 device_printf(sc->dev, "Patched pins configuration:\n");
7716 hdac_dump_pin_configs(devinfo);
7719 device_printf(sc->dev, "Parsing pin associations...\n");
7721 hdac_audio_as_parse(devinfo);
7723 device_printf(sc->dev, "Building AFG tree...\n");
7725 hdac_audio_build_tree(devinfo);
7727 device_printf(sc->dev, "Disabling unassociated "
7730 hdac_audio_disable_unas(devinfo);
7732 device_printf(sc->dev, "Disabling nonselected "
7735 hdac_audio_disable_notselected(devinfo);
7737 device_printf(sc->dev, "Disabling useless...\n");
7739 hdac_audio_disable_useless(devinfo);
7741 device_printf(sc->dev, "Disabling "
7742 "crossassociatement connections...\n");
7744 hdac_audio_disable_crossas(devinfo);
7746 device_printf(sc->dev, "Disabling useless...\n");
7748 hdac_audio_disable_useless(devinfo);
7750 device_printf(sc->dev, "Binding associations to channels...\n");
7752 hdac_audio_bind_as(devinfo);
7754 device_printf(sc->dev, "Assigning names to signal sources...\n");
7756 hdac_audio_assign_names(devinfo);
7758 device_printf(sc->dev, "Assigning mixers to the tree...\n");
7760 hdac_audio_assign_mixers(devinfo);
7762 device_printf(sc->dev, "Preparing pin controls...\n");
7764 hdac_audio_prepare_pin_ctrl(devinfo);
7766 device_printf(sc->dev, "AFG commit...\n");
7768 hdac_audio_commit(devinfo);
7770 device_printf(sc->dev, "HP switch init...\n");
7772 hdac_hp_switch_init(devinfo);
7774 if ((devinfo->function.audio.quirks & HDA_QUIRK_DMAPOS) &&
7776 if (hdac_dma_alloc(sc, &sc->pos_dma,
7777 (sc->num_iss + sc->num_oss + sc->num_bss) * 8) != 0) {
7779 device_printf(sc->dev, "Failed to "
7780 "allocate DMA pos buffer "
7788 device_printf(sc->dev, "Creating PCM devices...\n");
7790 hdac_create_pcms(devinfo);
7793 if (devinfo->function.audio.quirks != 0) {
7794 device_printf(sc->dev, "FG config/quirks:");
7795 for (i = 0; i < HDAC_QUIRKS_TAB_LEN; i++) {
7796 if ((devinfo->function.audio.quirks &
7797 hdac_quirks_tab[i].value) ==
7798 hdac_quirks_tab[i].value)
7799 printf(" %s", hdac_quirks_tab[i].key);
7804 device_printf(sc->dev, "\n");
7805 device_printf(sc->dev, "+-------------------+\n");
7806 device_printf(sc->dev, "| DUMPING HDA NODES |\n");
7807 device_printf(sc->dev, "+-------------------+\n");
7808 hdac_dump_nodes(devinfo);
7812 device_printf(sc->dev, "\n");
7813 device_printf(sc->dev, "+------------------------+\n");
7814 device_printf(sc->dev, "| DUMPING HDA AMPLIFIERS |\n");
7815 device_printf(sc->dev, "+------------------------+\n");
7816 device_printf(sc->dev, "\n");
7818 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) {
7819 device_printf(sc->dev, "%3d: nid %3d %s (%s) index %d", i,
7820 (ctl->widget != NULL) ? ctl->widget->nid : -1,
7821 (ctl->ndir == HDA_CTL_IN)?"in ":"out",
7822 (ctl->dir == HDA_CTL_IN)?"in ":"out",
7824 if (ctl->childwidget != NULL)
7825 printf(" cnid %3d", ctl->childwidget->nid);
7828 printf(" ossmask=0x%08x\n",
7830 device_printf(sc->dev,
7831 " mute: %d step: %3d size: %3d off: %3d%s\n",
7832 ctl->mute, ctl->step, ctl->size, ctl->offset,
7833 (ctl->enable == 0) ? " [DISABLED]" :
7834 ((ctl->ossmask == 0) ? " [UNUSED]" : ""));
7842 device_printf(sc->dev, "\n");
7845 bus_generic_attach(sc->dev);
7847 SYSCTL_ADD_PROC(device_get_sysctl_ctx(sc->dev),
7848 SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev)), OID_AUTO,
7849 "polling", CTLTYPE_INT | CTLFLAG_RW, sc->dev, sizeof(sc->dev),
7850 sysctl_hdac_polling, "I", "Enable polling mode");
7851 SYSCTL_ADD_PROC(device_get_sysctl_ctx(sc->dev),
7852 SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev)), OID_AUTO,
7853 "polling_interval", CTLTYPE_INT | CTLFLAG_RW, sc->dev,
7854 sizeof(sc->dev), sysctl_hdac_polling_interval, "I",
7855 "Controller/Jack Sense polling interval (1-1000 ms)");
7856 SYSCTL_ADD_PROC(device_get_sysctl_ctx(sc->dev),
7857 SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev)), OID_AUTO,
7858 "pindump", CTLTYPE_INT | CTLFLAG_RW, sc->dev, sizeof(sc->dev),
7859 sysctl_hdac_pindump, "I", "Dump pin states/data");
7862 /****************************************************************************
7863 * int hdac_suspend(device_t)
7865 * Suspend and power down HDA bus and codecs.
7866 ****************************************************************************/
7868 hdac_suspend(device_t dev)
7870 struct hdac_softc *sc;
7871 struct hdac_codec *codec;
7872 struct hdac_devinfo *devinfo;
7873 int codec_index, fg_index, i;
7876 device_printf(dev, "Suspend...\n");
7879 sc = device_get_softc(dev);
7883 device_printf(dev, "Stop streams...\n");
7885 for (i = 0; i < sc->num_chans; i++) {
7886 if (sc->chans[i].flags & HDAC_CHN_RUNNING) {
7887 sc->chans[i].flags |= HDAC_CHN_SUSPEND;
7888 hdac_channel_stop(sc, &sc->chans[i]);
7892 for (codec_index = 0; codec_index < HDAC_CODEC_MAX; codec_index++) {
7893 codec = sc->codecs[codec_index];
7896 for (fg_index = 0; fg_index < codec->num_fgs; fg_index++) {
7897 devinfo = &codec->fgs[fg_index];
7901 " cad=%d nid=%d to the D3 state...\n",
7902 codec->cad, devinfo->nid);
7905 HDA_CMD_SET_POWER_STATE(codec->cad,
7906 devinfo->nid, HDA_CMD_POWER_STATE_D3),
7912 device_printf(dev, "Reset controller...\n");
7914 callout_stop(&sc->poll_hda);
7915 callout_stop(&sc->poll_hdac);
7916 callout_stop(&sc->poll_jack);
7919 taskqueue_drain(taskqueue_thread, &sc->unsolq_task);
7920 callout_drain(&sc->poll_hda);
7921 callout_drain(&sc->poll_hdac);
7922 callout_drain(&sc->poll_jack);
7925 device_printf(dev, "Suspend done\n");
7931 /****************************************************************************
7932 * int hdac_resume(device_t)
7934 * Powerup and restore HDA bus and codecs state.
7935 ****************************************************************************/
7937 hdac_resume(device_t dev)
7939 struct hdac_softc *sc;
7940 struct hdac_codec *codec;
7941 struct hdac_devinfo *devinfo;
7942 int codec_index, fg_index, i;
7945 device_printf(dev, "Resume...\n");
7948 sc = device_get_softc(dev);
7951 /* Quiesce everything */
7953 device_printf(dev, "Reset controller...\n");
7957 /* Initialize the CORB and RIRB */
7961 /* Start the corb and rirb engines */
7963 device_printf(dev, "Starting CORB Engine...\n");
7965 hdac_corb_start(sc);
7967 device_printf(dev, "Starting RIRB Engine...\n");
7969 hdac_rirb_start(sc);
7973 "Enabling controller interrupt...\n");
7975 HDAC_WRITE_4(&sc->mem, HDAC_GCTL, HDAC_READ_4(&sc->mem, HDAC_GCTL) |
7977 if (sc->polling == 0) {
7978 HDAC_WRITE_4(&sc->mem, HDAC_INTCTL,
7979 HDAC_INTCTL_CIE | HDAC_INTCTL_GIE);
7981 callout_reset(&sc->poll_hdac, 1, hdac_poll_callback, sc);
7985 for (codec_index = 0; codec_index < HDAC_CODEC_MAX; codec_index++) {
7986 codec = sc->codecs[codec_index];
7989 for (fg_index = 0; fg_index < codec->num_fgs; fg_index++) {
7990 devinfo = &codec->fgs[fg_index];
7991 if (devinfo->node_type !=
7992 HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO) {
7995 "Power down unsupported non-audio FG"
7996 " cad=%d nid=%d to the D3 state...\n",
7997 codec->cad, devinfo->nid);
8000 HDA_CMD_SET_POWER_STATE(codec->cad,
8001 devinfo->nid, HDA_CMD_POWER_STATE_D3),
8008 "Power up audio FG cad=%d nid=%d...\n",
8009 devinfo->codec->cad, devinfo->nid);
8011 hdac_powerup(devinfo);
8013 device_printf(dev, "AFG commit...\n");
8015 hdac_audio_commit(devinfo);
8017 device_printf(dev, "HP switch init...\n");
8019 hdac_hp_switch_init(devinfo);
8022 for (i = 0; i < devinfo->function.audio.num_devs; i++) {
8023 struct hdac_pcm_devinfo *pdevinfo =
8024 &devinfo->function.audio.devs[i];
8026 device_printf(pdevinfo->dev,
8027 "OSS mixer reinitialization...\n");
8029 if (mixer_reinit(pdevinfo->dev) == -1)
8030 device_printf(pdevinfo->dev,
8031 "unable to reinitialize the mixer\n");
8038 device_printf(dev, "Start streams...\n");
8040 for (i = 0; i < sc->num_chans; i++) {
8041 if (sc->chans[i].flags & HDAC_CHN_SUSPEND) {
8042 sc->chans[i].flags &= ~HDAC_CHN_SUSPEND;
8043 hdac_channel_start(sc, &sc->chans[i]);
8050 device_printf(dev, "Resume done\n");
8055 /****************************************************************************
8056 * int hdac_detach(device_t)
8058 * Detach and free up resources utilized by the hdac device.
8059 ****************************************************************************/
8061 hdac_detach(device_t dev)
8063 struct hdac_softc *sc;
8065 int i, devcount, error;
8067 if ((error = device_get_children(dev, &devlist, &devcount)) != 0)
8069 for (i = 0; i < devcount; i++) {
8070 if ((error = device_delete_child(dev, devlist[i])) != 0) {
8071 free(devlist, M_TEMP);
8075 free(devlist, M_TEMP);
8077 sc = device_get_softc(dev);
8078 hdac_release_resources(sc);
8084 hdac_print_child(device_t dev, device_t child)
8086 struct hdac_pcm_devinfo *pdevinfo =
8087 (struct hdac_pcm_devinfo *)device_get_ivars(child);
8090 retval = bus_print_child_header(dev, child);
8091 retval += printf(" at cad %d nid %d",
8092 pdevinfo->devinfo->codec->cad, pdevinfo->devinfo->nid);
8093 retval += bus_print_child_footer(dev, child);
8098 static device_method_t hdac_methods[] = {
8099 /* device interface */
8100 DEVMETHOD(device_probe, hdac_probe),
8101 DEVMETHOD(device_attach, hdac_attach),
8102 DEVMETHOD(device_detach, hdac_detach),
8103 DEVMETHOD(device_suspend, hdac_suspend),
8104 DEVMETHOD(device_resume, hdac_resume),
8106 DEVMETHOD(bus_print_child, hdac_print_child),
8110 static driver_t hdac_driver = {
8113 sizeof(struct hdac_softc),
8116 static devclass_t hdac_devclass;
8118 DRIVER_MODULE(snd_hda, pci, hdac_driver, hdac_devclass, 0, 0);
8119 MODULE_DEPEND(snd_hda, sound, SOUND_MINVER, SOUND_PREFVER, SOUND_MAXVER);
8120 MODULE_VERSION(snd_hda, 1);
8123 hdac_pcm_probe(device_t dev)
8125 struct hdac_pcm_devinfo *pdevinfo =
8126 (struct hdac_pcm_devinfo *)device_get_ivars(dev);
8129 snprintf(buf, sizeof(buf), "HDA %s PCM #%d %s",
8130 hdac_codec_name(pdevinfo->devinfo->codec),
8132 (pdevinfo->digital == 3)?"DisplayPort":
8133 ((pdevinfo->digital == 2)?"HDMI":
8134 ((pdevinfo->digital)?"Digital":"Analog")));
8135 device_set_desc_copy(dev, buf);
8140 hdac_pcm_attach(device_t dev)
8142 struct hdac_pcm_devinfo *pdevinfo =
8143 (struct hdac_pcm_devinfo *)device_get_ivars(dev);
8144 struct hdac_softc *sc = pdevinfo->devinfo->codec->sc;
8145 char status[SND_STATUSLEN];
8148 pdevinfo->chan_size = pcm_getbuffersize(dev,
8149 HDA_BUFSZ_MIN, HDA_BUFSZ_DEFAULT, HDA_BUFSZ_MAX);
8152 device_printf(dev, "+--------------------------------------+\n");
8153 device_printf(dev, "| DUMPING PCM Playback/Record Channels |\n");
8154 device_printf(dev, "+--------------------------------------+\n");
8155 hdac_dump_pcmchannels(pdevinfo);
8156 device_printf(dev, "\n");
8157 device_printf(dev, "+-------------------------------+\n");
8158 device_printf(dev, "| DUMPING Playback/Record Paths |\n");
8159 device_printf(dev, "+-------------------------------+\n");
8160 hdac_dump_dac(pdevinfo);
8161 hdac_dump_adc(pdevinfo);
8162 hdac_dump_mix(pdevinfo);
8163 device_printf(dev, "\n");
8164 device_printf(dev, "+-------------------------+\n");
8165 device_printf(dev, "| DUMPING Volume Controls |\n");
8166 device_printf(dev, "+-------------------------+\n");
8167 hdac_dump_ctls(pdevinfo, "Master Volume", SOUND_MASK_VOLUME);
8168 hdac_dump_ctls(pdevinfo, "PCM Volume", SOUND_MASK_PCM);
8169 hdac_dump_ctls(pdevinfo, "CD Volume", SOUND_MASK_CD);
8170 hdac_dump_ctls(pdevinfo, "Microphone Volume", SOUND_MASK_MIC);
8171 hdac_dump_ctls(pdevinfo, "Microphone2 Volume", SOUND_MASK_MONITOR);
8172 hdac_dump_ctls(pdevinfo, "Line-in Volume", SOUND_MASK_LINE);
8173 hdac_dump_ctls(pdevinfo, "Speaker/Beep Volume", SOUND_MASK_SPEAKER);
8174 hdac_dump_ctls(pdevinfo, "Recording Level", SOUND_MASK_RECLEV);
8175 hdac_dump_ctls(pdevinfo, "Input Mix Level", SOUND_MASK_IMIX);
8176 hdac_dump_ctls(pdevinfo, "Input Monitoring Level", SOUND_MASK_IGAIN);
8177 hdac_dump_ctls(pdevinfo, NULL, 0);
8178 device_printf(dev, "\n");
8181 if (resource_int_value(device_get_name(dev),
8182 device_get_unit(dev), "blocksize", &i) == 0 && i > 0) {
8184 if (i < HDA_BLK_MIN)
8186 pdevinfo->chan_blkcnt = pdevinfo->chan_size / i;
8188 while (pdevinfo->chan_blkcnt >> i)
8190 pdevinfo->chan_blkcnt = 1 << (i - 1);
8191 if (pdevinfo->chan_blkcnt < HDA_BDL_MIN)
8192 pdevinfo->chan_blkcnt = HDA_BDL_MIN;
8193 else if (pdevinfo->chan_blkcnt > HDA_BDL_MAX)
8194 pdevinfo->chan_blkcnt = HDA_BDL_MAX;
8196 pdevinfo->chan_blkcnt = HDA_BDL_DEFAULT;
8199 * We don't register interrupt handler with snd_setup_intr
8200 * in pcm device. Mark pcm device as MPSAFE manually.
8202 pcm_setflags(dev, pcm_getflags(dev) | SD_F_MPSAFE);
8205 device_printf(dev, "OSS mixer initialization...\n");
8207 if (mixer_init(dev, &hdac_audio_ctl_ossmixer_class, pdevinfo) != 0)
8208 device_printf(dev, "Can't register mixer\n");
8211 device_printf(dev, "Registering PCM channels...\n");
8213 if (pcm_register(dev, pdevinfo, (pdevinfo->play >= 0)?1:0,
8214 (pdevinfo->rec >= 0)?1:0) != 0)
8215 device_printf(dev, "Can't register PCM\n");
8217 pdevinfo->registered++;
8219 if (pdevinfo->play >= 0)
8220 pcm_addchan(dev, PCMDIR_PLAY, &hdac_channel_class, pdevinfo);
8221 if (pdevinfo->rec >= 0)
8222 pcm_addchan(dev, PCMDIR_REC, &hdac_channel_class, pdevinfo);
8224 snprintf(status, SND_STATUSLEN, "at cad %d nid %d on %s %s",
8225 pdevinfo->devinfo->codec->cad, pdevinfo->devinfo->nid,
8226 device_get_nameunit(sc->dev), PCM_KLDSTRING(snd_hda));
8227 pcm_setstatus(dev, status);
8233 hdac_pcm_detach(device_t dev)
8235 struct hdac_pcm_devinfo *pdevinfo =
8236 (struct hdac_pcm_devinfo *)device_get_ivars(dev);
8239 if (pdevinfo->registered > 0) {
8240 err = pcm_unregister(dev);
8248 static device_method_t hdac_pcm_methods[] = {
8249 /* device interface */
8250 DEVMETHOD(device_probe, hdac_pcm_probe),
8251 DEVMETHOD(device_attach, hdac_pcm_attach),
8252 DEVMETHOD(device_detach, hdac_pcm_detach),
8256 static driver_t hdac_pcm_driver = {
8262 DRIVER_MODULE(snd_hda_pcm, hdac, hdac_pcm_driver, pcm_devclass, 0, 0);