Rev 2434 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2130 | serge | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
2465 | Serge | 3 | ;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;; |
2130 | serge | 4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
||
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
7 | |||
8 | format MS COFF |
||
9 | |||
2434 | Serge | 10 | DEBUG equ 1 |
2130 | serge | 11 | |
12 | include 'proc32.inc' |
||
13 | include 'imports.inc' |
||
14 | |||
2434 | Serge | 15 | API_VERSION equ 0x01000100 |
2130 | serge | 16 | |
2434 | Serge | 17 | USE_COM_IRQ equ 0 ;make irq 3 and irq 4 available for PCI devices |
18 | IRQ_REMAP equ 0 |
||
19 | IRQ_LINE equ 0 |
||
2130 | serge | 20 | |
21 | |||
22 | ;irq 0,1,2,8,12,13 недоступны |
||
23 | ; FEDCBA9876543210 |
||
2434 | Serge | 24 | VALID_IRQ equ 1100111011111000b |
25 | ATTCH_IRQ equ 0000111010100000b |
||
2130 | serge | 26 | |
27 | if USE_COM_IRQ |
||
2434 | Serge | 28 | ATTCH_IRQ equ 0000111010111000b |
2130 | serge | 29 | end if |
30 | |||
2434 | Serge | 31 | CPU_FREQ equ 2600d |
2130 | serge | 32 | |
33 | BIT0 EQU 0x00000001 |
||
34 | BIT1 EQU 0x00000002 |
||
35 | BIT5 EQU 0x00000020 |
||
36 | BIT10 EQU 0x00000400 |
||
37 | |||
2434 | Serge | 38 | VID_VIA equ 0x1106 |
2130 | serge | 39 | |
2434 | Serge | 40 | CTRL_VT82C686 equ 0x3058 |
41 | CTRL_VT8233_5 equ 0x3059 |
||
2130 | serge | 42 | |
43 | |||
2434 | Serge | 44 | CODEC_MASTER_VOL_REG equ 0x02 |
45 | CODEC_AUX_VOL equ 0x04 ; |
||
46 | CODEC_PCM_OUT_REG equ 0x18 ; PCM output volume |
||
47 | CODEC_EXT_AUDIO_REG equ 0x28 ; extended audio |
||
2130 | serge | 48 | CODEC_EXT_AUDIO_CTRL_REG equ 0x2a ; extended audio control |
49 | CODEC_PCM_FRONT_DACRATE_REG equ 0x2c ; PCM out sample rate |
||
50 | CODEC_PCM_SURND_DACRATE_REG equ 0x2e ; surround sound sample rate |
||
51 | CODEC_PCM_LFE_DACRATE_REG equ 0x30 ; LFE sample rate |
||
52 | |||
53 | |||
54 | ;VIA host controller registers set |
||
55 | ;; common offsets |
||
2434 | Serge | 56 | VIA_REG_OFFSET_STATUS equ 0x00 ;; byte - channel status |
57 | VIA_REG_STAT_ACTIVE equ 0x80 ;; RO |
||
58 | VIA_REG_STAT_PAUSED equ 0x40 ;; RO |
||
59 | VIA_REG_STAT_TRIGGER_QUEUED equ 0x08 ;; RO |
||
60 | VIA_REG_STAT_STOPPED equ 0x04 ;; RWC |
||
61 | VIA_REG_STAT_EOL equ 0x02 ;; RWC |
||
62 | VIA_REG_STAT_FLAG equ 0x01 ;; RWC |
||
63 | VIA_REG_OFFSET_CONTROL equ 0x01 ;; byte - channel control |
||
64 | VIA_REG_CTRL_START equ 0x80 ;; WO |
||
65 | VIA_REG_CTRL_TERMINATE equ 0x40 ;; WO |
||
66 | VIA_REG_CTRL_AUTOSTART equ 0x20 |
||
67 | VIA_REG_CTRL_PAUSE equ 0x08 ;; RW |
||
68 | VIA_REG_CTRL_INT_STOP equ 0x04 |
||
69 | VIA_REG_CTRL_INT_EOL equ 0x02 |
||
70 | VIA_REG_CTRL_INT_FLAG equ 0x01 |
||
71 | VIA_REG_CTRL_RESET equ 0x01 ;; RW - probably reset? undocumented |
||
72 | VIA_REG_CTRL_INT equ (VIA_REG_CTRL_INT_FLAG or \ |
||
73 | VIA_REG_CTRL_INT_EOL or \ |
||
74 | VIA_REG_CTRL_AUTOSTART) |
||
75 | VIA_REG_OFFSET_TYPE equ 0x02 ;; byte - channel type (686 only) |
||
76 | VIA_REG_TYPE_AUTOSTART equ 0x80 ;; RW - autostart at EOL |
||
77 | VIA_REG_TYPE_16BIT equ 0x20 ;; RW |
||
78 | VIA_REG_TYPE_STEREO equ 0x10 ;; RW |
||
79 | VIA_REG_TYPE_INT_LLINE equ 0x00 |
||
80 | VIA_REG_TYPE_INT_LSAMPLE equ 0x04 |
||
81 | VIA_REG_TYPE_INT_LESSONE equ 0x08 |
||
82 | VIA_REG_TYPE_INT_MASK equ 0x0c |
||
83 | VIA_REG_TYPE_INT_EOL equ 0x02 |
||
84 | VIA_REG_TYPE_INT_FLAG equ 0x01 |
||
2130 | serge | 85 | VIA_REG_OFFSET_TABLE_PTR equ 0x04 ;; dword - channel table pointer |
86 | VIA_REG_OFFSET_CURR_PTR equ 0x04 ;; dword - channel current pointer |
||
87 | VIA_REG_OFFSET_STOP_IDX equ 0x08 ;; dword - stop index, channel type, sample rate |
||
2434 | Serge | 88 | VIA8233_REG_TYPE_16BIT equ 0x00200000 ;; RW |
89 | VIA8233_REG_TYPE_STEREO equ 0x00100000 ;; RW |
||
2130 | serge | 90 | VIA_REG_OFFSET_CURR_COUNT equ 0x0c ;; dword - channel current count (24 bit) |
91 | VIA_REG_OFFSET_CURR_INDEX equ 0x0f ;; byte - channel current index (for via8233 only) |
||
92 | |||
93 | |||
2434 | Serge | 94 | VIADEV_PLAYBACK equ 0x00 |
95 | VIADEV_CAPTURE equ 0x10 |
||
96 | VIADEV_FM equ 0x20 |
||
2130 | serge | 97 | |
98 | ;; AC'97 ;; |
||
2434 | Serge | 99 | VIA_REG_AC97 equ 0x80 ; dword |
100 | VIA_REG_AC97_CODEC_ID_MASK equ 0xC0000000 ;(3<<30) |
||
101 | VIA_REG_AC97_CODEC_ID_SHIFT equ 30 |
||
102 | VIA_REG_AC97_CODEC_ID_PRIMARY equ 0x00 |
||
103 | VIA_REG_AC97_CODEC_ID_SECONDARY equ 0x01 |
||
104 | VIA_REG_AC97_SECONDARY_VALID equ 0x08000000 ;(1<<27) |
||
105 | VIA_REG_AC97_PRIMARY_VALID equ 0x02000000 ;(1<<25) |
||
106 | VIA_REG_AC97_BUSY equ 0x01000000 ;(1<<24) |
||
107 | VIA_REG_AC97_READ equ 0x00800000 ;(1<<23) |
||
108 | VIA_REG_AC97_CMD_SHIFT equ 16 |
||
109 | VIA_REG_AC97_CMD_MASK equ 0x7E |
||
110 | VIA_REG_AC97_DATA_SHIFT equ 0 |
||
111 | VIA_REG_AC97_DATA_MASK equ 0xFFFF |
||
2130 | serge | 112 | |
2434 | Serge | 113 | VIA_REG_SGD_SHADOW equ 0x84 ; dword |
2130 | serge | 114 | |
115 | ;; via8233-specific registers ;; |
||
2434 | Serge | 116 | VIA_REG_OFS_PLAYBACK_VOLUME_L equ 0x02 ;; byte |
117 | VIA_REG_OFS_PLAYBACK_VOLUME_R equ 0x03 ;; byte |
||
118 | VIA_REG_OFS_MULTPLAY_FORMAT equ 0x02 ;; byte - format and channels |
||
119 | VIA_REG_MULTPLAY_FMT_8BIT equ 0x00 |
||
120 | VIA_REG_MULTPLAY_FMT_16BIT equ 0x80 |
||
121 | VIA_REG_MULTPLAY_FMT_CH_MASK equ 0x70 ;; # channels << 4 (valid = 1,2,4,6) |
||
122 | VIA_REG_OFS_CAPTURE_FIFO equ 0x02 ;; byte - bit 6 = fifo enable |
||
123 | VIA_REG_CAPTURE_FIFO_ENABLE equ 0x40 |
||
2130 | serge | 124 | |
2434 | Serge | 125 | VIA_DXS_MAX_VOLUME equ 31 ;; max. volume (attenuation) of reg 0x32/33 |
2130 | serge | 126 | |
2434 | Serge | 127 | VIA_TBL_BIT_FLAG equ 0x40000000 |
128 | VIA_TBL_BIT_EOL equ 0x80000000 |
||
2130 | serge | 129 | |
130 | ;; pci space ;; |
||
2434 | Serge | 131 | VIA_ACLINK_STAT equ 0x40 |
2130 | serge | 132 | ;... |
2434 | Serge | 133 | VIA_ACLINK_C00_READY equ 0x01 ; primary codec ready |
134 | VIA_ACLINK_CTRL equ 0x41 |
||
135 | VIA_ACLINK_CTRL_ENABLE equ 0x80 ; 0: disable, 1: enable |
||
136 | VIA_ACLINK_CTRL_RESET equ 0x40 ; 0: assert, 1: de-assert |
||
137 | VIA_ACLINK_CTRL_SYNC equ 0x20 ; 0: release SYNC, 1: force SYNC hi |
||
138 | VIA_ACLINK_CTRL_SDO equ 0x10 ; 0: release SDO, 1: force SDO hi |
||
139 | VIA_ACLINK_CTRL_VRA equ 0x08 ; 0: disable VRA, 1: enable VRA |
||
140 | VIA_ACLINK_CTRL_PCM equ 0x04 ; 0: disable PCM, 1: enable PCM |
||
141 | VIA_ACLINK_CTRL_FM equ 0x02 ; via686 only |
||
142 | VIA_ACLINK_CTRL_SB equ 0x01 ; via686 only |
||
143 | VIA_ACLINK_CTRL_INIT equ (VIA_ACLINK_CTRL_ENABLE or \ |
||
144 | VIA_ACLINK_CTRL_RESET or \ |
||
145 | VIA_ACLINK_CTRL_PCM or \ |
||
146 | VIA_ACLINK_CTRL_VRA) |
||
147 | VIA_FUNC_ENABLE equ 0x42 |
||
148 | VIA_FUNC_MIDI_PNP equ 0x80 ; FIXME: it's 0x40 in the datasheet! |
||
149 | VIA_FUNC_MIDI_IRQMASK equ 0x40 ; FIXME: not documented! |
||
150 | VIA_FUNC_RX2C_WRITE equ 0x20 |
||
151 | VIA_FUNC_SB_FIFO_EMPTY equ 0x10 |
||
152 | VIA_FUNC_ENABLE_GAME equ 0x08 |
||
153 | VIA_FUNC_ENABLE_FM equ 0x04 |
||
154 | VIA_FUNC_ENABLE_MIDI equ 0x02 |
||
155 | VIA_FUNC_ENABLE_SB equ 0x01 |
||
156 | VIA_PNP_CONTROL equ 0x43 |
||
157 | VIA_FM_NMI_CTRL equ 0x48 |
||
158 | VIA8233_VOLCHG_CTRL equ 0x48 |
||
159 | VIA8233_SPDIF_CTRL equ 0x49 |
||
160 | VIA8233_SPDIF_DX3 equ 0x08 |
||
161 | VIA8233_SPDIF_SLOT_MASK equ 0x03 |
||
162 | VIA8233_SPDIF_SLOT_1011 equ 0x00 |
||
163 | VIA8233_SPDIF_SLOT_34 equ 0x01 |
||
164 | VIA8233_SPDIF_SLOT_78 equ 0x02 |
||
165 | VIA8233_SPDIF_SLOT_69 equ 0x03 |
||
2130 | serge | 166 | ;] Asper |
167 | |||
168 | |||
2434 | Serge | 169 | SRV_GETVERSION equ 0 |
170 | DEV_PLAY equ 1 |
||
171 | DEV_STOP equ 2 |
||
172 | DEV_CALLBACK equ 3 |
||
173 | DEV_SET_BUFF equ 4 |
||
174 | DEV_NOTIFY equ 5 |
||
2130 | serge | 175 | DEV_SET_MASTERVOL equ 6 |
176 | DEV_GET_MASTERVOL equ 7 |
||
2434 | Serge | 177 | DEV_GET_INFO equ 8 |
2130 | serge | 178 | |
2434 | Serge | 179 | struc AC_CNTRL ;AC controller base class |
180 | { .bus dd ? |
||
181 | .devfn dd ? |
||
2130 | serge | 182 | |
2434 | Serge | 183 | .vendor dd ? |
184 | .dev_id dd ? |
||
185 | .pci_cmd dd ? |
||
186 | .pci_stat dd ? |
||
2130 | serge | 187 | |
188 | .codec_io_base dd ? |
||
189 | .codec_mem_base dd ? |
||
190 | |||
191 | .ctrl_io_base dd ? |
||
192 | .ctrl_mem_base dd ? |
||
2434 | Serge | 193 | .cfg_reg dd ? |
194 | .int_line dd ? |
||
2130 | serge | 195 | |
2434 | Serge | 196 | .vendor_ids dd ? ;vendor id string |
197 | .ctrl_ids dd ? ;hub id string |
||
2130 | serge | 198 | |
2434 | Serge | 199 | .buffer dd ? |
2130 | serge | 200 | |
2434 | Serge | 201 | .notify_pos dd ? |
202 | .notify_task dd ? |
||
2130 | serge | 203 | |
2434 | Serge | 204 | .lvi_reg dd ? |
205 | .ctrl_setup dd ? |
||
2130 | serge | 206 | .user_callback dd ? |
207 | .codec_read16 dd ? |
||
208 | .codec_write16 dd ? |
||
209 | |||
2434 | Serge | 210 | .ctrl_read8 dd ? |
211 | .ctrl_read16 dd ? |
||
212 | .ctrl_read32 dd ? |
||
2130 | serge | 213 | |
2434 | Serge | 214 | .ctrl_write8 dd ? |
2130 | serge | 215 | .ctrl_write16 dd ? |
216 | .ctrl_write32 dd ? |
||
217 | } |
||
218 | |||
2434 | Serge | 219 | struc CODEC ;Audio Chip base class |
2130 | serge | 220 | { |
2434 | Serge | 221 | .chip_id dd ? |
222 | .flags dd ? |
||
223 | .status dd ? |
||
2130 | serge | 224 | |
225 | .ac_vendor_ids dd ? ;ac vendor id string |
||
2434 | Serge | 226 | .chip_ids dd ? ;chip model string |
2130 | serge | 227 | |
2434 | Serge | 228 | .shadow_flag dd ? |
229 | dd ? |
||
2130 | serge | 230 | |
2434 | Serge | 231 | .regs dw ? ; codec registers |
2130 | serge | 232 | .reg_master_vol dw ? ;0x02 |
233 | .reg_aux_out_vol dw ? ;0x04 |
||
234 | .reg_mone_vol dw ? ;0x06 |
||
235 | .reg_master_tone dw ? ;0x08 |
||
236 | .reg_beep_vol dw ? ;0x0A |
||
237 | .reg_phone_vol dw ? ;0x0C |
||
2434 | Serge | 238 | .reg_mic_vol dw ? ;0x0E |
2130 | serge | 239 | .reg_line_in_vol dw ? ;0x10 |
2434 | Serge | 240 | .reg_cd_vol dw ? ;0x12 |
2130 | serge | 241 | .reg_video_vol dw ? ;0x14 |
242 | .reg_aux_in_vol dw ? ;0x16 |
||
243 | .reg_pcm_out_vol dw ? ;0x18 |
||
244 | .reg_rec_select dw ? ;0x1A |
||
245 | .reg_rec_gain dw ? ;0x1C |
||
246 | .reg_rec_gain_mic dw ? ;0x1E |
||
2434 | Serge | 247 | .reg_gen dw ? ;0x20 |
248 | .reg_3d_ctrl dw ? ;0X22 |
||
249 | .reg_page dw ? ;0X24 |
||
2130 | serge | 250 | .reg_powerdown dw ? ;0x26 |
251 | .reg_ext_audio dw ? ;0x28 |
||
2434 | Serge | 252 | .reg_ext_st dw ? ;0x2a |
2130 | serge | 253 | .reg_pcm_front_rate dw ? ;0x2c |
254 | .reg_pcm_surr_rate dw ? ;0x2e |
||
255 | .reg_lfe_rate dw ? ;0x30 |
||
256 | .reg_pcm_in_rate dw ? ;0x32 |
||
2434 | Serge | 257 | dw ? ;0x34 |
2130 | serge | 258 | .reg_cent_lfe_vol dw ? ;0x36 |
259 | .reg_surr_vol dw ? ;0x38 |
||
260 | .reg_spdif_ctrl dw ? ;0x3A |
||
2434 | Serge | 261 | dw ? ;0x3C |
262 | dw ? ;0x3E |
||
263 | dw ? ;0x40 |
||
264 | dw ? ;0x42 |
||
265 | dw ? ;0x44 |
||
266 | dw ? ;0x46 |
||
267 | dw ? ;0x48 |
||
268 | dw ? ;0x4A |
||
269 | dw ? ;0x4C |
||
270 | dw ? ;0x4E |
||
271 | dw ? ;0x50 |
||
272 | dw ? ;0x52 |
||
273 | dw ? ;0x54 |
||
274 | dw ? ;0x56 |
||
275 | dw ? ;0x58 |
||
276 | dw ? ;0x5A |
||
277 | dw ? ;0x5C |
||
278 | dw ? ;0x5E |
||
279 | .reg_page_0 dw ? ;0x60 |
||
280 | .reg_page_1 dw ? ;0x62 |
||
281 | .reg_page_2 dw ? ;0x64 |
||
282 | .reg_page_3 dw ? ;0x66 |
||
283 | .reg_page_4 dw ? ;0x68 |
||
284 | .reg_page_5 dw ? ;0x6A |
||
285 | .reg_page_6 dw ? ;0x6C |
||
286 | .reg_page_7 dw ? ;0x6E |
||
287 | dw ? ;0x70 |
||
288 | dw ? ;0x72 |
||
289 | dw ? ;0x74 |
||
290 | dw ? ;0x76 |
||
291 | dw ? ;0x78 |
||
292 | dw ? ;0x7A |
||
2130 | serge | 293 | .reg_vendor_id_1 dw ? ;0x7C |
294 | .reg_vendor_id_2 dw ? ;0x7E |
||
295 | |||
296 | |||
2434 | Serge | 297 | .reset dd ? ;virual |
2130 | serge | 298 | .set_master_vol dd ? |
299 | } |
||
300 | |||
301 | struc CTRL_INFO |
||
2434 | Serge | 302 | { .pci_cmd dd ? |
303 | .irq dd ? |
||
2130 | serge | 304 | .glob_cntrl dd ? |
2434 | Serge | 305 | .glob_sta dd ? |
2130 | serge | 306 | .codec_io_base dd ? |
307 | .ctrl_io_base dd ? |
||
308 | .codec_mem_base dd ? |
||
309 | .ctrl_mem_base dd ? |
||
2434 | Serge | 310 | .codec_id dd ? |
2130 | serge | 311 | } |
312 | |||
313 | struc IOCTL |
||
2434 | Serge | 314 | { .handle dd ? |
315 | .io_code dd ? |
||
316 | .input dd ? |
||
317 | .inp_size dd ? |
||
318 | .output dd ? |
||
319 | .out_size dd ? |
||
2130 | serge | 320 | } |
321 | |||
322 | virtual at 0 |
||
323 | IOCTL IOCTL |
||
324 | end virtual |
||
325 | |||
2434 | Serge | 326 | EVENT_NOTIFY equ 0x00000200 |
2130 | serge | 327 | |
328 | public START |
||
329 | public service_proc |
||
330 | public version |
||
331 | |||
332 | section '.flat' code readable align 16 |
||
333 | |||
334 | proc START stdcall, state:dword |
||
335 | |||
2434 | Serge | 336 | cmp [state], 1 |
337 | jne .stop |
||
2130 | serge | 338 | |
339 | if DEBUG |
||
2434 | Serge | 340 | mov esi, msgInit |
341 | call SysMsgBoardStr |
||
2130 | serge | 342 | end if |
343 | |||
2434 | Serge | 344 | call detect_controller |
345 | test eax, eax |
||
346 | jz .fail |
||
2130 | serge | 347 | |
348 | if DEBUG |
||
2434 | Serge | 349 | mov esi, [ctrl.vendor_ids] |
350 | call SysMsgBoardStr |
||
351 | mov esi, [ctrl.ctrl_ids] |
||
352 | call SysMsgBoardStr |
||
2130 | serge | 353 | end if |
354 | |||
2434 | Serge | 355 | call init_controller |
356 | test eax, eax |
||
357 | jz .fail |
||
2130 | serge | 358 | |
2434 | Serge | 359 | call init_codec |
360 | test eax, eax |
||
361 | jz .fail |
||
2130 | serge | 362 | |
2434 | Serge | 363 | call setup_codec |
2130 | serge | 364 | |
2434 | Serge | 365 | mov esi, msgPrimBuff |
366 | call SysMsgBoardStr |
||
367 | call create_primary_buff |
||
368 | mov esi, msgDone |
||
369 | call SysMsgBoardStr |
||
2130 | serge | 370 | |
371 | if IRQ_REMAP |
||
2434 | Serge | 372 | pushf |
373 | cli |
||
2130 | serge | 374 | |
2434 | Serge | 375 | mov ebx, [ctrl.int_line] |
376 | in al, 0xA1 |
||
377 | mov ah, al |
||
378 | in al, 0x21 |
||
379 | test ebx, ebx |
||
380 | jz .skip |
||
381 | bts ax, bx ;mask old line |
||
2130 | serge | 382 | .skip: |
2434 | Serge | 383 | bts ax, IRQ_LINE ;mask new ine |
384 | out 0x21, al |
||
385 | mov al, ah |
||
386 | out 0xA1, al |
||
2130 | serge | 387 | |
2434 | Serge | 388 | stdcall PciWrite8, 0, 0xF8, 0x61, IRQ_LINE ;remap IRQ |
2130 | serge | 389 | |
2434 | Serge | 390 | mov dx, 0x4d0 ;8259 ELCR1 |
391 | in al, dx |
||
392 | bts ax, IRQ_LINE |
||
393 | out dx, al ;set level-triggered mode |
||
394 | mov [ctrl.int_line], IRQ_LINE |
||
395 | popf |
||
396 | mov esi, msgRemap |
||
397 | call SysMsgBoardStr |
||
2130 | serge | 398 | end if |
399 | |||
2434 | Serge | 400 | mov eax, VALID_IRQ |
401 | mov ebx, [ctrl.int_line] |
||
402 | mov esi, msgInvIRQ |
||
403 | bt eax, ebx |
||
404 | jnc .fail_msg |
||
405 | mov eax, ATTCH_IRQ |
||
406 | mov esi, msgAttchIRQ |
||
407 | bt eax, ebx |
||
408 | jnc .fail_msg |
||
2130 | serge | 409 | |
2434 | Serge | 410 | stdcall AttachIntHandler, ebx, ac97_irq_VIA, dword 0 |
2130 | serge | 411 | .reg: |
2434 | Serge | 412 | stdcall RegService, sz_sound_srv, service_proc |
413 | ret |
||
2130 | serge | 414 | .fail: |
415 | if DEBUG |
||
2434 | Serge | 416 | mov esi, msgFail |
417 | call SysMsgBoardStr |
||
2130 | serge | 418 | end if |
2434 | Serge | 419 | xor eax, eax |
420 | ret |
||
2130 | serge | 421 | .fail_msg: |
2434 | Serge | 422 | call SysMsgBoardStr |
423 | xor eax, eax |
||
424 | ret |
||
2130 | serge | 425 | .stop: |
2434 | Serge | 426 | call stop |
427 | xor eax, eax |
||
428 | ret |
||
2130 | serge | 429 | endp |
430 | |||
2434 | Serge | 431 | handle equ IOCTL.handle |
432 | io_code equ IOCTL.io_code |
||
433 | input equ IOCTL.input |
||
434 | inp_size equ IOCTL.inp_size |
||
435 | output equ IOCTL.output |
||
436 | out_size equ IOCTL.out_size |
||
2130 | serge | 437 | |
438 | align 4 |
||
439 | proc service_proc stdcall, ioctl:dword |
||
440 | |||
2434 | Serge | 441 | mov edi, [ioctl] |
442 | mov eax, [edi+io_code] |
||
2130 | serge | 443 | |
2434 | Serge | 444 | cmp eax, SRV_GETVERSION |
445 | jne @F |
||
446 | mov eax, [edi+output] |
||
447 | cmp [edi+out_size], 4 |
||
448 | jne .fail |
||
2130 | serge | 449 | |
2434 | Serge | 450 | mov [eax], dword API_VERSION |
451 | xor eax, eax |
||
452 | ret |
||
2130 | serge | 453 | @@: |
2434 | Serge | 454 | cmp eax, DEV_PLAY |
455 | jne @F |
||
2130 | serge | 456 | if DEBUG |
2434 | Serge | 457 | mov esi, msgPlay |
458 | call SysMsgBoardStr |
||
2130 | serge | 459 | end if |
2434 | Serge | 460 | call play |
461 | ret |
||
2130 | serge | 462 | @@: |
2434 | Serge | 463 | cmp eax, DEV_STOP |
464 | jne @F |
||
2130 | serge | 465 | if DEBUG |
2434 | Serge | 466 | mov esi, msgStop |
467 | call SysMsgBoardStr |
||
2130 | serge | 468 | end if |
2434 | Serge | 469 | call stop |
470 | ret |
||
2130 | serge | 471 | @@: |
2434 | Serge | 472 | cmp eax, DEV_CALLBACK |
473 | jne @F |
||
474 | mov ebx, [edi+input] |
||
475 | stdcall set_callback, [ebx] |
||
476 | ret |
||
2130 | serge | 477 | @@: |
2434 | Serge | 478 | cmp eax, DEV_SET_MASTERVOL |
479 | jne @F |
||
480 | mov eax, [edi+input] |
||
481 | mov eax, [eax] |
||
482 | call set_master_vol ;eax= vol |
||
483 | ret |
||
2130 | serge | 484 | @@: |
2434 | Serge | 485 | cmp eax, DEV_GET_MASTERVOL |
486 | jne @F |
||
487 | mov ebx, [edi+output] |
||
488 | stdcall get_master_vol, ebx |
||
489 | ret |
||
2130 | serge | 490 | @@: |
2434 | Serge | 491 | cmp eax, DEV_GET_INFO |
492 | jne @F |
||
493 | mov ebx, [edi+output] |
||
494 | stdcall get_dev_info, ebx |
||
495 | ret |
||
2130 | serge | 496 | @@: |
497 | .fail: |
||
2434 | Serge | 498 | or eax, -1 |
499 | ret |
||
2130 | serge | 500 | endp |
501 | |||
502 | restore handle |
||
503 | restore io_code |
||
504 | restore input |
||
505 | restore inp_size |
||
506 | restore output |
||
507 | restore out_size |
||
508 | |||
509 | |||
510 | align 4 |
||
511 | proc ac97_irq_VIA |
||
2434 | Serge | 512 | locals |
513 | status db 0 |
||
514 | endl |
||
2130 | serge | 515 | |
2434 | Serge | 516 | mov edx, VIADEV_PLAYBACK +VIA_REG_OFFSET_STATUS |
517 | call [ctrl.ctrl_read8] |
||
518 | test al, VIA_REG_STAT_ACTIVE |
||
519 | jz @f |
||
2130 | serge | 520 | |
2434 | Serge | 521 | and al, VIA_REG_STAT_EOL or VIA_REG_STAT_FLAG or VIA_REG_STAT_STOPPED |
522 | mov byte [status], al |
||
2130 | serge | 523 | |
2434 | Serge | 524 | mov ebx, dword [buff_list] |
525 | cmp [ctrl.user_callback], 0 |
||
526 | je @f |
||
527 | stdcall [ctrl.user_callback], ebx |
||
2130 | serge | 528 | @@: |
2434 | Serge | 529 | mov al, byte [status] ;; ack ;; |
530 | mov edx, VIADEV_PLAYBACK +VIA_REG_OFFSET_STATUS |
||
531 | call [ctrl.ctrl_write8] |
||
2130 | serge | 532 | |
2434 | Serge | 533 | ret |
2130 | serge | 534 | endp |
535 | |||
536 | |||
537 | align 4 |
||
538 | proc create_primary_buff |
||
539 | |||
2434 | Serge | 540 | stdcall KernelAlloc, 0x10000 |
541 | mov [ctrl.buffer], eax |
||
2130 | serge | 542 | |
2434 | Serge | 543 | mov edi, eax |
544 | mov ecx, 0x10000/4 |
||
545 | xor eax, eax |
||
546 | cld |
||
547 | rep stosd |
||
2130 | serge | 548 | |
2434 | Serge | 549 | mov eax, [ctrl.buffer] |
550 | call GetPgAddr |
||
551 | mov edi, pcmout_bdl |
||
552 | stosd |
||
553 | mov eax, 0x80004000 |
||
554 | stosd |
||
2130 | serge | 555 | |
2434 | Serge | 556 | mov edi, buff_list |
557 | mov eax, [ctrl.buffer] |
||
558 | mov ecx, 4 |
||
2130 | serge | 559 | @@: |
2434 | Serge | 560 | mov [edi], eax |
561 | mov [edi+16], eax |
||
562 | mov [edi+32], eax |
||
563 | mov [edi+48], eax |
||
564 | mov [edi+64], eax |
||
565 | mov [edi+80], eax |
||
566 | mov [edi+96], eax |
||
567 | mov [edi+112], eax |
||
2130 | serge | 568 | |
2434 | Serge | 569 | ;add eax, 0x4000 |
570 | add edi, 4 |
||
571 | loop @B |
||
2130 | serge | 572 | |
2434 | Serge | 573 | stdcall channel_reset, VIADEV_PLAYBACK |
574 | stdcall codec_check_ready |
||
2130 | serge | 575 | |
2434 | Serge | 576 | mov eax, pcmout_bdl |
577 | mov ebx, eax |
||
578 | call GetPgAddr |
||
579 | and ebx, 0xFFF |
||
580 | add eax, ebx |
||
2130 | serge | 581 | |
2434 | Serge | 582 | mov edx, VIADEV_PLAYBACK +VIA_REG_OFFSET_TABLE_PTR |
583 | call [ctrl.ctrl_write32] |
||
2130 | serge | 584 | |
2434 | Serge | 585 | stdcall codec_check_ready |
2130 | serge | 586 | |
2434 | Serge | 587 | mov edx, VIADEV_PLAYBACK +VIA_REG_OFS_PLAYBACK_VOLUME_L |
588 | mov eax, 7 ;31 |
||
589 | call [ctrl.ctrl_write8] |
||
2130 | serge | 590 | |
2434 | Serge | 591 | mov edx, VIADEV_PLAYBACK +VIA_REG_OFS_PLAYBACK_VOLUME_R |
592 | mov eax, 7 ;31 |
||
593 | call [ctrl.ctrl_write8] |
||
2130 | serge | 594 | |
2434 | Serge | 595 | mov edx, VIADEV_PLAYBACK +VIA_REG_OFFSET_STOP_IDX |
596 | mov eax, VIA8233_REG_TYPE_16BIT or VIA8233_REG_TYPE_STEREO or 0xfffff or 0xff000000 |
||
597 | mov [ctrl.lvi_reg], 16 ;0xF;eax |
||
598 | call [ctrl.ctrl_write32] |
||
2130 | serge | 599 | |
2434 | Serge | 600 | stdcall codec_check_ready |
601 | ret |
||
2130 | serge | 602 | endp |
603 | |||
604 | |||
605 | proc channel_reset channel:dword |
||
2434 | Serge | 606 | mov esi, dword [channel] |
607 | mov edx, esi |
||
608 | add edx, VIA_REG_OFFSET_CONTROL |
||
609 | mov eax, VIA_REG_CTRL_PAUSE or VIA_REG_CTRL_TERMINATE or VIA_REG_CTRL_RESET |
||
610 | call [ctrl.ctrl_write8] |
||
2130 | serge | 611 | |
2434 | Serge | 612 | mov edx, esi |
613 | add edx, VIA_REG_OFFSET_CONTROL |
||
614 | call [ctrl.ctrl_read8] |
||
2130 | serge | 615 | |
2434 | Serge | 616 | mov eax, 50000 ; wait 50 ms |
617 | call StallExec |
||
618 | ; disable interrupts |
||
619 | mov edx, esi |
||
620 | add edx, VIA_REG_OFFSET_CONTROL |
||
621 | xor eax, eax |
||
622 | call [ctrl.ctrl_write8] |
||
2130 | serge | 623 | |
2434 | Serge | 624 | ; clear interrupts |
625 | mov edx, esi |
||
626 | add edx, VIA_REG_OFFSET_STATUS |
||
627 | mov eax, 0x03 |
||
628 | call [ctrl.ctrl_write8] |
||
2130 | serge | 629 | |
2434 | Serge | 630 | ;outb(0x00, VIADEV_REG(viadev, OFFSET_TYPE)); /* for via686 */ |
631 | ; mov edx, esi ;; for via686 |
||
632 | ; add edx, VIA_REG_OFFSET_TYPE |
||
633 | ; mov eax, 0x03 |
||
634 | ; call [ctrl.ctrl_write8] |
||
2130 | serge | 635 | |
2434 | Serge | 636 | ;; outl(0, VIADEV_REG(viadev, OFFSET_CURR_PTR)); |
637 | ;mov edx, esi |
||
638 | ;add edx, VIA_REG_OFFSET_CURR_PTR |
||
639 | ;xor eax, eax |
||
640 | ;call [ctrl.ctrl_write8] |
||
2130 | serge | 641 | |
2434 | Serge | 642 | ret |
2130 | serge | 643 | endp |
644 | |||
645 | |||
646 | align 4 |
||
647 | proc detect_controller |
||
2434 | Serge | 648 | locals |
649 | last_bus dd ? |
||
650 | bus dd ? |
||
651 | devfn dd ? |
||
652 | endl |
||
2130 | serge | 653 | |
2434 | Serge | 654 | xor eax, eax |
655 | mov [bus], eax |
||
656 | inc eax |
||
657 | call PciApi |
||
658 | cmp eax, -1 |
||
659 | je .err |
||
2130 | serge | 660 | |
2434 | Serge | 661 | mov [last_bus], eax |
2130 | serge | 662 | |
663 | .next_bus: |
||
2434 | Serge | 664 | and [devfn], 0 |
2130 | serge | 665 | .next_dev: |
2434 | Serge | 666 | stdcall PciRead32, [bus], [devfn], dword 0 |
667 | test eax, eax |
||
668 | jz .next |
||
669 | cmp eax, -1 |
||
670 | je .next |
||
2130 | serge | 671 | |
2434 | Serge | 672 | mov edi, devices |
2130 | serge | 673 | @@: |
2434 | Serge | 674 | mov ebx, [edi] |
675 | test ebx, ebx |
||
676 | jz .next |
||
2130 | serge | 677 | |
2434 | Serge | 678 | cmp eax, ebx |
679 | je .found |
||
680 | add edi, 12 |
||
681 | jmp @B |
||
2130 | serge | 682 | .next: |
2434 | Serge | 683 | inc [devfn] |
684 | cmp [devfn], 256 |
||
685 | jb .next_dev |
||
686 | mov eax, [bus] |
||
687 | inc eax |
||
688 | mov [bus], eax |
||
689 | cmp eax, [last_bus] |
||
690 | jna .next_bus |
||
691 | xor eax, eax |
||
692 | ret |
||
2130 | serge | 693 | .found: |
2434 | Serge | 694 | mov ebx, [bus] |
695 | mov [ctrl.bus], ebx |
||
2130 | serge | 696 | |
2434 | Serge | 697 | mov ecx, [devfn] |
698 | mov [ctrl.devfn], ecx |
||
2130 | serge | 699 | |
2434 | Serge | 700 | mov edx, eax |
701 | and edx, 0xFFFF |
||
702 | mov [ctrl.vendor], edx |
||
703 | shr eax, 16 |
||
704 | mov [ctrl.dev_id], eax |
||
2130 | serge | 705 | |
2434 | Serge | 706 | mov ebx, [edi+4] |
707 | mov [ctrl.ctrl_ids], ebx |
||
708 | mov esi, [edi+8] |
||
709 | mov [ctrl.ctrl_setup], esi |
||
2130 | serge | 710 | |
2434 | Serge | 711 | cmp edx, VID_VIA |
712 | jne @F |
||
713 | mov [ctrl.vendor_ids], msg_VIA |
||
714 | ret |
||
2130 | serge | 715 | @@: |
716 | |||
717 | .err: |
||
2434 | Serge | 718 | xor eax, eax |
719 | mov [ctrl.vendor_ids], eax ;something wrong ? |
||
720 | ret |
||
2130 | serge | 721 | endp |
722 | |||
723 | align 4 |
||
724 | proc init_controller |
||
725 | |||
2434 | Serge | 726 | stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 4 |
727 | mov ebx, eax |
||
728 | and eax, 0xFFFF |
||
729 | mov [ctrl.pci_cmd], eax |
||
730 | shr ebx, 16 |
||
731 | mov [ctrl.pci_stat], ebx |
||
2130 | serge | 732 | |
2434 | Serge | 733 | mov esi, msgPciCmd |
734 | call SysMsgBoardStr |
||
735 | call dword2str |
||
736 | call SysMsgBoardStr |
||
2130 | serge | 737 | |
2434 | Serge | 738 | mov esi, msgPciStat |
739 | call SysMsgBoardStr |
||
740 | mov eax, [ctrl.pci_stat] |
||
741 | call dword2str |
||
742 | call SysMsgBoardStr |
||
2130 | serge | 743 | |
2434 | Serge | 744 | mov esi, msgCtrlIsaIo |
745 | call SysMsgBoardStr |
||
746 | stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x10 |
||
747 | call dword2str |
||
748 | call SysMsgBoardStr |
||
2130 | serge | 749 | |
2434 | Serge | 750 | and eax, 0xFFC0 |
751 | mov [ctrl.ctrl_io_base], eax |
||
2130 | serge | 752 | |
753 | .default: |
||
2434 | Serge | 754 | stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x3C |
755 | and eax, 0xFF |
||
2130 | serge | 756 | @@: |
2434 | Serge | 757 | mov [ctrl.int_line], eax |
2130 | serge | 758 | |
2434 | Serge | 759 | ;stdcall PciRead8, [ctrl.bus], [ctrl.devfn], dword VIA_FUNC_ENABLE ;0x42 |
760 | ;mov byte [old_legacy], al |
||
2130 | serge | 761 | |
2434 | Serge | 762 | ;stdcall PciRead8, [ctrl.bus], [ctrl.devfn], dword VIA_PNP_CONTROL ;0x43 |
763 | ;mov byte [old_legacy_cfg], al |
||
2130 | serge | 764 | |
2434 | Serge | 765 | ;mov al, VIA_FUNC_ENABLE_SB or VIA_FUNC_ENABLE_FM |
766 | ;xor al, 0xFF |
||
767 | ;and al, byte [old_legacy] |
||
768 | ;and eax, 0xFF |
||
769 | ;stdcall PciWrite8, [ctrl.bus], [ctrl.devfn], dword VIA_FUNC_ENABLE, eax ;0x42 |
||
770 | ;mov byte [old_legacy], al |
||
2130 | serge | 771 | |
2434 | Serge | 772 | call [ctrl.ctrl_setup] |
773 | xor eax, eax |
||
774 | inc eax |
||
775 | ret |
||
2130 | serge | 776 | endp |
777 | |||
778 | align 4 |
||
779 | proc set_VIA |
||
2434 | Serge | 780 | mov [ctrl.codec_read16], codec_io_r16 ;virtual |
781 | mov [ctrl.codec_write16], codec_io_w16 ;virtual |
||
2130 | serge | 782 | |
2434 | Serge | 783 | mov [ctrl.ctrl_read8 ], ctrl_io_r8 ;virtual |
784 | mov [ctrl.ctrl_read16], ctrl_io_r16 ;virtual |
||
785 | mov [ctrl.ctrl_read32], ctrl_io_r32 ;virtual |
||
2130 | serge | 786 | |
2434 | Serge | 787 | mov [ctrl.ctrl_write8 ], ctrl_io_w8 ;virtual |
788 | mov [ctrl.ctrl_write16], ctrl_io_w16 ;virtual |
||
789 | mov [ctrl.ctrl_write32], ctrl_io_w32 ;virtual |
||
790 | ret |
||
2130 | serge | 791 | endp |
792 | |||
793 | |||
794 | align 4 |
||
795 | proc init_codec |
||
2434 | Serge | 796 | locals |
797 | counter dd ? |
||
798 | endl |
||
2130 | serge | 799 | |
2434 | Serge | 800 | mov esi, msgControl |
801 | call SysMsgBoardStr |
||
802 | stdcall PciRead8, [ctrl.bus], [ctrl.devfn], dword VIA_ACLINK_CTRL |
||
803 | and eax, 0xFF |
||
804 | call dword2str |
||
805 | call SysMsgBoardStr |
||
2130 | serge | 806 | |
2434 | Serge | 807 | mov esi, msgStatus |
808 | call SysMsgBoardStr |
||
809 | stdcall PciRead8, [ctrl.bus], [ctrl.devfn], dword VIA_ACLINK_STAT |
||
810 | and eax, 0xFF |
||
811 | push eax |
||
812 | call dword2str |
||
813 | call SysMsgBoardStr |
||
814 | pop eax |
||
2130 | serge | 815 | |
2434 | Serge | 816 | test eax, VIA_ACLINK_C00_READY |
817 | jz .ready |
||
2130 | serge | 818 | |
2434 | Serge | 819 | call reset_codec |
820 | test eax, eax |
||
821 | jz .err |
||
2130 | serge | 822 | |
823 | .ready: |
||
2434 | Serge | 824 | xor edx, edx ; ac_reg_0 |
825 | call [ctrl.codec_write16] |
||
826 | jmp .done |
||
2130 | serge | 827 | |
828 | .err: |
||
2434 | Serge | 829 | xor eax, eax ; timeout error |
830 | ret |
||
2130 | serge | 831 | |
832 | .done: |
||
2434 | Serge | 833 | call detect_codec |
2130 | serge | 834 | |
2434 | Serge | 835 | xor eax, eax |
836 | inc eax |
||
837 | ret |
||
2130 | serge | 838 | endp |
839 | |||
840 | align 4 |
||
841 | proc reset_codec |
||
2434 | Serge | 842 | stdcall PciWrite8, [ctrl.bus], [ctrl.devfn], dword VIA_ACLINK_CTRL, \ |
843 | VIA_ACLINK_CTRL_ENABLE or VIA_ACLINK_CTRL_RESET or VIA_ACLINK_CTRL_SYNC |
||
844 | mov eax, 100000 ; wait 100 ms |
||
845 | call StallExec |
||
2130 | serge | 846 | .cold: |
2434 | Serge | 847 | call cold_reset |
848 | jnc .ok |
||
2130 | serge | 849 | |
850 | if DEBUG |
||
2434 | Serge | 851 | mov esi, msgCFail |
852 | call SysMsgBoardStr |
||
2130 | serge | 853 | end if |
2434 | Serge | 854 | xor eax, eax ; timeout error |
855 | ret |
||
2130 | serge | 856 | .ok: |
857 | if DEBUG |
||
2434 | Serge | 858 | mov esi, msgResetOk |
859 | call SysMsgBoardStr |
||
2130 | serge | 860 | end if |
2434 | Serge | 861 | xor eax, eax |
862 | inc eax |
||
863 | ret |
||
2130 | serge | 864 | endp |
865 | |||
866 | |||
867 | align 4 |
||
868 | proc cold_reset |
||
2434 | Serge | 869 | locals |
870 | counter dd ? |
||
871 | endl |
||
2130 | serge | 872 | |
2434 | Serge | 873 | stdcall PciWrite8, [ctrl.bus], [ctrl.devfn], dword VIA_ACLINK_CTRL, dword 0 |
2130 | serge | 874 | |
875 | if DEBUG |
||
2434 | Serge | 876 | mov esi, msgCold |
877 | call SysMsgBoardStr |
||
2130 | serge | 878 | end if |
879 | |||
2434 | Serge | 880 | mov eax, 100000 ; wait 100 ms ;400000 ; wait 400 ms |
881 | call StallExec |
||
2130 | serge | 882 | |
2434 | Serge | 883 | ;; ACLink on, deassert ACLink reset, VSR, SGD data out |
884 | ;; note - FM data out has trouble with non VRA codecs !! |
||
885 | stdcall PciWrite8, [ctrl.bus], [ctrl.devfn], dword VIA_ACLINK_CTRL, dword VIA_ACLINK_CTRL_INIT |
||
2130 | serge | 886 | |
2434 | Serge | 887 | mov [counter], 16 ; total 20*100 ms = 2s |
2130 | serge | 888 | .wait: |
2434 | Serge | 889 | stdcall PciRead8, [ctrl.bus], [ctrl.devfn], dword VIA_ACLINK_STAT |
890 | test eax, VIA_ACLINK_C00_READY |
||
891 | jnz .ok |
||
2130 | serge | 892 | |
2434 | Serge | 893 | mov eax, 100000 ; wait 100 ms |
894 | call StallExec |
||
2130 | serge | 895 | |
2434 | Serge | 896 | dec [counter] |
897 | jnz .wait |
||
2130 | serge | 898 | |
899 | if DEBUG |
||
2434 | Serge | 900 | mov esi, msgCRFail |
901 | call SysMsgBoardStr |
||
2130 | serge | 902 | end if |
903 | |||
904 | .fail: |
||
2434 | Serge | 905 | stc |
906 | ret |
||
2130 | serge | 907 | .ok: |
2434 | Serge | 908 | mov esi, msgControl |
909 | call SysMsgBoardStr |
||
910 | stdcall PciRead8, [ctrl.bus], [ctrl.devfn], dword VIA_ACLINK_CTRL |
||
911 | call dword2str |
||
912 | call SysMsgBoardStr |
||
2130 | serge | 913 | |
2434 | Serge | 914 | mov esi, msgStatus |
915 | call SysMsgBoardStr |
||
916 | stdcall PciRead8, [ctrl.bus], [ctrl.devfn], dword VIA_ACLINK_STAT |
||
917 | and eax, 0xFF |
||
918 | push eax |
||
919 | call dword2str |
||
920 | call SysMsgBoardStr |
||
921 | pop eax |
||
2130 | serge | 922 | |
2434 | Serge | 923 | test eax, VIA_ACLINK_C00_READY ;CTRL_ST_CREADY |
924 | jz .fail |
||
925 | clc |
||
926 | ret |
||
2130 | serge | 927 | endp |
928 | |||
929 | align 4 |
||
930 | play: |
||
2434 | Serge | 931 | mov edx, VIADEV_PLAYBACK +VIA_REG_OFFSET_STOP_IDX |
932 | mov eax, VIA8233_REG_TYPE_16BIT or VIA8233_REG_TYPE_STEREO or 0xfffff or 0xff000000 |
||
933 | mov [ctrl.lvi_reg], 16 |
||
934 | call [ctrl.ctrl_write32] |
||
2130 | serge | 935 | |
2434 | Serge | 936 | mov eax, VIA_REG_CTRL_INT |
937 | or eax, VIA_REG_CTRL_START |
||
938 | mov edx, VIADEV_PLAYBACK +VIA_REG_OFFSET_CONTROL |
||
939 | call [ctrl.ctrl_write8] |
||
2130 | serge | 940 | |
2434 | Serge | 941 | xor eax, eax |
942 | ret |
||
2130 | serge | 943 | |
944 | align 4 |
||
945 | stop: |
||
2434 | Serge | 946 | mov eax, VIA_REG_CTRL_INT |
947 | or eax, VIA_REG_CTRL_TERMINATE |
||
948 | mov edx, VIADEV_PLAYBACK +VIA_REG_OFFSET_CONTROL |
||
949 | call [ctrl.ctrl_write8] |
||
2130 | serge | 950 | |
2434 | Serge | 951 | stdcall channel_reset, VIADEV_PLAYBACK |
952 | xor eax, eax |
||
953 | ret |
||
2130 | serge | 954 | |
955 | align 4 |
||
956 | proc get_dev_info stdcall, p_info:dword |
||
2434 | Serge | 957 | virtual at esi |
958 | CTRL_INFO CTRL_INFO |
||
959 | end virtual |
||
2130 | serge | 960 | |
2434 | Serge | 961 | mov esi, [p_info] |
962 | mov eax, [ctrl.int_line] |
||
963 | mov ecx, [ctrl.ctrl_io_base] |
||
964 | mov [CTRL_INFO.irq], eax |
||
965 | mov [CTRL_INFO.ctrl_io_base], ecx |
||
2130 | serge | 966 | |
2434 | Serge | 967 | xor eax, eax |
968 | ;mov edx, VIADEV_PLAYBACK +VIA_REG_OFFSET_TABLE_PTR |
||
969 | ;call [ctrl.ctrl_read32] |
||
970 | mov [CTRL_INFO.codec_io_base], eax |
||
971 | ;mov edx, VIADEV_PLAYBACK +VIA_REG_OFFSET_STOP_IDX |
||
972 | ;call [ctrl.ctrl_read32] |
||
973 | mov [CTRL_INFO.codec_mem_base], eax |
||
974 | ;mov edx, VIADEV_PLAYBACK +VIA_REG_OFFSET_CURR_COUNT |
||
975 | ;call [ctrl.ctrl_read32] |
||
976 | mov [CTRL_INFO.ctrl_mem_base], eax |
||
2130 | serge | 977 | |
2434 | Serge | 978 | mov eax, [codec.chip_id] |
979 | mov [CTRL_INFO.codec_id], eax |
||
2130 | serge | 980 | |
2434 | Serge | 981 | mov edx, VIADEV_PLAYBACK +VIA_REG_OFFSET_CONTROL |
982 | call [ctrl.ctrl_read8] |
||
983 | and eax, 0xFF |
||
984 | mov [CTRL_INFO.glob_cntrl], eax |
||
2130 | serge | 985 | |
2434 | Serge | 986 | mov edx, VIADEV_PLAYBACK +VIA_REG_OFFSET_STATUS |
987 | call [ctrl.ctrl_read8] |
||
988 | and eax, 0xFF |
||
989 | mov [CTRL_INFO.glob_sta], eax |
||
2130 | serge | 990 | |
2434 | Serge | 991 | mov ebx, [ctrl.pci_cmd] |
992 | mov [CTRL_INFO.pci_cmd], ebx |
||
993 | ret |
||
2130 | serge | 994 | endp |
995 | |||
996 | align 4 |
||
997 | proc set_callback stdcall, handler:dword |
||
2434 | Serge | 998 | mov eax, [handler] |
999 | mov [ctrl.user_callback], eax |
||
1000 | ret |
||
2130 | serge | 1001 | endp |
1002 | |||
1003 | |||
1004 | align 4 |
||
1005 | proc codec_check_ready stdcall |
||
2434 | Serge | 1006 | locals |
1007 | counter dd ? |
||
1008 | endl |
||
2130 | serge | 1009 | |
2434 | Serge | 1010 | mov [counter], 1000 ; total 1000*1 ms = 1s |
2130 | serge | 1011 | .wait: |
2434 | Serge | 1012 | call [ctrl.codec_read16] |
1013 | test eax, VIA_REG_AC97_BUSY |
||
1014 | jz .ok |
||
2130 | serge | 1015 | |
2434 | Serge | 1016 | mov eax, 1000 ; wait 1 ms |
1017 | call StallExec |
||
2130 | serge | 1018 | |
2434 | Serge | 1019 | sub [counter] , 1 |
1020 | jnz .wait |
||
2130 | serge | 1021 | .err: |
2434 | Serge | 1022 | mov eax, -1 |
1023 | ret |
||
2130 | serge | 1024 | .ok: |
2434 | Serge | 1025 | and eax, 0xFFFF |
1026 | ret |
||
2130 | serge | 1027 | endp |
1028 | |||
1029 | |||
1030 | align 4 |
||
1031 | proc codec_valid stdcall |
||
2434 | Serge | 1032 | stdcall codec_check_ready |
1033 | ret |
||
2130 | serge | 1034 | endp |
1035 | |||
1036 | align 4 |
||
2434 | Serge | 1037 | proc codec_read stdcall, ac_reg:dword ; reg = edx, reval = eax |
1038 | locals |
||
1039 | counter dd ? |
||
1040 | endl |
||
2130 | serge | 1041 | |
2434 | Serge | 1042 | ;Use only primary codec. |
1043 | mov eax, [ac_reg] |
||
1044 | and eax, 0x7F |
||
1045 | shl eax, VIA_REG_AC97_CMD_SHIFT |
||
1046 | or eax, VIA_REG_AC97_PRIMARY_VALID or VIA_REG_AC97_READ |
||
2130 | serge | 1047 | |
2434 | Serge | 1048 | mov [counter], 3 ; total 3*20 ms = 60ms |
2130 | serge | 1049 | .wait: |
2434 | Serge | 1050 | push eax |
1051 | call [ctrl.codec_write16] |
||
2130 | serge | 1052 | |
2434 | Serge | 1053 | mov eax, 20000 ; wait 20 ms |
1054 | call StallExec |
||
2130 | serge | 1055 | |
2434 | Serge | 1056 | stdcall codec_valid |
1057 | cmp eax, 0 |
||
1058 | pop eax |
||
1059 | jge .ok |
||
2130 | serge | 1060 | |
2434 | Serge | 1061 | sub [counter] , 1 |
1062 | jnz .wait |
||
1063 | jmp .err |
||
2130 | serge | 1064 | |
1065 | .ok: |
||
2434 | Serge | 1066 | mov eax, 25000 ; wait 25 ms |
1067 | call StallExec |
||
2130 | serge | 1068 | |
2434 | Serge | 1069 | call [ctrl.codec_read16] ;change edx !!! |
1070 | and eax, 0xFFFF |
||
1071 | ret |
||
2130 | serge | 1072 | .err: |
1073 | if DEBUG |
||
2434 | Serge | 1074 | mov esi, msgCInvalid |
1075 | call SysMsgBoardStr |
||
2130 | serge | 1076 | end if |
2434 | Serge | 1077 | mov eax, -1 ; invalid codec error |
1078 | ret |
||
2130 | serge | 1079 | endp |
1080 | |||
1081 | align 4 |
||
1082 | proc codec_write stdcall, ac_reg:dword |
||
2434 | Serge | 1083 | ;Use only primary codec. |
1084 | mov esi, [ac_reg] |
||
1085 | mov edx, esi |
||
1086 | shl edx, VIA_REG_AC97_CMD_SHIFT |
||
2130 | serge | 1087 | |
2434 | Serge | 1088 | shl eax, VIA_REG_AC97_DATA_SHIFT |
1089 | or edx, eax |
||
2130 | serge | 1090 | |
2434 | Serge | 1091 | mov eax, VIA_REG_AC97_CODEC_ID_PRIMARY ;not VIA_REG_AC97_CODEC_ID_PRIMARY |
1092 | shl eax, VIA_REG_AC97_CODEC_ID_SHIFT |
||
1093 | or edx, eax |
||
2130 | serge | 1094 | |
2434 | Serge | 1095 | mov eax, edx |
1096 | mov edx, esi |
||
1097 | call [ctrl.codec_write16] |
||
1098 | mov [codec.regs+esi], ax |
||
2130 | serge | 1099 | |
2434 | Serge | 1100 | stdcall codec_check_ready |
1101 | cmp eax, 0 |
||
1102 | jl .err |
||
2130 | serge | 1103 | .ok: |
2434 | Serge | 1104 | ret |
2130 | serge | 1105 | .err: |
1106 | if DEBUG |
||
2434 | Serge | 1107 | mov esi, msgCFail |
1108 | call SysMsgBoardStr |
||
2130 | serge | 1109 | end if |
2434 | Serge | 1110 | ;mov eax, -1 ; codec not ready error |
1111 | ret |
||
2130 | serge | 1112 | endp |
1113 | |||
1114 | align 4 |
||
1115 | proc StallExec |
||
2434 | Serge | 1116 | push ecx |
1117 | push edx |
||
1118 | push ebx |
||
1119 | push eax |
||
2130 | serge | 1120 | |
2434 | Serge | 1121 | mov ecx, CPU_FREQ |
1122 | mul ecx |
||
1123 | mov ebx, eax ;low |
||
1124 | mov ecx, edx ;high |
||
1125 | rdtsc |
||
1126 | add ebx, eax |
||
1127 | adc ecx, edx |
||
2130 | serge | 1128 | @@: |
2434 | Serge | 1129 | rdtsc |
1130 | sub eax, ebx |
||
1131 | sbb edx, ecx |
||
1132 | js @B |
||
2130 | serge | 1133 | |
2434 | Serge | 1134 | pop eax |
1135 | pop ebx |
||
1136 | pop edx |
||
1137 | pop ecx |
||
1138 | ret |
||
2130 | serge | 1139 | endp |
1140 | |||
1141 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
1142 | ; CONTROLLER IO functions |
||
1143 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
1144 | |||
1145 | align 4 |
||
1146 | proc codec_io_r16 ;r32 |
||
2434 | Serge | 1147 | mov edx, [ctrl.ctrl_io_base] |
1148 | add edx, VIA_REG_AC97 |
||
1149 | in eax, dx |
||
1150 | ret |
||
2130 | serge | 1151 | endp |
1152 | |||
1153 | align 4 |
||
1154 | proc codec_io_w16 ;w32 |
||
2434 | Serge | 1155 | mov edx, [ctrl.ctrl_io_base] |
1156 | add edx, VIA_REG_AC97 |
||
1157 | out dx, eax |
||
1158 | ret |
||
2130 | serge | 1159 | endp |
1160 | |||
1161 | align 4 |
||
1162 | proc ctrl_io_r8 |
||
2434 | Serge | 1163 | add edx, [ctrl.ctrl_io_base] |
1164 | in al, dx |
||
1165 | ret |
||
2130 | serge | 1166 | endp |
1167 | |||
1168 | align 4 |
||
1169 | proc ctrl_io_r16 |
||
2434 | Serge | 1170 | add edx, [ctrl.ctrl_io_base] |
1171 | in ax, dx |
||
1172 | ret |
||
2130 | serge | 1173 | endp |
1174 | |||
1175 | align 4 |
||
1176 | proc ctrl_io_r32 |
||
2434 | Serge | 1177 | add edx, [ctrl.ctrl_io_base] |
1178 | in eax, dx |
||
1179 | ret |
||
2130 | serge | 1180 | endp |
1181 | |||
1182 | align 4 |
||
1183 | proc ctrl_io_w8 |
||
2434 | Serge | 1184 | add edx, [ctrl.ctrl_io_base] |
1185 | out dx, al |
||
1186 | ret |
||
2130 | serge | 1187 | endp |
1188 | |||
1189 | align 4 |
||
1190 | proc ctrl_io_w16 |
||
2434 | Serge | 1191 | add edx, [ctrl.ctrl_io_base] |
1192 | out dx, ax |
||
1193 | ret |
||
2130 | serge | 1194 | endp |
1195 | |||
1196 | align 4 |
||
1197 | proc ctrl_io_w32 |
||
2434 | Serge | 1198 | add edx, [ctrl.ctrl_io_base] |
1199 | out dx, eax |
||
1200 | ret |
||
2130 | serge | 1201 | endp |
1202 | |||
1203 | |||
1204 | align 4 |
||
1205 | dword2str: |
||
2434 | Serge | 1206 | push eax ebx ecx |
1207 | mov esi, hex_buff |
||
1208 | mov ecx, -8 |
||
2130 | serge | 1209 | @@: |
2434 | Serge | 1210 | rol eax, 4 |
1211 | mov ebx, eax |
||
1212 | and ebx, 0x0F |
||
1213 | mov bl, [ebx+hexletters] |
||
1214 | mov [8+esi+ecx], bl |
||
1215 | inc ecx |
||
1216 | jnz @B |
||
1217 | pop ecx ebx eax |
||
1218 | ret |
||
2130 | serge | 1219 | |
1220 | hexletters db '0123456789ABCDEF' |
||
1221 | hex_buff db 8 dup(0),13,10,0 |
||
1222 | |||
1223 | |||
1224 | include "codec.inc" |
||
1225 | |||
1226 | align 4 |
||
1227 | devices dd (CTRL_VT82C686 shl 16)+VID_VIA,msg_VT82C686,set_VIA |
||
2434 | Serge | 1228 | dd (CTRL_VT8233_5 shl 16)+VID_VIA,msg_VT8233,set_VIA |
1229 | dd 0 ;terminator |
||
2130 | serge | 1230 | |
1231 | |||
1232 | version dd (5 shl 16) or (API_VERSION and 0xFFFF) |
||
1233 | |||
1234 | msg_VT82C686 db 'VT82C686', 13,10, 0 |
||
1235 | msg_VT8233 db 'VT8233', 13,10, 0 |
||
2434 | Serge | 1236 | msg_VIA db 'VIA' , 13,10, 0 |
2130 | serge | 1237 | |
2434 | Serge | 1238 | szKernel db 'KERNEL', 0 |
1239 | sz_sound_srv db 'SOUND',0 |
||
2130 | serge | 1240 | |
1241 | msgInit db 'detect hardware...',13,10,0 |
||
1242 | msgFail db 'device not found',13,10,0 |
||
1243 | msgAttchIRQ db 'IRQ line not supported', 13,10, 0 |
||
1244 | msgInvIRQ db 'IRQ line not assigned or invalid', 13,10, 0 |
||
1245 | msgPlay db 'start play', 13,10,0 |
||
1246 | msgStop db 'stop play', 13,10,0 |
||
1247 | ;msgIRQ db 'AC97 IRQ', 13,10,0 |
||
1248 | ;msgInitCtrl db 'init controller',13,10,0 |
||
1249 | ;msgInitCodec db 'init codec',13,10,0 |
||
1250 | msgPrimBuff db 'create primary buffer ...',0 |
||
1251 | msgDone db 'done',13,10,0 |
||
1252 | msgRemap db 'Remap IRQ',13,10,0 |
||
1253 | ;msgReg db 'set service handler',13,10,0 |
||
1254 | ;msgOk db 'service installed',13,10,0 |
||
1255 | msgCold db 'cold reset',13,10,0 |
||
1256 | ;msgWarm db 'warm reset',13,10,0 |
||
1257 | ;msgWRFail db 'warm reset failed',13,10,0 |
||
1258 | msgCRFail db 'cold reset failed',13,10,0 |
||
1259 | msgCFail db 'codec not ready',13,10,0 |
||
1260 | msgCInvalid db 'codec is not valid',13,10,0 ;Asper |
||
1261 | msgResetOk db 'reset complete',13,10,0 |
||
1262 | msgStatus db 'global status ',0 |
||
1263 | msgControl db 'global control ',0 |
||
1264 | msgPciCmd db 'PCI command ',0 |
||
1265 | msgPciStat db 'PCI status ',0 |
||
1266 | msgCtrlIsaIo db 'controller io base ',0 |
||
1267 | ;msgMixIsaIo db 'codec io base ',0 |
||
1268 | ;msgCtrlMMIo db 'controller mmio base ',0 |
||
1269 | ;msgMixMMIo db 'codec mmio base ',0 |
||
1270 | ;msgIrqMap db 'AC97 irq map as ',0 |
||
1271 | |||
1272 | |||
1273 | section '.data' data readable writable align 16 |
||
1274 | |||
2434 | Serge | 1275 | pcmout_bdl rq 32 |
1276 | buff_list rd 32 |
||
2130 | serge | 1277 | |
1278 | codec CODEC |
||
1279 | ctrl AC_CNTRL |
||
1280 | |||
2434 | Serge | 1281 | chip_type rb 1><>23) |