Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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