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