Subversion Repositories Kolibri OS

Rev

Rev 188 | 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 [ctrl.user_callback], 0
337
           ret
338
endp
339
168 serge 340
 
341
io_code    equ  IOCTL.io_code
342
input      equ  IOCTL.input
343
inp_size   equ  IOCTL.inp_size
344
output     equ  IOCTL.output
345
out_size   equ  IOCTL.out_size
346
347
 
348
proc service_proc stdcall, ioctl:dword
349
350
 
351
           mov eax, [edi+io_code]
352
	   cmp eax, DEV_PLAY
353
	   jne @F
354
     if DEBUG
355
	   mov esi, msgPlay
356
           call SysMsgBoardStr
188 serge 357
     end if
168 serge 358
	   call play
359
	   ret
360
@@:
361
	   cmp eax, DEV_STOP
362
	   jne @F
363
     if DEBUG
364
	   mov esi, msgStop
365
           call SysMsgBoardStr
188 serge 366
     end if
168 serge 367
	   call stop
368
	   ret
369
@@:
370
	   cmp eax, DEV_CALLBACK
371
	   jne @F
372
           mov ebx, [edi+input]
373
           stdcall set_callback, [ebx]
374
	   ret
375
@@:
376
	   cmp eax, DEV_SET_MASTERVOL
377
	   jne @F
378
           mov ebx, [edi+input]
379
           stdcall set_master_vol, [ebx]
380
	   ret
381
@@:
382
	   cmp eax, DEV_GET_MASTERVOL
383
	   jne @F
384
           mov ebx, [edi+output]
385
           test ebx, ebx
386
           jz .fail
387
388
 
389
	   ret
390
@@:
391
	   cmp eax, DEV_GET_INFO
392
	   jne @F
393
           mov ebx, [edi+output]
394
	   stdcall get_dev_info, ebx
395
	   ret
396
@@:
397
.fail:
398
	   xor eax, eax
399
	   ret
400
endp
401
402
 
403
restore   io_code
404
restore   input
405
restore   inp_size
406
restore   output
407
restore   out_size
408
409
 
410
proc ac97_irq
411
412
 
413
;           mov esi, msgIRQ
414
;           call SysMsgBoardStr
188 serge 415
;     end if
168 serge 416
417
 
418
	   mov al, 0x14
419
	   call [ctrl.ctrl_write8]
420
421
 
422
	   mov edx, PCM_OUT_SR_REG
423
	   call [ctrl.ctrl_write16]
424
425
 
426
	   call [ctrl.ctrl_read8]
427
428
 
429
           cmp eax, [civ_val]
430
           je .skip
431
432
 
433
	   dec eax
434
	   and eax, 0x1F
435
	   mov [ctrl.lvi_reg], eax
436
437
 
438
	   call [ctrl.ctrl_write8]
439
440
 
441
	   mov ax, 0x1D
442
	   call [ctrl.ctrl_write8]
443
444
 
445
           add eax, 2
446
	   and eax, 31
447
	   mov ebx, dword [buff_list+eax*4]
448
449
 
450
	   je @f
451
452
 
453
@@:
454
	   ret
455
456
 
457
	   mov edx, PCM_OUT_CR_REG
458
	   mov ax, 0x1D
459
	   call [ctrl.ctrl_write8]
460
           ret
461
endp
462
463
 
464
proc create_primary_buff
465
466
 
188 serge 467
	   mov [ctrl.buffer], eax
168 serge 468
469
 
470
           mov ecx, 0x10000/4
471
           xor eax, eax
472
           rep stosd
473
474
 
188 serge 475
168 serge 476
 
477
	   mov ecx, 4
478
	   mov edi, pcmout_bdl
479
@@:
480
	   mov [edi], eax
481
	   mov [edi+4], ebx
482
483
 
484
	   mov [edi+4+32], ebx
485
486
 
487
	   mov [edi+4+64], ebx
488
489
 
490
	   mov [edi+4+96], ebx
491
492
 
493
	   mov [edi+4+128], ebx
494
495
 
496
	   mov [edi+4+160], ebx
497
498
 
499
	   mov [edi+4+192], ebx
500
501
 
502
	   mov [edi+4+224], ebx
503
504
 
505
	   add edi, 8
506
	   loop @B
507
508
 
509
	   mov eax, [ctrl.buffer]
510
	   mov ecx, 4
511
@@:
512
	   mov [edi], eax
513
	   mov [edi+16], eax
514
	   mov [edi+32], eax
515
	   mov [edi+48], eax
516
	   mov [edi+64], eax
517
	   mov [edi+80], eax
518
	   mov [edi+96], eax
519
	   mov [edi+112], eax
520
521
 
522
	   add edi, 4
523
	   loop @B
524
525
 
526
           stdcall GetPgAddr, ecx
188 serge 527
	   and ecx, 0xFFF
168 serge 528
	   add eax, ecx
529
530
 
531
	   call [ctrl.ctrl_write32]
532
533
 
534
	   mov [ctrl.lvi_reg], eax
535
	   mov edx, PCM_OUT_LVI_REG
536
	   call [ctrl.ctrl_write8]
537
538
 
539
           call [ctrl.ctrl_read32]
540
           and eax, not 0x000000C0
541
           mov edx, GLOB_CTRL
542
           call [ctrl.ctrl_write32]
543
544
 
545
 
546
endp
547
548
 
549
proc detect_controller
550
	   locals
551
	     last_bus dd ?
552
	     bus      dd ?
553
	     devfn    dd ?
554
	   endl
555
556
 
557
	   mov [bus], eax
558
	   inc eax
559
           call PciApi
188 serge 560
	   cmp eax, -1
168 serge 561
	   je .err
562
563
 
564
565
 
566
	   and [devfn], 0
567
.next_dev:
568
           stdcall PciRead32, [bus], [devfn], dword 0
188 serge 569
	   test eax, eax
168 serge 570
	   jz .next
571
	   cmp eax, -1
572
	   je .next
573
574
 
575
@@:
576
	   mov ebx, [edi]
577
	   test ebx, ebx
578
	   jz .next
579
580
 
581
	   je .found
582
	   add edi, 12
583
	   jmp @B
584
585
 
586
	   cmp [devfn], 256
587
	   jb  .next_dev
588
	   mov eax, [bus]
589
	   inc eax
590
	   mov [bus], eax
591
	   cmp eax, [last_bus]
592
	   jna .next_bus
593
	   xor eax, eax
594
	   ret
595
.found:
596
	   mov ebx, [bus]
597
	   mov [ctrl.bus], ebx
598
599
 
600
	   mov [ctrl.devfn], ecx
601
602
 
603
	   and edx, 0xFFFF
604
	   mov [ctrl.vendor], edx
605
	   shr eax, 16
606
	   mov [ctrl.dev_id], eax
607
608
 
609
	   mov [ctrl.ctrl_ids], ebx
610
	   mov [ctrl.vendor_ids], msg_SIS
611
612
 
613
	   mov [ctrl.ctrl_setup], esi
614
615
 
616
.err:
617
	   xor eax, eax
618
	   ret
619
endp
620
621
 
622
proc init_controller
623
624
 
188 serge 625
	   mov ebx, eax
168 serge 626
	   and eax, 0xFFFF
627
	   mov [ctrl.pci_cmd], eax
628
	   shr ebx, 16
629
	   mov [ctrl.pci_stat], ebx
630
631
 
188 serge 632
	   and eax,0xFFFE
168 serge 633
	   mov [ctrl.codec_io_base], eax
634
635
 
188 serge 636
	   and eax, 0xFFC0
168 serge 637
	   mov [ctrl.ctrl_io_base], eax
638
639
 
188 serge 640
	   mov [ctrl.codec_mem_base], eax
168 serge 641
642
 
188 serge 643
	   mov [ctrl.ctrl_mem_base], eax
168 serge 644
645
 
188 serge 646
	   and eax, 0xFF
168 serge 647
	   mov [ctrl.int_line], eax
648
649
 
188 serge 650
	   and eax, 0xFF
168 serge 651
	   mov [ctrl.cfg_reg], eax
652
653
 
654
	   xor eax, eax
655
	   inc eax
656
	   ret
657
endp
658
659
 
660
proc set_SIS
661
	   mov [ctrl.codec_read16],  codec_io_r16    ;virtual
662
	   mov [ctrl.codec_write16], codec_io_w16    ;virtual
663
664
 
665
	   mov [ctrl.ctrl_read16],  ctrl_io_r16      ;virtual
666
	   mov [ctrl.ctrl_read32],  ctrl_io_r32      ;virtual
667
668
 
669
	   mov [ctrl.ctrl_write16], ctrl_io_w16      ;virtual
670
	   mov [ctrl.ctrl_write32], ctrl_io_w32      ;virtual
671
	   ret
672
endp
673
674
 
675
proc reset_controller
676
677
 
678
	   mov edx, PCM_IN_CR_REG
679
	   call [ctrl.ctrl_write8]
680
681
 
682
	   call [ctrl.ctrl_write8]
683
684
 
685
	   call [ctrl.ctrl_write8]
686
687
 
688
	   mov edx, PCM_IN_CR_REG
689
	   call [ctrl.ctrl_write8]
690
691
 
692
	   call [ctrl.ctrl_write8]
693
694
 
695
	   call [ctrl.ctrl_write8]
696
697
 
698
 
699
endp
700
701
 
702
proc init_codec
703
	   locals
704
	     counter dd ?
705
	   endl
706
707
 
708
	   and eax, eax
709
	   jz .err
710
711
 
712
	   call [ctrl.codec_write16]
713
714
 
715
	   mov edx, CODEC_REG_POWERDOWN
716
	   call [ctrl.codec_write16]
717
718
 
719
.wait:
720
	   mov edx, CODEC_REG_POWERDOWN
721
	   call [ctrl.codec_read16]
722
	   and eax, 0x0F
723
	   cmp eax, 0x0F
724
	   jz .ready
725
726
 
727
	   call StallExec
728
	   sub [counter] , 1
729
	   jnz .wait
730
.err:
731
	   xor eax, eax        ; timeout error
732
	   ret
733
.ready:
734
	   call detect_codec
735
736
 
737
	   inc eax
738
	   ret
739
endp
740
741
 
742
proc reset_codec
743
	   mov edx, GLOB_CTRL
744
	   call [ctrl.ctrl_read32]
745
746
 
747
           jz .cold
748
749
 
750
           jnc .ok
751
.cold:
752
	   call cold_reset
753
	   jnc .ok
754
755
 
756
	   mov esi, msgCFail
757
           call SysMsgBoardStr
188 serge 758
     end if
168 serge 759
	   xor eax, eax 	   ; timeout error
760
	   ret
761
.ok:
762
           xor eax, eax
763
	   inc eax
764
	   ret
765
endp
766
767
 
768
proc warm_reset
769
	   locals
770
	     counter dd ?
771
	   endl
772
773
 
774
	   mov edx, GLOB_CTRL
775
	   call [ctrl.ctrl_write32]
776
777
 
778
	   mov esi, msgWarm
779
           call SysMsgBoardStr
188 serge 780
     end if
168 serge 781
782
 
783
.wait:
784
	   mov eax, 100000	   ; wait 100 ms
785
	   call StallExec
786
787
 
788
	   call [ctrl.ctrl_read32]
789
	   test eax, 4
790
	   jz .ok
791
	   sub [counter], 1
792
	   jnz .wait
793
794
 
795
	   mov esi, msgWRFail
796
           call SysMsgBoardStr
188 serge 797
     end if
168 serge 798
799
 
800
	   ret
801
.ok:
802
	   mov edx, CTRL_STAT
803
	   call [ctrl.ctrl_read32]
804
	   and eax, CTRL_ST_CREADY
805
           jz .fail
806
           clc
807
	   ret
808
.fail:
809
           stc
810
	   ret
811
endp
812
813
 
814
proc cold_reset
815
	   locals
816
	     counter dd ?
817
	   endl
818
819
 
820
	   mov edx, GLOB_CTRL
821
	   call [ctrl.ctrl_write32]
822
823
 
824
	   mov esi, msgCold
825
           call SysMsgBoardStr
188 serge 826
     end if
168 serge 827
828
 
829
	   call StallExec
830
831
 
832
	   mov edx, GLOB_CTRL
833
	   call [ctrl.ctrl_write32]
834
835
 
836
.wait:
837
	   mov eax, 100000	   ; wait 100 ms
838
	   call StallExec
839
840
 
841
	   call [ctrl.ctrl_read32]
842
	   test eax, 4
843
	   jz .ok
844
	   sub [counter], 1
845
	   jnz .wait
846
847
 
848
	   mov esi, msgCRFail
849
           call SysMsgBoardStr
188 serge 850
     end if
168 serge 851
	   stc
852
	   ret
853
.ok:
854
	   mov edx, CTRL_STAT
855
	   call [ctrl.ctrl_read32]
856
	   and eax, CTRL_ST_CREADY
857
           jz .fail
858
           clc
859
	   ret
860
.fail:
861
           stc
862
	   ret
863
endp
864
865
 
866
proc play
867
           xor eax, eax
868
           mov [civ_val], eax
869
           mov edx, PCM_OUT_CIV_REG
870
	   call [ctrl.ctrl_write8]
871
872
 
873
	   mov [ctrl.lvi_reg], eax
874
	   mov edx, PCM_OUT_LVI_REG
875
	   call [ctrl.ctrl_write8]
876
877
 
878
	   mov ax, 0x1D
879
	   call [ctrl.ctrl_write8]
880
	   ret
881
endp
882
883
 
884
proc stop
885
	   mov edx, PCM_OUT_CR_REG
886
	   mov ax, 0x14
887
	   call [ctrl.ctrl_write8]
888
889
 
890
	   mov [ctrl.lvi_reg], eax
891
	   mov edx, PCM_OUT_LVI_REG
892
	   call [ctrl.ctrl_write8]
893
894
 
895
endp
896
897
 
898
proc get_dev_info stdcall, p_info:dword
899
           virtual at esi
900
             CTRL_INFO CTRL_INFO
901
           end virtual
902
903
 
904
           mov eax, [ctrl.int_line]
905
           mov ebx, [ctrl.codec_io_base]
906
           mov ecx, [ctrl.ctrl_io_base]
907
           mov edx, [ctrl.codec_mem_base]
908
           mov edi, [ctrl.ctrl_mem_base]
909
910
 
911
           mov [CTRL_INFO.codec_io_base], ebx
912
           mov [CTRL_INFO.ctrl_io_base], ecx
913
           mov [CTRL_INFO.codec_mem_base], edx
914
           mov [CTRL_INFO.ctrl_mem_base], edi
915
916
 
917
           mov [CTRL_INFO.codec_id], eax
918
919
 
920
           call [ctrl.ctrl_read32]
921
           mov [CTRL_INFO.glob_cntrl], eax
922
923
 
924
           call [ctrl.ctrl_read32]
925
           mov [CTRL_INFO.glob_sta], eax
926
927
 
928
           mov [CTRL_INFO.pci_cmd], ebx
929
930
 
931
endp
932
933
 
934
proc set_callback stdcall, handler:dword
935
	   mov eax, [handler]
936
	   mov [ctrl.user_callback], eax
937
	   ret
938
endp
939
940
 
941
proc codec_read stdcall, ac_reg:dword	   ; reg = edx, reval = eax
942
943
 
944
945
 
946
	   shr ebx, 1
947
	   bt [codec.shadow_flag], ebx
948
	   jc .use_shadow
949
950
 
951
	   mov ecx, eax
952
953
 
954
	   call [ctrl.ctrl_read32]
955
	   test eax, CTRL_ST_RCS
956
	   jz .read_ok
957
958
 
959
	   call [ctrl.ctrl_write32]
960
	   xor eax,eax
961
	   not eax		;timeout
962
	   ret
963
.read_ok:
964
	   mov edx, [ac_reg]
965
	   mov [codec.regs+edx], cx
966
	   bts [codec.shadow_flag], ebx
967
	   mov eax, ecx
968
	   ret
969
.use_shadow:
970
	   movzx eax, word [codec.regs+edx]
971
	   ret
972
endp
973
974
 
975
proc codec_write stdcall, ac_reg:dword
976
	   push eax
977
	   call check_semafore
978
	   and eax, eax
979
	   jz .err
980
	   pop eax
981
982
 
983
	   mov edx, esi
984
	   call [ctrl.codec_write16]
985
	   mov [codec.regs+esi], ax
986
	   shr esi, 1
987
	   bts [codec.shadow_flag], esi
988
	   ret
989
.err:
990
	   pop eax
991
	   ret
992
endp
993
994
 
995
 
996
proc codec_check_ready
997
998
 
999
	  call [ctrl.ctrl_read32]
1000
	  and eax, CTRL_ST_CREADY
1001
	  jz .not_ready
1002
1003
 
1004
	  inc eax
1005
	  ret
1006
1007
 
1008
.not_ready:
1009
	  xor eax, eax
1010
	  ret
1011
endp
1012
1013
 
1014
 
1015
proc check_semafore
1016
	   local counter:DWORD
1017
1018
 
1019
.l1:
1020
	   mov edx, CTRL_CAS
1021
	   call [ctrl.ctrl_read8]
1022
	   and eax, CAS_FLAG
1023
	   jz .ok
1024
1025
 
1026
	   call StallExec
1027
	   sub [counter], 1
1028
	   jnz .l1
1029
	   xor eax, eax
1030
	   ret
1031
align 4
1032
.ok:
1033
	   xor eax,eax
1034
	   inc eax
1035
	   ret
1036
endp
1037
1038
 
1039
proc StallExec
1040
	   push ecx
1041
	   push edx
1042
	   push ebx
1043
	   push eax
1044
1045
 
1046
	   mul ecx
1047
	   mov ebx, eax       ;low
1048
	   mov ecx, edx       ;high
1049
	   rdtsc
1050
	   add ebx, eax
1051
	   adc ecx,edx
1052
@@:
1053
	   rdtsc
1054
	   sub eax, ebx
1055
	   sbb edx, ecx
1056
	   jb @B
1057
1058
 
1059
	   pop ebx
1060
	   pop edx
1061
	   pop ecx
1062
	   ret
1063
endp
1064
1065
 
1066
;          CONTROLLER IO functions
1067
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1068
1069
 
1070
proc codec_io_r16
1071
	add edx, [ctrl.codec_io_base]
1072
	in  ax, dx
1073
	ret
1074
endp
1075
1076
 
1077
proc codec_io_w16
1078
	add edx, [ctrl.codec_io_base]
1079
	out dx, ax
1080
	ret
1081
endp
1082
1083
 
1084
proc ctrl_io_r8
1085
	add edx, [ctrl.ctrl_io_base]
1086
	in  al, dx
1087
	ret
1088
endp
1089
1090
 
1091
proc ctrl_io_r16
1092
	add edx, [ctrl.ctrl_io_base]
1093
	in  ax, dx
1094
	ret
1095
endp
1096
1097
 
1098
proc ctrl_io_r32
1099
	add edx, [ctrl.ctrl_io_base]
1100
	in  eax, dx
1101
	ret
1102
endp
1103
1104
 
1105
proc ctrl_io_w8
1106
	add edx, [ctrl.ctrl_io_base]
1107
	out dx, al
1108
	ret
1109
endp
1110
1111
 
1112
proc ctrl_io_w16
1113
	add edx, [ctrl.ctrl_io_base]
1114
	out dx, ax
1115
	ret
1116
endp
1117
1118
 
1119
proc ctrl_io_w32
1120
	add edx, [ctrl.ctrl_io_base]
1121
	out dx, eax
1122
	ret
1123
endp
1124
1125
 
1126
1127
 
188 serge 1128
devices dd (CTRL_SIS  shl 16)+VID_SIS,msg_AC, set_SIS
168 serge 1129
	dd 0
1130
1131
 
1132
msg_SIS   db 'Silicon Integrated Systems',13,10, 0
1133
1134
 
1135
1136
 
1137
msgFail      db 'device not found',13,10,0
1138
msgPlay      db 'start play', 13,10,0
1139
msgStop      db 'stop play',  13,10,0
1140
msgNotify    db 'call notify',13,10,0
1141
msgIRQ	     db 'AC97 IRQ', 13,10,0
1142
msgInitCtrl  db 'init controller',13,10,0
1143
msgInitCodec db 'init codec',13,10,0
1144
msgPrimBuff  db 'create primary buffer',13,10,0
1145
msgReg       db 'set service handler',13,10,0
1146
msgOk        db 'service installed',13,10,0
1147
msgCold      db 'cold resret',13,10,0
1148
msgWarm      db 'warm reset',13,10,0
1149
msgWRFail    db 'warm reset failed',13,10,0
1150
msgCRFail    db 'cold reset failed',13,10,0
1151
msgCFail     db 'codec not ready',13,10,0
1152
188 serge 1153
 
1154
1155
 
1156
buff_list        rd 32
1157
1158
 
1159
ctrl AC_CNTRL
1160
1161
 
1162
civ_val  rd 1
1163