2 * Copyright (c) 2006 Stephane E. Potvin <sepotvin@videotron.ca>
3 * Copyright (c) 2006 Ariff Abdullah <ariff@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * $FreeBSD: src/sys/dev/sound/pci/hda/hdac.c,v 1.36.2.6 2007/10/26 20:48:18 ariff Exp $
28 * $DragonFly: src/sys/dev/sound/pci/hda/hdac.c,v 1.12 2007/11/30 07:53:53 hasso Exp $
32 * Intel High Definition Audio (Controller) driver for FreeBSD. Be advised
33 * that this driver still in its early stage, and possible of rewrite are
34 * pretty much guaranteed. There are supposedly several distinct parent/child
35 * busses to make this "perfect", but as for now and for the sake of
36 * simplicity, everything is gobble up within single source.
39 * 1) HDA Controller support
40 * 2) HDA Codecs support, which may include
44 * 3) Widget parser - the real magic of why this driver works on so
45 * many hardwares with minimal vendor specific quirk. The original
46 * parser was written using Ruby and can be found at
47 * http://people.freebsd.org/~ariff/HDA/parser.rb . This crude
48 * ruby parser take the verbose dmesg dump as its input. Refer to
49 * http://www.microsoft.com/whdc/device/audio/default.mspx for various
50 * interesting documents, especially UAA (Universal Audio Architecture).
51 * 4) Possible vendor specific support.
52 * (snd_hda_intel, snd_hda_ati, etc..)
54 * Thanks to Ahmad Ubaidah Omar @ Defenxis Sdn. Bhd. for the
55 * Compaq V3000 with Conexant HDA.
57 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
59 * * This driver is a collaborative effort made by: *
61 * * Stephane E. Potvin <sepotvin@videotron.ca> *
62 * * Andrea Bittau <a.bittau@cs.ucl.ac.uk> *
63 * * Wesley Morgan <morganw@chemikals.org> *
64 * * Daniel Eischen <deischen@FreeBSD.org> *
65 * * Maxime Guillaud <bsd-ports@mguillaud.net> *
66 * * Ariff Abdullah <ariff@FreeBSD.org> *
68 * * ....and various people from freebsd-multimedia@FreeBSD.org *
70 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
73 #include <dev/sound/pcm/sound.h>
74 #include <bus/pci/pcireg.h>
75 #include <bus/pci/pcivar.h>
77 #include <sys/ctype.h>
78 #include <sys/taskqueue.h>
80 #include <dev/sound/pci/hda/hdac_private.h>
81 #include <dev/sound/pci/hda/hdac_reg.h>
82 #include <dev/sound/pci/hda/hda_reg.h>
83 #include <dev/sound/pci/hda/hdac.h>
87 #define HDA_DRV_TEST_REV "20071020_0048"
88 #define HDA_WIDGET_PARSER_REV 1
90 SND_DECLARE_FILE("$DragonFly: src/sys/dev/sound/pci/hda/hdac.c,v 1.12 2007/11/30 07:53:53 hasso Exp $");
92 #define HDA_BOOTVERBOSE(stmt) do { \
93 if (bootverbose != 0) { \
99 #undef HDAC_INTR_EXTRA
100 #define HDAC_INTR_EXTRA 1
103 #define hdac_lock(sc) snd_mtxlock((sc)->lock)
104 #define hdac_unlock(sc) snd_mtxunlock((sc)->lock)
105 #define hdac_lockassert(sc) snd_mtxassert((sc)->lock)
106 #define hdac_lockowned(sc) (1)/* mtx_owned((sc)->lock) */
108 #if 0 /* TODO: No uncacheable DMA support in DragonFly. */
109 #include <machine/specialreg.h>
110 #define HDAC_DMA_ATTR(sc, v, s, attr) do { \
111 vm_offset_t va = (vm_offset_t)(v); \
112 vm_size_t sz = (vm_size_t)(s); \
113 if ((sc) != NULL && ((sc)->flags & HDAC_F_DMA_NOCACHE) && \
114 va != 0 && sz != 0) \
115 (void)pmap_change_attr(va, sz, (attr)); \
118 #define HDAC_DMA_ATTR(...)
121 #define HDA_FLAG_MATCH(fl, v) (((fl) & (v)) == (v))
122 #define HDA_DEV_MATCH(fl, v) ((fl) == (v) || \
123 (fl) == 0xffffffff || \
124 (((fl) & 0xffff0000) == 0xffff0000 && \
125 ((fl) & 0x0000ffff) == ((v) & 0x0000ffff)) || \
126 (((fl) & 0x0000ffff) == 0x0000ffff && \
127 ((fl) & 0xffff0000) == ((v) & 0xffff0000)))
128 #define HDA_MATCH_ALL 0xffffffff
129 #define HDAC_INVALID 0xffffffff
131 /* Default controller / jack sense poll: 250ms */
132 #define HDAC_POLL_INTERVAL max(hz >> 2, 1)
135 * Make room for possible 4096 playback/record channels, in 100 years to come.
137 #define HDAC_TRIGGER_NONE 0x00000000
138 #define HDAC_TRIGGER_PLAY 0x00000fff
139 #define HDAC_TRIGGER_REC 0x00fff000
140 #define HDAC_TRIGGER_UNSOL 0x80000000
142 #define HDA_MODEL_CONSTRUCT(vendor, model) \
143 (((uint32_t)(model) << 16) | ((vendor##_VENDORID) & 0xffff))
145 /* Controller models */
148 #define INTEL_VENDORID 0x8086
149 #define HDA_INTEL_82801F HDA_MODEL_CONSTRUCT(INTEL, 0x2668)
150 #define HDA_INTEL_63XXESB HDA_MODEL_CONSTRUCT(INTEL, 0x269a)
151 #define HDA_INTEL_82801G HDA_MODEL_CONSTRUCT(INTEL, 0x27d8)
152 #define HDA_INTEL_82801H HDA_MODEL_CONSTRUCT(INTEL, 0x284b)
153 #define HDA_INTEL_82801I HDA_MODEL_CONSTRUCT(INTEL, 0x293e)
154 #define HDA_INTEL_ALL HDA_MODEL_CONSTRUCT(INTEL, 0xffff)
157 #define NVIDIA_VENDORID 0x10de
158 #define HDA_NVIDIA_MCP51 HDA_MODEL_CONSTRUCT(NVIDIA, 0x026c)
159 #define HDA_NVIDIA_MCP55 HDA_MODEL_CONSTRUCT(NVIDIA, 0x0371)
160 #define HDA_NVIDIA_MCP61A HDA_MODEL_CONSTRUCT(NVIDIA, 0x03e4)
161 #define HDA_NVIDIA_MCP61B HDA_MODEL_CONSTRUCT(NVIDIA, 0x03f0)
162 #define HDA_NVIDIA_MCP65A HDA_MODEL_CONSTRUCT(NVIDIA, 0x044a)
163 #define HDA_NVIDIA_MCP65B HDA_MODEL_CONSTRUCT(NVIDIA, 0x044b)
164 #define HDA_NVIDIA_ALL HDA_MODEL_CONSTRUCT(NVIDIA, 0xffff)
167 #define ATI_VENDORID 0x1002
168 #define HDA_ATI_SB450 HDA_MODEL_CONSTRUCT(ATI, 0x437b)
169 #define HDA_ATI_SB600 HDA_MODEL_CONSTRUCT(ATI, 0x4383)
170 #define HDA_ATI_ALL HDA_MODEL_CONSTRUCT(ATI, 0xffff)
173 #define VIA_VENDORID 0x1106
174 #define HDA_VIA_VT82XX HDA_MODEL_CONSTRUCT(VIA, 0x3288)
175 #define HDA_VIA_ALL HDA_MODEL_CONSTRUCT(VIA, 0xffff)
178 #define SIS_VENDORID 0x1039
179 #define HDA_SIS_966 HDA_MODEL_CONSTRUCT(SIS, 0x7502)
180 #define HDA_SIS_ALL HDA_MODEL_CONSTRUCT(SIS, 0xffff)
185 #define INTEL_D101GGC_SUBVENDOR HDA_MODEL_CONSTRUCT(INTEL, 0xd600)
188 #define HP_VENDORID 0x103c
189 #define HP_V3000_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x30b5)
190 #define HP_NX7400_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x30a2)
191 #define HP_NX6310_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x30aa)
192 #define HP_NX6325_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x30b0)
193 #define HP_XW4300_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x3013)
194 #define HP_3010_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x3010)
195 #define HP_DV5000_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x30a5)
196 #define HP_DC7700_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x2802)
197 #define HP_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0xffff)
198 /* What is wrong with XN 2563 anyway? (Got the picture ?) */
199 #define HP_NX6325_SUBVENDORX 0x103c30b0
202 #define DELL_VENDORID 0x1028
203 #define DELL_D820_SUBVENDOR HDA_MODEL_CONSTRUCT(DELL, 0x01cc)
204 #define DELL_I1300_SUBVENDOR HDA_MODEL_CONSTRUCT(DELL, 0x01c9)
205 #define DELL_XPSM1210_SUBVENDOR HDA_MODEL_CONSTRUCT(DELL, 0x01d7)
206 #define DELL_OPLX745_SUBVENDOR HDA_MODEL_CONSTRUCT(DELL, 0x01da)
207 #define DELL_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(DELL, 0xffff)
210 #define CLEVO_VENDORID 0x1558
211 #define CLEVO_D900T_SUBVENDOR HDA_MODEL_CONSTRUCT(CLEVO, 0x0900)
212 #define CLEVO_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(CLEVO, 0xffff)
215 #define ACER_VENDORID 0x1025
216 #define ACER_A5050_SUBVENDOR HDA_MODEL_CONSTRUCT(ACER, 0x010f)
217 #define ACER_3681WXM_SUBVENDOR HDA_MODEL_CONSTRUCT(ACER, 0x0110)
218 #define ACER_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(ACER, 0xffff)
221 #define ASUS_VENDORID 0x1043
222 #define ASUS_M5200_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x1993)
223 #define ASUS_U5F_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x1263)
224 #define ASUS_A8JC_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x1153)
225 #define ASUS_P1AH2_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x81cb)
226 #define ASUS_A7M_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x1323)
227 #define ASUS_A7T_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x13c2)
228 #define ASUS_W6F_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x1263)
229 #define ASUS_W2J_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x1971)
230 #define ASUS_F3JC_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x1338)
231 #define ASUS_M2V_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x81e7)
232 #define ASUS_M2N_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x8234)
233 #define ASUS_M2NPVMX_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x81cb)
234 #define ASUS_P5BWD_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x81ec)
235 #define ASUS_A8NVMCSM_SUBVENDOR HDA_MODEL_CONSTRUCT(NVIDIA, 0xcb84)
236 #define ASUS_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0xffff)
239 #define IBM_VENDORID 0x1014
240 #define IBM_M52_SUBVENDOR HDA_MODEL_CONSTRUCT(IBM, 0x02f6)
241 #define IBM_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(IBM, 0xffff)
244 #define LENOVO_VENDORID 0x17aa
245 #define LENOVO_3KN100_SUBVENDOR HDA_MODEL_CONSTRUCT(LENOVO, 0x2066)
246 #define LENOVO_TCA55_SUBVENDOR HDA_MODEL_CONSTRUCT(LENOVO, 0x1015)
247 #define LENOVO_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(LENOVO, 0xffff)
250 #define SAMSUNG_VENDORID 0x144d
251 #define SAMSUNG_Q1_SUBVENDOR HDA_MODEL_CONSTRUCT(SAMSUNG, 0xc027)
252 #define SAMSUNG_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(SAMSUNG, 0xffff)
255 #define MEDION_VENDORID 0x161f
256 #define MEDION_MD95257_SUBVENDOR HDA_MODEL_CONSTRUCT(MEDION, 0x203d)
257 #define MEDION_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(MEDION, 0xffff)
260 * Apple Intel MacXXXX seems using Sigmatel codec/vendor id
261 * instead of their own, which is beyond my comprehension
262 * (see HDA_CODEC_STAC9221 below).
264 #define APPLE_INTEL_MAC 0x76808384
267 #define LG_VENDORID 0x1854
268 #define LG_LW20_SUBVENDOR HDA_MODEL_CONSTRUCT(LG, 0x0018)
269 #define LG_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(LG, 0xffff)
271 /* Fujitsu Siemens */
272 #define FS_VENDORID 0x1734
273 #define FS_PA1510_SUBVENDOR HDA_MODEL_CONSTRUCT(FS, 0x10b8)
274 #define FS_SI1848_SUBVENDOR HDA_MODEL_CONSTRUCT(FS, 0x10cd)
275 #define FS_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(FS, 0xffff)
277 /* Fujitsu Limited */
278 #define FL_VENDORID 0x10cf
279 #define FL_S7020D_SUBVENDOR HDA_MODEL_CONSTRUCT(FL, 0x1326)
280 #define FL_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(FL, 0xffff)
283 #define TOSHIBA_VENDORID 0x1179
284 #define TOSHIBA_U200_SUBVENDOR HDA_MODEL_CONSTRUCT(TOSHIBA, 0x0001)
285 #define TOSHIBA_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(TOSHIBA, 0xffff)
287 /* Micro-Star International (MSI) */
288 #define MSI_VENDORID 0x1462
289 #define MSI_MS1034_SUBVENDOR HDA_MODEL_CONSTRUCT(MSI, 0x0349)
290 #define MSI_MS034A_SUBVENDOR HDA_MODEL_CONSTRUCT(MSI, 0x034a)
291 #define MSI_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(MSI, 0xffff)
293 /* Giga-Byte Technology */
294 #define GB_VENDORID 0x1458
295 #define GB_G33S2H_SUBVENDOR HDA_MODEL_CONSTRUCT(GB, 0xa022)
296 #define GP_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(GB, 0xffff)
299 #define UNIWILL_VENDORID 0x1584
300 #define UNIWILL_9075_SUBVENDOR HDA_MODEL_CONSTRUCT(UNIWILL, 0x9075)
301 #define UNIWILL_9080_SUBVENDOR HDA_MODEL_CONSTRUCT(UNIWILL, 0x9080)
304 /* Misc constants.. */
305 #define HDA_AMP_MUTE_DEFAULT (0xffffffff)
306 #define HDA_AMP_MUTE_NONE (0)
307 #define HDA_AMP_MUTE_LEFT (1 << 0)
308 #define HDA_AMP_MUTE_RIGHT (1 << 1)
309 #define HDA_AMP_MUTE_ALL (HDA_AMP_MUTE_LEFT | HDA_AMP_MUTE_RIGHT)
311 #define HDA_AMP_LEFT_MUTED(v) ((v) & (HDA_AMP_MUTE_LEFT))
312 #define HDA_AMP_RIGHT_MUTED(v) (((v) & HDA_AMP_MUTE_RIGHT) >> 1)
314 #define HDA_DAC_PATH (1 << 0)
315 #define HDA_ADC_PATH (1 << 1)
316 #define HDA_ADC_RECSEL (1 << 2)
318 #define HDA_DAC_LOCKED (1 << 3)
319 #define HDA_ADC_LOCKED (1 << 4)
321 #define HDA_CTL_OUT (1 << 0)
322 #define HDA_CTL_IN (1 << 1)
323 #define HDA_CTL_BOTH (HDA_CTL_IN | HDA_CTL_OUT)
325 #define HDA_GPIO_MAX 8
326 /* 0 - 7 = GPIO , 8 = Flush */
327 #define HDA_QUIRK_GPIO0 (1 << 0)
328 #define HDA_QUIRK_GPIO1 (1 << 1)
329 #define HDA_QUIRK_GPIO2 (1 << 2)
330 #define HDA_QUIRK_GPIO3 (1 << 3)
331 #define HDA_QUIRK_GPIO4 (1 << 4)
332 #define HDA_QUIRK_GPIO5 (1 << 5)
333 #define HDA_QUIRK_GPIO6 (1 << 6)
334 #define HDA_QUIRK_GPIO7 (1 << 7)
335 #define HDA_QUIRK_GPIOFLUSH (1 << 8)
337 /* 9 - 25 = anything else */
338 #define HDA_QUIRK_SOFTPCMVOL (1 << 9)
339 #define HDA_QUIRK_FIXEDRATE (1 << 10)
340 #define HDA_QUIRK_FORCESTEREO (1 << 11)
341 #define HDA_QUIRK_EAPDINV (1 << 12)
342 #define HDA_QUIRK_DMAPOS (1 << 13)
344 /* 26 - 31 = vrefs */
345 #define HDA_QUIRK_IVREF50 (1 << 26)
346 #define HDA_QUIRK_IVREF80 (1 << 27)
347 #define HDA_QUIRK_IVREF100 (1 << 28)
348 #define HDA_QUIRK_OVREF50 (1 << 29)
349 #define HDA_QUIRK_OVREF80 (1 << 30)
350 #define HDA_QUIRK_OVREF100 (1 << 31)
352 #define HDA_QUIRK_IVREF (HDA_QUIRK_IVREF50 | HDA_QUIRK_IVREF80 | \
354 #define HDA_QUIRK_OVREF (HDA_QUIRK_OVREF50 | HDA_QUIRK_OVREF80 | \
356 #define HDA_QUIRK_VREF (HDA_QUIRK_IVREF | HDA_QUIRK_OVREF)
358 #define SOUND_MASK_SKIP (1 << 30)
359 #define SOUND_MASK_DISABLE (1 << 31)
361 static const struct {
364 } hdac_quirks_tab[] = {
365 { "gpio0", HDA_QUIRK_GPIO0 },
366 { "gpio1", HDA_QUIRK_GPIO1 },
367 { "gpio2", HDA_QUIRK_GPIO2 },
368 { "gpio3", HDA_QUIRK_GPIO3 },
369 { "gpio4", HDA_QUIRK_GPIO4 },
370 { "gpio5", HDA_QUIRK_GPIO5 },
371 { "gpio6", HDA_QUIRK_GPIO6 },
372 { "gpio7", HDA_QUIRK_GPIO7 },
373 { "gpioflush", HDA_QUIRK_GPIOFLUSH },
374 { "softpcmvol", HDA_QUIRK_SOFTPCMVOL },
375 { "fixedrate", HDA_QUIRK_FIXEDRATE },
376 { "forcestereo", HDA_QUIRK_FORCESTEREO },
377 { "eapdinv", HDA_QUIRK_EAPDINV },
378 { "dmapos", HDA_QUIRK_DMAPOS },
379 { "ivref50", HDA_QUIRK_IVREF50 },
380 { "ivref80", HDA_QUIRK_IVREF80 },
381 { "ivref100", HDA_QUIRK_IVREF100 },
382 { "ovref50", HDA_QUIRK_OVREF50 },
383 { "ovref80", HDA_QUIRK_OVREF80 },
384 { "ovref100", HDA_QUIRK_OVREF100 },
385 { "ivref", HDA_QUIRK_IVREF },
386 { "ovref", HDA_QUIRK_OVREF },
387 { "vref", HDA_QUIRK_VREF },
389 #define HDAC_QUIRKS_TAB_LEN \
390 (sizeof(hdac_quirks_tab) / sizeof(hdac_quirks_tab[0]))
392 #define HDA_BDL_MIN 2
393 #define HDA_BDL_MAX 256
394 #define HDA_BDL_DEFAULT HDA_BDL_MIN
396 #define HDA_BLK_MIN HDAC_DMA_ALIGNMENT
397 #define HDA_BLK_ALIGN (~(HDA_BLK_MIN - 1))
399 #define HDA_BUFSZ_MIN 4096
400 #define HDA_BUFSZ_MAX 65536
401 #define HDA_BUFSZ_DEFAULT 16384
403 #define HDA_PARSE_MAXDEPTH 10
405 #define HDAC_UNSOLTAG_EVENT_HP 0x00
406 #define HDAC_UNSOLTAG_EVENT_TEST 0x01
408 MALLOC_DEFINE(M_HDAC, "hdac", "High Definition Audio Controller");
416 static uint32_t hdac_fmt[] = {
417 AFMT_STEREO | AFMT_S16_LE,
421 static struct pcmchan_caps hdac_caps = {48000, 48000, hdac_fmt, 0};
423 static const struct {
427 { HDA_INTEL_82801F, "Intel 82801F" },
428 { HDA_INTEL_63XXESB, "Intel 631x/632xESB" },
429 { HDA_INTEL_82801G, "Intel 82801G" },
430 { HDA_INTEL_82801H, "Intel 82801H" },
431 { HDA_INTEL_82801I, "Intel 82801I" },
432 { HDA_NVIDIA_MCP51, "NVidia MCP51" },
433 { HDA_NVIDIA_MCP55, "NVidia MCP55" },
434 { HDA_NVIDIA_MCP61A, "NVidia MCP61A" },
435 { HDA_NVIDIA_MCP61B, "NVidia MCP61B" },
436 { HDA_NVIDIA_MCP65A, "NVidia MCP65A" },
437 { HDA_NVIDIA_MCP65B, "NVidia MCP65B" },
438 { HDA_ATI_SB450, "ATI SB450" },
439 { HDA_ATI_SB600, "ATI SB600" },
440 { HDA_VIA_VT82XX, "VIA VT8251/8237A" },
441 { HDA_SIS_966, "SiS 966" },
443 { HDA_INTEL_ALL, "Intel (Unknown)" },
444 { HDA_NVIDIA_ALL, "NVidia (Unknown)" },
445 { HDA_ATI_ALL, "ATI (Unknown)" },
446 { HDA_VIA_ALL, "VIA (Unknown)" },
447 { HDA_SIS_ALL, "SiS (Unknown)" },
449 #define HDAC_DEVICES_LEN (sizeof(hdac_devices) / sizeof(hdac_devices[0]))
451 static const struct {
456 } hdac_pcie_snoop[] = {
457 { INTEL_VENDORID, 0x00, 0x00, 0x00 },
458 { ATI_VENDORID, 0x42, 0xf8, 0x02 },
459 { NVIDIA_VENDORID, 0x4e, 0xf0, 0x0f },
461 #define HDAC_PCIESNOOP_LEN \
462 (sizeof(hdac_pcie_snoop) / sizeof(hdac_pcie_snoop[0]))
464 static const struct {
471 { 8000, 1, 0x0000, 0x0000, 0x0500 }, /* (48000 * 1) / 6 */
472 { 9600, 0, 0x0000, 0x0000, 0x0400 }, /* (48000 * 1) / 5 */
473 { 12000, 0, 0x0000, 0x0000, 0x0300 }, /* (48000 * 1) / 4 */
474 { 16000, 1, 0x0000, 0x0000, 0x0200 }, /* (48000 * 1) / 3 */
475 { 18000, 0, 0x0000, 0x1000, 0x0700 }, /* (48000 * 3) / 8 */
476 { 19200, 0, 0x0000, 0x0800, 0x0400 }, /* (48000 * 2) / 5 */
477 { 24000, 0, 0x0000, 0x0000, 0x0100 }, /* (48000 * 1) / 2 */
478 { 28800, 0, 0x0000, 0x1000, 0x0400 }, /* (48000 * 3) / 5 */
479 { 32000, 1, 0x0000, 0x0800, 0x0200 }, /* (48000 * 2) / 3 */
480 { 36000, 0, 0x0000, 0x1000, 0x0300 }, /* (48000 * 3) / 4 */
481 { 38400, 0, 0x0000, 0x1800, 0x0400 }, /* (48000 * 4) / 5 */
482 { 48000, 1, 0x0000, 0x0000, 0x0000 }, /* (48000 * 1) / 1 */
483 { 64000, 0, 0x0000, 0x1800, 0x0200 }, /* (48000 * 4) / 3 */
484 { 72000, 0, 0x0000, 0x1000, 0x0100 }, /* (48000 * 3) / 2 */
485 { 96000, 1, 0x0000, 0x0800, 0x0000 }, /* (48000 * 2) / 1 */
486 { 144000, 0, 0x0000, 0x1000, 0x0000 }, /* (48000 * 3) / 1 */
487 { 192000, 1, 0x0000, 0x1800, 0x0000 }, /* (48000 * 4) / 1 */
488 { 8820, 0, 0x4000, 0x0000, 0x0400 }, /* (44100 * 1) / 5 */
489 { 11025, 1, 0x4000, 0x0000, 0x0300 }, /* (44100 * 1) / 4 */
490 { 12600, 0, 0x4000, 0x0800, 0x0600 }, /* (44100 * 2) / 7 */
491 { 14700, 0, 0x4000, 0x0000, 0x0200 }, /* (44100 * 1) / 3 */
492 { 17640, 0, 0x4000, 0x0800, 0x0400 }, /* (44100 * 2) / 5 */
493 { 18900, 0, 0x4000, 0x1000, 0x0600 }, /* (44100 * 3) / 7 */
494 { 22050, 1, 0x4000, 0x0000, 0x0100 }, /* (44100 * 1) / 2 */
495 { 25200, 0, 0x4000, 0x1800, 0x0600 }, /* (44100 * 4) / 7 */
496 { 26460, 0, 0x4000, 0x1000, 0x0400 }, /* (44100 * 3) / 5 */
497 { 29400, 0, 0x4000, 0x0800, 0x0200 }, /* (44100 * 2) / 3 */
498 { 33075, 0, 0x4000, 0x1000, 0x0300 }, /* (44100 * 3) / 4 */
499 { 35280, 0, 0x4000, 0x1800, 0x0400 }, /* (44100 * 4) / 5 */
500 { 44100, 1, 0x4000, 0x0000, 0x0000 }, /* (44100 * 1) / 1 */
501 { 58800, 0, 0x4000, 0x1800, 0x0200 }, /* (44100 * 4) / 3 */
502 { 66150, 0, 0x4000, 0x1000, 0x0100 }, /* (44100 * 3) / 2 */
503 { 88200, 1, 0x4000, 0x0800, 0x0000 }, /* (44100 * 2) / 1 */
504 { 132300, 0, 0x4000, 0x1000, 0x0000 }, /* (44100 * 3) / 1 */
505 { 176400, 1, 0x4000, 0x1800, 0x0000 }, /* (44100 * 4) / 1 */
507 #define HDA_RATE_TAB_LEN (sizeof(hda_rate_tab) / sizeof(hda_rate_tab[0]))
509 /* All codecs you can eat... */
510 #define HDA_CODEC_CONSTRUCT(vendor, id) \
511 (((uint32_t)(vendor##_VENDORID) << 16) | ((id) & 0xffff))
514 #define REALTEK_VENDORID 0x10ec
515 #define HDA_CODEC_ALC260 HDA_CODEC_CONSTRUCT(REALTEK, 0x0260)
516 #define HDA_CODEC_ALC262 HDA_CODEC_CONSTRUCT(REALTEK, 0x0262)
517 #define HDA_CODEC_ALC268 HDA_CODEC_CONSTRUCT(REALTEK, 0x0268)
518 #define HDA_CODEC_ALC660 HDA_CODEC_CONSTRUCT(REALTEK, 0x0660)
519 #define HDA_CODEC_ALC861 HDA_CODEC_CONSTRUCT(REALTEK, 0x0861)
520 #define HDA_CODEC_ALC861VD HDA_CODEC_CONSTRUCT(REALTEK, 0x0862)
521 #define HDA_CODEC_ALC880 HDA_CODEC_CONSTRUCT(REALTEK, 0x0880)
522 #define HDA_CODEC_ALC882 HDA_CODEC_CONSTRUCT(REALTEK, 0x0882)
523 #define HDA_CODEC_ALC883 HDA_CODEC_CONSTRUCT(REALTEK, 0x0883)
524 #define HDA_CODEC_ALC885 HDA_CODEC_CONSTRUCT(REALTEK, 0x0885)
525 #define HDA_CODEC_ALC888 HDA_CODEC_CONSTRUCT(REALTEK, 0x0888)
526 #define HDA_CODEC_ALCXXXX HDA_CODEC_CONSTRUCT(REALTEK, 0xffff)
529 #define ANALOGDEVICES_VENDORID 0x11d4
530 #define HDA_CODEC_AD1981HD HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0x1981)
531 #define HDA_CODEC_AD1983 HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0x1983)
532 #define HDA_CODEC_AD1986A HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0x1986)
533 #define HDA_CODEC_AD1988 HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0x1988)
534 #define HDA_CODEC_AD1988B HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0x198b)
535 #define HDA_CODEC_ADXXXX HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0xffff)
538 #define CMEDIA_VENDORID 0x434d
539 #define HDA_CODEC_CMI9880 HDA_CODEC_CONSTRUCT(CMEDIA, 0x4980)
540 #define HDA_CODEC_CMIXXXX HDA_CODEC_CONSTRUCT(CMEDIA, 0xffff)
543 #define SIGMATEL_VENDORID 0x8384
544 #define HDA_CODEC_STAC9221 HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7680)
545 #define HDA_CODEC_STAC9221D HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7683)
546 #define HDA_CODEC_STAC9220 HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7690)
547 #define HDA_CODEC_STAC922XD HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7681)
548 #define HDA_CODEC_STAC9227 HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7618)
549 #define HDA_CODEC_STAC9271D HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7627)
550 #define HDA_CODEC_STACXXXX HDA_CODEC_CONSTRUCT(SIGMATEL, 0xffff)
555 * Ok, the truth is, I don't have any idea at all whether
556 * it is "Venice" or "Waikiki" or other unnamed CXyadayada. The only
557 * place that tell me it is "Venice" is from its Windows driver INF.
560 * Waikiki - CX20551-22
562 #define CONEXANT_VENDORID 0x14f1
563 #define HDA_CODEC_CXVENICE HDA_CODEC_CONSTRUCT(CONEXANT, 0x5045)
564 #define HDA_CODEC_CXWAIKIKI HDA_CODEC_CONSTRUCT(CONEXANT, 0x5047)
565 #define HDA_CODEC_CXXXXX HDA_CODEC_CONSTRUCT(CONEXANT, 0xffff)
568 #define HDA_CODEC_VT1708_8 HDA_CODEC_CONSTRUCT(VIA, 0x1708)
569 #define HDA_CODEC_VT1708_9 HDA_CODEC_CONSTRUCT(VIA, 0x1709)
570 #define HDA_CODEC_VT1708_A HDA_CODEC_CONSTRUCT(VIA, 0x170a)
571 #define HDA_CODEC_VT1708_B HDA_CODEC_CONSTRUCT(VIA, 0x170b)
572 #define HDA_CODEC_VT1709_0 HDA_CODEC_CONSTRUCT(VIA, 0xe710)
573 #define HDA_CODEC_VT1709_1 HDA_CODEC_CONSTRUCT(VIA, 0xe711)
574 #define HDA_CODEC_VT1709_2 HDA_CODEC_CONSTRUCT(VIA, 0xe712)
575 #define HDA_CODEC_VT1709_3 HDA_CODEC_CONSTRUCT(VIA, 0xe713)
576 #define HDA_CODEC_VT1709_4 HDA_CODEC_CONSTRUCT(VIA, 0xe714)
577 #define HDA_CODEC_VT1709_5 HDA_CODEC_CONSTRUCT(VIA, 0xe715)
578 #define HDA_CODEC_VT1709_6 HDA_CODEC_CONSTRUCT(VIA, 0xe716)
579 #define HDA_CODEC_VT1709_7 HDA_CODEC_CONSTRUCT(VIA, 0xe717)
580 #define HDA_CODEC_VTXXXX HDA_CODEC_CONSTRUCT(VIA, 0xffff)
584 static const struct {
588 { HDA_CODEC_ALC260, "Realtek ALC260" },
589 { HDA_CODEC_ALC262, "Realtek ALC262" },
590 { HDA_CODEC_ALC268, "Realtek ALC268" },
591 { HDA_CODEC_ALC660, "Realtek ALC660" },
592 { HDA_CODEC_ALC861, "Realtek ALC861" },
593 { HDA_CODEC_ALC861VD, "Realtek ALC861-VD" },
594 { HDA_CODEC_ALC880, "Realtek ALC880" },
595 { HDA_CODEC_ALC882, "Realtek ALC882" },
596 { HDA_CODEC_ALC883, "Realtek ALC883" },
597 { HDA_CODEC_ALC885, "Realtek ALC885" },
598 { HDA_CODEC_ALC888, "Realtek ALC888" },
599 { HDA_CODEC_AD1981HD, "Analog Devices AD1981HD" },
600 { HDA_CODEC_AD1983, "Analog Devices AD1983" },
601 { HDA_CODEC_AD1986A, "Analog Devices AD1986A" },
602 { HDA_CODEC_AD1988, "Analog Devices AD1988" },
603 { HDA_CODEC_AD1988B, "Analog Devices AD1988B" },
604 { HDA_CODEC_CMI9880, "CMedia CMI9880" },
605 { HDA_CODEC_STAC9221, "Sigmatel STAC9221" },
606 { HDA_CODEC_STAC9221D, "Sigmatel STAC9221D" },
607 { HDA_CODEC_STAC9220, "Sigmatel STAC9220" },
608 { HDA_CODEC_STAC922XD, "Sigmatel STAC9220D/9223D" },
609 { HDA_CODEC_STAC9227, "Sigmatel STAC9227" },
610 { HDA_CODEC_STAC9271D, "Sigmatel STAC9271D" },
611 { HDA_CODEC_CXVENICE, "Conexant Venice" },
612 { HDA_CODEC_CXWAIKIKI, "Conexant Waikiki" },
613 { HDA_CODEC_VT1708_8, "VIA VT1708_8" },
614 { HDA_CODEC_VT1708_9, "VIA VT1708_9" },
615 { HDA_CODEC_VT1708_A, "VIA VT1708_A" },
616 { HDA_CODEC_VT1708_B, "VIA VT1708_B" },
617 { HDA_CODEC_VT1709_0, "VIA VT1709_0" },
618 { HDA_CODEC_VT1709_1, "VIA VT1709_1" },
619 { HDA_CODEC_VT1709_2, "VIA VT1709_2" },
620 { HDA_CODEC_VT1709_3, "VIA VT1709_3" },
621 { HDA_CODEC_VT1709_4, "VIA VT1709_4" },
622 { HDA_CODEC_VT1709_5, "VIA VT1709_5" },
623 { HDA_CODEC_VT1709_6, "VIA VT1709_6" },
624 { HDA_CODEC_VT1709_7, "VIA VT1709_7" },
626 { HDA_CODEC_ALCXXXX, "Realtek (Unknown)" },
627 { HDA_CODEC_ADXXXX, "Analog Devices (Unknown)" },
628 { HDA_CODEC_CMIXXXX, "CMedia (Unknown)" },
629 { HDA_CODEC_STACXXXX, "Sigmatel (Unknown)" },
630 { HDA_CODEC_CXXXXX, "Conexant (Unknown)" },
631 { HDA_CODEC_VTXXXX, "VIA (Unknown)" },
633 #define HDAC_CODECS_LEN (sizeof(hdac_codecs) / sizeof(hdac_codecs[0]))
641 static const struct {
651 } hdac_hp_switch[] = {
652 /* Specific OEM models */
653 { HP_V3000_SUBVENDOR, HDA_CODEC_CXVENICE, HDAC_HP_SWITCH_CTL,
654 0, 0, -1, 17, { 16, -1 }, 16 },
655 /* { HP_XW4300_SUBVENDOR, HDA_CODEC_ALC260, HDAC_HP_SWITCH_CTL,
656 0, 0, -1, 21, { 16, 17, -1 }, -1 } */
657 /* { HP_3010_SUBVENDOR, HDA_CODEC_ALC260, HDAC_HP_SWITCH_DEBUG,
658 0, 1, 0, 16, { 15, 18, 19, 20, 21, -1 }, -1 }, */
659 { HP_NX7400_SUBVENDOR, HDA_CODEC_AD1981HD, HDAC_HP_SWITCH_CTL,
660 0, 0, -1, 6, { 5, -1 }, 5 },
661 { HP_NX6310_SUBVENDOR, HDA_CODEC_AD1981HD, HDAC_HP_SWITCH_CTL,
662 0, 0, -1, 6, { 5, -1 }, 5 },
663 { HP_NX6325_SUBVENDOR, HDA_CODEC_AD1981HD, HDAC_HP_SWITCH_CTL,
664 0, 0, -1, 6, { 5, -1 }, 5 },
665 /* { HP_DC7700_SUBVENDOR, HDA_CODEC_ALC262, HDAC_HP_SWITCH_CTL,
666 0, 0, -1, 21, { 22, 27, -1 }, -1 }, */
667 { TOSHIBA_U200_SUBVENDOR, HDA_CODEC_AD1981HD, HDAC_HP_SWITCH_CTL,
668 0, 0, -1, 6, { 5, -1 }, -1 },
669 { DELL_D820_SUBVENDOR, HDA_CODEC_STAC9220, HDAC_HP_SWITCH_CTRL,
670 0, 0, -1, 13, { 14, -1 }, -1 },
671 { DELL_I1300_SUBVENDOR, HDA_CODEC_STAC9220, HDAC_HP_SWITCH_CTRL,
672 0, 0, -1, 13, { 14, -1 }, -1 },
673 { DELL_OPLX745_SUBVENDOR, HDA_CODEC_AD1983, HDAC_HP_SWITCH_CTL,
674 0, 0, -1, 6, { 5, 7, -1 }, -1 },
675 { APPLE_INTEL_MAC, HDA_CODEC_STAC9221, HDAC_HP_SWITCH_CTRL,
676 0, 0, -1, 10, { 13, -1 }, -1 },
677 { LENOVO_3KN100_SUBVENDOR, HDA_CODEC_AD1986A, HDAC_HP_SWITCH_CTL,
678 1, 0, -1, 26, { 27, -1 }, -1 },
679 /* { LENOVO_TCA55_SUBVENDOR, HDA_CODEC_AD1986A, HDAC_HP_SWITCH_CTL,
680 0, 0, -1, 26, { 27, 28, 29, 30, -1 }, -1 }, */
681 { LG_LW20_SUBVENDOR, HDA_CODEC_ALC880, HDAC_HP_SWITCH_CTL,
682 0, 0, -1, 27, { 20, -1 }, -1 },
683 { ACER_A5050_SUBVENDOR, HDA_CODEC_ALC883, HDAC_HP_SWITCH_CTL,
684 0, 0, -1, 20, { 21, -1 }, -1 },
685 { ACER_3681WXM_SUBVENDOR, HDA_CODEC_ALC883, HDAC_HP_SWITCH_CTL,
686 0, 0, -1, 20, { 21, -1 }, -1 },
687 { UNIWILL_9080_SUBVENDOR, HDA_CODEC_ALC883, HDAC_HP_SWITCH_CTL,
688 0, 0, -1, 20, { 21, -1 }, -1 },
689 { MSI_MS1034_SUBVENDOR, HDA_CODEC_ALC883, HDAC_HP_SWITCH_CTL,
690 0, 0, -1, 20, { 27, -1 }, -1 },
691 { MSI_MS034A_SUBVENDOR, HDA_CODEC_ALC883, HDAC_HP_SWITCH_CTL,
692 0, 0, -1, 20, { 27, -1 }, -1 },
693 { FS_SI1848_SUBVENDOR, HDA_CODEC_ALC883, HDAC_HP_SWITCH_CTL,
694 0, 0, -1, 20, { 21, -1 }, -1 },
695 { FL_S7020D_SUBVENDOR, HDA_CODEC_ALC260, HDAC_HP_SWITCH_CTL,
696 0, 0, -1, 20, { 16, -1 }, -1 },
698 * All models that at least come from the same vendor with
701 { HP_ALL_SUBVENDOR, HDA_CODEC_CXVENICE, HDAC_HP_SWITCH_CTL,
702 0, 0, -1, 17, { 16, -1 }, 16 },
703 { HP_ALL_SUBVENDOR, HDA_CODEC_AD1981HD, HDAC_HP_SWITCH_CTL,
704 0, 0, -1, 6, { 5, -1 }, 5 },
705 { TOSHIBA_ALL_SUBVENDOR, HDA_CODEC_AD1981HD, HDAC_HP_SWITCH_CTL,
706 0, 0, -1, 6, { 5, -1 }, -1 },
707 { DELL_ALL_SUBVENDOR, HDA_CODEC_STAC9220, HDAC_HP_SWITCH_CTRL,
708 0, 0, -1, 13, { 14, -1 }, -1 },
710 { LENOVO_ALL_SUBVENDOR, HDA_CODEC_AD1986A, HDAC_HP_SWITCH_CTL,
711 1, 0, -1, 26, { 27, -1 }, -1 },
712 { ACER_ALL_SUBVENDOR, HDA_CODEC_ALC883, HDAC_HP_SWITCH_CTL,
713 0, 0, -1, 20, { 21, -1 }, -1 },
716 #define HDAC_HP_SWITCH_LEN \
717 (sizeof(hdac_hp_switch) / sizeof(hdac_hp_switch[0]))
719 static const struct {
724 } hdac_eapd_switch[] = {
725 { HP_V3000_SUBVENDOR, HDA_CODEC_CXVENICE, 16, 1 },
726 { HP_NX7400_SUBVENDOR, HDA_CODEC_AD1981HD, 5, 1 },
727 { HP_NX6310_SUBVENDOR, HDA_CODEC_AD1981HD, 5, 1 },
729 #define HDAC_EAPD_SWITCH_LEN \
730 (sizeof(hdac_eapd_switch) / sizeof(hdac_eapd_switch[0]))
732 /****************************************************************************
733 * Function prototypes
734 ****************************************************************************/
735 static void hdac_intr_handler(void *);
736 static int hdac_reset(struct hdac_softc *);
737 static int hdac_get_capabilities(struct hdac_softc *);
738 static void hdac_dma_cb(void *, bus_dma_segment_t *, int, int);
739 static int hdac_dma_alloc(struct hdac_softc *,
740 struct hdac_dma *, bus_size_t);
741 static void hdac_dma_free(struct hdac_softc *, struct hdac_dma *);
742 static int hdac_mem_alloc(struct hdac_softc *);
743 static void hdac_mem_free(struct hdac_softc *);
744 static int hdac_irq_alloc(struct hdac_softc *);
745 static void hdac_irq_free(struct hdac_softc *);
746 static void hdac_corb_init(struct hdac_softc *);
747 static void hdac_rirb_init(struct hdac_softc *);
748 static void hdac_corb_start(struct hdac_softc *);
749 static void hdac_rirb_start(struct hdac_softc *);
750 static void hdac_scan_codecs(struct hdac_softc *, int);
751 static int hdac_probe_codec(struct hdac_codec *);
752 static struct hdac_devinfo *hdac_probe_function(struct hdac_codec *, nid_t);
753 static void hdac_add_child(struct hdac_softc *, struct hdac_devinfo *);
755 static void hdac_attach2(void *);
757 static uint32_t hdac_command_sendone_internal(struct hdac_softc *,
759 static void hdac_command_send_internal(struct hdac_softc *,
760 struct hdac_command_list *, int);
762 static int hdac_probe(device_t);
763 static int hdac_attach(device_t);
764 static int hdac_detach(device_t);
765 static void hdac_widget_connection_select(struct hdac_widget *, uint8_t);
766 static void hdac_audio_ctl_amp_set(struct hdac_audio_ctl *,
768 static struct hdac_audio_ctl *hdac_audio_ctl_amp_get(struct hdac_devinfo *,
770 static void hdac_audio_ctl_amp_set_internal(struct hdac_softc *,
771 nid_t, nid_t, int, int, int, int, int, int);
772 static int hdac_audio_ctl_ossmixer_getnextdev(struct hdac_devinfo *);
773 static struct hdac_widget *hdac_widget_get(struct hdac_devinfo *, nid_t);
775 static int hdac_rirb_flush(struct hdac_softc *sc);
776 static int hdac_unsolq_flush(struct hdac_softc *sc);
778 #define hdac_command(a1, a2, a3) \
779 hdac_command_sendone_internal(a1, a2, a3)
781 #define hdac_codec_id(d) \
782 ((uint32_t)((d == NULL) ? 0x00000000 : \
783 ((((uint32_t)(d)->vendor_id & 0x0000ffff) << 16) | \
784 ((uint32_t)(d)->device_id & 0x0000ffff))))
787 hdac_codec_name(struct hdac_devinfo *devinfo)
792 id = hdac_codec_id(devinfo);
794 for (i = 0; i < HDAC_CODECS_LEN; i++) {
795 if (HDA_DEV_MATCH(hdac_codecs[i].id, id))
796 return (hdac_codecs[i].name);
799 return ((id == 0x00000000) ? "NULL Codec" : "Unknown Codec");
803 hdac_audio_ctl_ossmixer_mask2name(uint32_t devmask)
805 static char *ossname[] = SOUND_DEVICE_NAMES;
806 static char *unknown = "???";
809 for (i = SOUND_MIXER_NRDEVICES - 1; i >= 0; i--) {
810 if (devmask & (1 << i))
817 hdac_audio_ctl_ossmixer_mask2allname(uint32_t mask, char *buf, size_t len)
819 static char *ossname[] = SOUND_DEVICE_NAMES;
823 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
824 if (mask & (1 << i)) {
826 strlcat(buf, ", ", len);
827 strlcat(buf, ossname[i], len);
833 static struct hdac_audio_ctl *
834 hdac_audio_ctl_each(struct hdac_devinfo *devinfo, int *index)
836 if (devinfo == NULL ||
837 devinfo->node_type != HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO ||
838 index == NULL || devinfo->function.audio.ctl == NULL ||
839 devinfo->function.audio.ctlcnt < 1 ||
840 *index < 0 || *index >= devinfo->function.audio.ctlcnt)
842 return (&devinfo->function.audio.ctl[(*index)++]);
845 static struct hdac_audio_ctl *
846 hdac_audio_ctl_amp_get(struct hdac_devinfo *devinfo, nid_t nid,
849 struct hdac_audio_ctl *ctl, *retctl = NULL;
850 int i, at, atindex, found = 0;
852 if (devinfo == NULL || devinfo->function.audio.ctl == NULL)
865 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) {
866 if (ctl->enable == 0 || ctl->widget == NULL)
868 if (!(ctl->widget->nid == nid && (atindex == -1 ||
869 ctl->index == atindex)))
877 return ((at == -1) ? retctl : NULL);
881 hdac_hp_switch_handler(struct hdac_devinfo *devinfo)
883 struct hdac_softc *sc;
884 struct hdac_widget *w;
885 struct hdac_audio_ctl *ctl;
886 uint32_t val, id, res;
887 int i = 0, j, timeout, forcemute;
890 if (devinfo == NULL || devinfo->codec == NULL ||
891 devinfo->codec->sc == NULL)
894 sc = devinfo->codec->sc;
895 cad = devinfo->codec->cad;
896 id = hdac_codec_id(devinfo);
897 for (i = 0; i < HDAC_HP_SWITCH_LEN; i++) {
898 if (HDA_DEV_MATCH(hdac_hp_switch[i].model,
899 sc->pci_subvendor) &&
900 hdac_hp_switch[i].id == id)
904 if (i >= HDAC_HP_SWITCH_LEN)
908 if (hdac_hp_switch[i].eapdnid != -1) {
909 w = hdac_widget_get(devinfo, hdac_hp_switch[i].eapdnid);
910 if (w != NULL && w->param.eapdbtl != HDAC_INVALID)
911 forcemute = (w->param.eapdbtl &
912 HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD) ? 0 : 1;
915 if (hdac_hp_switch[i].execsense != -1)
917 HDA_CMD_SET_PIN_SENSE(cad, hdac_hp_switch[i].hpnid,
918 hdac_hp_switch[i].execsense), cad);
922 res = hdac_command(sc,
923 HDA_CMD_GET_PIN_SENSE(cad, hdac_hp_switch[i].hpnid),
925 if (hdac_hp_switch[i].execsense == -1 || res != 0x7fffffff)
928 } while (--timeout != 0);
931 device_printf(sc->dev,
932 "HDA_DEBUG: Pin sense: nid=%d timeout=%d res=0x%08x\n",
933 hdac_hp_switch[i].hpnid, timeout, res);
936 res = HDA_CMD_GET_PIN_SENSE_PRESENCE_DETECT(res);
937 res ^= hdac_hp_switch[i].inverted;
939 switch (hdac_hp_switch[i].type) {
940 case HDAC_HP_SWITCH_CTL:
941 ctl = hdac_audio_ctl_amp_get(devinfo,
942 hdac_hp_switch[i].hpnid, 0, 1);
944 val = (res != 0 && forcemute == 0) ?
945 HDA_AMP_MUTE_NONE : HDA_AMP_MUTE_ALL;
946 if (val != ctl->muted) {
948 hdac_audio_ctl_amp_set(ctl,
949 HDA_AMP_MUTE_DEFAULT, ctl->left,
953 for (j = 0; hdac_hp_switch[i].spkrnid[j] != -1; j++) {
954 ctl = hdac_audio_ctl_amp_get(devinfo,
955 hdac_hp_switch[i].spkrnid[j], 0, 1);
958 val = (res != 0 || forcemute == 1) ?
959 HDA_AMP_MUTE_ALL : HDA_AMP_MUTE_NONE;
960 if (val == ctl->muted)
963 hdac_audio_ctl_amp_set(ctl, HDA_AMP_MUTE_DEFAULT,
964 ctl->left, ctl->right);
967 case HDAC_HP_SWITCH_CTRL:
970 w = hdac_widget_get(devinfo, hdac_hp_switch[i].hpnid);
971 if (w != NULL && w->type ==
972 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) {
974 val = w->wclass.pin.ctrl |
975 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
977 val = w->wclass.pin.ctrl &
978 ~HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
979 if (val != w->wclass.pin.ctrl) {
980 w->wclass.pin.ctrl = val;
982 HDA_CMD_SET_PIN_WIDGET_CTRL(cad,
983 w->nid, w->wclass.pin.ctrl), cad);
986 for (j = 0; hdac_hp_switch[i].spkrnid[j] != -1; j++) {
987 w = hdac_widget_get(devinfo,
988 hdac_hp_switch[i].spkrnid[j]);
989 if (w == NULL || w->type !=
990 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
992 val = w->wclass.pin.ctrl &
993 ~HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
994 if (val == w->wclass.pin.ctrl)
996 w->wclass.pin.ctrl = val;
997 hdac_command(sc, HDA_CMD_SET_PIN_WIDGET_CTRL(
998 cad, w->nid, w->wclass.pin.ctrl), cad);
1002 w = hdac_widget_get(devinfo, hdac_hp_switch[i].hpnid);
1003 if (w != NULL && w->type ==
1004 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) {
1005 val = w->wclass.pin.ctrl &
1006 ~HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
1007 if (val != w->wclass.pin.ctrl) {
1008 w->wclass.pin.ctrl = val;
1010 HDA_CMD_SET_PIN_WIDGET_CTRL(cad,
1011 w->nid, w->wclass.pin.ctrl), cad);
1014 for (j = 0; hdac_hp_switch[i].spkrnid[j] != -1; j++) {
1015 w = hdac_widget_get(devinfo,
1016 hdac_hp_switch[i].spkrnid[j]);
1017 if (w == NULL || w->type !=
1018 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
1021 val = w->wclass.pin.ctrl |
1022 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
1024 val = w->wclass.pin.ctrl &
1025 ~HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
1026 if (val == w->wclass.pin.ctrl)
1028 w->wclass.pin.ctrl = val;
1029 hdac_command(sc, HDA_CMD_SET_PIN_WIDGET_CTRL(
1030 cad, w->nid, w->wclass.pin.ctrl), cad);
1034 case HDAC_HP_SWITCH_DEBUG:
1035 if (hdac_hp_switch[i].execsense != -1)
1037 HDA_CMD_SET_PIN_SENSE(cad, hdac_hp_switch[i].hpnid,
1038 hdac_hp_switch[i].execsense), cad);
1039 res = hdac_command(sc,
1040 HDA_CMD_GET_PIN_SENSE(cad, hdac_hp_switch[i].hpnid), cad);
1041 device_printf(sc->dev,
1042 "[ 0] HDA_DEBUG: Pin sense: nid=%d res=0x%08x\n",
1043 hdac_hp_switch[i].hpnid, res);
1044 for (j = 0; hdac_hp_switch[i].spkrnid[j] != -1; j++) {
1045 w = hdac_widget_get(devinfo,
1046 hdac_hp_switch[i].spkrnid[j]);
1047 if (w == NULL || w->type !=
1048 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
1050 if (hdac_hp_switch[i].execsense != -1)
1052 HDA_CMD_SET_PIN_SENSE(cad, w->nid,
1053 hdac_hp_switch[i].execsense), cad);
1054 res = hdac_command(sc,
1055 HDA_CMD_GET_PIN_SENSE(cad, w->nid), cad);
1056 device_printf(sc->dev,
1057 "[%2d] HDA_DEBUG: Pin sense: nid=%d res=0x%08x\n",
1058 j + 1, w->nid, res);
1067 hdac_unsolicited_handler(struct hdac_codec *codec, uint32_t tag)
1069 struct hdac_softc *sc;
1070 struct hdac_devinfo *devinfo = NULL;
1071 device_t *devlist = NULL;
1074 if (codec == NULL || codec->sc == NULL)
1080 device_printf(sc->dev, "HDA_DEBUG: Unsol Tag: 0x%08x\n", tag);
1083 device_get_children(sc->dev, &devlist, &devcount);
1084 for (i = 0; devlist != NULL && i < devcount; i++) {
1085 devinfo = (struct hdac_devinfo *)device_get_ivars(devlist[i]);
1086 if (devinfo != NULL && devinfo->node_type ==
1087 HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO &&
1088 devinfo->codec != NULL &&
1089 devinfo->codec->cad == codec->cad) {
1094 if (devlist != NULL)
1095 kfree(devlist, M_TEMP);
1097 if (devinfo == NULL)
1101 case HDAC_UNSOLTAG_EVENT_HP:
1102 hdac_hp_switch_handler(devinfo);
1104 case HDAC_UNSOLTAG_EVENT_TEST:
1105 device_printf(sc->dev, "Unsol Test!\n");
1113 hdac_stream_intr(struct hdac_softc *sc, struct hdac_chan *ch)
1115 /* XXX to be removed */
1116 #ifdef HDAC_INTR_EXTRA
1120 if (!(ch->flags & HDAC_CHN_RUNNING))
1123 /* XXX to be removed */
1124 #ifdef HDAC_INTR_EXTRA
1125 res = HDAC_READ_1(&sc->mem, ch->off + HDAC_SDSTS);
1128 /* XXX to be removed */
1129 #ifdef HDAC_INTR_EXTRA
1131 if (res & (HDAC_SDSTS_DESE | HDAC_SDSTS_FIFOE))
1132 device_printf(sc->dev,
1133 "PCMDIR_%s intr triggered beyond stream boundary:"
1135 (ch->dir == PCMDIR_PLAY) ? "PLAY" : "REC", res);
1139 HDAC_WRITE_1(&sc->mem, ch->off + HDAC_SDSTS,
1140 HDAC_SDSTS_DESE | HDAC_SDSTS_FIFOE | HDAC_SDSTS_BCIS );
1142 /* XXX to be removed */
1143 #ifdef HDAC_INTR_EXTRA
1144 if (res & HDAC_SDSTS_BCIS) {
1147 /* XXX to be removed */
1148 #ifdef HDAC_INTR_EXTRA
1155 /****************************************************************************
1156 * void hdac_intr_handler(void *)
1158 * Interrupt handler. Processes interrupts received from the hdac.
1159 ****************************************************************************/
1161 hdac_intr_handler(void *context)
1163 struct hdac_softc *sc;
1166 struct hdac_rirb *rirb_base;
1169 sc = (struct hdac_softc *)context;
1172 if (sc->polling != 0) {
1177 /* Do we have anything to do? */
1178 intsts = HDAC_READ_4(&sc->mem, HDAC_INTSTS);
1179 if (!HDA_FLAG_MATCH(intsts, HDAC_INTSTS_GIS)) {
1186 /* Was this a controller interrupt? */
1187 if (HDA_FLAG_MATCH(intsts, HDAC_INTSTS_CIS)) {
1188 rirb_base = (struct hdac_rirb *)sc->rirb_dma.dma_vaddr;
1189 rirbsts = HDAC_READ_1(&sc->mem, HDAC_RIRBSTS);
1190 /* Get as many responses that we can */
1191 while (HDA_FLAG_MATCH(rirbsts, HDAC_RIRBSTS_RINTFL)) {
1192 HDAC_WRITE_1(&sc->mem,
1193 HDAC_RIRBSTS, HDAC_RIRBSTS_RINTFL);
1194 if (hdac_rirb_flush(sc) != 0)
1195 trigger |= HDAC_TRIGGER_UNSOL;
1196 rirbsts = HDAC_READ_1(&sc->mem, HDAC_RIRBSTS);
1198 /* XXX to be removed */
1199 /* Clear interrupt and exit */
1200 #ifdef HDAC_INTR_EXTRA
1201 HDAC_WRITE_4(&sc->mem, HDAC_INTSTS, HDAC_INTSTS_CIS);
1205 if (intsts & HDAC_INTSTS_SIS_MASK) {
1206 if ((intsts & (1 << sc->num_iss)) &&
1207 hdac_stream_intr(sc, &sc->play) != 0)
1208 trigger |= HDAC_TRIGGER_PLAY;
1209 if ((intsts & (1 << 0)) &&
1210 hdac_stream_intr(sc, &sc->rec) != 0)
1211 trigger |= HDAC_TRIGGER_REC;
1212 /* XXX to be removed */
1213 #ifdef HDAC_INTR_EXTRA
1214 HDAC_WRITE_4(&sc->mem, HDAC_INTSTS, intsts &
1215 HDAC_INTSTS_SIS_MASK);
1221 if (trigger & HDAC_TRIGGER_PLAY)
1222 chn_intr(sc->play.c);
1223 if (trigger & HDAC_TRIGGER_REC)
1224 chn_intr(sc->rec.c);
1225 if (trigger & HDAC_TRIGGER_UNSOL)
1226 taskqueue_enqueue(taskqueue_swi, &sc->unsolq_task);
1229 /****************************************************************************
1230 * int hdac_reset(hdac_softc *)
1232 * Reset the hdac to a quiescent and known state.
1233 ****************************************************************************/
1235 hdac_reset(struct hdac_softc *sc)
1241 * Stop all Streams DMA engine
1243 for (i = 0; i < sc->num_iss; i++)
1244 HDAC_WRITE_4(&sc->mem, HDAC_ISDCTL(sc, i), 0x0);
1245 for (i = 0; i < sc->num_oss; i++)
1246 HDAC_WRITE_4(&sc->mem, HDAC_OSDCTL(sc, i), 0x0);
1247 for (i = 0; i < sc->num_bss; i++)
1248 HDAC_WRITE_4(&sc->mem, HDAC_BSDCTL(sc, i), 0x0);
1251 * Stop Control DMA engines.
1253 HDAC_WRITE_1(&sc->mem, HDAC_CORBCTL, 0x0);
1254 HDAC_WRITE_1(&sc->mem, HDAC_RIRBCTL, 0x0);
1257 * Reset DMA position buffer.
1259 HDAC_WRITE_4(&sc->mem, HDAC_DPIBLBASE, 0x0);
1260 HDAC_WRITE_4(&sc->mem, HDAC_DPIBUBASE, 0x0);
1263 * Reset the controller. The reset must remain asserted for
1264 * a minimum of 100us.
1266 gctl = HDAC_READ_4(&sc->mem, HDAC_GCTL);
1267 HDAC_WRITE_4(&sc->mem, HDAC_GCTL, gctl & ~HDAC_GCTL_CRST);
1270 gctl = HDAC_READ_4(&sc->mem, HDAC_GCTL);
1271 if (!(gctl & HDAC_GCTL_CRST))
1275 if (gctl & HDAC_GCTL_CRST) {
1276 device_printf(sc->dev, "Unable to put hdac in reset\n");
1280 gctl = HDAC_READ_4(&sc->mem, HDAC_GCTL);
1281 HDAC_WRITE_4(&sc->mem, HDAC_GCTL, gctl | HDAC_GCTL_CRST);
1284 gctl = HDAC_READ_4(&sc->mem, HDAC_GCTL);
1285 if (gctl & HDAC_GCTL_CRST)
1289 if (!(gctl & HDAC_GCTL_CRST)) {
1290 device_printf(sc->dev, "Device stuck in reset\n");
1295 * Wait for codecs to finish their own reset sequence. The delay here
1296 * should be of 250us but for some reasons, on it's not enough on my
1297 * computer. Let's use twice as much as necessary to make sure that
1298 * it's reset properly.
1306 /****************************************************************************
1307 * int hdac_get_capabilities(struct hdac_softc *);
1309 * Retreive the general capabilities of the hdac;
1310 * Number of Input Streams
1311 * Number of Output Streams
1312 * Number of bidirectional Streams
1314 * CORB and RIRB sizes
1315 ****************************************************************************/
1317 hdac_get_capabilities(struct hdac_softc *sc)
1320 uint8_t corbsize, rirbsize;
1322 gcap = HDAC_READ_2(&sc->mem, HDAC_GCAP);
1323 sc->num_iss = HDAC_GCAP_ISS(gcap);
1324 sc->num_oss = HDAC_GCAP_OSS(gcap);
1325 sc->num_bss = HDAC_GCAP_BSS(gcap);
1327 sc->support_64bit = HDA_FLAG_MATCH(gcap, HDAC_GCAP_64OK);
1329 corbsize = HDAC_READ_1(&sc->mem, HDAC_CORBSIZE);
1330 if ((corbsize & HDAC_CORBSIZE_CORBSZCAP_256) ==
1331 HDAC_CORBSIZE_CORBSZCAP_256)
1332 sc->corb_size = 256;
1333 else if ((corbsize & HDAC_CORBSIZE_CORBSZCAP_16) ==
1334 HDAC_CORBSIZE_CORBSZCAP_16)
1336 else if ((corbsize & HDAC_CORBSIZE_CORBSZCAP_2) ==
1337 HDAC_CORBSIZE_CORBSZCAP_2)
1340 device_printf(sc->dev, "%s: Invalid corb size (%x)\n",
1341 __func__, corbsize);
1345 rirbsize = HDAC_READ_1(&sc->mem, HDAC_RIRBSIZE);
1346 if ((rirbsize & HDAC_RIRBSIZE_RIRBSZCAP_256) ==
1347 HDAC_RIRBSIZE_RIRBSZCAP_256)
1348 sc->rirb_size = 256;
1349 else if ((rirbsize & HDAC_RIRBSIZE_RIRBSZCAP_16) ==
1350 HDAC_RIRBSIZE_RIRBSZCAP_16)
1352 else if ((rirbsize & HDAC_RIRBSIZE_RIRBSZCAP_2) ==
1353 HDAC_RIRBSIZE_RIRBSZCAP_2)
1356 device_printf(sc->dev, "%s: Invalid rirb size (%x)\n",
1357 __func__, rirbsize);
1365 /****************************************************************************
1368 * This function is called by bus_dmamap_load when the mapping has been
1369 * established. We just record the physical address of the mapping into
1370 * the struct hdac_dma passed in.
1371 ****************************************************************************/
1373 hdac_dma_cb(void *callback_arg, bus_dma_segment_t *segs, int nseg, int error)
1375 struct hdac_dma *dma;
1378 dma = (struct hdac_dma *)callback_arg;
1379 dma->dma_paddr = segs[0].ds_addr;
1384 /****************************************************************************
1385 * int hdac_dma_alloc
1387 * This function allocate and setup a dma region (struct hdac_dma).
1388 * It must be freed by a corresponding hdac_dma_free.
1389 ****************************************************************************/
1391 hdac_dma_alloc(struct hdac_softc *sc, struct hdac_dma *dma, bus_size_t size)
1397 roundsz = roundup2(size, HDAC_DMA_ALIGNMENT);
1398 lowaddr = (sc->support_64bit) ? BUS_SPACE_MAXADDR :
1399 BUS_SPACE_MAXADDR_32BIT;
1400 bzero(dma, sizeof(*dma));
1405 result = bus_dma_tag_create(NULL, /* parent */
1406 HDAC_DMA_ALIGNMENT, /* alignment */
1408 lowaddr, /* lowaddr */
1409 BUS_SPACE_MAXADDR, /* highaddr */
1410 NULL, /* filtfunc */
1411 NULL, /* fistfuncarg */
1412 roundsz, /* maxsize */
1414 roundsz, /* maxsegsz */
1416 &dma->dma_tag); /* dmat */
1418 device_printf(sc->dev, "%s: bus_dma_tag_create failed (%x)\n",
1420 goto hdac_dma_alloc_fail;
1424 * Allocate DMA memory
1426 #if 0 /* TODO: No uncacheable DMA support in DragonFly. */
1427 result = bus_dmamem_alloc(dma->dma_tag, (void **)&dma->dma_vaddr,
1428 BUS_DMA_NOWAIT | BUS_DMA_ZERO |
1429 ((sc->flags & HDAC_F_DMA_NOCACHE) ? BUS_DMA_NOCACHE : 0),
1432 result = bus_dmamem_alloc(dma->dma_tag, (void **)&dma->dma_vaddr,
1433 BUS_DMA_NOWAIT | BUS_DMA_ZERO, &dma->dma_map);
1436 device_printf(sc->dev, "%s: bus_dmamem_alloc failed (%x)\n",
1438 goto hdac_dma_alloc_fail;
1441 dma->dma_size = roundsz;
1446 result = bus_dmamap_load(dma->dma_tag, dma->dma_map,
1447 (void *)dma->dma_vaddr, roundsz, hdac_dma_cb, (void *)dma, 0);
1448 if (result != 0 || dma->dma_paddr == 0) {
1451 device_printf(sc->dev, "%s: bus_dmamem_load failed (%x)\n",
1453 goto hdac_dma_alloc_fail;
1457 device_printf(sc->dev, "%s: size=%ju -> roundsz=%ju\n",
1458 __func__, (uintmax_t)size, (uintmax_t)roundsz);
1463 hdac_dma_alloc_fail:
1464 hdac_dma_free(sc, dma);
1470 /****************************************************************************
1471 * void hdac_dma_free(struct hdac_softc *, struct hdac_dma *)
1473 * Free a struct dhac_dma that has been previously allocated via the
1474 * hdac_dma_alloc function.
1475 ****************************************************************************/
1477 hdac_dma_free(struct hdac_softc *sc, struct hdac_dma *dma)
1479 if (dma->dma_map != NULL) {
1482 bus_dmamap_sync(dma->dma_tag, dma->dma_map,
1483 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
1485 bus_dmamap_unload(dma->dma_tag, dma->dma_map);
1487 if (dma->dma_vaddr != NULL) {
1488 bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
1489 dma->dma_vaddr = NULL;
1491 dma->dma_map = NULL;
1492 if (dma->dma_tag != NULL) {
1493 bus_dma_tag_destroy(dma->dma_tag);
1494 dma->dma_tag = NULL;
1499 /****************************************************************************
1500 * int hdac_mem_alloc(struct hdac_softc *)
1502 * Allocate all the bus resources necessary to speak with the physical
1504 ****************************************************************************/
1506 hdac_mem_alloc(struct hdac_softc *sc)
1508 struct hdac_mem *mem;
1511 mem->mem_rid = PCIR_BAR(0);
1512 mem->mem_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY,
1513 &mem->mem_rid, RF_ACTIVE);
1514 if (mem->mem_res == NULL) {
1515 device_printf(sc->dev,
1516 "%s: Unable to allocate memory resource\n", __func__);
1519 mem->mem_tag = rman_get_bustag(mem->mem_res);
1520 mem->mem_handle = rman_get_bushandle(mem->mem_res);
1525 /****************************************************************************
1526 * void hdac_mem_free(struct hdac_softc *)
1528 * Free up resources previously allocated by hdac_mem_alloc.
1529 ****************************************************************************/
1531 hdac_mem_free(struct hdac_softc *sc)
1533 struct hdac_mem *mem;
1536 if (mem->mem_res != NULL)
1537 bus_release_resource(sc->dev, SYS_RES_MEMORY, mem->mem_rid,
1539 mem->mem_res = NULL;
1542 /****************************************************************************
1543 * int hdac_irq_alloc(struct hdac_softc *)
1545 * Allocate and setup the resources necessary for interrupt handling.
1546 ****************************************************************************/
1548 hdac_irq_alloc(struct hdac_softc *sc)
1550 struct hdac_irq *irq;
1556 #if 0 /* TODO: No MSI support in DragonFly yet. */
1557 if ((sc->flags & HDAC_F_MSI) &&
1558 (result = pci_msi_count(sc->dev)) == 1 &&
1559 pci_alloc_msi(sc->dev, &result) == 0)
1563 sc->flags &= ~HDAC_F_MSI;
1565 irq->irq_res = bus_alloc_resource_any(sc->dev, SYS_RES_IRQ,
1566 &irq->irq_rid, RF_SHAREABLE | RF_ACTIVE);
1567 if (irq->irq_res == NULL) {
1568 device_printf(sc->dev, "%s: Unable to allocate irq\n",
1570 goto hdac_irq_alloc_fail;
1572 result = snd_setup_intr(sc->dev, irq->irq_res, INTR_MPSAFE,
1573 hdac_intr_handler, sc, &irq->irq_handle);
1575 device_printf(sc->dev,
1576 "%s: Unable to setup interrupt handler (%x)\n",
1578 goto hdac_irq_alloc_fail;
1583 hdac_irq_alloc_fail:
1589 /****************************************************************************
1590 * void hdac_irq_free(struct hdac_softc *)
1592 * Free up resources previously allocated by hdac_irq_alloc.
1593 ****************************************************************************/
1595 hdac_irq_free(struct hdac_softc *sc)
1597 struct hdac_irq *irq;
1600 if (irq->irq_res != NULL && irq->irq_handle != NULL)
1601 bus_teardown_intr(sc->dev, irq->irq_res, irq->irq_handle);
1602 if (irq->irq_res != NULL)
1603 bus_release_resource(sc->dev, SYS_RES_IRQ, irq->irq_rid,
1605 #if 0 /* TODO: No MSI support in DragonFly yet. */
1606 if ((sc->flags & HDAC_F_MSI) && irq->irq_rid == 0x1)
1607 pci_release_msi(sc->dev);
1609 irq->irq_handle = NULL;
1610 irq->irq_res = NULL;
1614 /****************************************************************************
1615 * void hdac_corb_init(struct hdac_softc *)
1617 * Initialize the corb registers for operations but do not start it up yet.
1618 * The CORB engine must not be running when this function is called.
1619 ****************************************************************************/
1621 hdac_corb_init(struct hdac_softc *sc)
1626 /* Setup the CORB size. */
1627 switch (sc->corb_size) {
1629 corbsize = HDAC_CORBSIZE_CORBSIZE(HDAC_CORBSIZE_CORBSIZE_256);
1632 corbsize = HDAC_CORBSIZE_CORBSIZE(HDAC_CORBSIZE_CORBSIZE_16);
1635 corbsize = HDAC_CORBSIZE_CORBSIZE(HDAC_CORBSIZE_CORBSIZE_2);
1638 panic("%s: Invalid CORB size (%x)\n", __func__, sc->corb_size);
1640 HDAC_WRITE_1(&sc->mem, HDAC_CORBSIZE, corbsize);
1642 /* Setup the CORB Address in the hdac */
1643 corbpaddr = (uint64_t)sc->corb_dma.dma_paddr;
1644 HDAC_WRITE_4(&sc->mem, HDAC_CORBLBASE, (uint32_t)corbpaddr);
1645 HDAC_WRITE_4(&sc->mem, HDAC_CORBUBASE, (uint32_t)(corbpaddr >> 32));
1647 /* Set the WP and RP */
1649 HDAC_WRITE_2(&sc->mem, HDAC_CORBWP, sc->corb_wp);
1650 HDAC_WRITE_2(&sc->mem, HDAC_CORBRP, HDAC_CORBRP_CORBRPRST);
1652 * The HDA specification indicates that the CORBRPRST bit will always
1653 * read as zero. Unfortunately, it seems that at least the 82801G
1654 * doesn't reset the bit to zero, which stalls the corb engine.
1655 * manually reset the bit to zero before continuing.
1657 HDAC_WRITE_2(&sc->mem, HDAC_CORBRP, 0x0);
1659 /* Enable CORB error reporting */
1661 HDAC_WRITE_1(&sc->mem, HDAC_CORBCTL, HDAC_CORBCTL_CMEIE);
1665 /****************************************************************************
1666 * void hdac_rirb_init(struct hdac_softc *)
1668 * Initialize the rirb registers for operations but do not start it up yet.
1669 * The RIRB engine must not be running when this function is called.
1670 ****************************************************************************/
1672 hdac_rirb_init(struct hdac_softc *sc)
1677 /* Setup the RIRB size. */
1678 switch (sc->rirb_size) {
1680 rirbsize = HDAC_RIRBSIZE_RIRBSIZE(HDAC_RIRBSIZE_RIRBSIZE_256);
1683 rirbsize = HDAC_RIRBSIZE_RIRBSIZE(HDAC_RIRBSIZE_RIRBSIZE_16);
1686 rirbsize = HDAC_RIRBSIZE_RIRBSIZE(HDAC_RIRBSIZE_RIRBSIZE_2);
1689 panic("%s: Invalid RIRB size (%x)\n", __func__, sc->rirb_size);
1691 HDAC_WRITE_1(&sc->mem, HDAC_RIRBSIZE, rirbsize);
1693 /* Setup the RIRB Address in the hdac */
1694 rirbpaddr = (uint64_t)sc->rirb_dma.dma_paddr;
1695 HDAC_WRITE_4(&sc->mem, HDAC_RIRBLBASE, (uint32_t)rirbpaddr);
1696 HDAC_WRITE_4(&sc->mem, HDAC_RIRBUBASE, (uint32_t)(rirbpaddr >> 32));
1698 /* Setup the WP and RP */
1700 HDAC_WRITE_2(&sc->mem, HDAC_RIRBWP, HDAC_RIRBWP_RIRBWPRST);
1702 if (sc->polling == 0) {
1703 /* Setup the interrupt threshold */
1704 HDAC_WRITE_2(&sc->mem, HDAC_RINTCNT, sc->rirb_size / 2);
1706 /* Enable Overrun and response received reporting */
1708 HDAC_WRITE_1(&sc->mem, HDAC_RIRBCTL,
1709 HDAC_RIRBCTL_RIRBOIC | HDAC_RIRBCTL_RINTCTL);
1711 HDAC_WRITE_1(&sc->mem, HDAC_RIRBCTL, HDAC_RIRBCTL_RINTCTL);
1717 * Make sure that the Host CPU cache doesn't contain any dirty
1718 * cache lines that falls in the rirb. If I understood correctly, it
1719 * should be sufficient to do this only once as the rirb is purely
1720 * read-only from now on.
1722 bus_dmamap_sync(sc->rirb_dma.dma_tag, sc->rirb_dma.dma_map,
1723 BUS_DMASYNC_PREREAD);
1727 /****************************************************************************
1728 * void hdac_corb_start(hdac_softc *)
1730 * Startup the corb DMA engine
1731 ****************************************************************************/
1733 hdac_corb_start(struct hdac_softc *sc)
1737 corbctl = HDAC_READ_1(&sc->mem, HDAC_CORBCTL);
1738 corbctl |= HDAC_CORBCTL_CORBRUN;
1739 HDAC_WRITE_1(&sc->mem, HDAC_CORBCTL, corbctl);
1742 /****************************************************************************
1743 * void hdac_rirb_start(hdac_softc *)
1745 * Startup the rirb DMA engine
1746 ****************************************************************************/
1748 hdac_rirb_start(struct hdac_softc *sc)
1752 rirbctl = HDAC_READ_1(&sc->mem, HDAC_RIRBCTL);
1753 rirbctl |= HDAC_RIRBCTL_RIRBDMAEN;
1754 HDAC_WRITE_1(&sc->mem, HDAC_RIRBCTL, rirbctl);
1758 /****************************************************************************
1759 * void hdac_scan_codecs(struct hdac_softc *, int)
1761 * Scan the bus for available codecs, starting with num.
1762 ****************************************************************************/
1764 hdac_scan_codecs(struct hdac_softc *sc, int num)
1766 struct hdac_codec *codec;
1772 if (num >= HDAC_CODEC_MAX)
1773 num = HDAC_CODEC_MAX - 1;
1775 statests = HDAC_READ_2(&sc->mem, HDAC_STATESTS);
1776 for (i = num; i < HDAC_CODEC_MAX; i++) {
1777 if (HDAC_STATESTS_SDIWAKE(statests, i)) {
1778 /* We have found a codec. */
1779 codec = (struct hdac_codec *)kmalloc(sizeof(*codec),
1780 M_HDAC, M_ZERO | M_NOWAIT);
1781 if (codec == NULL) {
1782 device_printf(sc->dev,
1783 "Unable to allocate memory for codec\n");
1786 codec->commands = NULL;
1787 codec->responses_received = 0;
1788 codec->verbs_sent = 0;
1791 sc->codecs[i] = codec;
1792 if (hdac_probe_codec(codec) != 0)
1796 /* All codecs have been probed, now try to attach drivers to them */
1797 /* bus_generic_attach(sc->dev); */
1800 /****************************************************************************
1801 * void hdac_probe_codec(struct hdac_softc *, int)
1803 * Probe a the given codec_id for available function groups.
1804 ****************************************************************************/
1806 hdac_probe_codec(struct hdac_codec *codec)
1808 struct hdac_softc *sc = codec->sc;
1809 struct hdac_devinfo *devinfo;
1810 uint32_t vendorid, revisionid, subnode;
1814 nid_t cad = codec->cad;
1817 device_printf(sc->dev, "HDA_DEBUG: Probing codec: %d\n", cad);
1819 vendorid = hdac_command(sc,
1820 HDA_CMD_GET_PARAMETER(cad, 0x0, HDA_PARAM_VENDOR_ID),
1822 revisionid = hdac_command(sc,
1823 HDA_CMD_GET_PARAMETER(cad, 0x0, HDA_PARAM_REVISION_ID),
1825 subnode = hdac_command(sc,
1826 HDA_CMD_GET_PARAMETER(cad, 0x0, HDA_PARAM_SUB_NODE_COUNT),
1828 startnode = HDA_PARAM_SUB_NODE_COUNT_START(subnode);
1829 endnode = startnode + HDA_PARAM_SUB_NODE_COUNT_TOTAL(subnode);
1832 device_printf(sc->dev, "HDA_DEBUG: \tstartnode=%d endnode=%d\n",
1833 startnode, endnode);
1835 for (i = startnode; i < endnode; i++) {
1836 devinfo = hdac_probe_function(codec, i);
1837 if (devinfo != NULL) {
1838 /* XXX Ignore other FG. */
1839 devinfo->vendor_id =
1840 HDA_PARAM_VENDOR_ID_VENDOR_ID(vendorid);
1841 devinfo->device_id =
1842 HDA_PARAM_VENDOR_ID_DEVICE_ID(vendorid);
1843 devinfo->revision_id =
1844 HDA_PARAM_REVISION_ID_REVISION_ID(revisionid);
1845 devinfo->stepping_id =
1846 HDA_PARAM_REVISION_ID_STEPPING_ID(revisionid);
1848 device_printf(sc->dev,
1849 "HDA_DEBUG: \tFound AFG nid=%d "
1850 "[startnode=%d endnode=%d]\n",
1851 devinfo->nid, startnode, endnode);
1858 device_printf(sc->dev, "HDA_DEBUG: \tAFG not found\n");
1863 static struct hdac_devinfo *
1864 hdac_probe_function(struct hdac_codec *codec, nid_t nid)
1866 struct hdac_softc *sc = codec->sc;
1867 struct hdac_devinfo *devinfo;
1868 uint32_t fctgrptype;
1869 nid_t cad = codec->cad;
1871 fctgrptype = HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE(hdac_command(sc,
1872 HDA_CMD_GET_PARAMETER(cad, nid, HDA_PARAM_FCT_GRP_TYPE), cad));
1874 /* XXX For now, ignore other FG. */
1875 if (fctgrptype != HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO)
1878 devinfo = (struct hdac_devinfo *)kmalloc(sizeof(*devinfo), M_HDAC,
1880 if (devinfo == NULL) {
1881 device_printf(sc->dev, "%s: Unable to allocate ivar\n",
1887 devinfo->node_type = fctgrptype;
1888 devinfo->codec = codec;
1890 hdac_add_child(sc, devinfo);
1896 hdac_add_child(struct hdac_softc *sc, struct hdac_devinfo *devinfo)
1898 devinfo->dev = device_add_child(sc->dev, NULL, -1);
1899 device_set_ivars(devinfo->dev, (void *)devinfo);
1900 /* XXX - Print more information when booting verbose??? */
1904 hdac_widget_connection_parse(struct hdac_widget *w)
1906 struct hdac_softc *sc = w->devinfo->codec->sc;
1908 int i, j, max, ents, entnum;
1909 nid_t cad = w->devinfo->codec->cad;
1911 nid_t cnid, addcnid, prevcnid;
1915 res = hdac_command(sc,
1916 HDA_CMD_GET_PARAMETER(cad, nid, HDA_PARAM_CONN_LIST_LENGTH), cad);
1918 ents = HDA_PARAM_CONN_LIST_LENGTH_LIST_LENGTH(res);
1923 entnum = HDA_PARAM_CONN_LIST_LENGTH_LONG_FORM(res) ? 2 : 4;
1924 max = (sizeof(w->conns) / sizeof(w->conns[0])) - 1;
1927 #define CONN_RMASK(e) (1 << ((32 / (e)) - 1))
1928 #define CONN_NMASK(e) (CONN_RMASK(e) - 1)
1929 #define CONN_RESVAL(r, e, n) ((r) >> ((32 / (e)) * (n)))
1930 #define CONN_RANGE(r, e, n) (CONN_RESVAL(r, e, n) & CONN_RMASK(e))
1931 #define CONN_CNID(r, e, n) (CONN_RESVAL(r, e, n) & CONN_NMASK(e))
1933 for (i = 0; i < ents; i += entnum) {
1934 res = hdac_command(sc,
1935 HDA_CMD_GET_CONN_LIST_ENTRY(cad, nid, i), cad);
1936 for (j = 0; j < entnum; j++) {
1937 cnid = CONN_CNID(res, entnum, j);
1939 if (w->nconns < ents)
1940 device_printf(sc->dev,
1941 "%s: nid=%d WARNING: zero cnid "
1942 "entnum=%d j=%d index=%d "
1943 "entries=%d found=%d res=0x%08x\n",
1944 __func__, nid, entnum, j, i,
1945 ents, w->nconns, res);
1949 if (cnid < w->devinfo->startnode ||
1950 cnid >= w->devinfo->endnode) {
1952 device_printf(sc->dev,
1953 "%s: GHOST: nid=%d j=%d "
1954 "entnum=%d index=%d res=0x%08x\n",
1955 __func__, nid, j, entnum, i, res);
1958 if (CONN_RANGE(res, entnum, j) == 0)
1960 else if (prevcnid == 0 || prevcnid >= cnid) {
1961 device_printf(sc->dev,
1962 "%s: WARNING: Invalid child range "
1963 "nid=%d index=%d j=%d entnum=%d "
1964 "prevcnid=%d cnid=%d res=0x%08x\n",
1965 __func__, nid, i, j, entnum, prevcnid,
1969 addcnid = prevcnid + 1;
1970 while (addcnid <= cnid) {
1971 if (w->nconns > max) {
1972 device_printf(sc->dev,
1973 "%s: nid=%d: Adding %d: "
1974 "Max connection reached! max=%d\n",
1975 __func__, nid, addcnid, max + 1);
1978 w->conns[w->nconns++] = addcnid++;
1986 device_printf(sc->dev,
1987 "HDA_DEBUG: %s: nid=%d entries=%d found=%d\n",
1988 __func__, nid, ents, w->nconns);
1994 hdac_widget_pin_getconfig(struct hdac_widget *w)
1996 struct hdac_softc *sc;
1997 uint32_t config, orig, id;
2000 sc = w->devinfo->codec->sc;
2001 cad = w->devinfo->codec->cad;
2003 id = hdac_codec_id(w->devinfo);
2005 config = hdac_command(sc,
2006 HDA_CMD_GET_CONFIGURATION_DEFAULT(cad, nid),
2011 * XXX REWRITE!!!! Don't argue!
2013 if (id == HDA_CODEC_ALC880 && sc->pci_subvendor == LG_LW20_SUBVENDOR) {
2016 config &= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
2017 config |= HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN;
2020 config &= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
2021 config |= HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT;
2026 } else if (id == HDA_CODEC_ALC880 &&
2027 (sc->pci_subvendor == CLEVO_D900T_SUBVENDOR ||
2028 sc->pci_subvendor == ASUS_M5200_SUBVENDOR)) {
2042 config &= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
2043 config |= HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN;
2045 case 25: /* XXX MIC2 */
2046 config &= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
2047 config |= HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN;
2049 case 26: /* LINE1 */
2050 config &= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
2051 config |= HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN;
2053 case 27: /* XXX LINE2 */
2054 config &= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
2055 config |= HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN;
2058 config &= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
2059 config |= HDA_CONFIG_DEFAULTCONF_DEVICE_CD;
2068 } else if (id == HDA_CODEC_ALC883 &&
2069 (sc->pci_subvendor == MSI_MS034A_SUBVENDOR ||
2070 HDA_DEV_MATCH(ACER_ALL_SUBVENDOR, sc->pci_subvendor))) {
2073 config &= ~(HDA_CONFIG_DEFAULTCONF_DEVICE_MASK |
2074 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK);
2075 config |= (HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN |
2076 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_FIXED);
2079 config &= ~(HDA_CONFIG_DEFAULTCONF_DEVICE_MASK |
2080 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK);
2081 config |= (HDA_CONFIG_DEFAULTCONF_DEVICE_CD |
2082 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_FIXED);
2087 } else if (id == HDA_CODEC_CXVENICE && sc->pci_subvendor ==
2088 HP_V3000_SUBVENDOR) {
2091 config &= ~HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK;
2092 config |= HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_NONE;
2095 config &= ~(HDA_CONFIG_DEFAULTCONF_DEVICE_MASK |
2096 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK);
2097 config |= (HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN |
2098 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_FIXED);
2101 config &= ~(HDA_CONFIG_DEFAULTCONF_DEVICE_MASK |
2102 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK);
2103 config |= (HDA_CONFIG_DEFAULTCONF_DEVICE_CD |
2104 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_FIXED);
2109 } else if (id == HDA_CODEC_CXWAIKIKI && sc->pci_subvendor ==
2110 HP_DV5000_SUBVENDOR) {
2114 config &= ~HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK;
2115 config |= HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_NONE;
2120 } else if (id == HDA_CODEC_ALC861 && sc->pci_subvendor ==
2121 ASUS_W6F_SUBVENDOR) {
2124 config &= ~(HDA_CONFIG_DEFAULTCONF_DEVICE_MASK |
2125 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK);
2126 config |= (HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_OUT |
2127 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_FIXED);
2130 config &= ~(HDA_CONFIG_DEFAULTCONF_DEVICE_MASK |
2131 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK);
2132 config |= (HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT |
2133 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_JACK);
2138 } else if (id == HDA_CODEC_ALC861 && sc->pci_subvendor ==
2139 UNIWILL_9075_SUBVENDOR) {
2142 config &= ~(HDA_CONFIG_DEFAULTCONF_DEVICE_MASK |
2143 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK);
2144 config |= (HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT |
2145 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_JACK);
2150 } else if (id == HDA_CODEC_AD1986A &&
2151 (sc->pci_subvendor == ASUS_M2NPVMX_SUBVENDOR ||
2152 sc->pci_subvendor == ASUS_A8NVMCSM_SUBVENDOR)) {
2155 config &= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
2156 config |= HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN;
2159 config &= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
2160 config |= HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN;
2169 device_printf(sc->dev,
2170 "HDA_DEBUG: Pin config nid=%u 0x%08x -> 0x%08x\n",
2178 hdac_widget_pin_getcaps(struct hdac_widget *w)
2180 struct hdac_softc *sc;
2181 uint32_t caps, orig, id;
2184 sc = w->devinfo->codec->sc;
2185 cad = w->devinfo->codec->cad;
2187 id = hdac_codec_id(w->devinfo);
2189 caps = hdac_command(sc,
2190 HDA_CMD_GET_PARAMETER(cad, nid, HDA_PARAM_PIN_CAP), cad);
2195 device_printf(sc->dev,
2196 "HDA_DEBUG: Pin caps nid=%u 0x%08x -> 0x%08x\n",
2204 hdac_widget_pin_parse(struct hdac_widget *w)
2206 struct hdac_softc *sc = w->devinfo->codec->sc;
2207 uint32_t config, pincap;
2208 char *devstr, *connstr;
2209 nid_t cad = w->devinfo->codec->cad;
2212 config = hdac_widget_pin_getconfig(w);
2213 w->wclass.pin.config = config;
2215 pincap = hdac_widget_pin_getcaps(w);
2216 w->wclass.pin.cap = pincap;
2218 w->wclass.pin.ctrl = hdac_command(sc,
2219 HDA_CMD_GET_PIN_WIDGET_CTRL(cad, nid), cad) &
2220 ~(HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE |
2221 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE |
2222 HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE |
2223 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK);
2225 if (HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap))
2226 w->wclass.pin.ctrl |= HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE;
2227 if (HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap))
2228 w->wclass.pin.ctrl |= HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE;
2229 if (HDA_PARAM_PIN_CAP_INPUT_CAP(pincap))
2230 w->wclass.pin.ctrl |= HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE;
2231 if (HDA_PARAM_PIN_CAP_EAPD_CAP(pincap)) {
2232 w->param.eapdbtl = hdac_command(sc,
2233 HDA_CMD_GET_EAPD_BTL_ENABLE(cad, nid), cad);
2234 w->param.eapdbtl &= 0x7;
2235 w->param.eapdbtl |= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
2237 w->param.eapdbtl = HDAC_INVALID;
2239 switch (config & HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) {
2240 case HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_OUT:
2241 devstr = "line out";
2243 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER:
2246 case HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT:
2247 devstr = "headphones out";
2249 case HDA_CONFIG_DEFAULTCONF_DEVICE_CD:
2252 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_OUT:
2253 devstr = "SPDIF out";
2255 case HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_OUT:
2256 devstr = "digital (other) out";
2258 case HDA_CONFIG_DEFAULTCONF_DEVICE_MODEM_LINE:
2259 devstr = "modem, line side";
2261 case HDA_CONFIG_DEFAULTCONF_DEVICE_MODEM_HANDSET:
2262 devstr = "modem, handset side";
2264 case HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN:
2267 case HDA_CONFIG_DEFAULTCONF_DEVICE_AUX:
2270 case HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN:
2273 case HDA_CONFIG_DEFAULTCONF_DEVICE_TELEPHONY:
2274 devstr = "telephony";
2276 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_IN:
2277 devstr = "SPDIF in";
2279 case HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_IN:
2280 devstr = "digital (other) in";
2282 case HDA_CONFIG_DEFAULTCONF_DEVICE_OTHER:
2290 switch (config & HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK) {
2291 case HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_JACK:
2294 case HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_NONE:
2297 case HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_FIXED:
2300 case HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_BOTH:
2301 connstr = "jack / fixed";
2304 connstr = "unknown";
2308 strlcat(w->name, ": ", sizeof(w->name));
2309 strlcat(w->name, devstr, sizeof(w->name));
2310 strlcat(w->name, " (", sizeof(w->name));
2311 strlcat(w->name, connstr, sizeof(w->name));
2312 strlcat(w->name, ")", sizeof(w->name));
2316 hdac_widget_parse(struct hdac_widget *w)
2318 struct hdac_softc *sc = w->devinfo->codec->sc;
2321 nid_t cad = w->devinfo->codec->cad;
2324 wcap = hdac_command(sc,
2325 HDA_CMD_GET_PARAMETER(cad, nid, HDA_PARAM_AUDIO_WIDGET_CAP),
2327 w->param.widget_cap = wcap;
2328 w->type = HDA_PARAM_AUDIO_WIDGET_CAP_TYPE(wcap);
2331 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT:
2332 typestr = "audio output";
2334 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT:
2335 typestr = "audio input";
2337 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER:
2338 typestr = "audio mixer";
2340 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR:
2341 typestr = "audio selector";
2343 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
2346 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_POWER_WIDGET:
2347 typestr = "power widget";
2349 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_VOLUME_WIDGET:
2350 typestr = "volume widget";
2352 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET:
2353 typestr = "beep widget";
2355 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_VENDOR_WIDGET:
2356 typestr = "vendor widget";
2359 typestr = "unknown type";
2363 strlcpy(w->name, typestr, sizeof(w->name));
2365 if (HDA_PARAM_AUDIO_WIDGET_CAP_POWER_CTRL(wcap)) {
2367 HDA_CMD_SET_POWER_STATE(cad, nid, HDA_CMD_POWER_STATE_D0),
2372 hdac_widget_connection_parse(w);
2374 if (HDA_PARAM_AUDIO_WIDGET_CAP_OUT_AMP(wcap)) {
2375 if (HDA_PARAM_AUDIO_WIDGET_CAP_AMP_OVR(wcap))
2376 w->param.outamp_cap =
2378 HDA_CMD_GET_PARAMETER(cad, nid,
2379 HDA_PARAM_OUTPUT_AMP_CAP), cad);
2381 w->param.outamp_cap =
2382 w->devinfo->function.audio.outamp_cap;
2384 w->param.outamp_cap = 0;
2386 if (HDA_PARAM_AUDIO_WIDGET_CAP_IN_AMP(wcap)) {
2387 if (HDA_PARAM_AUDIO_WIDGET_CAP_AMP_OVR(wcap))
2388 w->param.inamp_cap =
2390 HDA_CMD_GET_PARAMETER(cad, nid,
2391 HDA_PARAM_INPUT_AMP_CAP), cad);
2393 w->param.inamp_cap =
2394 w->devinfo->function.audio.inamp_cap;
2396 w->param.inamp_cap = 0;
2398 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT ||
2399 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
2400 if (HDA_PARAM_AUDIO_WIDGET_CAP_FORMAT_OVR(wcap)) {
2401 cap = hdac_command(sc,
2402 HDA_CMD_GET_PARAMETER(cad, nid,
2403 HDA_PARAM_SUPP_STREAM_FORMATS), cad);
2404 w->param.supp_stream_formats = (cap != 0) ? cap :
2405 w->devinfo->function.audio.supp_stream_formats;
2406 cap = hdac_command(sc,
2407 HDA_CMD_GET_PARAMETER(cad, nid,
2408 HDA_PARAM_SUPP_PCM_SIZE_RATE), cad);
2409 w->param.supp_pcm_size_rate = (cap != 0) ? cap :
2410 w->devinfo->function.audio.supp_pcm_size_rate;
2412 w->param.supp_stream_formats =
2413 w->devinfo->function.audio.supp_stream_formats;
2414 w->param.supp_pcm_size_rate =
2415 w->devinfo->function.audio.supp_pcm_size_rate;
2418 w->param.supp_stream_formats = 0;
2419 w->param.supp_pcm_size_rate = 0;
2422 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
2423 hdac_widget_pin_parse(w);
2426 static struct hdac_widget *
2427 hdac_widget_get(struct hdac_devinfo *devinfo, nid_t nid)
2429 if (devinfo == NULL || devinfo->widget == NULL ||
2430 nid < devinfo->startnode || nid >= devinfo->endnode)
2432 return (&devinfo->widget[nid - devinfo->startnode]);
2436 hda_poll_channel(struct hdac_chan *ch)
2439 volatile uint32_t ptr;
2441 if (!(ch->flags & HDAC_CHN_RUNNING))
2444 sz = ch->blksz * ch->blkcnt;
2445 if (ch->dmapos != NULL)
2446 ptr = *(ch->dmapos);
2448 ptr = HDAC_READ_4(&ch->devinfo->codec->sc->mem,
2449 ch->off + HDAC_SDLPIB);
2452 ptr &= ~(ch->blksz - 1);
2453 delta = (sz + ptr - ch->prevptr) % sz;
2455 if (delta < ch->blksz)
2463 #define hda_chan_active(sc) (((sc)->play.flags | (sc)->rec.flags) & \
2467 hda_poll_callback(void *arg)
2469 struct hdac_softc *sc = arg;
2476 if (sc->polling == 0 || hda_chan_active(sc) == 0) {
2482 trigger |= (hda_poll_channel(&sc->play) != 0) ? HDAC_TRIGGER_PLAY : 0;
2483 trigger |= (hda_poll_channel(&sc->rec)) != 0 ? HDAC_TRIGGER_REC : 0;
2486 callout_reset(&sc->poll_hda, 1/*sc->poll_ticks*/,
2487 hda_poll_callback, sc);
2491 if (trigger & HDAC_TRIGGER_PLAY)
2492 chn_intr(sc->play.c);
2493 if (trigger & HDAC_TRIGGER_REC)
2494 chn_intr(sc->rec.c);
2498 hdac_rirb_flush(struct hdac_softc *sc)
2500 struct hdac_rirb *rirb_base, *rirb;
2501 struct hdac_codec *codec;
2502 struct hdac_command_list *commands;
2508 rirb_base = (struct hdac_rirb *)sc->rirb_dma.dma_vaddr;
2509 rirbwp = HDAC_READ_1(&sc->mem, HDAC_RIRBWP);
2511 bus_dmamap_sync(sc->rirb_dma.dma_tag, sc->rirb_dma.dma_map,
2512 BUS_DMASYNC_POSTREAD);
2516 while (sc->rirb_rp != rirbwp) {
2518 sc->rirb_rp %= sc->rirb_size;
2519 rirb = &rirb_base[sc->rirb_rp];
2520 cad = HDAC_RIRB_RESPONSE_EX_SDATA_IN(rirb->response_ex);
2521 if (cad < 0 || cad >= HDAC_CODEC_MAX ||
2522 sc->codecs[cad] == NULL)
2524 resp = rirb->response;
2525 codec = sc->codecs[cad];
2526 commands = codec->commands;
2527 if (rirb->response_ex & HDAC_RIRB_RESPONSE_EX_UNSOLICITED) {
2528 sc->unsolq[sc->unsolq_wp++] = (cad << 16) |
2529 ((resp >> 26) & 0xffff);
2530 sc->unsolq_wp %= HDAC_UNSOLQ_MAX;
2531 } else if (commands != NULL && commands->num_commands > 0 &&
2532 codec->responses_received < commands->num_commands)
2533 commands->responses[codec->responses_received++] =
2542 hdac_unsolq_flush(struct hdac_softc *sc)
2548 if (sc->unsolq_st == HDAC_UNSOLQ_READY) {
2549 sc->unsolq_st = HDAC_UNSOLQ_BUSY;
2550 while (sc->unsolq_rp != sc->unsolq_wp) {
2551 cad = sc->unsolq[sc->unsolq_rp] >> 16;
2552 tag = sc->unsolq[sc->unsolq_rp++] & 0xffff;
2553 sc->unsolq_rp %= HDAC_UNSOLQ_MAX;
2554 hdac_unsolicited_handler(sc->codecs[cad], tag);
2557 sc->unsolq_st = HDAC_UNSOLQ_READY;
2564 hdac_poll_callback(void *arg)
2566 struct hdac_softc *sc = arg;
2571 if (sc->polling == 0 || sc->poll_ival == 0) {
2575 if (hdac_rirb_flush(sc) != 0)
2576 hdac_unsolq_flush(sc);
2577 callout_reset(&sc->poll_hdac, sc->poll_ival, hdac_poll_callback, sc);
2582 hdac_stream_stop(struct hdac_chan *ch)
2584 struct hdac_softc *sc = ch->devinfo->codec->sc;
2587 ctl = HDAC_READ_1(&sc->mem, ch->off + HDAC_SDCTL0);
2588 ctl &= ~(HDAC_SDCTL_IOCE | HDAC_SDCTL_FEIE | HDAC_SDCTL_DEIE |
2590 HDAC_WRITE_1(&sc->mem, ch->off + HDAC_SDCTL0, ctl);
2592 ch->flags &= ~HDAC_CHN_RUNNING;
2594 if (sc->polling != 0) {
2597 if (hda_chan_active(sc) == 0) {
2598 callout_stop(&sc->poll_hda);
2601 if (sc->play.flags & HDAC_CHN_RUNNING)
2605 pollticks = ((uint64_t)hz * ch->blksz) /
2606 ((uint64_t)sndbuf_getbps(ch->b) *
2607 sndbuf_getspd(ch->b));
2611 if (pollticks < 1) {
2613 device_printf(sc->dev,
2614 "%s: pollticks=%d < 1 !\n",
2615 __func__, pollticks);
2619 if (pollticks > sc->poll_ticks) {
2621 device_printf(sc->dev,
2622 "%s: pollticks %d -> %d\n",
2623 __func__, sc->poll_ticks,
2626 sc->poll_ticks = pollticks;
2627 callout_reset(&sc->poll_hda, 1,
2628 hda_poll_callback, sc);
2632 ctl = HDAC_READ_4(&sc->mem, HDAC_INTCTL);
2633 ctl &= ~(1 << (ch->off >> 5));
2634 HDAC_WRITE_4(&sc->mem, HDAC_INTCTL, ctl);
2639 hdac_stream_start(struct hdac_chan *ch)
2641 struct hdac_softc *sc = ch->devinfo->codec->sc;
2644 if (sc->polling != 0) {
2647 pollticks = ((uint64_t)hz * ch->blksz) /
2648 ((uint64_t)sndbuf_getbps(ch->b) * sndbuf_getspd(ch->b));
2652 if (pollticks < 1) {
2654 device_printf(sc->dev,
2655 "%s: pollticks=%d < 1 !\n",
2656 __func__, pollticks);
2660 if (hda_chan_active(sc) == 0 || pollticks < sc->poll_ticks) {
2662 if (hda_chan_active(sc) == 0) {
2663 device_printf(sc->dev,
2664 "%s: pollticks=%d\n",
2665 __func__, pollticks);
2667 device_printf(sc->dev,
2668 "%s: pollticks %d -> %d\n",
2669 __func__, sc->poll_ticks,
2673 sc->poll_ticks = pollticks;
2674 callout_reset(&sc->poll_hda, 1, hda_poll_callback,
2677 ctl = HDAC_READ_1(&sc->mem, ch->off + HDAC_SDCTL0);
2678 ctl |= HDAC_SDCTL_RUN;
2680 ctl = HDAC_READ_4(&sc->mem, HDAC_INTCTL);
2681 ctl |= 1 << (ch->off >> 5);
2682 HDAC_WRITE_4(&sc->mem, HDAC_INTCTL, ctl);
2683 ctl = HDAC_READ_1(&sc->mem, ch->off + HDAC_SDCTL0);
2684 ctl |= HDAC_SDCTL_IOCE | HDAC_SDCTL_FEIE | HDAC_SDCTL_DEIE |
2687 HDAC_WRITE_1(&sc->mem, ch->off + HDAC_SDCTL0, ctl);
2689 ch->flags |= HDAC_CHN_RUNNING;
2693 hdac_stream_reset(struct hdac_chan *ch)
2695 struct hdac_softc *sc = ch->devinfo->codec->sc;
2700 ctl = HDAC_READ_1(&sc->mem, ch->off + HDAC_SDCTL0);
2701 ctl |= HDAC_SDCTL_SRST;
2702 HDAC_WRITE_1(&sc->mem, ch->off + HDAC_SDCTL0, ctl);
2704 ctl = HDAC_READ_1(&sc->mem, ch->off + HDAC_SDCTL0);
2705 if (ctl & HDAC_SDCTL_SRST)
2709 if (!(ctl & HDAC_SDCTL_SRST)) {
2710 device_printf(sc->dev, "timeout in reset\n");
2712 ctl &= ~HDAC_SDCTL_SRST;
2713 HDAC_WRITE_1(&sc->mem, ch->off + HDAC_SDCTL0, ctl);
2716 ctl = HDAC_READ_1(&sc->mem, ch->off + HDAC_SDCTL0);
2717 if (!(ctl & HDAC_SDCTL_SRST))
2721 if (ctl & HDAC_SDCTL_SRST)
2722 device_printf(sc->dev, "can't reset!\n");
2726 hdac_stream_setid(struct hdac_chan *ch)
2728 struct hdac_softc *sc = ch->devinfo->codec->sc;
2731 ctl = HDAC_READ_1(&sc->mem, ch->off + HDAC_SDCTL2);
2732 ctl &= ~HDAC_SDCTL2_STRM_MASK;
2733 ctl |= ch->sid << HDAC_SDCTL2_STRM_SHIFT;
2734 HDAC_WRITE_1(&sc->mem, ch->off + HDAC_SDCTL2, ctl);
2738 hdac_bdl_setup(struct hdac_chan *ch)
2740 struct hdac_softc *sc = ch->devinfo->codec->sc;
2741 struct hdac_bdle *bdle;
2743 uint32_t blksz, blkcnt;
2746 addr = (uint64_t)sndbuf_getbufaddr(ch->b);
2747 bdle = (struct hdac_bdle *)ch->bdl_dma.dma_vaddr;
2749 if (sc->polling != 0) {
2750 blksz = ch->blksz * ch->blkcnt;
2754 blkcnt = ch->blkcnt;
2757 for (i = 0; i < blkcnt; i++, bdle++) {
2758 bdle->addrl = (uint32_t)addr;
2759 bdle->addrh = (uint32_t)(addr >> 32);
2761 bdle->ioc = 1 ^ sc->polling;
2765 HDAC_WRITE_4(&sc->mem, ch->off + HDAC_SDCBL, blksz * blkcnt);
2766 HDAC_WRITE_2(&sc->mem, ch->off + HDAC_SDLVI, blkcnt - 1);
2767 addr = ch->bdl_dma.dma_paddr;
2768 HDAC_WRITE_4(&sc->mem, ch->off + HDAC_SDBDPL, (uint32_t)addr);
2769 HDAC_WRITE_4(&sc->mem, ch->off + HDAC_SDBDPU, (uint32_t)(addr >> 32));
2770 if (ch->dmapos != NULL &&
2771 !(HDAC_READ_4(&sc->mem, HDAC_DPIBLBASE) & 0x00000001)) {
2772 addr = sc->pos_dma.dma_paddr;
2773 HDAC_WRITE_4(&sc->mem, HDAC_DPIBLBASE,
2774 ((uint32_t)addr & HDAC_DPLBASE_DPLBASE_MASK) | 0x00000001);
2775 HDAC_WRITE_4(&sc->mem, HDAC_DPIBUBASE, (uint32_t)(addr >> 32));
2780 hdac_bdl_alloc(struct hdac_chan *ch)
2782 struct hdac_softc *sc = ch->devinfo->codec->sc;
2785 rc = hdac_dma_alloc(sc, &ch->bdl_dma,
2786 sizeof(struct hdac_bdle) * HDA_BDL_MAX);
2788 device_printf(sc->dev, "can't alloc bdl\n");
2796 hdac_audio_ctl_amp_set_internal(struct hdac_softc *sc, nid_t cad, nid_t nid,
2797 int index, int lmute, int rmute,
2798 int left, int right, int dir)
2805 if (left != right || lmute != rmute) {
2806 v = (1 << (15 - dir)) | (1 << 13) | (index << 8) |
2807 (lmute << 7) | left;
2809 HDA_CMD_SET_AMP_GAIN_MUTE(cad, nid, v), cad);
2810 v = (1 << (15 - dir)) | (1 << 12) | (index << 8) |
2811 (rmute << 7) | right;
2813 v = (1 << (15 - dir)) | (3 << 12) | (index << 8) |
2814 (lmute << 7) | left;
2817 HDA_CMD_SET_AMP_GAIN_MUTE(cad, nid, v), cad);
2821 hdac_audio_ctl_amp_set(struct hdac_audio_ctl *ctl, uint32_t mute,
2822 int left, int right)
2824 struct hdac_softc *sc;
2828 if (ctl == NULL || ctl->widget == NULL ||
2829 ctl->widget->devinfo == NULL ||
2830 ctl->widget->devinfo->codec == NULL ||
2831 ctl->widget->devinfo->codec->sc == NULL)
2834 sc = ctl->widget->devinfo->codec->sc;
2835 cad = ctl->widget->devinfo->codec->cad;
2836 nid = ctl->widget->nid;
2838 if (mute == HDA_AMP_MUTE_DEFAULT) {
2839 lmute = HDA_AMP_LEFT_MUTED(ctl->muted);
2840 rmute = HDA_AMP_RIGHT_MUTED(ctl->muted);
2842 lmute = HDA_AMP_LEFT_MUTED(mute);
2843 rmute = HDA_AMP_RIGHT_MUTED(mute);
2846 if (ctl->dir & HDA_CTL_OUT)
2847 hdac_audio_ctl_amp_set_internal(sc, cad, nid, ctl->index,
2848 lmute, rmute, left, right, 0);
2849 if (ctl->dir & HDA_CTL_IN)
2850 hdac_audio_ctl_amp_set_internal(sc, cad, nid, ctl->index,
2851 lmute, rmute, left, right, 1);
2857 hdac_widget_connection_select(struct hdac_widget *w, uint8_t index)
2859 if (w == NULL || w->nconns < 1 || index > (w->nconns - 1))
2861 hdac_command(w->devinfo->codec->sc,
2862 HDA_CMD_SET_CONNECTION_SELECT_CONTROL(w->devinfo->codec->cad,
2863 w->nid, index), w->devinfo->codec->cad);
2868 /****************************************************************************
2869 * uint32_t hdac_command_sendone_internal
2871 * Wrapper function that sends only one command to a given codec
2872 ****************************************************************************/
2874 hdac_command_sendone_internal(struct hdac_softc *sc, uint32_t verb, nid_t cad)
2876 struct hdac_command_list cl;
2877 uint32_t response = HDAC_INVALID;
2879 if (!hdac_lockowned(sc))
2880 device_printf(sc->dev, "WARNING!!!! mtx not owned!!!!\n");
2881 cl.num_commands = 1;
2883 cl.responses = &response;
2885 hdac_command_send_internal(sc, &cl, cad);
2890 /****************************************************************************
2891 * hdac_command_send_internal
2893 * Send a command list to the codec via the corb. We queue as much verbs as
2894 * we can and msleep on the codec. When the interrupt get the responses
2895 * back from the rirb, it will wake us up so we can queue the remaining verbs
2897 ****************************************************************************/
2899 hdac_command_send_internal(struct hdac_softc *sc,
2900 struct hdac_command_list *commands, nid_t cad)
2902 struct hdac_codec *codec;
2907 struct hdac_rirb *rirb_base;
2909 if (sc == NULL || sc->codecs[cad] == NULL || commands == NULL ||
2910 commands->num_commands < 1)
2913 codec = sc->codecs[cad];
2914 codec->commands = commands;
2915 codec->responses_received = 0;
2916 codec->verbs_sent = 0;
2917 corb = (uint32_t *)sc->corb_dma.dma_vaddr;
2918 rirb_base = (struct hdac_rirb *)sc->rirb_dma.dma_vaddr;
2921 if (codec->verbs_sent != commands->num_commands) {
2922 /* Queue as many verbs as possible */
2923 corbrp = HDAC_READ_2(&sc->mem, HDAC_CORBRP);
2925 bus_dmamap_sync(sc->corb_dma.dma_tag,
2926 sc->corb_dma.dma_map, BUS_DMASYNC_PREWRITE);
2928 while (codec->verbs_sent != commands->num_commands &&
2929 ((sc->corb_wp + 1) % sc->corb_size) != corbrp) {
2931 sc->corb_wp %= sc->corb_size;
2933 commands->verbs[codec->verbs_sent++];
2936 /* Send the verbs to the codecs */
2938 bus_dmamap_sync(sc->corb_dma.dma_tag,
2939 sc->corb_dma.dma_map, BUS_DMASYNC_POSTWRITE);
2941 HDAC_WRITE_2(&sc->mem, HDAC_CORBWP, sc->corb_wp);
2945 while (hdac_rirb_flush(sc) == 0 && --timeout)
2947 } while ((codec->verbs_sent != commands->num_commands ||
2948 codec->responses_received != commands->num_commands) && --retry);
2951 device_printf(sc->dev,
2952 "%s: TIMEOUT numcmd=%d, sent=%d, received=%d\n",
2953 __func__, commands->num_commands, codec->verbs_sent,
2954 codec->responses_received);
2956 codec->commands = NULL;
2957 codec->responses_received = 0;
2958 codec->verbs_sent = 0;
2960 hdac_unsolq_flush(sc);
2964 /****************************************************************************
2966 ****************************************************************************/
2968 /****************************************************************************
2969 * int hdac_probe(device_t)
2971 * Probe for the presence of an hdac. If none is found, check for a generic
2972 * match using the subclass of the device.
2973 ****************************************************************************/
2975 hdac_probe(device_t dev)
2979 uint16_t class, subclass;
2982 model = (uint32_t)pci_get_device(dev) << 16;
2983 model |= (uint32_t)pci_get_vendor(dev) & 0x0000ffff;
2984 class = pci_get_class(dev);
2985 subclass = pci_get_subclass(dev);
2987 bzero(desc, sizeof(desc));
2989 for (i = 0; i < HDAC_DEVICES_LEN; i++) {
2990 if (hdac_devices[i].model == model) {
2991 strlcpy(desc, hdac_devices[i].desc, sizeof(desc));
2992 result = BUS_PROBE_DEFAULT;
2995 if (HDA_DEV_MATCH(hdac_devices[i].model, model) &&
2996 class == PCIC_MULTIMEDIA &&
2997 subclass == PCIS_MULTIMEDIA_HDA) {
2998 strlcpy(desc, hdac_devices[i].desc, sizeof(desc));
2999 result = BUS_PROBE_GENERIC;
3003 if (result == ENXIO && class == PCIC_MULTIMEDIA &&
3004 subclass == PCIS_MULTIMEDIA_HDA) {
3005 strlcpy(desc, "Generic", sizeof(desc));
3006 result = BUS_PROBE_GENERIC;
3008 if (result != ENXIO) {
3009 strlcat(desc, " High Definition Audio Controller",
3011 device_set_desc_copy(dev, desc);
3018 hdac_channel_init(kobj_t obj, void *data, struct snd_dbuf *b,
3019 struct pcm_channel *c, int dir)
3021 struct hdac_devinfo *devinfo = data;
3022 struct hdac_softc *sc = devinfo->codec->sc;
3023 struct hdac_chan *ch;
3026 if (dir == PCMDIR_PLAY) {
3028 ch->off = (sc->num_iss + devinfo->function.audio.playcnt) << 5;
3029 devinfo->function.audio.playcnt++;
3032 ch->off = devinfo->function.audio.reccnt << 5;
3033 devinfo->function.audio.reccnt++;
3035 if (devinfo->function.audio.quirks & HDA_QUIRK_FIXEDRATE) {
3036 ch->caps.minspeed = ch->caps.maxspeed = 48000;
3037 ch->pcmrates[0] = 48000;
3038 ch->pcmrates[1] = 0;
3040 if (sc->pos_dma.dma_vaddr != NULL)
3041 ch->dmapos = (uint32_t *)(sc->pos_dma.dma_vaddr +
3042 (sc->streamcnt * 8));
3045 ch->sid = ++sc->streamcnt;
3049 ch->devinfo = devinfo;
3050 ch->blksz = sc->chan_size / sc->chan_blkcnt;
3051 ch->blkcnt = sc->chan_blkcnt;
3054 if (hdac_bdl_alloc(ch) != 0) {
3059 if (sndbuf_alloc(ch->b, sc->chan_dmat, sc->chan_size) != 0)
3062 HDAC_DMA_ATTR(sc, sndbuf_getbuf(ch->b), sndbuf_getmaxsize(ch->b),
3069 hdac_channel_free(kobj_t obj, void *data)
3071 struct hdac_softc *sc;
3072 struct hdac_chan *ch;
3074 ch = (struct hdac_chan *)data;
3075 sc = (ch != NULL && ch->devinfo != NULL && ch->devinfo->codec != NULL) ?
3076 ch->devinfo->codec->sc : NULL;
3077 if (ch != NULL && sc != NULL) {
3078 HDAC_DMA_ATTR(sc, sndbuf_getbuf(ch->b),
3079 sndbuf_getmaxsize(ch->b), PAT_WRITE_BACK);
3086 hdac_channel_setformat(kobj_t obj, void *data, uint32_t format)
3088 struct hdac_chan *ch = data;
3091 for (i = 0; ch->caps.fmtlist[i] != 0; i++) {
3092 if (format == ch->caps.fmtlist[i]) {
3102 hdac_channel_setspeed(kobj_t obj, void *data, uint32_t speed)
3104 struct hdac_chan *ch = data;
3105 uint32_t spd = 0, threshold;
3108 for (i = 0; ch->pcmrates[i] != 0; i++) {
3109 spd = ch->pcmrates[i];
3110 threshold = spd + ((ch->pcmrates[i + 1] != 0) ?
3111 ((ch->pcmrates[i + 1] - spd) >> 1) : 0);
3112 if (speed < threshold)
3116 if (spd == 0) /* impossible */
3125 hdac_stream_setup(struct hdac_chan *ch)
3127 struct hdac_softc *sc = ch->devinfo->codec->sc;
3129 nid_t cad = ch->devinfo->codec->cad;
3133 if (ch->fmt & AFMT_S16_LE)
3134 fmt |= ch->bit16 << 4;
3135 else if (ch->fmt & AFMT_S32_LE)
3136 fmt |= ch->bit32 << 4;
3140 for (i = 0; i < HDA_RATE_TAB_LEN; i++) {
3141 if (hda_rate_tab[i].valid && ch->spd == hda_rate_tab[i].rate) {
3142 fmt |= hda_rate_tab[i].base;
3143 fmt |= hda_rate_tab[i].mul;
3144 fmt |= hda_rate_tab[i].div;
3149 if (ch->fmt & AFMT_STEREO)
3152 HDAC_WRITE_2(&sc->mem, ch->off + HDAC_SDFMT, fmt);
3154 for (i = 0; ch->io[i] != -1; i++) {
3156 device_printf(sc->dev,
3157 "HDA_DEBUG: PCMDIR_%s: Stream setup nid=%d "
3159 (ch->dir == PCMDIR_PLAY) ? "PLAY" : "REC",
3163 HDA_CMD_SET_CONV_FMT(cad, ch->io[i], fmt), cad);
3165 HDA_CMD_SET_CONV_STREAM_CHAN(cad, ch->io[i],
3166 ch->sid << 4), cad);
3171 hdac_channel_setfragments(kobj_t obj, void *data,
3172 uint32_t blksz, uint32_t blkcnt)
3174 struct hdac_chan *ch = data;
3175 struct hdac_softc *sc = ch->devinfo->codec->sc;
3177 blksz &= HDA_BLK_ALIGN;
3179 if (blksz > (sndbuf_getmaxsize(ch->b) / HDA_BDL_MIN))
3180 blksz = sndbuf_getmaxsize(ch->b) / HDA_BDL_MIN;
3181 if (blksz < HDA_BLK_MIN)
3182 blksz = HDA_BLK_MIN;
3183 if (blkcnt > HDA_BDL_MAX)
3184 blkcnt = HDA_BDL_MAX;
3185 if (blkcnt < HDA_BDL_MIN)
3186 blkcnt = HDA_BDL_MIN;
3188 while ((blksz * blkcnt) > sndbuf_getmaxsize(ch->b)) {
3189 if ((blkcnt >> 1) >= HDA_BDL_MIN)
3191 else if ((blksz >> 1) >= HDA_BLK_MIN)
3197 if ((sndbuf_getblksz(ch->b) != blksz ||
3198 sndbuf_getblkcnt(ch->b) != blkcnt) &&
3199 sndbuf_resize(ch->b, blkcnt, blksz) != 0)
3200 device_printf(sc->dev, "%s: failed blksz=%u blkcnt=%u\n",
3201 __func__, blksz, blkcnt);
3203 ch->blksz = sndbuf_getblksz(ch->b);
3204 ch->blkcnt = sndbuf_getblkcnt(ch->b);
3210 hdac_channel_setblocksize(kobj_t obj, void *data, uint32_t blksz)
3212 struct hdac_chan *ch = data;
3213 struct hdac_softc *sc = ch->devinfo->codec->sc;
3215 hdac_channel_setfragments(obj, data, blksz, sc->chan_blkcnt);
3221 hdac_channel_stop(struct hdac_softc *sc, struct hdac_chan *ch)
3223 struct hdac_devinfo *devinfo = ch->devinfo;
3224 nid_t cad = devinfo->codec->cad;
3227 hdac_stream_stop(ch);
3229 for (i = 0; ch->io[i] != -1; i++) {
3231 HDA_CMD_SET_CONV_STREAM_CHAN(cad, ch->io[i],
3237 hdac_channel_start(struct hdac_softc *sc, struct hdac_chan *ch)
3241 hdac_stream_stop(ch);
3242 hdac_stream_reset(ch);
3244 hdac_stream_setid(ch);
3245 hdac_stream_setup(ch);
3246 hdac_stream_start(ch);
3250 hdac_channel_trigger(kobj_t obj, void *data, int go)
3252 struct hdac_chan *ch = data;
3253 struct hdac_softc *sc = ch->devinfo->codec->sc;
3255 if (!(go == PCMTRIG_START || go == PCMTRIG_STOP || go == PCMTRIG_ABORT))
3261 hdac_channel_start(sc, ch);
3265 hdac_channel_stop(sc, ch);
3276 hdac_channel_getptr(kobj_t obj, void *data)
3278 struct hdac_chan *ch = data;
3279 struct hdac_softc *sc = ch->devinfo->codec->sc;
3283 if (sc->polling != 0)
3285 else if (ch->dmapos != NULL)
3286 ptr = *(ch->dmapos);
3288 ptr = HDAC_READ_4(&sc->mem, ch->off + HDAC_SDLPIB);
3292 * Round to available space and force 128 bytes aligment.
3294 ptr %= ch->blksz * ch->blkcnt;
3295 ptr &= HDA_BLK_ALIGN;
3300 static struct pcmchan_caps *
3301 hdac_channel_getcaps(kobj_t obj, void *data)
3303 return (&((struct hdac_chan *)data)->caps);
3306 static kobj_method_t hdac_channel_methods[] = {
3307 KOBJMETHOD(channel_init, hdac_channel_init),
3308 KOBJMETHOD(channel_free, hdac_channel_free),
3309 KOBJMETHOD(channel_setformat, hdac_channel_setformat),
3310 KOBJMETHOD(channel_setspeed, hdac_channel_setspeed),
3311 KOBJMETHOD(channel_setblocksize, hdac_channel_setblocksize),
3312 KOBJMETHOD(channel_trigger, hdac_channel_trigger),
3313 KOBJMETHOD(channel_getptr, hdac_channel_getptr),
3314 KOBJMETHOD(channel_getcaps, hdac_channel_getcaps),
3317 CHANNEL_DECLARE(hdac_channel);
3320 hdac_jack_poll_callback(void *arg)
3322 struct hdac_devinfo *devinfo = arg;
3323 struct hdac_softc *sc;
3325 if (devinfo == NULL || devinfo->codec == NULL ||
3326 devinfo->codec->sc == NULL)
3328 sc = devinfo->codec->sc;
3330 if (sc->poll_ival == 0) {
3334 hdac_hp_switch_handler(devinfo);
3335 callout_reset(&sc->poll_jack, sc->poll_ival,
3336 hdac_jack_poll_callback, devinfo);
3341 hdac_audio_ctl_ossmixer_init(struct snd_mixer *m)
3343 struct hdac_devinfo *devinfo = mix_getdevinfo(m);
3344 struct hdac_softc *sc = devinfo->codec->sc;
3345 struct hdac_widget *w, *cw;
3346 struct hdac_audio_ctl *ctl;
3347 uint32_t mask, recmask, id;
3348 int i, j, softpcmvol;
3356 id = hdac_codec_id(devinfo);
3357 cad = devinfo->codec->cad;
3358 for (i = 0; i < HDAC_HP_SWITCH_LEN; i++) {
3359 if (!(HDA_DEV_MATCH(hdac_hp_switch[i].model,
3360 sc->pci_subvendor) && hdac_hp_switch[i].id == id))
3362 w = hdac_widget_get(devinfo, hdac_hp_switch[i].hpnid);
3363 if (w == NULL || w->enable == 0 || w->type !=
3364 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
3366 if (hdac_hp_switch[i].polling != 0)
3367 callout_reset(&sc->poll_jack, 1,
3368 hdac_jack_poll_callback, devinfo);
3369 else if (HDA_PARAM_AUDIO_WIDGET_CAP_UNSOL_CAP(w->param.widget_cap))
3371 HDA_CMD_SET_UNSOLICITED_RESPONSE(cad, w->nid,
3372 HDA_CMD_SET_UNSOLICITED_RESPONSE_ENABLE |
3373 HDAC_UNSOLTAG_EVENT_HP), cad);
3376 hdac_hp_switch_handler(devinfo);
3378 device_printf(sc->dev,
3379 "HDA_DEBUG: Enabling headphone/speaker "
3380 "audio routing switching:\n");
3381 device_printf(sc->dev,
3382 "HDA_DEBUG: \tindex=%d nid=%d "
3383 "pci_subvendor=0x%08x "
3384 "codec=0x%08x [%s]\n",
3385 i, w->nid, sc->pci_subvendor, id,
3386 (hdac_hp_switch[i].polling != 0) ? "POLL" :
3391 for (i = 0; i < HDAC_EAPD_SWITCH_LEN; i++) {
3392 if (!(HDA_DEV_MATCH(hdac_eapd_switch[i].model,
3393 sc->pci_subvendor) &&
3394 hdac_eapd_switch[i].id == id))
3396 w = hdac_widget_get(devinfo, hdac_eapd_switch[i].eapdnid);
3397 if (w == NULL || w->enable == 0)
3399 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX ||
3400 w->param.eapdbtl == HDAC_INVALID)
3402 mask |= SOUND_MASK_OGAIN;
3406 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3407 w = hdac_widget_get(devinfo, i);
3408 if (w == NULL || w->enable == 0)
3410 mask |= w->ctlflags;
3411 if (!(w->pflags & HDA_ADC_RECSEL))
3413 for (j = 0; j < w->nconns; j++) {
3414 cw = hdac_widget_get(devinfo, w->conns[j]);
3415 if (cw == NULL || cw->enable == 0)
3417 recmask |= cw->ctlflags;
3421 if (!(mask & SOUND_MASK_PCM)) {
3423 mask |= SOUND_MASK_PCM;
3425 softpcmvol = (devinfo->function.audio.quirks &
3426 HDA_QUIRK_SOFTPCMVOL) ? 1 : 0;
3430 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) {
3431 if (ctl->widget == NULL || ctl->enable == 0)
3433 if (!(ctl->ossmask & SOUND_MASK_PCM))
3439 if (softpcmvol == 1 || ctl == NULL) {
3440 pcm_setflags(sc->dev, pcm_getflags(sc->dev) | SD_F_SOFTPCMVOL);
3442 device_printf(sc->dev,
3443 "HDA_DEBUG: %s Soft PCM volume\n",
3445 "Forcing" : "Enabling");
3449 * XXX Temporary quirk for STAC9220, until the parser
3452 if (id == HDA_CODEC_STAC9220) {
3453 mask |= SOUND_MASK_VOLUME;
3454 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) !=
3456 if (ctl->widget == NULL || ctl->enable == 0)
3458 if (ctl->widget->nid == 11 && ctl->index == 0) {
3459 ctl->ossmask = SOUND_MASK_VOLUME;
3460 ctl->ossval = 100 | (100 << 8);
3462 ctl->ossmask &= ~SOUND_MASK_VOLUME;
3464 } else if (id == HDA_CODEC_STAC9221) {
3465 mask |= SOUND_MASK_VOLUME;
3466 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) !=
3468 if (ctl->widget == NULL)
3470 if (ctl->widget->type ==
3471 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT &&
3472 ctl->index == 0 && (ctl->widget->nid == 2 ||
3473 ctl->widget->enable != 0)) {
3475 ctl->ossmask = SOUND_MASK_VOLUME;
3476 ctl->ossval = 100 | (100 << 8);
3477 } else if (ctl->enable == 0)
3480 ctl->ossmask &= ~SOUND_MASK_VOLUME;
3483 mix_setparentchild(m, SOUND_MIXER_VOLUME,
3485 if (!(mask & SOUND_MASK_VOLUME))
3486 mix_setrealdev(m, SOUND_MIXER_VOLUME,
3488 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) !=
3490 if (ctl->widget == NULL || ctl->enable == 0)
3492 if (!HDA_FLAG_MATCH(ctl->ossmask,
3493 SOUND_MASK_VOLUME | SOUND_MASK_PCM))
3495 if (!(ctl->mute == 1 && ctl->step == 0))
3501 recmask &= ~(SOUND_MASK_PCM | SOUND_MASK_RECLEV | SOUND_MASK_SPEAKER |
3502 SOUND_MASK_BASS | SOUND_MASK_TREBLE | SOUND_MASK_IGAIN |
3504 recmask &= (1 << SOUND_MIXER_NRDEVICES) - 1;
3505 mask &= (1 << SOUND_MIXER_NRDEVICES) - 1;
3507 mix_setrecdevs(m, recmask);
3508 mix_setdevs(m, mask);
3516 hdac_audio_ctl_ossmixer_set(struct snd_mixer *m, unsigned dev,
3517 unsigned left, unsigned right)
3519 struct hdac_devinfo *devinfo = mix_getdevinfo(m);
3520 struct hdac_softc *sc = devinfo->codec->sc;
3521 struct hdac_widget *w;
3522 struct hdac_audio_ctl *ctl;
3524 int lvol, rvol, mlvol, mrvol;
3528 if (dev == SOUND_MIXER_OGAIN) {
3530 /*if (left != right || !(left == 0 || left == 1)) {
3534 id = hdac_codec_id(devinfo);
3535 for (i = 0; i < HDAC_EAPD_SWITCH_LEN; i++) {
3536 if (HDA_DEV_MATCH(hdac_eapd_switch[i].model,
3537 sc->pci_subvendor) &&
3538 hdac_eapd_switch[i].id == id)
3541 if (i >= HDAC_EAPD_SWITCH_LEN) {
3545 w = hdac_widget_get(devinfo, hdac_eapd_switch[i].eapdnid);
3547 w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX ||
3548 w->param.eapdbtl == HDAC_INVALID) {
3552 orig = w->param.eapdbtl;
3554 w->param.eapdbtl &= ~HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
3556 w->param.eapdbtl |= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
3557 if (orig != w->param.eapdbtl) {
3560 if (hdac_eapd_switch[i].hp_switch != 0)
3561 hdac_hp_switch_handler(devinfo);
3562 val = w->param.eapdbtl;
3563 if (devinfo->function.audio.quirks & HDA_QUIRK_EAPDINV)
3564 val ^= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
3566 HDA_CMD_SET_EAPD_BTL_ENABLE(devinfo->codec->cad,
3567 w->nid, val), devinfo->codec->cad);
3570 return (left | (left << 8));
3572 if (dev == SOUND_MIXER_VOLUME)
3573 devinfo->function.audio.mvol = left | (right << 8);
3575 mlvol = devinfo->function.audio.mvol & 0x7f;
3576 mrvol = (devinfo->function.audio.mvol >> 8) & 0x7f;
3581 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) {
3582 if (ctl->widget == NULL || ctl->enable == 0 ||
3583 !(ctl->ossmask & (1 << dev)))
3586 case SOUND_MIXER_VOLUME:
3587 lvol = ((ctl->ossval & 0x7f) * left) / 100;
3588 lvol = (lvol * ctl->step) / 100;
3589 rvol = (((ctl->ossval >> 8) & 0x7f) * right) / 100;
3590 rvol = (rvol * ctl->step) / 100;
3593 if (ctl->ossmask & SOUND_MASK_VOLUME) {
3594 lvol = (left * mlvol) / 100;
3595 lvol = (lvol * ctl->step) / 100;
3596 rvol = (right * mrvol) / 100;
3597 rvol = (rvol * ctl->step) / 100;
3599 lvol = (left * ctl->step) / 100;
3600 rvol = (right * ctl->step) / 100;
3602 ctl->ossval = left | (right << 8);
3606 if (ctl->step < 1) {
3607 mute |= (left == 0) ? HDA_AMP_MUTE_LEFT :
3608 (ctl->muted & HDA_AMP_MUTE_LEFT);
3609 mute |= (right == 0) ? HDA_AMP_MUTE_RIGHT :
3610 (ctl->muted & HDA_AMP_MUTE_RIGHT);
3612 mute |= (lvol == 0) ? HDA_AMP_MUTE_LEFT :
3613 (ctl->muted & HDA_AMP_MUTE_LEFT);
3614 mute |= (rvol == 0) ? HDA_AMP_MUTE_RIGHT :
3615 (ctl->muted & HDA_AMP_MUTE_RIGHT);
3617 hdac_audio_ctl_amp_set(ctl, mute, lvol, rvol);
3621 return (left | (right << 8));
3625 hdac_audio_ctl_ossmixer_setrecsrc(struct snd_mixer *m, uint32_t src)
3627 struct hdac_devinfo *devinfo = mix_getdevinfo(m);
3628 struct hdac_widget *w, *cw;
3629 struct hdac_softc *sc = devinfo->codec->sc;
3630 uint32_t ret = src, target;
3634 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
3635 if (src & (1 << i)) {
3643 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3644 w = hdac_widget_get(devinfo, i);
3645 if (w == NULL || w->enable == 0)
3647 if (!(w->pflags & HDA_ADC_RECSEL))
3649 for (j = 0; j < w->nconns; j++) {
3650 cw = hdac_widget_get(devinfo, w->conns[j]);
3651 if (cw == NULL || cw->enable == 0)
3653 if ((target == SOUND_MASK_VOLUME &&
3655 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) ||
3656 (target != SOUND_MASK_VOLUME &&
3658 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER))
3660 if (cw->ctlflags & target) {
3661 if (!(w->pflags & HDA_ADC_LOCKED))
3662 hdac_widget_connection_select(w, j);
3674 static kobj_method_t hdac_audio_ctl_ossmixer_methods[] = {
3675 KOBJMETHOD(mixer_init, hdac_audio_ctl_ossmixer_init),
3676 KOBJMETHOD(mixer_set, hdac_audio_ctl_ossmixer_set),
3677 KOBJMETHOD(mixer_setrecsrc, hdac_audio_ctl_ossmixer_setrecsrc),
3680 MIXER_DECLARE(hdac_audio_ctl_ossmixer);
3683 hdac_unsolq_task(void *context, int pending)
3685 struct hdac_softc *sc;
3687 sc = (struct hdac_softc *)context;
3690 hdac_unsolq_flush(sc);
3694 /****************************************************************************
3695 * int hdac_attach(device_t)
3697 * Attach the device into the kernel. Interrupts usually won't be enabled
3698 * when this function is called. Setup everything that doesn't require
3699 * interrupts and defer probing of codecs until interrupts are enabled.
3700 ****************************************************************************/
3702 hdac_attach(device_t dev)
3704 struct hdac_softc *sc;
3710 sc = kmalloc(sizeof(*sc), M_DEVBUF, M_WAITOK | M_ZERO);
3711 sc->lock = snd_mtxcreate(device_get_nameunit(dev), HDAC_MTX_NAME);
3713 sc->pci_subvendor = (uint32_t)pci_get_subdevice(sc->dev) << 16;
3714 sc->pci_subvendor |= (uint32_t)pci_get_subvendor(sc->dev) & 0x0000ffff;
3715 vendor = pci_get_vendor(dev);
3717 if (sc->pci_subvendor == HP_NX6325_SUBVENDORX) {
3718 /* Screw nx6325 - subdevice/subvendor swapped */
3719 sc->pci_subvendor = HP_NX6325_SUBVENDOR;
3722 callout_init(&sc->poll_hda);
3723 callout_init(&sc->poll_hdac);
3724 callout_init(&sc->poll_jack);
3726 TASK_INIT(&sc->unsolq_task, 0, hdac_unsolq_task, sc);
3729 sc->poll_ival = HDAC_POLL_INTERVAL;
3730 if (resource_int_value(device_get_name(dev),
3731 device_get_unit(dev), "polling", &i) == 0 && i != 0)
3736 sc->chan_size = pcm_getbuffersize(dev,
3737 HDA_BUFSZ_MIN, HDA_BUFSZ_DEFAULT, HDA_BUFSZ_MAX);
3739 if (resource_int_value(device_get_name(dev),
3740 device_get_unit(dev), "blocksize", &i) == 0 && i > 0) {
3742 if (i < HDA_BLK_MIN)
3744 sc->chan_blkcnt = sc->chan_size / i;
3746 while (sc->chan_blkcnt >> i)
3748 sc->chan_blkcnt = 1 << (i - 1);
3749 if (sc->chan_blkcnt < HDA_BDL_MIN)
3750 sc->chan_blkcnt = HDA_BDL_MIN;
3751 else if (sc->chan_blkcnt > HDA_BDL_MAX)
3752 sc->chan_blkcnt = HDA_BDL_MAX;
3754 sc->chan_blkcnt = HDA_BDL_DEFAULT;
3756 result = bus_dma_tag_create(NULL, /* parent */
3757 HDAC_DMA_ALIGNMENT, /* alignment */
3759 BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
3760 BUS_SPACE_MAXADDR, /* highaddr */
3761 NULL, /* filtfunc */
3762 NULL, /* fistfuncarg */
3763 sc->chan_size, /* maxsize */
3765 sc->chan_size, /* maxsegsz */
3767 &sc->chan_dmat); /* dmat */
3769 device_printf(dev, "%s: bus_dma_tag_create failed (%x)\n",
3771 snd_mtxfree(sc->lock);
3772 kfree(sc, M_DEVBUF);
3778 for (i = 0; i < HDAC_CODEC_MAX; i++)
3779 sc->codecs[i] = NULL;
3781 pci_enable_busmaster(dev);
3783 if (vendor == INTEL_VENDORID) {
3785 v = pci_read_config(dev, 0x44, 1);
3786 pci_write_config(dev, 0x44, v & 0xf8, 1);
3788 device_printf(dev, "TCSEL: 0x%02d -> 0x%02d\n", v,
3789 pci_read_config(dev, 0x44, 1));
3792 #if 0 /* TODO: No MSI support yet in DragonFly. */
3793 if (resource_int_value(device_get_name(dev),
3794 device_get_unit(dev), "msi", &i) == 0 && i != 0 &&
3795 pci_msi_count(dev) == 1)
3796 sc->flags |= HDAC_F_MSI;
3799 sc->flags &= ~HDAC_F_MSI;
3801 #if 0 /* TODO: No uncacheable DMA support in DragonFly. */
3802 sc->flags |= HDAC_F_DMA_NOCACHE;
3804 if (resource_int_value(device_get_name(dev),
3805 device_get_unit(dev), "snoop", &i) == 0 && i != 0) {
3807 sc->flags &= ~HDAC_F_DMA_NOCACHE;
3810 * Try to enable PCIe snoop to avoid messing around with
3811 * uncacheable DMA attribute. Since PCIe snoop register
3812 * config is pretty much vendor specific, there are no
3813 * general solutions on how to enable it, forcing us (even
3814 * Microsoft) to enable uncacheable or write combined DMA
3817 * http://msdn2.microsoft.com/en-us/library/ms790324.aspx
3819 for (i = 0; i < HDAC_PCIESNOOP_LEN; i++) {
3820 if (hdac_pcie_snoop[i].vendor != vendor)
3822 sc->flags &= ~HDAC_F_DMA_NOCACHE;
3823 if (hdac_pcie_snoop[i].reg == 0x00)
3825 v = pci_read_config(dev, hdac_pcie_snoop[i].reg, 1);
3826 if ((v & hdac_pcie_snoop[i].enable) ==
3827 hdac_pcie_snoop[i].enable)
3829 v &= hdac_pcie_snoop[i].mask;
3830 v |= hdac_pcie_snoop[i].enable;
3831 pci_write_config(dev, hdac_pcie_snoop[i].reg, v, 1);
3832 v = pci_read_config(dev, hdac_pcie_snoop[i].reg, 1);
3833 if ((v & hdac_pcie_snoop[i].enable) !=
3834 hdac_pcie_snoop[i].enable) {
3837 "WARNING: Failed to enable PCIe "
3840 #if 0 /* TODO: No uncacheable DMA support in DragonFly. */
3841 sc->flags |= HDAC_F_DMA_NOCACHE;
3846 #if 0 /* TODO: No uncacheable DMA support in DragonFly. */
3851 device_printf(dev, "DMA Coherency: %s / vendor=0x%04x\n",
3852 (sc->flags & HDAC_F_DMA_NOCACHE) ?
3853 "Uncacheable" : "PCIe snoop", vendor);
3856 /* Allocate resources */
3857 result = hdac_mem_alloc(sc);
3859 goto hdac_attach_fail;
3860 result = hdac_irq_alloc(sc);
3862 goto hdac_attach_fail;
3864 /* Get Capabilities */
3865 result = hdac_get_capabilities(sc);
3867 goto hdac_attach_fail;
3869 /* Allocate CORB and RIRB dma memory */
3870 result = hdac_dma_alloc(sc, &sc->corb_dma,
3871 sc->corb_size * sizeof(uint32_t));
3873 goto hdac_attach_fail;
3874 result = hdac_dma_alloc(sc, &sc->rirb_dma,
3875 sc->rirb_size * sizeof(struct hdac_rirb));
3877 goto hdac_attach_fail;
3879 /* Quiesce everything */
3882 /* Initialize the CORB and RIRB */
3886 /* Defer remaining of initialization until interrupts are enabled */
3887 sc->intrhook.ich_func = hdac_attach2;
3888 sc->intrhook.ich_arg = (void *)sc;
3889 if (cold == 0 || config_intrhook_establish(&sc->intrhook) != 0) {
3890 sc->intrhook.ich_func = NULL;
3891 hdac_attach2((void *)sc);
3898 hdac_dma_free(sc, &sc->rirb_dma);
3899 hdac_dma_free(sc, &sc->corb_dma);
3901 snd_mtxfree(sc->lock);
3902 kfree(sc, M_DEVBUF);
3908 hdac_audio_parse(struct hdac_devinfo *devinfo)
3910 struct hdac_softc *sc = devinfo->codec->sc;
3911 struct hdac_widget *w;
3916 cad = devinfo->codec->cad;
3920 HDA_CMD_SET_POWER_STATE(cad, nid, HDA_CMD_POWER_STATE_D0), cad);
3924 res = hdac_command(sc,
3925 HDA_CMD_GET_PARAMETER(cad , nid, HDA_PARAM_SUB_NODE_COUNT), cad);
3927 devinfo->nodecnt = HDA_PARAM_SUB_NODE_COUNT_TOTAL(res);
3928 devinfo->startnode = HDA_PARAM_SUB_NODE_COUNT_START(res);
3929 devinfo->endnode = devinfo->startnode + devinfo->nodecnt;
3931 res = hdac_command(sc,
3932 HDA_CMD_GET_PARAMETER(cad , nid, HDA_PARAM_GPIO_COUNT), cad);
3933 devinfo->function.audio.gpio = res;
3936 device_printf(sc->dev, " Vendor: 0x%08x\n",
3937 devinfo->vendor_id);
3938 device_printf(sc->dev, " Device: 0x%08x\n",
3939 devinfo->device_id);
3940 device_printf(sc->dev, " Revision: 0x%08x\n",
3941 devinfo->revision_id);
3942 device_printf(sc->dev, " Stepping: 0x%08x\n",
3943 devinfo->stepping_id);
3944 device_printf(sc->dev, "PCI Subvendor: 0x%08x\n",
3946 device_printf(sc->dev, " Nodes: start=%d "
3947 "endnode=%d total=%d\n",
3948 devinfo->startnode, devinfo->endnode, devinfo->nodecnt);
3949 device_printf(sc->dev, " CORB size: %d\n", sc->corb_size);
3950 device_printf(sc->dev, " RIRB size: %d\n", sc->rirb_size);
3951 device_printf(sc->dev, " Streams: ISS=%d OSS=%d BSS=%d\n",
3952 sc->num_iss, sc->num_oss, sc->num_bss);
3953 device_printf(sc->dev, " GPIO: 0x%08x\n",
3954 devinfo->function.audio.gpio);
3955 device_printf(sc->dev, " NumGPIO=%d NumGPO=%d "
3956 "NumGPI=%d GPIWake=%d GPIUnsol=%d\n",
3957 HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->function.audio.gpio),
3958 HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->function.audio.gpio),
3959 HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->function.audio.gpio),
3960 HDA_PARAM_GPIO_COUNT_GPI_WAKE(devinfo->function.audio.gpio),
3961 HDA_PARAM_GPIO_COUNT_GPI_UNSOL(devinfo->function.audio.gpio));
3964 res = hdac_command(sc,
3965 HDA_CMD_GET_PARAMETER(cad, nid, HDA_PARAM_SUPP_STREAM_FORMATS),
3967 devinfo->function.audio.supp_stream_formats = res;
3969 res = hdac_command(sc,
3970 HDA_CMD_GET_PARAMETER(cad, nid, HDA_PARAM_SUPP_PCM_SIZE_RATE),
3972 devinfo->function.audio.supp_pcm_size_rate = res;
3974 res = hdac_command(sc,
3975 HDA_CMD_GET_PARAMETER(cad, nid, HDA_PARAM_OUTPUT_AMP_CAP),
3977 devinfo->function.audio.outamp_cap = res;
3979 res = hdac_command(sc,
3980 HDA_CMD_GET_PARAMETER(cad, nid, HDA_PARAM_INPUT_AMP_CAP),
3982 devinfo->function.audio.inamp_cap = res;
3984 if (devinfo->nodecnt > 0)
3985 devinfo->widget = (struct hdac_widget *)kmalloc(
3986 sizeof(*(devinfo->widget)) * devinfo->nodecnt, M_HDAC,
3989 devinfo->widget = NULL;
3991 if (devinfo->widget == NULL) {
3992 device_printf(sc->dev, "unable to allocate widgets!\n");
3993 devinfo->endnode = devinfo->startnode;
3994 devinfo->nodecnt = 0;
3998 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
3999 w = hdac_widget_get(devinfo, i);
4001 device_printf(sc->dev, "Ghost widget! nid=%d!\n", i);
4003 w->devinfo = devinfo;
4009 w->param.eapdbtl = HDAC_INVALID;
4010 hdac_widget_parse(w);
4016 hdac_audio_ctl_parse(struct hdac_devinfo *devinfo)
4018 struct hdac_softc *sc = devinfo->codec->sc;
4019 struct hdac_audio_ctl *ctls;
4020 struct hdac_widget *w, *cw;
4021 int i, j, cnt, max, ocap, icap;
4022 int mute, offset, step, size;
4024 /* XXX This is redundant */
4026 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4027 w = hdac_widget_get(devinfo, i);
4028 if (w == NULL || w->enable == 0)
4030 if (w->param.outamp_cap != 0)
4032 if (w->param.inamp_cap != 0) {
4034 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR:
4035 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER:
4036 for (j = 0; j < w->nconns; j++) {
4037 cw = hdac_widget_get(devinfo,
4039 if (cw == NULL || cw->enable == 0)
4051 devinfo->function.audio.ctlcnt = max;
4056 ctls = (struct hdac_audio_ctl *)kmalloc(
4057 sizeof(*ctls) * max, M_HDAC, M_ZERO | M_NOWAIT);
4061 device_printf(sc->dev, "unable to allocate ctls!\n");
4062 devinfo->function.audio.ctlcnt = 0;
4067 for (i = devinfo->startnode; cnt < max && i < devinfo->endnode; i++) {
4069 device_printf(sc->dev, "%s: Ctl overflow!\n",
4073 w = hdac_widget_get(devinfo, i);
4074 if (w == NULL || w->enable == 0)
4076 ocap = w->param.outamp_cap;
4077 icap = w->param.inamp_cap;
4079 mute = HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(ocap);
4080 step = HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(ocap);
4081 size = HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(ocap);
4082 offset = HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(ocap);
4083 /*if (offset > step) {
4085 device_printf(sc->dev,
4086 "HDA_DEBUG: BUGGY outamp: nid=%d "
4087 "[offset=%d > step=%d]\n",
4088 w->nid, offset, step);
4092 ctls[cnt].enable = 1;
4093 ctls[cnt].widget = w;
4094 ctls[cnt].mute = mute;
4095 ctls[cnt].step = step;
4096 ctls[cnt].size = size;
4097 ctls[cnt].offset = offset;
4098 ctls[cnt].left = offset;
4099 ctls[cnt].right = offset;
4100 ctls[cnt++].dir = HDA_CTL_OUT;
4104 mute = HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(icap);
4105 step = HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(icap);
4106 size = HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(icap);
4107 offset = HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(icap);
4108 /*if (offset > step) {
4110 device_printf(sc->dev,
4111 "HDA_DEBUG: BUGGY inamp: nid=%d "
4112 "[offset=%d > step=%d]\n",
4113 w->nid, offset, step);
4118 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR:
4119 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER:
4120 for (j = 0; j < w->nconns; j++) {
4122 device_printf(sc->dev,
4123 "%s: Ctl overflow!\n",
4127 cw = hdac_widget_get(devinfo,
4129 if (cw == NULL || cw->enable == 0)
4131 ctls[cnt].enable = 1;
4132 ctls[cnt].widget = w;
4133 ctls[cnt].childwidget = cw;
4134 ctls[cnt].index = j;
4135 ctls[cnt].mute = mute;
4136 ctls[cnt].step = step;
4137 ctls[cnt].size = size;
4138 ctls[cnt].offset = offset;
4139 ctls[cnt].left = offset;
4140 ctls[cnt].right = offset;
4141 ctls[cnt++].dir = HDA_CTL_IN;
4146 device_printf(sc->dev,
4147 "%s: Ctl overflow!\n",
4151 ctls[cnt].enable = 1;
4152 ctls[cnt].widget = w;
4153 ctls[cnt].mute = mute;
4154 ctls[cnt].step = step;
4155 ctls[cnt].size = size;
4156 ctls[cnt].offset = offset;
4157 ctls[cnt].left = offset;
4158 ctls[cnt].right = offset;
4159 ctls[cnt++].dir = HDA_CTL_IN;
4165 devinfo->function.audio.ctl = ctls;
4168 static const struct {
4171 uint32_t set, unset;
4174 * XXX Force stereo quirk. Monoural recording / playback
4175 * on few codecs (especially ALC880) seems broken or
4176 * perhaps unsupported.
4178 { HDA_MATCH_ALL, HDA_MATCH_ALL,
4179 HDA_QUIRK_FORCESTEREO | HDA_QUIRK_IVREF, 0 },
4180 { ACER_ALL_SUBVENDOR, HDA_MATCH_ALL,
4181 HDA_QUIRK_GPIO0, 0 },
4182 { ASUS_M5200_SUBVENDOR, HDA_CODEC_ALC880,
4183 HDA_QUIRK_GPIO0, 0 },
4184 { ASUS_A7M_SUBVENDOR, HDA_CODEC_ALC880,
4185 HDA_QUIRK_GPIO0, 0 },
4186 { ASUS_A7T_SUBVENDOR, HDA_CODEC_ALC882,
4187 HDA_QUIRK_GPIO0, 0 },
4188 { ASUS_W2J_SUBVENDOR, HDA_CODEC_ALC882,
4189 HDA_QUIRK_GPIO0, 0 },
4190 { ASUS_U5F_SUBVENDOR, HDA_CODEC_AD1986A,
4191 HDA_QUIRK_EAPDINV, 0 },
4192 { ASUS_A8JC_SUBVENDOR, HDA_CODEC_AD1986A,
4193 HDA_QUIRK_EAPDINV, 0 },
4194 { ASUS_F3JC_SUBVENDOR, HDA_CODEC_ALC861,
4195 HDA_QUIRK_OVREF, 0 },
4196 { ASUS_W6F_SUBVENDOR, HDA_CODEC_ALC861,
4197 HDA_QUIRK_OVREF, 0 },
4198 { UNIWILL_9075_SUBVENDOR, HDA_CODEC_ALC861,
4199 HDA_QUIRK_OVREF, 0 },
4200 /*{ ASUS_M2N_SUBVENDOR, HDA_CODEC_AD1988,
4201 HDA_QUIRK_IVREF80, HDA_QUIRK_IVREF50 | HDA_QUIRK_IVREF100 },*/
4202 { MEDION_MD95257_SUBVENDOR, HDA_CODEC_ALC880,
4203 HDA_QUIRK_GPIO1, 0 },
4204 { LENOVO_3KN100_SUBVENDOR, HDA_CODEC_AD1986A,
4205 HDA_QUIRK_EAPDINV, 0 },
4206 { SAMSUNG_Q1_SUBVENDOR, HDA_CODEC_AD1986A,
4207 HDA_QUIRK_EAPDINV, 0 },
4208 { APPLE_INTEL_MAC, HDA_CODEC_STAC9221,
4209 HDA_QUIRK_GPIO0 | HDA_QUIRK_GPIO1, 0 },
4210 { HDA_MATCH_ALL, HDA_CODEC_AD1988,
4211 HDA_QUIRK_IVREF80, HDA_QUIRK_IVREF50 | HDA_QUIRK_IVREF100 },
4212 { HDA_MATCH_ALL, HDA_CODEC_AD1988B,
4213 HDA_QUIRK_IVREF80, HDA_QUIRK_IVREF50 | HDA_QUIRK_IVREF100 },
4214 { HDA_MATCH_ALL, HDA_CODEC_CXVENICE,
4215 0, HDA_QUIRK_FORCESTEREO },
4216 { HDA_MATCH_ALL, HDA_CODEC_STACXXXX,
4217 HDA_QUIRK_SOFTPCMVOL, 0 }
4219 #define HDAC_QUIRKS_LEN (sizeof(hdac_quirks) / sizeof(hdac_quirks[0]))
4222 hdac_vendor_patch_parse(struct hdac_devinfo *devinfo)
4224 struct hdac_widget *w;
4225 struct hdac_audio_ctl *ctl;
4226 uint32_t id, subvendor;
4229 id = hdac_codec_id(devinfo);
4230 subvendor = devinfo->codec->sc->pci_subvendor;
4235 for (i = 0; i < HDAC_QUIRKS_LEN; i++) {
4236 if (!(HDA_DEV_MATCH(hdac_quirks[i].model, subvendor) &&
4237 HDA_DEV_MATCH(hdac_quirks[i].id, id)))
4239 if (hdac_quirks[i].set != 0)
4240 devinfo->function.audio.quirks |=
4242 if (hdac_quirks[i].unset != 0)
4243 devinfo->function.audio.quirks &=
4244 ~(hdac_quirks[i].unset);
4248 case HDA_CODEC_ALC260:
4249 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4250 w = hdac_widget_get(devinfo, i);
4251 if (w == NULL || w->enable == 0)
4254 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT)
4259 if (subvendor == HP_XW4300_SUBVENDOR) {
4260 ctl = hdac_audio_ctl_amp_get(devinfo, 16, 0, 1);
4261 if (ctl != NULL && ctl->widget != NULL) {
4262 ctl->ossmask = SOUND_MASK_SPEAKER;
4263 ctl->widget->ctlflags |= SOUND_MASK_SPEAKER;
4265 ctl = hdac_audio_ctl_amp_get(devinfo, 17, 0, 1);
4266 if (ctl != NULL && ctl->widget != NULL) {
4267 ctl->ossmask = SOUND_MASK_SPEAKER;
4268 ctl->widget->ctlflags |= SOUND_MASK_SPEAKER;
4270 } else if (subvendor == HP_3010_SUBVENDOR) {
4271 ctl = hdac_audio_ctl_amp_get(devinfo, 17, 0, 1);
4272 if (ctl != NULL && ctl->widget != NULL) {
4273 ctl->ossmask = SOUND_MASK_SPEAKER;
4274 ctl->widget->ctlflags |= SOUND_MASK_SPEAKER;
4276 ctl = hdac_audio_ctl_amp_get(devinfo, 21, 0, 1);
4277 if (ctl != NULL && ctl->widget != NULL) {
4278 ctl->ossmask = SOUND_MASK_SPEAKER;
4279 ctl->widget->ctlflags |= SOUND_MASK_SPEAKER;
4283 case HDA_CODEC_ALC262:
4284 if (subvendor == HP_DC7700_SUBVENDOR) {
4285 ctl = hdac_audio_ctl_amp_get(devinfo, 22, 0, 1);
4286 if (ctl != NULL && ctl->widget != NULL) {
4287 ctl->ossmask = SOUND_MASK_SPEAKER;
4288 ctl->widget->ctlflags |= SOUND_MASK_SPEAKER;
4290 ctl = hdac_audio_ctl_amp_get(devinfo, 27, 0, 1);
4291 if (ctl != NULL && ctl->widget != NULL) {
4292 ctl->ossmask = SOUND_MASK_SPEAKER;
4293 ctl->widget->ctlflags |= SOUND_MASK_SPEAKER;
4297 case HDA_CODEC_ALC861:
4298 ctl = hdac_audio_ctl_amp_get(devinfo, 21, 2, 1);
4300 ctl->muted = HDA_AMP_MUTE_ALL;
4302 case HDA_CODEC_ALC880:
4303 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4304 w = hdac_widget_get(devinfo, i);
4305 if (w == NULL || w->enable == 0)
4308 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT &&
4309 w->nid != 9 && w->nid != 29) {
4311 } else if (w->type !=
4312 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET &&
4315 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET;
4316 w->param.widget_cap &=
4317 ~HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_MASK;
4318 w->param.widget_cap |=
4319 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET <<
4320 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_SHIFT;
4321 strlcpy(w->name, "beep widget", sizeof(w->name));
4325 case HDA_CODEC_ALC883:
4327 * nid: 24/25 = External (jack) or Internal (fixed) Mic.
4328 * Clear vref cap for jack connectivity.
4330 w = hdac_widget_get(devinfo, 24);
4331 if (w != NULL && w->enable != 0 && w->type ==
4332 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
4333 (w->wclass.pin.config &
4334 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK) ==
4335 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_JACK)
4336 w->wclass.pin.cap &= ~(
4337 HDA_PARAM_PIN_CAP_VREF_CTRL_100_MASK |
4338 HDA_PARAM_PIN_CAP_VREF_CTRL_80_MASK |
4339 HDA_PARAM_PIN_CAP_VREF_CTRL_50_MASK);
4340 w = hdac_widget_get(devinfo, 25);
4341 if (w != NULL && w->enable != 0 && w->type ==
4342 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
4343 (w->wclass.pin.config &
4344 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK) ==
4345 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_JACK)
4346 w->wclass.pin.cap &= ~(
4347 HDA_PARAM_PIN_CAP_VREF_CTRL_100_MASK |
4348 HDA_PARAM_PIN_CAP_VREF_CTRL_80_MASK |
4349 HDA_PARAM_PIN_CAP_VREF_CTRL_50_MASK);
4351 * nid: 26 = Line-in, leave it alone.
4354 case HDA_CODEC_AD1981HD:
4355 w = hdac_widget_get(devinfo, 11);
4356 if (w != NULL && w->enable != 0 && w->nconns > 3)
4358 if (subvendor == IBM_M52_SUBVENDOR) {
4359 ctl = hdac_audio_ctl_amp_get(devinfo, 7, 0, 1);
4361 ctl->ossmask = SOUND_MASK_SPEAKER;
4364 case HDA_CODEC_AD1986A:
4365 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4366 w = hdac_widget_get(devinfo, i);
4367 if (w == NULL || w->enable == 0)
4370 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT)
4375 if (subvendor == ASUS_M2NPVMX_SUBVENDOR ||
4376 subvendor == ASUS_A8NVMCSM_SUBVENDOR) {
4377 /* nid 28 is mic, nid 29 is line-in */
4378 w = hdac_widget_get(devinfo, 15);
4381 w = hdac_widget_get(devinfo, 16);
4386 case HDA_CODEC_AD1988:
4387 case HDA_CODEC_AD1988B:
4388 /*w = hdac_widget_get(devinfo, 12);
4391 w->pflags |= HDA_ADC_LOCKED;
4393 w = hdac_widget_get(devinfo, 13);
4396 w->pflags |= HDA_ADC_LOCKED;
4398 w = hdac_widget_get(devinfo, 14);
4401 w->pflags |= HDA_ADC_LOCKED;
4403 ctl = hdac_audio_ctl_amp_get(devinfo, 57, 0, 1);
4405 ctl->ossmask = SOUND_MASK_IGAIN;
4406 ctl->widget->ctlflags |= SOUND_MASK_IGAIN;
4408 ctl = hdac_audio_ctl_amp_get(devinfo, 58, 0, 1);
4410 ctl->ossmask = SOUND_MASK_IGAIN;
4411 ctl->widget->ctlflags |= SOUND_MASK_IGAIN;
4413 ctl = hdac_audio_ctl_amp_get(devinfo, 60, 0, 1);
4415 ctl->ossmask = SOUND_MASK_IGAIN;
4416 ctl->widget->ctlflags |= SOUND_MASK_IGAIN;
4418 ctl = hdac_audio_ctl_amp_get(devinfo, 32, 0, 1);
4420 ctl->ossmask = SOUND_MASK_MIC | SOUND_MASK_VOLUME;
4421 ctl->widget->ctlflags |= SOUND_MASK_MIC;
4423 ctl = hdac_audio_ctl_amp_get(devinfo, 32, 4, 1);
4425 ctl->ossmask = SOUND_MASK_MIC | SOUND_MASK_VOLUME;
4426 ctl->widget->ctlflags |= SOUND_MASK_MIC;
4428 ctl = hdac_audio_ctl_amp_get(devinfo, 32, 1, 1);
4430 ctl->ossmask = SOUND_MASK_LINE | SOUND_MASK_VOLUME;
4431 ctl->widget->ctlflags |= SOUND_MASK_LINE;
4433 ctl = hdac_audio_ctl_amp_get(devinfo, 32, 7, 1);
4435 ctl->ossmask = SOUND_MASK_SPEAKER | SOUND_MASK_VOLUME;
4436 ctl->widget->ctlflags |= SOUND_MASK_SPEAKER;
4439 case HDA_CODEC_STAC9221:
4441 * Dell XPS M1210 need all DACs for each output jacks
4443 if (subvendor == DELL_XPSM1210_SUBVENDOR)
4445 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4446 w = hdac_widget_get(devinfo, i);
4447 if (w == NULL || w->enable == 0)
4450 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT)
4456 case HDA_CODEC_STAC9221D:
4457 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4458 w = hdac_widget_get(devinfo, i);
4459 if (w == NULL || w->enable == 0)
4462 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT &&
4468 case HDA_CODEC_STAC9227:
4469 w = hdac_widget_get(devinfo, 8);
4472 w = hdac_widget_get(devinfo, 9);
4476 case HDA_CODEC_CXWAIKIKI:
4477 if (subvendor == HP_DV5000_SUBVENDOR) {
4478 w = hdac_widget_get(devinfo, 27);
4482 ctl = hdac_audio_ctl_amp_get(devinfo, 16, 0, 1);
4484 ctl->ossmask = SOUND_MASK_SKIP;
4485 ctl = hdac_audio_ctl_amp_get(devinfo, 25, 0, 1);
4486 if (ctl != NULL && ctl->childwidget != NULL &&
4487 ctl->childwidget->enable != 0) {
4488 ctl->ossmask = SOUND_MASK_PCM | SOUND_MASK_VOLUME;
4489 ctl->childwidget->ctlflags |= SOUND_MASK_PCM;
4491 ctl = hdac_audio_ctl_amp_get(devinfo, 25, 1, 1);
4492 if (ctl != NULL && ctl->childwidget != NULL &&
4493 ctl->childwidget->enable != 0) {
4494 ctl->ossmask = SOUND_MASK_LINE | SOUND_MASK_VOLUME;
4495 ctl->childwidget->ctlflags |= SOUND_MASK_LINE;
4497 ctl = hdac_audio_ctl_amp_get(devinfo, 25, 2, 1);
4498 if (ctl != NULL && ctl->childwidget != NULL &&
4499 ctl->childwidget->enable != 0) {
4500 ctl->ossmask = SOUND_MASK_MIC | SOUND_MASK_VOLUME;
4501 ctl->childwidget->ctlflags |= SOUND_MASK_MIC;
4503 ctl = hdac_audio_ctl_amp_get(devinfo, 26, 0, 1);
4505 ctl->ossmask = SOUND_MASK_SKIP;
4506 /* XXX mixer \=rec mic broken.. why?!? */
4507 /* ctl->widget->ctlflags |= SOUND_MASK_MIC; */
4516 hdac_audio_ctl_ossmixer_getnextdev(struct hdac_devinfo *devinfo)
4518 int *dev = &devinfo->function.audio.ossidx;
4520 while (*dev < SOUND_MIXER_NRDEVICES) {
4522 case SOUND_MIXER_VOLUME:
4523 case SOUND_MIXER_BASS:
4524 case SOUND_MIXER_TREBLE:
4525 case SOUND_MIXER_PCM:
4526 case SOUND_MIXER_SPEAKER:
4527 case SOUND_MIXER_LINE:
4528 case SOUND_MIXER_MIC:
4529 case SOUND_MIXER_CD:
4530 case SOUND_MIXER_RECLEV:
4531 case SOUND_MIXER_IGAIN:
4532 case SOUND_MIXER_OGAIN: /* reserved for EAPD switch */
4545 hdac_widget_find_dac_path(struct hdac_devinfo *devinfo, nid_t nid, int depth)
4547 struct hdac_widget *w;
4550 if (depth > HDA_PARSE_MAXDEPTH)
4552 w = hdac_widget_get(devinfo, nid);
4553 if (w == NULL || w->enable == 0)
4556 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT:
4557 w->pflags |= HDA_DAC_PATH;
4560 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER:
4561 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR:
4562 for (i = 0; i < w->nconns; i++) {
4563 if (hdac_widget_find_dac_path(devinfo,
4564 w->conns[i], depth + 1) != 0) {
4565 if (w->selconn == -1)
4568 w->pflags |= HDA_DAC_PATH;
4579 hdac_widget_find_adc_path(struct hdac_devinfo *devinfo, nid_t nid, int depth)
4581 struct hdac_widget *w;
4582 int i, conndev, ret = 0;
4584 if (depth > HDA_PARSE_MAXDEPTH)
4586 w = hdac_widget_get(devinfo, nid);
4587 if (w == NULL || w->enable == 0)
4590 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT:
4591 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR:
4592 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER:
4593 for (i = 0; i < w->nconns; i++) {
4594 if (hdac_widget_find_adc_path(devinfo, w->conns[i],
4596 if (w->selconn == -1)
4598 w->pflags |= HDA_ADC_PATH;
4603 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX:
4604 conndev = w->wclass.pin.config &
4605 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
4606 if (HDA_PARAM_PIN_CAP_INPUT_CAP(w->wclass.pin.cap) &&
4607 (conndev == HDA_CONFIG_DEFAULTCONF_DEVICE_CD ||
4608 conndev == HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN ||
4609 conndev == HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN)) {
4610 w->pflags |= HDA_ADC_PATH;
4614 /*case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER:
4615 if (w->pflags & HDA_DAC_PATH) {
4616 w->pflags |= HDA_ADC_PATH;
4627 hdac_audio_ctl_outamp_build(struct hdac_devinfo *devinfo,
4628 nid_t nid, nid_t pnid, int index, int depth)
4630 struct hdac_widget *w, *pw;
4631 struct hdac_audio_ctl *ctl;
4633 int i, ossdev, conndev, strategy;
4635 if (depth > HDA_PARSE_MAXDEPTH)
4638 w = hdac_widget_get(devinfo, nid);
4639 if (w == NULL || w->enable == 0)
4642 pw = hdac_widget_get(devinfo, pnid);
4643 strategy = devinfo->function.audio.parsing_strategy;
4645 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER
4646 || w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR) {
4647 for (i = 0; i < w->nconns; i++) {
4648 fl |= hdac_audio_ctl_outamp_build(devinfo, w->conns[i],
4649 w->nid, i, depth + 1);
4653 } else if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT &&
4654 (w->pflags & HDA_DAC_PATH)) {
4656 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) {
4657 if (ctl->enable == 0 || ctl->widget == NULL)
4659 /* XXX This should be compressed! */
4660 if (((ctl->widget->nid == w->nid) ||
4661 (ctl->widget->nid == pnid && ctl->index == index &&
4662 (ctl->dir & HDA_CTL_IN)) ||
4663 (ctl->widget->nid == pnid && pw != NULL &&
4665 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR &&
4666 (pw->nconns < 2 || pw->selconn == index ||
4667 pw->selconn == -1) &&
4668 (ctl->dir & HDA_CTL_OUT)) ||
4669 (strategy == HDA_PARSE_DIRECT &&
4670 ctl->widget->nid == w->nid)) &&
4671 !(ctl->ossmask & ~SOUND_MASK_VOLUME)) {
4672 /*if (pw != NULL && pw->selconn == -1)
4673 pw->selconn = index;
4674 fl |= SOUND_MASK_VOLUME;
4675 fl |= SOUND_MASK_PCM;
4676 ctl->ossmask |= SOUND_MASK_VOLUME;
4677 ctl->ossmask |= SOUND_MASK_PCM;
4678 ctl->ossdev = SOUND_MIXER_PCM;*/
4679 if (!(w->ctlflags & SOUND_MASK_PCM) ||
4681 !(pw->ctlflags & SOUND_MASK_PCM))) {
4682 fl |= SOUND_MASK_VOLUME;
4683 fl |= SOUND_MASK_PCM;
4684 ctl->ossmask |= SOUND_MASK_VOLUME;
4685 ctl->ossmask |= SOUND_MASK_PCM;
4686 ctl->ossdev = SOUND_MIXER_PCM;
4687 w->ctlflags |= SOUND_MASK_VOLUME;
4688 w->ctlflags |= SOUND_MASK_PCM;
4690 if (pw->selconn == -1)
4691 pw->selconn = index;
4702 } else if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
4703 HDA_PARAM_PIN_CAP_INPUT_CAP(w->wclass.pin.cap) &&
4704 (w->pflags & HDA_ADC_PATH)) {
4705 conndev = w->wclass.pin.config &
4706 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
4708 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) {
4709 if (ctl->enable == 0 || ctl->widget == NULL)
4711 /* XXX This should be compressed! */
4712 if (((ctl->widget->nid == pnid && ctl->index == index &&
4713 (ctl->dir & HDA_CTL_IN)) ||
4714 (ctl->widget->nid == pnid && pw != NULL &&
4716 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR &&
4717 (pw->nconns < 2 || pw->selconn == index ||
4718 pw->selconn == -1) &&
4719 (ctl->dir & HDA_CTL_OUT)) ||
4720 (strategy == HDA_PARSE_DIRECT &&
4721 ctl->widget->nid == w->nid)) &&
4722 !(ctl->ossmask & ~SOUND_MASK_VOLUME)) {
4723 if (pw != NULL && pw->selconn == -1)
4724 pw->selconn = index;
4727 case HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN:
4728 ossdev = SOUND_MIXER_MIC;
4730 case HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN:
4731 ossdev = SOUND_MIXER_LINE;
4733 case HDA_CONFIG_DEFAULTCONF_DEVICE_CD:
4734 ossdev = SOUND_MIXER_CD;
4738 hdac_audio_ctl_ossmixer_getnextdev(
4744 if (strategy == HDA_PARSE_MIXER) {
4745 fl |= SOUND_MASK_VOLUME;
4746 ctl->ossmask |= SOUND_MASK_VOLUME;
4749 ctl->ossmask |= 1 << ossdev;
4750 ctl->ossdev = ossdev;
4755 } else if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET) {
4757 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) {
4758 if (ctl->enable == 0 || ctl->widget == NULL)
4760 /* XXX This should be compressed! */
4761 if (((ctl->widget->nid == pnid && ctl->index == index &&
4762 (ctl->dir & HDA_CTL_IN)) ||
4763 (ctl->widget->nid == pnid && pw != NULL &&
4765 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR &&
4766 (pw->nconns < 2 || pw->selconn == index ||
4767 pw->selconn == -1) &&
4768 (ctl->dir & HDA_CTL_OUT)) ||
4769 (strategy == HDA_PARSE_DIRECT &&
4770 ctl->widget->nid == w->nid)) &&
4771 !(ctl->ossmask & ~SOUND_MASK_VOLUME)) {
4772 if (pw != NULL && pw->selconn == -1)
4773 pw->selconn = index;
4774 fl |= SOUND_MASK_VOLUME;
4775 fl |= SOUND_MASK_SPEAKER;
4776 ctl->ossmask |= SOUND_MASK_VOLUME;
4777 ctl->ossmask |= SOUND_MASK_SPEAKER;
4778 ctl->ossdev = SOUND_MIXER_SPEAKER;
4788 hdac_audio_ctl_inamp_build(struct hdac_devinfo *devinfo, nid_t nid, int depth)
4790 struct hdac_widget *w, *cw;
4791 struct hdac_audio_ctl *ctl;
4795 if (depth > HDA_PARSE_MAXDEPTH)
4798 w = hdac_widget_get(devinfo, nid);
4799 if (w == NULL || w->enable == 0)
4801 /*if (!(w->pflags & HDA_ADC_PATH))
4803 if (!(w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT ||
4804 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR))
4807 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) {
4808 if (ctl->enable == 0 || ctl->widget == NULL)
4810 if (ctl->widget->nid == nid) {
4811 ctl->ossmask |= SOUND_MASK_RECLEV;
4812 w->ctlflags |= SOUND_MASK_RECLEV;
4813 return (SOUND_MASK_RECLEV);
4816 for (i = 0; i < w->nconns; i++) {
4817 cw = hdac_widget_get(devinfo, w->conns[i]);
4818 if (cw == NULL || cw->enable == 0)
4820 if (cw->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR)
4822 fl = hdac_audio_ctl_inamp_build(devinfo, cw->nid, depth + 1);
4833 hdac_audio_ctl_recsel_build(struct hdac_devinfo *devinfo, nid_t nid, int depth)
4835 struct hdac_widget *w, *cw;
4838 if (depth > HDA_PARSE_MAXDEPTH)
4841 w = hdac_widget_get(devinfo, nid);
4842 if (w == NULL || w->enable == 0)
4844 /*if (!(w->pflags & HDA_ADC_PATH))
4846 if (!(w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT ||
4847 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR))
4850 for (i = 0; i < w->nconns; i++) {
4851 cw = hdac_widget_get(devinfo, w->conns[i]);
4855 w->pflags |= HDA_ADC_RECSEL;
4859 for (i = 0; i < w->nconns; i++) {
4860 if (hdac_audio_ctl_recsel_build(devinfo,
4861 w->conns[i], depth + 1) != 0)
4868 hdac_audio_build_tree_strategy(struct hdac_devinfo *devinfo)
4870 struct hdac_widget *w, *cw;
4871 int i, j, conndev, found_dac = 0;
4874 strategy = devinfo->function.audio.parsing_strategy;
4876 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4877 w = hdac_widget_get(devinfo, i);
4878 if (w == NULL || w->enable == 0)
4880 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
4882 if (!HDA_PARAM_PIN_CAP_OUTPUT_CAP(w->wclass.pin.cap))
4884 conndev = w->wclass.pin.config &
4885 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK;
4886 if (!(conndev == HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT ||
4887 conndev == HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER ||
4888 conndev == HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_OUT))
4890 for (j = 0; j < w->nconns; j++) {
4891 cw = hdac_widget_get(devinfo, w->conns[j]);
4892 if (cw == NULL || cw->enable == 0)
4894 if (strategy == HDA_PARSE_MIXER && !(cw->type ==
4895 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER ||
4897 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR))
4899 if (hdac_widget_find_dac_path(devinfo, cw->nid, 0)
4901 if (w->selconn == -1)
4903 w->pflags |= HDA_DAC_PATH;
4913 hdac_audio_build_tree(struct hdac_devinfo *devinfo)
4915 struct hdac_widget *w;
4916 struct hdac_audio_ctl *ctl;
4917 int i, j, dacs, strategy;
4919 /* Construct DAC path */
4920 strategy = HDA_PARSE_MIXER;
4921 devinfo->function.audio.parsing_strategy = strategy;
4923 device_printf(devinfo->codec->sc->dev,
4924 "HDA_DEBUG: HWiP: HDA Widget Parser - Revision %d\n",
4925 HDA_WIDGET_PARSER_REV);
4927 dacs = hdac_audio_build_tree_strategy(devinfo);
4930 device_printf(devinfo->codec->sc->dev,
4931 "HDA_DEBUG: HWiP: 0 DAC path found! "
4933 "using HDA_PARSE_DIRECT strategy.\n");
4935 strategy = HDA_PARSE_DIRECT;
4936 devinfo->function.audio.parsing_strategy = strategy;
4937 dacs = hdac_audio_build_tree_strategy(devinfo);
4941 device_printf(devinfo->codec->sc->dev,
4942 "HDA_DEBUG: HWiP: Found %d DAC path using HDA_PARSE_%s "
4944 dacs, (strategy == HDA_PARSE_MIXER) ? "MIXER" : "DIRECT");
4947 /* Construct ADC path */
4948 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4949 w = hdac_widget_get(devinfo, i);
4950 if (w == NULL || w->enable == 0)
4952 if (w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT)
4954 (void)hdac_widget_find_adc_path(devinfo, w->nid, 0);
4958 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4959 w = hdac_widget_get(devinfo, i);
4960 if (w == NULL || w->enable == 0)
4962 if ((strategy == HDA_PARSE_MIXER &&
4963 (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER ||
4964 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR)
4965 && (w->pflags & HDA_DAC_PATH)) ||
4966 (strategy == HDA_PARSE_DIRECT && (w->pflags &
4967 (HDA_DAC_PATH | HDA_ADC_PATH)))) {
4968 w->ctlflags |= hdac_audio_ctl_outamp_build(devinfo,
4969 w->nid, devinfo->startnode - 1, 0, 0);
4970 } else if (w->type ==
4971 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET) {
4973 while ((ctl = hdac_audio_ctl_each(devinfo, &j)) !=
4975 if (ctl->enable == 0 || ctl->widget == NULL)
4977 if (ctl->widget->nid != w->nid)
4979 ctl->ossmask |= SOUND_MASK_VOLUME;
4980 ctl->ossmask |= SOUND_MASK_SPEAKER;
4981 ctl->ossdev = SOUND_MIXER_SPEAKER;
4982 w->ctlflags |= SOUND_MASK_VOLUME;
4983 w->ctlflags |= SOUND_MASK_SPEAKER;
4988 /* Input mixers (rec) */
4989 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
4990 w = hdac_widget_get(devinfo, i);
4991 if (w == NULL || w->enable == 0)
4993 if (!(w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT &&
4994 w->pflags & HDA_ADC_PATH))
4996 hdac_audio_ctl_inamp_build(devinfo, w->nid, 0);
4997 hdac_audio_ctl_recsel_build(devinfo, w->nid, 0);
5001 #define HDA_COMMIT_CONN (1 << 0)
5002 #define HDA_COMMIT_CTRL (1 << 1)
5003 #define HDA_COMMIT_EAPD (1 << 2)
5004 #define HDA_COMMIT_GPIO (1 << 3)
5005 #define HDA_COMMIT_MISC (1 << 4)
5006 #define HDA_COMMIT_ALL (HDA_COMMIT_CONN | HDA_COMMIT_CTRL | \
5007 HDA_COMMIT_EAPD | HDA_COMMIT_GPIO | HDA_COMMIT_MISC)
5010 hdac_audio_commit(struct hdac_devinfo *devinfo, uint32_t cfl)
5012 struct hdac_softc *sc = devinfo->codec->sc;
5013 struct hdac_widget *w;
5017 if (!(cfl & HDA_COMMIT_ALL))
5020 cad = devinfo->codec->cad;
5022 if ((cfl & HDA_COMMIT_MISC)) {
5023 if (sc->pci_subvendor == APPLE_INTEL_MAC)
5024 hdac_command(sc, HDA_CMD_12BIT(cad, devinfo->nid,
5028 if (cfl & HDA_COMMIT_GPIO) {
5029 uint32_t gdata, gmask, gdir;
5030 int commitgpio, numgpio;
5037 numgpio = HDA_PARAM_GPIO_COUNT_NUM_GPIO(
5038 devinfo->function.audio.gpio);
5040 if (devinfo->function.audio.quirks & HDA_QUIRK_GPIOFLUSH)
5041 commitgpio = (numgpio > 0) ? 1 : 0;
5043 for (i = 0; i < numgpio && i < HDA_GPIO_MAX; i++) {
5044 if (!(devinfo->function.audio.quirks &
5047 if (commitgpio == 0) {
5050 gdata = hdac_command(sc,
5051 HDA_CMD_GET_GPIO_DATA(cad,
5052 devinfo->nid), cad);
5053 gmask = hdac_command(sc,
5054 HDA_CMD_GET_GPIO_ENABLE_MASK(cad,
5055 devinfo->nid), cad);
5056 gdir = hdac_command(sc,
5057 HDA_CMD_GET_GPIO_DIRECTION(cad,
5058 devinfo->nid), cad);
5059 device_printf(sc->dev,
5060 "GPIO init: data=0x%08x "
5061 "mask=0x%08x dir=0x%08x\n",
5062 gdata, gmask, gdir);
5074 if (commitgpio != 0) {
5076 device_printf(sc->dev,
5077 "GPIO commit: data=0x%08x mask=0x%08x "
5079 gdata, gmask, gdir);
5082 HDA_CMD_SET_GPIO_ENABLE_MASK(cad, devinfo->nid,
5085 HDA_CMD_SET_GPIO_DIRECTION(cad, devinfo->nid,
5088 HDA_CMD_SET_GPIO_DATA(cad, devinfo->nid,
5093 for (i = 0; i < devinfo->nodecnt; i++) {
5094 w = &devinfo->widget[i];
5095 if (w == NULL || w->enable == 0)
5097 if (cfl & HDA_COMMIT_CONN) {
5098 if (w->selconn == -1)
5101 hdac_widget_connection_select(w, w->selconn);
5103 if ((cfl & HDA_COMMIT_CTRL) &&
5104 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) {
5107 pincap = w->wclass.pin.cap;
5109 if ((w->pflags & (HDA_DAC_PATH | HDA_ADC_PATH)) ==
5110 (HDA_DAC_PATH | HDA_ADC_PATH))
5111 device_printf(sc->dev, "WARNING: node %d "
5112 "participate both for DAC/ADC!\n", w->nid);
5113 if (w->pflags & HDA_DAC_PATH) {
5114 w->wclass.pin.ctrl &=
5115 ~HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE;
5116 if ((w->wclass.pin.config &
5117 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK) !=
5118 HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT)
5119 w->wclass.pin.ctrl &=
5120 ~HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE;
5121 if ((devinfo->function.audio.quirks & HDA_QUIRK_OVREF100) &&
5122 HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap))
5123 w->wclass.pin.ctrl |=
5124 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
5125 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_100);
5126 else if ((devinfo->function.audio.quirks & HDA_QUIRK_OVREF80) &&
5127 HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap))
5128 w->wclass.pin.ctrl |=
5129 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
5130 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_80);
5131 else if ((devinfo->function.audio.quirks & HDA_QUIRK_OVREF50) &&
5132 HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap))
5133 w->wclass.pin.ctrl |=
5134 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
5135 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_50);
5136 } else if (w->pflags & HDA_ADC_PATH) {
5137 w->wclass.pin.ctrl &=
5138 ~(HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE |
5139 HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE);
5140 if ((devinfo->function.audio.quirks & HDA_QUIRK_IVREF100) &&
5141 HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap))
5142 w->wclass.pin.ctrl |=
5143 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
5144 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_100);
5145 else if ((devinfo->function.audio.quirks & HDA_QUIRK_IVREF80) &&
5146 HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap))
5147 w->wclass.pin.ctrl |=
5148 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
5149 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_80);
5150 else if ((devinfo->function.audio.quirks & HDA_QUIRK_IVREF50) &&
5151 HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap))
5152 w->wclass.pin.ctrl |=
5153 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
5154 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_50);
5156 w->wclass.pin.ctrl &= ~(
5157 HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE |
5158 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE |
5159 HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE |
5160 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK);
5162 HDA_CMD_SET_PIN_WIDGET_CTRL(cad, w->nid,
5163 w->wclass.pin.ctrl), cad);
5165 if ((cfl & HDA_COMMIT_EAPD) &&
5166 w->param.eapdbtl != HDAC_INVALID) {
5169 val = w->param.eapdbtl;
5170 if (devinfo->function.audio.quirks &
5172 val ^= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD;
5174 HDA_CMD_SET_EAPD_BTL_ENABLE(cad, w->nid,
5183 hdac_audio_ctl_commit(struct hdac_devinfo *devinfo)
5185 struct hdac_softc *sc = devinfo->codec->sc;
5186 struct hdac_audio_ctl *ctl;
5189 devinfo->function.audio.mvol = 100 | (100 << 8);
5191 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) {
5192 if (ctl->enable == 0 || ctl->widget == NULL) {
5194 device_printf(sc->dev, "[%2d] Ctl nid=%d",
5195 i, (ctl->widget != NULL) ?
5196 ctl->widget->nid : -1);
5197 if (ctl->childwidget != NULL)
5198 kprintf(" childnid=%d",
5199 ctl->childwidget->nid);
5200 if (ctl->widget == NULL)
5201 kprintf(" NULL WIDGET!");
5202 kprintf(" DISABLED\n");
5207 if (ctl->ossmask == 0) {
5208 device_printf(sc->dev, "[%2d] Ctl nid=%d",
5209 i, ctl->widget->nid);
5210 if (ctl->childwidget != NULL)
5211 kprintf(" childnid=%d",
5212 ctl->childwidget->nid);
5213 kprintf(" Bind to NONE\n");
5216 if (ctl->step > 0) {
5217 ctl->ossval = (ctl->left * 100) / ctl->step;
5218 ctl->ossval |= ((ctl->right * 100) / ctl->step) << 8;
5221 hdac_audio_ctl_amp_set(ctl, HDA_AMP_MUTE_DEFAULT,
5222 ctl->left, ctl->right);
5227 hdac_pcmchannel_setup(struct hdac_devinfo *devinfo, int dir)
5229 struct hdac_chan *ch;
5230 struct hdac_widget *w;
5231 uint32_t cap, fmtcap, pcmcap, path;
5232 int i, type, ret, max;
5234 if (dir == PCMDIR_PLAY) {
5235 type = HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT;
5236 ch = &devinfo->codec->sc->play;
5237 path = HDA_DAC_PATH;
5239 type = HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT;
5240 ch = &devinfo->codec->sc->rec;
5241 path = HDA_ADC_PATH;
5244 ch->caps = hdac_caps;
5245 ch->caps.fmtlist = ch->fmtlist;
5248 ch->pcmrates[0] = 48000;
5249 ch->pcmrates[1] = 0;
5252 fmtcap = devinfo->function.audio.supp_stream_formats;
5253 pcmcap = devinfo->function.audio.supp_pcm_size_rate;
5254 max = (sizeof(ch->io) / sizeof(ch->io[0])) - 1;
5256 for (i = devinfo->startnode; i < devinfo->endnode && ret < max; i++) {
5257 w = hdac_widget_get(devinfo, i);
5258 if (w == NULL || w->enable == 0 || w->type != type ||
5259 !(w->pflags & path))
5261 cap = w->param.widget_cap;
5262 /*if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(cap))
5264 if (!HDA_PARAM_AUDIO_WIDGET_CAP_STEREO(cap))
5266 cap = w->param.supp_stream_formats;
5267 /*if (HDA_PARAM_SUPP_STREAM_FORMATS_AC3(cap)) {
5269 if (HDA_PARAM_SUPP_STREAM_FORMATS_FLOAT32(cap)) {
5271 if (!HDA_PARAM_SUPP_STREAM_FORMATS_PCM(cap))
5274 fmtcap = w->param.supp_stream_formats;
5275 pcmcap = w->param.supp_pcm_size_rate;
5277 fmtcap &= w->param.supp_stream_formats;
5278 pcmcap &= w->param.supp_pcm_size_rate;
5284 ch->supp_stream_formats = fmtcap;
5285 ch->supp_pcm_size_rate = pcmcap;
5296 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16BIT(cap))
5298 else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8BIT(cap))
5300 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(cap))
5302 else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(cap))
5304 else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(cap))
5307 if (!(devinfo->function.audio.quirks & HDA_QUIRK_FORCESTEREO))
5308 ch->fmtlist[i++] = AFMT_S16_LE;
5309 ch->fmtlist[i++] = AFMT_S16_LE | AFMT_STEREO;
5310 if (ch->bit32 > 0) {
5311 if (!(devinfo->function.audio.quirks &
5312 HDA_QUIRK_FORCESTEREO))
5313 ch->fmtlist[i++] = AFMT_S32_LE;
5314 ch->fmtlist[i++] = AFMT_S32_LE | AFMT_STEREO;
5318 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8KHZ(cap))
5319 ch->pcmrates[i++] = 8000;
5320 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_11KHZ(cap))
5321 ch->pcmrates[i++] = 11025;
5322 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16KHZ(cap))
5323 ch->pcmrates[i++] = 16000;
5324 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_22KHZ(cap))
5325 ch->pcmrates[i++] = 22050;
5326 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32KHZ(cap))
5327 ch->pcmrates[i++] = 32000;
5328 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_44KHZ(cap))
5329 ch->pcmrates[i++] = 44100;
5330 /* if (HDA_PARAM_SUPP_PCM_SIZE_RATE_48KHZ(cap)) */
5331 ch->pcmrates[i++] = 48000;
5332 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_88KHZ(cap))
5333 ch->pcmrates[i++] = 88200;
5334 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_96KHZ(cap))
5335 ch->pcmrates[i++] = 96000;
5336 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_176KHZ(cap))
5337 ch->pcmrates[i++] = 176400;
5338 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_192KHZ(cap))
5339 ch->pcmrates[i++] = 192000;
5340 /* if (HDA_PARAM_SUPP_PCM_SIZE_RATE_384KHZ(cap)) */
5341 ch->pcmrates[i] = 0;
5343 ch->caps.minspeed = ch->pcmrates[0];
5344 ch->caps.maxspeed = ch->pcmrates[i - 1];
5352 hdac_dump_ctls(struct hdac_devinfo *devinfo, const char *banner, uint32_t flag)
5354 struct hdac_audio_ctl *ctl;
5355 struct hdac_softc *sc = devinfo->codec->sc;
5361 fl = SOUND_MASK_VOLUME | SOUND_MASK_PCM |
5362 SOUND_MASK_CD | SOUND_MASK_LINE | SOUND_MASK_RECLEV |
5363 SOUND_MASK_MIC | SOUND_MASK_SPEAKER | SOUND_MASK_OGAIN;
5367 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) {
5368 if (ctl->enable == 0 || ctl->widget == NULL ||
5369 ctl->widget->enable == 0 || (ctl->ossmask &
5370 (SOUND_MASK_SKIP | SOUND_MASK_DISABLE)))
5372 if ((flag == 0 && (ctl->ossmask & ~fl)) ||
5373 (flag != 0 && (ctl->ossmask & flag))) {
5374 if (banner != NULL) {
5375 device_printf(sc->dev, "\n");
5376 device_printf(sc->dev, "%s\n", banner);
5378 goto hdac_ctl_dump_it_all;
5384 hdac_ctl_dump_it_all:
5386 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) {
5387 if (ctl->enable == 0 || ctl->widget == NULL ||
5388 ctl->widget->enable == 0)
5390 if (!((flag == 0 && (ctl->ossmask & ~fl)) ||
5391 (flag != 0 && (ctl->ossmask & flag))))
5394 device_printf(sc->dev, "\n");
5395 device_printf(sc->dev, "Unknown Ctl (OSS: %s)\n",
5396 hdac_audio_ctl_ossmixer_mask2name(ctl->ossmask));
5398 device_printf(sc->dev, " |\n");
5399 device_printf(sc->dev, " +- nid: %2d index: %2d ",
5400 ctl->widget->nid, ctl->index);
5401 if (ctl->childwidget != NULL)
5402 kprintf("(nid: %2d) ", ctl->childwidget->nid);
5405 kprintf("mute: %d step: %3d size: %3d off: %3d dir=0x%x ossmask=0x%08x\n",
5406 ctl->mute, ctl->step, ctl->size, ctl->offset, ctl->dir,
5412 hdac_dump_audio_formats(struct hdac_softc *sc, uint32_t fcap, uint32_t pcmcap)
5418 device_printf(sc->dev, " Stream cap: 0x%08x\n", cap);
5419 device_printf(sc->dev, " Format:");
5420 if (HDA_PARAM_SUPP_STREAM_FORMATS_AC3(cap))
5422 if (HDA_PARAM_SUPP_STREAM_FORMATS_FLOAT32(cap))
5423 kprintf(" FLOAT32");
5424 if (HDA_PARAM_SUPP_STREAM_FORMATS_PCM(cap))
5430 device_printf(sc->dev, " PCM cap: 0x%08x\n", cap);
5431 device_printf(sc->dev, " PCM size:");
5432 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8BIT(cap))
5434 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16BIT(cap))
5436 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(cap))
5438 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(cap))
5440 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(cap))
5443 device_printf(sc->dev, " PCM rate:");
5444 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8KHZ(cap))
5446 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_11KHZ(cap))
5448 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16KHZ(cap))
5450 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_22KHZ(cap))
5452 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32KHZ(cap))
5454 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_44KHZ(cap))
5457 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_88KHZ(cap))
5459 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_96KHZ(cap))
5461 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_176KHZ(cap))
5463 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_192KHZ(cap))
5470 hdac_dump_pin(struct hdac_softc *sc, struct hdac_widget *w)
5472 uint32_t pincap, wcap;
5474 pincap = w->wclass.pin.cap;
5475 wcap = w->param.widget_cap;
5477 device_printf(sc->dev, " Pin cap: 0x%08x\n", pincap);
5478 device_printf(sc->dev, " ");
5479 if (HDA_PARAM_PIN_CAP_IMP_SENSE_CAP(pincap))
5481 if (HDA_PARAM_PIN_CAP_TRIGGER_REQD(pincap))
5483 if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(pincap))
5485 if (HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap))
5487 if (HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap))
5489 if (HDA_PARAM_PIN_CAP_INPUT_CAP(pincap))
5491 if (HDA_PARAM_PIN_CAP_BALANCED_IO_PINS(pincap))
5493 if (HDA_PARAM_PIN_CAP_VREF_CTRL(pincap)) {
5495 if (HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap))
5497 if (HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap))
5499 if (HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap))
5501 if (HDA_PARAM_PIN_CAP_VREF_CTRL_GROUND(pincap))
5503 if (HDA_PARAM_PIN_CAP_VREF_CTRL_HIZ(pincap))
5507 if (HDA_PARAM_PIN_CAP_EAPD_CAP(pincap))
5509 if (HDA_PARAM_AUDIO_WIDGET_CAP_UNSOL_CAP(wcap))
5510 kprintf(" : UNSOL");
5512 device_printf(sc->dev, " Pin config: 0x%08x\n",
5513 w->wclass.pin.config);
5514 device_printf(sc->dev, " Pin control: 0x%08x", w->wclass.pin.ctrl);
5515 if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE)
5517 if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE)
5519 if (w->wclass.pin.ctrl & HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE)
5525 hdac_dump_amp(struct hdac_softc *sc, uint32_t cap, char *banner)
5527 device_printf(sc->dev, " %s amp: 0x%08x\n", banner, cap);
5528 device_printf(sc->dev, " "
5529 "mute=%d step=%d size=%d offset=%d\n",
5530 HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(cap),
5531 HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(cap),
5532 HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(cap),
5533 HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(cap));
5537 hdac_dump_nodes(struct hdac_devinfo *devinfo)
5539 struct hdac_softc *sc = devinfo->codec->sc;
5540 struct hdac_widget *w, *cw;
5543 device_printf(sc->dev, "\n");
5544 device_printf(sc->dev, "Default Parameter\n");
5545 device_printf(sc->dev, "-----------------\n");
5546 hdac_dump_audio_formats(sc,
5547 devinfo->function.audio.supp_stream_formats,
5548 devinfo->function.audio.supp_pcm_size_rate);
5549 device_printf(sc->dev, " IN amp: 0x%08x\n",
5550 devinfo->function.audio.inamp_cap);
5551 device_printf(sc->dev, " OUT amp: 0x%08x\n",
5552 devinfo->function.audio.outamp_cap);
5553 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5554 w = hdac_widget_get(devinfo, i);
5556 device_printf(sc->dev, "Ghost widget nid=%d\n", i);
5559 device_printf(sc->dev, "\n");
5560 device_printf(sc->dev, " nid: %d [%s]%s\n", w->nid,
5561 HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap) ?
5562 "DIGITAL" : "ANALOG",
5563 (w->enable == 0) ? " [DISABLED]" : "");
5564 device_printf(sc->dev, " name: %s\n", w->name);
5565 device_printf(sc->dev, " widget_cap: 0x%08x\n",
5566 w->param.widget_cap);
5567 device_printf(sc->dev, " Parse flags: 0x%08x\n",
5569 device_printf(sc->dev, " Ctl flags: 0x%08x\n",
5571 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT ||
5572 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT) {
5573 hdac_dump_audio_formats(sc,
5574 w->param.supp_stream_formats,
5575 w->param.supp_pcm_size_rate);
5576 } else if (w->type ==
5577 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
5578 hdac_dump_pin(sc, w);
5579 if (w->param.eapdbtl != HDAC_INVALID)
5580 device_printf(sc->dev, " EAPD: 0x%08x\n",
5582 if (HDA_PARAM_AUDIO_WIDGET_CAP_OUT_AMP(w->param.widget_cap) &&
5583 w->param.outamp_cap != 0)
5584 hdac_dump_amp(sc, w->param.outamp_cap, "Output");
5585 if (HDA_PARAM_AUDIO_WIDGET_CAP_IN_AMP(w->param.widget_cap) &&
5586 w->param.inamp_cap != 0)
5587 hdac_dump_amp(sc, w->param.inamp_cap, " Input");
5588 device_printf(sc->dev, " connections: %d\n", w->nconns);
5589 for (j = 0; j < w->nconns; j++) {
5590 cw = hdac_widget_get(devinfo, w->conns[j]);
5591 device_printf(sc->dev, " |\n");
5592 device_printf(sc->dev, " + <- nid=%d [%s]",
5593 w->conns[j], (cw == NULL) ? "GHOST!" : cw->name);
5595 kprintf(" [UNKNOWN]");
5596 else if (cw->enable == 0)
5597 kprintf(" [DISABLED]");
5598 if (w->nconns > 1 && w->selconn == j && w->type !=
5599 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER)
5600 kprintf(" (selected)");
5608 hdac_dump_dac_internal(struct hdac_devinfo *devinfo, nid_t nid, int depth)
5610 struct hdac_widget *w, *cw;
5611 struct hdac_softc *sc = devinfo->codec->sc;
5614 if (depth > HDA_PARSE_MAXDEPTH)
5617 w = hdac_widget_get(devinfo, nid);
5618 if (w == NULL || w->enable == 0 || !(w->pflags & HDA_DAC_PATH))
5621 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) {
5622 device_printf(sc->dev, "\n");
5623 device_printf(sc->dev, " nid=%d [%s]\n", w->nid, w->name);
5624 device_printf(sc->dev, " ^\n");
5625 device_printf(sc->dev, " |\n");
5626 device_printf(sc->dev, " +-----<------+\n");
5628 device_printf(sc->dev, " ^\n");
5629 device_printf(sc->dev, " |\n");
5630 device_printf(sc->dev, " ");
5631 kprintf(" nid=%d [%s]\n", w->nid, w->name);
5634 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT) {
5636 } else if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER) {
5637 for (i = 0; i < w->nconns; i++) {
5638 cw = hdac_widget_get(devinfo, w->conns[i]);
5639 if (cw == NULL || cw->enable == 0 || cw->type ==
5640 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
5642 if (hdac_dump_dac_internal(devinfo, cw->nid,
5646 } else if ((w->type ==
5647 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR ||
5648 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) &&
5649 w->selconn > -1 && w->selconn < w->nconns) {
5650 if (hdac_dump_dac_internal(devinfo, w->conns[w->selconn],
5659 hdac_dump_dac(struct hdac_devinfo *devinfo)
5661 struct hdac_widget *w;
5662 struct hdac_softc *sc = devinfo->codec->sc;
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 ||
5670 !(w->pflags & HDA_DAC_PATH))
5674 device_printf(sc->dev, "\n");
5675 device_printf(sc->dev, "Playback path:\n");
5677 hdac_dump_dac_internal(devinfo, w->nid, 0);
5682 hdac_dump_adc(struct hdac_devinfo *devinfo)
5684 struct hdac_widget *w, *cw;
5685 struct hdac_softc *sc = devinfo->codec->sc;
5690 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5691 w = hdac_widget_get(devinfo, i);
5692 if (w == NULL || w->enable == 0)
5694 if (!(w->pflags & HDA_ADC_RECSEL))
5698 device_printf(sc->dev, "\n");
5699 device_printf(sc->dev, "Recording sources:\n");
5701 device_printf(sc->dev, "\n");
5702 device_printf(sc->dev, " nid=%d [%s]\n", w->nid, w->name);
5703 for (j = 0; j < w->nconns; j++) {
5704 cw = hdac_widget_get(devinfo, w->conns[j]);
5705 if (cw == NULL || cw->enable == 0)
5707 hdac_audio_ctl_ossmixer_mask2allname(cw->ctlflags,
5708 ossdevs, sizeof(ossdevs));
5709 device_printf(sc->dev, " |\n");
5710 device_printf(sc->dev, " + <- nid=%d [%s]",
5712 if (strlen(ossdevs) > 0) {
5713 kprintf(" [recsrc: %s]", ossdevs);
5721 hdac_dump_pcmchannels(struct hdac_softc *sc, int pcnt, int rcnt)
5726 device_printf(sc->dev, "\n");
5727 device_printf(sc->dev, " PCM Playback: %d\n", pcnt);
5728 hdac_dump_audio_formats(sc, sc->play.supp_stream_formats,
5729 sc->play.supp_pcm_size_rate);
5730 device_printf(sc->dev, " DAC:");
5731 for (nids = sc->play.io; *nids != -1; nids++)
5732 kprintf(" %d", *nids);
5737 device_printf(sc->dev, "\n");
5738 device_printf(sc->dev, " PCM Record: %d\n", rcnt);
5739 hdac_dump_audio_formats(sc, sc->play.supp_stream_formats,
5740 sc->rec.supp_pcm_size_rate);
5741 device_printf(sc->dev, " ADC:");
5742 for (nids = sc->rec.io; *nids != -1; nids++)
5743 kprintf(" %d", *nids);
5749 hdac_release_resources(struct hdac_softc *sc)
5751 struct hdac_devinfo *devinfo = NULL;
5752 device_t *devlist = NULL;
5761 callout_stop(&sc->poll_hda);
5762 callout_stop(&sc->poll_hdac);
5763 callout_stop(&sc->poll_jack);
5769 /* give pending interrupts stuck on the lock a chance to clear */
5771 tsleep(&sc->irq, 0, "hdaslp", hz / 10);
5773 device_get_children(sc->dev, &devlist, &devcount);
5774 for (i = 0; devlist != NULL && i < devcount; i++) {
5775 devinfo = (struct hdac_devinfo *)device_get_ivars(devlist[i]);
5776 if (devinfo == NULL)
5778 if (devinfo->widget != NULL)
5779 kfree(devinfo->widget, M_HDAC);
5780 if (devinfo->node_type ==
5781 HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO &&
5782 devinfo->function.audio.ctl != NULL)
5783 kfree(devinfo->function.audio.ctl, M_HDAC);
5784 kfree(devinfo, M_HDAC);
5785 device_delete_child(sc->dev, devlist[i]);
5787 if (devlist != NULL)
5788 kfree(devlist, M_TEMP);
5790 for (i = 0; i < HDAC_CODEC_MAX; i++) {
5791 if (sc->codecs[i] != NULL)
5792 kfree(sc->codecs[i], M_HDAC);
5793 sc->codecs[i] = NULL;
5796 hdac_dma_free(sc, &sc->pos_dma);
5797 hdac_dma_free(sc, &sc->rirb_dma);
5798 hdac_dma_free(sc, &sc->corb_dma);
5799 if (sc->play.blkcnt > 0)
5800 hdac_dma_free(sc, &sc->play.bdl_dma);
5801 if (sc->rec.blkcnt > 0)
5802 hdac_dma_free(sc, &sc->rec.bdl_dma);
5803 if (sc->chan_dmat != NULL) {
5804 bus_dma_tag_destroy(sc->chan_dmat);
5805 sc->chan_dmat = NULL;
5808 snd_mtxfree(sc->lock);
5809 kfree(sc, M_DEVBUF);
5812 /* This function surely going to make its way into upper level someday. */
5814 hdac_config_fetch(struct hdac_softc *sc, uint32_t *on, uint32_t *off)
5817 int i = 0, j, k, len, inv;
5825 if (resource_string_value(device_get_name(sc->dev),
5826 device_get_unit(sc->dev), "config", &res) != 0)
5828 if (!(res != NULL && strlen(res) > 0))
5831 device_printf(sc->dev, "HDA_DEBUG: HDA Config:");
5834 while (res[i] != '\0' &&
5835 (res[i] == ',' || isspace(res[i]) != 0))
5837 if (res[i] == '\0') {
5844 while (res[j] != '\0' &&
5845 !(res[j] == ',' || isspace(res[j]) != 0))
5848 if (len > 2 && strncmp(res + i, "no", 2) == 0)
5852 for (k = 0; len > inv && k < HDAC_QUIRKS_TAB_LEN; k++) {
5853 if (strncmp(res + i + inv,
5854 hdac_quirks_tab[k].key, len - inv) != 0)
5856 if (len - inv != strlen(hdac_quirks_tab[k].key))
5859 kprintf(" %s%s", (inv != 0) ? "no" : "",
5860 hdac_quirks_tab[k].key);
5862 if (inv == 0 && on != NULL)
5863 *on |= hdac_quirks_tab[k].value;
5864 else if (inv != 0 && off != NULL)
5865 *off |= hdac_quirks_tab[k].value;
5872 #ifdef SND_DYNSYSCTL
5874 sysctl_hdac_polling(SYSCTL_HANDLER_ARGS)
5876 struct hdac_softc *sc;
5877 struct hdac_devinfo *devinfo;
5882 dev = oidp->oid_arg1;
5883 devinfo = pcm_getdevinfo(dev);
5884 if (devinfo == NULL || devinfo->codec == NULL ||
5885 devinfo->codec->sc == NULL)
5887 sc = devinfo->codec->sc;
5891 err = sysctl_handle_int(oidp, &val, 0, req);
5893 if (err != 0 || req->newptr == NULL)
5895 if (val < 0 || val > 1)
5899 if (val != sc->polling) {
5900 if (hda_chan_active(sc) != 0)
5902 else if (val == 0) {
5903 callout_stop(&sc->poll_hdac);
5906 HDAC_WRITE_2(&sc->mem, HDAC_RINTCNT,
5908 ctl = HDAC_READ_1(&sc->mem, HDAC_RIRBCTL);
5909 ctl |= HDAC_RIRBCTL_RINTCTL;
5910 HDAC_WRITE_1(&sc->mem, HDAC_RIRBCTL, ctl);
5911 HDAC_WRITE_4(&sc->mem, HDAC_INTCTL,
5912 HDAC_INTCTL_CIE | HDAC_INTCTL_GIE);
5916 HDAC_WRITE_4(&sc->mem, HDAC_INTCTL, 0);
5917 HDAC_WRITE_2(&sc->mem, HDAC_RINTCNT, 0);
5918 ctl = HDAC_READ_1(&sc->mem, HDAC_RIRBCTL);
5919 ctl &= ~HDAC_RIRBCTL_RINTCTL;
5920 HDAC_WRITE_1(&sc->mem, HDAC_RIRBCTL, ctl);
5921 callout_reset(&sc->poll_hdac, 1, hdac_poll_callback,
5933 sysctl_hdac_polling_interval(SYSCTL_HANDLER_ARGS)
5935 struct hdac_softc *sc;
5936 struct hdac_devinfo *devinfo;
5940 dev = oidp->oid_arg1;
5941 devinfo = pcm_getdevinfo(dev);
5942 if (devinfo == NULL || devinfo->codec == NULL ||
5943 devinfo->codec->sc == NULL)
5945 sc = devinfo->codec->sc;
5947 val = ((uint64_t)sc->poll_ival * 1000) / hz;
5949 err = sysctl_handle_int(oidp, &val, 0, req);
5951 if (err != 0 || req->newptr == NULL)
5958 val = ((uint64_t)val * hz) / 1000;
5965 sc->poll_ival = val;
5973 sysctl_hdac_pindump(SYSCTL_HANDLER_ARGS)
5975 struct hdac_softc *sc;
5976 struct hdac_devinfo *devinfo;
5977 struct hdac_widget *w;
5979 uint32_t res, pincap, execres;
5983 dev = oidp->oid_arg1;
5984 devinfo = pcm_getdevinfo(dev);
5985 if (devinfo == NULL || devinfo->codec == NULL ||
5986 devinfo->codec->sc == NULL)
5989 err = sysctl_handle_int(oidp, &val, 0, req);
5990 if (err != 0 || req->newptr == NULL || val == 0)
5992 sc = devinfo->codec->sc;
5993 cad = devinfo->codec->cad;
5995 device_printf(dev, "HDAC Dump AFG [nid=%d]:\n", devinfo->nid);
5996 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
5997 w = hdac_widget_get(devinfo, i);
5998 if (w == NULL || w->type !=
5999 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
6001 pincap = w->wclass.pin.cap;
6002 if ((HDA_PARAM_PIN_CAP_IMP_SENSE_CAP(pincap) ||
6003 HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(pincap)) &&
6004 HDA_PARAM_PIN_CAP_TRIGGER_REQD(pincap)) {
6007 HDA_CMD_SET_PIN_SENSE(cad, w->nid, 0), cad);
6009 res = hdac_command(sc,
6010 HDA_CMD_GET_PIN_SENSE(cad, w->nid), cad);
6011 if (res != 0x7fffffff)
6014 } while (--timeout != 0);
6017 res = hdac_command(sc, HDA_CMD_GET_PIN_SENSE(cad,
6021 "PIN_SENSE: nid=%-3d timeout=%d res=0x%08x [%s]\n",
6022 w->nid, timeout, res,
6023 (w->enable == 0) ? "DISABLED" : "ENABLED");
6026 "NumGPIO=%d NumGPO=%d NumGPI=%d GPIWake=%d GPIUnsol=%d\n",
6027 HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->function.audio.gpio),
6028 HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->function.audio.gpio),
6029 HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->function.audio.gpio),
6030 HDA_PARAM_GPIO_COUNT_GPI_WAKE(devinfo->function.audio.gpio),
6031 HDA_PARAM_GPIO_COUNT_GPI_UNSOL(devinfo->function.audio.gpio));
6032 if (HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo->function.audio.gpio) > 0) {
6033 device_printf(dev, " GPI:");
6034 res = hdac_command(sc,
6035 HDA_CMD_GET_GPI_DATA(cad, devinfo->nid), cad);
6036 kprintf(" data=0x%08x", res);
6037 res = hdac_command(sc,
6038 HDA_CMD_GET_GPI_WAKE_ENABLE_MASK(cad, devinfo->nid),
6040 kprintf(" wake=0x%08x", res);
6041 res = hdac_command(sc,
6042 HDA_CMD_GET_GPI_UNSOLICITED_ENABLE_MASK(cad, devinfo->nid),
6044 kprintf(" unsol=0x%08x", res);
6045 res = hdac_command(sc,
6046 HDA_CMD_GET_GPI_STICKY_MASK(cad, devinfo->nid), cad);
6047 kprintf(" sticky=0x%08x\n", res);
6049 if (HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo->function.audio.gpio) > 0) {
6050 device_printf(dev, " GPO:");
6051 res = hdac_command(sc,
6052 HDA_CMD_GET_GPO_DATA(cad, devinfo->nid), cad);
6053 kprintf(" data=0x%08x\n", res);
6055 if (HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo->function.audio.gpio) > 0) {
6056 device_printf(dev, "GPI0:");
6057 res = hdac_command(sc,
6058 HDA_CMD_GET_GPIO_DATA(cad, devinfo->nid), cad);
6059 kprintf(" data=0x%08x", res);
6060 res = hdac_command(sc,
6061 HDA_CMD_GET_GPIO_ENABLE_MASK(cad, devinfo->nid), cad);
6062 kprintf(" enable=0x%08x", res);
6063 res = hdac_command(sc,
6064 HDA_CMD_GET_GPIO_DIRECTION(cad, devinfo->nid), cad);
6065 kprintf(" direction=0x%08x\n", res);
6066 res = hdac_command(sc,
6067 HDA_CMD_GET_GPIO_WAKE_ENABLE_MASK(cad, devinfo->nid), cad);
6068 device_printf(dev, " wake=0x%08x", res);
6069 res = hdac_command(sc,
6070 HDA_CMD_GET_GPIO_UNSOLICITED_ENABLE_MASK(cad, devinfo->nid),
6072 kprintf(" unsol=0x%08x", res);
6073 res = hdac_command(sc,
6074 HDA_CMD_GET_GPIO_STICKY_MASK(cad, devinfo->nid), cad);
6075 kprintf(" sticky=0x%08x\n", res);
6084 hdac_attach2(void *arg)
6086 struct hdac_softc *sc;
6087 struct hdac_widget *w;
6088 struct hdac_audio_ctl *ctl;
6089 uint32_t quirks_on, quirks_off;
6090 int pcnt, rcnt, codec_index;
6092 char status[SND_STATUSLEN];
6093 device_t *devlist = NULL;
6095 struct hdac_devinfo *devinfo = NULL;
6097 sc = (struct hdac_softc *)arg;
6099 hdac_config_fetch(sc, &quirks_on, &quirks_off);
6102 device_printf(sc->dev, "HDA_DEBUG: HDA Config: on=0x%08x off=0x%08x\n",
6103 quirks_on, quirks_off);
6106 if (resource_int_value(device_get_name(sc->dev),
6107 device_get_unit(sc->dev), "codec_index", &codec_index) != 0) {
6108 switch (sc->pci_subvendor) {
6109 case GB_G33S2H_SUBVENDOR:
6120 /* Remove ourselves from the config hooks */
6121 if (sc->intrhook.ich_func != NULL) {
6122 config_intrhook_disestablish(&sc->intrhook);
6123 sc->intrhook.ich_func = NULL;
6126 /* Start the corb and rirb engines */
6128 device_printf(sc->dev, "HDA_DEBUG: Starting CORB Engine...\n");
6130 hdac_corb_start(sc);
6132 device_printf(sc->dev, "HDA_DEBUG: Starting RIRB Engine...\n");
6134 hdac_rirb_start(sc);
6137 device_printf(sc->dev,
6138 "HDA_DEBUG: Enabling controller interrupt...\n");
6140 if (sc->polling == 0)
6141 HDAC_WRITE_4(&sc->mem, HDAC_INTCTL,
6142 HDAC_INTCTL_CIE | HDAC_INTCTL_GIE);
6143 HDAC_WRITE_4(&sc->mem, HDAC_GCTL, HDAC_READ_4(&sc->mem, HDAC_GCTL) |
6149 device_printf(sc->dev,
6150 "HDA_DEBUG: Scanning HDA codecs [start index=%d] ...\n",
6153 hdac_scan_codecs(sc, codec_index);
6155 device_get_children(sc->dev, &devlist, &devcount);
6156 for (i = 0; devlist != NULL && i < devcount; i++) {
6157 devinfo = (struct hdac_devinfo *)device_get_ivars(devlist[i]);
6158 if (devinfo != NULL && devinfo->node_type ==
6159 HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO) {
6164 if (devlist != NULL)
6165 kfree(devlist, M_TEMP);
6167 if (devinfo == NULL) {
6169 device_printf(sc->dev, "Audio Function Group not found!\n");
6170 hdac_release_resources(sc);
6175 device_printf(sc->dev,
6176 "HDA_DEBUG: Parsing AFG nid=%d cad=%d\n",
6177 devinfo->nid, devinfo->codec->cad);
6179 hdac_audio_parse(devinfo);
6181 device_printf(sc->dev, "HDA_DEBUG: Parsing Ctls...\n");
6183 hdac_audio_ctl_parse(devinfo);
6185 device_printf(sc->dev, "HDA_DEBUG: Parsing vendor patch...\n");
6187 hdac_vendor_patch_parse(devinfo);
6189 devinfo->function.audio.quirks |= quirks_on;
6190 if (quirks_off != 0)
6191 devinfo->function.audio.quirks &= ~quirks_off;
6193 /* XXX Disable all DIGITAL path. */
6194 for (i = devinfo->startnode; i < devinfo->endnode; i++) {
6195 w = hdac_widget_get(devinfo, i);
6198 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap)) {
6202 /* XXX Disable useless pin ? */
6203 if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX &&
6204 (w->wclass.pin.config &
6205 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK) ==
6206 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_NONE)
6210 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) {
6211 if (ctl->widget == NULL)
6213 if (ctl->ossmask & SOUND_MASK_DISABLE)
6216 if (w->enable == 0 ||
6217 HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap))
6219 w = ctl->childwidget;
6222 if (w->enable == 0 ||
6223 HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w->param.widget_cap))
6228 device_printf(sc->dev, "HDA_DEBUG: Building AFG tree...\n");
6230 hdac_audio_build_tree(devinfo);
6233 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) {
6234 if (ctl->ossmask & (SOUND_MASK_SKIP | SOUND_MASK_DISABLE))
6238 device_printf(sc->dev, "HDA_DEBUG: AFG commit...\n");
6240 hdac_audio_commit(devinfo, HDA_COMMIT_ALL);
6242 device_printf(sc->dev, "HDA_DEBUG: Ctls commit...\n");
6244 hdac_audio_ctl_commit(devinfo);
6247 device_printf(sc->dev, "HDA_DEBUG: PCMDIR_PLAY setup...\n");
6249 pcnt = hdac_pcmchannel_setup(devinfo, PCMDIR_PLAY);
6251 device_printf(sc->dev, "HDA_DEBUG: PCMDIR_REC setup...\n");
6253 rcnt = hdac_pcmchannel_setup(devinfo, PCMDIR_REC);
6257 device_printf(sc->dev,
6258 "HDA_DEBUG: OSS mixer initialization...\n");
6262 * There is no point of return after this. If the driver failed,
6263 * so be it. Let the detach procedure do all the cleanup.
6265 if (mixer_init(sc->dev, &hdac_audio_ctl_ossmixer_class, devinfo) != 0)
6266 device_printf(sc->dev, "Can't register mixer\n");
6274 device_printf(sc->dev,
6275 "HDA_DEBUG: Registering PCM channels...\n");
6277 if (pcm_register(sc->dev, devinfo, pcnt, rcnt) != 0)
6278 device_printf(sc->dev, "Can't register PCM\n");
6282 if ((devinfo->function.audio.quirks & HDA_QUIRK_DMAPOS) &&
6283 hdac_dma_alloc(sc, &sc->pos_dma,
6284 (sc->num_iss + sc->num_oss + sc->num_bss) * 8) != 0) {
6286 device_printf(sc->dev,
6287 "Failed to allocate DMA pos buffer (non-fatal)\n");
6291 for (i = 0; i < pcnt; i++)
6292 pcm_addchan(sc->dev, PCMDIR_PLAY, &hdac_channel_class, devinfo);
6293 for (i = 0; i < rcnt; i++)
6294 pcm_addchan(sc->dev, PCMDIR_REC, &hdac_channel_class, devinfo);
6296 #ifdef SND_DYNSYSCTL
6297 SYSCTL_ADD_PROC(snd_sysctl_tree(sc->dev),
6298 SYSCTL_CHILDREN(snd_sysctl_tree_top(sc->dev)), OID_AUTO,
6299 "polling", CTLTYPE_INT | CTLFLAG_RW, sc->dev, sizeof(sc->dev),
6300 sysctl_hdac_polling, "I", "Enable polling mode");
6301 SYSCTL_ADD_PROC(snd_sysctl_tree(sc->dev),
6302 SYSCTL_CHILDREN(snd_sysctl_tree_top(sc->dev)), OID_AUTO,
6303 "polling_interval", CTLTYPE_INT | CTLFLAG_RW, sc->dev,
6304 sizeof(sc->dev), sysctl_hdac_polling_interval, "I",
6305 "Controller/Jack Sense polling interval (1-1000 ms)");
6307 SYSCTL_ADD_PROC(snd_sysctl_tree(sc->dev),
6308 SYSCTL_CHILDREN(snd_sysctl_tree_top(sc->dev)), OID_AUTO,
6309 "pindump", CTLTYPE_INT | CTLFLAG_RW, sc->dev, sizeof(sc->dev),
6310 sysctl_hdac_pindump, "I", "Dump pin states/data");
6314 ksnprintf(status, SND_STATUSLEN, "at memory 0x%lx irq %ld %s [%s]",
6315 rman_get_start(sc->mem.mem_res), rman_get_start(sc->irq.irq_res),
6316 PCM_KLDSTRING(snd_hda), HDA_DRV_TEST_REV);
6317 pcm_setstatus(sc->dev, status);
6318 device_printf(sc->dev, "<HDA Codec: %s>\n", hdac_codec_name(devinfo));
6320 device_printf(sc->dev, "<HDA Codec ID: 0x%08x>\n",
6321 hdac_codec_id(devinfo));
6323 device_printf(sc->dev, "<HDA Driver Revision: %s>\n",
6327 if (devinfo->function.audio.quirks != 0) {
6328 device_printf(sc->dev, "\n");
6329 device_printf(sc->dev, "HDA config/quirks:");
6330 for (i = 0; i < HDAC_QUIRKS_TAB_LEN; i++) {
6331 if ((devinfo->function.audio.quirks &
6332 hdac_quirks_tab[i].value) ==
6333 hdac_quirks_tab[i].value)
6334 kprintf(" %s", hdac_quirks_tab[i].key);
6338 device_printf(sc->dev, "\n");
6339 device_printf(sc->dev, "+-------------------+\n");
6340 device_printf(sc->dev, "| DUMPING HDA NODES |\n");
6341 device_printf(sc->dev, "+-------------------+\n");
6342 hdac_dump_nodes(devinfo);
6343 device_printf(sc->dev, "\n");
6344 device_printf(sc->dev, "+------------------------+\n");
6345 device_printf(sc->dev, "| DUMPING HDA AMPLIFIERS |\n");
6346 device_printf(sc->dev, "+------------------------+\n");
6347 device_printf(sc->dev, "\n");
6349 while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) {
6350 device_printf(sc->dev, "%3d: nid=%d", i,
6351 (ctl->widget != NULL) ? ctl->widget->nid : -1);
6352 if (ctl->childwidget != NULL)
6353 kprintf(" cnid=%d", ctl->childwidget->nid);
6354 kprintf(" dir=0x%x index=%d "
6355 "ossmask=0x%08x ossdev=%d%s\n",
6356 ctl->dir, ctl->index,
6357 ctl->ossmask, ctl->ossdev,
6358 (ctl->enable == 0) ? " [DISABLED]" : "");
6360 device_printf(sc->dev, "\n");
6361 device_printf(sc->dev, "+-----------------------------------+\n");
6362 device_printf(sc->dev, "| DUMPING HDA AUDIO/VOLUME CONTROLS |\n");
6363 device_printf(sc->dev, "+-----------------------------------+\n");
6364 hdac_dump_ctls(devinfo, "Master Volume (OSS: vol)", SOUND_MASK_VOLUME);
6365 hdac_dump_ctls(devinfo, "PCM Volume (OSS: pcm)", SOUND_MASK_PCM);
6366 hdac_dump_ctls(devinfo, "CD Volume (OSS: cd)", SOUND_MASK_CD);
6367 hdac_dump_ctls(devinfo, "Microphone Volume (OSS: mic)", SOUND_MASK_MIC);
6368 hdac_dump_ctls(devinfo, "Line-in Volume (OSS: line)", SOUND_MASK_LINE);
6369 hdac_dump_ctls(devinfo, "Recording Level (OSS: rec)", SOUND_MASK_RECLEV);
6370 hdac_dump_ctls(devinfo, "Speaker/Beep (OSS: speaker)", SOUND_MASK_SPEAKER);
6371 hdac_dump_ctls(devinfo, NULL, 0);
6372 hdac_dump_dac(devinfo);
6373 hdac_dump_adc(devinfo);
6374 device_printf(sc->dev, "\n");
6375 device_printf(sc->dev, "+--------------------------------------+\n");
6376 device_printf(sc->dev, "| DUMPING PCM Playback/Record Channels |\n");
6377 device_printf(sc->dev, "+--------------------------------------+\n");
6378 hdac_dump_pcmchannels(sc, pcnt, rcnt);
6381 if (sc->polling != 0) {
6383 callout_reset(&sc->poll_hdac, 1, hdac_poll_callback, sc);
6388 /****************************************************************************
6389 * int hdac_detach(device_t)
6391 * Detach and free up resources utilized by the hdac device.
6392 ****************************************************************************/
6394 hdac_detach(device_t dev)
6396 struct hdac_softc *sc = NULL;
6397 struct hdac_devinfo *devinfo = NULL;
6400 devinfo = (struct hdac_devinfo *)pcm_getdevinfo(dev);
6401 if (devinfo != NULL && devinfo->codec != NULL)
6402 sc = devinfo->codec->sc;
6406 if (sc->registered > 0) {
6407 err = pcm_unregister(dev);
6412 hdac_release_resources(sc);
6417 static device_method_t hdac_methods[] = {
6418 /* device interface */
6419 DEVMETHOD(device_probe, hdac_probe),
6420 DEVMETHOD(device_attach, hdac_attach),
6421 DEVMETHOD(device_detach, hdac_detach),
6425 static driver_t hdac_driver = {
6431 DRIVER_MODULE(snd_hda, pci, hdac_driver, pcm_devclass, 0, 0);
6432 MODULE_DEPEND(snd_hda, sound, SOUND_MINVER, SOUND_PREFVER, SOUND_MAXVER);
6433 MODULE_VERSION(snd_hda, 1);