xref: /illumos-gate/usr/src/uts/common/io/audio/drv/audiohd/audiohd.h (revision a4faba164aa153855d621c694fc5aa75dd183b81)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 #ifndef _SYS_AUDIOHD_IMPL_H_
26 #define	_SYS_AUDIOHD_IMPL_H_
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 /*
33  * vendor IDs of PCI audio controllers
34  */
35 #define	AUDIOHD_VID_INTEL	0x8086
36 #define	AUDIOHD_VID_ATI		0x1002
37 #define	AUDIOHD_VID_NVIDIA	0x10de
38 #define	AUDIOHD_VID_SIGMATEL	0x8384
39 
40 /*
41  * specific codec id used by specific vendors
42  */
43 #define	AUDIOHD_CODEC_IDT7608	0x111d7608
44 #define	AUDIOHD_CODEC_IDT76B2	0x111d76b2
45 #define	AUDIOHD_CODEC_AD1981	0x11d41981
46 #define	AUDIOHD_CODECID_ALC888	0x10ec0888
47 #define	AUDIOHD_CODECID_SONY1	0x10ec0260
48 #define	AUDIOHD_CODECID_SONY2	0x10ec0262
49 
50 #define	AUDIOHD_INTS		50
51 #define	AUDIOHD_MAX_INTS	1500
52 #define	AUDIOHD_MIN_INTS	32
53 
54 #define	AUDIOHD_DEV_CONFIG	"onboard1"
55 #define	AUDIOHD_DEV_VERSION	"a"
56 
57 #define	AUDIOHD_FMT_PCM		0x001
58 /*
59  * Only for Intel hardware:
60  * PCI Express traffic class select register in PCI configure space
61  */
62 #define	AUDIOHD_INTEL_PCI_TCSEL 0x44
63 
64 /*
65  * Only for ATI SB450:
66  * MISC control register 2
67  */
68 #define	AUDIOHD_ATI_PCI_MISC2	0x42
69 #define	AUDIOHD_ATI_MISC2_SNOOP	0x02
70 #define	AUDIOHDC_NID(x)		x
71 #define	AUDIOHDC_NULL_NODE	-1
72 #define	AUDIOHD_NULL_CONN	((uint_t)(-1))
73 /*
74  * currently, only the format of 48K sample rate, 16-bit
75  * 2-channel is supported.
76  */
77 #define	AUDIOHD_FMT_PCMOUT	0x0011
78 #define	AUDIOHD_FMT_PCMIN	0x0011
79 
80 #define	AUDIOHD_EXT_AMP_MASK	0x00010000
81 #define	AUDIOHD_EXT_AMP_ENABLE	0x02
82 /* NVIDIA snoop */
83 #define	AUDIOHD_NVIDIA_SNOOP	0x0f
84 
85 /* Power On/Off */
86 #define	AUDIOHD_PW_OFF		1
87 #define	AUDIOHD_PW_ON		0
88 #define	AUDIOHD_PW_D0		0
89 #define	AUDIOHD_PW_D2		2
90 
91 #define	AUDIOHD_INTEL_TCS_MASK	0xf8
92 #define	AUDIOHD_ATI_MISC2_MASK	0xf8
93 
94 /* Pin speaker On/Off */
95 #define	AUDIOHD_SP_ON		1
96 #define	AUDIOHD_SP_OFF		0
97 
98 #define	AUDIOHD_PORT_MAX		15
99 #define	AUDIOHD_CODEC_MAX	16
100 #define	AUDIOHD_MEMIO_LEN	0x4000
101 
102 #define	AUDIOHD_RETRY_TIMES	60
103 #define	AUDIOHD_TEST_TIMES	500
104 #define	AUDIOHD_OUTSTR_NUM_OFF	12
105 #define	AUDIOHD_INSTR_NUM_OFF	8
106 
107 #define	AUDIOHD_CORB_SIZE_OFF	0x4e
108 
109 #define	AUDIOHD_URCAP_MASK	0x80
110 #define	AUDIOHD_DTCCAP_MASK	0x4
111 #define	AUDIOHD_UR_ENABLE_OFF	8
112 #define	AUDIOHD_UR_TAG_MASK	0x1f
113 
114 #define	AUDIOHD_CIS_MASK	0x40000000
115 
116 #define	AUDIOHD_RIRB_UR_MASK	0x10
117 #define	AUDIOHD_RIRB_CODEC_MASK	0xf
118 #define	AUDIOHD_RIRB_WID_OFF	27
119 #define	AUDIOHD_RIRB_INTRCNT	0x0
120 #define	AUDIOHD_RIRB_WPMASK	0xff
121 
122 #define	AUDIOHD_FORM_MASK	0x0080
123 #define	AUDIOHD_LEN_MASK	0x007f
124 #define	AUDIOHD_PIN_CAP_MASK	0x00000010
125 #define	AUDIOHD_PIN_CONF_MASK	0xc0000000
126 #define	AUDIOHD_PIN_CON_MASK	3
127 #define	AUDIOHD_PIN_CON_STEP	30
128 #define	AUDIOHD_PIN_IO_MASK	0X0018
129 #define	AUDIOHD_PIN_SEQ_MASK	0x0000000f
130 #define	AUDIOHD_PIN_ASO_MASK	0x000000f0
131 #define	AUDIOHD_PIN_ASO_OFF	0x4
132 #define	AUDIOHD_PIN_DEV_MASK	0x00f00000
133 #define	AUDIOHD_PIN_DEV_OFF	20
134 #define	AUDIOHD_PIN_NUMS	6
135 #define	AUDIOHD_PIN_NO_CONN	0x40000000
136 #define	AUDIOHD_PIN_IN_ENABLE	0x20
137 #define	AUDIOHD_PIN_OUT_ENABLE	0x40
138 #define	AUDIOHD_PIN_PRES_OFF	0x20
139 #define	AUDIOHD_PIN_CONTP_OFF	0x1e
140 #define	AUDIOHD_PIN_CON_JACK	0
141 #define	AUDIOHD_PIN_CON_FIXED	0x2
142 #define	AUDIOHD_PIN_CONTP_MASK	0x3
143 #define	AUDIOHD_PIN_VREF_L1	0x20
144 #define	AUDIOHD_PIN_VREF_L2	0x10
145 #define	AUDIOHD_PIN_VREF_L3	0x04
146 #define	AUDIOHD_PIN_VREF_L4	0x02
147 #define	AUDIOHD_PIN_VREF_OFF	8
148 #define	AUDIOHD_PIN_VREF_MASK	0xff
149 #define	AUDIOHD_PIN_CLR_MASK		0xf
150 #define	AUDIOHD_PIN_CLR_OFF		12
151 
152 
153 #define	AUDIOHD_VERB_ADDR_OFF	28
154 #define	AUDIOHD_VERB_NID_OFF	20
155 #define	AUDIOHD_VERB_CMD_OFF	8
156 #define	AUDIOHD_VERB_CMD16_OFF	16
157 
158 #define	AUDIOHD_RING_MAX_SIZE	0x00ff
159 #define	AUDIOHD_POS_MASK	~0x00000003
160 #define	AUDIOHD_REC_TAG_OFF	4
161 #define	AUDIOHD_PLAY_TAG_OFF	4
162 #define	AUDIOHD_PLAY_CTL_OFF	2
163 #define	AUDIOHD_REC_CTL_OFF	2
164 
165 #define	AUDIOHD_SPDIF_ON	1
166 #define	AUDIOHD_SPDIF_MASK	0x00ff
167 
168 #define	AUDIOHD_GAIN_OFF	8
169 
170 #define	AUDIOHD_CODEC_STR_OFF	16
171 #define	AUDIOHD_CODEC_STR_MASK	0x000000ff
172 #define	AUDIOHD_CODEC_NUM_MASK	0x000000ff
173 #define	AUDIOHD_CODEC_TYPE_MASK	0x000000ff
174 
175 #define	AUDIOHD_FRAGFR_ALIGN	16
176 #define	AUDIOHD_BDLE_BUF_ALIGN	128
177 #define	AUDIOHD_CMDIO_ENT_MASK	0x00ff	/* 256 entries for CORB/RIRB */
178 #define	AUDIOHD_CDBIO_CORB_LEN	1024	/* 256 entries for CORB, 1024B */
179 #define	AUDIOHD_CDBIO_RIRB_LEN	2048	/* 256 entries for RIRB, 2048B */
180 #define	AUDIOHD_BDLE_NUMS	4	/* 4 entires for record/play BD list */
181 
182 #define	AUDIOHD_PORT_UNMUTE	(0xffffffff)
183 
184 /*
185  * Audio registers of high definition
186  */
187 #define	AUDIOHD_REG_GCAP		0x00
188 #define	AUDIOHDR_GCAP_OUTSTREAMS	0xf000
189 #define	AUDIOHDR_GCAP_INSTREAMS		0x0f00
190 #define	AUDIOHDR_GCAP_BSTREAMS		0x00f8
191 #define	AUDIOHDR_GCAP_NSDO		0x0006
192 #define	AUDIOHDR_GCAP_64OK		0x0001
193 
194 #define	AUDIOHD_REG_VMIN		0x02
195 #define	AUDIOHD_REG_VMAJ		0x03
196 #define	AUDIOHD_REG_OUTPAY		0x04
197 #define	AUDIOHD_REG_INPAY		0x06
198 #define	AUDIOHD_REG_GCTL		0x08
199 #define	AUDIOHD_REG_WAKEEN		0x0C
200 #define	AUDIOHD_REG_STATESTS		0x0E
201 #define	AUDIOHD_STATESTS_BIT_SDINS	0x7F
202 
203 #define	AUDIOHD_REG_GSTS		0x10
204 #define	AUDIOHD_REG_INTCTL		0x20
205 #define	AUDIOHD_INTCTL_BIT_GIE		0x80000000
206 #define	AUDIOHD_INTCTL_BIT_CIE		0x40000000
207 #define	AUDIOHD_INTCTL_BIT_SIE		0x3FFFFFFF
208 
209 
210 #define	AUDIOHD_REG_INTSTS		0x24
211 #define	AUDIOHD_INTSTS_BIT_GIS		0x80000000
212 #define	AUDIOHD_INTSTS_BIT_CIS		0x40000000
213 #define	AUDIOHD_INTSTS_BIT_SINTS	(0x3fffffff)
214 
215 #define	AUDIOHD_REG_WALCLK		0x30
216 #define	AUDIOHD_REG_SYNC		0x38
217 
218 #define	AUDIOHD_REG_CORBLBASE		0x40
219 #define	AUDIOHD_REG_CORBUBASE		0x44
220 #define	AUDIOHD_REG_CORBWP		0x48
221 #define	AUDIOHD_REG_CORBRP		0x4A
222 #define	AUDIOHD_REG_CORBCTL		0x4C
223 #define	AUDIOHD_REG_CORBST		0x4D
224 #define	AUDIOHD_REG_CORBSIZE		0x4E
225 
226 #define	AUDIOHD_REG_RIRBLBASE		0x50
227 #define	AUDIOHD_REG_RIRBUBASE		0x54
228 #define	AUDIOHD_REG_RIRBWP		0x58
229 #define	AUDIOHD_REG_RINTCNT		0x5A
230 #define	AUDIOHD_REG_RIRBCTL		0x5C
231 #define	AUDIOHD_REG_RIRBSTS		0x5D
232 #define	AUDIOHD_REG_RIRBSIZE		0x5E
233 
234 #define	AUDIOHD_REG_IC			0x60
235 #define	AUDIOHD_REG_IR			0x64
236 #define	AUDIOHD_REG_IRS			0x68
237 #define	AUDIOHD_REG_DPLBASE		0x70
238 #define	AUDIOHD_REG_DPUBASE		0x74
239 
240 #define	AUDIOHD_REG_SD_BASE		0x80
241 #define	AUDIOHD_REG_SD_LEN		0x20
242 
243 /*
244  * Offset of Stream Descriptor Registers
245  */
246 #define	AUDIOHD_SDREG_OFFSET_CTL		0x00
247 #define	AUDIOHD_SDREG_OFFSET_STS		0x03
248 #define	AUDIOHD_SDREG_OFFSET_LPIB		0x04
249 #define	AUDIOHD_SDREG_OFFSET_CBL		0x08
250 #define	AUDIOHD_SDREG_OFFSET_LVI		0x0c
251 #define	AUDIOHD_SDREG_OFFSET_FIFOW		0x0e
252 #define	AUDIOHD_SDREG_OFFSET_FIFOSIZE		0x10
253 #define	AUDIOHD_SDREG_OFFSET_FORMAT		0x12
254 #define	AUDIOHD_SDREG_OFFSET_BDLPL		0x18
255 #define	AUDIOHD_SDREG_OFFSET_BDLPU		0x1c
256 
257 /* bits for stream descriptor control reg */
258 #define	AUDIOHDR_SD_CTL_DEIE		0x000010
259 #define	AUDIOHDR_SD_CTL_FEIE		0x000008
260 #define	AUDIOHDR_SD_CTL_IOCE		0x000004
261 #define	AUDIOHDR_SD_CTL_SRUN		0x000002
262 #define	AUDIOHDR_SD_CTL_SRST		0x000001
263 #define	AUDIOHDR_SD_CTL_INTS	\
264 	(AUDIOHDR_SD_CTL_DEIE |	\
265 	AUDIOHDR_SD_CTL_FEIE |	\
266 	AUDIOHDR_SD_CTL_IOCE)
267 
268 
269 /* bits for stream descriptor status register */
270 #define	AUDIOHDR_SD_STS_BCIS		0x0004
271 #define	AUDIOHDR_SD_STS_FIFOE		0x0008
272 #define	AUDIOHDR_SD_STS_DESE		0x0010
273 #define	AUDIOHDR_SD_STS_FIFORY		0x0020
274 #define	AUDIOHDR_SD_STS_INTRS	\
275 	(AUDIOHDR_SD_STS_BCIS | \
276 	AUDIOHDR_SD_STS_FIFOE |	\
277 	AUDIOHDR_SD_STS_DESE)
278 
279 
280 /* bits for GCTL register */
281 #define	AUDIOHDR_GCTL_CRST		0x00000001
282 #define	AUDIOHDR_GCTL_URESPE		0x00000100
283 
284 /* bits for CORBRP register */
285 #define	AUDIOHDR_CORBRP_RESET		0x8000
286 #define	AUDIOHDR_CORBRP_WPTR		0x00ff
287 
288 /* bits for CORBCTL register */
289 #define	AUDIOHDR_CORBCTL_CMEIE		0x01
290 #define	AUDIOHDR_CORBCTL_DMARUN		0x02
291 
292 /* bits for CORB SIZE register */
293 #define	AUDIOHDR_CORBSZ_8		0
294 #define	AUDIOHDR_CORBSZ_16		1
295 #define	AUDIOHDR_CORBSZ_256		2
296 
297 /* bits for RIRBCTL register */
298 #define	AUDIOHDR_RIRBCTL_RINTCTL	0x01
299 #define	AUDIOHDR_RIRBCTL_DMARUN		0x02
300 #define	AUDIOHDR_RIRBCTL_RIRBOIC	0x04
301 #define	AUDIOHDR_RIRBCTL_RSTINT		0xfe
302 
303 /* bits for RIRBWP register */
304 #define	AUDIOHDR_RIRBWP_RESET		0x8000
305 #define	AUDIOHDR_RIRBWP_WPTR		0x00ff
306 
307 /* bits for RIRB SIZE register */
308 #define	AUDIOHDR_RIRBSZ_8		0
309 #define	AUDIOHDR_RIRBSZ_16		1
310 #define	AUDIOHDR_RIRBSZ_256		2
311 
312 #define	AUDIOHD_BDLE_RIRB_SDI		0x0000000f
313 #define	AUDIOHD_BDLE_RIRB_UNSOLICIT	0x00000010
314 
315 /* HD spec: ID of Root node is 0 */
316 #define	AUDIOHDC_NODE_ROOT		0x00
317 
318 /* HD spec: ID of audio function group is "1" */
319 #define	AUDIOHDC_AUDIO_FUNC_GROUP	1
320 
321 /*
322  * HD audio verbs can be either 12-bit or 4-bit in length.
323  */
324 #define	AUDIOHDC_12BIT_VERB_MASK	0xfffff000
325 #define	AUDIOHDC_4BIT_VERB_MASK		0xfffffff0
326 
327 #define	AUDIOHDC_SAMPR48000		48000
328 #define	AUDIOHDC_MAX_BEEP_GEN		12000
329 #define	AUDIOHDC_MIX_BEEP_GEN		47
330 #define	AUDIOHDC_MUTE_BEEP_GEN		0x0
331 
332 /*
333  * 12-bit verbs
334  */
335 #define	AUDIOHDC_VERB_GET_PARAM			0xf00
336 
337 #define	AUDIOHDC_VERB_GET_CONN_SEL		0xf01
338 #define	AUDIOHDC_VERB_SET_CONN_SEL		0x701
339 
340 #define	AUDIOHDC_VERB_GET_CONN_LIST_ENT		0xf02
341 #define	AUDIOHDC_VERB_GET_PROCESS_STATE		0xf03
342 #define	AUDIOHDC_VERB_GET_SDI_SEL		0xf04
343 
344 #define	AUDIOHDC_VERB_GET_POWER_STATE		0xf05
345 #define	AUDIOHDC_VERB_SET_POWER_STATE		0x705
346 
347 #define	AUDIOHDC_VERB_GET_STREAM_CHANN		0xf06
348 #define	AUDIOHDC_VERB_SET_STREAM_CHANN		0x706
349 
350 #define	AUDIOHDC_VERB_GET_PIN_CTRL		0xf07
351 #define	AUDIOHDC_VERB_SET_PIN_CTRL		0x707
352 
353 #define	AUDIOHDC_VERB_GET_UNS_ENABLE		0xf08
354 
355 #define	AUDIOHDC_VERB_GET_PIN_SENSE		0xf09
356 #define	AUDIOHDC_VERB_EXEC_PIN_SENSE		0x709
357 
358 #define	AUDIOHDC_VERB_GET_BEEP_GEN		0xf0a
359 #define	AUDIOHDC_VERB_SET_BEEP_GEN		0x70a
360 
361 #define	AUDIOHDC_VERB_GET_EAPD			0xf0c
362 #define	AUDIOHDC_VERB_SET_EAPD			0x70c
363 
364 #define	AUDIOHDC_VERB_GET_DEFAULT_CONF		0xf1c
365 #define	AUDIOHDC_VERB_GET_SPDIF_CTL		0xf0d
366 #define	AUDIOHDC_VERB_SET_SPDIF_LCL		0x70d
367 
368 #define	AUDIOHDC_VERB_SET_URCTRL		0x708
369 #define	AUDIOHDC_VERB_GET_PIN_SENSE		0xf09
370 
371 #define	AUDIOHDC_VERB_GET_GPIO_MASK		0xf16
372 #define	AUDIOHDC_VERB_SET_GPIO_MASK		0x716
373 
374 #define	AUDIOHDC_VERB_GET_GPIO_DIREC		0xf17
375 #define	AUDIOHDC_VERB_SET_GPIO_DIREC		0x717
376 
377 #define	AUDIOHDC_VERB_GET_GPIO_DATA		0xf15
378 #define	AUDIOHDC_VERB_SET_GPIO_DATA		0x715
379 
380 #define	AUDIOHDC_VERB_GET_GPIO_STCK		0xf1a
381 #define	AUDIOHDC_VERB_SET_GPIO_STCK		0x71a
382 
383 #define	AUDIOHDC_GPIO_ENABLE			0xff
384 #define	AUDIOHDC_GPIO_DIRECT			0xf1
385 
386 #define	AUDIOHDC_GPIO_DATA_CTRL			0xff
387 #define	AUDIOHDC_GPIO_STCK_CTRL			0xff
388 /*
389  * 4-bit verbs
390  */
391 #define	AUDIOHDC_VERB_GET_CONV_FMT		0xa
392 #define	AUDIOHDC_VERB_SET_CONV_FMT		0x2
393 
394 #define	AUDIOHDC_VERB_GET_AMP_MUTE		0xb
395 #define	AUDIOHDC_VERB_SET_AMP_MUTE		0x3
396 #define	AUDIOHDC_VERB_SET_BEEP_VOL		0x3A0
397 
398 /*
399  * parameters of nodes
400  */
401 #define	AUDIOHDC_PAR_VENDOR_ID			0x00
402 #define	AUDIOHDC_PAR_SUBSYS_ID			0x01
403 #define	AUDIOHDC_PAR_REV_ID			0x02
404 #define	AUDIOHDC_PAR_NODE_COUNT			0x04
405 #define	AUDIOHDC_PAR_FUNCTION_TYPE		0x05
406 #define	AUDIOHDC_PAR_AUDIO_FG_CAP		0x08
407 #define	AUDIOHDC_PAR_AUDIO_WID_CAP		0x09
408 #define	AUDIOHDC_PAR_PCM			0x0a
409 #define	AUDIOHDC_PAR_STREAM			0x0b
410 #define	AUDIOHDC_PAR_PIN_CAP			0x0c
411 #define	AUDIOHDC_PAR_INAMP_CAP			0x0d
412 #define	AUDIOHDC_PAR_CONNLIST_LEN		0x0e
413 #define	AUDIOHDC_PAR_POWER_STATE		0x0f
414 #define	AUDIOHDC_PAR_PROC_CAP			0x10
415 #define	AUDIOHDC_PAR_GPIO_CAP			0x11
416 #define	AUDIOHDC_PAR_OUTAMP_CAP			0x12
417 
418 /*
419  * bits for get/set amplifier gain/mute
420  */
421 #define	AUDIOHDC_AMP_SET_OUTPUT			0x8000
422 #define	AUDIOHDC_AMP_SET_INPUT			0x4000
423 #define	AUDIOHDC_AMP_SET_LEFT			0x2000
424 #define	AUDIOHDC_AMP_SET_RIGHT			0x1000
425 #define	AUDIOHDC_AMP_SET_MUTE			0x0080
426 #define	AUDIOHDC_AMP_SET_LNR			0x3000
427 #define	AUDIOHDC_AMP_SET_LR_INPUT		0x7000
428 #define	AUDIOHDC_AMP_SET_LR_OUTPUT		0xb000
429 #define	AUDIOHDC_AMP_SET_INDEX_OFFSET		8
430 #define	AUDIOHDC_AMP_SET_GAIN_MASK		0x007f
431 #define	AUDIOHDC_GAIN_MAX			0x7f
432 #define	AUDIOHDC_GAIN_BITS			7
433 #define	AUDIOHDC_GAIN_DEFAULT			0x0f
434 
435 #define	AUDIOHDC_AMP_GET_OUTPUT			0x8000
436 #define	AUDIOHDC_AMP_GET_INPUT			0x0000
437 
438 /* value used to set max volume for left output */
439 #define	AUDIOHDC_AMP_LOUT_MAX	\
440 	(AUDIOHDC_AMP_SET_OUTPUT | \
441 	AUDIOHDC_AMP_SET_LEFT | \
442 	AUDIOHDC_GAIN_MAX)
443 
444 /* value used to set max volume for right output */
445 #define	AUDIOHDC_AMP_ROUT_MAX	\
446 	(AUDIOHDC_AMP_SET_OUTPUT | \
447 	AUDIOHDC_AMP_SET_RIGHT | \
448 	AUDIOHDC_GAIN_MAX)
449 
450 
451 /*
452  * Bits for pin widget control verb
453  */
454 #define	AUDIOHDC_PIN_CONTROL_HP_ENABLE		0x80
455 #define	AUDIOHDC_PIN_CONTROL_OUT_ENABLE		0x40
456 #define	AUDIOHDC_PIN_CONTROL_IN_ENABLE		0x20
457 
458 /*
459  * Bits for Amplifier capabilities
460  */
461 #define	AUDIOHDC_AMP_CAP_MUTE_CAP		0x80000000
462 #define	AUDIOHDC_AMP_CAP_STEP_SIZE		0x007f0000
463 #define	AUDIOHDC_AMP_CAP_STEP_NUMS		0x00007f00
464 #define	AUDIOHDC_AMP_CAP_0DB_OFFSET		0x0000007f
465 
466 
467 /*
468  * Bits for Audio Widget Capabilities
469  */
470 #define	AUDIOHD_WIDCAP_STEREO		0x00000001
471 #define	AUDIOHD_WIDCAP_INAMP		0x00000002
472 #define	AUDIOHD_WIDCAP_OUTAMP		0x00000004
473 #define	AUDIOHD_WIDCAP_AMP_OVRIDE	0x00000008
474 #define	AUDIOHD_WIDCAP_FMT_OVRIDE	0x00000010
475 #define	AUDIOHD_WIDCAP_STRIP		0x00000020
476 #define	AUDIOHD_WIDCAP_PROC_WID		0x00000040
477 #define	AUDIOHD_WIDCAP_UNSOL		0x00000080
478 #define	AUDIOHD_WIDCAP_CONNLIST		0x00000100
479 #define	AUDIOHD_WIDCAP_DIGIT		0x00000200
480 #define	AUDIOHD_WIDCAP_PWRCTRL		0x00000400
481 #define	AUDIOHD_WIDCAP_LRSWAP		0x00000800
482 #define	AUDIOHD_WIDCAP_TYPE		0x00f00000
483 #define	AUDIOHD_WIDCAP_TO_WIDTYPE(wcap)		\
484 	((wcap & AUDIOHD_WIDCAP_TYPE) >> 20)
485 
486 
487 #define	AUDIOHD_CODEC_FAILURE	(uint32_t)(-1)
488 
489 /*
490  * buffer descriptor list entry of stream descriptor
491  */
492 typedef struct {
493 	uint64_t	sbde_addr;
494 	uint32_t	sbde_len;
495 	uint32_t
496 		sbde_ioc: 1,
497 		reserved: 31;
498 }sd_bdle_t;
499 
500 
501 #define	AUDIOHD_PLAY_STARTED		0x00000001
502 #define	AUDIOHD_PLAY_EMPTY		0x00000002
503 #define	AUDIOHD_PLAY_PAUSED		0x00000004
504 #define	AUDIOHD_RECORD_STARTED		0x00000008
505 
506 enum audiohda_widget_type {
507 	WTYPE_AUDIO_OUT = 0,
508 	WTYPE_AUDIO_IN,
509 	WTYPE_AUDIO_MIX,
510 	WTYPE_AUDIO_SEL,
511 	WTYPE_PIN,
512 	WTYPE_POWER,
513 	WTYPE_VOL_KNOB,
514 	WTYPE_BEEP,
515 	WTYPE_VENDOR = 0xf
516 };
517 
518 enum audiohda_device_type {
519 	DTYPE_LINEOUT = 0,
520 	DTYPE_SPEAKER,
521 	DTYPE_HP_OUT,
522 	DTYPE_CD,
523 	DTYPE_SPDIF_OUT,
524 	DTYPE_DIGIT_OUT,
525 	DTYPE_MODEM_SIDE,
526 	DTYPE_MODEM_HNAD_SIDE,
527 	DTYPE_LINE_IN,
528 	DTYPE_AUX,
529 	DTYPE_MIC_IN,
530 	DTYPE_TEL,
531 	DTYPE_SPDIF_IN,
532 	DTYPE_DIGIT_IN,
533 	DTYPE_OTHER = 0x0f,
534 };
535 
536 enum audiohd_pin_color {
537 	AUDIOHD_PIN_UNKNOWN = 0,
538 	AUDIOHD_PIN_BLACK,
539 	AUDIOHD_PIN_GREY,
540 	AUDIOHD_PIN_BLUE,
541 	AUDIOHD_PIN_GREEN,
542 	AUDIOHD_PIN_RED,
543 	AUDIOHD_PIN_ORANGE,
544 	AUDIOHD_PIN_YELLOW,
545 	AUDIOHD_PIN_PURPLE,
546 	AUDIOHD_PIN_PINK,
547 	AUDIOHD_PIN_WHITE = 0xe,
548 	AUDIOHD_PIN_OTHER = 0xf,
549 };
550 
551 #define	CTRL_NUM	16
552 
553 /* values for audiohd_widget.path_flags */
554 #define	AUDIOHD_PATH_DAC	(1 << 0)
555 #define	AUDIOHD_PATH_ADC	(1 << 1)
556 #define	AUDIOHD_PATH_MON	(1 << 2)
557 #define	AUDIOHD_PATH_NOMON	(1 << 3)
558 #define	AUDIOHD_PATH_BEEP	(1 << 4)
559 
560 typedef struct audiohd_path		audiohd_path_t;
561 typedef struct audiohd_widget	audiohd_widget_t;
562 typedef struct audiohd_state	audiohd_state_t;
563 typedef struct audiohd_pin	audiohd_pin_t;
564 typedef struct hda_codec	hda_codec_t;
565 typedef uint32_t	wid_t;		/* id of widget */
566 typedef	struct audiohd_entry_prop	audiohd_entry_prop_t;
567 typedef	enum audiohda_device_type	audiohda_device_type_t;
568 typedef	enum audiohd_pin_color		audiohd_pin_color_t;
569 
570 #define	AUDIOHD_MAX_WIDGET		128
571 #define	AUDIOHD_MAX_CONN		16
572 #define	AUDIOHD_MAX_PINS		16
573 #define	AUDIOHD_MAX_DEPTH		8
574 
575 struct audiohd_entry_prop {
576 	uint32_t	conn_len;
577 	uint32_t	mask_range;
578 	uint32_t	mask_wid;
579 	wid_t		input_wid;
580 	int		conns_per_entry;
581 	int		bits_per_conn;
582 };
583 struct audiohd_widget {
584 	wid_t		wid_wid;
585 	hda_codec_t	*codec;
586 	enum audiohda_widget_type type;
587 
588 	uint32_t	widget_cap;
589 	uint32_t	pcm_format;
590 	uint32_t	inamp_cap;
591 	uint32_t	outamp_cap;
592 
593 	uint32_t	path_flags;
594 
595 	int		out_weight;
596 	int		in_weight;
597 	int		finish;
598 
599 	/*
600 	 * wid of possible & selected input connections
601 	 */
602 	wid_t		avail_conn[AUDIOHD_MAX_CONN];
603 	wid_t		selconn;
604 	/*
605 	 * for monitor path
606 	 */
607 	wid_t		selmon[AUDIOHD_MAX_CONN];
608 	uint16_t 	used;
609 
610 	/*
611 	 * available (input) connections. 0 means this widget
612 	 * has fixed connection
613 	 */
614 	int		nconns;
615 
616 	/*
617 	 * pointer to struct depending on widget type:
618 	 *	1. DAC	audiohd_ostream_t
619 	 *	2. ADC	audiohd_istream_t
620 	 *	3. PIN	audiohd_pin_t
621 	 */
622 	void	*priv;
623 };
624 
625 #define	AUDIOHD_FLAG_LINEOUT		(1 << 0)
626 #define	AUDIOHD_FLAG_SPEAKER		(1 << 1)
627 #define	AUDIOHD_FLAG_HP			(1 << 2)
628 #define	AUDIOHD_FLAG_MONO		(1 << 3)
629 
630 #define	AUDIOHD_MAX_MIXER		5
631 #define	AUDIOHD_MAX_PIN			4
632 
633 #define	PORT_DAC		0
634 #define	PORT_ADC		1
635 #define	PORT_MAX		2
636 typedef enum {
637 	PLAY = 0,
638 	RECORD = 1,
639 	BEEP = 2,
640 } path_type_t;
641 
642 struct audiohd_path {
643 	wid_t			adda_wid;
644 	wid_t			beep_wid;
645 
646 	wid_t			pin_wid[AUDIOHD_MAX_PINS];
647 	int			sum_selconn[AUDIOHD_MAX_PINS];
648 	int			mon_wid[AUDIOHD_MAX_PIN][AUDIOHD_MAX_MIXER];
649 	int			pin_nums;
650 	int			maxmixer[AUDIOHD_MAX_PINS];
651 
652 	path_type_t		path_type;
653 
654 	wid_t			mute_wid;
655 	int			mute_dir;
656 	wid_t			gain_wid;
657 	int			gain_dir;
658 	uint32_t		gain_bits;
659 
660 	uint32_t		pin_outputs;
661 	uint8_t			tag;
662 
663 	hda_codec_t		*codec;
664 
665 	wid_t			sum_wid;
666 
667 	audiohd_state_t		*statep;
668 };
669 
670 typedef struct audiohd_port
671 {
672 	uint8_t			nchan;
673 	int			index;
674 	uint16_t		regoff;
675 	boolean_t		started;
676 	boolean_t		triggered;
677 
678 	unsigned		fragfr;
679 	unsigned		nframes;
680 	uint64_t		count;
681 	int			curpos;
682 	int			intrs;
683 
684 	uint_t			format;
685 	unsigned		sync_dir;
686 
687 	ddi_dma_handle_t	samp_dmah;
688 	ddi_acc_handle_t	samp_acch;
689 	size_t			samp_size;
690 	caddr_t			samp_kaddr;
691 	uint64_t		samp_paddr;
692 
693 	ddi_dma_handle_t	bdl_dmah;
694 	ddi_acc_handle_t	bdl_acch;
695 	size_t			bdl_size;
696 	caddr_t			bdl_kaddr;
697 	uint64_t		bdl_paddr;
698 
699 	audio_engine_t		*engine;
700 	audiohd_state_t		*statep;
701 }audiohd_port_t;
702 
703 typedef struct audiohd_ctrl
704 {
705 	audiohd_state_t		*statep;
706 	audio_ctrl_t		*ctrl;
707 	uint32_t		num;
708 	uint64_t		val;
709 } audiohd_ctrl_t;
710 
711 struct audiohd_pin {
712 	audiohd_pin_t	*next;
713 	wid_t		wid;
714 	wid_t		mute_wid;	/* node used to mute this pin */
715 	int		mute_dir;	/* 1: input, 2: output */
716 	wid_t		gain_wid;	/* node for gain control */
717 	int		gain_dir;	/* _OUTPUT/_INPUT */
718 	uint32_t	gain_bits;
719 
720 	uint8_t		vrefvalue;	/* value of VRef */
721 
722 	uint32_t	cap;
723 	uint32_t	config;
724 	uint32_t	ctrl;
725 	uint32_t	assoc;
726 	uint32_t	seq;
727 	wid_t		adc_dac_wid; /* AD/DA wid which can route to this pin */
728 	wid_t		beep_wid;
729 	int		no_phys_conn;
730 	enum audiohda_device_type	device;
731 
732 	/*
733 	 * mg_dir, mg_gain, mg_wid are used to store the monitor gain control
734 	 * widget wid.
735 	 */
736 	int		mg_dir[AUDIOHD_MAX_CONN];
737 	int		mg_gain[AUDIOHD_MAX_CONN];
738 	int		mg_wid[AUDIOHD_MAX_CONN];
739 	int		num;
740 	int		finish;
741 
742 };
743 
744 typedef struct {
745 	ddi_dma_handle_t	ad_dmahdl;
746 	ddi_acc_handle_t	ad_acchdl;
747 	caddr_t			ad_vaddr;	/* virtual addr */
748 	uint64_t		ad_paddr;	/* physical addr */
749 	size_t			ad_req_sz;	/* required size of memory */
750 	size_t			ad_real_sz;	/* real size of memory */
751 } audiohd_dma_t;
752 
753 struct hda_codec {
754 	uint8_t		index;		/* codec address */
755 	uint32_t	vid;		/* vendor id and device id */
756 	uint32_t	revid;		/* revision id */
757 	wid_t		wid_afg;	/* id of AFG */
758 	wid_t		first_wid;	/* wid of 1st subnode of AFG */
759 	wid_t		last_wid;	/* wid of the last subnode of AFG */
760 	int		nnodes;		/* # of subnodes of AFG */
761 	uint8_t		nistream;
762 
763 	uint32_t	outamp_cap;
764 	uint32_t	inamp_cap;
765 	uint32_t	stream_format;
766 	uint32_t	pcm_format;
767 
768 	audiohd_state_t		*soft_statep;
769 
770 	/* use wid as index to the array of widget pointers */
771 	audiohd_widget_t	*widget[AUDIOHD_MAX_WIDGET];
772 
773 
774 	audiohd_port_t		*port[AUDIOHD_PORT_MAX];
775 	uint8_t			portnum;
776 	audiohd_pin_t		*first_pin;
777 };
778 
779 #define	AUDIOHD_MAX_ASSOC	15
780 struct audiohd_state {
781 	dev_info_t	*hda_dip;
782 	kstat_t		*hda_ksp;
783 	kmutex_t	hda_mutex;
784 	uint32_t	hda_flags;
785 
786 	boolean_t	soft_volume;
787 	boolean_t	intr_added;
788 
789 	caddr_t				hda_reg_base;
790 	ddi_acc_handle_t		hda_pci_handle;
791 	ddi_acc_handle_t		hda_reg_handle;
792 
793 	ddi_intr_handle_t 	*htable; 	/* For array of interrupts */
794 	int			intr_type;	/* What type of interrupt */
795 	int			intr_rqst;	/* # of request intrs count */
796 	int			intr_cnt;	/* # of intrs count returned */
797 	uint_t			intr_pri;	/* Interrupt priority */
798 	int			intr_cap;	/* Interrupt capabilities */
799 	boolean_t		msi_enable;
800 
801 	audiohd_dma_t	hda_dma_corb;
802 	audiohd_dma_t	hda_dma_rirb;
803 
804 
805 	uint8_t		hda_rirb_rp;		/* read pointer for rirb */
806 	uint16_t	hda_codec_mask;
807 
808 
809 	audio_dev_t	*adev;
810 
811 
812 	int		hda_pint_freq;	/* play intr frequence */
813 	int		hda_rint_freq;	/* record intr frequence */
814 
815 	int		hda_input_streams;	/* # of input stream */
816 	int		hda_output_streams;	/* # of output stream */
817 	int		hda_streams_nums;	/* # of stream */
818 
819 	uint_t		hda_play_regbase;
820 	uint_t		hda_record_regbase;
821 
822 	uint_t		hda_play_stag;		/* tag of playback stream */
823 	uint_t		hda_record_stag;	/* tag of record stream */
824 	uint_t		hda_play_lgain;		/* left gain for playback */
825 	uint_t		hda_play_rgain;		/* right gain for playback */
826 
827 	/*
828 	 * Now, for the time being, we add some fields
829 	 * for parsing codec topology
830 	 */
831 	hda_codec_t	*codec[AUDIOHD_CODEC_MAX];
832 	/*
833 	 * Suspend/Resume used fields
834 	 */
835 	boolean_t	suspended;
836 	boolean_t	monitor_unsupported;
837 
838 	audiohd_path_t	*path[AUDIOHD_PORT_MAX];
839 	uint8_t		pathnum;
840 	audiohd_port_t	*port[PORT_MAX];
841 	uint8_t		pchan;
842 	uint8_t		rchan;
843 
844 	uint64_t	inmask;
845 
846 	uint_t		hda_out_ports;
847 	uint_t		in_port;
848 
849 	/*
850 	 * Controls
851 	 */
852 	audiohd_ctrl_t		*controls[CTRL_NUM];
853 
854 	/* for multichannel */
855 	uint8_t			chann[AUDIOHD_MAX_ASSOC];
856 	uint8_t			assoc;
857 
858 };
859 
860 
861 /*
862  * Operation for high definition audio control system bus
863  * interface registers
864  */
865 #define	AUDIOHD_REG_GET8(reg)	\
866 	ddi_get8(statep->hda_reg_handle, \
867 	(void *)((char *)statep->hda_reg_base + (reg)))
868 
869 #define	AUDIOHD_REG_GET16(reg)	\
870 	ddi_get16(statep->hda_reg_handle, \
871 	(void *)((char *)statep->hda_reg_base + (reg)))
872 
873 #define	AUDIOHD_REG_GET32(reg)	\
874 	ddi_get32(statep->hda_reg_handle, \
875 	(void *)((char *)statep->hda_reg_base + (reg)))
876 
877 #define	AUDIOHD_REG_GET64(reg)	\
878 	ddi_get64(statep->hda_reg_handle, \
879 	(void *)((char *)statep->hda_reg_base + (reg)))
880 
881 #define	AUDIOHD_REG_SET8(reg, val)	\
882 	ddi_put8(statep->hda_reg_handle, \
883 	(void *)((char *)statep->hda_reg_base + (reg)), (val))
884 
885 #define	AUDIOHD_REG_SET16(reg, val)	\
886 	ddi_put16(statep->hda_reg_handle, \
887 	(void *)((char *)statep->hda_reg_base + (reg)), (val))
888 
889 #define	AUDIOHD_REG_SET32(reg, val)	\
890 	ddi_put32(statep->hda_reg_handle, \
891 	(void *)((char *)statep->hda_reg_base + (reg)), (val))
892 
893 #define	AUDIOHD_REG_SET64(reg, val)	\
894 	ddi_put64(statep->hda_reg_handle, \
895 	(void *)((char *)statep->hda_reg_base + (reg)), (val))
896 
897 
898 /*
899  * enable a pin widget to output
900  */
901 #define	AUDIOHD_ENABLE_PIN_OUT(statep, caddr, wid) \
902 { \
903 	uint32_t	lTmp; \
904 \
905 	lTmp = audioha_codec_verb_get(statep, caddr, wid, \
906 	    AUDIOHDC_VERB_GET_PIN_CTRL, 0); \
907 	if (lTmp == AUDIOHD_CODEC_FAILURE) \
908 		return (DDI_FAILURE); \
909 	lTmp = audioha_codec_verb_get(statep, caddr, wid, \
910 	    AUDIOHDC_VERB_SET_PIN_CTRL, \
911 	    (lTmp | AUDIOHDC_PIN_CONTROL_OUT_ENABLE | \
912 	    AUDIOHDC_PIN_CONTROL_HP_ENABLE)); \
913 	if (lTmp == AUDIOHD_CODEC_FAILURE) \
914 		return (DDI_FAILURE); \
915 }
916 
917 /*
918  * disable output pin
919  */
920 #define	AUDIOHD_DISABLE_PIN_OUT(statep, caddr, wid) \
921 { \
922 	uint32_t	lTmp; \
923 \
924 	lTmp = audioha_codec_verb_get(statep, caddr, wid, \
925 	    AUDIOHDC_VERB_GET_PIN_CTRL, 0); \
926 	if (lTmp == AUDIOHD_CODEC_FAILURE) \
927 		return (DDI_FAILURE); \
928 	lTmp = audioha_codec_verb_get(statep, caddr, wid, \
929 	    AUDIOHDC_VERB_SET_PIN_CTRL, \
930 	    (lTmp & ~AUDIOHDC_PIN_CONTROL_OUT_ENABLE)); \
931 	if (lTmp == AUDIOHD_CODEC_FAILURE) \
932 		return (DDI_FAILURE); \
933 }
934 
935 /*
936  * enable a pin widget to input
937  */
938 #define	AUDIOHD_ENABLE_PIN_IN(statep, caddr, wid) \
939 { \
940 	(void) audioha_codec_verb_get(statep, caddr, wid, \
941 	    AUDIOHDC_VERB_SET_PIN_CTRL, AUDIOHDC_PIN_CONTROL_IN_ENABLE | 4); \
942 }
943 
944 
945 /*
946  * disable input pin
947  */
948 #define	AUDIOHD_DISABLE_PIN_IN(statep, caddr, wid) \
949 { \
950 	uint32_t	lTmp; \
951 \
952 	lTmp = audioha_codec_verb_get(statep, caddr, wid, \
953 	    AUDIOHDC_VERB_GET_PIN_CTRL, 0); \
954 	if (lTmp == AUDIOHD_CODEC_FAILURE) \
955 		return (DDI_FAILURE); \
956 	lTmp = audioha_codec_verb_get(statep, caddr, wid, \
957 	    AUDIOHDC_VERB_SET_PIN_CTRL, \
958 	    (lTmp & ~AUDIOHDC_PIN_CONTROL_IN_ENABLE)); \
959 	if (lTmp == AUDIOHD_CODEC_FAILURE) \
960 		return (DDI_FAILURE); \
961 }
962 
963 /*
964  * unmute an output pin
965  */
966 #define	AUDIOHD_NODE_UNMUTE_OUT(statep, caddr, wid) \
967 { \
968 	if (audioha_codec_4bit_verb_get(statep, \
969 	    caddr, wid, AUDIOHDC_VERB_SET_AMP_MUTE, \
970 	    AUDIOHDC_AMP_SET_LR_OUTPUT | AUDIOHDC_GAIN_MAX) == \
971 	    AUDIOHD_CODEC_FAILURE) \
972 		return (DDI_FAILURE); \
973 }
974 
975 #ifdef __cplusplus
976 }
977 #endif
978 
979 #endif	/* _SYS_AUDIOHD_IMPL_H_ */
980