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