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.7 2007/11/27 23:37:16 ariff Exp $
28 * $DragonFly: src/sys/dev/sound/pci/hda/hdac.c,v 1.13 2007/11/30 08:06:00 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 "20071122_0049"
88 #define HDA_WIDGET_PARSER_REV 1
90 SND_DECLARE_FILE("$DragonFly: src/sys/dev/sound/pci/hda/hdac.c,v 1.13 2007/11/30 08:06:00 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_MCP61_1 HDA_MODEL_CONSTRUCT(NVIDIA, 0x03e4)
161 #define HDA_NVIDIA_MCP61_2 HDA_MODEL_CONSTRUCT(NVIDIA, 0x03f0)
162 #define HDA_NVIDIA_MCP65_1 HDA_MODEL_CONSTRUCT(NVIDIA, 0x044a)
163 #define HDA_NVIDIA_MCP65_2 HDA_MODEL_CONSTRUCT(NVIDIA, 0x044b)
164 #define HDA_NVIDIA_MCP67_1 HDA_MODEL_CONSTRUCT(NVIDIA, 0x055c)
165 #define HDA_NVIDIA_MCP67_2 HDA_MODEL_CONSTRUCT(NVIDIA, 0x055d)
166 #define HDA_NVIDIA_ALL HDA_MODEL_CONSTRUCT(NVIDIA, 0xffff)
169 #define ATI_VENDORID 0x1002
170 #define HDA_ATI_SB450 HDA_MODEL_CONSTRUCT(ATI, 0x437b)
171 #define HDA_ATI_SB600 HDA_MODEL_CONSTRUCT(ATI, 0x4383)
172 #define HDA_ATI_ALL HDA_MODEL_CONSTRUCT(ATI, 0xffff)
175 #define VIA_VENDORID 0x1106
176 #define HDA_VIA_VT82XX HDA_MODEL_CONSTRUCT(VIA, 0x3288)
177 #define HDA_VIA_ALL HDA_MODEL_CONSTRUCT(VIA, 0xffff)
180 #define SIS_VENDORID 0x1039
181 #define HDA_SIS_966 HDA_MODEL_CONSTRUCT(SIS, 0x7502)
182 #define HDA_SIS_ALL HDA_MODEL_CONSTRUCT(SIS, 0xffff)
187 #define INTEL_D101GGC_SUBVENDOR HDA_MODEL_CONSTRUCT(INTEL, 0xd600)
190 #define HP_VENDORID 0x103c
191 #define HP_V3000_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x30b5)
192 #define HP_NX7400_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x30a2)
193 #define HP_NX6310_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x30aa)
194 #define HP_NX6325_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x30b0)
195 #define HP_XW4300_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x3013)
196 #define HP_3010_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x3010)
197 #define HP_DV5000_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x30a5)
198 #define HP_DC7700_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x2802)
199 #define HP_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0xffff)
200 /* What is wrong with XN 2563 anyway? (Got the picture ?) */
201 #define HP_NX6325_SUBVENDORX 0x103c30b0
204 #define DELL_VENDORID 0x1028
205 #define DELL_D820_SUBVENDOR HDA_MODEL_CONSTRUCT(DELL, 0x01cc)
206 #define DELL_I1300_SUBVENDOR HDA_MODEL_CONSTRUCT(DELL, 0x01c9)
207 #define DELL_XPSM1210_SUBVENDOR HDA_MODEL_CONSTRUCT(DELL, 0x01d7)
208 #define DELL_OPLX745_SUBVENDOR HDA_MODEL_CONSTRUCT(DELL, 0x01da)
209 #define DELL_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(DELL, 0xffff)
212 #define CLEVO_VENDORID 0x1558
213 #define CLEVO_D900T_SUBVENDOR HDA_MODEL_CONSTRUCT(CLEVO, 0x0900)
214 #define CLEVO_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(CLEVO, 0xffff)
217 #define ACER_VENDORID 0x1025
218 #define ACER_A5050_SUBVENDOR HDA_MODEL_CONSTRUCT(ACER, 0x010f)
219 #define ACER_A4520_SUBVENDOR HDA_MODEL_CONSTRUCT(ACER, 0x0127)
220 #define ACER_3681WXM_SUBVENDOR HDA_MODEL_CONSTRUCT(ACER, 0x0110)
221 #define ACER_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(ACER, 0xffff)
224 #define ASUS_VENDORID 0x1043
225 #define ASUS_M5200_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x1993)
226 #define ASUS_U5F_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x1263)
227 #define ASUS_A8JC_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x1153)
228 #define ASUS_P1AH2_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x81cb)
229 #define ASUS_A7M_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x1323)
230 #define ASUS_A7T_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x13c2)
231 #define ASUS_W6F_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x1263)
232 #define ASUS_W2J_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x1971)
233 #define ASUS_F3JC_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x1338)
234 #define ASUS_M2V_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x81e7)
235 #define ASUS_M2N_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x8234)
236 #define ASUS_M2NPVMX_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x81cb)
237 #define ASUS_P5BWD_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x81ec)
238 #define ASUS_A8NVMCSM_SUBVENDOR HDA_MODEL_CONSTRUCT(NVIDIA, 0xcb84)
239 #define ASUS_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0xffff)
242 #define IBM_VENDORID 0x1014
243 #define IBM_M52_SUBVENDOR HDA_MODEL_CONSTRUCT(IBM, 0x02f6)
244 #define IBM_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(IBM, 0xffff)
247 #define LENOVO_VENDORID 0x17aa
248 #define LENOVO_3KN100_SUBVENDOR HDA_MODEL_CONSTRUCT(LENOVO, 0x2066)
249 #define LENOVO_TCA55_SUBVENDOR HDA_MODEL_CONSTRUCT(LENOVO, 0x1015)
250 #define LENOVO_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(LENOVO, 0xffff)
253 #define SAMSUNG_VENDORID 0x144d
254 #define SAMSUNG_Q1_SUBVENDOR HDA_MODEL_CONSTRUCT(SAMSUNG, 0xc027)
255 #define SAMSUNG_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(SAMSUNG, 0xffff)
258 #define MEDION_VENDORID 0x161f
259 #define MEDION_MD95257_SUBVENDOR HDA_MODEL_CONSTRUCT(MEDION, 0x203d)
260 #define MEDION_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(MEDION, 0xffff)
262 /* Apple Computer Inc. */
263 #define APPLE_VENDORID 0x106b
264 #define APPLE_MB3_SUBVENDOR HDA_MODEL_CONSTRUCT(APPLE, 0x00a1)
267 * Apple Intel MacXXXX seems using Sigmatel codec/vendor id
268 * instead of their own, which is beyond my comprehension
269 * (see HDA_CODEC_STAC9221 below).
271 #define APPLE_INTEL_MAC 0x76808384
274 #define LG_VENDORID 0x1854
275 #define LG_LW20_SUBVENDOR HDA_MODEL_CONSTRUCT(LG, 0x0018)
276 #define LG_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(LG, 0xffff)
278 /* Fujitsu Siemens */
279 #define FS_VENDORID 0x1734
280 #define FS_PA1510_SUBVENDOR HDA_MODEL_CONSTRUCT(FS, 0x10b8)
281 #define FS_SI1848_SUBVENDOR HDA_MODEL_CONSTRUCT(FS, 0x10cd)
282 #define FS_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(FS, 0xffff)
284 /* Fujitsu Limited */
285 #define FL_VENDORID 0x10cf
286 #define FL_S7020D_SUBVENDOR HDA_MODEL_CONSTRUCT(FL, 0x1326)
287 #define FL_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(FL, 0xffff)
290 #define TOSHIBA_VENDORID 0x1179
291 #define TOSHIBA_U200_SUBVENDOR HDA_MODEL_CONSTRUCT(TOSHIBA, 0x0001)
292 #define TOSHIBA_A135_SUBVENDOR HDA_MODEL_CONSTRUCT(TOSHIBA, 0xff01)
293 #define TOSHIBA_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(TOSHIBA, 0xffff)
295 /* Micro-Star International (MSI) */
296 #define MSI_VENDORID 0x1462
297 #define MSI_MS1034_SUBVENDOR HDA_MODEL_CONSTRUCT(MSI, 0x0349)
298 #define MSI_MS034A_SUBVENDOR HDA_MODEL_CONSTRUCT(MSI, 0x034a)
299 #define MSI_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(MSI, 0xffff)
301 /* Giga-Byte Technology */
302 #define GB_VENDORID 0x1458
303 #define GB_G33S2H_SUBVENDOR HDA_MODEL_CONSTRUCT(GB, 0xa022)
304 #define GP_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(GB, 0xffff)
307 #define UNIWILL_VENDORID 0x1584
308 #define UNIWILL_9075_SUBVENDOR HDA_MODEL_CONSTRUCT(UNIWILL, 0x9075)
309 #define UNIWILL_9080_SUBVENDOR HDA_MODEL_CONSTRUCT(UNIWILL, 0x9080)
312 /* Misc constants.. */
313 #define HDA_AMP_MUTE_DEFAULT (0xffffffff)
314 #define HDA_AMP_MUTE_NONE (0)
315 #define HDA_AMP_MUTE_LEFT (1 << 0)
316 #define HDA_AMP_MUTE_RIGHT (1 << 1)
317 #define HDA_AMP_MUTE_ALL (HDA_AMP_MUTE_LEFT | HDA_AMP_MUTE_RIGHT)
319 #define HDA_AMP_LEFT_MUTED(v) ((v) & (HDA_AMP_MUTE_LEFT))
320 #define HDA_AMP_RIGHT_MUTED(v) (((v) & HDA_AMP_MUTE_RIGHT) >> 1)
322 #define HDA_DAC_PATH (1 << 0)
323 #define HDA_ADC_PATH (1 << 1)
324 #define HDA_ADC_RECSEL (1 << 2)
326 #define HDA_DAC_LOCKED (1 << 3)
327 #define HDA_ADC_LOCKED (1 << 4)
329 #define HDA_CTL_OUT (1 << 0)
330 #define HDA_CTL_IN (1 << 1)
331 #define HDA_CTL_BOTH (HDA_CTL_IN | HDA_CTL_OUT)
333 #define HDA_GPIO_MAX 8
334 /* 0 - 7 = GPIO , 8 = Flush */
335 #define HDA_QUIRK_GPIO0 (1 << 0)
336 #define HDA_QUIRK_GPIO1 (1 << 1)
337 #define HDA_QUIRK_GPIO2 (1 << 2)
338 #define HDA_QUIRK_GPIO3 (1 << 3)
339 #define HDA_QUIRK_GPIO4 (1 << 4)
340 #define HDA_QUIRK_GPIO5 (1 << 5)
341 #define HDA_QUIRK_GPIO6 (1 << 6)
342 #define HDA_QUIRK_GPIO7 (1 << 7)
343 #define HDA_QUIRK_GPIOFLUSH (1 << 8)
345 /* 9 - 25 = anything else */
346 #define HDA_QUIRK_SOFTPCMVOL (1 << 9)
347 #define HDA_QUIRK_FIXEDRATE (1 << 10)
348 #define HDA_QUIRK_FORCESTEREO (1 << 11)
349 #define HDA_QUIRK_EAPDINV (1 << 12)
350 #define HDA_QUIRK_DMAPOS (1 << 13)
352 /* 26 - 31 = vrefs */
353 #define HDA_QUIRK_IVREF50 (1 << 26)
354 #define HDA_QUIRK_IVREF80 (1 << 27)
355 #define HDA_QUIRK_IVREF100 (1 << 28)
356 #define HDA_QUIRK_OVREF50 (1 << 29)
357 #define HDA_QUIRK_OVREF80 (1 << 30)
358 #define HDA_QUIRK_OVREF100 (1 << 31)
360 #define HDA_QUIRK_IVREF (HDA_QUIRK_IVREF50 | HDA_QUIRK_IVREF80 | \
362 #define HDA_QUIRK_OVREF (HDA_QUIRK_OVREF50 | HDA_QUIRK_OVREF80 | \
364 #define HDA_QUIRK_VREF (HDA_QUIRK_IVREF | HDA_QUIRK_OVREF)
366 #define SOUND_MASK_SKIP (1 << 30)
367 #define SOUND_MASK_DISABLE (1 << 31)
369 static const struct {
372 } hdac_quirks_tab
[] = {
373 { "gpio0", HDA_QUIRK_GPIO0
},
374 { "gpio1", HDA_QUIRK_GPIO1
},
375 { "gpio2", HDA_QUIRK_GPIO2
},
376 { "gpio3", HDA_QUIRK_GPIO3
},
377 { "gpio4", HDA_QUIRK_GPIO4
},
378 { "gpio5", HDA_QUIRK_GPIO5
},
379 { "gpio6", HDA_QUIRK_GPIO6
},
380 { "gpio7", HDA_QUIRK_GPIO7
},
381 { "gpioflush", HDA_QUIRK_GPIOFLUSH
},
382 { "softpcmvol", HDA_QUIRK_SOFTPCMVOL
},
383 { "fixedrate", HDA_QUIRK_FIXEDRATE
},
384 { "forcestereo", HDA_QUIRK_FORCESTEREO
},
385 { "eapdinv", HDA_QUIRK_EAPDINV
},
386 { "dmapos", HDA_QUIRK_DMAPOS
},
387 { "ivref50", HDA_QUIRK_IVREF50
},
388 { "ivref80", HDA_QUIRK_IVREF80
},
389 { "ivref100", HDA_QUIRK_IVREF100
},
390 { "ovref50", HDA_QUIRK_OVREF50
},
391 { "ovref80", HDA_QUIRK_OVREF80
},
392 { "ovref100", HDA_QUIRK_OVREF100
},
393 { "ivref", HDA_QUIRK_IVREF
},
394 { "ovref", HDA_QUIRK_OVREF
},
395 { "vref", HDA_QUIRK_VREF
},
397 #define HDAC_QUIRKS_TAB_LEN \
398 (sizeof(hdac_quirks_tab) / sizeof(hdac_quirks_tab[0]))
400 #define HDA_BDL_MIN 2
401 #define HDA_BDL_MAX 256
402 #define HDA_BDL_DEFAULT HDA_BDL_MIN
404 #define HDA_BLK_MIN HDAC_DMA_ALIGNMENT
405 #define HDA_BLK_ALIGN (~(HDA_BLK_MIN - 1))
407 #define HDA_BUFSZ_MIN 4096
408 #define HDA_BUFSZ_MAX 65536
409 #define HDA_BUFSZ_DEFAULT 16384
411 #define HDA_PARSE_MAXDEPTH 10
413 #define HDAC_UNSOLTAG_EVENT_HP 0x00
414 #define HDAC_UNSOLTAG_EVENT_TEST 0x01
416 MALLOC_DEFINE(M_HDAC
, "hdac", "High Definition Audio Controller");
424 static uint32_t hdac_fmt
[] = {
425 AFMT_STEREO
| AFMT_S16_LE
,
429 static struct pcmchan_caps hdac_caps
= {48000, 48000, hdac_fmt
, 0};
431 static const struct {
435 { HDA_INTEL_82801F
, "Intel 82801F" },
436 { HDA_INTEL_63XXESB
, "Intel 631x/632xESB" },
437 { HDA_INTEL_82801G
, "Intel 82801G" },
438 { HDA_INTEL_82801H
, "Intel 82801H" },
439 { HDA_INTEL_82801I
, "Intel 82801I" },
440 { HDA_NVIDIA_MCP51
, "NVidia MCP51" },
441 { HDA_NVIDIA_MCP55
, "NVidia MCP55" },
442 { HDA_NVIDIA_MCP61_1
, "NVidia MCP61" },
443 { HDA_NVIDIA_MCP61_2
, "NVidia MCP61" },
444 { HDA_NVIDIA_MCP65_1
, "NVidia MCP65" },
445 { HDA_NVIDIA_MCP67_1
, "NVidia MCP67" },
446 { HDA_NVIDIA_MCP67_2
, "NVidia MCP67" },
447 { HDA_ATI_SB450
, "ATI SB450" },
448 { HDA_ATI_SB600
, "ATI SB600" },
449 { HDA_VIA_VT82XX
, "VIA VT8251/8237A" },
450 { HDA_SIS_966
, "SiS 966" },
452 { HDA_INTEL_ALL
, "Intel (Unknown)" },
453 { HDA_NVIDIA_ALL
, "NVidia (Unknown)" },
454 { HDA_ATI_ALL
, "ATI (Unknown)" },
455 { HDA_VIA_ALL
, "VIA (Unknown)" },
456 { HDA_SIS_ALL
, "SiS (Unknown)" },
458 #define HDAC_DEVICES_LEN (sizeof(hdac_devices) / sizeof(hdac_devices[0]))
460 static const struct {
465 } hdac_pcie_snoop
[] = {
466 { INTEL_VENDORID
, 0x00, 0x00, 0x00 },
467 { ATI_VENDORID
, 0x42, 0xf8, 0x02 },
468 { NVIDIA_VENDORID
, 0x4e, 0xf0, 0x0f },
470 #define HDAC_PCIESNOOP_LEN \
471 (sizeof(hdac_pcie_snoop) / sizeof(hdac_pcie_snoop[0]))
473 static const struct {
480 { 8000, 1, 0x0000, 0x0000, 0x0500 }, /* (48000 * 1) / 6 */
481 { 9600, 0, 0x0000, 0x0000, 0x0400 }, /* (48000 * 1) / 5 */
482 { 12000, 0, 0x0000, 0x0000, 0x0300 }, /* (48000 * 1) / 4 */
483 { 16000, 1, 0x0000, 0x0000, 0x0200 }, /* (48000 * 1) / 3 */
484 { 18000, 0, 0x0000, 0x1000, 0x0700 }, /* (48000 * 3) / 8 */
485 { 19200, 0, 0x0000, 0x0800, 0x0400 }, /* (48000 * 2) / 5 */
486 { 24000, 0, 0x0000, 0x0000, 0x0100 }, /* (48000 * 1) / 2 */
487 { 28800, 0, 0x0000, 0x1000, 0x0400 }, /* (48000 * 3) / 5 */
488 { 32000, 1, 0x0000, 0x0800, 0x0200 }, /* (48000 * 2) / 3 */
489 { 36000, 0, 0x0000, 0x1000, 0x0300 }, /* (48000 * 3) / 4 */
490 { 38400, 0, 0x0000, 0x1800, 0x0400 }, /* (48000 * 4) / 5 */
491 { 48000, 1, 0x0000, 0x0000, 0x0000 }, /* (48000 * 1) / 1 */
492 { 64000, 0, 0x0000, 0x1800, 0x0200 }, /* (48000 * 4) / 3 */
493 { 72000, 0, 0x0000, 0x1000, 0x0100 }, /* (48000 * 3) / 2 */
494 { 96000, 1, 0x0000, 0x0800, 0x0000 }, /* (48000 * 2) / 1 */
495 { 144000, 0, 0x0000, 0x1000, 0x0000 }, /* (48000 * 3) / 1 */
496 { 192000, 1, 0x0000, 0x1800, 0x0000 }, /* (48000 * 4) / 1 */
497 { 8820, 0, 0x4000, 0x0000, 0x0400 }, /* (44100 * 1) / 5 */
498 { 11025, 1, 0x4000, 0x0000, 0x0300 }, /* (44100 * 1) / 4 */
499 { 12600, 0, 0x4000, 0x0800, 0x0600 }, /* (44100 * 2) / 7 */
500 { 14700, 0, 0x4000, 0x0000, 0x0200 }, /* (44100 * 1) / 3 */
501 { 17640, 0, 0x4000, 0x0800, 0x0400 }, /* (44100 * 2) / 5 */
502 { 18900, 0, 0x4000, 0x1000, 0x0600 }, /* (44100 * 3) / 7 */
503 { 22050, 1, 0x4000, 0x0000, 0x0100 }, /* (44100 * 1) / 2 */
504 { 25200, 0, 0x4000, 0x1800, 0x0600 }, /* (44100 * 4) / 7 */
505 { 26460, 0, 0x4000, 0x1000, 0x0400 }, /* (44100 * 3) / 5 */
506 { 29400, 0, 0x4000, 0x0800, 0x0200 }, /* (44100 * 2) / 3 */
507 { 33075, 0, 0x4000, 0x1000, 0x0300 }, /* (44100 * 3) / 4 */
508 { 35280, 0, 0x4000, 0x1800, 0x0400 }, /* (44100 * 4) / 5 */
509 { 44100, 1, 0x4000, 0x0000, 0x0000 }, /* (44100 * 1) / 1 */
510 { 58800, 0, 0x4000, 0x1800, 0x0200 }, /* (44100 * 4) / 3 */
511 { 66150, 0, 0x4000, 0x1000, 0x0100 }, /* (44100 * 3) / 2 */
512 { 88200, 1, 0x4000, 0x0800, 0x0000 }, /* (44100 * 2) / 1 */
513 { 132300, 0, 0x4000, 0x1000, 0x0000 }, /* (44100 * 3) / 1 */
514 { 176400, 1, 0x4000, 0x1800, 0x0000 }, /* (44100 * 4) / 1 */
516 #define HDA_RATE_TAB_LEN (sizeof(hda_rate_tab) / sizeof(hda_rate_tab[0]))
518 /* All codecs you can eat... */
519 #define HDA_CODEC_CONSTRUCT(vendor, id) \
520 (((uint32_t)(vendor##_VENDORID) << 16) | ((id) & 0xffff))
523 #define REALTEK_VENDORID 0x10ec
524 #define HDA_CODEC_ALC260 HDA_CODEC_CONSTRUCT(REALTEK, 0x0260)
525 #define HDA_CODEC_ALC262 HDA_CODEC_CONSTRUCT(REALTEK, 0x0262)
526 #define HDA_CODEC_ALC268 HDA_CODEC_CONSTRUCT(REALTEK, 0x0268)
527 #define HDA_CODEC_ALC660 HDA_CODEC_CONSTRUCT(REALTEK, 0x0660)
528 #define HDA_CODEC_ALC861 HDA_CODEC_CONSTRUCT(REALTEK, 0x0861)
529 #define HDA_CODEC_ALC861VD HDA_CODEC_CONSTRUCT(REALTEK, 0x0862)
530 #define HDA_CODEC_ALC880 HDA_CODEC_CONSTRUCT(REALTEK, 0x0880)
531 #define HDA_CODEC_ALC882 HDA_CODEC_CONSTRUCT(REALTEK, 0x0882)
532 #define HDA_CODEC_ALC883 HDA_CODEC_CONSTRUCT(REALTEK, 0x0883)
533 #define HDA_CODEC_ALC885 HDA_CODEC_CONSTRUCT(REALTEK, 0x0885)
534 #define HDA_CODEC_ALC888 HDA_CODEC_CONSTRUCT(REALTEK, 0x0888)
535 #define HDA_CODEC_ALCXXXX HDA_CODEC_CONSTRUCT(REALTEK, 0xffff)
538 #define ANALOGDEVICES_VENDORID 0x11d4
539 #define HDA_CODEC_AD1981HD HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0x1981)
540 #define HDA_CODEC_AD1983 HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0x1983)
541 #define HDA_CODEC_AD1986A HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0x1986)
542 #define HDA_CODEC_AD1988 HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0x1988)
543 #define HDA_CODEC_AD1988B HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0x198b)
544 #define HDA_CODEC_ADXXXX HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0xffff)
547 #define CMEDIA_VENDORID 0x434d
548 #define HDA_CODEC_CMI9880 HDA_CODEC_CONSTRUCT(CMEDIA, 0x4980)
549 #define HDA_CODEC_CMIXXXX HDA_CODEC_CONSTRUCT(CMEDIA, 0xffff)
552 #define SIGMATEL_VENDORID 0x8384
553 #define HDA_CODEC_STAC9221 HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7680)
554 #define HDA_CODEC_STAC9221D HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7683)
555 #define HDA_CODEC_STAC9220 HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7690)
556 #define HDA_CODEC_STAC922XD HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7681)
557 #define HDA_CODEC_STAC9227 HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7618)
558 #define HDA_CODEC_STAC9271D HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7627)
559 #define HDA_CODEC_STACXXXX HDA_CODEC_CONSTRUCT(SIGMATEL, 0xffff)
564 * Ok, the truth is, I don't have any idea at all whether
565 * it is "Venice" or "Waikiki" or other unnamed CXyadayada. The only
566 * place that tell me it is "Venice" is from its Windows driver INF.
569 * Waikiki - CX20551-22
571 #define CONEXANT_VENDORID 0x14f1
572 #define HDA_CODEC_CXVENICE HDA_CODEC_CONSTRUCT(CONEXANT, 0x5045)
573 #define HDA_CODEC_CXWAIKIKI HDA_CODEC_CONSTRUCT(CONEXANT, 0x5047)
574 #define HDA_CODEC_CXXXXX HDA_CODEC_CONSTRUCT(CONEXANT, 0xffff)
577 #define HDA_CODEC_VT1708_8 HDA_CODEC_CONSTRUCT(VIA, 0x1708)
578 #define HDA_CODEC_VT1708_9 HDA_CODEC_CONSTRUCT(VIA, 0x1709)
579 #define HDA_CODEC_VT1708_A HDA_CODEC_CONSTRUCT(VIA, 0x170a)
580 #define HDA_CODEC_VT1708_B HDA_CODEC_CONSTRUCT(VIA, 0x170b)
581 #define HDA_CODEC_VT1709_0 HDA_CODEC_CONSTRUCT(VIA, 0xe710)
582 #define HDA_CODEC_VT1709_1 HDA_CODEC_CONSTRUCT(VIA, 0xe711)
583 #define HDA_CODEC_VT1709_2 HDA_CODEC_CONSTRUCT(VIA, 0xe712)
584 #define HDA_CODEC_VT1709_3 HDA_CODEC_CONSTRUCT(VIA, 0xe713)
585 #define HDA_CODEC_VT1709_4 HDA_CODEC_CONSTRUCT(VIA, 0xe714)
586 #define HDA_CODEC_VT1709_5 HDA_CODEC_CONSTRUCT(VIA, 0xe715)
587 #define HDA_CODEC_VT1709_6 HDA_CODEC_CONSTRUCT(VIA, 0xe716)
588 #define HDA_CODEC_VT1709_7 HDA_CODEC_CONSTRUCT(VIA, 0xe717)
589 #define HDA_CODEC_VTXXXX HDA_CODEC_CONSTRUCT(VIA, 0xffff)
593 static const struct {
597 { HDA_CODEC_ALC260
, "Realtek ALC260" },
598 { HDA_CODEC_ALC262
, "Realtek ALC262" },
599 { HDA_CODEC_ALC268
, "Realtek ALC268" },
600 { HDA_CODEC_ALC660
, "Realtek ALC660" },
601 { HDA_CODEC_ALC861
, "Realtek ALC861" },
602 { HDA_CODEC_ALC861VD
, "Realtek ALC861-VD" },
603 { HDA_CODEC_ALC880
, "Realtek ALC880" },
604 { HDA_CODEC_ALC882
, "Realtek ALC882" },
605 { HDA_CODEC_ALC883
, "Realtek ALC883" },
606 { HDA_CODEC_ALC885
, "Realtek ALC885" },
607 { HDA_CODEC_ALC888
, "Realtek ALC888" },
608 { HDA_CODEC_AD1981HD
, "Analog Devices AD1981HD" },
609 { HDA_CODEC_AD1983
, "Analog Devices AD1983" },
610 { HDA_CODEC_AD1986A
, "Analog Devices AD1986A" },
611 { HDA_CODEC_AD1988
, "Analog Devices AD1988" },
612 { HDA_CODEC_AD1988B
, "Analog Devices AD1988B" },
613 { HDA_CODEC_CMI9880
, "CMedia CMI9880" },
614 { HDA_CODEC_STAC9221
, "Sigmatel STAC9221" },
615 { HDA_CODEC_STAC9221D
, "Sigmatel STAC9221D" },
616 { HDA_CODEC_STAC9220
, "Sigmatel STAC9220" },
617 { HDA_CODEC_STAC922XD
, "Sigmatel STAC9220D/9223D" },
618 { HDA_CODEC_STAC9227
, "Sigmatel STAC9227" },
619 { HDA_CODEC_STAC9271D
, "Sigmatel STAC9271D" },
620 { HDA_CODEC_CXVENICE
, "Conexant Venice" },
621 { HDA_CODEC_CXWAIKIKI
, "Conexant Waikiki" },
622 { HDA_CODEC_VT1708_8
, "VIA VT1708_8" },
623 { HDA_CODEC_VT1708_9
, "VIA VT1708_9" },
624 { HDA_CODEC_VT1708_A
, "VIA VT1708_A" },
625 { HDA_CODEC_VT1708_B
, "VIA VT1708_B" },
626 { HDA_CODEC_VT1709_0
, "VIA VT1709_0" },
627 { HDA_CODEC_VT1709_1
, "VIA VT1709_1" },
628 { HDA_CODEC_VT1709_2
, "VIA VT1709_2" },
629 { HDA_CODEC_VT1709_3
, "VIA VT1709_3" },
630 { HDA_CODEC_VT1709_4
, "VIA VT1709_4" },
631 { HDA_CODEC_VT1709_5
, "VIA VT1709_5" },
632 { HDA_CODEC_VT1709_6
, "VIA VT1709_6" },
633 { HDA_CODEC_VT1709_7
, "VIA VT1709_7" },
635 { HDA_CODEC_ALCXXXX
, "Realtek (Unknown)" },
636 { HDA_CODEC_ADXXXX
, "Analog Devices (Unknown)" },
637 { HDA_CODEC_CMIXXXX
, "CMedia (Unknown)" },
638 { HDA_CODEC_STACXXXX
, "Sigmatel (Unknown)" },
639 { HDA_CODEC_CXXXXX
, "Conexant (Unknown)" },
640 { HDA_CODEC_VTXXXX
, "VIA (Unknown)" },
642 #define HDAC_CODECS_LEN (sizeof(hdac_codecs) / sizeof(hdac_codecs[0]))
650 static const struct {
660 } hdac_hp_switch
[] = {
661 /* Specific OEM models */
662 { HP_V3000_SUBVENDOR
, HDA_CODEC_CXVENICE
, HDAC_HP_SWITCH_CTL
,
663 0, 0, -1, 17, { 16, -1 }, 16 },
664 /* { HP_XW4300_SUBVENDOR, HDA_CODEC_ALC260, HDAC_HP_SWITCH_CTL,
665 0, 0, -1, 21, { 16, 17, -1 }, -1 } */
666 /* { HP_3010_SUBVENDOR, HDA_CODEC_ALC260, HDAC_HP_SWITCH_DEBUG,
667 0, 1, 0, 16, { 15, 18, 19, 20, 21, -1 }, -1 }, */
668 { HP_NX7400_SUBVENDOR
, HDA_CODEC_AD1981HD
, HDAC_HP_SWITCH_CTL
,
669 0, 0, -1, 6, { 5, -1 }, 5 },
670 { HP_NX6310_SUBVENDOR
, HDA_CODEC_AD1981HD
, HDAC_HP_SWITCH_CTL
,
671 0, 0, -1, 6, { 5, -1 }, 5 },
672 { HP_NX6325_SUBVENDOR
, HDA_CODEC_AD1981HD
, HDAC_HP_SWITCH_CTL
,
673 0, 0, -1, 6, { 5, -1 }, 5 },
674 /* { HP_DC7700_SUBVENDOR, HDA_CODEC_ALC262, HDAC_HP_SWITCH_CTL,
675 0, 0, -1, 21, { 22, 27, -1 }, -1 }, */
676 { TOSHIBA_U200_SUBVENDOR
, HDA_CODEC_AD1981HD
, HDAC_HP_SWITCH_CTL
,
677 0, 0, -1, 6, { 5, -1 }, -1 },
678 { TOSHIBA_A135_SUBVENDOR
, HDA_CODEC_ALC861VD
, HDAC_HP_SWITCH_CTL
,
679 0, 0, -1, 27, { 20, -1 }, -1 },
680 { DELL_D820_SUBVENDOR
, HDA_CODEC_STAC9220
, HDAC_HP_SWITCH_CTRL
,
681 0, 0, -1, 13, { 14, -1 }, -1 },
682 { DELL_I1300_SUBVENDOR
, HDA_CODEC_STAC9220
, HDAC_HP_SWITCH_CTRL
,
683 0, 0, -1, 13, { 14, -1 }, -1 },
684 { DELL_OPLX745_SUBVENDOR
, HDA_CODEC_AD1983
, HDAC_HP_SWITCH_CTL
,
685 0, 0, -1, 6, { 5, 7, -1 }, -1 },
686 { APPLE_MB3_SUBVENDOR
, HDA_CODEC_ALC885
, HDAC_HP_SWITCH_CTL
,
687 0, 0, -1, 21, { 20, 22, -1 }, -1 },
688 { APPLE_INTEL_MAC
, HDA_CODEC_STAC9221
, HDAC_HP_SWITCH_CTRL
,
689 0, 0, -1, 10, { 13, -1 }, -1 },
690 { LENOVO_3KN100_SUBVENDOR
, HDA_CODEC_AD1986A
, HDAC_HP_SWITCH_CTL
,
691 1, 0, -1, 26, { 27, -1 }, -1 },
692 /* { LENOVO_TCA55_SUBVENDOR, HDA_CODEC_AD1986A, HDAC_HP_SWITCH_CTL,
693 0, 0, -1, 26, { 27, 28, 29, 30, -1 }, -1 }, */
694 { LG_LW20_SUBVENDOR
, HDA_CODEC_ALC880
, HDAC_HP_SWITCH_CTL
,
695 0, 0, -1, 27, { 20, -1 }, -1 },
696 { ACER_A5050_SUBVENDOR
, HDA_CODEC_ALC883
, HDAC_HP_SWITCH_CTL
,
697 0, 0, -1, 20, { 21, -1 }, -1 },
698 { ACER_3681WXM_SUBVENDOR
, HDA_CODEC_ALC883
, HDAC_HP_SWITCH_CTL
,
699 0, 0, -1, 20, { 21, -1 }, -1 },
700 { ACER_A4520_SUBVENDOR
, HDA_CODEC_ALC268
, HDAC_HP_SWITCH_CTL
,
701 0, 0, -1, 20, { 21, -1 }, -1 },
702 { UNIWILL_9080_SUBVENDOR
, HDA_CODEC_ALC883
, HDAC_HP_SWITCH_CTL
,
703 0, 0, -1, 20, { 21, -1 }, -1 },
704 { MSI_MS1034_SUBVENDOR
, HDA_CODEC_ALC883
, HDAC_HP_SWITCH_CTL
,
705 0, 0, -1, 20, { 27, -1 }, -1 },
706 { MSI_MS034A_SUBVENDOR
, HDA_CODEC_ALC883
, HDAC_HP_SWITCH_CTL
,
707 0, 0, -1, 20, { 27, -1 }, -1 },
708 { FS_SI1848_SUBVENDOR
, HDA_CODEC_ALC883
, HDAC_HP_SWITCH_CTL
,
709 0, 0, -1, 20, { 21, -1 }, -1 },
710 { FL_S7020D_SUBVENDOR
, HDA_CODEC_ALC260
, HDAC_HP_SWITCH_CTL
,
711 0, 0, -1, 20, { 16, -1 }, -1 },
713 * All models that at least come from the same vendor with
716 { HP_ALL_SUBVENDOR
, HDA_CODEC_CXVENICE
, HDAC_HP_SWITCH_CTL
,
717 0, 0, -1, 17, { 16, -1 }, 16 },
718 { HP_ALL_SUBVENDOR
, HDA_CODEC_AD1981HD
, HDAC_HP_SWITCH_CTL
,
719 0, 0, -1, 6, { 5, -1 }, 5 },
720 { TOSHIBA_ALL_SUBVENDOR
, HDA_CODEC_AD1981HD
, HDAC_HP_SWITCH_CTL
,
721 0, 0, -1, 6, { 5, -1 }, -1 },
722 { DELL_ALL_SUBVENDOR
, HDA_CODEC_STAC9220
, HDAC_HP_SWITCH_CTRL
,
723 0, 0, -1, 13, { 14, -1 }, -1 },
725 { LENOVO_ALL_SUBVENDOR
, HDA_CODEC_AD1986A
, HDAC_HP_SWITCH_CTL
,
726 1, 0, -1, 26, { 27, -1 }, -1 },
727 { ACER_ALL_SUBVENDOR
, HDA_CODEC_ALC883
, HDAC_HP_SWITCH_CTL
,
728 0, 0, -1, 20, { 21, -1 }, -1 },
731 #define HDAC_HP_SWITCH_LEN \
732 (sizeof(hdac_hp_switch) / sizeof(hdac_hp_switch[0]))
734 static const struct {
739 } hdac_eapd_switch
[] = {
740 { HP_V3000_SUBVENDOR
, HDA_CODEC_CXVENICE
, 16, 1 },
741 { HP_NX7400_SUBVENDOR
, HDA_CODEC_AD1981HD
, 5, 1 },
742 { HP_NX6310_SUBVENDOR
, HDA_CODEC_AD1981HD
, 5, 1 },
744 #define HDAC_EAPD_SWITCH_LEN \
745 (sizeof(hdac_eapd_switch) / sizeof(hdac_eapd_switch[0]))
747 /****************************************************************************
748 * Function prototypes
749 ****************************************************************************/
750 static void hdac_intr_handler(void *);
751 static int hdac_reset(struct hdac_softc
*);
752 static int hdac_get_capabilities(struct hdac_softc
*);
753 static void hdac_dma_cb(void *, bus_dma_segment_t
*, int, int);
754 static int hdac_dma_alloc(struct hdac_softc
*,
755 struct hdac_dma
*, bus_size_t
);
756 static void hdac_dma_free(struct hdac_softc
*, struct hdac_dma
*);
757 static int hdac_mem_alloc(struct hdac_softc
*);
758 static void hdac_mem_free(struct hdac_softc
*);
759 static int hdac_irq_alloc(struct hdac_softc
*);
760 static void hdac_irq_free(struct hdac_softc
*);
761 static void hdac_corb_init(struct hdac_softc
*);
762 static void hdac_rirb_init(struct hdac_softc
*);
763 static void hdac_corb_start(struct hdac_softc
*);
764 static void hdac_rirb_start(struct hdac_softc
*);
765 static void hdac_scan_codecs(struct hdac_softc
*, int);
766 static int hdac_probe_codec(struct hdac_codec
*);
767 static struct hdac_devinfo
*hdac_probe_function(struct hdac_codec
*, nid_t
);
768 static void hdac_add_child(struct hdac_softc
*, struct hdac_devinfo
*);
770 static void hdac_attach2(void *);
772 static uint32_t hdac_command_sendone_internal(struct hdac_softc
*,
774 static void hdac_command_send_internal(struct hdac_softc
*,
775 struct hdac_command_list
*, int);
777 static int hdac_probe(device_t
);
778 static int hdac_attach(device_t
);
779 static int hdac_detach(device_t
);
780 static void hdac_widget_connection_select(struct hdac_widget
*, uint8_t);
781 static void hdac_audio_ctl_amp_set(struct hdac_audio_ctl
*,
783 static struct hdac_audio_ctl
*hdac_audio_ctl_amp_get(struct hdac_devinfo
*,
785 static void hdac_audio_ctl_amp_set_internal(struct hdac_softc
*,
786 nid_t
, nid_t
, int, int, int, int, int, int);
787 static int hdac_audio_ctl_ossmixer_getnextdev(struct hdac_devinfo
*);
788 static struct hdac_widget
*hdac_widget_get(struct hdac_devinfo
*, nid_t
);
790 static int hdac_rirb_flush(struct hdac_softc
*sc
);
791 static int hdac_unsolq_flush(struct hdac_softc
*sc
);
793 #define hdac_command(a1, a2, a3) \
794 hdac_command_sendone_internal(a1, a2, a3)
796 #define hdac_codec_id(d) \
797 ((uint32_t)((d == NULL) ? 0x00000000 : \
798 ((((uint32_t)(d)->vendor_id & 0x0000ffff) << 16) | \
799 ((uint32_t)(d)->device_id & 0x0000ffff))))
802 hdac_codec_name(struct hdac_devinfo
*devinfo
)
807 id
= hdac_codec_id(devinfo
);
809 for (i
= 0; i
< HDAC_CODECS_LEN
; i
++) {
810 if (HDA_DEV_MATCH(hdac_codecs
[i
].id
, id
))
811 return (hdac_codecs
[i
].name
);
814 return ((id
== 0x00000000) ? "NULL Codec" : "Unknown Codec");
818 hdac_audio_ctl_ossmixer_mask2name(uint32_t devmask
)
820 static char *ossname
[] = SOUND_DEVICE_NAMES
;
821 static char *unknown
= "???";
824 for (i
= SOUND_MIXER_NRDEVICES
- 1; i
>= 0; i
--) {
825 if (devmask
& (1 << i
))
832 hdac_audio_ctl_ossmixer_mask2allname(uint32_t mask
, char *buf
, size_t len
)
834 static char *ossname
[] = SOUND_DEVICE_NAMES
;
838 for (i
= 0; i
< SOUND_MIXER_NRDEVICES
; i
++) {
839 if (mask
& (1 << i
)) {
841 strlcat(buf
, ", ", len
);
842 strlcat(buf
, ossname
[i
], len
);
848 static struct hdac_audio_ctl
*
849 hdac_audio_ctl_each(struct hdac_devinfo
*devinfo
, int *index
)
851 if (devinfo
== NULL
||
852 devinfo
->node_type
!= HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO
||
853 index
== NULL
|| devinfo
->function
.audio
.ctl
== NULL
||
854 devinfo
->function
.audio
.ctlcnt
< 1 ||
855 *index
< 0 || *index
>= devinfo
->function
.audio
.ctlcnt
)
857 return (&devinfo
->function
.audio
.ctl
[(*index
)++]);
860 static struct hdac_audio_ctl
*
861 hdac_audio_ctl_amp_get(struct hdac_devinfo
*devinfo
, nid_t nid
,
864 struct hdac_audio_ctl
*ctl
, *retctl
= NULL
;
865 int i
, at
, atindex
, found
= 0;
867 if (devinfo
== NULL
|| devinfo
->function
.audio
.ctl
== NULL
)
880 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) != NULL
) {
881 if (ctl
->enable
== 0 || ctl
->widget
== NULL
)
883 if (!(ctl
->widget
->nid
== nid
&& (atindex
== -1 ||
884 ctl
->index
== atindex
)))
892 return ((at
== -1) ? retctl
: NULL
);
896 hdac_hp_switch_handler(struct hdac_devinfo
*devinfo
)
898 struct hdac_softc
*sc
;
899 struct hdac_widget
*w
;
900 struct hdac_audio_ctl
*ctl
;
901 uint32_t val
, id
, res
;
902 int i
= 0, j
, timeout
, forcemute
;
905 if (devinfo
== NULL
|| devinfo
->codec
== NULL
||
906 devinfo
->codec
->sc
== NULL
)
909 sc
= devinfo
->codec
->sc
;
910 cad
= devinfo
->codec
->cad
;
911 id
= hdac_codec_id(devinfo
);
912 for (i
= 0; i
< HDAC_HP_SWITCH_LEN
; i
++) {
913 if (HDA_DEV_MATCH(hdac_hp_switch
[i
].model
,
914 sc
->pci_subvendor
) &&
915 hdac_hp_switch
[i
].id
== id
)
919 if (i
>= HDAC_HP_SWITCH_LEN
)
923 if (hdac_hp_switch
[i
].eapdnid
!= -1) {
924 w
= hdac_widget_get(devinfo
, hdac_hp_switch
[i
].eapdnid
);
925 if (w
!= NULL
&& w
->param
.eapdbtl
!= HDAC_INVALID
)
926 forcemute
= (w
->param
.eapdbtl
&
927 HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD
) ? 0 : 1;
930 if (hdac_hp_switch
[i
].execsense
!= -1)
932 HDA_CMD_SET_PIN_SENSE(cad
, hdac_hp_switch
[i
].hpnid
,
933 hdac_hp_switch
[i
].execsense
), cad
);
937 res
= hdac_command(sc
,
938 HDA_CMD_GET_PIN_SENSE(cad
, hdac_hp_switch
[i
].hpnid
),
940 if (hdac_hp_switch
[i
].execsense
== -1 || res
!= 0x7fffffff)
943 } while (--timeout
!= 0);
946 device_printf(sc
->dev
,
947 "HDA_DEBUG: Pin sense: nid=%d timeout=%d res=0x%08x\n",
948 hdac_hp_switch
[i
].hpnid
, timeout
, res
);
951 res
= HDA_CMD_GET_PIN_SENSE_PRESENCE_DETECT(res
);
952 res
^= hdac_hp_switch
[i
].inverted
;
954 switch (hdac_hp_switch
[i
].type
) {
955 case HDAC_HP_SWITCH_CTL
:
956 ctl
= hdac_audio_ctl_amp_get(devinfo
,
957 hdac_hp_switch
[i
].hpnid
, 0, 1);
959 val
= (res
!= 0 && forcemute
== 0) ?
960 HDA_AMP_MUTE_NONE
: HDA_AMP_MUTE_ALL
;
961 if (val
!= ctl
->muted
) {
963 hdac_audio_ctl_amp_set(ctl
,
964 HDA_AMP_MUTE_DEFAULT
, ctl
->left
,
968 for (j
= 0; hdac_hp_switch
[i
].spkrnid
[j
] != -1; j
++) {
969 ctl
= hdac_audio_ctl_amp_get(devinfo
,
970 hdac_hp_switch
[i
].spkrnid
[j
], 0, 1);
973 val
= (res
!= 0 || forcemute
== 1) ?
974 HDA_AMP_MUTE_ALL
: HDA_AMP_MUTE_NONE
;
975 if (val
== ctl
->muted
)
978 hdac_audio_ctl_amp_set(ctl
, HDA_AMP_MUTE_DEFAULT
,
979 ctl
->left
, ctl
->right
);
982 case HDAC_HP_SWITCH_CTRL
:
985 w
= hdac_widget_get(devinfo
, hdac_hp_switch
[i
].hpnid
);
986 if (w
!= NULL
&& w
->type
==
987 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
) {
989 val
= w
->wclass
.pin
.ctrl
|
990 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE
;
992 val
= w
->wclass
.pin
.ctrl
&
993 ~HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE
;
994 if (val
!= w
->wclass
.pin
.ctrl
) {
995 w
->wclass
.pin
.ctrl
= val
;
997 HDA_CMD_SET_PIN_WIDGET_CTRL(cad
,
998 w
->nid
, w
->wclass
.pin
.ctrl
), cad
);
1001 for (j
= 0; hdac_hp_switch
[i
].spkrnid
[j
] != -1; j
++) {
1002 w
= hdac_widget_get(devinfo
,
1003 hdac_hp_switch
[i
].spkrnid
[j
]);
1004 if (w
== NULL
|| w
->type
!=
1005 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
)
1007 val
= w
->wclass
.pin
.ctrl
&
1008 ~HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE
;
1009 if (val
== w
->wclass
.pin
.ctrl
)
1011 w
->wclass
.pin
.ctrl
= val
;
1012 hdac_command(sc
, HDA_CMD_SET_PIN_WIDGET_CTRL(
1013 cad
, w
->nid
, w
->wclass
.pin
.ctrl
), cad
);
1017 w
= hdac_widget_get(devinfo
, hdac_hp_switch
[i
].hpnid
);
1018 if (w
!= NULL
&& w
->type
==
1019 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
) {
1020 val
= w
->wclass
.pin
.ctrl
&
1021 ~HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE
;
1022 if (val
!= w
->wclass
.pin
.ctrl
) {
1023 w
->wclass
.pin
.ctrl
= val
;
1025 HDA_CMD_SET_PIN_WIDGET_CTRL(cad
,
1026 w
->nid
, w
->wclass
.pin
.ctrl
), cad
);
1029 for (j
= 0; hdac_hp_switch
[i
].spkrnid
[j
] != -1; j
++) {
1030 w
= hdac_widget_get(devinfo
,
1031 hdac_hp_switch
[i
].spkrnid
[j
]);
1032 if (w
== NULL
|| w
->type
!=
1033 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
)
1036 val
= w
->wclass
.pin
.ctrl
|
1037 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE
;
1039 val
= w
->wclass
.pin
.ctrl
&
1040 ~HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE
;
1041 if (val
== w
->wclass
.pin
.ctrl
)
1043 w
->wclass
.pin
.ctrl
= val
;
1044 hdac_command(sc
, HDA_CMD_SET_PIN_WIDGET_CTRL(
1045 cad
, w
->nid
, w
->wclass
.pin
.ctrl
), cad
);
1049 case HDAC_HP_SWITCH_DEBUG
:
1050 if (hdac_hp_switch
[i
].execsense
!= -1)
1052 HDA_CMD_SET_PIN_SENSE(cad
, hdac_hp_switch
[i
].hpnid
,
1053 hdac_hp_switch
[i
].execsense
), cad
);
1054 res
= hdac_command(sc
,
1055 HDA_CMD_GET_PIN_SENSE(cad
, hdac_hp_switch
[i
].hpnid
), cad
);
1056 device_printf(sc
->dev
,
1057 "[ 0] HDA_DEBUG: Pin sense: nid=%d res=0x%08x\n",
1058 hdac_hp_switch
[i
].hpnid
, res
);
1059 for (j
= 0; hdac_hp_switch
[i
].spkrnid
[j
] != -1; j
++) {
1060 w
= hdac_widget_get(devinfo
,
1061 hdac_hp_switch
[i
].spkrnid
[j
]);
1062 if (w
== NULL
|| w
->type
!=
1063 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
)
1065 if (hdac_hp_switch
[i
].execsense
!= -1)
1067 HDA_CMD_SET_PIN_SENSE(cad
, w
->nid
,
1068 hdac_hp_switch
[i
].execsense
), cad
);
1069 res
= hdac_command(sc
,
1070 HDA_CMD_GET_PIN_SENSE(cad
, w
->nid
), cad
);
1071 device_printf(sc
->dev
,
1072 "[%2d] HDA_DEBUG: Pin sense: nid=%d res=0x%08x\n",
1073 j
+ 1, w
->nid
, res
);
1082 hdac_unsolicited_handler(struct hdac_codec
*codec
, uint32_t tag
)
1084 struct hdac_softc
*sc
;
1085 struct hdac_devinfo
*devinfo
= NULL
;
1086 device_t
*devlist
= NULL
;
1089 if (codec
== NULL
|| codec
->sc
== NULL
)
1095 device_printf(sc
->dev
, "HDA_DEBUG: Unsol Tag: 0x%08x\n", tag
);
1098 device_get_children(sc
->dev
, &devlist
, &devcount
);
1099 for (i
= 0; devlist
!= NULL
&& i
< devcount
; i
++) {
1100 devinfo
= (struct hdac_devinfo
*)device_get_ivars(devlist
[i
]);
1101 if (devinfo
!= NULL
&& devinfo
->node_type
==
1102 HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO
&&
1103 devinfo
->codec
!= NULL
&&
1104 devinfo
->codec
->cad
== codec
->cad
) {
1109 if (devlist
!= NULL
)
1110 kfree(devlist
, M_TEMP
);
1112 if (devinfo
== NULL
)
1116 case HDAC_UNSOLTAG_EVENT_HP
:
1117 hdac_hp_switch_handler(devinfo
);
1119 case HDAC_UNSOLTAG_EVENT_TEST
:
1120 device_printf(sc
->dev
, "Unsol Test!\n");
1128 hdac_stream_intr(struct hdac_softc
*sc
, struct hdac_chan
*ch
)
1130 /* XXX to be removed */
1131 #ifdef HDAC_INTR_EXTRA
1135 if (!(ch
->flags
& HDAC_CHN_RUNNING
))
1138 /* XXX to be removed */
1139 #ifdef HDAC_INTR_EXTRA
1140 res
= HDAC_READ_1(&sc
->mem
, ch
->off
+ HDAC_SDSTS
);
1143 /* XXX to be removed */
1144 #ifdef HDAC_INTR_EXTRA
1146 if (res
& (HDAC_SDSTS_DESE
| HDAC_SDSTS_FIFOE
))
1147 device_printf(sc
->dev
,
1148 "PCMDIR_%s intr triggered beyond stream boundary:"
1150 (ch
->dir
== PCMDIR_PLAY
) ? "PLAY" : "REC", res
);
1154 HDAC_WRITE_1(&sc
->mem
, ch
->off
+ HDAC_SDSTS
,
1155 HDAC_SDSTS_DESE
| HDAC_SDSTS_FIFOE
| HDAC_SDSTS_BCIS
);
1157 /* XXX to be removed */
1158 #ifdef HDAC_INTR_EXTRA
1159 if (res
& HDAC_SDSTS_BCIS
) {
1162 /* XXX to be removed */
1163 #ifdef HDAC_INTR_EXTRA
1170 /****************************************************************************
1171 * void hdac_intr_handler(void *)
1173 * Interrupt handler. Processes interrupts received from the hdac.
1174 ****************************************************************************/
1176 hdac_intr_handler(void *context
)
1178 struct hdac_softc
*sc
;
1181 struct hdac_rirb
*rirb_base
;
1184 sc
= (struct hdac_softc
*)context
;
1187 if (sc
->polling
!= 0) {
1192 /* Do we have anything to do? */
1193 intsts
= HDAC_READ_4(&sc
->mem
, HDAC_INTSTS
);
1194 if (!HDA_FLAG_MATCH(intsts
, HDAC_INTSTS_GIS
)) {
1201 /* Was this a controller interrupt? */
1202 if (HDA_FLAG_MATCH(intsts
, HDAC_INTSTS_CIS
)) {
1203 rirb_base
= (struct hdac_rirb
*)sc
->rirb_dma
.dma_vaddr
;
1204 rirbsts
= HDAC_READ_1(&sc
->mem
, HDAC_RIRBSTS
);
1205 /* Get as many responses that we can */
1206 while (HDA_FLAG_MATCH(rirbsts
, HDAC_RIRBSTS_RINTFL
)) {
1207 HDAC_WRITE_1(&sc
->mem
,
1208 HDAC_RIRBSTS
, HDAC_RIRBSTS_RINTFL
);
1209 if (hdac_rirb_flush(sc
) != 0)
1210 trigger
|= HDAC_TRIGGER_UNSOL
;
1211 rirbsts
= HDAC_READ_1(&sc
->mem
, HDAC_RIRBSTS
);
1213 /* XXX to be removed */
1214 /* Clear interrupt and exit */
1215 #ifdef HDAC_INTR_EXTRA
1216 HDAC_WRITE_4(&sc
->mem
, HDAC_INTSTS
, HDAC_INTSTS_CIS
);
1220 if (intsts
& HDAC_INTSTS_SIS_MASK
) {
1221 if ((intsts
& (1 << sc
->num_iss
)) &&
1222 hdac_stream_intr(sc
, &sc
->play
) != 0)
1223 trigger
|= HDAC_TRIGGER_PLAY
;
1224 if ((intsts
& (1 << 0)) &&
1225 hdac_stream_intr(sc
, &sc
->rec
) != 0)
1226 trigger
|= HDAC_TRIGGER_REC
;
1227 /* XXX to be removed */
1228 #ifdef HDAC_INTR_EXTRA
1229 HDAC_WRITE_4(&sc
->mem
, HDAC_INTSTS
, intsts
&
1230 HDAC_INTSTS_SIS_MASK
);
1236 if (trigger
& HDAC_TRIGGER_PLAY
)
1237 chn_intr(sc
->play
.c
);
1238 if (trigger
& HDAC_TRIGGER_REC
)
1239 chn_intr(sc
->rec
.c
);
1240 if (trigger
& HDAC_TRIGGER_UNSOL
)
1241 taskqueue_enqueue(taskqueue_swi
, &sc
->unsolq_task
);
1244 /****************************************************************************
1245 * int hdac_reset(hdac_softc *)
1247 * Reset the hdac to a quiescent and known state.
1248 ****************************************************************************/
1250 hdac_reset(struct hdac_softc
*sc
)
1256 * Stop all Streams DMA engine
1258 for (i
= 0; i
< sc
->num_iss
; i
++)
1259 HDAC_WRITE_4(&sc
->mem
, HDAC_ISDCTL(sc
, i
), 0x0);
1260 for (i
= 0; i
< sc
->num_oss
; i
++)
1261 HDAC_WRITE_4(&sc
->mem
, HDAC_OSDCTL(sc
, i
), 0x0);
1262 for (i
= 0; i
< sc
->num_bss
; i
++)
1263 HDAC_WRITE_4(&sc
->mem
, HDAC_BSDCTL(sc
, i
), 0x0);
1266 * Stop Control DMA engines.
1268 HDAC_WRITE_1(&sc
->mem
, HDAC_CORBCTL
, 0x0);
1269 HDAC_WRITE_1(&sc
->mem
, HDAC_RIRBCTL
, 0x0);
1272 * Reset DMA position buffer.
1274 HDAC_WRITE_4(&sc
->mem
, HDAC_DPIBLBASE
, 0x0);
1275 HDAC_WRITE_4(&sc
->mem
, HDAC_DPIBUBASE
, 0x0);
1278 * Reset the controller. The reset must remain asserted for
1279 * a minimum of 100us.
1281 gctl
= HDAC_READ_4(&sc
->mem
, HDAC_GCTL
);
1282 HDAC_WRITE_4(&sc
->mem
, HDAC_GCTL
, gctl
& ~HDAC_GCTL_CRST
);
1285 gctl
= HDAC_READ_4(&sc
->mem
, HDAC_GCTL
);
1286 if (!(gctl
& HDAC_GCTL_CRST
))
1290 if (gctl
& HDAC_GCTL_CRST
) {
1291 device_printf(sc
->dev
, "Unable to put hdac in reset\n");
1295 gctl
= HDAC_READ_4(&sc
->mem
, HDAC_GCTL
);
1296 HDAC_WRITE_4(&sc
->mem
, HDAC_GCTL
, gctl
| HDAC_GCTL_CRST
);
1299 gctl
= HDAC_READ_4(&sc
->mem
, HDAC_GCTL
);
1300 if (gctl
& HDAC_GCTL_CRST
)
1304 if (!(gctl
& HDAC_GCTL_CRST
)) {
1305 device_printf(sc
->dev
, "Device stuck in reset\n");
1310 * Wait for codecs to finish their own reset sequence. The delay here
1311 * should be of 250us but for some reasons, on it's not enough on my
1312 * computer. Let's use twice as much as necessary to make sure that
1313 * it's reset properly.
1321 /****************************************************************************
1322 * int hdac_get_capabilities(struct hdac_softc *);
1324 * Retreive the general capabilities of the hdac;
1325 * Number of Input Streams
1326 * Number of Output Streams
1327 * Number of bidirectional Streams
1329 * CORB and RIRB sizes
1330 ****************************************************************************/
1332 hdac_get_capabilities(struct hdac_softc
*sc
)
1335 uint8_t corbsize
, rirbsize
;
1337 gcap
= HDAC_READ_2(&sc
->mem
, HDAC_GCAP
);
1338 sc
->num_iss
= HDAC_GCAP_ISS(gcap
);
1339 sc
->num_oss
= HDAC_GCAP_OSS(gcap
);
1340 sc
->num_bss
= HDAC_GCAP_BSS(gcap
);
1342 sc
->support_64bit
= HDA_FLAG_MATCH(gcap
, HDAC_GCAP_64OK
);
1344 corbsize
= HDAC_READ_1(&sc
->mem
, HDAC_CORBSIZE
);
1345 if ((corbsize
& HDAC_CORBSIZE_CORBSZCAP_256
) ==
1346 HDAC_CORBSIZE_CORBSZCAP_256
)
1347 sc
->corb_size
= 256;
1348 else if ((corbsize
& HDAC_CORBSIZE_CORBSZCAP_16
) ==
1349 HDAC_CORBSIZE_CORBSZCAP_16
)
1351 else if ((corbsize
& HDAC_CORBSIZE_CORBSZCAP_2
) ==
1352 HDAC_CORBSIZE_CORBSZCAP_2
)
1355 device_printf(sc
->dev
, "%s: Invalid corb size (%x)\n",
1356 __func__
, corbsize
);
1360 rirbsize
= HDAC_READ_1(&sc
->mem
, HDAC_RIRBSIZE
);
1361 if ((rirbsize
& HDAC_RIRBSIZE_RIRBSZCAP_256
) ==
1362 HDAC_RIRBSIZE_RIRBSZCAP_256
)
1363 sc
->rirb_size
= 256;
1364 else if ((rirbsize
& HDAC_RIRBSIZE_RIRBSZCAP_16
) ==
1365 HDAC_RIRBSIZE_RIRBSZCAP_16
)
1367 else if ((rirbsize
& HDAC_RIRBSIZE_RIRBSZCAP_2
) ==
1368 HDAC_RIRBSIZE_RIRBSZCAP_2
)
1371 device_printf(sc
->dev
, "%s: Invalid rirb size (%x)\n",
1372 __func__
, rirbsize
);
1380 /****************************************************************************
1383 * This function is called by bus_dmamap_load when the mapping has been
1384 * established. We just record the physical address of the mapping into
1385 * the struct hdac_dma passed in.
1386 ****************************************************************************/
1388 hdac_dma_cb(void *callback_arg
, bus_dma_segment_t
*segs
, int nseg
, int error
)
1390 struct hdac_dma
*dma
;
1393 dma
= (struct hdac_dma
*)callback_arg
;
1394 dma
->dma_paddr
= segs
[0].ds_addr
;
1399 /****************************************************************************
1400 * int hdac_dma_alloc
1402 * This function allocate and setup a dma region (struct hdac_dma).
1403 * It must be freed by a corresponding hdac_dma_free.
1404 ****************************************************************************/
1406 hdac_dma_alloc(struct hdac_softc
*sc
, struct hdac_dma
*dma
, bus_size_t size
)
1412 roundsz
= roundup2(size
, HDAC_DMA_ALIGNMENT
);
1413 lowaddr
= (sc
->support_64bit
) ? BUS_SPACE_MAXADDR
:
1414 BUS_SPACE_MAXADDR_32BIT
;
1415 bzero(dma
, sizeof(*dma
));
1420 result
= bus_dma_tag_create(NULL
, /* parent */
1421 HDAC_DMA_ALIGNMENT
, /* alignment */
1423 lowaddr
, /* lowaddr */
1424 BUS_SPACE_MAXADDR
, /* highaddr */
1425 NULL
, /* filtfunc */
1426 NULL
, /* fistfuncarg */
1427 roundsz
, /* maxsize */
1429 roundsz
, /* maxsegsz */
1431 &dma
->dma_tag
); /* dmat */
1433 device_printf(sc
->dev
, "%s: bus_dma_tag_create failed (%x)\n",
1435 goto hdac_dma_alloc_fail
;
1439 * Allocate DMA memory
1441 #if 0 /* TODO: No uncacheable DMA support in DragonFly. */
1442 result
= bus_dmamem_alloc(dma
->dma_tag
, (void **)&dma
->dma_vaddr
,
1443 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
|
1444 ((sc
->flags
& HDAC_F_DMA_NOCACHE
) ? BUS_DMA_NOCACHE
: 0),
1447 result
= bus_dmamem_alloc(dma
->dma_tag
, (void **)&dma
->dma_vaddr
,
1448 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &dma
->dma_map
);
1451 device_printf(sc
->dev
, "%s: bus_dmamem_alloc failed (%x)\n",
1453 goto hdac_dma_alloc_fail
;
1456 dma
->dma_size
= roundsz
;
1461 result
= bus_dmamap_load(dma
->dma_tag
, dma
->dma_map
,
1462 (void *)dma
->dma_vaddr
, roundsz
, hdac_dma_cb
, (void *)dma
, 0);
1463 if (result
!= 0 || dma
->dma_paddr
== 0) {
1466 device_printf(sc
->dev
, "%s: bus_dmamem_load failed (%x)\n",
1468 goto hdac_dma_alloc_fail
;
1472 device_printf(sc
->dev
, "%s: size=%ju -> roundsz=%ju\n",
1473 __func__
, (uintmax_t)size
, (uintmax_t)roundsz
);
1478 hdac_dma_alloc_fail
:
1479 hdac_dma_free(sc
, dma
);
1485 /****************************************************************************
1486 * void hdac_dma_free(struct hdac_softc *, struct hdac_dma *)
1488 * Free a struct dhac_dma that has been previously allocated via the
1489 * hdac_dma_alloc function.
1490 ****************************************************************************/
1492 hdac_dma_free(struct hdac_softc
*sc
, struct hdac_dma
*dma
)
1494 if (dma
->dma_map
!= NULL
) {
1497 bus_dmamap_sync(dma
->dma_tag
, dma
->dma_map
,
1498 BUS_DMASYNC_POSTREAD
| BUS_DMASYNC_POSTWRITE
);
1500 bus_dmamap_unload(dma
->dma_tag
, dma
->dma_map
);
1502 if (dma
->dma_vaddr
!= NULL
) {
1503 bus_dmamem_free(dma
->dma_tag
, dma
->dma_vaddr
, dma
->dma_map
);
1504 dma
->dma_vaddr
= NULL
;
1506 dma
->dma_map
= NULL
;
1507 if (dma
->dma_tag
!= NULL
) {
1508 bus_dma_tag_destroy(dma
->dma_tag
);
1509 dma
->dma_tag
= NULL
;
1514 /****************************************************************************
1515 * int hdac_mem_alloc(struct hdac_softc *)
1517 * Allocate all the bus resources necessary to speak with the physical
1519 ****************************************************************************/
1521 hdac_mem_alloc(struct hdac_softc
*sc
)
1523 struct hdac_mem
*mem
;
1526 mem
->mem_rid
= PCIR_BAR(0);
1527 mem
->mem_res
= bus_alloc_resource_any(sc
->dev
, SYS_RES_MEMORY
,
1528 &mem
->mem_rid
, RF_ACTIVE
);
1529 if (mem
->mem_res
== NULL
) {
1530 device_printf(sc
->dev
,
1531 "%s: Unable to allocate memory resource\n", __func__
);
1534 mem
->mem_tag
= rman_get_bustag(mem
->mem_res
);
1535 mem
->mem_handle
= rman_get_bushandle(mem
->mem_res
);
1540 /****************************************************************************
1541 * void hdac_mem_free(struct hdac_softc *)
1543 * Free up resources previously allocated by hdac_mem_alloc.
1544 ****************************************************************************/
1546 hdac_mem_free(struct hdac_softc
*sc
)
1548 struct hdac_mem
*mem
;
1551 if (mem
->mem_res
!= NULL
)
1552 bus_release_resource(sc
->dev
, SYS_RES_MEMORY
, mem
->mem_rid
,
1554 mem
->mem_res
= NULL
;
1557 /****************************************************************************
1558 * int hdac_irq_alloc(struct hdac_softc *)
1560 * Allocate and setup the resources necessary for interrupt handling.
1561 ****************************************************************************/
1563 hdac_irq_alloc(struct hdac_softc
*sc
)
1565 struct hdac_irq
*irq
;
1571 #if 0 /* TODO: No MSI support in DragonFly yet. */
1572 if ((sc
->flags
& HDAC_F_MSI
) &&
1573 (result
= pci_msi_count(sc
->dev
)) == 1 &&
1574 pci_alloc_msi(sc
->dev
, &result
) == 0)
1578 sc
->flags
&= ~HDAC_F_MSI
;
1580 irq
->irq_res
= bus_alloc_resource_any(sc
->dev
, SYS_RES_IRQ
,
1581 &irq
->irq_rid
, RF_SHAREABLE
| RF_ACTIVE
);
1582 if (irq
->irq_res
== NULL
) {
1583 device_printf(sc
->dev
, "%s: Unable to allocate irq\n",
1585 goto hdac_irq_alloc_fail
;
1587 result
= snd_setup_intr(sc
->dev
, irq
->irq_res
, INTR_MPSAFE
,
1588 hdac_intr_handler
, sc
, &irq
->irq_handle
);
1590 device_printf(sc
->dev
,
1591 "%s: Unable to setup interrupt handler (%x)\n",
1593 goto hdac_irq_alloc_fail
;
1598 hdac_irq_alloc_fail
:
1604 /****************************************************************************
1605 * void hdac_irq_free(struct hdac_softc *)
1607 * Free up resources previously allocated by hdac_irq_alloc.
1608 ****************************************************************************/
1610 hdac_irq_free(struct hdac_softc
*sc
)
1612 struct hdac_irq
*irq
;
1615 if (irq
->irq_res
!= NULL
&& irq
->irq_handle
!= NULL
)
1616 bus_teardown_intr(sc
->dev
, irq
->irq_res
, irq
->irq_handle
);
1617 if (irq
->irq_res
!= NULL
)
1618 bus_release_resource(sc
->dev
, SYS_RES_IRQ
, irq
->irq_rid
,
1620 #if 0 /* TODO: No MSI support in DragonFly yet. */
1621 if ((sc
->flags
& HDAC_F_MSI
) && irq
->irq_rid
== 0x1)
1622 pci_release_msi(sc
->dev
);
1624 irq
->irq_handle
= NULL
;
1625 irq
->irq_res
= NULL
;
1629 /****************************************************************************
1630 * void hdac_corb_init(struct hdac_softc *)
1632 * Initialize the corb registers for operations but do not start it up yet.
1633 * The CORB engine must not be running when this function is called.
1634 ****************************************************************************/
1636 hdac_corb_init(struct hdac_softc
*sc
)
1641 /* Setup the CORB size. */
1642 switch (sc
->corb_size
) {
1644 corbsize
= HDAC_CORBSIZE_CORBSIZE(HDAC_CORBSIZE_CORBSIZE_256
);
1647 corbsize
= HDAC_CORBSIZE_CORBSIZE(HDAC_CORBSIZE_CORBSIZE_16
);
1650 corbsize
= HDAC_CORBSIZE_CORBSIZE(HDAC_CORBSIZE_CORBSIZE_2
);
1653 panic("%s: Invalid CORB size (%x)\n", __func__
, sc
->corb_size
);
1655 HDAC_WRITE_1(&sc
->mem
, HDAC_CORBSIZE
, corbsize
);
1657 /* Setup the CORB Address in the hdac */
1658 corbpaddr
= (uint64_t)sc
->corb_dma
.dma_paddr
;
1659 HDAC_WRITE_4(&sc
->mem
, HDAC_CORBLBASE
, (uint32_t)corbpaddr
);
1660 HDAC_WRITE_4(&sc
->mem
, HDAC_CORBUBASE
, (uint32_t)(corbpaddr
>> 32));
1662 /* Set the WP and RP */
1664 HDAC_WRITE_2(&sc
->mem
, HDAC_CORBWP
, sc
->corb_wp
);
1665 HDAC_WRITE_2(&sc
->mem
, HDAC_CORBRP
, HDAC_CORBRP_CORBRPRST
);
1667 * The HDA specification indicates that the CORBRPRST bit will always
1668 * read as zero. Unfortunately, it seems that at least the 82801G
1669 * doesn't reset the bit to zero, which stalls the corb engine.
1670 * manually reset the bit to zero before continuing.
1672 HDAC_WRITE_2(&sc
->mem
, HDAC_CORBRP
, 0x0);
1674 /* Enable CORB error reporting */
1676 HDAC_WRITE_1(&sc
->mem
, HDAC_CORBCTL
, HDAC_CORBCTL_CMEIE
);
1680 /****************************************************************************
1681 * void hdac_rirb_init(struct hdac_softc *)
1683 * Initialize the rirb registers for operations but do not start it up yet.
1684 * The RIRB engine must not be running when this function is called.
1685 ****************************************************************************/
1687 hdac_rirb_init(struct hdac_softc
*sc
)
1692 /* Setup the RIRB size. */
1693 switch (sc
->rirb_size
) {
1695 rirbsize
= HDAC_RIRBSIZE_RIRBSIZE(HDAC_RIRBSIZE_RIRBSIZE_256
);
1698 rirbsize
= HDAC_RIRBSIZE_RIRBSIZE(HDAC_RIRBSIZE_RIRBSIZE_16
);
1701 rirbsize
= HDAC_RIRBSIZE_RIRBSIZE(HDAC_RIRBSIZE_RIRBSIZE_2
);
1704 panic("%s: Invalid RIRB size (%x)\n", __func__
, sc
->rirb_size
);
1706 HDAC_WRITE_1(&sc
->mem
, HDAC_RIRBSIZE
, rirbsize
);
1708 /* Setup the RIRB Address in the hdac */
1709 rirbpaddr
= (uint64_t)sc
->rirb_dma
.dma_paddr
;
1710 HDAC_WRITE_4(&sc
->mem
, HDAC_RIRBLBASE
, (uint32_t)rirbpaddr
);
1711 HDAC_WRITE_4(&sc
->mem
, HDAC_RIRBUBASE
, (uint32_t)(rirbpaddr
>> 32));
1713 /* Setup the WP and RP */
1715 HDAC_WRITE_2(&sc
->mem
, HDAC_RIRBWP
, HDAC_RIRBWP_RIRBWPRST
);
1717 if (sc
->polling
== 0) {
1718 /* Setup the interrupt threshold */
1719 HDAC_WRITE_2(&sc
->mem
, HDAC_RINTCNT
, sc
->rirb_size
/ 2);
1721 /* Enable Overrun and response received reporting */
1723 HDAC_WRITE_1(&sc
->mem
, HDAC_RIRBCTL
,
1724 HDAC_RIRBCTL_RIRBOIC
| HDAC_RIRBCTL_RINTCTL
);
1726 HDAC_WRITE_1(&sc
->mem
, HDAC_RIRBCTL
, HDAC_RIRBCTL_RINTCTL
);
1732 * Make sure that the Host CPU cache doesn't contain any dirty
1733 * cache lines that falls in the rirb. If I understood correctly, it
1734 * should be sufficient to do this only once as the rirb is purely
1735 * read-only from now on.
1737 bus_dmamap_sync(sc
->rirb_dma
.dma_tag
, sc
->rirb_dma
.dma_map
,
1738 BUS_DMASYNC_PREREAD
);
1742 /****************************************************************************
1743 * void hdac_corb_start(hdac_softc *)
1745 * Startup the corb DMA engine
1746 ****************************************************************************/
1748 hdac_corb_start(struct hdac_softc
*sc
)
1752 corbctl
= HDAC_READ_1(&sc
->mem
, HDAC_CORBCTL
);
1753 corbctl
|= HDAC_CORBCTL_CORBRUN
;
1754 HDAC_WRITE_1(&sc
->mem
, HDAC_CORBCTL
, corbctl
);
1757 /****************************************************************************
1758 * void hdac_rirb_start(hdac_softc *)
1760 * Startup the rirb DMA engine
1761 ****************************************************************************/
1763 hdac_rirb_start(struct hdac_softc
*sc
)
1767 rirbctl
= HDAC_READ_1(&sc
->mem
, HDAC_RIRBCTL
);
1768 rirbctl
|= HDAC_RIRBCTL_RIRBDMAEN
;
1769 HDAC_WRITE_1(&sc
->mem
, HDAC_RIRBCTL
, rirbctl
);
1773 /****************************************************************************
1774 * void hdac_scan_codecs(struct hdac_softc *, int)
1776 * Scan the bus for available codecs, starting with num.
1777 ****************************************************************************/
1779 hdac_scan_codecs(struct hdac_softc
*sc
, int num
)
1781 struct hdac_codec
*codec
;
1787 if (num
>= HDAC_CODEC_MAX
)
1788 num
= HDAC_CODEC_MAX
- 1;
1790 statests
= HDAC_READ_2(&sc
->mem
, HDAC_STATESTS
);
1791 for (i
= num
; i
< HDAC_CODEC_MAX
; i
++) {
1792 if (HDAC_STATESTS_SDIWAKE(statests
, i
)) {
1793 /* We have found a codec. */
1794 codec
= (struct hdac_codec
*)kmalloc(sizeof(*codec
),
1795 M_HDAC
, M_ZERO
| M_NOWAIT
);
1796 if (codec
== NULL
) {
1797 device_printf(sc
->dev
,
1798 "Unable to allocate memory for codec\n");
1801 codec
->commands
= NULL
;
1802 codec
->responses_received
= 0;
1803 codec
->verbs_sent
= 0;
1806 sc
->codecs
[i
] = codec
;
1807 if (hdac_probe_codec(codec
) != 0)
1811 /* All codecs have been probed, now try to attach drivers to them */
1812 /* bus_generic_attach(sc->dev); */
1815 /****************************************************************************
1816 * void hdac_probe_codec(struct hdac_softc *, int)
1818 * Probe a the given codec_id for available function groups.
1819 ****************************************************************************/
1821 hdac_probe_codec(struct hdac_codec
*codec
)
1823 struct hdac_softc
*sc
= codec
->sc
;
1824 struct hdac_devinfo
*devinfo
;
1825 uint32_t vendorid
, revisionid
, subnode
;
1829 nid_t cad
= codec
->cad
;
1832 device_printf(sc
->dev
, "HDA_DEBUG: Probing codec: %d\n", cad
);
1834 vendorid
= hdac_command(sc
,
1835 HDA_CMD_GET_PARAMETER(cad
, 0x0, HDA_PARAM_VENDOR_ID
),
1837 revisionid
= hdac_command(sc
,
1838 HDA_CMD_GET_PARAMETER(cad
, 0x0, HDA_PARAM_REVISION_ID
),
1840 subnode
= hdac_command(sc
,
1841 HDA_CMD_GET_PARAMETER(cad
, 0x0, HDA_PARAM_SUB_NODE_COUNT
),
1843 startnode
= HDA_PARAM_SUB_NODE_COUNT_START(subnode
);
1844 endnode
= startnode
+ HDA_PARAM_SUB_NODE_COUNT_TOTAL(subnode
);
1847 device_printf(sc
->dev
, "HDA_DEBUG: \tstartnode=%d endnode=%d\n",
1848 startnode
, endnode
);
1850 for (i
= startnode
; i
< endnode
; i
++) {
1851 devinfo
= hdac_probe_function(codec
, i
);
1852 if (devinfo
!= NULL
) {
1853 /* XXX Ignore other FG. */
1854 devinfo
->vendor_id
=
1855 HDA_PARAM_VENDOR_ID_VENDOR_ID(vendorid
);
1856 devinfo
->device_id
=
1857 HDA_PARAM_VENDOR_ID_DEVICE_ID(vendorid
);
1858 devinfo
->revision_id
=
1859 HDA_PARAM_REVISION_ID_REVISION_ID(revisionid
);
1860 devinfo
->stepping_id
=
1861 HDA_PARAM_REVISION_ID_STEPPING_ID(revisionid
);
1863 device_printf(sc
->dev
,
1864 "HDA_DEBUG: \tFound AFG nid=%d "
1865 "[startnode=%d endnode=%d]\n",
1866 devinfo
->nid
, startnode
, endnode
);
1873 device_printf(sc
->dev
, "HDA_DEBUG: \tAFG not found\n");
1878 static struct hdac_devinfo
*
1879 hdac_probe_function(struct hdac_codec
*codec
, nid_t nid
)
1881 struct hdac_softc
*sc
= codec
->sc
;
1882 struct hdac_devinfo
*devinfo
;
1883 uint32_t fctgrptype
;
1884 nid_t cad
= codec
->cad
;
1886 fctgrptype
= HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE(hdac_command(sc
,
1887 HDA_CMD_GET_PARAMETER(cad
, nid
, HDA_PARAM_FCT_GRP_TYPE
), cad
));
1889 /* XXX For now, ignore other FG. */
1890 if (fctgrptype
!= HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO
)
1893 devinfo
= (struct hdac_devinfo
*)kmalloc(sizeof(*devinfo
), M_HDAC
,
1895 if (devinfo
== NULL
) {
1896 device_printf(sc
->dev
, "%s: Unable to allocate ivar\n",
1902 devinfo
->node_type
= fctgrptype
;
1903 devinfo
->codec
= codec
;
1905 hdac_add_child(sc
, devinfo
);
1911 hdac_add_child(struct hdac_softc
*sc
, struct hdac_devinfo
*devinfo
)
1913 devinfo
->dev
= device_add_child(sc
->dev
, NULL
, -1);
1914 device_set_ivars(devinfo
->dev
, (void *)devinfo
);
1915 /* XXX - Print more information when booting verbose??? */
1919 hdac_widget_connection_parse(struct hdac_widget
*w
)
1921 struct hdac_softc
*sc
= w
->devinfo
->codec
->sc
;
1923 int i
, j
, max
, ents
, entnum
;
1924 nid_t cad
= w
->devinfo
->codec
->cad
;
1926 nid_t cnid
, addcnid
, prevcnid
;
1930 res
= hdac_command(sc
,
1931 HDA_CMD_GET_PARAMETER(cad
, nid
, HDA_PARAM_CONN_LIST_LENGTH
), cad
);
1933 ents
= HDA_PARAM_CONN_LIST_LENGTH_LIST_LENGTH(res
);
1938 entnum
= HDA_PARAM_CONN_LIST_LENGTH_LONG_FORM(res
) ? 2 : 4;
1939 max
= (sizeof(w
->conns
) / sizeof(w
->conns
[0])) - 1;
1942 #define CONN_RMASK(e) (1 << ((32 / (e)) - 1))
1943 #define CONN_NMASK(e) (CONN_RMASK(e) - 1)
1944 #define CONN_RESVAL(r, e, n) ((r) >> ((32 / (e)) * (n)))
1945 #define CONN_RANGE(r, e, n) (CONN_RESVAL(r, e, n) & CONN_RMASK(e))
1946 #define CONN_CNID(r, e, n) (CONN_RESVAL(r, e, n) & CONN_NMASK(e))
1948 for (i
= 0; i
< ents
; i
+= entnum
) {
1949 res
= hdac_command(sc
,
1950 HDA_CMD_GET_CONN_LIST_ENTRY(cad
, nid
, i
), cad
);
1951 for (j
= 0; j
< entnum
; j
++) {
1952 cnid
= CONN_CNID(res
, entnum
, j
);
1954 if (w
->nconns
< ents
)
1955 device_printf(sc
->dev
,
1956 "%s: nid=%d WARNING: zero cnid "
1957 "entnum=%d j=%d index=%d "
1958 "entries=%d found=%d res=0x%08x\n",
1959 __func__
, nid
, entnum
, j
, i
,
1960 ents
, w
->nconns
, res
);
1964 if (cnid
< w
->devinfo
->startnode
||
1965 cnid
>= w
->devinfo
->endnode
) {
1967 device_printf(sc
->dev
,
1968 "%s: GHOST: nid=%d j=%d "
1969 "entnum=%d index=%d res=0x%08x\n",
1970 __func__
, nid
, j
, entnum
, i
, res
);
1973 if (CONN_RANGE(res
, entnum
, j
) == 0)
1975 else if (prevcnid
== 0 || prevcnid
>= cnid
) {
1976 device_printf(sc
->dev
,
1977 "%s: WARNING: Invalid child range "
1978 "nid=%d index=%d j=%d entnum=%d "
1979 "prevcnid=%d cnid=%d res=0x%08x\n",
1980 __func__
, nid
, i
, j
, entnum
, prevcnid
,
1984 addcnid
= prevcnid
+ 1;
1985 while (addcnid
<= cnid
) {
1986 if (w
->nconns
> max
) {
1987 device_printf(sc
->dev
,
1988 "%s: nid=%d: Adding %d: "
1989 "Max connection reached! max=%d\n",
1990 __func__
, nid
, addcnid
, max
+ 1);
1993 w
->conns
[w
->nconns
++] = addcnid
++;
2001 device_printf(sc
->dev
,
2002 "HDA_DEBUG: %s: nid=%d entries=%d found=%d\n",
2003 __func__
, nid
, ents
, w
->nconns
);
2009 hdac_widget_pin_getconfig(struct hdac_widget
*w
)
2011 struct hdac_softc
*sc
;
2012 uint32_t config
, orig
, id
;
2015 sc
= w
->devinfo
->codec
->sc
;
2016 cad
= w
->devinfo
->codec
->cad
;
2018 id
= hdac_codec_id(w
->devinfo
);
2020 config
= hdac_command(sc
,
2021 HDA_CMD_GET_CONFIGURATION_DEFAULT(cad
, nid
),
2026 * XXX REWRITE!!!! Don't argue!
2028 if (id
== HDA_CODEC_ALC880
&& sc
->pci_subvendor
== LG_LW20_SUBVENDOR
) {
2031 config
&= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
;
2032 config
|= HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN
;
2035 config
&= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
;
2036 config
|= HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT
;
2041 } else if (id
== HDA_CODEC_ALC880
&&
2042 (sc
->pci_subvendor
== CLEVO_D900T_SUBVENDOR
||
2043 sc
->pci_subvendor
== ASUS_M5200_SUBVENDOR
)) {
2057 config
&= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
;
2058 config
|= HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN
;
2060 case 25: /* XXX MIC2 */
2061 config
&= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
;
2062 config
|= HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN
;
2064 case 26: /* LINE1 */
2065 config
&= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
;
2066 config
|= HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN
;
2068 case 27: /* XXX LINE2 */
2069 config
&= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
;
2070 config
|= HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN
;
2073 config
&= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
;
2074 config
|= HDA_CONFIG_DEFAULTCONF_DEVICE_CD
;
2083 } else if (id
== HDA_CODEC_ALC883
&&
2084 (sc
->pci_subvendor
== MSI_MS034A_SUBVENDOR
||
2085 HDA_DEV_MATCH(ACER_ALL_SUBVENDOR
, sc
->pci_subvendor
))) {
2088 config
&= ~(HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
|
2089 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK
);
2090 config
|= (HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN
|
2091 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_FIXED
);
2094 config
&= ~(HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
|
2095 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK
);
2096 config
|= (HDA_CONFIG_DEFAULTCONF_DEVICE_CD
|
2097 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_FIXED
);
2102 } else if (id
== HDA_CODEC_CXVENICE
&& sc
->pci_subvendor
==
2103 HP_V3000_SUBVENDOR
) {
2106 config
&= ~HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK
;
2107 config
|= HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_NONE
;
2110 config
&= ~(HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
|
2111 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK
);
2112 config
|= (HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN
|
2113 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_FIXED
);
2116 config
&= ~(HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
|
2117 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK
);
2118 config
|= (HDA_CONFIG_DEFAULTCONF_DEVICE_CD
|
2119 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_FIXED
);
2124 } else if (id
== HDA_CODEC_CXWAIKIKI
&& sc
->pci_subvendor
==
2125 HP_DV5000_SUBVENDOR
) {
2129 config
&= ~HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK
;
2130 config
|= HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_NONE
;
2135 } else if (id
== HDA_CODEC_ALC861
&& sc
->pci_subvendor
==
2136 ASUS_W6F_SUBVENDOR
) {
2139 config
&= ~(HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
|
2140 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK
);
2141 config
|= (HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_OUT
|
2142 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_FIXED
);
2145 config
&= ~(HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
|
2146 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK
);
2147 config
|= (HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT
|
2148 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_JACK
);
2153 } else if (id
== HDA_CODEC_ALC861
&& sc
->pci_subvendor
==
2154 UNIWILL_9075_SUBVENDOR
) {
2157 config
&= ~(HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
|
2158 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK
);
2159 config
|= (HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT
|
2160 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_JACK
);
2165 } else if (id
== HDA_CODEC_AD1986A
&&
2166 (sc
->pci_subvendor
== ASUS_M2NPVMX_SUBVENDOR
||
2167 sc
->pci_subvendor
== ASUS_A8NVMCSM_SUBVENDOR
)) {
2170 config
&= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
;
2171 config
|= HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN
;
2174 config
&= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
;
2175 config
|= HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN
;
2184 device_printf(sc
->dev
,
2185 "HDA_DEBUG: Pin config nid=%u 0x%08x -> 0x%08x\n",
2193 hdac_widget_pin_getcaps(struct hdac_widget
*w
)
2195 struct hdac_softc
*sc
;
2196 uint32_t caps
, orig
, id
;
2199 sc
= w
->devinfo
->codec
->sc
;
2200 cad
= w
->devinfo
->codec
->cad
;
2202 id
= hdac_codec_id(w
->devinfo
);
2204 caps
= hdac_command(sc
,
2205 HDA_CMD_GET_PARAMETER(cad
, nid
, HDA_PARAM_PIN_CAP
), cad
);
2210 device_printf(sc
->dev
,
2211 "HDA_DEBUG: Pin caps nid=%u 0x%08x -> 0x%08x\n",
2219 hdac_widget_pin_parse(struct hdac_widget
*w
)
2221 struct hdac_softc
*sc
= w
->devinfo
->codec
->sc
;
2222 uint32_t config
, pincap
;
2223 char *devstr
, *connstr
;
2224 nid_t cad
= w
->devinfo
->codec
->cad
;
2227 config
= hdac_widget_pin_getconfig(w
);
2228 w
->wclass
.pin
.config
= config
;
2230 pincap
= hdac_widget_pin_getcaps(w
);
2231 w
->wclass
.pin
.cap
= pincap
;
2233 w
->wclass
.pin
.ctrl
= hdac_command(sc
,
2234 HDA_CMD_GET_PIN_WIDGET_CTRL(cad
, nid
), cad
) &
2235 ~(HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE
|
2236 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE
|
2237 HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE
|
2238 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK
);
2240 if (HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap
))
2241 w
->wclass
.pin
.ctrl
|= HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE
;
2242 if (HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap
))
2243 w
->wclass
.pin
.ctrl
|= HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE
;
2244 if (HDA_PARAM_PIN_CAP_INPUT_CAP(pincap
))
2245 w
->wclass
.pin
.ctrl
|= HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE
;
2246 if (HDA_PARAM_PIN_CAP_EAPD_CAP(pincap
)) {
2247 w
->param
.eapdbtl
= hdac_command(sc
,
2248 HDA_CMD_GET_EAPD_BTL_ENABLE(cad
, nid
), cad
);
2249 w
->param
.eapdbtl
&= 0x7;
2250 w
->param
.eapdbtl
|= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD
;
2252 w
->param
.eapdbtl
= HDAC_INVALID
;
2254 switch (config
& HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
) {
2255 case HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_OUT
:
2256 devstr
= "line out";
2258 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER
:
2261 case HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT
:
2262 devstr
= "headphones out";
2264 case HDA_CONFIG_DEFAULTCONF_DEVICE_CD
:
2267 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_OUT
:
2268 devstr
= "SPDIF out";
2270 case HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_OUT
:
2271 devstr
= "digital (other) out";
2273 case HDA_CONFIG_DEFAULTCONF_DEVICE_MODEM_LINE
:
2274 devstr
= "modem, line side";
2276 case HDA_CONFIG_DEFAULTCONF_DEVICE_MODEM_HANDSET
:
2277 devstr
= "modem, handset side";
2279 case HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN
:
2282 case HDA_CONFIG_DEFAULTCONF_DEVICE_AUX
:
2285 case HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN
:
2288 case HDA_CONFIG_DEFAULTCONF_DEVICE_TELEPHONY
:
2289 devstr
= "telephony";
2291 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_IN
:
2292 devstr
= "SPDIF in";
2294 case HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_IN
:
2295 devstr
= "digital (other) in";
2297 case HDA_CONFIG_DEFAULTCONF_DEVICE_OTHER
:
2305 switch (config
& HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK
) {
2306 case HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_JACK
:
2309 case HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_NONE
:
2312 case HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_FIXED
:
2315 case HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_BOTH
:
2316 connstr
= "jack / fixed";
2319 connstr
= "unknown";
2323 strlcat(w
->name
, ": ", sizeof(w
->name
));
2324 strlcat(w
->name
, devstr
, sizeof(w
->name
));
2325 strlcat(w
->name
, " (", sizeof(w
->name
));
2326 strlcat(w
->name
, connstr
, sizeof(w
->name
));
2327 strlcat(w
->name
, ")", sizeof(w
->name
));
2331 hdac_widget_parse(struct hdac_widget
*w
)
2333 struct hdac_softc
*sc
= w
->devinfo
->codec
->sc
;
2336 nid_t cad
= w
->devinfo
->codec
->cad
;
2339 wcap
= hdac_command(sc
,
2340 HDA_CMD_GET_PARAMETER(cad
, nid
, HDA_PARAM_AUDIO_WIDGET_CAP
),
2342 w
->param
.widget_cap
= wcap
;
2343 w
->type
= HDA_PARAM_AUDIO_WIDGET_CAP_TYPE(wcap
);
2346 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT
:
2347 typestr
= "audio output";
2349 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT
:
2350 typestr
= "audio input";
2352 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER
:
2353 typestr
= "audio mixer";
2355 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR
:
2356 typestr
= "audio selector";
2358 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
:
2361 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_POWER_WIDGET
:
2362 typestr
= "power widget";
2364 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_VOLUME_WIDGET
:
2365 typestr
= "volume widget";
2367 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET
:
2368 typestr
= "beep widget";
2370 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_VENDOR_WIDGET
:
2371 typestr
= "vendor widget";
2374 typestr
= "unknown type";
2378 strlcpy(w
->name
, typestr
, sizeof(w
->name
));
2380 if (HDA_PARAM_AUDIO_WIDGET_CAP_POWER_CTRL(wcap
)) {
2382 HDA_CMD_SET_POWER_STATE(cad
, nid
, HDA_CMD_POWER_STATE_D0
),
2387 hdac_widget_connection_parse(w
);
2389 if (HDA_PARAM_AUDIO_WIDGET_CAP_OUT_AMP(wcap
)) {
2390 if (HDA_PARAM_AUDIO_WIDGET_CAP_AMP_OVR(wcap
))
2391 w
->param
.outamp_cap
=
2393 HDA_CMD_GET_PARAMETER(cad
, nid
,
2394 HDA_PARAM_OUTPUT_AMP_CAP
), cad
);
2396 w
->param
.outamp_cap
=
2397 w
->devinfo
->function
.audio
.outamp_cap
;
2399 w
->param
.outamp_cap
= 0;
2401 if (HDA_PARAM_AUDIO_WIDGET_CAP_IN_AMP(wcap
)) {
2402 if (HDA_PARAM_AUDIO_WIDGET_CAP_AMP_OVR(wcap
))
2403 w
->param
.inamp_cap
=
2405 HDA_CMD_GET_PARAMETER(cad
, nid
,
2406 HDA_PARAM_INPUT_AMP_CAP
), cad
);
2408 w
->param
.inamp_cap
=
2409 w
->devinfo
->function
.audio
.inamp_cap
;
2411 w
->param
.inamp_cap
= 0;
2413 if (w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT
||
2414 w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT
) {
2415 if (HDA_PARAM_AUDIO_WIDGET_CAP_FORMAT_OVR(wcap
)) {
2416 cap
= hdac_command(sc
,
2417 HDA_CMD_GET_PARAMETER(cad
, nid
,
2418 HDA_PARAM_SUPP_STREAM_FORMATS
), cad
);
2419 w
->param
.supp_stream_formats
= (cap
!= 0) ? cap
:
2420 w
->devinfo
->function
.audio
.supp_stream_formats
;
2421 cap
= hdac_command(sc
,
2422 HDA_CMD_GET_PARAMETER(cad
, nid
,
2423 HDA_PARAM_SUPP_PCM_SIZE_RATE
), cad
);
2424 w
->param
.supp_pcm_size_rate
= (cap
!= 0) ? cap
:
2425 w
->devinfo
->function
.audio
.supp_pcm_size_rate
;
2427 w
->param
.supp_stream_formats
=
2428 w
->devinfo
->function
.audio
.supp_stream_formats
;
2429 w
->param
.supp_pcm_size_rate
=
2430 w
->devinfo
->function
.audio
.supp_pcm_size_rate
;
2433 w
->param
.supp_stream_formats
= 0;
2434 w
->param
.supp_pcm_size_rate
= 0;
2437 if (w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
)
2438 hdac_widget_pin_parse(w
);
2441 static struct hdac_widget
*
2442 hdac_widget_get(struct hdac_devinfo
*devinfo
, nid_t nid
)
2444 if (devinfo
== NULL
|| devinfo
->widget
== NULL
||
2445 nid
< devinfo
->startnode
|| nid
>= devinfo
->endnode
)
2447 return (&devinfo
->widget
[nid
- devinfo
->startnode
]);
2451 hda_poll_channel(struct hdac_chan
*ch
)
2454 volatile uint32_t ptr
;
2456 if (!(ch
->flags
& HDAC_CHN_RUNNING
))
2459 sz
= ch
->blksz
* ch
->blkcnt
;
2460 if (ch
->dmapos
!= NULL
)
2461 ptr
= *(ch
->dmapos
);
2463 ptr
= HDAC_READ_4(&ch
->devinfo
->codec
->sc
->mem
,
2464 ch
->off
+ HDAC_SDLPIB
);
2467 ptr
&= ~(ch
->blksz
- 1);
2468 delta
= (sz
+ ptr
- ch
->prevptr
) % sz
;
2470 if (delta
< ch
->blksz
)
2478 #define hda_chan_active(sc) (((sc)->play.flags | (sc)->rec.flags) & \
2482 hda_poll_callback(void *arg
)
2484 struct hdac_softc
*sc
= arg
;
2491 if (sc
->polling
== 0 || hda_chan_active(sc
) == 0) {
2497 trigger
|= (hda_poll_channel(&sc
->play
) != 0) ? HDAC_TRIGGER_PLAY
: 0;
2498 trigger
|= (hda_poll_channel(&sc
->rec
)) != 0 ? HDAC_TRIGGER_REC
: 0;
2501 callout_reset(&sc
->poll_hda
, 1/*sc->poll_ticks*/,
2502 hda_poll_callback
, sc
);
2506 if (trigger
& HDAC_TRIGGER_PLAY
)
2507 chn_intr(sc
->play
.c
);
2508 if (trigger
& HDAC_TRIGGER_REC
)
2509 chn_intr(sc
->rec
.c
);
2513 hdac_rirb_flush(struct hdac_softc
*sc
)
2515 struct hdac_rirb
*rirb_base
, *rirb
;
2516 struct hdac_codec
*codec
;
2517 struct hdac_command_list
*commands
;
2523 rirb_base
= (struct hdac_rirb
*)sc
->rirb_dma
.dma_vaddr
;
2524 rirbwp
= HDAC_READ_1(&sc
->mem
, HDAC_RIRBWP
);
2526 bus_dmamap_sync(sc
->rirb_dma
.dma_tag
, sc
->rirb_dma
.dma_map
,
2527 BUS_DMASYNC_POSTREAD
);
2531 while (sc
->rirb_rp
!= rirbwp
) {
2533 sc
->rirb_rp
%= sc
->rirb_size
;
2534 rirb
= &rirb_base
[sc
->rirb_rp
];
2535 cad
= HDAC_RIRB_RESPONSE_EX_SDATA_IN(rirb
->response_ex
);
2536 if (cad
< 0 || cad
>= HDAC_CODEC_MAX
||
2537 sc
->codecs
[cad
] == NULL
)
2539 resp
= rirb
->response
;
2540 codec
= sc
->codecs
[cad
];
2541 commands
= codec
->commands
;
2542 if (rirb
->response_ex
& HDAC_RIRB_RESPONSE_EX_UNSOLICITED
) {
2543 sc
->unsolq
[sc
->unsolq_wp
++] = (cad
<< 16) |
2544 ((resp
>> 26) & 0xffff);
2545 sc
->unsolq_wp
%= HDAC_UNSOLQ_MAX
;
2546 } else if (commands
!= NULL
&& commands
->num_commands
> 0 &&
2547 codec
->responses_received
< commands
->num_commands
)
2548 commands
->responses
[codec
->responses_received
++] =
2557 hdac_unsolq_flush(struct hdac_softc
*sc
)
2563 if (sc
->unsolq_st
== HDAC_UNSOLQ_READY
) {
2564 sc
->unsolq_st
= HDAC_UNSOLQ_BUSY
;
2565 while (sc
->unsolq_rp
!= sc
->unsolq_wp
) {
2566 cad
= sc
->unsolq
[sc
->unsolq_rp
] >> 16;
2567 tag
= sc
->unsolq
[sc
->unsolq_rp
++] & 0xffff;
2568 sc
->unsolq_rp
%= HDAC_UNSOLQ_MAX
;
2569 hdac_unsolicited_handler(sc
->codecs
[cad
], tag
);
2572 sc
->unsolq_st
= HDAC_UNSOLQ_READY
;
2579 hdac_poll_callback(void *arg
)
2581 struct hdac_softc
*sc
= arg
;
2586 if (sc
->polling
== 0 || sc
->poll_ival
== 0) {
2590 if (hdac_rirb_flush(sc
) != 0)
2591 hdac_unsolq_flush(sc
);
2592 callout_reset(&sc
->poll_hdac
, sc
->poll_ival
, hdac_poll_callback
, sc
);
2597 hdac_stream_stop(struct hdac_chan
*ch
)
2599 struct hdac_softc
*sc
= ch
->devinfo
->codec
->sc
;
2602 ctl
= HDAC_READ_1(&sc
->mem
, ch
->off
+ HDAC_SDCTL0
);
2603 ctl
&= ~(HDAC_SDCTL_IOCE
| HDAC_SDCTL_FEIE
| HDAC_SDCTL_DEIE
|
2605 HDAC_WRITE_1(&sc
->mem
, ch
->off
+ HDAC_SDCTL0
, ctl
);
2607 ch
->flags
&= ~HDAC_CHN_RUNNING
;
2609 if (sc
->polling
!= 0) {
2612 if (hda_chan_active(sc
) == 0) {
2613 callout_stop(&sc
->poll_hda
);
2616 if (sc
->play
.flags
& HDAC_CHN_RUNNING
)
2620 pollticks
= ((uint64_t)hz
* ch
->blksz
) /
2621 ((uint64_t)sndbuf_getbps(ch
->b
) *
2622 sndbuf_getspd(ch
->b
));
2626 if (pollticks
< 1) {
2628 device_printf(sc
->dev
,
2629 "%s: pollticks=%d < 1 !\n",
2630 __func__
, pollticks
);
2634 if (pollticks
> sc
->poll_ticks
) {
2636 device_printf(sc
->dev
,
2637 "%s: pollticks %d -> %d\n",
2638 __func__
, sc
->poll_ticks
,
2641 sc
->poll_ticks
= pollticks
;
2642 callout_reset(&sc
->poll_hda
, 1,
2643 hda_poll_callback
, sc
);
2647 ctl
= HDAC_READ_4(&sc
->mem
, HDAC_INTCTL
);
2648 ctl
&= ~(1 << (ch
->off
>> 5));
2649 HDAC_WRITE_4(&sc
->mem
, HDAC_INTCTL
, ctl
);
2654 hdac_stream_start(struct hdac_chan
*ch
)
2656 struct hdac_softc
*sc
= ch
->devinfo
->codec
->sc
;
2659 if (sc
->polling
!= 0) {
2662 pollticks
= ((uint64_t)hz
* ch
->blksz
) /
2663 ((uint64_t)sndbuf_getbps(ch
->b
) * sndbuf_getspd(ch
->b
));
2667 if (pollticks
< 1) {
2669 device_printf(sc
->dev
,
2670 "%s: pollticks=%d < 1 !\n",
2671 __func__
, pollticks
);
2675 if (hda_chan_active(sc
) == 0 || pollticks
< sc
->poll_ticks
) {
2677 if (hda_chan_active(sc
) == 0) {
2678 device_printf(sc
->dev
,
2679 "%s: pollticks=%d\n",
2680 __func__
, pollticks
);
2682 device_printf(sc
->dev
,
2683 "%s: pollticks %d -> %d\n",
2684 __func__
, sc
->poll_ticks
,
2688 sc
->poll_ticks
= pollticks
;
2689 callout_reset(&sc
->poll_hda
, 1, hda_poll_callback
,
2692 ctl
= HDAC_READ_1(&sc
->mem
, ch
->off
+ HDAC_SDCTL0
);
2693 ctl
|= HDAC_SDCTL_RUN
;
2695 ctl
= HDAC_READ_4(&sc
->mem
, HDAC_INTCTL
);
2696 ctl
|= 1 << (ch
->off
>> 5);
2697 HDAC_WRITE_4(&sc
->mem
, HDAC_INTCTL
, ctl
);
2698 ctl
= HDAC_READ_1(&sc
->mem
, ch
->off
+ HDAC_SDCTL0
);
2699 ctl
|= HDAC_SDCTL_IOCE
| HDAC_SDCTL_FEIE
| HDAC_SDCTL_DEIE
|
2702 HDAC_WRITE_1(&sc
->mem
, ch
->off
+ HDAC_SDCTL0
, ctl
);
2704 ch
->flags
|= HDAC_CHN_RUNNING
;
2708 hdac_stream_reset(struct hdac_chan
*ch
)
2710 struct hdac_softc
*sc
= ch
->devinfo
->codec
->sc
;
2715 ctl
= HDAC_READ_1(&sc
->mem
, ch
->off
+ HDAC_SDCTL0
);
2716 ctl
|= HDAC_SDCTL_SRST
;
2717 HDAC_WRITE_1(&sc
->mem
, ch
->off
+ HDAC_SDCTL0
, ctl
);
2719 ctl
= HDAC_READ_1(&sc
->mem
, ch
->off
+ HDAC_SDCTL0
);
2720 if (ctl
& HDAC_SDCTL_SRST
)
2724 if (!(ctl
& HDAC_SDCTL_SRST
)) {
2725 device_printf(sc
->dev
, "timeout in reset\n");
2727 ctl
&= ~HDAC_SDCTL_SRST
;
2728 HDAC_WRITE_1(&sc
->mem
, ch
->off
+ HDAC_SDCTL0
, ctl
);
2731 ctl
= HDAC_READ_1(&sc
->mem
, ch
->off
+ HDAC_SDCTL0
);
2732 if (!(ctl
& HDAC_SDCTL_SRST
))
2736 if (ctl
& HDAC_SDCTL_SRST
)
2737 device_printf(sc
->dev
, "can't reset!\n");
2741 hdac_stream_setid(struct hdac_chan
*ch
)
2743 struct hdac_softc
*sc
= ch
->devinfo
->codec
->sc
;
2746 ctl
= HDAC_READ_1(&sc
->mem
, ch
->off
+ HDAC_SDCTL2
);
2747 ctl
&= ~HDAC_SDCTL2_STRM_MASK
;
2748 ctl
|= ch
->sid
<< HDAC_SDCTL2_STRM_SHIFT
;
2749 HDAC_WRITE_1(&sc
->mem
, ch
->off
+ HDAC_SDCTL2
, ctl
);
2753 hdac_bdl_setup(struct hdac_chan
*ch
)
2755 struct hdac_softc
*sc
= ch
->devinfo
->codec
->sc
;
2756 struct hdac_bdle
*bdle
;
2758 uint32_t blksz
, blkcnt
;
2761 addr
= (uint64_t)sndbuf_getbufaddr(ch
->b
);
2762 bdle
= (struct hdac_bdle
*)ch
->bdl_dma
.dma_vaddr
;
2764 if (sc
->polling
!= 0) {
2765 blksz
= ch
->blksz
* ch
->blkcnt
;
2769 blkcnt
= ch
->blkcnt
;
2772 for (i
= 0; i
< blkcnt
; i
++, bdle
++) {
2773 bdle
->addrl
= (uint32_t)addr
;
2774 bdle
->addrh
= (uint32_t)(addr
>> 32);
2776 bdle
->ioc
= 1 ^ sc
->polling
;
2780 HDAC_WRITE_4(&sc
->mem
, ch
->off
+ HDAC_SDCBL
, blksz
* blkcnt
);
2781 HDAC_WRITE_2(&sc
->mem
, ch
->off
+ HDAC_SDLVI
, blkcnt
- 1);
2782 addr
= ch
->bdl_dma
.dma_paddr
;
2783 HDAC_WRITE_4(&sc
->mem
, ch
->off
+ HDAC_SDBDPL
, (uint32_t)addr
);
2784 HDAC_WRITE_4(&sc
->mem
, ch
->off
+ HDAC_SDBDPU
, (uint32_t)(addr
>> 32));
2785 if (ch
->dmapos
!= NULL
&&
2786 !(HDAC_READ_4(&sc
->mem
, HDAC_DPIBLBASE
) & 0x00000001)) {
2787 addr
= sc
->pos_dma
.dma_paddr
;
2788 HDAC_WRITE_4(&sc
->mem
, HDAC_DPIBLBASE
,
2789 ((uint32_t)addr
& HDAC_DPLBASE_DPLBASE_MASK
) | 0x00000001);
2790 HDAC_WRITE_4(&sc
->mem
, HDAC_DPIBUBASE
, (uint32_t)(addr
>> 32));
2795 hdac_bdl_alloc(struct hdac_chan
*ch
)
2797 struct hdac_softc
*sc
= ch
->devinfo
->codec
->sc
;
2800 rc
= hdac_dma_alloc(sc
, &ch
->bdl_dma
,
2801 sizeof(struct hdac_bdle
) * HDA_BDL_MAX
);
2803 device_printf(sc
->dev
, "can't alloc bdl\n");
2811 hdac_audio_ctl_amp_set_internal(struct hdac_softc
*sc
, nid_t cad
, nid_t nid
,
2812 int index
, int lmute
, int rmute
,
2813 int left
, int right
, int dir
)
2820 if (left
!= right
|| lmute
!= rmute
) {
2821 v
= (1 << (15 - dir
)) | (1 << 13) | (index
<< 8) |
2822 (lmute
<< 7) | left
;
2824 HDA_CMD_SET_AMP_GAIN_MUTE(cad
, nid
, v
), cad
);
2825 v
= (1 << (15 - dir
)) | (1 << 12) | (index
<< 8) |
2826 (rmute
<< 7) | right
;
2828 v
= (1 << (15 - dir
)) | (3 << 12) | (index
<< 8) |
2829 (lmute
<< 7) | left
;
2832 HDA_CMD_SET_AMP_GAIN_MUTE(cad
, nid
, v
), cad
);
2836 hdac_audio_ctl_amp_set(struct hdac_audio_ctl
*ctl
, uint32_t mute
,
2837 int left
, int right
)
2839 struct hdac_softc
*sc
;
2843 if (ctl
== NULL
|| ctl
->widget
== NULL
||
2844 ctl
->widget
->devinfo
== NULL
||
2845 ctl
->widget
->devinfo
->codec
== NULL
||
2846 ctl
->widget
->devinfo
->codec
->sc
== NULL
)
2849 sc
= ctl
->widget
->devinfo
->codec
->sc
;
2850 cad
= ctl
->widget
->devinfo
->codec
->cad
;
2851 nid
= ctl
->widget
->nid
;
2853 if (mute
== HDA_AMP_MUTE_DEFAULT
) {
2854 lmute
= HDA_AMP_LEFT_MUTED(ctl
->muted
);
2855 rmute
= HDA_AMP_RIGHT_MUTED(ctl
->muted
);
2857 lmute
= HDA_AMP_LEFT_MUTED(mute
);
2858 rmute
= HDA_AMP_RIGHT_MUTED(mute
);
2861 if (ctl
->dir
& HDA_CTL_OUT
)
2862 hdac_audio_ctl_amp_set_internal(sc
, cad
, nid
, ctl
->index
,
2863 lmute
, rmute
, left
, right
, 0);
2864 if (ctl
->dir
& HDA_CTL_IN
)
2865 hdac_audio_ctl_amp_set_internal(sc
, cad
, nid
, ctl
->index
,
2866 lmute
, rmute
, left
, right
, 1);
2872 hdac_widget_connection_select(struct hdac_widget
*w
, uint8_t index
)
2874 if (w
== NULL
|| w
->nconns
< 1 || index
> (w
->nconns
- 1))
2876 hdac_command(w
->devinfo
->codec
->sc
,
2877 HDA_CMD_SET_CONNECTION_SELECT_CONTROL(w
->devinfo
->codec
->cad
,
2878 w
->nid
, index
), w
->devinfo
->codec
->cad
);
2883 /****************************************************************************
2884 * uint32_t hdac_command_sendone_internal
2886 * Wrapper function that sends only one command to a given codec
2887 ****************************************************************************/
2889 hdac_command_sendone_internal(struct hdac_softc
*sc
, uint32_t verb
, nid_t cad
)
2891 struct hdac_command_list cl
;
2892 uint32_t response
= HDAC_INVALID
;
2894 if (!hdac_lockowned(sc
))
2895 device_printf(sc
->dev
, "WARNING!!!! mtx not owned!!!!\n");
2896 cl
.num_commands
= 1;
2898 cl
.responses
= &response
;
2900 hdac_command_send_internal(sc
, &cl
, cad
);
2905 /****************************************************************************
2906 * hdac_command_send_internal
2908 * Send a command list to the codec via the corb. We queue as much verbs as
2909 * we can and msleep on the codec. When the interrupt get the responses
2910 * back from the rirb, it will wake us up so we can queue the remaining verbs
2912 ****************************************************************************/
2914 hdac_command_send_internal(struct hdac_softc
*sc
,
2915 struct hdac_command_list
*commands
, nid_t cad
)
2917 struct hdac_codec
*codec
;
2922 struct hdac_rirb
*rirb_base
;
2924 if (sc
== NULL
|| sc
->codecs
[cad
] == NULL
|| commands
== NULL
||
2925 commands
->num_commands
< 1)
2928 codec
= sc
->codecs
[cad
];
2929 codec
->commands
= commands
;
2930 codec
->responses_received
= 0;
2931 codec
->verbs_sent
= 0;
2932 corb
= (uint32_t *)sc
->corb_dma
.dma_vaddr
;
2933 rirb_base
= (struct hdac_rirb
*)sc
->rirb_dma
.dma_vaddr
;
2936 if (codec
->verbs_sent
!= commands
->num_commands
) {
2937 /* Queue as many verbs as possible */
2938 corbrp
= HDAC_READ_2(&sc
->mem
, HDAC_CORBRP
);
2940 bus_dmamap_sync(sc
->corb_dma
.dma_tag
,
2941 sc
->corb_dma
.dma_map
, BUS_DMASYNC_PREWRITE
);
2943 while (codec
->verbs_sent
!= commands
->num_commands
&&
2944 ((sc
->corb_wp
+ 1) % sc
->corb_size
) != corbrp
) {
2946 sc
->corb_wp
%= sc
->corb_size
;
2948 commands
->verbs
[codec
->verbs_sent
++];
2951 /* Send the verbs to the codecs */
2953 bus_dmamap_sync(sc
->corb_dma
.dma_tag
,
2954 sc
->corb_dma
.dma_map
, BUS_DMASYNC_POSTWRITE
);
2956 HDAC_WRITE_2(&sc
->mem
, HDAC_CORBWP
, sc
->corb_wp
);
2960 while (hdac_rirb_flush(sc
) == 0 && --timeout
)
2962 } while ((codec
->verbs_sent
!= commands
->num_commands
||
2963 codec
->responses_received
!= commands
->num_commands
) && --retry
);
2966 device_printf(sc
->dev
,
2967 "%s: TIMEOUT numcmd=%d, sent=%d, received=%d\n",
2968 __func__
, commands
->num_commands
, codec
->verbs_sent
,
2969 codec
->responses_received
);
2971 codec
->commands
= NULL
;
2972 codec
->responses_received
= 0;
2973 codec
->verbs_sent
= 0;
2975 hdac_unsolq_flush(sc
);
2979 /****************************************************************************
2981 ****************************************************************************/
2983 /****************************************************************************
2984 * int hdac_probe(device_t)
2986 * Probe for the presence of an hdac. If none is found, check for a generic
2987 * match using the subclass of the device.
2988 ****************************************************************************/
2990 hdac_probe(device_t dev
)
2994 uint16_t class, subclass
;
2997 model
= (uint32_t)pci_get_device(dev
) << 16;
2998 model
|= (uint32_t)pci_get_vendor(dev
) & 0x0000ffff;
2999 class = pci_get_class(dev
);
3000 subclass
= pci_get_subclass(dev
);
3002 bzero(desc
, sizeof(desc
));
3004 for (i
= 0; i
< HDAC_DEVICES_LEN
; i
++) {
3005 if (hdac_devices
[i
].model
== model
) {
3006 strlcpy(desc
, hdac_devices
[i
].desc
, sizeof(desc
));
3007 result
= BUS_PROBE_DEFAULT
;
3010 if (HDA_DEV_MATCH(hdac_devices
[i
].model
, model
) &&
3011 class == PCIC_MULTIMEDIA
&&
3012 subclass
== PCIS_MULTIMEDIA_HDA
) {
3013 strlcpy(desc
, hdac_devices
[i
].desc
, sizeof(desc
));
3014 result
= BUS_PROBE_GENERIC
;
3018 if (result
== ENXIO
&& class == PCIC_MULTIMEDIA
&&
3019 subclass
== PCIS_MULTIMEDIA_HDA
) {
3020 strlcpy(desc
, "Generic", sizeof(desc
));
3021 result
= BUS_PROBE_GENERIC
;
3023 if (result
!= ENXIO
) {
3024 strlcat(desc
, " High Definition Audio Controller",
3026 device_set_desc_copy(dev
, desc
);
3033 hdac_channel_init(kobj_t obj
, void *data
, struct snd_dbuf
*b
,
3034 struct pcm_channel
*c
, int dir
)
3036 struct hdac_devinfo
*devinfo
= data
;
3037 struct hdac_softc
*sc
= devinfo
->codec
->sc
;
3038 struct hdac_chan
*ch
;
3041 if (dir
== PCMDIR_PLAY
) {
3043 ch
->off
= (sc
->num_iss
+ devinfo
->function
.audio
.playcnt
) << 5;
3044 devinfo
->function
.audio
.playcnt
++;
3047 ch
->off
= devinfo
->function
.audio
.reccnt
<< 5;
3048 devinfo
->function
.audio
.reccnt
++;
3050 if (devinfo
->function
.audio
.quirks
& HDA_QUIRK_FIXEDRATE
) {
3051 ch
->caps
.minspeed
= ch
->caps
.maxspeed
= 48000;
3052 ch
->pcmrates
[0] = 48000;
3053 ch
->pcmrates
[1] = 0;
3055 if (sc
->pos_dma
.dma_vaddr
!= NULL
)
3056 ch
->dmapos
= (uint32_t *)(sc
->pos_dma
.dma_vaddr
+
3057 (sc
->streamcnt
* 8));
3060 ch
->sid
= ++sc
->streamcnt
;
3064 ch
->devinfo
= devinfo
;
3065 ch
->blksz
= sc
->chan_size
/ sc
->chan_blkcnt
;
3066 ch
->blkcnt
= sc
->chan_blkcnt
;
3069 if (hdac_bdl_alloc(ch
) != 0) {
3074 if (sndbuf_alloc(ch
->b
, sc
->chan_dmat
, sc
->chan_size
) != 0)
3077 HDAC_DMA_ATTR(sc
, sndbuf_getbuf(ch
->b
), sndbuf_getmaxsize(ch
->b
),
3084 hdac_channel_free(kobj_t obj
, void *data
)
3086 struct hdac_softc
*sc
;
3087 struct hdac_chan
*ch
;
3089 ch
= (struct hdac_chan
*)data
;
3090 sc
= (ch
!= NULL
&& ch
->devinfo
!= NULL
&& ch
->devinfo
->codec
!= NULL
) ?
3091 ch
->devinfo
->codec
->sc
: NULL
;
3092 if (ch
!= NULL
&& sc
!= NULL
) {
3093 HDAC_DMA_ATTR(sc
, sndbuf_getbuf(ch
->b
),
3094 sndbuf_getmaxsize(ch
->b
), PAT_WRITE_BACK
);
3101 hdac_channel_setformat(kobj_t obj
, void *data
, uint32_t format
)
3103 struct hdac_chan
*ch
= data
;
3106 for (i
= 0; ch
->caps
.fmtlist
[i
] != 0; i
++) {
3107 if (format
== ch
->caps
.fmtlist
[i
]) {
3117 hdac_channel_setspeed(kobj_t obj
, void *data
, uint32_t speed
)
3119 struct hdac_chan
*ch
= data
;
3120 uint32_t spd
= 0, threshold
;
3123 for (i
= 0; ch
->pcmrates
[i
] != 0; i
++) {
3124 spd
= ch
->pcmrates
[i
];
3125 threshold
= spd
+ ((ch
->pcmrates
[i
+ 1] != 0) ?
3126 ((ch
->pcmrates
[i
+ 1] - spd
) >> 1) : 0);
3127 if (speed
< threshold
)
3131 if (spd
== 0) /* impossible */
3140 hdac_stream_setup(struct hdac_chan
*ch
)
3142 struct hdac_softc
*sc
= ch
->devinfo
->codec
->sc
;
3143 struct hdac_widget
*w
;
3144 int i
, chn
, totalchn
;
3145 nid_t cad
= ch
->devinfo
->codec
->cad
;
3149 if (ch
->fmt
& AFMT_S16_LE
)
3150 fmt
|= ch
->bit16
<< 4;
3151 else if (ch
->fmt
& AFMT_S32_LE
)
3152 fmt
|= ch
->bit32
<< 4;
3156 for (i
= 0; i
< HDA_RATE_TAB_LEN
; i
++) {
3157 if (hda_rate_tab
[i
].valid
&& ch
->spd
== hda_rate_tab
[i
].rate
) {
3158 fmt
|= hda_rate_tab
[i
].base
;
3159 fmt
|= hda_rate_tab
[i
].mul
;
3160 fmt
|= hda_rate_tab
[i
].div
;
3165 if (ch
->fmt
& AFMT_STEREO
) {
3171 HDAC_WRITE_2(&sc
->mem
, ch
->off
+ HDAC_SDFMT
, fmt
);
3174 for (i
= 0; ch
->io
[i
] != -1; i
++) {
3175 w
= hdac_widget_get(ch
->devinfo
, ch
->io
[i
]);
3179 device_printf(sc
->dev
,
3180 "HDA_DEBUG: PCMDIR_%s: Stream setup nid=%d "
3182 (ch
->dir
== PCMDIR_PLAY
) ? "PLAY" : "REC",
3186 HDA_CMD_SET_CONV_FMT(cad
, ch
->io
[i
], fmt
), cad
);
3188 HDA_CMD_SET_CONV_STREAM_CHAN(cad
, ch
->io
[i
],
3189 (chn
< totalchn
) ? ((ch
->sid
<< 4) | chn
) : 0), cad
);
3191 HDA_PARAM_AUDIO_WIDGET_CAP_STEREO(w
->param
.widget_cap
) ?
3197 hdac_channel_setfragments(kobj_t obj
, void *data
,
3198 uint32_t blksz
, uint32_t blkcnt
)
3200 struct hdac_chan
*ch
= data
;
3201 struct hdac_softc
*sc
= ch
->devinfo
->codec
->sc
;
3203 blksz
&= HDA_BLK_ALIGN
;
3205 if (blksz
> (sndbuf_getmaxsize(ch
->b
) / HDA_BDL_MIN
))
3206 blksz
= sndbuf_getmaxsize(ch
->b
) / HDA_BDL_MIN
;
3207 if (blksz
< HDA_BLK_MIN
)
3208 blksz
= HDA_BLK_MIN
;
3209 if (blkcnt
> HDA_BDL_MAX
)
3210 blkcnt
= HDA_BDL_MAX
;
3211 if (blkcnt
< HDA_BDL_MIN
)
3212 blkcnt
= HDA_BDL_MIN
;
3214 while ((blksz
* blkcnt
) > sndbuf_getmaxsize(ch
->b
)) {
3215 if ((blkcnt
>> 1) >= HDA_BDL_MIN
)
3217 else if ((blksz
>> 1) >= HDA_BLK_MIN
)
3223 if ((sndbuf_getblksz(ch
->b
) != blksz
||
3224 sndbuf_getblkcnt(ch
->b
) != blkcnt
) &&
3225 sndbuf_resize(ch
->b
, blkcnt
, blksz
) != 0)
3226 device_printf(sc
->dev
, "%s: failed blksz=%u blkcnt=%u\n",
3227 __func__
, blksz
, blkcnt
);
3229 ch
->blksz
= sndbuf_getblksz(ch
->b
);
3230 ch
->blkcnt
= sndbuf_getblkcnt(ch
->b
);
3236 hdac_channel_setblocksize(kobj_t obj
, void *data
, uint32_t blksz
)
3238 struct hdac_chan
*ch
= data
;
3239 struct hdac_softc
*sc
= ch
->devinfo
->codec
->sc
;
3241 hdac_channel_setfragments(obj
, data
, blksz
, sc
->chan_blkcnt
);
3247 hdac_channel_stop(struct hdac_softc
*sc
, struct hdac_chan
*ch
)
3249 struct hdac_devinfo
*devinfo
= ch
->devinfo
;
3250 nid_t cad
= devinfo
->codec
->cad
;
3253 hdac_stream_stop(ch
);
3255 for (i
= 0; ch
->io
[i
] != -1; i
++) {
3257 HDA_CMD_SET_CONV_STREAM_CHAN(cad
, ch
->io
[i
],
3263 hdac_channel_start(struct hdac_softc
*sc
, struct hdac_chan
*ch
)
3267 hdac_stream_stop(ch
);
3268 hdac_stream_reset(ch
);
3270 hdac_stream_setid(ch
);
3271 hdac_stream_setup(ch
);
3272 hdac_stream_start(ch
);
3276 hdac_channel_trigger(kobj_t obj
, void *data
, int go
)
3278 struct hdac_chan
*ch
= data
;
3279 struct hdac_softc
*sc
= ch
->devinfo
->codec
->sc
;
3281 if (!(go
== PCMTRIG_START
|| go
== PCMTRIG_STOP
|| go
== PCMTRIG_ABORT
))
3287 hdac_channel_start(sc
, ch
);
3291 hdac_channel_stop(sc
, ch
);
3302 hdac_channel_getptr(kobj_t obj
, void *data
)
3304 struct hdac_chan
*ch
= data
;
3305 struct hdac_softc
*sc
= ch
->devinfo
->codec
->sc
;
3309 if (sc
->polling
!= 0)
3311 else if (ch
->dmapos
!= NULL
)
3312 ptr
= *(ch
->dmapos
);
3314 ptr
= HDAC_READ_4(&sc
->mem
, ch
->off
+ HDAC_SDLPIB
);
3318 * Round to available space and force 128 bytes aligment.
3320 ptr
%= ch
->blksz
* ch
->blkcnt
;
3321 ptr
&= HDA_BLK_ALIGN
;
3326 static struct pcmchan_caps
*
3327 hdac_channel_getcaps(kobj_t obj
, void *data
)
3329 return (&((struct hdac_chan
*)data
)->caps
);
3332 static kobj_method_t hdac_channel_methods
[] = {
3333 KOBJMETHOD(channel_init
, hdac_channel_init
),
3334 KOBJMETHOD(channel_free
, hdac_channel_free
),
3335 KOBJMETHOD(channel_setformat
, hdac_channel_setformat
),
3336 KOBJMETHOD(channel_setspeed
, hdac_channel_setspeed
),
3337 KOBJMETHOD(channel_setblocksize
, hdac_channel_setblocksize
),
3338 KOBJMETHOD(channel_trigger
, hdac_channel_trigger
),
3339 KOBJMETHOD(channel_getptr
, hdac_channel_getptr
),
3340 KOBJMETHOD(channel_getcaps
, hdac_channel_getcaps
),
3343 CHANNEL_DECLARE(hdac_channel
);
3346 hdac_jack_poll_callback(void *arg
)
3348 struct hdac_devinfo
*devinfo
= arg
;
3349 struct hdac_softc
*sc
;
3351 if (devinfo
== NULL
|| devinfo
->codec
== NULL
||
3352 devinfo
->codec
->sc
== NULL
)
3354 sc
= devinfo
->codec
->sc
;
3356 if (sc
->poll_ival
== 0) {
3360 hdac_hp_switch_handler(devinfo
);
3361 callout_reset(&sc
->poll_jack
, sc
->poll_ival
,
3362 hdac_jack_poll_callback
, devinfo
);
3367 hdac_audio_ctl_ossmixer_init(struct snd_mixer
*m
)
3369 struct hdac_devinfo
*devinfo
= mix_getdevinfo(m
);
3370 struct hdac_softc
*sc
= devinfo
->codec
->sc
;
3371 struct hdac_widget
*w
, *cw
;
3372 struct hdac_audio_ctl
*ctl
;
3373 uint32_t mask
, recmask
, id
;
3374 int i
, j
, softpcmvol
;
3382 id
= hdac_codec_id(devinfo
);
3383 cad
= devinfo
->codec
->cad
;
3384 for (i
= 0; i
< HDAC_HP_SWITCH_LEN
; i
++) {
3385 if (!(HDA_DEV_MATCH(hdac_hp_switch
[i
].model
,
3386 sc
->pci_subvendor
) && hdac_hp_switch
[i
].id
== id
))
3388 w
= hdac_widget_get(devinfo
, hdac_hp_switch
[i
].hpnid
);
3389 if (w
== NULL
|| w
->enable
== 0 || w
->type
!=
3390 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
)
3392 if (hdac_hp_switch
[i
].polling
!= 0)
3393 callout_reset(&sc
->poll_jack
, 1,
3394 hdac_jack_poll_callback
, devinfo
);
3395 else if (HDA_PARAM_AUDIO_WIDGET_CAP_UNSOL_CAP(w
->param
.widget_cap
))
3397 HDA_CMD_SET_UNSOLICITED_RESPONSE(cad
, w
->nid
,
3398 HDA_CMD_SET_UNSOLICITED_RESPONSE_ENABLE
|
3399 HDAC_UNSOLTAG_EVENT_HP
), cad
);
3402 hdac_hp_switch_handler(devinfo
);
3404 device_printf(sc
->dev
,
3405 "HDA_DEBUG: Enabling headphone/speaker "
3406 "audio routing switching:\n");
3407 device_printf(sc
->dev
,
3408 "HDA_DEBUG: \tindex=%d nid=%d "
3409 "pci_subvendor=0x%08x "
3410 "codec=0x%08x [%s]\n",
3411 i
, w
->nid
, sc
->pci_subvendor
, id
,
3412 (hdac_hp_switch
[i
].polling
!= 0) ? "POLL" :
3417 for (i
= 0; i
< HDAC_EAPD_SWITCH_LEN
; i
++) {
3418 if (!(HDA_DEV_MATCH(hdac_eapd_switch
[i
].model
,
3419 sc
->pci_subvendor
) &&
3420 hdac_eapd_switch
[i
].id
== id
))
3422 w
= hdac_widget_get(devinfo
, hdac_eapd_switch
[i
].eapdnid
);
3423 if (w
== NULL
|| w
->enable
== 0)
3425 if (w
->type
!= HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
||
3426 w
->param
.eapdbtl
== HDAC_INVALID
)
3428 mask
|= SOUND_MASK_OGAIN
;
3432 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
3433 w
= hdac_widget_get(devinfo
, i
);
3434 if (w
== NULL
|| w
->enable
== 0)
3436 mask
|= w
->ctlflags
;
3437 if (!(w
->pflags
& HDA_ADC_RECSEL
))
3439 for (j
= 0; j
< w
->nconns
; j
++) {
3440 cw
= hdac_widget_get(devinfo
, w
->conns
[j
]);
3441 if (cw
== NULL
|| cw
->enable
== 0)
3443 recmask
|= cw
->ctlflags
;
3447 if (!(mask
& SOUND_MASK_PCM
)) {
3449 mask
|= SOUND_MASK_PCM
;
3451 softpcmvol
= (devinfo
->function
.audio
.quirks
&
3452 HDA_QUIRK_SOFTPCMVOL
) ? 1 : 0;
3456 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) != NULL
) {
3457 if (ctl
->widget
== NULL
|| ctl
->enable
== 0)
3459 if (!(ctl
->ossmask
& SOUND_MASK_PCM
))
3465 if (softpcmvol
== 1 || ctl
== NULL
) {
3466 pcm_setflags(sc
->dev
, pcm_getflags(sc
->dev
) | SD_F_SOFTPCMVOL
);
3468 device_printf(sc
->dev
,
3469 "HDA_DEBUG: %s Soft PCM volume\n",
3471 "Forcing" : "Enabling");
3475 * XXX Temporary quirk for STAC9220, until the parser
3478 if (id
== HDA_CODEC_STAC9220
) {
3479 mask
|= SOUND_MASK_VOLUME
;
3480 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) !=
3482 if (ctl
->widget
== NULL
|| ctl
->enable
== 0)
3484 if (ctl
->widget
->nid
== 11 && ctl
->index
== 0) {
3485 ctl
->ossmask
= SOUND_MASK_VOLUME
;
3486 ctl
->ossval
= 100 | (100 << 8);
3488 ctl
->ossmask
&= ~SOUND_MASK_VOLUME
;
3490 } else if (id
== HDA_CODEC_STAC9221
) {
3491 mask
|= SOUND_MASK_VOLUME
;
3492 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) !=
3494 if (ctl
->widget
== NULL
)
3496 if (ctl
->widget
->type
==
3497 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT
&&
3498 ctl
->index
== 0 && (ctl
->widget
->nid
== 2 ||
3499 ctl
->widget
->enable
!= 0)) {
3501 ctl
->ossmask
= SOUND_MASK_VOLUME
;
3502 ctl
->ossval
= 100 | (100 << 8);
3503 } else if (ctl
->enable
== 0)
3506 ctl
->ossmask
&= ~SOUND_MASK_VOLUME
;
3509 mix_setparentchild(m
, SOUND_MIXER_VOLUME
,
3511 if (!(mask
& SOUND_MASK_VOLUME
))
3512 mix_setrealdev(m
, SOUND_MIXER_VOLUME
,
3514 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) !=
3516 if (ctl
->widget
== NULL
|| ctl
->enable
== 0)
3518 if (!HDA_FLAG_MATCH(ctl
->ossmask
,
3519 SOUND_MASK_VOLUME
| SOUND_MASK_PCM
))
3521 if (!(ctl
->mute
== 1 && ctl
->step
== 0))
3527 recmask
&= ~(SOUND_MASK_PCM
| SOUND_MASK_RECLEV
| SOUND_MASK_SPEAKER
|
3528 SOUND_MASK_BASS
| SOUND_MASK_TREBLE
| SOUND_MASK_IGAIN
|
3530 recmask
&= (1 << SOUND_MIXER_NRDEVICES
) - 1;
3531 mask
&= (1 << SOUND_MIXER_NRDEVICES
) - 1;
3533 mix_setrecdevs(m
, recmask
);
3534 mix_setdevs(m
, mask
);
3542 hdac_audio_ctl_ossmixer_set(struct snd_mixer
*m
, unsigned dev
,
3543 unsigned left
, unsigned right
)
3545 struct hdac_devinfo
*devinfo
= mix_getdevinfo(m
);
3546 struct hdac_softc
*sc
= devinfo
->codec
->sc
;
3547 struct hdac_widget
*w
;
3548 struct hdac_audio_ctl
*ctl
;
3550 int lvol
, rvol
, mlvol
, mrvol
;
3554 if (dev
== SOUND_MIXER_OGAIN
) {
3556 /*if (left != right || !(left == 0 || left == 1)) {
3560 id
= hdac_codec_id(devinfo
);
3561 for (i
= 0; i
< HDAC_EAPD_SWITCH_LEN
; i
++) {
3562 if (HDA_DEV_MATCH(hdac_eapd_switch
[i
].model
,
3563 sc
->pci_subvendor
) &&
3564 hdac_eapd_switch
[i
].id
== id
)
3567 if (i
>= HDAC_EAPD_SWITCH_LEN
) {
3571 w
= hdac_widget_get(devinfo
, hdac_eapd_switch
[i
].eapdnid
);
3573 w
->type
!= HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
||
3574 w
->param
.eapdbtl
== HDAC_INVALID
) {
3578 orig
= w
->param
.eapdbtl
;
3580 w
->param
.eapdbtl
&= ~HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD
;
3582 w
->param
.eapdbtl
|= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD
;
3583 if (orig
!= w
->param
.eapdbtl
) {
3586 if (hdac_eapd_switch
[i
].hp_switch
!= 0)
3587 hdac_hp_switch_handler(devinfo
);
3588 val
= w
->param
.eapdbtl
;
3589 if (devinfo
->function
.audio
.quirks
& HDA_QUIRK_EAPDINV
)
3590 val
^= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD
;
3592 HDA_CMD_SET_EAPD_BTL_ENABLE(devinfo
->codec
->cad
,
3593 w
->nid
, val
), devinfo
->codec
->cad
);
3596 return (left
| (left
<< 8));
3598 if (dev
== SOUND_MIXER_VOLUME
)
3599 devinfo
->function
.audio
.mvol
= left
| (right
<< 8);
3601 mlvol
= devinfo
->function
.audio
.mvol
& 0x7f;
3602 mrvol
= (devinfo
->function
.audio
.mvol
>> 8) & 0x7f;
3607 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) != NULL
) {
3608 if (ctl
->widget
== NULL
|| ctl
->enable
== 0 ||
3609 !(ctl
->ossmask
& (1 << dev
)))
3612 case SOUND_MIXER_VOLUME
:
3613 lvol
= ((ctl
->ossval
& 0x7f) * left
) / 100;
3614 lvol
= (lvol
* ctl
->step
) / 100;
3615 rvol
= (((ctl
->ossval
>> 8) & 0x7f) * right
) / 100;
3616 rvol
= (rvol
* ctl
->step
) / 100;
3619 if (ctl
->ossmask
& SOUND_MASK_VOLUME
) {
3620 lvol
= (left
* mlvol
) / 100;
3621 lvol
= (lvol
* ctl
->step
) / 100;
3622 rvol
= (right
* mrvol
) / 100;
3623 rvol
= (rvol
* ctl
->step
) / 100;
3625 lvol
= (left
* ctl
->step
) / 100;
3626 rvol
= (right
* ctl
->step
) / 100;
3628 ctl
->ossval
= left
| (right
<< 8);
3632 if (ctl
->step
< 1) {
3633 mute
|= (left
== 0) ? HDA_AMP_MUTE_LEFT
:
3634 (ctl
->muted
& HDA_AMP_MUTE_LEFT
);
3635 mute
|= (right
== 0) ? HDA_AMP_MUTE_RIGHT
:
3636 (ctl
->muted
& HDA_AMP_MUTE_RIGHT
);
3638 mute
|= (lvol
== 0) ? HDA_AMP_MUTE_LEFT
:
3639 (ctl
->muted
& HDA_AMP_MUTE_LEFT
);
3640 mute
|= (rvol
== 0) ? HDA_AMP_MUTE_RIGHT
:
3641 (ctl
->muted
& HDA_AMP_MUTE_RIGHT
);
3643 hdac_audio_ctl_amp_set(ctl
, mute
, lvol
, rvol
);
3647 return (left
| (right
<< 8));
3651 hdac_audio_ctl_ossmixer_setrecsrc(struct snd_mixer
*m
, uint32_t src
)
3653 struct hdac_devinfo
*devinfo
= mix_getdevinfo(m
);
3654 struct hdac_widget
*w
, *cw
;
3655 struct hdac_softc
*sc
= devinfo
->codec
->sc
;
3656 uint32_t ret
= src
, target
;
3660 for (i
= 0; i
< SOUND_MIXER_NRDEVICES
; i
++) {
3661 if (src
& (1 << i
)) {
3669 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
3670 w
= hdac_widget_get(devinfo
, i
);
3671 if (w
== NULL
|| w
->enable
== 0)
3673 if (!(w
->pflags
& HDA_ADC_RECSEL
))
3675 for (j
= 0; j
< w
->nconns
; j
++) {
3676 cw
= hdac_widget_get(devinfo
, w
->conns
[j
]);
3677 if (cw
== NULL
|| cw
->enable
== 0)
3679 if ((target
== SOUND_MASK_VOLUME
&&
3681 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER
) ||
3682 (target
!= SOUND_MASK_VOLUME
&&
3684 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER
))
3686 if (cw
->ctlflags
& target
) {
3687 if (!(w
->pflags
& HDA_ADC_LOCKED
))
3688 hdac_widget_connection_select(w
, j
);
3700 static kobj_method_t hdac_audio_ctl_ossmixer_methods
[] = {
3701 KOBJMETHOD(mixer_init
, hdac_audio_ctl_ossmixer_init
),
3702 KOBJMETHOD(mixer_set
, hdac_audio_ctl_ossmixer_set
),
3703 KOBJMETHOD(mixer_setrecsrc
, hdac_audio_ctl_ossmixer_setrecsrc
),
3706 MIXER_DECLARE(hdac_audio_ctl_ossmixer
);
3709 hdac_unsolq_task(void *context
, int pending
)
3711 struct hdac_softc
*sc
;
3713 sc
= (struct hdac_softc
*)context
;
3716 hdac_unsolq_flush(sc
);
3720 /****************************************************************************
3721 * int hdac_attach(device_t)
3723 * Attach the device into the kernel. Interrupts usually won't be enabled
3724 * when this function is called. Setup everything that doesn't require
3725 * interrupts and defer probing of codecs until interrupts are enabled.
3726 ****************************************************************************/
3728 hdac_attach(device_t dev
)
3730 struct hdac_softc
*sc
;
3736 sc
= kmalloc(sizeof(*sc
), M_DEVBUF
, M_WAITOK
| M_ZERO
);
3737 sc
->lock
= snd_mtxcreate(device_get_nameunit(dev
), HDAC_MTX_NAME
);
3739 sc
->pci_subvendor
= (uint32_t)pci_get_subdevice(sc
->dev
) << 16;
3740 sc
->pci_subvendor
|= (uint32_t)pci_get_subvendor(sc
->dev
) & 0x0000ffff;
3741 vendor
= pci_get_vendor(dev
);
3743 if (sc
->pci_subvendor
== HP_NX6325_SUBVENDORX
) {
3744 /* Screw nx6325 - subdevice/subvendor swapped */
3745 sc
->pci_subvendor
= HP_NX6325_SUBVENDOR
;
3748 callout_init(&sc
->poll_hda
);
3749 callout_init(&sc
->poll_hdac
);
3750 callout_init(&sc
->poll_jack
);
3752 TASK_INIT(&sc
->unsolq_task
, 0, hdac_unsolq_task
, sc
);
3755 sc
->poll_ival
= HDAC_POLL_INTERVAL
;
3756 if (resource_int_value(device_get_name(dev
),
3757 device_get_unit(dev
), "polling", &i
) == 0 && i
!= 0)
3762 sc
->chan_size
= pcm_getbuffersize(dev
,
3763 HDA_BUFSZ_MIN
, HDA_BUFSZ_DEFAULT
, HDA_BUFSZ_MAX
);
3765 if (resource_int_value(device_get_name(dev
),
3766 device_get_unit(dev
), "blocksize", &i
) == 0 && i
> 0) {
3768 if (i
< HDA_BLK_MIN
)
3770 sc
->chan_blkcnt
= sc
->chan_size
/ i
;
3772 while (sc
->chan_blkcnt
>> i
)
3774 sc
->chan_blkcnt
= 1 << (i
- 1);
3775 if (sc
->chan_blkcnt
< HDA_BDL_MIN
)
3776 sc
->chan_blkcnt
= HDA_BDL_MIN
;
3777 else if (sc
->chan_blkcnt
> HDA_BDL_MAX
)
3778 sc
->chan_blkcnt
= HDA_BDL_MAX
;
3780 sc
->chan_blkcnt
= HDA_BDL_DEFAULT
;
3782 result
= bus_dma_tag_create(NULL
, /* parent */
3783 HDAC_DMA_ALIGNMENT
, /* alignment */
3785 BUS_SPACE_MAXADDR_32BIT
, /* lowaddr */
3786 BUS_SPACE_MAXADDR
, /* highaddr */
3787 NULL
, /* filtfunc */
3788 NULL
, /* fistfuncarg */
3789 sc
->chan_size
, /* maxsize */
3791 sc
->chan_size
, /* maxsegsz */
3793 &sc
->chan_dmat
); /* dmat */
3795 device_printf(dev
, "%s: bus_dma_tag_create failed (%x)\n",
3797 snd_mtxfree(sc
->lock
);
3798 kfree(sc
, M_DEVBUF
);
3804 for (i
= 0; i
< HDAC_CODEC_MAX
; i
++)
3805 sc
->codecs
[i
] = NULL
;
3807 pci_enable_busmaster(dev
);
3809 if (vendor
== INTEL_VENDORID
) {
3811 v
= pci_read_config(dev
, 0x44, 1);
3812 pci_write_config(dev
, 0x44, v
& 0xf8, 1);
3814 device_printf(dev
, "TCSEL: 0x%02d -> 0x%02d\n", v
,
3815 pci_read_config(dev
, 0x44, 1));
3818 #if 0 /* TODO: No MSI support yet in DragonFly. */
3819 if (resource_int_value(device_get_name(dev
),
3820 device_get_unit(dev
), "msi", &i
) == 0 && i
!= 0 &&
3821 pci_msi_count(dev
) == 1)
3822 sc
->flags
|= HDAC_F_MSI
;
3825 sc
->flags
&= ~HDAC_F_MSI
;
3827 #if 0 /* TODO: No uncacheable DMA support in DragonFly. */
3828 sc
->flags
|= HDAC_F_DMA_NOCACHE
;
3830 if (resource_int_value(device_get_name(dev
),
3831 device_get_unit(dev
), "snoop", &i
) == 0 && i
!= 0) {
3833 sc
->flags
&= ~HDAC_F_DMA_NOCACHE
;
3836 * Try to enable PCIe snoop to avoid messing around with
3837 * uncacheable DMA attribute. Since PCIe snoop register
3838 * config is pretty much vendor specific, there are no
3839 * general solutions on how to enable it, forcing us (even
3840 * Microsoft) to enable uncacheable or write combined DMA
3843 * http://msdn2.microsoft.com/en-us/library/ms790324.aspx
3845 for (i
= 0; i
< HDAC_PCIESNOOP_LEN
; i
++) {
3846 if (hdac_pcie_snoop
[i
].vendor
!= vendor
)
3848 sc
->flags
&= ~HDAC_F_DMA_NOCACHE
;
3849 if (hdac_pcie_snoop
[i
].reg
== 0x00)
3851 v
= pci_read_config(dev
, hdac_pcie_snoop
[i
].reg
, 1);
3852 if ((v
& hdac_pcie_snoop
[i
].enable
) ==
3853 hdac_pcie_snoop
[i
].enable
)
3855 v
&= hdac_pcie_snoop
[i
].mask
;
3856 v
|= hdac_pcie_snoop
[i
].enable
;
3857 pci_write_config(dev
, hdac_pcie_snoop
[i
].reg
, v
, 1);
3858 v
= pci_read_config(dev
, hdac_pcie_snoop
[i
].reg
, 1);
3859 if ((v
& hdac_pcie_snoop
[i
].enable
) !=
3860 hdac_pcie_snoop
[i
].enable
) {
3863 "WARNING: Failed to enable PCIe "
3866 #if 0 /* TODO: No uncacheable DMA support in DragonFly. */
3867 sc
->flags
|= HDAC_F_DMA_NOCACHE
;
3872 #if 0 /* TODO: No uncacheable DMA support in DragonFly. */
3877 device_printf(dev
, "DMA Coherency: %s / vendor=0x%04x\n",
3878 (sc
->flags
& HDAC_F_DMA_NOCACHE
) ?
3879 "Uncacheable" : "PCIe snoop", vendor
);
3882 /* Allocate resources */
3883 result
= hdac_mem_alloc(sc
);
3885 goto hdac_attach_fail
;
3886 result
= hdac_irq_alloc(sc
);
3888 goto hdac_attach_fail
;
3890 /* Get Capabilities */
3891 result
= hdac_get_capabilities(sc
);
3893 goto hdac_attach_fail
;
3895 /* Allocate CORB and RIRB dma memory */
3896 result
= hdac_dma_alloc(sc
, &sc
->corb_dma
,
3897 sc
->corb_size
* sizeof(uint32_t));
3899 goto hdac_attach_fail
;
3900 result
= hdac_dma_alloc(sc
, &sc
->rirb_dma
,
3901 sc
->rirb_size
* sizeof(struct hdac_rirb
));
3903 goto hdac_attach_fail
;
3905 /* Quiesce everything */
3908 /* Initialize the CORB and RIRB */
3912 /* Defer remaining of initialization until interrupts are enabled */
3913 sc
->intrhook
.ich_func
= hdac_attach2
;
3914 sc
->intrhook
.ich_arg
= (void *)sc
;
3915 if (cold
== 0 || config_intrhook_establish(&sc
->intrhook
) != 0) {
3916 sc
->intrhook
.ich_func
= NULL
;
3917 hdac_attach2((void *)sc
);
3924 hdac_dma_free(sc
, &sc
->rirb_dma
);
3925 hdac_dma_free(sc
, &sc
->corb_dma
);
3927 snd_mtxfree(sc
->lock
);
3928 kfree(sc
, M_DEVBUF
);
3934 hdac_audio_parse(struct hdac_devinfo
*devinfo
)
3936 struct hdac_softc
*sc
= devinfo
->codec
->sc
;
3937 struct hdac_widget
*w
;
3942 cad
= devinfo
->codec
->cad
;
3946 HDA_CMD_SET_POWER_STATE(cad
, nid
, HDA_CMD_POWER_STATE_D0
), cad
);
3950 res
= hdac_command(sc
,
3951 HDA_CMD_GET_PARAMETER(cad
, nid
, HDA_PARAM_SUB_NODE_COUNT
), cad
);
3953 devinfo
->nodecnt
= HDA_PARAM_SUB_NODE_COUNT_TOTAL(res
);
3954 devinfo
->startnode
= HDA_PARAM_SUB_NODE_COUNT_START(res
);
3955 devinfo
->endnode
= devinfo
->startnode
+ devinfo
->nodecnt
;
3957 res
= hdac_command(sc
,
3958 HDA_CMD_GET_PARAMETER(cad
, nid
, HDA_PARAM_GPIO_COUNT
), cad
);
3959 devinfo
->function
.audio
.gpio
= res
;
3962 device_printf(sc
->dev
, " Vendor: 0x%08x\n",
3963 devinfo
->vendor_id
);
3964 device_printf(sc
->dev
, " Device: 0x%08x\n",
3965 devinfo
->device_id
);
3966 device_printf(sc
->dev
, " Revision: 0x%08x\n",
3967 devinfo
->revision_id
);
3968 device_printf(sc
->dev
, " Stepping: 0x%08x\n",
3969 devinfo
->stepping_id
);
3970 device_printf(sc
->dev
, "PCI Subvendor: 0x%08x\n",
3972 device_printf(sc
->dev
, " Nodes: start=%d "
3973 "endnode=%d total=%d\n",
3974 devinfo
->startnode
, devinfo
->endnode
, devinfo
->nodecnt
);
3975 device_printf(sc
->dev
, " CORB size: %d\n", sc
->corb_size
);
3976 device_printf(sc
->dev
, " RIRB size: %d\n", sc
->rirb_size
);
3977 device_printf(sc
->dev
, " Streams: ISS=%d OSS=%d BSS=%d\n",
3978 sc
->num_iss
, sc
->num_oss
, sc
->num_bss
);
3979 device_printf(sc
->dev
, " GPIO: 0x%08x\n",
3980 devinfo
->function
.audio
.gpio
);
3981 device_printf(sc
->dev
, " NumGPIO=%d NumGPO=%d "
3982 "NumGPI=%d GPIWake=%d GPIUnsol=%d\n",
3983 HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo
->function
.audio
.gpio
),
3984 HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo
->function
.audio
.gpio
),
3985 HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo
->function
.audio
.gpio
),
3986 HDA_PARAM_GPIO_COUNT_GPI_WAKE(devinfo
->function
.audio
.gpio
),
3987 HDA_PARAM_GPIO_COUNT_GPI_UNSOL(devinfo
->function
.audio
.gpio
));
3990 res
= hdac_command(sc
,
3991 HDA_CMD_GET_PARAMETER(cad
, nid
, HDA_PARAM_SUPP_STREAM_FORMATS
),
3993 devinfo
->function
.audio
.supp_stream_formats
= res
;
3995 res
= hdac_command(sc
,
3996 HDA_CMD_GET_PARAMETER(cad
, nid
, HDA_PARAM_SUPP_PCM_SIZE_RATE
),
3998 devinfo
->function
.audio
.supp_pcm_size_rate
= res
;
4000 res
= hdac_command(sc
,
4001 HDA_CMD_GET_PARAMETER(cad
, nid
, HDA_PARAM_OUTPUT_AMP_CAP
),
4003 devinfo
->function
.audio
.outamp_cap
= res
;
4005 res
= hdac_command(sc
,
4006 HDA_CMD_GET_PARAMETER(cad
, nid
, HDA_PARAM_INPUT_AMP_CAP
),
4008 devinfo
->function
.audio
.inamp_cap
= res
;
4010 if (devinfo
->nodecnt
> 0)
4011 devinfo
->widget
= (struct hdac_widget
*)kmalloc(
4012 sizeof(*(devinfo
->widget
)) * devinfo
->nodecnt
, M_HDAC
,
4015 devinfo
->widget
= NULL
;
4017 if (devinfo
->widget
== NULL
) {
4018 device_printf(sc
->dev
, "unable to allocate widgets!\n");
4019 devinfo
->endnode
= devinfo
->startnode
;
4020 devinfo
->nodecnt
= 0;
4024 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
4025 w
= hdac_widget_get(devinfo
, i
);
4027 device_printf(sc
->dev
, "Ghost widget! nid=%d!\n", i
);
4029 w
->devinfo
= devinfo
;
4035 w
->param
.eapdbtl
= HDAC_INVALID
;
4036 hdac_widget_parse(w
);
4042 hdac_audio_ctl_parse(struct hdac_devinfo
*devinfo
)
4044 struct hdac_softc
*sc
= devinfo
->codec
->sc
;
4045 struct hdac_audio_ctl
*ctls
;
4046 struct hdac_widget
*w
, *cw
;
4047 int i
, j
, cnt
, max
, ocap
, icap
;
4048 int mute
, offset
, step
, size
;
4050 /* XXX This is redundant */
4052 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
4053 w
= hdac_widget_get(devinfo
, i
);
4054 if (w
== NULL
|| w
->enable
== 0)
4056 if (w
->param
.outamp_cap
!= 0)
4058 if (w
->param
.inamp_cap
!= 0) {
4060 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR
:
4061 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER
:
4062 for (j
= 0; j
< w
->nconns
; j
++) {
4063 cw
= hdac_widget_get(devinfo
,
4065 if (cw
== NULL
|| cw
->enable
== 0)
4077 devinfo
->function
.audio
.ctlcnt
= max
;
4082 ctls
= (struct hdac_audio_ctl
*)kmalloc(
4083 sizeof(*ctls
) * max
, M_HDAC
, M_ZERO
| M_NOWAIT
);
4087 device_printf(sc
->dev
, "unable to allocate ctls!\n");
4088 devinfo
->function
.audio
.ctlcnt
= 0;
4093 for (i
= devinfo
->startnode
; cnt
< max
&& i
< devinfo
->endnode
; i
++) {
4095 device_printf(sc
->dev
, "%s: Ctl overflow!\n",
4099 w
= hdac_widget_get(devinfo
, i
);
4100 if (w
== NULL
|| w
->enable
== 0)
4102 ocap
= w
->param
.outamp_cap
;
4103 icap
= w
->param
.inamp_cap
;
4105 mute
= HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(ocap
);
4106 step
= HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(ocap
);
4107 size
= HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(ocap
);
4108 offset
= HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(ocap
);
4109 /*if (offset > step) {
4111 device_printf(sc->dev,
4112 "HDA_DEBUG: BUGGY outamp: nid=%d "
4113 "[offset=%d > step=%d]\n",
4114 w->nid, offset, step);
4118 ctls
[cnt
].enable
= 1;
4119 ctls
[cnt
].widget
= w
;
4120 ctls
[cnt
].mute
= mute
;
4121 ctls
[cnt
].step
= step
;
4122 ctls
[cnt
].size
= size
;
4123 ctls
[cnt
].offset
= offset
;
4124 ctls
[cnt
].left
= offset
;
4125 ctls
[cnt
].right
= offset
;
4126 ctls
[cnt
++].dir
= HDA_CTL_OUT
;
4130 mute
= HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(icap
);
4131 step
= HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(icap
);
4132 size
= HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(icap
);
4133 offset
= HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(icap
);
4134 /*if (offset > step) {
4136 device_printf(sc->dev,
4137 "HDA_DEBUG: BUGGY inamp: nid=%d "
4138 "[offset=%d > step=%d]\n",
4139 w->nid, offset, step);
4144 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR
:
4145 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER
:
4146 for (j
= 0; j
< w
->nconns
; j
++) {
4148 device_printf(sc
->dev
,
4149 "%s: Ctl overflow!\n",
4153 cw
= hdac_widget_get(devinfo
,
4155 if (cw
== NULL
|| cw
->enable
== 0)
4157 ctls
[cnt
].enable
= 1;
4158 ctls
[cnt
].widget
= w
;
4159 ctls
[cnt
].childwidget
= cw
;
4160 ctls
[cnt
].index
= j
;
4161 ctls
[cnt
].mute
= mute
;
4162 ctls
[cnt
].step
= step
;
4163 ctls
[cnt
].size
= size
;
4164 ctls
[cnt
].offset
= offset
;
4165 ctls
[cnt
].left
= offset
;
4166 ctls
[cnt
].right
= offset
;
4167 ctls
[cnt
++].dir
= HDA_CTL_IN
;
4172 device_printf(sc
->dev
,
4173 "%s: Ctl overflow!\n",
4177 ctls
[cnt
].enable
= 1;
4178 ctls
[cnt
].widget
= w
;
4179 ctls
[cnt
].mute
= mute
;
4180 ctls
[cnt
].step
= step
;
4181 ctls
[cnt
].size
= size
;
4182 ctls
[cnt
].offset
= offset
;
4183 ctls
[cnt
].left
= offset
;
4184 ctls
[cnt
].right
= offset
;
4185 ctls
[cnt
++].dir
= HDA_CTL_IN
;
4191 devinfo
->function
.audio
.ctl
= ctls
;
4194 static const struct {
4197 uint32_t set
, unset
;
4200 * XXX Force stereo quirk. Monoural recording / playback
4201 * on few codecs (especially ALC880) seems broken or
4202 * perhaps unsupported.
4204 { HDA_MATCH_ALL
, HDA_MATCH_ALL
,
4205 HDA_QUIRK_FORCESTEREO
| HDA_QUIRK_IVREF
, 0 },
4206 { ACER_ALL_SUBVENDOR
, HDA_MATCH_ALL
,
4207 HDA_QUIRK_GPIO0
, 0 },
4208 { ASUS_M5200_SUBVENDOR
, HDA_CODEC_ALC880
,
4209 HDA_QUIRK_GPIO0
, 0 },
4210 { ASUS_A7M_SUBVENDOR
, HDA_CODEC_ALC880
,
4211 HDA_QUIRK_GPIO0
, 0 },
4212 { ASUS_A7T_SUBVENDOR
, HDA_CODEC_ALC882
,
4213 HDA_QUIRK_GPIO0
, 0 },
4214 { ASUS_W2J_SUBVENDOR
, HDA_CODEC_ALC882
,
4215 HDA_QUIRK_GPIO0
, 0 },
4216 { ASUS_U5F_SUBVENDOR
, HDA_CODEC_AD1986A
,
4217 HDA_QUIRK_EAPDINV
, 0 },
4218 { ASUS_A8JC_SUBVENDOR
, HDA_CODEC_AD1986A
,
4219 HDA_QUIRK_EAPDINV
, 0 },
4220 { ASUS_F3JC_SUBVENDOR
, HDA_CODEC_ALC861
,
4221 HDA_QUIRK_OVREF
, 0 },
4222 { ASUS_W6F_SUBVENDOR
, HDA_CODEC_ALC861
,
4223 HDA_QUIRK_OVREF
, 0 },
4224 { UNIWILL_9075_SUBVENDOR
, HDA_CODEC_ALC861
,
4225 HDA_QUIRK_OVREF
, 0 },
4226 /*{ ASUS_M2N_SUBVENDOR, HDA_CODEC_AD1988,
4227 HDA_QUIRK_IVREF80, HDA_QUIRK_IVREF50 | HDA_QUIRK_IVREF100 },*/
4228 { MEDION_MD95257_SUBVENDOR
, HDA_CODEC_ALC880
,
4229 HDA_QUIRK_GPIO1
, 0 },
4230 { LENOVO_3KN100_SUBVENDOR
, HDA_CODEC_AD1986A
,
4231 HDA_QUIRK_EAPDINV
, 0 },
4232 { SAMSUNG_Q1_SUBVENDOR
, HDA_CODEC_AD1986A
,
4233 HDA_QUIRK_EAPDINV
, 0 },
4234 { APPLE_MB3_SUBVENDOR
, HDA_CODEC_ALC885
,
4235 HDA_QUIRK_GPIO0
| HDA_QUIRK_OVREF50
, 0},
4236 { APPLE_INTEL_MAC
, HDA_CODEC_STAC9221
,
4237 HDA_QUIRK_GPIO0
| HDA_QUIRK_GPIO1
, 0 },
4238 { HDA_MATCH_ALL
, HDA_CODEC_AD1988
,
4239 HDA_QUIRK_IVREF80
, HDA_QUIRK_IVREF50
| HDA_QUIRK_IVREF100
},
4240 { HDA_MATCH_ALL
, HDA_CODEC_AD1988B
,
4241 HDA_QUIRK_IVREF80
, HDA_QUIRK_IVREF50
| HDA_QUIRK_IVREF100
},
4242 { HDA_MATCH_ALL
, HDA_CODEC_CXVENICE
,
4243 0, HDA_QUIRK_FORCESTEREO
},
4244 { HDA_MATCH_ALL
, HDA_CODEC_STACXXXX
,
4245 HDA_QUIRK_SOFTPCMVOL
, 0 }
4247 #define HDAC_QUIRKS_LEN (sizeof(hdac_quirks) / sizeof(hdac_quirks[0]))
4250 hdac_vendor_patch_parse(struct hdac_devinfo
*devinfo
)
4252 struct hdac_widget
*w
;
4253 struct hdac_audio_ctl
*ctl
;
4254 uint32_t id
, subvendor
;
4257 id
= hdac_codec_id(devinfo
);
4258 subvendor
= devinfo
->codec
->sc
->pci_subvendor
;
4263 for (i
= 0; i
< HDAC_QUIRKS_LEN
; i
++) {
4264 if (!(HDA_DEV_MATCH(hdac_quirks
[i
].model
, subvendor
) &&
4265 HDA_DEV_MATCH(hdac_quirks
[i
].id
, id
)))
4267 if (hdac_quirks
[i
].set
!= 0)
4268 devinfo
->function
.audio
.quirks
|=
4270 if (hdac_quirks
[i
].unset
!= 0)
4271 devinfo
->function
.audio
.quirks
&=
4272 ~(hdac_quirks
[i
].unset
);
4276 case HDA_CODEC_ALC260
:
4277 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
4278 w
= hdac_widget_get(devinfo
, i
);
4279 if (w
== NULL
|| w
->enable
== 0)
4282 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT
)
4287 if (subvendor
== HP_XW4300_SUBVENDOR
) {
4288 ctl
= hdac_audio_ctl_amp_get(devinfo
, 16, 0, 1);
4289 if (ctl
!= NULL
&& ctl
->widget
!= NULL
) {
4290 ctl
->ossmask
= SOUND_MASK_SPEAKER
;
4291 ctl
->widget
->ctlflags
|= SOUND_MASK_SPEAKER
;
4293 ctl
= hdac_audio_ctl_amp_get(devinfo
, 17, 0, 1);
4294 if (ctl
!= NULL
&& ctl
->widget
!= NULL
) {
4295 ctl
->ossmask
= SOUND_MASK_SPEAKER
;
4296 ctl
->widget
->ctlflags
|= SOUND_MASK_SPEAKER
;
4298 } else if (subvendor
== HP_3010_SUBVENDOR
) {
4299 ctl
= hdac_audio_ctl_amp_get(devinfo
, 17, 0, 1);
4300 if (ctl
!= NULL
&& ctl
->widget
!= NULL
) {
4301 ctl
->ossmask
= SOUND_MASK_SPEAKER
;
4302 ctl
->widget
->ctlflags
|= SOUND_MASK_SPEAKER
;
4304 ctl
= hdac_audio_ctl_amp_get(devinfo
, 21, 0, 1);
4305 if (ctl
!= NULL
&& ctl
->widget
!= NULL
) {
4306 ctl
->ossmask
= SOUND_MASK_SPEAKER
;
4307 ctl
->widget
->ctlflags
|= SOUND_MASK_SPEAKER
;
4311 case HDA_CODEC_ALC262
:
4312 if (subvendor
== HP_DC7700_SUBVENDOR
) {
4313 ctl
= hdac_audio_ctl_amp_get(devinfo
, 22, 0, 1);
4314 if (ctl
!= NULL
&& ctl
->widget
!= NULL
) {
4315 ctl
->ossmask
= SOUND_MASK_SPEAKER
;
4316 ctl
->widget
->ctlflags
|= SOUND_MASK_SPEAKER
;
4318 ctl
= hdac_audio_ctl_amp_get(devinfo
, 27, 0, 1);
4319 if (ctl
!= NULL
&& ctl
->widget
!= NULL
) {
4320 ctl
->ossmask
= SOUND_MASK_SPEAKER
;
4321 ctl
->widget
->ctlflags
|= SOUND_MASK_SPEAKER
;
4325 case HDA_CODEC_ALC861
:
4326 ctl
= hdac_audio_ctl_amp_get(devinfo
, 21, 2, 1);
4328 ctl
->muted
= HDA_AMP_MUTE_ALL
;
4330 case HDA_CODEC_ALC880
:
4331 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
4332 w
= hdac_widget_get(devinfo
, i
);
4333 if (w
== NULL
|| w
->enable
== 0)
4336 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT
&&
4337 w
->nid
!= 9 && w
->nid
!= 29) {
4339 } else if (w
->type
!=
4340 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET
&&
4343 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET
;
4344 w
->param
.widget_cap
&=
4345 ~HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_MASK
;
4346 w
->param
.widget_cap
|=
4347 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET
<<
4348 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_SHIFT
;
4349 strlcpy(w
->name
, "beep widget", sizeof(w
->name
));
4353 case HDA_CODEC_ALC883
:
4355 * nid: 24/25 = External (jack) or Internal (fixed) Mic.
4356 * Clear vref cap for jack connectivity.
4358 w
= hdac_widget_get(devinfo
, 24);
4359 if (w
!= NULL
&& w
->enable
!= 0 && w
->type
==
4360 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
&&
4361 (w
->wclass
.pin
.config
&
4362 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK
) ==
4363 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_JACK
)
4364 w
->wclass
.pin
.cap
&= ~(
4365 HDA_PARAM_PIN_CAP_VREF_CTRL_100_MASK
|
4366 HDA_PARAM_PIN_CAP_VREF_CTRL_80_MASK
|
4367 HDA_PARAM_PIN_CAP_VREF_CTRL_50_MASK
);
4368 w
= hdac_widget_get(devinfo
, 25);
4369 if (w
!= NULL
&& w
->enable
!= 0 && w
->type
==
4370 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
&&
4371 (w
->wclass
.pin
.config
&
4372 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK
) ==
4373 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_JACK
)
4374 w
->wclass
.pin
.cap
&= ~(
4375 HDA_PARAM_PIN_CAP_VREF_CTRL_100_MASK
|
4376 HDA_PARAM_PIN_CAP_VREF_CTRL_80_MASK
|
4377 HDA_PARAM_PIN_CAP_VREF_CTRL_50_MASK
);
4379 * nid: 26 = Line-in, leave it alone.
4382 case HDA_CODEC_AD1981HD
:
4383 w
= hdac_widget_get(devinfo
, 11);
4384 if (w
!= NULL
&& w
->enable
!= 0 && w
->nconns
> 3)
4386 if (subvendor
== IBM_M52_SUBVENDOR
) {
4387 ctl
= hdac_audio_ctl_amp_get(devinfo
, 7, 0, 1);
4389 ctl
->ossmask
= SOUND_MASK_SPEAKER
;
4392 case HDA_CODEC_AD1986A
:
4393 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
4394 w
= hdac_widget_get(devinfo
, i
);
4395 if (w
== NULL
|| w
->enable
== 0)
4398 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT
)
4403 if (subvendor
== ASUS_M2NPVMX_SUBVENDOR
||
4404 subvendor
== ASUS_A8NVMCSM_SUBVENDOR
) {
4405 /* nid 28 is mic, nid 29 is line-in */
4406 w
= hdac_widget_get(devinfo
, 15);
4409 w
= hdac_widget_get(devinfo
, 16);
4414 case HDA_CODEC_AD1988
:
4415 case HDA_CODEC_AD1988B
:
4416 /*w = hdac_widget_get(devinfo, 12);
4419 w->pflags |= HDA_ADC_LOCKED;
4421 w = hdac_widget_get(devinfo, 13);
4424 w->pflags |= HDA_ADC_LOCKED;
4426 w = hdac_widget_get(devinfo, 14);
4429 w->pflags |= HDA_ADC_LOCKED;
4431 ctl
= hdac_audio_ctl_amp_get(devinfo
, 57, 0, 1);
4433 ctl
->ossmask
= SOUND_MASK_IGAIN
;
4434 ctl
->widget
->ctlflags
|= SOUND_MASK_IGAIN
;
4436 ctl
= hdac_audio_ctl_amp_get(devinfo
, 58, 0, 1);
4438 ctl
->ossmask
= SOUND_MASK_IGAIN
;
4439 ctl
->widget
->ctlflags
|= SOUND_MASK_IGAIN
;
4441 ctl
= hdac_audio_ctl_amp_get(devinfo
, 60, 0, 1);
4443 ctl
->ossmask
= SOUND_MASK_IGAIN
;
4444 ctl
->widget
->ctlflags
|= SOUND_MASK_IGAIN
;
4446 ctl
= hdac_audio_ctl_amp_get(devinfo
, 32, 0, 1);
4448 ctl
->ossmask
= SOUND_MASK_MIC
| SOUND_MASK_VOLUME
;
4449 ctl
->widget
->ctlflags
|= SOUND_MASK_MIC
;
4451 ctl
= hdac_audio_ctl_amp_get(devinfo
, 32, 4, 1);
4453 ctl
->ossmask
= SOUND_MASK_MIC
| SOUND_MASK_VOLUME
;
4454 ctl
->widget
->ctlflags
|= SOUND_MASK_MIC
;
4456 ctl
= hdac_audio_ctl_amp_get(devinfo
, 32, 1, 1);
4458 ctl
->ossmask
= SOUND_MASK_LINE
| SOUND_MASK_VOLUME
;
4459 ctl
->widget
->ctlflags
|= SOUND_MASK_LINE
;
4461 ctl
= hdac_audio_ctl_amp_get(devinfo
, 32, 7, 1);
4463 ctl
->ossmask
= SOUND_MASK_SPEAKER
| SOUND_MASK_VOLUME
;
4464 ctl
->widget
->ctlflags
|= SOUND_MASK_SPEAKER
;
4467 case HDA_CODEC_STAC9221
:
4469 * Dell XPS M1210 need all DACs for each output jacks
4471 if (subvendor
== DELL_XPSM1210_SUBVENDOR
)
4473 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
4474 w
= hdac_widget_get(devinfo
, i
);
4475 if (w
== NULL
|| w
->enable
== 0)
4478 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT
)
4484 case HDA_CODEC_STAC9221D
:
4485 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
4486 w
= hdac_widget_get(devinfo
, i
);
4487 if (w
== NULL
|| w
->enable
== 0)
4490 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT
&&
4496 case HDA_CODEC_STAC9227
:
4497 w
= hdac_widget_get(devinfo
, 8);
4500 w
= hdac_widget_get(devinfo
, 9);
4504 case HDA_CODEC_CXWAIKIKI
:
4505 if (subvendor
== HP_DV5000_SUBVENDOR
) {
4506 w
= hdac_widget_get(devinfo
, 27);
4510 ctl
= hdac_audio_ctl_amp_get(devinfo
, 16, 0, 1);
4512 ctl
->ossmask
= SOUND_MASK_SKIP
;
4513 ctl
= hdac_audio_ctl_amp_get(devinfo
, 25, 0, 1);
4514 if (ctl
!= NULL
&& ctl
->childwidget
!= NULL
&&
4515 ctl
->childwidget
->enable
!= 0) {
4516 ctl
->ossmask
= SOUND_MASK_PCM
| SOUND_MASK_VOLUME
;
4517 ctl
->childwidget
->ctlflags
|= SOUND_MASK_PCM
;
4519 ctl
= hdac_audio_ctl_amp_get(devinfo
, 25, 1, 1);
4520 if (ctl
!= NULL
&& ctl
->childwidget
!= NULL
&&
4521 ctl
->childwidget
->enable
!= 0) {
4522 ctl
->ossmask
= SOUND_MASK_LINE
| SOUND_MASK_VOLUME
;
4523 ctl
->childwidget
->ctlflags
|= SOUND_MASK_LINE
;
4525 ctl
= hdac_audio_ctl_amp_get(devinfo
, 25, 2, 1);
4526 if (ctl
!= NULL
&& ctl
->childwidget
!= NULL
&&
4527 ctl
->childwidget
->enable
!= 0) {
4528 ctl
->ossmask
= SOUND_MASK_MIC
| SOUND_MASK_VOLUME
;
4529 ctl
->childwidget
->ctlflags
|= SOUND_MASK_MIC
;
4531 ctl
= hdac_audio_ctl_amp_get(devinfo
, 26, 0, 1);
4533 ctl
->ossmask
= SOUND_MASK_SKIP
;
4534 /* XXX mixer \=rec mic broken.. why?!? */
4535 /* ctl->widget->ctlflags |= SOUND_MASK_MIC; */
4544 hdac_audio_ctl_ossmixer_getnextdev(struct hdac_devinfo
*devinfo
)
4546 int *dev
= &devinfo
->function
.audio
.ossidx
;
4548 while (*dev
< SOUND_MIXER_NRDEVICES
) {
4550 case SOUND_MIXER_VOLUME
:
4551 case SOUND_MIXER_BASS
:
4552 case SOUND_MIXER_TREBLE
:
4553 case SOUND_MIXER_PCM
:
4554 case SOUND_MIXER_SPEAKER
:
4555 case SOUND_MIXER_LINE
:
4556 case SOUND_MIXER_MIC
:
4557 case SOUND_MIXER_CD
:
4558 case SOUND_MIXER_RECLEV
:
4559 case SOUND_MIXER_IGAIN
:
4560 case SOUND_MIXER_OGAIN
: /* reserved for EAPD switch */
4573 hdac_widget_find_dac_path(struct hdac_devinfo
*devinfo
, nid_t nid
, int depth
)
4575 struct hdac_widget
*w
;
4578 if (depth
> HDA_PARSE_MAXDEPTH
)
4580 w
= hdac_widget_get(devinfo
, nid
);
4581 if (w
== NULL
|| w
->enable
== 0)
4584 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT
:
4585 w
->pflags
|= HDA_DAC_PATH
;
4588 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER
:
4589 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR
:
4590 for (i
= 0; i
< w
->nconns
; i
++) {
4591 if (hdac_widget_find_dac_path(devinfo
,
4592 w
->conns
[i
], depth
+ 1) != 0) {
4593 if (w
->selconn
== -1)
4596 w
->pflags
|= HDA_DAC_PATH
;
4607 hdac_widget_find_adc_path(struct hdac_devinfo
*devinfo
, nid_t nid
, int depth
)
4609 struct hdac_widget
*w
;
4610 int i
, conndev
, ret
= 0;
4612 if (depth
> HDA_PARSE_MAXDEPTH
)
4614 w
= hdac_widget_get(devinfo
, nid
);
4615 if (w
== NULL
|| w
->enable
== 0)
4618 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT
:
4619 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR
:
4620 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER
:
4621 for (i
= 0; i
< w
->nconns
; i
++) {
4622 if (hdac_widget_find_adc_path(devinfo
, w
->conns
[i
],
4624 if (w
->selconn
== -1)
4626 w
->pflags
|= HDA_ADC_PATH
;
4631 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
:
4632 conndev
= w
->wclass
.pin
.config
&
4633 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
;
4634 if (HDA_PARAM_PIN_CAP_INPUT_CAP(w
->wclass
.pin
.cap
) &&
4635 (conndev
== HDA_CONFIG_DEFAULTCONF_DEVICE_CD
||
4636 conndev
== HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN
||
4637 conndev
== HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN
)) {
4638 w
->pflags
|= HDA_ADC_PATH
;
4642 /*case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER:
4643 if (w->pflags & HDA_DAC_PATH) {
4644 w->pflags |= HDA_ADC_PATH;
4655 hdac_audio_ctl_outamp_build(struct hdac_devinfo
*devinfo
,
4656 nid_t nid
, nid_t pnid
, int index
, int depth
)
4658 struct hdac_widget
*w
, *pw
;
4659 struct hdac_audio_ctl
*ctl
;
4661 int i
, ossdev
, conndev
, strategy
;
4663 if (depth
> HDA_PARSE_MAXDEPTH
)
4666 w
= hdac_widget_get(devinfo
, nid
);
4667 if (w
== NULL
|| w
->enable
== 0)
4670 pw
= hdac_widget_get(devinfo
, pnid
);
4671 strategy
= devinfo
->function
.audio
.parsing_strategy
;
4673 if (w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER
4674 || w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR
) {
4675 for (i
= 0; i
< w
->nconns
; i
++) {
4676 fl
|= hdac_audio_ctl_outamp_build(devinfo
, w
->conns
[i
],
4677 w
->nid
, i
, depth
+ 1);
4681 } else if (w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT
&&
4682 (w
->pflags
& HDA_DAC_PATH
)) {
4684 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) != NULL
) {
4685 if (ctl
->enable
== 0 || ctl
->widget
== NULL
)
4687 /* XXX This should be compressed! */
4688 if (((ctl
->widget
->nid
== w
->nid
) ||
4689 (ctl
->widget
->nid
== pnid
&& ctl
->index
== index
&&
4690 (ctl
->dir
& HDA_CTL_IN
)) ||
4691 (ctl
->widget
->nid
== pnid
&& pw
!= NULL
&&
4693 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR
&&
4694 (pw
->nconns
< 2 || pw
->selconn
== index
||
4695 pw
->selconn
== -1) &&
4696 (ctl
->dir
& HDA_CTL_OUT
)) ||
4697 (strategy
== HDA_PARSE_DIRECT
&&
4698 ctl
->widget
->nid
== w
->nid
)) &&
4699 !(ctl
->ossmask
& ~SOUND_MASK_VOLUME
)) {
4700 /*if (pw != NULL && pw->selconn == -1)
4701 pw->selconn = index;
4702 fl |= SOUND_MASK_VOLUME;
4703 fl |= SOUND_MASK_PCM;
4704 ctl->ossmask |= SOUND_MASK_VOLUME;
4705 ctl->ossmask |= SOUND_MASK_PCM;
4706 ctl->ossdev = SOUND_MIXER_PCM;*/
4707 if (!(w
->ctlflags
& SOUND_MASK_PCM
) ||
4709 !(pw
->ctlflags
& SOUND_MASK_PCM
))) {
4710 fl
|= SOUND_MASK_VOLUME
;
4711 fl
|= SOUND_MASK_PCM
;
4712 ctl
->ossmask
|= SOUND_MASK_VOLUME
;
4713 ctl
->ossmask
|= SOUND_MASK_PCM
;
4714 ctl
->ossdev
= SOUND_MIXER_PCM
;
4715 w
->ctlflags
|= SOUND_MASK_VOLUME
;
4716 w
->ctlflags
|= SOUND_MASK_PCM
;
4718 if (pw
->selconn
== -1)
4719 pw
->selconn
= index
;
4730 } else if (w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
&&
4731 HDA_PARAM_PIN_CAP_INPUT_CAP(w
->wclass
.pin
.cap
) &&
4732 (w
->pflags
& HDA_ADC_PATH
)) {
4733 conndev
= w
->wclass
.pin
.config
&
4734 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
;
4736 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) != NULL
) {
4737 if (ctl
->enable
== 0 || ctl
->widget
== NULL
)
4739 /* XXX This should be compressed! */
4740 if (((ctl
->widget
->nid
== pnid
&& ctl
->index
== index
&&
4741 (ctl
->dir
& HDA_CTL_IN
)) ||
4742 (ctl
->widget
->nid
== pnid
&& pw
!= NULL
&&
4744 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR
&&
4745 (pw
->nconns
< 2 || pw
->selconn
== index
||
4746 pw
->selconn
== -1) &&
4747 (ctl
->dir
& HDA_CTL_OUT
)) ||
4748 (strategy
== HDA_PARSE_DIRECT
&&
4749 ctl
->widget
->nid
== w
->nid
)) &&
4750 !(ctl
->ossmask
& ~SOUND_MASK_VOLUME
)) {
4751 if (pw
!= NULL
&& pw
->selconn
== -1)
4752 pw
->selconn
= index
;
4755 case HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN
:
4756 ossdev
= SOUND_MIXER_MIC
;
4758 case HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN
:
4759 ossdev
= SOUND_MIXER_LINE
;
4761 case HDA_CONFIG_DEFAULTCONF_DEVICE_CD
:
4762 ossdev
= SOUND_MIXER_CD
;
4766 hdac_audio_ctl_ossmixer_getnextdev(
4772 if (strategy
== HDA_PARSE_MIXER
) {
4773 fl
|= SOUND_MASK_VOLUME
;
4774 ctl
->ossmask
|= SOUND_MASK_VOLUME
;
4777 ctl
->ossmask
|= 1 << ossdev
;
4778 ctl
->ossdev
= ossdev
;
4783 } else if (w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET
) {
4785 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) != NULL
) {
4786 if (ctl
->enable
== 0 || ctl
->widget
== NULL
)
4788 /* XXX This should be compressed! */
4789 if (((ctl
->widget
->nid
== pnid
&& ctl
->index
== index
&&
4790 (ctl
->dir
& HDA_CTL_IN
)) ||
4791 (ctl
->widget
->nid
== pnid
&& pw
!= NULL
&&
4793 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR
&&
4794 (pw
->nconns
< 2 || pw
->selconn
== index
||
4795 pw
->selconn
== -1) &&
4796 (ctl
->dir
& HDA_CTL_OUT
)) ||
4797 (strategy
== HDA_PARSE_DIRECT
&&
4798 ctl
->widget
->nid
== w
->nid
)) &&
4799 !(ctl
->ossmask
& ~SOUND_MASK_VOLUME
)) {
4800 if (pw
!= NULL
&& pw
->selconn
== -1)
4801 pw
->selconn
= index
;
4802 fl
|= SOUND_MASK_VOLUME
;
4803 fl
|= SOUND_MASK_SPEAKER
;
4804 ctl
->ossmask
|= SOUND_MASK_VOLUME
;
4805 ctl
->ossmask
|= SOUND_MASK_SPEAKER
;
4806 ctl
->ossdev
= SOUND_MIXER_SPEAKER
;
4816 hdac_audio_ctl_inamp_build(struct hdac_devinfo
*devinfo
, nid_t nid
, int depth
)
4818 struct hdac_widget
*w
, *cw
;
4819 struct hdac_audio_ctl
*ctl
;
4823 if (depth
> HDA_PARSE_MAXDEPTH
)
4826 w
= hdac_widget_get(devinfo
, nid
);
4827 if (w
== NULL
|| w
->enable
== 0)
4829 /*if (!(w->pflags & HDA_ADC_PATH))
4831 if (!(w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT ||
4832 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR))
4835 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) != NULL
) {
4836 if (ctl
->enable
== 0 || ctl
->widget
== NULL
)
4838 if (ctl
->widget
->nid
== nid
) {
4839 ctl
->ossmask
|= SOUND_MASK_RECLEV
;
4840 w
->ctlflags
|= SOUND_MASK_RECLEV
;
4841 return (SOUND_MASK_RECLEV
);
4844 for (i
= 0; i
< w
->nconns
; i
++) {
4845 cw
= hdac_widget_get(devinfo
, w
->conns
[i
]);
4846 if (cw
== NULL
|| cw
->enable
== 0)
4848 if (cw
->type
!= HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR
)
4850 fl
= hdac_audio_ctl_inamp_build(devinfo
, cw
->nid
, depth
+ 1);
4861 hdac_audio_ctl_recsel_build(struct hdac_devinfo
*devinfo
, nid_t nid
, int depth
)
4863 struct hdac_widget
*w
, *cw
;
4866 if (depth
> HDA_PARSE_MAXDEPTH
)
4869 w
= hdac_widget_get(devinfo
, nid
);
4870 if (w
== NULL
|| w
->enable
== 0)
4872 /*if (!(w->pflags & HDA_ADC_PATH))
4874 if (!(w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT ||
4875 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR))
4878 for (i
= 0; i
< w
->nconns
; i
++) {
4879 cw
= hdac_widget_get(devinfo
, w
->conns
[i
]);
4883 w
->pflags
|= HDA_ADC_RECSEL
;
4887 for (i
= 0; i
< w
->nconns
; i
++) {
4888 if (hdac_audio_ctl_recsel_build(devinfo
,
4889 w
->conns
[i
], depth
+ 1) != 0)
4896 hdac_audio_build_tree_strategy(struct hdac_devinfo
*devinfo
)
4898 struct hdac_widget
*w
, *cw
;
4899 int i
, j
, conndev
, found_dac
= 0;
4902 strategy
= devinfo
->function
.audio
.parsing_strategy
;
4904 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
4905 w
= hdac_widget_get(devinfo
, i
);
4906 if (w
== NULL
|| w
->enable
== 0)
4908 if (w
->type
!= HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
)
4910 if (!HDA_PARAM_PIN_CAP_OUTPUT_CAP(w
->wclass
.pin
.cap
))
4912 conndev
= w
->wclass
.pin
.config
&
4913 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
;
4914 if (!(conndev
== HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT
||
4915 conndev
== HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER
||
4916 conndev
== HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_OUT
))
4918 for (j
= 0; j
< w
->nconns
; j
++) {
4919 cw
= hdac_widget_get(devinfo
, w
->conns
[j
]);
4920 if (cw
== NULL
|| cw
->enable
== 0)
4922 if (strategy
== HDA_PARSE_MIXER
&& !(cw
->type
==
4923 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER
||
4925 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR
))
4927 if (hdac_widget_find_dac_path(devinfo
, cw
->nid
, 0)
4929 if (w
->selconn
== -1)
4931 w
->pflags
|= HDA_DAC_PATH
;
4941 hdac_audio_build_tree(struct hdac_devinfo
*devinfo
)
4943 struct hdac_widget
*w
;
4944 struct hdac_audio_ctl
*ctl
;
4945 int i
, j
, dacs
, strategy
;
4947 /* Construct DAC path */
4948 strategy
= HDA_PARSE_MIXER
;
4949 devinfo
->function
.audio
.parsing_strategy
= strategy
;
4951 device_printf(devinfo
->codec
->sc
->dev
,
4952 "HDA_DEBUG: HWiP: HDA Widget Parser - Revision %d\n",
4953 HDA_WIDGET_PARSER_REV
);
4955 dacs
= hdac_audio_build_tree_strategy(devinfo
);
4958 device_printf(devinfo
->codec
->sc
->dev
,
4959 "HDA_DEBUG: HWiP: 0 DAC path found! "
4961 "using HDA_PARSE_DIRECT strategy.\n");
4963 strategy
= HDA_PARSE_DIRECT
;
4964 devinfo
->function
.audio
.parsing_strategy
= strategy
;
4965 dacs
= hdac_audio_build_tree_strategy(devinfo
);
4969 device_printf(devinfo
->codec
->sc
->dev
,
4970 "HDA_DEBUG: HWiP: Found %d DAC path using HDA_PARSE_%s "
4972 dacs
, (strategy
== HDA_PARSE_MIXER
) ? "MIXER" : "DIRECT");
4975 /* Construct ADC path */
4976 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
4977 w
= hdac_widget_get(devinfo
, i
);
4978 if (w
== NULL
|| w
->enable
== 0)
4980 if (w
->type
!= HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT
)
4982 (void)hdac_widget_find_adc_path(devinfo
, w
->nid
, 0);
4986 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
4987 w
= hdac_widget_get(devinfo
, i
);
4988 if (w
== NULL
|| w
->enable
== 0)
4990 if ((strategy
== HDA_PARSE_MIXER
&&
4991 (w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER
||
4992 w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR
)
4993 && (w
->pflags
& HDA_DAC_PATH
)) ||
4994 (strategy
== HDA_PARSE_DIRECT
&& (w
->pflags
&
4995 (HDA_DAC_PATH
| HDA_ADC_PATH
)))) {
4996 w
->ctlflags
|= hdac_audio_ctl_outamp_build(devinfo
,
4997 w
->nid
, devinfo
->startnode
- 1, 0, 0);
4998 } else if (w
->type
==
4999 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET
) {
5001 while ((ctl
= hdac_audio_ctl_each(devinfo
, &j
)) !=
5003 if (ctl
->enable
== 0 || ctl
->widget
== NULL
)
5005 if (ctl
->widget
->nid
!= w
->nid
)
5007 ctl
->ossmask
|= SOUND_MASK_VOLUME
;
5008 ctl
->ossmask
|= SOUND_MASK_SPEAKER
;
5009 ctl
->ossdev
= SOUND_MIXER_SPEAKER
;
5010 w
->ctlflags
|= SOUND_MASK_VOLUME
;
5011 w
->ctlflags
|= SOUND_MASK_SPEAKER
;
5016 /* Input mixers (rec) */
5017 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
5018 w
= hdac_widget_get(devinfo
, i
);
5019 if (w
== NULL
|| w
->enable
== 0)
5021 if (!(w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT
&&
5022 w
->pflags
& HDA_ADC_PATH
))
5024 hdac_audio_ctl_inamp_build(devinfo
, w
->nid
, 0);
5025 hdac_audio_ctl_recsel_build(devinfo
, w
->nid
, 0);
5029 #define HDA_COMMIT_CONN (1 << 0)
5030 #define HDA_COMMIT_CTRL (1 << 1)
5031 #define HDA_COMMIT_EAPD (1 << 2)
5032 #define HDA_COMMIT_GPIO (1 << 3)
5033 #define HDA_COMMIT_MISC (1 << 4)
5034 #define HDA_COMMIT_ALL (HDA_COMMIT_CONN | HDA_COMMIT_CTRL | \
5035 HDA_COMMIT_EAPD | HDA_COMMIT_GPIO | HDA_COMMIT_MISC)
5038 hdac_audio_commit(struct hdac_devinfo
*devinfo
, uint32_t cfl
)
5040 struct hdac_softc
*sc
= devinfo
->codec
->sc
;
5041 struct hdac_widget
*w
;
5045 if (!(cfl
& HDA_COMMIT_ALL
))
5048 cad
= devinfo
->codec
->cad
;
5050 if ((cfl
& HDA_COMMIT_MISC
)) {
5051 if (sc
->pci_subvendor
== APPLE_INTEL_MAC
)
5052 hdac_command(sc
, HDA_CMD_12BIT(cad
, devinfo
->nid
,
5056 if (cfl
& HDA_COMMIT_GPIO
) {
5057 uint32_t gdata
, gmask
, gdir
;
5058 int commitgpio
, numgpio
;
5065 numgpio
= HDA_PARAM_GPIO_COUNT_NUM_GPIO(
5066 devinfo
->function
.audio
.gpio
);
5068 if (devinfo
->function
.audio
.quirks
& HDA_QUIRK_GPIOFLUSH
)
5069 commitgpio
= (numgpio
> 0) ? 1 : 0;
5071 for (i
= 0; i
< numgpio
&& i
< HDA_GPIO_MAX
; i
++) {
5072 if (!(devinfo
->function
.audio
.quirks
&
5075 if (commitgpio
== 0) {
5078 gdata
= hdac_command(sc
,
5079 HDA_CMD_GET_GPIO_DATA(cad
,
5080 devinfo
->nid
), cad
);
5081 gmask
= hdac_command(sc
,
5082 HDA_CMD_GET_GPIO_ENABLE_MASK(cad
,
5083 devinfo
->nid
), cad
);
5084 gdir
= hdac_command(sc
,
5085 HDA_CMD_GET_GPIO_DIRECTION(cad
,
5086 devinfo
->nid
), cad
);
5087 device_printf(sc
->dev
,
5088 "GPIO init: data=0x%08x "
5089 "mask=0x%08x dir=0x%08x\n",
5090 gdata
, gmask
, gdir
);
5102 if (commitgpio
!= 0) {
5104 device_printf(sc
->dev
,
5105 "GPIO commit: data=0x%08x mask=0x%08x "
5107 gdata
, gmask
, gdir
);
5110 HDA_CMD_SET_GPIO_ENABLE_MASK(cad
, devinfo
->nid
,
5113 HDA_CMD_SET_GPIO_DIRECTION(cad
, devinfo
->nid
,
5116 HDA_CMD_SET_GPIO_DATA(cad
, devinfo
->nid
,
5121 for (i
= 0; i
< devinfo
->nodecnt
; i
++) {
5122 w
= &devinfo
->widget
[i
];
5123 if (w
== NULL
|| w
->enable
== 0)
5125 if (cfl
& HDA_COMMIT_CONN
) {
5126 if (w
->selconn
== -1)
5129 hdac_widget_connection_select(w
, w
->selconn
);
5131 if ((cfl
& HDA_COMMIT_CTRL
) &&
5132 w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
) {
5135 pincap
= w
->wclass
.pin
.cap
;
5137 if ((w
->pflags
& (HDA_DAC_PATH
| HDA_ADC_PATH
)) ==
5138 (HDA_DAC_PATH
| HDA_ADC_PATH
))
5139 device_printf(sc
->dev
, "WARNING: node %d "
5140 "participate both for DAC/ADC!\n", w
->nid
);
5141 if (w
->pflags
& HDA_DAC_PATH
) {
5142 w
->wclass
.pin
.ctrl
&=
5143 ~HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE
;
5144 if ((w
->wclass
.pin
.config
&
5145 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
) !=
5146 HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT
)
5147 w
->wclass
.pin
.ctrl
&=
5148 ~HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE
;
5149 if ((devinfo
->function
.audio
.quirks
& HDA_QUIRK_OVREF100
) &&
5150 HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap
))
5151 w
->wclass
.pin
.ctrl
|=
5152 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
5153 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_100
);
5154 else if ((devinfo
->function
.audio
.quirks
& HDA_QUIRK_OVREF80
) &&
5155 HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap
))
5156 w
->wclass
.pin
.ctrl
|=
5157 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
5158 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_80
);
5159 else if ((devinfo
->function
.audio
.quirks
& HDA_QUIRK_OVREF50
) &&
5160 HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap
))
5161 w
->wclass
.pin
.ctrl
|=
5162 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
5163 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_50
);
5164 } else if (w
->pflags
& HDA_ADC_PATH
) {
5165 w
->wclass
.pin
.ctrl
&=
5166 ~(HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE
|
5167 HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE
);
5168 if ((devinfo
->function
.audio
.quirks
& HDA_QUIRK_IVREF100
) &&
5169 HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap
))
5170 w
->wclass
.pin
.ctrl
|=
5171 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
5172 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_100
);
5173 else if ((devinfo
->function
.audio
.quirks
& HDA_QUIRK_IVREF80
) &&
5174 HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap
))
5175 w
->wclass
.pin
.ctrl
|=
5176 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
5177 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_80
);
5178 else if ((devinfo
->function
.audio
.quirks
& HDA_QUIRK_IVREF50
) &&
5179 HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap
))
5180 w
->wclass
.pin
.ctrl
|=
5181 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
5182 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_50
);
5184 w
->wclass
.pin
.ctrl
&= ~(
5185 HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE
|
5186 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE
|
5187 HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE
|
5188 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK
);
5190 HDA_CMD_SET_PIN_WIDGET_CTRL(cad
, w
->nid
,
5191 w
->wclass
.pin
.ctrl
), cad
);
5193 if ((cfl
& HDA_COMMIT_EAPD
) &&
5194 w
->param
.eapdbtl
!= HDAC_INVALID
) {
5197 val
= w
->param
.eapdbtl
;
5198 if (devinfo
->function
.audio
.quirks
&
5200 val
^= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD
;
5202 HDA_CMD_SET_EAPD_BTL_ENABLE(cad
, w
->nid
,
5211 hdac_audio_ctl_commit(struct hdac_devinfo
*devinfo
)
5213 struct hdac_softc
*sc
= devinfo
->codec
->sc
;
5214 struct hdac_audio_ctl
*ctl
;
5217 devinfo
->function
.audio
.mvol
= 100 | (100 << 8);
5219 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) != NULL
) {
5220 if (ctl
->enable
== 0 || ctl
->widget
== NULL
) {
5222 device_printf(sc
->dev
, "[%2d] Ctl nid=%d",
5223 i
, (ctl
->widget
!= NULL
) ?
5224 ctl
->widget
->nid
: -1);
5225 if (ctl
->childwidget
!= NULL
)
5226 kprintf(" childnid=%d",
5227 ctl
->childwidget
->nid
);
5228 if (ctl
->widget
== NULL
)
5229 kprintf(" NULL WIDGET!");
5230 kprintf(" DISABLED\n");
5235 if (ctl
->ossmask
== 0) {
5236 device_printf(sc
->dev
, "[%2d] Ctl nid=%d",
5237 i
, ctl
->widget
->nid
);
5238 if (ctl
->childwidget
!= NULL
)
5239 kprintf(" childnid=%d",
5240 ctl
->childwidget
->nid
);
5241 kprintf(" Bind to NONE\n");
5244 if (ctl
->step
> 0) {
5245 ctl
->ossval
= (ctl
->left
* 100) / ctl
->step
;
5246 ctl
->ossval
|= ((ctl
->right
* 100) / ctl
->step
) << 8;
5249 hdac_audio_ctl_amp_set(ctl
, HDA_AMP_MUTE_DEFAULT
,
5250 ctl
->left
, ctl
->right
);
5255 hdac_pcmchannel_setup(struct hdac_devinfo
*devinfo
, int dir
)
5257 struct hdac_chan
*ch
;
5258 struct hdac_widget
*w
;
5259 uint32_t cap
, fmtcap
, pcmcap
, path
;
5260 int i
, type
, ret
, max
;
5262 if (dir
== PCMDIR_PLAY
) {
5263 type
= HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT
;
5264 ch
= &devinfo
->codec
->sc
->play
;
5265 path
= HDA_DAC_PATH
;
5267 type
= HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT
;
5268 ch
= &devinfo
->codec
->sc
->rec
;
5269 path
= HDA_ADC_PATH
;
5272 ch
->caps
= hdac_caps
;
5273 ch
->caps
.fmtlist
= ch
->fmtlist
;
5276 ch
->pcmrates
[0] = 48000;
5277 ch
->pcmrates
[1] = 0;
5280 fmtcap
= devinfo
->function
.audio
.supp_stream_formats
;
5281 pcmcap
= devinfo
->function
.audio
.supp_pcm_size_rate
;
5282 max
= (sizeof(ch
->io
) / sizeof(ch
->io
[0])) - 1;
5284 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
&& ret
< max
; i
++) {
5285 w
= hdac_widget_get(devinfo
, i
);
5286 if (w
== NULL
|| w
->enable
== 0 || w
->type
!= type
||
5287 !(w
->pflags
& path
))
5289 cap
= w
->param
.widget_cap
;
5290 /*if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(cap))
5292 if (!HDA_PARAM_AUDIO_WIDGET_CAP_STEREO(cap
))
5294 cap
= w
->param
.supp_stream_formats
;
5295 /*if (HDA_PARAM_SUPP_STREAM_FORMATS_AC3(cap)) {
5297 if (HDA_PARAM_SUPP_STREAM_FORMATS_FLOAT32(cap)) {
5299 if (!HDA_PARAM_SUPP_STREAM_FORMATS_PCM(cap
))
5302 fmtcap
= w
->param
.supp_stream_formats
;
5303 pcmcap
= w
->param
.supp_pcm_size_rate
;
5305 fmtcap
&= w
->param
.supp_stream_formats
;
5306 pcmcap
&= w
->param
.supp_pcm_size_rate
;
5312 ch
->supp_stream_formats
= fmtcap
;
5313 ch
->supp_pcm_size_rate
= pcmcap
;
5324 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16BIT(cap
))
5326 else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8BIT(cap
))
5328 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(cap
))
5330 else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(cap
))
5332 else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(cap
))
5335 if (!(devinfo
->function
.audio
.quirks
& HDA_QUIRK_FORCESTEREO
))
5336 ch
->fmtlist
[i
++] = AFMT_S16_LE
;
5337 ch
->fmtlist
[i
++] = AFMT_S16_LE
| AFMT_STEREO
;
5338 if (ch
->bit32
> 0) {
5339 if (!(devinfo
->function
.audio
.quirks
&
5340 HDA_QUIRK_FORCESTEREO
))
5341 ch
->fmtlist
[i
++] = AFMT_S32_LE
;
5342 ch
->fmtlist
[i
++] = AFMT_S32_LE
| AFMT_STEREO
;
5346 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8KHZ(cap
))
5347 ch
->pcmrates
[i
++] = 8000;
5348 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_11KHZ(cap
))
5349 ch
->pcmrates
[i
++] = 11025;
5350 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16KHZ(cap
))
5351 ch
->pcmrates
[i
++] = 16000;
5352 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_22KHZ(cap
))
5353 ch
->pcmrates
[i
++] = 22050;
5354 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32KHZ(cap
))
5355 ch
->pcmrates
[i
++] = 32000;
5356 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_44KHZ(cap
))
5357 ch
->pcmrates
[i
++] = 44100;
5358 /* if (HDA_PARAM_SUPP_PCM_SIZE_RATE_48KHZ(cap)) */
5359 ch
->pcmrates
[i
++] = 48000;
5360 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_88KHZ(cap
))
5361 ch
->pcmrates
[i
++] = 88200;
5362 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_96KHZ(cap
))
5363 ch
->pcmrates
[i
++] = 96000;
5364 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_176KHZ(cap
))
5365 ch
->pcmrates
[i
++] = 176400;
5366 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_192KHZ(cap
))
5367 ch
->pcmrates
[i
++] = 192000;
5368 /* if (HDA_PARAM_SUPP_PCM_SIZE_RATE_384KHZ(cap)) */
5369 ch
->pcmrates
[i
] = 0;
5371 ch
->caps
.minspeed
= ch
->pcmrates
[0];
5372 ch
->caps
.maxspeed
= ch
->pcmrates
[i
- 1];
5380 hdac_dump_ctls(struct hdac_devinfo
*devinfo
, const char *banner
, uint32_t flag
)
5382 struct hdac_audio_ctl
*ctl
;
5383 struct hdac_softc
*sc
= devinfo
->codec
->sc
;
5389 fl
= SOUND_MASK_VOLUME
| SOUND_MASK_PCM
|
5390 SOUND_MASK_CD
| SOUND_MASK_LINE
| SOUND_MASK_RECLEV
|
5391 SOUND_MASK_MIC
| SOUND_MASK_SPEAKER
| SOUND_MASK_OGAIN
;
5395 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) != NULL
) {
5396 if (ctl
->enable
== 0 || ctl
->widget
== NULL
||
5397 ctl
->widget
->enable
== 0 || (ctl
->ossmask
&
5398 (SOUND_MASK_SKIP
| SOUND_MASK_DISABLE
)))
5400 if ((flag
== 0 && (ctl
->ossmask
& ~fl
)) ||
5401 (flag
!= 0 && (ctl
->ossmask
& flag
))) {
5402 if (banner
!= NULL
) {
5403 device_printf(sc
->dev
, "\n");
5404 device_printf(sc
->dev
, "%s\n", banner
);
5406 goto hdac_ctl_dump_it_all
;
5412 hdac_ctl_dump_it_all
:
5414 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) != NULL
) {
5415 if (ctl
->enable
== 0 || ctl
->widget
== NULL
||
5416 ctl
->widget
->enable
== 0)
5418 if (!((flag
== 0 && (ctl
->ossmask
& ~fl
)) ||
5419 (flag
!= 0 && (ctl
->ossmask
& flag
))))
5422 device_printf(sc
->dev
, "\n");
5423 device_printf(sc
->dev
, "Unknown Ctl (OSS: %s)\n",
5424 hdac_audio_ctl_ossmixer_mask2name(ctl
->ossmask
));
5426 device_printf(sc
->dev
, " |\n");
5427 device_printf(sc
->dev
, " +- nid: %2d index: %2d ",
5428 ctl
->widget
->nid
, ctl
->index
);
5429 if (ctl
->childwidget
!= NULL
)
5430 kprintf("(nid: %2d) ", ctl
->childwidget
->nid
);
5433 kprintf("mute: %d step: %3d size: %3d off: %3d dir=0x%x ossmask=0x%08x\n",
5434 ctl
->mute
, ctl
->step
, ctl
->size
, ctl
->offset
, ctl
->dir
,
5440 hdac_dump_audio_formats(struct hdac_softc
*sc
, uint32_t fcap
, uint32_t pcmcap
)
5446 device_printf(sc
->dev
, " Stream cap: 0x%08x\n", cap
);
5447 device_printf(sc
->dev
, " Format:");
5448 if (HDA_PARAM_SUPP_STREAM_FORMATS_AC3(cap
))
5450 if (HDA_PARAM_SUPP_STREAM_FORMATS_FLOAT32(cap
))
5451 kprintf(" FLOAT32");
5452 if (HDA_PARAM_SUPP_STREAM_FORMATS_PCM(cap
))
5458 device_printf(sc
->dev
, " PCM cap: 0x%08x\n", cap
);
5459 device_printf(sc
->dev
, " PCM size:");
5460 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8BIT(cap
))
5462 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16BIT(cap
))
5464 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(cap
))
5466 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(cap
))
5468 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(cap
))
5471 device_printf(sc
->dev
, " PCM rate:");
5472 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8KHZ(cap
))
5474 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_11KHZ(cap
))
5476 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16KHZ(cap
))
5478 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_22KHZ(cap
))
5480 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32KHZ(cap
))
5482 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_44KHZ(cap
))
5485 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_88KHZ(cap
))
5487 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_96KHZ(cap
))
5489 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_176KHZ(cap
))
5491 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_192KHZ(cap
))
5498 hdac_dump_pin(struct hdac_softc
*sc
, struct hdac_widget
*w
)
5500 uint32_t pincap
, wcap
;
5502 pincap
= w
->wclass
.pin
.cap
;
5503 wcap
= w
->param
.widget_cap
;
5505 device_printf(sc
->dev
, " Pin cap: 0x%08x\n", pincap
);
5506 device_printf(sc
->dev
, " ");
5507 if (HDA_PARAM_PIN_CAP_IMP_SENSE_CAP(pincap
))
5509 if (HDA_PARAM_PIN_CAP_TRIGGER_REQD(pincap
))
5511 if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(pincap
))
5513 if (HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap
))
5515 if (HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap
))
5517 if (HDA_PARAM_PIN_CAP_INPUT_CAP(pincap
))
5519 if (HDA_PARAM_PIN_CAP_BALANCED_IO_PINS(pincap
))
5521 if (HDA_PARAM_PIN_CAP_VREF_CTRL(pincap
)) {
5523 if (HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap
))
5525 if (HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap
))
5527 if (HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap
))
5529 if (HDA_PARAM_PIN_CAP_VREF_CTRL_GROUND(pincap
))
5531 if (HDA_PARAM_PIN_CAP_VREF_CTRL_HIZ(pincap
))
5535 if (HDA_PARAM_PIN_CAP_EAPD_CAP(pincap
))
5537 if (HDA_PARAM_AUDIO_WIDGET_CAP_UNSOL_CAP(wcap
))
5538 kprintf(" : UNSOL");
5540 device_printf(sc
->dev
, " Pin config: 0x%08x\n",
5541 w
->wclass
.pin
.config
);
5542 device_printf(sc
->dev
, " Pin control: 0x%08x", w
->wclass
.pin
.ctrl
);
5543 if (w
->wclass
.pin
.ctrl
& HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE
)
5545 if (w
->wclass
.pin
.ctrl
& HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE
)
5547 if (w
->wclass
.pin
.ctrl
& HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE
)
5553 hdac_dump_amp(struct hdac_softc
*sc
, uint32_t cap
, char *banner
)
5555 device_printf(sc
->dev
, " %s amp: 0x%08x\n", banner
, cap
);
5556 device_printf(sc
->dev
, " "
5557 "mute=%d step=%d size=%d offset=%d\n",
5558 HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(cap
),
5559 HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(cap
),
5560 HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(cap
),
5561 HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(cap
));
5565 hdac_dump_nodes(struct hdac_devinfo
*devinfo
)
5567 struct hdac_softc
*sc
= devinfo
->codec
->sc
;
5568 struct hdac_widget
*w
, *cw
;
5571 device_printf(sc
->dev
, "\n");
5572 device_printf(sc
->dev
, "Default Parameter\n");
5573 device_printf(sc
->dev
, "-----------------\n");
5574 hdac_dump_audio_formats(sc
,
5575 devinfo
->function
.audio
.supp_stream_formats
,
5576 devinfo
->function
.audio
.supp_pcm_size_rate
);
5577 device_printf(sc
->dev
, " IN amp: 0x%08x\n",
5578 devinfo
->function
.audio
.inamp_cap
);
5579 device_printf(sc
->dev
, " OUT amp: 0x%08x\n",
5580 devinfo
->function
.audio
.outamp_cap
);
5581 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
5582 w
= hdac_widget_get(devinfo
, i
);
5584 device_printf(sc
->dev
, "Ghost widget nid=%d\n", i
);
5587 device_printf(sc
->dev
, "\n");
5588 device_printf(sc
->dev
, " nid: %d [%s]%s\n", w
->nid
,
5589 HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w
->param
.widget_cap
) ?
5590 "DIGITAL" : "ANALOG",
5591 (w
->enable
== 0) ? " [DISABLED]" : "");
5592 device_printf(sc
->dev
, " name: %s\n", w
->name
);
5593 device_printf(sc
->dev
, " widget_cap: 0x%08x\n",
5594 w
->param
.widget_cap
);
5595 device_printf(sc
->dev
, " Parse flags: 0x%08x\n",
5597 device_printf(sc
->dev
, " Ctl flags: 0x%08x\n",
5599 if (w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT
||
5600 w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT
) {
5601 hdac_dump_audio_formats(sc
,
5602 w
->param
.supp_stream_formats
,
5603 w
->param
.supp_pcm_size_rate
);
5604 } else if (w
->type
==
5605 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
)
5606 hdac_dump_pin(sc
, w
);
5607 if (w
->param
.eapdbtl
!= HDAC_INVALID
)
5608 device_printf(sc
->dev
, " EAPD: 0x%08x\n",
5610 if (HDA_PARAM_AUDIO_WIDGET_CAP_OUT_AMP(w
->param
.widget_cap
) &&
5611 w
->param
.outamp_cap
!= 0)
5612 hdac_dump_amp(sc
, w
->param
.outamp_cap
, "Output");
5613 if (HDA_PARAM_AUDIO_WIDGET_CAP_IN_AMP(w
->param
.widget_cap
) &&
5614 w
->param
.inamp_cap
!= 0)
5615 hdac_dump_amp(sc
, w
->param
.inamp_cap
, " Input");
5616 device_printf(sc
->dev
, " connections: %d\n", w
->nconns
);
5617 for (j
= 0; j
< w
->nconns
; j
++) {
5618 cw
= hdac_widget_get(devinfo
, w
->conns
[j
]);
5619 device_printf(sc
->dev
, " |\n");
5620 device_printf(sc
->dev
, " + <- nid=%d [%s]",
5621 w
->conns
[j
], (cw
== NULL
) ? "GHOST!" : cw
->name
);
5623 kprintf(" [UNKNOWN]");
5624 else if (cw
->enable
== 0)
5625 kprintf(" [DISABLED]");
5626 if (w
->nconns
> 1 && w
->selconn
== j
&& w
->type
!=
5627 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER
)
5628 kprintf(" (selected)");
5636 hdac_dump_dac_internal(struct hdac_devinfo
*devinfo
, nid_t nid
, int depth
)
5638 struct hdac_widget
*w
, *cw
;
5639 struct hdac_softc
*sc
= devinfo
->codec
->sc
;
5642 if (depth
> HDA_PARSE_MAXDEPTH
)
5645 w
= hdac_widget_get(devinfo
, nid
);
5646 if (w
== NULL
|| w
->enable
== 0 || !(w
->pflags
& HDA_DAC_PATH
))
5649 if (w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
) {
5650 device_printf(sc
->dev
, "\n");
5651 device_printf(sc
->dev
, " nid=%d [%s]\n", w
->nid
, w
->name
);
5652 device_printf(sc
->dev
, " ^\n");
5653 device_printf(sc
->dev
, " |\n");
5654 device_printf(sc
->dev
, " +-----<------+\n");
5656 device_printf(sc
->dev
, " ^\n");
5657 device_printf(sc
->dev
, " |\n");
5658 device_printf(sc
->dev
, " ");
5659 kprintf(" nid=%d [%s]\n", w
->nid
, w
->name
);
5662 if (w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT
) {
5664 } else if (w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER
) {
5665 for (i
= 0; i
< w
->nconns
; i
++) {
5666 cw
= hdac_widget_get(devinfo
, w
->conns
[i
]);
5667 if (cw
== NULL
|| cw
->enable
== 0 || cw
->type
==
5668 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
)
5670 if (hdac_dump_dac_internal(devinfo
, cw
->nid
,
5674 } else if ((w
->type
==
5675 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR
||
5676 w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
) &&
5677 w
->selconn
> -1 && w
->selconn
< w
->nconns
) {
5678 if (hdac_dump_dac_internal(devinfo
, w
->conns
[w
->selconn
],
5687 hdac_dump_dac(struct hdac_devinfo
*devinfo
)
5689 struct hdac_widget
*w
;
5690 struct hdac_softc
*sc
= devinfo
->codec
->sc
;
5693 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
5694 w
= hdac_widget_get(devinfo
, i
);
5695 if (w
== NULL
|| w
->enable
== 0)
5697 if (w
->type
!= HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
||
5698 !(w
->pflags
& HDA_DAC_PATH
))
5702 device_printf(sc
->dev
, "\n");
5703 device_printf(sc
->dev
, "Playback path:\n");
5705 hdac_dump_dac_internal(devinfo
, w
->nid
, 0);
5710 hdac_dump_adc(struct hdac_devinfo
*devinfo
)
5712 struct hdac_widget
*w
, *cw
;
5713 struct hdac_softc
*sc
= devinfo
->codec
->sc
;
5718 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
5719 w
= hdac_widget_get(devinfo
, i
);
5720 if (w
== NULL
|| w
->enable
== 0)
5722 if (!(w
->pflags
& HDA_ADC_RECSEL
))
5726 device_printf(sc
->dev
, "\n");
5727 device_printf(sc
->dev
, "Recording sources:\n");
5729 device_printf(sc
->dev
, "\n");
5730 device_printf(sc
->dev
, " nid=%d [%s]\n", w
->nid
, w
->name
);
5731 for (j
= 0; j
< w
->nconns
; j
++) {
5732 cw
= hdac_widget_get(devinfo
, w
->conns
[j
]);
5733 if (cw
== NULL
|| cw
->enable
== 0)
5735 hdac_audio_ctl_ossmixer_mask2allname(cw
->ctlflags
,
5736 ossdevs
, sizeof(ossdevs
));
5737 device_printf(sc
->dev
, " |\n");
5738 device_printf(sc
->dev
, " + <- nid=%d [%s]",
5740 if (strlen(ossdevs
) > 0) {
5741 kprintf(" [recsrc: %s]", ossdevs
);
5749 hdac_dump_pcmchannels(struct hdac_softc
*sc
, int pcnt
, int rcnt
)
5754 device_printf(sc
->dev
, "\n");
5755 device_printf(sc
->dev
, " PCM Playback: %d\n", pcnt
);
5756 hdac_dump_audio_formats(sc
, sc
->play
.supp_stream_formats
,
5757 sc
->play
.supp_pcm_size_rate
);
5758 device_printf(sc
->dev
, " DAC:");
5759 for (nids
= sc
->play
.io
; *nids
!= -1; nids
++)
5760 kprintf(" %d", *nids
);
5765 device_printf(sc
->dev
, "\n");
5766 device_printf(sc
->dev
, " PCM Record: %d\n", rcnt
);
5767 hdac_dump_audio_formats(sc
, sc
->play
.supp_stream_formats
,
5768 sc
->rec
.supp_pcm_size_rate
);
5769 device_printf(sc
->dev
, " ADC:");
5770 for (nids
= sc
->rec
.io
; *nids
!= -1; nids
++)
5771 kprintf(" %d", *nids
);
5777 hdac_release_resources(struct hdac_softc
*sc
)
5779 struct hdac_devinfo
*devinfo
= NULL
;
5780 device_t
*devlist
= NULL
;
5789 callout_stop(&sc
->poll_hda
);
5790 callout_stop(&sc
->poll_hdac
);
5791 callout_stop(&sc
->poll_jack
);
5797 /* give pending interrupts stuck on the lock a chance to clear */
5799 tsleep(&sc
->irq
, 0, "hdaslp", hz
/ 10);
5801 device_get_children(sc
->dev
, &devlist
, &devcount
);
5802 for (i
= 0; devlist
!= NULL
&& i
< devcount
; i
++) {
5803 devinfo
= (struct hdac_devinfo
*)device_get_ivars(devlist
[i
]);
5804 if (devinfo
== NULL
)
5806 if (devinfo
->widget
!= NULL
)
5807 kfree(devinfo
->widget
, M_HDAC
);
5808 if (devinfo
->node_type
==
5809 HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO
&&
5810 devinfo
->function
.audio
.ctl
!= NULL
)
5811 kfree(devinfo
->function
.audio
.ctl
, M_HDAC
);
5812 kfree(devinfo
, M_HDAC
);
5813 device_delete_child(sc
->dev
, devlist
[i
]);
5815 if (devlist
!= NULL
)
5816 kfree(devlist
, M_TEMP
);
5818 for (i
= 0; i
< HDAC_CODEC_MAX
; i
++) {
5819 if (sc
->codecs
[i
] != NULL
)
5820 kfree(sc
->codecs
[i
], M_HDAC
);
5821 sc
->codecs
[i
] = NULL
;
5824 hdac_dma_free(sc
, &sc
->pos_dma
);
5825 hdac_dma_free(sc
, &sc
->rirb_dma
);
5826 hdac_dma_free(sc
, &sc
->corb_dma
);
5827 if (sc
->play
.blkcnt
> 0)
5828 hdac_dma_free(sc
, &sc
->play
.bdl_dma
);
5829 if (sc
->rec
.blkcnt
> 0)
5830 hdac_dma_free(sc
, &sc
->rec
.bdl_dma
);
5831 if (sc
->chan_dmat
!= NULL
) {
5832 bus_dma_tag_destroy(sc
->chan_dmat
);
5833 sc
->chan_dmat
= NULL
;
5836 snd_mtxfree(sc
->lock
);
5837 kfree(sc
, M_DEVBUF
);
5840 /* This function surely going to make its way into upper level someday. */
5842 hdac_config_fetch(struct hdac_softc
*sc
, uint32_t *on
, uint32_t *off
)
5845 int i
= 0, j
, k
, len
, inv
;
5853 if (resource_string_value(device_get_name(sc
->dev
),
5854 device_get_unit(sc
->dev
), "config", &res
) != 0)
5856 if (!(res
!= NULL
&& strlen(res
) > 0))
5859 device_printf(sc
->dev
, "HDA_DEBUG: HDA Config:");
5862 while (res
[i
] != '\0' &&
5863 (res
[i
] == ',' || isspace(res
[i
]) != 0))
5865 if (res
[i
] == '\0') {
5872 while (res
[j
] != '\0' &&
5873 !(res
[j
] == ',' || isspace(res
[j
]) != 0))
5876 if (len
> 2 && strncmp(res
+ i
, "no", 2) == 0)
5880 for (k
= 0; len
> inv
&& k
< HDAC_QUIRKS_TAB_LEN
; k
++) {
5881 if (strncmp(res
+ i
+ inv
,
5882 hdac_quirks_tab
[k
].key
, len
- inv
) != 0)
5884 if (len
- inv
!= strlen(hdac_quirks_tab
[k
].key
))
5887 kprintf(" %s%s", (inv
!= 0) ? "no" : "",
5888 hdac_quirks_tab
[k
].key
);
5890 if (inv
== 0 && on
!= NULL
)
5891 *on
|= hdac_quirks_tab
[k
].value
;
5892 else if (inv
!= 0 && off
!= NULL
)
5893 *off
|= hdac_quirks_tab
[k
].value
;
5900 #ifdef SND_DYNSYSCTL
5902 sysctl_hdac_polling(SYSCTL_HANDLER_ARGS
)
5904 struct hdac_softc
*sc
;
5905 struct hdac_devinfo
*devinfo
;
5910 dev
= oidp
->oid_arg1
;
5911 devinfo
= pcm_getdevinfo(dev
);
5912 if (devinfo
== NULL
|| devinfo
->codec
== NULL
||
5913 devinfo
->codec
->sc
== NULL
)
5915 sc
= devinfo
->codec
->sc
;
5919 err
= sysctl_handle_int(oidp
, &val
, 0, req
);
5921 if (err
!= 0 || req
->newptr
== NULL
)
5923 if (val
< 0 || val
> 1)
5927 if (val
!= sc
->polling
) {
5928 if (hda_chan_active(sc
) != 0)
5930 else if (val
== 0) {
5931 callout_stop(&sc
->poll_hdac
);
5934 HDAC_WRITE_2(&sc
->mem
, HDAC_RINTCNT
,
5936 ctl
= HDAC_READ_1(&sc
->mem
, HDAC_RIRBCTL
);
5937 ctl
|= HDAC_RIRBCTL_RINTCTL
;
5938 HDAC_WRITE_1(&sc
->mem
, HDAC_RIRBCTL
, ctl
);
5939 HDAC_WRITE_4(&sc
->mem
, HDAC_INTCTL
,
5940 HDAC_INTCTL_CIE
| HDAC_INTCTL_GIE
);
5944 HDAC_WRITE_4(&sc
->mem
, HDAC_INTCTL
, 0);
5945 HDAC_WRITE_2(&sc
->mem
, HDAC_RINTCNT
, 0);
5946 ctl
= HDAC_READ_1(&sc
->mem
, HDAC_RIRBCTL
);
5947 ctl
&= ~HDAC_RIRBCTL_RINTCTL
;
5948 HDAC_WRITE_1(&sc
->mem
, HDAC_RIRBCTL
, ctl
);
5949 callout_reset(&sc
->poll_hdac
, 1, hdac_poll_callback
,
5961 sysctl_hdac_polling_interval(SYSCTL_HANDLER_ARGS
)
5963 struct hdac_softc
*sc
;
5964 struct hdac_devinfo
*devinfo
;
5968 dev
= oidp
->oid_arg1
;
5969 devinfo
= pcm_getdevinfo(dev
);
5970 if (devinfo
== NULL
|| devinfo
->codec
== NULL
||
5971 devinfo
->codec
->sc
== NULL
)
5973 sc
= devinfo
->codec
->sc
;
5975 val
= ((uint64_t)sc
->poll_ival
* 1000) / hz
;
5977 err
= sysctl_handle_int(oidp
, &val
, 0, req
);
5979 if (err
!= 0 || req
->newptr
== NULL
)
5986 val
= ((uint64_t)val
* hz
) / 1000;
5993 sc
->poll_ival
= val
;
6001 sysctl_hdac_pindump(SYSCTL_HANDLER_ARGS
)
6003 struct hdac_softc
*sc
;
6004 struct hdac_devinfo
*devinfo
;
6005 struct hdac_widget
*w
;
6007 uint32_t res
, pincap
, execres
;
6011 dev
= oidp
->oid_arg1
;
6012 devinfo
= pcm_getdevinfo(dev
);
6013 if (devinfo
== NULL
|| devinfo
->codec
== NULL
||
6014 devinfo
->codec
->sc
== NULL
)
6017 err
= sysctl_handle_int(oidp
, &val
, 0, req
);
6018 if (err
!= 0 || req
->newptr
== NULL
|| val
== 0)
6020 sc
= devinfo
->codec
->sc
;
6021 cad
= devinfo
->codec
->cad
;
6023 device_printf(dev
, "HDAC Dump AFG [nid=%d]:\n", devinfo
->nid
);
6024 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
6025 w
= hdac_widget_get(devinfo
, i
);
6026 if (w
== NULL
|| w
->type
!=
6027 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
)
6029 pincap
= w
->wclass
.pin
.cap
;
6030 if ((HDA_PARAM_PIN_CAP_IMP_SENSE_CAP(pincap
) ||
6031 HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(pincap
)) &&
6032 HDA_PARAM_PIN_CAP_TRIGGER_REQD(pincap
)) {
6035 HDA_CMD_SET_PIN_SENSE(cad
, w
->nid
, 0), cad
);
6037 res
= hdac_command(sc
,
6038 HDA_CMD_GET_PIN_SENSE(cad
, w
->nid
), cad
);
6039 if (res
!= 0x7fffffff)
6042 } while (--timeout
!= 0);
6045 res
= hdac_command(sc
, HDA_CMD_GET_PIN_SENSE(cad
,
6049 "PIN_SENSE: nid=%-3d timeout=%d res=0x%08x [%s]\n",
6050 w
->nid
, timeout
, res
,
6051 (w
->enable
== 0) ? "DISABLED" : "ENABLED");
6054 "NumGPIO=%d NumGPO=%d NumGPI=%d GPIWake=%d GPIUnsol=%d\n",
6055 HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo
->function
.audio
.gpio
),
6056 HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo
->function
.audio
.gpio
),
6057 HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo
->function
.audio
.gpio
),
6058 HDA_PARAM_GPIO_COUNT_GPI_WAKE(devinfo
->function
.audio
.gpio
),
6059 HDA_PARAM_GPIO_COUNT_GPI_UNSOL(devinfo
->function
.audio
.gpio
));
6060 if (HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo
->function
.audio
.gpio
) > 0) {
6061 device_printf(dev
, " GPI:");
6062 res
= hdac_command(sc
,
6063 HDA_CMD_GET_GPI_DATA(cad
, devinfo
->nid
), cad
);
6064 kprintf(" data=0x%08x", res
);
6065 res
= hdac_command(sc
,
6066 HDA_CMD_GET_GPI_WAKE_ENABLE_MASK(cad
, devinfo
->nid
),
6068 kprintf(" wake=0x%08x", res
);
6069 res
= hdac_command(sc
,
6070 HDA_CMD_GET_GPI_UNSOLICITED_ENABLE_MASK(cad
, devinfo
->nid
),
6072 kprintf(" unsol=0x%08x", res
);
6073 res
= hdac_command(sc
,
6074 HDA_CMD_GET_GPI_STICKY_MASK(cad
, devinfo
->nid
), cad
);
6075 kprintf(" sticky=0x%08x\n", res
);
6077 if (HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo
->function
.audio
.gpio
) > 0) {
6078 device_printf(dev
, " GPO:");
6079 res
= hdac_command(sc
,
6080 HDA_CMD_GET_GPO_DATA(cad
, devinfo
->nid
), cad
);
6081 kprintf(" data=0x%08x\n", res
);
6083 if (HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo
->function
.audio
.gpio
) > 0) {
6084 device_printf(dev
, "GPI0:");
6085 res
= hdac_command(sc
,
6086 HDA_CMD_GET_GPIO_DATA(cad
, devinfo
->nid
), cad
);
6087 kprintf(" data=0x%08x", res
);
6088 res
= hdac_command(sc
,
6089 HDA_CMD_GET_GPIO_ENABLE_MASK(cad
, devinfo
->nid
), cad
);
6090 kprintf(" enable=0x%08x", res
);
6091 res
= hdac_command(sc
,
6092 HDA_CMD_GET_GPIO_DIRECTION(cad
, devinfo
->nid
), cad
);
6093 kprintf(" direction=0x%08x\n", res
);
6094 res
= hdac_command(sc
,
6095 HDA_CMD_GET_GPIO_WAKE_ENABLE_MASK(cad
, devinfo
->nid
), cad
);
6096 device_printf(dev
, " wake=0x%08x", res
);
6097 res
= hdac_command(sc
,
6098 HDA_CMD_GET_GPIO_UNSOLICITED_ENABLE_MASK(cad
, devinfo
->nid
),
6100 kprintf(" unsol=0x%08x", res
);
6101 res
= hdac_command(sc
,
6102 HDA_CMD_GET_GPIO_STICKY_MASK(cad
, devinfo
->nid
), cad
);
6103 kprintf(" sticky=0x%08x\n", res
);
6112 hdac_attach2(void *arg
)
6114 struct hdac_softc
*sc
;
6115 struct hdac_widget
*w
;
6116 struct hdac_audio_ctl
*ctl
;
6117 uint32_t quirks_on
, quirks_off
;
6118 int pcnt
, rcnt
, codec_index
;
6120 char status
[SND_STATUSLEN
];
6121 device_t
*devlist
= NULL
;
6123 struct hdac_devinfo
*devinfo
= NULL
;
6125 sc
= (struct hdac_softc
*)arg
;
6127 hdac_config_fetch(sc
, &quirks_on
, &quirks_off
);
6130 device_printf(sc
->dev
, "HDA_DEBUG: HDA Config: on=0x%08x off=0x%08x\n",
6131 quirks_on
, quirks_off
);
6134 if (resource_int_value(device_get_name(sc
->dev
),
6135 device_get_unit(sc
->dev
), "codec_index", &codec_index
) != 0) {
6136 switch (sc
->pci_subvendor
) {
6137 case GB_G33S2H_SUBVENDOR
:
6148 /* Remove ourselves from the config hooks */
6149 if (sc
->intrhook
.ich_func
!= NULL
) {
6150 config_intrhook_disestablish(&sc
->intrhook
);
6151 sc
->intrhook
.ich_func
= NULL
;
6154 /* Start the corb and rirb engines */
6156 device_printf(sc
->dev
, "HDA_DEBUG: Starting CORB Engine...\n");
6158 hdac_corb_start(sc
);
6160 device_printf(sc
->dev
, "HDA_DEBUG: Starting RIRB Engine...\n");
6162 hdac_rirb_start(sc
);
6165 device_printf(sc
->dev
,
6166 "HDA_DEBUG: Enabling controller interrupt...\n");
6168 if (sc
->polling
== 0)
6169 HDAC_WRITE_4(&sc
->mem
, HDAC_INTCTL
,
6170 HDAC_INTCTL_CIE
| HDAC_INTCTL_GIE
);
6171 HDAC_WRITE_4(&sc
->mem
, HDAC_GCTL
, HDAC_READ_4(&sc
->mem
, HDAC_GCTL
) |
6177 device_printf(sc
->dev
,
6178 "HDA_DEBUG: Scanning HDA codecs [start index=%d] ...\n",
6181 hdac_scan_codecs(sc
, codec_index
);
6183 device_get_children(sc
->dev
, &devlist
, &devcount
);
6184 for (i
= 0; devlist
!= NULL
&& i
< devcount
; i
++) {
6185 devinfo
= (struct hdac_devinfo
*)device_get_ivars(devlist
[i
]);
6186 if (devinfo
!= NULL
&& devinfo
->node_type
==
6187 HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO
) {
6192 if (devlist
!= NULL
)
6193 kfree(devlist
, M_TEMP
);
6195 if (devinfo
== NULL
) {
6197 device_printf(sc
->dev
, "Audio Function Group not found!\n");
6198 hdac_release_resources(sc
);
6203 device_printf(sc
->dev
,
6204 "HDA_DEBUG: Parsing AFG nid=%d cad=%d\n",
6205 devinfo
->nid
, devinfo
->codec
->cad
);
6207 hdac_audio_parse(devinfo
);
6209 device_printf(sc
->dev
, "HDA_DEBUG: Parsing Ctls...\n");
6211 hdac_audio_ctl_parse(devinfo
);
6213 device_printf(sc
->dev
, "HDA_DEBUG: Parsing vendor patch...\n");
6215 hdac_vendor_patch_parse(devinfo
);
6217 devinfo
->function
.audio
.quirks
|= quirks_on
;
6218 if (quirks_off
!= 0)
6219 devinfo
->function
.audio
.quirks
&= ~quirks_off
;
6221 /* XXX Disable all DIGITAL path. */
6222 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
6223 w
= hdac_widget_get(devinfo
, i
);
6226 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w
->param
.widget_cap
)) {
6230 /* XXX Disable useless pin ? */
6231 if (w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
&&
6232 (w
->wclass
.pin
.config
&
6233 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK
) ==
6234 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_NONE
)
6238 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) != NULL
) {
6239 if (ctl
->widget
== NULL
)
6241 if (ctl
->ossmask
& SOUND_MASK_DISABLE
)
6244 if (w
->enable
== 0 ||
6245 HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w
->param
.widget_cap
))
6247 w
= ctl
->childwidget
;
6250 if (w
->enable
== 0 ||
6251 HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w
->param
.widget_cap
))
6256 device_printf(sc
->dev
, "HDA_DEBUG: Building AFG tree...\n");
6258 hdac_audio_build_tree(devinfo
);
6261 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) != NULL
) {
6262 if (ctl
->ossmask
& (SOUND_MASK_SKIP
| SOUND_MASK_DISABLE
))
6266 device_printf(sc
->dev
, "HDA_DEBUG: AFG commit...\n");
6268 hdac_audio_commit(devinfo
, HDA_COMMIT_ALL
);
6270 device_printf(sc
->dev
, "HDA_DEBUG: Ctls commit...\n");
6272 hdac_audio_ctl_commit(devinfo
);
6275 device_printf(sc
->dev
, "HDA_DEBUG: PCMDIR_PLAY setup...\n");
6277 pcnt
= hdac_pcmchannel_setup(devinfo
, PCMDIR_PLAY
);
6279 device_printf(sc
->dev
, "HDA_DEBUG: PCMDIR_REC setup...\n");
6281 rcnt
= hdac_pcmchannel_setup(devinfo
, PCMDIR_REC
);
6285 device_printf(sc
->dev
,
6286 "HDA_DEBUG: OSS mixer initialization...\n");
6290 * There is no point of return after this. If the driver failed,
6291 * so be it. Let the detach procedure do all the cleanup.
6293 if (mixer_init(sc
->dev
, &hdac_audio_ctl_ossmixer_class
, devinfo
) != 0)
6294 device_printf(sc
->dev
, "Can't register mixer\n");
6302 device_printf(sc
->dev
,
6303 "HDA_DEBUG: Registering PCM channels...\n");
6305 if (pcm_register(sc
->dev
, devinfo
, pcnt
, rcnt
) != 0)
6306 device_printf(sc
->dev
, "Can't register PCM\n");
6310 if ((devinfo
->function
.audio
.quirks
& HDA_QUIRK_DMAPOS
) &&
6311 hdac_dma_alloc(sc
, &sc
->pos_dma
,
6312 (sc
->num_iss
+ sc
->num_oss
+ sc
->num_bss
) * 8) != 0) {
6314 device_printf(sc
->dev
,
6315 "Failed to allocate DMA pos buffer (non-fatal)\n");
6319 for (i
= 0; i
< pcnt
; i
++)
6320 pcm_addchan(sc
->dev
, PCMDIR_PLAY
, &hdac_channel_class
, devinfo
);
6321 for (i
= 0; i
< rcnt
; i
++)
6322 pcm_addchan(sc
->dev
, PCMDIR_REC
, &hdac_channel_class
, devinfo
);
6324 #ifdef SND_DYNSYSCTL
6325 SYSCTL_ADD_PROC(snd_sysctl_tree(sc
->dev
),
6326 SYSCTL_CHILDREN(snd_sysctl_tree_top(sc
->dev
)), OID_AUTO
,
6327 "polling", CTLTYPE_INT
| CTLFLAG_RW
, sc
->dev
, sizeof(sc
->dev
),
6328 sysctl_hdac_polling
, "I", "Enable polling mode");
6329 SYSCTL_ADD_PROC(snd_sysctl_tree(sc
->dev
),
6330 SYSCTL_CHILDREN(snd_sysctl_tree_top(sc
->dev
)), OID_AUTO
,
6331 "polling_interval", CTLTYPE_INT
| CTLFLAG_RW
, sc
->dev
,
6332 sizeof(sc
->dev
), sysctl_hdac_polling_interval
, "I",
6333 "Controller/Jack Sense polling interval (1-1000 ms)");
6335 SYSCTL_ADD_PROC(snd_sysctl_tree(sc
->dev
),
6336 SYSCTL_CHILDREN(snd_sysctl_tree_top(sc
->dev
)), OID_AUTO
,
6337 "pindump", CTLTYPE_INT
| CTLFLAG_RW
, sc
->dev
, sizeof(sc
->dev
),
6338 sysctl_hdac_pindump
, "I", "Dump pin states/data");
6342 ksnprintf(status
, SND_STATUSLEN
, "at memory 0x%lx irq %ld %s [%s]",
6343 rman_get_start(sc
->mem
.mem_res
), rman_get_start(sc
->irq
.irq_res
),
6344 PCM_KLDSTRING(snd_hda
), HDA_DRV_TEST_REV
);
6345 pcm_setstatus(sc
->dev
, status
);
6346 device_printf(sc
->dev
, "<HDA Codec: %s>\n", hdac_codec_name(devinfo
));
6348 device_printf(sc
->dev
, "<HDA Codec ID: 0x%08x>\n",
6349 hdac_codec_id(devinfo
));
6351 device_printf(sc
->dev
, "<HDA Driver Revision: %s>\n",
6355 if (devinfo
->function
.audio
.quirks
!= 0) {
6356 device_printf(sc
->dev
, "\n");
6357 device_printf(sc
->dev
, "HDA config/quirks:");
6358 for (i
= 0; i
< HDAC_QUIRKS_TAB_LEN
; i
++) {
6359 if ((devinfo
->function
.audio
.quirks
&
6360 hdac_quirks_tab
[i
].value
) ==
6361 hdac_quirks_tab
[i
].value
)
6362 kprintf(" %s", hdac_quirks_tab
[i
].key
);
6366 device_printf(sc
->dev
, "\n");
6367 device_printf(sc
->dev
, "+-------------------+\n");
6368 device_printf(sc
->dev
, "| DUMPING HDA NODES |\n");
6369 device_printf(sc
->dev
, "+-------------------+\n");
6370 hdac_dump_nodes(devinfo
);
6371 device_printf(sc
->dev
, "\n");
6372 device_printf(sc
->dev
, "+------------------------+\n");
6373 device_printf(sc
->dev
, "| DUMPING HDA AMPLIFIERS |\n");
6374 device_printf(sc
->dev
, "+------------------------+\n");
6375 device_printf(sc
->dev
, "\n");
6377 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) != NULL
) {
6378 device_printf(sc
->dev
, "%3d: nid=%d", i
,
6379 (ctl
->widget
!= NULL
) ? ctl
->widget
->nid
: -1);
6380 if (ctl
->childwidget
!= NULL
)
6381 kprintf(" cnid=%d", ctl
->childwidget
->nid
);
6382 kprintf(" dir=0x%x index=%d "
6383 "ossmask=0x%08x ossdev=%d%s\n",
6384 ctl
->dir
, ctl
->index
,
6385 ctl
->ossmask
, ctl
->ossdev
,
6386 (ctl
->enable
== 0) ? " [DISABLED]" : "");
6388 device_printf(sc
->dev
, "\n");
6389 device_printf(sc
->dev
, "+-----------------------------------+\n");
6390 device_printf(sc
->dev
, "| DUMPING HDA AUDIO/VOLUME CONTROLS |\n");
6391 device_printf(sc
->dev
, "+-----------------------------------+\n");
6392 hdac_dump_ctls(devinfo
, "Master Volume (OSS: vol)", SOUND_MASK_VOLUME
);
6393 hdac_dump_ctls(devinfo
, "PCM Volume (OSS: pcm)", SOUND_MASK_PCM
);
6394 hdac_dump_ctls(devinfo
, "CD Volume (OSS: cd)", SOUND_MASK_CD
);
6395 hdac_dump_ctls(devinfo
, "Microphone Volume (OSS: mic)", SOUND_MASK_MIC
);
6396 hdac_dump_ctls(devinfo
, "Line-in Volume (OSS: line)", SOUND_MASK_LINE
);
6397 hdac_dump_ctls(devinfo
, "Recording Level (OSS: rec)", SOUND_MASK_RECLEV
);
6398 hdac_dump_ctls(devinfo
, "Speaker/Beep (OSS: speaker)", SOUND_MASK_SPEAKER
);
6399 hdac_dump_ctls(devinfo
, NULL
, 0);
6400 hdac_dump_dac(devinfo
);
6401 hdac_dump_adc(devinfo
);
6402 device_printf(sc
->dev
, "\n");
6403 device_printf(sc
->dev
, "+--------------------------------------+\n");
6404 device_printf(sc
->dev
, "| DUMPING PCM Playback/Record Channels |\n");
6405 device_printf(sc
->dev
, "+--------------------------------------+\n");
6406 hdac_dump_pcmchannels(sc
, pcnt
, rcnt
);
6409 if (sc
->polling
!= 0) {
6411 callout_reset(&sc
->poll_hdac
, 1, hdac_poll_callback
, sc
);
6416 /****************************************************************************
6417 * int hdac_detach(device_t)
6419 * Detach and free up resources utilized by the hdac device.
6420 ****************************************************************************/
6422 hdac_detach(device_t dev
)
6424 struct hdac_softc
*sc
= NULL
;
6425 struct hdac_devinfo
*devinfo
= NULL
;
6428 devinfo
= (struct hdac_devinfo
*)pcm_getdevinfo(dev
);
6429 if (devinfo
!= NULL
&& devinfo
->codec
!= NULL
)
6430 sc
= devinfo
->codec
->sc
;
6434 if (sc
->registered
> 0) {
6435 err
= pcm_unregister(dev
);
6440 hdac_release_resources(sc
);
6445 static device_method_t hdac_methods
[] = {
6446 /* device interface */
6447 DEVMETHOD(device_probe
, hdac_probe
),
6448 DEVMETHOD(device_attach
, hdac_attach
),
6449 DEVMETHOD(device_detach
, hdac_detach
),
6453 static driver_t hdac_driver
= {
6459 DRIVER_MODULE(snd_hda
, pci
, hdac_driver
, pcm_devclass
, 0, 0);
6460 MODULE_DEPEND(snd_hda
, sound
, SOUND_MINVER
, SOUND_PREFVER
, SOUND_MAXVER
);
6461 MODULE_VERSION(snd_hda
, 1);