Rev 214 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
168 | serge | 1 | |
2 | |||
3 | |||
4 | |||
5 | |||
6 | |||
7 | |||
8 | |||
9 | |||
10 | |||
11 | BIT1 EQU 0x00000002 |
||
12 | BIT2 EQU 0x00000004 |
||
13 | BIT3 EQU 0x00000008 |
||
14 | BIT4 EQU 0x00000010 |
||
15 | BIT5 EQU 0x00000020 |
||
16 | BIT6 EQU 0x00000040 |
||
17 | BIT7 EQU 0x00000080 |
||
18 | BIT8 EQU 0x00000100 |
||
19 | BIT9 EQU 0x00000200 |
||
20 | BIT10 EQU 0x00000400 |
||
21 | BIT11 EQU 0x00000800 |
||
22 | BIT12 EQU 0x00001000 |
||
23 | BIT13 EQU 0x00002000 |
||
24 | BIT14 EQU 0x00004000 |
||
25 | BIT15 EQU 0x00008000 |
||
26 | BIT16 EQU 0x00010000 |
||
27 | BIT17 EQU 0x00020000 |
||
28 | BIT18 EQU 0x00040000 |
||
29 | BIT19 EQU 0x00080000 |
||
30 | BIT20 EQU 0x00100000 |
||
31 | BIT21 EQU 0x00200000 |
||
32 | BIT22 EQU 0x00400000 |
||
33 | BIT23 EQU 0x00800000 |
||
34 | BIT24 EQU 0x00100000 |
||
35 | BIT25 EQU 0x02000000 |
||
36 | BIT26 EQU 0x04000000 |
||
37 | BIT27 EQU 0x08000000 |
||
38 | BIT28 EQU 0x10000000 |
||
39 | BIT29 EQU 0x20000000 |
||
40 | BIT30 EQU 0x40000000 |
||
41 | BIT31 EQU 0x80000000 |
||
42 | |||
43 | |||
44 | CTRL_SIS equ 0x7012 |
||
45 | |||
46 | |||
47 | PCM_OUT_CR_REG equ 0x1b ; PCM out Control Register |
||
48 | PCM_OUT_LVI_REG equ 0x15 ; PCM last valid index |
||
49 | PCM_OUT_SR_REG equ 0x18 ; PCM out Status register |
||
50 | PCM_OUT_PIV_REG equ 0x1a ; PCM out prefetched index |
||
51 | PCM_OUT_CIV_REG equ 0x14 ; PCM out current index |
||
52 | |||
53 | |||
54 | MC_IN_CR_REG equ 0x2b ; MIC in Control Register |
||
55 | RR equ BIT1 ; reset registers. Nukes all regs |
||
56 | |||
57 | |||
58 | CODEC_AUX_VOL equ 0x04 ; |
||
59 | CODEC_PCM_OUT_REG equ 18h ; PCM output volume |
||
60 | CODEC_EXT_AUDIO_REG equ 28h ; extended audio |
||
61 | CODEC_EXT_AUDIO_CTRL_REG equ 2ah ; extended audio control |
||
62 | CODEC_PCM_FRONT_DACRATE_REG equ 2ch ; PCM out sample rate |
||
63 | CODEC_PCM_SURND_DACRATE_REG equ 2eh ; surround sound sample rate |
||
64 | CODEC_PCM_LFE_DACRATE_REG equ 30h ; LFE sample rate |
||
65 | |||
66 | |||
67 | |||
68 | CTRL_STAT equ 0x30 ; Global Status |
||
69 | CTRL_CAS equ 0x34 ; Codec Access Semiphore |
||
70 | |||
71 | |||
72 | |||
73 | |||
74 | |||
75 | |||
76 | |||
77 | |||
78 | CTRL_CNT_AC_OFF equ 0x00000008 ; ACLINK Off |
||
79 | CTRL_CNT_WARM equ 0x00000004 ; AC97 Warm Reset |
||
80 | CTRL_CNT_COLD equ 0x00000002 ; AC97 Cold Reset |
||
81 | CTRL_CNT_GIE equ 0x00000001 ; GPI Interrupt Enable |
||
82 | |||
83 | |||
84 | CODEC_REG_ST equ 0x26 |
||
85 | |||
86 | |||
87 | |||
88 | DEV_STOP equ 2 |
||
89 | DEV_CALLBACK equ 3 |
||
90 | DEV_SET_BUFF equ 4 |
||
91 | DEV_NOTIFY equ 5 |
||
92 | DEV_SET_MASTERVOL equ 6 |
||
93 | DEV_GET_MASTERVOL equ 7 |
||
94 | DEV_GET_INFO equ 8 |
||
95 | |||
96 | |||
97 | { .bus dd ? |
||
188 | serge | 98 | .devfn dd ? |
99 | |||
168 | serge | 100 | |
188 | serge | 101 | .dev_id dd ? |
102 | .pci_cmd dd ? |
||
103 | .pci_stat dd ? |
||
104 | |||
168 | serge | 105 | |
188 | serge | 106 | .codec_mem_base dd ? |
107 | |||
168 | serge | 108 | |
188 | serge | 109 | .ctrl_mem_base dd ? |
110 | .cfg_reg dd ? |
||
111 | .int_line dd ? |
||
112 | |||
168 | serge | 113 | |
188 | serge | 114 | .ctrl_ids dd ? ;hub id string |
115 | |||
168 | serge | 116 | |
188 | serge | 117 | |
168 | serge | 118 | |
188 | serge | 119 | .notify_task dd ? |
120 | |||
168 | serge | 121 | |
188 | serge | 122 | .ctrl_setup dd ? |
123 | .user_callback dd ? |
||
124 | .codec_read16 dd ? |
||
125 | .codec_write16 dd ? |
||
126 | |||
168 | serge | 127 | |
188 | serge | 128 | .ctrl_read16 dd ? |
129 | .ctrl_read32 dd ? |
||
130 | |||
168 | serge | 131 | |
188 | serge | 132 | .ctrl_write16 dd ? |
133 | .ctrl_write32 dd ? |
||
134 | } |
||
168 | serge | 135 | |
136 | |||
137 | { |
||
138 | .chip_id dd ? |
||
188 | serge | 139 | .flags dd ? |
140 | .status dd ? |
||
141 | |||
168 | serge | 142 | |
188 | serge | 143 | .chip_ids dd ? ;chip model string |
144 | |||
168 | serge | 145 | |
188 | serge | 146 | dd ? |
147 | |||
168 | serge | 148 | |
188 | serge | 149 | .reg_master_vol dw ? ;0x02 |
150 | .reg_aux_out_vol dw ? ;0x04 |
||
151 | .reg_mone_vol dw ? ;0x06 |
||
152 | .reg_master_tone dw ? ;0x08 |
||
153 | .reg_beep_vol dw ? ;0x0A |
||
154 | .reg_phone_vol dw ? ;0x0C |
||
155 | .reg_mic_vol dw ? ;0x0E |
||
156 | .reg_line_in_vol dw ? ;0x10 |
||
157 | .reg_cd_vol dw ? ;0x12 |
||
158 | .reg_video_vol dw ? ;0x14 |
||
159 | .reg_aux_in_vol dw ? ;0x16 |
||
160 | .reg_pcm_out_vol dw ? ;0x18 |
||
161 | .reg_rec_select dw ? ;0x1A |
||
162 | .reg_rec_gain dw ? ;0x1C |
||
163 | .reg_rec_gain_mic dw ? ;0x1E |
||
164 | .reg_gen dw ? ;0x20 |
||
165 | .reg_3d_ctrl dw ? ;0X22 |
||
166 | .reg_page dw ? ;0X24 |
||
167 | .reg_powerdown dw ? ;0x26 |
||
168 | .reg_ext_audio dw ? ;0x28 |
||
169 | .reg_ext_st dw ? ;0x2a |
||
170 | .reg_pcm_front_rate dw ? ;0x2c |
||
171 | .reg_pcm_surr_rate dw ? ;0x2e |
||
172 | .reg_lfe_rate dw ? ;0x30 |
||
173 | .reg_pcm_in_rate dw ? ;0x32 |
||
174 | dw ? ;0x34 |
||
175 | .reg_cent_lfe_vol dw ? ;0x36 |
||
176 | .reg_surr_vol dw ? ;0x38 |
||
177 | .reg_spdif_ctrl dw ? ;0x3A |
||
178 | dw ? ;0x3C |
||
179 | dw ? ;0x3E |
||
180 | dw ? ;0x40 |
||
181 | dw ? ;0x42 |
||
182 | dw ? ;0x44 |
||
183 | dw ? ;0x46 |
||
184 | dw ? ;0x48 |
||
185 | dw ? ;0x4A |
||
186 | dw ? ;0x4C |
||
187 | dw ? ;0x4E |
||
188 | dw ? ;0x50 |
||
189 | dw ? ;0x52 |
||
190 | dw ? ;0x54 |
||
191 | dw ? ;0x56 |
||
192 | dw ? ;0x58 |
||
193 | dw ? ;0x5A |
||
194 | dw ? ;0x5C |
||
195 | dw ? ;0x5E |
||
196 | .reg_page_0 dw ? ;0x60 |
||
197 | .reg_page_1 dw ? ;0x62 |
||
198 | .reg_page_2 dw ? ;0x64 |
||
199 | .reg_page_3 dw ? ;0x66 |
||
200 | .reg_page_4 dw ? ;0x68 |
||
201 | .reg_page_5 dw ? ;0x6A |
||
202 | .reg_page_6 dw ? ;0x6C |
||
203 | .reg_page_7 dw ? ;0x6E |
||
204 | dw ? ;0x70 |
||
205 | dw ? ;0x72 |
||
206 | dw ? ;0x74 |
||
207 | dw ? ;0x76 |
||
208 | dw ? ;0x78 |
||
209 | dw ? ;0x7A |
||
210 | .reg_vendor_id_1 dw ? ;0x7C |
||
211 | .reg_vendor_id_2 dw ? ;0x7E |
||
212 | |||
168 | serge | 213 | |
214 | |||
188 | serge | 215 | .set_master_vol dd ? |
216 | } |
||
168 | serge | 217 | |
218 | |||
219 | { .pci_cmd dd ? |
||
220 | .irq dd ? |
||
221 | .glob_cntrl dd ? |
||
222 | .glob_sta dd ? |
||
223 | .codec_io_base dd ? |
||
224 | .ctrl_io_base dd ? |
||
225 | .codec_mem_base dd ? |
||
226 | .ctrl_mem_base dd ? |
||
227 | .codec_id dd ? |
||
228 | } |
||
229 | |||
230 | |||
231 | { .handle dd ? |
||
232 | .io_code dd ? |
||
233 | .input dd ? |
||
234 | .inp_size dd ? |
||
235 | .output dd ? |
||
236 | .out_size dd ? |
||
237 | } |
||
238 | |||
239 | |||
240 | IOCTL IOCTL |
||
241 | end virtual |
||
242 | |||
243 | |||
244 | |||
245 | |||
246 | new_app_base equ 0x60400000; 0x01000000 |
||
247 | PROC_BASE equ OS_BASE+0x0080000 |
||
248 | |||
249 | |||
188 | serge | 250 | public service_proc |
168 | serge | 251 | |
252 | |||
188 | serge | 253 | extrn SysMsgBoardStr |
254 | extrn PciApi |
||
255 | extrn PciRead32 |
||
256 | extrn PciRead8 |
||
257 | extrn PciWrite8 |
||
258 | extrn AllocKernelSpace |
||
259 | extrn MapPage |
||
260 | extrn RegService |
||
261 | extrn KernelAlloc |
||
262 | extrn GetPgAddr |
||
263 | extrn GetCurrentTask |
||
264 | |||
168 | serge | 265 | |
188 | serge | 266 | |
267 | |||
214 | serge | 268 | |
269 | |||
270 | cmp eax, 1 |
||
271 | je .entry |
||
272 | jmp .stop |
||
273 | .entry: |
||
274 | if DEBUG |
||
168 | serge | 275 | mov esi, msgInit |
276 | call SysMsgBoardStr |
||
188 | serge | 277 | end if |
168 | serge | 278 | |
279 | |||
280 | test eax, eax |
||
281 | jz .fail |
||
282 | |||
283 | |||
284 | mov esi,[ctrl.vendor_ids] |
||
285 | call SysMsgBoardStr |
||
188 | serge | 286 | mov esi, [ctrl.ctrl_ids] |
168 | serge | 287 | call SysMsgBoardStr |
188 | serge | 288 | end if |
168 | serge | 289 | |
290 | |||
291 | test eax, eax |
||
292 | jz .fail |
||
293 | |||
294 | |||
295 | mov esi, msgInitCodec |
||
296 | call SysMsgBoardStr |
||
188 | serge | 297 | end if |
168 | serge | 298 | |
299 | |||
300 | test eax, eax |
||
301 | jz .fail |
||
302 | |||
303 | |||
304 | mov esi, [codec.ac_vendor_ids] |
||
305 | call SysMsgBoardStr |
||
188 | serge | 306 | |
168 | serge | 307 | |
308 | call SysMsgBoardStr |
||
188 | serge | 309 | end if |
168 | serge | 310 | |
311 | |||
312 | call setup_codec |
||
313 | |||
314 | |||
315 | call SysMsgBoardStr |
||
188 | serge | 316 | |
168 | serge | 317 | |
318 | |||
319 | |||
188 | serge | 320 | |
168 | serge | 321 | |
188 | serge | 322 | |
168 | serge | 323 | |
324 | call SysMsgBoardStr |
||
188 | serge | 325 | |
168 | serge | 326 | |
327 | .fail: |
||
328 | if DEBUG |
||
329 | mov esi, msgFail |
||
330 | call SysMsgBoardStr |
||
188 | serge | 331 | end if |
168 | serge | 332 | xor eax, eax |
214 | serge | 333 | ret |
334 | .stop: |
||
335 | call stop |
||
336 | mov ax, 0x1c |
||
224 | serge | 337 | mov edx, PCM_OUT_SR_REG |
338 | call [ctrl.ctrl_write16] |
||
339 | mov [ctrl.user_callback], 0 |
||
214 | serge | 340 | ret |
341 | endp |
||
342 | |||
168 | serge | 343 | |
344 | io_code equ IOCTL.io_code |
||
345 | input equ IOCTL.input |
||
346 | inp_size equ IOCTL.inp_size |
||
347 | output equ IOCTL.output |
||
348 | out_size equ IOCTL.out_size |
||
349 | |||
350 | |||
351 | proc service_proc stdcall, ioctl:dword |
||
352 | |||
353 | |||
354 | mov eax, [edi+io_code] |
||
355 | cmp eax, DEV_PLAY |
||
356 | jne @F |
||
357 | if DEBUG |
||
358 | mov esi, msgPlay |
||
359 | call SysMsgBoardStr |
||
188 | serge | 360 | end if |
168 | serge | 361 | call play |
362 | ret |
||
363 | @@: |
||
364 | cmp eax, DEV_STOP |
||
365 | jne @F |
||
366 | if DEBUG |
||
367 | mov esi, msgStop |
||
368 | call SysMsgBoardStr |
||
188 | serge | 369 | end if |
168 | serge | 370 | call stop |
371 | ret |
||
372 | @@: |
||
373 | cmp eax, DEV_CALLBACK |
||
374 | jne @F |
||
375 | mov ebx, [edi+input] |
||
376 | stdcall set_callback, [ebx] |
||
377 | ret |
||
378 | @@: |
||
379 | cmp eax, DEV_SET_MASTERVOL |
||
380 | jne @F |
||
381 | mov ebx, [edi+input] |
||
382 | stdcall set_master_vol, [ebx] |
||
383 | ret |
||
384 | @@: |
||
385 | cmp eax, DEV_GET_MASTERVOL |
||
386 | jne @F |
||
387 | mov ebx, [edi+output] |
||
388 | test ebx, ebx |
||
389 | jz .fail |
||
390 | |||
391 | |||
392 | ret |
||
393 | @@: |
||
394 | cmp eax, DEV_GET_INFO |
||
395 | jne @F |
||
396 | mov ebx, [edi+output] |
||
397 | stdcall get_dev_info, ebx |
||
398 | ret |
||
399 | @@: |
||
400 | .fail: |
||
401 | xor eax, eax |
||
402 | ret |
||
403 | endp |
||
404 | |||
405 | |||
406 | restore io_code |
||
407 | restore input |
||
408 | restore inp_size |
||
409 | restore output |
||
410 | restore out_size |
||
411 | |||
412 | |||
413 | proc ac97_irq |
||
414 | |||
415 | |||
416 | ; mov esi, msgIRQ |
||
417 | ; call SysMsgBoardStr |
||
188 | serge | 418 | ; end if |
168 | serge | 419 | |
420 | |||
421 | mov al, 0x14 |
||
422 | call [ctrl.ctrl_write8] |
||
423 | |||
424 | |||
425 | mov edx, PCM_OUT_SR_REG |
||
426 | call [ctrl.ctrl_write16] |
||
427 | |||
428 | |||
429 | call [ctrl.ctrl_read8] |
||
430 | |||
431 | |||
432 | cmp eax, [civ_val] |
||
433 | je .skip |
||
434 | |||
435 | |||
436 | dec eax |
||
437 | and eax, 0x1F |
||
438 | mov [ctrl.lvi_reg], eax |
||
439 | |||
440 | |||
441 | call [ctrl.ctrl_write8] |
||
442 | |||
443 | |||
444 | mov ax, 0x1D |
||
445 | call [ctrl.ctrl_write8] |
||
446 | |||
447 | |||
448 | add eax, 2 |
||
449 | and eax, 31 |
||
450 | mov ebx, dword [buff_list+eax*4] |
||
451 | |||
452 | |||
453 | je @f |
||
454 | |||
455 | |||
456 | @@: |
||
457 | ret |
||
458 | |||
459 | |||
460 | mov edx, PCM_OUT_CR_REG |
||
461 | mov ax, 0x1D |
||
462 | call [ctrl.ctrl_write8] |
||
463 | ret |
||
464 | endp |
||
465 | |||
466 | |||
467 | proc create_primary_buff |
||
468 | |||
469 | |||
188 | serge | 470 | mov [ctrl.buffer], eax |
168 | serge | 471 | |
472 | |||
473 | mov ecx, 0x10000/4 |
||
474 | xor eax, eax |
||
475 | rep stosd |
||
476 | |||
477 | |||
188 | serge | 478 | |
168 | serge | 479 | |
480 | mov ecx, 4 |
||
481 | mov edi, pcmout_bdl |
||
482 | @@: |
||
483 | mov [edi], eax |
||
484 | mov [edi+4], ebx |
||
485 | |||
486 | |||
487 | mov [edi+4+32], ebx |
||
488 | |||
489 | |||
490 | mov [edi+4+64], ebx |
||
491 | |||
492 | |||
493 | mov [edi+4+96], ebx |
||
494 | |||
495 | |||
496 | mov [edi+4+128], ebx |
||
497 | |||
498 | |||
499 | mov [edi+4+160], ebx |
||
500 | |||
501 | |||
502 | mov [edi+4+192], ebx |
||
503 | |||
504 | |||
505 | mov [edi+4+224], ebx |
||
506 | |||
507 | |||
508 | add edi, 8 |
||
509 | loop @B |
||
510 | |||
511 | |||
512 | mov eax, [ctrl.buffer] |
||
513 | mov ecx, 4 |
||
514 | @@: |
||
515 | mov [edi], eax |
||
516 | mov [edi+16], eax |
||
517 | mov [edi+32], eax |
||
518 | mov [edi+48], eax |
||
519 | mov [edi+64], eax |
||
520 | mov [edi+80], eax |
||
521 | mov [edi+96], eax |
||
522 | mov [edi+112], eax |
||
523 | |||
524 | |||
525 | add edi, 4 |
||
526 | loop @B |
||
527 | |||
528 | |||
529 | stdcall GetPgAddr, ecx |
||
188 | serge | 530 | and ecx, 0xFFF |
168 | serge | 531 | add eax, ecx |
532 | |||
533 | |||
534 | call [ctrl.ctrl_write32] |
||
535 | |||
536 | |||
537 | mov [ctrl.lvi_reg], eax |
||
538 | mov edx, PCM_OUT_LVI_REG |
||
539 | call [ctrl.ctrl_write8] |
||
540 | |||
541 | |||
542 | call [ctrl.ctrl_read32] |
||
543 | and eax, not 0x000000C0 |
||
544 | mov edx, GLOB_CTRL |
||
545 | call [ctrl.ctrl_write32] |
||
546 | |||
547 | |||
548 | |||
549 | endp |
||
550 | |||
551 | |||
552 | proc detect_controller |
||
553 | locals |
||
554 | last_bus dd ? |
||
555 | bus dd ? |
||
556 | devfn dd ? |
||
557 | endl |
||
558 | |||
559 | |||
560 | mov [bus], eax |
||
561 | inc eax |
||
562 | call PciApi |
||
188 | serge | 563 | cmp eax, -1 |
168 | serge | 564 | je .err |
565 | |||
566 | |||
567 | |||
568 | |||
569 | and [devfn], 0 |
||
570 | .next_dev: |
||
571 | stdcall PciRead32, [bus], [devfn], dword 0 |
||
188 | serge | 572 | test eax, eax |
168 | serge | 573 | jz .next |
574 | cmp eax, -1 |
||
575 | je .next |
||
576 | |||
577 | |||
578 | @@: |
||
579 | mov ebx, [edi] |
||
580 | test ebx, ebx |
||
581 | jz .next |
||
582 | |||
583 | |||
584 | je .found |
||
585 | add edi, 12 |
||
586 | jmp @B |
||
587 | |||
588 | |||
589 | cmp [devfn], 256 |
||
590 | jb .next_dev |
||
591 | mov eax, [bus] |
||
592 | inc eax |
||
593 | mov [bus], eax |
||
594 | cmp eax, [last_bus] |
||
595 | jna .next_bus |
||
596 | xor eax, eax |
||
597 | ret |
||
598 | .found: |
||
599 | mov ebx, [bus] |
||
600 | mov [ctrl.bus], ebx |
||
601 | |||
602 | |||
603 | mov [ctrl.devfn], ecx |
||
604 | |||
605 | |||
606 | and edx, 0xFFFF |
||
607 | mov [ctrl.vendor], edx |
||
608 | shr eax, 16 |
||
609 | mov [ctrl.dev_id], eax |
||
610 | |||
611 | |||
612 | mov [ctrl.ctrl_ids], ebx |
||
613 | mov [ctrl.vendor_ids], msg_SIS |
||
614 | |||
615 | |||
616 | mov [ctrl.ctrl_setup], esi |
||
617 | |||
618 | |||
619 | .err: |
||
620 | xor eax, eax |
||
621 | ret |
||
622 | endp |
||
623 | |||
624 | |||
625 | proc init_controller |
||
626 | |||
627 | |||
188 | serge | 628 | mov ebx, eax |
168 | serge | 629 | and eax, 0xFFFF |
630 | mov [ctrl.pci_cmd], eax |
||
631 | shr ebx, 16 |
||
632 | mov [ctrl.pci_stat], ebx |
||
633 | |||
634 | |||
188 | serge | 635 | and eax,0xFFFE |
168 | serge | 636 | mov [ctrl.codec_io_base], eax |
637 | |||
638 | |||
188 | serge | 639 | and eax, 0xFFC0 |
168 | serge | 640 | mov [ctrl.ctrl_io_base], eax |
641 | |||
642 | |||
188 | serge | 643 | mov [ctrl.codec_mem_base], eax |
168 | serge | 644 | |
645 | |||
188 | serge | 646 | mov [ctrl.ctrl_mem_base], eax |
168 | serge | 647 | |
648 | |||
188 | serge | 649 | and eax, 0xFF |
168 | serge | 650 | mov [ctrl.int_line], eax |
651 | |||
652 | |||
188 | serge | 653 | and eax, 0xFF |
168 | serge | 654 | mov [ctrl.cfg_reg], eax |
655 | |||
656 | |||
657 | xor eax, eax |
||
658 | inc eax |
||
659 | ret |
||
660 | endp |
||
661 | |||
662 | |||
663 | proc set_SIS |
||
664 | mov [ctrl.codec_read16], codec_io_r16 ;virtual |
||
665 | mov [ctrl.codec_write16], codec_io_w16 ;virtual |
||
666 | |||
667 | |||
668 | mov [ctrl.ctrl_read16], ctrl_io_r16 ;virtual |
||
669 | mov [ctrl.ctrl_read32], ctrl_io_r32 ;virtual |
||
670 | |||
671 | |||
672 | mov [ctrl.ctrl_write16], ctrl_io_w16 ;virtual |
||
673 | mov [ctrl.ctrl_write32], ctrl_io_w32 ;virtual |
||
674 | ret |
||
675 | endp |
||
676 | |||
677 | |||
678 | proc reset_controller |
||
679 | |||
680 | |||
681 | mov edx, PCM_IN_CR_REG |
||
682 | call [ctrl.ctrl_write8] |
||
683 | |||
684 | |||
685 | call [ctrl.ctrl_write8] |
||
686 | |||
687 | |||
688 | call [ctrl.ctrl_write8] |
||
689 | |||
690 | |||
691 | mov edx, PCM_IN_CR_REG |
||
692 | call [ctrl.ctrl_write8] |
||
693 | |||
694 | |||
695 | call [ctrl.ctrl_write8] |
||
696 | |||
697 | |||
698 | call [ctrl.ctrl_write8] |
||
699 | |||
700 | |||
701 | |||
702 | endp |
||
703 | |||
704 | |||
705 | proc init_codec |
||
706 | locals |
||
707 | counter dd ? |
||
708 | endl |
||
709 | |||
710 | |||
711 | and eax, eax |
||
712 | jz .err |
||
713 | |||
714 | |||
715 | call [ctrl.codec_write16] |
||
716 | |||
717 | |||
718 | mov edx, CODEC_REG_POWERDOWN |
||
719 | call [ctrl.codec_write16] |
||
720 | |||
721 | |||
722 | .wait: |
||
723 | mov edx, CODEC_REG_POWERDOWN |
||
724 | call [ctrl.codec_read16] |
||
725 | and eax, 0x0F |
||
726 | cmp eax, 0x0F |
||
727 | jz .ready |
||
728 | |||
729 | |||
730 | call StallExec |
||
731 | sub [counter] , 1 |
||
732 | jnz .wait |
||
733 | .err: |
||
734 | xor eax, eax ; timeout error |
||
735 | ret |
||
736 | .ready: |
||
737 | call detect_codec |
||
738 | |||
739 | |||
740 | inc eax |
||
741 | ret |
||
742 | endp |
||
743 | |||
744 | |||
745 | proc reset_codec |
||
746 | mov edx, GLOB_CTRL |
||
747 | call [ctrl.ctrl_read32] |
||
748 | |||
749 | |||
750 | jz .cold |
||
751 | |||
752 | |||
753 | jnc .ok |
||
754 | .cold: |
||
755 | call cold_reset |
||
756 | jnc .ok |
||
757 | |||
758 | |||
759 | mov esi, msgCFail |
||
760 | call SysMsgBoardStr |
||
188 | serge | 761 | end if |
168 | serge | 762 | xor eax, eax ; timeout error |
763 | ret |
||
764 | .ok: |
||
765 | xor eax, eax |
||
766 | inc eax |
||
767 | ret |
||
768 | endp |
||
769 | |||
770 | |||
771 | proc warm_reset |
||
772 | locals |
||
773 | counter dd ? |
||
774 | endl |
||
775 | |||
776 | |||
777 | mov edx, GLOB_CTRL |
||
778 | call [ctrl.ctrl_write32] |
||
779 | |||
780 | |||
781 | mov esi, msgWarm |
||
782 | call SysMsgBoardStr |
||
188 | serge | 783 | end if |
168 | serge | 784 | |
785 | |||
786 | .wait: |
||
787 | mov eax, 100000 ; wait 100 ms |
||
788 | call StallExec |
||
789 | |||
790 | |||
791 | call [ctrl.ctrl_read32] |
||
792 | test eax, 4 |
||
793 | jz .ok |
||
794 | sub [counter], 1 |
||
795 | jnz .wait |
||
796 | |||
797 | |||
798 | mov esi, msgWRFail |
||
799 | call SysMsgBoardStr |
||
188 | serge | 800 | end if |
168 | serge | 801 | |
802 | |||
803 | ret |
||
804 | .ok: |
||
805 | mov edx, CTRL_STAT |
||
806 | call [ctrl.ctrl_read32] |
||
807 | and eax, CTRL_ST_CREADY |
||
808 | jz .fail |
||
809 | clc |
||
810 | ret |
||
811 | .fail: |
||
812 | stc |
||
813 | ret |
||
814 | endp |
||
815 | |||
816 | |||
817 | proc cold_reset |
||
818 | locals |
||
819 | counter dd ? |
||
820 | endl |
||
821 | |||
822 | |||
823 | mov edx, GLOB_CTRL |
||
824 | call [ctrl.ctrl_write32] |
||
825 | |||
826 | |||
827 | mov esi, msgCold |
||
828 | call SysMsgBoardStr |
||
188 | serge | 829 | end if |
168 | serge | 830 | |
831 | |||
832 | call StallExec |
||
833 | |||
834 | |||
835 | mov edx, GLOB_CTRL |
||
836 | call [ctrl.ctrl_write32] |
||
837 | |||
838 | |||
839 | .wait: |
||
840 | mov eax, 100000 ; wait 100 ms |
||
841 | call StallExec |
||
842 | |||
843 | |||
844 | call [ctrl.ctrl_read32] |
||
845 | test eax, 4 |
||
846 | jz .ok |
||
847 | sub [counter], 1 |
||
848 | jnz .wait |
||
849 | |||
850 | |||
851 | mov esi, msgCRFail |
||
852 | call SysMsgBoardStr |
||
188 | serge | 853 | end if |
168 | serge | 854 | stc |
855 | ret |
||
856 | .ok: |
||
857 | mov edx, CTRL_STAT |
||
858 | call [ctrl.ctrl_read32] |
||
859 | and eax, CTRL_ST_CREADY |
||
860 | jz .fail |
||
861 | clc |
||
862 | ret |
||
863 | .fail: |
||
864 | stc |
||
865 | ret |
||
866 | endp |
||
867 | |||
868 | |||
869 | proc play |
||
870 | xor eax, eax |
||
871 | mov [civ_val], eax |
||
872 | mov edx, PCM_OUT_CIV_REG |
||
873 | call [ctrl.ctrl_write8] |
||
874 | |||
875 | |||
876 | mov [ctrl.lvi_reg], eax |
||
877 | mov edx, PCM_OUT_LVI_REG |
||
878 | call [ctrl.ctrl_write8] |
||
879 | |||
880 | |||
881 | mov ax, 0x1D |
||
882 | call [ctrl.ctrl_write8] |
||
883 | ret |
||
884 | endp |
||
885 | |||
886 | |||
887 | proc stop |
||
888 | mov edx, PCM_OUT_CR_REG |
||
889 | mov ax, 0x14 |
||
890 | call [ctrl.ctrl_write8] |
||
891 | |||
892 | |||
893 | mov [ctrl.lvi_reg], eax |
||
894 | mov edx, PCM_OUT_LVI_REG |
||
895 | call [ctrl.ctrl_write8] |
||
896 | ret |
||
897 | endp |
||
898 | |||
899 | |||
900 | proc get_dev_info stdcall, p_info:dword |
||
901 | virtual at esi |
||
902 | CTRL_INFO CTRL_INFO |
||
903 | end virtual |
||
904 | |||
905 | |||
906 | mov eax, [ctrl.int_line] |
||
907 | mov ebx, [ctrl.codec_io_base] |
||
908 | mov ecx, [ctrl.ctrl_io_base] |
||
909 | mov edx, [ctrl.codec_mem_base] |
||
910 | mov edi, [ctrl.ctrl_mem_base] |
||
911 | |||
912 | |||
913 | mov [CTRL_INFO.codec_io_base], ebx |
||
914 | mov [CTRL_INFO.ctrl_io_base], ecx |
||
915 | mov [CTRL_INFO.codec_mem_base], edx |
||
916 | mov [CTRL_INFO.ctrl_mem_base], edi |
||
917 | |||
918 | |||
919 | mov [CTRL_INFO.codec_id], eax |
||
920 | |||
921 | |||
922 | call [ctrl.ctrl_read32] |
||
923 | mov [CTRL_INFO.glob_cntrl], eax |
||
924 | |||
925 | |||
926 | call [ctrl.ctrl_read32] |
||
927 | mov [CTRL_INFO.glob_sta], eax |
||
928 | |||
929 | |||
930 | mov [CTRL_INFO.pci_cmd], ebx |
||
931 | |||
932 | |||
933 | endp |
||
934 | |||
935 | |||
936 | proc set_callback stdcall, handler:dword |
||
937 | mov eax, [handler] |
||
938 | mov [ctrl.user_callback], eax |
||
939 | ret |
||
940 | endp |
||
941 | |||
942 | |||
943 | proc codec_read stdcall, ac_reg:dword ; reg = edx, reval = eax |
||
944 | |||
945 | |||
946 | |||
947 | |||
948 | shr ebx, 1 |
||
949 | bt [codec.shadow_flag], ebx |
||
950 | jc .use_shadow |
||
951 | |||
952 | |||
953 | mov ecx, eax |
||
954 | |||
955 | |||
956 | call [ctrl.ctrl_read32] |
||
957 | test eax, CTRL_ST_RCS |
||
958 | jz .read_ok |
||
959 | |||
960 | |||
961 | call [ctrl.ctrl_write32] |
||
962 | xor eax,eax |
||
963 | not eax ;timeout |
||
964 | ret |
||
965 | .read_ok: |
||
966 | mov edx, [ac_reg] |
||
967 | mov [codec.regs+edx], cx |
||
968 | bts [codec.shadow_flag], ebx |
||
969 | mov eax, ecx |
||
970 | ret |
||
971 | .use_shadow: |
||
972 | movzx eax, word [codec.regs+edx] |
||
973 | ret |
||
974 | endp |
||
975 | |||
976 | |||
977 | proc codec_write stdcall, ac_reg:dword |
||
978 | push eax |
||
979 | call check_semafore |
||
980 | and eax, eax |
||
981 | jz .err |
||
982 | pop eax |
||
983 | |||
984 | |||
985 | mov edx, esi |
||
986 | call [ctrl.codec_write16] |
||
987 | mov [codec.regs+esi], ax |
||
988 | shr esi, 1 |
||
989 | bts [codec.shadow_flag], esi |
||
990 | ret |
||
991 | .err: |
||
992 | pop eax |
||
993 | ret |
||
994 | endp |
||
995 | |||
996 | |||
997 | |||
998 | proc codec_check_ready |
||
999 | |||
1000 | |||
1001 | call [ctrl.ctrl_read32] |
||
1002 | and eax, CTRL_ST_CREADY |
||
1003 | jz .not_ready |
||
1004 | |||
1005 | |||
1006 | inc eax |
||
1007 | ret |
||
1008 | |||
1009 | |||
1010 | .not_ready: |
||
1011 | xor eax, eax |
||
1012 | ret |
||
1013 | endp |
||
1014 | |||
1015 | |||
1016 | |||
1017 | proc check_semafore |
||
1018 | local counter:DWORD |
||
1019 | |||
1020 | |||
1021 | .l1: |
||
1022 | mov edx, CTRL_CAS |
||
1023 | call [ctrl.ctrl_read8] |
||
1024 | and eax, CAS_FLAG |
||
1025 | jz .ok |
||
1026 | |||
1027 | |||
1028 | call StallExec |
||
1029 | sub [counter], 1 |
||
1030 | jnz .l1 |
||
1031 | xor eax, eax |
||
1032 | ret |
||
1033 | align 4 |
||
1034 | .ok: |
||
1035 | xor eax,eax |
||
1036 | inc eax |
||
1037 | ret |
||
1038 | endp |
||
1039 | |||
1040 | |||
1041 | proc StallExec |
||
1042 | push ecx |
||
1043 | push edx |
||
1044 | push ebx |
||
1045 | push eax |
||
1046 | |||
1047 | |||
1048 | mul ecx |
||
1049 | mov ebx, eax ;low |
||
1050 | mov ecx, edx ;high |
||
1051 | rdtsc |
||
1052 | add ebx, eax |
||
1053 | adc ecx,edx |
||
1054 | @@: |
||
1055 | rdtsc |
||
1056 | sub eax, ebx |
||
1057 | sbb edx, ecx |
||
1058 | jb @B |
||
1059 | |||
1060 | |||
1061 | pop ebx |
||
1062 | pop edx |
||
1063 | pop ecx |
||
1064 | ret |
||
1065 | endp |
||
1066 | |||
1067 | |||
1068 | ; CONTROLLER IO functions |
||
1069 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
1070 | |||
1071 | |||
1072 | proc codec_io_r16 |
||
1073 | add edx, [ctrl.codec_io_base] |
||
1074 | in ax, dx |
||
1075 | ret |
||
1076 | endp |
||
1077 | |||
1078 | |||
1079 | proc codec_io_w16 |
||
1080 | add edx, [ctrl.codec_io_base] |
||
1081 | out dx, ax |
||
1082 | ret |
||
1083 | endp |
||
1084 | |||
1085 | |||
1086 | proc ctrl_io_r8 |
||
1087 | add edx, [ctrl.ctrl_io_base] |
||
1088 | in al, dx |
||
1089 | ret |
||
1090 | endp |
||
1091 | |||
1092 | |||
1093 | proc ctrl_io_r16 |
||
1094 | add edx, [ctrl.ctrl_io_base] |
||
1095 | in ax, dx |
||
1096 | ret |
||
1097 | endp |
||
1098 | |||
1099 | |||
1100 | proc ctrl_io_r32 |
||
1101 | add edx, [ctrl.ctrl_io_base] |
||
1102 | in eax, dx |
||
1103 | ret |
||
1104 | endp |
||
1105 | |||
1106 | |||
1107 | proc ctrl_io_w8 |
||
1108 | add edx, [ctrl.ctrl_io_base] |
||
1109 | out dx, al |
||
1110 | ret |
||
1111 | endp |
||
1112 | |||
1113 | |||
1114 | proc ctrl_io_w16 |
||
1115 | add edx, [ctrl.ctrl_io_base] |
||
1116 | out dx, ax |
||
1117 | ret |
||
1118 | endp |
||
1119 | |||
1120 | |||
1121 | proc ctrl_io_w32 |
||
1122 | add edx, [ctrl.ctrl_io_base] |
||
1123 | out dx, eax |
||
1124 | ret |
||
1125 | endp |
||
1126 | |||
1127 | |||
1128 | |||
1129 | |||
188 | serge | 1130 | devices dd (CTRL_SIS shl 16)+VID_SIS,msg_AC, set_SIS |
168 | serge | 1131 | dd 0 |
1132 | |||
1133 | |||
1134 | msg_SIS db 'Silicon Integrated Systems',13,10, 0 |
||
1135 | |||
1136 | |||
1137 | |||
1138 | |||
1139 | msgFail db 'device not found',13,10,0 |
||
1140 | msgPlay db 'start play', 13,10,0 |
||
1141 | msgStop db 'stop play', 13,10,0 |
||
1142 | msgNotify db 'call notify',13,10,0 |
||
1143 | msgIRQ db 'AC97 IRQ', 13,10,0 |
||
1144 | msgInitCtrl db 'init controller',13,10,0 |
||
1145 | msgInitCodec db 'init codec',13,10,0 |
||
1146 | msgPrimBuff db 'create primary buffer',13,10,0 |
||
1147 | msgReg db 'set service handler',13,10,0 |
||
1148 | msgOk db 'service installed',13,10,0 |
||
1149 | msgCold db 'cold resret',13,10,0 |
||
1150 | msgWarm db 'warm reset',13,10,0 |
||
1151 | msgWRFail db 'warm reset failed',13,10,0 |
||
1152 | msgCRFail db 'cold reset failed',13,10,0 |
||
1153 | msgCFail db 'codec not ready',13,10,0 |
||
1154 | |||
188 | serge | 1155 | |
1156 | |||
1157 | |||
1158 | buff_list rd 32 |
||
1159 | |||
1160 | |||
1161 | ctrl AC_CNTRL |
||
1162 | |||
1163 | |||
1164 | civ_val rd 1 |
||
1165 |