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.4 2007/07/04 04:05:22 ariff Exp $
28 * $DragonFly: src/sys/dev/sound/pci/hda/hdac.c,v 1.10 2007/11/30 07:41:28 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 "20070702_0046"
88 #define HDA_WIDGET_PARSER_REV 1
90 SND_DECLARE_FILE("$DragonFly: src/sys/dev/sound/pci/hda/hdac.c,v 1.10 2007/11/30 07:41:28 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)->nocache != 0 && va != 0 && sz != 0) \
114 (void)pmap_change_attr(va, sz, (attr)); \
117 #define HDAC_DMA_ATTR(...)
120 #define HDA_FLAG_MATCH(fl, v) (((fl) & (v)) == (v))
121 #define HDA_DEV_MATCH(fl, v) ((fl) == (v) || \
122 (fl) == 0xffffffff || \
123 (((fl) & 0xffff0000) == 0xffff0000 && \
124 ((fl) & 0x0000ffff) == ((v) & 0x0000ffff)) || \
125 (((fl) & 0x0000ffff) == 0x0000ffff && \
126 ((fl) & 0xffff0000) == ((v) & 0xffff0000)))
127 #define HDA_MATCH_ALL 0xffffffff
128 #define HDAC_INVALID 0xffffffff
130 /* Default controller / jack sense poll: 250ms */
131 #define HDAC_POLL_INTERVAL max(hz >> 2, 1)
134 * Make room for possible 4096 playback/record channels, in 100 years to come.
136 #define HDAC_TRIGGER_NONE 0x00000000
137 #define HDAC_TRIGGER_PLAY 0x00000fff
138 #define HDAC_TRIGGER_REC 0x00fff000
139 #define HDAC_TRIGGER_UNSOL 0x80000000
141 #define HDA_MODEL_CONSTRUCT(vendor, model) \
142 (((uint32_t)(model) << 16) | ((vendor##_VENDORID) & 0xffff))
144 /* Controller models */
147 #define INTEL_VENDORID 0x8086
148 #define HDA_INTEL_82801F HDA_MODEL_CONSTRUCT(INTEL, 0x2668)
149 #define HDA_INTEL_82801G HDA_MODEL_CONSTRUCT(INTEL, 0x27d8)
150 #define HDA_INTEL_82801H HDA_MODEL_CONSTRUCT(INTEL, 0x284b)
151 #define HDA_INTEL_63XXESB HDA_MODEL_CONSTRUCT(INTEL, 0x269a)
152 #define HDA_INTEL_ALL HDA_MODEL_CONSTRUCT(INTEL, 0xffff)
155 #define NVIDIA_VENDORID 0x10de
156 #define HDA_NVIDIA_MCP51 HDA_MODEL_CONSTRUCT(NVIDIA, 0x026c)
157 #define HDA_NVIDIA_MCP55 HDA_MODEL_CONSTRUCT(NVIDIA, 0x0371)
158 #define HDA_NVIDIA_MCP61A HDA_MODEL_CONSTRUCT(NVIDIA, 0x03e4)
159 #define HDA_NVIDIA_MCP61B HDA_MODEL_CONSTRUCT(NVIDIA, 0x03f0)
160 #define HDA_NVIDIA_MCP65A HDA_MODEL_CONSTRUCT(NVIDIA, 0x044a)
161 #define HDA_NVIDIA_MCP65B HDA_MODEL_CONSTRUCT(NVIDIA, 0x044b)
162 #define HDA_NVIDIA_ALL HDA_MODEL_CONSTRUCT(NVIDIA, 0xffff)
165 #define ATI_VENDORID 0x1002
166 #define HDA_ATI_SB450 HDA_MODEL_CONSTRUCT(ATI, 0x437b)
167 #define HDA_ATI_SB600 HDA_MODEL_CONSTRUCT(ATI, 0x4383)
168 #define HDA_ATI_ALL HDA_MODEL_CONSTRUCT(ATI, 0xffff)
171 #define VIA_VENDORID 0x1106
172 #define HDA_VIA_VT82XX HDA_MODEL_CONSTRUCT(VIA, 0x3288)
173 #define HDA_VIA_ALL HDA_MODEL_CONSTRUCT(VIA, 0xffff)
176 #define SIS_VENDORID 0x1039
177 #define HDA_SIS_966 HDA_MODEL_CONSTRUCT(SIS, 0x7502)
178 #define HDA_SIS_ALL HDA_MODEL_CONSTRUCT(SIS, 0xffff)
183 #define INTEL_D101GGC_SUBVENDOR HDA_MODEL_CONSTRUCT(INTEL, 0xd600)
186 #define HP_VENDORID 0x103c
187 #define HP_V3000_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x30b5)
188 #define HP_NX7400_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x30a2)
189 #define HP_NX6310_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x30aa)
190 #define HP_NX6325_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x30b0)
191 #define HP_XW4300_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x3013)
192 #define HP_3010_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x3010)
193 #define HP_DV5000_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0x30a5)
194 #define HP_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(HP, 0xffff)
195 /* What is wrong with XN 2563 anyway? (Got the picture ?) */
196 #define HP_NX6325_SUBVENDORX 0x103c30b0
199 #define DELL_VENDORID 0x1028
200 #define DELL_D820_SUBVENDOR HDA_MODEL_CONSTRUCT(DELL, 0x01cc)
201 #define DELL_I1300_SUBVENDOR HDA_MODEL_CONSTRUCT(DELL, 0x01c9)
202 #define DELL_XPSM1210_SUBVENDOR HDA_MODEL_CONSTRUCT(DELL, 0x01d7)
203 #define DELL_OPLX745_SUBVENDOR HDA_MODEL_CONSTRUCT(DELL, 0x01da)
204 #define DELL_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(DELL, 0xffff)
207 #define CLEVO_VENDORID 0x1558
208 #define CLEVO_D900T_SUBVENDOR HDA_MODEL_CONSTRUCT(CLEVO, 0x0900)
209 #define CLEVO_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(CLEVO, 0xffff)
212 #define ACER_VENDORID 0x1025
213 #define ACER_A5050_SUBVENDOR HDA_MODEL_CONSTRUCT(ACER, 0x010f)
214 #define ACER_3681WXM_SUBVENDOR HDA_MODEL_CONSTRUCT(ACER, 0x0110)
215 #define ACER_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(ACER, 0xffff)
218 #define ASUS_VENDORID 0x1043
219 #define ASUS_M5200_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x1993)
220 #define ASUS_U5F_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x1263)
221 #define ASUS_A8JC_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x1153)
222 #define ASUS_P1AH2_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x81cb)
223 #define ASUS_A7M_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x1323)
224 #define ASUS_A7T_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x13c2)
225 #define ASUS_W6F_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x1263)
226 #define ASUS_W2J_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x1971)
227 #define ASUS_F3JC_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x1338)
228 #define ASUS_M2V_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x81e7)
229 #define ASUS_M2N_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x8234)
230 #define ASUS_M2NPVMX_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x81cb)
231 #define ASUS_P5BWD_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0x81ec)
232 #define ASUS_A8NVMCSM_SUBVENDOR HDA_MODEL_CONSTRUCT(NVIDIA, 0xcb84)
233 #define ASUS_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(ASUS, 0xffff)
236 #define IBM_VENDORID 0x1014
237 #define IBM_M52_SUBVENDOR HDA_MODEL_CONSTRUCT(IBM, 0x02f6)
238 #define IBM_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(IBM, 0xffff)
241 #define LENOVO_VENDORID 0x17aa
242 #define LENOVO_3KN100_SUBVENDOR HDA_MODEL_CONSTRUCT(LENOVO, 0x2066)
243 #define LENOVO_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(LENOVO, 0xffff)
246 #define SAMSUNG_VENDORID 0x144d
247 #define SAMSUNG_Q1_SUBVENDOR HDA_MODEL_CONSTRUCT(SAMSUNG, 0xc027)
248 #define SAMSUNG_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(SAMSUNG, 0xffff)
251 #define MEDION_VENDORID 0x161f
252 #define MEDION_MD95257_SUBVENDOR HDA_MODEL_CONSTRUCT(MEDION, 0x203d)
253 #define MEDION_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(MEDION, 0xffff)
256 * Apple Intel MacXXXX seems using Sigmatel codec/vendor id
257 * instead of their own, which is beyond my comprehension
258 * (see HDA_CODEC_STAC9221 below).
260 #define APPLE_INTEL_MAC 0x76808384
263 #define LG_VENDORID 0x1854
264 #define LG_LW20_SUBVENDOR HDA_MODEL_CONSTRUCT(LG, 0x0018)
265 #define LG_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(LG, 0xffff)
267 /* Fujitsu Siemens */
268 #define FS_VENDORID 0x1734
269 #define FS_PA1510_SUBVENDOR HDA_MODEL_CONSTRUCT(FS, 0x10b8)
270 #define FS_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(FS, 0xffff)
273 #define TOSHIBA_VENDORID 0x1179
274 #define TOSHIBA_U200_SUBVENDOR HDA_MODEL_CONSTRUCT(TOSHIBA, 0x0001)
275 #define TOSHIBA_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(TOSHIBA, 0xffff)
277 /* Micro-Star International (MSI) */
278 #define MSI_VENDORID 0x1462
279 #define MSI_MS1034_SUBVENDOR HDA_MODEL_CONSTRUCT(MSI, 0x0349)
280 #define MSI_ALL_SUBVENDOR HDA_MODEL_CONSTRUCT(MSI, 0xffff)
283 #define UNIWILL_VENDORID 0x1584
284 #define UNIWILL_9075_SUBVENDOR HDA_MODEL_CONSTRUCT(UNIWILL, 0x9075)
285 #define UNIWILL_9080_SUBVENDOR HDA_MODEL_CONSTRUCT(UNIWILL, 0x9080)
288 /* Misc constants.. */
289 #define HDA_AMP_MUTE_DEFAULT (0xffffffff)
290 #define HDA_AMP_MUTE_NONE (0)
291 #define HDA_AMP_MUTE_LEFT (1 << 0)
292 #define HDA_AMP_MUTE_RIGHT (1 << 1)
293 #define HDA_AMP_MUTE_ALL (HDA_AMP_MUTE_LEFT | HDA_AMP_MUTE_RIGHT)
295 #define HDA_AMP_LEFT_MUTED(v) ((v) & (HDA_AMP_MUTE_LEFT))
296 #define HDA_AMP_RIGHT_MUTED(v) (((v) & HDA_AMP_MUTE_RIGHT) >> 1)
298 #define HDA_DAC_PATH (1 << 0)
299 #define HDA_ADC_PATH (1 << 1)
300 #define HDA_ADC_RECSEL (1 << 2)
302 #define HDA_DAC_LOCKED (1 << 3)
303 #define HDA_ADC_LOCKED (1 << 4)
305 #define HDA_CTL_OUT (1 << 0)
306 #define HDA_CTL_IN (1 << 1)
307 #define HDA_CTL_BOTH (HDA_CTL_IN | HDA_CTL_OUT)
309 #define HDA_GPIO_MAX 8
310 /* 0 - 7 = GPIO , 8 = Flush */
311 #define HDA_QUIRK_GPIO0 (1 << 0)
312 #define HDA_QUIRK_GPIO1 (1 << 1)
313 #define HDA_QUIRK_GPIO2 (1 << 2)
314 #define HDA_QUIRK_GPIO3 (1 << 3)
315 #define HDA_QUIRK_GPIO4 (1 << 4)
316 #define HDA_QUIRK_GPIO5 (1 << 5)
317 #define HDA_QUIRK_GPIO6 (1 << 6)
318 #define HDA_QUIRK_GPIO7 (1 << 7)
319 #define HDA_QUIRK_GPIOFLUSH (1 << 8)
321 /* 9 - 25 = anything else */
322 #define HDA_QUIRK_SOFTPCMVOL (1 << 9)
323 #define HDA_QUIRK_FIXEDRATE (1 << 10)
324 #define HDA_QUIRK_FORCESTEREO (1 << 11)
325 #define HDA_QUIRK_EAPDINV (1 << 12)
326 #define HDA_QUIRK_DMAPOS (1 << 13)
328 /* 26 - 31 = vrefs */
329 #define HDA_QUIRK_IVREF50 (1 << 26)
330 #define HDA_QUIRK_IVREF80 (1 << 27)
331 #define HDA_QUIRK_IVREF100 (1 << 28)
332 #define HDA_QUIRK_OVREF50 (1 << 29)
333 #define HDA_QUIRK_OVREF80 (1 << 30)
334 #define HDA_QUIRK_OVREF100 (1 << 31)
336 #define HDA_QUIRK_IVREF (HDA_QUIRK_IVREF50 | HDA_QUIRK_IVREF80 | \
338 #define HDA_QUIRK_OVREF (HDA_QUIRK_OVREF50 | HDA_QUIRK_OVREF80 | \
340 #define HDA_QUIRK_VREF (HDA_QUIRK_IVREF | HDA_QUIRK_OVREF)
342 #define SOUND_MASK_SKIP (1 << 30)
343 #define SOUND_MASK_DISABLE (1 << 31)
345 static const struct {
348 } hdac_quirks_tab
[] = {
349 { "gpio0", HDA_QUIRK_GPIO0
},
350 { "gpio1", HDA_QUIRK_GPIO1
},
351 { "gpio2", HDA_QUIRK_GPIO2
},
352 { "gpio3", HDA_QUIRK_GPIO3
},
353 { "gpio4", HDA_QUIRK_GPIO4
},
354 { "gpio5", HDA_QUIRK_GPIO5
},
355 { "gpio6", HDA_QUIRK_GPIO6
},
356 { "gpio7", HDA_QUIRK_GPIO7
},
357 { "gpioflush", HDA_QUIRK_GPIOFLUSH
},
358 { "softpcmvol", HDA_QUIRK_SOFTPCMVOL
},
359 { "fixedrate", HDA_QUIRK_FIXEDRATE
},
360 { "forcestereo", HDA_QUIRK_FORCESTEREO
},
361 { "eapdinv", HDA_QUIRK_EAPDINV
},
362 { "dmapos", HDA_QUIRK_DMAPOS
},
363 { "ivref50", HDA_QUIRK_IVREF50
},
364 { "ivref80", HDA_QUIRK_IVREF80
},
365 { "ivref100", HDA_QUIRK_IVREF100
},
366 { "ovref50", HDA_QUIRK_OVREF50
},
367 { "ovref80", HDA_QUIRK_OVREF80
},
368 { "ovref100", HDA_QUIRK_OVREF100
},
369 { "ivref", HDA_QUIRK_IVREF
},
370 { "ovref", HDA_QUIRK_OVREF
},
371 { "vref", HDA_QUIRK_VREF
},
373 #define HDAC_QUIRKS_TAB_LEN \
374 (sizeof(hdac_quirks_tab) / sizeof(hdac_quirks_tab[0]))
376 #define HDA_BDL_MIN 2
377 #define HDA_BDL_MAX 256
378 #define HDA_BDL_DEFAULT HDA_BDL_MIN
380 #define HDA_BLK_MIN HDAC_DMA_ALIGNMENT
381 #define HDA_BLK_ALIGN (~(HDA_BLK_MIN - 1))
383 #define HDA_BUFSZ_MIN 4096
384 #define HDA_BUFSZ_MAX 65536
385 #define HDA_BUFSZ_DEFAULT 16384
387 #define HDA_PARSE_MAXDEPTH 10
389 #define HDAC_UNSOLTAG_EVENT_HP 0x00
390 #define HDAC_UNSOLTAG_EVENT_TEST 0x01
392 MALLOC_DEFINE(M_HDAC
, "hdac", "High Definition Audio Controller");
400 static uint32_t hdac_fmt
[] = {
401 AFMT_STEREO
| AFMT_S16_LE
,
405 static struct pcmchan_caps hdac_caps
= {48000, 48000, hdac_fmt
, 0};
407 static const struct {
411 { HDA_INTEL_82801F
, "Intel 82801F" },
412 { HDA_INTEL_82801G
, "Intel 82801G" },
413 { HDA_INTEL_82801H
, "Intel 82801H" },
414 { HDA_INTEL_63XXESB
, "Intel 631x/632xESB" },
415 { HDA_NVIDIA_MCP51
, "NVidia MCP51" },
416 { HDA_NVIDIA_MCP55
, "NVidia MCP55" },
417 { HDA_NVIDIA_MCP61A
, "NVidia MCP61A" },
418 { HDA_NVIDIA_MCP61B
, "NVidia MCP61B" },
419 { HDA_NVIDIA_MCP65A
, "NVidia MCP65A" },
420 { HDA_NVIDIA_MCP65B
, "NVidia MCP65B" },
421 { HDA_ATI_SB450
, "ATI SB450" },
422 { HDA_ATI_SB600
, "ATI SB600" },
423 { HDA_VIA_VT82XX
, "VIA VT8251/8237A" },
424 { HDA_SIS_966
, "SiS 966" },
426 { HDA_INTEL_ALL
, "Intel (Unknown)" },
427 { HDA_NVIDIA_ALL
, "NVidia (Unknown)" },
428 { HDA_ATI_ALL
, "ATI (Unknown)" },
429 { HDA_VIA_ALL
, "VIA (Unknown)" },
430 { HDA_SIS_ALL
, "SiS (Unknown)" },
432 #define HDAC_DEVICES_LEN (sizeof(hdac_devices) / sizeof(hdac_devices[0]))
434 static const struct {
439 } hdac_pcie_snoop
[] = {
440 { INTEL_VENDORID
, 0x00, 0x00, 0x00 },
441 { ATI_VENDORID
, 0x42, 0xf8, 0x02 },
442 { NVIDIA_VENDORID
, 0x4e, 0xf0, 0x0f },
444 #define HDAC_PCIESNOOP_LEN \
445 (sizeof(hdac_pcie_snoop) / sizeof(hdac_pcie_snoop[0]))
447 static const struct {
454 { 8000, 1, 0x0000, 0x0000, 0x0500 }, /* (48000 * 1) / 6 */
455 { 9600, 0, 0x0000, 0x0000, 0x0400 }, /* (48000 * 1) / 5 */
456 { 12000, 0, 0x0000, 0x0000, 0x0300 }, /* (48000 * 1) / 4 */
457 { 16000, 1, 0x0000, 0x0000, 0x0200 }, /* (48000 * 1) / 3 */
458 { 18000, 0, 0x0000, 0x1000, 0x0700 }, /* (48000 * 3) / 8 */
459 { 19200, 0, 0x0000, 0x0800, 0x0400 }, /* (48000 * 2) / 5 */
460 { 24000, 0, 0x0000, 0x0000, 0x0100 }, /* (48000 * 1) / 2 */
461 { 28800, 0, 0x0000, 0x1000, 0x0400 }, /* (48000 * 3) / 5 */
462 { 32000, 1, 0x0000, 0x0800, 0x0200 }, /* (48000 * 2) / 3 */
463 { 36000, 0, 0x0000, 0x1000, 0x0300 }, /* (48000 * 3) / 4 */
464 { 38400, 0, 0x0000, 0x1800, 0x0400 }, /* (48000 * 4) / 5 */
465 { 48000, 1, 0x0000, 0x0000, 0x0000 }, /* (48000 * 1) / 1 */
466 { 64000, 0, 0x0000, 0x1800, 0x0200 }, /* (48000 * 4) / 3 */
467 { 72000, 0, 0x0000, 0x1000, 0x0100 }, /* (48000 * 3) / 2 */
468 { 96000, 1, 0x0000, 0x0800, 0x0000 }, /* (48000 * 2) / 1 */
469 { 144000, 0, 0x0000, 0x1000, 0x0000 }, /* (48000 * 3) / 1 */
470 { 192000, 1, 0x0000, 0x1800, 0x0000 }, /* (48000 * 4) / 1 */
471 { 8820, 0, 0x4000, 0x0000, 0x0400 }, /* (44100 * 1) / 5 */
472 { 11025, 1, 0x4000, 0x0000, 0x0300 }, /* (44100 * 1) / 4 */
473 { 12600, 0, 0x4000, 0x0800, 0x0600 }, /* (44100 * 2) / 7 */
474 { 14700, 0, 0x4000, 0x0000, 0x0200 }, /* (44100 * 1) / 3 */
475 { 17640, 0, 0x4000, 0x0800, 0x0400 }, /* (44100 * 2) / 5 */
476 { 18900, 0, 0x4000, 0x1000, 0x0600 }, /* (44100 * 3) / 7 */
477 { 22050, 1, 0x4000, 0x0000, 0x0100 }, /* (44100 * 1) / 2 */
478 { 25200, 0, 0x4000, 0x1800, 0x0600 }, /* (44100 * 4) / 7 */
479 { 26460, 0, 0x4000, 0x1000, 0x0400 }, /* (44100 * 3) / 5 */
480 { 29400, 0, 0x4000, 0x0800, 0x0200 }, /* (44100 * 2) / 3 */
481 { 33075, 0, 0x4000, 0x1000, 0x0300 }, /* (44100 * 3) / 4 */
482 { 35280, 0, 0x4000, 0x1800, 0x0400 }, /* (44100 * 4) / 5 */
483 { 44100, 1, 0x4000, 0x0000, 0x0000 }, /* (44100 * 1) / 1 */
484 { 58800, 0, 0x4000, 0x1800, 0x0200 }, /* (44100 * 4) / 3 */
485 { 66150, 0, 0x4000, 0x1000, 0x0100 }, /* (44100 * 3) / 2 */
486 { 88200, 1, 0x4000, 0x0800, 0x0000 }, /* (44100 * 2) / 1 */
487 { 132300, 0, 0x4000, 0x1000, 0x0000 }, /* (44100 * 3) / 1 */
488 { 176400, 1, 0x4000, 0x1800, 0x0000 }, /* (44100 * 4) / 1 */
490 #define HDA_RATE_TAB_LEN (sizeof(hda_rate_tab) / sizeof(hda_rate_tab[0]))
492 /* All codecs you can eat... */
493 #define HDA_CODEC_CONSTRUCT(vendor, id) \
494 (((uint32_t)(vendor##_VENDORID) << 16) | ((id) & 0xffff))
497 #define REALTEK_VENDORID 0x10ec
498 #define HDA_CODEC_ALC260 HDA_CODEC_CONSTRUCT(REALTEK, 0x0260)
499 #define HDA_CODEC_ALC262 HDA_CODEC_CONSTRUCT(REALTEK, 0x0262)
500 #define HDA_CODEC_ALC660 HDA_CODEC_CONSTRUCT(REALTEK, 0x0660)
501 #define HDA_CODEC_ALC861 HDA_CODEC_CONSTRUCT(REALTEK, 0x0861)
502 #define HDA_CODEC_ALC861VD HDA_CODEC_CONSTRUCT(REALTEK, 0x0862)
503 #define HDA_CODEC_ALC880 HDA_CODEC_CONSTRUCT(REALTEK, 0x0880)
504 #define HDA_CODEC_ALC882 HDA_CODEC_CONSTRUCT(REALTEK, 0x0882)
505 #define HDA_CODEC_ALC883 HDA_CODEC_CONSTRUCT(REALTEK, 0x0883)
506 #define HDA_CODEC_ALC885 HDA_CODEC_CONSTRUCT(REALTEK, 0x0885)
507 #define HDA_CODEC_ALC888 HDA_CODEC_CONSTRUCT(REALTEK, 0x0888)
508 #define HDA_CODEC_ALCXXXX HDA_CODEC_CONSTRUCT(REALTEK, 0xffff)
511 #define ANALOGDEVICES_VENDORID 0x11d4
512 #define HDA_CODEC_AD1981HD HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0x1981)
513 #define HDA_CODEC_AD1983 HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0x1983)
514 #define HDA_CODEC_AD1986A HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0x1986)
515 #define HDA_CODEC_AD1988 HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0x1988)
516 #define HDA_CODEC_AD1988B HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0x198b)
517 #define HDA_CODEC_ADXXXX HDA_CODEC_CONSTRUCT(ANALOGDEVICES, 0xffff)
520 #define CMEDIA_VENDORID 0x434d
521 #define HDA_CODEC_CMI9880 HDA_CODEC_CONSTRUCT(CMEDIA, 0x4980)
522 #define HDA_CODEC_CMIXXXX HDA_CODEC_CONSTRUCT(CMEDIA, 0xffff)
525 #define SIGMATEL_VENDORID 0x8384
526 #define HDA_CODEC_STAC9221 HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7680)
527 #define HDA_CODEC_STAC9221D HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7683)
528 #define HDA_CODEC_STAC9220 HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7690)
529 #define HDA_CODEC_STAC922XD HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7681)
530 #define HDA_CODEC_STAC9227 HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7618)
531 #define HDA_CODEC_STAC9271D HDA_CODEC_CONSTRUCT(SIGMATEL, 0x7627)
532 #define HDA_CODEC_STACXXXX HDA_CODEC_CONSTRUCT(SIGMATEL, 0xffff)
537 * Ok, the truth is, I don't have any idea at all whether
538 * it is "Venice" or "Waikiki" or other unnamed CXyadayada. The only
539 * place that tell me it is "Venice" is from its Windows driver INF.
542 * Waikiki - CX20551-22
544 #define CONEXANT_VENDORID 0x14f1
545 #define HDA_CODEC_CXVENICE HDA_CODEC_CONSTRUCT(CONEXANT, 0x5045)
546 #define HDA_CODEC_CXWAIKIKI HDA_CODEC_CONSTRUCT(CONEXANT, 0x5047)
547 #define HDA_CODEC_CXXXXX HDA_CODEC_CONSTRUCT(CONEXANT, 0xffff)
550 #define HDA_CODEC_VT1708_8 HDA_CODEC_CONSTRUCT(VIA, 0x1708)
551 #define HDA_CODEC_VT1708_9 HDA_CODEC_CONSTRUCT(VIA, 0x1709)
552 #define HDA_CODEC_VT1708_A HDA_CODEC_CONSTRUCT(VIA, 0x170a)
553 #define HDA_CODEC_VT1708_B HDA_CODEC_CONSTRUCT(VIA, 0x170b)
554 #define HDA_CODEC_VT1709_0 HDA_CODEC_CONSTRUCT(VIA, 0xe710)
555 #define HDA_CODEC_VT1709_1 HDA_CODEC_CONSTRUCT(VIA, 0xe711)
556 #define HDA_CODEC_VT1709_2 HDA_CODEC_CONSTRUCT(VIA, 0xe712)
557 #define HDA_CODEC_VT1709_3 HDA_CODEC_CONSTRUCT(VIA, 0xe713)
558 #define HDA_CODEC_VT1709_4 HDA_CODEC_CONSTRUCT(VIA, 0xe714)
559 #define HDA_CODEC_VT1709_5 HDA_CODEC_CONSTRUCT(VIA, 0xe715)
560 #define HDA_CODEC_VT1709_6 HDA_CODEC_CONSTRUCT(VIA, 0xe716)
561 #define HDA_CODEC_VT1709_7 HDA_CODEC_CONSTRUCT(VIA, 0xe717)
562 #define HDA_CODEC_VTXXXX HDA_CODEC_CONSTRUCT(VIA, 0xffff)
566 static const struct {
570 { HDA_CODEC_ALC260
, "Realtek ALC260" },
571 { HDA_CODEC_ALC262
, "Realtek ALC262" },
572 { HDA_CODEC_ALC660
, "Realtek ALC660" },
573 { HDA_CODEC_ALC861
, "Realtek ALC861" },
574 { HDA_CODEC_ALC861VD
, "Realtek ALC861-VD" },
575 { HDA_CODEC_ALC880
, "Realtek ALC880" },
576 { HDA_CODEC_ALC882
, "Realtek ALC882" },
577 { HDA_CODEC_ALC883
, "Realtek ALC883" },
578 { HDA_CODEC_ALC885
, "Realtek ALC885" },
579 { HDA_CODEC_ALC888
, "Realtek ALC888" },
580 { HDA_CODEC_AD1981HD
, "Analog Devices AD1981HD" },
581 { HDA_CODEC_AD1983
, "Analog Devices AD1983" },
582 { HDA_CODEC_AD1986A
, "Analog Devices AD1986A" },
583 { HDA_CODEC_AD1988
, "Analog Devices AD1988" },
584 { HDA_CODEC_AD1988B
, "Analog Devices AD1988B" },
585 { HDA_CODEC_CMI9880
, "CMedia CMI9880" },
586 { HDA_CODEC_STAC9221
, "Sigmatel STAC9221" },
587 { HDA_CODEC_STAC9221D
, "Sigmatel STAC9221D" },
588 { HDA_CODEC_STAC9220
, "Sigmatel STAC9220" },
589 { HDA_CODEC_STAC922XD
, "Sigmatel STAC9220D/9223D" },
590 { HDA_CODEC_STAC9227
, "Sigmatel STAC9227" },
591 { HDA_CODEC_STAC9271D
, "Sigmatel STAC9271D" },
592 { HDA_CODEC_CXVENICE
, "Conexant Venice" },
593 { HDA_CODEC_CXWAIKIKI
, "Conexant Waikiki" },
594 { HDA_CODEC_VT1708_8
, "VIA VT1708_8" },
595 { HDA_CODEC_VT1708_9
, "VIA VT1708_9" },
596 { HDA_CODEC_VT1708_A
, "VIA VT1708_A" },
597 { HDA_CODEC_VT1708_B
, "VIA VT1708_B" },
598 { HDA_CODEC_VT1709_0
, "VIA VT1709_0" },
599 { HDA_CODEC_VT1709_1
, "VIA VT1709_1" },
600 { HDA_CODEC_VT1709_2
, "VIA VT1709_2" },
601 { HDA_CODEC_VT1709_3
, "VIA VT1709_3" },
602 { HDA_CODEC_VT1709_4
, "VIA VT1709_4" },
603 { HDA_CODEC_VT1709_5
, "VIA VT1709_5" },
604 { HDA_CODEC_VT1709_6
, "VIA VT1709_6" },
605 { HDA_CODEC_VT1709_7
, "VIA VT1709_7" },
607 { HDA_CODEC_ALCXXXX
, "Realtek (Unknown)" },
608 { HDA_CODEC_ADXXXX
, "Analog Devices (Unknown)" },
609 { HDA_CODEC_CMIXXXX
, "CMedia (Unknown)" },
610 { HDA_CODEC_STACXXXX
, "Sigmatel (Unknown)" },
611 { HDA_CODEC_CXXXXX
, "Conexant (Unknown)" },
612 { HDA_CODEC_VTXXXX
, "VIA (Unknown)" },
614 #define HDAC_CODECS_LEN (sizeof(hdac_codecs) / sizeof(hdac_codecs[0]))
622 static const struct {
632 } hdac_hp_switch
[] = {
633 /* Specific OEM models */
634 { HP_V3000_SUBVENDOR
, HDA_CODEC_CXVENICE
, HDAC_HP_SWITCH_CTL
,
635 0, 0, -1, 17, { 16, -1 }, 16 },
636 /* { HP_XW4300_SUBVENDOR, HDA_CODEC_ALC260, HDAC_HP_SWITCH_CTL,
637 0, 0, -1, 21, { 16, 17, -1 }, -1 } */
638 /*{ HP_3010_SUBVENDOR, HDA_CODEC_ALC260, HDAC_HP_SWITCH_DEBUG,
639 0, 1, 0, 16, { 15, 18, 19, 20, 21, -1 }, -1 },*/
640 { HP_NX7400_SUBVENDOR
, HDA_CODEC_AD1981HD
, HDAC_HP_SWITCH_CTL
,
641 0, 0, -1, 6, { 5, -1 }, 5 },
642 { HP_NX6310_SUBVENDOR
, HDA_CODEC_AD1981HD
, HDAC_HP_SWITCH_CTL
,
643 0, 0, -1, 6, { 5, -1 }, 5 },
644 { HP_NX6325_SUBVENDOR
, HDA_CODEC_AD1981HD
, HDAC_HP_SWITCH_CTL
,
645 0, 0, -1, 6, { 5, -1 }, 5 },
646 { TOSHIBA_U200_SUBVENDOR
, HDA_CODEC_AD1981HD
, HDAC_HP_SWITCH_CTL
,
647 0, 0, -1, 6, { 5, -1 }, -1 },
648 { DELL_D820_SUBVENDOR
, HDA_CODEC_STAC9220
, HDAC_HP_SWITCH_CTRL
,
649 0, 0, -1, 13, { 14, -1 }, -1 },
650 { DELL_I1300_SUBVENDOR
, HDA_CODEC_STAC9220
, HDAC_HP_SWITCH_CTRL
,
651 0, 0, -1, 13, { 14, -1 }, -1 },
652 { DELL_OPLX745_SUBVENDOR
, HDA_CODEC_AD1983
, HDAC_HP_SWITCH_CTL
,
653 0, 0, -1, 6, { 5, 7, -1 }, -1 },
654 { APPLE_INTEL_MAC
, HDA_CODEC_STAC9221
, HDAC_HP_SWITCH_CTRL
,
655 0, 0, -1, 10, { 13, -1 }, -1 },
656 { LENOVO_3KN100_SUBVENDOR
, HDA_CODEC_AD1986A
, HDAC_HP_SWITCH_CTL
,
657 1, 0, -1, 26, { 27, -1 }, -1 },
658 { LG_LW20_SUBVENDOR
, HDA_CODEC_ALC880
, HDAC_HP_SWITCH_CTL
,
659 0, 0, -1, 27, { 20, -1 }, -1 },
660 { ACER_A5050_SUBVENDOR
, HDA_CODEC_ALC883
, HDAC_HP_SWITCH_CTL
,
661 0, 0, -1, 20, { 21, -1 }, -1 },
662 { ACER_3681WXM_SUBVENDOR
, HDA_CODEC_ALC883
, HDAC_HP_SWITCH_CTL
,
663 0, 0, -1, 20, { 21, -1 }, -1 },
664 { UNIWILL_9080_SUBVENDOR
, HDA_CODEC_ALC883
, HDAC_HP_SWITCH_CTL
,
665 0, 0, -1, 20, { 21, -1 }, -1 },
666 { MSI_MS1034_SUBVENDOR
, HDA_CODEC_ALC883
, HDAC_HP_SWITCH_CTL
,
667 0, 0, -1, 20, { 27, -1 }, -1 },
669 * All models that at least come from the same vendor with
672 { HP_ALL_SUBVENDOR
, HDA_CODEC_CXVENICE
, HDAC_HP_SWITCH_CTL
,
673 0, 0, -1, 17, { 16, -1 }, 16 },
674 { HP_ALL_SUBVENDOR
, HDA_CODEC_AD1981HD
, HDAC_HP_SWITCH_CTL
,
675 0, 0, -1, 6, { 5, -1 }, 5 },
676 { TOSHIBA_ALL_SUBVENDOR
, HDA_CODEC_AD1981HD
, HDAC_HP_SWITCH_CTL
,
677 0, 0, -1, 6, { 5, -1 }, -1 },
678 { DELL_ALL_SUBVENDOR
, HDA_CODEC_STAC9220
, HDAC_HP_SWITCH_CTRL
,
679 0, 0, -1, 13, { 14, -1 }, -1 },
680 { LENOVO_ALL_SUBVENDOR
, HDA_CODEC_AD1986A
, HDAC_HP_SWITCH_CTL
,
681 1, 0, -1, 26, { 27, -1 }, -1 },
683 { ACER_ALL_SUBVENDOR
, HDA_CODEC_ALC883
, HDAC_HP_SWITCH_CTL
,
684 0, 0, -1, 20, { 21, -1 }, -1 },
687 #define HDAC_HP_SWITCH_LEN \
688 (sizeof(hdac_hp_switch) / sizeof(hdac_hp_switch[0]))
690 static const struct {
695 } hdac_eapd_switch
[] = {
696 { HP_V3000_SUBVENDOR
, HDA_CODEC_CXVENICE
, 16, 1 },
697 { HP_NX7400_SUBVENDOR
, HDA_CODEC_AD1981HD
, 5, 1 },
698 { HP_NX6310_SUBVENDOR
, HDA_CODEC_AD1981HD
, 5, 1 },
700 #define HDAC_EAPD_SWITCH_LEN \
701 (sizeof(hdac_eapd_switch) / sizeof(hdac_eapd_switch[0]))
703 /****************************************************************************
704 * Function prototypes
705 ****************************************************************************/
706 static void hdac_intr_handler(void *);
707 static int hdac_reset(struct hdac_softc
*);
708 static int hdac_get_capabilities(struct hdac_softc
*);
709 static void hdac_dma_cb(void *, bus_dma_segment_t
*, int, int);
710 static int hdac_dma_alloc(struct hdac_softc
*,
711 struct hdac_dma
*, bus_size_t
);
712 static void hdac_dma_free(struct hdac_softc
*, struct hdac_dma
*);
713 static int hdac_mem_alloc(struct hdac_softc
*);
714 static void hdac_mem_free(struct hdac_softc
*);
715 static int hdac_irq_alloc(struct hdac_softc
*);
716 static void hdac_irq_free(struct hdac_softc
*);
717 static void hdac_corb_init(struct hdac_softc
*);
718 static void hdac_rirb_init(struct hdac_softc
*);
719 static void hdac_corb_start(struct hdac_softc
*);
720 static void hdac_rirb_start(struct hdac_softc
*);
721 static void hdac_scan_codecs(struct hdac_softc
*);
722 static int hdac_probe_codec(struct hdac_codec
*);
723 static struct hdac_devinfo
*hdac_probe_function(struct hdac_codec
*, nid_t
);
724 static void hdac_add_child(struct hdac_softc
*, struct hdac_devinfo
*);
726 static void hdac_attach2(void *);
728 static uint32_t hdac_command_sendone_internal(struct hdac_softc
*,
730 static void hdac_command_send_internal(struct hdac_softc
*,
731 struct hdac_command_list
*, int);
733 static int hdac_probe(device_t
);
734 static int hdac_attach(device_t
);
735 static int hdac_detach(device_t
);
736 static void hdac_widget_connection_select(struct hdac_widget
*, uint8_t);
737 static void hdac_audio_ctl_amp_set(struct hdac_audio_ctl
*,
739 static struct hdac_audio_ctl
*hdac_audio_ctl_amp_get(struct hdac_devinfo
*,
741 static void hdac_audio_ctl_amp_set_internal(struct hdac_softc
*,
742 nid_t
, nid_t
, int, int, int, int, int, int);
743 static int hdac_audio_ctl_ossmixer_getnextdev(struct hdac_devinfo
*);
744 static struct hdac_widget
*hdac_widget_get(struct hdac_devinfo
*, nid_t
);
746 static int hdac_rirb_flush(struct hdac_softc
*sc
);
747 static int hdac_unsolq_flush(struct hdac_softc
*sc
);
749 #define hdac_command(a1, a2, a3) \
750 hdac_command_sendone_internal(a1, a2, a3)
752 #define hdac_codec_id(d) \
753 ((uint32_t)((d == NULL) ? 0x00000000 : \
754 ((((uint32_t)(d)->vendor_id & 0x0000ffff) << 16) | \
755 ((uint32_t)(d)->device_id & 0x0000ffff))))
758 hdac_codec_name(struct hdac_devinfo
*devinfo
)
763 id
= hdac_codec_id(devinfo
);
765 for (i
= 0; i
< HDAC_CODECS_LEN
; i
++) {
766 if (HDA_DEV_MATCH(hdac_codecs
[i
].id
, id
))
767 return (hdac_codecs
[i
].name
);
770 return ((id
== 0x00000000) ? "NULL Codec" : "Unknown Codec");
774 hdac_audio_ctl_ossmixer_mask2name(uint32_t devmask
)
776 static char *ossname
[] = SOUND_DEVICE_NAMES
;
777 static char *unknown
= "???";
780 for (i
= SOUND_MIXER_NRDEVICES
- 1; i
>= 0; i
--) {
781 if (devmask
& (1 << i
))
788 hdac_audio_ctl_ossmixer_mask2allname(uint32_t mask
, char *buf
, size_t len
)
790 static char *ossname
[] = SOUND_DEVICE_NAMES
;
794 for (i
= 0; i
< SOUND_MIXER_NRDEVICES
; i
++) {
795 if (mask
& (1 << i
)) {
797 strlcat(buf
, ", ", len
);
798 strlcat(buf
, ossname
[i
], len
);
804 static struct hdac_audio_ctl
*
805 hdac_audio_ctl_each(struct hdac_devinfo
*devinfo
, int *index
)
807 if (devinfo
== NULL
||
808 devinfo
->node_type
!= HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO
||
809 index
== NULL
|| devinfo
->function
.audio
.ctl
== NULL
||
810 devinfo
->function
.audio
.ctlcnt
< 1 ||
811 *index
< 0 || *index
>= devinfo
->function
.audio
.ctlcnt
)
813 return (&devinfo
->function
.audio
.ctl
[(*index
)++]);
816 static struct hdac_audio_ctl
*
817 hdac_audio_ctl_amp_get(struct hdac_devinfo
*devinfo
, nid_t nid
,
820 struct hdac_audio_ctl
*ctl
, *retctl
= NULL
;
821 int i
, at
, atindex
, found
= 0;
823 if (devinfo
== NULL
|| devinfo
->function
.audio
.ctl
== NULL
)
836 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) != NULL
) {
837 if (ctl
->enable
== 0 || ctl
->widget
== NULL
)
839 if (!(ctl
->widget
->nid
== nid
&& (atindex
== -1 ||
840 ctl
->index
== atindex
)))
848 return ((at
== -1) ? retctl
: NULL
);
852 hdac_hp_switch_handler(struct hdac_devinfo
*devinfo
)
854 struct hdac_softc
*sc
;
855 struct hdac_widget
*w
;
856 struct hdac_audio_ctl
*ctl
;
857 uint32_t val
, id
, res
;
858 int i
= 0, j
, timeout
, forcemute
;
861 if (devinfo
== NULL
|| devinfo
->codec
== NULL
||
862 devinfo
->codec
->sc
== NULL
)
865 sc
= devinfo
->codec
->sc
;
866 cad
= devinfo
->codec
->cad
;
867 id
= hdac_codec_id(devinfo
);
868 for (i
= 0; i
< HDAC_HP_SWITCH_LEN
; i
++) {
869 if (HDA_DEV_MATCH(hdac_hp_switch
[i
].model
,
870 sc
->pci_subvendor
) &&
871 hdac_hp_switch
[i
].id
== id
)
875 if (i
>= HDAC_HP_SWITCH_LEN
)
879 if (hdac_hp_switch
[i
].eapdnid
!= -1) {
880 w
= hdac_widget_get(devinfo
, hdac_hp_switch
[i
].eapdnid
);
881 if (w
!= NULL
&& w
->param
.eapdbtl
!= HDAC_INVALID
)
882 forcemute
= (w
->param
.eapdbtl
&
883 HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD
) ? 0 : 1;
886 if (hdac_hp_switch
[i
].execsense
!= -1)
888 HDA_CMD_SET_PIN_SENSE(cad
, hdac_hp_switch
[i
].hpnid
,
889 hdac_hp_switch
[i
].execsense
), cad
);
893 res
= hdac_command(sc
,
894 HDA_CMD_GET_PIN_SENSE(cad
, hdac_hp_switch
[i
].hpnid
),
896 if (hdac_hp_switch
[i
].execsense
== -1 || res
!= 0x7fffffff)
899 } while (--timeout
!= 0);
902 device_printf(sc
->dev
,
903 "HDA_DEBUG: Pin sense: nid=%d timeout=%d res=0x%08x\n",
904 hdac_hp_switch
[i
].hpnid
, timeout
, res
);
907 res
= HDA_CMD_GET_PIN_SENSE_PRESENCE_DETECT(res
);
908 res
^= hdac_hp_switch
[i
].inverted
;
910 switch (hdac_hp_switch
[i
].type
) {
911 case HDAC_HP_SWITCH_CTL
:
912 ctl
= hdac_audio_ctl_amp_get(devinfo
,
913 hdac_hp_switch
[i
].hpnid
, 0, 1);
915 val
= (res
!= 0 && forcemute
== 0) ?
916 HDA_AMP_MUTE_NONE
: HDA_AMP_MUTE_ALL
;
917 if (val
!= ctl
->muted
) {
919 hdac_audio_ctl_amp_set(ctl
,
920 HDA_AMP_MUTE_DEFAULT
, ctl
->left
,
924 for (j
= 0; hdac_hp_switch
[i
].spkrnid
[j
] != -1; j
++) {
925 ctl
= hdac_audio_ctl_amp_get(devinfo
,
926 hdac_hp_switch
[i
].spkrnid
[j
], 0, 1);
929 val
= (res
!= 0 || forcemute
== 1) ?
930 HDA_AMP_MUTE_ALL
: HDA_AMP_MUTE_NONE
;
931 if (val
== ctl
->muted
)
934 hdac_audio_ctl_amp_set(ctl
, HDA_AMP_MUTE_DEFAULT
,
935 ctl
->left
, ctl
->right
);
938 case HDAC_HP_SWITCH_CTRL
:
941 w
= hdac_widget_get(devinfo
, hdac_hp_switch
[i
].hpnid
);
942 if (w
!= NULL
&& w
->type
==
943 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
) {
945 val
= w
->wclass
.pin
.ctrl
|
946 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE
;
948 val
= w
->wclass
.pin
.ctrl
&
949 ~HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE
;
950 if (val
!= w
->wclass
.pin
.ctrl
) {
951 w
->wclass
.pin
.ctrl
= val
;
953 HDA_CMD_SET_PIN_WIDGET_CTRL(cad
,
954 w
->nid
, w
->wclass
.pin
.ctrl
), cad
);
957 for (j
= 0; hdac_hp_switch
[i
].spkrnid
[j
] != -1; j
++) {
958 w
= hdac_widget_get(devinfo
,
959 hdac_hp_switch
[i
].spkrnid
[j
]);
960 if (w
== NULL
|| w
->type
!=
961 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
)
963 val
= w
->wclass
.pin
.ctrl
&
964 ~HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE
;
965 if (val
== w
->wclass
.pin
.ctrl
)
967 w
->wclass
.pin
.ctrl
= val
;
968 hdac_command(sc
, HDA_CMD_SET_PIN_WIDGET_CTRL(
969 cad
, w
->nid
, w
->wclass
.pin
.ctrl
), cad
);
973 w
= hdac_widget_get(devinfo
, hdac_hp_switch
[i
].hpnid
);
974 if (w
!= NULL
&& w
->type
==
975 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
) {
976 val
= w
->wclass
.pin
.ctrl
&
977 ~HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE
;
978 if (val
!= w
->wclass
.pin
.ctrl
) {
979 w
->wclass
.pin
.ctrl
= val
;
981 HDA_CMD_SET_PIN_WIDGET_CTRL(cad
,
982 w
->nid
, w
->wclass
.pin
.ctrl
), cad
);
985 for (j
= 0; hdac_hp_switch
[i
].spkrnid
[j
] != -1; j
++) {
986 w
= hdac_widget_get(devinfo
,
987 hdac_hp_switch
[i
].spkrnid
[j
]);
988 if (w
== NULL
|| w
->type
!=
989 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
)
992 val
= w
->wclass
.pin
.ctrl
|
993 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE
;
995 val
= w
->wclass
.pin
.ctrl
&
996 ~HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE
;
997 if (val
== w
->wclass
.pin
.ctrl
)
999 w
->wclass
.pin
.ctrl
= val
;
1000 hdac_command(sc
, HDA_CMD_SET_PIN_WIDGET_CTRL(
1001 cad
, w
->nid
, w
->wclass
.pin
.ctrl
), cad
);
1005 case HDAC_HP_SWITCH_DEBUG
:
1006 if (hdac_hp_switch
[i
].execsense
!= -1)
1008 HDA_CMD_SET_PIN_SENSE(cad
, hdac_hp_switch
[i
].hpnid
,
1009 hdac_hp_switch
[i
].execsense
), cad
);
1010 res
= hdac_command(sc
,
1011 HDA_CMD_GET_PIN_SENSE(cad
, hdac_hp_switch
[i
].hpnid
), cad
);
1012 device_printf(sc
->dev
,
1013 "[ 0] HDA_DEBUG: Pin sense: nid=%d res=0x%08x\n",
1014 hdac_hp_switch
[i
].hpnid
, res
);
1015 for (j
= 0; hdac_hp_switch
[i
].spkrnid
[j
] != -1; j
++) {
1016 w
= hdac_widget_get(devinfo
,
1017 hdac_hp_switch
[i
].spkrnid
[j
]);
1018 if (w
== NULL
|| w
->type
!=
1019 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
)
1021 if (hdac_hp_switch
[i
].execsense
!= -1)
1023 HDA_CMD_SET_PIN_SENSE(cad
, w
->nid
,
1024 hdac_hp_switch
[i
].execsense
), cad
);
1025 res
= hdac_command(sc
,
1026 HDA_CMD_GET_PIN_SENSE(cad
, w
->nid
), cad
);
1027 device_printf(sc
->dev
,
1028 "[%2d] HDA_DEBUG: Pin sense: nid=%d res=0x%08x\n",
1029 j
+ 1, w
->nid
, res
);
1038 hdac_unsolicited_handler(struct hdac_codec
*codec
, uint32_t tag
)
1040 struct hdac_softc
*sc
;
1041 struct hdac_devinfo
*devinfo
= NULL
;
1042 device_t
*devlist
= NULL
;
1045 if (codec
== NULL
|| codec
->sc
== NULL
)
1051 device_printf(sc
->dev
, "HDA_DEBUG: Unsol Tag: 0x%08x\n", tag
);
1054 device_get_children(sc
->dev
, &devlist
, &devcount
);
1055 for (i
= 0; devlist
!= NULL
&& i
< devcount
; i
++) {
1056 devinfo
= (struct hdac_devinfo
*)device_get_ivars(devlist
[i
]);
1057 if (devinfo
!= NULL
&& devinfo
->node_type
==
1058 HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO
&&
1059 devinfo
->codec
!= NULL
&&
1060 devinfo
->codec
->cad
== codec
->cad
) {
1065 if (devlist
!= NULL
)
1066 kfree(devlist
, M_TEMP
);
1068 if (devinfo
== NULL
)
1072 case HDAC_UNSOLTAG_EVENT_HP
:
1073 hdac_hp_switch_handler(devinfo
);
1075 case HDAC_UNSOLTAG_EVENT_TEST
:
1076 device_printf(sc
->dev
, "Unsol Test!\n");
1084 hdac_stream_intr(struct hdac_softc
*sc
, struct hdac_chan
*ch
)
1086 /* XXX to be removed */
1087 #ifdef HDAC_INTR_EXTRA
1091 if (ch
->blkcnt
== 0)
1094 /* XXX to be removed */
1095 #ifdef HDAC_INTR_EXTRA
1096 res
= HDAC_READ_1(&sc
->mem
, ch
->off
+ HDAC_SDSTS
);
1099 /* XXX to be removed */
1100 #ifdef HDAC_INTR_EXTRA
1102 if (res
& (HDAC_SDSTS_DESE
| HDAC_SDSTS_FIFOE
))
1103 device_printf(sc
->dev
,
1104 "PCMDIR_%s intr triggered beyond stream boundary:"
1106 (ch
->dir
== PCMDIR_PLAY
) ? "PLAY" : "REC", res
);
1110 HDAC_WRITE_1(&sc
->mem
, ch
->off
+ HDAC_SDSTS
,
1111 HDAC_SDSTS_DESE
| HDAC_SDSTS_FIFOE
| HDAC_SDSTS_BCIS
);
1113 /* XXX to be removed */
1114 #ifdef HDAC_INTR_EXTRA
1115 if (res
& HDAC_SDSTS_BCIS
) {
1118 /* XXX to be removed */
1119 #ifdef HDAC_INTR_EXTRA
1126 /****************************************************************************
1127 * void hdac_intr_handler(void *)
1129 * Interrupt handler. Processes interrupts received from the hdac.
1130 ****************************************************************************/
1132 hdac_intr_handler(void *context
)
1134 struct hdac_softc
*sc
;
1137 struct hdac_rirb
*rirb_base
;
1140 sc
= (struct hdac_softc
*)context
;
1143 if (sc
->polling
!= 0) {
1148 /* Do we have anything to do? */
1149 intsts
= HDAC_READ_4(&sc
->mem
, HDAC_INTSTS
);
1150 if (!HDA_FLAG_MATCH(intsts
, HDAC_INTSTS_GIS
)) {
1157 /* Was this a controller interrupt? */
1158 if (HDA_FLAG_MATCH(intsts
, HDAC_INTSTS_CIS
)) {
1159 rirb_base
= (struct hdac_rirb
*)sc
->rirb_dma
.dma_vaddr
;
1160 rirbsts
= HDAC_READ_1(&sc
->mem
, HDAC_RIRBSTS
);
1161 /* Get as many responses that we can */
1162 while (HDA_FLAG_MATCH(rirbsts
, HDAC_RIRBSTS_RINTFL
)) {
1163 HDAC_WRITE_1(&sc
->mem
,
1164 HDAC_RIRBSTS
, HDAC_RIRBSTS_RINTFL
);
1165 if (hdac_rirb_flush(sc
) != 0)
1166 trigger
|= HDAC_TRIGGER_UNSOL
;
1167 rirbsts
= HDAC_READ_1(&sc
->mem
, HDAC_RIRBSTS
);
1169 /* XXX to be removed */
1170 /* Clear interrupt and exit */
1171 #ifdef HDAC_INTR_EXTRA
1172 HDAC_WRITE_4(&sc
->mem
, HDAC_INTSTS
, HDAC_INTSTS_CIS
);
1176 if (intsts
& HDAC_INTSTS_SIS_MASK
) {
1177 if ((intsts
& (1 << sc
->num_iss
)) &&
1178 hdac_stream_intr(sc
, &sc
->play
) != 0)
1179 trigger
|= HDAC_TRIGGER_PLAY
;
1180 if ((intsts
& (1 << 0)) &&
1181 hdac_stream_intr(sc
, &sc
->rec
) != 0)
1182 trigger
|= HDAC_TRIGGER_REC
;
1183 /* XXX to be removed */
1184 #ifdef HDAC_INTR_EXTRA
1185 HDAC_WRITE_4(&sc
->mem
, HDAC_INTSTS
, intsts
&
1186 HDAC_INTSTS_SIS_MASK
);
1192 if (trigger
& HDAC_TRIGGER_PLAY
)
1193 chn_intr(sc
->play
.c
);
1194 if (trigger
& HDAC_TRIGGER_REC
)
1195 chn_intr(sc
->rec
.c
);
1196 if (trigger
& HDAC_TRIGGER_UNSOL
)
1197 taskqueue_enqueue(taskqueue_swi
, &sc
->unsolq_task
);
1200 /****************************************************************************
1201 * int hdac_reset(hdac_softc *)
1203 * Reset the hdac to a quiescent and known state.
1204 ****************************************************************************/
1206 hdac_reset(struct hdac_softc
*sc
)
1212 * Stop all Streams DMA engine
1214 for (i
= 0; i
< sc
->num_iss
; i
++)
1215 HDAC_WRITE_4(&sc
->mem
, HDAC_ISDCTL(sc
, i
), 0x0);
1216 for (i
= 0; i
< sc
->num_oss
; i
++)
1217 HDAC_WRITE_4(&sc
->mem
, HDAC_OSDCTL(sc
, i
), 0x0);
1218 for (i
= 0; i
< sc
->num_bss
; i
++)
1219 HDAC_WRITE_4(&sc
->mem
, HDAC_BSDCTL(sc
, i
), 0x0);
1222 * Stop Control DMA engines.
1224 HDAC_WRITE_1(&sc
->mem
, HDAC_CORBCTL
, 0x0);
1225 HDAC_WRITE_1(&sc
->mem
, HDAC_RIRBCTL
, 0x0);
1228 * Reset DMA position buffer.
1230 HDAC_WRITE_4(&sc
->mem
, HDAC_DPIBLBASE
, 0x0);
1231 HDAC_WRITE_4(&sc
->mem
, HDAC_DPIBUBASE
, 0x0);
1234 * Reset the controller. The reset must remain asserted for
1235 * a minimum of 100us.
1237 gctl
= HDAC_READ_4(&sc
->mem
, HDAC_GCTL
);
1238 HDAC_WRITE_4(&sc
->mem
, HDAC_GCTL
, gctl
& ~HDAC_GCTL_CRST
);
1241 gctl
= HDAC_READ_4(&sc
->mem
, HDAC_GCTL
);
1242 if (!(gctl
& HDAC_GCTL_CRST
))
1246 if (gctl
& HDAC_GCTL_CRST
) {
1247 device_printf(sc
->dev
, "Unable to put hdac in reset\n");
1251 gctl
= HDAC_READ_4(&sc
->mem
, HDAC_GCTL
);
1252 HDAC_WRITE_4(&sc
->mem
, HDAC_GCTL
, gctl
| HDAC_GCTL_CRST
);
1255 gctl
= HDAC_READ_4(&sc
->mem
, HDAC_GCTL
);
1256 if (gctl
& HDAC_GCTL_CRST
)
1260 if (!(gctl
& HDAC_GCTL_CRST
)) {
1261 device_printf(sc
->dev
, "Device stuck in reset\n");
1266 * Wait for codecs to finish their own reset sequence. The delay here
1267 * should be of 250us but for some reasons, on it's not enough on my
1268 * computer. Let's use twice as much as necessary to make sure that
1269 * it's reset properly.
1277 /****************************************************************************
1278 * int hdac_get_capabilities(struct hdac_softc *);
1280 * Retreive the general capabilities of the hdac;
1281 * Number of Input Streams
1282 * Number of Output Streams
1283 * Number of bidirectional Streams
1285 * CORB and RIRB sizes
1286 ****************************************************************************/
1288 hdac_get_capabilities(struct hdac_softc
*sc
)
1291 uint8_t corbsize
, rirbsize
;
1293 gcap
= HDAC_READ_2(&sc
->mem
, HDAC_GCAP
);
1294 sc
->num_iss
= HDAC_GCAP_ISS(gcap
);
1295 sc
->num_oss
= HDAC_GCAP_OSS(gcap
);
1296 sc
->num_bss
= HDAC_GCAP_BSS(gcap
);
1298 sc
->support_64bit
= HDA_FLAG_MATCH(gcap
, HDAC_GCAP_64OK
);
1300 corbsize
= HDAC_READ_1(&sc
->mem
, HDAC_CORBSIZE
);
1301 if ((corbsize
& HDAC_CORBSIZE_CORBSZCAP_256
) ==
1302 HDAC_CORBSIZE_CORBSZCAP_256
)
1303 sc
->corb_size
= 256;
1304 else if ((corbsize
& HDAC_CORBSIZE_CORBSZCAP_16
) ==
1305 HDAC_CORBSIZE_CORBSZCAP_16
)
1307 else if ((corbsize
& HDAC_CORBSIZE_CORBSZCAP_2
) ==
1308 HDAC_CORBSIZE_CORBSZCAP_2
)
1311 device_printf(sc
->dev
, "%s: Invalid corb size (%x)\n",
1312 __func__
, corbsize
);
1316 rirbsize
= HDAC_READ_1(&sc
->mem
, HDAC_RIRBSIZE
);
1317 if ((rirbsize
& HDAC_RIRBSIZE_RIRBSZCAP_256
) ==
1318 HDAC_RIRBSIZE_RIRBSZCAP_256
)
1319 sc
->rirb_size
= 256;
1320 else if ((rirbsize
& HDAC_RIRBSIZE_RIRBSZCAP_16
) ==
1321 HDAC_RIRBSIZE_RIRBSZCAP_16
)
1323 else if ((rirbsize
& HDAC_RIRBSIZE_RIRBSZCAP_2
) ==
1324 HDAC_RIRBSIZE_RIRBSZCAP_2
)
1327 device_printf(sc
->dev
, "%s: Invalid rirb size (%x)\n",
1328 __func__
, rirbsize
);
1336 /****************************************************************************
1339 * This function is called by bus_dmamap_load when the mapping has been
1340 * established. We just record the physical address of the mapping into
1341 * the struct hdac_dma passed in.
1342 ****************************************************************************/
1344 hdac_dma_cb(void *callback_arg
, bus_dma_segment_t
*segs
, int nseg
, int error
)
1346 struct hdac_dma
*dma
;
1349 dma
= (struct hdac_dma
*)callback_arg
;
1350 dma
->dma_paddr
= segs
[0].ds_addr
;
1355 /****************************************************************************
1356 * int hdac_dma_alloc
1358 * This function allocate and setup a dma region (struct hdac_dma).
1359 * It must be freed by a corresponding hdac_dma_free.
1360 ****************************************************************************/
1362 hdac_dma_alloc(struct hdac_softc
*sc
, struct hdac_dma
*dma
, bus_size_t size
)
1368 roundsz
= roundup2(size
, HDAC_DMA_ALIGNMENT
);
1369 lowaddr
= (sc
->support_64bit
) ? BUS_SPACE_MAXADDR
:
1370 BUS_SPACE_MAXADDR_32BIT
;
1371 bzero(dma
, sizeof(*dma
));
1376 result
= bus_dma_tag_create(NULL
, /* parent */
1377 HDAC_DMA_ALIGNMENT
, /* alignment */
1379 lowaddr
, /* lowaddr */
1380 BUS_SPACE_MAXADDR
, /* highaddr */
1381 NULL
, /* filtfunc */
1382 NULL
, /* fistfuncarg */
1383 roundsz
, /* maxsize */
1385 roundsz
, /* maxsegsz */
1387 &dma
->dma_tag
); /* dmat */
1389 device_printf(sc
->dev
, "%s: bus_dma_tag_create failed (%x)\n",
1391 goto hdac_dma_alloc_fail
;
1395 * Allocate DMA memory
1397 #if 0 /* TODO: No uncacheable DMA support in DragonFly. */
1398 result
= bus_dmamem_alloc(dma
->dma_tag
, (void **)&dma
->dma_vaddr
,
1399 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
|
1400 ((sc
->nocache
!= 0) ? BUS_DMA_NOCACHE
: 0), &dma
->dma_map
);
1402 result
= bus_dmamem_alloc(dma
->dma_tag
, (void **)&dma
->dma_vaddr
,
1403 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &dma
->dma_map
);
1406 device_printf(sc
->dev
, "%s: bus_dmamem_alloc failed (%x)\n",
1408 goto hdac_dma_alloc_fail
;
1411 dma
->dma_size
= roundsz
;
1416 result
= bus_dmamap_load(dma
->dma_tag
, dma
->dma_map
,
1417 (void *)dma
->dma_vaddr
, roundsz
, hdac_dma_cb
, (void *)dma
, 0);
1418 if (result
!= 0 || dma
->dma_paddr
== 0) {
1421 device_printf(sc
->dev
, "%s: bus_dmamem_load failed (%x)\n",
1423 goto hdac_dma_alloc_fail
;
1427 device_printf(sc
->dev
, "%s: size=%ju -> roundsz=%ju\n",
1428 __func__
, (uintmax_t)size
, (uintmax_t)roundsz
);
1433 hdac_dma_alloc_fail
:
1434 hdac_dma_free(sc
, dma
);
1440 /****************************************************************************
1441 * void hdac_dma_free(struct hdac_softc *, struct hdac_dma *)
1443 * Free a struct dhac_dma that has been previously allocated via the
1444 * hdac_dma_alloc function.
1445 ****************************************************************************/
1447 hdac_dma_free(struct hdac_softc
*sc
, struct hdac_dma
*dma
)
1449 if (dma
->dma_map
!= NULL
) {
1452 bus_dmamap_sync(dma
->dma_tag
, dma
->dma_map
,
1453 BUS_DMASYNC_POSTREAD
| BUS_DMASYNC_POSTWRITE
);
1455 bus_dmamap_unload(dma
->dma_tag
, dma
->dma_map
);
1457 if (dma
->dma_vaddr
!= NULL
) {
1458 bus_dmamem_free(dma
->dma_tag
, dma
->dma_vaddr
, dma
->dma_map
);
1459 dma
->dma_vaddr
= NULL
;
1461 dma
->dma_map
= NULL
;
1462 if (dma
->dma_tag
!= NULL
) {
1463 bus_dma_tag_destroy(dma
->dma_tag
);
1464 dma
->dma_tag
= NULL
;
1469 /****************************************************************************
1470 * int hdac_mem_alloc(struct hdac_softc *)
1472 * Allocate all the bus resources necessary to speak with the physical
1474 ****************************************************************************/
1476 hdac_mem_alloc(struct hdac_softc
*sc
)
1478 struct hdac_mem
*mem
;
1481 mem
->mem_rid
= PCIR_BAR(0);
1482 mem
->mem_res
= bus_alloc_resource_any(sc
->dev
, SYS_RES_MEMORY
,
1483 &mem
->mem_rid
, RF_ACTIVE
);
1484 if (mem
->mem_res
== NULL
) {
1485 device_printf(sc
->dev
,
1486 "%s: Unable to allocate memory resource\n", __func__
);
1489 mem
->mem_tag
= rman_get_bustag(mem
->mem_res
);
1490 mem
->mem_handle
= rman_get_bushandle(mem
->mem_res
);
1495 /****************************************************************************
1496 * void hdac_mem_free(struct hdac_softc *)
1498 * Free up resources previously allocated by hdac_mem_alloc.
1499 ****************************************************************************/
1501 hdac_mem_free(struct hdac_softc
*sc
)
1503 struct hdac_mem
*mem
;
1506 if (mem
->mem_res
!= NULL
)
1507 bus_release_resource(sc
->dev
, SYS_RES_MEMORY
, mem
->mem_rid
,
1509 mem
->mem_res
= NULL
;
1512 /****************************************************************************
1513 * int hdac_irq_alloc(struct hdac_softc *)
1515 * Allocate and setup the resources necessary for interrupt handling.
1516 ****************************************************************************/
1518 hdac_irq_alloc(struct hdac_softc
*sc
)
1520 struct hdac_irq
*irq
;
1525 irq
->irq_res
= bus_alloc_resource_any(sc
->dev
, SYS_RES_IRQ
,
1526 &irq
->irq_rid
, RF_SHAREABLE
| RF_ACTIVE
);
1527 if (irq
->irq_res
== NULL
) {
1528 device_printf(sc
->dev
, "%s: Unable to allocate irq\n",
1530 goto hdac_irq_alloc_fail
;
1532 result
= snd_setup_intr(sc
->dev
, irq
->irq_res
, INTR_MPSAFE
,
1533 hdac_intr_handler
, sc
, &irq
->irq_handle
);
1535 device_printf(sc
->dev
,
1536 "%s: Unable to setup interrupt handler (%x)\n",
1538 goto hdac_irq_alloc_fail
;
1543 hdac_irq_alloc_fail
:
1549 /****************************************************************************
1550 * void hdac_irq_free(struct hdac_softc *)
1552 * Free up resources previously allocated by hdac_irq_alloc.
1553 ****************************************************************************/
1555 hdac_irq_free(struct hdac_softc
*sc
)
1557 struct hdac_irq
*irq
;
1560 if (irq
->irq_res
!= NULL
&& irq
->irq_handle
!= NULL
)
1561 bus_teardown_intr(sc
->dev
, irq
->irq_res
, irq
->irq_handle
);
1562 if (irq
->irq_res
!= NULL
)
1563 bus_release_resource(sc
->dev
, SYS_RES_IRQ
, irq
->irq_rid
,
1565 irq
->irq_handle
= NULL
;
1566 irq
->irq_res
= NULL
;
1569 /****************************************************************************
1570 * void hdac_corb_init(struct hdac_softc *)
1572 * Initialize the corb registers for operations but do not start it up yet.
1573 * The CORB engine must not be running when this function is called.
1574 ****************************************************************************/
1576 hdac_corb_init(struct hdac_softc
*sc
)
1581 /* Setup the CORB size. */
1582 switch (sc
->corb_size
) {
1584 corbsize
= HDAC_CORBSIZE_CORBSIZE(HDAC_CORBSIZE_CORBSIZE_256
);
1587 corbsize
= HDAC_CORBSIZE_CORBSIZE(HDAC_CORBSIZE_CORBSIZE_16
);
1590 corbsize
= HDAC_CORBSIZE_CORBSIZE(HDAC_CORBSIZE_CORBSIZE_2
);
1593 panic("%s: Invalid CORB size (%x)\n", __func__
, sc
->corb_size
);
1595 HDAC_WRITE_1(&sc
->mem
, HDAC_CORBSIZE
, corbsize
);
1597 /* Setup the CORB Address in the hdac */
1598 corbpaddr
= (uint64_t)sc
->corb_dma
.dma_paddr
;
1599 HDAC_WRITE_4(&sc
->mem
, HDAC_CORBLBASE
, (uint32_t)corbpaddr
);
1600 HDAC_WRITE_4(&sc
->mem
, HDAC_CORBUBASE
, (uint32_t)(corbpaddr
>> 32));
1602 /* Set the WP and RP */
1604 HDAC_WRITE_2(&sc
->mem
, HDAC_CORBWP
, sc
->corb_wp
);
1605 HDAC_WRITE_2(&sc
->mem
, HDAC_CORBRP
, HDAC_CORBRP_CORBRPRST
);
1607 * The HDA specification indicates that the CORBRPRST bit will always
1608 * read as zero. Unfortunately, it seems that at least the 82801G
1609 * doesn't reset the bit to zero, which stalls the corb engine.
1610 * manually reset the bit to zero before continuing.
1612 HDAC_WRITE_2(&sc
->mem
, HDAC_CORBRP
, 0x0);
1614 /* Enable CORB error reporting */
1616 HDAC_WRITE_1(&sc
->mem
, HDAC_CORBCTL
, HDAC_CORBCTL_CMEIE
);
1620 /****************************************************************************
1621 * void hdac_rirb_init(struct hdac_softc *)
1623 * Initialize the rirb registers for operations but do not start it up yet.
1624 * The RIRB engine must not be running when this function is called.
1625 ****************************************************************************/
1627 hdac_rirb_init(struct hdac_softc
*sc
)
1632 /* Setup the RIRB size. */
1633 switch (sc
->rirb_size
) {
1635 rirbsize
= HDAC_RIRBSIZE_RIRBSIZE(HDAC_RIRBSIZE_RIRBSIZE_256
);
1638 rirbsize
= HDAC_RIRBSIZE_RIRBSIZE(HDAC_RIRBSIZE_RIRBSIZE_16
);
1641 rirbsize
= HDAC_RIRBSIZE_RIRBSIZE(HDAC_RIRBSIZE_RIRBSIZE_2
);
1644 panic("%s: Invalid RIRB size (%x)\n", __func__
, sc
->rirb_size
);
1646 HDAC_WRITE_1(&sc
->mem
, HDAC_RIRBSIZE
, rirbsize
);
1648 /* Setup the RIRB Address in the hdac */
1649 rirbpaddr
= (uint64_t)sc
->rirb_dma
.dma_paddr
;
1650 HDAC_WRITE_4(&sc
->mem
, HDAC_RIRBLBASE
, (uint32_t)rirbpaddr
);
1651 HDAC_WRITE_4(&sc
->mem
, HDAC_RIRBUBASE
, (uint32_t)(rirbpaddr
>> 32));
1653 /* Setup the WP and RP */
1655 HDAC_WRITE_2(&sc
->mem
, HDAC_RIRBWP
, HDAC_RIRBWP_RIRBWPRST
);
1657 if (sc
->polling
== 0) {
1658 /* Setup the interrupt threshold */
1659 HDAC_WRITE_2(&sc
->mem
, HDAC_RINTCNT
, sc
->rirb_size
/ 2);
1661 /* Enable Overrun and response received reporting */
1663 HDAC_WRITE_1(&sc
->mem
, HDAC_RIRBCTL
,
1664 HDAC_RIRBCTL_RIRBOIC
| HDAC_RIRBCTL_RINTCTL
);
1666 HDAC_WRITE_1(&sc
->mem
, HDAC_RIRBCTL
, HDAC_RIRBCTL_RINTCTL
);
1672 * Make sure that the Host CPU cache doesn't contain any dirty
1673 * cache lines that falls in the rirb. If I understood correctly, it
1674 * should be sufficient to do this only once as the rirb is purely
1675 * read-only from now on.
1677 bus_dmamap_sync(sc
->rirb_dma
.dma_tag
, sc
->rirb_dma
.dma_map
,
1678 BUS_DMASYNC_PREREAD
);
1682 /****************************************************************************
1683 * void hdac_corb_start(hdac_softc *)
1685 * Startup the corb DMA engine
1686 ****************************************************************************/
1688 hdac_corb_start(struct hdac_softc
*sc
)
1692 corbctl
= HDAC_READ_1(&sc
->mem
, HDAC_CORBCTL
);
1693 corbctl
|= HDAC_CORBCTL_CORBRUN
;
1694 HDAC_WRITE_1(&sc
->mem
, HDAC_CORBCTL
, corbctl
);
1697 /****************************************************************************
1698 * void hdac_rirb_start(hdac_softc *)
1700 * Startup the rirb DMA engine
1701 ****************************************************************************/
1703 hdac_rirb_start(struct hdac_softc
*sc
)
1707 rirbctl
= HDAC_READ_1(&sc
->mem
, HDAC_RIRBCTL
);
1708 rirbctl
|= HDAC_RIRBCTL_RIRBDMAEN
;
1709 HDAC_WRITE_1(&sc
->mem
, HDAC_RIRBCTL
, rirbctl
);
1713 /****************************************************************************
1714 * void hdac_scan_codecs(struct hdac_softc *)
1716 * Scan the bus for available codecs.
1717 ****************************************************************************/
1719 hdac_scan_codecs(struct hdac_softc
*sc
)
1721 struct hdac_codec
*codec
;
1725 statests
= HDAC_READ_2(&sc
->mem
, HDAC_STATESTS
);
1726 for (i
= 0; i
< HDAC_CODEC_MAX
; i
++) {
1727 if (HDAC_STATESTS_SDIWAKE(statests
, i
)) {
1728 /* We have found a codec. */
1729 codec
= (struct hdac_codec
*)kmalloc(sizeof(*codec
),
1730 M_HDAC
, M_ZERO
| M_NOWAIT
);
1731 if (codec
== NULL
) {
1732 device_printf(sc
->dev
,
1733 "Unable to allocate memory for codec\n");
1736 codec
->commands
= NULL
;
1737 codec
->responses_received
= 0;
1738 codec
->verbs_sent
= 0;
1741 sc
->codecs
[i
] = codec
;
1742 if (hdac_probe_codec(codec
) != 0)
1746 /* All codecs have been probed, now try to attach drivers to them */
1747 /* bus_generic_attach(sc->dev); */
1750 /****************************************************************************
1751 * void hdac_probe_codec(struct hdac_softc *, int)
1753 * Probe a the given codec_id for available function groups.
1754 ****************************************************************************/
1756 hdac_probe_codec(struct hdac_codec
*codec
)
1758 struct hdac_softc
*sc
= codec
->sc
;
1759 struct hdac_devinfo
*devinfo
;
1760 uint32_t vendorid
, revisionid
, subnode
;
1764 nid_t cad
= codec
->cad
;
1767 device_printf(sc
->dev
, "HDA_DEBUG: Probing codec: %d\n", cad
);
1769 vendorid
= hdac_command(sc
,
1770 HDA_CMD_GET_PARAMETER(cad
, 0x0, HDA_PARAM_VENDOR_ID
),
1772 revisionid
= hdac_command(sc
,
1773 HDA_CMD_GET_PARAMETER(cad
, 0x0, HDA_PARAM_REVISION_ID
),
1775 subnode
= hdac_command(sc
,
1776 HDA_CMD_GET_PARAMETER(cad
, 0x0, HDA_PARAM_SUB_NODE_COUNT
),
1778 startnode
= HDA_PARAM_SUB_NODE_COUNT_START(subnode
);
1779 endnode
= startnode
+ HDA_PARAM_SUB_NODE_COUNT_TOTAL(subnode
);
1782 device_printf(sc
->dev
, "HDA_DEBUG: \tstartnode=%d endnode=%d\n",
1783 startnode
, endnode
);
1785 for (i
= startnode
; i
< endnode
; i
++) {
1786 devinfo
= hdac_probe_function(codec
, i
);
1787 if (devinfo
!= NULL
) {
1788 /* XXX Ignore other FG. */
1789 devinfo
->vendor_id
=
1790 HDA_PARAM_VENDOR_ID_VENDOR_ID(vendorid
);
1791 devinfo
->device_id
=
1792 HDA_PARAM_VENDOR_ID_DEVICE_ID(vendorid
);
1793 devinfo
->revision_id
=
1794 HDA_PARAM_REVISION_ID_REVISION_ID(revisionid
);
1795 devinfo
->stepping_id
=
1796 HDA_PARAM_REVISION_ID_STEPPING_ID(revisionid
);
1798 device_printf(sc
->dev
,
1799 "HDA_DEBUG: \tFound AFG nid=%d "
1800 "[startnode=%d endnode=%d]\n",
1801 devinfo
->nid
, startnode
, endnode
);
1808 device_printf(sc
->dev
, "HDA_DEBUG: \tAFG not found\n");
1813 static struct hdac_devinfo
*
1814 hdac_probe_function(struct hdac_codec
*codec
, nid_t nid
)
1816 struct hdac_softc
*sc
= codec
->sc
;
1817 struct hdac_devinfo
*devinfo
;
1818 uint32_t fctgrptype
;
1819 nid_t cad
= codec
->cad
;
1821 fctgrptype
= HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE(hdac_command(sc
,
1822 HDA_CMD_GET_PARAMETER(cad
, nid
, HDA_PARAM_FCT_GRP_TYPE
), cad
));
1824 /* XXX For now, ignore other FG. */
1825 if (fctgrptype
!= HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO
)
1828 devinfo
= (struct hdac_devinfo
*)kmalloc(sizeof(*devinfo
), M_HDAC
,
1830 if (devinfo
== NULL
) {
1831 device_printf(sc
->dev
, "%s: Unable to allocate ivar\n",
1837 devinfo
->node_type
= fctgrptype
;
1838 devinfo
->codec
= codec
;
1840 hdac_add_child(sc
, devinfo
);
1846 hdac_add_child(struct hdac_softc
*sc
, struct hdac_devinfo
*devinfo
)
1848 devinfo
->dev
= device_add_child(sc
->dev
, NULL
, -1);
1849 device_set_ivars(devinfo
->dev
, (void *)devinfo
);
1850 /* XXX - Print more information when booting verbose??? */
1854 hdac_widget_connection_parse(struct hdac_widget
*w
)
1856 struct hdac_softc
*sc
= w
->devinfo
->codec
->sc
;
1858 int i
, j
, max
, ents
, entnum
;
1859 nid_t cad
= w
->devinfo
->codec
->cad
;
1861 nid_t cnid
, addcnid
, prevcnid
;
1865 res
= hdac_command(sc
,
1866 HDA_CMD_GET_PARAMETER(cad
, nid
, HDA_PARAM_CONN_LIST_LENGTH
), cad
);
1868 ents
= HDA_PARAM_CONN_LIST_LENGTH_LIST_LENGTH(res
);
1873 entnum
= HDA_PARAM_CONN_LIST_LENGTH_LONG_FORM(res
) ? 2 : 4;
1874 max
= (sizeof(w
->conns
) / sizeof(w
->conns
[0])) - 1;
1877 #define CONN_RMASK(e) (1 << ((32 / (e)) - 1))
1878 #define CONN_NMASK(e) (CONN_RMASK(e) - 1)
1879 #define CONN_RESVAL(r, e, n) ((r) >> ((32 / (e)) * (n)))
1880 #define CONN_RANGE(r, e, n) (CONN_RESVAL(r, e, n) & CONN_RMASK(e))
1881 #define CONN_CNID(r, e, n) (CONN_RESVAL(r, e, n) & CONN_NMASK(e))
1883 for (i
= 0; i
< ents
; i
+= entnum
) {
1884 res
= hdac_command(sc
,
1885 HDA_CMD_GET_CONN_LIST_ENTRY(cad
, nid
, i
), cad
);
1886 for (j
= 0; j
< entnum
; j
++) {
1887 cnid
= CONN_CNID(res
, entnum
, j
);
1889 if (w
->nconns
< ents
)
1890 device_printf(sc
->dev
,
1891 "%s: nid=%d WARNING: zero cnid "
1892 "entnum=%d j=%d index=%d "
1893 "entries=%d found=%d res=0x%08x\n",
1894 __func__
, nid
, entnum
, j
, i
,
1895 ents
, w
->nconns
, res
);
1899 if (cnid
< w
->devinfo
->startnode
||
1900 cnid
>= w
->devinfo
->endnode
) {
1902 device_printf(sc
->dev
,
1903 "%s: GHOST: nid=%d j=%d "
1904 "entnum=%d index=%d res=0x%08x\n",
1905 __func__
, nid
, j
, entnum
, i
, res
);
1908 if (CONN_RANGE(res
, entnum
, j
) == 0)
1910 else if (prevcnid
== 0 || prevcnid
>= cnid
) {
1911 device_printf(sc
->dev
,
1912 "%s: WARNING: Invalid child range "
1913 "nid=%d index=%d j=%d entnum=%d "
1914 "prevcnid=%d cnid=%d res=0x%08x\n",
1915 __func__
, nid
, i
, j
, entnum
, prevcnid
,
1919 addcnid
= prevcnid
+ 1;
1920 while (addcnid
<= cnid
) {
1921 if (w
->nconns
> max
) {
1922 device_printf(sc
->dev
,
1923 "%s: nid=%d: Adding %d: "
1924 "Max connection reached! max=%d\n",
1925 __func__
, nid
, addcnid
, max
+ 1);
1928 w
->conns
[w
->nconns
++] = addcnid
++;
1936 device_printf(sc
->dev
,
1937 "HDA_DEBUG: %s: nid=%d entries=%d found=%d\n",
1938 __func__
, nid
, ents
, w
->nconns
);
1944 hdac_widget_pin_getconfig(struct hdac_widget
*w
)
1946 struct hdac_softc
*sc
;
1947 uint32_t config
, orig
, id
;
1950 sc
= w
->devinfo
->codec
->sc
;
1951 cad
= w
->devinfo
->codec
->cad
;
1953 id
= hdac_codec_id(w
->devinfo
);
1955 config
= hdac_command(sc
,
1956 HDA_CMD_GET_CONFIGURATION_DEFAULT(cad
, nid
),
1961 * XXX REWRITE!!!! Don't argue!
1963 if (id
== HDA_CODEC_ALC880
&& sc
->pci_subvendor
== LG_LW20_SUBVENDOR
) {
1966 config
&= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
;
1967 config
|= HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN
;
1970 config
&= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
;
1971 config
|= HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT
;
1976 } else if (id
== HDA_CODEC_ALC880
&&
1977 (sc
->pci_subvendor
== CLEVO_D900T_SUBVENDOR
||
1978 sc
->pci_subvendor
== ASUS_M5200_SUBVENDOR
)) {
1992 config
&= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
;
1993 config
|= HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN
;
1995 case 25: /* XXX MIC2 */
1996 config
&= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
;
1997 config
|= HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN
;
1999 case 26: /* LINE1 */
2000 config
&= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
;
2001 config
|= HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN
;
2003 case 27: /* XXX LINE2 */
2004 config
&= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
;
2005 config
|= HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN
;
2008 config
&= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
;
2009 config
|= HDA_CONFIG_DEFAULTCONF_DEVICE_CD
;
2018 } else if (id
== HDA_CODEC_ALC883
&&
2019 HDA_DEV_MATCH(ACER_ALL_SUBVENDOR
, sc
->pci_subvendor
)) {
2022 config
&= ~(HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
|
2023 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK
);
2024 config
|= (HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN
|
2025 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_FIXED
);
2028 config
&= ~(HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
|
2029 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK
);
2030 config
|= (HDA_CONFIG_DEFAULTCONF_DEVICE_CD
|
2031 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_FIXED
);
2036 } else if (id
== HDA_CODEC_CXVENICE
&& sc
->pci_subvendor
==
2037 HP_V3000_SUBVENDOR
) {
2040 config
&= ~HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK
;
2041 config
|= HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_NONE
;
2044 config
&= ~(HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
|
2045 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK
);
2046 config
|= (HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN
|
2047 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_FIXED
);
2050 config
&= ~(HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
|
2051 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK
);
2052 config
|= (HDA_CONFIG_DEFAULTCONF_DEVICE_CD
|
2053 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_FIXED
);
2058 } else if (id
== HDA_CODEC_CXWAIKIKI
&& sc
->pci_subvendor
==
2059 HP_DV5000_SUBVENDOR
) {
2063 config
&= ~HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK
;
2064 config
|= HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_NONE
;
2069 } else if (id
== HDA_CODEC_ALC861
&& sc
->pci_subvendor
==
2070 ASUS_W6F_SUBVENDOR
) {
2073 config
&= ~(HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
|
2074 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK
);
2075 config
|= (HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_OUT
|
2076 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_FIXED
);
2079 config
&= ~(HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
|
2080 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK
);
2081 config
|= (HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT
|
2082 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_JACK
);
2087 } else if (id
== HDA_CODEC_ALC861
&& sc
->pci_subvendor
==
2088 UNIWILL_9075_SUBVENDOR
) {
2091 config
&= ~(HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
|
2092 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK
);
2093 config
|= (HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT
|
2094 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_JACK
);
2099 } else if (id
== HDA_CODEC_AD1986A
&&
2100 (sc
->pci_subvendor
== ASUS_M2NPVMX_SUBVENDOR
||
2101 sc
->pci_subvendor
== ASUS_A8NVMCSM_SUBVENDOR
)) {
2104 config
&= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
;
2105 config
|= HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN
;
2108 config
&= ~HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
;
2109 config
|= HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN
;
2118 device_printf(sc
->dev
,
2119 "HDA_DEBUG: Pin config nid=%u 0x%08x -> 0x%08x\n",
2127 hdac_widget_pin_getcaps(struct hdac_widget
*w
)
2129 struct hdac_softc
*sc
;
2130 uint32_t caps
, orig
, id
;
2133 sc
= w
->devinfo
->codec
->sc
;
2134 cad
= w
->devinfo
->codec
->cad
;
2136 id
= hdac_codec_id(w
->devinfo
);
2138 caps
= hdac_command(sc
,
2139 HDA_CMD_GET_PARAMETER(cad
, nid
, HDA_PARAM_PIN_CAP
), cad
);
2144 device_printf(sc
->dev
,
2145 "HDA_DEBUG: Pin caps nid=%u 0x%08x -> 0x%08x\n",
2153 hdac_widget_pin_parse(struct hdac_widget
*w
)
2155 struct hdac_softc
*sc
= w
->devinfo
->codec
->sc
;
2156 uint32_t config
, pincap
;
2157 char *devstr
, *connstr
;
2158 nid_t cad
= w
->devinfo
->codec
->cad
;
2161 config
= hdac_widget_pin_getconfig(w
);
2162 w
->wclass
.pin
.config
= config
;
2164 pincap
= hdac_widget_pin_getcaps(w
);
2165 w
->wclass
.pin
.cap
= pincap
;
2167 w
->wclass
.pin
.ctrl
= hdac_command(sc
,
2168 HDA_CMD_GET_PIN_WIDGET_CTRL(cad
, nid
), cad
) &
2169 ~(HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE
|
2170 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE
|
2171 HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE
|
2172 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK
);
2174 if (HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap
))
2175 w
->wclass
.pin
.ctrl
|= HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE
;
2176 if (HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap
))
2177 w
->wclass
.pin
.ctrl
|= HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE
;
2178 if (HDA_PARAM_PIN_CAP_INPUT_CAP(pincap
))
2179 w
->wclass
.pin
.ctrl
|= HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE
;
2180 if (HDA_PARAM_PIN_CAP_EAPD_CAP(pincap
)) {
2181 w
->param
.eapdbtl
= hdac_command(sc
,
2182 HDA_CMD_GET_EAPD_BTL_ENABLE(cad
, nid
), cad
);
2183 w
->param
.eapdbtl
&= 0x7;
2184 w
->param
.eapdbtl
|= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD
;
2186 w
->param
.eapdbtl
= HDAC_INVALID
;
2188 switch (config
& HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
) {
2189 case HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_OUT
:
2190 devstr
= "line out";
2192 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER
:
2195 case HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT
:
2196 devstr
= "headphones out";
2198 case HDA_CONFIG_DEFAULTCONF_DEVICE_CD
:
2201 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_OUT
:
2202 devstr
= "SPDIF out";
2204 case HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_OUT
:
2205 devstr
= "digital (other) out";
2207 case HDA_CONFIG_DEFAULTCONF_DEVICE_MODEM_LINE
:
2208 devstr
= "modem, line side";
2210 case HDA_CONFIG_DEFAULTCONF_DEVICE_MODEM_HANDSET
:
2211 devstr
= "modem, handset side";
2213 case HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN
:
2216 case HDA_CONFIG_DEFAULTCONF_DEVICE_AUX
:
2219 case HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN
:
2222 case HDA_CONFIG_DEFAULTCONF_DEVICE_TELEPHONY
:
2223 devstr
= "telephony";
2225 case HDA_CONFIG_DEFAULTCONF_DEVICE_SPDIF_IN
:
2226 devstr
= "SPDIF in";
2228 case HDA_CONFIG_DEFAULTCONF_DEVICE_DIGITAL_OTHER_IN
:
2229 devstr
= "digital (other) in";
2231 case HDA_CONFIG_DEFAULTCONF_DEVICE_OTHER
:
2239 switch (config
& HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK
) {
2240 case HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_JACK
:
2243 case HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_NONE
:
2246 case HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_FIXED
:
2249 case HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_BOTH
:
2250 connstr
= "jack / fixed";
2253 connstr
= "unknown";
2257 strlcat(w
->name
, ": ", sizeof(w
->name
));
2258 strlcat(w
->name
, devstr
, sizeof(w
->name
));
2259 strlcat(w
->name
, " (", sizeof(w
->name
));
2260 strlcat(w
->name
, connstr
, sizeof(w
->name
));
2261 strlcat(w
->name
, ")", sizeof(w
->name
));
2265 hdac_widget_parse(struct hdac_widget
*w
)
2267 struct hdac_softc
*sc
= w
->devinfo
->codec
->sc
;
2270 nid_t cad
= w
->devinfo
->codec
->cad
;
2273 wcap
= hdac_command(sc
,
2274 HDA_CMD_GET_PARAMETER(cad
, nid
, HDA_PARAM_AUDIO_WIDGET_CAP
),
2276 w
->param
.widget_cap
= wcap
;
2277 w
->type
= HDA_PARAM_AUDIO_WIDGET_CAP_TYPE(wcap
);
2280 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT
:
2281 typestr
= "audio output";
2283 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT
:
2284 typestr
= "audio input";
2286 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER
:
2287 typestr
= "audio mixer";
2289 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR
:
2290 typestr
= "audio selector";
2292 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
:
2295 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_POWER_WIDGET
:
2296 typestr
= "power widget";
2298 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_VOLUME_WIDGET
:
2299 typestr
= "volume widget";
2301 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET
:
2302 typestr
= "beep widget";
2304 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_VENDOR_WIDGET
:
2305 typestr
= "vendor widget";
2308 typestr
= "unknown type";
2312 strlcpy(w
->name
, typestr
, sizeof(w
->name
));
2314 if (HDA_PARAM_AUDIO_WIDGET_CAP_POWER_CTRL(wcap
)) {
2316 HDA_CMD_SET_POWER_STATE(cad
, nid
, HDA_CMD_POWER_STATE_D0
),
2321 hdac_widget_connection_parse(w
);
2323 if (HDA_PARAM_AUDIO_WIDGET_CAP_OUT_AMP(wcap
)) {
2324 if (HDA_PARAM_AUDIO_WIDGET_CAP_AMP_OVR(wcap
))
2325 w
->param
.outamp_cap
=
2327 HDA_CMD_GET_PARAMETER(cad
, nid
,
2328 HDA_PARAM_OUTPUT_AMP_CAP
), cad
);
2330 w
->param
.outamp_cap
=
2331 w
->devinfo
->function
.audio
.outamp_cap
;
2333 w
->param
.outamp_cap
= 0;
2335 if (HDA_PARAM_AUDIO_WIDGET_CAP_IN_AMP(wcap
)) {
2336 if (HDA_PARAM_AUDIO_WIDGET_CAP_AMP_OVR(wcap
))
2337 w
->param
.inamp_cap
=
2339 HDA_CMD_GET_PARAMETER(cad
, nid
,
2340 HDA_PARAM_INPUT_AMP_CAP
), cad
);
2342 w
->param
.inamp_cap
=
2343 w
->devinfo
->function
.audio
.inamp_cap
;
2345 w
->param
.inamp_cap
= 0;
2347 if (w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT
||
2348 w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT
) {
2349 if (HDA_PARAM_AUDIO_WIDGET_CAP_FORMAT_OVR(wcap
)) {
2350 cap
= hdac_command(sc
,
2351 HDA_CMD_GET_PARAMETER(cad
, nid
,
2352 HDA_PARAM_SUPP_STREAM_FORMATS
), cad
);
2353 w
->param
.supp_stream_formats
= (cap
!= 0) ? cap
:
2354 w
->devinfo
->function
.audio
.supp_stream_formats
;
2355 cap
= hdac_command(sc
,
2356 HDA_CMD_GET_PARAMETER(cad
, nid
,
2357 HDA_PARAM_SUPP_PCM_SIZE_RATE
), cad
);
2358 w
->param
.supp_pcm_size_rate
= (cap
!= 0) ? cap
:
2359 w
->devinfo
->function
.audio
.supp_pcm_size_rate
;
2361 w
->param
.supp_stream_formats
=
2362 w
->devinfo
->function
.audio
.supp_stream_formats
;
2363 w
->param
.supp_pcm_size_rate
=
2364 w
->devinfo
->function
.audio
.supp_pcm_size_rate
;
2367 w
->param
.supp_stream_formats
= 0;
2368 w
->param
.supp_pcm_size_rate
= 0;
2371 if (w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
)
2372 hdac_widget_pin_parse(w
);
2375 static struct hdac_widget
*
2376 hdac_widget_get(struct hdac_devinfo
*devinfo
, nid_t nid
)
2378 if (devinfo
== NULL
|| devinfo
->widget
== NULL
||
2379 nid
< devinfo
->startnode
|| nid
>= devinfo
->endnode
)
2381 return (&devinfo
->widget
[nid
- devinfo
->startnode
]);
2385 hda_poll_channel(struct hdac_chan
*ch
)
2388 volatile uint32_t ptr
;
2390 if (ch
->active
== 0)
2393 sz
= ch
->blksz
* ch
->blkcnt
;
2394 if (ch
->dmapos
!= NULL
)
2395 ptr
= *(ch
->dmapos
);
2397 ptr
= HDAC_READ_4(&ch
->devinfo
->codec
->sc
->mem
,
2398 ch
->off
+ HDAC_SDLPIB
);
2401 ptr
&= ~(ch
->blksz
- 1);
2402 delta
= (sz
+ ptr
- ch
->prevptr
) % sz
;
2404 if (delta
< ch
->blksz
)
2412 #define hda_chan_active(sc) ((sc)->play.active + (sc)->rec.active)
2415 hda_poll_callback(void *arg
)
2417 struct hdac_softc
*sc
= arg
;
2424 if (sc
->polling
== 0 || hda_chan_active(sc
) == 0) {
2430 trigger
|= (hda_poll_channel(&sc
->play
) != 0) ? HDAC_TRIGGER_PLAY
: 0;
2431 trigger
|= (hda_poll_channel(&sc
->rec
)) != 0 ? HDAC_TRIGGER_REC
: 0;
2434 callout_reset(&sc
->poll_hda
, 1/*sc->poll_ticks*/,
2435 hda_poll_callback
, sc
);
2439 if (trigger
& HDAC_TRIGGER_PLAY
)
2440 chn_intr(sc
->play
.c
);
2441 if (trigger
& HDAC_TRIGGER_REC
)
2442 chn_intr(sc
->rec
.c
);
2446 hdac_rirb_flush(struct hdac_softc
*sc
)
2448 struct hdac_rirb
*rirb_base
, *rirb
;
2449 struct hdac_codec
*codec
;
2450 struct hdac_command_list
*commands
;
2456 rirb_base
= (struct hdac_rirb
*)sc
->rirb_dma
.dma_vaddr
;
2457 rirbwp
= HDAC_READ_1(&sc
->mem
, HDAC_RIRBWP
);
2459 bus_dmamap_sync(sc
->rirb_dma
.dma_tag
, sc
->rirb_dma
.dma_map
,
2460 BUS_DMASYNC_POSTREAD
);
2464 while (sc
->rirb_rp
!= rirbwp
) {
2466 sc
->rirb_rp
%= sc
->rirb_size
;
2467 rirb
= &rirb_base
[sc
->rirb_rp
];
2468 cad
= HDAC_RIRB_RESPONSE_EX_SDATA_IN(rirb
->response_ex
);
2469 if (cad
< 0 || cad
>= HDAC_CODEC_MAX
||
2470 sc
->codecs
[cad
] == NULL
)
2472 resp
= rirb
->response
;
2473 codec
= sc
->codecs
[cad
];
2474 commands
= codec
->commands
;
2475 if (rirb
->response_ex
& HDAC_RIRB_RESPONSE_EX_UNSOLICITED
) {
2476 sc
->unsolq
[sc
->unsolq_wp
++] = (cad
<< 16) |
2477 ((resp
>> 26) & 0xffff);
2478 sc
->unsolq_wp
%= HDAC_UNSOLQ_MAX
;
2479 } else if (commands
!= NULL
&& commands
->num_commands
> 0 &&
2480 codec
->responses_received
< commands
->num_commands
)
2481 commands
->responses
[codec
->responses_received
++] =
2490 hdac_unsolq_flush(struct hdac_softc
*sc
)
2496 if (sc
->unsolq_st
== HDAC_UNSOLQ_READY
) {
2497 sc
->unsolq_st
= HDAC_UNSOLQ_BUSY
;
2498 while (sc
->unsolq_rp
!= sc
->unsolq_wp
) {
2499 cad
= sc
->unsolq
[sc
->unsolq_rp
] >> 16;
2500 tag
= sc
->unsolq
[sc
->unsolq_rp
++] & 0xffff;
2501 sc
->unsolq_rp
%= HDAC_UNSOLQ_MAX
;
2502 hdac_unsolicited_handler(sc
->codecs
[cad
], tag
);
2505 sc
->unsolq_st
= HDAC_UNSOLQ_READY
;
2512 hdac_poll_callback(void *arg
)
2514 struct hdac_softc
*sc
= arg
;
2519 if (sc
->polling
== 0 || sc
->poll_ival
== 0) {
2523 if (hdac_rirb_flush(sc
) != 0)
2524 hdac_unsolq_flush(sc
);
2525 callout_reset(&sc
->poll_hdac
, sc
->poll_ival
, hdac_poll_callback
, sc
);
2530 hdac_stream_stop(struct hdac_chan
*ch
)
2532 struct hdac_softc
*sc
= ch
->devinfo
->codec
->sc
;
2535 ctl
= HDAC_READ_1(&sc
->mem
, ch
->off
+ HDAC_SDCTL0
);
2536 ctl
&= ~(HDAC_SDCTL_IOCE
| HDAC_SDCTL_FEIE
| HDAC_SDCTL_DEIE
|
2538 HDAC_WRITE_1(&sc
->mem
, ch
->off
+ HDAC_SDCTL0
, ctl
);
2542 if (sc
->polling
!= 0) {
2545 if (hda_chan_active(sc
) == 0) {
2546 callout_stop(&sc
->poll_hda
);
2549 if (sc
->play
.active
!= 0)
2553 pollticks
= ((uint64_t)hz
* ch
->blksz
) /
2554 ((uint64_t)sndbuf_getbps(ch
->b
) *
2555 sndbuf_getspd(ch
->b
));
2559 if (pollticks
< 1) {
2561 device_printf(sc
->dev
,
2562 "%s: pollticks=%d < 1 !\n",
2563 __func__
, pollticks
);
2567 if (pollticks
> sc
->poll_ticks
) {
2569 device_printf(sc
->dev
,
2570 "%s: pollticks %d -> %d\n",
2571 __func__
, sc
->poll_ticks
,
2574 sc
->poll_ticks
= pollticks
;
2575 callout_reset(&sc
->poll_hda
, 1,
2576 hda_poll_callback
, sc
);
2580 ctl
= HDAC_READ_4(&sc
->mem
, HDAC_INTCTL
);
2581 ctl
&= ~(1 << (ch
->off
>> 5));
2582 HDAC_WRITE_4(&sc
->mem
, HDAC_INTCTL
, ctl
);
2587 hdac_stream_start(struct hdac_chan
*ch
)
2589 struct hdac_softc
*sc
= ch
->devinfo
->codec
->sc
;
2592 if (sc
->polling
!= 0) {
2595 pollticks
= ((uint64_t)hz
* ch
->blksz
) /
2596 ((uint64_t)sndbuf_getbps(ch
->b
) * sndbuf_getspd(ch
->b
));
2600 if (pollticks
< 1) {
2602 device_printf(sc
->dev
,
2603 "%s: pollticks=%d < 1 !\n",
2604 __func__
, pollticks
);
2608 if (hda_chan_active(sc
) == 0 || pollticks
< sc
->poll_ticks
) {
2610 if (hda_chan_active(sc
) == 0) {
2611 device_printf(sc
->dev
,
2612 "%s: pollticks=%d\n",
2613 __func__
, pollticks
);
2615 device_printf(sc
->dev
,
2616 "%s: pollticks %d -> %d\n",
2617 __func__
, sc
->poll_ticks
,
2621 sc
->poll_ticks
= pollticks
;
2622 callout_reset(&sc
->poll_hda
, 1, hda_poll_callback
,
2625 ctl
= HDAC_READ_1(&sc
->mem
, ch
->off
+ HDAC_SDCTL0
);
2626 ctl
|= HDAC_SDCTL_RUN
;
2628 ctl
= HDAC_READ_4(&sc
->mem
, HDAC_INTCTL
);
2629 ctl
|= 1 << (ch
->off
>> 5);
2630 HDAC_WRITE_4(&sc
->mem
, HDAC_INTCTL
, ctl
);
2631 ctl
= HDAC_READ_1(&sc
->mem
, ch
->off
+ HDAC_SDCTL0
);
2632 ctl
|= HDAC_SDCTL_IOCE
| HDAC_SDCTL_FEIE
| HDAC_SDCTL_DEIE
|
2635 HDAC_WRITE_1(&sc
->mem
, ch
->off
+ HDAC_SDCTL0
, ctl
);
2641 hdac_stream_reset(struct hdac_chan
*ch
)
2643 struct hdac_softc
*sc
= ch
->devinfo
->codec
->sc
;
2648 ctl
= HDAC_READ_1(&sc
->mem
, ch
->off
+ HDAC_SDCTL0
);
2649 ctl
|= HDAC_SDCTL_SRST
;
2650 HDAC_WRITE_1(&sc
->mem
, ch
->off
+ HDAC_SDCTL0
, ctl
);
2652 ctl
= HDAC_READ_1(&sc
->mem
, ch
->off
+ HDAC_SDCTL0
);
2653 if (ctl
& HDAC_SDCTL_SRST
)
2657 if (!(ctl
& HDAC_SDCTL_SRST
)) {
2658 device_printf(sc
->dev
, "timeout in reset\n");
2660 ctl
&= ~HDAC_SDCTL_SRST
;
2661 HDAC_WRITE_1(&sc
->mem
, ch
->off
+ HDAC_SDCTL0
, ctl
);
2664 ctl
= HDAC_READ_1(&sc
->mem
, ch
->off
+ HDAC_SDCTL0
);
2665 if (!(ctl
& HDAC_SDCTL_SRST
))
2669 if (ctl
& HDAC_SDCTL_SRST
)
2670 device_printf(sc
->dev
, "can't reset!\n");
2674 hdac_stream_setid(struct hdac_chan
*ch
)
2676 struct hdac_softc
*sc
= ch
->devinfo
->codec
->sc
;
2679 ctl
= HDAC_READ_1(&sc
->mem
, ch
->off
+ HDAC_SDCTL2
);
2680 ctl
&= ~HDAC_SDCTL2_STRM_MASK
;
2681 ctl
|= ch
->sid
<< HDAC_SDCTL2_STRM_SHIFT
;
2682 HDAC_WRITE_1(&sc
->mem
, ch
->off
+ HDAC_SDCTL2
, ctl
);
2686 hdac_bdl_setup(struct hdac_chan
*ch
)
2688 struct hdac_softc
*sc
= ch
->devinfo
->codec
->sc
;
2689 struct hdac_bdle
*bdle
;
2691 uint32_t blksz
, blkcnt
;
2694 addr
= (uint64_t)sndbuf_getbufaddr(ch
->b
);
2695 bdle
= (struct hdac_bdle
*)ch
->bdl_dma
.dma_vaddr
;
2697 if (sc
->polling
!= 0) {
2698 blksz
= ch
->blksz
* ch
->blkcnt
;
2702 blkcnt
= ch
->blkcnt
;
2705 for (i
= 0; i
< blkcnt
; i
++, bdle
++) {
2706 bdle
->addrl
= (uint32_t)addr
;
2707 bdle
->addrh
= (uint32_t)(addr
>> 32);
2709 bdle
->ioc
= 1 ^ sc
->polling
;
2713 HDAC_WRITE_4(&sc
->mem
, ch
->off
+ HDAC_SDCBL
, blksz
* blkcnt
);
2714 HDAC_WRITE_2(&sc
->mem
, ch
->off
+ HDAC_SDLVI
, blkcnt
- 1);
2715 addr
= ch
->bdl_dma
.dma_paddr
;
2716 HDAC_WRITE_4(&sc
->mem
, ch
->off
+ HDAC_SDBDPL
, (uint32_t)addr
);
2717 HDAC_WRITE_4(&sc
->mem
, ch
->off
+ HDAC_SDBDPU
, (uint32_t)(addr
>> 32));
2718 if (ch
->dmapos
!= NULL
&&
2719 !(HDAC_READ_4(&sc
->mem
, HDAC_DPIBLBASE
) & 0x00000001)) {
2720 addr
= sc
->pos_dma
.dma_paddr
;
2721 HDAC_WRITE_4(&sc
->mem
, HDAC_DPIBLBASE
,
2722 ((uint32_t)addr
& HDAC_DPLBASE_DPLBASE_MASK
) | 0x00000001);
2723 HDAC_WRITE_4(&sc
->mem
, HDAC_DPIBUBASE
, (uint32_t)(addr
>> 32));
2728 hdac_bdl_alloc(struct hdac_chan
*ch
)
2730 struct hdac_softc
*sc
= ch
->devinfo
->codec
->sc
;
2733 rc
= hdac_dma_alloc(sc
, &ch
->bdl_dma
,
2734 sizeof(struct hdac_bdle
) * HDA_BDL_MAX
);
2736 device_printf(sc
->dev
, "can't alloc bdl\n");
2744 hdac_audio_ctl_amp_set_internal(struct hdac_softc
*sc
, nid_t cad
, nid_t nid
,
2745 int index
, int lmute
, int rmute
,
2746 int left
, int right
, int dir
)
2753 if (left
!= right
|| lmute
!= rmute
) {
2754 v
= (1 << (15 - dir
)) | (1 << 13) | (index
<< 8) |
2755 (lmute
<< 7) | left
;
2757 HDA_CMD_SET_AMP_GAIN_MUTE(cad
, nid
, v
), cad
);
2758 v
= (1 << (15 - dir
)) | (1 << 12) | (index
<< 8) |
2759 (rmute
<< 7) | right
;
2761 v
= (1 << (15 - dir
)) | (3 << 12) | (index
<< 8) |
2762 (lmute
<< 7) | left
;
2765 HDA_CMD_SET_AMP_GAIN_MUTE(cad
, nid
, v
), cad
);
2769 hdac_audio_ctl_amp_set(struct hdac_audio_ctl
*ctl
, uint32_t mute
,
2770 int left
, int right
)
2772 struct hdac_softc
*sc
;
2776 if (ctl
== NULL
|| ctl
->widget
== NULL
||
2777 ctl
->widget
->devinfo
== NULL
||
2778 ctl
->widget
->devinfo
->codec
== NULL
||
2779 ctl
->widget
->devinfo
->codec
->sc
== NULL
)
2782 sc
= ctl
->widget
->devinfo
->codec
->sc
;
2783 cad
= ctl
->widget
->devinfo
->codec
->cad
;
2784 nid
= ctl
->widget
->nid
;
2786 if (mute
== HDA_AMP_MUTE_DEFAULT
) {
2787 lmute
= HDA_AMP_LEFT_MUTED(ctl
->muted
);
2788 rmute
= HDA_AMP_RIGHT_MUTED(ctl
->muted
);
2790 lmute
= HDA_AMP_LEFT_MUTED(mute
);
2791 rmute
= HDA_AMP_RIGHT_MUTED(mute
);
2794 if (ctl
->dir
& HDA_CTL_OUT
)
2795 hdac_audio_ctl_amp_set_internal(sc
, cad
, nid
, ctl
->index
,
2796 lmute
, rmute
, left
, right
, 0);
2797 if (ctl
->dir
& HDA_CTL_IN
)
2798 hdac_audio_ctl_amp_set_internal(sc
, cad
, nid
, ctl
->index
,
2799 lmute
, rmute
, left
, right
, 1);
2805 hdac_widget_connection_select(struct hdac_widget
*w
, uint8_t index
)
2807 if (w
== NULL
|| w
->nconns
< 1 || index
> (w
->nconns
- 1))
2809 hdac_command(w
->devinfo
->codec
->sc
,
2810 HDA_CMD_SET_CONNECTION_SELECT_CONTROL(w
->devinfo
->codec
->cad
,
2811 w
->nid
, index
), w
->devinfo
->codec
->cad
);
2816 /****************************************************************************
2817 * uint32_t hdac_command_sendone_internal
2819 * Wrapper function that sends only one command to a given codec
2820 ****************************************************************************/
2822 hdac_command_sendone_internal(struct hdac_softc
*sc
, uint32_t verb
, nid_t cad
)
2824 struct hdac_command_list cl
;
2825 uint32_t response
= HDAC_INVALID
;
2827 if (!hdac_lockowned(sc
))
2828 device_printf(sc
->dev
, "WARNING!!!! mtx not owned!!!!\n");
2829 cl
.num_commands
= 1;
2831 cl
.responses
= &response
;
2833 hdac_command_send_internal(sc
, &cl
, cad
);
2838 /****************************************************************************
2839 * hdac_command_send_internal
2841 * Send a command list to the codec via the corb. We queue as much verbs as
2842 * we can and msleep on the codec. When the interrupt get the responses
2843 * back from the rirb, it will wake us up so we can queue the remaining verbs
2845 ****************************************************************************/
2847 hdac_command_send_internal(struct hdac_softc
*sc
,
2848 struct hdac_command_list
*commands
, nid_t cad
)
2850 struct hdac_codec
*codec
;
2855 struct hdac_rirb
*rirb_base
;
2857 if (sc
== NULL
|| sc
->codecs
[cad
] == NULL
|| commands
== NULL
||
2858 commands
->num_commands
< 1)
2861 codec
= sc
->codecs
[cad
];
2862 codec
->commands
= commands
;
2863 codec
->responses_received
= 0;
2864 codec
->verbs_sent
= 0;
2865 corb
= (uint32_t *)sc
->corb_dma
.dma_vaddr
;
2866 rirb_base
= (struct hdac_rirb
*)sc
->rirb_dma
.dma_vaddr
;
2869 if (codec
->verbs_sent
!= commands
->num_commands
) {
2870 /* Queue as many verbs as possible */
2871 corbrp
= HDAC_READ_2(&sc
->mem
, HDAC_CORBRP
);
2873 bus_dmamap_sync(sc
->corb_dma
.dma_tag
,
2874 sc
->corb_dma
.dma_map
, BUS_DMASYNC_PREWRITE
);
2876 while (codec
->verbs_sent
!= commands
->num_commands
&&
2877 ((sc
->corb_wp
+ 1) % sc
->corb_size
) != corbrp
) {
2879 sc
->corb_wp
%= sc
->corb_size
;
2881 commands
->verbs
[codec
->verbs_sent
++];
2884 /* Send the verbs to the codecs */
2886 bus_dmamap_sync(sc
->corb_dma
.dma_tag
,
2887 sc
->corb_dma
.dma_map
, BUS_DMASYNC_POSTWRITE
);
2889 HDAC_WRITE_2(&sc
->mem
, HDAC_CORBWP
, sc
->corb_wp
);
2893 while (hdac_rirb_flush(sc
) == 0 && --timeout
)
2895 } while ((codec
->verbs_sent
!= commands
->num_commands
||
2896 codec
->responses_received
!= commands
->num_commands
) && --retry
);
2899 device_printf(sc
->dev
,
2900 "%s: TIMEOUT numcmd=%d, sent=%d, received=%d\n",
2901 __func__
, commands
->num_commands
, codec
->verbs_sent
,
2902 codec
->responses_received
);
2904 codec
->commands
= NULL
;
2905 codec
->responses_received
= 0;
2906 codec
->verbs_sent
= 0;
2908 hdac_unsolq_flush(sc
);
2912 /****************************************************************************
2914 ****************************************************************************/
2916 /****************************************************************************
2917 * int hdac_probe(device_t)
2919 * Probe for the presence of an hdac. If none is found, check for a generic
2920 * match using the subclass of the device.
2921 ****************************************************************************/
2923 hdac_probe(device_t dev
)
2927 uint16_t class, subclass
;
2930 model
= (uint32_t)pci_get_device(dev
) << 16;
2931 model
|= (uint32_t)pci_get_vendor(dev
) & 0x0000ffff;
2932 class = pci_get_class(dev
);
2933 subclass
= pci_get_subclass(dev
);
2935 bzero(desc
, sizeof(desc
));
2937 for (i
= 0; i
< HDAC_DEVICES_LEN
; i
++) {
2938 if (hdac_devices
[i
].model
== model
) {
2939 strlcpy(desc
, hdac_devices
[i
].desc
, sizeof(desc
));
2940 result
= BUS_PROBE_DEFAULT
;
2943 if (HDA_DEV_MATCH(hdac_devices
[i
].model
, model
) &&
2944 class == PCIC_MULTIMEDIA
&&
2945 subclass
== PCIS_MULTIMEDIA_HDA
) {
2946 strlcpy(desc
, hdac_devices
[i
].desc
, sizeof(desc
));
2947 result
= BUS_PROBE_GENERIC
;
2951 if (result
== ENXIO
&& class == PCIC_MULTIMEDIA
&&
2952 subclass
== PCIS_MULTIMEDIA_HDA
) {
2953 strlcpy(desc
, "Generic", sizeof(desc
));
2954 result
= BUS_PROBE_GENERIC
;
2956 if (result
!= ENXIO
) {
2957 strlcat(desc
, " High Definition Audio Controller",
2959 device_set_desc_copy(dev
, desc
);
2966 hdac_channel_init(kobj_t obj
, void *data
, struct snd_dbuf
*b
,
2967 struct pcm_channel
*c
, int dir
)
2969 struct hdac_devinfo
*devinfo
= data
;
2970 struct hdac_softc
*sc
= devinfo
->codec
->sc
;
2971 struct hdac_chan
*ch
;
2974 if (dir
== PCMDIR_PLAY
) {
2976 ch
->off
= (sc
->num_iss
+ devinfo
->function
.audio
.playcnt
) << 5;
2977 devinfo
->function
.audio
.playcnt
++;
2980 ch
->off
= devinfo
->function
.audio
.reccnt
<< 5;
2981 devinfo
->function
.audio
.reccnt
++;
2983 if (devinfo
->function
.audio
.quirks
& HDA_QUIRK_FIXEDRATE
) {
2984 ch
->caps
.minspeed
= ch
->caps
.maxspeed
= 48000;
2985 ch
->pcmrates
[0] = 48000;
2986 ch
->pcmrates
[1] = 0;
2988 if (sc
->pos_dma
.dma_vaddr
!= NULL
)
2989 ch
->dmapos
= (uint32_t *)(sc
->pos_dma
.dma_vaddr
+
2990 (sc
->streamcnt
* 8));
2993 ch
->sid
= ++sc
->streamcnt
;
2997 ch
->devinfo
= devinfo
;
2998 ch
->blksz
= sc
->chan_size
/ sc
->chan_blkcnt
;
2999 ch
->blkcnt
= sc
->chan_blkcnt
;
3002 if (hdac_bdl_alloc(ch
) != 0) {
3007 if (sndbuf_alloc(ch
->b
, sc
->chan_dmat
, sc
->chan_size
) != 0)
3010 HDAC_DMA_ATTR(sc
, sndbuf_getbuf(ch
->b
), sndbuf_getmaxsize(ch
->b
),
3017 hdac_channel_free(kobj_t obj
, void *data
)
3019 struct hdac_softc
*sc
;
3020 struct hdac_chan
*ch
;
3022 ch
= (struct hdac_chan
*)data
;
3023 sc
= (ch
!= NULL
&& ch
->devinfo
!= NULL
&& ch
->devinfo
->codec
!= NULL
) ?
3024 ch
->devinfo
->codec
->sc
: NULL
;
3025 if (ch
!= NULL
&& sc
!= NULL
) {
3026 HDAC_DMA_ATTR(sc
, sndbuf_getbuf(ch
->b
),
3027 sndbuf_getmaxsize(ch
->b
), PAT_WRITE_BACK
);
3034 hdac_channel_setformat(kobj_t obj
, void *data
, uint32_t format
)
3036 struct hdac_chan
*ch
= data
;
3039 for (i
= 0; ch
->caps
.fmtlist
[i
] != 0; i
++) {
3040 if (format
== ch
->caps
.fmtlist
[i
]) {
3050 hdac_channel_setspeed(kobj_t obj
, void *data
, uint32_t speed
)
3052 struct hdac_chan
*ch
= data
;
3053 uint32_t spd
= 0, threshold
;
3056 for (i
= 0; ch
->pcmrates
[i
] != 0; i
++) {
3057 spd
= ch
->pcmrates
[i
];
3058 threshold
= spd
+ ((ch
->pcmrates
[i
+ 1] != 0) ?
3059 ((ch
->pcmrates
[i
+ 1] - spd
) >> 1) : 0);
3060 if (speed
< threshold
)
3064 if (spd
== 0) /* impossible */
3073 hdac_stream_setup(struct hdac_chan
*ch
)
3075 struct hdac_softc
*sc
= ch
->devinfo
->codec
->sc
;
3077 nid_t cad
= ch
->devinfo
->codec
->cad
;
3081 if (ch
->fmt
& AFMT_S16_LE
)
3082 fmt
|= ch
->bit16
<< 4;
3083 else if (ch
->fmt
& AFMT_S32_LE
)
3084 fmt
|= ch
->bit32
<< 4;
3088 for (i
= 0; i
< HDA_RATE_TAB_LEN
; i
++) {
3089 if (hda_rate_tab
[i
].valid
&& ch
->spd
== hda_rate_tab
[i
].rate
) {
3090 fmt
|= hda_rate_tab
[i
].base
;
3091 fmt
|= hda_rate_tab
[i
].mul
;
3092 fmt
|= hda_rate_tab
[i
].div
;
3097 if (ch
->fmt
& AFMT_STEREO
)
3100 HDAC_WRITE_2(&sc
->mem
, ch
->off
+ HDAC_SDFMT
, fmt
);
3102 for (i
= 0; ch
->io
[i
] != -1; i
++) {
3104 device_printf(sc
->dev
,
3105 "HDA_DEBUG: PCMDIR_%s: Stream setup nid=%d "
3107 (ch
->dir
== PCMDIR_PLAY
) ? "PLAY" : "REC",
3111 HDA_CMD_SET_CONV_FMT(cad
, ch
->io
[i
], fmt
), cad
);
3113 HDA_CMD_SET_CONV_STREAM_CHAN(cad
, ch
->io
[i
],
3114 ch
->sid
<< 4), cad
);
3119 hdac_channel_setfragments(kobj_t obj
, void *data
,
3120 uint32_t blksz
, uint32_t blkcnt
)
3122 struct hdac_chan
*ch
= data
;
3123 struct hdac_softc
*sc
= ch
->devinfo
->codec
->sc
;
3125 blksz
&= HDA_BLK_ALIGN
;
3127 if (blksz
> (sndbuf_getmaxsize(ch
->b
) / HDA_BDL_MIN
))
3128 blksz
= sndbuf_getmaxsize(ch
->b
) / HDA_BDL_MIN
;
3129 if (blksz
< HDA_BLK_MIN
)
3130 blksz
= HDA_BLK_MIN
;
3131 if (blkcnt
> HDA_BDL_MAX
)
3132 blkcnt
= HDA_BDL_MAX
;
3133 if (blkcnt
< HDA_BDL_MIN
)
3134 blkcnt
= HDA_BDL_MIN
;
3136 while ((blksz
* blkcnt
) > sndbuf_getmaxsize(ch
->b
)) {
3137 if ((blkcnt
>> 1) >= HDA_BDL_MIN
)
3139 else if ((blksz
>> 1) >= HDA_BLK_MIN
)
3145 if ((sndbuf_getblksz(ch
->b
) != blksz
||
3146 sndbuf_getblkcnt(ch
->b
) != blkcnt
) &&
3147 sndbuf_resize(ch
->b
, blkcnt
, blksz
) != 0)
3148 device_printf(sc
->dev
, "%s: failed blksz=%u blkcnt=%u\n",
3149 __func__
, blksz
, blkcnt
);
3151 ch
->blksz
= sndbuf_getblksz(ch
->b
);
3152 ch
->blkcnt
= sndbuf_getblkcnt(ch
->b
);
3158 hdac_channel_setblocksize(kobj_t obj
, void *data
, uint32_t blksz
)
3160 struct hdac_chan
*ch
= data
;
3161 struct hdac_softc
*sc
= ch
->devinfo
->codec
->sc
;
3163 hdac_channel_setfragments(obj
, data
, blksz
, sc
->chan_blkcnt
);
3169 hdac_channel_stop(struct hdac_softc
*sc
, struct hdac_chan
*ch
)
3171 struct hdac_devinfo
*devinfo
= ch
->devinfo
;
3172 nid_t cad
= devinfo
->codec
->cad
;
3175 hdac_stream_stop(ch
);
3177 for (i
= 0; ch
->io
[i
] != -1; i
++) {
3179 HDA_CMD_SET_CONV_STREAM_CHAN(cad
, ch
->io
[i
],
3185 hdac_channel_start(struct hdac_softc
*sc
, struct hdac_chan
*ch
)
3189 hdac_stream_stop(ch
);
3190 hdac_stream_reset(ch
);
3192 hdac_stream_setid(ch
);
3193 hdac_stream_setup(ch
);
3194 hdac_stream_start(ch
);
3198 hdac_channel_trigger(kobj_t obj
, void *data
, int go
)
3200 struct hdac_chan
*ch
= data
;
3201 struct hdac_softc
*sc
= ch
->devinfo
->codec
->sc
;
3203 if (!(go
== PCMTRIG_START
|| go
== PCMTRIG_STOP
|| go
== PCMTRIG_ABORT
))
3209 hdac_channel_start(sc
, ch
);
3213 hdac_channel_stop(sc
, ch
);
3224 hdac_channel_getptr(kobj_t obj
, void *data
)
3226 struct hdac_chan
*ch
= data
;
3227 struct hdac_softc
*sc
= ch
->devinfo
->codec
->sc
;
3231 if (sc
->polling
!= 0)
3233 else if (ch
->dmapos
!= NULL
)
3234 ptr
= *(ch
->dmapos
);
3236 ptr
= HDAC_READ_4(&sc
->mem
, ch
->off
+ HDAC_SDLPIB
);
3240 * Round to available space and force 128 bytes aligment.
3242 ptr
%= ch
->blksz
* ch
->blkcnt
;
3243 ptr
&= HDA_BLK_ALIGN
;
3248 static struct pcmchan_caps
*
3249 hdac_channel_getcaps(kobj_t obj
, void *data
)
3251 return (&((struct hdac_chan
*)data
)->caps
);
3254 static kobj_method_t hdac_channel_methods
[] = {
3255 KOBJMETHOD(channel_init
, hdac_channel_init
),
3256 KOBJMETHOD(channel_free
, hdac_channel_free
),
3257 KOBJMETHOD(channel_setformat
, hdac_channel_setformat
),
3258 KOBJMETHOD(channel_setspeed
, hdac_channel_setspeed
),
3259 KOBJMETHOD(channel_setblocksize
, hdac_channel_setblocksize
),
3260 KOBJMETHOD(channel_trigger
, hdac_channel_trigger
),
3261 KOBJMETHOD(channel_getptr
, hdac_channel_getptr
),
3262 KOBJMETHOD(channel_getcaps
, hdac_channel_getcaps
),
3265 CHANNEL_DECLARE(hdac_channel
);
3268 hdac_jack_poll_callback(void *arg
)
3270 struct hdac_devinfo
*devinfo
= arg
;
3271 struct hdac_softc
*sc
;
3273 if (devinfo
== NULL
|| devinfo
->codec
== NULL
||
3274 devinfo
->codec
->sc
== NULL
)
3276 sc
= devinfo
->codec
->sc
;
3278 if (sc
->poll_ival
== 0) {
3282 hdac_hp_switch_handler(devinfo
);
3283 callout_reset(&sc
->poll_jack
, sc
->poll_ival
,
3284 hdac_jack_poll_callback
, devinfo
);
3289 hdac_audio_ctl_ossmixer_init(struct snd_mixer
*m
)
3291 struct hdac_devinfo
*devinfo
= mix_getdevinfo(m
);
3292 struct hdac_softc
*sc
= devinfo
->codec
->sc
;
3293 struct hdac_widget
*w
, *cw
;
3294 struct hdac_audio_ctl
*ctl
;
3295 uint32_t mask
, recmask
, id
;
3296 int i
, j
, softpcmvol
;
3304 id
= hdac_codec_id(devinfo
);
3305 cad
= devinfo
->codec
->cad
;
3306 for (i
= 0; i
< HDAC_HP_SWITCH_LEN
; i
++) {
3307 if (!(HDA_DEV_MATCH(hdac_hp_switch
[i
].model
,
3308 sc
->pci_subvendor
) && hdac_hp_switch
[i
].id
== id
))
3310 w
= hdac_widget_get(devinfo
, hdac_hp_switch
[i
].hpnid
);
3311 if (w
== NULL
|| w
->enable
== 0 || w
->type
!=
3312 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
)
3314 if (hdac_hp_switch
[i
].polling
!= 0)
3315 callout_reset(&sc
->poll_jack
, 1,
3316 hdac_jack_poll_callback
, devinfo
);
3317 else if (HDA_PARAM_AUDIO_WIDGET_CAP_UNSOL_CAP(w
->param
.widget_cap
))
3319 HDA_CMD_SET_UNSOLICITED_RESPONSE(cad
, w
->nid
,
3320 HDA_CMD_SET_UNSOLICITED_RESPONSE_ENABLE
|
3321 HDAC_UNSOLTAG_EVENT_HP
), cad
);
3324 hdac_hp_switch_handler(devinfo
);
3326 device_printf(sc
->dev
,
3327 "HDA_DEBUG: Enabling headphone/speaker "
3328 "audio routing switching:\n");
3329 device_printf(sc
->dev
,
3330 "HDA_DEBUG: \tindex=%d nid=%d "
3331 "pci_subvendor=0x%08x "
3332 "codec=0x%08x [%s]\n",
3333 i
, w
->nid
, sc
->pci_subvendor
, id
,
3334 (hdac_hp_switch
[i
].polling
!= 0) ? "POLL" :
3339 for (i
= 0; i
< HDAC_EAPD_SWITCH_LEN
; i
++) {
3340 if (!(HDA_DEV_MATCH(hdac_eapd_switch
[i
].model
,
3341 sc
->pci_subvendor
) &&
3342 hdac_eapd_switch
[i
].id
== id
))
3344 w
= hdac_widget_get(devinfo
, hdac_eapd_switch
[i
].eapdnid
);
3345 if (w
== NULL
|| w
->enable
== 0)
3347 if (w
->type
!= HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
||
3348 w
->param
.eapdbtl
== HDAC_INVALID
)
3350 mask
|= SOUND_MASK_OGAIN
;
3354 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
3355 w
= hdac_widget_get(devinfo
, i
);
3356 if (w
== NULL
|| w
->enable
== 0)
3358 mask
|= w
->ctlflags
;
3359 if (!(w
->pflags
& HDA_ADC_RECSEL
))
3361 for (j
= 0; j
< w
->nconns
; j
++) {
3362 cw
= hdac_widget_get(devinfo
, w
->conns
[j
]);
3363 if (cw
== NULL
|| cw
->enable
== 0)
3365 recmask
|= cw
->ctlflags
;
3369 if (!(mask
& SOUND_MASK_PCM
)) {
3371 mask
|= SOUND_MASK_PCM
;
3373 softpcmvol
= (devinfo
->function
.audio
.quirks
&
3374 HDA_QUIRK_SOFTPCMVOL
) ? 1 : 0;
3378 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) != NULL
) {
3379 if (ctl
->widget
== NULL
|| ctl
->enable
== 0)
3381 if (!(ctl
->ossmask
& SOUND_MASK_PCM
))
3387 if (softpcmvol
== 1 || ctl
== NULL
) {
3388 pcm_setflags(sc
->dev
, pcm_getflags(sc
->dev
) | SD_F_SOFTPCMVOL
);
3390 device_printf(sc
->dev
,
3391 "HDA_DEBUG: %s Soft PCM volume\n",
3393 "Forcing" : "Enabling");
3397 * XXX Temporary quirk for STAC9220, until the parser
3400 if (id
== HDA_CODEC_STAC9220
) {
3401 mask
|= SOUND_MASK_VOLUME
;
3402 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) !=
3404 if (ctl
->widget
== NULL
|| ctl
->enable
== 0)
3406 if (ctl
->widget
->nid
== 11 && ctl
->index
== 0) {
3407 ctl
->ossmask
= SOUND_MASK_VOLUME
;
3408 ctl
->ossval
= 100 | (100 << 8);
3410 ctl
->ossmask
&= ~SOUND_MASK_VOLUME
;
3412 } else if (id
== HDA_CODEC_STAC9221
) {
3413 mask
|= SOUND_MASK_VOLUME
;
3414 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) !=
3416 if (ctl
->widget
== NULL
)
3418 if (ctl
->widget
->type
==
3419 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT
&&
3420 ctl
->index
== 0 && (ctl
->widget
->nid
== 2 ||
3421 ctl
->widget
->enable
!= 0)) {
3423 ctl
->ossmask
= SOUND_MASK_VOLUME
;
3424 ctl
->ossval
= 100 | (100 << 8);
3425 } else if (ctl
->enable
== 0)
3428 ctl
->ossmask
&= ~SOUND_MASK_VOLUME
;
3431 mix_setparentchild(m
, SOUND_MIXER_VOLUME
,
3433 if (!(mask
& SOUND_MASK_VOLUME
))
3434 mix_setrealdev(m
, SOUND_MIXER_VOLUME
,
3436 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) !=
3438 if (ctl
->widget
== NULL
|| ctl
->enable
== 0)
3440 if (!HDA_FLAG_MATCH(ctl
->ossmask
,
3441 SOUND_MASK_VOLUME
| SOUND_MASK_PCM
))
3443 if (!(ctl
->mute
== 1 && ctl
->step
== 0))
3449 recmask
&= ~(SOUND_MASK_PCM
| SOUND_MASK_RECLEV
| SOUND_MASK_SPEAKER
|
3450 SOUND_MASK_BASS
| SOUND_MASK_TREBLE
| SOUND_MASK_IGAIN
|
3452 recmask
&= (1 << SOUND_MIXER_NRDEVICES
) - 1;
3453 mask
&= (1 << SOUND_MIXER_NRDEVICES
) - 1;
3455 mix_setrecdevs(m
, recmask
);
3456 mix_setdevs(m
, mask
);
3464 hdac_audio_ctl_ossmixer_set(struct snd_mixer
*m
, unsigned dev
,
3465 unsigned left
, unsigned right
)
3467 struct hdac_devinfo
*devinfo
= mix_getdevinfo(m
);
3468 struct hdac_softc
*sc
= devinfo
->codec
->sc
;
3469 struct hdac_widget
*w
;
3470 struct hdac_audio_ctl
*ctl
;
3472 int lvol
, rvol
, mlvol
, mrvol
;
3476 if (dev
== SOUND_MIXER_OGAIN
) {
3478 /*if (left != right || !(left == 0 || left == 1)) {
3482 id
= hdac_codec_id(devinfo
);
3483 for (i
= 0; i
< HDAC_EAPD_SWITCH_LEN
; i
++) {
3484 if (HDA_DEV_MATCH(hdac_eapd_switch
[i
].model
,
3485 sc
->pci_subvendor
) &&
3486 hdac_eapd_switch
[i
].id
== id
)
3489 if (i
>= HDAC_EAPD_SWITCH_LEN
) {
3493 w
= hdac_widget_get(devinfo
, hdac_eapd_switch
[i
].eapdnid
);
3495 w
->type
!= HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
||
3496 w
->param
.eapdbtl
== HDAC_INVALID
) {
3500 orig
= w
->param
.eapdbtl
;
3502 w
->param
.eapdbtl
&= ~HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD
;
3504 w
->param
.eapdbtl
|= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD
;
3505 if (orig
!= w
->param
.eapdbtl
) {
3508 if (hdac_eapd_switch
[i
].hp_switch
!= 0)
3509 hdac_hp_switch_handler(devinfo
);
3510 val
= w
->param
.eapdbtl
;
3511 if (devinfo
->function
.audio
.quirks
& HDA_QUIRK_EAPDINV
)
3512 val
^= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD
;
3514 HDA_CMD_SET_EAPD_BTL_ENABLE(devinfo
->codec
->cad
,
3515 w
->nid
, val
), devinfo
->codec
->cad
);
3518 return (left
| (left
<< 8));
3520 if (dev
== SOUND_MIXER_VOLUME
)
3521 devinfo
->function
.audio
.mvol
= left
| (right
<< 8);
3523 mlvol
= devinfo
->function
.audio
.mvol
& 0x7f;
3524 mrvol
= (devinfo
->function
.audio
.mvol
>> 8) & 0x7f;
3529 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) != NULL
) {
3530 if (ctl
->widget
== NULL
|| ctl
->enable
== 0 ||
3531 !(ctl
->ossmask
& (1 << dev
)))
3534 case SOUND_MIXER_VOLUME
:
3535 lvol
= ((ctl
->ossval
& 0x7f) * left
) / 100;
3536 lvol
= (lvol
* ctl
->step
) / 100;
3537 rvol
= (((ctl
->ossval
>> 8) & 0x7f) * right
) / 100;
3538 rvol
= (rvol
* ctl
->step
) / 100;
3541 if (ctl
->ossmask
& SOUND_MASK_VOLUME
) {
3542 lvol
= (left
* mlvol
) / 100;
3543 lvol
= (lvol
* ctl
->step
) / 100;
3544 rvol
= (right
* mrvol
) / 100;
3545 rvol
= (rvol
* ctl
->step
) / 100;
3547 lvol
= (left
* ctl
->step
) / 100;
3548 rvol
= (right
* ctl
->step
) / 100;
3550 ctl
->ossval
= left
| (right
<< 8);
3554 if (ctl
->step
< 1) {
3555 mute
|= (left
== 0) ? HDA_AMP_MUTE_LEFT
:
3556 (ctl
->muted
& HDA_AMP_MUTE_LEFT
);
3557 mute
|= (right
== 0) ? HDA_AMP_MUTE_RIGHT
:
3558 (ctl
->muted
& HDA_AMP_MUTE_RIGHT
);
3560 mute
|= (lvol
== 0) ? HDA_AMP_MUTE_LEFT
:
3561 (ctl
->muted
& HDA_AMP_MUTE_LEFT
);
3562 mute
|= (rvol
== 0) ? HDA_AMP_MUTE_RIGHT
:
3563 (ctl
->muted
& HDA_AMP_MUTE_RIGHT
);
3565 hdac_audio_ctl_amp_set(ctl
, mute
, lvol
, rvol
);
3569 return (left
| (right
<< 8));
3573 hdac_audio_ctl_ossmixer_setrecsrc(struct snd_mixer
*m
, uint32_t src
)
3575 struct hdac_devinfo
*devinfo
= mix_getdevinfo(m
);
3576 struct hdac_widget
*w
, *cw
;
3577 struct hdac_softc
*sc
= devinfo
->codec
->sc
;
3578 uint32_t ret
= src
, target
;
3582 for (i
= 0; i
< SOUND_MIXER_NRDEVICES
; i
++) {
3583 if (src
& (1 << i
)) {
3591 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
3592 w
= hdac_widget_get(devinfo
, i
);
3593 if (w
== NULL
|| w
->enable
== 0)
3595 if (!(w
->pflags
& HDA_ADC_RECSEL
))
3597 for (j
= 0; j
< w
->nconns
; j
++) {
3598 cw
= hdac_widget_get(devinfo
, w
->conns
[j
]);
3599 if (cw
== NULL
|| cw
->enable
== 0)
3601 if ((target
== SOUND_MASK_VOLUME
&&
3603 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER
) ||
3604 (target
!= SOUND_MASK_VOLUME
&&
3606 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER
))
3608 if (cw
->ctlflags
& target
) {
3609 if (!(w
->pflags
& HDA_ADC_LOCKED
))
3610 hdac_widget_connection_select(w
, j
);
3622 static kobj_method_t hdac_audio_ctl_ossmixer_methods
[] = {
3623 KOBJMETHOD(mixer_init
, hdac_audio_ctl_ossmixer_init
),
3624 KOBJMETHOD(mixer_set
, hdac_audio_ctl_ossmixer_set
),
3625 KOBJMETHOD(mixer_setrecsrc
, hdac_audio_ctl_ossmixer_setrecsrc
),
3628 MIXER_DECLARE(hdac_audio_ctl_ossmixer
);
3631 hdac_unsolq_task(void *context
, int pending
)
3633 struct hdac_softc
*sc
;
3635 sc
= (struct hdac_softc
*)context
;
3638 hdac_unsolq_flush(sc
);
3642 /****************************************************************************
3643 * int hdac_attach(device_t)
3645 * Attach the device into the kernel. Interrupts usually won't be enabled
3646 * when this function is called. Setup everything that doesn't require
3647 * interrupts and defer probing of codecs until interrupts are enabled.
3648 ****************************************************************************/
3650 hdac_attach(device_t dev
)
3652 struct hdac_softc
*sc
;
3658 sc
= kmalloc(sizeof(*sc
), M_DEVBUF
, M_WAITOK
| M_ZERO
);
3659 sc
->lock
= snd_mtxcreate(device_get_nameunit(dev
), HDAC_MTX_NAME
);
3661 sc
->pci_subvendor
= (uint32_t)pci_get_subdevice(sc
->dev
) << 16;
3662 sc
->pci_subvendor
|= (uint32_t)pci_get_subvendor(sc
->dev
) & 0x0000ffff;
3663 vendor
= pci_get_vendor(dev
);
3665 if (sc
->pci_subvendor
== HP_NX6325_SUBVENDORX
) {
3666 /* Screw nx6325 - subdevice/subvendor swapped */
3667 sc
->pci_subvendor
= HP_NX6325_SUBVENDOR
;
3670 callout_init(&sc
->poll_hda
);
3671 callout_init(&sc
->poll_hdac
);
3672 callout_init(&sc
->poll_jack
);
3674 TASK_INIT(&sc
->unsolq_task
, 0, hdac_unsolq_task
, sc
);
3677 sc
->poll_ival
= HDAC_POLL_INTERVAL
;
3678 if (resource_int_value(device_get_name(dev
),
3679 device_get_unit(dev
), "polling", &i
) == 0 && i
!= 0)
3684 sc
->chan_size
= pcm_getbuffersize(dev
,
3685 HDA_BUFSZ_MIN
, HDA_BUFSZ_DEFAULT
, HDA_BUFSZ_MAX
);
3687 if (resource_int_value(device_get_name(dev
),
3688 device_get_unit(dev
), "blocksize", &i
) == 0 && i
> 0) {
3690 if (i
< HDA_BLK_MIN
)
3692 sc
->chan_blkcnt
= sc
->chan_size
/ i
;
3694 while (sc
->chan_blkcnt
>> i
)
3696 sc
->chan_blkcnt
= 1 << (i
- 1);
3697 if (sc
->chan_blkcnt
< HDA_BDL_MIN
)
3698 sc
->chan_blkcnt
= HDA_BDL_MIN
;
3699 else if (sc
->chan_blkcnt
> HDA_BDL_MAX
)
3700 sc
->chan_blkcnt
= HDA_BDL_MAX
;
3702 sc
->chan_blkcnt
= HDA_BDL_DEFAULT
;
3704 result
= bus_dma_tag_create(NULL
, /* parent */
3705 HDAC_DMA_ALIGNMENT
, /* alignment */
3707 BUS_SPACE_MAXADDR_32BIT
, /* lowaddr */
3708 BUS_SPACE_MAXADDR
, /* highaddr */
3709 NULL
, /* filtfunc */
3710 NULL
, /* fistfuncarg */
3711 sc
->chan_size
, /* maxsize */
3713 sc
->chan_size
, /* maxsegsz */
3715 &sc
->chan_dmat
); /* dmat */
3717 device_printf(dev
, "%s: bus_dma_tag_create failed (%x)\n",
3719 snd_mtxfree(sc
->lock
);
3720 kfree(sc
, M_DEVBUF
);
3726 for (i
= 0; i
< HDAC_CODEC_MAX
; i
++)
3727 sc
->codecs
[i
] = NULL
;
3729 pci_enable_busmaster(dev
);
3731 if (vendor
== INTEL_VENDORID
) {
3733 v
= pci_read_config(dev
, 0x44, 1);
3734 pci_write_config(dev
, 0x44, v
& 0xf8, 1);
3736 device_printf(dev
, "TCSEL: 0x%02d -> 0x%02d\n", v
,
3737 pci_read_config(dev
, 0x44, 1));
3741 #if 0 /* TODO: No uncacheable DMA support in DragonFly. */
3744 if (resource_int_value(device_get_name(dev
),
3745 device_get_unit(dev
), "snoop", &i
) == 0 && i
!= 0) {
3750 * Try to enable PCIe snoop to avoid messing around with
3751 * uncacheable DMA attribute. Since PCIe snoop register
3752 * config is pretty much vendor specific, there are no
3753 * general solutions on how to enable it, forcing us (even
3754 * Microsoft) to enable uncacheable or write combined DMA
3757 * http://msdn2.microsoft.com/en-us/library/ms790324.aspx
3759 for (i
= 0; i
< HDAC_PCIESNOOP_LEN
; i
++) {
3760 if (hdac_pcie_snoop
[i
].vendor
!= vendor
)
3763 if (hdac_pcie_snoop
[i
].reg
== 0x00)
3765 v
= pci_read_config(dev
, hdac_pcie_snoop
[i
].reg
, 1);
3766 if ((v
& hdac_pcie_snoop
[i
].enable
) ==
3767 hdac_pcie_snoop
[i
].enable
)
3769 v
&= hdac_pcie_snoop
[i
].mask
;
3770 v
|= hdac_pcie_snoop
[i
].enable
;
3771 pci_write_config(dev
, hdac_pcie_snoop
[i
].reg
, v
, 1);
3772 v
= pci_read_config(dev
, hdac_pcie_snoop
[i
].reg
, 1);
3773 if ((v
& hdac_pcie_snoop
[i
].enable
) !=
3774 hdac_pcie_snoop
[i
].enable
) {
3777 "WARNING: Failed to enable PCIe "
3780 #if 0 /* TODO: No uncacheable DMA support in DragonFly. */
3786 #if 0 /* TODO: No uncacheable DMA support in DragonFly. */
3791 device_printf(dev
, "DMA Coherency: %s / vendor=0x%04x\n",
3792 (sc
->nocache
== 0) ? "PCIe snoop" : "Uncacheable", vendor
);
3795 /* Allocate resources */
3796 result
= hdac_mem_alloc(sc
);
3798 goto hdac_attach_fail
;
3799 result
= hdac_irq_alloc(sc
);
3801 goto hdac_attach_fail
;
3803 /* Get Capabilities */
3804 result
= hdac_get_capabilities(sc
);
3806 goto hdac_attach_fail
;
3808 /* Allocate CORB and RIRB dma memory */
3809 result
= hdac_dma_alloc(sc
, &sc
->corb_dma
,
3810 sc
->corb_size
* sizeof(uint32_t));
3812 goto hdac_attach_fail
;
3813 result
= hdac_dma_alloc(sc
, &sc
->rirb_dma
,
3814 sc
->rirb_size
* sizeof(struct hdac_rirb
));
3816 goto hdac_attach_fail
;
3818 /* Quiesce everything */
3821 /* Initialize the CORB and RIRB */
3825 /* Defer remaining of initialization until interrupts are enabled */
3826 sc
->intrhook
.ich_func
= hdac_attach2
;
3827 sc
->intrhook
.ich_arg
= (void *)sc
;
3828 if (cold
== 0 || config_intrhook_establish(&sc
->intrhook
) != 0) {
3829 sc
->intrhook
.ich_func
= NULL
;
3830 hdac_attach2((void *)sc
);
3837 hdac_dma_free(sc
, &sc
->rirb_dma
);
3838 hdac_dma_free(sc
, &sc
->corb_dma
);
3840 snd_mtxfree(sc
->lock
);
3841 kfree(sc
, M_DEVBUF
);
3847 hdac_audio_parse(struct hdac_devinfo
*devinfo
)
3849 struct hdac_softc
*sc
= devinfo
->codec
->sc
;
3850 struct hdac_widget
*w
;
3855 cad
= devinfo
->codec
->cad
;
3859 HDA_CMD_SET_POWER_STATE(cad
, nid
, HDA_CMD_POWER_STATE_D0
), cad
);
3863 res
= hdac_command(sc
,
3864 HDA_CMD_GET_PARAMETER(cad
, nid
, HDA_PARAM_SUB_NODE_COUNT
), cad
);
3866 devinfo
->nodecnt
= HDA_PARAM_SUB_NODE_COUNT_TOTAL(res
);
3867 devinfo
->startnode
= HDA_PARAM_SUB_NODE_COUNT_START(res
);
3868 devinfo
->endnode
= devinfo
->startnode
+ devinfo
->nodecnt
;
3870 res
= hdac_command(sc
,
3871 HDA_CMD_GET_PARAMETER(cad
, nid
, HDA_PARAM_GPIO_COUNT
), cad
);
3872 devinfo
->function
.audio
.gpio
= res
;
3875 device_printf(sc
->dev
, " Vendor: 0x%08x\n",
3876 devinfo
->vendor_id
);
3877 device_printf(sc
->dev
, " Device: 0x%08x\n",
3878 devinfo
->device_id
);
3879 device_printf(sc
->dev
, " Revision: 0x%08x\n",
3880 devinfo
->revision_id
);
3881 device_printf(sc
->dev
, " Stepping: 0x%08x\n",
3882 devinfo
->stepping_id
);
3883 device_printf(sc
->dev
, "PCI Subvendor: 0x%08x\n",
3885 device_printf(sc
->dev
, " Nodes: start=%d "
3886 "endnode=%d total=%d\n",
3887 devinfo
->startnode
, devinfo
->endnode
, devinfo
->nodecnt
);
3888 device_printf(sc
->dev
, " CORB size: %d\n", sc
->corb_size
);
3889 device_printf(sc
->dev
, " RIRB size: %d\n", sc
->rirb_size
);
3890 device_printf(sc
->dev
, " Streams: ISS=%d OSS=%d BSS=%d\n",
3891 sc
->num_iss
, sc
->num_oss
, sc
->num_bss
);
3892 device_printf(sc
->dev
, " GPIO: 0x%08x\n",
3893 devinfo
->function
.audio
.gpio
);
3894 device_printf(sc
->dev
, " NumGPIO=%d NumGPO=%d "
3895 "NumGPI=%d GPIWake=%d GPIUnsol=%d\n",
3896 HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo
->function
.audio
.gpio
),
3897 HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo
->function
.audio
.gpio
),
3898 HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo
->function
.audio
.gpio
),
3899 HDA_PARAM_GPIO_COUNT_GPI_WAKE(devinfo
->function
.audio
.gpio
),
3900 HDA_PARAM_GPIO_COUNT_GPI_UNSOL(devinfo
->function
.audio
.gpio
));
3903 res
= hdac_command(sc
,
3904 HDA_CMD_GET_PARAMETER(cad
, nid
, HDA_PARAM_SUPP_STREAM_FORMATS
),
3906 devinfo
->function
.audio
.supp_stream_formats
= res
;
3908 res
= hdac_command(sc
,
3909 HDA_CMD_GET_PARAMETER(cad
, nid
, HDA_PARAM_SUPP_PCM_SIZE_RATE
),
3911 devinfo
->function
.audio
.supp_pcm_size_rate
= res
;
3913 res
= hdac_command(sc
,
3914 HDA_CMD_GET_PARAMETER(cad
, nid
, HDA_PARAM_OUTPUT_AMP_CAP
),
3916 devinfo
->function
.audio
.outamp_cap
= res
;
3918 res
= hdac_command(sc
,
3919 HDA_CMD_GET_PARAMETER(cad
, nid
, HDA_PARAM_INPUT_AMP_CAP
),
3921 devinfo
->function
.audio
.inamp_cap
= res
;
3923 if (devinfo
->nodecnt
> 0)
3924 devinfo
->widget
= (struct hdac_widget
*)kmalloc(
3925 sizeof(*(devinfo
->widget
)) * devinfo
->nodecnt
, M_HDAC
,
3928 devinfo
->widget
= NULL
;
3930 if (devinfo
->widget
== NULL
) {
3931 device_printf(sc
->dev
, "unable to allocate widgets!\n");
3932 devinfo
->endnode
= devinfo
->startnode
;
3933 devinfo
->nodecnt
= 0;
3937 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
3938 w
= hdac_widget_get(devinfo
, i
);
3940 device_printf(sc
->dev
, "Ghost widget! nid=%d!\n", i
);
3942 w
->devinfo
= devinfo
;
3948 w
->param
.eapdbtl
= HDAC_INVALID
;
3949 hdac_widget_parse(w
);
3955 hdac_audio_ctl_parse(struct hdac_devinfo
*devinfo
)
3957 struct hdac_softc
*sc
= devinfo
->codec
->sc
;
3958 struct hdac_audio_ctl
*ctls
;
3959 struct hdac_widget
*w
, *cw
;
3960 int i
, j
, cnt
, max
, ocap
, icap
;
3961 int mute
, offset
, step
, size
;
3963 /* XXX This is redundant */
3965 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
3966 w
= hdac_widget_get(devinfo
, i
);
3967 if (w
== NULL
|| w
->enable
== 0)
3969 if (w
->param
.outamp_cap
!= 0)
3971 if (w
->param
.inamp_cap
!= 0) {
3973 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR
:
3974 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER
:
3975 for (j
= 0; j
< w
->nconns
; j
++) {
3976 cw
= hdac_widget_get(devinfo
,
3978 if (cw
== NULL
|| cw
->enable
== 0)
3990 devinfo
->function
.audio
.ctlcnt
= max
;
3995 ctls
= (struct hdac_audio_ctl
*)kmalloc(
3996 sizeof(*ctls
) * max
, M_HDAC
, M_ZERO
| M_NOWAIT
);
4000 device_printf(sc
->dev
, "unable to allocate ctls!\n");
4001 devinfo
->function
.audio
.ctlcnt
= 0;
4006 for (i
= devinfo
->startnode
; cnt
< max
&& i
< devinfo
->endnode
; i
++) {
4008 device_printf(sc
->dev
, "%s: Ctl overflow!\n",
4012 w
= hdac_widget_get(devinfo
, i
);
4013 if (w
== NULL
|| w
->enable
== 0)
4015 ocap
= w
->param
.outamp_cap
;
4016 icap
= w
->param
.inamp_cap
;
4018 mute
= HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(ocap
);
4019 step
= HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(ocap
);
4020 size
= HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(ocap
);
4021 offset
= HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(ocap
);
4022 /*if (offset > step) {
4024 device_printf(sc->dev,
4025 "HDA_DEBUG: BUGGY outamp: nid=%d "
4026 "[offset=%d > step=%d]\n",
4027 w->nid, offset, step);
4031 ctls
[cnt
].enable
= 1;
4032 ctls
[cnt
].widget
= w
;
4033 ctls
[cnt
].mute
= mute
;
4034 ctls
[cnt
].step
= step
;
4035 ctls
[cnt
].size
= size
;
4036 ctls
[cnt
].offset
= offset
;
4037 ctls
[cnt
].left
= offset
;
4038 ctls
[cnt
].right
= offset
;
4039 ctls
[cnt
++].dir
= HDA_CTL_OUT
;
4043 mute
= HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(icap
);
4044 step
= HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(icap
);
4045 size
= HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(icap
);
4046 offset
= HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(icap
);
4047 /*if (offset > step) {
4049 device_printf(sc->dev,
4050 "HDA_DEBUG: BUGGY inamp: nid=%d "
4051 "[offset=%d > step=%d]\n",
4052 w->nid, offset, step);
4057 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR
:
4058 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER
:
4059 for (j
= 0; j
< w
->nconns
; j
++) {
4061 device_printf(sc
->dev
,
4062 "%s: Ctl overflow!\n",
4066 cw
= hdac_widget_get(devinfo
,
4068 if (cw
== NULL
|| cw
->enable
== 0)
4070 ctls
[cnt
].enable
= 1;
4071 ctls
[cnt
].widget
= w
;
4072 ctls
[cnt
].childwidget
= cw
;
4073 ctls
[cnt
].index
= j
;
4074 ctls
[cnt
].mute
= mute
;
4075 ctls
[cnt
].step
= step
;
4076 ctls
[cnt
].size
= size
;
4077 ctls
[cnt
].offset
= offset
;
4078 ctls
[cnt
].left
= offset
;
4079 ctls
[cnt
].right
= offset
;
4080 ctls
[cnt
++].dir
= HDA_CTL_IN
;
4085 device_printf(sc
->dev
,
4086 "%s: Ctl overflow!\n",
4090 ctls
[cnt
].enable
= 1;
4091 ctls
[cnt
].widget
= w
;
4092 ctls
[cnt
].mute
= mute
;
4093 ctls
[cnt
].step
= step
;
4094 ctls
[cnt
].size
= size
;
4095 ctls
[cnt
].offset
= offset
;
4096 ctls
[cnt
].left
= offset
;
4097 ctls
[cnt
].right
= offset
;
4098 ctls
[cnt
++].dir
= HDA_CTL_IN
;
4104 devinfo
->function
.audio
.ctl
= ctls
;
4107 static const struct {
4110 uint32_t set
, unset
;
4113 * XXX Force stereo quirk. Monoural recording / playback
4114 * on few codecs (especially ALC880) seems broken or
4115 * perhaps unsupported.
4117 { HDA_MATCH_ALL
, HDA_MATCH_ALL
,
4118 HDA_QUIRK_FORCESTEREO
| HDA_QUIRK_IVREF
, 0 },
4119 { ACER_ALL_SUBVENDOR
, HDA_MATCH_ALL
,
4120 HDA_QUIRK_GPIO0
, 0 },
4121 { ASUS_M5200_SUBVENDOR
, HDA_CODEC_ALC880
,
4122 HDA_QUIRK_GPIO0
, 0 },
4123 { ASUS_A7M_SUBVENDOR
, HDA_CODEC_ALC880
,
4124 HDA_QUIRK_GPIO0
, 0 },
4125 { ASUS_A7T_SUBVENDOR
, HDA_CODEC_ALC882
,
4126 HDA_QUIRK_GPIO0
, 0 },
4127 { ASUS_W2J_SUBVENDOR
, HDA_CODEC_ALC882
,
4128 HDA_QUIRK_GPIO0
, 0 },
4129 { ASUS_U5F_SUBVENDOR
, HDA_CODEC_AD1986A
,
4130 HDA_QUIRK_EAPDINV
, 0 },
4131 { ASUS_A8JC_SUBVENDOR
, HDA_CODEC_AD1986A
,
4132 HDA_QUIRK_EAPDINV
, 0 },
4133 { ASUS_F3JC_SUBVENDOR
, HDA_CODEC_ALC861
,
4134 HDA_QUIRK_OVREF
, 0 },
4135 { ASUS_W6F_SUBVENDOR
, HDA_CODEC_ALC861
,
4136 HDA_QUIRK_OVREF
, 0 },
4137 { UNIWILL_9075_SUBVENDOR
, HDA_CODEC_ALC861
,
4138 HDA_QUIRK_OVREF
, 0 },
4139 /*{ ASUS_M2N_SUBVENDOR, HDA_CODEC_AD1988,
4140 HDA_QUIRK_IVREF80, HDA_QUIRK_IVREF50 | HDA_QUIRK_IVREF100 },*/
4141 { MEDION_MD95257_SUBVENDOR
, HDA_CODEC_ALC880
,
4142 HDA_QUIRK_GPIO1
, 0 },
4143 { LENOVO_3KN100_SUBVENDOR
, HDA_CODEC_AD1986A
,
4144 HDA_QUIRK_EAPDINV
, 0 },
4145 { SAMSUNG_Q1_SUBVENDOR
, HDA_CODEC_AD1986A
,
4146 HDA_QUIRK_EAPDINV
, 0 },
4147 { APPLE_INTEL_MAC
, HDA_CODEC_STAC9221
,
4148 HDA_QUIRK_GPIO0
| HDA_QUIRK_GPIO1
, 0 },
4149 { HDA_MATCH_ALL
, HDA_CODEC_AD1988
,
4150 HDA_QUIRK_IVREF80
, HDA_QUIRK_IVREF50
| HDA_QUIRK_IVREF100
},
4151 { HDA_MATCH_ALL
, HDA_CODEC_AD1988B
,
4152 HDA_QUIRK_IVREF80
, HDA_QUIRK_IVREF50
| HDA_QUIRK_IVREF100
},
4153 { HDA_MATCH_ALL
, HDA_CODEC_CXVENICE
,
4154 0, HDA_QUIRK_FORCESTEREO
},
4155 { HDA_MATCH_ALL
, HDA_CODEC_STACXXXX
,
4156 HDA_QUIRK_SOFTPCMVOL
, 0 }
4158 #define HDAC_QUIRKS_LEN (sizeof(hdac_quirks) / sizeof(hdac_quirks[0]))
4161 hdac_vendor_patch_parse(struct hdac_devinfo
*devinfo
)
4163 struct hdac_widget
*w
;
4164 struct hdac_audio_ctl
*ctl
;
4165 uint32_t id
, subvendor
;
4168 id
= hdac_codec_id(devinfo
);
4169 subvendor
= devinfo
->codec
->sc
->pci_subvendor
;
4174 for (i
= 0; i
< HDAC_QUIRKS_LEN
; i
++) {
4175 if (!(HDA_DEV_MATCH(hdac_quirks
[i
].model
, subvendor
) &&
4176 HDA_DEV_MATCH(hdac_quirks
[i
].id
, id
)))
4178 if (hdac_quirks
[i
].set
!= 0)
4179 devinfo
->function
.audio
.quirks
|=
4181 if (hdac_quirks
[i
].unset
!= 0)
4182 devinfo
->function
.audio
.quirks
&=
4183 ~(hdac_quirks
[i
].unset
);
4187 case HDA_CODEC_ALC260
:
4188 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
4189 w
= hdac_widget_get(devinfo
, i
);
4190 if (w
== NULL
|| w
->enable
== 0)
4193 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT
)
4198 if (subvendor
== HP_XW4300_SUBVENDOR
) {
4199 ctl
= hdac_audio_ctl_amp_get(devinfo
, 16, 0, 1);
4200 if (ctl
!= NULL
&& ctl
->widget
!= NULL
) {
4201 ctl
->ossmask
= SOUND_MASK_SPEAKER
;
4202 ctl
->widget
->ctlflags
|= SOUND_MASK_SPEAKER
;
4204 ctl
= hdac_audio_ctl_amp_get(devinfo
, 17, 0, 1);
4205 if (ctl
!= NULL
&& ctl
->widget
!= NULL
) {
4206 ctl
->ossmask
= SOUND_MASK_SPEAKER
;
4207 ctl
->widget
->ctlflags
|= SOUND_MASK_SPEAKER
;
4209 } else if (subvendor
== HP_3010_SUBVENDOR
) {
4210 ctl
= hdac_audio_ctl_amp_get(devinfo
, 17, 0, 1);
4211 if (ctl
!= NULL
&& ctl
->widget
!= NULL
) {
4212 ctl
->ossmask
= SOUND_MASK_SPEAKER
;
4213 ctl
->widget
->ctlflags
|= SOUND_MASK_SPEAKER
;
4215 ctl
= hdac_audio_ctl_amp_get(devinfo
, 21, 0, 1);
4216 if (ctl
!= NULL
&& ctl
->widget
!= NULL
) {
4217 ctl
->ossmask
= SOUND_MASK_SPEAKER
;
4218 ctl
->widget
->ctlflags
|= SOUND_MASK_SPEAKER
;
4222 case HDA_CODEC_ALC861
:
4223 ctl
= hdac_audio_ctl_amp_get(devinfo
, 21, 2, 1);
4225 ctl
->muted
= HDA_AMP_MUTE_ALL
;
4227 case HDA_CODEC_ALC880
:
4228 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
4229 w
= hdac_widget_get(devinfo
, i
);
4230 if (w
== NULL
|| w
->enable
== 0)
4233 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT
&&
4234 w
->nid
!= 9 && w
->nid
!= 29) {
4236 } else if (w
->type
!=
4237 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET
&&
4240 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET
;
4241 w
->param
.widget_cap
&=
4242 ~HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_MASK
;
4243 w
->param
.widget_cap
|=
4244 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET
<<
4245 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_SHIFT
;
4246 strlcpy(w
->name
, "beep widget", sizeof(w
->name
));
4250 case HDA_CODEC_ALC883
:
4252 * nid: 24/25 = External (jack) or Internal (fixed) Mic.
4253 * Clear vref cap for jack connectivity.
4255 w
= hdac_widget_get(devinfo
, 24);
4256 if (w
!= NULL
&& w
->enable
!= 0 && w
->type
==
4257 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
&&
4258 (w
->wclass
.pin
.config
&
4259 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK
) ==
4260 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_JACK
)
4261 w
->wclass
.pin
.cap
&= ~(
4262 HDA_PARAM_PIN_CAP_VREF_CTRL_100_MASK
|
4263 HDA_PARAM_PIN_CAP_VREF_CTRL_80_MASK
|
4264 HDA_PARAM_PIN_CAP_VREF_CTRL_50_MASK
);
4265 w
= hdac_widget_get(devinfo
, 25);
4266 if (w
!= NULL
&& w
->enable
!= 0 && w
->type
==
4267 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
&&
4268 (w
->wclass
.pin
.config
&
4269 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK
) ==
4270 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_JACK
)
4271 w
->wclass
.pin
.cap
&= ~(
4272 HDA_PARAM_PIN_CAP_VREF_CTRL_100_MASK
|
4273 HDA_PARAM_PIN_CAP_VREF_CTRL_80_MASK
|
4274 HDA_PARAM_PIN_CAP_VREF_CTRL_50_MASK
);
4276 * nid: 26 = Line-in, leave it alone.
4279 case HDA_CODEC_AD1981HD
:
4280 w
= hdac_widget_get(devinfo
, 11);
4281 if (w
!= NULL
&& w
->enable
!= 0 && w
->nconns
> 3)
4283 if (subvendor
== IBM_M52_SUBVENDOR
) {
4284 ctl
= hdac_audio_ctl_amp_get(devinfo
, 7, 0, 1);
4286 ctl
->ossmask
= SOUND_MASK_SPEAKER
;
4289 case HDA_CODEC_AD1986A
:
4290 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
4291 w
= hdac_widget_get(devinfo
, i
);
4292 if (w
== NULL
|| w
->enable
== 0)
4295 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT
)
4300 if (subvendor
== ASUS_M2NPVMX_SUBVENDOR
||
4301 subvendor
== ASUS_A8NVMCSM_SUBVENDOR
) {
4302 /* nid 28 is mic, nid 29 is line-in */
4303 w
= hdac_widget_get(devinfo
, 15);
4306 w
= hdac_widget_get(devinfo
, 16);
4311 case HDA_CODEC_AD1988
:
4312 case HDA_CODEC_AD1988B
:
4313 /*w = hdac_widget_get(devinfo, 12);
4316 w->pflags |= HDA_ADC_LOCKED;
4318 w = hdac_widget_get(devinfo, 13);
4321 w->pflags |= HDA_ADC_LOCKED;
4323 w = hdac_widget_get(devinfo, 14);
4326 w->pflags |= HDA_ADC_LOCKED;
4328 ctl
= hdac_audio_ctl_amp_get(devinfo
, 57, 0, 1);
4330 ctl
->ossmask
= SOUND_MASK_IGAIN
;
4331 ctl
->widget
->ctlflags
|= SOUND_MASK_IGAIN
;
4333 ctl
= hdac_audio_ctl_amp_get(devinfo
, 58, 0, 1);
4335 ctl
->ossmask
= SOUND_MASK_IGAIN
;
4336 ctl
->widget
->ctlflags
|= SOUND_MASK_IGAIN
;
4338 ctl
= hdac_audio_ctl_amp_get(devinfo
, 60, 0, 1);
4340 ctl
->ossmask
= SOUND_MASK_IGAIN
;
4341 ctl
->widget
->ctlflags
|= SOUND_MASK_IGAIN
;
4343 ctl
= hdac_audio_ctl_amp_get(devinfo
, 32, 0, 1);
4345 ctl
->ossmask
= SOUND_MASK_MIC
| SOUND_MASK_VOLUME
;
4346 ctl
->widget
->ctlflags
|= SOUND_MASK_MIC
;
4348 ctl
= hdac_audio_ctl_amp_get(devinfo
, 32, 4, 1);
4350 ctl
->ossmask
= SOUND_MASK_MIC
| SOUND_MASK_VOLUME
;
4351 ctl
->widget
->ctlflags
|= SOUND_MASK_MIC
;
4353 ctl
= hdac_audio_ctl_amp_get(devinfo
, 32, 1, 1);
4355 ctl
->ossmask
= SOUND_MASK_LINE
| SOUND_MASK_VOLUME
;
4356 ctl
->widget
->ctlflags
|= SOUND_MASK_LINE
;
4358 ctl
= hdac_audio_ctl_amp_get(devinfo
, 32, 7, 1);
4360 ctl
->ossmask
= SOUND_MASK_SPEAKER
| SOUND_MASK_VOLUME
;
4361 ctl
->widget
->ctlflags
|= SOUND_MASK_SPEAKER
;
4364 case HDA_CODEC_STAC9221
:
4366 * Dell XPS M1210 need all DACs for each output jacks
4368 if (subvendor
== DELL_XPSM1210_SUBVENDOR
)
4370 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
4371 w
= hdac_widget_get(devinfo
, i
);
4372 if (w
== NULL
|| w
->enable
== 0)
4375 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT
)
4381 case HDA_CODEC_STAC9221D
:
4382 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
4383 w
= hdac_widget_get(devinfo
, i
);
4384 if (w
== NULL
|| w
->enable
== 0)
4387 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT
&&
4393 case HDA_CODEC_STAC9227
:
4394 w
= hdac_widget_get(devinfo
, 8);
4397 w
= hdac_widget_get(devinfo
, 9);
4401 case HDA_CODEC_CXWAIKIKI
:
4402 if (subvendor
== HP_DV5000_SUBVENDOR
) {
4403 w
= hdac_widget_get(devinfo
, 27);
4407 ctl
= hdac_audio_ctl_amp_get(devinfo
, 16, 0, 1);
4409 ctl
->ossmask
= SOUND_MASK_SKIP
;
4410 ctl
= hdac_audio_ctl_amp_get(devinfo
, 25, 0, 1);
4411 if (ctl
!= NULL
&& ctl
->childwidget
!= NULL
&&
4412 ctl
->childwidget
->enable
!= 0) {
4413 ctl
->ossmask
= SOUND_MASK_PCM
| SOUND_MASK_VOLUME
;
4414 ctl
->childwidget
->ctlflags
|= SOUND_MASK_PCM
;
4416 ctl
= hdac_audio_ctl_amp_get(devinfo
, 25, 1, 1);
4417 if (ctl
!= NULL
&& ctl
->childwidget
!= NULL
&&
4418 ctl
->childwidget
->enable
!= 0) {
4419 ctl
->ossmask
= SOUND_MASK_LINE
| SOUND_MASK_VOLUME
;
4420 ctl
->childwidget
->ctlflags
|= SOUND_MASK_LINE
;
4422 ctl
= hdac_audio_ctl_amp_get(devinfo
, 25, 2, 1);
4423 if (ctl
!= NULL
&& ctl
->childwidget
!= NULL
&&
4424 ctl
->childwidget
->enable
!= 0) {
4425 ctl
->ossmask
= SOUND_MASK_MIC
| SOUND_MASK_VOLUME
;
4426 ctl
->childwidget
->ctlflags
|= SOUND_MASK_MIC
;
4428 ctl
= hdac_audio_ctl_amp_get(devinfo
, 26, 0, 1);
4430 ctl
->ossmask
= SOUND_MASK_SKIP
;
4431 /* XXX mixer \=rec mic broken.. why?!? */
4432 /* ctl->widget->ctlflags |= SOUND_MASK_MIC; */
4441 hdac_audio_ctl_ossmixer_getnextdev(struct hdac_devinfo
*devinfo
)
4443 int *dev
= &devinfo
->function
.audio
.ossidx
;
4445 while (*dev
< SOUND_MIXER_NRDEVICES
) {
4447 case SOUND_MIXER_VOLUME
:
4448 case SOUND_MIXER_BASS
:
4449 case SOUND_MIXER_TREBLE
:
4450 case SOUND_MIXER_PCM
:
4451 case SOUND_MIXER_SPEAKER
:
4452 case SOUND_MIXER_LINE
:
4453 case SOUND_MIXER_MIC
:
4454 case SOUND_MIXER_CD
:
4455 case SOUND_MIXER_RECLEV
:
4456 case SOUND_MIXER_IGAIN
:
4457 case SOUND_MIXER_OGAIN
: /* reserved for EAPD switch */
4470 hdac_widget_find_dac_path(struct hdac_devinfo
*devinfo
, nid_t nid
, int depth
)
4472 struct hdac_widget
*w
;
4475 if (depth
> HDA_PARSE_MAXDEPTH
)
4477 w
= hdac_widget_get(devinfo
, nid
);
4478 if (w
== NULL
|| w
->enable
== 0)
4481 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT
:
4482 w
->pflags
|= HDA_DAC_PATH
;
4485 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER
:
4486 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR
:
4487 for (i
= 0; i
< w
->nconns
; i
++) {
4488 if (hdac_widget_find_dac_path(devinfo
,
4489 w
->conns
[i
], depth
+ 1) != 0) {
4490 if (w
->selconn
== -1)
4493 w
->pflags
|= HDA_DAC_PATH
;
4504 hdac_widget_find_adc_path(struct hdac_devinfo
*devinfo
, nid_t nid
, int depth
)
4506 struct hdac_widget
*w
;
4507 int i
, conndev
, ret
= 0;
4509 if (depth
> HDA_PARSE_MAXDEPTH
)
4511 w
= hdac_widget_get(devinfo
, nid
);
4512 if (w
== NULL
|| w
->enable
== 0)
4515 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT
:
4516 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR
:
4517 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER
:
4518 for (i
= 0; i
< w
->nconns
; i
++) {
4519 if (hdac_widget_find_adc_path(devinfo
, w
->conns
[i
],
4521 if (w
->selconn
== -1)
4523 w
->pflags
|= HDA_ADC_PATH
;
4528 case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
:
4529 conndev
= w
->wclass
.pin
.config
&
4530 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
;
4531 if (HDA_PARAM_PIN_CAP_INPUT_CAP(w
->wclass
.pin
.cap
) &&
4532 (conndev
== HDA_CONFIG_DEFAULTCONF_DEVICE_CD
||
4533 conndev
== HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN
||
4534 conndev
== HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN
)) {
4535 w
->pflags
|= HDA_ADC_PATH
;
4539 /*case HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER:
4540 if (w->pflags & HDA_DAC_PATH) {
4541 w->pflags |= HDA_ADC_PATH;
4552 hdac_audio_ctl_outamp_build(struct hdac_devinfo
*devinfo
,
4553 nid_t nid
, nid_t pnid
, int index
, int depth
)
4555 struct hdac_widget
*w
, *pw
;
4556 struct hdac_audio_ctl
*ctl
;
4558 int i
, ossdev
, conndev
, strategy
;
4560 if (depth
> HDA_PARSE_MAXDEPTH
)
4563 w
= hdac_widget_get(devinfo
, nid
);
4564 if (w
== NULL
|| w
->enable
== 0)
4567 pw
= hdac_widget_get(devinfo
, pnid
);
4568 strategy
= devinfo
->function
.audio
.parsing_strategy
;
4570 if (w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER
4571 || w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR
) {
4572 for (i
= 0; i
< w
->nconns
; i
++) {
4573 fl
|= hdac_audio_ctl_outamp_build(devinfo
, w
->conns
[i
],
4574 w
->nid
, i
, depth
+ 1);
4578 } else if (w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT
&&
4579 (w
->pflags
& HDA_DAC_PATH
)) {
4581 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) != NULL
) {
4582 if (ctl
->enable
== 0 || ctl
->widget
== NULL
)
4584 /* XXX This should be compressed! */
4585 if (((ctl
->widget
->nid
== w
->nid
) ||
4586 (ctl
->widget
->nid
== pnid
&& ctl
->index
== index
&&
4587 (ctl
->dir
& HDA_CTL_IN
)) ||
4588 (ctl
->widget
->nid
== pnid
&& pw
!= NULL
&&
4590 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR
&&
4591 (pw
->nconns
< 2 || pw
->selconn
== index
||
4592 pw
->selconn
== -1) &&
4593 (ctl
->dir
& HDA_CTL_OUT
)) ||
4594 (strategy
== HDA_PARSE_DIRECT
&&
4595 ctl
->widget
->nid
== w
->nid
)) &&
4596 !(ctl
->ossmask
& ~SOUND_MASK_VOLUME
)) {
4597 /*if (pw != NULL && pw->selconn == -1)
4598 pw->selconn = index;
4599 fl |= SOUND_MASK_VOLUME;
4600 fl |= SOUND_MASK_PCM;
4601 ctl->ossmask |= SOUND_MASK_VOLUME;
4602 ctl->ossmask |= SOUND_MASK_PCM;
4603 ctl->ossdev = SOUND_MIXER_PCM;*/
4604 if (!(w
->ctlflags
& SOUND_MASK_PCM
) ||
4606 !(pw
->ctlflags
& SOUND_MASK_PCM
))) {
4607 fl
|= SOUND_MASK_VOLUME
;
4608 fl
|= SOUND_MASK_PCM
;
4609 ctl
->ossmask
|= SOUND_MASK_VOLUME
;
4610 ctl
->ossmask
|= SOUND_MASK_PCM
;
4611 ctl
->ossdev
= SOUND_MIXER_PCM
;
4612 w
->ctlflags
|= SOUND_MASK_VOLUME
;
4613 w
->ctlflags
|= SOUND_MASK_PCM
;
4615 if (pw
->selconn
== -1)
4616 pw
->selconn
= index
;
4627 } else if (w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
&&
4628 HDA_PARAM_PIN_CAP_INPUT_CAP(w
->wclass
.pin
.cap
) &&
4629 (w
->pflags
& HDA_ADC_PATH
)) {
4630 conndev
= w
->wclass
.pin
.config
&
4631 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
;
4633 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) != NULL
) {
4634 if (ctl
->enable
== 0 || ctl
->widget
== NULL
)
4636 /* XXX This should be compressed! */
4637 if (((ctl
->widget
->nid
== pnid
&& ctl
->index
== index
&&
4638 (ctl
->dir
& HDA_CTL_IN
)) ||
4639 (ctl
->widget
->nid
== pnid
&& pw
!= NULL
&&
4641 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR
&&
4642 (pw
->nconns
< 2 || pw
->selconn
== index
||
4643 pw
->selconn
== -1) &&
4644 (ctl
->dir
& HDA_CTL_OUT
)) ||
4645 (strategy
== HDA_PARSE_DIRECT
&&
4646 ctl
->widget
->nid
== w
->nid
)) &&
4647 !(ctl
->ossmask
& ~SOUND_MASK_VOLUME
)) {
4648 if (pw
!= NULL
&& pw
->selconn
== -1)
4649 pw
->selconn
= index
;
4652 case HDA_CONFIG_DEFAULTCONF_DEVICE_MIC_IN
:
4653 ossdev
= SOUND_MIXER_MIC
;
4655 case HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_IN
:
4656 ossdev
= SOUND_MIXER_LINE
;
4658 case HDA_CONFIG_DEFAULTCONF_DEVICE_CD
:
4659 ossdev
= SOUND_MIXER_CD
;
4663 hdac_audio_ctl_ossmixer_getnextdev(
4669 if (strategy
== HDA_PARSE_MIXER
) {
4670 fl
|= SOUND_MASK_VOLUME
;
4671 ctl
->ossmask
|= SOUND_MASK_VOLUME
;
4674 ctl
->ossmask
|= 1 << ossdev
;
4675 ctl
->ossdev
= ossdev
;
4680 } else if (w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET
) {
4682 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) != NULL
) {
4683 if (ctl
->enable
== 0 || ctl
->widget
== NULL
)
4685 /* XXX This should be compressed! */
4686 if (((ctl
->widget
->nid
== pnid
&& ctl
->index
== index
&&
4687 (ctl
->dir
& HDA_CTL_IN
)) ||
4688 (ctl
->widget
->nid
== pnid
&& pw
!= NULL
&&
4690 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR
&&
4691 (pw
->nconns
< 2 || pw
->selconn
== index
||
4692 pw
->selconn
== -1) &&
4693 (ctl
->dir
& HDA_CTL_OUT
)) ||
4694 (strategy
== HDA_PARSE_DIRECT
&&
4695 ctl
->widget
->nid
== w
->nid
)) &&
4696 !(ctl
->ossmask
& ~SOUND_MASK_VOLUME
)) {
4697 if (pw
!= NULL
&& pw
->selconn
== -1)
4698 pw
->selconn
= index
;
4699 fl
|= SOUND_MASK_VOLUME
;
4700 fl
|= SOUND_MASK_SPEAKER
;
4701 ctl
->ossmask
|= SOUND_MASK_VOLUME
;
4702 ctl
->ossmask
|= SOUND_MASK_SPEAKER
;
4703 ctl
->ossdev
= SOUND_MIXER_SPEAKER
;
4713 hdac_audio_ctl_inamp_build(struct hdac_devinfo
*devinfo
, nid_t nid
, int depth
)
4715 struct hdac_widget
*w
, *cw
;
4716 struct hdac_audio_ctl
*ctl
;
4720 if (depth
> HDA_PARSE_MAXDEPTH
)
4723 w
= hdac_widget_get(devinfo
, nid
);
4724 if (w
== NULL
|| w
->enable
== 0)
4726 /*if (!(w->pflags & HDA_ADC_PATH))
4728 if (!(w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT ||
4729 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR))
4732 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) != NULL
) {
4733 if (ctl
->enable
== 0 || ctl
->widget
== NULL
)
4735 if (ctl
->widget
->nid
== nid
) {
4736 ctl
->ossmask
|= SOUND_MASK_RECLEV
;
4737 w
->ctlflags
|= SOUND_MASK_RECLEV
;
4738 return (SOUND_MASK_RECLEV
);
4741 for (i
= 0; i
< w
->nconns
; i
++) {
4742 cw
= hdac_widget_get(devinfo
, w
->conns
[i
]);
4743 if (cw
== NULL
|| cw
->enable
== 0)
4745 if (cw
->type
!= HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR
)
4747 fl
= hdac_audio_ctl_inamp_build(devinfo
, cw
->nid
, depth
+ 1);
4758 hdac_audio_ctl_recsel_build(struct hdac_devinfo
*devinfo
, nid_t nid
, int depth
)
4760 struct hdac_widget
*w
, *cw
;
4763 if (depth
> HDA_PARSE_MAXDEPTH
)
4766 w
= hdac_widget_get(devinfo
, nid
);
4767 if (w
== NULL
|| w
->enable
== 0)
4769 /*if (!(w->pflags & HDA_ADC_PATH))
4771 if (!(w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT ||
4772 w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR))
4775 for (i
= 0; i
< w
->nconns
; i
++) {
4776 cw
= hdac_widget_get(devinfo
, w
->conns
[i
]);
4780 w
->pflags
|= HDA_ADC_RECSEL
;
4784 for (i
= 0; i
< w
->nconns
; i
++) {
4785 if (hdac_audio_ctl_recsel_build(devinfo
,
4786 w
->conns
[i
], depth
+ 1) != 0)
4793 hdac_audio_build_tree_strategy(struct hdac_devinfo
*devinfo
)
4795 struct hdac_widget
*w
, *cw
;
4796 int i
, j
, conndev
, found_dac
= 0;
4799 strategy
= devinfo
->function
.audio
.parsing_strategy
;
4801 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
4802 w
= hdac_widget_get(devinfo
, i
);
4803 if (w
== NULL
|| w
->enable
== 0)
4805 if (w
->type
!= HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
)
4807 if (!HDA_PARAM_PIN_CAP_OUTPUT_CAP(w
->wclass
.pin
.cap
))
4809 conndev
= w
->wclass
.pin
.config
&
4810 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
;
4811 if (!(conndev
== HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT
||
4812 conndev
== HDA_CONFIG_DEFAULTCONF_DEVICE_SPEAKER
||
4813 conndev
== HDA_CONFIG_DEFAULTCONF_DEVICE_LINE_OUT
))
4815 for (j
= 0; j
< w
->nconns
; j
++) {
4816 cw
= hdac_widget_get(devinfo
, w
->conns
[j
]);
4817 if (cw
== NULL
|| cw
->enable
== 0)
4819 if (strategy
== HDA_PARSE_MIXER
&& !(cw
->type
==
4820 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER
||
4822 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR
))
4824 if (hdac_widget_find_dac_path(devinfo
, cw
->nid
, 0)
4826 if (w
->selconn
== -1)
4828 w
->pflags
|= HDA_DAC_PATH
;
4838 hdac_audio_build_tree(struct hdac_devinfo
*devinfo
)
4840 struct hdac_widget
*w
;
4841 struct hdac_audio_ctl
*ctl
;
4842 int i
, j
, dacs
, strategy
;
4844 /* Construct DAC path */
4845 strategy
= HDA_PARSE_MIXER
;
4846 devinfo
->function
.audio
.parsing_strategy
= strategy
;
4848 device_printf(devinfo
->codec
->sc
->dev
,
4849 "HDA_DEBUG: HWiP: HDA Widget Parser - Revision %d\n",
4850 HDA_WIDGET_PARSER_REV
);
4852 dacs
= hdac_audio_build_tree_strategy(devinfo
);
4855 device_printf(devinfo
->codec
->sc
->dev
,
4856 "HDA_DEBUG: HWiP: 0 DAC path found! "
4858 "using HDA_PARSE_DIRECT strategy.\n");
4860 strategy
= HDA_PARSE_DIRECT
;
4861 devinfo
->function
.audio
.parsing_strategy
= strategy
;
4862 dacs
= hdac_audio_build_tree_strategy(devinfo
);
4866 device_printf(devinfo
->codec
->sc
->dev
,
4867 "HDA_DEBUG: HWiP: Found %d DAC path using HDA_PARSE_%s "
4869 dacs
, (strategy
== HDA_PARSE_MIXER
) ? "MIXER" : "DIRECT");
4872 /* Construct ADC path */
4873 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
4874 w
= hdac_widget_get(devinfo
, i
);
4875 if (w
== NULL
|| w
->enable
== 0)
4877 if (w
->type
!= HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT
)
4879 (void)hdac_widget_find_adc_path(devinfo
, w
->nid
, 0);
4883 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
4884 w
= hdac_widget_get(devinfo
, i
);
4885 if (w
== NULL
|| w
->enable
== 0)
4887 if ((strategy
== HDA_PARSE_MIXER
&&
4888 (w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER
||
4889 w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR
)
4890 && (w
->pflags
& HDA_DAC_PATH
)) ||
4891 (strategy
== HDA_PARSE_DIRECT
&& (w
->pflags
&
4892 (HDA_DAC_PATH
| HDA_ADC_PATH
)))) {
4893 w
->ctlflags
|= hdac_audio_ctl_outamp_build(devinfo
,
4894 w
->nid
, devinfo
->startnode
- 1, 0, 0);
4895 } else if (w
->type
==
4896 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_BEEP_WIDGET
) {
4898 while ((ctl
= hdac_audio_ctl_each(devinfo
, &j
)) !=
4900 if (ctl
->enable
== 0 || ctl
->widget
== NULL
)
4902 if (ctl
->widget
->nid
!= w
->nid
)
4904 ctl
->ossmask
|= SOUND_MASK_VOLUME
;
4905 ctl
->ossmask
|= SOUND_MASK_SPEAKER
;
4906 ctl
->ossdev
= SOUND_MIXER_SPEAKER
;
4907 w
->ctlflags
|= SOUND_MASK_VOLUME
;
4908 w
->ctlflags
|= SOUND_MASK_SPEAKER
;
4913 /* Input mixers (rec) */
4914 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
4915 w
= hdac_widget_get(devinfo
, i
);
4916 if (w
== NULL
|| w
->enable
== 0)
4918 if (!(w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT
&&
4919 w
->pflags
& HDA_ADC_PATH
))
4921 hdac_audio_ctl_inamp_build(devinfo
, w
->nid
, 0);
4922 hdac_audio_ctl_recsel_build(devinfo
, w
->nid
, 0);
4926 #define HDA_COMMIT_CONN (1 << 0)
4927 #define HDA_COMMIT_CTRL (1 << 1)
4928 #define HDA_COMMIT_EAPD (1 << 2)
4929 #define HDA_COMMIT_GPIO (1 << 3)
4930 #define HDA_COMMIT_MISC (1 << 4)
4931 #define HDA_COMMIT_ALL (HDA_COMMIT_CONN | HDA_COMMIT_CTRL | \
4932 HDA_COMMIT_EAPD | HDA_COMMIT_GPIO | HDA_COMMIT_MISC)
4935 hdac_audio_commit(struct hdac_devinfo
*devinfo
, uint32_t cfl
)
4937 struct hdac_softc
*sc
= devinfo
->codec
->sc
;
4938 struct hdac_widget
*w
;
4942 if (!(cfl
& HDA_COMMIT_ALL
))
4945 cad
= devinfo
->codec
->cad
;
4947 if ((cfl
& HDA_COMMIT_MISC
)) {
4948 if (sc
->pci_subvendor
== APPLE_INTEL_MAC
)
4949 hdac_command(sc
, HDA_CMD_12BIT(cad
, devinfo
->nid
,
4953 if (cfl
& HDA_COMMIT_GPIO
) {
4954 uint32_t gdata
, gmask
, gdir
;
4955 int commitgpio
, numgpio
;
4962 numgpio
= HDA_PARAM_GPIO_COUNT_NUM_GPIO(
4963 devinfo
->function
.audio
.gpio
);
4965 if (devinfo
->function
.audio
.quirks
& HDA_QUIRK_GPIOFLUSH
)
4966 commitgpio
= (numgpio
> 0) ? 1 : 0;
4968 for (i
= 0; i
< numgpio
&& i
< HDA_GPIO_MAX
; i
++) {
4969 if (!(devinfo
->function
.audio
.quirks
&
4972 if (commitgpio
== 0) {
4975 gdata
= hdac_command(sc
,
4976 HDA_CMD_GET_GPIO_DATA(cad
,
4977 devinfo
->nid
), cad
);
4978 gmask
= hdac_command(sc
,
4979 HDA_CMD_GET_GPIO_ENABLE_MASK(cad
,
4980 devinfo
->nid
), cad
);
4981 gdir
= hdac_command(sc
,
4982 HDA_CMD_GET_GPIO_DIRECTION(cad
,
4983 devinfo
->nid
), cad
);
4984 device_printf(sc
->dev
,
4985 "GPIO init: data=0x%08x "
4986 "mask=0x%08x dir=0x%08x\n",
4987 gdata
, gmask
, gdir
);
4999 if (commitgpio
!= 0) {
5001 device_printf(sc
->dev
,
5002 "GPIO commit: data=0x%08x mask=0x%08x "
5004 gdata
, gmask
, gdir
);
5007 HDA_CMD_SET_GPIO_ENABLE_MASK(cad
, devinfo
->nid
,
5010 HDA_CMD_SET_GPIO_DIRECTION(cad
, devinfo
->nid
,
5013 HDA_CMD_SET_GPIO_DATA(cad
, devinfo
->nid
,
5018 for (i
= 0; i
< devinfo
->nodecnt
; i
++) {
5019 w
= &devinfo
->widget
[i
];
5020 if (w
== NULL
|| w
->enable
== 0)
5022 if (cfl
& HDA_COMMIT_CONN
) {
5023 if (w
->selconn
== -1)
5026 hdac_widget_connection_select(w
, w
->selconn
);
5028 if ((cfl
& HDA_COMMIT_CTRL
) &&
5029 w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
) {
5032 pincap
= w
->wclass
.pin
.cap
;
5034 if ((w
->pflags
& (HDA_DAC_PATH
| HDA_ADC_PATH
)) ==
5035 (HDA_DAC_PATH
| HDA_ADC_PATH
))
5036 device_printf(sc
->dev
, "WARNING: node %d "
5037 "participate both for DAC/ADC!\n", w
->nid
);
5038 if (w
->pflags
& HDA_DAC_PATH
) {
5039 w
->wclass
.pin
.ctrl
&=
5040 ~HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE
;
5041 if ((w
->wclass
.pin
.config
&
5042 HDA_CONFIG_DEFAULTCONF_DEVICE_MASK
) !=
5043 HDA_CONFIG_DEFAULTCONF_DEVICE_HP_OUT
)
5044 w
->wclass
.pin
.ctrl
&=
5045 ~HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE
;
5046 if ((devinfo
->function
.audio
.quirks
& HDA_QUIRK_OVREF100
) &&
5047 HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap
))
5048 w
->wclass
.pin
.ctrl
|=
5049 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
5050 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_100
);
5051 else if ((devinfo
->function
.audio
.quirks
& HDA_QUIRK_OVREF80
) &&
5052 HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap
))
5053 w
->wclass
.pin
.ctrl
|=
5054 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
5055 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_80
);
5056 else if ((devinfo
->function
.audio
.quirks
& HDA_QUIRK_OVREF50
) &&
5057 HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap
))
5058 w
->wclass
.pin
.ctrl
|=
5059 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
5060 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_50
);
5061 } else if (w
->pflags
& HDA_ADC_PATH
) {
5062 w
->wclass
.pin
.ctrl
&=
5063 ~(HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE
|
5064 HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE
);
5065 if ((devinfo
->function
.audio
.quirks
& HDA_QUIRK_IVREF100
) &&
5066 HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap
))
5067 w
->wclass
.pin
.ctrl
|=
5068 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
5069 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_100
);
5070 else if ((devinfo
->function
.audio
.quirks
& HDA_QUIRK_IVREF80
) &&
5071 HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap
))
5072 w
->wclass
.pin
.ctrl
|=
5073 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
5074 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_80
);
5075 else if ((devinfo
->function
.audio
.quirks
& HDA_QUIRK_IVREF50
) &&
5076 HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap
))
5077 w
->wclass
.pin
.ctrl
|=
5078 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE(
5079 HDA_CMD_PIN_WIDGET_CTRL_VREF_ENABLE_50
);
5081 w
->wclass
.pin
.ctrl
&= ~(
5082 HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE
|
5083 HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE
|
5084 HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE
|
5085 HDA_CMD_SET_PIN_WIDGET_CTRL_VREF_ENABLE_MASK
);
5087 HDA_CMD_SET_PIN_WIDGET_CTRL(cad
, w
->nid
,
5088 w
->wclass
.pin
.ctrl
), cad
);
5090 if ((cfl
& HDA_COMMIT_EAPD
) &&
5091 w
->param
.eapdbtl
!= HDAC_INVALID
) {
5094 val
= w
->param
.eapdbtl
;
5095 if (devinfo
->function
.audio
.quirks
&
5097 val
^= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD
;
5099 HDA_CMD_SET_EAPD_BTL_ENABLE(cad
, w
->nid
,
5108 hdac_audio_ctl_commit(struct hdac_devinfo
*devinfo
)
5110 struct hdac_softc
*sc
= devinfo
->codec
->sc
;
5111 struct hdac_audio_ctl
*ctl
;
5114 devinfo
->function
.audio
.mvol
= 100 | (100 << 8);
5116 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) != NULL
) {
5117 if (ctl
->enable
== 0 || ctl
->widget
== NULL
) {
5119 device_printf(sc
->dev
, "[%2d] Ctl nid=%d",
5120 i
, (ctl
->widget
!= NULL
) ?
5121 ctl
->widget
->nid
: -1);
5122 if (ctl
->childwidget
!= NULL
)
5123 kprintf(" childnid=%d",
5124 ctl
->childwidget
->nid
);
5125 if (ctl
->widget
== NULL
)
5126 kprintf(" NULL WIDGET!");
5127 kprintf(" DISABLED\n");
5132 if (ctl
->ossmask
== 0) {
5133 device_printf(sc
->dev
, "[%2d] Ctl nid=%d",
5134 i
, ctl
->widget
->nid
);
5135 if (ctl
->childwidget
!= NULL
)
5136 kprintf(" childnid=%d",
5137 ctl
->childwidget
->nid
);
5138 kprintf(" Bind to NONE\n");
5141 if (ctl
->step
> 0) {
5142 ctl
->ossval
= (ctl
->left
* 100) / ctl
->step
;
5143 ctl
->ossval
|= ((ctl
->right
* 100) / ctl
->step
) << 8;
5146 hdac_audio_ctl_amp_set(ctl
, HDA_AMP_MUTE_DEFAULT
,
5147 ctl
->left
, ctl
->right
);
5152 hdac_pcmchannel_setup(struct hdac_devinfo
*devinfo
, int dir
)
5154 struct hdac_chan
*ch
;
5155 struct hdac_widget
*w
;
5156 uint32_t cap
, fmtcap
, pcmcap
, path
;
5157 int i
, type
, ret
, max
;
5159 if (dir
== PCMDIR_PLAY
) {
5160 type
= HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT
;
5161 ch
= &devinfo
->codec
->sc
->play
;
5162 path
= HDA_DAC_PATH
;
5164 type
= HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT
;
5165 ch
= &devinfo
->codec
->sc
->rec
;
5166 path
= HDA_ADC_PATH
;
5169 ch
->caps
= hdac_caps
;
5170 ch
->caps
.fmtlist
= ch
->fmtlist
;
5173 ch
->pcmrates
[0] = 48000;
5174 ch
->pcmrates
[1] = 0;
5177 fmtcap
= devinfo
->function
.audio
.supp_stream_formats
;
5178 pcmcap
= devinfo
->function
.audio
.supp_pcm_size_rate
;
5179 max
= (sizeof(ch
->io
) / sizeof(ch
->io
[0])) - 1;
5181 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
&& ret
< max
; i
++) {
5182 w
= hdac_widget_get(devinfo
, i
);
5183 if (w
== NULL
|| w
->enable
== 0 || w
->type
!= type
||
5184 !(w
->pflags
& path
))
5186 cap
= w
->param
.widget_cap
;
5187 /*if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(cap))
5189 if (!HDA_PARAM_AUDIO_WIDGET_CAP_STEREO(cap
))
5191 cap
= w
->param
.supp_stream_formats
;
5192 /*if (HDA_PARAM_SUPP_STREAM_FORMATS_AC3(cap)) {
5194 if (HDA_PARAM_SUPP_STREAM_FORMATS_FLOAT32(cap)) {
5196 if (!HDA_PARAM_SUPP_STREAM_FORMATS_PCM(cap
))
5199 fmtcap
= w
->param
.supp_stream_formats
;
5200 pcmcap
= w
->param
.supp_pcm_size_rate
;
5202 fmtcap
&= w
->param
.supp_stream_formats
;
5203 pcmcap
&= w
->param
.supp_pcm_size_rate
;
5209 ch
->supp_stream_formats
= fmtcap
;
5210 ch
->supp_pcm_size_rate
= pcmcap
;
5221 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16BIT(cap
))
5223 else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8BIT(cap
))
5225 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(cap
))
5227 else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(cap
))
5229 else if (HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(cap
))
5232 if (!(devinfo
->function
.audio
.quirks
& HDA_QUIRK_FORCESTEREO
))
5233 ch
->fmtlist
[i
++] = AFMT_S16_LE
;
5234 ch
->fmtlist
[i
++] = AFMT_S16_LE
| AFMT_STEREO
;
5235 if (ch
->bit32
> 0) {
5236 if (!(devinfo
->function
.audio
.quirks
&
5237 HDA_QUIRK_FORCESTEREO
))
5238 ch
->fmtlist
[i
++] = AFMT_S32_LE
;
5239 ch
->fmtlist
[i
++] = AFMT_S32_LE
| AFMT_STEREO
;
5243 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8KHZ(cap
))
5244 ch
->pcmrates
[i
++] = 8000;
5245 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_11KHZ(cap
))
5246 ch
->pcmrates
[i
++] = 11025;
5247 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16KHZ(cap
))
5248 ch
->pcmrates
[i
++] = 16000;
5249 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_22KHZ(cap
))
5250 ch
->pcmrates
[i
++] = 22050;
5251 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32KHZ(cap
))
5252 ch
->pcmrates
[i
++] = 32000;
5253 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_44KHZ(cap
))
5254 ch
->pcmrates
[i
++] = 44100;
5255 /* if (HDA_PARAM_SUPP_PCM_SIZE_RATE_48KHZ(cap)) */
5256 ch
->pcmrates
[i
++] = 48000;
5257 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_88KHZ(cap
))
5258 ch
->pcmrates
[i
++] = 88200;
5259 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_96KHZ(cap
))
5260 ch
->pcmrates
[i
++] = 96000;
5261 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_176KHZ(cap
))
5262 ch
->pcmrates
[i
++] = 176400;
5263 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_192KHZ(cap
))
5264 ch
->pcmrates
[i
++] = 192000;
5265 /* if (HDA_PARAM_SUPP_PCM_SIZE_RATE_384KHZ(cap)) */
5266 ch
->pcmrates
[i
] = 0;
5268 ch
->caps
.minspeed
= ch
->pcmrates
[0];
5269 ch
->caps
.maxspeed
= ch
->pcmrates
[i
- 1];
5277 hdac_dump_ctls(struct hdac_devinfo
*devinfo
, const char *banner
, uint32_t flag
)
5279 struct hdac_audio_ctl
*ctl
;
5280 struct hdac_softc
*sc
= devinfo
->codec
->sc
;
5286 fl
= SOUND_MASK_VOLUME
| SOUND_MASK_PCM
|
5287 SOUND_MASK_CD
| SOUND_MASK_LINE
| SOUND_MASK_RECLEV
|
5288 SOUND_MASK_MIC
| SOUND_MASK_SPEAKER
| SOUND_MASK_OGAIN
;
5292 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) != NULL
) {
5293 if (ctl
->enable
== 0 || ctl
->widget
== NULL
||
5294 ctl
->widget
->enable
== 0 || (ctl
->ossmask
&
5295 (SOUND_MASK_SKIP
| SOUND_MASK_DISABLE
)))
5297 if ((flag
== 0 && (ctl
->ossmask
& ~fl
)) ||
5298 (flag
!= 0 && (ctl
->ossmask
& flag
))) {
5299 if (banner
!= NULL
) {
5300 device_printf(sc
->dev
, "\n");
5301 device_printf(sc
->dev
, "%s\n", banner
);
5303 goto hdac_ctl_dump_it_all
;
5309 hdac_ctl_dump_it_all
:
5311 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) != NULL
) {
5312 if (ctl
->enable
== 0 || ctl
->widget
== NULL
||
5313 ctl
->widget
->enable
== 0)
5315 if (!((flag
== 0 && (ctl
->ossmask
& ~fl
)) ||
5316 (flag
!= 0 && (ctl
->ossmask
& flag
))))
5319 device_printf(sc
->dev
, "\n");
5320 device_printf(sc
->dev
, "Unknown Ctl (OSS: %s)\n",
5321 hdac_audio_ctl_ossmixer_mask2name(ctl
->ossmask
));
5323 device_printf(sc
->dev
, " |\n");
5324 device_printf(sc
->dev
, " +- nid: %2d index: %2d ",
5325 ctl
->widget
->nid
, ctl
->index
);
5326 if (ctl
->childwidget
!= NULL
)
5327 kprintf("(nid: %2d) ", ctl
->childwidget
->nid
);
5330 kprintf("mute: %d step: %3d size: %3d off: %3d dir=0x%x ossmask=0x%08x\n",
5331 ctl
->mute
, ctl
->step
, ctl
->size
, ctl
->offset
, ctl
->dir
,
5337 hdac_dump_audio_formats(struct hdac_softc
*sc
, uint32_t fcap
, uint32_t pcmcap
)
5343 device_printf(sc
->dev
, " Stream cap: 0x%08x\n", cap
);
5344 device_printf(sc
->dev
, " Format:");
5345 if (HDA_PARAM_SUPP_STREAM_FORMATS_AC3(cap
))
5347 if (HDA_PARAM_SUPP_STREAM_FORMATS_FLOAT32(cap
))
5348 kprintf(" FLOAT32");
5349 if (HDA_PARAM_SUPP_STREAM_FORMATS_PCM(cap
))
5355 device_printf(sc
->dev
, " PCM cap: 0x%08x\n", cap
);
5356 device_printf(sc
->dev
, " PCM size:");
5357 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8BIT(cap
))
5359 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16BIT(cap
))
5361 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_20BIT(cap
))
5363 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_24BIT(cap
))
5365 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32BIT(cap
))
5368 device_printf(sc
->dev
, " PCM rate:");
5369 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_8KHZ(cap
))
5371 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_11KHZ(cap
))
5373 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_16KHZ(cap
))
5375 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_22KHZ(cap
))
5377 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_32KHZ(cap
))
5379 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_44KHZ(cap
))
5382 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_88KHZ(cap
))
5384 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_96KHZ(cap
))
5386 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_176KHZ(cap
))
5388 if (HDA_PARAM_SUPP_PCM_SIZE_RATE_192KHZ(cap
))
5395 hdac_dump_pin(struct hdac_softc
*sc
, struct hdac_widget
*w
)
5397 uint32_t pincap
, wcap
;
5399 pincap
= w
->wclass
.pin
.cap
;
5400 wcap
= w
->param
.widget_cap
;
5402 device_printf(sc
->dev
, " Pin cap: 0x%08x\n", pincap
);
5403 device_printf(sc
->dev
, " ");
5404 if (HDA_PARAM_PIN_CAP_IMP_SENSE_CAP(pincap
))
5406 if (HDA_PARAM_PIN_CAP_TRIGGER_REQD(pincap
))
5408 if (HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(pincap
))
5410 if (HDA_PARAM_PIN_CAP_HEADPHONE_CAP(pincap
))
5412 if (HDA_PARAM_PIN_CAP_OUTPUT_CAP(pincap
))
5414 if (HDA_PARAM_PIN_CAP_INPUT_CAP(pincap
))
5416 if (HDA_PARAM_PIN_CAP_BALANCED_IO_PINS(pincap
))
5418 if (HDA_PARAM_PIN_CAP_VREF_CTRL(pincap
)) {
5420 if (HDA_PARAM_PIN_CAP_VREF_CTRL_50(pincap
))
5422 if (HDA_PARAM_PIN_CAP_VREF_CTRL_80(pincap
))
5424 if (HDA_PARAM_PIN_CAP_VREF_CTRL_100(pincap
))
5426 if (HDA_PARAM_PIN_CAP_VREF_CTRL_GROUND(pincap
))
5428 if (HDA_PARAM_PIN_CAP_VREF_CTRL_HIZ(pincap
))
5432 if (HDA_PARAM_PIN_CAP_EAPD_CAP(pincap
))
5434 if (HDA_PARAM_AUDIO_WIDGET_CAP_UNSOL_CAP(wcap
))
5435 kprintf(" : UNSOL");
5437 device_printf(sc
->dev
, " Pin config: 0x%08x\n",
5438 w
->wclass
.pin
.config
);
5439 device_printf(sc
->dev
, " Pin control: 0x%08x", w
->wclass
.pin
.ctrl
);
5440 if (w
->wclass
.pin
.ctrl
& HDA_CMD_SET_PIN_WIDGET_CTRL_HPHN_ENABLE
)
5442 if (w
->wclass
.pin
.ctrl
& HDA_CMD_SET_PIN_WIDGET_CTRL_IN_ENABLE
)
5444 if (w
->wclass
.pin
.ctrl
& HDA_CMD_SET_PIN_WIDGET_CTRL_OUT_ENABLE
)
5450 hdac_dump_amp(struct hdac_softc
*sc
, uint32_t cap
, char *banner
)
5452 device_printf(sc
->dev
, " %s amp: 0x%08x\n", banner
, cap
);
5453 device_printf(sc
->dev
, " "
5454 "mute=%d step=%d size=%d offset=%d\n",
5455 HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP(cap
),
5456 HDA_PARAM_OUTPUT_AMP_CAP_NUMSTEPS(cap
),
5457 HDA_PARAM_OUTPUT_AMP_CAP_STEPSIZE(cap
),
5458 HDA_PARAM_OUTPUT_AMP_CAP_OFFSET(cap
));
5462 hdac_dump_nodes(struct hdac_devinfo
*devinfo
)
5464 struct hdac_softc
*sc
= devinfo
->codec
->sc
;
5465 struct hdac_widget
*w
, *cw
;
5468 device_printf(sc
->dev
, "\n");
5469 device_printf(sc
->dev
, "Default Parameter\n");
5470 device_printf(sc
->dev
, "-----------------\n");
5471 hdac_dump_audio_formats(sc
,
5472 devinfo
->function
.audio
.supp_stream_formats
,
5473 devinfo
->function
.audio
.supp_pcm_size_rate
);
5474 device_printf(sc
->dev
, " IN amp: 0x%08x\n",
5475 devinfo
->function
.audio
.inamp_cap
);
5476 device_printf(sc
->dev
, " OUT amp: 0x%08x\n",
5477 devinfo
->function
.audio
.outamp_cap
);
5478 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
5479 w
= hdac_widget_get(devinfo
, i
);
5481 device_printf(sc
->dev
, "Ghost widget nid=%d\n", i
);
5484 device_printf(sc
->dev
, "\n");
5485 device_printf(sc
->dev
, " nid: %d [%s]%s\n", w
->nid
,
5486 HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w
->param
.widget_cap
) ?
5487 "DIGITAL" : "ANALOG",
5488 (w
->enable
== 0) ? " [DISABLED]" : "");
5489 device_printf(sc
->dev
, " name: %s\n", w
->name
);
5490 device_printf(sc
->dev
, " widget_cap: 0x%08x\n",
5491 w
->param
.widget_cap
);
5492 device_printf(sc
->dev
, " Parse flags: 0x%08x\n",
5494 device_printf(sc
->dev
, " Ctl flags: 0x%08x\n",
5496 if (w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT
||
5497 w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_INPUT
) {
5498 hdac_dump_audio_formats(sc
,
5499 w
->param
.supp_stream_formats
,
5500 w
->param
.supp_pcm_size_rate
);
5501 } else if (w
->type
==
5502 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
)
5503 hdac_dump_pin(sc
, w
);
5504 if (w
->param
.eapdbtl
!= HDAC_INVALID
)
5505 device_printf(sc
->dev
, " EAPD: 0x%08x\n",
5507 if (HDA_PARAM_AUDIO_WIDGET_CAP_OUT_AMP(w
->param
.widget_cap
) &&
5508 w
->param
.outamp_cap
!= 0)
5509 hdac_dump_amp(sc
, w
->param
.outamp_cap
, "Output");
5510 if (HDA_PARAM_AUDIO_WIDGET_CAP_IN_AMP(w
->param
.widget_cap
) &&
5511 w
->param
.inamp_cap
!= 0)
5512 hdac_dump_amp(sc
, w
->param
.inamp_cap
, " Input");
5513 device_printf(sc
->dev
, " connections: %d\n", w
->nconns
);
5514 for (j
= 0; j
< w
->nconns
; j
++) {
5515 cw
= hdac_widget_get(devinfo
, w
->conns
[j
]);
5516 device_printf(sc
->dev
, " |\n");
5517 device_printf(sc
->dev
, " + <- nid=%d [%s]",
5518 w
->conns
[j
], (cw
== NULL
) ? "GHOST!" : cw
->name
);
5520 kprintf(" [UNKNOWN]");
5521 else if (cw
->enable
== 0)
5522 kprintf(" [DISABLED]");
5523 if (w
->nconns
> 1 && w
->selconn
== j
&& w
->type
!=
5524 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER
)
5525 kprintf(" (selected)");
5533 hdac_dump_dac_internal(struct hdac_devinfo
*devinfo
, nid_t nid
, int depth
)
5535 struct hdac_widget
*w
, *cw
;
5536 struct hdac_softc
*sc
= devinfo
->codec
->sc
;
5539 if (depth
> HDA_PARSE_MAXDEPTH
)
5542 w
= hdac_widget_get(devinfo
, nid
);
5543 if (w
== NULL
|| w
->enable
== 0 || !(w
->pflags
& HDA_DAC_PATH
))
5546 if (w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
) {
5547 device_printf(sc
->dev
, "\n");
5548 device_printf(sc
->dev
, " nid=%d [%s]\n", w
->nid
, w
->name
);
5549 device_printf(sc
->dev
, " ^\n");
5550 device_printf(sc
->dev
, " |\n");
5551 device_printf(sc
->dev
, " +-----<------+\n");
5553 device_printf(sc
->dev
, " ^\n");
5554 device_printf(sc
->dev
, " |\n");
5555 device_printf(sc
->dev
, " ");
5556 kprintf(" nid=%d [%s]\n", w
->nid
, w
->name
);
5559 if (w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_OUTPUT
) {
5561 } else if (w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_MIXER
) {
5562 for (i
= 0; i
< w
->nconns
; i
++) {
5563 cw
= hdac_widget_get(devinfo
, w
->conns
[i
]);
5564 if (cw
== NULL
|| cw
->enable
== 0 || cw
->type
==
5565 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
)
5567 if (hdac_dump_dac_internal(devinfo
, cw
->nid
,
5571 } else if ((w
->type
==
5572 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_AUDIO_SELECTOR
||
5573 w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
) &&
5574 w
->selconn
> -1 && w
->selconn
< w
->nconns
) {
5575 if (hdac_dump_dac_internal(devinfo
, w
->conns
[w
->selconn
],
5584 hdac_dump_dac(struct hdac_devinfo
*devinfo
)
5586 struct hdac_widget
*w
;
5587 struct hdac_softc
*sc
= devinfo
->codec
->sc
;
5590 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
5591 w
= hdac_widget_get(devinfo
, i
);
5592 if (w
== NULL
|| w
->enable
== 0)
5594 if (w
->type
!= HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
||
5595 !(w
->pflags
& HDA_DAC_PATH
))
5599 device_printf(sc
->dev
, "\n");
5600 device_printf(sc
->dev
, "Playback path:\n");
5602 hdac_dump_dac_internal(devinfo
, w
->nid
, 0);
5607 hdac_dump_adc(struct hdac_devinfo
*devinfo
)
5609 struct hdac_widget
*w
, *cw
;
5610 struct hdac_softc
*sc
= devinfo
->codec
->sc
;
5615 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
5616 w
= hdac_widget_get(devinfo
, i
);
5617 if (w
== NULL
|| w
->enable
== 0)
5619 if (!(w
->pflags
& HDA_ADC_RECSEL
))
5623 device_printf(sc
->dev
, "\n");
5624 device_printf(sc
->dev
, "Recording sources:\n");
5626 device_printf(sc
->dev
, "\n");
5627 device_printf(sc
->dev
, " nid=%d [%s]\n", w
->nid
, w
->name
);
5628 for (j
= 0; j
< w
->nconns
; j
++) {
5629 cw
= hdac_widget_get(devinfo
, w
->conns
[j
]);
5630 if (cw
== NULL
|| cw
->enable
== 0)
5632 hdac_audio_ctl_ossmixer_mask2allname(cw
->ctlflags
,
5633 ossdevs
, sizeof(ossdevs
));
5634 device_printf(sc
->dev
, " |\n");
5635 device_printf(sc
->dev
, " + <- nid=%d [%s]",
5637 if (strlen(ossdevs
) > 0) {
5638 kprintf(" [recsrc: %s]", ossdevs
);
5646 hdac_dump_pcmchannels(struct hdac_softc
*sc
, int pcnt
, int rcnt
)
5651 device_printf(sc
->dev
, "\n");
5652 device_printf(sc
->dev
, " PCM Playback: %d\n", pcnt
);
5653 hdac_dump_audio_formats(sc
, sc
->play
.supp_stream_formats
,
5654 sc
->play
.supp_pcm_size_rate
);
5655 device_printf(sc
->dev
, " DAC:");
5656 for (nids
= sc
->play
.io
; *nids
!= -1; nids
++)
5657 kprintf(" %d", *nids
);
5662 device_printf(sc
->dev
, "\n");
5663 device_printf(sc
->dev
, " PCM Record: %d\n", rcnt
);
5664 hdac_dump_audio_formats(sc
, sc
->play
.supp_stream_formats
,
5665 sc
->rec
.supp_pcm_size_rate
);
5666 device_printf(sc
->dev
, " ADC:");
5667 for (nids
= sc
->rec
.io
; *nids
!= -1; nids
++)
5668 kprintf(" %d", *nids
);
5674 hdac_release_resources(struct hdac_softc
*sc
)
5676 struct hdac_devinfo
*devinfo
= NULL
;
5677 device_t
*devlist
= NULL
;
5686 callout_stop(&sc
->poll_hda
);
5687 callout_stop(&sc
->poll_hdac
);
5688 callout_stop(&sc
->poll_jack
);
5694 /* give pending interrupts stuck on the lock a chance to clear */
5696 tsleep(&sc
->irq
, 0, "hdaslp", hz
/ 10);
5698 device_get_children(sc
->dev
, &devlist
, &devcount
);
5699 for (i
= 0; devlist
!= NULL
&& i
< devcount
; i
++) {
5700 devinfo
= (struct hdac_devinfo
*)device_get_ivars(devlist
[i
]);
5701 if (devinfo
== NULL
)
5703 if (devinfo
->widget
!= NULL
)
5704 kfree(devinfo
->widget
, M_HDAC
);
5705 if (devinfo
->node_type
==
5706 HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO
&&
5707 devinfo
->function
.audio
.ctl
!= NULL
)
5708 kfree(devinfo
->function
.audio
.ctl
, M_HDAC
);
5709 kfree(devinfo
, M_HDAC
);
5710 device_delete_child(sc
->dev
, devlist
[i
]);
5712 if (devlist
!= NULL
)
5713 kfree(devlist
, M_TEMP
);
5715 for (i
= 0; i
< HDAC_CODEC_MAX
; i
++) {
5716 if (sc
->codecs
[i
] != NULL
)
5717 kfree(sc
->codecs
[i
], M_HDAC
);
5718 sc
->codecs
[i
] = NULL
;
5721 hdac_dma_free(sc
, &sc
->pos_dma
);
5722 hdac_dma_free(sc
, &sc
->rirb_dma
);
5723 hdac_dma_free(sc
, &sc
->corb_dma
);
5724 if (sc
->play
.blkcnt
> 0)
5725 hdac_dma_free(sc
, &sc
->play
.bdl_dma
);
5726 if (sc
->rec
.blkcnt
> 0)
5727 hdac_dma_free(sc
, &sc
->rec
.bdl_dma
);
5728 if (sc
->chan_dmat
!= NULL
) {
5729 bus_dma_tag_destroy(sc
->chan_dmat
);
5730 sc
->chan_dmat
= NULL
;
5733 snd_mtxfree(sc
->lock
);
5734 kfree(sc
, M_DEVBUF
);
5737 /* This function surely going to make its way into upper level someday. */
5739 hdac_config_fetch(struct hdac_softc
*sc
, uint32_t *on
, uint32_t *off
)
5742 int i
= 0, j
, k
, len
, inv
;
5750 if (resource_string_value(device_get_name(sc
->dev
),
5751 device_get_unit(sc
->dev
), "config", &res
) != 0)
5753 if (!(res
!= NULL
&& strlen(res
) > 0))
5756 device_printf(sc
->dev
, "HDA_DEBUG: HDA Config:");
5759 while (res
[i
] != '\0' &&
5760 (res
[i
] == ',' || isspace(res
[i
]) != 0))
5762 if (res
[i
] == '\0') {
5769 while (res
[j
] != '\0' &&
5770 !(res
[j
] == ',' || isspace(res
[j
]) != 0))
5773 if (len
> 2 && strncmp(res
+ i
, "no", 2) == 0)
5777 for (k
= 0; len
> inv
&& k
< HDAC_QUIRKS_TAB_LEN
; k
++) {
5778 if (strncmp(res
+ i
+ inv
,
5779 hdac_quirks_tab
[k
].key
, len
- inv
) != 0)
5781 if (len
- inv
!= strlen(hdac_quirks_tab
[k
].key
))
5784 kprintf(" %s%s", (inv
!= 0) ? "no" : "",
5785 hdac_quirks_tab
[k
].key
);
5787 if (inv
== 0 && on
!= NULL
)
5788 *on
|= hdac_quirks_tab
[k
].value
;
5789 else if (inv
!= 0 && off
!= NULL
)
5790 *off
|= hdac_quirks_tab
[k
].value
;
5797 #ifdef SND_DYNSYSCTL
5799 sysctl_hdac_polling(SYSCTL_HANDLER_ARGS
)
5801 struct hdac_softc
*sc
;
5802 struct hdac_devinfo
*devinfo
;
5807 dev
= oidp
->oid_arg1
;
5808 devinfo
= pcm_getdevinfo(dev
);
5809 if (devinfo
== NULL
|| devinfo
->codec
== NULL
||
5810 devinfo
->codec
->sc
== NULL
)
5812 sc
= devinfo
->codec
->sc
;
5816 err
= sysctl_handle_int(oidp
, &val
, 0, req
);
5818 if (err
!= 0 || req
->newptr
== NULL
)
5820 if (val
< 0 || val
> 1)
5824 if (val
!= sc
->polling
) {
5825 if (hda_chan_active(sc
) != 0)
5827 else if (val
== 0) {
5828 callout_stop(&sc
->poll_hdac
);
5831 HDAC_WRITE_2(&sc
->mem
, HDAC_RINTCNT
,
5833 ctl
= HDAC_READ_1(&sc
->mem
, HDAC_RIRBCTL
);
5834 ctl
|= HDAC_RIRBCTL_RINTCTL
;
5835 HDAC_WRITE_1(&sc
->mem
, HDAC_RIRBCTL
, ctl
);
5836 HDAC_WRITE_4(&sc
->mem
, HDAC_INTCTL
,
5837 HDAC_INTCTL_CIE
| HDAC_INTCTL_GIE
);
5841 HDAC_WRITE_4(&sc
->mem
, HDAC_INTCTL
, 0);
5842 HDAC_WRITE_2(&sc
->mem
, HDAC_RINTCNT
, 0);
5843 ctl
= HDAC_READ_1(&sc
->mem
, HDAC_RIRBCTL
);
5844 ctl
&= ~HDAC_RIRBCTL_RINTCTL
;
5845 HDAC_WRITE_1(&sc
->mem
, HDAC_RIRBCTL
, ctl
);
5846 callout_reset(&sc
->poll_hdac
, 1, hdac_poll_callback
,
5858 sysctl_hdac_polling_interval(SYSCTL_HANDLER_ARGS
)
5860 struct hdac_softc
*sc
;
5861 struct hdac_devinfo
*devinfo
;
5865 dev
= oidp
->oid_arg1
;
5866 devinfo
= pcm_getdevinfo(dev
);
5867 if (devinfo
== NULL
|| devinfo
->codec
== NULL
||
5868 devinfo
->codec
->sc
== NULL
)
5870 sc
= devinfo
->codec
->sc
;
5872 val
= ((uint64_t)sc
->poll_ival
* 1000) / hz
;
5874 err
= sysctl_handle_int(oidp
, &val
, 0, req
);
5876 if (err
!= 0 || req
->newptr
== NULL
)
5883 val
= ((uint64_t)val
* hz
) / 1000;
5890 sc
->poll_ival
= val
;
5898 sysctl_hdac_pindump(SYSCTL_HANDLER_ARGS
)
5900 struct hdac_softc
*sc
;
5901 struct hdac_devinfo
*devinfo
;
5902 struct hdac_widget
*w
;
5904 uint32_t res
, pincap
, execres
;
5908 dev
= oidp
->oid_arg1
;
5909 devinfo
= pcm_getdevinfo(dev
);
5910 if (devinfo
== NULL
|| devinfo
->codec
== NULL
||
5911 devinfo
->codec
->sc
== NULL
)
5914 err
= sysctl_handle_int(oidp
, &val
, 0, req
);
5915 if (err
!= 0 || req
->newptr
== NULL
|| val
== 0)
5917 sc
= devinfo
->codec
->sc
;
5918 cad
= devinfo
->codec
->cad
;
5920 device_printf(dev
, "HDAC Dump AFG [nid=%d]:\n", devinfo
->nid
);
5921 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
5922 w
= hdac_widget_get(devinfo
, i
);
5923 if (w
== NULL
|| w
->type
!=
5924 HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
)
5926 pincap
= w
->wclass
.pin
.cap
;
5927 if ((HDA_PARAM_PIN_CAP_IMP_SENSE_CAP(pincap
) ||
5928 HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP(pincap
)) &&
5929 HDA_PARAM_PIN_CAP_TRIGGER_REQD(pincap
)) {
5932 HDA_CMD_SET_PIN_SENSE(cad
, w
->nid
, 0), cad
);
5934 res
= hdac_command(sc
,
5935 HDA_CMD_GET_PIN_SENSE(cad
, w
->nid
), cad
);
5936 if (res
!= 0x7fffffff)
5939 } while (--timeout
!= 0);
5942 res
= hdac_command(sc
, HDA_CMD_GET_PIN_SENSE(cad
,
5946 "PIN_SENSE: nid=%-3d timeout=%d res=0x%08x [%s]\n",
5947 w
->nid
, timeout
, res
,
5948 (w
->enable
== 0) ? "DISABLED" : "ENABLED");
5951 "NumGPIO=%d NumGPO=%d NumGPI=%d GPIWake=%d GPIUnsol=%d\n",
5952 HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo
->function
.audio
.gpio
),
5953 HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo
->function
.audio
.gpio
),
5954 HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo
->function
.audio
.gpio
),
5955 HDA_PARAM_GPIO_COUNT_GPI_WAKE(devinfo
->function
.audio
.gpio
),
5956 HDA_PARAM_GPIO_COUNT_GPI_UNSOL(devinfo
->function
.audio
.gpio
));
5957 if (HDA_PARAM_GPIO_COUNT_NUM_GPI(devinfo
->function
.audio
.gpio
) > 0) {
5958 device_printf(dev
, " GPI:");
5959 res
= hdac_command(sc
,
5960 HDA_CMD_GET_GPI_DATA(cad
, devinfo
->nid
), cad
);
5961 kprintf(" data=0x%08x", res
);
5962 res
= hdac_command(sc
,
5963 HDA_CMD_GET_GPI_WAKE_ENABLE_MASK(cad
, devinfo
->nid
),
5965 kprintf(" wake=0x%08x", res
);
5966 res
= hdac_command(sc
,
5967 HDA_CMD_GET_GPI_UNSOLICITED_ENABLE_MASK(cad
, devinfo
->nid
),
5969 kprintf(" unsol=0x%08x", res
);
5970 res
= hdac_command(sc
,
5971 HDA_CMD_GET_GPI_STICKY_MASK(cad
, devinfo
->nid
), cad
);
5972 kprintf(" sticky=0x%08x\n", res
);
5974 if (HDA_PARAM_GPIO_COUNT_NUM_GPO(devinfo
->function
.audio
.gpio
) > 0) {
5975 device_printf(dev
, " GPO:");
5976 res
= hdac_command(sc
,
5977 HDA_CMD_GET_GPO_DATA(cad
, devinfo
->nid
), cad
);
5978 kprintf(" data=0x%08x\n", res
);
5980 if (HDA_PARAM_GPIO_COUNT_NUM_GPIO(devinfo
->function
.audio
.gpio
) > 0) {
5981 device_printf(dev
, "GPI0:");
5982 res
= hdac_command(sc
,
5983 HDA_CMD_GET_GPIO_DATA(cad
, devinfo
->nid
), cad
);
5984 kprintf(" data=0x%08x", res
);
5985 res
= hdac_command(sc
,
5986 HDA_CMD_GET_GPIO_ENABLE_MASK(cad
, devinfo
->nid
), cad
);
5987 kprintf(" enable=0x%08x", res
);
5988 res
= hdac_command(sc
,
5989 HDA_CMD_GET_GPIO_DIRECTION(cad
, devinfo
->nid
), cad
);
5990 kprintf(" direction=0x%08x\n", res
);
5991 res
= hdac_command(sc
,
5992 HDA_CMD_GET_GPIO_WAKE_ENABLE_MASK(cad
, devinfo
->nid
), cad
);
5993 device_printf(dev
, " wake=0x%08x", res
);
5994 res
= hdac_command(sc
,
5995 HDA_CMD_GET_GPIO_UNSOLICITED_ENABLE_MASK(cad
, devinfo
->nid
),
5997 kprintf(" unsol=0x%08x", res
);
5998 res
= hdac_command(sc
,
5999 HDA_CMD_GET_GPIO_STICKY_MASK(cad
, devinfo
->nid
), cad
);
6000 kprintf(" sticky=0x%08x\n", res
);
6009 hdac_attach2(void *arg
)
6011 struct hdac_softc
*sc
;
6012 struct hdac_widget
*w
;
6013 struct hdac_audio_ctl
*ctl
;
6014 uint32_t quirks_on
, quirks_off
;
6017 char status
[SND_STATUSLEN
];
6018 device_t
*devlist
= NULL
;
6020 struct hdac_devinfo
*devinfo
= NULL
;
6022 sc
= (struct hdac_softc
*)arg
;
6024 hdac_config_fetch(sc
, &quirks_on
, &quirks_off
);
6027 device_printf(sc
->dev
, "HDA_DEBUG: HDA Config: on=0x%08x off=0x%08x\n",
6028 quirks_on
, quirks_off
);
6033 /* Remove ourselves from the config hooks */
6034 if (sc
->intrhook
.ich_func
!= NULL
) {
6035 config_intrhook_disestablish(&sc
->intrhook
);
6036 sc
->intrhook
.ich_func
= NULL
;
6039 /* Start the corb and rirb engines */
6041 device_printf(sc
->dev
, "HDA_DEBUG: Starting CORB Engine...\n");
6043 hdac_corb_start(sc
);
6045 device_printf(sc
->dev
, "HDA_DEBUG: Starting RIRB Engine...\n");
6047 hdac_rirb_start(sc
);
6050 device_printf(sc
->dev
,
6051 "HDA_DEBUG: Enabling controller interrupt...\n");
6053 if (sc
->polling
== 0)
6054 HDAC_WRITE_4(&sc
->mem
, HDAC_INTCTL
,
6055 HDAC_INTCTL_CIE
| HDAC_INTCTL_GIE
);
6056 HDAC_WRITE_4(&sc
->mem
, HDAC_GCTL
, HDAC_READ_4(&sc
->mem
, HDAC_GCTL
) |
6062 device_printf(sc
->dev
, "HDA_DEBUG: Scanning HDA codecs...\n");
6064 hdac_scan_codecs(sc
);
6066 device_get_children(sc
->dev
, &devlist
, &devcount
);
6067 for (i
= 0; devlist
!= NULL
&& i
< devcount
; i
++) {
6068 devinfo
= (struct hdac_devinfo
*)device_get_ivars(devlist
[i
]);
6069 if (devinfo
!= NULL
&& devinfo
->node_type
==
6070 HDA_PARAM_FCT_GRP_TYPE_NODE_TYPE_AUDIO
) {
6075 if (devlist
!= NULL
)
6076 kfree(devlist
, M_TEMP
);
6078 if (devinfo
== NULL
) {
6080 device_printf(sc
->dev
, "Audio Function Group not found!\n");
6081 hdac_release_resources(sc
);
6086 device_printf(sc
->dev
,
6087 "HDA_DEBUG: Parsing AFG nid=%d cad=%d\n",
6088 devinfo
->nid
, devinfo
->codec
->cad
);
6090 hdac_audio_parse(devinfo
);
6092 device_printf(sc
->dev
, "HDA_DEBUG: Parsing Ctls...\n");
6094 hdac_audio_ctl_parse(devinfo
);
6096 device_printf(sc
->dev
, "HDA_DEBUG: Parsing vendor patch...\n");
6098 hdac_vendor_patch_parse(devinfo
);
6100 devinfo
->function
.audio
.quirks
|= quirks_on
;
6101 if (quirks_off
!= 0)
6102 devinfo
->function
.audio
.quirks
&= ~quirks_off
;
6104 /* XXX Disable all DIGITAL path. */
6105 for (i
= devinfo
->startnode
; i
< devinfo
->endnode
; i
++) {
6106 w
= hdac_widget_get(devinfo
, i
);
6109 if (HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w
->param
.widget_cap
)) {
6113 /* XXX Disable useless pin ? */
6114 if (w
->type
== HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX
&&
6115 (w
->wclass
.pin
.config
&
6116 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_MASK
) ==
6117 HDA_CONFIG_DEFAULTCONF_CONNECTIVITY_NONE
)
6121 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) != NULL
) {
6122 if (ctl
->widget
== NULL
)
6124 if (ctl
->ossmask
& SOUND_MASK_DISABLE
)
6127 if (w
->enable
== 0 ||
6128 HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w
->param
.widget_cap
))
6130 w
= ctl
->childwidget
;
6133 if (w
->enable
== 0 ||
6134 HDA_PARAM_AUDIO_WIDGET_CAP_DIGITAL(w
->param
.widget_cap
))
6139 device_printf(sc
->dev
, "HDA_DEBUG: Building AFG tree...\n");
6141 hdac_audio_build_tree(devinfo
);
6144 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) != NULL
) {
6145 if (ctl
->ossmask
& (SOUND_MASK_SKIP
| SOUND_MASK_DISABLE
))
6149 device_printf(sc
->dev
, "HDA_DEBUG: AFG commit...\n");
6151 hdac_audio_commit(devinfo
, HDA_COMMIT_ALL
);
6153 device_printf(sc
->dev
, "HDA_DEBUG: Ctls commit...\n");
6155 hdac_audio_ctl_commit(devinfo
);
6158 device_printf(sc
->dev
, "HDA_DEBUG: PCMDIR_PLAY setup...\n");
6160 pcnt
= hdac_pcmchannel_setup(devinfo
, PCMDIR_PLAY
);
6162 device_printf(sc
->dev
, "HDA_DEBUG: PCMDIR_REC setup...\n");
6164 rcnt
= hdac_pcmchannel_setup(devinfo
, PCMDIR_REC
);
6168 device_printf(sc
->dev
,
6169 "HDA_DEBUG: OSS mixer initialization...\n");
6173 * There is no point of return after this. If the driver failed,
6174 * so be it. Let the detach procedure do all the cleanup.
6176 if (mixer_init(sc
->dev
, &hdac_audio_ctl_ossmixer_class
, devinfo
) != 0)
6177 device_printf(sc
->dev
, "Can't register mixer\n");
6185 device_printf(sc
->dev
,
6186 "HDA_DEBUG: Registering PCM channels...\n");
6188 if (pcm_register(sc
->dev
, devinfo
, pcnt
, rcnt
) != 0)
6189 device_printf(sc
->dev
, "Can't register PCM\n");
6193 if ((devinfo
->function
.audio
.quirks
& HDA_QUIRK_DMAPOS
) &&
6194 hdac_dma_alloc(sc
, &sc
->pos_dma
,
6195 (sc
->num_iss
+ sc
->num_oss
+ sc
->num_bss
) * 8) != 0) {
6197 device_printf(sc
->dev
,
6198 "Failed to allocate DMA pos buffer (non-fatal)\n");
6202 for (i
= 0; i
< pcnt
; i
++)
6203 pcm_addchan(sc
->dev
, PCMDIR_PLAY
, &hdac_channel_class
, devinfo
);
6204 for (i
= 0; i
< rcnt
; i
++)
6205 pcm_addchan(sc
->dev
, PCMDIR_REC
, &hdac_channel_class
, devinfo
);
6207 #ifdef SND_DYNSYSCTL
6208 SYSCTL_ADD_PROC(snd_sysctl_tree(sc
->dev
),
6209 SYSCTL_CHILDREN(snd_sysctl_tree_top(sc
->dev
)), OID_AUTO
,
6210 "polling", CTLTYPE_INT
| CTLFLAG_RW
, sc
->dev
, sizeof(sc
->dev
),
6211 sysctl_hdac_polling
, "I", "Enable polling mode");
6212 SYSCTL_ADD_PROC(snd_sysctl_tree(sc
->dev
),
6213 SYSCTL_CHILDREN(snd_sysctl_tree_top(sc
->dev
)), OID_AUTO
,
6214 "polling_interval", CTLTYPE_INT
| CTLFLAG_RW
, sc
->dev
,
6215 sizeof(sc
->dev
), sysctl_hdac_polling_interval
, "I",
6216 "Controller/Jack Sense polling interval (1-1000 ms)");
6218 SYSCTL_ADD_PROC(snd_sysctl_tree(sc
->dev
),
6219 SYSCTL_CHILDREN(snd_sysctl_tree_top(sc
->dev
)), OID_AUTO
,
6220 "pindump", CTLTYPE_INT
| CTLFLAG_RW
, sc
->dev
, sizeof(sc
->dev
),
6221 sysctl_hdac_pindump
, "I", "Dump pin states/data");
6225 ksnprintf(status
, SND_STATUSLEN
, "at memory 0x%lx irq %ld %s [%s]",
6226 rman_get_start(sc
->mem
.mem_res
), rman_get_start(sc
->irq
.irq_res
),
6227 PCM_KLDSTRING(snd_hda
), HDA_DRV_TEST_REV
);
6228 pcm_setstatus(sc
->dev
, status
);
6229 device_printf(sc
->dev
, "<HDA Codec: %s>\n", hdac_codec_name(devinfo
));
6231 device_printf(sc
->dev
, "<HDA Codec ID: 0x%08x>\n",
6232 hdac_codec_id(devinfo
));
6234 device_printf(sc
->dev
, "<HDA Driver Revision: %s>\n",
6238 if (devinfo
->function
.audio
.quirks
!= 0) {
6239 device_printf(sc
->dev
, "\n");
6240 device_printf(sc
->dev
, "HDA config/quirks:");
6241 for (i
= 0; i
< HDAC_QUIRKS_TAB_LEN
; i
++) {
6242 if ((devinfo
->function
.audio
.quirks
&
6243 hdac_quirks_tab
[i
].value
) ==
6244 hdac_quirks_tab
[i
].value
)
6245 kprintf(" %s", hdac_quirks_tab
[i
].key
);
6249 device_printf(sc
->dev
, "\n");
6250 device_printf(sc
->dev
, "+-------------------+\n");
6251 device_printf(sc
->dev
, "| DUMPING HDA NODES |\n");
6252 device_printf(sc
->dev
, "+-------------------+\n");
6253 hdac_dump_nodes(devinfo
);
6254 device_printf(sc
->dev
, "\n");
6255 device_printf(sc
->dev
, "+------------------------+\n");
6256 device_printf(sc
->dev
, "| DUMPING HDA AMPLIFIERS |\n");
6257 device_printf(sc
->dev
, "+------------------------+\n");
6258 device_printf(sc
->dev
, "\n");
6260 while ((ctl
= hdac_audio_ctl_each(devinfo
, &i
)) != NULL
) {
6261 device_printf(sc
->dev
, "%3d: nid=%d", i
,
6262 (ctl
->widget
!= NULL
) ? ctl
->widget
->nid
: -1);
6263 if (ctl
->childwidget
!= NULL
)
6264 kprintf(" cnid=%d", ctl
->childwidget
->nid
);
6265 kprintf(" dir=0x%x index=%d "
6266 "ossmask=0x%08x ossdev=%d%s\n",
6267 ctl
->dir
, ctl
->index
,
6268 ctl
->ossmask
, ctl
->ossdev
,
6269 (ctl
->enable
== 0) ? " [DISABLED]" : "");
6271 device_printf(sc
->dev
, "\n");
6272 device_printf(sc
->dev
, "+-----------------------------------+\n");
6273 device_printf(sc
->dev
, "| DUMPING HDA AUDIO/VOLUME CONTROLS |\n");
6274 device_printf(sc
->dev
, "+-----------------------------------+\n");
6275 hdac_dump_ctls(devinfo
, "Master Volume (OSS: vol)", SOUND_MASK_VOLUME
);
6276 hdac_dump_ctls(devinfo
, "PCM Volume (OSS: pcm)", SOUND_MASK_PCM
);
6277 hdac_dump_ctls(devinfo
, "CD Volume (OSS: cd)", SOUND_MASK_CD
);
6278 hdac_dump_ctls(devinfo
, "Microphone Volume (OSS: mic)", SOUND_MASK_MIC
);
6279 hdac_dump_ctls(devinfo
, "Line-in Volume (OSS: line)", SOUND_MASK_LINE
);
6280 hdac_dump_ctls(devinfo
, "Recording Level (OSS: rec)", SOUND_MASK_RECLEV
);
6281 hdac_dump_ctls(devinfo
, "Speaker/Beep (OSS: speaker)", SOUND_MASK_SPEAKER
);
6282 hdac_dump_ctls(devinfo
, NULL
, 0);
6283 hdac_dump_dac(devinfo
);
6284 hdac_dump_adc(devinfo
);
6285 device_printf(sc
->dev
, "\n");
6286 device_printf(sc
->dev
, "+--------------------------------------+\n");
6287 device_printf(sc
->dev
, "| DUMPING PCM Playback/Record Channels |\n");
6288 device_printf(sc
->dev
, "+--------------------------------------+\n");
6289 hdac_dump_pcmchannels(sc
, pcnt
, rcnt
);
6292 if (sc
->polling
!= 0) {
6294 callout_reset(&sc
->poll_hdac
, 1, hdac_poll_callback
, sc
);
6299 /****************************************************************************
6300 * int hdac_detach(device_t)
6302 * Detach and free up resources utilized by the hdac device.
6303 ****************************************************************************/
6305 hdac_detach(device_t dev
)
6307 struct hdac_softc
*sc
= NULL
;
6308 struct hdac_devinfo
*devinfo
= NULL
;
6311 devinfo
= (struct hdac_devinfo
*)pcm_getdevinfo(dev
);
6312 if (devinfo
!= NULL
&& devinfo
->codec
!= NULL
)
6313 sc
= devinfo
->codec
->sc
;
6317 if (sc
->registered
> 0) {
6318 err
= pcm_unregister(dev
);
6323 hdac_release_resources(sc
);
6328 static device_method_t hdac_methods
[] = {
6329 /* device interface */
6330 DEVMETHOD(device_probe
, hdac_probe
),
6331 DEVMETHOD(device_attach
, hdac_attach
),
6332 DEVMETHOD(device_detach
, hdac_detach
),
6336 static driver_t hdac_driver
= {
6342 DRIVER_MODULE(snd_hda
, pci
, hdac_driver
, pcm_devclass
, 0, 0);
6343 MODULE_DEPEND(snd_hda
, sound
, SOUND_MINVER
, SOUND_PREFVER
, SOUND_MAXVER
);
6344 MODULE_VERSION(snd_hda
, 1);