root / hw / ac97.c @ 60398748
History | View | Annotate | Download (36.9 kB)
1 | e5c9a13e | balrog | /*
|
---|---|---|---|
2 | e5c9a13e | balrog | * Copyright (C) 2006 InnoTek Systemberatung GmbH
|
3 | e5c9a13e | balrog | *
|
4 | e5c9a13e | balrog | * This file is part of VirtualBox Open Source Edition (OSE), as
|
5 | e5c9a13e | balrog | * available from http://www.virtualbox.org. This file is free software;
|
6 | e5c9a13e | balrog | * you can redistribute it and/or modify it under the terms of the GNU
|
7 | e5c9a13e | balrog | * General Public License as published by the Free Software Foundation,
|
8 | e5c9a13e | balrog | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
9 | e5c9a13e | balrog | * distribution. VirtualBox OSE is distributed in the hope that it will
|
10 | e5c9a13e | balrog | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
11 | e5c9a13e | balrog | *
|
12 | e5c9a13e | balrog | * If you received this file as part of a commercial VirtualBox
|
13 | e5c9a13e | balrog | * distribution, then only the terms of your commercial VirtualBox
|
14 | e5c9a13e | balrog | * license agreement apply instead of the previous paragraph.
|
15 | e5c9a13e | balrog | */
|
16 | e5c9a13e | balrog | |
17 | e5c9a13e | balrog | #include "hw.h" |
18 | e5c9a13e | balrog | #include "audiodev.h" |
19 | e5c9a13e | balrog | #include "audio/audio.h" |
20 | e5c9a13e | balrog | #include "pci.h" |
21 | e5c9a13e | balrog | |
22 | e5c9a13e | balrog | enum {
|
23 | e5c9a13e | balrog | AC97_Reset = 0x00,
|
24 | e5c9a13e | balrog | AC97_Master_Volume_Mute = 0x02,
|
25 | e5c9a13e | balrog | AC97_Headphone_Volume_Mute = 0x04,
|
26 | e5c9a13e | balrog | AC97_Master_Volume_Mono_Mute = 0x06,
|
27 | e5c9a13e | balrog | AC97_Master_Tone_RL = 0x08,
|
28 | e5c9a13e | balrog | AC97_PC_BEEP_Volume_Mute = 0x0A,
|
29 | e5c9a13e | balrog | AC97_Phone_Volume_Mute = 0x0C,
|
30 | e5c9a13e | balrog | AC97_Mic_Volume_Mute = 0x0E,
|
31 | e5c9a13e | balrog | AC97_Line_In_Volume_Mute = 0x10,
|
32 | e5c9a13e | balrog | AC97_CD_Volume_Mute = 0x12,
|
33 | e5c9a13e | balrog | AC97_Video_Volume_Mute = 0x14,
|
34 | e5c9a13e | balrog | AC97_Aux_Volume_Mute = 0x16,
|
35 | e5c9a13e | balrog | AC97_PCM_Out_Volume_Mute = 0x18,
|
36 | e5c9a13e | balrog | AC97_Record_Select = 0x1A,
|
37 | e5c9a13e | balrog | AC97_Record_Gain_Mute = 0x1C,
|
38 | e5c9a13e | balrog | AC97_Record_Gain_Mic_Mute = 0x1E,
|
39 | e5c9a13e | balrog | AC97_General_Purpose = 0x20,
|
40 | e5c9a13e | balrog | AC97_3D_Control = 0x22,
|
41 | e5c9a13e | balrog | AC97_AC_97_RESERVED = 0x24,
|
42 | e5c9a13e | balrog | AC97_Powerdown_Ctrl_Stat = 0x26,
|
43 | e5c9a13e | balrog | AC97_Extended_Audio_ID = 0x28,
|
44 | e5c9a13e | balrog | AC97_Extended_Audio_Ctrl_Stat = 0x2A,
|
45 | e5c9a13e | balrog | AC97_PCM_Front_DAC_Rate = 0x2C,
|
46 | e5c9a13e | balrog | AC97_PCM_Surround_DAC_Rate = 0x2E,
|
47 | e5c9a13e | balrog | AC97_PCM_LFE_DAC_Rate = 0x30,
|
48 | e5c9a13e | balrog | AC97_PCM_LR_ADC_Rate = 0x32,
|
49 | e5c9a13e | balrog | AC97_MIC_ADC_Rate = 0x34,
|
50 | e5c9a13e | balrog | AC97_6Ch_Vol_C_LFE_Mute = 0x36,
|
51 | e5c9a13e | balrog | AC97_6Ch_Vol_L_R_Surround_Mute = 0x38,
|
52 | e5c9a13e | balrog | AC97_Vendor_Reserved = 0x58,
|
53 | e5c9a13e | balrog | AC97_Vendor_ID1 = 0x7c,
|
54 | e5c9a13e | balrog | AC97_Vendor_ID2 = 0x7e
|
55 | e5c9a13e | balrog | }; |
56 | e5c9a13e | balrog | |
57 | e5c9a13e | balrog | #define SOFT_VOLUME
|
58 | e5c9a13e | balrog | #define SR_FIFOE 16 /* rwc */ |
59 | e5c9a13e | balrog | #define SR_BCIS 8 /* rwc */ |
60 | e5c9a13e | balrog | #define SR_LVBCI 4 /* rwc */ |
61 | e5c9a13e | balrog | #define SR_CELV 2 /* ro */ |
62 | e5c9a13e | balrog | #define SR_DCH 1 /* ro */ |
63 | e5c9a13e | balrog | #define SR_VALID_MASK ((1 << 5) - 1) |
64 | e5c9a13e | balrog | #define SR_WCLEAR_MASK (SR_FIFOE | SR_BCIS | SR_LVBCI)
|
65 | e5c9a13e | balrog | #define SR_RO_MASK (SR_DCH | SR_CELV)
|
66 | e5c9a13e | balrog | #define SR_INT_MASK (SR_FIFOE | SR_BCIS | SR_LVBCI)
|
67 | e5c9a13e | balrog | |
68 | e5c9a13e | balrog | #define CR_IOCE 16 /* rw */ |
69 | e5c9a13e | balrog | #define CR_FEIE 8 /* rw */ |
70 | e5c9a13e | balrog | #define CR_LVBIE 4 /* rw */ |
71 | e5c9a13e | balrog | #define CR_RR 2 /* rw */ |
72 | e5c9a13e | balrog | #define CR_RPBM 1 /* rw */ |
73 | e5c9a13e | balrog | #define CR_VALID_MASK ((1 << 5) - 1) |
74 | e5c9a13e | balrog | #define CR_DONT_CLEAR_MASK (CR_IOCE | CR_FEIE | CR_LVBIE)
|
75 | e5c9a13e | balrog | |
76 | e5c9a13e | balrog | #define GC_WR 4 /* rw */ |
77 | e5c9a13e | balrog | #define GC_CR 2 /* rw */ |
78 | e5c9a13e | balrog | #define GC_VALID_MASK ((1 << 6) - 1) |
79 | e5c9a13e | balrog | |
80 | e5c9a13e | balrog | #define GS_MD3 (1<<17) /* rw */ |
81 | e5c9a13e | balrog | #define GS_AD3 (1<<16) /* rw */ |
82 | e5c9a13e | balrog | #define GS_RCS (1<<15) /* rwc */ |
83 | e5c9a13e | balrog | #define GS_B3S12 (1<<14) /* ro */ |
84 | e5c9a13e | balrog | #define GS_B2S12 (1<<13) /* ro */ |
85 | e5c9a13e | balrog | #define GS_B1S12 (1<<12) /* ro */ |
86 | e5c9a13e | balrog | #define GS_S1R1 (1<<11) /* rwc */ |
87 | e5c9a13e | balrog | #define GS_S0R1 (1<<10) /* rwc */ |
88 | e5c9a13e | balrog | #define GS_S1CR (1<<9) /* ro */ |
89 | e5c9a13e | balrog | #define GS_S0CR (1<<8) /* ro */ |
90 | e5c9a13e | balrog | #define GS_MINT (1<<7) /* ro */ |
91 | e5c9a13e | balrog | #define GS_POINT (1<<6) /* ro */ |
92 | e5c9a13e | balrog | #define GS_PIINT (1<<5) /* ro */ |
93 | e5c9a13e | balrog | #define GS_RSRVD ((1<<4)|(1<<3)) |
94 | e5c9a13e | balrog | #define GS_MOINT (1<<2) /* ro */ |
95 | e5c9a13e | balrog | #define GS_MIINT (1<<1) /* ro */ |
96 | e5c9a13e | balrog | #define GS_GSCI 1 /* rwc */ |
97 | e5c9a13e | balrog | #define GS_RO_MASK (GS_B3S12| \
|
98 | e5c9a13e | balrog | GS_B2S12| \ |
99 | e5c9a13e | balrog | GS_B1S12| \ |
100 | e5c9a13e | balrog | GS_S1CR| \ |
101 | e5c9a13e | balrog | GS_S0CR| \ |
102 | e5c9a13e | balrog | GS_MINT| \ |
103 | e5c9a13e | balrog | GS_POINT| \ |
104 | e5c9a13e | balrog | GS_PIINT| \ |
105 | e5c9a13e | balrog | GS_RSRVD| \ |
106 | e5c9a13e | balrog | GS_MOINT| \ |
107 | e5c9a13e | balrog | GS_MIINT) |
108 | e5c9a13e | balrog | #define GS_VALID_MASK ((1 << 18) - 1) |
109 | e5c9a13e | balrog | #define GS_WCLEAR_MASK (GS_RCS|GS_S1R1|GS_S0R1|GS_GSCI)
|
110 | e5c9a13e | balrog | |
111 | e5c9a13e | balrog | #define BD_IOC (1<<31) |
112 | e5c9a13e | balrog | #define BD_BUP (1<<30) |
113 | e5c9a13e | balrog | |
114 | e5c9a13e | balrog | #define EACS_VRA 1 |
115 | e5c9a13e | balrog | #define EACS_VRM 8 |
116 | e5c9a13e | balrog | |
117 | e5c9a13e | balrog | #define VOL_MASK 0x1f |
118 | e5c9a13e | balrog | #define MUTE_SHIFT 15 |
119 | e5c9a13e | balrog | |
120 | e5c9a13e | balrog | #define REC_MASK 7 |
121 | e5c9a13e | balrog | enum {
|
122 | e5c9a13e | balrog | REC_MIC = 0,
|
123 | e5c9a13e | balrog | REC_CD, |
124 | e5c9a13e | balrog | REC_VIDEO, |
125 | e5c9a13e | balrog | REC_AUX, |
126 | e5c9a13e | balrog | REC_LINE_IN, |
127 | e5c9a13e | balrog | REC_STEREO_MIX, |
128 | e5c9a13e | balrog | REC_MONO_MIX, |
129 | e5c9a13e | balrog | REC_PHONE |
130 | e5c9a13e | balrog | }; |
131 | e5c9a13e | balrog | |
132 | e5c9a13e | balrog | typedef struct BD { |
133 | e5c9a13e | balrog | uint32_t addr; |
134 | e5c9a13e | balrog | uint32_t ctl_len; |
135 | e5c9a13e | balrog | } BD; |
136 | e5c9a13e | balrog | |
137 | e5c9a13e | balrog | typedef struct AC97BusMasterRegs { |
138 | e5c9a13e | balrog | uint32_t bdbar; /* rw 0 */
|
139 | e5c9a13e | balrog | uint8_t civ; /* ro 0 */
|
140 | e5c9a13e | balrog | uint8_t lvi; /* rw 0 */
|
141 | e5c9a13e | balrog | uint16_t sr; /* rw 1 */
|
142 | e5c9a13e | balrog | uint16_t picb; /* ro 0 */
|
143 | e5c9a13e | balrog | uint8_t piv; /* ro 0 */
|
144 | e5c9a13e | balrog | uint8_t cr; /* rw 0 */
|
145 | e5c9a13e | balrog | unsigned int bd_valid; |
146 | e5c9a13e | balrog | BD bd; |
147 | e5c9a13e | balrog | } AC97BusMasterRegs; |
148 | e5c9a13e | balrog | |
149 | e5c9a13e | balrog | typedef struct AC97LinkState { |
150 | 10ee2aaa | Juan Quintela | PCIDevice dev; |
151 | e5c9a13e | balrog | QEMUSoundCard card; |
152 | e5c9a13e | balrog | uint32_t glob_cnt; |
153 | e5c9a13e | balrog | uint32_t glob_sta; |
154 | e5c9a13e | balrog | uint32_t cas; |
155 | e5c9a13e | balrog | uint32_t last_samp; |
156 | e5c9a13e | balrog | AC97BusMasterRegs bm_regs[3];
|
157 | e5c9a13e | balrog | uint8_t mixer_data[256];
|
158 | e5c9a13e | balrog | SWVoiceIn *voice_pi; |
159 | e5c9a13e | balrog | SWVoiceOut *voice_po; |
160 | e5c9a13e | balrog | SWVoiceIn *voice_mc; |
161 | 2c44375d | malc | int invalid_freq[3]; |
162 | e5c9a13e | balrog | uint8_t silence[128];
|
163 | e5c9a13e | balrog | uint32_t base[2];
|
164 | e5c9a13e | balrog | int bup_flag;
|
165 | e5c9a13e | balrog | } AC97LinkState; |
166 | e5c9a13e | balrog | |
167 | e5c9a13e | balrog | enum {
|
168 | e5c9a13e | balrog | BUP_SET = 1,
|
169 | e5c9a13e | balrog | BUP_LAST = 2
|
170 | e5c9a13e | balrog | }; |
171 | e5c9a13e | balrog | |
172 | e5c9a13e | balrog | #ifdef DEBUG_AC97
|
173 | e5c9a13e | balrog | #define dolog(...) AUD_log ("ac97", __VA_ARGS__) |
174 | e5c9a13e | balrog | #else
|
175 | e5c9a13e | balrog | #define dolog(...)
|
176 | e5c9a13e | balrog | #endif
|
177 | e5c9a13e | balrog | |
178 | e5c9a13e | balrog | #define MKREGS(prefix, start) \
|
179 | e5c9a13e | balrog | enum { \
|
180 | e5c9a13e | balrog | prefix ## _BDBAR = start, \ |
181 | e5c9a13e | balrog | prefix ## _CIV = start + 4, \ |
182 | e5c9a13e | balrog | prefix ## _LVI = start + 5, \ |
183 | e5c9a13e | balrog | prefix ## _SR = start + 6, \ |
184 | e5c9a13e | balrog | prefix ## _PICB = start + 8, \ |
185 | e5c9a13e | balrog | prefix ## _PIV = start + 10, \ |
186 | e5c9a13e | balrog | prefix ## _CR = start + 11 \ |
187 | e5c9a13e | balrog | } |
188 | e5c9a13e | balrog | |
189 | e5c9a13e | balrog | enum {
|
190 | e5c9a13e | balrog | PI_INDEX = 0,
|
191 | e5c9a13e | balrog | PO_INDEX, |
192 | e5c9a13e | balrog | MC_INDEX, |
193 | e5c9a13e | balrog | LAST_INDEX |
194 | e5c9a13e | balrog | }; |
195 | e5c9a13e | balrog | |
196 | e5c9a13e | balrog | MKREGS (PI, PI_INDEX * 16);
|
197 | e5c9a13e | balrog | MKREGS (PO, PO_INDEX * 16);
|
198 | e5c9a13e | balrog | MKREGS (MC, MC_INDEX * 16);
|
199 | e5c9a13e | balrog | |
200 | e5c9a13e | balrog | enum {
|
201 | e5c9a13e | balrog | GLOB_CNT = 0x2c,
|
202 | e5c9a13e | balrog | GLOB_STA = 0x30,
|
203 | e5c9a13e | balrog | CAS = 0x34
|
204 | e5c9a13e | balrog | }; |
205 | e5c9a13e | balrog | |
206 | e5c9a13e | balrog | #define GET_BM(index) (((index) >> 4) & 3) |
207 | e5c9a13e | balrog | |
208 | e5c9a13e | balrog | static void po_callback (void *opaque, int free); |
209 | e5c9a13e | balrog | static void pi_callback (void *opaque, int avail); |
210 | e5c9a13e | balrog | static void mc_callback (void *opaque, int avail); |
211 | e5c9a13e | balrog | |
212 | e5c9a13e | balrog | static void warm_reset (AC97LinkState *s) |
213 | e5c9a13e | balrog | { |
214 | e5c9a13e | balrog | (void) s;
|
215 | e5c9a13e | balrog | } |
216 | e5c9a13e | balrog | |
217 | e5c9a13e | balrog | static void cold_reset (AC97LinkState * s) |
218 | e5c9a13e | balrog | { |
219 | e5c9a13e | balrog | (void) s;
|
220 | e5c9a13e | balrog | } |
221 | e5c9a13e | balrog | |
222 | e5c9a13e | balrog | static void fetch_bd (AC97LinkState *s, AC97BusMasterRegs *r) |
223 | e5c9a13e | balrog | { |
224 | e5c9a13e | balrog | uint8_t b[8];
|
225 | e5c9a13e | balrog | |
226 | e5c9a13e | balrog | cpu_physical_memory_read (r->bdbar + r->civ * 8, b, 8); |
227 | e5c9a13e | balrog | r->bd_valid = 1;
|
228 | e5c9a13e | balrog | r->bd.addr = le32_to_cpu (*(uint32_t *) &b[0]) & ~3; |
229 | e5c9a13e | balrog | r->bd.ctl_len = le32_to_cpu (*(uint32_t *) &b[4]);
|
230 | e5c9a13e | balrog | r->picb = r->bd.ctl_len & 0xffff;
|
231 | e5c9a13e | balrog | dolog ("bd %2d addr=%#x ctl=%#06x len=%#x(%d bytes)\n",
|
232 | e5c9a13e | balrog | r->civ, r->bd.addr, r->bd.ctl_len >> 16,
|
233 | e5c9a13e | balrog | r->bd.ctl_len & 0xffff,
|
234 | e5c9a13e | balrog | (r->bd.ctl_len & 0xffff) << 1); |
235 | e5c9a13e | balrog | } |
236 | e5c9a13e | balrog | |
237 | e5c9a13e | balrog | static void update_sr (AC97LinkState *s, AC97BusMasterRegs *r, uint32_t new_sr) |
238 | e5c9a13e | balrog | { |
239 | e5c9a13e | balrog | int event = 0; |
240 | e5c9a13e | balrog | int level = 0; |
241 | e5c9a13e | balrog | uint32_t new_mask = new_sr & SR_INT_MASK; |
242 | e5c9a13e | balrog | uint32_t old_mask = r->sr & SR_INT_MASK; |
243 | e5c9a13e | balrog | uint32_t masks[] = {GS_PIINT, GS_POINT, GS_MINT}; |
244 | e5c9a13e | balrog | |
245 | e5c9a13e | balrog | if (new_mask ^ old_mask) {
|
246 | e5c9a13e | balrog | /** @todo is IRQ deasserted when only one of status bits is cleared? */
|
247 | e5c9a13e | balrog | if (!new_mask) {
|
248 | e5c9a13e | balrog | event = 1;
|
249 | e5c9a13e | balrog | level = 0;
|
250 | e5c9a13e | balrog | } |
251 | e5c9a13e | balrog | else {
|
252 | e5c9a13e | balrog | if ((new_mask & SR_LVBCI) && (r->cr & CR_LVBIE)) {
|
253 | e5c9a13e | balrog | event = 1;
|
254 | e5c9a13e | balrog | level = 1;
|
255 | e5c9a13e | balrog | } |
256 | e5c9a13e | balrog | if ((new_mask & SR_BCIS) && (r->cr & CR_IOCE)) {
|
257 | e5c9a13e | balrog | event = 1;
|
258 | e5c9a13e | balrog | level = 1;
|
259 | e5c9a13e | balrog | } |
260 | e5c9a13e | balrog | } |
261 | e5c9a13e | balrog | } |
262 | e5c9a13e | balrog | |
263 | e5c9a13e | balrog | r->sr = new_sr; |
264 | e5c9a13e | balrog | |
265 | e5c9a13e | balrog | dolog ("IOC%d LVB%d sr=%#x event=%d level=%d\n",
|
266 | e5c9a13e | balrog | r->sr & SR_BCIS, r->sr & SR_LVBCI, |
267 | e5c9a13e | balrog | r->sr, |
268 | e5c9a13e | balrog | event, level); |
269 | e5c9a13e | balrog | |
270 | e5c9a13e | balrog | if (!event)
|
271 | e5c9a13e | balrog | return;
|
272 | e5c9a13e | balrog | |
273 | e5c9a13e | balrog | if (level) {
|
274 | e5c9a13e | balrog | s->glob_sta |= masks[r - s->bm_regs]; |
275 | e5c9a13e | balrog | dolog ("set irq level=1\n");
|
276 | 10ee2aaa | Juan Quintela | qemu_set_irq (s->dev.irq[0], 1); |
277 | e5c9a13e | balrog | } |
278 | e5c9a13e | balrog | else {
|
279 | e5c9a13e | balrog | s->glob_sta &= ~masks[r - s->bm_regs]; |
280 | e5c9a13e | balrog | dolog ("set irq level=0\n");
|
281 | 10ee2aaa | Juan Quintela | qemu_set_irq (s->dev.irq[0], 0); |
282 | e5c9a13e | balrog | } |
283 | e5c9a13e | balrog | } |
284 | e5c9a13e | balrog | |
285 | e5c9a13e | balrog | static void voice_set_active (AC97LinkState *s, int bm_index, int on) |
286 | e5c9a13e | balrog | { |
287 | e5c9a13e | balrog | switch (bm_index) {
|
288 | e5c9a13e | balrog | case PI_INDEX:
|
289 | e5c9a13e | balrog | AUD_set_active_in (s->voice_pi, on); |
290 | e5c9a13e | balrog | break;
|
291 | e5c9a13e | balrog | |
292 | e5c9a13e | balrog | case PO_INDEX:
|
293 | e5c9a13e | balrog | AUD_set_active_out (s->voice_po, on); |
294 | e5c9a13e | balrog | break;
|
295 | e5c9a13e | balrog | |
296 | e5c9a13e | balrog | case MC_INDEX:
|
297 | e5c9a13e | balrog | AUD_set_active_in (s->voice_mc, on); |
298 | e5c9a13e | balrog | break;
|
299 | e5c9a13e | balrog | |
300 | e5c9a13e | balrog | default:
|
301 | e5c9a13e | balrog | AUD_log ("ac97", "invalid bm_index(%d) in voice_set_active", bm_index); |
302 | e5c9a13e | balrog | break;
|
303 | e5c9a13e | balrog | } |
304 | e5c9a13e | balrog | } |
305 | e5c9a13e | balrog | |
306 | e5c9a13e | balrog | static void reset_bm_regs (AC97LinkState *s, AC97BusMasterRegs *r) |
307 | e5c9a13e | balrog | { |
308 | e5c9a13e | balrog | dolog ("reset_bm_regs\n");
|
309 | e5c9a13e | balrog | r->bdbar = 0;
|
310 | e5c9a13e | balrog | r->civ = 0;
|
311 | e5c9a13e | balrog | r->lvi = 0;
|
312 | e5c9a13e | balrog | /** todo do we need to do that? */
|
313 | e5c9a13e | balrog | update_sr (s, r, SR_DCH); |
314 | e5c9a13e | balrog | r->picb = 0;
|
315 | e5c9a13e | balrog | r->piv = 0;
|
316 | e5c9a13e | balrog | r->cr = r->cr & CR_DONT_CLEAR_MASK; |
317 | e5c9a13e | balrog | r->bd_valid = 0;
|
318 | e5c9a13e | balrog | |
319 | e5c9a13e | balrog | voice_set_active (s, r - s->bm_regs, 0);
|
320 | e5c9a13e | balrog | memset (s->silence, 0, sizeof (s->silence)); |
321 | e5c9a13e | balrog | } |
322 | e5c9a13e | balrog | |
323 | e5c9a13e | balrog | static void mixer_store (AC97LinkState *s, uint32_t i, uint16_t v) |
324 | e5c9a13e | balrog | { |
325 | e5c9a13e | balrog | if (i + 2 > sizeof (s->mixer_data)) { |
326 | e5c9a13e | balrog | dolog ("mixer_store: index %d out of bounds %d\n",
|
327 | e5c9a13e | balrog | i, sizeof (s->mixer_data));
|
328 | e5c9a13e | balrog | return;
|
329 | e5c9a13e | balrog | } |
330 | e5c9a13e | balrog | |
331 | e5c9a13e | balrog | s->mixer_data[i + 0] = v & 0xff; |
332 | e5c9a13e | balrog | s->mixer_data[i + 1] = v >> 8; |
333 | e5c9a13e | balrog | } |
334 | e5c9a13e | balrog | |
335 | e5c9a13e | balrog | static uint16_t mixer_load (AC97LinkState *s, uint32_t i)
|
336 | e5c9a13e | balrog | { |
337 | e5c9a13e | balrog | uint16_t val = 0xffff;
|
338 | e5c9a13e | balrog | |
339 | e5c9a13e | balrog | if (i + 2 > sizeof (s->mixer_data)) { |
340 | e5c9a13e | balrog | dolog ("mixer_store: index %d out of bounds %d\n",
|
341 | e5c9a13e | balrog | i, sizeof (s->mixer_data));
|
342 | e5c9a13e | balrog | } |
343 | e5c9a13e | balrog | else {
|
344 | e5c9a13e | balrog | val = s->mixer_data[i + 0] | (s->mixer_data[i + 1] << 8); |
345 | e5c9a13e | balrog | } |
346 | e5c9a13e | balrog | |
347 | e5c9a13e | balrog | return val;
|
348 | e5c9a13e | balrog | } |
349 | e5c9a13e | balrog | |
350 | e5c9a13e | balrog | static void open_voice (AC97LinkState *s, int index, int freq) |
351 | e5c9a13e | balrog | { |
352 | 1ea879e5 | malc | struct audsettings as;
|
353 | e5c9a13e | balrog | |
354 | e5c9a13e | balrog | as.freq = freq; |
355 | e5c9a13e | balrog | as.nchannels = 2;
|
356 | e5c9a13e | balrog | as.fmt = AUD_FMT_S16; |
357 | e5c9a13e | balrog | as.endianness = 0;
|
358 | e5c9a13e | balrog | |
359 | 2c44375d | malc | if (freq > 0) { |
360 | 2c44375d | malc | s->invalid_freq[index] = 0;
|
361 | 2c44375d | malc | switch (index) {
|
362 | 2c44375d | malc | case PI_INDEX:
|
363 | 2c44375d | malc | s->voice_pi = AUD_open_in ( |
364 | 2c44375d | malc | &s->card, |
365 | 2c44375d | malc | s->voice_pi, |
366 | 2c44375d | malc | "ac97.pi",
|
367 | 2c44375d | malc | s, |
368 | 2c44375d | malc | pi_callback, |
369 | 2c44375d | malc | &as |
370 | 2c44375d | malc | ); |
371 | 2c44375d | malc | break;
|
372 | e5c9a13e | balrog | |
373 | 2c44375d | malc | case PO_INDEX:
|
374 | 2c44375d | malc | s->voice_po = AUD_open_out ( |
375 | 2c44375d | malc | &s->card, |
376 | 2c44375d | malc | s->voice_po, |
377 | 2c44375d | malc | "ac97.po",
|
378 | 2c44375d | malc | s, |
379 | 2c44375d | malc | po_callback, |
380 | 2c44375d | malc | &as |
381 | 2c44375d | malc | ); |
382 | 2c44375d | malc | break;
|
383 | e5c9a13e | balrog | |
384 | 2c44375d | malc | case MC_INDEX:
|
385 | 2c44375d | malc | s->voice_mc = AUD_open_in ( |
386 | 2c44375d | malc | &s->card, |
387 | 2c44375d | malc | s->voice_mc, |
388 | 2c44375d | malc | "ac97.mc",
|
389 | 2c44375d | malc | s, |
390 | 2c44375d | malc | mc_callback, |
391 | 2c44375d | malc | &as |
392 | 2c44375d | malc | ); |
393 | 2c44375d | malc | break;
|
394 | 2c44375d | malc | } |
395 | 2c44375d | malc | } |
396 | 2c44375d | malc | else {
|
397 | 2c44375d | malc | s->invalid_freq[index] = freq; |
398 | 2c44375d | malc | switch (index) {
|
399 | 2c44375d | malc | case PI_INDEX:
|
400 | 2c44375d | malc | AUD_close_in (&s->card, s->voice_pi); |
401 | 2c44375d | malc | s->voice_pi = NULL;
|
402 | 2c44375d | malc | break;
|
403 | 2c44375d | malc | |
404 | 2c44375d | malc | case PO_INDEX:
|
405 | 2c44375d | malc | AUD_close_out (&s->card, s->voice_po); |
406 | 2c44375d | malc | s->voice_po = NULL;
|
407 | 2c44375d | malc | break;
|
408 | 2c44375d | malc | |
409 | 2c44375d | malc | case MC_INDEX:
|
410 | 2c44375d | malc | AUD_close_in (&s->card, s->voice_mc); |
411 | 2c44375d | malc | s->voice_mc = NULL;
|
412 | 2c44375d | malc | break;
|
413 | 2c44375d | malc | } |
414 | e5c9a13e | balrog | } |
415 | e5c9a13e | balrog | } |
416 | e5c9a13e | balrog | |
417 | e5c9a13e | balrog | static void reset_voices (AC97LinkState *s, uint8_t active[LAST_INDEX]) |
418 | e5c9a13e | balrog | { |
419 | e5c9a13e | balrog | uint16_t freq; |
420 | e5c9a13e | balrog | |
421 | e5c9a13e | balrog | freq = mixer_load (s, AC97_PCM_LR_ADC_Rate); |
422 | e5c9a13e | balrog | open_voice (s, PI_INDEX, freq); |
423 | e5c9a13e | balrog | AUD_set_active_in (s->voice_pi, active[PI_INDEX]); |
424 | e5c9a13e | balrog | |
425 | e5c9a13e | balrog | freq = mixer_load (s, AC97_PCM_Front_DAC_Rate); |
426 | e5c9a13e | balrog | open_voice (s, PO_INDEX, freq); |
427 | e5c9a13e | balrog | AUD_set_active_out (s->voice_po, active[PO_INDEX]); |
428 | e5c9a13e | balrog | |
429 | e5c9a13e | balrog | freq = mixer_load (s, AC97_MIC_ADC_Rate); |
430 | e5c9a13e | balrog | open_voice (s, MC_INDEX, freq); |
431 | e5c9a13e | balrog | AUD_set_active_in (s->voice_mc, active[MC_INDEX]); |
432 | e5c9a13e | balrog | } |
433 | e5c9a13e | balrog | |
434 | e5c9a13e | balrog | #ifdef USE_MIXER
|
435 | e5c9a13e | balrog | static void set_volume (AC97LinkState *s, int index, |
436 | e5c9a13e | balrog | audmixerctl_t mt, uint32_t val) |
437 | e5c9a13e | balrog | { |
438 | e5c9a13e | balrog | int mute = (val >> MUTE_SHIFT) & 1; |
439 | e5c9a13e | balrog | uint8_t rvol = VOL_MASK - (val & VOL_MASK); |
440 | e5c9a13e | balrog | uint8_t lvol = VOL_MASK - ((val >> 8) & VOL_MASK);
|
441 | e5c9a13e | balrog | rvol = 255 * rvol / VOL_MASK;
|
442 | e5c9a13e | balrog | lvol = 255 * lvol / VOL_MASK;
|
443 | e5c9a13e | balrog | |
444 | e5c9a13e | balrog | #ifdef SOFT_VOLUME
|
445 | e5c9a13e | balrog | if (index == AC97_Master_Volume_Mute) {
|
446 | e5c9a13e | balrog | AUD_set_volume_out (s->voice_po, mute, lvol, rvol); |
447 | e5c9a13e | balrog | } |
448 | e5c9a13e | balrog | else {
|
449 | e5c9a13e | balrog | AUD_set_volume (mt, &mute, &lvol, &rvol); |
450 | e5c9a13e | balrog | } |
451 | e5c9a13e | balrog | #else
|
452 | e5c9a13e | balrog | AUD_set_volume (mt, &mute, &lvol, &rvol); |
453 | e5c9a13e | balrog | #endif
|
454 | e5c9a13e | balrog | |
455 | e5c9a13e | balrog | rvol = VOL_MASK - ((VOL_MASK * rvol) / 255);
|
456 | e5c9a13e | balrog | lvol = VOL_MASK - ((VOL_MASK * lvol) / 255);
|
457 | e5c9a13e | balrog | mixer_store (s, index, val); |
458 | e5c9a13e | balrog | } |
459 | e5c9a13e | balrog | |
460 | e5c9a13e | balrog | static audrecsource_t ac97_to_aud_record_source (uint8_t i)
|
461 | e5c9a13e | balrog | { |
462 | e5c9a13e | balrog | switch (i) {
|
463 | e5c9a13e | balrog | case REC_MIC:
|
464 | e5c9a13e | balrog | return AUD_REC_MIC;
|
465 | e5c9a13e | balrog | |
466 | e5c9a13e | balrog | case REC_CD:
|
467 | e5c9a13e | balrog | return AUD_REC_CD;
|
468 | e5c9a13e | balrog | |
469 | e5c9a13e | balrog | case REC_VIDEO:
|
470 | e5c9a13e | balrog | return AUD_REC_VIDEO;
|
471 | e5c9a13e | balrog | |
472 | e5c9a13e | balrog | case REC_AUX:
|
473 | e5c9a13e | balrog | return AUD_REC_AUX;
|
474 | e5c9a13e | balrog | |
475 | e5c9a13e | balrog | case REC_LINE_IN:
|
476 | e5c9a13e | balrog | return AUD_REC_LINE_IN;
|
477 | e5c9a13e | balrog | |
478 | e5c9a13e | balrog | case REC_PHONE:
|
479 | e5c9a13e | balrog | return AUD_REC_PHONE;
|
480 | e5c9a13e | balrog | |
481 | e5c9a13e | balrog | default:
|
482 | e5c9a13e | balrog | dolog ("Unknown record source %d, using MIC\n", i);
|
483 | e5c9a13e | balrog | return AUD_REC_MIC;
|
484 | e5c9a13e | balrog | } |
485 | e5c9a13e | balrog | } |
486 | e5c9a13e | balrog | |
487 | e5c9a13e | balrog | static uint8_t aud_to_ac97_record_source (audrecsource_t rs)
|
488 | e5c9a13e | balrog | { |
489 | e5c9a13e | balrog | switch (rs) {
|
490 | e5c9a13e | balrog | case AUD_REC_MIC:
|
491 | e5c9a13e | balrog | return REC_MIC;
|
492 | e5c9a13e | balrog | |
493 | e5c9a13e | balrog | case AUD_REC_CD:
|
494 | e5c9a13e | balrog | return REC_CD;
|
495 | e5c9a13e | balrog | |
496 | e5c9a13e | balrog | case AUD_REC_VIDEO:
|
497 | e5c9a13e | balrog | return REC_VIDEO;
|
498 | e5c9a13e | balrog | |
499 | e5c9a13e | balrog | case AUD_REC_AUX:
|
500 | e5c9a13e | balrog | return REC_AUX;
|
501 | e5c9a13e | balrog | |
502 | e5c9a13e | balrog | case AUD_REC_LINE_IN:
|
503 | e5c9a13e | balrog | return REC_LINE_IN;
|
504 | e5c9a13e | balrog | |
505 | e5c9a13e | balrog | case AUD_REC_PHONE:
|
506 | e5c9a13e | balrog | return REC_PHONE;
|
507 | e5c9a13e | balrog | |
508 | e5c9a13e | balrog | default:
|
509 | e5c9a13e | balrog | dolog ("Unknown audio recording source %d using MIC\n", rs);
|
510 | e5c9a13e | balrog | return REC_MIC;
|
511 | e5c9a13e | balrog | } |
512 | e5c9a13e | balrog | } |
513 | e5c9a13e | balrog | |
514 | e5c9a13e | balrog | static void record_select (AC97LinkState *s, uint32_t val) |
515 | e5c9a13e | balrog | { |
516 | e5c9a13e | balrog | uint8_t rs = val & REC_MASK; |
517 | e5c9a13e | balrog | uint8_t ls = (val >> 8) & REC_MASK;
|
518 | e5c9a13e | balrog | audrecsource_t ars = ac97_to_aud_record_source (rs); |
519 | e5c9a13e | balrog | audrecsource_t als = ac97_to_aud_record_source (ls); |
520 | e5c9a13e | balrog | AUD_set_record_source (&als, &ars); |
521 | e5c9a13e | balrog | rs = aud_to_ac97_record_source (ars); |
522 | e5c9a13e | balrog | ls = aud_to_ac97_record_source (als); |
523 | e5c9a13e | balrog | mixer_store (s, AC97_Record_Select, rs | (ls << 8));
|
524 | e5c9a13e | balrog | } |
525 | e5c9a13e | balrog | #endif
|
526 | e5c9a13e | balrog | |
527 | e5c9a13e | balrog | static void mixer_reset (AC97LinkState *s) |
528 | e5c9a13e | balrog | { |
529 | e5c9a13e | balrog | uint8_t active[LAST_INDEX]; |
530 | e5c9a13e | balrog | |
531 | e5c9a13e | balrog | dolog ("mixer_reset\n");
|
532 | e5c9a13e | balrog | memset (s->mixer_data, 0, sizeof (s->mixer_data)); |
533 | e5c9a13e | balrog | memset (active, 0, sizeof (active)); |
534 | e5c9a13e | balrog | mixer_store (s, AC97_Reset , 0x0000); /* 6940 */ |
535 | e5c9a13e | balrog | mixer_store (s, AC97_Master_Volume_Mono_Mute , 0x8000);
|
536 | e5c9a13e | balrog | mixer_store (s, AC97_PC_BEEP_Volume_Mute , 0x0000);
|
537 | e5c9a13e | balrog | |
538 | e5c9a13e | balrog | mixer_store (s, AC97_Phone_Volume_Mute , 0x8008);
|
539 | e5c9a13e | balrog | mixer_store (s, AC97_Mic_Volume_Mute , 0x8008);
|
540 | e5c9a13e | balrog | mixer_store (s, AC97_CD_Volume_Mute , 0x8808);
|
541 | e5c9a13e | balrog | mixer_store (s, AC97_Aux_Volume_Mute , 0x8808);
|
542 | e5c9a13e | balrog | mixer_store (s, AC97_Record_Gain_Mic_Mute , 0x8000);
|
543 | e5c9a13e | balrog | mixer_store (s, AC97_General_Purpose , 0x0000);
|
544 | e5c9a13e | balrog | mixer_store (s, AC97_3D_Control , 0x0000);
|
545 | e5c9a13e | balrog | mixer_store (s, AC97_Powerdown_Ctrl_Stat , 0x000f);
|
546 | e5c9a13e | balrog | |
547 | e5c9a13e | balrog | /*
|
548 | e5c9a13e | balrog | * Sigmatel 9700 (STAC9700)
|
549 | e5c9a13e | balrog | */
|
550 | e5c9a13e | balrog | mixer_store (s, AC97_Vendor_ID1 , 0x8384);
|
551 | e5c9a13e | balrog | mixer_store (s, AC97_Vendor_ID2 , 0x7600); /* 7608 */ |
552 | e5c9a13e | balrog | |
553 | e5c9a13e | balrog | mixer_store (s, AC97_Extended_Audio_ID , 0x0809);
|
554 | e5c9a13e | balrog | mixer_store (s, AC97_Extended_Audio_Ctrl_Stat, 0x0009);
|
555 | e5c9a13e | balrog | mixer_store (s, AC97_PCM_Front_DAC_Rate , 0xbb80);
|
556 | e5c9a13e | balrog | mixer_store (s, AC97_PCM_Surround_DAC_Rate , 0xbb80);
|
557 | e5c9a13e | balrog | mixer_store (s, AC97_PCM_LFE_DAC_Rate , 0xbb80);
|
558 | e5c9a13e | balrog | mixer_store (s, AC97_PCM_LR_ADC_Rate , 0xbb80);
|
559 | e5c9a13e | balrog | mixer_store (s, AC97_MIC_ADC_Rate , 0xbb80);
|
560 | e5c9a13e | balrog | |
561 | e5c9a13e | balrog | #ifdef USE_MIXER
|
562 | e5c9a13e | balrog | record_select (s, 0);
|
563 | e5c9a13e | balrog | set_volume (s, AC97_Master_Volume_Mute, AUD_MIXER_VOLUME , 0x8000);
|
564 | e5c9a13e | balrog | set_volume (s, AC97_PCM_Out_Volume_Mute, AUD_MIXER_PCM , 0x8808);
|
565 | e5c9a13e | balrog | set_volume (s, AC97_Line_In_Volume_Mute, AUD_MIXER_LINE_IN, 0x8808);
|
566 | e5c9a13e | balrog | #endif
|
567 | e5c9a13e | balrog | reset_voices (s, active); |
568 | e5c9a13e | balrog | } |
569 | e5c9a13e | balrog | |
570 | e5c9a13e | balrog | /**
|
571 | e5c9a13e | balrog | * Native audio mixer
|
572 | e5c9a13e | balrog | * I/O Reads
|
573 | e5c9a13e | balrog | */
|
574 | e5c9a13e | balrog | static uint32_t nam_readb (void *opaque, uint32_t addr) |
575 | e5c9a13e | balrog | { |
576 | 10ee2aaa | Juan Quintela | AC97LinkState *s = opaque; |
577 | e5c9a13e | balrog | dolog ("U nam readb %#x\n", addr);
|
578 | e5c9a13e | balrog | s->cas = 0;
|
579 | e5c9a13e | balrog | return ~0U; |
580 | e5c9a13e | balrog | } |
581 | e5c9a13e | balrog | |
582 | e5c9a13e | balrog | static uint32_t nam_readw (void *opaque, uint32_t addr) |
583 | e5c9a13e | balrog | { |
584 | 10ee2aaa | Juan Quintela | AC97LinkState *s = opaque; |
585 | e5c9a13e | balrog | uint32_t val = ~0U;
|
586 | e5c9a13e | balrog | uint32_t index = addr - s->base[0];
|
587 | e5c9a13e | balrog | s->cas = 0;
|
588 | e5c9a13e | balrog | val = mixer_load (s, index); |
589 | e5c9a13e | balrog | return val;
|
590 | e5c9a13e | balrog | } |
591 | e5c9a13e | balrog | |
592 | e5c9a13e | balrog | static uint32_t nam_readl (void *opaque, uint32_t addr) |
593 | e5c9a13e | balrog | { |
594 | 10ee2aaa | Juan Quintela | AC97LinkState *s = opaque; |
595 | e5c9a13e | balrog | dolog ("U nam readl %#x\n", addr);
|
596 | e5c9a13e | balrog | s->cas = 0;
|
597 | e5c9a13e | balrog | return ~0U; |
598 | e5c9a13e | balrog | } |
599 | e5c9a13e | balrog | |
600 | e5c9a13e | balrog | /**
|
601 | e5c9a13e | balrog | * Native audio mixer
|
602 | e5c9a13e | balrog | * I/O Writes
|
603 | e5c9a13e | balrog | */
|
604 | e5c9a13e | balrog | static void nam_writeb (void *opaque, uint32_t addr, uint32_t val) |
605 | e5c9a13e | balrog | { |
606 | 10ee2aaa | Juan Quintela | AC97LinkState *s = opaque; |
607 | e5c9a13e | balrog | dolog ("U nam writeb %#x <- %#x\n", addr, val);
|
608 | e5c9a13e | balrog | s->cas = 0;
|
609 | e5c9a13e | balrog | } |
610 | e5c9a13e | balrog | |
611 | e5c9a13e | balrog | static void nam_writew (void *opaque, uint32_t addr, uint32_t val) |
612 | e5c9a13e | balrog | { |
613 | 10ee2aaa | Juan Quintela | AC97LinkState *s = opaque; |
614 | e5c9a13e | balrog | uint32_t index = addr - s->base[0];
|
615 | e5c9a13e | balrog | s->cas = 0;
|
616 | e5c9a13e | balrog | switch (index) {
|
617 | e5c9a13e | balrog | case AC97_Reset:
|
618 | e5c9a13e | balrog | mixer_reset (s); |
619 | e5c9a13e | balrog | break;
|
620 | e5c9a13e | balrog | case AC97_Powerdown_Ctrl_Stat:
|
621 | e5c9a13e | balrog | val &= ~0xf;
|
622 | e5c9a13e | balrog | val |= mixer_load (s, index) & 0xf;
|
623 | e5c9a13e | balrog | mixer_store (s, index, val); |
624 | e5c9a13e | balrog | break;
|
625 | e5c9a13e | balrog | #ifdef USE_MIXER
|
626 | e5c9a13e | balrog | case AC97_Master_Volume_Mute:
|
627 | e5c9a13e | balrog | set_volume (s, index, AUD_MIXER_VOLUME, val); |
628 | e5c9a13e | balrog | break;
|
629 | e5c9a13e | balrog | case AC97_PCM_Out_Volume_Mute:
|
630 | e5c9a13e | balrog | set_volume (s, index, AUD_MIXER_PCM, val); |
631 | e5c9a13e | balrog | break;
|
632 | e5c9a13e | balrog | case AC97_Line_In_Volume_Mute:
|
633 | e5c9a13e | balrog | set_volume (s, index, AUD_MIXER_LINE_IN, val); |
634 | e5c9a13e | balrog | break;
|
635 | e5c9a13e | balrog | case AC97_Record_Select:
|
636 | e5c9a13e | balrog | record_select (s, val); |
637 | e5c9a13e | balrog | break;
|
638 | e5c9a13e | balrog | #endif
|
639 | e5c9a13e | balrog | case AC97_Vendor_ID1:
|
640 | e5c9a13e | balrog | case AC97_Vendor_ID2:
|
641 | e5c9a13e | balrog | dolog ("Attempt to write vendor ID to %#x\n", val);
|
642 | e5c9a13e | balrog | break;
|
643 | e5c9a13e | balrog | case AC97_Extended_Audio_ID:
|
644 | e5c9a13e | balrog | dolog ("Attempt to write extended audio ID to %#x\n", val);
|
645 | e5c9a13e | balrog | break;
|
646 | e5c9a13e | balrog | case AC97_Extended_Audio_Ctrl_Stat:
|
647 | e5c9a13e | balrog | if (!(val & EACS_VRA)) {
|
648 | e5c9a13e | balrog | mixer_store (s, AC97_PCM_Front_DAC_Rate, 0xbb80);
|
649 | e5c9a13e | balrog | mixer_store (s, AC97_PCM_LR_ADC_Rate, 0xbb80);
|
650 | e5c9a13e | balrog | open_voice (s, PI_INDEX, 48000);
|
651 | e5c9a13e | balrog | open_voice (s, PO_INDEX, 48000);
|
652 | e5c9a13e | balrog | } |
653 | e5c9a13e | balrog | if (!(val & EACS_VRM)) {
|
654 | e5c9a13e | balrog | mixer_store (s, AC97_MIC_ADC_Rate, 0xbb80);
|
655 | e5c9a13e | balrog | open_voice (s, MC_INDEX, 48000);
|
656 | e5c9a13e | balrog | } |
657 | e5c9a13e | balrog | dolog ("Setting extended audio control to %#x\n", val);
|
658 | e5c9a13e | balrog | mixer_store (s, AC97_Extended_Audio_Ctrl_Stat, val); |
659 | e5c9a13e | balrog | break;
|
660 | e5c9a13e | balrog | case AC97_PCM_Front_DAC_Rate:
|
661 | e5c9a13e | balrog | if (mixer_load (s, AC97_Extended_Audio_Ctrl_Stat) & EACS_VRA) {
|
662 | e5c9a13e | balrog | mixer_store (s, index, val); |
663 | e5c9a13e | balrog | dolog ("Set front DAC rate to %d\n", val);
|
664 | e5c9a13e | balrog | open_voice (s, PO_INDEX, val); |
665 | e5c9a13e | balrog | } |
666 | e5c9a13e | balrog | else {
|
667 | e5c9a13e | balrog | dolog ("Attempt to set front DAC rate to %d, "
|
668 | e5c9a13e | balrog | "but VRA is not set\n",
|
669 | e5c9a13e | balrog | val); |
670 | e5c9a13e | balrog | } |
671 | e5c9a13e | balrog | break;
|
672 | e5c9a13e | balrog | case AC97_MIC_ADC_Rate:
|
673 | e5c9a13e | balrog | if (mixer_load (s, AC97_Extended_Audio_Ctrl_Stat) & EACS_VRM) {
|
674 | e5c9a13e | balrog | mixer_store (s, index, val); |
675 | e5c9a13e | balrog | dolog ("Set MIC ADC rate to %d\n", val);
|
676 | e5c9a13e | balrog | open_voice (s, MC_INDEX, val); |
677 | e5c9a13e | balrog | } |
678 | e5c9a13e | balrog | else {
|
679 | e5c9a13e | balrog | dolog ("Attempt to set MIC ADC rate to %d, "
|
680 | e5c9a13e | balrog | "but VRM is not set\n",
|
681 | e5c9a13e | balrog | val); |
682 | e5c9a13e | balrog | } |
683 | e5c9a13e | balrog | break;
|
684 | e5c9a13e | balrog | case AC97_PCM_LR_ADC_Rate:
|
685 | e5c9a13e | balrog | if (mixer_load (s, AC97_Extended_Audio_Ctrl_Stat) & EACS_VRA) {
|
686 | e5c9a13e | balrog | mixer_store (s, index, val); |
687 | e5c9a13e | balrog | dolog ("Set front LR ADC rate to %d\n", val);
|
688 | e5c9a13e | balrog | open_voice (s, PI_INDEX, val); |
689 | e5c9a13e | balrog | } |
690 | e5c9a13e | balrog | else {
|
691 | e5c9a13e | balrog | dolog ("Attempt to set LR ADC rate to %d, but VRA is not set\n",
|
692 | e5c9a13e | balrog | val); |
693 | e5c9a13e | balrog | } |
694 | e5c9a13e | balrog | break;
|
695 | e5c9a13e | balrog | default:
|
696 | e5c9a13e | balrog | dolog ("U nam writew %#x <- %#x\n", addr, val);
|
697 | e5c9a13e | balrog | mixer_store (s, index, val); |
698 | e5c9a13e | balrog | break;
|
699 | e5c9a13e | balrog | } |
700 | e5c9a13e | balrog | } |
701 | e5c9a13e | balrog | |
702 | e5c9a13e | balrog | static void nam_writel (void *opaque, uint32_t addr, uint32_t val) |
703 | e5c9a13e | balrog | { |
704 | 10ee2aaa | Juan Quintela | AC97LinkState *s = opaque; |
705 | e5c9a13e | balrog | dolog ("U nam writel %#x <- %#x\n", addr, val);
|
706 | e5c9a13e | balrog | s->cas = 0;
|
707 | e5c9a13e | balrog | } |
708 | e5c9a13e | balrog | |
709 | e5c9a13e | balrog | /**
|
710 | e5c9a13e | balrog | * Native audio bus master
|
711 | e5c9a13e | balrog | * I/O Reads
|
712 | e5c9a13e | balrog | */
|
713 | e5c9a13e | balrog | static uint32_t nabm_readb (void *opaque, uint32_t addr) |
714 | e5c9a13e | balrog | { |
715 | 10ee2aaa | Juan Quintela | AC97LinkState *s = opaque; |
716 | e5c9a13e | balrog | AC97BusMasterRegs *r = NULL;
|
717 | e5c9a13e | balrog | uint32_t index = addr - s->base[1];
|
718 | e5c9a13e | balrog | uint32_t val = ~0U;
|
719 | e5c9a13e | balrog | |
720 | e5c9a13e | balrog | switch (index) {
|
721 | e5c9a13e | balrog | case CAS:
|
722 | e5c9a13e | balrog | dolog ("CAS %d\n", s->cas);
|
723 | e5c9a13e | balrog | val = s->cas; |
724 | e5c9a13e | balrog | s->cas = 1;
|
725 | e5c9a13e | balrog | break;
|
726 | e5c9a13e | balrog | case PI_CIV:
|
727 | e5c9a13e | balrog | case PO_CIV:
|
728 | e5c9a13e | balrog | case MC_CIV:
|
729 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
730 | e5c9a13e | balrog | val = r->civ; |
731 | e5c9a13e | balrog | dolog ("CIV[%d] -> %#x\n", GET_BM (index), val);
|
732 | e5c9a13e | balrog | break;
|
733 | e5c9a13e | balrog | case PI_LVI:
|
734 | e5c9a13e | balrog | case PO_LVI:
|
735 | e5c9a13e | balrog | case MC_LVI:
|
736 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
737 | e5c9a13e | balrog | val = r->lvi; |
738 | e5c9a13e | balrog | dolog ("LVI[%d] -> %#x\n", GET_BM (index), val);
|
739 | e5c9a13e | balrog | break;
|
740 | e5c9a13e | balrog | case PI_PIV:
|
741 | e5c9a13e | balrog | case PO_PIV:
|
742 | e5c9a13e | balrog | case MC_PIV:
|
743 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
744 | e5c9a13e | balrog | val = r->piv; |
745 | e5c9a13e | balrog | dolog ("PIV[%d] -> %#x\n", GET_BM (index), val);
|
746 | e5c9a13e | balrog | break;
|
747 | e5c9a13e | balrog | case PI_CR:
|
748 | e5c9a13e | balrog | case PO_CR:
|
749 | e5c9a13e | balrog | case MC_CR:
|
750 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
751 | e5c9a13e | balrog | val = r->cr; |
752 | e5c9a13e | balrog | dolog ("CR[%d] -> %#x\n", GET_BM (index), val);
|
753 | e5c9a13e | balrog | break;
|
754 | e5c9a13e | balrog | case PI_SR:
|
755 | e5c9a13e | balrog | case PO_SR:
|
756 | e5c9a13e | balrog | case MC_SR:
|
757 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
758 | e5c9a13e | balrog | val = r->sr & 0xff;
|
759 | e5c9a13e | balrog | dolog ("SRb[%d] -> %#x\n", GET_BM (index), val);
|
760 | e5c9a13e | balrog | break;
|
761 | e5c9a13e | balrog | default:
|
762 | e5c9a13e | balrog | dolog ("U nabm readb %#x -> %#x\n", addr, val);
|
763 | e5c9a13e | balrog | break;
|
764 | e5c9a13e | balrog | } |
765 | e5c9a13e | balrog | return val;
|
766 | e5c9a13e | balrog | } |
767 | e5c9a13e | balrog | |
768 | e5c9a13e | balrog | static uint32_t nabm_readw (void *opaque, uint32_t addr) |
769 | e5c9a13e | balrog | { |
770 | 10ee2aaa | Juan Quintela | AC97LinkState *s = opaque; |
771 | e5c9a13e | balrog | AC97BusMasterRegs *r = NULL;
|
772 | e5c9a13e | balrog | uint32_t index = addr - s->base[1];
|
773 | e5c9a13e | balrog | uint32_t val = ~0U;
|
774 | e5c9a13e | balrog | |
775 | e5c9a13e | balrog | switch (index) {
|
776 | e5c9a13e | balrog | case PI_SR:
|
777 | e5c9a13e | balrog | case PO_SR:
|
778 | e5c9a13e | balrog | case MC_SR:
|
779 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
780 | e5c9a13e | balrog | val = r->sr; |
781 | e5c9a13e | balrog | dolog ("SR[%d] -> %#x\n", GET_BM (index), val);
|
782 | e5c9a13e | balrog | break;
|
783 | e5c9a13e | balrog | case PI_PICB:
|
784 | e5c9a13e | balrog | case PO_PICB:
|
785 | e5c9a13e | balrog | case MC_PICB:
|
786 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
787 | e5c9a13e | balrog | val = r->picb; |
788 | e5c9a13e | balrog | dolog ("PICB[%d] -> %#x\n", GET_BM (index), val);
|
789 | e5c9a13e | balrog | break;
|
790 | e5c9a13e | balrog | default:
|
791 | e5c9a13e | balrog | dolog ("U nabm readw %#x -> %#x\n", addr, val);
|
792 | e5c9a13e | balrog | break;
|
793 | e5c9a13e | balrog | } |
794 | e5c9a13e | balrog | return val;
|
795 | e5c9a13e | balrog | } |
796 | e5c9a13e | balrog | |
797 | e5c9a13e | balrog | static uint32_t nabm_readl (void *opaque, uint32_t addr) |
798 | e5c9a13e | balrog | { |
799 | 10ee2aaa | Juan Quintela | AC97LinkState *s = opaque; |
800 | e5c9a13e | balrog | AC97BusMasterRegs *r = NULL;
|
801 | e5c9a13e | balrog | uint32_t index = addr - s->base[1];
|
802 | e5c9a13e | balrog | uint32_t val = ~0U;
|
803 | e5c9a13e | balrog | |
804 | e5c9a13e | balrog | switch (index) {
|
805 | e5c9a13e | balrog | case PI_BDBAR:
|
806 | e5c9a13e | balrog | case PO_BDBAR:
|
807 | e5c9a13e | balrog | case MC_BDBAR:
|
808 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
809 | e5c9a13e | balrog | val = r->bdbar; |
810 | e5c9a13e | balrog | dolog ("BMADDR[%d] -> %#x\n", GET_BM (index), val);
|
811 | e5c9a13e | balrog | break;
|
812 | e5c9a13e | balrog | case PI_CIV:
|
813 | e5c9a13e | balrog | case PO_CIV:
|
814 | e5c9a13e | balrog | case MC_CIV:
|
815 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
816 | e5c9a13e | balrog | val = r->civ | (r->lvi << 8) | (r->sr << 16); |
817 | e5c9a13e | balrog | dolog ("CIV LVI SR[%d] -> %#x, %#x, %#x\n", GET_BM (index),
|
818 | e5c9a13e | balrog | r->civ, r->lvi, r->sr); |
819 | e5c9a13e | balrog | break;
|
820 | e5c9a13e | balrog | case PI_PICB:
|
821 | e5c9a13e | balrog | case PO_PICB:
|
822 | e5c9a13e | balrog | case MC_PICB:
|
823 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
824 | e5c9a13e | balrog | val = r->picb | (r->piv << 16) | (r->cr << 24); |
825 | e5c9a13e | balrog | dolog ("PICB PIV CR[%d] -> %#x %#x %#x %#x\n", GET_BM (index),
|
826 | e5c9a13e | balrog | val, r->picb, r->piv, r->cr); |
827 | e5c9a13e | balrog | break;
|
828 | e5c9a13e | balrog | case GLOB_CNT:
|
829 | e5c9a13e | balrog | val = s->glob_cnt; |
830 | e5c9a13e | balrog | dolog ("glob_cnt -> %#x\n", val);
|
831 | e5c9a13e | balrog | break;
|
832 | e5c9a13e | balrog | case GLOB_STA:
|
833 | e5c9a13e | balrog | val = s->glob_sta | GS_S0CR; |
834 | e5c9a13e | balrog | dolog ("glob_sta -> %#x\n", val);
|
835 | e5c9a13e | balrog | break;
|
836 | e5c9a13e | balrog | default:
|
837 | e5c9a13e | balrog | dolog ("U nabm readl %#x -> %#x\n", addr, val);
|
838 | e5c9a13e | balrog | break;
|
839 | e5c9a13e | balrog | } |
840 | e5c9a13e | balrog | return val;
|
841 | e5c9a13e | balrog | } |
842 | e5c9a13e | balrog | |
843 | e5c9a13e | balrog | /**
|
844 | e5c9a13e | balrog | * Native audio bus master
|
845 | e5c9a13e | balrog | * I/O Writes
|
846 | e5c9a13e | balrog | */
|
847 | e5c9a13e | balrog | static void nabm_writeb (void *opaque, uint32_t addr, uint32_t val) |
848 | e5c9a13e | balrog | { |
849 | 10ee2aaa | Juan Quintela | AC97LinkState *s = opaque; |
850 | e5c9a13e | balrog | AC97BusMasterRegs *r = NULL;
|
851 | e5c9a13e | balrog | uint32_t index = addr - s->base[1];
|
852 | e5c9a13e | balrog | switch (index) {
|
853 | e5c9a13e | balrog | case PI_LVI:
|
854 | e5c9a13e | balrog | case PO_LVI:
|
855 | e5c9a13e | balrog | case MC_LVI:
|
856 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
857 | e5c9a13e | balrog | if ((r->cr & CR_RPBM) && (r->sr & SR_DCH)) {
|
858 | e5c9a13e | balrog | r->sr &= ~(SR_DCH | SR_CELV); |
859 | e5c9a13e | balrog | r->civ = r->piv; |
860 | e5c9a13e | balrog | r->piv = (r->piv + 1) % 32; |
861 | e5c9a13e | balrog | fetch_bd (s, r); |
862 | e5c9a13e | balrog | } |
863 | e5c9a13e | balrog | r->lvi = val % 32;
|
864 | e5c9a13e | balrog | dolog ("LVI[%d] <- %#x\n", GET_BM (index), val);
|
865 | e5c9a13e | balrog | break;
|
866 | e5c9a13e | balrog | case PI_CR:
|
867 | e5c9a13e | balrog | case PO_CR:
|
868 | e5c9a13e | balrog | case MC_CR:
|
869 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
870 | e5c9a13e | balrog | if (val & CR_RR) {
|
871 | e5c9a13e | balrog | reset_bm_regs (s, r); |
872 | e5c9a13e | balrog | } |
873 | e5c9a13e | balrog | else {
|
874 | e5c9a13e | balrog | r->cr = val & CR_VALID_MASK; |
875 | e5c9a13e | balrog | if (!(r->cr & CR_RPBM)) {
|
876 | e5c9a13e | balrog | voice_set_active (s, r - s->bm_regs, 0);
|
877 | e5c9a13e | balrog | r->sr |= SR_DCH; |
878 | e5c9a13e | balrog | } |
879 | e5c9a13e | balrog | else {
|
880 | e5c9a13e | balrog | r->civ = r->piv; |
881 | e5c9a13e | balrog | r->piv = (r->piv + 1) % 32; |
882 | e5c9a13e | balrog | fetch_bd (s, r); |
883 | e5c9a13e | balrog | r->sr &= ~SR_DCH; |
884 | e5c9a13e | balrog | voice_set_active (s, r - s->bm_regs, 1);
|
885 | e5c9a13e | balrog | } |
886 | e5c9a13e | balrog | } |
887 | e5c9a13e | balrog | dolog ("CR[%d] <- %#x (cr %#x)\n", GET_BM (index), val, r->cr);
|
888 | e5c9a13e | balrog | break;
|
889 | e5c9a13e | balrog | case PI_SR:
|
890 | e5c9a13e | balrog | case PO_SR:
|
891 | e5c9a13e | balrog | case MC_SR:
|
892 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
893 | e5c9a13e | balrog | r->sr |= val & ~(SR_RO_MASK | SR_WCLEAR_MASK); |
894 | e5c9a13e | balrog | update_sr (s, r, r->sr & ~(val & SR_WCLEAR_MASK)); |
895 | e5c9a13e | balrog | dolog ("SR[%d] <- %#x (sr %#x)\n", GET_BM (index), val, r->sr);
|
896 | e5c9a13e | balrog | break;
|
897 | e5c9a13e | balrog | default:
|
898 | e5c9a13e | balrog | dolog ("U nabm writeb %#x <- %#x\n", addr, val);
|
899 | e5c9a13e | balrog | break;
|
900 | e5c9a13e | balrog | } |
901 | e5c9a13e | balrog | } |
902 | e5c9a13e | balrog | |
903 | e5c9a13e | balrog | static void nabm_writew (void *opaque, uint32_t addr, uint32_t val) |
904 | e5c9a13e | balrog | { |
905 | 10ee2aaa | Juan Quintela | AC97LinkState *s = opaque; |
906 | e5c9a13e | balrog | AC97BusMasterRegs *r = NULL;
|
907 | e5c9a13e | balrog | uint32_t index = addr - s->base[1];
|
908 | e5c9a13e | balrog | switch (index) {
|
909 | e5c9a13e | balrog | case PI_SR:
|
910 | e5c9a13e | balrog | case PO_SR:
|
911 | e5c9a13e | balrog | case MC_SR:
|
912 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
913 | e5c9a13e | balrog | r->sr |= val & ~(SR_RO_MASK | SR_WCLEAR_MASK); |
914 | e5c9a13e | balrog | update_sr (s, r, r->sr & ~(val & SR_WCLEAR_MASK)); |
915 | e5c9a13e | balrog | dolog ("SR[%d] <- %#x (sr %#x)\n", GET_BM (index), val, r->sr);
|
916 | e5c9a13e | balrog | break;
|
917 | e5c9a13e | balrog | default:
|
918 | e5c9a13e | balrog | dolog ("U nabm writew %#x <- %#x\n", addr, val);
|
919 | e5c9a13e | balrog | break;
|
920 | e5c9a13e | balrog | } |
921 | e5c9a13e | balrog | } |
922 | e5c9a13e | balrog | |
923 | e5c9a13e | balrog | static void nabm_writel (void *opaque, uint32_t addr, uint32_t val) |
924 | e5c9a13e | balrog | { |
925 | 10ee2aaa | Juan Quintela | AC97LinkState *s = opaque; |
926 | e5c9a13e | balrog | AC97BusMasterRegs *r = NULL;
|
927 | e5c9a13e | balrog | uint32_t index = addr - s->base[1];
|
928 | e5c9a13e | balrog | switch (index) {
|
929 | e5c9a13e | balrog | case PI_BDBAR:
|
930 | e5c9a13e | balrog | case PO_BDBAR:
|
931 | e5c9a13e | balrog | case MC_BDBAR:
|
932 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
933 | e5c9a13e | balrog | r->bdbar = val & ~3;
|
934 | e5c9a13e | balrog | dolog ("BDBAR[%d] <- %#x (bdbar %#x)\n",
|
935 | e5c9a13e | balrog | GET_BM (index), val, r->bdbar); |
936 | e5c9a13e | balrog | break;
|
937 | e5c9a13e | balrog | case GLOB_CNT:
|
938 | e5c9a13e | balrog | if (val & GC_WR)
|
939 | e5c9a13e | balrog | warm_reset (s); |
940 | e5c9a13e | balrog | if (val & GC_CR)
|
941 | e5c9a13e | balrog | cold_reset (s); |
942 | e5c9a13e | balrog | if (!(val & (GC_WR | GC_CR)))
|
943 | e5c9a13e | balrog | s->glob_cnt = val & GC_VALID_MASK; |
944 | e5c9a13e | balrog | dolog ("glob_cnt <- %#x (glob_cnt %#x)\n", val, s->glob_cnt);
|
945 | e5c9a13e | balrog | break;
|
946 | e5c9a13e | balrog | case GLOB_STA:
|
947 | e5c9a13e | balrog | s->glob_sta &= ~(val & GS_WCLEAR_MASK); |
948 | e5c9a13e | balrog | s->glob_sta |= (val & ~(GS_WCLEAR_MASK | GS_RO_MASK)) & GS_VALID_MASK; |
949 | e5c9a13e | balrog | dolog ("glob_sta <- %#x (glob_sta %#x)\n", val, s->glob_sta);
|
950 | e5c9a13e | balrog | break;
|
951 | e5c9a13e | balrog | default:
|
952 | e5c9a13e | balrog | dolog ("U nabm writel %#x <- %#x\n", addr, val);
|
953 | e5c9a13e | balrog | break;
|
954 | e5c9a13e | balrog | } |
955 | e5c9a13e | balrog | } |
956 | e5c9a13e | balrog | |
957 | e5c9a13e | balrog | static int write_audio (AC97LinkState *s, AC97BusMasterRegs *r, |
958 | e5c9a13e | balrog | int max, int *stop) |
959 | e5c9a13e | balrog | { |
960 | e5c9a13e | balrog | uint8_t tmpbuf[4096];
|
961 | e5c9a13e | balrog | uint32_t addr = r->bd.addr; |
962 | e5c9a13e | balrog | uint32_t temp = r->picb << 1;
|
963 | e5c9a13e | balrog | uint32_t written = 0;
|
964 | e5c9a13e | balrog | int to_copy = 0; |
965 | e5c9a13e | balrog | temp = audio_MIN (temp, max); |
966 | e5c9a13e | balrog | |
967 | e5c9a13e | balrog | if (!temp) {
|
968 | e5c9a13e | balrog | *stop = 1;
|
969 | e5c9a13e | balrog | return 0; |
970 | e5c9a13e | balrog | } |
971 | e5c9a13e | balrog | |
972 | e5c9a13e | balrog | while (temp) {
|
973 | e5c9a13e | balrog | int copied;
|
974 | e5c9a13e | balrog | to_copy = audio_MIN (temp, sizeof (tmpbuf));
|
975 | e5c9a13e | balrog | cpu_physical_memory_read (addr, tmpbuf, to_copy); |
976 | e5c9a13e | balrog | copied = AUD_write (s->voice_po, tmpbuf, to_copy); |
977 | e5c9a13e | balrog | dolog ("write_audio max=%x to_copy=%x copied=%x\n",
|
978 | e5c9a13e | balrog | max, to_copy, copied); |
979 | e5c9a13e | balrog | if (!copied) {
|
980 | e5c9a13e | balrog | *stop = 1;
|
981 | e5c9a13e | balrog | break;
|
982 | e5c9a13e | balrog | } |
983 | e5c9a13e | balrog | temp -= copied; |
984 | e5c9a13e | balrog | addr += copied; |
985 | e5c9a13e | balrog | written += copied; |
986 | e5c9a13e | balrog | } |
987 | e5c9a13e | balrog | |
988 | e5c9a13e | balrog | if (!temp) {
|
989 | e5c9a13e | balrog | if (to_copy < 4) { |
990 | e5c9a13e | balrog | dolog ("whoops\n");
|
991 | e5c9a13e | balrog | s->last_samp = 0;
|
992 | e5c9a13e | balrog | } |
993 | e5c9a13e | balrog | else {
|
994 | e5c9a13e | balrog | s->last_samp = *(uint32_t *) &tmpbuf[to_copy - 4];
|
995 | e5c9a13e | balrog | } |
996 | e5c9a13e | balrog | } |
997 | e5c9a13e | balrog | |
998 | e5c9a13e | balrog | r->bd.addr = addr; |
999 | e5c9a13e | balrog | return written;
|
1000 | e5c9a13e | balrog | } |
1001 | e5c9a13e | balrog | |
1002 | e5c9a13e | balrog | static void write_bup (AC97LinkState *s, int elapsed) |
1003 | e5c9a13e | balrog | { |
1004 | e5c9a13e | balrog | int written = 0; |
1005 | e5c9a13e | balrog | |
1006 | e5c9a13e | balrog | dolog ("write_bup\n");
|
1007 | e5c9a13e | balrog | if (!(s->bup_flag & BUP_SET)) {
|
1008 | e5c9a13e | balrog | if (s->bup_flag & BUP_LAST) {
|
1009 | e5c9a13e | balrog | int i;
|
1010 | e5c9a13e | balrog | uint8_t *p = s->silence; |
1011 | e5c9a13e | balrog | for (i = 0; i < sizeof (s->silence) / 4; i++, p += 4) { |
1012 | e5c9a13e | balrog | *(uint32_t *) p = s->last_samp; |
1013 | e5c9a13e | balrog | } |
1014 | e5c9a13e | balrog | } |
1015 | e5c9a13e | balrog | else {
|
1016 | e5c9a13e | balrog | memset (s->silence, 0, sizeof (s->silence)); |
1017 | e5c9a13e | balrog | } |
1018 | e5c9a13e | balrog | s->bup_flag |= BUP_SET; |
1019 | e5c9a13e | balrog | } |
1020 | e5c9a13e | balrog | |
1021 | e5c9a13e | balrog | while (elapsed) {
|
1022 | e5c9a13e | balrog | int temp = audio_MIN (elapsed, sizeof (s->silence)); |
1023 | e5c9a13e | balrog | while (temp) {
|
1024 | e5c9a13e | balrog | int copied = AUD_write (s->voice_po, s->silence, temp);
|
1025 | e5c9a13e | balrog | if (!copied)
|
1026 | e5c9a13e | balrog | return;
|
1027 | e5c9a13e | balrog | temp -= copied; |
1028 | e5c9a13e | balrog | elapsed -= copied; |
1029 | e5c9a13e | balrog | written += copied; |
1030 | e5c9a13e | balrog | } |
1031 | e5c9a13e | balrog | } |
1032 | e5c9a13e | balrog | } |
1033 | e5c9a13e | balrog | |
1034 | e5c9a13e | balrog | static int read_audio (AC97LinkState *s, AC97BusMasterRegs *r, |
1035 | e5c9a13e | balrog | int max, int *stop) |
1036 | e5c9a13e | balrog | { |
1037 | e5c9a13e | balrog | uint8_t tmpbuf[4096];
|
1038 | e5c9a13e | balrog | uint32_t addr = r->bd.addr; |
1039 | e5c9a13e | balrog | uint32_t temp = r->picb << 1;
|
1040 | e5c9a13e | balrog | uint32_t nread = 0;
|
1041 | e5c9a13e | balrog | int to_copy = 0; |
1042 | e5c9a13e | balrog | SWVoiceIn *voice = (r - s->bm_regs) == MC_INDEX ? s->voice_mc : s->voice_pi; |
1043 | e5c9a13e | balrog | |
1044 | e5c9a13e | balrog | temp = audio_MIN (temp, max); |
1045 | e5c9a13e | balrog | |
1046 | e5c9a13e | balrog | if (!temp) {
|
1047 | e5c9a13e | balrog | *stop = 1;
|
1048 | e5c9a13e | balrog | return 0; |
1049 | e5c9a13e | balrog | } |
1050 | e5c9a13e | balrog | |
1051 | e5c9a13e | balrog | while (temp) {
|
1052 | e5c9a13e | balrog | int acquired;
|
1053 | e5c9a13e | balrog | to_copy = audio_MIN (temp, sizeof (tmpbuf));
|
1054 | e5c9a13e | balrog | acquired = AUD_read (voice, tmpbuf, to_copy); |
1055 | e5c9a13e | balrog | if (!acquired) {
|
1056 | e5c9a13e | balrog | *stop = 1;
|
1057 | e5c9a13e | balrog | break;
|
1058 | e5c9a13e | balrog | } |
1059 | e5c9a13e | balrog | cpu_physical_memory_write (addr, tmpbuf, acquired); |
1060 | e5c9a13e | balrog | temp -= acquired; |
1061 | e5c9a13e | balrog | addr += acquired; |
1062 | e5c9a13e | balrog | nread += acquired; |
1063 | e5c9a13e | balrog | } |
1064 | e5c9a13e | balrog | |
1065 | e5c9a13e | balrog | r->bd.addr = addr; |
1066 | e5c9a13e | balrog | return nread;
|
1067 | e5c9a13e | balrog | } |
1068 | e5c9a13e | balrog | |
1069 | e5c9a13e | balrog | static void transfer_audio (AC97LinkState *s, int index, int elapsed) |
1070 | e5c9a13e | balrog | { |
1071 | e5c9a13e | balrog | AC97BusMasterRegs *r = &s->bm_regs[index]; |
1072 | e5c9a13e | balrog | int written = 0, stop = 0; |
1073 | e5c9a13e | balrog | |
1074 | 2c44375d | malc | if (s->invalid_freq[index]) {
|
1075 | 2c44375d | malc | AUD_log ("ac97", "attempt to use voice %d with invalid frequency %d\n", |
1076 | 2c44375d | malc | index, s->invalid_freq[index]); |
1077 | 2c44375d | malc | return;
|
1078 | 2c44375d | malc | } |
1079 | 2c44375d | malc | |
1080 | e5c9a13e | balrog | if (r->sr & SR_DCH) {
|
1081 | e5c9a13e | balrog | if (r->cr & CR_RPBM) {
|
1082 | e5c9a13e | balrog | switch (index) {
|
1083 | e5c9a13e | balrog | case PO_INDEX:
|
1084 | e5c9a13e | balrog | write_bup (s, elapsed); |
1085 | e5c9a13e | balrog | break;
|
1086 | e5c9a13e | balrog | } |
1087 | e5c9a13e | balrog | } |
1088 | e5c9a13e | balrog | return;
|
1089 | e5c9a13e | balrog | } |
1090 | e5c9a13e | balrog | |
1091 | e5c9a13e | balrog | while ((elapsed >> 1) && !stop) { |
1092 | e5c9a13e | balrog | int temp;
|
1093 | e5c9a13e | balrog | |
1094 | e5c9a13e | balrog | if (!r->bd_valid) {
|
1095 | e5c9a13e | balrog | dolog ("invalid bd\n");
|
1096 | e5c9a13e | balrog | fetch_bd (s, r); |
1097 | e5c9a13e | balrog | } |
1098 | e5c9a13e | balrog | |
1099 | e5c9a13e | balrog | if (!r->picb) {
|
1100 | e5c9a13e | balrog | dolog ("fresh bd %d is empty %#x %#x\n",
|
1101 | e5c9a13e | balrog | r->civ, r->bd.addr, r->bd.ctl_len); |
1102 | e5c9a13e | balrog | if (r->civ == r->lvi) {
|
1103 | e5c9a13e | balrog | r->sr |= SR_DCH; /* CELV? */
|
1104 | e5c9a13e | balrog | s->bup_flag = 0;
|
1105 | e5c9a13e | balrog | break;
|
1106 | e5c9a13e | balrog | } |
1107 | e5c9a13e | balrog | r->sr &= ~SR_CELV; |
1108 | e5c9a13e | balrog | r->civ = r->piv; |
1109 | e5c9a13e | balrog | r->piv = (r->piv + 1) % 32; |
1110 | e5c9a13e | balrog | fetch_bd (s, r); |
1111 | e5c9a13e | balrog | return;
|
1112 | e5c9a13e | balrog | } |
1113 | e5c9a13e | balrog | |
1114 | e5c9a13e | balrog | switch (index) {
|
1115 | e5c9a13e | balrog | case PO_INDEX:
|
1116 | e5c9a13e | balrog | temp = write_audio (s, r, elapsed, &stop); |
1117 | e5c9a13e | balrog | written += temp; |
1118 | e5c9a13e | balrog | elapsed -= temp; |
1119 | e5c9a13e | balrog | r->picb -= (temp >> 1);
|
1120 | e5c9a13e | balrog | break;
|
1121 | e5c9a13e | balrog | |
1122 | e5c9a13e | balrog | case PI_INDEX:
|
1123 | e5c9a13e | balrog | case MC_INDEX:
|
1124 | e5c9a13e | balrog | temp = read_audio (s, r, elapsed, &stop); |
1125 | e5c9a13e | balrog | elapsed -= temp; |
1126 | e5c9a13e | balrog | r->picb -= (temp >> 1);
|
1127 | e5c9a13e | balrog | break;
|
1128 | e5c9a13e | balrog | } |
1129 | e5c9a13e | balrog | |
1130 | e5c9a13e | balrog | if (!r->picb) {
|
1131 | e5c9a13e | balrog | uint32_t new_sr = r->sr & ~SR_CELV; |
1132 | e5c9a13e | balrog | |
1133 | e5c9a13e | balrog | if (r->bd.ctl_len & BD_IOC) {
|
1134 | e5c9a13e | balrog | new_sr |= SR_BCIS; |
1135 | e5c9a13e | balrog | } |
1136 | e5c9a13e | balrog | |
1137 | e5c9a13e | balrog | if (r->civ == r->lvi) {
|
1138 | e5c9a13e | balrog | dolog ("Underrun civ (%d) == lvi (%d)\n", r->civ, r->lvi);
|
1139 | e5c9a13e | balrog | |
1140 | e5c9a13e | balrog | new_sr |= SR_LVBCI | SR_DCH | SR_CELV; |
1141 | e5c9a13e | balrog | stop = 1;
|
1142 | e5c9a13e | balrog | s->bup_flag = (r->bd.ctl_len & BD_BUP) ? BUP_LAST : 0;
|
1143 | e5c9a13e | balrog | } |
1144 | e5c9a13e | balrog | else {
|
1145 | e5c9a13e | balrog | r->civ = r->piv; |
1146 | e5c9a13e | balrog | r->piv = (r->piv + 1) % 32; |
1147 | e5c9a13e | balrog | fetch_bd (s, r); |
1148 | e5c9a13e | balrog | } |
1149 | e5c9a13e | balrog | |
1150 | e5c9a13e | balrog | update_sr (s, r, new_sr); |
1151 | e5c9a13e | balrog | } |
1152 | e5c9a13e | balrog | } |
1153 | e5c9a13e | balrog | } |
1154 | e5c9a13e | balrog | |
1155 | e5c9a13e | balrog | static void pi_callback (void *opaque, int avail) |
1156 | e5c9a13e | balrog | { |
1157 | e5c9a13e | balrog | transfer_audio (opaque, PI_INDEX, avail); |
1158 | e5c9a13e | balrog | } |
1159 | e5c9a13e | balrog | |
1160 | e5c9a13e | balrog | static void mc_callback (void *opaque, int avail) |
1161 | e5c9a13e | balrog | { |
1162 | e5c9a13e | balrog | transfer_audio (opaque, MC_INDEX, avail); |
1163 | e5c9a13e | balrog | } |
1164 | e5c9a13e | balrog | |
1165 | e5c9a13e | balrog | static void po_callback (void *opaque, int free) |
1166 | e5c9a13e | balrog | { |
1167 | e5c9a13e | balrog | transfer_audio (opaque, PO_INDEX, free); |
1168 | e5c9a13e | balrog | } |
1169 | e5c9a13e | balrog | |
1170 | e5c9a13e | balrog | static void ac97_save (QEMUFile *f, void *opaque) |
1171 | e5c9a13e | balrog | { |
1172 | e5c9a13e | balrog | size_t i; |
1173 | e5c9a13e | balrog | uint8_t active[LAST_INDEX]; |
1174 | e5c9a13e | balrog | AC97LinkState *s = opaque; |
1175 | e5c9a13e | balrog | |
1176 | 10ee2aaa | Juan Quintela | pci_device_save (&s->dev, f); |
1177 | 279a6544 | malc | |
1178 | e5c9a13e | balrog | qemu_put_be32s (f, &s->glob_cnt); |
1179 | e5c9a13e | balrog | qemu_put_be32s (f, &s->glob_sta); |
1180 | e5c9a13e | balrog | qemu_put_be32s (f, &s->cas); |
1181 | e5c9a13e | balrog | |
1182 | b1503cda | malc | for (i = 0; i < ARRAY_SIZE (s->bm_regs); ++i) { |
1183 | e5c9a13e | balrog | AC97BusMasterRegs *r = &s->bm_regs[i]; |
1184 | e5c9a13e | balrog | qemu_put_be32s (f, &r->bdbar); |
1185 | e5c9a13e | balrog | qemu_put_8s (f, &r->civ); |
1186 | e5c9a13e | balrog | qemu_put_8s (f, &r->lvi); |
1187 | e5c9a13e | balrog | qemu_put_be16s (f, &r->sr); |
1188 | e5c9a13e | balrog | qemu_put_be16s (f, &r->picb); |
1189 | e5c9a13e | balrog | qemu_put_8s (f, &r->piv); |
1190 | e5c9a13e | balrog | qemu_put_8s (f, &r->cr); |
1191 | e5c9a13e | balrog | qemu_put_be32s (f, &r->bd_valid); |
1192 | e5c9a13e | balrog | qemu_put_be32s (f, &r->bd.addr); |
1193 | e5c9a13e | balrog | qemu_put_be32s (f, &r->bd.ctl_len); |
1194 | e5c9a13e | balrog | } |
1195 | e5c9a13e | balrog | qemu_put_buffer (f, s->mixer_data, sizeof (s->mixer_data));
|
1196 | e5c9a13e | balrog | |
1197 | e5c9a13e | balrog | active[PI_INDEX] = AUD_is_active_in (s->voice_pi) ? 1 : 0; |
1198 | e5c9a13e | balrog | active[PO_INDEX] = AUD_is_active_out (s->voice_po) ? 1 : 0; |
1199 | e5c9a13e | balrog | active[MC_INDEX] = AUD_is_active_in (s->voice_mc) ? 1 : 0; |
1200 | e5c9a13e | balrog | qemu_put_buffer (f, active, sizeof (active));
|
1201 | e5c9a13e | balrog | } |
1202 | e5c9a13e | balrog | |
1203 | e5c9a13e | balrog | static int ac97_load (QEMUFile *f, void *opaque, int version_id) |
1204 | e5c9a13e | balrog | { |
1205 | 279a6544 | malc | int ret;
|
1206 | e5c9a13e | balrog | size_t i; |
1207 | e5c9a13e | balrog | uint8_t active[LAST_INDEX]; |
1208 | e5c9a13e | balrog | AC97LinkState *s = opaque; |
1209 | e5c9a13e | balrog | |
1210 | 279a6544 | malc | if (version_id != 2) |
1211 | e5c9a13e | balrog | return -EINVAL;
|
1212 | e5c9a13e | balrog | |
1213 | 10ee2aaa | Juan Quintela | ret = pci_device_load (&s->dev, f); |
1214 | 279a6544 | malc | if (ret)
|
1215 | 279a6544 | malc | return ret;
|
1216 | 279a6544 | malc | |
1217 | e5c9a13e | balrog | qemu_get_be32s (f, &s->glob_cnt); |
1218 | e5c9a13e | balrog | qemu_get_be32s (f, &s->glob_sta); |
1219 | e5c9a13e | balrog | qemu_get_be32s (f, &s->cas); |
1220 | e5c9a13e | balrog | |
1221 | b1503cda | malc | for (i = 0; i < ARRAY_SIZE (s->bm_regs); ++i) { |
1222 | e5c9a13e | balrog | AC97BusMasterRegs *r = &s->bm_regs[i]; |
1223 | e5c9a13e | balrog | qemu_get_be32s (f, &r->bdbar); |
1224 | e5c9a13e | balrog | qemu_get_8s (f, &r->civ); |
1225 | e5c9a13e | balrog | qemu_get_8s (f, &r->lvi); |
1226 | e5c9a13e | balrog | qemu_get_be16s (f, &r->sr); |
1227 | e5c9a13e | balrog | qemu_get_be16s (f, &r->picb); |
1228 | e5c9a13e | balrog | qemu_get_8s (f, &r->piv); |
1229 | e5c9a13e | balrog | qemu_get_8s (f, &r->cr); |
1230 | e5c9a13e | balrog | qemu_get_be32s (f, &r->bd_valid); |
1231 | e5c9a13e | balrog | qemu_get_be32s (f, &r->bd.addr); |
1232 | e5c9a13e | balrog | qemu_get_be32s (f, &r->bd.ctl_len); |
1233 | e5c9a13e | balrog | } |
1234 | e5c9a13e | balrog | qemu_get_buffer (f, s->mixer_data, sizeof (s->mixer_data));
|
1235 | e5c9a13e | balrog | qemu_get_buffer (f, active, sizeof (active));
|
1236 | e5c9a13e | balrog | |
1237 | e5c9a13e | balrog | #ifdef USE_MIXER
|
1238 | e5c9a13e | balrog | record_select (s, mixer_load (s, AC97_Record_Select)); |
1239 | e5c9a13e | balrog | #define V_(a, b) set_volume (s, a, b, mixer_load (s, a))
|
1240 | e5c9a13e | balrog | V_ (AC97_Master_Volume_Mute, AUD_MIXER_VOLUME); |
1241 | e5c9a13e | balrog | V_ (AC97_PCM_Out_Volume_Mute, AUD_MIXER_PCM); |
1242 | e5c9a13e | balrog | V_ (AC97_Line_In_Volume_Mute, AUD_MIXER_LINE_IN); |
1243 | e5c9a13e | balrog | #undef V_
|
1244 | e5c9a13e | balrog | #endif
|
1245 | e5c9a13e | balrog | reset_voices (s, active); |
1246 | e5c9a13e | balrog | |
1247 | e5c9a13e | balrog | s->bup_flag = 0;
|
1248 | e5c9a13e | balrog | s->last_samp = 0;
|
1249 | e5c9a13e | balrog | return 0; |
1250 | e5c9a13e | balrog | } |
1251 | e5c9a13e | balrog | |
1252 | e5c9a13e | balrog | static void ac97_map (PCIDevice *pci_dev, int region_num, |
1253 | 6e355d90 | Isaku Yamahata | pcibus_t addr, pcibus_t size, int type)
|
1254 | e5c9a13e | balrog | { |
1255 | 10ee2aaa | Juan Quintela | AC97LinkState *s = DO_UPCAST (AC97LinkState, dev, pci_dev); |
1256 | 10ee2aaa | Juan Quintela | PCIDevice *d = &s->dev; |
1257 | e5c9a13e | balrog | |
1258 | e5c9a13e | balrog | if (!region_num) {
|
1259 | e5c9a13e | balrog | s->base[0] = addr;
|
1260 | e5c9a13e | balrog | register_ioport_read (addr, 256 * 1, 1, nam_readb, d); |
1261 | e5c9a13e | balrog | register_ioport_read (addr, 256 * 2, 2, nam_readw, d); |
1262 | e5c9a13e | balrog | register_ioport_read (addr, 256 * 4, 4, nam_readl, d); |
1263 | e5c9a13e | balrog | register_ioport_write (addr, 256 * 1, 1, nam_writeb, d); |
1264 | e5c9a13e | balrog | register_ioport_write (addr, 256 * 2, 2, nam_writew, d); |
1265 | e5c9a13e | balrog | register_ioport_write (addr, 256 * 4, 4, nam_writel, d); |
1266 | e5c9a13e | balrog | } |
1267 | e5c9a13e | balrog | else {
|
1268 | e5c9a13e | balrog | s->base[1] = addr;
|
1269 | e5c9a13e | balrog | register_ioport_read (addr, 64 * 1, 1, nabm_readb, d); |
1270 | e5c9a13e | balrog | register_ioport_read (addr, 64 * 2, 2, nabm_readw, d); |
1271 | e5c9a13e | balrog | register_ioport_read (addr, 64 * 4, 4, nabm_readl, d); |
1272 | e5c9a13e | balrog | register_ioport_write (addr, 64 * 1, 1, nabm_writeb, d); |
1273 | e5c9a13e | balrog | register_ioport_write (addr, 64 * 2, 2, nabm_writew, d); |
1274 | e5c9a13e | balrog | register_ioport_write (addr, 64 * 4, 4, nabm_writel, d); |
1275 | e5c9a13e | balrog | } |
1276 | e5c9a13e | balrog | } |
1277 | e5c9a13e | balrog | |
1278 | e5c9a13e | balrog | static void ac97_on_reset (void *opaque) |
1279 | e5c9a13e | balrog | { |
1280 | e5c9a13e | balrog | AC97LinkState *s = opaque; |
1281 | e5c9a13e | balrog | |
1282 | e5c9a13e | balrog | reset_bm_regs (s, &s->bm_regs[0]);
|
1283 | e5c9a13e | balrog | reset_bm_regs (s, &s->bm_regs[1]);
|
1284 | e5c9a13e | balrog | reset_bm_regs (s, &s->bm_regs[2]);
|
1285 | e5c9a13e | balrog | |
1286 | e5c9a13e | balrog | /*
|
1287 | e5c9a13e | balrog | * Reset the mixer too. The Windows XP driver seems to rely on
|
1288 | e5c9a13e | balrog | * this. At least it wants to read the vendor id before it resets
|
1289 | e5c9a13e | balrog | * the codec manually.
|
1290 | e5c9a13e | balrog | */
|
1291 | e5c9a13e | balrog | mixer_reset (s); |
1292 | e5c9a13e | balrog | } |
1293 | e5c9a13e | balrog | |
1294 | 81a322d4 | Gerd Hoffmann | static int ac97_initfn (PCIDevice *dev) |
1295 | e5c9a13e | balrog | { |
1296 | 10ee2aaa | Juan Quintela | AC97LinkState *s = DO_UPCAST (AC97LinkState, dev, dev); |
1297 | 10ee2aaa | Juan Quintela | uint8_t *c = s->dev.config; |
1298 | e5c9a13e | balrog | |
1299 | d999f7e0 | malc | pci_config_set_vendor_id (c, PCI_VENDOR_ID_INTEL); /* ro */
|
1300 | d999f7e0 | malc | pci_config_set_device_id (c, PCI_DEVICE_ID_INTEL_82801AA_5); /* ro */
|
1301 | e5c9a13e | balrog | |
1302 | e5c9a13e | balrog | c[0x04] = 0x00; /* pcicmd pci command rw, ro */ |
1303 | e5c9a13e | balrog | c[0x05] = 0x00; |
1304 | e5c9a13e | balrog | |
1305 | e5c9a13e | balrog | c[0x06] = 0x80; /* pcists pci status rwc, ro */ |
1306 | e5c9a13e | balrog | c[0x07] = 0x02; |
1307 | e5c9a13e | balrog | |
1308 | e5c9a13e | balrog | c[0x08] = 0x01; /* rid revision ro */ |
1309 | e5c9a13e | balrog | c[0x09] = 0x00; /* pi programming interface ro */ |
1310 | d999f7e0 | malc | pci_config_set_class (c, PCI_CLASS_MULTIMEDIA_AUDIO); /* ro */
|
1311 | 6407f373 | Isaku Yamahata | c[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; /* headtyp header type ro */
|
1312 | e5c9a13e | balrog | |
1313 | e5c9a13e | balrog | c[0x10] = 0x01; /* nabmar native audio mixer base |
1314 | e5c9a13e | balrog | address rw */
|
1315 | e5c9a13e | balrog | c[0x11] = 0x00; |
1316 | e5c9a13e | balrog | c[0x12] = 0x00; |
1317 | e5c9a13e | balrog | c[0x13] = 0x00; |
1318 | e5c9a13e | balrog | |
1319 | e5c9a13e | balrog | c[0x14] = 0x01; /* nabmbar native audio bus mastering |
1320 | e5c9a13e | balrog | base address rw */
|
1321 | e5c9a13e | balrog | c[0x15] = 0x00; |
1322 | e5c9a13e | balrog | c[0x16] = 0x00; |
1323 | e5c9a13e | balrog | c[0x17] = 0x00; |
1324 | e5c9a13e | balrog | |
1325 | e5c9a13e | balrog | c[0x2c] = 0x86; /* svid subsystem vendor id rwo */ |
1326 | e5c9a13e | balrog | c[0x2d] = 0x80; |
1327 | e5c9a13e | balrog | |
1328 | e5c9a13e | balrog | c[0x2e] = 0x00; /* sid subsystem id rwo */ |
1329 | e5c9a13e | balrog | c[0x2f] = 0x00; |
1330 | e5c9a13e | balrog | |
1331 | e5c9a13e | balrog | c[0x3c] = 0x00; /* intr_ln interrupt line rw */ |
1332 | e5c9a13e | balrog | c[0x3d] = 0x01; /* intr_pn interrupt pin ro */ |
1333 | e5c9a13e | balrog | |
1334 | 0392a017 | Isaku Yamahata | pci_register_bar (&s->dev, 0, 256 * 4, PCI_BASE_ADDRESS_SPACE_IO, |
1335 | 0392a017 | Isaku Yamahata | ac97_map); |
1336 | 0392a017 | Isaku Yamahata | pci_register_bar (&s->dev, 1, 64 * 4, PCI_BASE_ADDRESS_SPACE_IO, ac97_map); |
1337 | 279a6544 | malc | register_savevm ("ac97", 0, 2, ac97_save, ac97_load, s); |
1338 | a08d4367 | Jan Kiszka | qemu_register_reset (ac97_on_reset, s); |
1339 | 1a7dafce | malc | AUD_register_card ("ac97", &s->card);
|
1340 | e5c9a13e | balrog | ac97_on_reset (s); |
1341 | 81a322d4 | Gerd Hoffmann | return 0; |
1342 | d88a76d1 | Gerd Hoffmann | } |
1343 | d88a76d1 | Gerd Hoffmann | |
1344 | d88a76d1 | Gerd Hoffmann | int ac97_init (PCIBus *bus)
|
1345 | d88a76d1 | Gerd Hoffmann | { |
1346 | 0c3271c5 | Anthony Liguori | pci_create_simple (bus, -1, "AC97"); |
1347 | e5c9a13e | balrog | return 0; |
1348 | e5c9a13e | balrog | } |
1349 | d88a76d1 | Gerd Hoffmann | |
1350 | d88a76d1 | Gerd Hoffmann | static PCIDeviceInfo ac97_info = {
|
1351 | d88a76d1 | Gerd Hoffmann | .qdev.name = "AC97",
|
1352 | f3519986 | Gerd Hoffmann | .qdev.desc = "Intel 82801AA AC97 Audio",
|
1353 | 10ee2aaa | Juan Quintela | .qdev.size = sizeof (AC97LinkState),
|
1354 | d88a76d1 | Gerd Hoffmann | .init = ac97_initfn, |
1355 | d88a76d1 | Gerd Hoffmann | }; |
1356 | d88a76d1 | Gerd Hoffmann | |
1357 | 0c3271c5 | Anthony Liguori | static void ac97_register (void) |
1358 | d88a76d1 | Gerd Hoffmann | { |
1359 | 0c3271c5 | Anthony Liguori | pci_qdev_register (&ac97_info); |
1360 | d88a76d1 | Gerd Hoffmann | } |
1361 | 0c3271c5 | Anthony Liguori | device_init (ac97_register); |