Subversion Repositories Kolibri OS

Rev

Rev 9274 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3083 leency 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
5363 yogev_ezra 3
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
3083 leency 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
5048 Asper 8
format PE DLL native 0.05
9
section '.flat' code readable writable executable
3083 leency 10
 
11
DEBUG		equ 1
3498 mario79 12
FDEBUG		equ 0
3083 leency 13
DEBUG_IRQ	equ 0
14
 
5048 Asper 15
USE_SINGLE_MODE equ  0	 ; 1 = Single mode; 0 = Normal mode.
16
USE_UNSOL_EV	equ  1	 ; 1 = Use unsolicited events; 0 = Do not use unsolicited events.
3083 leency 17
 
6943 Asper 18
TEST_VERSION_NUMBER  equ '019a'
3083 leency 19
 
20
;Asper+ [
5048 Asper 21
SDO_TAG  equ 1	      ;Output stream tag id (any number except 0)
22
SDO_IDX  equ 4	      ;Output stream index
9285 punk_joker 23
;According to "Intel� I/O Controller Hub 6 (ICH6) High Definition Audio / AC �97 Programmer�s Reference Manual (PRM) May 2005 Document"
24
;and "Intel� I/O Controller Hub 6 (ICH6) Family Datasheet" SDO0=4,
3083 leency 25
;but according to "High Definition Audio Specification Revision 1.0a June 17, 2010" SDO0 depends on the number of SDIs.
26
 
5048 Asper 27
SDO_INT 	equ 1 shl SDO_IDX	;Output stream interrupt (must be power of 2)
28
SDO_OFS 	equ 0x80+(SDO_IDX*0x20) ;Output stream offset
3083 leency 29
;Asper+ ]
30
 
31
CURRENT_API	equ   0x0100	  ;1.00
32
COMPATIBLE_API	equ   0x0101	  ;1.01
33
API_VERSION	equ   (COMPATIBLE_API shl 16) or CURRENT_API
34
 
35
IRQ_REMAP	equ 0
36
IRQ_LINE	equ 0
37
 
38
CPU_FREQ	equ  2600d
39
 
40
; Vendors
41
VID_INTEL	  equ 0x8086
42
VID_NVIDIA	  equ 0x10DE
43
VID_ATI 	  equ 0x1002
44
VID_AMD 	  equ 0x1022
3170 hidnplayr 45
VID_VIA 	  equ 0x1106
3083 leency 46
VID_SIS 	  equ 0x1039
47
VID_ULI 	  equ 0x10B9
48
VID_CREATIVE	  equ 0x1102
49
VID_TERA	  equ 0x6549
50
VID_RDC 	  equ 0x17F3
51
VID_VMWARE	  equ 0x15AD
52
 
53
; Devices
54
; Intel
6299 serge 55
CTRL_INTEL_SCH2       equ  0x080a
6943 Asper 56
CTRL_INTEL_HPT	      equ  0x0c0c
6299 serge 57
CTRL_INTEL_0F04       equ  0x0F04
6943 Asper 58
CTRL_INTEL_CPT	      equ  0x1c20
59
CTRL_INTEL_PGB	      equ  0x1d20
6299 serge 60
CTRL_INTEL_PPT1       equ  0x1e20
61
CTRL_INTEL_2284       equ  0x2284
62
CTRL_INTEL_ICH6       equ  0x2668
63
CTRL_INTEL_63XXESB    equ  0x269a
64
CTRL_INTEL_ICH7       equ  0x27d8
65
CTRL_INTEL_ICH8       equ  0x284b
66
CTRL_INTEL_82801_UNK1 equ  0x2911
67
CTRL_INTEL_ICH9       equ  0x293e
68
CTRL_INTEL_ICH9_2     equ  0x293f
69
CTRL_INTEL_ICH10      equ  0x3a3e
70
CTRL_INTEL_ICH10_2    equ  0x3a6e
6943 Asper 71
CTRL_INTEL_PCH	      equ  0x3b56
6299 serge 72
CTRL_INTEL_PCH2       equ  0x3b57
6943 Asper 73
CTRL_INTEL_SCH	      equ  0x811b
74
CTRL_INTEL_LPT	      equ  0x8c20
6299 serge 75
CTRL_INTEL_8ca0       equ  0x8cA0
76
CTRL_INTEL_8d20       equ  0x8d20
77
CTRL_INTEL_8d21       equ  0x8d21
78
CTRL_INTEL_A1F0       equ  0xA1F0
79
CTRL_INTEL_A270       equ  0xA270
80
CTRL_INTEL_9C20       equ  0x9c20
81
CTRL_INTEL_9C21       equ  0x9c21
82
CTRL_INTEL_9CA0       equ  0x9cA0
83
CTRL_INTEL_A170       equ  0xA170
84
CTRL_INTEL_9D70       equ  0x9D70
85
CTRL_INTEL_5A98       equ  0x5A98
3083 leency 86
; Nvidia
87
CTRL_NVIDIA_MCP51	 equ  0x026c
88
CTRL_NVIDIA_MCP55	 equ  0x0371
89
CTRL_NVIDIA_MCP61_1	 equ  0x03e4
90
CTRL_NVIDIA_MCP61_2	 equ  0x03f0
91
CTRL_NVIDIA_MCP65_1	 equ  0x044a
92
CTRL_NVIDIA_MCP65_2	 equ  0x044b
93
CTRL_NVIDIA_MCP67_1	 equ  0x055c
94
CTRL_NVIDIA_MCP67_2	 equ  0x055d
95
CTRL_NVIDIA_MCP78_1	 equ  0x0774
96
CTRL_NVIDIA_MCP78_2	 equ  0x0775
97
CTRL_NVIDIA_MCP78_3	 equ  0x0776
98
CTRL_NVIDIA_MCP78_4	 equ  0x0777
99
CTRL_NVIDIA_MCP73_1	 equ  0x07fc
100
CTRL_NVIDIA_MCP73_2	 equ  0x07fd
101
CTRL_NVIDIA_MCP79_1	 equ  0x0ac0
102
CTRL_NVIDIA_MCP79_2	 equ  0x0ac1
103
CTRL_NVIDIA_MCP79_3	 equ  0x0ac2
104
CTRL_NVIDIA_MCP79_4	 equ  0x0ac3
105
CTRL_NVIDIA_0BE2	 equ  0x0be2
106
CTRL_NVIDIA_0BE3	 equ  0x0be3
107
CTRL_NVIDIA_0BE4	 equ  0x0be4
108
CTRL_NVIDIA_GT100	 equ  0x0be5
109
CTRL_NVIDIA_GT106	 equ  0x0be9
110
CTRL_NVIDIA_GT108	 equ  0x0bea
111
CTRL_NVIDIA_GT104	 equ  0x0beb
112
CTRL_NVIDIA_GT116	 equ  0x0bee
113
CTRL_NVIDIA_MCP89_1	 equ  0x0d94
114
CTRL_NVIDIA_MCP89_2	 equ  0x0d95
115
CTRL_NVIDIA_MCP89_3	 equ  0x0d96
116
CTRL_NVIDIA_MCP89_4	 equ  0x0d97
117
CTRL_NVIDIA_GF119	 equ  0x0e08
118
CTRL_NVIDIA_GF110_1	 equ  0x0e09
119
CTRL_NVIDIA_GF110_2	 equ  0x0e0c
120
; ATI
121
CTRL_ATI_SB450		 equ  0x437b
122
CTRL_ATI_SB600		 equ  0x4383
123
; ATI HDMI
124
CTRL_ATI_RS600		 equ  0x793b
125
CTRL_ATI_RS690		 equ  0x7919
126
CTRL_ATI_RS780		 equ  0x960f
127
CTRL_ATI_RS_UNK1	 equ  0x970f
128
CTRL_ATI_R600		 equ  0xaa00
129
CTRL_ATI_RV630		 equ  0xaa08
130
CTRL_ATI_RV610		 equ  0xaa10
131
CTRL_ATI_RV670		 equ  0xaa18
132
CTRL_ATI_RV635		 equ  0xaa20
133
CTRL_ATI_RV620		 equ  0xaa28
134
CTRL_ATI_RV770		 equ  0xaa30
135
CTRL_ATI_RV730		 equ  0xaa38
136
CTRL_ATI_RV710		 equ  0xaa40
137
CTRL_ATI_RV740		 equ  0xaa48
138
; AMD
139
CTRL_AMD_HUDSON 	 equ  0x780d
7737 dunkaist 140
CTRL_AMD_RAVEN_RIDGE	 equ  0x15e3
9285 punk_joker 141
CTRL_AMD_MATISSE	 equ  0x1487
3083 leency 142
; VIA
143
CTRL_VIA_VT82XX 	 equ  0x3288
144
CTRL_VIA_VT61XX 	 equ  0x9140
145
CTRL_VIA_VT71XX 	 equ  0x9170
146
; SiS
147
CTRL_SIS_966		 equ  0x7502
148
; ULI
149
CTRL_ULI_M5461		 equ  0x5461
150
; Creative
151
CTRL_CREATIVE_CA0110_IBG     equ  0x0009
152
CTRL_CREATIVE_SOUND_CORE3D_1 equ  0x0010
153
CTRL_CREATIVE_SOUND_CORE3D_2 equ  0x0012
154
; Teradici
155
CTRL_TERA_UNK1		 equ  0x1200
156
; RDC Semiconductor
157
CTRL_RDC_R3010		 equ  0x3010
158
;VMware
159
CTRL_VMWARE_UNK1	 equ  0x1977
160
 
161
 
162
; driver types
163
AZX_DRIVER_ICH		 equ  0
164
AZX_DRIVER_PCH		 equ  1
165
AZX_DRIVER_SCH		 equ  2
166
AZX_DRIVER_ATI		 equ  3
167
AZX_DRIVER_ATIHDMI	 equ  4
168
AZX_DRIVER_VIA		 equ  5
169
AZX_DRIVER_SIS		 equ  6
170
AZX_DRIVER_ULI		 equ  7
171
AZX_DRIVER_NVIDIA	 equ  8
172
AZX_DRIVER_TERA 	 equ  9
173
AZX_DRIVER_CTX		 equ  10
174
AZX_DRIVER_GENERIC	 equ  11
175
AZX_NUM_DRIVERS 	 equ  12
176
 
177
 
178
; registers
179
 
180
ICH6_REG_GCAP		 equ  0x00
181
ICH6_REG_VMIN		 equ  0x02
182
ICH6_REG_VMAJ		 equ  0x03
183
ICH6_REG_OUTPAY 	 equ  0x04
184
ICH6_REG_INPAY		 equ  0x06
185
ICH6_REG_GCTL		 equ  0x08
186
  ICH6_GCTL_RESET	   equ	(1 shl 0)  ; controller reset
187
  ICH6_GCTL_FCNTRL	   equ	(1 shl 1)  ; flush control
188
  ICH6_GCTL_UNSOL	   equ	(1 shl 8)  ; accept unsol. response enable
189
ICH6_REG_WAKEEN 	 equ  0x0c
190
ICH6_REG_STATESTS	 equ  0x0e
191
ICH6_REG_GSTS		 equ  0x10
192
  ICH6_GSTS_FSTS	   equ	(1 shl 1)  ; flush status
193
ICH6_REG_INTCTL 	 equ  0x20
194
ICH6_REG_INTSTS 	 equ  0x24
195
ICH6_REG_WALLCLK	 equ  0x30  ; 24Mhz source
196
ICH6_REG_OLD_SSYNC	 equ  0x34  ; SSYNC for old ICH
197
ICH6_REG_SSYNC		 equ  0x38
198
ICH6_REG_CORBLBASE	 equ  0x40
199
ICH6_REG_CORBUBASE	 equ  0x44
200
ICH6_REG_CORBWP 	 equ  0x48
201
ICH6_REG_CORBRP 	 equ  0x4A
202
  ICH6_CORBRP_RST	   equ	(1 shl 15)  ; read pointer reset
203
ICH6_REG_CORBCTL	 equ  0x4c
204
  ICH6_CORBCTL_RUN	   equ	(1 shl 1)   ; enable DMA
205
  ICH6_CORBCTL_CMEIE	   equ	(1 shl 0)   ; enable memory error irq
206
ICH6_REG_CORBSTS	 equ  0x4d
207
  ICH6_CORBSTS_CMEI	   equ	(1 shl 0)   ; memory error indication
208
ICH6_REG_CORBSIZE	 equ  0x4e
209
 
210
ICH6_REG_RIRBLBASE	 equ  0x50
211
ICH6_REG_RIRBUBASE	 equ  0x54
212
ICH6_REG_RIRBWP 	 equ  0x58
213
  ICH6_RIRBWP_RST	   equ	(1 shl 15)  ; write pointer reset
214
ICH6_REG_RINTCNT	 equ  0x5a
215
ICH6_REG_RIRBCTL	 equ  0x5c
216
  ICH6_RBCTL_IRQ_EN	   equ	(1 shl 0)   ; enable IRQ
217
  ICH6_RBCTL_DMA_EN	   equ	(1 shl 1)   ; enable DMA
218
  ICH6_RBCTL_OVERRUN_EN    equ	(1 shl 2)   ; enable overrun irq
219
ICH6_REG_RIRBSTS	 equ  0x5d
220
  ICH6_RBSTS_IRQ	   equ	(1 shl 0)   ; response irq
221
  ICH6_RBSTS_OVERRUN	   equ	(1 shl 2)   ; overrun irq
222
ICH6_REG_RIRBSIZE	 equ  0x5e
223
 
224
ICH6_REG_IC		 equ  0x60
225
ICH6_REG_IR		 equ  0x64
226
ICH6_REG_IRS		 equ  0x68
227
  ICH6_IRS_VALID	   equ	2
228
  ICH6_IRS_BUSY 	   equ	1
229
 
230
ICH6_REG_DPLBASE	 equ  0x70
231
ICH6_REG_DPUBASE	 equ  0x74
232
  ICH6_DPLBASE_ENABLE	   equ	1     ; Enable position buffer
233
 
234
; SD offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
235
SDI0_SD_OFFSET	  equ  0x80
236
SDI1_SD_OFFSET	  equ  0xA0
237
SDI2_SD_OFFSET	  equ  0xC0
238
SDI3_SD_OFFSET	  equ  0xE0
239
SDO0_SD_OFFSET	  equ  0x100
240
SDO1_SD_OFFSET	  equ  0x120
241
SDO2_SD_OFFSET	  equ  0X140
242
SDO3_SD_OFFSET	  equ  0x160
243
 
244
; stream register offsets from stream base
245
ICH6_REG_SD_CTL 	 equ  0x00
246
ICH6_REG_SD_STS 	 equ  0x03
247
ICH6_REG_SD_LPIB	 equ  0x04
248
ICH6_REG_SD_CBL 	 equ  0x08
249
ICH6_REG_SD_LVI 	 equ  0x0c
250
ICH6_REG_SD_FIFOW	 equ  0x0e
251
ICH6_REG_SD_FIFOSIZE	 equ  0x10
252
ICH6_REG_SD_FORMAT	 equ  0x12
253
ICH6_REG_SD_BDLPL	 equ  0x18
254
ICH6_REG_SD_BDLPU	 equ  0x1c
255
 
256
; PCI space
257
ICH6_PCIREG_TCSEL	 equ  0x44
258
 
259
; other constants
260
ICH6_RIRB_EX_UNSOL_EV	 equ   (1 shl 4)
261
 
262
; max number of SDs
263
MAX_ICH6_DEV		 equ  8
264
; max number of fragments - we may use more if allocating more pages for BDL
265
AZX_MAX_FRAG		 equ  (4096 / (MAX_ICH6_DEV * 16))
266
; max buffer size - no h/w limit, you can increase as you like
267
AZX_MAX_BUF_SIZE	 equ  (1024*1024*1024)
268
; max number of PCM devices per card
269
AZX_MAX_PCMS		 equ  8
270
 
271
; RIRB int mask: overrun[2], response[0]
272
RIRB_INT_RESPONSE	 equ  0x01
273
RIRB_INT_OVERRUN	 equ  0x04
274
RIRB_INT_MASK		 equ  0x05
275
 
276
; STATESTS int mask: SD2,SD1,SD0
277
STATESTS_INT_MASK	 equ  0x07
278
AZX_MAX_CODECS		 equ  4
279
 
280
; SD_CTL bits
281
SD_CTL_STREAM_RESET	 equ  0x01    ; stream reset bit
282
SD_CTL_DMA_START	 equ  0x02    ; stream DMA start bit
283
SD_CTL_STREAM_TAG_MASK	 equ  (0xf shl 20)
284
SD_CTL_STREAM_TAG_SHIFT  equ  20
285
 
286
; SD_CTL and SD_STS
287
SD_INT_DESC_ERR 	 equ  0x10    ; descriptor error interrupt
288
SD_INT_FIFO_ERR 	 equ  0x08    ; FIFO error interrupt
289
SD_INT_COMPLETE 	 equ  0x04    ; completion interrupt
290
SD_INT_MASK		 equ  (SD_INT_DESC_ERR or SD_INT_FIFO_ERR or SD_INT_COMPLETE)
291
 
292
; SD_STS
293
SD_STS_FIFO_READY	 equ  0x20    ; FIFO ready
294
 
295
; INTCTL and INTSTS
296
ICH6_INT_ALL_STREAM	 equ  0xff	      ; all stream interrupts
297
ICH6_INT_CTRL_EN	 equ  0x40000000      ; controller interrupt enable bit
298
ICH6_INT_GLOBAL_EN	 equ  0x80000000      ; global interrupt enable bit
299
 
300
; GCTL reset bit
301
ICH6_GCTL_RESET 	 equ  1
302
 
303
; CORB/RIRB control, read/write pointer
304
ICH6_RBCTL_DMA_EN	 equ  0x02    ; enable DMA
305
ICH6_RBCTL_IRQ_EN	 equ  0x01    ; enable IRQ
306
ICH6_RBRWP_CLR		 equ  0x8000  ; read/write pointer clear
307
; below are so far hardcoded - should read registers in future
308
ICH6_MAX_CORB_ENTRIES	 equ  256
309
ICH6_MAX_RIRB_ENTRIES	 equ  256
310
 
311
; position fix mode
5048 Asper 312
POS_FIX_AUTO		 equ  0
313
POS_FIX_LPIB		 equ  1
314
POS_FIX_POSBUF		 equ  2
315
POS_FIX_VIACOMBO	 equ  4
316
POS_FIX_COMBO		 equ  8
3083 leency 317
 
318
; Defines for ATI HD Audio support in SB450 south bridge
319
ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR   equ  0x42
320
ATI_SB450_HDAUDIO_ENABLE_SNOOP	    equ  0x02
321
 
322
; Defines for Nvidia HDA support
323
NVIDIA_HDA_TRANSREG_ADDR	    equ  0x4e
324
NVIDIA_HDA_ENABLE_COHBITS	    equ  0x0f
325
NVIDIA_HDA_ISTRM_COH		    equ  0x4d
326
NVIDIA_HDA_OSTRM_COH		    equ  0x4c
327
NVIDIA_HDA_ENABLE_COHBIT	    equ  0x01
328
 
329
; Defines for Intel SCH HDA snoop control
330
INTEL_SCH_HDA_DEVC		    equ  0x78
331
INTEL_SCH_HDA_DEVC_NOSNOOP	    equ  (0x1 shl 11)
332
 
333
; Define IN stream 0 FIFO size offset in VIA controller
334
VIA_IN_STREAM0_FIFO_SIZE_OFFSET     equ  0x90
335
; Define VIA HD Audio Device ID
336
VIA_HDAC_DEVICE_ID		    equ  0x3288
337
 
338
; HD Audio class code
339
PCI_CLASS_MULTIMEDIA_HD_AUDIO	    equ  0x0403
340
 
341
 
342
SRV_GETVERSION		 equ  0
343
DEV_PLAY		 equ  1
344
DEV_STOP		 equ  2
345
DEV_CALLBACK		 equ  3
346
DEV_SET_BUFF		 equ  4
347
DEV_NOTIFY		 equ  5
348
DEV_SET_MASTERVOL	 equ  6
349
DEV_GET_MASTERVOL	 equ  7
350
DEV_GET_INFO		 equ  8
351
DEV_GET_POS		 equ  9
352
DEV_SET_CHANNEL_VOLUME	 equ  10
353
DEV_GET_CHANNEL_VOLUME	 equ  11
354
;Asper: Non standard system service. For the tests only! [
355
DEV_EXEC_CODEC_CMD	 equ  100
356
;Asper: Non standard system service. For the tests only! ]
357
 
358
struc AC_CNTRL		    ;AC controller base class
5048 Asper 359
{
360
	.bus		    dd ?
361
	.devfn		    dd ?
3083 leency 362
 
5048 Asper 363
	.vendor 	    dw ?
364
	.dev_id 	    dw ?
365
	.pci_cmd	    dd ?
366
	.pci_stat	    dd ?
3083 leency 367
 
5048 Asper 368
	.ctrl_io_base	    dd ?
369
	.ctrl_mem_base	    dd ?
370
	.cfg_reg	    dd ?
371
	.int_line	    dd ?
3083 leency 372
 
5048 Asper 373
	.vendor_ids	    dd ?    ;vendor id string
374
	.ctrl_ids	    dd ?    ;hub id string
3083 leency 375
 
5048 Asper 376
	.buffer 	    dd ?
3083 leency 377
 
5048 Asper 378
	.notify_pos	    dd ?
379
	.notify_task	    dd ?
3083 leency 380
 
5048 Asper 381
	.lvi_reg	    dd ?
382
	.civ_val	    dd 1
383
	.user_callback	    dd ?
3083 leency 384
 
5048 Asper 385
	.ctrl_read8	    dd ?
386
	.ctrl_read16	    dd ?
387
	.ctrl_read32	    dd ?
3083 leency 388
 
5048 Asper 389
	.ctrl_write8	    dd ?
390
	.ctrl_write16	    dd ?
391
	.ctrl_write32	    dd ?
3083 leency 392
 
5048 Asper 393
	.codec_mask	    dd ?
394
	.rb		    dd ?
395
	.rirb_rp	    dw 0
396
	.rirb_wp	    dw 0
397
	.corb_rp	    dw 0
398
	.corb_wp	    dw 0
399
	.rirb_cmd	    dd 0
400
	.rirb_res	    dd 0
401
	.rirb_error	    dd 0
402
	.response_reset     dd 0
403
	.polling_mode	    db 0
404
	.poll_count	    db 0
405
	.posbuf 	    dd ?
406
	.start_wallclk	    dd ? ; start + minimum wallclk
407
	.period_wallclk     dd ? ; wallclk for period
408
	.position_fix	    db ?
3083 leency 409
}
410
 
411
struc CODEC		   ;Audio Chip base class
412
{
5048 Asper 413
	.addr		    dd ?    ; codec slot index (codec address)
414
	.afg		    dd ?    ; AFG node id
415
	.mfg		    dd ?    ; MFG node id
3083 leency 416
 
5048 Asper 417
	.function_id	    dd ?
418
	.subsystem_id	    dd ?
419
	.revision_id	    dd ?
420
	.chip_id	    dw ?
421
	.vendor_id	    dw ?
3083 leency 422
 
5048 Asper 423
	; widget capabilities cache
424
	.num_nodes	    dw ?
425
	.start_nid	    dw ?
426
	.wcaps		    dd ?
3083 leency 427
 
5048 Asper 428
	.init_pins	    dd ?    ; initial (BIOS) pin configurations
429
	.num_pins	    dd ?    ;Asper +  : word is enough, but for align...
430
	.beeper_nid	    dw ?
431
		      .pad  dw ?
3083 leency 432
 
5048 Asper 433
	.ac_vendor_ids	    dd ?    ;ac vendor id string
434
	.chip_ids	    dd ?    ;chip model string
3083 leency 435
}
436
 
437
struc CTRL_INFO
5048 Asper 438
{
439
	.pci_cmd	    dd ?
440
	.irq		    dd ?
441
	.glob_cntrl	    dd ?
442
	.glob_sta	    dd ?
443
	.codec_io_base	    dd ?
444
	.ctrl_io_base	    dd ?
445
	.codec_mem_base     dd ?
446
	.ctrl_mem_base	    dd ?
447
	.codec_id	    dd ?
3083 leency 448
}
449
 
450
struc IOCTL
5048 Asper 451
{
452
	.handle 	    dd ?
453
	.io_code	    dd ?
454
	.input		    dd ?
455
	.inp_size	    dd ?
456
	.output 	    dd ?
457
	.out_size	    dd ?
3083 leency 458
}
459
 
460
EVENT_NOTIFY	equ 0x00000200
461
 
3496 Asper 462
; Macroses by CleverMouse
463
; The following macro assume that we are on uniprocessor machine.
464
; Serious work is needed for multiprocessor machines.
465
macro spin_lock_irqsave spinlock
466
{
467
	pushf
468
	cli
469
}
470
macro spin_unlock_irqrestore spinlock
471
{
472
	popf
473
}
474
macro spin_lock_irq spinlock
475
{
476
	cli
477
}
478
macro spin_unlock_irq spinlock
479
{
480
	sti
481
}
482
 
483
SPINLOCK_BUSY = 1
484
SPINLOCK_FREE = 0
485
 
486
macro spin_lock
487
{
488
	push	eax ebx
489
	mov	eax, aspinlock
490
	mov	ebx, SPINLOCK_BUSY
5048 Asper 491
@@:
3496 Asper 492
	lock	xchg [eax], ebx
493
	cmp	ebx, SPINLOCK_FREE
494
	jnz	@b
495
	pop	ebx eax
496
}
497
 
498
macro spin_unlock
499
{
500
	push	eax ebx
501
	mov	eax, aspinlock
502
	mov	eax, aspinlock
503
	mov	ebx, SPINLOCK_FREE
5048 Asper 504
	lock	xchg	[eax], ebx
3496 Asper 505
	pop	ebx eax
506
}
507
 
5048 Asper 508
data fixups
509
end data
3083 leency 510
 
5048 Asper 511
include '../../struct.inc'
512
include '../../macros.inc'
513
include '../../proc32.inc'
514
include '../../peimport.inc'
515
include 'CODEC_H.INC'
3083 leency 516
 
5048 Asper 517
entry START
3083 leency 518
 
5077 clevermous 519
;proc START c, reason:dword, cmdline:dword
520
proc START
5048 Asper 521
	push	ebx esi ; save used registers to be stdcall
522
virtual at esp
523
		rd	2 ; saved registers
524
		dd	? ; return address
525
.reason 	dd	? ; DRV_ENTRY or DRV_EXIT
526
.cmdline	dd	? ; normally NULL
527
end virtual
528
; 1. Check the reason for the call, do nothing unless initializing.
5077 clevermous 529
	cmp	[.reason], DRV_ENTRY
530
	jne	.stop
3083 leency 531
 
5048 Asper 532
if DEBUG
533
	mov	esi, msgTV
534
	invoke	SysMsgBoardStr
3083 leency 535
 
5048 Asper 536
	mov	esi, msgInit
537
	invoke	SysMsgBoardStr
538
end if
3083 leency 539
 
5048 Asper 540
	call	detect_controller
541
	test	eax, eax
542
	jz	.fail
3083 leency 543
 
5048 Asper 544
	mov	esi,[ctrl.vendor_ids]
545
	invoke	SysMsgBoardStr
546
	mov	esi, [ctrl.ctrl_ids]
547
	invoke	SysMsgBoardStr
3083 leency 548
 
5048 Asper 549
	call	init_controller
550
	test	eax, eax
551
	jz	.fail
3083 leency 552
 
553
;Asper This part is from "azx_create" proc. [
5048 Asper 554
	mov	[ctrl.position_fix], POS_FIX_LPIB
555
	cmp	[driver_type], AZX_DRIVER_VIA
556
	je	.set_via_patch
557
	cmp	[driver_type], AZX_DRIVER_ATI
558
	jne	.no_via_patch
559
.set_via_patch:
560
	or	[ctrl.position_fix], POS_FIX_VIACOMBO
561
.no_via_patch:
562
	; codec detection
563
	mov	eax, [ctrl.codec_mask]
564
	test	eax, eax
565
	jnz	@f
566
if DEBUG
567
	mov	esi, msgNoCodecsFound
568
	jmp	.fail_msg
569
else
570
	jmp	.fail
571
end if
572
@@:
3083 leency 573
;Asper ]
574
 
5048 Asper 575
	mov	esi, msgPrimBuff
576
	invoke	SysMsgBoardStr
577
	call	create_primary_buff
578
	mov	esi, msgDone
579
	invoke	SysMsgBoardStr
3083 leency 580
 
5048 Asper 581
if IRQ_REMAP
582
	pushf
583
	cli
3083 leency 584
 
5048 Asper 585
	mov	ebx, [ctrl.int_line]
586
	in	al, 0xA1
587
	mov	ah, al
588
	in	al, 0x21
589
	test	ebx, ebx
590
	jz	.skip
591
	bts	ax, bx			;mask old line
3083 leency 592
.skip
5048 Asper 593
	bts	ax, IRQ_LINE		;mask new line
594
	out	0x21, al
595
	mov	al, ah
596
	out	0xA1, al
3083 leency 597
					   ;remap IRQ
5048 Asper 598
	invoke	PciWrite8, 0, 0xF8, 0x61, IRQ_LINE
3083 leency 599
 
5048 Asper 600
	mov	dx, 0x4d0		;8259 ELCR1
601
	in	al, dx
602
	bts	ax, IRQ_LINE
603
	out	dx, al			;set level-triggered mode
604
	mov	[ctrl.int_line], IRQ_LINE
605
	popf
606
	mov	esi, msgRemap
607
	invoke	SysMsgBoardStr
608
end if
3083 leency 609
 
5048 Asper 610
	mov	ebx, [ctrl.int_line]
611
	invoke	AttachIntHandler, ebx, hda_irq, dword 0
3083 leency 612
 
613
;Asper This part is from "azx_probe" proc. [
5048 Asper 614
	call	azx_codec_create
615
	cmp	eax, 0
616
	jl	.fail
3083 leency 617
 
5048 Asper 618
	call	azx_codec_configure
619
	cmp	eax, 0
620
	jl	.fail
3083 leency 621
;] Asper
622
 
5048 Asper 623
	; create PCM streams
3083 leency 624
;Asper+ [
5048 Asper 625
	mov	eax, [spec.dac_node]
626
if DEBUG ;-
627
	push	eax esi
628
	mov	esi, msgVal
629
	invoke	SysMsgBoardStr
630
	stdcall  fdword2str, 3
631
	invoke	SysMsgBoardStr
632
	pop	esi eax
633
end if
3083 leency 634
 
5048 Asper 635
	test	eax, eax
636
	jz	.fail
637
	mov	ebx, [spec.dac_node+4]
638
if DEBUG ;-
639
	push	eax esi
640
	mov	esi, msgVal
641
	invoke	SysMsgBoardStr
642
	mov	eax, [spec.dac_node+4]
643
	stdcall fdword2str, 3
644
	invoke	SysMsgBoardStr
645
	pop	esi eax
646
end if
3083 leency 647
 
5048 Asper 648
	test	ebx, ebx
649
	jz	@f
650
	cmp	eax, ebx
651
	je	@f
652
	stdcall hda_codec_setup_stream, ebx, SDO_TAG, 0, 0x11	; Left & Right channels (Front panel)
653
@@:
654
	stdcall hda_codec_setup_stream, eax, SDO_TAG, 0, 0x11	; Left & Right channels (Back panel)
3083 leency 655
;Asper+ ]
656
 
6943 Asper 657
	invoke	TimerHS, 1, 0, snd_hda_automute, 0
5048 Asper 658
if USE_SINGLE_MODE
659
	mov	esi, msgSingleMode
660
	invoke	SysMsgBoardStr
661
else
662
	mov	esi, msgNormalMode
663
	invoke	SysMsgBoardStr
664
end if
3083 leency 665
 
666
.reg:
5048 Asper 667
	invoke	RegService, sz_sound_srv, service_proc
668
	pop	esi ebx
669
	ret
3083 leency 670
.fail:
5048 Asper 671
	mov	esi, msgFail
3083 leency 672
.fail_msg:
5048 Asper 673
	invoke	SysMsgBoardStr
674
	pop	esi ebx
675
	xor	eax, eax
676
	ret
3083 leency 677
.stop:
5048 Asper 678
	call	stop
679
	pop	esi ebx
680
	xor	eax, eax
681
	ret
3083 leency 682
endp
683
 
684
handle	   equ	IOCTL.handle
685
io_code    equ	IOCTL.io_code
686
input	   equ	IOCTL.input
687
inp_size   equ	IOCTL.inp_size
688
output	   equ	IOCTL.output
689
out_size   equ	IOCTL.out_size
690
 
691
align 4
692
proc service_proc stdcall, ioctl:dword
5048 Asper 693
	mov	edi, [ioctl]
694
	mov	eax, [edi+io_code]
3083 leency 695
 
5048 Asper 696
	cmp	eax, SRV_GETVERSION
697
	jne	@F
3083 leency 698
 
5048 Asper 699
	mov	eax, [edi+output]
700
	cmp	[edi+out_size], 4
701
	jne	.fail
3083 leency 702
 
5048 Asper 703
	mov	[eax], dword API_VERSION
704
	xor	eax, eax
705
	ret
3083 leency 706
@@:
5048 Asper 707
	cmp	eax, DEV_PLAY
708
	jne	@F
709
if DEBUG
710
	mov	esi, msgPlay
711
	invoke	SysMsgBoardStr
712
end if
713
	call	play
714
	xor	eax, eax
715
	ret
3083 leency 716
@@:
5048 Asper 717
	cmp	eax, DEV_STOP
718
	jne	@F
719
if DEBUG
720
	mov	esi, msgStop
721
	invoke	SysMsgBoardStr
722
end if
723
	call	stop
724
	xor	eax, eax
725
	ret
3083 leency 726
@@:
5048 Asper 727
	cmp	eax, DEV_CALLBACK
728
	jne	@f
729
	mov	ebx, [edi+input]
730
	stdcall set_callback, [ebx]
731
	xor	eax, eax
732
	ret
3083 leency 733
@@:
5048 Asper 734
	cmp	eax, DEV_SET_MASTERVOL
735
	jne	@f
736
	mov	eax, [edi+input]
737
	mov	eax, [eax]
738
	call	set_master_vol
739
	xor	eax, eax
740
	ret
3083 leency 741
@@:
5048 Asper 742
	cmp	eax, DEV_GET_MASTERVOL
743
	jne	@f
744
	mov	ebx, [edi+output]
745
	stdcall get_master_vol, ebx
746
	xor	eax, eax
747
	ret
3083 leency 748
;@@:
5048 Asper 749
;        cmp     eax, DEV_GET_INFO
750
;        jne     @f
751
;        mov     ebx, [edi+output]
752
;        stdcall get_dev_info, ebx
753
;        xor     eax, eax
754
;        ret
3083 leency 755
@@:
5048 Asper 756
	cmp	eax, DEV_GET_POS
757
	jne	@f
758
	stdcall azx_get_position
759
	shr	eax, 2
760
	mov	ebx, [edi+output]
761
	mov	[ebx], eax
762
	xor	eax, eax
763
	ret
3083 leency 764
@@:
5048 Asper 765
;        cmp     eax, DEV_SET_CHANNEL_VOLUME
766
;        jne     @f
767
;if DEBUG
768
;        mov     esi, msgSetChannelVolume
769
;        invoke  SysMsgBoardStr
770
;end if
771
;        mov      ebx, [edi+input]
772
;        mov      cl,  byte [ebx]      ; cl=channel
773
;        mov      eax, dword [ebx+1]   ; eax=volume in Db
774
;if DEBUG
775
;        push    eax esi
776
;        mov     esi, msgYAHOO1
777
;        invoke  SysMsgBoardStr
778
;        stdcall fdword2str, 1
779
;        invoke  SysMsgBoardStr
780
;        mov     esi, strSemicolon
781
;        invoke  SysMsgBoardStr
782
;        movzx   eax, cl
783
;        stdcall fdword2str, 3
784
;        invoke  SysMsgBoardStr
785
;        pop     esi eax
786
;end if
787
;    ;        call    set_channel_volume
788
;        xor     eax, eax
789
;        ret
3083 leency 790
;@@:
5048 Asper 791
;        cmp     eax, DEV_GET_CHANNEL_VOLUME
792
;        jne     @f
793
;        mov     cl,  byte [edi+input]  ; cl=channel
794
;        call    get_channel_volume
795
;        mov     ebx, [edi+output]
796
;        mov     [ebx], eax
797
;        xor     eax, eax
798
;        ret
3083 leency 799
;@@:
800
 
801
;Asper: Non standard system service. For the tests only! [
802
@@:
5048 Asper 803
	cmp	 eax, DEV_EXEC_CODEC_CMD
804
	jne	 @f
3083 leency 805
 
5048 Asper 806
	mov	 eax, [edi+input]
807
	mov	 eax, [eax]
808
	stdcall  codec_exec_verb, eax
809
	xor	 eax, eax
810
	ret
3083 leency 811
@@:
812
;Asper: Non standard system service. For the tests only! ]
813
 
814
.fail:
5048 Asper 815
	or	 eax, -1
816
	ret
3083 leency 817
endp
818
 
5048 Asper 819
restore handle
820
restore io_code
821
restore input
822
restore inp_size
823
restore output
824
restore out_size
3083 leency 825
 
826
 
827
align 4
828
proc hda_irq   ;+
5048 Asper 829
	spin_lock
830
if DEBUG_IRQ
831
	push	eax esi
832
	;mov     esi, msgIRQ
833
	;invoke  SysMsgBoardStr
6943 Asper 834
	invoke	GetTimerTicks
5048 Asper 835
	stdcall fdword2str, 2
836
	invoke	SysMsgBoardStr
837
	pop	esi eax
838
end if
839
	mov	edx, ICH6_REG_INTSTS
840
	call	azx_readl
841
	test	eax, eax
842
	jnz	@f
843
	spin_unlock
844
	ret
845
@@:
846
	mov	ebx, eax ; status
847
	mov	eax, SDO_INT
848
	test	ebx, eax
849
	jz	@f
3083 leency 850
 
5048 Asper 851
	mov	edx, ICH6_REG_SD_STS + SDO_OFS
852
	call	azx_readb
853
	mov	bl, al
3083 leency 854
 
5048 Asper 855
	mov	al, SD_INT_MASK
856
	mov	edx, ICH6_REG_SD_STS + SDO_OFS
857
	call	azx_writeb
3083 leency 858
 
5048 Asper 859
	test	bl, SD_INT_COMPLETE
860
	jz	@f
3083 leency 861
 
5048 Asper 862
	mov	eax, [ctrl.civ_val]
863
	inc	eax
864
	and	eax, 4-1 ;2-1
865
	mov	[ctrl.civ_val], eax
3083 leency 866
 
5048 Asper 867
	mov	ebx, dword [buff_list+eax*4]
868
	cmp	[ctrl.user_callback], 0
869
	je	@f
870
	stdcall [ctrl.user_callback], ebx
871
@@:
872
	; clear rirb int
873
	mov	edx, ICH6_REG_RIRBSTS
874
	call	azx_readb
3083 leency 875
 
5048 Asper 876
	test	al, RIRB_INT_MASK
877
	jz	.l1
878
	test	al, RIRB_INT_RESPONSE
879
	jz	.l2
3083 leency 880
 
5048 Asper 881
	cmp	byte [driver_type], AZX_DRIVER_CTX
882
	jne	@f
883
	mov	eax, 80    ; wait 80 us
884
	call	StallExec
885
@@:
886
	call	azx_update_rirb
887
.l2:
888
	mov	al, RIRB_INT_MASK
889
	mov	edx, ICH6_REG_RIRBSTS
890
	call	azx_writeb
891
.l1:
3083 leency 892
 
893
;if 0
894
	; clear state status int
5048 Asper 895
	mov	edx, ICH6_REG_STATESTS
896
	call	azx_readb
897
	test	al, 0x04
898
	jz	@f
3083 leency 899
 
5048 Asper 900
	mov	al, 0x04
901
	mov	edx, ICH6_REG_STATESTS
902
	call	azx_writeb
903
@@:
3083 leency 904
;end if
5048 Asper 905
	or	eax, 1
906
	spin_unlock
907
	ret
3083 leency 908
endp
909
 
910
 
911
align 4
912
proc create_primary_buff
913
 
5048 Asper 914
	invoke	KernelAlloc, 4096
915
	mov	[ctrl.posbuf], eax
3083 leency 916
 
5048 Asper 917
	invoke	KernelAlloc, 0x10000 ;0x8000
918
	mov	[ctrl.buffer], eax
3083 leency 919
 
5048 Asper 920
	mov	edi, eax
921
	mov	ecx, 0x10000/4 ;0x8000/4
922
	xor	eax, eax
923
	cld
924
	rep	stosd
3083 leency 925
 
5048 Asper 926
	invoke	KernelAlloc, 4096
927
	mov	[pcmout_bdl], eax
3083 leency 928
 
5048 Asper 929
	mov	edi, eax
930
	mov	ecx, 4096/4
931
	xor	eax, eax
932
	cld
933
	rep	stosd
3083 leency 934
 
5048 Asper 935
	; reset BDL address
936
	xor	eax, eax
937
	mov	edx, ICH6_REG_SD_BDLPL + SDO_OFS
938
	call	azx_writel
939
	xor	eax, eax
940
	mov	edx, ICH6_REG_SD_BDLPU + SDO_OFS
941
	call	azx_writel
3083 leency 942
 
5048 Asper 943
	; program the initial BDL entries
944
	mov	eax, [ctrl.buffer]
945
	mov	ebx, eax
946
	invoke	GetPgAddr
947
	and	ebx, 0xFFF
948
	add	eax, ebx
3083 leency 949
 
5048 Asper 950
	mov	ebx, 0x4000 ;buffer size
951
	mov	ecx, 8	    ;number of periods
952
	mov	edi, [pcmout_bdl] ;pcmout_bdl
953
.next_period:
954
	push	eax ecx
955
	mov	ecx, 4 ;2  ;number of bdl in a period
956
.next_bdl:
957
	; program the address field of the BDL entry
958
	mov	dword [edi], eax
959
	mov	dword [edi+4], 0
960
	; program the size field of the BDL entry
961
	mov	dword [edi+8],	ebx
962
	; program the IOC to enable interrupt when buffer completes
963
	mov	dword [edi+12], 0x01
3083 leency 964
 
5048 Asper 965
	add	eax, ebx
966
	add	edi, 16
967
	dec	ecx
968
	jnz	.next_bdl
3083 leency 969
 
5048 Asper 970
	pop	ecx eax
971
	dec	ecx
972
	jnz	.next_period
3083 leency 973
 
5048 Asper 974
	mov	edi, buff_list
975
	mov	eax, [ctrl.buffer]
976
	mov	ecx, 4 ;2
3083 leency 977
@@:
5048 Asper 978
	mov	[edi], eax
979
	mov	[edi+8], eax
980
	mov	[edi+16], eax
981
	mov	[edi+24], eax
982
	mov	[edi+32], eax
983
	mov	[edi+40], eax
984
	mov	[edi+48], eax
985
	mov	[edi+56], eax
3083 leency 986
 
5048 Asper 987
	add	eax, ebx
988
	add	edi, 4
989
	loop	@B
3083 leency 990
 
5048 Asper 991
	; wallclk has 24Mhz clock source
992
	mov	[ctrl.period_wallclk], ((0x4000 * 24000) / 48000) * 1000
3083 leency 993
 
5048 Asper 994
	call	azx_stream_reset
995
	call	azx_setup_controller
996
	ret
3083 leency 997
endp
998
 
999
align 4
1000
proc detect_controller
5048 Asper 1001
locals
1002
	last_bus dd ?
1003
	bus	 dd ?
1004
	devfn	 dd ?
1005
endl
1006
	xor	eax, eax
1007
	mov	[bus], eax
1008
	inc	eax
1009
	invoke	PciApi
1010
	cmp	eax, -1
1011
	je	.err
3083 leency 1012
 
5048 Asper 1013
	mov	[last_bus], eax
3083 leency 1014
 
5048 Asper 1015
.next_bus:
1016
	and	[devfn], 0
1017
.next_dev:
1018
	invoke	PciRead32, [bus], [devfn], dword 0
1019
	test	eax, eax
1020
	jz	.next
1021
	cmp	eax, -1
1022
	je	.next
3083 leency 1023
 
5048 Asper 1024
	mov	edi, devices
1025
@@:
1026
	mov	ebx, [edi]
1027
	test	ebx, ebx
1028
	jz	.next
3083 leency 1029
 
5048 Asper 1030
	cmp	eax, ebx
1031
	je	.found
1032
	add	edi, 12
1033
	jmp	@b
1034
.next:
1035
	inc	[devfn]
1036
	cmp	[devfn], 256
1037
	jb	.next_dev
1038
	mov	eax, [bus]
1039
	inc	eax
1040
	mov	[bus], eax
1041
	cmp	eax, [last_bus]
1042
	jna	.next_bus
1043
	xor	eax, eax
1044
	ret
1045
.found:
1046
	mov	ebx, [bus]
1047
	mov	[ctrl.bus], ebx
3083 leency 1048
 
5048 Asper 1049
	mov	ecx, [devfn]
1050
	mov	[ctrl.devfn], ecx
3083 leency 1051
 
5048 Asper 1052
	mov	edx, eax
1053
	and	edx, 0xFFFF
1054
	mov	[ctrl.vendor], dx
1055
	shr	eax, 16
1056
	mov	[ctrl.dev_id], ax
3083 leency 1057
 
5048 Asper 1058
	mov	ebx, [edi+4]
1059
	mov	[ctrl.ctrl_ids], ebx
3083 leency 1060
 
5048 Asper 1061
	cmp	edx, VID_INTEL
1062
	jne	@f
1063
	mov	[ctrl.vendor_ids], msg_Intel
1064
	jmp	.ok
1065
@@:
1066
	cmp	edx, VID_NVIDIA
1067
	jne	@f
1068
	mov	[ctrl.vendor_ids], msg_NVidia
1069
	jmp	.ok
1070
@@:
1071
	cmp	edx, VID_ATI
1072
	jne	@f
1073
	cmp	eax, 0x4383
1074
	jg	.ati_hdmi
1075
	mov	[ctrl.vendor_ids], msg_ATI
1076
	jmp	.ok
1077
.ati_hdmi:
1078
	mov	[ctrl.vendor_ids], msg_ATI_HDMI
1079
	jmp	.ok
1080
@@:
1081
	cmp	edx, VID_AMD
1082
	jne	@f
1083
	mov	[ctrl.vendor_ids], msg_AMD
1084
	jmp	.ok
1085
@@:
1086
	cmp	edx, VID_VIA
1087
	jne	@f
1088
	mov	[ctrl.vendor_ids], msg_VIA
1089
	jmp	.ok
1090
@@:
1091
	cmp	edx, VID_SIS
1092
	jne	@f
1093
	mov	[ctrl.vendor_ids], msg_SIS
1094
	jmp	.ok
1095
@@:
1096
	cmp	edx, VID_ULI
1097
	jne	@f
1098
	mov	[ctrl.vendor_ids], msg_ULI
1099
	jmp	.ok
1100
@@:
1101
	cmp	edx, VID_TERA
1102
	jne	@f
1103
	mov	[ctrl.vendor_ids], msg_TERA
1104
	jmp	.ok
1105
@@:
1106
	cmp	edx, VID_CREATIVE
1107
	jne	@f
1108
	mov	[ctrl.vendor_ids], msg_CREATIVE
1109
	jmp	.ok
1110
@@:
1111
	cmp	edx, VID_RDC
1112
	jne	@f
1113
	mov	[ctrl.vendor_ids], msg_RDC
1114
	jmp	.ok
1115
@@:
1116
	cmp	edx, VID_VMWARE
1117
	jne	@f
1118
	mov	[ctrl.vendor_ids], msg_VMWARE
1119
	jmp	.ok
1120
@@:
1121
.err:
1122
	xor	eax, eax
1123
	mov	[ctrl.vendor_ids], eax	   ;something  wrong ?
1124
	mov	[driver_type], -1
1125
	ret
1126
.ok:
1127
	mov	ebx, [edi+8]
1128
	mov	[driver_type], ebx
1129
	ret
3083 leency 1130
endp
1131
 
1132
align 4
1133
proc init_controller
1134
 
5048 Asper 1135
	invoke	PciRead32, [ctrl.bus], [ctrl.devfn], dword 4
7737 dunkaist 1136
	movi	ebx, 0x6
1137
	and	ebx, eax
1138
	cmp	ebx, 0x6 ; Test Master and Memory bits
1139
	jz	@f
1140
	or	eax, 0x6 ; Set Master and Memory bits
5048 Asper 1141
	invoke	PciWrite32, [ctrl.bus], [ctrl.devfn], dword 4, eax
1142
	invoke	PciRead32, [ctrl.bus], [ctrl.devfn], dword 4
1143
@@:
1144
	mov	ebx, eax
1145
	and	eax, 0xFFFF
1146
	mov	[ctrl.pci_cmd], eax
1147
	shr	ebx, 16
1148
	mov	[ctrl.pci_stat], ebx
3083 leency 1149
 
5048 Asper 1150
	mov	esi, msgPciCmd
1151
	invoke	SysMsgBoardStr
1152
	stdcall fdword2str, 2
1153
	invoke	SysMsgBoardStr
3083 leency 1154
 
5048 Asper 1155
	mov	esi, msgPciStat
1156
	invoke	SysMsgBoardStr
1157
	mov	eax, [ctrl.pci_stat]
1158
	stdcall fdword2str, 2
1159
	invoke	SysMsgBoardStr
3083 leency 1160
 
5048 Asper 1161
	mov	esi, msgHDALowMMIo
1162
	invoke	SysMsgBoardStr
1163
	invoke	PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x10
1164
	stdcall fdword2str, 2
1165
	invoke	SysMsgBoardStr
3083 leency 1166
 
5048 Asper 1167
	and	eax, 0xFFFFC000
1168
	mov	[ctrl.ctrl_mem_base], eax
3083 leency 1169
 
5048 Asper 1170
	mov	esi, msgHDAUpMMIo
1171
	invoke	SysMsgBoardStr
1172
	invoke	PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x14
1173
	;-mov     [ctrl.hda_upper_mem_base], eax
1174
	stdcall fdword2str, 2
1175
	invoke	SysMsgBoardStr
3083 leency 1176
 
5048 Asper 1177
.default:
1178
	invoke	PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x3C
1179
	and	eax, 0xFF
1180
@@:
1181
	mov	[ctrl.int_line], eax
1182
	mov	[ctrl.user_callback], 0
3083 leency 1183
 
5048 Asper 1184
	call	set_HDA
3083 leency 1185
;Asper This is from "azx_create" proc. [
5048 Asper 1186
	xor	eax, eax
1187
	mov	edx, ICH6_REG_GCAP
1188
	call	azx_readw
1189
if DEBUG
1190
	mov	esi, msgGCap
1191
	invoke	SysMsgBoardStr
1192
	stdcall fdword2str, 2
1193
	invoke	SysMsgBoardStr
1194
end if
1195
	; allocate CORB/RIRB
1196
	call	azx_alloc_cmd_io
3083 leency 1197
 
5048 Asper 1198
	; initialize chip
1199
	call	azx_init_pci
3083 leency 1200
 
5048 Asper 1201
	xor	eax, eax
1202
	call	azx_init_chip
3083 leency 1203
;] Asper
1204
 
5048 Asper 1205
	xor	eax, eax
1206
	inc	eax
1207
	ret
3083 leency 1208
endp
1209
 
1210
 
1211
 
5048 Asper 1212
PG_SW		equ 0x003
1213
PG_NOCACHE	equ 0x018
3083 leency 1214
 
1215
align 4
1216
proc set_HDA
5048 Asper 1217
	invoke	MapIoMem,[ctrl.ctrl_mem_base],0x1000,PG_SW+PG_NOCACHE
1218
	mov	[ctrl.ctrl_mem_base], eax
1219
	ret
3083 leency 1220
endp
1221
 
1222
 
1223
; in:  eax - fullreset_flag
1224
;
1225
; reset codec link
1226
align 4
1227
proc reset_controller
5048 Asper 1228
locals
1229
	counter dd ?
1230
endl
3083 leency 1231
 
5048 Asper 1232
	test	eax, eax
1233
	jz	.skip
3083 leency 1234
 
5048 Asper 1235
	; clear STATESTS
1236
	mov	eax, STATESTS_INT_MASK
1237
	mov	edx, ICH6_REG_STATESTS
1238
	call	azx_writeb
3083 leency 1239
 
5048 Asper 1240
	; reset controller
1241
	mov	edx, ICH6_REG_GCTL
1242
	call	azx_readl
1243
	mov	ebx, ICH6_GCTL_RESET
1244
	xor	ebx, -1
1245
	and	eax, ebx
1246
	mov	edx, ICH6_REG_GCTL
1247
	call	azx_writel
3083 leency 1248
 
5048 Asper 1249
	mov	[counter], 50	 ; total 50*100 us = 0.5s
1250
.wait0:
3083 leency 1251
 
5048 Asper 1252
	mov	edx, ICH6_REG_GCTL
1253
	call	azx_readb
1254
	test	eax, eax
1255
	jz	@f
3083 leency 1256
 
5048 Asper 1257
	mov	eax, 100    ; wait 100 us
1258
	call	StallExec
3083 leency 1259
 
5048 Asper 1260
	dec	[counter]
1261
	jnz	.wait0
1262
@@:
1263
	; delay for >= 100us for codec PLL to settle per spec
1264
	; Rev 0.9 section 5.5.1
1265
	mov	eax, 100    ; wait 100 us
1266
	call	StallExec
3083 leency 1267
 
5048 Asper 1268
	; Bring controller out of reset
1269
	mov	edx, ICH6_REG_GCTL
1270
	call	azx_readb
1271
	or	eax, ICH6_GCTL_RESET
1272
	mov	edx, ICH6_REG_GCTL
1273
	call	azx_writeb
3083 leency 1274
 
5048 Asper 1275
	mov	[counter], 50	 ; total 50*100 us = 0.5s
1276
.wait1:
3083 leency 1277
 
5048 Asper 1278
	mov	edx, ICH6_REG_GCTL
1279
	call	azx_readb
1280
	test	eax, eax
1281
	jnz	@f
3083 leency 1282
 
5048 Asper 1283
	mov	eax, 100    ; wait 100 us
1284
	call	StallExec
3083 leency 1285
 
5048 Asper 1286
	dec	[counter]
1287
	jnz	.wait1
1288
@@:
3083 leency 1289
 
5048 Asper 1290
	; Brent Chartrand said to wait >= 540us for codecs to intialize
1291
	mov	eax, 540    ; wait 540 us
1292
	call	StallExec
3083 leency 1293
 
5048 Asper 1294
.skip:
1295
	; check to see if controller is ready
1296
	mov	edx, ICH6_REG_GCTL
1297
	call	azx_readb
1298
	test	eax, eax
1299
	jz	.fail
3083 leency 1300
 
5048 Asper 1301
	; Accept unsolicited responses
1302
if USE_SINGLE_MODE
1303
else if USE_UNSOL_EV
3083 leency 1304
;UNSUPPORTED YET! [
5048 Asper 1305
	mov	edx, ICH6_REG_GCTL
1306
	call	azx_readl
1307
	or	eax, ICH6_GCTL_UNSOL
1308
	mov	edx, ICH6_REG_GCTL
1309
	call	azx_writel
3083 leency 1310
;UNSUPPORTED YET! ]
5048 Asper 1311
end if
3083 leency 1312
 
5048 Asper 1313
	; detect codecs
1314
	mov	eax, [ctrl.codec_mask]
1315
	test	ax, ax
1316
	jnz	@f
3083 leency 1317
 
5048 Asper 1318
	mov	edx, ICH6_REG_STATESTS
1319
	call	azx_readw
1320
	mov	[ctrl.codec_mask], eax
3083 leency 1321
 
5048 Asper 1322
if DEBUG
1323
	mov	esi, msgCodecMask
1324
	invoke	SysMsgBoardStr
1325
	stdcall fdword2str, 2
1326
	invoke	SysMsgBoardStr
1327
end if
3083 leency 1328
 
5048 Asper 1329
@@:
3083 leency 1330
 
5048 Asper 1331
.ok:
1332
	clc
1333
	ret
1334
.fail:
1335
if DEBUG
1336
	mov	esi, msgHDARFail
1337
	invoke	SysMsgBoardStr
1338
end if
1339
	stc
1340
	ret
3083 leency 1341
endp
1342
 
1343
 
1344
align 4
1345
play:
5048 Asper 1346
	spin_lock_irq
1347
	mov	edx, ICH6_REG_WALLCLK
1348
	call	azx_readl
1349
	mov	[ctrl.start_wallclk], eax
3083 leency 1350
 
5048 Asper 1351
	call	azx_stream_start
1352
	xor	eax, eax
1353
	spin_unlock_irq
1354
	ret
3083 leency 1355
 
1356
align 4
1357
stop:
5048 Asper 1358
	spin_lock_irq
1359
;*        call    azx_stream_stop        ;Asper: Hangs system
1360
;R        push    ebx ecx edx
1361
;R        ; stop DMA
1362
;R        mov     edx, ICH6_REG_SD_CTL
1363
;R        call    azx_sd_readb
1364
;R        mov     bl, SD_CTL_DMA_START or SD_INT_MASK
1365
;R        xor     bl, -1
1366
;R        and     al, bl
1367
;R        mov     edx, ICH6_REG_SD_CTL
1368
;R        call    azx_sd_writeb
1369
;R        mov     edx, ICH6_REG_SD_STS
1370
;R        mov     al, SD_INT_MASK
1371
;R        call    azx_sd_writeb  ; to be sure
1372
	  ; disable SIE
1373
;N        mov     edx, ICH6_REG_INTCTL
1374
;N        call    azx_readb
1375
;N        mov     bl, SDO_INT ;shl azx_dev->index
1376
;N        xor     bl, -1
1377
;N        and     al, bl
1378
;N        mov     edx, ICH6_REG_INTCTL
1379
;N        call    azx_writeb
3083 leency 1380
 
5048 Asper 1381
	;     int timeout = 5000;
1382
	;     while (azx_sd_readb(azx_dev, SD_CTL) & SD_CTL_DMA_START && --timeout) ;
3083 leency 1383
;Asper: Hangs system   [
5048 Asper 1384
;*        mov     ecx, 5000
1385
;*.l1:
1386
;*        mov     edx, ICH6_REG_SD_CTL
1387
;*        call    azx_sd_readb
1388
;*        test    al, SD_CTL_DMA_START
1389
;*        jz      @f
1390
;*        dec     ecx
1391
;*        jnz     .l1
1392
;*@@:
3083 leency 1393
;*
5048 Asper 1394
;*        pop     edx ecx ebx
3083 leency 1395
;Asper ]
1396
 
5048 Asper 1397
	xor	eax, eax
1398
	spin_unlock_irq
1399
	ret
3083 leency 1400
 
1401
;align 4
5048 Asper 1402
;proc get_dev_info stdcall, p_info:dword ;deprecated
1403
;virtual at esi
1404
;        CTRL_INFO CTRL_INFO
1405
;end virtual
3083 leency 1406
;
5048 Asper 1407
;        mov     esi, [p_info]
1408
;        mov     eax, [ctrl.int_line]
1409
;        mov     bx,  [ctrl.dev_id]
1410
;        shl     ebx, 16
1411
;        and     bx,  [ctrl.vendor]
1412
;        mov     ecx, [ctrl.pci_cmd]
1413
;        mov     edx, [ctrl.codec_mem_base] ;[ctrl.hda_lower_mem_base]
1414
;        mov     edi, [ctrl.ctrl_mem_base] ;[ctrl.hda_upper_mem_base]
3083 leency 1415
;
5048 Asper 1416
;        mov     [CTRL_INFO.irq], eax
1417
;        mov     [CTRL_INFO.codec_id], ebx
1418
;        mov     [CTRL_INFO.pci_cmd], ecx
1419
;        mov     [CTRL_INFO.codec_mem_base], edx
1420
;        mov     [CTRL_INFO.ctrl_mem_base], edi
3083 leency 1421
;
5048 Asper 1422
;        xor     eax, eax
1423
;        mov     [CTRL_INFO.codec_io_base], eax
1424
;        mov     [CTRL_INFO.ctrl_io_base], eax
1425
;        mov     [CTRL_INFO.glob_cntrl], eax
1426
;        mov     [CTRL_INFO.glob_sta], eax
1427
;        ret
3083 leency 1428
;endp
1429
 
1430
align 4
1431
proc set_callback stdcall, handler:dword
5048 Asper 1432
	mov	eax, [handler]
1433
	mov	[ctrl.user_callback], eax
1434
	ret
3083 leency 1435
endp
1436
 
1437
 
1438
 
1439
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1440
;; Interface for HD codec ;;
1441
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1442
 
1443
;;;;;;;;;;;;;;;;;;;;;;;;;;;
1444
;; CORB / RIRB interface ;;
1445
;;;;;;;;;;;;;;;;;;;;;;;;;;;
1446
 
5048 Asper 1447
proc azx_alloc_cmd_io
1448
	push	eax ecx edx
1449
	; single page (at least 4096 bytes) must suffice for both ringbuffers
1450
	invoke	KernelAlloc, 4096
1451
	mov	[ctrl.rb], eax
3083 leency 1452
 
5048 Asper 1453
	mov	edi, eax
1454
	mov	ecx, 4096/4
1455
	xor	eax, eax
1456
	cld
1457
	rep	stosd
3083 leency 1458
 
5048 Asper 1459
	pop	edx ecx eax
1460
	ret
3083 leency 1461
endp
1462
 
5048 Asper 1463
proc azx_init_cmd_io
1464
	spin_lock_irq
1465
	pusha
1466
	; CORB set up
1467
	mov	eax, [ctrl.rb]
1468
	mov	ebx, eax
1469
	invoke	GetPgAddr
1470
	and	ebx, 0xFFF
1471
	add	eax, ebx
1472
	push	eax  ; save corb address
1473
	mov	edx, ICH6_REG_CORBLBASE
1474
	call	azx_writel
1475
	xor	eax, eax
1476
	mov	edx, ICH6_REG_CORBUBASE
1477
	call	azx_writel
3083 leency 1478
 
5048 Asper 1479
	; set the corb size to 256 entries (ULI requires explicitly)
1480
	mov	al, 0x02
1481
	mov	edx, ICH6_REG_CORBSIZE
1482
	call	azx_writeb
1483
	; set the corb write pointer to 0
1484
	xor	ax, ax
1485
	mov	edx, ICH6_REG_CORBWP
1486
	call	azx_writew
1487
	; reset the corb hw read pointer
1488
	mov	ax, ICH6_CORBRP_RST
1489
	mov	edx, ICH6_REG_CORBRP
1490
	call	azx_writew
1491
	; enable corb dma
1492
	mov	al, ICH6_CORBCTL_RUN
1493
	mov	edx, ICH6_REG_CORBCTL
1494
	call	azx_writeb
3083 leency 1495
 
5048 Asper 1496
	; RIRB set up
1497
	mov	[ctrl.rirb_rp], 0
1498
	mov	[ctrl.rirb_wp], 0
1499
	mov	[ctrl.rirb_cmd], 0
3083 leency 1500
 
5048 Asper 1501
	pop	eax  ; restore corb address
1502
	add	eax, 2048
1503
	mov	edx, ICH6_REG_RIRBLBASE
1504
	call	azx_writel
1505
	xor	eax, eax
1506
	mov	edx, ICH6_REG_RIRBUBASE
1507
	call	azx_writel
3083 leency 1508
 
5048 Asper 1509
	; set the rirb size to 256 entries (ULI requires explicitly)
1510
	mov	al, 0x02
1511
	mov	edx, ICH6_REG_RIRBSIZE
1512
	call	azx_writeb
1513
	; reset the rirb hw write pointer
1514
	mov	ax, ICH6_RIRBWP_RST
1515
	mov	edx, ICH6_REG_RIRBWP
1516
	call	azx_writew
1517
	; set N=1, get RIRB response interrupt for new entry
1518
	xor	ax, ax
1519
	cmp	byte [driver_type], AZX_DRIVER_CTX
1520
	jne	@f
1521
	mov	ax, 0xC0-1
3083 leency 1522
  @@:
5048 Asper 1523
	inc	ax
1524
	mov	edx, ICH6_REG_RINTCNT
1525
	call	azx_writew
1526
	; enable rirb dma and response irq
1527
	mov	al, ICH6_RBCTL_DMA_EN or ICH6_RBCTL_IRQ_EN
1528
	mov	edx, ICH6_REG_RIRBCTL
1529
	call	azx_writeb
3083 leency 1530
 
5048 Asper 1531
	popa
1532
	spin_unlock_irq
1533
	ret
3083 leency 1534
endp
1535
 
5048 Asper 1536
proc azx_free_cmd_io
1537
	spin_lock_irq
1538
	push	eax edx
1539
	; disable ringbuffer DMAs
1540
	xor	al, al
1541
	mov	edx, ICH6_REG_RIRBCTL
1542
	call	azx_writeb
1543
	mov	edx, ICH6_REG_CORBCTL
1544
	call	azx_writeb
1545
	pop	edx eax
1546
	spin_unlock_irq
1547
	ret
3083 leency 1548
endp
1549
 
1550
 
1551
; send a command
5048 Asper 1552
proc azx_corb_send_cmd	stdcall, val:dword
1553
	spin_lock_irq
1554
	push	edx edi
1555
	xor	eax, eax
1556
	; add command to corb
1557
	mov	edx, ICH6_REG_CORBWP
1558
	call	azx_readb
1559
	inc	al
1560
	inc	dword [ctrl.rirb_cmd]
1561
	mov	edi, dword [ctrl.rb]
3083 leency 1562
 
5048 Asper 1563
	push	eax
1564
	shl	eax, 2 ;wp=wp*sizeof(corb entry)=wp*4
1565
	add	edi, eax
1566
	mov	eax, dword [val]
1567
	stosd
1568
	pop	eax
1569
	mov	edx, ICH6_REG_CORBWP
1570
	call	azx_writel
3083 leency 1571
 
5048 Asper 1572
	pop	edi edx
1573
	xor	eax, eax ;Asper+
1574
	spin_unlock_irq
1575
	ret
3083 leency 1576
endp
1577
 
1578
 
1579
; retrieve RIRB entry - called from interrupt handler
5048 Asper 1580
proc azx_update_rirb
1581
	pusha
1582
	xor	eax, eax
1583
	mov	edx, ICH6_REG_RIRBWP
1584
	call	azx_readb ;call  azx_readw
3083 leency 1585
 
5048 Asper 1586
	cmp	ax, [ctrl.rirb_wp]
1587
	je	.done
1588
	mov	[ctrl.rirb_wp], ax
1589
	mov	bx, [ctrl.rirb_rp]
3083 leency 1590
 
5048 Asper 1591
.l1:
1592
	cmp	bx, [ctrl.rirb_wp]
1593
	je	.l3
3083 leency 1594
 
5048 Asper 1595
	inc	bl
1596
.l2:
1597
	cmp	bx, ICH6_MAX_RIRB_ENTRIES
1598
	jl	@f
1599
	sub	bx, ICH6_MAX_RIRB_ENTRIES
1600
	jmp	.l2
1601
@@:
3083 leency 1602
 
5048 Asper 1603
	movzx	edx, bx
1604
	shl	edx, 1 + 2 ; an RIRB entry is 8-bytes
1605
	mov	esi, dword [ctrl.rb]
1606
	add	esi, 2048
1607
	add	esi, edx
1608
	lodsd	; res
1609
	mov	edx, eax
1610
	lodsd	; res_ex
3083 leency 1611
 
5048 Asper 1612
	test	eax, ICH6_RIRB_EX_UNSOL_EV
1613
	jz	@f
1614
	stdcall snd_hda_queue_unsol_event, edx, eax
1615
	jmp	.l1
1616
@@:
1617
	mov	ecx, [ctrl.rirb_cmd]
1618
	test	ecx, ecx
1619
	jz	@f
1620
	mov	[ctrl.rirb_res], edx
1621
	dec	dword [ctrl.rirb_cmd]
1622
	jmp	.l1
1623
@@:
1624
if DEBUG
1625
	push	esi
1626
	mov	esi, msgSpuriousResponce
1627
	invoke	SysMsgBoardStr
1628
	pop	esi
1629
end if
1630
	jmp	.l1
1631
.l3:
1632
	mov	[ctrl.rirb_rp], bx
1633
.done:
1634
	popa
1635
	ret
3083 leency 1636
endp
1637
 
1638
; receive a response
5048 Asper 1639
proc azx_rirb_get_response
1640
locals
1641
	do_poll db 0
1642
endl
3083 leency 1643
 
5048 Asper 1644
	push	ebx ecx edx
1645
.again:
1646
	mov	ecx, 1000;+1000
1647
.next_try:
1648
	mov	al, [ctrl.polling_mode]
1649
	test	al, al
1650
	jnz	.poll
1651
	mov	ah, [do_poll]
1652
	test	ah, ah
1653
	jz	@f
1654
.poll:
1655
	spin_lock_irq
1656
	call	azx_update_rirb
1657
	spin_unlock_irq
1658
@@:
1659
	mov	eax, [ctrl.rirb_cmd]
1660
	test	eax, eax
1661
	jnz	.l1
1662
	mov	[ctrl.rirb_error], 0
1663
	mov	al, [do_poll]
1664
	test	al, al
1665
	jnz	@f
1666
	mov	[ctrl.poll_count], 0
1667
@@:
1668
	mov	eax, [ctrl.rirb_res] ; the last value
1669
	jmp	.out
1670
.l1:
1671
	push	eax
1672
	mov	eax, 2000  ; temporary workaround
1673
	call	StallExec
1674
	pop	eax
1675
	dec	ecx
1676
	jnz	.next_try
1677
.no_next_try:
1678
	mov	al, [ctrl.polling_mode]
1679
	test	al, al
1680
	jnz	.no_poll
3083 leency 1681
 
5048 Asper 1682
	mov	al, [ctrl.poll_count]
1683
	cmp	al, 2
1684
	jge	.poll_count_overflow
1685
if DEBUG
1686
	push	eax esi
1687
	mov	esi, msgGetResponceTimeout
1688
	invoke	SysMsgBoardStr
1689
	mov	esi, msgPollingCodecOnce
1690
	invoke	SysMsgBoardStr
1691
	pop	esi eax
1692
end if
1693
	mov	[do_poll], 1
1694
	inc	[ctrl.poll_count]
1695
	jmp	.again
3083 leency 1696
 
5048 Asper 1697
.poll_count_overflow:
1698
if DEBUG
1699
	push	eax esi
1700
	mov	esi, msgGetResponceTimeout
1701
	invoke	SysMsgBoardStr
1702
	mov	esi, msgSwitchToPollMode
1703
	invoke	SysMsgBoardStr
1704
	pop	esi eax
1705
end if
1706
	mov	[ctrl.polling_mode], 1
1707
	jmp	.again
3083 leency 1708
 
5048 Asper 1709
.no_poll:
3083 leency 1710
 
5048 Asper 1711
	mov	al, [ctrl.polling_mode]
1712
	test	al, al
1713
	jz	@f
1714
	mov	eax, -1
1715
	jmp	.out
1716
@@:
3083 leency 1717
 
5048 Asper 1718
	; a fatal communication error; need either to reset or to fallback
1719
	; to the single_cmd mode
1720
	mov	[ctrl.rirb_error], 1
1721
	;Asper~ -?  [
1722
	mov	[ctrl.response_reset], 1
1723
	mov	eax, -1  ; give a chance to retry
1724
	jmp	.out
1725
	;Asper~ -?  ]
3083 leency 1726
 
5048 Asper 1727
	;-? mov     [ctrl.single_cmd], 1
1728
	mov	[ctrl.response_reset], 0
3083 leency 1729
 
5048 Asper 1730
	; release CORB/RIRB
1731
	call	azx_free_cmd_io
1732
	; disable unsolicited responses
1733
	mov	edx, ICH6_REG_GCTL
1734
	call	azx_readl
1735
	mov	ebx, ICH6_GCTL_UNSOL
1736
	xor	ebx, -1
1737
	and	eax, ebx
1738
	mov	edx, ICH6_REG_GCTL
1739
	call	azx_writel
1740
	mov	eax, -1
1741
.out:
1742
	pop	edx ecx ebx
1743
	ret
3083 leency 1744
endp
1745
 
1746
;
1747
; Use the single immediate command instead of CORB/RIRB for simplicity
1748
;
1749
; Note: according to Intel, this is not preferred use.  The command was
1750
;       intended for the BIOS only, and may get confused with unsolicited
1751
;       responses.  So, we shouldn't use it for normal operation from the
1752
;       driver.
1753
;       I left the codes, however, for debugging/testing purposes.
1754
;
1755
 
1756
; receive a response
5048 Asper 1757
proc azx_single_wait_for_response
1758
	push	ecx edx esi
3083 leency 1759
 
5048 Asper 1760
	mov	ecx, 50
1761
.l1:
1762
	test	ecx, ecx
1763
	jz	.timeout
3083 leency 1764
 
1765
	; check IRV busy bit
5048 Asper 1766
	mov	edx, ICH6_REG_IRS
1767
	call	azx_readw
1768
	test	ax, ICH6_IRS_VALID
1769
	jz	@f
3083 leency 1770
	; reuse rirb.res as the response return value
5048 Asper 1771
	mov	edx, ICH6_REG_IR
1772
	call	azx_readl
1773
	mov	[ctrl.rirb_res], eax
3083 leency 1774
 
5048 Asper 1775
	pop	esi edx ecx
1776
	xor	eax, eax
3083 leency 1777
	ret
5048 Asper 1778
@@:
1779
	xor	eax, eax
1780
	inc	eax
1781
	call	StallExec
3083 leency 1782
 
5048 Asper 1783
	dec	ecx
1784
	jmp	.l1
1785
.timeout:
1786
if DEBUG
1787
	xor	eax, eax
1788
	mov	edx, ICH6_REG_IRS
1789
	call	azx_readw
1790
	mov	esi, msgGetResponceTimeout
1791
	invoke	SysMsgBoardStr
1792
	mov	esi, msgIRS
1793
	invoke	SysMsgBoardStr
1794
	stdcall fdword2str, 2
1795
	invoke	SysMsgBoardStr
1796
end if
3083 leency 1797
 
5048 Asper 1798
	pop	esi edx ecx
1799
	mov	eax, -1
1800
	mov	[ctrl.rirb_res], eax
3083 leency 1801
	ret
1802
endp
1803
 
1804
; send a command
5048 Asper 1805
proc azx_single_send_cmd  stdcall, val:dword
3083 leency 1806
	push	ecx edx esi
1807
 
1808
	mov	ecx, 50
5048 Asper 1809
.l1:
3083 leency 1810
	test	ecx, ecx
1811
	jz	.timeout
1812
 
1813
	; check ICB busy bit
5048 Asper 1814
	mov	edx, ICH6_REG_IRS
1815
	call	azx_readw
1816
	test	ax, ICH6_IRS_BUSY
1817
	jnz	@f
3083 leency 1818
	; Clear IRV valid bit
5048 Asper 1819
	mov	edx, ICH6_REG_IRS
1820
	call	azx_readw
1821
	or	ax, ICH6_IRS_VALID
1822
	mov	edx, ICH6_REG_IRS
1823
	call	azx_writew
3083 leency 1824
 
5048 Asper 1825
	mov	eax, dword [val]
1826
	mov	edx, ICH6_REG_IC
1827
	call	azx_writel
3083 leency 1828
 
5048 Asper 1829
	mov	edx, ICH6_REG_IRS
1830
	call	azx_readw
1831
	or	ax, ICH6_IRS_BUSY
1832
	mov	edx, ICH6_REG_IRS
1833
	call	azx_writew
3083 leency 1834
 
1835
	stdcall azx_single_wait_for_response
5048 Asper 1836
	pop	esi edx ecx
3083 leency 1837
	ret
5048 Asper 1838
@@:
3083 leency 1839
	dec	ecx
1840
	jmp	.l1
5048 Asper 1841
.timeout:
1842
if DEBUG
1843
	xor	eax, eax
1844
	mov	edx, ICH6_REG_IRS
1845
	call	azx_readw
1846
	mov	esi, msgSendCmdTimeout
1847
	invoke	SysMsgBoardStr
1848
	stdcall fdword2str, 2
1849
	invoke	SysMsgBoardStr
1850
	mov	esi, msgVal
1851
	invoke	SysMsgBoardStr
1852
	mov	eax, dword [val]
1853
	stdcall fdword2str, 2
1854
	invoke	SysMsgBoardStr
1855
end if
3083 leency 1856
 
5048 Asper 1857
	pop	esi edx ecx
1858
	mov	eax, -1
3083 leency 1859
	ret
1860
endp
1861
 
1862
; receive a response
5048 Asper 1863
proc azx_single_get_response
1864
	mov	eax, [ctrl.rirb_res]
3083 leency 1865
	ret
1866
endp
1867
 
1868
;
1869
; The below are the main callbacks from hda_codec.
1870
;
1871
; They are just the skeleton to call sub-callbacks according to the
1872
; current setting of chip->single_cmd.
1873
;
1874
 
1875
; send a command
5048 Asper 1876
proc azx_send_cmd  stdcall, val:dword
1877
if USE_SINGLE_MODE
1878
	stdcall azx_single_send_cmd, [val]
1879
else
1880
	stdcall azx_corb_send_cmd, [val]
1881
end if
1882
	ret
3083 leency 1883
endp
1884
 
1885
; get a response
5048 Asper 1886
proc azx_get_response
1887
if USE_SINGLE_MODE
1888
	call	azx_single_get_response
1889
else
1890
	call	azx_rirb_get_response
1891
end if
1892
	ret
3083 leency 1893
endp
1894
 
1895
 
1896
;;;;;;;;;;;;;;;;;;;;;;;;
1897
;; Lowlevel interface ;;
1898
;;;;;;;;;;;;;;;;;;;;;;;;
1899
 
1900
; enable interrupts
5048 Asper 1901
proc azx_int_enable
1902
	push	 eax edx
1903
	; enable controller CIE and GIE
1904
	mov	edx, ICH6_REG_INTCTL
1905
	call	azx_readl
1906
	or	eax, ICH6_INT_CTRL_EN or ICH6_INT_GLOBAL_EN
1907
	mov	edx, ICH6_REG_INTCTL
1908
	call	azx_writel
1909
	pop	edx eax
1910
	ret
3083 leency 1911
endp
1912
 
1913
; disable interrupts
5048 Asper 1914
proc azx_int_disable
1915
	push	eax ebx edx
3083 leency 1916
 
5048 Asper 1917
	; disable interrupts in stream descriptor
1918
	mov	edx, ICH6_REG_SD_CTL + SDO_OFS
1919
	call	azx_readb
1920
	mov	bl, SD_INT_MASK
1921
	xor	bl, -1
1922
	and	al, bl
1923
	mov	edx, ICH6_REG_SD_CTL + SDO_OFS
1924
	call	azx_writeb
3083 leency 1925
 
5048 Asper 1926
	; disable SIE for all streams
1927
	xor	al, al
1928
	mov	edx, ICH6_REG_INTCTL
1929
	call	azx_writeb
3083 leency 1930
 
5048 Asper 1931
	; disable controller CIE and GIE
1932
	mov	edx, ICH6_REG_INTCTL
1933
	call	azx_readl
1934
	mov	ebx, ICH6_INT_CTRL_EN or ICH6_INT_GLOBAL_EN
1935
	xor	ebx, -1
1936
	and	eax, ebx
1937
	call	azx_writel
1938
	pop	edx ebx eax
1939
	ret
3083 leency 1940
endp
1941
 
1942
; clear interrupts
5048 Asper 1943
proc azx_int_clear
1944
	push	eax edx
3083 leency 1945
 
5048 Asper 1946
	; clear stream status
1947
	mov	al, SD_INT_MASK
1948
	mov	edx, ICH6_REG_SD_STS + SDO_OFS
1949
	call	azx_writeb
3083 leency 1950
 
5048 Asper 1951
	; clear STATESTS
1952
	mov	al, STATESTS_INT_MASK
1953
	mov	edx, ICH6_REG_STATESTS
1954
	call	azx_writeb
3083 leency 1955
 
5048 Asper 1956
	; clear rirb status
1957
	mov	al, RIRB_INT_MASK
1958
	mov	edx, ICH6_REG_RIRBSTS
1959
	call	azx_writeb
3083 leency 1960
 
5048 Asper 1961
	; clear int status
1962
	mov	eax, ICH6_INT_CTRL_EN or ICH6_INT_ALL_STREAM
1963
	mov	edx, ICH6_REG_INTSTS
1964
	call	azx_writel
1965
	pop	edx eax
1966
	ret
3083 leency 1967
endp
1968
 
1969
 
1970
; start a stream
5048 Asper 1971
proc azx_stream_start
1972
	push	eax edx
3083 leency 1973
 
5048 Asper 1974
	; enable SIE
1975
	mov	edx, ICH6_REG_INTCTL
1976
	call	azx_readl
3083 leency 1977
 
5048 Asper 1978
	or	eax, 0xC0000000 ;Asper+
1979
	or	eax, SDO_INT  ; Asper: output stream interrupt index
1980
	mov	edx, ICH6_REG_INTCTL
1981
	call	azx_writel
1982
	; set DMA start and interrupt mask
1983
	mov	edx, ICH6_REG_SD_CTL + SDO_OFS
1984
	call	azx_readb
3083 leency 1985
 
5048 Asper 1986
	or	al, SD_CTL_DMA_START or SD_INT_MASK
3083 leency 1987
 
5048 Asper 1988
	mov	edx, ICH6_REG_SD_CTL + SDO_OFS
1989
	call	azx_writeb
3083 leency 1990
 
5048 Asper 1991
	pop	edx eax
1992
	ret
3083 leency 1993
endp
1994
 
1995
; stop DMA
5048 Asper 1996
proc azx_stream_clear
1997
	push	eax ebx edx
1998
	mov	edx, ICH6_REG_SD_CTL + SDO_OFS
1999
	call	azx_readb
2000
	mov	bl, SD_CTL_DMA_START or SD_INT_MASK
2001
	xor	bl, -1
2002
	and	al, bl
2003
	mov	edx, ICH6_REG_SD_CTL + SDO_OFS
2004
	call	azx_writeb
2005
	mov	al, SD_INT_MASK
2006
	mov	edx, ICH6_REG_SD_STS + SDO_OFS
2007
	call	azx_writeb
2008
	pop	edx ebx eax
2009
	ret
3083 leency 2010
endp
2011
 
2012
; stop a stream
5048 Asper 2013
proc azx_stream_stop
2014
	push	eax ebx edx
2015
	call	azx_stream_clear
2016
	; disable SIE
2017
	mov	edx, ICH6_REG_INTCTL
2018
	call	azx_readl
2019
	mov	ebx, (SDO_INT)
2020
	xor	ebx, -1
2021
	and	eax, ebx
2022
	mov	edx, ICH6_REG_INTCTL
2023
	call	azx_writel
2024
	pop	edx ebx eax
2025
	ret
3083 leency 2026
endp
2027
 
2028
;
2029
;in: eax = full_reset
2030
;
2031
; initialize the chip
5048 Asper 2032
proc azx_init_chip
2033
	push	eax
3083 leency 2034
 
5048 Asper 2035
	; reset controller
2036
	mov	eax, 1 ;full reset
2037
	call	reset_controller
3083 leency 2038
 
5048 Asper 2039
	; initialize interrupts
2040
	call	azx_int_clear
2041
	call	azx_int_enable
3083 leency 2042
 
5048 Asper 2043
	; initialize the codec command I/O
2044
if USE_SINGLE_MODE
2045
else
2046
	call	azx_init_cmd_io
2047
end if
3083 leency 2048
 
5048 Asper 2049
	; program the position buffer
2050
	mov	eax, dword [ctrl.posbuf]
2051
	mov	ebx, eax
2052
	invoke	GetPgAddr
2053
	and	ebx, 0xFFF
2054
	add	eax, ebx
2055
	mov	edx, ICH6_REG_DPLBASE
2056
	call	azx_writel
2057
	xor	eax, eax
2058
	mov	edx, ICH6_REG_DPUBASE
2059
	call	azx_writel
3083 leency 2060
 
5048 Asper 2061
	pop	eax
2062
	ret
3083 leency 2063
endp
2064
 
2065
 
2066
; initialize the PCI registers
2067
 
2068
; update bits in a PCI register byte
5048 Asper 2069
proc update_pci_byte  stdcall, reg:dword, mask:dword, val:dword
2070
	push	ax bx
2071
	invoke	PciRead8, [ctrl.bus], [ctrl.devfn], [reg]
2072
	mov	bl, byte [mask]
2073
	mov	bh, bl
2074
	xor	bl, -1
2075
	and	al, bl
2076
	shr	bx, 8
2077
	and	bl, byte [val]
2078
	or	al, bl
2079
	invoke	PciWrite8, [ctrl.bus], [ctrl.devfn], [reg], eax
2080
	pop	bx ax
2081
	ret
3083 leency 2082
endp
2083
 
2084
 
5048 Asper 2085
proc azx_init_pci
2086
	; Clear bits 0-2 of PCI register TCSEL (at offset 0x44)
2087
	; TCSEL == Traffic Class Select Register, which sets PCI express QOS
2088
	; Ensuring these bits are 0 clears playback static on some HD Audio
2089
	; codecs
2090
	push	eax
2091
	stdcall update_pci_byte, ICH6_PCIREG_TCSEL, 0x07, 0
3083 leency 2092
 
5048 Asper 2093
	mov	eax, [driver_type]
2094
	cmp	eax, AZX_DRIVER_ATI
2095
	jne	@f
2096
	; For ATI SB450 azalia HD audio, we need to enable snoop
2097
	stdcall update_pci_byte, ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR, 0x07, ATI_SB450_HDAUDIO_ENABLE_SNOOP
2098
	jmp	.done
2099
@@:
2100
	cmp	eax, AZX_DRIVER_NVIDIA
2101
	jne	@f
2102
	; For NVIDIA HDA, enable snoop
2103
	stdcall update_pci_byte, NVIDIA_HDA_TRANSREG_ADDR, 0x0f, NVIDIA_HDA_ENABLE_COHBITS
2104
	stdcall update_pci_byte, NVIDIA_HDA_ISTRM_COH, 0x01, NVIDIA_HDA_ENABLE_COHBIT
2105
	stdcall update_pci_byte, NVIDIA_HDA_OSTRM_COH, 0x01, NVIDIA_HDA_ENABLE_COHBIT
2106
	jmp	.done
2107
@@:
2108
	cmp	eax, AZX_DRIVER_SCH
2109
	je	.l1
2110
	cmp	eax, AZX_DRIVER_PCH
2111
	jne	@f
2112
.l1:
2113
	invoke	PciRead16,  [ctrl.bus], [ctrl.devfn], dword INTEL_SCH_HDA_DEVC
2114
	test	ax, INTEL_SCH_HDA_DEVC_NOSNOOP
2115
	jz	@f
2116
	push	ebx
2117
	mov	ebx, INTEL_SCH_HDA_DEVC_NOSNOOP
2118
	xor	ebx, -1
2119
	and	eax, ebx
2120
	pop	ebx
2121
	invoke	PciWrite16,  [ctrl.bus], [ctrl.devfn], dword INTEL_SCH_HDA_DEVC, eax
2122
	invoke	PciRead16,  [ctrl.bus], [ctrl.devfn], dword INTEL_SCH_HDA_DEVC
3083 leency 2123
 
5048 Asper 2124
if DEBUG
2125
	push	esi
2126
	mov	esi, msgHDASnoopDisabled
2127
	invoke	SysMsgBoardStr
2128
	mov	esi, msg_OK
2129
	test	ax, INTEL_SCH_HDA_DEVC_NOSNOOP
2130
	jz	.snoop_ok
2131
	mov	esi, msg_Fail
2132
.snoop_ok:
2133
	invoke	SysMsgBoardStr
2134
	pop	esi
2135
end if
2136
@@:
2137
.done:
2138
	pop	eax
2139
	ret
3083 leency 2140
endp
2141
 
2142
 
2143
; reset stream
5048 Asper 2144
proc azx_stream_reset
2145
	push	eax ebx ecx edx
3083 leency 2146
 
5048 Asper 2147
	call	azx_stream_clear
3083 leency 2148
 
5048 Asper 2149
	mov	edx, ICH6_REG_SD_CTL + SDO_OFS
2150
	call	azx_readb
2151
	or	al, SD_CTL_STREAM_RESET
2152
	mov	edx, ICH6_REG_SD_CTL + SDO_OFS
2153
	call	azx_writeb
3083 leency 2154
 
5048 Asper 2155
	mov	eax, 3
2156
	call	StallExec
3083 leency 2157
 
5048 Asper 2158
	mov	ecx, 300
2159
.l1:
2160
	mov	edx, ICH6_REG_SD_CTL + SDO_OFS
2161
	call	azx_readb
2162
	test	al, SD_CTL_STREAM_RESET
2163
	jnz	@f
2164
	dec	ecx
2165
	jnz	.l1
2166
@@:
2167
	mov	bl, SD_CTL_STREAM_RESET
2168
	xor	bl, -1
2169
	and	al, bl
2170
	mov	edx, ICH6_REG_SD_CTL + SDO_OFS
2171
	call	azx_writeb
3083 leency 2172
 
5048 Asper 2173
	mov	eax, 3
2174
	call	StallExec
3083 leency 2175
 
5048 Asper 2176
	mov	ecx, 300
2177
	; waiting for hardware to report that the stream is out of reset
2178
.l2:
2179
	mov	edx, ICH6_REG_SD_CTL + SDO_OFS
2180
	call	azx_readb
2181
	test	al, SD_CTL_STREAM_RESET
2182
	jnz	@f
2183
	dec	ecx
2184
	jnz	.l2
2185
@@:
2186
	; reset first position - may not be synced with hw at this time
2187
	mov	edx, [ctrl.posbuf]
2188
	mov	dword [edx], 0
2189
	pop	edx ecx ebx eax
2190
	ret
3083 leency 2191
endp
2192
 
2193
 
2194
; set up the SD for streaming
2195
proc azx_setup_controller
5048 Asper 2196
	push	eax ebx ecx edx
2197
	; make sure the run bit is zero for SD
2198
	call	azx_stream_clear
3083 leency 2199
 
5048 Asper 2200
	; program the stream_tag
2201
	mov	edx, ICH6_REG_SD_CTL + SDO_OFS
2202
	call	azx_readl
2203
	mov	ecx, SD_CTL_STREAM_TAG_MASK
2204
	xor	ecx, -1
2205
	and	eax, ecx
2206
	mov	ecx, SDO_TAG
2207
	shl	ecx, SD_CTL_STREAM_TAG_SHIFT
2208
	or	eax, ecx
2209
	; Asper stream_tag = SDO_TAG
2210
	mov	edx, ICH6_REG_SD_CTL + SDO_OFS
2211
	call	azx_writel
3083 leency 2212
 
5048 Asper 2213
	; program the length of samples in cyclic buffer
2214
	mov	eax, 0x4000*32
2215
	mov	edx, ICH6_REG_SD_CBL + SDO_OFS
2216
	call	azx_writel
3083 leency 2217
 
5048 Asper 2218
	; program the stream format
2219
	; this value needs to be the same as the one programmed
2220
	mov	ax, 0x11
2221
	mov	edx, ICH6_REG_SD_FORMAT + SDO_OFS
2222
	call	azx_writew
3083 leency 2223
 
5048 Asper 2224
	; program the stream LVI (last valid index) of the BDL
2225
	mov	eax, 32-1 ;4-1 ;2-1
2226
	mov	[ctrl.lvi_reg], eax
2227
	mov	edx, ICH6_REG_SD_LVI + SDO_OFS
2228
	call	azx_writew
3083 leency 2229
 
5048 Asper 2230
	; program the BDL address
2231
	; lower BDL address
2232
	mov	eax, [pcmout_bdl]
2233
	mov	ebx, eax
2234
	invoke	GetPgAddr
2235
	and	ebx, 0xFFF
2236
	add	eax, ebx
2237
	mov	edx, ICH6_REG_SD_BDLPL + SDO_OFS
2238
	call	azx_writel
2239
	; upper BDL address
2240
	xor	eax, eax       ;upper_32bit(azx_dev->bdl_addr)
2241
	mov	edx, ICH6_REG_SD_BDLPU + SDO_OFS
2242
	call	azx_writel
3083 leency 2243
 
5048 Asper 2244
	; enable the position buffer
2245
	cmp	[ctrl.position_fix], POS_FIX_LPIB
2246
	jz	@f
2247
	mov	edx, ICH6_REG_DPLBASE
2248
	call	azx_readl
2249
	and	eax, ICH6_DPLBASE_ENABLE
2250
	jnz	@f
2251
	mov	eax, dword [ctrl.posbuf]
2252
	mov	ebx, eax
2253
	invoke	GetPgAddr
2254
	and	ebx, 0xFFF
2255
	add	eax, ebx
2256
	or	eax, ICH6_DPLBASE_ENABLE
2257
	mov	edx, ICH6_REG_DPLBASE
2258
	call	azx_writel
2259
@@:
2260
	; set the interrupt enable bits in the descriptor control register
2261
	mov	edx, ICH6_REG_SD_CTL + SDO_OFS
2262
	call	azx_readl
2263
	or	eax, SD_INT_MASK
2264
	mov	edx, ICH6_REG_SD_CTL + SDO_OFS
2265
	call	azx_writel
3083 leency 2266
 
5048 Asper 2267
	pop	edx ecx ebx eax
2268
	ret
3083 leency 2269
endp
2270
 
2271
 
2272
;(...)
2273
 
2274
; Probe the given codec address
2275
proc probe_codec, addr:dword
5048 Asper 2276
	push	edx
2277
	mov	eax, [addr]
2278
	shl	eax, 28
2279
	mov	edx, (AC_NODE_ROOT shl 20) or (AC_VERB_PARAMETERS shl 8) or AC_PAR_VENDOR_ID
2280
	or	eax, edx
2281
	stdcall azx_send_cmd, eax
2282
	stdcall azx_get_response
3083 leency 2283
 
5048 Asper 2284
	cmp	eax, -1
2285
	je	.out
2286
	mov	eax, [addr]
2287
	mov	[codec.addr], eax ;Asper+
2288
if DEBUG
2289
	push	esi
2290
	mov	esi, msgCodecOK
2291
	invoke	SysMsgBoardStr
2292
	mov	esi, msgCAd
2293
	invoke	SysMsgBoardStr
2294
	stdcall fdword2str, 3
2295
	invoke	SysMsgBoardStr
2296
	pop	esi
2297
end if
2298
	xor	eax, eax
2299
.out:
2300
	pop	edx
2301
	ret
3083 leency 2302
endp
2303
 
2304
 
2305
proc  azx_bus_reset
5048 Asper 2306
	call	azx_stop_chip
2307
	call	azx_init_chip
6943 Asper 2308
	ret
3083 leency 2309
endp
2310
 
2311
 
2312
; Codec initialization
5048 Asper 2313
proc azx_codec_create
2314
	push	ebx  ecx  edx
2315
	;(...)
3083 leency 2316
	; First try to probe all given codec slots
2317
	; Asper: We asume for now that max slots for codecs = 4
5048 Asper 2318
	xor	ecx, ecx
2319
	xor	edx, edx
2320
	inc	edx
2321
.next_slot:
2322
	test	edx, [ctrl.codec_mask]
2323
	jz	@f
2324
	stdcall probe_codec, ecx
2325
	test	eax, eax
2326
	jz	.init ;@f
2327
	; Some BIOSen give you wrong codec addresses that don't exist
2328
if DEBUG
2329
	mov	esi, msgCodecError
2330
	invoke	SysMsgBoardStr
2331
end if
2332
	mov	ebx, edx
2333
	xor	ebx, -1
2334
	and	[ctrl.codec_mask], ebx
3083 leency 2335
 
5048 Asper 2336
	; More badly, accessing to a non-existing
2337
	; codec often screws up the controller chip,
2338
	; and disturbs the further communications.
2339
	; Thus if an error occurs during probing,
2340
	; better to reset the controller chip to
2341
	; get back to the sanity state.
2342
	;call    azx_bus_reset
2343
@@:
2344
	shl	edx, 1
2345
	inc	ecx
2346
;if USE_FIRST_CODEC
2347
;        cmp     ecx, 1
2348
;else
2349
	cmp	ecx, 4
2350
;end if
2351
	jl	.next_slot
2352
	mov	eax, -1
2353
	jmp	.out
2354
.init:
2355
	push	ecx edx
2356
	stdcall snd_hda_codec_init
2357
	pop	edx ecx
2358
	test	eax, eax
2359
	jnz	@b
2360
.out:
2361
	pop	edx  ecx  ebx
2362
	ret
3083 leency 2363
endp
2364
 
2365
 
5048 Asper 2366
proc azx_codec_configure
2367
	;(...)
2368
	call	snd_hda_codec_configure
2369
	ret
3083 leency 2370
endp
2371
 
2372
 
5048 Asper 2373
proc azx_get_position
2374
	test	[ctrl.position_fix], POS_FIX_LPIB
2375
	jz	@f
2376
	; read LPIB
2377
	mov	edx, ICH6_REG_SD_LPIB + SDO_OFS
2378
	call	azx_readl
2379
	jmp	.out
2380
@@:
2381
	test	[ctrl.position_fix], POS_FIX_VIACOMBO
2382
	jz	@f
2383
;        call    azx_get_via_position
2384
;        jmp     .out
2385
@@:
2386
	; use the position buffer
2387
	push	edx
2388
	mov	edx, dword [ctrl.posbuf]
2389
	mov	eax, dword [edx]
2390
	pop	edx
2391
.out:
2392
	cmp	eax, 0x4000 ; bufsize
2393
	jl	@f
2394
	xor	eax, eax
2395
@@:
2396
	ret
3083 leency 2397
endp
2398
 
2399
 
5048 Asper 2400
proc azx_stop_chip
2401
	push	eax edx
3083 leency 2402
 
5048 Asper 2403
	; disable interrupts
2404
	call	azx_int_disable
2405
	call	azx_int_clear
3083 leency 2406
 
5048 Asper 2407
	; disable CORB/RIRB
2408
	call	azx_free_cmd_io
2409
 
2410
	; disable position buffer
2411
	xor	eax, eax
2412
	mov	edx, ICH6_REG_DPLBASE
2413
	call	azx_writel
2414
	mov	edx, ICH6_REG_DPUBASE
2415
	call	azx_writel
2416
	pop	edx eax
2417
	ret
3083 leency 2418
endp
2419
 
2420
 
2421
; in:  eax = volume (-10000 - 0)
2422
align 4
2423
set_master_vol:
5048 Asper 2424
	mov	ecx, 3
2425
	call	set_channel_volume
2426
	ret
3083 leency 2427
 
2428
 
2429
; out:  [pvol] = volume (-10000 - 0)
2430
align 4
2431
proc  get_master_vol stdcall, pvol:dword
5048 Asper 2432
	xor	ecx, ecx
2433
	call	get_channel_volume
2434
	mov	ebx, [pvol]
2435
	mov	[ebx], eax
2436
	xor	eax, eax
2437
	ret
3083 leency 2438
endp
2439
 
2440
 
2441
; in:   ecx = channel mask (1 - Left; 2 - Right; 3-Both)
2442
;       eax = volume (-10000 - 0)
2443
align 4
2444
set_channel_volume:
5048 Asper 2445
	push	eax ebx ecx edx
2446
	mov	ebx, [volume.maxDb]
2447
	neg	eax
2448
if DEBUG ;-
2449
	push	eax esi
2450
	mov	esi, msgNewVolume
2451
	invoke	SysMsgBoardStr
2452
	stdcall fdword2str, 2
2453
	invoke	SysMsgBoardStr
3083 leency 2454
 
5048 Asper 2455
	mov	esi, msgMinVolume
2456
	invoke	SysMsgBoardStr
2457
	mov	eax, ebx
2458
	stdcall fdword2str, 2
2459
	invoke	SysMsgBoardStr
2460
	pop	esi eax
2461
end if
2462
	test	ebx, ebx
2463
	jz	.err_out
3083 leency 2464
 
5048 Asper 2465
	cmp	eax, 0
2466
	jg	@f
2467
	xor	eax, eax
2468
	jmp	.set
2469
@@:
2470
	cmp	eax, ebx
2471
	jng	.set
2472
	mov	eax, ebx
2473
.set:
2474
	sub	ebx, eax
2475
	mov	eax, ebx
2476
	;cdq
2477
	xor	edx, edx
2478
	push	eax
2479
	movzx	eax, [volume.step_size]
2480
	imul	eax, (100/4)
2481
	mov	ebx, eax
2482
	pop	eax
2483
	xor	edx, edx
2484
	idiv	ebx
3083 leency 2485
 
5048 Asper 2486
	mov	edx, [volume.out_amp_node]
2487
	test	edx, edx
2488
	jz	.out
2489
	movzx	ebx, [edx+HDA_GNODE.nid]
3083 leency 2490
 
5048 Asper 2491
	test	ecx, 1	 ; Left channel ?
2492
	jz	@f
2493
	stdcall put_volume_mute, ebx, 0, HDA_OUTPUT, 0, eax
2494
@@:
2495
	test	ecx, 2	 ; Right channel ?
2496
	jz	.out
2497
	stdcall put_volume_mute, ebx, 1, HDA_OUTPUT, 0, eax
2498
.out:
2499
	pop	edx ecx ebx eax
2500
	ret
2501
.err_out:
2502
if DEBUG  ;-
2503
	push	esi
2504
	mov	esi, emsgNoVolCtrl
2505
	invoke	SysMsgBoardStr
2506
	pop	esi
2507
end if
2508
	jmp	.out
3083 leency 2509
 
2510
; in:   ecx = channel (1 - Left; 2 - Right)
2511
; out:  eax = volume (-10000 - 0)
2512
align 4
2513
get_channel_volume:
5048 Asper 2514
	push	ebx ecx edx
2515
	cmp	ecx, 2
2516
	jg	.out
2517
	dec	cl
2518
	xor	eax, eax
2519
	mov	edx, [volume.out_amp_node]
2520
	test	edx, edx
2521
	jz	.out
2522
	movzx	ebx, [edx+HDA_GNODE.nid]
2523
	stdcall get_volume_mute, ebx, ecx, HDA_OUTPUT, 0
2524
	and	eax, 0x7F ;get gain
2525
	mov	cl, [volume.step_size]
2526
	mul	cl
2527
	imul	eax, (-100/4)
2528
.out:
2529
	pop	edx ecx ebx
2530
	ret
3083 leency 2531
 
2532
 
2533
; in:  ecx = delay
2534
udelay:
3496 Asper 2535
	push	eax ecx edx
2536
	test	ecx, ecx
2537
	jnz	@f
2538
	inc	ecx
5048 Asper 2539
@@:
3496 Asper 2540
	mov	eax, ecx
2541
	mov	cx, 500
2542
	mul	cl
2543
	mov	ecx, edx
2544
	shl	ecx, 16
2545
	or	ecx, eax
5048 Asper 2546
@@:
3496 Asper 2547
	xor	eax, eax
2548
	cpuid
2549
	dec	ecx
2550
	jz	@b
2551
	pop	edx ecx eax
2552
	ret
3083 leency 2553
 
2554
align 4
2555
proc StallExec
3496 Asper 2556
	push	ecx edx ebx eax
3083 leency 2557
 
3496 Asper 2558
	mov	ecx, CPU_FREQ
2559
	mul	ecx
2560
	mov	ebx, eax       ;low
2561
	mov	ecx, edx       ;high
2562
	rdtsc
2563
	add	ebx, eax
2564
	adc	ecx,edx
5048 Asper 2565
@@:
3496 Asper 2566
	rdtsc
2567
	sub	eax, ebx
2568
	sbb	edx, ecx
2569
	js	@B
3083 leency 2570
 
3496 Asper 2571
	pop	eax ebx edx ecx
2572
	ret
3083 leency 2573
endp
2574
 
2575
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2576
;         MEMORY MAPPED IO    (os depended) ;
2577
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2578
 
2579
align 4
2580
proc azx_readb
3496 Asper 2581
	add	edx, [ctrl.ctrl_mem_base]
2582
	mov	al, [edx]
2583
	ret
3083 leency 2584
endp
2585
 
2586
align 4
2587
proc azx_readw
3496 Asper 2588
	add	edx, [ctrl.ctrl_mem_base]
2589
	mov	ax, [edx]
2590
	ret
3083 leency 2591
endp
2592
 
2593
align 4
2594
proc azx_readl
3496 Asper 2595
	add	edx, [ctrl.ctrl_mem_base]
2596
	mov	eax, [edx]
2597
	ret
3083 leency 2598
endp
2599
 
2600
align 4
2601
proc azx_writeb
3496 Asper 2602
	add	edx, [ctrl.ctrl_mem_base]
2603
	mov	[edx], al
2604
	ret
3083 leency 2605
endp
2606
 
2607
align 4
2608
proc azx_writew
3496 Asper 2609
	add	edx, [ctrl.ctrl_mem_base]
2610
	mov	[edx], ax
2611
	ret
3083 leency 2612
endp
2613
 
2614
align 4
2615
proc azx_writel
3496 Asper 2616
	add	edx, [ctrl.ctrl_mem_base]
2617
	mov	[edx], eax
2618
	ret
3083 leency 2619
endp
2620
 
2621
;_______
2622
 
6943 Asper 2623
proc  snd_hda_automute stdcall, data:dword
2624
	push	eax ebx ecx edx esi
2625
	mov	esi, [spec.out_pin_node+4]
2626
	mov	ecx, [spec.out_pin_node]
2627
	test	esi, esi
2628
	jnz	@f
2629
	xchg	ecx, esi
2630
	test	esi, esi
2631
	jz	.out
2632
@@:
2633
	movzx	edx, word [esi + HDA_GNODE.nid]
2634
	stdcall is_jack_detectable, edx
2635
	test	eax, eax
2636
	jz	.out
3083 leency 2637
 
6943 Asper 2638
	stdcall snd_hda_read_pin_sense, edx, 1
2639
	test	eax, AC_PINSENSE_PRESENCE
2640
	jnz	@f
2641
	xchg	ecx, esi
2642
@@:
2643
	; set PIN-Out enable
2644
	test	esi, esi
2645
	jz	.out
2646
	xor	edx, edx
2647
	test	[esi + HDA_GNODE.pin_caps], AC_PINCAP_HP_DRV
2648
	jz	@f
2649
	mov	edx, AC_PINCTL_HP_EN
2650
@@:
2651
	or	edx, AC_PINCTL_OUT_EN
2652
	movzx	eax, [esi + HDA_GNODE.nid]
2653
	stdcall snd_hda_codec_write, eax, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, edx
2654
 
2655
	; set PIN-Out disable
2656
	test	ecx, ecx
2657
	jz	.out
2658
	xor	edx, edx
2659
	movzx	eax, [ecx + HDA_GNODE.nid]
2660
	stdcall snd_hda_codec_write, eax, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, edx
2661
.out:
2662
	pop	esi edx ecx ebx eax
2663
	ret
2664
endp
2665
 
2666
 
3083 leency 2667
;Asper remember to add this functions:
2668
proc  snd_hda_queue_unsol_event stdcall, par1:dword, par2:dword
6946 Asper 2669
;if DEBUG
2670
;        push    esi
2671
;        mov     esi, msgUnsolEvent
2672
;        invoke  SysMsgBoardStr
2673
;        pop     esi
2674
;end if
6945 Asper 2675
if USE_UNSOL_EV = 1
5048 Asper 2676
	;Test. Do not make queue, process immediately!
2677
	;stdcall here snd_hda_read_pin_sense stdcall, nid:dword, trigger_sense:dword
2678
	;and then mute/unmute pin based on the results
6943 Asper 2679
	invoke	TimerHS, 1, 0, snd_hda_automute, 0
5048 Asper 2680
end if
3496 Asper 2681
	ret
3083 leency 2682
endp
2683
;...
2684
 
2685
 
2686
align 4
2687
proc  fdword2str stdcall, flags:dword	; bit 0 - skipLeadZeroes; bit 1 - newLine; other bits undefined
3496 Asper 2688
	push	eax ebx ecx
2689
	mov	esi, hex_buff
2690
	mov	ecx, -8
2691
	push	eax
5048 Asper 2692
@@:
3496 Asper 2693
	rol	eax, 4
2694
	mov	ebx, eax
2695
	and	ebx, 0x0F
2696
	mov	bl, [ebx+hexletters]
2697
	mov	[8+esi+ecx], bl
2698
	inc	ecx
2699
	jnz	@b
2700
	pop	eax
3083 leency 2701
 
3496 Asper 2702
	mov	dword [esi+8], 0
2703
	test	[flags], 0x2 ; new line ?
2704
	jz	.no_newline
2705
	mov	dword [esi+8], 0x00000A0D
5048 Asper 2706
.no_newline:
3083 leency 2707
 
3496 Asper 2708
	push	eax
2709
	test	[flags], 0x1 ; skip zero bits ?
2710
	jz	.no_skipz
2711
	mov	ecx, 8
5048 Asper 2712
@@:
3496 Asper 2713
	test	eax, 0xF0000000
2714
	jnz	.skipz_done
2715
	rol	eax, 4
2716
	inc	esi
2717
	dec	ecx
2718
	jnz	@b
2719
	dec	esi
5048 Asper 2720
.skipz_done:
2721
.no_skipz:
3496 Asper 2722
	pop	eax
3083 leency 2723
 
3496 Asper 2724
	pop	ecx ebx eax
2725
	ret
3083 leency 2726
endp
2727
 
2728
hexletters   db '0123456789ABCDEF'
2729
hex_buff     db 8 dup(0),13,10,0,0
2730
 
2731
 
3085 leency 2732
include "CODEC.INC"
3083 leency 2733
include "hda_generic.inc"
2734
 
2735
align 4
2736
devices:
2737
; Intel
5048 Asper 2738
	dd (CTRL_INTEL_SCH2    shl 16)+VID_INTEL,msg_INTEL_SCH2,	   AZX_DRIVER_SCH
2739
	dd (CTRL_INTEL_HPT     shl 16)+VID_INTEL,msg_INTEL_HPT, 	   AZX_DRIVER_SCH
2740
	dd (CTRL_INTEL_CPT     shl 16)+VID_INTEL,msg_INTEL_CPT, 	   AZX_DRIVER_PCH
2741
	dd (CTRL_INTEL_PGB     shl 16)+VID_INTEL,msg_INTEL_PGB, 	   AZX_DRIVER_PCH
2742
	dd (CTRL_INTEL_PPT1    shl 16)+VID_INTEL,msg_INTEL_PPT1,	   AZX_DRIVER_PCH
6943 Asper 2743
    dd (CTRL_INTEL_ICH6    shl 16)+VID_INTEL,msg_INTEL_ICH6,	   AZX_DRIVER_ICH
5048 Asper 2744
	dd (CTRL_INTEL_63XXESB shl 16)+VID_INTEL,msg_INTEL_63XXESB,	   AZX_DRIVER_ICH
6943 Asper 2745
    dd (CTRL_INTEL_ICH7    shl 16)+VID_INTEL,msg_INTEL_ICH7,	   AZX_DRIVER_ICH
2746
    dd (CTRL_INTEL_ICH8    shl 16)+VID_INTEL,msg_INTEL_ICH8,	   AZX_DRIVER_ICH
5048 Asper 2747
	dd (CTRL_INTEL_82801_UNK1  shl 16)+VID_INTEL,msg_INTEL_82801_UNK1, AZX_DRIVER_ICH
6943 Asper 2748
    dd (CTRL_INTEL_ICH9    shl 16)+VID_INTEL,msg_INTEL_ICH9,	   AZX_DRIVER_ICH
2749
    dd (CTRL_INTEL_ICH9_2  shl 16)+VID_INTEL,msg_INTEL_ICH9,	   AZX_DRIVER_ICH
2750
    dd (CTRL_INTEL_ICH10   shl 16)+VID_INTEL,msg_INTEL_ICH10,	   AZX_DRIVER_ICH
2751
    dd (CTRL_INTEL_ICH10_2 shl 16)+VID_INTEL,msg_INTEL_ICH10,	   AZX_DRIVER_ICH
5048 Asper 2752
	dd (CTRL_INTEL_PCH     shl 16)+VID_INTEL,msg_INTEL_PCH, 	   AZX_DRIVER_PCH
2753
	dd (CTRL_INTEL_PCH2    shl 16)+VID_INTEL,msg_INTEL_PCH2,	   AZX_DRIVER_PCH
2754
	dd (CTRL_INTEL_SCH     shl 16)+VID_INTEL,msg_INTEL_SCH, 	   AZX_DRIVER_SCH
2755
	dd (CTRL_INTEL_LPT     shl 16)+VID_INTEL,msg_INTEL_LPT, 	   AZX_DRIVER_PCH
6299 serge 2756
    dd (CTRL_INTEL_0F04    shl 16)+VID_INTEL,msg_INTEL_BAYTRAIL,   AZX_DRIVER_PCH
2757
    dd (CTRL_INTEL_2284    shl 16)+VID_INTEL,msg_INTEL_BRASWELL,   AZX_DRIVER_PCH
2758
    dd (CTRL_INTEL_8ca0    shl 16)+VID_INTEL,msg_INTEL_9SERIES,    AZX_DRIVER_PCH
2759
    dd (CTRL_INTEL_8d20    shl 16)+VID_INTEL,msg_INTEL_WELLSBURG,  AZX_DRIVER_PCH
2760
    dd (CTRL_INTEL_8d21    shl 16)+VID_INTEL,msg_INTEL_WELLSBURG,  AZX_DRIVER_PCH
2761
    dd (CTRL_INTEL_A1F0    shl 16)+VID_INTEL,msg_INTEL_LEWISBURG,  AZX_DRIVER_PCH
2762
    dd (CTRL_INTEL_A270    shl 16)+VID_INTEL,msg_INTEL_LEWISBURG,  AZX_DRIVER_PCH
2763
    dd (CTRL_INTEL_9C20    shl 16)+VID_INTEL,msg_INTEL_LYNX_LP,    AZX_DRIVER_PCH
2764
    dd (CTRL_INTEL_9C21    shl 16)+VID_INTEL,msg_INTEL_LYNX_LP,    AZX_DRIVER_PCH
2765
    dd (CTRL_INTEL_9CA0    shl 16)+VID_INTEL,msg_INTEL_WILD_LP,    AZX_DRIVER_PCH
2766
    dd (CTRL_INTEL_A170    shl 16)+VID_INTEL,msg_INTEL_SUNRISE,    AZX_DRIVER_PCH
6943 Asper 2767
    dd (CTRL_INTEL_9D70    shl 16)+VID_INTEL,msg_INTEL_SUN_LP,	   AZX_DRIVER_PCH
6299 serge 2768
    dd (CTRL_INTEL_5A98    shl 16)+VID_INTEL,msg_INTEL_BROXTON,    AZX_DRIVER_PCH
2769
 
3083 leency 2770
; Nvidia
5048 Asper 2771
	dd (CTRL_NVIDIA_MCP51	 shl 16)+VID_NVIDIA,msg_NVIDIA_MCP51,	   AZX_DRIVER_NVIDIA
2772
	dd (CTRL_NVIDIA_MCP55	 shl 16)+VID_NVIDIA,msg_NVIDIA_MCP55,	   AZX_DRIVER_NVIDIA
2773
	dd (CTRL_NVIDIA_MCP61_1  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP61,	   AZX_DRIVER_NVIDIA
2774
	dd (CTRL_NVIDIA_MCP61_2  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP61,	   AZX_DRIVER_NVIDIA
2775
	dd (CTRL_NVIDIA_MCP65_1  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP65,	   AZX_DRIVER_NVIDIA
2776
	dd (CTRL_NVIDIA_MCP65_2  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP65,	   AZX_DRIVER_NVIDIA
2777
	dd (CTRL_NVIDIA_MCP67_1  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP67,	   AZX_DRIVER_NVIDIA
2778
	dd (CTRL_NVIDIA_MCP67_2  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP67,	   AZX_DRIVER_NVIDIA
2779
	dd (CTRL_NVIDIA_MCP73_1  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP73,	   AZX_DRIVER_NVIDIA
2780
	dd (CTRL_NVIDIA_MCP73_2  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP73,	   AZX_DRIVER_NVIDIA
2781
	dd (CTRL_NVIDIA_MCP78_1  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP78,	   AZX_DRIVER_NVIDIA
2782
	dd (CTRL_NVIDIA_MCP78_2  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP78,	   AZX_DRIVER_NVIDIA
2783
	dd (CTRL_NVIDIA_MCP78_3  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP78,	   AZX_DRIVER_NVIDIA
2784
	dd (CTRL_NVIDIA_MCP78_4  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP78,	   AZX_DRIVER_NVIDIA
2785
	dd (CTRL_NVIDIA_MCP79_1  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP79,	   AZX_DRIVER_NVIDIA
2786
	dd (CTRL_NVIDIA_MCP79_2  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP79,	   AZX_DRIVER_NVIDIA
2787
	dd (CTRL_NVIDIA_MCP79_3  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP79,	   AZX_DRIVER_NVIDIA
2788
	dd (CTRL_NVIDIA_MCP79_4  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP79,	   AZX_DRIVER_NVIDIA
2789
	dd (CTRL_NVIDIA_0BE2	 shl 16)+VID_NVIDIA,msg_NVIDIA_0BE2,	   AZX_DRIVER_NVIDIA
2790
	dd (CTRL_NVIDIA_0BE3	 shl 16)+VID_NVIDIA,msg_NVIDIA_0BE3,	   AZX_DRIVER_NVIDIA
2791
	dd (CTRL_NVIDIA_0BE4	 shl 16)+VID_NVIDIA,msg_NVIDIA_0BE4,	   AZX_DRIVER_NVIDIA
2792
	dd (CTRL_NVIDIA_GT100	 shl 16)+VID_NVIDIA,msg_NVIDIA_GT100,	   AZX_DRIVER_NVIDIA
2793
	dd (CTRL_NVIDIA_GT106	 shl 16)+VID_NVIDIA,msg_NVIDIA_GT106,	   AZX_DRIVER_NVIDIA
2794
	dd (CTRL_NVIDIA_GT108	 shl 16)+VID_NVIDIA,msg_NVIDIA_GT108,	   AZX_DRIVER_NVIDIA
2795
	dd (CTRL_NVIDIA_GT104	 shl 16)+VID_NVIDIA,msg_NVIDIA_GT104,	   AZX_DRIVER_NVIDIA
2796
	dd (CTRL_NVIDIA_GT116	 shl 16)+VID_NVIDIA,msg_NVIDIA_GT116,	   AZX_DRIVER_NVIDIA
2797
	dd (CTRL_NVIDIA_MCP89_1  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP89,	   AZX_DRIVER_NVIDIA
2798
	dd (CTRL_NVIDIA_MCP89_2  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP89,	   AZX_DRIVER_NVIDIA
2799
	dd (CTRL_NVIDIA_MCP89_3  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP89,	   AZX_DRIVER_NVIDIA
2800
	dd (CTRL_NVIDIA_MCP89_4  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP89,	   AZX_DRIVER_NVIDIA
2801
	dd (CTRL_NVIDIA_GF119	 shl 16)+VID_NVIDIA,msg_NVIDIA_GF119,	   AZX_DRIVER_NVIDIA
2802
	dd (CTRL_NVIDIA_GF110_1  shl 16)+VID_NVIDIA,msg_NVIDIA_GF110,	   AZX_DRIVER_NVIDIA
2803
	dd (CTRL_NVIDIA_GF110_2  shl 16)+VID_NVIDIA,msg_NVIDIA_GF110,	   AZX_DRIVER_NVIDIA
3083 leency 2804
; ATI
5048 Asper 2805
	dd (CTRL_ATI_SB450  shl 16)+VID_ATI,msg_ATI_SB450,		   AZX_DRIVER_ATI
2806
	dd (CTRL_ATI_SB600  shl 16)+VID_ATI,msg_ATI_SB600,		   AZX_DRIVER_ATI
2807
	dd (CTRL_ATI_RS600  shl 16)+VID_ATI,msg_ATI_RS600,		   AZX_DRIVER_ATIHDMI
2808
	dd (CTRL_ATI_RS690  shl 16)+VID_ATI,msg_ATI_RS690,		   AZX_DRIVER_ATIHDMI
2809
	dd (CTRL_ATI_RS780  shl 16)+VID_ATI,msg_ATI_RS780,		   AZX_DRIVER_ATIHDMI
2810
	dd (CTRL_ATI_RS_UNK1  shl 16)+VID_ATI,msg_ATI_RS_UNK1,		   AZX_DRIVER_ATIHDMI
2811
	dd (CTRL_ATI_R600   shl 16)+VID_ATI,msg_ATI_R600,		   AZX_DRIVER_ATIHDMI
2812
	dd (CTRL_ATI_RV610  shl 16)+VID_ATI,msg_ATI_RV610,		   AZX_DRIVER_ATIHDMI
2813
	dd (CTRL_ATI_RV620  shl 16)+VID_ATI,msg_ATI_RV620,		   AZX_DRIVER_ATIHDMI
2814
	dd (CTRL_ATI_RV630  shl 16)+VID_ATI,msg_ATI_RV630,		   AZX_DRIVER_ATIHDMI
2815
	dd (CTRL_ATI_RV635  shl 16)+VID_ATI,msg_ATI_RV635,		   AZX_DRIVER_ATIHDMI
2816
	dd (CTRL_ATI_RV670  shl 16)+VID_ATI,msg_ATI_RV670,		   AZX_DRIVER_ATIHDMI
2817
	dd (CTRL_ATI_RV710  shl 16)+VID_ATI,msg_ATI_RV710,		   AZX_DRIVER_ATIHDMI
2818
	dd (CTRL_ATI_RV730  shl 16)+VID_ATI,msg_ATI_RV730,		   AZX_DRIVER_ATIHDMI
2819
	dd (CTRL_ATI_RV740  shl 16)+VID_ATI,msg_ATI_RV740,		   AZX_DRIVER_ATIHDMI
2820
	dd (CTRL_ATI_RV770  shl 16)+VID_ATI,msg_ATI_RV770,		   AZX_DRIVER_ATIHDMI
3083 leency 2821
; AMD
5048 Asper 2822
	dd (CTRL_AMD_HUDSON shl 16)+VID_AMD,msg_AMD_HUDSON,		   AZX_DRIVER_GENERIC
7737 dunkaist 2823
	dd (CTRL_AMD_RAVEN_RIDGE shl 16)+VID_AMD,msg_AMD_RAVEN_RIDGE,	   AZX_DRIVER_GENERIC
9285 punk_joker 2824
	dd (CTRL_AMD_MATISSE shl 16)+VID_AMD,msg_AMD_MATISSE,	   AZX_DRIVER_GENERIC
3083 leency 2825
; VIA
5048 Asper 2826
	dd (CTRL_VIA_VT82XX shl 16)+VID_VIA,msg_VIA_VT82XX,		   AZX_DRIVER_VIA
2827
	dd (CTRL_VIA_VT61XX shl 16)+VID_VIA,msg_VIA_VT61XX,		   AZX_DRIVER_GENERIC
2828
	dd (CTRL_VIA_VT71XX shl 16)+VID_VIA,msg_VIA_VT71XX,		   AZX_DRIVER_GENERIC
3083 leency 2829
; SiS
5048 Asper 2830
	dd (CTRL_SIS_966    shl 16)+VID_SIS,msg_SIS_966,		   AZX_DRIVER_SIS
3083 leency 2831
; ULI
5048 Asper 2832
	dd (CTRL_ULI_M5461  shl 16)+VID_ULI,msg_ULI_M5461,		   AZX_DRIVER_ULI
3083 leency 2833
; Teradici
5048 Asper 2834
	dd (CTRL_TERA_UNK1  shl 16)+VID_ULI,msg_TERA_UNK1,		   AZX_DRIVER_TERA
3083 leency 2835
; Creative
5048 Asper 2836
	dd (CTRL_CREATIVE_CA0110_IBG	 shl 16)+VID_CREATIVE,msg_CREATIVE_CA0110_IBG,	 AZX_DRIVER_CTX
2837
	dd (CTRL_CREATIVE_SOUND_CORE3D_1 shl 16)+VID_CREATIVE,msg_CREATIVE_SOUND_CORE3D, AZX_DRIVER_GENERIC
2838
	dd (CTRL_CREATIVE_SOUND_CORE3D_2 shl 16)+VID_CREATIVE,msg_CREATIVE_SOUND_CORE3D, AZX_DRIVER_GENERIC
3083 leency 2839
; RDC Semiconductor
5048 Asper 2840
	dd (CTRL_RDC_R3010  shl 16)+VID_RDC,msg_RDC_R3010,		   AZX_DRIVER_GENERIC
3083 leency 2841
; VMware
5048 Asper 2842
	dd (CTRL_VMWARE_UNK1  shl 16)+VID_VMWARE,msg_VMWARE_UNK1,	   AZX_DRIVER_GENERIC
3083 leency 2843
 
5048 Asper 2844
	dd 0	;terminator
3083 leency 2845
 
2846
 
2847
version      dd (5 shl 16) or (API_VERSION and 0xFFFF)
2848
 
2849
msg_Intel		db 'Intel ',0
2850
msg_INTEL_CPT		db 'Cougar Point',13,10,0
2851
msg_INTEL_PGB		db 'Patsburg',13,10,0
2852
msg_INTEL_PPT1		db 'Panther Point',13,10,0
2853
msg_INTEL_LPT		db 'Lynx Point',13,10,0
2854
msg_INTEL_HPT		db 'Haswell',13,10,0
6943 Asper 2855
msg_INTEL_ICH6	    db 'ICH6',13,10,0
3083 leency 2856
msg_INTEL_63XXESB	db '631x/632xESB',13,10,0
6943 Asper 2857
msg_INTEL_ICH7	    db 'ICH7', 13,10,0
2858
msg_INTEL_ICH8	    db 'ICH8', 13,10,0
2859
msg_INTEL_ICH9	    db 'ICH9', 13,10,0
6299 serge 2860
msg_INTEL_ICH10     db 'ICH10',13,10,0
3083 leency 2861
msg_INTEL_PCH		db 'PCH',13,10,0
2862
msg_INTEL_PCH2		db 'PCH2',13,10,0
2863
msg_INTEL_SCH		db 'Poulsbo',13,10,0
2864
msg_INTEL_SCH2		db 'Oaktrail',13,10,0
6299 serge 2865
msg_INTEL_BAYTRAIL  db 'BayTrail',  13,10,0
2866
msg_INTEL_BRASWELL  db 'Braswell',  13,10,0
2867
msg_INTEL_9SERIES   db '9 Series',  13,10,0
2868
msg_INTEL_WELLSBURG db 'Wellsburg',  13,10,0
2869
msg_INTEL_LEWISBURG db 'Lewisburg',  13,10,0
2870
msg_INTEL_LYNX_LP   db 'Lynx Point-LP',13,10,0
2871
msg_INTEL_WILD_LP   db 'Wildcat Point-LP',13,10,0
2872
msg_INTEL_SUNRISE   db 'Sunrise Point',13,10,0
2873
msg_INTEL_SUN_LP    db 'Sunrise Point-LP',13,10,0
2874
msg_INTEL_BROXTON   db 'Broxton-P',13,10,0
2875
 
3083 leency 2876
msg_INTEL_82801_UNK1	db '82801_UNK1',  13,10,0
2877
 
2878
msg_NVidia		db 'NVidia ',0
2879
msg_NVIDIA_MCP51	db 'MCP51',	 13,10,0
2880
msg_NVIDIA_MCP55	db 'MCP55',	 13,10,0
2881
msg_NVIDIA_MCP61	db 'MCP61',	 13,10,0
2882
msg_NVIDIA_MCP65	db 'MCP65',	 13,10,0
2883
msg_NVIDIA_MCP67	db 'MCP67',	 13,10,0
2884
msg_NVIDIA_MCP73	db 'MCP73',	 13,10,0
2885
msg_NVIDIA_MCP78	db 'MCP78',	 13,10,0
2886
msg_NVIDIA_MCP79	db 'MCP79',	 13,10,0
2887
msg_NVIDIA_MCP89	db 'MCP89',	 13,10,0
2888
msg_NVIDIA_0BE2 	db '(0x0be2)',	 13,10,0
2889
msg_NVIDIA_0BE3 	db '(0x0be3)',	 13,10,0
2890
msg_NVIDIA_0BE4 	db '(0x0be4)',	 13,10,0
2891
msg_NVIDIA_GT100	db 'GT100',	 13,10,0
2892
msg_NVIDIA_GT104	db 'GT104',	 13,10,0
2893
msg_NVIDIA_GT106	db 'GT106',	 13,10,0
2894
msg_NVIDIA_GT108	db 'GT108',	 13,10,0
2895
msg_NVIDIA_GT116	db 'GT116',	 13,10,0
2896
msg_NVIDIA_GF119	db 'GF119',	 13,10,0
2897
msg_NVIDIA_GF110	db 'GF110',	 13,10,0
2898
 
2899
msg_ATI 	     db 'ATI ',0
2900
msg_ATI_SB450	     db 'SB450',      13,10,0
2901
msg_ATI_SB600	     db 'SB600',      13,10,0
2902
 
2903
msg_ATI_HDMI	     db 'ATI HDMI ',0
2904
msg_ATI_RS600	     db 'RS600',      13,10,0
2905
msg_ATI_RS690	     db 'RS690',      13,10,0
2906
msg_ATI_RS780	     db 'RS780',      13,10,0
2907
msg_ATI_RS_UNK1      db 'RS_UNK1',    13,10,0
2908
msg_ATI_R600	     db 'R600',       13,10,0
2909
msg_ATI_RV610	     db 'RV610',      13,10,0
2910
msg_ATI_RV620	     db 'RV620',      13,10,0
2911
msg_ATI_RV630	     db 'RV630',      13,10,0
2912
msg_ATI_RV635	     db 'RV635',      13,10,0
2913
msg_ATI_RV670	     db 'RV670',      13,10,0
2914
msg_ATI_RV710	     db 'RV710',      13,10,0
2915
msg_ATI_RV730	     db 'RV730',      13,10,0
2916
msg_ATI_RV740	     db 'RV740',      13,10,0
2917
msg_ATI_RV770	     db 'RV770',      13,10,0
2918
 
2919
msg_AMD 	     db 'AMD ',0
2920
msg_AMD_HUDSON	     db 'Hudson',     13,10,0
7737 dunkaist 2921
msg_AMD_RAVEN_RIDGE  db 'RavenRidge', 13,10,0
9285 punk_joker 2922
msg_AMD_MATISSE	     db 'Matisse',    13,10,0
3083 leency 2923
 
2924
msg_VIA 	     db 'VIA ',0
2925
msg_VIA_VT82XX	     db 'VT8251/8237A',     13,10,0
2926
msg_VIA_VT61XX	     db 'GFX VT6122/VX11',  13,10,0
2927
msg_VIA_VT71XX	     db 'GFX VT7122/VX900', 13,10,0
2928
 
2929
msg_SIS 	     db 'SIS ',0
2930
msg_SIS_966	     db '966',	    13,10,0
2931
 
2932
msg_ULI 	     db 'ULI ',0
2933
msg_ULI_M5461	     db 'M5461',      13,10,0
2934
 
2935
msg_TERA	     db 'Teradici ',0
2936
msg_TERA_UNK1	     db 'UNK1',      13,10,0
2937
 
2938
msg_CREATIVE		      db 'Creative ',0
2939
msg_CREATIVE_CA0110_IBG       db 'CA0110-IBG',13,10,0 ;SB X-Fi Xtreme Audio
2940
msg_CREATIVE_SOUND_CORE3D     db 'Sound Core3D'
2941
 
2942
msg_RDC 	     db 'RDC ',0
2943
msg_RDC_R3010	     db 'R3010', 13,10,0
2944
 
2945
msg_VMWARE	     db 'VMware ',0
2946
msg_VMWARE_UNK1      db 'UNK1', 13,10,0
2947
 
2948
szKernel	     db 'KERNEL',0
2949
sz_sound_srv	     db 'SOUND',0
2950
 
2951
msgInit      db 'detect hardware...',13,10,0
2952
msgFail      db 'device not found',13,10,0
2953
msgAttchIRQ  db 'IRQ line not supported', 13,10,0
2954
msgInvIRQ    db 'IRQ line not assigned or invalid', 13,10,0
2955
msgPlay      db 'start play', 13,10,0
2956
msgStop      db 'stop play',  13,10,0
2957
msgSetChannelVolume  db 'Set Channel Volume', 13,10,0
2958
msgIRQ	     db 'HDA IRQ', 13,10,0
2959
msgInitCtrl  db 'init controller',13,10,0
2960
msgPrimBuff  db 'create primary buffer ...',0
2961
msgDone      db 'done',13,10,0
2962
msgRemap     db 'Remap IRQ',13,10,0
2963
msgOk	     db 'service installed',13,10,0
2964
msgCold      db 'cold reset',13,10,0
2965
    msgHDARFail    db 'controller not ready',13,10,0
2966
msgCFail     db 'codec not ready',13,10,0
2967
msgResetOk   db 'reset complete',13,10,0
2968
msgPciCmd    db 'PCI command     ',0
2969
msgPciStat   db 'PCI status      ',0
2970
    msgHDALowMMIo db 'lower mmio base ',0
2971
    msgHDAUpMMIo  db 'upper mmio base ',0
2972
msgIrqMap    db 'HDA irq map as      ',0
6946 Asper 2973
;msgUnsolEvent db 'Unsolicited event!',13,10,0
3083 leency 2974
 
2975
;Asper [
2976
if DEBUG
2977
    msgCodecMask	     db 'codec_mask = ',0
2978
    msgNoCodecsFound	     db 'no codecs found!',13,10,0
2979
    msgHDASnoopDisabled      db 'HDA snoop disabled, enabling ... ',0
2980
    msg_OK		     db 'OK',13,10,0
2981
    msg_Fail		     db 'Failed',13,10,0
2982
    msgSpuriousResponce      db 'spurious responce ',0
2983
    emsgInvalidAFGSubtree    db 'Invalid AFG subtree',13,10,0
2984
    emsgConnListNotAvailable db 'connection list not available for ',0
2985
    msgUnmuteOut	     db 'UNMUTE OUT: NID=',0
2986
    msgUnmuteIn 	     db 'UNMUTE IN: NID=',0
2987
    msgGetResponceTimeout    db 'get_response timeout: ',0
2988
    msgVal		     db ' val=',0
2989
    emsgBusResetFatalComm    db 'resetting BUS due to fatal communication error',13,10,0
2990
    msgCodecOK		     db 'codec probed OK',13,10,0
2991
    msgCodecError	     db 'codec probe error disabling it...',13,10,0
2992
    emsgNoAFGorMFGFound      db 'no AFG or MFG node found',13,10,0
4324 Asper 2993
    msgNoAFGFound	     db 'no AFG node found, trying another codec',13,10,0
3083 leency 2994
    emsgNoMem		     db 'hda_codec: cannot malloc',13,10,0
2995
    msgConnect		     db 'CONNECT: NID=',0
2996
    msgIdx		     db ' IDX=',0
2997
    msgSkipDigitalOutNode    db 'Skip Digital OUT node ',0
2998
    msgAudOutFound	     db 'AUD_OUT found ',0
2999
    emsgNoParserAvailable    db 'No codec parser is available',13,10,0
3000
    emsgNoProperOutputPathFound  db 'hda_generic: no proper output path found',13,10,0
3001
    emsgInvConnList	     db 'hda_codec: invalid CONNECT_LIST verb ',0
3002
    emsgInvDepRangeVal	     db 'hda_codec: invalid dep_range_val ',0
3003
    emsgTooManyConns	     db 'Too many connections',13,10,0
3004
	emsgNoVolCtrl	     db 'No volume control',13,10,0
3005
    msgHDACodecSetupStream   db 'hda_codec_setup_stream: NID=',0
3006
    msgStream		     db 'stream=',0
3007
    msgChannel		     db 'channel=',0
3008
    msgFormat		     db 'format=',0
3009
 
3010
    msgPollingCodecOnce      db 'polling the codec once',13,10,0 ;Asper~
3011
    msgSwitchToPollMode      db 'switching to polling mode',13,10,0 ;Asper~
3012
 
3013
    strSemicolon	     db ':',0
3014
    msgSETUP_FG_NODES	     db 'Setup FG nodes = start_nid:total_nodes = ',0
3015
    msgFG_TYPE		     db 'FG type = ',0
3016
    msgPinCfgs		     db 'Pin configurations:',13,10,0
3017
    msgWCaps		     db 'Widget capabilities:',13,10,0
3018
    msgCAd		     db 'CAd = ',0
3019
    msgTCSEL		     db 'PCI TCSEL     ',0
3020
    msgTV		     db 'HDA test version ',TEST_VERSION_NUMBER,13,10,0
3021
    msgGCap		     db 'GCAP = ',0
3022
end if
3023
 
3024
if USE_SINGLE_MODE
3025
    msgSingleMode	     db 'Single mode !',13,10,0
3026
    msgIRS		     db 'IRS=',0
3027
    msgSendCmdTimeout	     db 'send_cmd timeout: IRS=',0
3028
else
3029
    msgNormalMode	     db 'Normal mode !',13,10,0
3030
end if
3031
 
3032
if DEBUG
3033
    msgYAHOO2		     db 'YAHOO2: ',0
5048 Asper 3034
    msgMinVolume	     db 'MinVolume: ',0
3083 leency 3035
    msgNewVolume	     db 'NewVolume: ',0
3036
 
3037
    msgVerbQuery	     db 'Q: ',0
3038
    msgVerbAnswer	     db 'A: ',0
3039
    msgPin_Nid		     db 'Pin Nid = ',0
3040
    msgPin_Ctl		     db 'Pin Control = ',0
3041
    msgPin_Caps 	     db 'Pin Capabilities = ',0
3042
    msgDef_Cfg		     db 'Pin def_cfg = ',0
3043
    msgAmp_Out_Caps	     db 'Pin Amp Out caps = ',0
3044
    msgAmpVal		     db 'Amp val = ',0
3045
    msgEnableEAPD	     db 'Enable EAPD: NID=',0
3046
    msgBeeperNid	     db 'Beeper found: NID=',0
3047
    msgBeeperValue	     db 'Beeper initial value: ',0
3048
    msgBeepNow		     db 'Beep!',13,10,0
5048 Asper 3049
 
3050
    msgNodeSeq		     db 'Sequence of codec nodes:',13,10,0
3051
    msgNID		     db 'NID: 0x',0
3083 leency 3052
end if
3053
 
3054
;] Asper
3055
 
3496 Asper 3056
aspinlock	 dd SPINLOCK_FREE
3083 leency 3057
 
3058
codec CODEC
3059
ctrl AC_CNTRL
3060
 
3061
;Asper: BDL must be aligned to 128 according to HDA specification.
3062
pcmout_bdl	 rd 1
3063
buff_list	 rd 32
3064
 
3065
driver_type	 rd 1