Rev 2106 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
802 | serge | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3 | ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; |
||
4 | ;; Distributed under terms of the GNU General Public License ;; |
||
5 | ;; ;; |
||
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
7 | |||
8 | format MS COFF |
||
9 | |||
2434 | Serge | 10 | DEBUG equ 1 |
802 | serge | 11 | |
12 | include 'proc32.inc' |
||
13 | include 'imports.inc' |
||
14 | |||
2434 | Serge | 15 | API_VERSION equ 0x01000100 |
802 | serge | 16 | |
2434 | Serge | 17 | DEBUG_IRQ equ 0 |
802 | serge | 18 | |
2434 | Serge | 19 | USE_COM_IRQ equ 0 ;make irq 3 and irq 4 available for PCI devices |
20 | IRQ_REMAP equ 0 |
||
21 | IRQ_LINE equ 0 |
||
802 | serge | 22 | |
23 | |||
24 | ;irq 0,1,2,8,12,13 недоступны |
||
25 | ; FEDCBA9876543210 |
||
2434 | Serge | 26 | VALID_IRQ equ 1100111011111000b |
27 | ATTCH_IRQ equ 0000111010100000b |
||
802 | serge | 28 | |
29 | if USE_COM_IRQ |
||
2434 | Serge | 30 | ATTCH_IRQ equ 0000111010111000b |
802 | serge | 31 | end if |
32 | |||
2434 | Serge | 33 | CPU_FREQ equ 2600d |
802 | serge | 34 | |
35 | BIT0 EQU 0x00000001 |
||
36 | BIT1 EQU 0x00000002 |
||
37 | BIT2 EQU 0x00000004 |
||
38 | BIT3 EQU 0x00000008 |
||
39 | BIT4 EQU 0x00000010 |
||
40 | BIT5 EQU 0x00000020 |
||
41 | BIT6 EQU 0x00000040 |
||
42 | BIT7 EQU 0x00000080 |
||
43 | BIT8 EQU 0x00000100 |
||
44 | BIT9 EQU 0x00000200 |
||
45 | BIT10 EQU 0x00000400 |
||
46 | BIT11 EQU 0x00000800 |
||
47 | BIT12 EQU 0x00001000 |
||
48 | BIT13 EQU 0x00002000 |
||
49 | BIT14 EQU 0x00004000 |
||
50 | BIT15 EQU 0x00008000 |
||
51 | BIT16 EQU 0x00010000 |
||
52 | BIT17 EQU 0x00020000 |
||
53 | BIT18 EQU 0x00040000 |
||
54 | BIT19 EQU 0x00080000 |
||
55 | BIT20 EQU 0x00100000 |
||
56 | BIT21 EQU 0x00200000 |
||
57 | BIT22 EQU 0x00400000 |
||
58 | BIT23 EQU 0x00800000 |
||
59 | BIT24 EQU 0x00100000 |
||
60 | BIT25 EQU 0x02000000 |
||
61 | BIT26 EQU 0x04000000 |
||
62 | BIT27 EQU 0x08000000 |
||
63 | BIT28 EQU 0x10000000 |
||
64 | BIT29 EQU 0x20000000 |
||
65 | BIT30 EQU 0x40000000 |
||
66 | BIT31 EQU 0x80000000 |
||
67 | |||
68 | PCM_4 equ BIT20 |
||
69 | PCM_6 equ BIT21 |
||
70 | |||
2434 | Serge | 71 | VID_INTEL equ 0x8086 |
72 | VID_NVIDIA equ 0x10DE |
||
802 | serge | 73 | |
2434 | Serge | 74 | CTRL_ICH equ 0x2415 |
75 | CTRL_ICH0 equ 0x2425 |
||
76 | CTRL_ICH2 equ 0x2435 |
||
77 | CTRL_ICH3 equ 0x2445 |
||
78 | CTRL_ICH4 equ 0x24C5 |
||
79 | CTRL_ICH5 equ 0x24D5 |
||
80 | CTRL_ICH6 equ 0x266E |
||
81 | CTRL_ICH7 equ 0x27DE |
||
802 | serge | 82 | |
2434 | Serge | 83 | CTRL_NFORCE equ 0x01B1 |
84 | CTRL_NFORCE2 equ 0x006A |
||
85 | CTRL_NFORCE3 equ 0x00DA |
||
86 | CTRL_MCP04 equ 0x003A |
||
87 | CTRL_CK804 equ 0x0059 |
||
88 | CTRL_CK8 equ 0x008A |
||
89 | CTRL_CK8S equ 0x00EA |
||
90 | CTRL_MCP51 equ 0x026B |
||
802 | serge | 91 | |
92 | |||
2434 | Serge | 93 | PCM_OUT_BDL equ 0x10 ; PCM out buffer descriptors list |
94 | PCM_OUT_CR_REG equ 0x1b ; PCM out Control Register |
||
802 | serge | 95 | PCM_OUT_LVI_REG equ 0x15 ; PCM last valid index |
2434 | Serge | 96 | PCM_OUT_SR_REG equ 0x16 ; PCM out Status register |
802 | serge | 97 | PCM_OUT_PIV_REG equ 0x1a |
98 | PCM_OUT_CIV_REG equ 0x14 ; PCM out current index |
||
99 | |||
2434 | Serge | 100 | PCM_IN_CR_REG equ 0x0b ; PCM in Control Register |
101 | MC_IN_CR_REG equ 0x2b ; MIC in Control Register |
||
102 | RR equ BIT1 ; reset registers. Nukes all regs |
||
802 | serge | 103 | |
2434 | Serge | 104 | CODEC_MASTER_VOL_REG equ 0x02 |
105 | CODEC_AUX_VOL equ 0x04 ; |
||
106 | CODEC_PCM_OUT_REG equ 0x18 ; PCM output volume |
||
107 | CODEC_EXT_AUDIO_REG equ 0x28 ; extended audio |
||
802 | serge | 108 | CODEC_EXT_AUDIO_CTRL_REG equ 0x2a ; extended audio control |
109 | CODEC_PCM_FRONT_DACRATE_REG equ 0x2c ; PCM out sample rate |
||
110 | CODEC_PCM_SURND_DACRATE_REG equ 0x2e ; surround sound sample rate |
||
111 | CODEC_PCM_LFE_DACRATE_REG equ 0x30 ; LFE sample rate |
||
112 | |||
2434 | Serge | 113 | GLOB_CTRL equ 0x2C ; Global Control |
114 | CTRL_STAT equ 0x30 ; Global Status |
||
115 | CTRL_CAS equ 0x34 ; Codec Access Semiphore |
||
802 | serge | 116 | |
2434 | Serge | 117 | CAS_FLAG equ 0x01 ; Codec Access Semiphore Bit |
802 | serge | 118 | |
2434 | Serge | 119 | CTRL_ST_CREADY equ BIT8+BIT9+BIT28 ; Primary Codec Ready |
802 | serge | 120 | |
2434 | Serge | 121 | CTRL_ST_RCS equ 0x00008000 ; Read Completion Status |
802 | serge | 122 | |
2434 | Serge | 123 | CTRL_CNT_CRIE equ BIT4+BIT5+BIT6 ; Codecs Resume Interrupt Enable |
802 | serge | 124 | CTRL_CNT_AC_OFF equ 0x00000008 ; ACLINK Off |
2434 | Serge | 125 | CTRL_CNT_WARM equ 0x00000004 ; AC97 Warm Reset |
126 | CTRL_CNT_COLD equ 0x00000002 ; AC97 Cold Reset |
||
127 | CTRL_CNT_GIE equ 0x00000001 ; GPI Interrupt Enable |
||
802 | serge | 128 | |
129 | CODEC_REG_POWERDOWN equ 0x26 |
||
2434 | Serge | 130 | CODEC_REG_ST equ 0x26 |
802 | serge | 131 | |
2434 | Serge | 132 | SRV_GETVERSION equ 0 |
133 | DEV_PLAY equ 1 |
||
134 | DEV_STOP equ 2 |
||
135 | DEV_CALLBACK equ 3 |
||
136 | DEV_SET_BUFF equ 4 |
||
137 | DEV_NOTIFY equ 5 |
||
802 | serge | 138 | DEV_SET_MASTERVOL equ 6 |
139 | DEV_GET_MASTERVOL equ 7 |
||
2434 | Serge | 140 | DEV_GET_INFO equ 8 |
2010 | serge | 141 | DEV_GET_POS equ 9 |
802 | serge | 142 | |
2434 | Serge | 143 | struc AC_CNTRL ;AC controller base class |
144 | { .bus dd ? |
||
145 | .devfn dd ? |
||
802 | serge | 146 | |
2434 | Serge | 147 | .vendor dd ? |
148 | .dev_id dd ? |
||
149 | .pci_cmd dd ? |
||
150 | .pci_stat dd ? |
||
802 | serge | 151 | |
152 | .codec_io_base dd ? |
||
153 | .codec_mem_base dd ? |
||
154 | |||
155 | .ctrl_io_base dd ? |
||
156 | .ctrl_mem_base dd ? |
||
2434 | Serge | 157 | .cfg_reg dd ? |
158 | .int_line dd ? |
||
802 | serge | 159 | |
2434 | Serge | 160 | .vendor_ids dd ? ;vendor id string |
161 | .ctrl_ids dd ? ;hub id string |
||
802 | serge | 162 | |
2434 | Serge | 163 | .buffer dd ? |
802 | serge | 164 | |
2434 | Serge | 165 | .notify_pos dd ? |
166 | .notify_task dd ? |
||
802 | serge | 167 | |
2434 | Serge | 168 | .lvi_reg dd ? |
169 | .ctrl_setup dd ? |
||
802 | serge | 170 | .user_callback dd ? |
171 | .codec_read16 dd ? |
||
172 | .codec_write16 dd ? |
||
173 | |||
2434 | Serge | 174 | .ctrl_read8 dd ? |
175 | .ctrl_read16 dd ? |
||
176 | .ctrl_read32 dd ? |
||
802 | serge | 177 | |
2434 | Serge | 178 | .ctrl_write8 dd ? |
802 | serge | 179 | .ctrl_write16 dd ? |
180 | .ctrl_write32 dd ? |
||
181 | } |
||
182 | |||
2434 | Serge | 183 | struc CODEC ;Audio Chip base class |
802 | serge | 184 | { |
2434 | Serge | 185 | .chip_id dd ? |
186 | .flags dd ? |
||
187 | .status dd ? |
||
802 | serge | 188 | |
189 | .ac_vendor_ids dd ? ;ac vendor id string |
||
2434 | Serge | 190 | .chip_ids dd ? ;chip model string |
802 | serge | 191 | |
2434 | Serge | 192 | .shadow_flag dd ? |
193 | dd ? |
||
802 | serge | 194 | |
2434 | Serge | 195 | .regs dw ? ; codec registers |
802 | serge | 196 | .reg_master_vol dw ? ;0x02 |
197 | .reg_aux_out_vol dw ? ;0x04 |
||
198 | .reg_mone_vol dw ? ;0x06 |
||
199 | .reg_master_tone dw ? ;0x08 |
||
200 | .reg_beep_vol dw ? ;0x0A |
||
201 | .reg_phone_vol dw ? ;0x0C |
||
2434 | Serge | 202 | .reg_mic_vol dw ? ;0x0E |
802 | serge | 203 | .reg_line_in_vol dw ? ;0x10 |
2434 | Serge | 204 | .reg_cd_vol dw ? ;0x12 |
802 | serge | 205 | .reg_video_vol dw ? ;0x14 |
206 | .reg_aux_in_vol dw ? ;0x16 |
||
207 | .reg_pcm_out_vol dw ? ;0x18 |
||
208 | .reg_rec_select dw ? ;0x1A |
||
209 | .reg_rec_gain dw ? ;0x1C |
||
210 | .reg_rec_gain_mic dw ? ;0x1E |
||
2434 | Serge | 211 | .reg_gen dw ? ;0x20 |
212 | .reg_3d_ctrl dw ? ;0X22 |
||
213 | .reg_page dw ? ;0X24 |
||
802 | serge | 214 | .reg_powerdown dw ? ;0x26 |
215 | .reg_ext_audio dw ? ;0x28 |
||
2434 | Serge | 216 | .reg_ext_st dw ? ;0x2a |
802 | serge | 217 | .reg_pcm_front_rate dw ? ;0x2c |
218 | .reg_pcm_surr_rate dw ? ;0x2e |
||
219 | .reg_lfe_rate dw ? ;0x30 |
||
220 | .reg_pcm_in_rate dw ? ;0x32 |
||
2434 | Serge | 221 | dw ? ;0x34 |
802 | serge | 222 | .reg_cent_lfe_vol dw ? ;0x36 |
223 | .reg_surr_vol dw ? ;0x38 |
||
224 | .reg_spdif_ctrl dw ? ;0x3A |
||
2434 | Serge | 225 | dw ? ;0x3C |
226 | dw ? ;0x3E |
||
227 | dw ? ;0x40 |
||
228 | dw ? ;0x42 |
||
229 | dw ? ;0x44 |
||
230 | dw ? ;0x46 |
||
231 | dw ? ;0x48 |
||
232 | dw ? ;0x4A |
||
233 | dw ? ;0x4C |
||
234 | dw ? ;0x4E |
||
235 | dw ? ;0x50 |
||
236 | dw ? ;0x52 |
||
237 | dw ? ;0x54 |
||
238 | dw ? ;0x56 |
||
239 | dw ? ;0x58 |
||
240 | dw ? ;0x5A |
||
241 | dw ? ;0x5C |
||
242 | dw ? ;0x5E |
||
243 | .reg_page_0 dw ? ;0x60 |
||
244 | .reg_page_1 dw ? ;0x62 |
||
245 | .reg_page_2 dw ? ;0x64 |
||
246 | .reg_page_3 dw ? ;0x66 |
||
247 | .reg_page_4 dw ? ;0x68 |
||
248 | .reg_page_5 dw ? ;0x6A |
||
249 | .reg_page_6 dw ? ;0x6C |
||
250 | .reg_page_7 dw ? ;0x6E |
||
251 | dw ? ;0x70 |
||
252 | dw ? ;0x72 |
||
253 | dw ? ;0x74 |
||
254 | dw ? ;0x76 |
||
255 | dw ? ;0x78 |
||
256 | dw ? ;0x7A |
||
802 | serge | 257 | .reg_vendor_id_1 dw ? ;0x7C |
258 | .reg_vendor_id_2 dw ? ;0x7E |
||
259 | |||
260 | |||
2434 | Serge | 261 | .reset dd ? ;virual |
802 | serge | 262 | .set_master_vol dd ? |
263 | } |
||
264 | |||
265 | struc CTRL_INFO |
||
2434 | Serge | 266 | { .pci_cmd dd ? |
267 | .irq dd ? |
||
802 | serge | 268 | .glob_cntrl dd ? |
2434 | Serge | 269 | .glob_sta dd ? |
802 | serge | 270 | .codec_io_base dd ? |
271 | .ctrl_io_base dd ? |
||
272 | .codec_mem_base dd ? |
||
273 | .ctrl_mem_base dd ? |
||
2434 | Serge | 274 | .codec_id dd ? |
802 | serge | 275 | } |
276 | |||
277 | struc IOCTL |
||
2434 | Serge | 278 | { .handle dd ? |
279 | .io_code dd ? |
||
280 | .input dd ? |
||
281 | .inp_size dd ? |
||
282 | .output dd ? |
||
283 | .out_size dd ? |
||
802 | serge | 284 | } |
285 | |||
286 | virtual at 0 |
||
287 | IOCTL IOCTL |
||
288 | end virtual |
||
289 | |||
2434 | Serge | 290 | EVENT_NOTIFY equ 0x00000200 |
802 | serge | 291 | |
292 | public START |
||
293 | public service_proc |
||
294 | public version |
||
295 | |||
296 | section '.flat' code readable align 16 |
||
297 | |||
298 | proc START stdcall, state:dword |
||
299 | |||
2434 | Serge | 300 | cmp [state], 1 |
301 | jne .stop |
||
802 | serge | 302 | |
303 | if DEBUG |
||
2434 | Serge | 304 | mov esi, msgInit |
305 | call SysMsgBoardStr |
||
802 | serge | 306 | end if |
307 | |||
2434 | Serge | 308 | call detect_controller |
309 | test eax, eax |
||
310 | jz .fail |
||
802 | serge | 311 | |
312 | if DEBUG |
||
2434 | Serge | 313 | mov esi, [ctrl.vendor_ids] |
314 | call SysMsgBoardStr |
||
315 | mov esi, [ctrl.ctrl_ids] |
||
316 | call SysMsgBoardStr |
||
802 | serge | 317 | |
318 | end if |
||
319 | |||
2434 | Serge | 320 | call init_controller |
321 | test eax, eax |
||
322 | jz .fail |
||
802 | serge | 323 | |
2434 | Serge | 324 | call init_codec |
325 | test eax, eax |
||
326 | jz .fail |
||
802 | serge | 327 | |
2434 | Serge | 328 | call reset_controller |
329 | call setup_codec |
||
802 | serge | 330 | |
2434 | Serge | 331 | mov esi, msgPrimBuff |
332 | call SysMsgBoardStr |
||
333 | call create_primary_buff |
||
334 | mov esi, msgDone |
||
335 | call SysMsgBoardStr |
||
802 | serge | 336 | |
2015 | serge | 337 | if IRQ_REMAP |
2434 | Serge | 338 | pushf |
339 | cli |
||
2015 | serge | 340 | |
2434 | Serge | 341 | mov ebx, [ctrl.int_line] |
342 | in al, 0xA1 |
||
343 | mov ah, al |
||
344 | in al, 0x21 |
||
345 | test ebx, ebx |
||
346 | jz .skip |
||
347 | bts ax, bx ;mask old line |
||
2015 | serge | 348 | .skip |
2434 | Serge | 349 | bts ax, IRQ_LINE ;mask new ine |
350 | out 0x21, al |
||
351 | mov al, ah |
||
352 | out 0xA1, al |
||
353 | ;remap IRQ |
||
354 | stdcall PciWrite8, 0, 0xF8, 0x61, IRQ_LINE |
||
2015 | serge | 355 | |
2434 | Serge | 356 | mov dx, 0x4d0 ;8259 ELCR1 |
357 | in al, dx |
||
358 | bts ax, IRQ_LINE |
||
359 | out dx, al ;set level-triggered mode |
||
360 | mov [ctrl.int_line], IRQ_LINE |
||
361 | popf |
||
362 | mov esi, msgRemap |
||
363 | call SysMsgBoardStr |
||
2015 | serge | 364 | end if |
365 | |||
2434 | Serge | 366 | mov ebx, [ctrl.int_line] |
367 | stdcall AttachIntHandler, ebx, ac97_irq, dword 0 |
||
802 | serge | 368 | .reg: |
2434 | Serge | 369 | stdcall RegService, sz_sound_srv, service_proc |
370 | ret |
||
802 | serge | 371 | .fail: |
372 | if DEBUG |
||
2434 | Serge | 373 | mov esi, msgFail |
374 | call SysMsgBoardStr |
||
802 | serge | 375 | end if |
2434 | Serge | 376 | xor eax, eax |
377 | ret |
||
802 | serge | 378 | .fail_msg: |
2434 | Serge | 379 | call SysMsgBoardStr |
380 | xor eax, eax |
||
381 | ret |
||
802 | serge | 382 | .stop: |
2434 | Serge | 383 | call stop |
384 | xor eax, eax |
||
385 | ret |
||
802 | serge | 386 | endp |
387 | |||
2434 | Serge | 388 | handle equ IOCTL.handle |
389 | io_code equ IOCTL.io_code |
||
390 | input equ IOCTL.input |
||
391 | inp_size equ IOCTL.inp_size |
||
392 | output equ IOCTL.output |
||
393 | out_size equ IOCTL.out_size |
||
802 | serge | 394 | |
395 | align 4 |
||
396 | proc service_proc stdcall, ioctl:dword |
||
397 | |||
2434 | Serge | 398 | mov edi, [ioctl] |
399 | mov eax, [edi+io_code] |
||
802 | serge | 400 | |
2434 | Serge | 401 | cmp eax, SRV_GETVERSION |
402 | jne @F |
||
802 | serge | 403 | |
2434 | Serge | 404 | mov eax, [edi+output] |
405 | cmp [edi+out_size], 4 |
||
406 | jne .fail |
||
802 | serge | 407 | |
2434 | Serge | 408 | mov [eax], dword API_VERSION |
409 | xor eax, eax |
||
410 | ret |
||
802 | serge | 411 | @@: |
2434 | Serge | 412 | cmp eax, DEV_PLAY |
413 | jne @F |
||
802 | serge | 414 | if DEBUG |
2434 | Serge | 415 | mov esi, msgPlay |
416 | call SysMsgBoardStr |
||
802 | serge | 417 | end if |
2434 | Serge | 418 | call play |
419 | ret |
||
802 | serge | 420 | @@: |
2434 | Serge | 421 | cmp eax, DEV_STOP |
422 | jne @F |
||
802 | serge | 423 | if DEBUG |
2434 | Serge | 424 | mov esi, msgStop |
425 | call SysMsgBoardStr |
||
802 | serge | 426 | end if |
2434 | Serge | 427 | call stop |
428 | ret |
||
802 | serge | 429 | @@: |
2434 | Serge | 430 | cmp eax, DEV_CALLBACK |
431 | jne @F |
||
432 | mov ebx, [edi+input] |
||
433 | stdcall set_callback, [ebx] |
||
434 | ret |
||
802 | serge | 435 | @@: |
2434 | Serge | 436 | cmp eax, DEV_SET_MASTERVOL |
437 | jne @F |
||
438 | mov eax, [edi+input] |
||
439 | mov eax, [eax] |
||
440 | call set_master_vol ;eax= vol |
||
441 | ret |
||
802 | serge | 442 | @@: |
2434 | Serge | 443 | cmp eax, DEV_GET_MASTERVOL |
444 | jne @F |
||
445 | mov ebx, [edi+output] |
||
446 | stdcall get_master_vol, ebx |
||
447 | ret |
||
2010 | serge | 448 | |
449 | @@: |
||
2434 | Serge | 450 | cmp eax, DEV_GET_POS |
451 | jne @F |
||
2010 | serge | 452 | |
2434 | Serge | 453 | mov ebx, 8192 |
454 | mov edx, 0x18 |
||
455 | xor eax, eax |
||
456 | call [ctrl.ctrl_read16] |
||
457 | sub ebx, eax |
||
458 | shr ebx, 1 |
||
459 | mov edx, [edi+output] |
||
460 | mov [edx], ebx |
||
461 | xor eax, eax |
||
462 | ret |
||
802 | serge | 463 | ;@@: |
464 | ; cmp eax, DEV_GET_INFO |
||
465 | ; jne @F |
||
466 | ; mov ebx, [edi+output] |
||
467 | ; stdcall get_dev_info, ebx |
||
468 | ; ret |
||
469 | @@: |
||
470 | .fail: |
||
2434 | Serge | 471 | or eax, -1 |
472 | ret |
||
802 | serge | 473 | endp |
474 | |||
475 | restore handle |
||
476 | restore io_code |
||
477 | restore input |
||
478 | restore inp_size |
||
479 | restore output |
||
480 | restore out_size |
||
481 | |||
482 | align 4 |
||
483 | proc ac97_irq |
||
484 | |||
485 | if DEBUG_IRQ |
||
2434 | Serge | 486 | mov esi, msgIRQ |
487 | call SysMsgBoardStr |
||
802 | serge | 488 | end if |
489 | |||
2434 | Serge | 490 | mov edx, CTRL_STAT |
491 | call [ctrl.ctrl_read32] |
||
2010 | serge | 492 | |
2434 | Serge | 493 | cmp eax, 0xffffffff |
494 | je .exit |
||
2010 | serge | 495 | |
2434 | Serge | 496 | test eax, 0x40 |
497 | jnz .do_intr |
||
2010 | serge | 498 | |
2434 | Serge | 499 | test eax, eax |
500 | jz .exit |
||
2010 | serge | 501 | |
2434 | Serge | 502 | mov edx, CTRL_STAT |
503 | call [ctrl.ctrl_write32] |
||
2106 | serge | 504 | .exit: |
2434 | Serge | 505 | xor eax, eax |
506 | ret |
||
2010 | serge | 507 | |
508 | .do_intr: |
||
2434 | Serge | 509 | push eax |
2106 | serge | 510 | |
2434 | Serge | 511 | mov edx, PCM_OUT_CR_REG |
512 | mov al, 0x10; 0x10 |
||
513 | call [ctrl.ctrl_write8] |
||
802 | serge | 514 | |
2434 | Serge | 515 | mov ax, 0x1c |
516 | mov edx, PCM_OUT_SR_REG |
||
517 | call [ctrl.ctrl_write16] |
||
802 | serge | 518 | |
2434 | Serge | 519 | mov edx, PCM_OUT_CIV_REG |
520 | call [ctrl.ctrl_read8] |
||
802 | serge | 521 | |
2434 | Serge | 522 | and eax, 0x1F |
523 | cmp eax, [civ_val] |
||
524 | je .skip |
||
802 | serge | 525 | |
2434 | Serge | 526 | mov [civ_val], eax |
527 | dec eax |
||
528 | and eax, 0x1F |
||
529 | mov [ctrl.lvi_reg], eax |
||
802 | serge | 530 | |
2434 | Serge | 531 | mov edx, PCM_OUT_LVI_REG |
532 | call [ctrl.ctrl_write8] |
||
802 | serge | 533 | |
2434 | Serge | 534 | mov edx, PCM_OUT_CR_REG |
535 | mov ax, 0x11 ;0x1D |
||
536 | call [ctrl.ctrl_write8] |
||
802 | serge | 537 | |
2434 | Serge | 538 | mov eax, [civ_val] |
539 | add eax, 1 |
||
540 | and eax, 31 |
||
541 | mov ebx, dword [buff_list+eax*4] |
||
802 | serge | 542 | |
2434 | Serge | 543 | cmp [ctrl.user_callback], 0 |
544 | je .done |
||
802 | serge | 545 | |
2434 | Serge | 546 | stdcall [ctrl.user_callback], ebx |
2010 | serge | 547 | .done: |
2434 | Serge | 548 | pop eax |
549 | and eax, 0x40 |
||
550 | mov edx, CTRL_STAT |
||
551 | call [ctrl.ctrl_write32] |
||
552 | or eax, 1 |
||
553 | ret |
||
802 | serge | 554 | .skip: |
2434 | Serge | 555 | mov edx, PCM_OUT_CR_REG |
556 | mov ax, 0x11 ;0x1D |
||
557 | call [ctrl.ctrl_write8] |
||
558 | jmp .done |
||
802 | serge | 559 | endp |
560 | |||
561 | align 4 |
||
562 | proc create_primary_buff |
||
563 | |||
2434 | Serge | 564 | stdcall KernelAlloc, 0x10000 |
565 | mov [ctrl.buffer], eax |
||
802 | serge | 566 | |
2434 | Serge | 567 | mov edi, eax |
568 | mov ecx, 0x10000/4 |
||
569 | xor eax, eax |
||
570 | cld |
||
571 | rep stosd |
||
802 | serge | 572 | |
2434 | Serge | 573 | mov eax, [ctrl.buffer] |
574 | call GetPgAddr |
||
802 | serge | 575 | |
2434 | Serge | 576 | mov ebx, 0xC0002000 |
577 | mov ecx, 4 |
||
578 | mov edi, pcmout_bdl |
||
802 | serge | 579 | @@: |
2434 | Serge | 580 | mov [edi], eax |
581 | mov [edi+4], ebx |
||
802 | serge | 582 | |
2434 | Serge | 583 | mov [edi+32], eax |
584 | mov [edi+4+32], ebx |
||
802 | serge | 585 | |
2434 | Serge | 586 | mov [edi+64], eax |
587 | mov [edi+4+64], ebx |
||
802 | serge | 588 | |
2434 | Serge | 589 | mov [edi+96], eax |
590 | mov [edi+4+96], ebx |
||
802 | serge | 591 | |
2434 | Serge | 592 | mov [edi+128], eax |
593 | mov [edi+4+128], ebx |
||
802 | serge | 594 | |
2434 | Serge | 595 | mov [edi+160], eax |
596 | mov [edi+4+160], ebx |
||
802 | serge | 597 | |
2434 | Serge | 598 | mov [edi+192], eax |
599 | mov [edi+4+192], ebx |
||
802 | serge | 600 | |
2434 | Serge | 601 | mov [edi+224], eax |
602 | mov [edi+4+224], ebx |
||
802 | serge | 603 | |
2434 | Serge | 604 | add eax, 0x4000 |
605 | add edi, 8 |
||
606 | loop @B |
||
802 | serge | 607 | |
2434 | Serge | 608 | mov edi, buff_list |
609 | mov eax, [ctrl.buffer] |
||
610 | mov ecx, 4 |
||
802 | serge | 611 | @@: |
2434 | Serge | 612 | mov [edi], eax |
613 | mov [edi+16], eax |
||
614 | mov [edi+32], eax |
||
615 | mov [edi+48], eax |
||
616 | mov [edi+64], eax |
||
617 | mov [edi+80], eax |
||
618 | mov [edi+96], eax |
||
619 | mov [edi+112], eax |
||
802 | serge | 620 | |
2434 | Serge | 621 | add eax, 0x4000 |
622 | add edi, 4 |
||
623 | loop @B |
||
802 | serge | 624 | |
2434 | Serge | 625 | mov eax, pcmout_bdl |
626 | mov ebx, eax |
||
627 | call GetPgAddr ;eax |
||
628 | and ebx, 0xFFF |
||
629 | add eax, ebx |
||
802 | serge | 630 | |
2434 | Serge | 631 | mov edx, PCM_OUT_BDL |
632 | call [ctrl.ctrl_write32] |
||
802 | serge | 633 | |
2434 | Serge | 634 | mov eax, 16 |
635 | mov [ctrl.lvi_reg], eax |
||
636 | mov edx, PCM_OUT_LVI_REG |
||
637 | call [ctrl.ctrl_write8] |
||
638 | ret |
||
802 | serge | 639 | endp |
640 | |||
641 | align 4 |
||
642 | proc detect_controller |
||
2434 | Serge | 643 | locals |
644 | last_bus dd ? |
||
645 | bus dd ? |
||
646 | devfn dd ? |
||
647 | endl |
||
802 | serge | 648 | |
2434 | Serge | 649 | xor eax, eax |
650 | mov [bus], eax |
||
651 | inc eax |
||
652 | call PciApi |
||
653 | cmp eax, -1 |
||
654 | je .err |
||
802 | serge | 655 | |
2434 | Serge | 656 | mov [last_bus], eax |
802 | serge | 657 | |
658 | .next_bus: |
||
2434 | Serge | 659 | and [devfn], 0 |
802 | serge | 660 | .next_dev: |
2434 | Serge | 661 | stdcall PciRead32, [bus], [devfn], dword 0 |
662 | test eax, eax |
||
663 | jz .next |
||
664 | cmp eax, -1 |
||
665 | je .next |
||
802 | serge | 666 | |
2434 | Serge | 667 | mov edi, devices |
802 | serge | 668 | @@: |
2434 | Serge | 669 | mov ebx, [edi] |
670 | test ebx, ebx |
||
671 | jz .next |
||
802 | serge | 672 | |
2434 | Serge | 673 | cmp eax, ebx |
674 | je .found |
||
675 | add edi, 12 |
||
676 | jmp @B |
||
802 | serge | 677 | .next: |
2434 | Serge | 678 | inc [devfn] |
679 | cmp [devfn], 256 |
||
680 | jb .next_dev |
||
681 | mov eax, [bus] |
||
682 | inc eax |
||
683 | mov [bus], eax |
||
684 | cmp eax, [last_bus] |
||
685 | jna .next_bus |
||
686 | xor eax, eax |
||
687 | ret |
||
802 | serge | 688 | .found: |
2434 | Serge | 689 | mov ebx, [bus] |
690 | mov [ctrl.bus], ebx |
||
802 | serge | 691 | |
2434 | Serge | 692 | mov ecx, [devfn] |
693 | mov [ctrl.devfn], ecx |
||
802 | serge | 694 | |
2434 | Serge | 695 | mov edx, eax |
696 | and edx, 0xFFFF |
||
697 | mov [ctrl.vendor], edx |
||
698 | shr eax, 16 |
||
699 | mov [ctrl.dev_id], eax |
||
802 | serge | 700 | |
2434 | Serge | 701 | mov ebx, [edi+4] |
702 | mov [ctrl.ctrl_ids], ebx |
||
703 | mov esi, [edi+8] |
||
704 | mov [ctrl.ctrl_setup], esi |
||
802 | serge | 705 | |
2434 | Serge | 706 | cmp edx, VID_INTEL |
707 | jne @F |
||
708 | mov [ctrl.vendor_ids], msg_Intel |
||
709 | ret |
||
802 | serge | 710 | @@: |
2434 | Serge | 711 | cmp edx, VID_NVIDIA |
712 | jne @F |
||
713 | mov [ctrl.vendor_ids], msg_NVidia |
||
714 | ret |
||
802 | serge | 715 | @@: |
716 | .err: |
||
2434 | Serge | 717 | xor eax, eax |
718 | mov [ctrl.vendor_ids], eax ;something wrong ? |
||
719 | ret |
||
802 | serge | 720 | endp |
721 | |||
722 | align 4 |
||
723 | proc init_controller |
||
724 | |||
2434 | Serge | 725 | stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 4 |
726 | mov ebx, eax |
||
727 | and eax, 0xFFFF |
||
728 | mov [ctrl.pci_cmd], eax |
||
729 | shr ebx, 16 |
||
730 | mov [ctrl.pci_stat], ebx |
||
802 | serge | 731 | |
2434 | Serge | 732 | mov esi, msgPciCmd |
733 | call SysMsgBoardStr |
||
734 | call dword2str |
||
735 | call SysMsgBoardStr |
||
802 | serge | 736 | |
2434 | Serge | 737 | mov esi, msgPciStat |
738 | call SysMsgBoardStr |
||
739 | mov eax, [ctrl.pci_stat] |
||
740 | call dword2str |
||
741 | call SysMsgBoardStr |
||
802 | serge | 742 | |
2434 | Serge | 743 | mov esi, msgMixIsaIo |
744 | call SysMsgBoardStr |
||
802 | serge | 745 | |
2434 | Serge | 746 | stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x10 |
802 | serge | 747 | |
2434 | Serge | 748 | call dword2str |
749 | call SysMsgBoardStr |
||
802 | serge | 750 | |
2434 | Serge | 751 | and eax, 0xFFFE |
752 | mov [ctrl.codec_io_base], eax |
||
802 | serge | 753 | |
2434 | Serge | 754 | mov esi, msgCtrlIsaIo |
755 | call SysMsgBoardStr |
||
802 | serge | 756 | |
2434 | Serge | 757 | stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x14 |
802 | serge | 758 | |
2434 | Serge | 759 | call dword2str |
760 | call SysMsgBoardStr |
||
802 | serge | 761 | |
2434 | Serge | 762 | and eax, 0xFFC0 |
763 | mov [ctrl.ctrl_io_base], eax |
||
802 | serge | 764 | |
2434 | Serge | 765 | mov esi, msgMixMMIo |
766 | call SysMsgBoardStr |
||
802 | serge | 767 | |
2434 | Serge | 768 | stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x18 |
769 | mov [ctrl.codec_mem_base], eax |
||
802 | serge | 770 | |
2434 | Serge | 771 | call dword2str |
772 | call SysMsgBoardStr |
||
802 | serge | 773 | |
2434 | Serge | 774 | mov esi, msgCtrlMMIo |
775 | call SysMsgBoardStr |
||
802 | serge | 776 | |
2434 | Serge | 777 | stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x1C |
778 | mov [ctrl.ctrl_mem_base], eax |
||
802 | serge | 779 | |
2434 | Serge | 780 | call dword2str |
781 | call SysMsgBoardStr |
||
802 | serge | 782 | |
783 | if 0 |
||
784 | |||
785 | ;;patch for some ugly BIOS ICH-ICH5 compatible |
||
2434 | Serge | 786 | cmp [ctrl.vendor], VID_INTEL |
787 | jne .default |
||
802 | serge | 788 | |
2434 | Serge | 789 | mov esi, msgIrqMap |
790 | call SysMsgBoardStr |
||
791 | stdcall PciRead8, 0, 0xF8, 0x61 |
||
792 | and eax, 0xFF |
||
793 | call dword2str |
||
794 | call SysMsgBoardStr |
||
795 | btr eax, 7 ;when bit 7 set remap disabled |
||
796 | jnc @F |
||
797 | xor eax, eax |
||
798 | jmp @F |
||
802 | serge | 799 | end if |
800 | |||
801 | .default: |
||
2434 | Serge | 802 | stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x3C |
803 | and eax, 0xFF |
||
802 | serge | 804 | @@: |
2434 | Serge | 805 | mov [ctrl.int_line], eax |
802 | serge | 806 | |
2434 | Serge | 807 | stdcall PciRead8, [ctrl.bus], [ctrl.devfn], dword 0x41 |
808 | and eax, 0xFF |
||
809 | mov [ctrl.cfg_reg], eax |
||
802 | serge | 810 | |
2434 | Serge | 811 | mov [ctrl.user_callback], 0 |
2010 | serge | 812 | |
2434 | Serge | 813 | call [ctrl.ctrl_setup] |
814 | xor eax, eax |
||
815 | inc eax |
||
816 | ret |
||
802 | serge | 817 | endp |
818 | |||
819 | align 4 |
||
820 | proc set_ICH |
||
2434 | Serge | 821 | mov [ctrl.codec_read16], codec_io_r16 ;virtual |
822 | mov [ctrl.codec_write16], codec_io_w16 ;virtual |
||
802 | serge | 823 | |
2434 | Serge | 824 | mov [ctrl.ctrl_read8 ], ctrl_io_r8 ;virtual |
825 | mov [ctrl.ctrl_read16], ctrl_io_r16 ;virtual |
||
826 | mov [ctrl.ctrl_read32], ctrl_io_r32 ;virtual |
||
802 | serge | 827 | |
2434 | Serge | 828 | mov [ctrl.ctrl_write8 ], ctrl_io_w8 ;virtual |
829 | mov [ctrl.ctrl_write16], ctrl_io_w16 ;virtual |
||
830 | mov [ctrl.ctrl_write32], ctrl_io_w32 ;virtual |
||
831 | ret |
||
802 | serge | 832 | endp |
833 | |||
2434 | Serge | 834 | PG_SW equ 0x003 |
835 | PG_NOCACHE equ 0x018 |
||
802 | serge | 836 | |
837 | align 4 |
||
838 | proc set_ICH4 |
||
839 | |||
2434 | Serge | 840 | stdcall MapIoMem, [ctrl.codec_mem_base], 0x1000, PG_SW+PG_NOCACHE |
841 | mov [ctrl.codec_mem_base], eax |
||
802 | serge | 842 | |
2434 | Serge | 843 | stdcall MapIoMem, [ctrl.ctrl_mem_base], 0x1000, PG_SW+PG_NOCACHE |
844 | mov [ctrl.ctrl_mem_base], eax |
||
802 | serge | 845 | |
2434 | Serge | 846 | mov [ctrl.codec_read16], codec_mem_r16 ;virtual |
847 | mov [ctrl.codec_write16], codec_mem_w16 ;virtual |
||
802 | serge | 848 | |
2434 | Serge | 849 | mov [ctrl.ctrl_read8 ], ctrl_mem_r8 ;virtual |
850 | mov [ctrl.ctrl_read16], ctrl_mem_r16 ;virtual |
||
851 | mov [ctrl.ctrl_read32], ctrl_mem_r32 ;virtual |
||
802 | serge | 852 | |
2434 | Serge | 853 | mov [ctrl.ctrl_write8 ], ctrl_mem_w8 ;virtual |
854 | mov [ctrl.ctrl_write16], ctrl_mem_w16 ;virtual |
||
855 | mov [ctrl.ctrl_write32], ctrl_mem_w32 ;virtual |
||
856 | ret |
||
802 | serge | 857 | endp |
858 | |||
859 | align 4 |
||
860 | proc reset_controller |
||
861 | |||
2434 | Serge | 862 | xor eax, eax |
863 | mov edx, PCM_IN_CR_REG |
||
864 | call [ctrl.ctrl_write8] |
||
802 | serge | 865 | |
2434 | Serge | 866 | mov edx, PCM_OUT_CR_REG |
867 | call [ctrl.ctrl_write8] |
||
802 | serge | 868 | |
2434 | Serge | 869 | mov edx, MC_IN_CR_REG |
870 | call [ctrl.ctrl_write8] |
||
802 | serge | 871 | |
2434 | Serge | 872 | mov eax, RR |
873 | mov edx, PCM_IN_CR_REG |
||
874 | call [ctrl.ctrl_write8] |
||
802 | serge | 875 | |
2434 | Serge | 876 | mov edx, PCM_OUT_CR_REG |
877 | call [ctrl.ctrl_write8] |
||
802 | serge | 878 | |
2434 | Serge | 879 | mov edx, MC_IN_CR_REG |
880 | call [ctrl.ctrl_write8] |
||
881 | ret |
||
802 | serge | 882 | endp |
883 | |||
884 | align 4 |
||
885 | proc init_codec |
||
2434 | Serge | 886 | locals |
887 | counter dd ? |
||
888 | endl |
||
802 | serge | 889 | |
2434 | Serge | 890 | mov esi, msgControl |
891 | call SysMsgBoardStr |
||
802 | serge | 892 | |
2434 | Serge | 893 | mov edx, GLOB_CTRL |
894 | call [ctrl.ctrl_read32] |
||
895 | call dword2str |
||
896 | call SysMsgBoardStr |
||
802 | serge | 897 | |
2434 | Serge | 898 | mov esi, msgStatus |
899 | call SysMsgBoardStr |
||
802 | serge | 900 | |
2434 | Serge | 901 | mov edx, CTRL_STAT |
902 | call [ctrl.ctrl_read32] |
||
903 | push eax |
||
904 | call dword2str |
||
905 | call SysMsgBoardStr |
||
906 | pop eax |
||
907 | cmp eax, 0xFFFFFFFF |
||
908 | je .err |
||
802 | serge | 909 | |
2434 | Serge | 910 | test eax, CTRL_ST_CREADY |
911 | jnz .ready |
||
802 | serge | 912 | |
2434 | Serge | 913 | call reset_codec |
914 | test eax, eax |
||
915 | jz .err |
||
802 | serge | 916 | |
917 | .ready: |
||
2434 | Serge | 918 | xor edx, edx ;ac_reg_0 |
919 | call [ctrl.codec_write16] |
||
802 | serge | 920 | |
2434 | Serge | 921 | xor eax, eax |
922 | mov edx, CODEC_REG_POWERDOWN |
||
923 | call [ctrl.codec_write16] |
||
802 | serge | 924 | |
2434 | Serge | 925 | mov [counter], 200 ; total 200*5 ms = 1s |
802 | serge | 926 | .wait: |
2434 | Serge | 927 | mov eax, 5000 ; wait 5 ms |
928 | call StallExec |
||
802 | serge | 929 | |
2434 | Serge | 930 | mov edx, CODEC_REG_POWERDOWN |
931 | call [ctrl.codec_read16] |
||
932 | and eax, 0x0F |
||
933 | cmp eax, 0x0F |
||
934 | jz .done |
||
802 | serge | 935 | |
2434 | Serge | 936 | sub [counter] , 1 |
937 | jnz .wait |
||
802 | serge | 938 | .err: |
2434 | Serge | 939 | xor eax, eax ; timeout error |
940 | ret |
||
802 | serge | 941 | .done: |
2434 | Serge | 942 | mov eax, 2 ;force set 16-bit 2-channel PCM |
943 | mov edx, GLOB_CTRL |
||
944 | call [ctrl.ctrl_write32] |
||
945 | mov eax, 5000 ; wait 5 ms |
||
946 | call StallExec |
||
802 | serge | 947 | |
2434 | Serge | 948 | call detect_codec |
802 | serge | 949 | |
2434 | Serge | 950 | xor eax, eax |
951 | inc eax |
||
952 | ret |
||
802 | serge | 953 | endp |
954 | |||
955 | align 4 |
||
956 | proc reset_codec |
||
2434 | Serge | 957 | mov edx, GLOB_CTRL |
958 | call [ctrl.ctrl_read32] |
||
802 | serge | 959 | |
2434 | Serge | 960 | test eax, 0x02 |
961 | jz .cold |
||
802 | serge | 962 | |
2434 | Serge | 963 | call warm_reset |
964 | jnc .ok |
||
802 | serge | 965 | .cold: |
2434 | Serge | 966 | call cold_reset |
967 | jnc .ok |
||
802 | serge | 968 | |
969 | if DEBUG |
||
2434 | Serge | 970 | mov esi, msgCFail |
971 | call SysMsgBoardStr |
||
972 | end if |
||
973 | xor eax, eax ; timeout error |
||
974 | ret |
||
802 | serge | 975 | .ok: |
976 | if DEBUG |
||
2434 | Serge | 977 | mov esi, msgResetOk |
978 | call SysMsgBoardStr |
||
802 | serge | 979 | end if |
980 | |||
2434 | Serge | 981 | xor eax, eax |
982 | inc eax |
||
983 | ret |
||
802 | serge | 984 | endp |
985 | |||
986 | align 4 |
||
987 | proc warm_reset |
||
2434 | Serge | 988 | locals |
989 | counter dd ? |
||
990 | endl |
||
802 | serge | 991 | |
2434 | Serge | 992 | mov eax, 0x06 |
993 | mov edx, GLOB_CTRL |
||
994 | call [ctrl.ctrl_write32] |
||
802 | serge | 995 | |
996 | if DEBUG |
||
2434 | Serge | 997 | mov esi, msgWarm |
998 | call SysMsgBoardStr |
||
802 | serge | 999 | end if |
1000 | |||
2434 | Serge | 1001 | mov [counter], 10 ; total 10*100 ms = 1s |
802 | serge | 1002 | .wait: |
2434 | Serge | 1003 | mov eax, 100000 ; wait 100 ms |
1004 | call StallExec |
||
802 | serge | 1005 | |
2434 | Serge | 1006 | mov edx, CTRL_STAT |
1007 | call [ctrl.ctrl_read32] |
||
1008 | test eax, CTRL_ST_CREADY |
||
1009 | jnz .ok |
||
802 | serge | 1010 | |
2434 | Serge | 1011 | dec [counter] |
1012 | jnz .wait |
||
802 | serge | 1013 | |
1014 | if DEBUG |
||
2434 | Serge | 1015 | mov esi, msgWRFail |
1016 | call SysMsgBoardStr |
||
802 | serge | 1017 | end if |
1018 | .fail: |
||
2434 | Serge | 1019 | stc |
1020 | ret |
||
802 | serge | 1021 | .ok: |
2434 | Serge | 1022 | clc |
1023 | ret |
||
802 | serge | 1024 | endp |
1025 | |||
1026 | align 4 |
||
1027 | proc cold_reset |
||
2434 | Serge | 1028 | locals |
1029 | counter dd ? |
||
1030 | endl |
||
802 | serge | 1031 | |
2434 | Serge | 1032 | mov eax, 0x02 |
1033 | mov edx, GLOB_CTRL |
||
1034 | call [ctrl.ctrl_write32] |
||
802 | serge | 1035 | |
1036 | if DEBUG |
||
2434 | Serge | 1037 | mov esi, msgCold |
1038 | call SysMsgBoardStr |
||
802 | serge | 1039 | end if |
1040 | |||
2434 | Serge | 1041 | mov eax, 400000 ; wait 400 ms |
1042 | call StallExec |
||
802 | serge | 1043 | |
2434 | Serge | 1044 | mov [counter], 16 ; total 20*100 ms = 2s |
802 | serge | 1045 | .wait: |
1046 | |||
2434 | Serge | 1047 | mov edx, CTRL_STAT |
1048 | call [ctrl.ctrl_read32] |
||
1049 | test eax, CTRL_ST_CREADY |
||
1050 | jnz .ok |
||
802 | serge | 1051 | |
2434 | Serge | 1052 | mov eax, 100000 ; wait 100 ms |
1053 | call StallExec |
||
802 | serge | 1054 | |
2434 | Serge | 1055 | dec [counter] |
1056 | jnz .wait |
||
802 | serge | 1057 | |
1058 | if DEBUG |
||
2434 | Serge | 1059 | mov esi, msgCRFail |
1060 | call SysMsgBoardStr |
||
802 | serge | 1061 | end if |
1062 | |||
1063 | .fail: |
||
2434 | Serge | 1064 | stc |
1065 | ret |
||
802 | serge | 1066 | .ok: |
2434 | Serge | 1067 | mov esi, msgControl |
1068 | call SysMsgBoardStr |
||
802 | serge | 1069 | |
2434 | Serge | 1070 | mov edx, GLOB_CTRL |
1071 | call [ctrl.ctrl_read32] |
||
1072 | call dword2str |
||
1073 | call SysMsgBoardStr |
||
802 | serge | 1074 | |
2434 | Serge | 1075 | mov esi, msgStatus |
1076 | call SysMsgBoardStr |
||
802 | serge | 1077 | |
2434 | Serge | 1078 | mov edx, CTRL_STAT |
1079 | call [ctrl.ctrl_read32] |
||
1080 | push eax |
||
1081 | call dword2str |
||
1082 | call SysMsgBoardStr |
||
1083 | pop eax |
||
802 | serge | 1084 | |
2434 | Serge | 1085 | test eax, CTRL_ST_CREADY |
1086 | jz .fail |
||
1087 | clc |
||
1088 | ret |
||
802 | serge | 1089 | endp |
1090 | |||
1091 | align 4 |
||
1092 | play: |
||
2434 | Serge | 1093 | mov eax, 16 |
1094 | mov [ctrl.lvi_reg], eax |
||
1095 | mov edx, PCM_OUT_LVI_REG |
||
1096 | call [ctrl.ctrl_write8] |
||
802 | serge | 1097 | |
2434 | Serge | 1098 | mov edx, PCM_OUT_CR_REG |
1099 | mov ax, 0x1D |
||
1100 | call [ctrl.ctrl_write8] |
||
1101 | xor eax, eax |
||
1102 | ret |
||
802 | serge | 1103 | |
1104 | align 4 |
||
1105 | stop: |
||
2434 | Serge | 1106 | mov edx, PCM_OUT_CR_REG |
1107 | mov ax, 0x0 |
||
1108 | call [ctrl.ctrl_write8] |
||
802 | serge | 1109 | |
2434 | Serge | 1110 | mov ax, 0x1c |
1111 | mov edx, PCM_OUT_SR_REG |
||
1112 | call [ctrl.ctrl_write16] |
||
1113 | xor eax, eax |
||
1114 | ret |
||
802 | serge | 1115 | |
1116 | align 4 |
||
1117 | proc get_dev_info stdcall, p_info:dword |
||
2434 | Serge | 1118 | virtual at esi |
1119 | CTRL_INFO CTRL_INFO |
||
1120 | end virtual |
||
802 | serge | 1121 | |
2434 | Serge | 1122 | mov esi, [p_info] |
1123 | mov eax, [ctrl.int_line] |
||
1124 | mov ebx, [ctrl.codec_io_base] |
||
1125 | mov ecx, [ctrl.ctrl_io_base] |
||
1126 | mov edx, [ctrl.codec_mem_base] |
||
1127 | mov edi, [ctrl.ctrl_mem_base] |
||
802 | serge | 1128 | |
2434 | Serge | 1129 | mov [CTRL_INFO.irq], eax |
1130 | mov [CTRL_INFO.codec_io_base], ebx |
||
1131 | mov [CTRL_INFO.ctrl_io_base], ecx |
||
1132 | mov [CTRL_INFO.codec_mem_base], edx |
||
1133 | mov [CTRL_INFO.ctrl_mem_base], edi |
||
802 | serge | 1134 | |
2434 | Serge | 1135 | mov eax, [codec.chip_id] |
1136 | mov [CTRL_INFO.codec_id], eax |
||
802 | serge | 1137 | |
2434 | Serge | 1138 | mov edx, GLOB_CTRL |
1139 | call [ctrl.ctrl_read32] |
||
1140 | mov [CTRL_INFO.glob_cntrl], eax |
||
802 | serge | 1141 | |
2434 | Serge | 1142 | mov edx, CTRL_STAT |
1143 | call [ctrl.ctrl_read32] |
||
1144 | mov [CTRL_INFO.glob_sta], eax |
||
802 | serge | 1145 | |
2434 | Serge | 1146 | mov ebx, [ctrl.pci_cmd] |
1147 | mov [CTRL_INFO.pci_cmd], ebx |
||
1148 | ret |
||
802 | serge | 1149 | endp |
1150 | |||
1151 | align 4 |
||
1152 | proc set_callback stdcall, handler:dword |
||
2434 | Serge | 1153 | mov eax, [handler] |
1154 | mov [ctrl.user_callback], eax |
||
1155 | ret |
||
802 | serge | 1156 | endp |
1157 | |||
1158 | align 4 |
||
2434 | Serge | 1159 | proc codec_read stdcall, ac_reg:dword ; reg = edx, reval = eax |
802 | serge | 1160 | |
2434 | Serge | 1161 | mov edx, [ac_reg] |
802 | serge | 1162 | |
2434 | Serge | 1163 | mov ebx, edx |
1164 | shr ebx, 1 |
||
1165 | bt [codec.shadow_flag], ebx |
||
1166 | jc .use_shadow |
||
802 | serge | 1167 | |
2434 | Serge | 1168 | call [ctrl.codec_read16] ;change edx !!! |
1169 | mov ecx, eax |
||
802 | serge | 1170 | |
2434 | Serge | 1171 | mov edx, CTRL_STAT |
1172 | call [ctrl.ctrl_read32] |
||
1173 | test eax, CTRL_ST_RCS |
||
1174 | jz .read_ok |
||
802 | serge | 1175 | |
2434 | Serge | 1176 | mov edx, CTRL_STAT |
1177 | call [ctrl.ctrl_write32] |
||
1178 | xor eax, eax |
||
1179 | not eax ;timeout |
||
1180 | ret |
||
802 | serge | 1181 | .read_ok: |
2434 | Serge | 1182 | mov edx, [ac_reg] |
1183 | mov [codec.regs+edx], cx |
||
1184 | bts [codec.shadow_flag], ebx |
||
1185 | mov eax, ecx |
||
1186 | ret |
||
802 | serge | 1187 | .use_shadow: |
2434 | Serge | 1188 | movzx eax, word [codec.regs+edx] |
1189 | ret |
||
802 | serge | 1190 | endp |
1191 | |||
1192 | align 4 |
||
1193 | proc codec_write stdcall, ac_reg:dword |
||
2434 | Serge | 1194 | push eax |
1195 | call check_semafore |
||
1196 | and eax, eax |
||
1197 | jz .err |
||
1198 | pop eax |
||
802 | serge | 1199 | |
2434 | Serge | 1200 | mov esi, [ac_reg] |
1201 | mov edx, esi |
||
1202 | call [ctrl.codec_write16] |
||
1203 | mov [codec.regs+esi], ax |
||
1204 | shr esi, 1 |
||
1205 | bts [codec.shadow_flag], esi |
||
1206 | ret |
||
802 | serge | 1207 | .err: |
2434 | Serge | 1208 | pop eax |
1209 | ret |
||
802 | serge | 1210 | endp |
1211 | |||
1212 | align 4 |
||
1213 | proc codec_check_ready |
||
1214 | |||
2434 | Serge | 1215 | mov edx, CTRL_ST |
1216 | call [ctrl.ctrl_read32] |
||
1217 | and eax, CTRL_ST_CREADY |
||
1218 | jz .not_ready |
||
802 | serge | 1219 | |
2434 | Serge | 1220 | xor eax, wax |
1221 | inc eax |
||
1222 | ret |
||
802 | serge | 1223 | .not_ready: |
2434 | Serge | 1224 | xor eax, eax |
1225 | ret |
||
802 | serge | 1226 | endp |
1227 | |||
1228 | align 4 |
||
1229 | proc check_semafore |
||
2434 | Serge | 1230 | local counter:DWORD |
802 | serge | 1231 | |
2434 | Serge | 1232 | mov [counter], 100 |
802 | serge | 1233 | .l1: |
2434 | Serge | 1234 | mov edx, CTRL_CAS |
1235 | call [ctrl.ctrl_read8] |
||
1236 | and eax, CAS_FLAG |
||
1237 | jz .ok |
||
802 | serge | 1238 | |
2434 | Serge | 1239 | mov eax, 1 |
1240 | call StallExec |
||
1241 | sub [counter], 1 |
||
1242 | jnz .l1 |
||
1243 | xor eax, eax |
||
1244 | ret |
||
802 | serge | 1245 | align 4 |
1246 | .ok: |
||
2434 | Serge | 1247 | xor eax, eax |
1248 | inc eax |
||
1249 | ret |
||
802 | serge | 1250 | endp |
1251 | |||
1252 | align 4 |
||
1253 | proc StallExec |
||
2434 | Serge | 1254 | push ecx |
1255 | push edx |
||
1256 | push ebx |
||
1257 | push eax |
||
802 | serge | 1258 | |
2434 | Serge | 1259 | mov ecx, CPU_FREQ |
1260 | mul ecx |
||
1261 | mov ebx, eax ;low |
||
1262 | mov ecx, edx ;high |
||
1263 | rdtsc |
||
1264 | add ebx, eax |
||
1265 | adc ecx, edx |
||
802 | serge | 1266 | @@: |
2434 | Serge | 1267 | rdtsc |
1268 | sub eax, ebx |
||
1269 | sbb edx, ecx |
||
1270 | js @B |
||
802 | serge | 1271 | |
2434 | Serge | 1272 | pop eax |
1273 | pop ebx |
||
1274 | pop edx |
||
1275 | pop ecx |
||
1276 | ret |
||
802 | serge | 1277 | endp |
1278 | |||
1279 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
1280 | ; CONTROLLER IO functions |
||
1281 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
1282 | |||
1283 | align 4 |
||
1284 | proc codec_io_r16 |
||
2434 | Serge | 1285 | add edx, [ctrl.codec_io_base] |
1286 | in ax, dx |
||
1287 | ret |
||
802 | serge | 1288 | endp |
1289 | |||
1290 | align 4 |
||
1291 | proc codec_io_w16 |
||
2434 | Serge | 1292 | add edx, [ctrl.codec_io_base] |
1293 | out dx, ax |
||
1294 | ret |
||
802 | serge | 1295 | endp |
1296 | |||
1297 | align 4 |
||
1298 | proc ctrl_io_r8 |
||
2434 | Serge | 1299 | add edx, [ctrl.ctrl_io_base] |
1300 | in al, dx |
||
1301 | ret |
||
802 | serge | 1302 | endp |
1303 | |||
1304 | align 4 |
||
1305 | proc ctrl_io_r16 |
||
2434 | Serge | 1306 | add edx, [ctrl.ctrl_io_base] |
1307 | in ax, dx |
||
1308 | ret |
||
802 | serge | 1309 | endp |
1310 | |||
1311 | align 4 |
||
1312 | proc ctrl_io_r32 |
||
2434 | Serge | 1313 | add edx, [ctrl.ctrl_io_base] |
1314 | in eax, dx |
||
1315 | ret |
||
802 | serge | 1316 | endp |
1317 | |||
1318 | align 4 |
||
1319 | proc ctrl_io_w8 |
||
2434 | Serge | 1320 | add edx, [ctrl.ctrl_io_base] |
1321 | out dx, al |
||
1322 | ret |
||
802 | serge | 1323 | endp |
1324 | |||
1325 | align 4 |
||
1326 | proc ctrl_io_w16 |
||
2434 | Serge | 1327 | add edx, [ctrl.ctrl_io_base] |
1328 | out dx, ax |
||
1329 | ret |
||
802 | serge | 1330 | endp |
1331 | |||
1332 | align 4 |
||
1333 | proc ctrl_io_w32 |
||
2434 | Serge | 1334 | add edx, [ctrl.ctrl_io_base] |
1335 | out dx, eax |
||
1336 | ret |
||
802 | serge | 1337 | endp |
1338 | |||
1339 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
1340 | ; MEMORY MAPPED IO (os depended) |
||
1341 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
1342 | |||
1343 | align 4 |
||
1344 | proc codec_mem_r16 |
||
2434 | Serge | 1345 | add edx, [ctrl.codec_mem_base] |
1346 | mov ax, word [edx] |
||
1347 | ret |
||
802 | serge | 1348 | endp |
1349 | |||
1350 | align 4 |
||
1351 | proc codec_mem_w16 |
||
2434 | Serge | 1352 | add edx, [ctrl.codec_mem_base] |
1353 | mov word [edx], ax |
||
1354 | ret |
||
802 | serge | 1355 | endp |
1356 | |||
1357 | align 4 |
||
1358 | proc ctrl_mem_r8 |
||
2434 | Serge | 1359 | add edx, [ctrl.ctrl_mem_base] |
1360 | mov al, [edx] |
||
1361 | ret |
||
802 | serge | 1362 | endp |
1363 | |||
1364 | align 4 |
||
1365 | proc ctrl_mem_r16 |
||
2434 | Serge | 1366 | add edx, [ctrl.ctrl_mem_base] |
1367 | mov ax, [edx] |
||
1368 | ret |
||
802 | serge | 1369 | endp |
1370 | |||
1371 | align 4 |
||
1372 | proc ctrl_mem_r32 |
||
2434 | Serge | 1373 | add edx, [ctrl.ctrl_mem_base] |
1374 | mov eax, [edx] |
||
1375 | ret |
||
802 | serge | 1376 | endp |
1377 | |||
1378 | align 4 |
||
1379 | proc ctrl_mem_w8 |
||
2434 | Serge | 1380 | add edx, [ctrl.ctrl_mem_base] |
1381 | mov [edx], al |
||
1382 | ret |
||
802 | serge | 1383 | endp |
1384 | |||
1385 | align 4 |
||
1386 | proc ctrl_mem_w16 |
||
2434 | Serge | 1387 | add edx, [ctrl.ctrl_mem_base] |
1388 | mov [edx], ax |
||
1389 | ret |
||
802 | serge | 1390 | endp |
1391 | |||
1392 | align 4 |
||
1393 | proc ctrl_mem_w32 |
||
2434 | Serge | 1394 | add edx, [ctrl.ctrl_mem_base] |
1395 | mov [edx], eax |
||
1396 | ret |
||
802 | serge | 1397 | endp |
1398 | |||
1399 | align 4 |
||
1400 | dword2str: |
||
2434 | Serge | 1401 | mov esi, hex_buff |
1402 | mov ecx, -8 |
||
802 | serge | 1403 | @@: |
2434 | Serge | 1404 | rol eax, 4 |
1405 | mov ebx, eax |
||
1406 | and ebx, 0x0F |
||
1407 | mov bl, [ebx+hexletters] |
||
1408 | mov [8+esi+ecx], bl |
||
1409 | inc ecx |
||
1410 | jnz @B |
||
1411 | ret |
||
802 | serge | 1412 | |
1413 | hexletters db '0123456789ABCDEF' |
||
1414 | hex_buff db 8 dup(0),13,10,0 |
||
1415 | |||
1416 | |||
1417 | include "codec.inc" |
||
1418 | |||
1419 | align 4 |
||
1420 | devices dd (CTRL_ICH shl 16)+VID_INTEL,msg_ICH, set_ICH |
||
2434 | Serge | 1421 | dd (CTRL_ICH0 shl 16)+VID_INTEL,msg_ICH0,set_ICH |
1422 | dd (CTRL_ICH2 shl 16)+VID_INTEL,msg_ICH2,set_ICH |
||
1423 | dd (CTRL_ICH3 shl 16)+VID_INTEL,msg_ICH3,set_ICH |
||
1424 | dd (CTRL_ICH4 shl 16)+VID_INTEL,msg_ICH4,set_ICH4 |
||
1425 | dd (CTRL_ICH5 shl 16)+VID_INTEL,msg_ICH5,set_ICH4 |
||
1426 | dd (CTRL_ICH6 shl 16)+VID_INTEL,msg_ICH6,set_ICH4 |
||
1427 | dd (CTRL_ICH7 shl 16)+VID_INTEL,msg_ICH7,set_ICH4 |
||
802 | serge | 1428 | |
2434 | Serge | 1429 | dd (CTRL_NFORCE shl 16)+VID_NVIDIA,msg_NForce, set_ICH |
1430 | dd (CTRL_NFORCE2 shl 16)+VID_NVIDIA,msg_NForce2,set_ICH |
||
1431 | dd (CTRL_NFORCE3 shl 16)+VID_NVIDIA,msg_NForce3,set_ICH |
||
1432 | dd (CTRL_MCP04 shl 16)+VID_NVIDIA,msg_MCP04,set_ICH |
||
1433 | dd (CTRL_CK804 shl 16)+VID_NVIDIA,msg_CK804,set_ICH |
||
1434 | dd (CTRL_CK8 shl 16)+VID_NVIDIA,msg_CK8,set_ICH |
||
1435 | dd (CTRL_CK8S shl 16)+VID_NVIDIA,msg_CK8S,set_ICH |
||
1436 | dd (CTRL_MCP51 shl 16)+VID_NVIDIA,msg_MCP51,set_ICH |
||
802 | serge | 1437 | |
2434 | Serge | 1438 | dd 0 ;terminator |
802 | serge | 1439 | |
1440 | |||
1441 | version dd (5 shl 16) or (API_VERSION and 0xFFFF) |
||
1442 | |||
1443 | msg_ICH db '802801AA (ICH)', 13,10, 0 |
||
1444 | msg_ICH0 db '802801AB (ICH0)', 13,10, 0 |
||
1445 | msg_ICH2 db '802801BA (ICH2)', 13,10, 0 |
||
1446 | msg_ICH3 db '802801CA (ICH3)', 13,10, 0 |
||
1447 | msg_ICH4 db '802801DB (ICH4)', 13,10, 0 |
||
1448 | msg_ICH5 db '802801EB (ICH5)', 13,10, 0 |
||
1449 | msg_ICH6 db '802801FB (ICH6)', 13,10, 0 |
||
1450 | msg_ICH7 db '802801GB (ICH7)', 13,10, 0 |
||
1451 | msg_Intel db 'Intel ', 0 |
||
1452 | |||
1453 | msg_NForce db 'NForce', 13,10, 0 |
||
1454 | msg_NForce2 db 'NForce 2', 13,10, 0 |
||
1455 | msg_NForce3 db 'NForce 3', 13,10, 0 |
||
1456 | msg_MCP04 db 'NForce MCP04',13,10, 0 |
||
1457 | msg_CK804 db 'NForce CK804',13,10, 0 |
||
1458 | msg_CK8 db 'NForce CK8', 13,10, 0 |
||
1459 | msg_CK8S db 'NForce CK8S', 13,10, 0 |
||
1460 | msg_MCP51 db 'NForce MCP51',13,10, 0 |
||
1461 | |||
1462 | msg_NVidia db 'NVidia', 0 |
||
1463 | |||
2434 | Serge | 1464 | szKernel db 'KERNEL', 0 |
1465 | sz_sound_srv db 'SOUND',0 |
||
802 | serge | 1466 | |
1467 | msgInit db 'detect hardware...',13,10,0 |
||
1468 | msgFail db 'device not found',13,10,0 |
||
1469 | msgAttchIRQ db 'IRQ line not supported', 13,10, 0 |
||
1470 | msgInvIRQ db 'IRQ line not assigned or invalid', 13,10, 0 |
||
1471 | msgPlay db 'start play', 13,10,0 |
||
1472 | msgStop db 'stop play', 13,10,0 |
||
1473 | ;msgNotify db 'call notify',13,10,0 |
||
2434 | Serge | 1474 | msgIRQ db 'AC97 IRQ', 13,10,0 |
802 | serge | 1475 | msgInitCtrl db 'init controller',13,10,0 |
1476 | ;msgInitCodec db 'init codec',13,10,0 |
||
1477 | msgPrimBuff db 'create primary buffer ...',0 |
||
1478 | msgDone db 'done',13,10,0 |
||
1479 | msgRemap db 'Remap IRQ',13,10,0 |
||
1480 | ;msgReg db 'set service handler',13,10,0 |
||
2434 | Serge | 1481 | msgOk db 'service installed',13,10,0 |
802 | serge | 1482 | msgCold db 'cold reset',13,10,0 |
1483 | msgWarm db 'warm reset',13,10,0 |
||
1484 | msgWRFail db 'warm reset failed',13,10,0 |
||
1485 | msgCRFail db 'cold reset failed',13,10,0 |
||
1486 | msgCFail db 'codec not ready',13,10,0 |
||
1487 | msgResetOk db 'reset complete',13,10,0 |
||
1488 | msgStatus db 'global status ',0 |
||
1489 | msgControl db 'global control ',0 |
||
1490 | msgPciCmd db 'PCI command ',0 |
||
1491 | msgPciStat db 'PCI status ',0 |
||
1492 | msgCtrlIsaIo db 'controller io base ',0 |
||
1493 | msgMixIsaIo db 'codec io base ',0 |
||
1494 | msgCtrlMMIo db 'controller mmio base ',0 |
||
1495 | msgMixMMIo db 'codec mmio base ',0 |
||
1496 | msgIrqMap db 'AC97 irq map as ',0 |
||
1497 | |||
1498 | section '.data' data readable writable align 16 |
||
1499 | |||
2434 | Serge | 1500 | pcmout_bdl rq 32 |
1501 | buff_list rd 32 |
||
802 | serge | 1502 | |
1503 | codec CODEC |
||
1504 | ctrl AC_CNTRL |
||
1505 | |||
1506 | lpc_bus rd 1 |
||
1507 | civ_val rd 1 |