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);
4313 hdac_audio_parse(struct hdac_devinfo *devinfo)
4315 struct hdac_codec *codec = devinfo->codec;
4316 struct hdac_softc *sc = codec->sc;
4317 struct hdac_widget *w;
4322 cad = devinfo->codec->cad;
4325 res = hdac_command(sc,
4326 HDA_CMD_GET_PARAMETER(cad , nid, HDA_PARAM_GPIO_COUNT), cad);
4327 devinfo->function.audio.gpio = res;
4330 device_printf(sc->dev, "GPIO: 0x%08x "
4331 "NumGPIO=%d NumGPO=%d "
4332 "NumGPI=%d GPIWake=%d GPIUnsol=%d\n",
4333 devinfo->function.audio.gpio,
4334 HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->function.audio.gpio),
4335 HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->function.audio.gpio),
4336 HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->function.audio.gpio),
4337 HDA_PARAM_GPIO_COUNT_GPI_WAKE(devinfo->function.audio.gpio),
4338 HDA_PARAM_GPIO_COUNT_GPI_UNSOL(devinfo->function.audio.gpio));
4341 res = hdac_command(sc,
4342 HDA_CMD_GET_PARAMETER(cad, nid, HDA_PARAM_SUPP_STREAM_FORMATS),
4344 devinfo->function.audio.supp_stream_formats = res;
4346 res = hdac_command(sc,
4347 HDA_CMD_GET_PARAMETER(cad, nid, HDA_PARAM_SUPP_PCM_SIZE_RATE),
4349 devinfo->function.audio.supp_pcm_size_rate = res;
4351 res = hdac_command(sc,
4352 HDA_CMD_GET_PARAMETER(cad, nid, HDA_PARAM_OUTPUT_AMP_CAP),
4354 devinfo->function.audio.outamp_cap = res;
4356 res = hdac_command(sc,
4357 HDA_CMD_GET_PARAMETER(cad, nid, HDA_PARAM_INPUT_AMP_CAP),
4359 devinfo->function.audio.inamp_cap = res;
4361 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4362 w = hdac_widget_get(devinfo, i);
4364 device_printf(sc->dev, "Ghost widget! nid=%d!\n", i);
4366 w->devinfo = devinfo;
4373 w->param.eapdbtl = HDAC_INVALID;
4374 hdac_widget_parse(w);
4380 hdac_audio_ctl_parse(struct hdac_devinfo *devinfo)
4382 struct hdac_softc *sc = devinfo->codec->sc;
4383 struct hdac_audio_ctl *ctls;
4384 struct hdac_widget *w, *cw;
4385 int i, j, cnt, max, ocap, icap;
4386 int mute, offset, step, size;
4388 /* XXX This is redundant */
4390 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4391 w = hdac_widget_get(devinfo, i);
4392 if (w == NULL || w->enable == 0)
4394 if (w->param.outamp_cap != 0)
4396 if (w->param.inamp_cap != 0) {
4398 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR:
4399 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER:
4400 for (j = 0; j < w->nconns; j++) {
4401 cw = hdac_widget_get(devinfo,
4403 if (cw == NULL || cw->enable == 0)
4415 devinfo->function.audio.ctlcnt = max;
4420 ctls = (struct hdac_audio_ctl *)malloc(
4421 sizeof(*ctls) * max, M_HDAC, M_ZERO | M_NOWAIT);
4425 device_printf(sc->dev, "unable to allocate ctls!\n");
4426 devinfo->function.audio.ctlcnt = 0;
4431 for (i = devinfo->startnode; cnt < max && i < devinfo->endnode; i++) {
4433 device_printf(sc->dev, "%s: Ctl overflow!\n",
4437 w = hdac_widget_get(devinfo, i);
4438 if (w == NULL || w->enable == 0)
4440 ocap = w->param.outamp_cap;
4441 icap = w->param.inamp_cap;
4443 mute = HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(ocap);
4444 step = HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(ocap);
4445 size = HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(ocap);
4446 offset = HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(ocap);
4447 /*if (offset > step) {
4449 device_printf(sc->dev,
4450 "BUGGY outamp: nid=%d "
4451 "[offset=%d > step=%d]\n",
4452 w->nid, offset, step);
4456 ctls[cnt].enable = 1;
4457 ctls[cnt].widget = w;
4458 ctls[cnt].mute = mute;
4459 ctls[cnt].step = step;
4460 ctls[cnt].size = size;
4461 ctls[cnt].offset = offset;
4462 ctls[cnt].left = offset;
4463 ctls[cnt].right = offset;
4464 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX ||
4466 ctls[cnt].ndir = HDA_CTL_IN;
4468 ctls[cnt].ndir = HDA_CTL_OUT;
4469 ctls[cnt++].dir = HDA_CTL_OUT;
4473 mute = HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(icap);
4474 step = HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(icap);
4475 size = HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(icap);
4476 offset = HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(icap);
4477 /*if (offset > step) {
4479 device_printf(sc->dev,
4480 "BUGGY inamp: nid=%d "
4481 "[offset=%d > step=%d]\n",
4482 w->nid, offset, step);
4487 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR:
4488 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER:
4489 for (j = 0; j < w->nconns; j++) {
4491 device_printf(sc->dev,
4492 "%s: Ctl overflow!\n",
4496 cw = hdac_widget_get(devinfo,
4498 if (cw == NULL || cw->enable == 0)
4500 ctls[cnt].enable = 1;
4501 ctls[cnt].widget = w;
4502 ctls[cnt].childwidget = cw;
4503 ctls[cnt].index = j;
4504 ctls[cnt].mute = mute;
4505 ctls[cnt].step = step;
4506 ctls[cnt].size = size;
4507 ctls[cnt].offset = offset;
4508 ctls[cnt].left = offset;
4509 ctls[cnt].right = offset;
4510 ctls[cnt].ndir = HDA_CTL_IN;
4511 ctls[cnt++].dir = HDA_CTL_IN;
4516 device_printf(sc->dev,
4517 "%s: Ctl overflow!\n",
4521 ctls[cnt].enable = 1;
4522 ctls[cnt].widget = w;
4523 ctls[cnt].mute = mute;
4524 ctls[cnt].step = step;
4525 ctls[cnt].size = size;
4526 ctls[cnt].offset = offset;
4527 ctls[cnt].left = offset;
4528 ctls[cnt].right = offset;
4530 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
4531 ctls[cnt].ndir = HDA_CTL_OUT;
4533 ctls[cnt].ndir = HDA_CTL_IN;
4534 ctls[cnt++].dir = HDA_CTL_IN;
4540 devinfo->function.audio.ctl = ctls;
4544 hdac_audio_as_parse(struct hdac_devinfo *devinfo)
4546 struct hdac_softc *sc = devinfo->codec->sc;
4547 struct hdac_audio_as *as;
4548 struct hdac_widget *w;
4549 int i, j, cnt, max, type, dir, assoc, seq, first, hpredir;
4551 /* Count present associations */
4553 for (j = 1; j < 16; j++) {
4554 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4555 w = hdac_widget_get(devinfo, i);
4556 if (w == NULL || w->enable == 0)
4558 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
4560 if (HDA_CONFIG_DEFAULTCONF_ASSOCIATION(w->wclass.pin.config)
4564 if (j != 15) /* There could be many 1-pin assocs #15 */
4569 devinfo->function.audio.ascnt = max;
4574 as = (struct hdac_audio_as *)malloc(
4575 sizeof(*as) * max, M_HDAC, M_ZERO | M_NOWAIT);
4579 device_printf(sc->dev, "unable to allocate assocs!\n");
4580 devinfo->function.audio.ascnt = 0;
4584 for (i = 0; i < max; i++) {
4590 /* Scan associations skipping as=0. */
4592 for (j = 1; j < 16; j++) {
4595 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4596 w = hdac_widget_get(devinfo, i);
4597 if (w == NULL || w->enable == 0)
4599 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
4601 assoc = HDA_CONFIG_DEFAULTCONF_ASSOCIATION(w->wclass.pin.config);
4602 seq = HDA_CONFIG_DEFAULTCONF_SEQUENCE(w->wclass.pin.config);
4607 ("%s: Associations owerflow (%d of %d)",
4608 __func__, cnt, max));
4609 type = w->wclass.pin.config &
4610 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
4611 /* Get pin direction. */
4612 if (type == HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_OUT ||
4613 type == HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER ||
4614 type == HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT ||
4615 type == HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_OUT ||
4616 type == HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_OUT)
4620 /* If this is a first pin - create new association. */
4621 if (as[cnt].pincnt == 0) {
4628 /* Check association correctness. */
4629 if (as[cnt].pins[seq] != 0) {
4630 device_printf(sc->dev, "%s: Duplicate pin %d (%d) "
4631 "in association %d! Disabling association.\n",
4632 __func__, seq, w->nid, j);
4635 if (dir != as[cnt].dir) {
4636 device_printf(sc->dev, "%s: Pin %d has wrong "
4637 "direction for association %d! Disabling "
4639 __func__, w->nid, j);
4642 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) {
4643 if (HDA_PARAM_PIN_CAP_DP(w->wclass.pin.cap))
4644 as[cnt].digital = 3;
4645 else if (HDA_PARAM_PIN_CAP_HDMI(w->wclass.pin.cap))
4646 as[cnt].digital = 2;
4648 as[cnt].digital = 1;
4650 /* Headphones with seq=15 may mean redirection. */
4651 if (type == HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT &&
4654 as[cnt].pins[seq] = w->nid;
4656 /* Association 15 is a multiple unassociated pins. */
4660 if (j != 15 && as[cnt].pincnt > 0) {
4661 if (hpredir && as[cnt].pincnt > 1)
4662 as[cnt].hpredir = first;
4667 device_printf(sc->dev,
4668 "%d associations found:\n", max);
4669 for (i = 0; i < max; i++) {
4670 device_printf(sc->dev,
4671 "Association %d (%d) %s%s:\n",
4672 i, as[i].index, (as[i].dir == HDA_CTL_IN)?"in":"out",
4673 as[i].enable?"":" (disabled)");
4674 for (j = 0; j < 16; j++) {
4675 if (as[i].pins[j] == 0)
4677 device_printf(sc->dev,
4678 " Pin nid=%d seq=%d\n",
4684 devinfo->function.audio.as = as;
4687 static const struct {
4690 uint32_t set, unset;
4693 * XXX Force stereo quirk. Monoural recording / playback
4694 * on few codecs (especially ALC880) seems broken or
4695 * perhaps unsupported.
4697 { HDA_MATCH_ALL, HDA_MATCH_ALL,
4698 HDA_QUIRK_FORCESTEREO | HDA_QUIRK_IVREF, 0 },
4699 { ACER_ALL_SUBVENDOR, HDA_MATCH_ALL,
4700 HDA_QUIRK_GPIO0, 0 },
4701 { ASUS_G2K_SUBVENDOR, HDA_CODEC_ALC660,
4702 HDA_QUIRK_GPIO0, 0 },
4703 { ASUS_M5200_SUBVENDOR, HDA_CODEC_ALC880,
4704 HDA_QUIRK_GPIO0, 0 },
4705 { ASUS_A7M_SUBVENDOR, HDA_CODEC_ALC880,
4706 HDA_QUIRK_GPIO0, 0 },
4707 { ASUS_A7T_SUBVENDOR, HDA_CODEC_ALC882,
4708 HDA_QUIRK_GPIO0, 0 },
4709 { ASUS_W2J_SUBVENDOR, HDA_CODEC_ALC882,
4710 HDA_QUIRK_GPIO0, 0 },
4711 { ASUS_U5F_SUBVENDOR, HDA_CODEC_AD1986A,
4712 HDA_QUIRK_EAPDINV, 0 },
4713 { ASUS_A8X_SUBVENDOR, HDA_CODEC_AD1986A,
4714 HDA_QUIRK_EAPDINV, 0 },
4715 { ASUS_F3JC_SUBVENDOR, HDA_CODEC_ALC861,
4716 HDA_QUIRK_OVREF, 0 },
4717 { UNIWILL_9075_SUBVENDOR, HDA_CODEC_ALC861,
4718 HDA_QUIRK_OVREF, 0 },
4719 /*{ ASUS_M2N_SUBVENDOR, HDA_CODEC_AD1988,
4720 HDA_QUIRK_IVREF80, HDA_QUIRK_IVREF50 | HDA_QUIRK_IVREF100 },*/
4721 { MEDION_MD95257_SUBVENDOR, HDA_CODEC_ALC880,
4722 HDA_QUIRK_GPIO1, 0 },
4723 { LENOVO_3KN100_SUBVENDOR, HDA_CODEC_AD1986A,
4724 HDA_QUIRK_EAPDINV | HDA_QUIRK_SENSEINV, 0 },
4725 { SAMSUNG_Q1_SUBVENDOR, HDA_CODEC_AD1986A,
4726 HDA_QUIRK_EAPDINV, 0 },
4727 { APPLE_MB3_SUBVENDOR, HDA_CODEC_ALC885,
4728 HDA_QUIRK_GPIO0 | HDA_QUIRK_OVREF50, 0},
4729 { APPLE_INTEL_MAC, HDA_CODEC_STAC9221,
4730 HDA_QUIRK_GPIO0 | HDA_QUIRK_GPIO1, 0 },
4731 { APPLE_MACBOOKPRO55, HDA_CODEC_CS4206,
4732 HDA_QUIRK_GPIO1 | HDA_QUIRK_GPIO3, 0 },
4733 { DELL_D630_SUBVENDOR, HDA_CODEC_STAC9205X,
4734 HDA_QUIRK_GPIO0, 0 },
4735 { DELL_V1400_SUBVENDOR, HDA_CODEC_STAC9228X,
4736 HDA_QUIRK_GPIO2, 0 },
4737 { DELL_V1500_SUBVENDOR, HDA_CODEC_STAC9205X,
4738 HDA_QUIRK_GPIO0, 0 },
4739 { HDA_MATCH_ALL, HDA_CODEC_AD1988,
4740 HDA_QUIRK_IVREF80, HDA_QUIRK_IVREF50 | HDA_QUIRK_IVREF100 },
4741 { HDA_MATCH_ALL, HDA_CODEC_AD1988B,
4742 HDA_QUIRK_IVREF80, HDA_QUIRK_IVREF50 | HDA_QUIRK_IVREF100 },
4743 { HDA_MATCH_ALL, HDA_CODEC_CX20549,
4744 0, HDA_QUIRK_FORCESTEREO }
4746 #define HDAC_QUIRKS_LEN (sizeof(hdac_quirks) / sizeof(hdac_quirks[0]))
4749 hdac_vendor_patch_parse(struct hdac_devinfo *devinfo)
4751 struct hdac_widget *w;
4752 uint32_t id, subvendor;
4755 id = hdac_codec_id(devinfo->codec);
4756 subvendor = devinfo->codec->sc->pci_subvendor;
4761 for (i = 0; i < HDAC_QUIRKS_LEN; i++) {
4762 if (!(HDA_DEV_MATCH(hdac_quirks[i].model, subvendor) &&
4763 HDA_DEV_MATCH(hdac_quirks[i].id, id)))
4765 if (hdac_quirks[i].set != 0)
4766 devinfo->function.audio.quirks |=
4768 if (hdac_quirks[i].unset != 0)
4769 devinfo->function.audio.quirks &=
4770 ~(hdac_quirks[i].unset);
4774 case HDA_CODEC_AD1983:
4776 * This codec has several possible usages, but none
4777 * fit the parser best. Help parser to choose better.
4779 /* Disable direct unmixed playback to get pcm volume. */
4780 w = hdac_widget_get(devinfo, 5);
4782 w->connsenable[0] = 0;
4783 w = hdac_widget_get(devinfo, 6);
4785 w->connsenable[0] = 0;
4786 w = hdac_widget_get(devinfo, 11);
4788 w->connsenable[0] = 0;
4789 /* Disable mic and line selectors. */
4790 w = hdac_widget_get(devinfo, 12);
4792 w->connsenable[1] = 0;
4793 w = hdac_widget_get(devinfo, 13);
4795 w->connsenable[1] = 0;
4796 /* Disable recording from mono playback mix. */
4797 w = hdac_widget_get(devinfo, 20);
4799 w->connsenable[3] = 0;
4801 case HDA_CODEC_AD1986A:
4803 * This codec has overcomplicated input mixing.
4804 * Make some cleaning there.
4806 /* Disable input mono mixer. Not needed and not supported. */
4807 w = hdac_widget_get(devinfo, 43);
4810 /* Disable any with any input mixing mesh. Use separately. */
4811 w = hdac_widget_get(devinfo, 39);
4814 w = hdac_widget_get(devinfo, 40);
4817 w = hdac_widget_get(devinfo, 41);
4820 w = hdac_widget_get(devinfo, 42);
4823 /* Disable duplicate mixer node connector. */
4824 w = hdac_widget_get(devinfo, 15);
4826 w->connsenable[3] = 0;
4827 /* There is only one mic preamplifier, use it effectively. */
4828 w = hdac_widget_get(devinfo, 31);
4830 if ((w->wclass.pin.config &
4831 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) ==
4832 HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN) {
4833 w = hdac_widget_get(devinfo, 16);
4835 w->connsenable[2] = 0;
4837 w = hdac_widget_get(devinfo, 15);
4839 w->connsenable[0] = 0;
4842 w = hdac_widget_get(devinfo, 32);
4844 if ((w->wclass.pin.config &
4845 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) ==
4846 HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN) {
4847 w = hdac_widget_get(devinfo, 16);
4849 w->connsenable[0] = 0;
4851 w = hdac_widget_get(devinfo, 15);
4853 w->connsenable[1] = 0;
4857 if (subvendor == ASUS_A8X_SUBVENDOR) {
4859 * This is just plain ridiculous.. There
4860 * are several A8 series that share the same
4861 * pci id but works differently (EAPD).
4863 w = hdac_widget_get(devinfo, 26);
4864 if (w != NULL && w->type ==
4865 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
4866 (w->wclass.pin.config &
4867 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK) !=
4868 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_NONE)
4869 devinfo->function.audio.quirks &=
4873 case HDA_CODEC_AD1981HD:
4875 * This codec has very unusual design with several
4876 * points inappropriate for the present parser.
4878 /* Disable recording from mono playback mix. */
4879 w = hdac_widget_get(devinfo, 21);
4881 w->connsenable[3] = 0;
4882 /* Disable rear to front mic mixer, use separately. */
4883 w = hdac_widget_get(devinfo, 31);
4886 /* Disable direct playback, use mixer. */
4887 w = hdac_widget_get(devinfo, 5);
4889 w->connsenable[0] = 0;
4890 w = hdac_widget_get(devinfo, 6);
4892 w->connsenable[0] = 0;
4893 w = hdac_widget_get(devinfo, 9);
4895 w->connsenable[0] = 0;
4896 w = hdac_widget_get(devinfo, 24);
4898 w->connsenable[0] = 0;
4904 * Trace path from DAC to pin.
4907 hdac_audio_trace_dac(struct hdac_devinfo *devinfo, int as, int seq, nid_t nid,
4908 int dupseq, int min, int only, int depth)
4910 struct hdac_widget *w;
4914 if (depth > HDA_PARSE_MAXDEPTH)
4916 w = hdac_widget_get(devinfo, nid);
4917 if (w == NULL || w->enable == 0)
4921 device_printf(devinfo->codec->sc->dev,
4922 " %*stracing via nid %d\n",
4923 depth + 1, "", w->nid);
4926 /* Use only unused widgets */
4927 if (w->bindas >= 0 && w->bindas != as) {
4930 device_printf(devinfo->codec->sc->dev,
4931 " %*snid %d busy by association %d\n",
4932 depth + 1, "", w->nid, w->bindas);
4938 if (w->bindseqmask != 0) {
4941 device_printf(devinfo->codec->sc->dev,
4942 " %*snid %d busy by seqmask %x\n",
4943 depth + 1, "", w->nid, w->bindseqmask);
4949 /* If this is headphones - allow duplicate first pin. */
4950 if (w->bindseqmask != 0 &&
4951 (w->bindseqmask & (1 << dupseq)) == 0) {
4953 device_printf(devinfo->codec->sc->dev,
4954 " %*snid %d busy by seqmask %x\n",
4955 depth + 1, "", w->nid, w->bindseqmask);
4962 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT:
4963 /* Do not traverse input. AD1988 has digital monitor
4964 for which we are not ready. */
4966 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT:
4967 /* If we are tracing HP take only dac of first pin. */
4968 if ((only == 0 || only == w->nid) &&
4969 (w->nid >= min) && (dupseq < 0 || w->nid ==
4970 devinfo->function.audio.as[as].dacs[dupseq]))
4973 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
4978 /* Find reachable DACs with smallest nid respecting constraints. */
4979 for (i = 0; i < w->nconns; i++) {
4980 if (w->connsenable[i] == 0)
4982 if (w->selconn != -1 && w->selconn != i)
4984 if ((ret = hdac_audio_trace_dac(devinfo, as, seq,
4985 w->conns[i], dupseq, min, only, depth + 1)) != 0) {
4986 if (m == 0 || ret < m) {
4990 if (only || dupseq >= 0)
4994 if (m && only && ((w->nconns > 1 &&
4995 w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) ||
4996 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR))
5002 w->bindseqmask |= (1 << seq);
5006 device_printf(devinfo->codec->sc->dev,
5007 " %*snid %d returned %d\n",
5008 depth + 1, "", w->nid, m);
5015 * Trace path from widget to ADC.
5018 hdac_audio_trace_adc(struct hdac_devinfo *devinfo, int as, int seq, nid_t nid,
5019 int only, int depth)
5021 struct hdac_widget *w, *wc;
5025 if (depth > HDA_PARSE_MAXDEPTH)
5027 w = hdac_widget_get(devinfo, nid);
5028 if (w == NULL || w->enable == 0)
5031 device_printf(devinfo->codec->sc->dev,
5032 " %*stracing via nid %d\n",
5033 depth + 1, "", w->nid);
5035 /* Use only unused widgets */
5036 if (w->bindas >= 0 && w->bindas != as) {
5038 device_printf(devinfo->codec->sc->dev,
5039 " %*snid %d busy by association %d\n",
5040 depth + 1, "", w->nid, w->bindas);
5046 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT:
5047 /* If we are tracing HP take only dac of first pin. */
5051 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
5056 /* Try to find reachable ADCs with specified nid. */
5057 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
5058 wc = hdac_widget_get(devinfo, j);
5059 if (wc == NULL || wc->enable == 0)
5061 for (i = 0; i < wc->nconns; i++) {
5062 if (wc->connsenable[i] == 0)
5064 if (wc->conns[i] != nid)
5066 if (hdac_audio_trace_adc(devinfo, as, seq,
5067 j, only, depth + 1) != 0) {
5069 if (((wc->nconns > 1 &&
5070 wc->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) ||
5071 wc->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR) &&
5081 w->bindseqmask |= (1 << seq);
5084 device_printf(devinfo->codec->sc->dev,
5085 " %*snid %d returned %d\n",
5086 depth + 1, "", w->nid, res);
5092 * Erase trace path of the specified association.
5095 hdac_audio_undo_trace(struct hdac_devinfo *devinfo, int as, int seq)
5097 struct hdac_widget *w;
5100 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5101 w = hdac_widget_get(devinfo, i);
5102 if (w == NULL || w->enable == 0)
5104 if (w->bindas == as) {
5106 w->bindseqmask &= ~(1 << seq);
5107 if (w->bindseqmask == 0) {
5121 * Trace association path from DAC to output
5124 hdac_audio_trace_as_out(struct hdac_devinfo *devinfo, int as, int seq)
5126 struct hdac_audio_as *ases = devinfo->function.audio.as;
5131 for (i = seq; i < 16 && ases[as].pins[i] == 0; i++)
5133 /* Check if there is no any left. If so - we succeeded. */
5137 hpredir = (i == 15 && ases[as].fakeredir == 0)?ases[as].hpredir:-1;
5142 device_printf(devinfo->codec->sc->dev,
5143 " Tracing pin %d with min nid %d",
5144 ases[as].pins[i], min);
5146 printf(" and hpredir %d", hpredir);
5149 /* Trace this pin taking min nid into account. */
5150 res = hdac_audio_trace_dac(devinfo, as, i,
5151 ases[as].pins[i], hpredir, min, 0, 0);
5153 /* If we failed - return to previous and redo it. */
5155 device_printf(devinfo->codec->sc->dev,
5156 " Unable to trace pin %d seq %d with min "
5158 ases[as].pins[i], i, min);
5160 printf(" and hpredir %d", hpredir);
5166 device_printf(devinfo->codec->sc->dev,
5167 " Pin %d traced to DAC %d",
5168 ases[as].pins[i], res);
5170 printf(" and hpredir %d", hpredir);
5171 if (ases[as].fakeredir)
5172 printf(" with fake redirection");
5175 /* Trace again to mark the path */
5176 hdac_audio_trace_dac(devinfo, as, i,
5177 ases[as].pins[i], hpredir, min, res, 0);
5178 ases[as].dacs[i] = res;
5179 /* We succeeded, so call next. */
5180 if (hdac_audio_trace_as_out(devinfo, as, i + 1))
5182 /* If next failed, we should retry with next min */
5183 hdac_audio_undo_trace(devinfo, as, i);
5184 ases[as].dacs[i] = 0;
5190 * Trace association path from input to ADC
5193 hdac_audio_trace_as_in(struct hdac_devinfo *devinfo, int as)
5195 struct hdac_audio_as *ases = devinfo->function.audio.as;
5196 struct hdac_widget *w;
5199 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
5200 w = hdac_widget_get(devinfo, j);
5201 if (w == NULL || w->enable == 0)
5203 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT)
5205 if (w->bindas >= 0 && w->bindas != as)
5209 for (i = 0; i < 16; i++) {
5210 if (ases[as].pins[i] == 0)
5214 device_printf(devinfo->codec->sc->dev,
5215 " Tracing pin %d to ADC %d\n",
5216 ases[as].pins[i], j);
5218 /* Trace this pin taking goal into account. */
5219 if (hdac_audio_trace_adc(devinfo, as, i,
5220 ases[as].pins[i], j, 0) == 0) {
5221 /* If we failed - return to previous and redo it. */
5223 device_printf(devinfo->codec->sc->dev,
5224 " Unable to trace pin %d to ADC %d, undo traces\n",
5225 ases[as].pins[i], j);
5227 hdac_audio_undo_trace(devinfo, as, -1);
5228 for (k = 0; k < 16; k++)
5229 ases[as].dacs[k] = 0;
5233 device_printf(devinfo->codec->sc->dev,
5234 " Pin %d traced to ADC %d\n",
5235 ases[as].pins[i], j);
5237 ases[as].dacs[i] = j;
5246 * Trace input monitor path from mixer to output association.
5249 hdac_audio_trace_to_out(struct hdac_devinfo *devinfo, nid_t nid, int depth)
5251 struct hdac_audio_as *ases = devinfo->function.audio.as;
5252 struct hdac_widget *w, *wc;
5256 if (depth > HDA_PARSE_MAXDEPTH)
5258 w = hdac_widget_get(devinfo, nid);
5259 if (w == NULL || w->enable == 0)
5262 device_printf(devinfo->codec->sc->dev,
5263 " %*stracing via nid %d\n",
5264 depth + 1, "", w->nid);
5266 /* Use only unused widgets */
5267 if (depth > 0 && w->bindas != -1) {
5268 if (w->bindas < 0 || ases[w->bindas].dir == HDA_CTL_OUT) {
5270 device_printf(devinfo->codec->sc->dev,
5271 " %*snid %d found output association %d\n",
5272 depth + 1, "", w->nid, w->bindas);
5275 w->pflags |= HDA_ADC_MONITOR;
5279 device_printf(devinfo->codec->sc->dev,
5280 " %*snid %d busy by input association %d\n",
5281 depth + 1, "", w->nid, w->bindas);
5288 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT:
5289 /* Do not traverse input. AD1988 has digital monitor
5290 for which we are not ready. */
5292 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
5297 /* Try to find reachable ADCs with specified nid. */
5298 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
5299 wc = hdac_widget_get(devinfo, j);
5300 if (wc == NULL || wc->enable == 0)
5302 for (i = 0; i < wc->nconns; i++) {
5303 if (wc->connsenable[i] == 0)
5305 if (wc->conns[i] != nid)
5307 if (hdac_audio_trace_to_out(devinfo,
5308 j, depth + 1) != 0) {
5310 if (wc->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR &&
5318 if (res && w->bindas == -1)
5322 device_printf(devinfo->codec->sc->dev,
5323 " %*snid %d returned %d\n",
5324 depth + 1, "", w->nid, res);
5330 * Trace extra associations (beeper, monitor)
5333 hdac_audio_trace_as_extra(struct hdac_devinfo *devinfo)
5335 struct hdac_audio_as *as = devinfo->function.audio.as;
5336 struct hdac_widget *w;
5340 /* Find mixer associated with input, but supplying signal
5341 for output associations. Hope it will be input monitor. */
5343 device_printf(devinfo->codec->sc->dev,
5344 "Tracing input monitor\n");
5346 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
5347 w = hdac_widget_get(devinfo, j);
5348 if (w == NULL || w->enable == 0)
5350 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
5352 if (w->bindas < 0 || as[w->bindas].dir != HDA_CTL_IN)
5355 device_printf(devinfo->codec->sc->dev,
5356 " Tracing nid %d to out\n",
5359 if (hdac_audio_trace_to_out(devinfo, w->nid, 0)) {
5361 device_printf(devinfo->codec->sc->dev,
5362 " nid %d is input monitor\n",
5365 w->ossdev = SOUND_MIXER_IMIX;
5369 /* Other inputs monitor */
5370 /* Find input pins supplying signal for output associations.
5371 Hope it will be input monitoring. */
5373 device_printf(devinfo->codec->sc->dev,
5374 "Tracing other input monitors\n");
5376 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
5377 w = hdac_widget_get(devinfo, j);
5378 if (w == NULL || w->enable == 0)
5380 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
5382 if (w->bindas < 0 || as[w->bindas].dir != HDA_CTL_IN)
5385 device_printf(devinfo->codec->sc->dev,
5386 " Tracing nid %d to out\n",
5389 if (hdac_audio_trace_to_out(devinfo, w->nid, 0)) {
5391 device_printf(devinfo->codec->sc->dev,
5392 " nid %d is input monitor\n",
5400 device_printf(devinfo->codec->sc->dev,
5401 "Tracing beeper\n");
5403 for (j = devinfo->startnode; j < devinfo->endnode; j++) {
5404 w = hdac_widget_get(devinfo, j);
5405 if (w == NULL || w->enable == 0)
5407 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET)
5410 device_printf(devinfo->codec->sc->dev,
5411 " Tracing nid %d to out\n",
5414 if (hdac_audio_trace_to_out(devinfo, w->nid, 0)) {
5416 device_printf(devinfo->codec->sc->dev,
5417 " nid %d traced to out\n",
5426 * Bind assotiations to PCM channels
5429 hdac_audio_bind_as(struct hdac_devinfo *devinfo)
5431 struct hdac_softc *sc = devinfo->codec->sc;
5432 struct hdac_audio_as *as = devinfo->function.audio.as;
5433 int j, cnt = 0, free;
5435 for (j = 0; j < devinfo->function.audio.ascnt; j++) {
5439 if (sc->num_chans == 0) {
5440 sc->chans = (struct hdac_chan *)malloc(
5441 sizeof(struct hdac_chan) * cnt,
5442 M_HDAC, M_ZERO | M_NOWAIT);
5443 if (sc->chans == NULL) {
5444 device_printf(sc->dev,
5445 "Channels memory allocation failed!\n");
5449 sc->chans = (struct hdac_chan *)realloc(sc->chans,
5450 sizeof(struct hdac_chan) * (sc->num_chans + cnt),
5451 M_HDAC, M_ZERO | M_NOWAIT);
5452 if (sc->chans == NULL) {
5454 device_printf(sc->dev,
5455 "Channels memory allocation failed!\n");
5458 /* Fixup relative pointers after realloc */
5459 for (j = 0; j < sc->num_chans; j++)
5460 sc->chans[j].caps.fmtlist = sc->chans[j].fmtlist;
5462 free = sc->num_chans;
5463 sc->num_chans += cnt;
5465 for (j = free; j < free + cnt; j++) {
5466 sc->chans[j].devinfo = devinfo;
5467 sc->chans[j].as = -1;
5470 /* Assign associations in order of their numbers, */
5471 for (j = 0; j < devinfo->function.audio.ascnt; j++) {
5472 if (as[j].enable == 0)
5476 sc->chans[free].as = j;
5477 sc->chans[free].dir =
5478 (as[j].dir == HDA_CTL_IN) ? PCMDIR_REC : PCMDIR_PLAY;
5479 hdac_pcmchannel_setup(&sc->chans[free]);
5485 hdac_audio_disable_nonaudio(struct hdac_devinfo *devinfo)
5487 struct hdac_widget *w;
5490 /* Disable power and volume widgets. */
5491 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5492 w = hdac_widget_get(devinfo, i);
5493 if (w == NULL || w->enable == 0)
5495 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_POWER_WIDGET ||
5496 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_VOLUME_WIDGET) {
5499 device_printf(devinfo->codec->sc->dev,
5500 " Disabling nid %d due to it's"
5501 " non-audio type.\n",
5509 hdac_audio_disable_useless(struct hdac_devinfo *devinfo)
5511 struct hdac_widget *w, *cw;
5512 struct hdac_audio_ctl *ctl;
5513 int done, found, i, j, k;
5515 /* Disable useless pins. */
5516 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5517 w = hdac_widget_get(devinfo, i);
5518 if (w == NULL || w->enable == 0)
5520 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) {
5521 if ((w->wclass.pin.config &
5522 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK) ==
5523 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_NONE) {
5526 device_printf(devinfo->codec->sc->dev,
5527 " Disabling pin nid %d due"
5528 " to None connectivity.\n",
5531 } else if ((w->wclass.pin.config &
5532 HDA_CONFIG_DEFAULTCONF_ASSOCIATION_MASK) == 0) {
5535 device_printf(devinfo->codec->sc->dev,
5536 " Disabling unassociated"
5545 /* Disable and mute controls for disabled widgets. */
5547 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) {
5548 if (ctl->enable == 0)
5550 if (ctl->widget->enable == 0 ||
5551 (ctl->childwidget != NULL &&
5552 ctl->childwidget->enable == 0)) {
5554 ctl->muted = HDA_AMP_MUTE_ALL;
5558 if (ctl->ndir == HDA_CTL_IN)
5559 ctl->widget->connsenable[ctl->index] = 0;
5562 device_printf(devinfo->codec->sc->dev,
5563 " Disabling ctl %d nid %d cnid %d due"
5564 " to disabled widget.\n", i,
5566 (ctl->childwidget != NULL)?
5567 ctl->childwidget->nid:-1);
5571 /* Disable useless widgets. */
5572 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5573 w = hdac_widget_get(devinfo, i);
5574 if (w == NULL || w->enable == 0)
5576 /* Disable inputs with disabled child widgets. */
5577 for (j = 0; j < w->nconns; j++) {
5578 if (w->connsenable[j]) {
5579 cw = hdac_widget_get(devinfo, w->conns[j]);
5580 if (cw == NULL || cw->enable == 0) {
5581 w->connsenable[j] = 0;
5583 device_printf(devinfo->codec->sc->dev,
5584 " Disabling nid %d connection %d due"
5585 " to disabled child widget.\n",
5591 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR &&
5592 w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
5594 /* Disable mixers and selectors without inputs. */
5596 for (j = 0; j < w->nconns; j++) {
5597 if (w->connsenable[j]) {
5606 device_printf(devinfo->codec->sc->dev,
5607 " Disabling nid %d due to all it's"
5608 " inputs disabled.\n", w->nid);
5611 /* Disable nodes without consumers. */
5612 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR &&
5613 w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
5616 for (k = devinfo->startnode; k < devinfo->endnode; k++) {
5617 cw = hdac_widget_get(devinfo, k);
5618 if (cw == NULL || cw->enable == 0)
5620 for (j = 0; j < cw->nconns; j++) {
5621 if (cw->connsenable[j] && cw->conns[j] == i) {
5631 device_printf(devinfo->codec->sc->dev,
5632 " Disabling nid %d due to all it's"
5633 " consumers disabled.\n", w->nid);
5637 } while (done == 0);
5642 hdac_audio_disable_unas(struct hdac_devinfo *devinfo)
5644 struct hdac_audio_as *as = devinfo->function.audio.as;
5645 struct hdac_widget *w, *cw;
5646 struct hdac_audio_ctl *ctl;
5649 /* Disable unassosiated widgets. */
5650 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5651 w = hdac_widget_get(devinfo, i);
5652 if (w == NULL || w->enable == 0)
5654 if (w->bindas == -1) {
5657 device_printf(devinfo->codec->sc->dev,
5658 " Disabling unassociated nid %d.\n",
5663 /* Disable input connections on input pin and
5664 * output on output. */
5665 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5666 w = hdac_widget_get(devinfo, i);
5667 if (w == NULL || w->enable == 0)
5669 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
5673 if (as[w->bindas].dir == HDA_CTL_IN) {
5674 for (j = 0; j < w->nconns; j++) {
5675 if (w->connsenable[j] == 0)
5677 w->connsenable[j] = 0;
5679 device_printf(devinfo->codec->sc->dev,
5680 " Disabling connection to input pin "
5681 "nid %d conn %d.\n",
5685 ctl = hdac_audio_ctl_amp_get(devinfo, w->nid,
5687 if (ctl && ctl->enable) {
5689 ctl->muted = HDA_AMP_MUTE_ALL;
5695 ctl = hdac_audio_ctl_amp_get(devinfo, w->nid,
5696 HDA_CTL_OUT, -1, 1);
5697 if (ctl && ctl->enable) {
5699 ctl->muted = HDA_AMP_MUTE_ALL;
5704 for (k = devinfo->startnode; k < devinfo->endnode; k++) {
5705 cw = hdac_widget_get(devinfo, k);
5706 if (cw == NULL || cw->enable == 0)
5708 for (j = 0; j < cw->nconns; j++) {
5709 if (cw->connsenable[j] && cw->conns[j] == i) {
5710 cw->connsenable[j] = 0;
5712 device_printf(devinfo->codec->sc->dev,
5713 " Disabling connection from output pin "
5714 "nid %d conn %d cnid %d.\n",
5717 if (cw->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
5720 ctl = hdac_audio_ctl_amp_get(devinfo, k,
5722 if (ctl && ctl->enable) {
5724 ctl->muted = HDA_AMP_MUTE_ALL;
5737 hdac_audio_disable_notselected(struct hdac_devinfo *devinfo)
5739 struct hdac_audio_as *as = devinfo->function.audio.as;
5740 struct hdac_widget *w;
5743 /* On playback path we can safely disable all unseleted inputs. */
5744 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5745 w = hdac_widget_get(devinfo, i);
5746 if (w == NULL || w->enable == 0)
5750 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
5752 if (w->bindas < 0 || as[w->bindas].dir == HDA_CTL_IN)
5754 for (j = 0; j < w->nconns; j++) {
5755 if (w->connsenable[j] == 0)
5757 if (w->selconn < 0 || w->selconn == j)
5759 w->connsenable[j] = 0;
5761 device_printf(devinfo->codec->sc->dev,
5762 " Disabling unselected connection "
5763 "nid %d conn %d.\n",
5771 hdac_audio_disable_crossas(struct hdac_devinfo *devinfo)
5773 struct hdac_audio_as *ases = devinfo->function.audio.as;
5774 struct hdac_widget *w, *cw;
5775 struct hdac_audio_ctl *ctl;
5778 /* Disable crossassociatement and unwanted crosschannel connections. */
5779 /* ... using selectors */
5780 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5781 w = hdac_widget_get(devinfo, i);
5782 if (w == NULL || w->enable == 0)
5786 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
5788 if (w->bindas == -2)
5790 for (j = 0; j < w->nconns; j++) {
5791 if (w->connsenable[j] == 0)
5793 cw = hdac_widget_get(devinfo, w->conns[j]);
5794 if (cw == NULL || w->enable == 0)
5796 if (cw->bindas == -2 ||
5797 ((w->pflags & HDA_ADC_MONITOR) &&
5799 ases[cw->bindas].dir == HDA_CTL_IN))
5801 if (w->bindas == cw->bindas &&
5802 (w->bindseqmask & cw->bindseqmask) != 0)
5804 w->connsenable[j] = 0;
5806 device_printf(devinfo->codec->sc->dev,
5807 " Disabling crossassociatement connection "
5808 "nid %d conn %d cnid %d.\n",
5813 /* ... using controls */
5815 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) {
5816 if (ctl->enable == 0 || ctl->childwidget == NULL)
5818 if (ctl->widget->bindas == -2)
5820 if (ctl->childwidget->bindas == -2 ||
5821 ((ctl->widget->pflags & HDA_ADC_MONITOR) &&
5822 ctl->childwidget->bindas >= 0 &&
5823 ases[ctl->childwidget->bindas].dir == HDA_CTL_IN))
5825 if (ctl->widget->bindas != ctl->childwidget->bindas ||
5826 (ctl->widget->bindseqmask & ctl->childwidget->bindseqmask) == 0) {
5828 ctl->muted = HDA_AMP_MUTE_ALL;
5832 if (ctl->ndir == HDA_CTL_IN)
5833 ctl->widget->connsenable[ctl->index] = 0;
5835 device_printf(devinfo->codec->sc->dev,
5836 " Disabling crossassociatement connection "
5837 "ctl %d nid %d cnid %d.\n", i,
5839 ctl->childwidget->nid);
5846 #define HDA_CTL_GIVE(ctl) ((ctl)->step?1:0)
5849 * Find controls to control amplification for source.
5852 hdac_audio_ctl_source_amp(struct hdac_devinfo *devinfo, nid_t nid, int index,
5853 int ossdev, int ctlable, int depth, int need)
5855 struct hdac_widget *w, *wc;
5856 struct hdac_audio_ctl *ctl;
5857 int i, j, conns = 0, rneed;
5859 if (depth > HDA_PARSE_MAXDEPTH)
5862 w = hdac_widget_get(devinfo, nid);
5863 if (w == NULL || w->enable == 0)
5866 /* Count number of active inputs. */
5868 for (j = 0; j < w->nconns; j++) {
5869 if (w->connsenable[j])
5874 /* If this is not a first step - use input mixer.
5875 Pins have common input ctl so care must be taken. */
5876 if (depth > 0 && ctlable && (conns == 1 ||
5877 w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)) {
5878 ctl = hdac_audio_ctl_amp_get(devinfo, w->nid, HDA_CTL_IN,
5881 if (HDA_CTL_GIVE(ctl) & need)
5882 ctl->ossmask |= (1 << ossdev);
5884 ctl->possmask |= (1 << ossdev);
5885 need &= ~HDA_CTL_GIVE(ctl);
5889 /* If widget has own ossdev - not traverse it.
5890 It will be traversed on it's own. */
5891 if (w->ossdev >= 0 && depth > 0)
5894 /* We must not traverse pin */
5895 if ((w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT ||
5896 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) &&
5900 /* record that this widget exports such signal, */
5901 w->ossmask |= (1 << ossdev);
5903 /* If signals mixed, we can't assign controls farther.
5904 * Ignore this on depth zero. Caller must knows why.
5905 * Ignore this for static selectors if this input selected.
5911 ctl = hdac_audio_ctl_amp_get(devinfo, w->nid, HDA_CTL_OUT, -1, 1);
5913 if (HDA_CTL_GIVE(ctl) & need)
5914 ctl->ossmask |= (1 << ossdev);
5916 ctl->possmask |= (1 << ossdev);
5917 need &= ~HDA_CTL_GIVE(ctl);
5922 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5923 wc = hdac_widget_get(devinfo, i);
5924 if (wc == NULL || wc->enable == 0)
5926 for (j = 0; j < wc->nconns; j++) {
5927 if (wc->connsenable[j] && wc->conns[j] == nid) {
5928 rneed |= hdac_audio_ctl_source_amp(devinfo,
5929 wc->nid, j, ossdev, ctlable, depth + 1, need);
5939 * Find controls to control amplification for destination.
5942 hdac_audio_ctl_dest_amp(struct hdac_devinfo *devinfo, nid_t nid, int index,
5943 int ossdev, int depth, int need)
5945 struct hdac_audio_as *as = devinfo->function.audio.as;
5946 struct hdac_widget *w, *wc;
5947 struct hdac_audio_ctl *ctl;
5948 int i, j, consumers;
5950 if (depth > HDA_PARSE_MAXDEPTH)
5953 w = hdac_widget_get(devinfo, nid);
5954 if (w == NULL || w->enable == 0)
5958 /* If this node produce output for several consumers,
5959 we can't touch it. */
5961 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5962 wc = hdac_widget_get(devinfo, i);
5963 if (wc == NULL || wc->enable == 0)
5965 for (j = 0; j < wc->nconns; j++) {
5966 if (wc->connsenable[j] && wc->conns[j] == nid)
5970 /* The only exception is if real HP redirection is configured
5971 and this is a duplication point.
5972 XXX: Actually exception is not completely correct.
5973 XXX: Duplication point check is not perfect. */
5974 if ((consumers == 2 && (w->bindas < 0 ||
5975 as[w->bindas].hpredir < 0 || as[w->bindas].fakeredir ||
5976 (w->bindseqmask & (1 << 15)) == 0)) ||
5980 /* Else use it's output mixer. */
5981 ctl = hdac_audio_ctl_amp_get(devinfo, w->nid,
5982 HDA_CTL_OUT, -1, 1);
5984 if (HDA_CTL_GIVE(ctl) & need)
5985 ctl->ossmask |= (1 << ossdev);
5987 ctl->possmask |= (1 << ossdev);
5988 need &= ~HDA_CTL_GIVE(ctl);
5992 /* We must not traverse pin */
5993 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
5997 for (i = 0; i < w->nconns; i++) {
5999 if (w->connsenable[i] == 0)
6001 if (index >= 0 && i != index)
6003 ctl = hdac_audio_ctl_amp_get(devinfo, w->nid,
6006 if (HDA_CTL_GIVE(ctl) & tneed)
6007 ctl->ossmask |= (1 << ossdev);
6009 ctl->possmask |= (1 << ossdev);
6010 tneed &= ~HDA_CTL_GIVE(ctl);
6012 hdac_audio_ctl_dest_amp(devinfo, w->conns[i], -1, ossdev,
6018 * Assign OSS names to sound sources
6021 hdac_audio_assign_names(struct hdac_devinfo *devinfo)
6023 struct hdac_audio_as *as = devinfo->function.audio.as;
6024 struct hdac_widget *w;
6026 int type = -1, use, used = 0;
6027 static const int types[7][13] = {
6028 { SOUND_MIXER_LINE, SOUND_MIXER_LINE1, SOUND_MIXER_LINE2,
6029 SOUND_MIXER_LINE3, -1 }, /* line */
6030 { SOUND_MIXER_MONITOR, SOUND_MIXER_MIC, -1 }, /* int mic */
6031 { SOUND_MIXER_MIC, SOUND_MIXER_MONITOR, -1 }, /* ext mic */
6032 { SOUND_MIXER_CD, -1 }, /* cd */
6033 { SOUND_MIXER_SPEAKER, -1 }, /* speaker */
6034 { SOUND_MIXER_DIGITAL1, SOUND_MIXER_DIGITAL2, SOUND_MIXER_DIGITAL3,
6036 { SOUND_MIXER_LINE, SOUND_MIXER_LINE1, SOUND_MIXER_LINE2,
6037 SOUND_MIXER_LINE3, SOUND_MIXER_PHONEIN, SOUND_MIXER_PHONEOUT,
6038 SOUND_MIXER_VIDEO, SOUND_MIXER_RADIO, SOUND_MIXER_DIGITAL1,
6039 SOUND_MIXER_DIGITAL2, SOUND_MIXER_DIGITAL3, SOUND_MIXER_MONITOR,
6043 /* Surely known names */
6044 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
6045 w = hdac_widget_get(devinfo, i);
6046 if (w == NULL || w->enable == 0)
6048 if (w->bindas == -1)
6052 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
6053 if (as[w->bindas].dir == HDA_CTL_OUT)
6056 switch (w->wclass.pin.config & HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) {
6057 case HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN:
6060 case HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN:
6061 if ((w->wclass.pin.config & HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK)
6062 == HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_JACK)
6066 case HDA_CONFIG_DEFAULTCONF_DEVICE_CD:
6069 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER:
6072 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_IN:
6073 case HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_IN:
6080 while (types[type][j] >= 0 &&
6081 (used & (1 << types[type][j])) != 0) {
6084 if (types[type][j] >= 0)
6085 use = types[type][j];
6087 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT:
6088 use = SOUND_MIXER_PCM;
6090 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET:
6091 use = SOUND_MIXER_SPEAKER;
6101 /* Semi-known names */
6102 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
6103 w = hdac_widget_get(devinfo, i);
6104 if (w == NULL || w->enable == 0)
6108 if (w->bindas == -1)
6110 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
6112 if (as[w->bindas].dir == HDA_CTL_OUT)
6115 switch (w->wclass.pin.config & HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) {
6116 case HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_OUT:
6117 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER:
6118 case HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT:
6119 case HDA_CONFIG_DEFAULTCONF_DEVICE_AUX:
6122 case HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN:
6125 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_OUT:
6126 case HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_OUT:
6133 while (types[type][j] >= 0 &&
6134 (used & (1 << types[type][j])) != 0) {
6137 if (types[type][j] >= 0) {
6138 w->ossdev = types[type][j];
6139 used |= (1 << types[type][j]);
6143 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
6144 w = hdac_widget_get(devinfo, i);
6145 if (w == NULL || w->enable == 0)
6149 if (w->bindas == -1)
6151 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
6153 if (as[w->bindas].dir == HDA_CTL_OUT)
6156 while (types[6][j] >= 0 &&
6157 (used & (1 << types[6][j])) != 0) {
6160 if (types[6][j] >= 0) {
6161 w->ossdev = types[6][j];
6162 used |= (1 << types[6][j]);
6168 hdac_audio_build_tree(struct hdac_devinfo *devinfo)
6170 struct hdac_audio_as *as = devinfo->function.audio.as;
6173 /* Trace all associations in order of their numbers, */
6174 for (j = 0; j < devinfo->function.audio.ascnt; j++) {
6175 if (as[j].enable == 0)
6178 device_printf(devinfo->codec->sc->dev,
6179 "Tracing association %d (%d)\n", j, as[j].index);
6181 if (as[j].dir == HDA_CTL_OUT) {
6183 res = hdac_audio_trace_as_out(devinfo, j, 0);
6184 if (res == 0 && as[j].hpredir >= 0 &&
6185 as[j].fakeredir == 0) {
6186 /* If codec can't do analog HP redirection
6187 try to make it using one more DAC. */
6188 as[j].fakeredir = 1;
6192 res = hdac_audio_trace_as_in(devinfo, j);
6196 device_printf(devinfo->codec->sc->dev,
6197 "Association %d (%d) trace succeeded\n",
6202 device_printf(devinfo->codec->sc->dev,
6203 "Association %d (%d) trace failed\n",
6210 /* Trace mixer and beeper pseudo associations. */
6211 hdac_audio_trace_as_extra(devinfo);
6215 hdac_audio_assign_mixers(struct hdac_devinfo *devinfo)
6217 struct hdac_audio_as *as = devinfo->function.audio.as;
6218 struct hdac_audio_ctl *ctl;
6219 struct hdac_widget *w, *cw;
6222 /* Assign mixers to the tree. */
6223 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
6224 w = hdac_widget_get(devinfo, i);
6225 if (w == NULL || w->enable == 0)
6227 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT ||
6228 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET ||
6229 (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
6230 as[w->bindas].dir == HDA_CTL_IN)) {
6233 hdac_audio_ctl_source_amp(devinfo, w->nid, -1,
6234 w->ossdev, 1, 0, 1);
6235 } else if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
6236 hdac_audio_ctl_dest_amp(devinfo, w->nid, -1,
6237 SOUND_MIXER_RECLEV, 0, 1);
6238 } else if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
6239 as[w->bindas].dir == HDA_CTL_OUT) {
6240 hdac_audio_ctl_dest_amp(devinfo, w->nid, -1,
6241 SOUND_MIXER_VOLUME, 0, 1);
6243 if (w->ossdev == SOUND_MIXER_IMIX) {
6244 if (hdac_audio_ctl_source_amp(devinfo, w->nid, -1,
6245 w->ossdev, 1, 0, 1)) {
6246 /* If we are unable to control input monitor
6247 as source - try to control it as destination. */
6248 hdac_audio_ctl_dest_amp(devinfo, w->nid, -1,
6252 if (w->pflags & HDA_ADC_MONITOR) {
6253 for (j = 0; j < w->nconns; j++) {
6254 if (!w->connsenable[j])
6256 cw = hdac_widget_get(devinfo, w->conns[j]);
6257 if (cw == NULL || cw->enable == 0)
6259 if (cw->bindas == -1)
6261 if (cw->bindas >= 0 &&
6262 as[cw->bindas].dir != HDA_CTL_IN)
6264 hdac_audio_ctl_dest_amp(devinfo,
6265 w->nid, j, SOUND_MIXER_IGAIN, 0, 1);
6269 /* Treat unrequired as possible. */
6271 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) {
6272 if (ctl->ossmask == 0)
6273 ctl->ossmask = ctl->possmask;
6278 hdac_audio_prepare_pin_ctrl(struct hdac_devinfo *devinfo)
6280 struct hdac_audio_as *as = devinfo->function.audio.as;
6281 struct hdac_widget *w;
6285 for (i = 0; i < devinfo->nodecnt; i++) {
6286 w = &devinfo->widget[i];
6289 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
6292 pincap = w->wclass.pin.cap;
6294 /* Disable everything. */
6295 w->wclass.pin.ctrl &= ~(
6296 HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE |
6297 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE |
6298 HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE |
6299 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK);
6301 if (w->enable == 0 ||
6302 w->bindas < 0 || as[w->bindas].enable == 0) {
6303 /* Pin is unused so left it disabled. */
6305 } else if (as[w->bindas].dir == HDA_CTL_IN) {
6306 /* Input pin, configure for input. */
6307 if (HDA_PARAM_PIN_CAP_INPUT_CAP(pincap))
6308 w->wclass.pin.ctrl |=
6309 HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE;
6311 if ((devinfo->function.audio.quirks & HDA_QUIRK_IVREF100) &&
6312 HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap))
6313 w->wclass.pin.ctrl |=
6314 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
6315 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_100);
6316 else if ((devinfo->function.audio.quirks & HDA_QUIRK_IVREF80) &&
6317 HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap))
6318 w->wclass.pin.ctrl |=
6319 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
6320 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_80);
6321 else if ((devinfo->function.audio.quirks & HDA_QUIRK_IVREF50) &&
6322 HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap))
6323 w->wclass.pin.ctrl |=
6324 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
6325 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_50);
6327 /* Output pin, configure for output. */
6328 if (HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap))
6329 w->wclass.pin.ctrl |=
6330 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
6332 if (HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap) &&
6333 (w->wclass.pin.config &
6334 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) ==
6335 HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT)
6336 w->wclass.pin.ctrl |=
6337 HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE;
6339 if ((devinfo->function.audio.quirks & HDA_QUIRK_OVREF100) &&
6340 HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap))
6341 w->wclass.pin.ctrl |=
6342 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
6343 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_100);
6344 else if ((devinfo->function.audio.quirks & HDA_QUIRK_OVREF80) &&
6345 HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap))
6346 w->wclass.pin.ctrl |=
6347 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
6348 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_80);
6349 else if ((devinfo->function.audio.quirks & HDA_QUIRK_OVREF50) &&
6350 HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap))
6351 w->wclass.pin.ctrl |=
6352 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
6353 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_50);
6359 hdac_audio_ctl_commit(struct hdac_devinfo *devinfo)
6361 struct hdac_audio_ctl *ctl;
6365 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) {
6366 if (ctl->enable == 0 || ctl->ossmask != 0) {
6367 /* Mute disabled and mixer controllable controls.
6368 * Last will be initialized by mixer_init().
6369 * This expected to reduce click on startup. */
6370 hdac_audio_ctl_amp_set(ctl, HDA_AMP_MUTE_ALL, 0, 0);
6373 /* Init fixed controls to 0dB amplification. */
6377 hdac_audio_ctl_amp_set(ctl, HDA_AMP_MUTE_NONE, z, z);
6382 hdac_audio_commit(struct hdac_devinfo *devinfo)
6384 struct hdac_softc *sc = devinfo->codec->sc;
6385 struct hdac_widget *w;
6387 uint32_t gdata, gmask, gdir;
6388 int commitgpio, numgpio;
6391 cad = devinfo->codec->cad;
6393 if (sc->pci_subvendor == APPLE_INTEL_MAC)
6394 hdac_command(sc, HDA_CMD_12BIT(cad, devinfo->nid,
6397 /* Commit controls. */
6398 hdac_audio_ctl_commit(devinfo);
6400 /* Commit selectors, pins and EAPD. */
6401 for (i = 0; i < devinfo->nodecnt; i++) {
6402 w = &devinfo->widget[i];
6405 if (w->selconn == -1)
6408 hdac_widget_connection_select(w, w->selconn);
6409 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) {
6411 HDA_CMD_SET_PIN_WIDGET_CTRL(cad, w->nid,
6412 w->wclass.pin.ctrl), cad);
6414 if (w->param.eapdbtl != HDAC_INVALID) {
6417 val = w->param.eapdbtl;
6418 if (devinfo->function.audio.quirks &
6420 val ^= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
6422 HDA_CMD_SET_EAPD_BTL_ENABLE(cad, w->nid,
6432 numgpio = HDA_PARAM_GPIO_COUNT_NUM_GPIO(
6433 devinfo->function.audio.gpio);
6435 if (devinfo->function.audio.quirks & HDA_QUIRK_GPIOFLUSH)
6436 commitgpio = (numgpio > 0) ? 1 : 0;
6438 for (i = 0; i < numgpio && i < HDA_GPIO_MAX; i++) {
6439 if (!(devinfo->function.audio.quirks &
6442 if (commitgpio == 0) {
6445 gdata = hdac_command(sc,
6446 HDA_CMD_GET_GPIO_DATA(cad,
6447 devinfo->nid), cad);
6448 gmask = hdac_command(sc,
6449 HDA_CMD_GET_GPIO_ENABLE_MASK(cad,
6450 devinfo->nid), cad);
6451 gdir = hdac_command(sc,
6452 HDA_CMD_GET_GPIO_DIRECTION(cad,
6453 devinfo->nid), cad);
6454 device_printf(sc->dev,
6455 "GPIO init: data=0x%08x "
6456 "mask=0x%08x dir=0x%08x\n",
6457 gdata, gmask, gdir);
6469 if (commitgpio != 0) {
6471 device_printf(sc->dev,
6472 "GPIO commit: data=0x%08x mask=0x%08x "
6474 gdata, gmask, gdir);
6477 HDA_CMD_SET_GPIO_ENABLE_MASK(cad, devinfo->nid,
6480 HDA_CMD_SET_GPIO_DIRECTION(cad, devinfo->nid,
6483 HDA_CMD_SET_GPIO_DATA(cad, devinfo->nid,
6489 hdac_powerup(struct hdac_devinfo *devinfo)
6491 struct hdac_softc *sc = devinfo->codec->sc;
6492 nid_t cad = devinfo->codec->cad;
6496 HDA_CMD_SET_POWER_STATE(cad,
6497 devinfo->nid, HDA_CMD_POWER_STATE_D0),
6501 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
6503 HDA_CMD_SET_POWER_STATE(cad,
6504 i, HDA_CMD_POWER_STATE_D0),
6511 hdac_pcmchannel_setup(struct hdac_chan *ch)
6513 struct hdac_devinfo *devinfo = ch->devinfo;
6514 struct hdac_audio_as *as = devinfo->function.audio.as;
6515 struct hdac_widget *w;
6516 uint32_t cap, fmtcap, pcmcap;
6517 int i, j, ret, channels, onlystereo;
6520 ch->caps = hdac_caps;
6521 ch->caps.fmtlist = ch->fmtlist;
6524 ch->pcmrates[0] = 48000;
6525 ch->pcmrates[1] = 0;
6531 fmtcap = devinfo->function.audio.supp_stream_formats;
6532 pcmcap = devinfo->function.audio.supp_pcm_size_rate;
6534 for (i = 0; i < 16; i++) {
6535 /* Check as is correct */
6538 /* Cound only present DACs */
6539 if (as[ch->as].dacs[i] <= 0)
6541 /* Ignore duplicates */
6542 for (j = 0; j < ret; j++) {
6543 if (ch->io[j] == as[ch->as].dacs[i])
6549 w = hdac_widget_get(devinfo, as[ch->as].dacs[i]);
6550 if (w == NULL || w->enable == 0)
6552 cap = w->param.supp_stream_formats;
6553 if (!HDA_PARAM_SUPP_STREAM_FORMATS_PCM(cap) &&
6554 !HDA_PARAM_SUPP_STREAM_FORMATS_AC3(cap))
6556 /* Many CODECs does not declare AC3 support on SPDIF.
6557 I don't beleave that they doesn't support it! */
6558 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap))
6559 cap |= HDA_PARAM_SUPP_STREAM_FORMATS_AC3_MASK;
6562 pcmcap = w->param.supp_pcm_size_rate;
6565 pcmcap &= w->param.supp_pcm_size_rate;
6567 ch->io[ret++] = as[ch->as].dacs[i];
6568 /* Do not count redirection pin/dac channels. */
6569 if (i == 15 && as[ch->as].hpredir >= 0)
6571 channels += HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap) + 1;
6572 if (HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap) != 1)
6578 if (as[ch->as].fakeredir)
6580 /* Standard speaks only about stereo pins and playback, ... */
6581 if ((!onlystereo) || as[ch->as].dir != HDA_CTL_OUT)
6583 /* ..., but there it gives us info about speakers layout. */
6584 as[ch->as].pinset = pinset;
6586 ch->supp_stream_formats = fmtcap;
6587 ch->supp_pcm_size_rate = pcmcap;
6598 if (HDA_PARAM_SUPP_STREAM_FORMATS_PCM(fmtcap)) {
6599 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16BIT(pcmcap))
6601 else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8BIT(pcmcap))
6603 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(pcmcap))
6605 else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(pcmcap))
6607 else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(pcmcap))
6609 if (!(devinfo->function.audio.quirks & HDA_QUIRK_FORCESTEREO)) {
6610 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 1, 0);
6612 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 1, 0);
6614 if (channels >= 2) {
6615 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 2, 0);
6617 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 2, 0);
6619 if (channels == 4 || /* Any 4-channel */
6620 pinset == 0x0007 || /* 5.1 */
6621 pinset == 0x0013 || /* 5.1 */
6622 pinset == 0x0017) { /* 7.1 */
6623 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 4, 0);
6625 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 4, 0);
6627 if (channels == 6 || /* Any 6-channel */
6628 pinset == 0x0017) { /* 7.1 */
6629 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 6, 1);
6631 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 6, 1);
6633 if (channels == 8) { /* Any 8-channel */
6634 ch->fmtlist[i++] = SND_FORMAT(AFMT_S16_LE, 8, 1);
6636 ch->fmtlist[i++] = SND_FORMAT(AFMT_S32_LE, 8, 1);
6639 if (HDA_PARAM_SUPP_STREAM_FORMATS_AC3(fmtcap)) {
6640 ch->fmtlist[i++] = SND_FORMAT(AFMT_AC3, 2, 0);
6644 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8KHZ(pcmcap))
6645 ch->pcmrates[i++] = 8000;
6646 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_11KHZ(pcmcap))
6647 ch->pcmrates[i++] = 11025;
6648 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16KHZ(pcmcap))
6649 ch->pcmrates[i++] = 16000;
6650 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_22KHZ(pcmcap))
6651 ch->pcmrates[i++] = 22050;
6652 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32KHZ(pcmcap))
6653 ch->pcmrates[i++] = 32000;
6654 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_44KHZ(pcmcap))
6655 ch->pcmrates[i++] = 44100;
6656 /* if (HDA_PARAM_SUPP_PCM_SIZE_RATE_48KHZ(pcmcap)) */
6657 ch->pcmrates[i++] = 48000;
6658 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_88KHZ(pcmcap))
6659 ch->pcmrates[i++] = 88200;
6660 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_96KHZ(pcmcap))
6661 ch->pcmrates[i++] = 96000;
6662 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_176KHZ(pcmcap))
6663 ch->pcmrates[i++] = 176400;
6664 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_192KHZ(pcmcap))
6665 ch->pcmrates[i++] = 192000;
6666 /* if (HDA_PARAM_SUPP_PCM_SIZE_RATE_384KHZ(pcmcap)) */
6667 ch->pcmrates[i] = 0;
6669 ch->caps.minspeed = ch->pcmrates[0];
6670 ch->caps.maxspeed = ch->pcmrates[i - 1];
6678 hdac_create_pcms(struct hdac_devinfo *devinfo)
6680 struct hdac_softc *sc = devinfo->codec->sc;
6681 struct hdac_audio_as *as = devinfo->function.audio.as;
6682 int i, j, apdev = 0, ardev = 0, dpdev = 0, drdev = 0;
6684 for (i = 0; i < devinfo->function.audio.ascnt; i++) {
6685 if (as[i].enable == 0)
6687 if (as[i].dir == HDA_CTL_IN) {
6699 devinfo->function.audio.num_devs =
6700 max(ardev, apdev) + max(drdev, dpdev);
6701 devinfo->function.audio.devs =
6702 (struct hdac_pcm_devinfo *)malloc(
6703 devinfo->function.audio.num_devs * sizeof(struct hdac_pcm_devinfo),
6704 M_HDAC, M_ZERO | M_NOWAIT);
6705 if (devinfo->function.audio.devs == NULL) {
6706 device_printf(sc->dev,
6707 "Unable to allocate memory for devices\n");
6710 for (i = 0; i < devinfo->function.audio.num_devs; i++) {
6711 devinfo->function.audio.devs[i].index = i;
6712 devinfo->function.audio.devs[i].devinfo = devinfo;
6713 devinfo->function.audio.devs[i].play = -1;
6714 devinfo->function.audio.devs[i].rec = -1;
6715 devinfo->function.audio.devs[i].digital = 255;
6717 for (i = 0; i < devinfo->function.audio.ascnt; i++) {
6718 if (as[i].enable == 0)
6720 for (j = 0; j < devinfo->function.audio.num_devs; j++) {
6721 if (devinfo->function.audio.devs[j].digital != 255 &&
6722 (!devinfo->function.audio.devs[j].digital) !=
6725 if (as[i].dir == HDA_CTL_IN) {
6726 if (devinfo->function.audio.devs[j].rec >= 0)
6728 devinfo->function.audio.devs[j].rec
6731 if (devinfo->function.audio.devs[j].play >= 0)
6733 devinfo->function.audio.devs[j].play
6736 sc->chans[as[i].chan].pdevinfo =
6737 &devinfo->function.audio.devs[j];
6738 devinfo->function.audio.devs[j].digital =
6743 for (i = 0; i < devinfo->function.audio.num_devs; i++) {
6744 struct hdac_pcm_devinfo *pdevinfo =
6745 &devinfo->function.audio.devs[i];
6747 device_add_child(sc->dev, "pcm", -1);
6748 device_set_ivars(pdevinfo->dev,
6754 hdac_dump_ctls(struct hdac_pcm_devinfo *pdevinfo, const char *banner, uint32_t flag)
6756 struct hdac_devinfo *devinfo = pdevinfo->devinfo;
6757 struct hdac_audio_ctl *ctl;
6758 struct hdac_softc *sc = devinfo->codec->sc;
6763 flag = ~(SOUND_MASK_VOLUME | SOUND_MASK_PCM |
6764 SOUND_MASK_CD | SOUND_MASK_LINE | SOUND_MASK_RECLEV |
6765 SOUND_MASK_MIC | SOUND_MASK_SPEAKER | SOUND_MASK_IGAIN |
6766 SOUND_MASK_OGAIN | SOUND_MASK_IMIX | SOUND_MASK_MONITOR);
6769 for (j = 0; j < SOUND_MIXER_NRDEVICES; j++) {
6770 if ((flag & (1 << j)) == 0)
6774 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) {
6775 if (ctl->enable == 0 ||
6776 ctl->widget->enable == 0)
6778 if (!((pdevinfo->play >= 0 &&
6779 ctl->widget->bindas == sc->chans[pdevinfo->play].as) ||
6780 (pdevinfo->rec >= 0 &&
6781 ctl->widget->bindas == sc->chans[pdevinfo->rec].as) ||
6782 (ctl->widget->bindas == -2 && pdevinfo->index == 0)))
6784 if ((ctl->ossmask & (1 << j)) == 0)
6788 device_printf(pdevinfo->dev, "\n");
6789 if (banner != NULL) {
6790 device_printf(pdevinfo->dev, "%s", banner);
6792 device_printf(pdevinfo->dev, "Unknown Ctl");
6794 printf(" (OSS: %s)\n",
6795 hdac_audio_ctl_ossmixer_mask2allname(1 << j,
6797 device_printf(pdevinfo->dev, " |\n");
6800 device_printf(pdevinfo->dev, " +- ctl %2d (nid %3d %s", i,
6802 (ctl->ndir == HDA_CTL_IN)?"in ":"out");
6803 if (ctl->ndir == HDA_CTL_IN && ctl->ndir == ctl->dir)
6804 printf(" %2d): ", ctl->index);
6807 if (ctl->step > 0) {
6808 printf("%+d/%+ddB (%d steps)%s\n",
6809 (0 - ctl->offset) * (ctl->size + 1) / 4,
6810 (ctl->step - ctl->offset) * (ctl->size + 1) / 4,
6812 ctl->mute?" + mute":"");
6814 printf("%s\n", ctl->mute?"mute":"");
6820 hdac_dump_audio_formats(device_t dev, uint32_t fcap, uint32_t pcmcap)
6826 device_printf(dev, " Stream cap: 0x%08x\n", cap);
6827 device_printf(dev, " ");
6828 if (HDA_PARAM_SUPP_STREAM_FORMATS_AC3(cap))
6830 if (HDA_PARAM_SUPP_STREAM_FORMATS_FLOAT32(cap))
6832 if (HDA_PARAM_SUPP_STREAM_FORMATS_PCM(cap))
6838 device_printf(dev, " PCM cap: 0x%08x\n", cap);
6839 device_printf(dev, " ");
6840 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8BIT(cap))
6842 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16BIT(cap))
6844 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(cap))
6846 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(cap))
6848 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(cap))
6851 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8KHZ(cap))
6853 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_11KHZ(cap))
6855 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16KHZ(cap))
6857 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_22KHZ(cap))
6859 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32KHZ(cap))
6861 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_44KHZ(cap))
6864 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_88KHZ(cap))
6866 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_96KHZ(cap))
6868 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_176KHZ(cap))
6870 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_192KHZ(cap))
6877 hdac_dump_pin(struct hdac_softc *sc, struct hdac_widget *w)
6881 pincap = w->wclass.pin.cap;
6883 device_printf(sc->dev, " Pin cap: 0x%08x\n", pincap);
6884 device_printf(sc->dev, " ");
6885 if (HDA_PARAM_PIN_CAP_IMP_SENSE_CAP(pincap))
6887 if (HDA_PARAM_PIN_CAP_TRIGGER_REQD(pincap))
6889 if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(pincap))
6891 if (HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap))
6893 if (HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap))
6895 if (HDA_PARAM_PIN_CAP_INPUT_CAP(pincap))
6897 if (HDA_PARAM_PIN_CAP_BALANCED_IO_PINS(pincap))
6899 if (HDA_PARAM_PIN_CAP_HDMI(pincap))
6901 if (HDA_PARAM_PIN_CAP_VREF_CTRL(pincap)) {
6903 if (HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap))
6905 if (HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap))
6907 if (HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap))
6909 if (HDA_PARAM_PIN_CAP_VREF_CTRL_GROUND(pincap))
6911 if (HDA_PARAM_PIN_CAP_VREF_CTRL_HIZ(pincap))
6915 if (HDA_PARAM_PIN_CAP_EAPD_CAP(pincap))
6917 if (HDA_PARAM_PIN_CAP_DP(pincap))
6919 if (HDA_PARAM_PIN_CAP_HBR(pincap))
6922 device_printf(sc->dev, " Pin config: 0x%08x\n",
6923 w->wclass.pin.config);
6924 device_printf(sc->dev, " Pin control: 0x%08x", w->wclass.pin.ctrl);
6925 if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE)
6927 if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE)
6929 if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE)
6931 if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK)
6937 hdac_dump_pin_config(struct hdac_widget *w, uint32_t conf)
6939 struct hdac_softc *sc = w->devinfo->codec->sc;
6941 device_printf(sc->dev, " nid %d 0x%08x as %2d seq %2d %13s %5s "
6942 "jack %2d loc %2d color %7s misc %d%s\n",
6944 HDA_CONFIG_DEFAULTCONF_ASSOCIATION(conf),
6945 HDA_CONFIG_DEFAULTCONF_SEQUENCE(conf),
6946 HDA_DEVS[HDA_CONFIG_DEFAULTCONF_DEVICE(conf)],
6947 HDA_CONNS[HDA_CONFIG_DEFAULTCONF_CONNECTIVITY(conf)],
6948 HDA_CONFIG_DEFAULTCONF_CONNECTION_TYPE(conf),
6949 HDA_CONFIG_DEFAULTCONF_LOCATION(conf),
6950 HDA_COLORS[HDA_CONFIG_DEFAULTCONF_COLOR(conf)],
6951 HDA_CONFIG_DEFAULTCONF_MISC(conf),
6952 (w->enable == 0)?" [DISABLED]":"");
6956 hdac_dump_pin_configs(struct hdac_devinfo *devinfo)
6958 struct hdac_widget *w;
6961 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
6962 w = hdac_widget_get(devinfo, i);
6965 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
6967 hdac_dump_pin_config(w, w->wclass.pin.config);
6972 hdac_dump_amp(struct hdac_softc *sc, uint32_t cap, char *banner)
6974 device_printf(sc->dev, " %s amp: 0x%08x\n", banner, cap);
6975 device_printf(sc->dev, " "
6976 "mute=%d step=%d size=%d offset=%d\n",
6977 HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(cap),
6978 HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(cap),
6979 HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(cap),
6980 HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(cap));
6984 hdac_dump_nodes(struct hdac_devinfo *devinfo)
6986 struct hdac_softc *sc = devinfo->codec->sc;
6987 static char *ossname[] = SOUND_DEVICE_NAMES;
6988 struct hdac_widget *w, *cw;
6992 device_printf(sc->dev, "\n");
6993 device_printf(sc->dev, "Default Parameter\n");
6994 device_printf(sc->dev, "-----------------\n");
6995 hdac_dump_audio_formats(sc->dev,
6996 devinfo->function.audio.supp_stream_formats,
6997 devinfo->function.audio.supp_pcm_size_rate);
6998 device_printf(sc->dev, " IN amp: 0x%08x\n",
6999 devinfo->function.audio.inamp_cap);
7000 device_printf(sc->dev, " OUT amp: 0x%08x\n",
7001 devinfo->function.audio.outamp_cap);
7002 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
7003 w = hdac_widget_get(devinfo, i);
7005 device_printf(sc->dev, "Ghost widget nid=%d\n", i);
7008 device_printf(sc->dev, "\n");
7009 device_printf(sc->dev, " nid: %d%s\n", w->nid,
7010 (w->enable == 0) ? " [DISABLED]" : "");
7011 device_printf(sc->dev, " Name: %s\n", w->name);
7012 device_printf(sc->dev, " Widget cap: 0x%08x\n",
7013 w->param.widget_cap);
7014 if (w->param.widget_cap & 0x0ee1) {
7015 device_printf(sc->dev, " ");
7016 if (HDA_PARAM_AUDIO_WIDGET_CAP_LR_SWAP(w->param.widget_cap))
7018 if (HDA_PARAM_AUDIO_WIDGET_CAP_POWER_CTRL(w->param.widget_cap))
7020 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap))
7022 if (HDA_PARAM_AUDIO_WIDGET_CAP_UNSOL_CAP(w->param.widget_cap))
7024 if (HDA_PARAM_AUDIO_WIDGET_CAP_PROC_WIDGET(w->param.widget_cap))
7026 if (HDA_PARAM_AUDIO_WIDGET_CAP_STRIPE(w->param.widget_cap))
7028 j = HDA_PARAM_AUDIO_WIDGET_CAP_CC(w->param.widget_cap);
7032 printf(" %dCH", j + 1);
7035 if (w->bindas != -1) {
7036 device_printf(sc->dev, " Association: %d (0x%08x)\n",
7037 w->bindas, w->bindseqmask);
7039 if (w->ossmask != 0 || w->ossdev >= 0) {
7040 device_printf(sc->dev, " OSS: %s",
7041 hdac_audio_ctl_ossmixer_mask2allname(w->ossmask, buf, sizeof(buf)));
7043 printf(" (%s)", ossname[w->ossdev]);
7046 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT ||
7047 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
7048 hdac_dump_audio_formats(sc->dev,
7049 w->param.supp_stream_formats,
7050 w->param.supp_pcm_size_rate);
7051 } else if (w->type ==
7052 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
7053 hdac_dump_pin(sc, w);
7054 if (w->param.eapdbtl != HDAC_INVALID)
7055 device_printf(sc->dev, " EAPD: 0x%08x\n",
7057 if (HDA_PARAM_AUDIO_WIDGET_CAP_OUT_AMP(w->param.widget_cap) &&
7058 w->param.outamp_cap != 0)
7059 hdac_dump_amp(sc, w->param.outamp_cap, "Output");
7060 if (HDA_PARAM_AUDIO_WIDGET_CAP_IN_AMP(w->param.widget_cap) &&
7061 w->param.inamp_cap != 0)
7062 hdac_dump_amp(sc, w->param.inamp_cap, " Input");
7063 if (w->nconns > 0) {
7064 device_printf(sc->dev, " connections: %d\n", w->nconns);
7065 device_printf(sc->dev, " |\n");
7067 for (j = 0; j < w->nconns; j++) {
7068 cw = hdac_widget_get(devinfo, w->conns[j]);
7069 device_printf(sc->dev, " + %s<- nid=%d [%s]",
7070 (w->connsenable[j] == 0)?"[DISABLED] ":"",
7071 w->conns[j], (cw == NULL) ? "GHOST!" : cw->name);
7073 printf(" [UNKNOWN]");
7074 else if (cw->enable == 0)
7075 printf(" [DISABLED]");
7076 if (w->nconns > 1 && w->selconn == j && w->type !=
7077 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
7078 printf(" (selected)");
7086 hdac_dump_dst_nid(struct hdac_pcm_devinfo *pdevinfo, nid_t nid, int depth)
7088 struct hdac_devinfo *devinfo = pdevinfo->devinfo;
7089 struct hdac_widget *w, *cw;
7093 if (depth > HDA_PARSE_MAXDEPTH)
7096 w = hdac_widget_get(devinfo, nid);
7097 if (w == NULL || w->enable == 0)
7101 device_printf(pdevinfo->dev, "%*s", 4, "");
7103 device_printf(pdevinfo->dev, "%*s + <- ", 4 + (depth - 1) * 7, "");
7104 printf("nid=%d [%s]", w->nid, w->name);
7107 if (w->ossmask == 0) {
7111 printf(" [src: %s]",
7112 hdac_audio_ctl_ossmixer_mask2allname(
7113 w->ossmask, buf, sizeof(buf)));
7114 if (w->ossdev >= 0) {
7121 for (i = 0; i < w->nconns; i++) {
7122 if (w->connsenable[i] == 0)
7124 cw = hdac_widget_get(devinfo, w->conns[i]);
7125 if (cw == NULL || cw->enable == 0 || cw->bindas == -1)
7128 device_printf(pdevinfo->dev, "%*s |\n", 4 + (depth) * 7, "");
7131 hdac_dump_dst_nid(pdevinfo, w->conns[i], depth + 1);
7137 hdac_dump_dac(struct hdac_pcm_devinfo *pdevinfo)
7139 struct hdac_devinfo *devinfo = pdevinfo->devinfo;
7140 struct hdac_softc *sc = devinfo->codec->sc;
7141 struct hdac_audio_as *as;
7142 struct hdac_widget *w;
7145 if (pdevinfo->play < 0)
7148 as = &devinfo->function.audio.as[sc->chans[pdevinfo->play].as];
7149 for (i = 0; i < 16; i++) {
7150 if (as->pins[i] <= 0)
7152 w = hdac_widget_get(devinfo, as->pins[i]);
7153 if (w == NULL || w->enable == 0)
7157 device_printf(pdevinfo->dev, "\n");
7158 device_printf(pdevinfo->dev, "Playback:\n");
7160 device_printf(pdevinfo->dev, "\n");
7161 hdac_dump_dst_nid(pdevinfo, as->pins[i], 0);
7166 hdac_dump_adc(struct hdac_pcm_devinfo *pdevinfo)
7168 struct hdac_devinfo *devinfo = pdevinfo->devinfo;
7169 struct hdac_softc *sc = devinfo->codec->sc;
7170 struct hdac_widget *w;
7174 if (pdevinfo->rec < 0)
7177 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
7178 w = hdac_widget_get(devinfo, i);
7179 if (w == NULL || w->enable == 0)
7181 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT)
7183 if (w->bindas != sc->chans[pdevinfo->rec].as)
7187 device_printf(pdevinfo->dev, "\n");
7188 device_printf(pdevinfo->dev, "Record:\n");
7190 device_printf(pdevinfo->dev, "\n");
7191 hdac_dump_dst_nid(pdevinfo, i, 0);
7196 hdac_dump_mix(struct hdac_pcm_devinfo *pdevinfo)
7198 struct hdac_devinfo *devinfo = pdevinfo->devinfo;
7199 struct hdac_widget *w;
7203 if (pdevinfo->index != 0)
7206 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
7207 w = hdac_widget_get(devinfo, i);
7208 if (w == NULL || w->enable == 0)
7210 if (w->ossdev != SOUND_MIXER_IMIX)
7214 device_printf(pdevinfo->dev, "\n");
7215 device_printf(pdevinfo->dev, "Input Mix:\n");
7217 device_printf(pdevinfo->dev, "\n");
7218 hdac_dump_dst_nid(pdevinfo, i, 0);
7223 hdac_dump_pcmchannels(struct hdac_pcm_devinfo *pdevinfo)
7225 struct hdac_softc *sc = pdevinfo->devinfo->codec->sc;
7229 if (pdevinfo->play >= 0) {
7231 device_printf(pdevinfo->dev, "\n");
7232 device_printf(pdevinfo->dev, "Playback:\n");
7233 device_printf(pdevinfo->dev, "\n");
7234 hdac_dump_audio_formats(pdevinfo->dev, sc->chans[i].supp_stream_formats,
7235 sc->chans[i].supp_pcm_size_rate);
7236 device_printf(pdevinfo->dev, " DAC:");
7237 for (nids = sc->chans[i].io; *nids != -1; nids++)
7238 printf(" %d", *nids);
7241 if (pdevinfo->rec >= 0) {
7243 device_printf(pdevinfo->dev, "\n");
7244 device_printf(pdevinfo->dev, "Record:\n");
7245 device_printf(pdevinfo->dev, "\n");
7246 hdac_dump_audio_formats(pdevinfo->dev, sc->chans[i].supp_stream_formats,
7247 sc->chans[i].supp_pcm_size_rate);
7248 device_printf(pdevinfo->dev, " ADC:");
7249 for (nids = sc->chans[i].io; *nids != -1; nids++)
7250 printf(" %d", *nids);
7256 hdac_release_resources(struct hdac_softc *sc)
7266 callout_stop(&sc->poll_hda);
7267 callout_stop(&sc->poll_hdac);
7268 callout_stop(&sc->poll_jack);
7271 taskqueue_drain(taskqueue_thread, &sc->unsolq_task);
7272 callout_drain(&sc->poll_hda);
7273 callout_drain(&sc->poll_hdac);
7274 callout_drain(&sc->poll_jack);
7278 for (i = 0; i < HDAC_CODEC_MAX; i++) {
7279 if (sc->codecs[i] == NULL)
7281 for (j = 0; j < sc->codecs[i]->num_fgs; j++) {
7282 free(sc->codecs[i]->fgs[j].widget, M_HDAC);
7283 if (sc->codecs[i]->fgs[j].node_type ==
7284 HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO) {
7285 free(sc->codecs[i]->fgs[j].function.audio.ctl,
7287 free(sc->codecs[i]->fgs[j].function.audio.as,
7289 free(sc->codecs[i]->fgs[j].function.audio.devs,
7293 free(sc->codecs[i]->fgs, M_HDAC);
7294 free(sc->codecs[i], M_HDAC);
7295 sc->codecs[i] = NULL;
7298 hdac_dma_free(sc, &sc->pos_dma);
7299 hdac_dma_free(sc, &sc->rirb_dma);
7300 hdac_dma_free(sc, &sc->corb_dma);
7301 for (i = 0; i < sc->num_chans; i++) {
7302 if (sc->chans[i].blkcnt > 0)
7303 hdac_dma_free(sc, &sc->chans[i].bdl_dma);
7305 free(sc->chans, M_HDAC);
7306 if (sc->chan_dmat != NULL) {
7307 bus_dma_tag_destroy(sc->chan_dmat);
7308 sc->chan_dmat = NULL;
7311 snd_mtxfree(sc->lock);
7314 /* This function surely going to make its way into upper level someday. */
7316 hdac_config_fetch(struct hdac_softc *sc, uint32_t *on, uint32_t *off)
7318 const char *res = NULL;
7319 int i = 0, j, k, len, inv;
7327 if (resource_string_value(device_get_name(sc->dev),
7328 device_get_unit(sc->dev), "config", &res) != 0)
7330 if (!(res != NULL && strlen(res) > 0))
7333 device_printf(sc->dev, "HDA Config:");
7336 while (res[i] != '\0' &&
7337 (res[i] == ',' || isspace(res[i]) != 0))
7339 if (res[i] == '\0') {
7346 while (res[j] != '\0' &&
7347 !(res[j] == ',' || isspace(res[j]) != 0))
7350 if (len > 2 && strncmp(res + i, "no", 2) == 0)
7354 for (k = 0; len > inv && k < HDAC_QUIRKS_TAB_LEN; k++) {
7355 if (strncmp(res + i + inv,
7356 hdac_quirks_tab[k].key, len - inv) != 0)
7358 if (len - inv != strlen(hdac_quirks_tab[k].key))
7361 printf(" %s%s", (inv != 0) ? "no" : "",
7362 hdac_quirks_tab[k].key);
7364 if (inv == 0 && on != NULL)
7365 *on |= hdac_quirks_tab[k].value;
7366 else if (inv != 0 && off != NULL)
7367 *off |= hdac_quirks_tab[k].value;
7375 sysctl_hdac_polling(SYSCTL_HANDLER_ARGS)
7377 struct hdac_softc *sc;
7382 dev = oidp->oid_arg1;
7383 sc = device_get_softc(dev);
7389 err = sysctl_handle_int(oidp, &val, 0, req);
7391 if (err != 0 || req->newptr == NULL)
7393 if (val < 0 || val > 1)
7397 if (val != sc->polling) {
7399 callout_stop(&sc->poll_hda);
7400 callout_stop(&sc->poll_hdac);
7402 callout_drain(&sc->poll_hda);
7403 callout_drain(&sc->poll_hdac);
7406 ctl = HDAC_READ_4(&sc->mem, HDAC_INTCTL);
7407 ctl |= HDAC_INTCTL_GIE;
7408 HDAC_WRITE_4(&sc->mem, HDAC_INTCTL, ctl);
7410 ctl = HDAC_READ_4(&sc->mem, HDAC_INTCTL);
7411 ctl &= ~HDAC_INTCTL_GIE;
7412 HDAC_WRITE_4(&sc->mem, HDAC_INTCTL, ctl);
7414 taskqueue_drain(taskqueue_thread, &sc->unsolq_task);
7417 hdac_poll_reinit(sc);
7418 callout_reset(&sc->poll_hdac, 1, hdac_poll_callback, sc);
7427 sysctl_hdac_polling_interval(SYSCTL_HANDLER_ARGS)
7429 struct hdac_softc *sc;
7433 dev = oidp->oid_arg1;
7434 sc = device_get_softc(dev);
7438 val = ((uint64_t)sc->poll_ival * 1000) / hz;
7440 err = sysctl_handle_int(oidp, &val, 0, req);
7442 if (err != 0 || req->newptr == NULL)
7449 val = ((uint64_t)val * hz) / 1000;
7456 sc->poll_ival = val;
7463 sysctl_hdac_pindump(SYSCTL_HANDLER_ARGS)
7465 struct hdac_softc *sc;
7466 struct hdac_codec *codec;
7467 struct hdac_devinfo *devinfo;
7468 struct hdac_widget *w;
7470 uint32_t res, pincap, delay;
7471 int codec_index, fg_index;
7475 dev = oidp->oid_arg1;
7476 sc = device_get_softc(dev);
7480 err = sysctl_handle_int(oidp, &val, 0, req);
7481 if (err != 0 || req->newptr == NULL || val == 0)
7484 /* XXX: Temporary. For debugging. */
7488 } else if (val == 101) {
7494 for (codec_index = 0; codec_index < HDAC_CODEC_MAX; codec_index++) {
7495 codec = sc->codecs[codec_index];
7499 for (fg_index = 0; fg_index < codec->num_fgs; fg_index++) {
7500 devinfo = &codec->fgs[fg_index];
7501 if (devinfo->node_type !=
7502 HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO)
7505 device_printf(dev, "Dumping AFG cad=%d nid=%d pins:\n",
7506 codec_index, devinfo->nid);
7507 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
7508 w = hdac_widget_get(devinfo, i);
7509 if (w == NULL || w->type !=
7510 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
7512 hdac_dump_pin_config(w, w->wclass.pin.config);
7513 pincap = w->wclass.pin.cap;
7514 device_printf(dev, " Caps: %2s %3s %2s %4s %4s",
7515 HDA_PARAM_PIN_CAP_INPUT_CAP(pincap)?"IN":"",
7516 HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap)?"OUT":"",
7517 HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap)?"HP":"",
7518 HDA_PARAM_PIN_CAP_EAPD_CAP(pincap)?"EAPD":"",
7519 HDA_PARAM_PIN_CAP_VREF_CTRL(pincap)?"VREF":"");
7520 if (HDA_PARAM_PIN_CAP_IMP_SENSE_CAP(pincap) ||
7521 HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(pincap)) {
7522 if (HDA_PARAM_PIN_CAP_TRIGGER_REQD(pincap)) {
7525 HDA_CMD_SET_PIN_SENSE(cad, w->nid, 0), cad);
7527 res = hdac_command(sc,
7528 HDA_CMD_GET_PIN_SENSE(cad, w->nid), cad);
7529 if (res != 0x7fffffff && res != 0xffffffff)
7532 } while (++delay < 10000);
7535 res = hdac_command(sc, HDA_CMD_GET_PIN_SENSE(cad,
7538 printf(" Sense: 0x%08x", res);
7540 printf(" delay %dus", delay * 10);
7545 "NumGPIO=%d NumGPO=%d NumGPI=%d GPIWake=%d GPIUnsol=%d\n",
7546 HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->function.audio.gpio),
7547 HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->function.audio.gpio),
7548 HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->function.audio.gpio),
7549 HDA_PARAM_GPIO_COUNT_GPI_WAKE(devinfo->function.audio.gpio),
7550 HDA_PARAM_GPIO_COUNT_GPI_UNSOL(devinfo->function.audio.gpio));
7551 if (HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->function.audio.gpio) > 0) {
7552 device_printf(dev, " GPI:");
7553 res = hdac_command(sc,
7554 HDA_CMD_GET_GPI_DATA(cad, devinfo->nid), cad);
7555 printf(" data=0x%08x", res);
7556 res = hdac_command(sc,
7557 HDA_CMD_GET_GPI_WAKE_ENABLE_MASK(cad, devinfo->nid),
7559 printf(" wake=0x%08x", res);
7560 res = hdac_command(sc,
7561 HDA_CMD_GET_GPI_UNSOLICITED_ENABLE_MASK(cad, devinfo->nid),
7563 printf(" unsol=0x%08x", res);
7564 res = hdac_command(sc,
7565 HDA_CMD_GET_GPI_STICKY_MASK(cad, devinfo->nid), cad);
7566 printf(" sticky=0x%08x\n", res);
7568 if (HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->function.audio.gpio) > 0) {
7569 device_printf(dev, " GPO:");
7570 res = hdac_command(sc,
7571 HDA_CMD_GET_GPO_DATA(cad, devinfo->nid), cad);
7572 printf(" data=0x%08x\n", res);
7574 if (HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->function.audio.gpio) > 0) {
7575 device_printf(dev, "GPIO:");
7576 res = hdac_command(sc,
7577 HDA_CMD_GET_GPIO_DATA(cad, devinfo->nid), cad);
7578 printf(" data=0x%08x", res);
7579 res = hdac_command(sc,
7580 HDA_CMD_GET_GPIO_ENABLE_MASK(cad, devinfo->nid), cad);
7581 printf(" enable=0x%08x", res);
7582 res = hdac_command(sc,
7583 HDA_CMD_GET_GPIO_DIRECTION(cad, devinfo->nid), cad);
7584 printf(" direction=0x%08x\n", res);
7585 res = hdac_command(sc,
7586 HDA_CMD_GET_GPIO_WAKE_ENABLE_MASK(cad, devinfo->nid), cad);
7587 device_printf(dev, " wake=0x%08x", res);
7588 res = hdac_command(sc,
7589 HDA_CMD_GET_GPIO_UNSOLICITED_ENABLE_MASK(cad, devinfo->nid),
7591 printf(" unsol=0x%08x", res);
7592 res = hdac_command(sc,
7593 HDA_CMD_GET_GPIO_STICKY_MASK(cad, devinfo->nid), cad);
7594 printf(" sticky=0x%08x\n", res);
7603 hdac_attach2(void *arg)
7605 struct hdac_codec *codec;
7606 struct hdac_softc *sc;
7607 struct hdac_audio_ctl *ctl;
7608 uint32_t quirks_on, quirks_off;
7609 int codec_index, fg_index;
7610 int i, dmaalloc = 0;
7611 struct hdac_devinfo *devinfo;
7613 sc = (struct hdac_softc *)arg;
7615 hdac_config_fetch(sc, &quirks_on, &quirks_off);
7618 device_printf(sc->dev, "HDA Config: on=0x%08x off=0x%08x\n",
7619 quirks_on, quirks_off);
7624 /* Remove ourselves from the config hooks */
7625 if (sc->intrhook.ich_func != NULL) {
7626 config_intrhook_disestablish(&sc->intrhook);
7627 sc->intrhook.ich_func = NULL;
7630 /* Start the corb and rirb engines */
7632 device_printf(sc->dev, "Starting CORB Engine...\n");
7634 hdac_corb_start(sc);
7636 device_printf(sc->dev, "Starting RIRB Engine...\n");
7638 hdac_rirb_start(sc);
7641 device_printf(sc->dev,
7642 "Enabling controller interrupt...\n");
7644 HDAC_WRITE_4(&sc->mem, HDAC_GCTL, HDAC_READ_4(&sc->mem, HDAC_GCTL) |
7646 if (sc->polling == 0) {
7647 HDAC_WRITE_4(&sc->mem, HDAC_INTCTL,
7648 HDAC_INTCTL_CIE | HDAC_INTCTL_GIE);
7650 callout_reset(&sc->poll_hdac, 1, hdac_poll_callback, sc);
7655 device_printf(sc->dev,
7656 "Scanning HDA codecs ...\n");
7658 hdac_scan_codecs(sc);
7660 for (codec_index = 0; codec_index < HDAC_CODEC_MAX; codec_index++) {
7661 codec = sc->codecs[codec_index];
7664 for (fg_index = 0; fg_index < codec->num_fgs; fg_index++) {
7665 devinfo = &codec->fgs[fg_index];
7667 device_printf(sc->dev, "\n");
7668 device_printf(sc->dev,
7669 "Processing %s FG cad=%d nid=%d...\n",
7670 (devinfo->node_type == HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO) ? "audio":
7671 (devinfo->node_type == HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_MODEM) ? "modem":
7673 devinfo->codec->cad, devinfo->nid);
7675 if (devinfo->node_type !=
7676 HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO) {
7678 device_printf(sc->dev,
7679 "Powering down...\n");
7682 HDA_CMD_SET_POWER_STATE(codec->cad,
7683 devinfo->nid, HDA_CMD_POWER_STATE_D3),
7689 device_printf(sc->dev, "Powering up...\n");
7691 hdac_powerup(devinfo);
7693 device_printf(sc->dev, "Parsing audio FG...\n");
7695 hdac_audio_parse(devinfo);
7697 device_printf(sc->dev, "Parsing Ctls...\n");
7699 hdac_audio_ctl_parse(devinfo);
7701 device_printf(sc->dev, "Parsing vendor patch...\n");
7703 hdac_vendor_patch_parse(devinfo);
7704 devinfo->function.audio.quirks |= quirks_on;
7705 devinfo->function.audio.quirks &= ~quirks_off;
7708 device_printf(sc->dev, "Disabling nonaudio...\n");
7710 hdac_audio_disable_nonaudio(devinfo);
7712 device_printf(sc->dev, "Disabling useless...\n");
7714 hdac_audio_disable_useless(devinfo);
7716 device_printf(sc->dev, "Patched pins configuration:\n");
7717 hdac_dump_pin_configs(devinfo);
7720 device_printf(sc->dev, "Parsing pin associations...\n");
7722 hdac_audio_as_parse(devinfo);
7724 device_printf(sc->dev, "Building AFG tree...\n");
7726 hdac_audio_build_tree(devinfo);
7728 device_printf(sc->dev, "Disabling unassociated "
7731 hdac_audio_disable_unas(devinfo);
7733 device_printf(sc->dev, "Disabling nonselected "
7736 hdac_audio_disable_notselected(devinfo);
7738 device_printf(sc->dev, "Disabling useless...\n");
7740 hdac_audio_disable_useless(devinfo);
7742 device_printf(sc->dev, "Disabling "
7743 "crossassociatement connections...\n");
7745 hdac_audio_disable_crossas(devinfo);
7747 device_printf(sc->dev, "Disabling useless...\n");
7749 hdac_audio_disable_useless(devinfo);
7751 device_printf(sc->dev, "Binding associations to channels...\n");
7753 hdac_audio_bind_as(devinfo);
7755 device_printf(sc->dev, "Assigning names to signal sources...\n");
7757 hdac_audio_assign_names(devinfo);
7759 device_printf(sc->dev, "Assigning mixers to the tree...\n");
7761 hdac_audio_assign_mixers(devinfo);
7763 device_printf(sc->dev, "Preparing pin controls...\n");
7765 hdac_audio_prepare_pin_ctrl(devinfo);
7767 device_printf(sc->dev, "AFG commit...\n");
7769 hdac_audio_commit(devinfo);
7771 device_printf(sc->dev, "HP switch init...\n");
7773 hdac_hp_switch_init(devinfo);
7775 if ((devinfo->function.audio.quirks & HDA_QUIRK_DMAPOS) &&
7777 if (hdac_dma_alloc(sc, &sc->pos_dma,
7778 (sc->num_iss + sc->num_oss + sc->num_bss) * 8) != 0) {
7780 device_printf(sc->dev, "Failed to "
7781 "allocate DMA pos buffer "
7789 device_printf(sc->dev, "Creating PCM devices...\n");
7791 hdac_create_pcms(devinfo);
7794 if (devinfo->function.audio.quirks != 0) {
7795 device_printf(sc->dev, "FG config/quirks:");
7796 for (i = 0; i < HDAC_QUIRKS_TAB_LEN; i++) {
7797 if ((devinfo->function.audio.quirks &
7798 hdac_quirks_tab[i].value) ==
7799 hdac_quirks_tab[i].value)
7800 printf(" %s", hdac_quirks_tab[i].key);
7805 device_printf(sc->dev, "\n");
7806 device_printf(sc->dev, "+-------------------+\n");
7807 device_printf(sc->dev, "| DUMPING HDA NODES |\n");
7808 device_printf(sc->dev, "+-------------------+\n");
7809 hdac_dump_nodes(devinfo);
7813 device_printf(sc->dev, "\n");
7814 device_printf(sc->dev, "+------------------------+\n");
7815 device_printf(sc->dev, "| DUMPING HDA AMPLIFIERS |\n");
7816 device_printf(sc->dev, "+------------------------+\n");
7817 device_printf(sc->dev, "\n");
7819 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) {
7820 device_printf(sc->dev, "%3d: nid %3d %s (%s) index %d", i,
7821 (ctl->widget != NULL) ? ctl->widget->nid : -1,
7822 (ctl->ndir == HDA_CTL_IN)?"in ":"out",
7823 (ctl->dir == HDA_CTL_IN)?"in ":"out",
7825 if (ctl->childwidget != NULL)
7826 printf(" cnid %3d", ctl->childwidget->nid);
7829 printf(" ossmask=0x%08x\n",
7831 device_printf(sc->dev,
7832 " mute: %d step: %3d size: %3d off: %3d%s\n",
7833 ctl->mute, ctl->step, ctl->size, ctl->offset,
7834 (ctl->enable == 0) ? " [DISABLED]" :
7835 ((ctl->ossmask == 0) ? " [UNUSED]" : ""));
7843 device_printf(sc->dev, "\n");
7846 bus_generic_attach(sc->dev);
7848 SYSCTL_ADD_PROC(device_get_sysctl_ctx(sc->dev),
7849 SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev)), OID_AUTO,
7850 "polling", CTLTYPE_INT | CTLFLAG_RW, sc->dev, sizeof(sc->dev),
7851 sysctl_hdac_polling, "I", "Enable polling mode");
7852 SYSCTL_ADD_PROC(device_get_sysctl_ctx(sc->dev),
7853 SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev)), OID_AUTO,
7854 "polling_interval", CTLTYPE_INT | CTLFLAG_RW, sc->dev,
7855 sizeof(sc->dev), sysctl_hdac_polling_interval, "I",
7856 "Controller/Jack Sense polling interval (1-1000 ms)");
7857 SYSCTL_ADD_PROC(device_get_sysctl_ctx(sc->dev),
7858 SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev)), OID_AUTO,
7859 "pindump", CTLTYPE_INT | CTLFLAG_RW, sc->dev, sizeof(sc->dev),
7860 sysctl_hdac_pindump, "I", "Dump pin states/data");
7863 /****************************************************************************
7864 * int hdac_suspend(device_t)
7866 * Suspend and power down HDA bus and codecs.
7867 ****************************************************************************/
7869 hdac_suspend(device_t dev)
7871 struct hdac_softc *sc;
7872 struct hdac_codec *codec;
7873 struct hdac_devinfo *devinfo;
7874 int codec_index, fg_index, i;
7877 device_printf(dev, "Suspend...\n");
7880 sc = device_get_softc(dev);
7884 device_printf(dev, "Stop streams...\n");
7886 for (i = 0; i < sc->num_chans; i++) {
7887 if (sc->chans[i].flags & HDAC_CHN_RUNNING) {
7888 sc->chans[i].flags |= HDAC_CHN_SUSPEND;
7889 hdac_channel_stop(sc, &sc->chans[i]);
7893 for (codec_index = 0; codec_index < HDAC_CODEC_MAX; codec_index++) {
7894 codec = sc->codecs[codec_index];
7897 for (fg_index = 0; fg_index < codec->num_fgs; fg_index++) {
7898 devinfo = &codec->fgs[fg_index];
7902 " cad=%d nid=%d to the D3 state...\n",
7903 codec->cad, devinfo->nid);
7906 HDA_CMD_SET_POWER_STATE(codec->cad,
7907 devinfo->nid, HDA_CMD_POWER_STATE_D3),
7913 device_printf(dev, "Reset controller...\n");
7915 callout_stop(&sc->poll_hda);
7916 callout_stop(&sc->poll_hdac);
7917 callout_stop(&sc->poll_jack);
7920 taskqueue_drain(taskqueue_thread, &sc->unsolq_task);
7921 callout_drain(&sc->poll_hda);
7922 callout_drain(&sc->poll_hdac);
7923 callout_drain(&sc->poll_jack);
7926 device_printf(dev, "Suspend done\n");
7932 /****************************************************************************
7933 * int hdac_resume(device_t)
7935 * Powerup and restore HDA bus and codecs state.
7936 ****************************************************************************/
7938 hdac_resume(device_t dev)
7940 struct hdac_softc *sc;
7941 struct hdac_codec *codec;
7942 struct hdac_devinfo *devinfo;
7943 int codec_index, fg_index, i;
7946 device_printf(dev, "Resume...\n");
7949 sc = device_get_softc(dev);
7952 /* Quiesce everything */
7954 device_printf(dev, "Reset controller...\n");
7958 /* Initialize the CORB and RIRB */
7962 /* Start the corb and rirb engines */
7964 device_printf(dev, "Starting CORB Engine...\n");
7966 hdac_corb_start(sc);
7968 device_printf(dev, "Starting RIRB Engine...\n");
7970 hdac_rirb_start(sc);
7974 "Enabling controller interrupt...\n");
7976 HDAC_WRITE_4(&sc->mem, HDAC_GCTL, HDAC_READ_4(&sc->mem, HDAC_GCTL) |
7978 if (sc->polling == 0) {
7979 HDAC_WRITE_4(&sc->mem, HDAC_INTCTL,
7980 HDAC_INTCTL_CIE | HDAC_INTCTL_GIE);
7982 callout_reset(&sc->poll_hdac, 1, hdac_poll_callback, sc);
7986 for (codec_index = 0; codec_index < HDAC_CODEC_MAX; codec_index++) {
7987 codec = sc->codecs[codec_index];
7990 for (fg_index = 0; fg_index < codec->num_fgs; fg_index++) {
7991 devinfo = &codec->fgs[fg_index];
7992 if (devinfo->node_type !=
7993 HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO) {
7996 "Power down unsupported non-audio FG"
7997 " cad=%d nid=%d to the D3 state...\n",
7998 codec->cad, devinfo->nid);
8001 HDA_CMD_SET_POWER_STATE(codec->cad,
8002 devinfo->nid, HDA_CMD_POWER_STATE_D3),
8009 "Power up audio FG cad=%d nid=%d...\n",
8010 devinfo->codec->cad, devinfo->nid);
8012 hdac_powerup(devinfo);
8014 device_printf(dev, "AFG commit...\n");
8016 hdac_audio_commit(devinfo);
8018 device_printf(dev, "HP switch init...\n");
8020 hdac_hp_switch_init(devinfo);
8023 for (i = 0; i < devinfo->function.audio.num_devs; i++) {
8024 struct hdac_pcm_devinfo *pdevinfo =
8025 &devinfo->function.audio.devs[i];
8027 device_printf(pdevinfo->dev,
8028 "OSS mixer reinitialization...\n");
8030 if (mixer_reinit(pdevinfo->dev) == -1)
8031 device_printf(pdevinfo->dev,
8032 "unable to reinitialize the mixer\n");
8039 device_printf(dev, "Start streams...\n");
8041 for (i = 0; i < sc->num_chans; i++) {
8042 if (sc->chans[i].flags & HDAC_CHN_SUSPEND) {
8043 sc->chans[i].flags &= ~HDAC_CHN_SUSPEND;
8044 hdac_channel_start(sc, &sc->chans[i]);
8051 device_printf(dev, "Resume done\n");
8056 /****************************************************************************
8057 * int hdac_detach(device_t)
8059 * Detach and free up resources utilized by the hdac device.
8060 ****************************************************************************/
8062 hdac_detach(device_t dev)
8064 struct hdac_softc *sc;
8066 int i, devcount, error;
8068 if ((error = device_get_children(dev, &devlist, &devcount)) != 0)
8070 for (i = 0; i < devcount; i++) {
8071 if ((error = device_delete_child(dev, devlist[i])) != 0) {
8072 free(devlist, M_TEMP);
8076 free(devlist, M_TEMP);
8078 sc = device_get_softc(dev);
8079 hdac_release_resources(sc);
8085 hdac_print_child(device_t dev, device_t child)
8087 struct hdac_pcm_devinfo *pdevinfo =
8088 (struct hdac_pcm_devinfo *)device_get_ivars(child);
8091 retval = bus_print_child_header(dev, child);
8092 retval += printf(" at cad %d nid %d",
8093 pdevinfo->devinfo->codec->cad, pdevinfo->devinfo->nid);
8094 retval += bus_print_child_footer(dev, child);
8099 static device_method_t hdac_methods[] = {
8100 /* device interface */
8101 DEVMETHOD(device_probe, hdac_probe),
8102 DEVMETHOD(device_attach, hdac_attach),
8103 DEVMETHOD(device_detach, hdac_detach),
8104 DEVMETHOD(device_suspend, hdac_suspend),
8105 DEVMETHOD(device_resume, hdac_resume),
8107 DEVMETHOD(bus_print_child, hdac_print_child),
8111 static driver_t hdac_driver = {
8114 sizeof(struct hdac_softc),
8117 static devclass_t hdac_devclass;
8119 DRIVER_MODULE(snd_hda, pci, hdac_driver, hdac_devclass, 0, 0);
8120 MODULE_DEPEND(snd_hda, sound, SOUND_MINVER, SOUND_PREFVER, SOUND_MAXVER);
8121 MODULE_VERSION(snd_hda, 1);
8124 hdac_pcm_probe(device_t dev)
8126 struct hdac_pcm_devinfo *pdevinfo =
8127 (struct hdac_pcm_devinfo *)device_get_ivars(dev);
8130 snprintf(buf, sizeof(buf), "HDA %s PCM #%d %s",
8131 hdac_codec_name(pdevinfo->devinfo->codec),
8133 (pdevinfo->digital == 3)?"DisplayPort":
8134 ((pdevinfo->digital == 2)?"HDMI":
8135 ((pdevinfo->digital)?"Digital":"Analog")));
8136 device_set_desc_copy(dev, buf);
8141 hdac_pcm_attach(device_t dev)
8143 struct hdac_pcm_devinfo *pdevinfo =
8144 (struct hdac_pcm_devinfo *)device_get_ivars(dev);
8145 struct hdac_softc *sc = pdevinfo->devinfo->codec->sc;
8146 char status[SND_STATUSLEN];
8149 pdevinfo->chan_size = pcm_getbuffersize(dev,
8150 HDA_BUFSZ_MIN, HDA_BUFSZ_DEFAULT, HDA_BUFSZ_MAX);
8153 device_printf(dev, "+--------------------------------------+\n");
8154 device_printf(dev, "| DUMPING PCM Playback/Record Channels |\n");
8155 device_printf(dev, "+--------------------------------------+\n");
8156 hdac_dump_pcmchannels(pdevinfo);
8157 device_printf(dev, "\n");
8158 device_printf(dev, "+-------------------------------+\n");
8159 device_printf(dev, "| DUMPING Playback/Record Paths |\n");
8160 device_printf(dev, "+-------------------------------+\n");
8161 hdac_dump_dac(pdevinfo);
8162 hdac_dump_adc(pdevinfo);
8163 hdac_dump_mix(pdevinfo);
8164 device_printf(dev, "\n");
8165 device_printf(dev, "+-------------------------+\n");
8166 device_printf(dev, "| DUMPING Volume Controls |\n");
8167 device_printf(dev, "+-------------------------+\n");
8168 hdac_dump_ctls(pdevinfo, "Master Volume", SOUND_MASK_VOLUME);
8169 hdac_dump_ctls(pdevinfo, "PCM Volume", SOUND_MASK_PCM);
8170 hdac_dump_ctls(pdevinfo, "CD Volume", SOUND_MASK_CD);
8171 hdac_dump_ctls(pdevinfo, "Microphone Volume", SOUND_MASK_MIC);
8172 hdac_dump_ctls(pdevinfo, "Microphone2 Volume", SOUND_MASK_MONITOR);
8173 hdac_dump_ctls(pdevinfo, "Line-in Volume", SOUND_MASK_LINE);
8174 hdac_dump_ctls(pdevinfo, "Speaker/Beep Volume", SOUND_MASK_SPEAKER);
8175 hdac_dump_ctls(pdevinfo, "Recording Level", SOUND_MASK_RECLEV);
8176 hdac_dump_ctls(pdevinfo, "Input Mix Level", SOUND_MASK_IMIX);
8177 hdac_dump_ctls(pdevinfo, "Input Monitoring Level", SOUND_MASK_IGAIN);
8178 hdac_dump_ctls(pdevinfo, NULL, 0);
8179 device_printf(dev, "\n");
8182 if (resource_int_value(device_get_name(dev),
8183 device_get_unit(dev), "blocksize", &i) == 0 && i > 0) {
8185 if (i < HDA_BLK_MIN)
8187 pdevinfo->chan_blkcnt = pdevinfo->chan_size / i;
8189 while (pdevinfo->chan_blkcnt >> i)
8191 pdevinfo->chan_blkcnt = 1 << (i - 1);
8192 if (pdevinfo->chan_blkcnt < HDA_BDL_MIN)
8193 pdevinfo->chan_blkcnt = HDA_BDL_MIN;
8194 else if (pdevinfo->chan_blkcnt > HDA_BDL_MAX)
8195 pdevinfo->chan_blkcnt = HDA_BDL_MAX;
8197 pdevinfo->chan_blkcnt = HDA_BDL_DEFAULT;
8200 * We don't register interrupt handler with snd_setup_intr
8201 * in pcm device. Mark pcm device as MPSAFE manually.
8203 pcm_setflags(dev, pcm_getflags(dev) | SD_F_MPSAFE);
8206 device_printf(dev, "OSS mixer initialization...\n");
8208 if (mixer_init(dev, &hdac_audio_ctl_ossmixer_class, pdevinfo) != 0)
8209 device_printf(dev, "Can't register mixer\n");
8212 device_printf(dev, "Registering PCM channels...\n");
8214 if (pcm_register(dev, pdevinfo, (pdevinfo->play >= 0)?1:0,
8215 (pdevinfo->rec >= 0)?1:0) != 0)
8216 device_printf(dev, "Can't register PCM\n");
8218 pdevinfo->registered++;
8220 if (pdevinfo->play >= 0)
8221 pcm_addchan(dev, PCMDIR_PLAY, &hdac_channel_class, pdevinfo);
8222 if (pdevinfo->rec >= 0)
8223 pcm_addchan(dev, PCMDIR_REC, &hdac_channel_class, pdevinfo);
8225 snprintf(status, SND_STATUSLEN, "at cad %d nid %d on %s %s",
8226 pdevinfo->devinfo->codec->cad, pdevinfo->devinfo->nid,
8227 device_get_nameunit(sc->dev), PCM_KLDSTRING(snd_hda));
8228 pcm_setstatus(dev, status);
8234 hdac_pcm_detach(device_t dev)
8236 struct hdac_pcm_devinfo *pdevinfo =
8237 (struct hdac_pcm_devinfo *)device_get_ivars(dev);
8240 if (pdevinfo->registered > 0) {
8241 err = pcm_unregister(dev);
8249 static device_method_t hdac_pcm_methods[] = {
8250 /* device interface */
8251 DEVMETHOD(device_probe, hdac_pcm_probe),
8252 DEVMETHOD(device_attach, hdac_pcm_attach),
8253 DEVMETHOD(device_detach, hdac_pcm_detach),
8257 static driver_t hdac_pcm_driver = {
8263 DRIVER_MODULE(snd_hda_pcm, hdac, hdac_pcm_driver, pcm_devclass, 0, 0);