Subversion Repositories Kolibri OS

Rev

Rev 4324 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4324 Rev 4555
1
;; Compose a 32bit command word to be sent to the HD-audio controller
1
;; Compose a 32bit command word to be sent to the HD-audio controller
2
proc make_codec_cmd stdcall, nid:dword, direct:dword, verb:dword, parm:dword
2
proc make_codec_cmd stdcall, nid:dword, direct:dword, verb:dword, parm:dword
3
    push   ebx
3
    push   ebx
4
 
4
 
5
    and    dword [codec.addr], 0xF
5
    and    dword [codec.addr], 0xF
6
    and    dword [direct], 1
6
    and    dword [direct], 1
7
    and    dword [nid], 0x7F
7
    and    dword [nid], 0x7F
8
    and    dword [verb], 0xFFF
8
    and    dword [verb], 0xFFF
9
    and    dword [parm], 0xFFFF
9
    and    dword [parm], 0xFFFF
10
 
10
 
11
    mov    eax, [codec.addr]
11
    mov    eax, [codec.addr]
12
    shl    eax, 28
12
    shl    eax, 28
13
    mov    ebx, [direct]
13
    mov    ebx, [direct]
14
    shl    ebx, 27
14
    shl    ebx, 27
15
    or     eax, ebx
15
    or     eax, ebx
16
    mov    ebx, [nid]
16
    mov    ebx, [nid]
17
    shl    ebx, 20
17
    shl    ebx, 20
18
    or     eax, ebx
18
    or     eax, ebx
19
    mov    ebx, [verb]
19
    mov    ebx, [verb]
20
    shl    ebx, 8
20
    shl    ebx, 8
21
    or     eax, ebx
21
    or     eax, ebx
22
    mov    ebx, [parm]
22
    mov    ebx, [parm]
23
    or     eax, ebx
23
    or     eax, ebx
24
    pop    ebx
24
    pop    ebx
25
    ret
25
    ret
26
 .err:
26
 .err:
27
    pop    ebx
27
    pop    ebx
28
    mov    eax, -1
28
    mov    eax, -1
29
    ret
29
    ret
30
endp
30
endp
31
 
31
 
32
;; Send and receive a verb
32
;; Send and receive a verb
33
proc  codec_exec_verb stdcall, cmd:dword;, res:dword <- returned in eax
33
proc  codec_exec_verb stdcall, cmd:dword;, res:dword <- returned in eax
34
    push   ebx  edx
34
    push   ebx  edx
35
    mov    ebx, [cmd]
35
    mov    ebx, [cmd]
36
    cmp    ebx, -1
36
    cmp    ebx, -1
37
    jne    @f
37
    jne    @f
38
    pop    edx  ebx
38
    pop    edx  ebx
39
    mov    eax, -1
39
    mov    eax, -1
40
    ret
40
    ret
41
  @@:
41
  @@:
42
  if  FDEBUG   ;YAHOO
42
  if  FDEBUG   ;YAHOO
43
    push   eax esi
43
    push   eax esi
44
    mov    esi, msgVerbQuery
44
    mov    esi, msgVerbQuery
45
    call   SysMsgBoardStr
45
    call   SysMsgBoardStr
46
    mov    eax, ebx
46
    mov    eax, ebx
47
    stdcall fdword2str, 2
47
    stdcall fdword2str, 2
48
    call   SysMsgBoardStr
48
    call   SysMsgBoardStr
49
    pop    esi eax
49
    pop    esi eax
50
  end if
50
  end if
51
 
51
 
52
    mov    edx, -1
52
    mov    edx, -1
53
  .again:
53
  .again:
54
    ; call   snd_hda_power_up
54
    ; call   snd_hda_power_up
55
    stdcall  azx_send_cmd, ebx
55
    stdcall  azx_send_cmd, ebx
56
    mov    ebx, eax
56
    mov    ebx, eax
57
    test   ebx, ebx
57
    test   ebx, ebx
58
    jnz    @f
58
    jnz    @f
59
    call  azx_get_response
59
    call  azx_get_response
60
    mov    edx, eax
60
    mov    edx, eax
61
  if  FDEBUG
61
  if  FDEBUG
62
    test   edx, edx
62
    test   edx, edx
63
    jz     .end_debug
63
    jz     .end_debug
64
    push   eax esi
64
    push   eax esi
65
    mov    esi, msgVerbAnswer
65
    mov    esi, msgVerbAnswer
66
    call   SysMsgBoardStr
66
    call   SysMsgBoardStr
67
    mov    eax, edx
67
    mov    eax, edx
68
    stdcall fdword2str, 2
68
    stdcall fdword2str, 2
69
    call   SysMsgBoardStr
69
    call   SysMsgBoardStr
70
    pop    esi eax
70
    pop    esi eax
71
   .end_debug:
71
   .end_debug:
72
  end if
72
  end if
73
 
73
 
74
  @@:
74
  @@:
75
 
75
 
76
    ;call   snd_hda_power_down
76
    ;call   snd_hda_power_down
77
    cmp    edx, -1
77
    cmp    edx, -1
78
    jne    .l1
78
    jne    .l1
79
 
79
 
80
    mov    eax, [ctrl.rirb_error]
80
    mov    eax, [ctrl.rirb_error]
81
    test   eax, eax
81
    test   eax, eax
82
    jz     .l1
82
    jz     .l1
83
 
83
 
84
    mov    eax, [ctrl.response_reset]
84
    mov    eax, [ctrl.response_reset]
85
    jz     @f
85
    jz     @f
86
 
86
 
87
  if  DEBUG
87
  if  DEBUG
88
    push   esi
88
    push   esi
89
    mov    esi, emsgBusResetFatalComm
89
    mov    esi, emsgBusResetFatalComm
90
    call   SysMsgBoardStr
90
    call   SysMsgBoardStr
91
    pop    esi
91
    pop    esi
92
  end if
92
  end if
93
    call   azx_bus_reset
93
    call   azx_bus_reset
94
  @@:
94
  @@:
95
  .l1:
95
  .l1:
96
    ;; clear reset-flag when the communication gets recovered
96
    ;; clear reset-flag when the communication gets recovered
97
    test   ebx, ebx
97
    test   ebx, ebx
98
    jnz    @f
98
    jnz    @f
99
    mov    [ctrl.response_reset], 0
99
    mov    [ctrl.response_reset], 0
100
  @@:
100
  @@:
101
    mov    eax, edx
101
    mov    eax, edx
102
 
102
 
103
    pop    edx  ebx
103
    pop    edx  ebx
104
    ret
104
    ret
105
endp
105
endp
106
 
106
 
107
 
107
 
108
;;
108
;;
109
;; snd_hda_codec_read - send a command and get the response
109
;; snd_hda_codec_read - send a command and get the response
110
;; @nid: NID to send the command
110
;; @nid: NID to send the command
111
;; @direct: direct flag
111
;; @direct: direct flag
112
;; @verb: the verb to send
112
;; @verb: the verb to send
113
;; @parm: the parameter for the verb
113
;; @parm: the parameter for the verb
114
;;
114
;;
115
;; Send a single command and read the corresponding response.
115
;; Send a single command and read the corresponding response.
116
;;
116
;;
117
;; Returns the obtained response value, or -1 for an error.
117
;; Returns the obtained response value, or -1 for an error.
118
;;
118
;;
119
proc  snd_hda_codec_read stdcall, nid:dword, direct:dword, verb:dword, parm:dword
119
proc  snd_hda_codec_read stdcall, nid:dword, direct:dword, verb:dword, parm:dword
120
    stdcall  make_codec_cmd, [nid], [direct], [verb], [parm]
120
    stdcall  make_codec_cmd, [nid], [direct], [verb], [parm]
121
    stdcall  codec_exec_verb, eax
121
    stdcall  codec_exec_verb, eax
122
    ret
122
    ret
123
endp
123
endp
124
 
124
 
125
 
125
 
126
;;
126
;;
127
;; snd_hda_codec_write - send a single command without waiting for response
127
;; snd_hda_codec_write - send a single command without waiting for response
128
;; @nid: NID to send the command
128
;; @nid: NID to send the command
129
;; @direct: direct flag
129
;; @direct: direct flag
130
;; @verb: the verb to send
130
;; @verb: the verb to send
131
;; @parm: the parameter for the verb
131
;; @parm: the parameter for the verb
132
;;
132
;;
133
;; Send a single command without waiting for response.
133
;; Send a single command without waiting for response.
134
;;
134
;;
135
;; Returns 0 if successful, or a negative error code.
135
;; Returns 0 if successful, or a negative error code.
136
;;
136
;;
137
proc  snd_hda_codec_write stdcall, nid:dword, direct:dword, verb:dword, parm:dword
137
proc  snd_hda_codec_write stdcall, nid:dword, direct:dword, verb:dword, parm:dword
138
    ; Do we need to support a sync write?
138
    ; Do we need to support a sync write?
139
    stdcall  make_codec_cmd, [nid], [direct], [verb], [parm]
139
    stdcall  make_codec_cmd, [nid], [direct], [verb], [parm]
140
    stdcall  codec_exec_verb, eax
140
    stdcall  codec_exec_verb, eax
141
    ret
141
    ret
142
endp
142
endp
143
 
143
 
144
 
144
 
145
;;
145
;;
146
;; snd_hda_sequence_write - sequence writes
146
;; snd_hda_sequence_write - sequence writes
147
;; @seq: VERB array to send
147
;; @seq: VERB array to send
148
;;
148
;;
149
;; Send the commands sequentially from the given array.
149
;; Send the commands sequentially from the given array.
150
;; The array must be terminated with NID=0.
150
;; The array must be terminated with NID=0.
151
;;
151
;;
152
proc  snd_hda_sequence_write stdcall, seq:dword
152
proc  snd_hda_sequence_write stdcall, seq:dword
153
    push     eax  ebx  ecx  esi
153
    push     eax  ebx  ecx  esi
154
    mov      esi, [seq]
154
    mov      esi, [seq]
155
  @@:
155
  @@:
156
    ;mov      ecx, [esi + hda_verb.nid]
156
    ;mov      ecx, [esi + hda_verb.nid]
157
    ;mov      ebx, [esi + hda_verb.verb]
157
    ;mov      ebx, [esi + hda_verb.verb]
158
    ;mov      eax, [esi + hda_verb.param]
158
    ;mov      eax, [esi + hda_verb.param]
159
    ;stdcall  snd_hda_codec_write, ecx, 0, ebx, eax
159
    ;stdcall  snd_hda_codec_write, ecx, 0, ebx, eax
160
    ;add      esi, hda_verb.sizeof
160
    ;add      esi, hda_verb.sizeof
161
    ;test     ecx, ecx
161
    ;test     ecx, ecx
162
    ;jnz      @b
162
    ;jnz      @b
163
    ;______________________________________
163
    ;______________________________________
164
    cmp      dword [esi], 0
164
    cmp      dword [esi], 0
165
    je       .out
165
    je       .out
166
    movzx    ecx, word [esi] ; NID
166
    movzx    ecx, word [esi] ; NID
167
    movzx    ebx, word [esi+2] ; verb
167
    movzx    ebx, word [esi+2] ; verb
168
    and      bx, 0x0FFF
168
    and      bx, 0x0FFF
169
    movzx    eax, word [esi + 4] ; sizeof(param) = 4 bytes
169
    movzx    eax, word [esi + 4] ; sizeof(param) = 4 bytes
170
    stdcall  snd_hda_codec_write, ecx, 0, ebx, eax
170
    stdcall  snd_hda_codec_write, ecx, 0, ebx, eax
171
    add      esi, 6
171
    add      esi, 6
172
    jmp      @b
172
    jmp      @b
173
 .out:
173
 .out:
174
    pop      esi  ecx  ebx  eax
174
    pop      esi  ecx  ebx  eax
175
    ret
175
    ret
176
endp
176
endp
177
 
177
 
178
 
178
 
179
macro  snd_hda_param_read  nid, param
179
macro  snd_hda_param_read  nid, param
180
{
180
{
181
    stdcall  snd_hda_codec_read, nid, 0, AC_VERB_PARAMETERS, param
181
    stdcall  snd_hda_codec_read, nid, 0, AC_VERB_PARAMETERS, param
182
}
182
}
183
 
183
 
184
;;
184
;;
185
;; snd_hda_get_sub_nodes - get the range of sub nodes
185
;; snd_hda_get_sub_nodes - get the range of sub nodes
186
;; @codec: the HDA codec
186
;; @codec: the HDA codec
187
;; @nid: NID to parse
187
;; @nid: NID to parse
188
;; @start_id: the pointer to store the start NID
188
;; @start_id: the pointer to store the start NID
189
;;
189
;;
190
;; Parse the NID and store the start NID of its sub-nodes.
190
;; Parse the NID and store the start NID of its sub-nodes.
191
;; Returns the number of sub-nodes.
191
;; Returns the number of sub-nodes.
192
;;
192
;;
193
proc  snd_hda_get_sub_nodes stdcall, nid:dword;, start_id:dword  <- returned in upper word of eax
193
proc  snd_hda_get_sub_nodes stdcall, nid:dword;, start_id:dword  <- returned in upper word of eax
194
    snd_hda_param_read  [nid], AC_PAR_NODE_COUNT
194
    snd_hda_param_read  [nid], AC_PAR_NODE_COUNT
195
 
195
 
196
    cmp      eax, -1
196
    cmp      eax, -1
197
    jne      @f
197
    jne      @f
198
    inc      eax
198
    inc      eax
199
  @@:
199
  @@:
200
    and      eax, 0x7FFF7FFF
200
    and      eax, 0x7FFF7FFF
201
 
201
 
202
    ret
202
    ret
203
endp
203
endp
204
 
204
 
205
;;
205
;;
206
;; snd_hda_get_connections - get connection list
206
;; snd_hda_get_connections - get connection list
207
;; @codec: the HDA codec
207
;; @codec: the HDA codec
208
;; @nid: NID to parse
208
;; @nid: NID to parse
209
;; @conn_list: connection list array
209
;; @conn_list: connection list array
210
;; @max_conns: max. number of connections to store
210
;; @max_conns: max. number of connections to store
211
;;
211
;;
212
;; Parses the connection list of the given widget and stores the list
212
;; Parses the connection list of the given widget and stores the list
213
;; of NIDs.
213
;; of NIDs.
214
;;
214
;;
215
;; Returns the number of connections, or a negative error code.
215
;; Returns the number of connections, or a negative error code.
216
;;
216
;;
217
proc  snd_hda_get_connections stdcall, nid:dword, conn_list:dword, max_conns:dword   ;Asper: Complete translation!
217
proc  snd_hda_get_connections stdcall, nid:dword, conn_list:dword, max_conns:dword   ;Asper: Complete translation!
218
    locals
218
    locals
219
       parm          dd ?
219
       parm          dd ?
220
       conn_len      dd ?
220
       conn_len      dd ?
221
       conns         dd 0
221
       conns         dd 0
222
       shift         db 8
222
       shift         db 8
223
       num_elements  dd 4
223
       num_elements  dd 4
224
       mask          dd 0x7F
224
       mask          dd 0x7F
225
       wcaps         dd ?
225
       wcaps         dd ?
226
       prev_nid      dw 1 ;Asper: Hmm.. Probably ALSA bug that it isn't initialized. I suppose to init it with 1.
226
       prev_nid      dw 1 ;Asper: Hmm.. Probably ALSA bug that it isn't initialized. I suppose to init it with 1.
227
    endl
227
    endl
228
 
228
 
229
    push     ebx ecx edx edi esi
229
    push     ebx ecx edx edi esi
230
    mov      edi, [conn_list]
230
    mov      edi, [conn_list]
231
    test     edi, edi
231
    test     edi, edi
232
    jz       .err_out
232
    jz       .err_out
233
    mov      ecx, [max_conns]
233
    mov      ecx, [max_conns]
234
    cmp      ecx, 0
234
    cmp      ecx, 0
235
    jle      .err_out
235
    jle      .err_out
236
 
236
 
237
 
237
 
238
    stdcall  get_wcaps, [nid]
238
    stdcall  get_wcaps, [nid]
239
    mov      ebx, eax
239
    mov      ebx, eax
240
    mov      [wcaps], eax
240
    mov      [wcaps], eax
241
    stdcall  get_wcaps_type, ebx
241
    stdcall  get_wcaps_type, ebx
242
    cmp      eax, AC_WID_VOL_KNB
242
    cmp      eax, AC_WID_VOL_KNB
243
    je       .conn_list_ok
243
    je       .conn_list_ok
244
    test     ebx, AC_WCAP_CONN_LIST
244
    test     ebx, AC_WCAP_CONN_LIST
245
    jnz      .conn_list_ok
245
    jnz      .conn_list_ok
246
  if DEBUG
246
  if DEBUG
247
    mov      esi, emsgConnListNotAvailable
247
    mov      esi, emsgConnListNotAvailable
248
    call     SysMsgBoardStr
248
    call     SysMsgBoardStr
249
    mov      eax, [nid]
249
    mov      eax, [nid]
250
    stdcall fdword2str, 3
250
    stdcall fdword2str, 3
251
    call     SysMsgBoardStr
251
    call     SysMsgBoardStr
252
  end if
252
  end if
253
    xor      eax, eax
253
    xor      eax, eax
254
    dec      eax
254
    dec      eax
255
    jmp      .out
255
    jmp      .out
256
  .conn_list_ok:
256
  .conn_list_ok:
257
 
257
 
258
    snd_hda_param_read  [nid], AC_PAR_CONNLIST_LEN
258
    snd_hda_param_read  [nid], AC_PAR_CONNLIST_LEN
259
    mov      [parm], eax
259
    mov      [parm], eax
260
 
260
 
261
    test     eax, AC_CLIST_LONG
261
    test     eax, AC_CLIST_LONG
262
    jz       @f
262
    jz       @f
263
    ; long form
263
    ; long form
264
    mov      [shift], 16
264
    mov      [shift], 16
265
    mov      [num_elements], 2
265
    mov      [num_elements], 2
266
    mov      [mask], 0x7FFF ;Asper+
266
    mov      [mask], 0x7FFF ;Asper+
267
  @@:
267
  @@:
268
    and      eax, AC_CLIST_LENGTH
268
    and      eax, AC_CLIST_LENGTH
269
    test     eax, eax
269
    test     eax, eax
270
    jz       .out ; no connection
270
    jz       .out ; no connection
271
 
271
 
272
    mov      [conn_len], eax
272
    mov      [conn_len], eax
273
    cmp      eax, 1
273
    cmp      eax, 1
274
    jne      .multi_conns
274
    jne      .multi_conns
275
    ; single connection
275
    ; single connection
276
    stdcall  snd_hda_codec_read, [nid], 0, AC_VERB_GET_CONNECT_LIST, 0
276
    stdcall  snd_hda_codec_read, [nid], 0, AC_VERB_GET_CONNECT_LIST, 0
277
    mov      [parm], eax
277
    mov      [parm], eax
278
    cmp      [parm], -1
278
    cmp      [parm], -1
279
    jne      @f
279
    jne      @f
280
    cmp      [ctrl.rirb_error], 0
280
    cmp      [ctrl.rirb_error], 0
281
    jne      @f
281
    jne      @f
282
    xor      eax, eax
282
    xor      eax, eax
283
    dec      eax
283
    dec      eax
284
    jmp      .out
284
    jmp      .out
285
  @@:
285
  @@:
286
 
286
 
287
    mov      eax, [parm]
287
    mov      eax, [parm]
288
    and      eax, [mask]
288
    and      eax, [mask]
289
    stosd
289
    stosd
290
    xor      eax, eax
290
    xor      eax, eax
291
    inc      eax
291
    inc      eax
292
    jmp      .out
292
    jmp      .out
293
  .multi_conns:
293
  .multi_conns:
294
 
294
 
295
    ; multi connection
295
    ; multi connection
296
    xor      ecx, ecx
296
    xor      ecx, ecx
297
    mov      edx, [num_elements]
297
    mov      edx, [num_elements]
298
  .next_conn:
298
  .next_conn:
299
    mov      eax, ecx
299
    mov      eax, ecx
300
  .mod:
300
  .mod:
301
    cmp      eax, edx
301
    cmp      eax, edx
302
    jl       .mod_counted
302
    jl       .mod_counted
303
    sub      eax, edx
303
    sub      eax, edx
304
    jmp      .mod
304
    jmp      .mod
305
  .mod_counted:
305
  .mod_counted:
306
 
306
 
307
    test     eax, eax
307
    test     eax, eax
308
    jnz      .l1
308
    jnz      .l1
309
    stdcall  snd_hda_codec_read, [nid], 0, AC_VERB_GET_CONNECT_LIST, ecx
309
    stdcall  snd_hda_codec_read, [nid], 0, AC_VERB_GET_CONNECT_LIST, ecx
310
    mov      [parm], eax
310
    mov      [parm], eax
311
 
311
 
312
    cmp      eax, -1
312
    cmp      eax, -1
313
    jne      .l1
313
    jne      .l1
314
    cmp      [ctrl.rirb_error], 0
314
    cmp      [ctrl.rirb_error], 0
315
    jne      .err_out
315
    jne      .err_out
316
  .l1:
316
  .l1:
317
 
317
 
318
    mov      eax, 1
318
    mov      eax, 1
319
    push     ecx
319
    push     ecx
320
    mov      cl, [shift]
320
    mov      cl, [shift]
321
    dec      cl
321
    dec      cl
322
    shl      eax, cl
322
    shl      eax, cl
323
    and      eax, [parm]
323
    and      eax, [parm]
324
    pop      ecx
324
    pop      ecx
325
    mov      ebx, eax  ;ranges
325
    mov      ebx, eax  ;ranges
326
 
326
 
327
    mov      eax, [parm]
327
    mov      eax, [parm]
328
    and      eax, [mask] ;val
328
    and      eax, [mask] ;val
329
 
329
 
330
    test     eax, eax
330
    test     eax, eax
331
    jnz      @f
331
    jnz      @f
332
 if DEBUG
332
 if DEBUG
333
    push     eax esi
333
    push     eax esi
334
    mov      esi, emsgInvConnList
334
    mov      esi, emsgInvConnList
335
    call     SysMsgBoardStr
335
    call     SysMsgBoardStr
336
    mov      eax, [nid]
336
    mov      eax, [nid]
337
    stdcall  fdword2str, 1
337
    stdcall  fdword2str, 1
338
    call     SysMsgBoardStr
338
    call     SysMsgBoardStr
339
 
339
 
340
    mov      esi, strSemicolon
340
    mov      esi, strSemicolon
341
    call     SysMsgBoardStr
341
    call     SysMsgBoardStr
342
    mov      eax, ecx
342
    mov      eax, ecx
343
    stdcall  fdword2str, 0
343
    stdcall  fdword2str, 0
344
    call     SysMsgBoardStr
344
    call     SysMsgBoardStr
345
 
345
 
346
    mov      esi, strSemicolon
346
    mov      esi, strSemicolon
347
    call     SysMsgBoardStr
347
    call     SysMsgBoardStr
348
    mov      eax, [parm]
348
    mov      eax, [parm]
349
    stdcall  fdword2str, 2
349
    stdcall  fdword2str, 2
350
    call     SysMsgBoardStr
350
    call     SysMsgBoardStr
351
    pop      esi eax
351
    pop      esi eax
352
 end if
352
 end if
353
    xor      eax, eax
353
    xor      eax, eax
354
    jmp      .out
354
    jmp      .out
355
  @@:
355
  @@:
356
    push     ecx
356
    push     ecx
357
    mov      cl, [shift]
357
    mov      cl, [shift]
358
    shr      [parm], cl
358
    shr      [parm], cl
359
    pop      ecx
359
    pop      ecx
360
 
360
 
361
    test     ebx, ebx
361
    test     ebx, ebx
362
    jz       .range_zero
362
    jz       .range_zero
363
    ; ranges between the previous and this one
363
    ; ranges between the previous and this one
364
    movzx    esi, word [prev_nid]
364
    movzx    esi, word [prev_nid]
365
    test     esi, esi
365
    test     esi, esi
366
    jz       .l2
366
    jz       .l2
367
    cmp      esi, eax
367
    cmp      esi, eax
368
    jl       @f
368
    jl       @f
369
  .l2:
369
  .l2:
370
 if DEBUG
370
 if DEBUG
371
    push     eax esi
371
    push     eax esi
372
    push     esi
372
    push     esi
373
    mov      esi, emsgInvDepRangeVal
373
    mov      esi, emsgInvDepRangeVal
374
    call     SysMsgBoardStr
374
    call     SysMsgBoardStr
375
    pop      esi
375
    pop      esi
376
    push     eax
376
    push     eax
377
    mov      eax, esi
377
    mov      eax, esi
378
    stdcall  fdword2str, 0
378
    stdcall  fdword2str, 0
379
    call     SysMsgBoardStr
379
    call     SysMsgBoardStr
380
 
380
 
381
    mov      esi, strSemicolon
381
    mov      esi, strSemicolon
382
    call     SysMsgBoardStr
382
    call     SysMsgBoardStr
383
    pop      eax
383
    pop      eax
384
    stdcall  fdword2str, 2
384
    stdcall  fdword2str, 2
385
    call     SysMsgBoardStr
385
    call     SysMsgBoardStr
386
    pop      esi eax
386
    pop      esi eax
387
 end if
387
 end if
388
    jmp      .continue
388
    jmp      .continue
389
  @@:
389
  @@:
390
    push     ecx
390
    push     ecx
391
    mov      ecx, esi
391
    mov      ecx, esi
392
    inc      ecx
392
    inc      ecx
393
    mov      ebx, [conns]
393
    mov      ebx, [conns]
394
  .next_conn2:
394
  .next_conn2:
395
    cmp      ebx, [max_conns]
395
    cmp      ebx, [max_conns]
396
    jl       @f
396
    jl       @f
397
 if DEBUG
397
 if DEBUG
398
    push     esi
398
    push     esi
399
    mov      esi, emsgTooManyConns
399
    mov      esi, emsgTooManyConns
400
    call     SysMsgBoardStr
400
    call     SysMsgBoardStr
401
    pop      esi
401
    pop      esi
402
 end if
402
 end if
403
    pop      ecx
403
    pop      ecx
404
    jmp      .err_out
404
    jmp      .err_out
405
  @@:
405
  @@:
406
    shl      ebx, 1
406
    shl      ebx, 1
407
    push     edi
407
    push     edi
408
    add      edi, ebx
408
    add      edi, ebx
409
    mov      word [edi], cx
409
    mov      word [edi], cx
410
    pop      edi
410
    pop      edi
411
    shr      ebx, 1
411
    shr      ebx, 1
412
    inc      ebx
412
    inc      ebx
413
    inc      ecx
413
    inc      ecx
414
    cmp      ecx, eax
414
    cmp      ecx, eax
415
    jle      .next_conn2
415
    jle      .next_conn2
416
 
416
 
417
    mov      [conns], ebx
417
    mov      [conns], ebx
418
    pop      ecx
418
    pop      ecx
419
    jmp      .end_range_test
419
    jmp      .end_range_test
420
  .range_zero:
420
  .range_zero:
421
 
421
 
422
    mov      ebx, [conns]
422
    mov      ebx, [conns]
423
    cmp      ebx, [max_conns]
423
    cmp      ebx, [max_conns]
424
    jl       @f
424
    jl       @f
425
 if DEBUG
425
 if DEBUG
426
    push     esi
426
    push     esi
427
    mov      esi, emsgTooManyConns
427
    mov      esi, emsgTooManyConns
428
    call     SysMsgBoardStr
428
    call     SysMsgBoardStr
429
    pop      esi
429
    pop      esi
430
 end if
430
 end if
431
    jmp      .err_out
431
    jmp      .err_out
432
  @@:
432
  @@:
433
    shl      ebx, 1
433
    shl      ebx, 1
434
    push     edi
434
    push     edi
435
    add      edi, ebx
435
    add      edi, ebx
436
    mov      word [edi], ax
436
    mov      word [edi], ax
437
    pop      edi
437
    pop      edi
438
    shr      ebx, 1
438
    shr      ebx, 1
439
    inc      ebx
439
    inc      ebx
440
    mov      [conns], ebx
440
    mov      [conns], ebx
441
  .end_range_test:
441
  .end_range_test:
442
    mov      [prev_nid], ax
442
    mov      [prev_nid], ax
443
  .continue:
443
  .continue:
444
    inc      ecx
444
    inc      ecx
445
    cmp      ecx, [conn_len]
445
    cmp      ecx, [conn_len]
446
    jl       .next_conn
446
    jl       .next_conn
447
 
447
 
448
     mov     eax, [conns]
448
     mov     eax, [conns]
449
  .out:
449
  .out:
450
     pop     esi edi edx ecx ebx
450
     pop     esi edi edx ecx ebx
451
     ret
451
     ret
452
  .err_out:
452
  .err_out:
453
     pop     esi edi edx ecx ebx
453
     pop     esi edi edx ecx ebx
454
     mov     eax, -1
454
     mov     eax, -1
455
     ret
455
     ret
456
endp
456
endp
457
 
457
 
458
 
458
 
459
; Asper: Have to be realized later, when we will work with such events, but not NOW!
459
; Asper: Have to be realized later, when we will work with such events, but not NOW!
460
;proc  snd_hda_queue_unsol_events stdcall, res:dword, res_ex:dword
460
;proc  snd_hda_queue_unsol_events stdcall, res:dword, res_ex:dword
461
;    push     ebx  edi  esi
461
;    push     ebx  edi  esi
462
;    ...
462
;    ...
463
;    pop      esi  edi  ebx
463
;    pop      esi  edi  ebx
464
;    ret
464
;    ret
465
;endp
465
;endp
466
 
466
 
467
; This functions also will be later realized.
467
; This functions also will be later realized.
468
;proc  process_unsol_events stdcall, work:dword
468
;proc  process_unsol_events stdcall, work:dword
469
;proc  init_usol_queue stdcall, bus:dword
469
;proc  init_usol_queue stdcall, bus:dword
470
 
470
 
471
;;
471
;;
472
;; snd_hda_bus_new - create a HDA bus
472
;; snd_hda_bus_new - create a HDA bus
473
;; @card: the card entry
473
;; @card: the card entry
474
;; @temp: the template for hda_bus information
474
;; @temp: the template for hda_bus information
475
;; @busp: the pointer to store the created bus instance
475
;; @busp: the pointer to store the created bus instance
476
;;
476
;;
477
;; Returns 0 if successful, or a negative error code.
477
;; Returns 0 if successful, or a negative error code.
478
;;
478
;;
479
;proc  snd_hda_bus_new
479
;proc  snd_hda_bus_new
480
    ; if we want to support unsolicited events, we have to solve this
480
    ; if we want to support unsolicited events, we have to solve this
481
    ;    bus->workq = create_singlethread_workqueue(bus->workq_name);
481
    ;    bus->workq = create_singlethread_workqueue(bus->workq_name);
482
    ; (...)
482
    ; (...)
483
;    xor   eax, eax
483
;    xor   eax, eax
484
;    ret
484
;    ret
485
;endp
485
;endp
486
 
486
 
487
;;
487
;;
488
;; snd_hda_codec_init - initialize a HDA codec
488
;; snd_hda_codec_init - initialize a HDA codec
489
;;
489
;;
490
;; Returns 0 if successful, or a negative error code.
490
;; Returns 0 if successful, or a negative error code.
491
;;
491
;;
492
proc  snd_hda_codec_init    ; We use just one codec (the first found)
492
proc  snd_hda_codec_init    ; We use just one codec (the first found)
493
     snd_hda_param_read  AC_NODE_ROOT, AC_PAR_VENDOR_ID
493
     snd_hda_param_read  AC_NODE_ROOT, AC_PAR_VENDOR_ID
494
     cmp     eax, -1
494
     cmp     eax, -1
495
     jne     @f
495
     jne     @f
496
     snd_hda_param_read  AC_NODE_ROOT, AC_PAR_VENDOR_ID
496
     snd_hda_param_read  AC_NODE_ROOT, AC_PAR_VENDOR_ID
497
  @@:
497
  @@:
498
     mov     [codec.chip_id], ax
498
     mov     [codec.chip_id], ax
499
     shr     eax, 16
499
     shr     eax, 16
500
     mov     [codec.vendor_id], ax
500
     mov     [codec.vendor_id], ax
501
 
501
 
502
     snd_hda_param_read  AC_NODE_ROOT, AC_PAR_SUBSYSTEM_ID
502
     snd_hda_param_read  AC_NODE_ROOT, AC_PAR_SUBSYSTEM_ID
503
     mov     [codec.subsystem_id], eax
503
     mov     [codec.subsystem_id], eax
504
 
504
 
505
     snd_hda_param_read  AC_NODE_ROOT, AC_PAR_REV_ID
505
     snd_hda_param_read  AC_NODE_ROOT, AC_PAR_REV_ID
506
     mov     [codec.revision_id], eax
506
     mov     [codec.revision_id], eax
507
 
507
 
508
     stdcall setup_fg_nodes
508
     stdcall setup_fg_nodes
509
 
509
 
510
     mov     eax, [codec.afg]
510
     mov     eax, [codec.afg]
511
     test    eax, eax
511
     test    eax, eax
512
     jnz     @f
512
     jnz     @f
513
 
513
 
514
     ;Asper+: try to use another codec if possible [
514
     ;Asper+: try to use another codec if possible [
515
  if DEBUG
515
  if DEBUG
516
     push    esi
516
     push    esi
517
     mov     esi, msgNoAFGFound
517
     mov     esi, msgNoAFGFound
518
     call    SysMsgBoardStr
518
     call    SysMsgBoardStr
519
     pop     esi
519
     pop     esi
520
  end  if
520
  end  if
521
     push    ecx
521
     push    ecx
522
     inc     eax
522
     inc     eax
523
     mov     ecx, [codec.addr]
523
     mov     ecx, [codec.addr]
524
     shl     eax, cl
524
     shl     eax, cl
525
     pop     ecx
525
     pop     ecx
526
     cmp     eax, [ctrl.codec_mask]
526
     cmp     eax, [ctrl.codec_mask]
527
     jl      .skip_codec
527
     jl      .skip_codec
528
     ;Asper+]
528
     ;Asper+]
529
 
529
 
530
     mov     eax, [codec.mfg]
530
     mov     eax, [codec.mfg]
531
     test    eax, eax
531
     test    eax, eax
532
     jnz     @f
532
     jnz     @f
533
  if DEBUG
533
  if DEBUG
534
     push    esi
534
     push    esi
535
     mov     esi, emsgNoAFGorMFGFound
535
     mov     esi, emsgNoAFGorMFGFound
536
     call    SysMsgBoardStr
536
     call    SysMsgBoardStr
537
     pop     esi
537
     pop     esi
538
  end  if
538
  end  if
539
  .skip_codec:
539
  .skip_codec:
540
     mov     eax, -1
540
     mov     eax, -1
541
     ret
541
     ret
542
  @@:
542
  @@:
543
 
543
 
544
     mov     ebx, eax
544
     mov     ebx, eax
545
     push    ebx
545
     push    ebx
546
     stdcall read_widget_caps, eax
546
     stdcall read_widget_caps, eax
547
 
547
 
548
     cmp     eax, 0
548
     cmp     eax, 0
549
     jge     @f
549
     jge     @f
550
  if DEBUG
550
  if DEBUG
551
     push    esi
551
     push    esi
552
     mov     esi, emsgNoMem
552
     mov     esi, emsgNoMem
553
     call    SysMsgBoardStr
553
     call    SysMsgBoardStr
554
     pop     esi
554
     pop     esi
555
  end  if
555
  end  if
556
     pop     ebx
556
     pop     ebx
557
     mov     eax, -1
557
     mov     eax, -1
558
     ret
558
     ret
559
  @@:
559
  @@:
560
 
560
 
561
     call read_pin_defaults
561
     call read_pin_defaults
562
 
562
 
563
     cmp     eax, 0
563
     cmp     eax, 0
564
     jge     @f
564
     jge     @f
565
     pop     ebx
565
     pop     ebx
566
     mov     eax, -1
566
     mov     eax, -1
567
     ret
567
     ret
568
  @@:
568
  @@:
569
     mov     eax, [codec.subsystem_id]
569
     mov     eax, [codec.subsystem_id]
570
     test    eax, eax
570
     test    eax, eax
571
     jnz     @f
571
     jnz     @f
572
     stdcall snd_hda_codec_read, ebx, 0, AC_VERB_GET_SUBSYSTEM_ID, 0
572
     stdcall snd_hda_codec_read, ebx, 0, AC_VERB_GET_SUBSYSTEM_ID, 0
573
 
573
 
574
  @@:
574
  @@:
575
 
575
 
576
     ; power up all before initialization
576
     ; power up all before initialization
577
     stdcall snd_hda_set_power_state, ebx, AC_PWRST_D0
577
     stdcall snd_hda_set_power_state, ebx, AC_PWRST_D0
578
 
578
 
579
     xor     eax, eax
579
     xor     eax, eax
580
     pop     ebx
580
     pop     ebx
581
     ret
581
     ret
582
endp
582
endp
583
 
583
 
584
 
584
 
585
;;
585
;;
586
;; snd_hda_codec_configure - (Re-)configure the HD-audio codec
586
;; snd_hda_codec_configure - (Re-)configure the HD-audio codec
587
;;
587
;;
588
;; Start parsing of the given codec tree and (re-)initialize the whole
588
;; Start parsing of the given codec tree and (re-)initialize the whole
589
;; patch instance.
589
;; patch instance.
590
;;
590
;;
591
;; Returns 0 if successful or a negative error code.
591
;; Returns 0 if successful or a negative error code.
592
;;
592
;;
593
proc  snd_hda_codec_configure
593
proc  snd_hda_codec_configure
594
     call    get_codec_name
594
     call    get_codec_name
595
  @@:
595
  @@:
596
     ; call the default parser
596
     ; call the default parser
597
     stdcall snd_hda_parse_generic_codec  ;entry point to generic tree parser!!!
597
     stdcall snd_hda_parse_generic_codec  ;entry point to generic tree parser!!!
598
 
598
 
599
     test    eax, eax
599
     test    eax, eax
600
     jz      @f
600
     jz      @f
601
  if DEBUG
601
  if DEBUG
602
     push    esi
602
     push    esi
603
     mov     esi, emsgNoParserAvailable
603
     mov     esi, emsgNoParserAvailable
604
     call    SysMsgBoardStr
604
     call    SysMsgBoardStr
605
     pop     esi
605
     pop     esi
606
  end if
606
  end if
607
  @@:
607
  @@:
608
  .out:
608
  .out:
609
     ret
609
     ret
610
endp
610
endp
611
 
611
 
612
 
612
 
613
; get_codec_name - store the codec name
613
; get_codec_name - store the codec name
614
proc  get_codec_name
614
proc  get_codec_name
615
     push    eax  ebx  edi  esi
615
     push    eax  ebx  edi  esi
616
     mov     eax, [codec.ac_vendor_ids]
616
     mov     eax, [codec.ac_vendor_ids]
617
     test    eax, eax
617
     test    eax, eax
618
     jnz     .get_chip_name
618
     jnz     .get_chip_name
619
     mov     ax, [codec.vendor_id]
619
     mov     ax, [codec.vendor_id]
620
     mov     edi, hda_vendor_ids
620
     mov     edi, hda_vendor_ids
621
 
621
 
622
  @@:
622
  @@:
623
     mov     ebx, [edi]
623
     mov     ebx, [edi]
624
     test    ebx, ebx
624
     test    ebx, ebx
625
     jz      .unknown
625
     jz      .unknown
626
 
626
 
627
     cmp     ax, bx
627
     cmp     ax, bx
628
     jne     .next
628
     jne     .next
629
     mov     eax, [edi+4]
629
     mov     eax, [edi+4]
630
     mov     [codec.ac_vendor_ids], eax
630
     mov     [codec.ac_vendor_ids], eax
631
     mov     esi, eax
631
     mov     esi, eax
632
     call    SysMsgBoardStr
632
     call    SysMsgBoardStr
633
  .get_chip_name:
633
  .get_chip_name:
634
     stdcall detect_chip, [edi+8]
634
     stdcall detect_chip, [edi+8]
635
     pop     esi  edi  ebx  eax
635
     pop     esi  edi  ebx  eax
636
     ret
636
     ret
637
  .next:
637
  .next:
638
     add     edi, 12
638
     add     edi, 12
639
     jmp     @b
639
     jmp     @b
640
  .unknown:
640
  .unknown:
641
     mov     [codec.ac_vendor_ids], ac_unknown
641
     mov     [codec.ac_vendor_ids], ac_unknown
642
     mov     [codec.chip_ids], chip_unknown
642
     mov     [codec.chip_ids], chip_unknown
643
 
643
 
644
     mov     esi, chip_unknown
644
     mov     esi, chip_unknown
645
     call    SysMsgBoardStr
645
     call    SysMsgBoardStr
646
     movzx   eax, [codec.chip_id]
646
     movzx   eax, [codec.chip_id]
647
     stdcall fdword2str, 2
647
     stdcall fdword2str, 2
648
     call    SysMsgBoardStr
648
     call    SysMsgBoardStr
649
     pop     esi  edi  ebx  eax
649
     pop     esi  edi  ebx  eax
650
     ret
650
     ret
651
endp
651
endp
652
 
652
 
653
 
653
 
654
align 4
654
align 4
655
proc detect_chip stdcall, chip_tab:dword
655
proc detect_chip stdcall, chip_tab:dword
656
 
656
 
657
     push    eax  ebx  edi  esi
657
     push    eax  ebx  edi  esi
658
     mov     ax, [codec.chip_id]
658
     mov     ax, [codec.chip_id]
659
 
659
 
660
     mov     edi, [chip_tab]
660
     mov     edi, [chip_tab]
661
@@:
661
@@:
662
     mov     ebx, [edi]
662
     mov     ebx, [edi]
663
     cmp     ebx, 0xFF
663
     cmp     ebx, 0xFF
664
     je      .unknown
664
     je      .unknown
665
 
665
 
666
     cmp     ax, bx
666
     cmp     ax, bx
667
     jne     .next
667
     jne     .next
668
     mov     eax, [edi+4]
668
     mov     eax, [edi+4]
669
     mov     [codec.chip_ids], eax
669
     mov     [codec.chip_ids], eax
670
     mov     esi, eax
670
     mov     esi, eax
671
     call    SysMsgBoardStr
671
     call    SysMsgBoardStr
672
     pop     esi  edi  ebx  eax
672
     pop     esi  edi  ebx  eax
673
     ret
673
     ret
674
.next:
674
.next:
675
     add     edi, 8
675
     add     edi, 8
676
     jmp     @b
676
     jmp     @b
677
.unknown:
677
.unknown:
678
     mov     [codec.chip_ids], chip_unknown
678
     mov     [codec.chip_ids], chip_unknown
679
     mov     esi, chip_unknown
679
     mov     esi, chip_unknown
680
     call    SysMsgBoardStr
680
     call    SysMsgBoardStr
681
     movzx   eax, [codec.chip_id]
681
     movzx   eax, [codec.chip_id]
682
     stdcall fdword2str, 2
682
     stdcall fdword2str, 2
683
     call    SysMsgBoardStr
683
     call    SysMsgBoardStr
684
     pop     esi  edi  ebx  eax
684
     pop     esi  edi  ebx  eax
685
     ret
685
     ret
686
endp
686
endp
687
 
687
 
688
 
688
 
689
;; look for an AFG and MFG nodes
689
;; look for an AFG and MFG nodes
690
proc setup_fg_nodes
690
proc setup_fg_nodes
691
     push    eax  ebx  ecx
691
     push    eax  ebx  ecx
692
     stdcall snd_hda_get_sub_nodes, AC_NODE_ROOT
692
     stdcall snd_hda_get_sub_nodes, AC_NODE_ROOT
693
     mov     ecx, eax
693
     mov     ecx, eax
694
     and     ecx, 0x7FFF ; total_nodes
694
     and     ecx, 0x7FFF ; total_nodes
695
     mov     ebx, eax
695
     mov     ebx, eax
696
     shr     ebx, 16
696
     shr     ebx, 16
697
     and     ebx, 0x7FFF ; nid
697
     and     ebx, 0x7FFF ; nid
698
 
698
 
699
if DEBUG    ;YAHOO
699
if DEBUG    ;YAHOO
700
     push    eax esi
700
     push    eax esi
701
     mov     esi, msgSETUP_FG_NODES
701
     mov     esi, msgSETUP_FG_NODES
702
     call    SysMsgBoardStr
702
     call    SysMsgBoardStr
703
     mov     eax, ebx
703
     mov     eax, ebx
704
     stdcall fdword2str, 1
704
     stdcall fdword2str, 1
705
     call    SysMsgBoardStr
705
     call    SysMsgBoardStr
706
 
706
 
707
     mov     esi, strSemicolon
707
     mov     esi, strSemicolon
708
     call    SysMsgBoardStr
708
     call    SysMsgBoardStr
709
     mov     eax, ecx
709
     mov     eax, ecx
710
     stdcall fdword2str, 3
710
     stdcall fdword2str, 3
711
     call    SysMsgBoardStr
711
     call    SysMsgBoardStr
712
     pop     esi eax
712
     pop     esi eax
713
end if
713
end if
714
 
714
 
715
  .next:
715
  .next:
716
     test    ecx, ecx
716
     test    ecx, ecx
717
     jz      .l1
717
     jz      .l1
718
     snd_hda_param_read  ebx, AC_PAR_FUNCTION_TYPE
718
     snd_hda_param_read  ebx, AC_PAR_FUNCTION_TYPE
719
     and     eax, 0xFF
719
     and     eax, 0xFF
720
 
720
 
721
if DEBUG    ;YAHOO
721
if DEBUG    ;YAHOO
722
     push    eax esi
722
     push    eax esi
723
     mov     esi, msgFG_TYPE
723
     mov     esi, msgFG_TYPE
724
     call    SysMsgBoardStr
724
     call    SysMsgBoardStr
725
     stdcall fdword2str, 3
725
     stdcall fdword2str, 3
726
     call    SysMsgBoardStr
726
     call    SysMsgBoardStr
727
     pop     esi eax
727
     pop     esi eax
728
end if
728
end if
729
 
729
 
730
     cmp     eax, AC_GRP_AUDIO_FUNCTION
730
     cmp     eax, AC_GRP_AUDIO_FUNCTION
731
     jne     @f
731
     jne     @f
732
 
732
 
733
     mov     [codec.afg], ebx
733
     mov     [codec.afg], ebx
734
     mov     [codec.function_id], eax
734
     mov     [codec.function_id], eax
735
     jmp     .continue
735
     jmp     .continue
736
  @@:
736
  @@:
737
     cmp     eax, AC_GRP_MODEM_FUNCTION
737
     cmp     eax, AC_GRP_MODEM_FUNCTION
738
     jne     @f
738
     jne     @f
739
 
739
 
740
     mov     [codec.mfg], ebx
740
     mov     [codec.mfg], ebx
741
     mov     [codec.function_id], eax
741
     mov     [codec.function_id], eax
742
     jmp     .continue
742
     jmp     .continue
743
  @@:
743
  @@:
744
  .continue:
744
  .continue:
745
     inc     ebx
745
     inc     ebx
746
     dec     ecx
746
     dec     ecx
747
     jnz     .next
747
     jnz     .next
748
  .l1:
748
  .l1:
749
     pop     ecx  ebx  eax
749
     pop     ecx  ebx  eax
750
     ret
750
     ret
751
endp
751
endp
752
 
752
 
753
 
753
 
754
;======================================================================================
754
;======================================================================================
755
; read widget caps for each widget and store in cache
755
; read widget caps for each widget and store in cache
756
proc  read_widget_caps stdcall, fg_node:dword
756
proc  read_widget_caps stdcall, fg_node:dword
757
     push    ebx ecx edx edi
757
     push    ebx ecx edx edi
758
 
758
 
759
     stdcall snd_hda_get_sub_nodes, [fg_node]
759
     stdcall snd_hda_get_sub_nodes, [fg_node]
760
     mov     ecx, eax
760
     mov     ecx, eax
761
     and     ecx, 0x7FFF ; total_nodes
761
     and     ecx, 0x7FFF ; total_nodes
762
     mov     [codec.num_nodes], cx
762
     mov     [codec.num_nodes], cx
763
     mov     ebx, eax
763
     mov     ebx, eax
764
     shr     ebx, 16
764
     shr     ebx, 16
765
     and     ebx, 0x7FFF ; nid
765
     and     ebx, 0x7FFF ; nid
766
     mov     [codec.start_nid], bx
766
     mov     [codec.start_nid], bx
767
 
767
 
768
if DEBUG    ;YAHOO
768
if DEBUG    ;YAHOO
769
     push    eax esi
769
     push    eax esi
770
     mov     esi, msgSETUP_FG_NODES
770
     mov     esi, msgSETUP_FG_NODES
771
     call    SysMsgBoardStr
771
     call    SysMsgBoardStr
772
     mov     eax, ebx
772
     mov     eax, ebx
773
     stdcall fdword2str, 1
773
     stdcall fdword2str, 1
774
     call    SysMsgBoardStr
774
     call    SysMsgBoardStr
775
 
775
 
776
     mov     esi, strSemicolon
776
     mov     esi, strSemicolon
777
     call    SysMsgBoardStr
777
     call    SysMsgBoardStr
778
     mov     eax, ecx
778
     mov     eax, ecx
779
     stdcall fdword2str, 3
779
     stdcall fdword2str, 3
780
     call    SysMsgBoardStr
780
     call    SysMsgBoardStr
781
     pop     esi eax
781
     pop     esi eax
782
end if
782
end if
783
 
783
 
784
if FDEBUG    ;YAHOO
784
if FDEBUG    ;YAHOO
785
     push    esi
785
     push    esi
786
     mov     esi, msgWCaps
786
     mov     esi, msgWCaps
787
     call    SysMsgBoardStr
787
     call    SysMsgBoardStr
788
     pop     esi
788
     pop     esi
789
end if
789
end if
790
 
790
 
791
     mov     eax, ecx
791
     mov     eax, ecx
792
     shl     eax, 2
792
     shl     eax, 2
793
     push    ebx ecx
793
     push    ebx ecx
794
     call    Kmalloc
794
     call    Kmalloc
795
     pop     ecx ebx
795
     pop     ecx ebx
796
     test    eax, eax
796
     test    eax, eax
797
     jz      .err_out
797
     jz      .err_out
798
     mov     [codec.wcaps], eax
798
     mov     [codec.wcaps], eax
799
 
799
 
800
     mov     edi, eax
800
     mov     edi, eax
801
  .next_node:
801
  .next_node:
802
 
802
 
803
     snd_hda_param_read  ebx, AC_PAR_AUDIO_WIDGET_CAP
803
     snd_hda_param_read  ebx, AC_PAR_AUDIO_WIDGET_CAP
804
     stosd
804
     stosd
805
     inc     ebx
805
     inc     ebx
806
     dec     ecx
806
     dec     ecx
807
     jnz     .next_node
807
     jnz     .next_node
808
     pop     edi edx ecx ebx
808
     pop     edi edx ecx ebx
809
     xor     eax, eax
809
     xor     eax, eax
810
     ret
810
     ret
811
  .err_out:
811
  .err_out:
812
     pop     edi edx ecx ebx
812
     pop     edi edx ecx ebx
813
     xor     eax, eax
813
     xor     eax, eax
814
     dec     eax
814
     dec     eax
815
     ret
815
     ret
816
endp
816
endp
817
 
817
 
818
 
818
 
819
; read all pin default configurations and save codec->init_pins
819
; read all pin default configurations and save codec->init_pins
820
proc  read_pin_defaults
820
proc  read_pin_defaults
821
     push    ebx ecx edx edi
821
     push    ebx ecx edx edi
822
 
822
 
823
     movzx   ebx, [codec.start_nid]
823
     movzx   ebx, [codec.start_nid]
824
     movzx   ecx, [codec.num_nodes]
824
     movzx   ecx, [codec.num_nodes]
825
 
825
 
826
     ;Asper [
826
     ;Asper [
827
     mov     eax, HDA_PINCFG.sizeof
827
     mov     eax, HDA_PINCFG.sizeof
828
     mul     cl
828
     mul     cl
829
     push    ebx ecx
829
     push    ebx ecx
830
     call    Kmalloc
830
     call    Kmalloc
831
     pop     ecx ebx
831
     pop     ecx ebx
832
     test    eax, eax
832
     test    eax, eax
833
     jz      .err_out
833
     jz      .err_out
834
     mov     [codec.init_pins], eax
834
     mov     [codec.init_pins], eax
835
     mov     edi, eax
835
     mov     [codec.num_pins], 0
-
 
836
     mov     edi, eax
836
     ;Asper ]
837
     ;Asper ]
837
 
838
 
838
if FDEBUG
839
if FDEBUG
839
   push   eax esi
840
   push   eax esi
840
   mov    esi, msgPinCfgs
841
   mov    esi, msgPinCfgs
841
   call   SysMsgBoardStr
842
   call   SysMsgBoardStr
842
   pop    esi eax
843
   pop    esi eax
843
end if
844
end if
844
 
845
 
845
 
846
 
846
  .next_node:
847
  .next_node:
847
     stdcall get_wcaps, ebx
848
     stdcall get_wcaps, ebx
848
     and  eax, AC_WCAP_TYPE
849
     and  eax, AC_WCAP_TYPE
849
     shr  eax, AC_WCAP_TYPE_SHIFT
850
     shr  eax, AC_WCAP_TYPE_SHIFT
850
 
851
 
851
     cmp     eax, AC_WID_PIN
852
     cmp     eax, AC_WID_PIN
852
     jne     .continue
853
     jne     .continue
853
 
854
 
854
     mov     [edi + HDA_PINCFG.nid], bx
855
     mov     [edi + HDA_PINCFG.nid], bx
855
     stdcall snd_hda_codec_read, ebx, 0, AC_VERB_GET_CONFIG_DEFAULT, 0
856
     stdcall snd_hda_codec_read, ebx, 0, AC_VERB_GET_CONFIG_DEFAULT, 0
856
     mov     [edi + HDA_PINCFG.cfg], eax
857
     mov     [edi + HDA_PINCFG.cfg], eax
857
 
858
     add     edi, HDA_PINCFG.sizeof
-
 
859
     inc     [codec.num_pins]
-
 
860
 
858
  .continue:
861
  .continue:
859
     add     edi, HDA_PINCFG.sizeof
-
 
860
     inc     ebx
862
     inc     ebx
861
     dec     ecx
863
     dec     ecx
862
     jnz     .next_node
864
     jnz     .next_node
863
 
865
 
864
;Asper [
-
 
865
     and     ebx, 0xFFFF
-
 
866
     sub     bx, [codec.start_nid]
-
 
867
     mov     [codec.num_pins], ebx
-
 
868
;Asper ]
-
 
869
 
-
 
870
     pop     edi edx ecx ebx
866
     pop     edi edx ecx ebx
871
     xor     eax, eax
867
     xor     eax, eax
872
     ret
868
     ret
873
  .err_out:
869
  .err_out:
874
     pop     edi edx ecx ebx
870
     pop     edi edx ecx ebx
875
     xor     eax, eax
871
     xor     eax, eax
876
     dec     eax
872
     dec     eax
877
     ret
873
     ret
878
endp
874
endp
879
 
875
 
880
 
876
 
881
 
877
 
882
; look up the given pin config list and return the item matching with NID
878
; look up the given pin config list and return the item matching with NID
883
proc  look_up_pincfg stdcall, array:dword, nid:dword
879
proc  look_up_pincfg stdcall, array:dword, nid:dword
884
     push    ebx ecx edx
880
     push    ebx ecx edx
885
     mov     ecx, [codec.num_pins]
881
     mov     ecx, [codec.num_pins]
886
     mov     eax, [array]
882
     mov     eax, [array]
887
     mov     ebx, [nid]
883
     mov     ebx, [nid]
888
  .next_pin:
884
  .next_pin:
889
     mov     dx,  [eax + HDA_PINCFG.nid]
885
     mov     dx,  [eax + HDA_PINCFG.nid]
890
     cmp     dx,  bx
886
     cmp     dx,  bx
891
     je      .out
887
     je      .out
892
  .continue:
888
  .continue:
893
     add     eax, HDA_PINCFG.sizeof
889
     add     eax, HDA_PINCFG.sizeof
894
     dec     ecx
890
     dec     ecx
895
     jnz     .next_pin
891
     jnz     .next_pin
896
 
892
 
897
     xor     eax, eax
893
     xor     eax, eax
898
  .out:
894
  .out:
899
     pop     edx ecx ebx
895
     pop     edx ecx ebx
900
     ret
896
     ret
901
endp
897
endp
902
 
898
 
903
; write a config value for the given NID
899
; write a config value for the given NID
904
proc  set_pincfg stdcall, nid:dword, cfg:dword
900
proc  set_pincfg stdcall, nid:dword, cfg:dword
905
     push    eax  ebx  ecx  edx
901
     push    eax  ebx  ecx  edx
906
     mov     eax, [cfg]
902
     mov     eax, [cfg]
907
     xor     ebx, ebx
903
     xor     ebx, ebx
908
     mov     edx, AC_VERB_SET_CONFIG_DEFAULT_BYTES_0
904
     mov     edx, AC_VERB_SET_CONFIG_DEFAULT_BYTES_0
909
     mov     ecx, 4
905
     mov     ecx, 4
910
  @@:
906
  @@:
911
     mov     bl,  al
907
     mov     bl,  al
912
     stdcall snd_hda_codec_write, [nid], 0, edx, ebx
908
     stdcall snd_hda_codec_write, [nid], 0, edx, ebx
913
     shr     eax, 8
909
     shr     eax, 8
914
     inc     edx
910
     inc     edx
915
     dec     ecx
911
     dec     ecx
916
     jnz     @b
912
     jnz     @b
917
  .l1:
913
  .l1:
918
     pop     edx  ecx  ebx  eax
914
     pop     edx  ecx  ebx  eax
919
     ret
915
     ret
920
endp
916
endp
921
 
917
 
922
 
918
 
923
;;
919
;;
924
;; snd_hda_codec_get_pincfg - Obtain a pin-default configuration
920
;; snd_hda_codec_get_pincfg - Obtain a pin-default configuration
925
;; @codec: the HDA codec
921
;; @codec: the HDA codec
926
;; @nid: NID to get the pin config
922
;; @nid: NID to get the pin config
927
;;
923
;;
928
;; Get the current pin config value of the given pin NID.
924
;; Get the current pin config value of the given pin NID.
929
;; If the pincfg value is cached or overridden via sysfs or driver,
925
;; If the pincfg value is cached or overridden via sysfs or driver,
930
;; returns the cached value.
926
;; returns the cached value.
931
;;
927
;;
932
proc  snd_hda_codec_get_pincfg stdcall, nid:dword
928
proc  snd_hda_codec_get_pincfg stdcall, nid:dword
933
     push    edi
929
     push    edi
934
     stdcall look_up_pincfg, [codec.init_pins], [nid]
930
     stdcall look_up_pincfg, [codec.init_pins], [nid]
935
     test    eax, eax
931
     test    eax, eax
936
     jz      @f
932
     jz      @f
937
     mov     edi, eax
933
     mov     edi, eax
938
     mov     eax, [edi + HDA_PINCFG.cfg]
934
     mov     eax, [edi + HDA_PINCFG.cfg]
939
  @@:
935
  @@:
940
     pop     edi
936
     pop     edi
941
     ret
937
     ret
942
endp
938
endp
943
 
939
 
944
;======================================================================================
940
;======================================================================================
945
 
941
 
946
;;
942
;;
947
;; snd_hda_codec_setup_stream - set up the codec for streaming
943
;; snd_hda_codec_setup_stream - set up the codec for streaming
948
;; @nid: the NID to set up
944
;; @nid: the NID to set up
949
;; @stream_tag: stream tag to pass, it's between 0x1 and 0xf.
945
;; @stream_tag: stream tag to pass, it's between 0x1 and 0xf.
950
;; @channel_id: channel id to pass, zero based.
946
;; @channel_id: channel id to pass, zero based.
951
;; @format: stream format.
947
;; @format: stream format.
952
;;
948
;;
953
proc hda_codec_setup_stream stdcall, nid:dword, stream_tag:dword, channel_id:dword, format:dword
949
proc hda_codec_setup_stream stdcall, nid:dword, stream_tag:dword, channel_id:dword, format:dword
954
     push    eax
950
     push    eax
955
     mov     eax, [nid]
951
     mov     eax, [nid]
956
     test    eax, eax
952
     test    eax, eax
957
     jnz     @f
953
     jnz     @f
958
     pop     eax
954
     pop     eax
959
     ret
955
     ret
960
  @@:
956
  @@:
961
  if DEBUG
957
  if DEBUG
962
     push    esi
958
     push    esi
963
     mov     esi, msgHDACodecSetupStream
959
     mov     esi, msgHDACodecSetupStream
964
     call    SysMsgBoardStr
960
     call    SysMsgBoardStr
965
     stdcall fdword2str, 3
961
     stdcall fdword2str, 3
966
     call    SysMsgBoardStr
962
     call    SysMsgBoardStr
967
 
963
 
968
     mov     esi, msgStream
964
     mov     esi, msgStream
969
     call    SysMsgBoardStr
965
     call    SysMsgBoardStr
970
     mov     eax, [stream_tag]
966
     mov     eax, [stream_tag]
971
     stdcall fdword2str, 3
967
     stdcall fdword2str, 3
972
     call    SysMsgBoardStr
968
     call    SysMsgBoardStr
973
 
969
 
974
     mov     esi, msgChannel
970
     mov     esi, msgChannel
975
     call    SysMsgBoardStr
971
     call    SysMsgBoardStr
976
     mov     eax, [channel_id]
972
     mov     eax, [channel_id]
977
     stdcall fdword2str, 3
973
     stdcall fdword2str, 3
978
     call    SysMsgBoardStr
974
     call    SysMsgBoardStr
979
 
975
 
980
     mov     esi, msgFormat
976
     mov     esi, msgFormat
981
     call    SysMsgBoardStr
977
     call    SysMsgBoardStr
982
     mov     eax, [format]
978
     mov     eax, [format]
983
     stdcall fdword2str, 3
979
     stdcall fdword2str, 3
984
     call    SysMsgBoardStr
980
     call    SysMsgBoardStr
985
     pop     esi
981
     pop     esi
986
  end if
982
  end if
987
     mov     eax, [stream_tag]
983
     mov     eax, [stream_tag]
988
     shl     eax, 4
984
     shl     eax, 4
989
     or      eax, [channel_id]
985
     or      eax, [channel_id]
990
     stdcall snd_hda_codec_write, [nid], 0, AC_VERB_SET_CHANNEL_STREAMID, eax
986
     stdcall snd_hda_codec_write, [nid], 0, AC_VERB_SET_CHANNEL_STREAMID, eax
991
 
987
 
992
     mov     eax, 1000  ; wait 1 ms
988
     mov     eax, 1000  ; wait 1 ms
993
     call    StallExec
989
     call    StallExec
994
 
990
 
995
     stdcall snd_hda_codec_write, [nid], 0, AC_VERB_SET_STREAM_FORMAT, [format]
991
     stdcall snd_hda_codec_write, [nid], 0, AC_VERB_SET_STREAM_FORMAT, [format]
996
     pop     eax
992
     pop     eax
997
     ret
993
     ret
998
endp
994
endp
999
 
995
 
1000
 
996
 
1001
proc snd_hda_codec_cleanup_stream stdcall, nid:dword
997
proc snd_hda_codec_cleanup_stream stdcall, nid:dword
1002
     push    eax
998
     push    eax
1003
     mov     eax, [nid]
999
     mov     eax, [nid]
1004
     test    eax, eax
1000
     test    eax, eax
1005
     jz      @f
1001
     jz      @f
1006
     pop     eax
1002
     pop     eax
1007
     ret
1003
     ret
1008
  @@:
1004
  @@:
1009
  if DEBUG
1005
  if DEBUG
1010
     push    esi
1006
     push    esi
1011
     mov     esi, msgHDACodecCleanupStream
1007
     mov     esi, msgHDACodecCleanupStream
1012
     call    SysMsgBoardStr
1008
     call    SysMsgBoardStr
1013
     stdcall fdword2str, 3
1009
     stdcall fdword2str, 3
1014
     call    SysMsgBoardStr
1010
     call    SysMsgBoardStr
1015
     pop     esi
1011
     pop     esi
1016
  end if
1012
  end if
1017
     stdcall snd_hda_codec_write, [nid], 0, AC_VERB_SET_CHANNEL_STREAMID, 0
1013
     stdcall snd_hda_codec_write, [nid], 0, AC_VERB_SET_CHANNEL_STREAMID, 0
1018
  if 0  ; keep the format
1014
  if 0  ; keep the format
1019
     mov     eax, 1000000  ; wait 100 ms
1015
     mov     eax, 1000000  ; wait 100 ms
1020
     call    StallExec
1016
     call    StallExec
1021
     stdcall snd_hda_codec_write, [nid], 0, AC_VERB_SET_STREAM_FORMAT, 0
1017
     stdcall snd_hda_codec_write, [nid], 0, AC_VERB_SET_STREAM_FORMAT, 0
1022
  end if
1018
  end if
1023
     pop     eax
1019
     pop     eax
1024
     ret
1020
     ret
1025
endp
1021
endp
1026
 
1022
 
1027
 
1023
 
1028
proc  read_pin_cap, nid:dword
1024
proc  read_pin_cap, nid:dword
1029
     snd_hda_param_read  [nid], AC_PAR_PIN_CAP
1025
     snd_hda_param_read  [nid], AC_PAR_PIN_CAP
1030
     ret
1026
     ret
1031
endp
1027
endp
1032
 
1028
 
1033
 
1029
 
1034
;; read the current volume
1030
;; read the current volume
1035
proc get_volume_mute stdcall, nid:dword, ch:dword, direction:dword, index:dword
1031
proc get_volume_mute stdcall, nid:dword, ch:dword, direction:dword, index:dword
1036
     push    ebx
1032
     push    ebx
1037
     mov     ebx, AC_AMP_GET_LEFT
1033
     mov     ebx, AC_AMP_GET_LEFT
1038
     mov     eax, [ch]
1034
     mov     eax, [ch]
1039
     test    eax, eax
1035
     test    eax, eax
1040
     jz      @f
1036
     jz      @f
1041
     mov     ebx, AC_AMP_GET_RIGHT
1037
     mov     ebx, AC_AMP_GET_RIGHT
1042
  @@:
1038
  @@:
1043
     mov     eax, [direction]
1039
     mov     eax, [direction]
1044
     cmp     eax, HDA_OUTPUT
1040
     cmp     eax, HDA_OUTPUT
1045
     jne     @f
1041
     jne     @f
1046
     or      ebx, AC_AMP_GET_OUTPUT
1042
     or      ebx, AC_AMP_GET_OUTPUT
1047
     jmp     .l1
1043
     jmp     .l1
1048
  @@:
1044
  @@:
1049
     or      ebx, AC_AMP_GET_INPUT
1045
     or      ebx, AC_AMP_GET_INPUT
1050
  .l1:
1046
  .l1:
1051
     or      ebx, [index]
1047
     or      ebx, [index]
1052
     stdcall snd_hda_codec_read, [nid], 0, AC_VERB_GET_AMP_GAIN_MUTE, ebx
1048
     stdcall snd_hda_codec_read, [nid], 0, AC_VERB_GET_AMP_GAIN_MUTE, ebx
1053
     and     eax, 0xFF
1049
     and     eax, 0xFF
1054
     pop     ebx
1050
     pop     ebx
1055
     ret
1051
     ret
1056
endp
1052
endp
1057
 
1053
 
1058
 
1054
 
1059
;; write the current volume in info to the h/w
1055
;; write the current volume in info to the h/w
1060
proc put_volume_mute stdcall, nid:dword, ch:dword, direction:dword, index:dword, val:dword
1056
proc put_volume_mute stdcall, nid:dword, ch:dword, direction:dword, index:dword, val:dword
1061
     push    eax  ebx
1057
     push    eax  ebx
1062
     mov     ebx, AC_AMP_SET_LEFT
1058
     mov     ebx, AC_AMP_SET_LEFT
1063
     mov     eax, [ch]
1059
     mov     eax, [ch]
1064
     test    eax, eax
1060
     test    eax, eax
1065
     jz      @f
1061
     jz      @f
1066
     mov     ebx, AC_AMP_SET_RIGHT
1062
     mov     ebx, AC_AMP_SET_RIGHT
1067
  @@:
1063
  @@:
1068
     mov     eax, [direction]
1064
     mov     eax, [direction]
1069
     cmp     eax, HDA_OUTPUT
1065
     cmp     eax, HDA_OUTPUT
1070
     jne     @f
1066
     jne     @f
1071
     or      ebx, AC_AMP_SET_OUTPUT
1067
     or      ebx, AC_AMP_SET_OUTPUT
1072
     jmp     .l1
1068
     jmp     .l1
1073
  @@:
1069
  @@:
1074
     or      ebx, AC_AMP_SET_INPUT
1070
     or      ebx, AC_AMP_SET_INPUT
1075
  .l1:
1071
  .l1:
1076
     mov     eax, [index]
1072
     mov     eax, [index]
1077
     shl     eax, AC_AMP_SET_INDEX_SHIFT
1073
     shl     eax, AC_AMP_SET_INDEX_SHIFT
1078
     or      ebx, eax
1074
     or      ebx, eax
1079
     or      ebx, [val]
1075
     or      ebx, [val]
1080
     stdcall snd_hda_codec_write, [nid], 0, AC_VERB_SET_AMP_GAIN_MUTE, ebx
1076
     stdcall snd_hda_codec_write, [nid], 0, AC_VERB_SET_AMP_GAIN_MUTE, ebx
1081
     pop     ebx  eax
1077
     pop     ebx  eax
1082
     ret
1078
     ret
1083
endp
1079
endp
1084
 
1080
 
1085
 
1081
 
1086
;;
1082
;;
1087
;; snd_hda_codec_amp_update - update the AMP value
1083
;; snd_hda_codec_amp_update - update the AMP value
1088
;; @nid: NID to read the AMP value
1084
;; @nid: NID to read the AMP value
1089
;; @ch: channel (left=0 or right=1)
1085
;; @ch: channel (left=0 or right=1)
1090
;; @direction: #HDA_INPUT or #HDA_OUTPUT
1086
;; @direction: #HDA_INPUT or #HDA_OUTPUT
1091
;; @idx: the index value (only for input direction)
1087
;; @idx: the index value (only for input direction)
1092
;; @mask: bit mask to set
1088
;; @mask: bit mask to set
1093
;; @val: the bits value to set
1089
;; @val: the bits value to set
1094
;;
1090
;;
1095
;; Update the AMP value with a bit mask.
1091
;; Update the AMP value with a bit mask.
1096
;; Returns 0 if the value is unchanged, 1 if changed.
1092
;; Returns 0 if the value is unchanged, 1 if changed.
1097
;;
1093
;;
1098
;-proc snd_hda_codec_amp_update stdcall, nid:dword, ch:dword, direction:dword, idx:dword, mask:dword, val:dword
1094
;-proc snd_hda_codec_amp_update stdcall, nid:dword, ch:dword, direction:dword, idx:dword, mask:dword, val:dword
1099
;-     push    ebx  edx
1095
;-     push    ebx  edx
1100
;-     mov     eax, [mask]
1096
;-     mov     eax, [mask]
1101
;-     mov     ebx, [val]
1097
;-     mov     ebx, [val]
1102
;-     and     ebx, eax
1098
;-     and     ebx, eax
1103
;-     xor     eax, -1
1099
;-     xor     eax, -1
1104
;-     mov     edx, eax
1100
;-     mov     edx, eax
1105
;-     stdcall get_volume_mute, [nid], [ch], [direction], [idx]
1101
;-     stdcall get_volume_mute, [nid], [ch], [direction], [idx]
1106
;-     and     eax, edx
1102
;-     and     eax, edx
1107
;-     or      ebx, eax
1103
;-     or      ebx, eax
1108
;-
1104
;-
1109
;-     stdcall put_volume_mute, [nid], [ch], [direction], [idx], ebx
1105
;-     stdcall put_volume_mute, [nid], [ch], [direction], [idx], ebx
1110
;-     xor     eax, eax
1106
;-     xor     eax, eax
1111
;-     inc     eax
1107
;-     inc     eax
1112
;-     pop     edx  ebx
1108
;-     pop     edx  ebx
1113
;-     ret
1109
;-     ret
1114
;-endp
1110
;-endp
1115
 
1111
 
1116
 
1112
 
1117
;;
1113
;;
1118
;; snd_hda_codec_amp_stereo - update the AMP stereo values
1114
;; snd_hda_codec_amp_stereo - update the AMP stereo values
1119
;; @nid: NID to read the AMP value
1115
;; @nid: NID to read the AMP value
1120
;; @direction: #HDA_INPUT or #HDA_OUTPUT
1116
;; @direction: #HDA_INPUT or #HDA_OUTPUT
1121
;; @idx: the index value (only for input direction)
1117
;; @idx: the index value (only for input direction)
1122
;; @mask: bit mask to set
1118
;; @mask: bit mask to set
1123
;; @val: the bits value to set
1119
;; @val: the bits value to set
1124
;;
1120
;;
1125
;; Update the AMP values like snd_hda_codec_amp_update(), but for a
1121
;; Update the AMP values like snd_hda_codec_amp_update(), but for a
1126
;; stereo widget with the same mask and value.
1122
;; stereo widget with the same mask and value.
1127
;;
1123
;;
1128
proc snd_hda_codec_amp_stereo stdcall, nid:dword, direction:dword, idx:dword, mask:dword, val:dword
1124
proc snd_hda_codec_amp_stereo stdcall, nid:dword, direction:dword, idx:dword, mask:dword, val:dword
1129
     push    ebx edx
1125
     push    ebx edx
1130
     mov     ebx, [val]
1126
     mov     ebx, [val]
1131
     mov     edx, [mask]
1127
     mov     edx, [mask]
1132
     and     ebx, edx
1128
     and     ebx, edx
1133
     stdcall put_volume_mute, [nid], 0, [direction], [idx], ebx
1129
     stdcall put_volume_mute, [nid], 0, [direction], [idx], ebx
1134
     stdcall put_volume_mute, [nid], 1, [direction], [idx], ebx
1130
     stdcall put_volume_mute, [nid], 1, [direction], [idx], ebx
1135
     pop     edx  ebx
1131
     pop     edx  ebx
1136
     ret
1132
     ret
1137
endp
1133
endp
1138
 
1134
 
1139
 
1135
 
1140
;; set power state of the codec
1136
;; set power state of the codec
1141
proc snd_hda_set_power_state stdcall, fg:dword, power_state:dword
1137
proc snd_hda_set_power_state stdcall, fg:dword, power_state:dword
1142
     push    eax ebx ecx edx
1138
     push    eax ebx ecx edx
1143
     ; this delay seems necessary to avoid click noise at power down
1139
     ; this delay seems necessary to avoid click noise at power down
1144
     mov     ebx, [power_state]
1140
     mov     ebx, [power_state]
1145
     cmp     ebx, AC_PWRST_D3
1141
     cmp     ebx, AC_PWRST_D3
1146
     jne     @f
1142
     jne     @f
1147
     mov     eax, 100000
1143
     mov     eax, 100000
1148
     call    StallExec
1144
     call    StallExec
1149
  @@:
1145
  @@:
1150
     stdcall snd_hda_codec_read, [fg], 0, AC_VERB_SET_POWER_STATE, ebx
1146
     stdcall snd_hda_codec_read, [fg], 0, AC_VERB_SET_POWER_STATE, ebx
1151
     ;partial workaround for "azx_get_response timeout"
1147
     ;partial workaround for "azx_get_response timeout"
1152
     cmp     ebx, AC_PWRST_D0
1148
     cmp     ebx, AC_PWRST_D0
1153
     jne     @f
1149
     jne     @f
1154
 
1150
 
1155
     mov     dx, [codec.vendor_id]
1151
     mov     dx, [codec.vendor_id]
1156
     cmp     dx, 0x14F1
1152
     cmp     dx, 0x14F1
1157
 
1153
 
1158
     jne     @f
1154
     jne     @f
1159
     mov     eax, 10000
1155
     mov     eax, 10000
1160
     call    StallExec
1156
     call    StallExec
1161
  @@:
1157
  @@:
1162
     movzx   ecx, [codec.num_nodes]
1158
     movzx   ecx, [codec.num_nodes]
1163
     movzx   edx, [codec.start_nid]
1159
     movzx   edx, [codec.start_nid]
1164
  .next_nid:
1160
  .next_nid:
1165
     stdcall get_wcaps, edx
1161
     stdcall get_wcaps, edx
1166
     test    eax, AC_WCAP_POWER
1162
     test    eax, AC_WCAP_POWER
1167
     jz      .skip_nid
1163
     jz      .skip_nid
1168
 
1164
 
1169
     stdcall get_wcaps_type, eax
1165
     stdcall get_wcaps_type, eax
1170
     cmp     ebx, AC_PWRST_D3
1166
     cmp     ebx, AC_PWRST_D3
1171
     jne     .l1
1167
     jne     .l1
1172
     cmp     eax, AC_WID_PIN
1168
     cmp     eax, AC_WID_PIN
1173
     jne     .l1
1169
     jne     .l1
1174
     ;don't power down the widget if it controls
1170
     ;don't power down the widget if it controls
1175
     ;eapd and EAPD_BTLENABLE is set.
1171
     ;eapd and EAPD_BTLENABLE is set.
1176
     stdcall  read_pin_cap, edx
1172
     stdcall  read_pin_cap, edx
1177
     test    eax, AC_PINCAP_EAPD
1173
     test    eax, AC_PINCAP_EAPD
1178
     jz      .l2
1174
     jz      .l2
1179
 
1175
 
1180
     stdcall snd_hda_codec_read, edx, 0, AC_VERB_GET_EAPD_BTLENABLE, 0
1176
     stdcall snd_hda_codec_read, edx, 0, AC_VERB_GET_EAPD_BTLENABLE, 0
1181
     and     eax, 0x02
1177
     and     eax, 0x02
1182
     test    eax, eax
1178
     test    eax, eax
1183
     jnz     .skip_nid
1179
     jnz     .skip_nid
1184
  .l2:
1180
  .l2:
1185
  .l1:
1181
  .l1:
1186
     stdcall snd_hda_codec_write, edx, 0, AC_VERB_SET_POWER_STATE, ebx
1182
     stdcall snd_hda_codec_write, edx, 0, AC_VERB_SET_POWER_STATE, ebx
1187
  .skip_nid:
1183
  .skip_nid:
1188
     inc     edx
1184
     inc     edx
1189
     dec     ecx
1185
     dec     ecx
1190
     jnz     .next_nid
1186
     jnz     .next_nid
1191
 
1187
 
1192
     cmp     ebx, AC_PWRST_D0
1188
     cmp     ebx, AC_PWRST_D0
1193
     jne     .out
1189
     jne     .out
1194
     ;wait until codec reaches to D0
1190
     ;wait until codec reaches to D0
1195
     mov     ecx, 500
1191
     mov     ecx, 500
1196
  .wait_D0:
1192
  .wait_D0:
1197
     stdcall snd_hda_codec_read, [fg], 0, AC_VERB_GET_POWER_STATE, 0
1193
     stdcall snd_hda_codec_read, [fg], 0, AC_VERB_GET_POWER_STATE, 0
1198
     cmp     eax, ebx
1194
     cmp     eax, ebx
1199
     je      .out
1195
     je      .out
1200
     mov     eax, 1000  ; msleep(1);
1196
     mov     eax, 1000  ; msleep(1);
1201
     call    StallExec
1197
     call    StallExec
1202
     dec     ecx
1198
     dec     ecx
1203
     jnz     .wait_D0
1199
     jnz     .wait_D0
1204
  .out:
1200
  .out:
1205
     pop     edx ecx ebx eax
1201
     pop     edx ecx ebx eax
1206
     ret
1202
     ret
1207
endp
1203
endp
1208
 
1204
 
1209
 
1205
 
1210
;data
1206
;data
1211
 
1207
 
1212
; codec vendors
1208
; codec vendors
1213
align 16
1209
align 16
1214
msg_Cirrus       db 'Cirrus Logic ',0
1210
msg_Cirrus       db 'Cirrus Logic ',0
1215
msg_Motorola       db 'Motorola ',0
1211
msg_Motorola       db 'Motorola ',0
1216
msg_SiliconImage     db 'Silicon Image ',0
1212
msg_SiliconImage     db 'Silicon Image ',0
1217
msg_Realtek       db 'Realtek ',0
1213
msg_Realtek       db 'Realtek ',0
1218
msg_Creative       db 'Creative ',0
1214
msg_Creative       db 'Creative ',0
1219
msg_IDT        db 'IDT ',0
1215
msg_IDT        db 'IDT ',0
1220
msg_LSI        db 'LSI ',0
1216
msg_LSI        db 'LSI ',0
1221
msg_AnalogDevices    db 'Analog Devices ',0
1217
msg_AnalogDevices    db 'Analog Devices ',0
1222
msg_CMedia       db 'C-Media ',0
1218
msg_CMedia       db 'C-Media ',0
1223
msg_Conexant       db 'Conexant ',0
1219
msg_Conexant       db 'Conexant ',0
1224
msg_Chrontel       db 'Chrontel ',0
1220
msg_Chrontel       db 'Chrontel ',0
1225
msg_LG         db 'LG ',0
1221
msg_LG         db 'LG ',0
1226
msg_Wolfson       db 'Wolfson Microelectronics ',0
1222
msg_Wolfson       db 'Wolfson Microelectronics ',0
1227
msg_Qumranet       db 'Qumranet ',0
1223
msg_Qumranet       db 'Qumranet ',0
1228
msg_SigmaTel       db 'SigmaTel ',0
1224
msg_SigmaTel       db 'SigmaTel ',0
1229
ac_unknown     db 'unknown manufacturer ',0
1225
ac_unknown     db 'unknown manufacturer ',0
1230
 
1226
 
1231
chip_unknown   db 'unknown codec id ', 0
1227
chip_unknown   db 'unknown codec id ', 0
1232
 
1228
 
1233
 
1229
 
1234
; codec vendor labels
1230
; codec vendor labels
1235
align 4
1231
align 4
1236
hda_vendor_ids:
1232
hda_vendor_ids:
1237
     dd    0x1002, msg_ATI, chips_ATI
1233
     dd    0x1002, msg_ATI, chips_ATI
1238
     dd    0x1013, msg_Cirrus, chips_Cirrus
1234
     dd    0x1013, msg_Cirrus, chips_Cirrus
1239
     dd    0x1057, msg_Motorola, chips_Motorola
1235
     dd    0x1057, msg_Motorola, chips_Motorola
1240
     dd    0x1095, msg_SiliconImage, chips_SiliconImage
1236
     dd    0x1095, msg_SiliconImage, chips_SiliconImage
1241
     dd    0x10de, msg_NVidia, chips_NVidia
1237
     dd    0x10de, msg_NVidia, chips_NVidia
1242
     dd    0x10ec, msg_Realtek, chips_Realtek
1238
     dd    0x10ec, msg_Realtek, chips_Realtek
1243
     dd    0x1102, msg_Creative, chips_Creative
1239
     dd    0x1102, msg_Creative, chips_Creative
1244
     dd    0x1106, msg_VIA, chips_VIA
1240
     dd    0x1106, msg_VIA, chips_VIA
1245
     dd    0x111d, msg_IDT, chips_IDT
1241
     dd    0x111d, msg_IDT, chips_IDT
1246
     dd    0x11c1, msg_LSI, chips_LSI
1242
     dd    0x11c1, msg_LSI, chips_LSI
1247
     dd    0x11d4, msg_AnalogDevices, chips_Analog
1243
     dd    0x11d4, msg_AnalogDevices, chips_Analog
1248
     dd    0x13f6, msg_CMedia, chips_CMedia
1244
     dd    0x13f6, msg_CMedia, chips_CMedia
1249
     dd    0x14f1, msg_Conexant, chips_Conexant
1245
     dd    0x14f1, msg_Conexant, chips_Conexant
1250
     dd    0x17e8, msg_Chrontel, chips_Chrontel
1246
     dd    0x17e8, msg_Chrontel, chips_Chrontel
1251
     dd    0x1854, msg_LG, chips_LG
1247
     dd    0x1854, msg_LG, chips_LG
1252
     dd    0x1aec, msg_Wolfson, chips_Wolfson
1248
     dd    0x1aec, msg_Wolfson, chips_Wolfson
1253
     dd    0x1af4, msg_Qumranet, chips_Qumranet   ; Qemu 0.14
1249
     dd    0x1af4, msg_Qumranet, chips_Qumranet   ; Qemu 0.14
1254
     dd    0x434d, msg_CMedia, chips_CMedia
1250
     dd    0x434d, msg_CMedia, chips_CMedia
1255
     dd    0x8086, msg_Intel, chips_Intel
1251
     dd    0x8086, msg_Intel, chips_Intel
1256
     dd    0x8384, msg_SigmaTel, chips_SigmaTel
1252
     dd    0x8384, msg_SigmaTel, chips_SigmaTel
1257
     dd    0 ; terminator
1253
     dd    0 ; terminator
1258
 
1254
 
1259
align 16             ;known codecs
1255
align 16             ;known codecs
1260
chips_ATI            dd 0xAA01, chip_ATIR6XX
1256
chips_ATI            dd 0xAA01, chip_ATIR6XX
1261
                     dd 0xFF
1257
                     dd 0xFF
1262
 
1258
 
1263
chips_Cirrus         dd 0xFF
1259
chips_Cirrus         dd 0xFF
1264
chips_Motorola       dd 0xFF
1260
chips_Motorola       dd 0xFF
1265
 
1261
 
1266
chips_SiliconImage   dd 0x1392, chip_SI1392
1262
chips_SiliconImage   dd 0x1392, chip_SI1392
1267
                     dd 0xFF
1263
                     dd 0xFF
1268
 
1264
 
1269
chips_NVidia         dd 0x0002, chip_MCP78
1265
chips_NVidia         dd 0x0002, chip_MCP78
1270
                     dd 0xFF
1266
                     dd 0xFF
1271
 
1267
 
1272
chips_Realtek        dd 0x0262, chip_ALC262
1268
chips_Realtek        dd 0x0262, chip_ALC262
1273
                     dd 0x0268, chip_ALC268
1269
                     dd 0x0268, chip_ALC268
1274
                     dd 0x0269, chip_ALC269
1270
                     dd 0x0269, chip_ALC269
1275
                     dd 0x0272, chip_ALC272
1271
                     dd 0x0272, chip_ALC272
1276
                     dd 0x0662, chip_ALC662
1272
                     dd 0x0662, chip_ALC662
1277
                     dd 0x0663, chip_ALC663
1273
                     dd 0x0663, chip_ALC663
1278
                     dd 0x0883, chip_ALC883
1274
                     dd 0x0883, chip_ALC883
1279
                     dd 0x0887, chip_ALC887
1275
                     dd 0x0887, chip_ALC887
1280
                     dd 0x0888, chip_ALC888
1276
                     dd 0x0888, chip_ALC888
1281
                     dd 0x0889, chip_ALC889
1277
                     dd 0x0889, chip_ALC889
1282
                     dd 0xFF
1278
                     dd 0xFF
1283
 
1279
 
1284
chips_Creative       dd 0xFF
1280
chips_Creative       dd 0xFF
1285
 
1281
 
1286
chips_VIA            dd 0xE721, chip_VT1708B_1
1282
chips_VIA            dd 0xE721, chip_VT1708B_1
1287
                     dd 0x0397, chip_VT17085_0
1283
                     dd 0x0397, chip_VT17085_0
1288
                     dd 0xFF
1284
                     dd 0xFF
1289
 
1285
 
1290
chips_IDT            dd 0xFF
1286
chips_IDT            dd 0xFF
1291
 
1287
 
1292
chips_LSI            dd 0x1039, chip_LSI1039
1288
chips_LSI            dd 0x1039, chip_LSI1039
1293
                     dd 0x1040, chip_LSI1040
1289
                     dd 0x1040, chip_LSI1040
1294
                     dd 0x3026, chip_LSI3026
1290
                     dd 0x3026, chip_LSI3026
1295
                     dd 0x3055, chip_LSI3055
1291
                     dd 0x3055, chip_LSI3055
1296
                     dd 0xFF
1292
                     dd 0xFF
1297
 
1293
 
1298
chips_Analog         dd 0x1986, chip_AD1986A
1294
chips_Analog         dd 0x1986, chip_AD1986A
1299
                     dd 0x198B, chip_AD198B
1295
                     dd 0x198B, chip_AD198B
1300
                     dd 0xFF
1296
                     dd 0xFF
1301
 
1297
 
1302
chips_CMedia         dd 0xFF
1298
chips_CMedia         dd 0xFF
1303
 
1299
 
1304
chips_Conexant       dd 0x5045, chip_CX20549
1300
chips_Conexant       dd 0x5045, chip_CX20549
1305
                     dd 0x5051, chip_CX20561
1301
                     dd 0x5051, chip_CX20561
1306
                     dd 0xFF
1302
                     dd 0xFF
1307
 
1303
 
1308
chips_Chrontel       dd 0xFF
1304
chips_Chrontel       dd 0xFF
1309
chips_LG             dd 0xFF
1305
chips_LG             dd 0xFF
1310
chips_Wolfson        dd 0xFF
1306
chips_Wolfson        dd 0xFF
1311
chips_Intel          dd 0xFF
1307
chips_Intel          dd 0xFF
1312
 
1308
 
1313
chips_Qumranet       dd 0x0010, chip_HDA_OUTPUT
1309
chips_Qumranet       dd 0x0010, chip_HDA_OUTPUT
1314
                     dd 0x0020, chip_HDA_DUPLEX
1310
                     dd 0x0020, chip_HDA_DUPLEX
1315
                     dd 0xFF
1311
                     dd 0xFF
1316
 
1312
 
1317
chips_SigmaTel       dd 0x7680, chip_STAC9221
1313
chips_SigmaTel       dd 0x7680, chip_STAC9221
1318
                     dd 0x7682, chip_STAC9221_A2
1314
                     dd 0x7682, chip_STAC9221_A2
1319
                     dd 0xFF
1315
                     dd 0xFF
1320
 
1316
 
1321
align 16
1317
align 16
1322
;AnalogDevices
1318
;AnalogDevices
1323
chip_AD1986A         db 'AD1986A',13,10,0
1319
chip_AD1986A         db 'AD1986A',13,10,0
1324
chip_AD198B          db 'AD198B',13,10,0
1320
chip_AD198B          db 'AD198B',13,10,0
1325
 
1321
 
1326
;ATI
1322
;ATI
1327
chip_ATIR6XX         db 'ATIR6XX',13,10,0
1323
chip_ATIR6XX         db 'ATIR6XX',13,10,0
1328
 
1324
 
1329
;Silicon Image
1325
;Silicon Image
1330
chip_SI1392          db 'SI1392',13,10,0
1326
chip_SI1392          db 'SI1392',13,10,0
1331
 
1327
 
1332
;NVidia
1328
;NVidia
1333
chip_MCP78           db 'MCP78',13,10,0
1329
chip_MCP78           db 'MCP78',13,10,0
1334
 
1330
 
1335
;Realtek
1331
;Realtek
1336
chip_ALC262          db 'ALC262',13,10,0
1332
chip_ALC262          db 'ALC262',13,10,0
1337
chip_ALC268          db 'ALC268',13,10,0
1333
chip_ALC268          db 'ALC268',13,10,0
1338
chip_ALC269          db 'ALC269',13,10,0
1334
chip_ALC269          db 'ALC269',13,10,0
1339
chip_ALC272          db 'ALC272',13,10,0
1335
chip_ALC272          db 'ALC272',13,10,0
1340
chip_ALC662          db 'ALC662',13,10,0
1336
chip_ALC662          db 'ALC662',13,10,0
1341
chip_ALC663          db 'ALC663',13,10,0
1337
chip_ALC663          db 'ALC663',13,10,0
1342
chip_ALC883          db 'ALC883',13,10,0
1338
chip_ALC883          db 'ALC883',13,10,0
1343
chip_ALC887          db 'ALC887',13,10,0
1339
chip_ALC887          db 'ALC887',13,10,0
1344
chip_ALC888          db 'ALC888',13,10,0
1340
chip_ALC888          db 'ALC888',13,10,0
1345
chip_ALC889          db 'ALC889',13,10,0
1341
chip_ALC889          db 'ALC889',13,10,0
1346
 
1342
 
1347
;Sigmatel
1343
;Sigmatel
1348
chip_STAC9221        db 'STAC9221',13,10,0
1344
chip_STAC9221        db 'STAC9221',13,10,0
1349
chip_STAC9221_A2     db 'STAC9221_A2',13,10,0
1345
chip_STAC9221_A2     db 'STAC9221_A2',13,10,0
1350
 
1346
 
1351
;VIA
1347
;VIA
1352
chip_VT1708B_1       db 'VT1708B_1',13,10,0
1348
chip_VT1708B_1       db 'VT1708B_1',13,10,0
1353
chip_VT17085_0       db 'VT17085_0',13,10,0
1349
chip_VT17085_0       db 'VT17085_0',13,10,0
1354
 
1350
 
1355
;Conexant
1351
;Conexant
1356
chip_CX20549         db 'CX20549',13,10,0
1352
chip_CX20549         db 'CX20549',13,10,0
1357
chip_CX20561         db 'CX20561',13,10,0
1353
chip_CX20561         db 'CX20561',13,10,0
1358
 
1354
 
1359
;Qumranet
1355
;Qumranet
1360
chip_HDA_OUTPUT      db 'HDA-OUTPUT',13,10,0
1356
chip_HDA_OUTPUT      db 'HDA-OUTPUT',13,10,0
1361
chip_HDA_DUPLEX      db 'HDA-DUPLEX',13,10,0
1357
chip_HDA_DUPLEX      db 'HDA-DUPLEX',13,10,0
1362
 
1358
 
1363
;LSI
1359
;LSI
1364
chip_LSI1039         db '1039 (Agere Systems HDA Modem)',13,10,0
1360
chip_LSI1039         db '1039 (Agere Systems HDA Modem)',13,10,0
1365
chip_LSI1040         db '1040 (Agere Systems HDA Modem)',13,10,0
1361
chip_LSI1040         db '1040 (Agere Systems HDA Modem)',13,10,0
1366
chip_LSI3026         db '3026 (Agere Systems HDA Modem)',13,10,0
1362
chip_LSI3026         db '3026 (Agere Systems HDA Modem)',13,10,0
1367
chip_LSI3055         db '3055 (Agere Systems HDA Modem)',13,10,0
1363
chip_LSI3055         db '3055 (Agere Systems HDA Modem)',13,10,0