root / hw / wm8750.c @ eb69b50a
History | View | Annotate | Download (17.8 kB)
1 |
/*
|
---|---|
2 |
* WM8750 audio CODEC.
|
3 |
*
|
4 |
* Copyright (c) 2006 Openedhand Ltd.
|
5 |
* Written by Andrzej Zaborowski <balrog@zabor.org>
|
6 |
*
|
7 |
* This file is licensed under GNU GPL.
|
8 |
*/
|
9 |
|
10 |
#include "hw.h" |
11 |
#include "i2c.h" |
12 |
#include "audio/audio.h" |
13 |
|
14 |
#define IN_PORT_N 3 |
15 |
#define OUT_PORT_N 3 |
16 |
|
17 |
#define CODEC "wm8750" |
18 |
|
19 |
struct wm_rate_s;
|
20 |
struct wm8750_s {
|
21 |
i2c_slave i2c; |
22 |
uint8_t i2c_data[2];
|
23 |
int i2c_len;
|
24 |
QEMUSoundCard card; |
25 |
SWVoiceIn *adc_voice[IN_PORT_N]; |
26 |
SWVoiceOut *dac_voice[OUT_PORT_N]; |
27 |
int enable;
|
28 |
void (*data_req)(void *, int, int); |
29 |
void *opaque;
|
30 |
uint8_t data_in[4096];
|
31 |
uint8_t data_out[4096];
|
32 |
int idx_in, req_in;
|
33 |
int idx_out, req_out;
|
34 |
|
35 |
SWVoiceOut **out[2];
|
36 |
uint8_t outvol[7], outmute[2]; |
37 |
SWVoiceIn **in[2];
|
38 |
uint8_t invol[4], inmute[2]; |
39 |
|
40 |
uint8_t diff[2], pol, ds, monomix[2], alc, mute; |
41 |
uint8_t path[4], mpath[2], power, format; |
42 |
uint32_t inmask, outmask; |
43 |
const struct wm_rate_s *rate; |
44 |
}; |
45 |
|
46 |
static inline void wm8750_in_load(struct wm8750_s *s) |
47 |
{ |
48 |
int acquired;
|
49 |
if (s->idx_in + s->req_in <= sizeof(s->data_in)) |
50 |
return;
|
51 |
s->idx_in = audio_MAX(0, (int) sizeof(s->data_in) - s->req_in); |
52 |
acquired = AUD_read(*s->in[0], s->data_in + s->idx_in,
|
53 |
sizeof(s->data_in) - s->idx_in);
|
54 |
} |
55 |
|
56 |
static inline void wm8750_out_flush(struct wm8750_s *s) |
57 |
{ |
58 |
int sent;
|
59 |
if (!s->idx_out)
|
60 |
return;
|
61 |
sent = AUD_write(*s->out[0], s->data_out, s->idx_out);
|
62 |
s->idx_out = 0;
|
63 |
} |
64 |
|
65 |
static void wm8750_audio_in_cb(void *opaque, int avail_b) |
66 |
{ |
67 |
struct wm8750_s *s = (struct wm8750_s *) opaque; |
68 |
s->req_in = avail_b; |
69 |
s->data_req(s->opaque, s->req_out >> 2, avail_b >> 2); |
70 |
|
71 |
#if 0
|
72 |
wm8750_in_load(s);
|
73 |
#endif
|
74 |
} |
75 |
|
76 |
static void wm8750_audio_out_cb(void *opaque, int free_b) |
77 |
{ |
78 |
struct wm8750_s *s = (struct wm8750_s *) opaque; |
79 |
|
80 |
s->req_out = free_b; |
81 |
s->data_req(s->opaque, free_b >> 2, s->req_in >> 2); |
82 |
wm8750_out_flush(s); |
83 |
} |
84 |
|
85 |
struct wm_rate_s {
|
86 |
int adc;
|
87 |
int adc_hz;
|
88 |
int dac;
|
89 |
int dac_hz;
|
90 |
}; |
91 |
|
92 |
static const struct wm_rate_s wm_rate_table[] = { |
93 |
{ 256, 48000, 256, 48000 }, /* SR: 00000 */ |
94 |
{ 384, 48000, 384, 48000 }, /* SR: 00001 */ |
95 |
{ 256, 48000, 1536, 8000 }, /* SR: 00010 */ |
96 |
{ 384, 48000, 2304, 8000 }, /* SR: 00011 */ |
97 |
{ 1536, 8000, 256, 48000 }, /* SR: 00100 */ |
98 |
{ 2304, 8000, 384, 48000 }, /* SR: 00101 */ |
99 |
{ 1536, 8000, 1536, 8000 }, /* SR: 00110 */ |
100 |
{ 2304, 8000, 2304, 8000 }, /* SR: 00111 */ |
101 |
{ 1024, 12000, 1024, 12000 }, /* SR: 01000 */ |
102 |
{ 1526, 12000, 1536, 12000 }, /* SR: 01001 */ |
103 |
{ 768, 16000, 768, 16000 }, /* SR: 01010 */ |
104 |
{ 1152, 16000, 1152, 16000 }, /* SR: 01011 */ |
105 |
{ 384, 32000, 384, 32000 }, /* SR: 01100 */ |
106 |
{ 576, 32000, 576, 32000 }, /* SR: 01101 */ |
107 |
{ 128, 96000, 128, 96000 }, /* SR: 01110 */ |
108 |
{ 192, 96000, 192, 96000 }, /* SR: 01111 */ |
109 |
{ 256, 44100, 256, 44100 }, /* SR: 10000 */ |
110 |
{ 384, 44100, 384, 44100 }, /* SR: 10001 */ |
111 |
{ 256, 44100, 1408, 8018 }, /* SR: 10010 */ |
112 |
{ 384, 44100, 2112, 8018 }, /* SR: 10011 */ |
113 |
{ 1408, 8018, 256, 44100 }, /* SR: 10100 */ |
114 |
{ 2112, 8018, 384, 44100 }, /* SR: 10101 */ |
115 |
{ 1408, 8018, 1408, 8018 }, /* SR: 10110 */ |
116 |
{ 2112, 8018, 2112, 8018 }, /* SR: 10111 */ |
117 |
{ 1024, 11025, 1024, 11025 }, /* SR: 11000 */ |
118 |
{ 1536, 11025, 1536, 11025 }, /* SR: 11001 */ |
119 |
{ 512, 22050, 512, 22050 }, /* SR: 11010 */ |
120 |
{ 768, 22050, 768, 22050 }, /* SR: 11011 */ |
121 |
{ 512, 24000, 512, 24000 }, /* SR: 11100 */ |
122 |
{ 768, 24000, 768, 24000 }, /* SR: 11101 */ |
123 |
{ 128, 88200, 128, 88200 }, /* SR: 11110 */ |
124 |
{ 192, 88200, 128, 88200 }, /* SR: 11111 */ |
125 |
}; |
126 |
|
127 |
static void wm8750_set_format(struct wm8750_s *s) |
128 |
{ |
129 |
int i;
|
130 |
audsettings_t in_fmt; |
131 |
audsettings_t out_fmt; |
132 |
audsettings_t monoout_fmt; |
133 |
|
134 |
wm8750_out_flush(s); |
135 |
|
136 |
if (s->in[0] && *s->in[0]) |
137 |
AUD_set_active_in(*s->in[0], 0); |
138 |
if (s->out[0] && *s->out[0]) |
139 |
AUD_set_active_out(*s->out[0], 0); |
140 |
|
141 |
for (i = 0; i < IN_PORT_N; i ++) |
142 |
if (s->adc_voice[i]) {
|
143 |
AUD_close_in(&s->card, s->adc_voice[i]); |
144 |
s->adc_voice[i] = 0;
|
145 |
} |
146 |
for (i = 0; i < OUT_PORT_N; i ++) |
147 |
if (s->dac_voice[i]) {
|
148 |
AUD_close_out(&s->card, s->dac_voice[i]); |
149 |
s->dac_voice[i] = 0;
|
150 |
} |
151 |
|
152 |
if (!s->enable)
|
153 |
return;
|
154 |
|
155 |
/* Setup input */
|
156 |
in_fmt.endianness = 0;
|
157 |
in_fmt.nchannels = 2;
|
158 |
in_fmt.freq = s->rate->adc_hz; |
159 |
in_fmt.fmt = AUD_FMT_S16; |
160 |
|
161 |
s->adc_voice[0] = AUD_open_in(&s->card, s->adc_voice[0], |
162 |
CODEC ".input1", s, wm8750_audio_in_cb, &in_fmt);
|
163 |
s->adc_voice[1] = AUD_open_in(&s->card, s->adc_voice[1], |
164 |
CODEC ".input2", s, wm8750_audio_in_cb, &in_fmt);
|
165 |
s->adc_voice[2] = AUD_open_in(&s->card, s->adc_voice[2], |
166 |
CODEC ".input3", s, wm8750_audio_in_cb, &in_fmt);
|
167 |
|
168 |
/* Setup output */
|
169 |
out_fmt.endianness = 0;
|
170 |
out_fmt.nchannels = 2;
|
171 |
out_fmt.freq = s->rate->dac_hz; |
172 |
out_fmt.fmt = AUD_FMT_S16; |
173 |
monoout_fmt.endianness = 0;
|
174 |
monoout_fmt.nchannels = 1;
|
175 |
monoout_fmt.freq = s->rate->dac_hz; |
176 |
monoout_fmt.fmt = AUD_FMT_S16; |
177 |
|
178 |
s->dac_voice[0] = AUD_open_out(&s->card, s->dac_voice[0], |
179 |
CODEC ".speaker", s, wm8750_audio_out_cb, &out_fmt);
|
180 |
s->dac_voice[1] = AUD_open_out(&s->card, s->dac_voice[1], |
181 |
CODEC ".headphone", s, wm8750_audio_out_cb, &out_fmt);
|
182 |
/* MONOMIX is also in stereo for simplicity */
|
183 |
s->dac_voice[2] = AUD_open_out(&s->card, s->dac_voice[2], |
184 |
CODEC ".monomix", s, wm8750_audio_out_cb, &out_fmt);
|
185 |
/* no sense emulating OUT3 which is a mix of other outputs */
|
186 |
|
187 |
/* We should connect the left and right channels to their
|
188 |
* respective inputs/outputs but we have completely no need
|
189 |
* for mixing or combining paths to different ports, so we
|
190 |
* connect both channels to where the left channel is routed. */
|
191 |
if (s->in[0] && *s->in[0]) |
192 |
AUD_set_active_in(*s->in[0], 1); |
193 |
if (s->out[0] && *s->out[0]) |
194 |
AUD_set_active_out(*s->out[0], 1); |
195 |
} |
196 |
|
197 |
static void inline wm8750_mask_update(struct wm8750_s *s) |
198 |
{ |
199 |
#define R_ONLY 0x0000ffff |
200 |
#define L_ONLY 0xffff0000 |
201 |
#define BOTH (R_ONLY | L_ONLY)
|
202 |
#define NONE (R_ONLY & L_ONLY)
|
203 |
s->inmask = |
204 |
(s->inmute[0] ? R_ONLY : BOTH) &
|
205 |
(s->inmute[1] ? L_ONLY : BOTH) &
|
206 |
(s->mute ? NONE : BOTH); |
207 |
s->outmask = |
208 |
(s->outmute[0] ? R_ONLY : BOTH) &
|
209 |
(s->outmute[1] ? L_ONLY : BOTH) &
|
210 |
(s->mute ? NONE : BOTH); |
211 |
} |
212 |
|
213 |
void wm8750_reset(i2c_slave *i2c)
|
214 |
{ |
215 |
struct wm8750_s *s = (struct wm8750_s *) i2c; |
216 |
s->rate = &wm_rate_table[0];
|
217 |
s->enable = 0;
|
218 |
wm8750_set_format(s); |
219 |
s->diff[0] = 0; |
220 |
s->diff[1] = 0; |
221 |
s->ds = 0;
|
222 |
s->alc = 0;
|
223 |
s->in[0] = &s->adc_voice[0]; |
224 |
s->invol[0] = 0x17; |
225 |
s->invol[1] = 0x17; |
226 |
s->invol[2] = 0xc3; |
227 |
s->invol[3] = 0xc3; |
228 |
s->out[0] = &s->dac_voice[0]; |
229 |
s->outvol[0] = 0xff; |
230 |
s->outvol[1] = 0xff; |
231 |
s->outvol[2] = 0x79; |
232 |
s->outvol[3] = 0x79; |
233 |
s->outvol[4] = 0x79; |
234 |
s->outvol[5] = 0x79; |
235 |
s->inmute[0] = 0; |
236 |
s->inmute[1] = 0; |
237 |
s->outmute[0] = 0; |
238 |
s->outmute[1] = 0; |
239 |
s->mute = 1;
|
240 |
s->path[0] = 0; |
241 |
s->path[1] = 0; |
242 |
s->path[2] = 0; |
243 |
s->path[3] = 0; |
244 |
s->mpath[0] = 0; |
245 |
s->mpath[1] = 0; |
246 |
s->format = 0x0a;
|
247 |
s->idx_in = sizeof(s->data_in);
|
248 |
s->req_in = 0;
|
249 |
s->idx_out = 0;
|
250 |
s->req_out = 0;
|
251 |
wm8750_mask_update(s); |
252 |
s->i2c_len = 0;
|
253 |
} |
254 |
|
255 |
static void wm8750_event(i2c_slave *i2c, enum i2c_event event) |
256 |
{ |
257 |
struct wm8750_s *s = (struct wm8750_s *) i2c; |
258 |
|
259 |
switch (event) {
|
260 |
case I2C_START_SEND:
|
261 |
s->i2c_len = 0;
|
262 |
break;
|
263 |
case I2C_FINISH:
|
264 |
#ifdef VERBOSE
|
265 |
if (s->i2c_len < 2) |
266 |
printf("%s: message too short (%i bytes)\n",
|
267 |
__FUNCTION__, s->i2c_len); |
268 |
#endif
|
269 |
break;
|
270 |
default:
|
271 |
break;
|
272 |
} |
273 |
} |
274 |
|
275 |
#define WM8750_LINVOL 0x00 |
276 |
#define WM8750_RINVOL 0x01 |
277 |
#define WM8750_LOUT1V 0x02 |
278 |
#define WM8750_ROUT1V 0x03 |
279 |
#define WM8750_ADCDAC 0x05 |
280 |
#define WM8750_IFACE 0x07 |
281 |
#define WM8750_SRATE 0x08 |
282 |
#define WM8750_LDAC 0x0a |
283 |
#define WM8750_RDAC 0x0b |
284 |
#define WM8750_BASS 0x0c |
285 |
#define WM8750_TREBLE 0x0d |
286 |
#define WM8750_RESET 0x0f |
287 |
#define WM8750_3D 0x10 |
288 |
#define WM8750_ALC1 0x11 |
289 |
#define WM8750_ALC2 0x12 |
290 |
#define WM8750_ALC3 0x13 |
291 |
#define WM8750_NGATE 0x14 |
292 |
#define WM8750_LADC 0x15 |
293 |
#define WM8750_RADC 0x16 |
294 |
#define WM8750_ADCTL1 0x17 |
295 |
#define WM8750_ADCTL2 0x18 |
296 |
#define WM8750_PWR1 0x19 |
297 |
#define WM8750_PWR2 0x1a |
298 |
#define WM8750_ADCTL3 0x1b |
299 |
#define WM8750_ADCIN 0x1f |
300 |
#define WM8750_LADCIN 0x20 |
301 |
#define WM8750_RADCIN 0x21 |
302 |
#define WM8750_LOUTM1 0x22 |
303 |
#define WM8750_LOUTM2 0x23 |
304 |
#define WM8750_ROUTM1 0x24 |
305 |
#define WM8750_ROUTM2 0x25 |
306 |
#define WM8750_MOUTM1 0x26 |
307 |
#define WM8750_MOUTM2 0x27 |
308 |
#define WM8750_LOUT2V 0x28 |
309 |
#define WM8750_ROUT2V 0x29 |
310 |
#define WM8750_MOUTV 0x2a |
311 |
|
312 |
static int wm8750_tx(i2c_slave *i2c, uint8_t data) |
313 |
{ |
314 |
struct wm8750_s *s = (struct wm8750_s *) i2c; |
315 |
uint8_t cmd; |
316 |
uint16_t value; |
317 |
|
318 |
if (s->i2c_len >= 2) { |
319 |
printf("%s: long message (%i bytes)\n", __FUNCTION__, s->i2c_len);
|
320 |
#ifdef VERBOSE
|
321 |
return 1; |
322 |
#endif
|
323 |
} |
324 |
s->i2c_data[s->i2c_len ++] = data; |
325 |
if (s->i2c_len != 2) |
326 |
return 0; |
327 |
|
328 |
cmd = s->i2c_data[0] >> 1; |
329 |
value = ((s->i2c_data[0] << 8) | s->i2c_data[1]) & 0x1ff; |
330 |
|
331 |
switch (cmd) {
|
332 |
case WM8750_LADCIN: /* ADC Signal Path Control (Left) */ |
333 |
s->diff[0] = (((value >> 6) & 3) == 3); /* LINSEL */ |
334 |
if (s->diff[0]) |
335 |
s->in[0] = &s->adc_voice[0 + s->ds * 1]; |
336 |
else
|
337 |
s->in[0] = &s->adc_voice[((value >> 6) & 3) * 1 + 0]; |
338 |
break;
|
339 |
|
340 |
case WM8750_RADCIN: /* ADC Signal Path Control (Right) */ |
341 |
s->diff[1] = (((value >> 6) & 3) == 3); /* RINSEL */ |
342 |
if (s->diff[1]) |
343 |
s->in[1] = &s->adc_voice[0 + s->ds * 1]; |
344 |
else
|
345 |
s->in[1] = &s->adc_voice[((value >> 6) & 3) * 1 + 0]; |
346 |
break;
|
347 |
|
348 |
case WM8750_ADCIN: /* ADC Input Mode */ |
349 |
s->ds = (value >> 8) & 1; /* DS */ |
350 |
if (s->diff[0]) |
351 |
s->in[0] = &s->adc_voice[0 + s->ds * 1]; |
352 |
if (s->diff[1]) |
353 |
s->in[1] = &s->adc_voice[0 + s->ds * 1]; |
354 |
s->monomix[0] = (value >> 6) & 3; /* MONOMIX */ |
355 |
break;
|
356 |
|
357 |
case WM8750_ADCTL1: /* Additional Control (1) */ |
358 |
s->monomix[1] = (value >> 1) & 1; /* DMONOMIX */ |
359 |
break;
|
360 |
|
361 |
case WM8750_PWR1: /* Power Management (1) */ |
362 |
s->enable = ((value >> 6) & 7) == 3; /* VMIDSEL, VREF */ |
363 |
wm8750_set_format(s); |
364 |
break;
|
365 |
|
366 |
case WM8750_LINVOL: /* Left Channel PGA */ |
367 |
s->invol[0] = value & 0x3f; /* LINVOL */ |
368 |
s->inmute[0] = (value >> 7) & 1; /* LINMUTE */ |
369 |
wm8750_mask_update(s); |
370 |
break;
|
371 |
|
372 |
case WM8750_RINVOL: /* Right Channel PGA */ |
373 |
s->invol[1] = value & 0x3f; /* RINVOL */ |
374 |
s->inmute[1] = (value >> 7) & 1; /* RINMUTE */ |
375 |
wm8750_mask_update(s); |
376 |
break;
|
377 |
|
378 |
case WM8750_ADCDAC: /* ADC and DAC Control */ |
379 |
s->pol = (value >> 5) & 3; /* ADCPOL */ |
380 |
s->mute = (value >> 3) & 1; /* DACMU */ |
381 |
wm8750_mask_update(s); |
382 |
break;
|
383 |
|
384 |
case WM8750_ADCTL3: /* Additional Control (3) */ |
385 |
break;
|
386 |
|
387 |
case WM8750_LADC: /* Left ADC Digital Volume */ |
388 |
s->invol[2] = value & 0xff; /* LADCVOL */ |
389 |
break;
|
390 |
|
391 |
case WM8750_RADC: /* Right ADC Digital Volume */ |
392 |
s->invol[3] = value & 0xff; /* RADCVOL */ |
393 |
break;
|
394 |
|
395 |
case WM8750_ALC1: /* ALC Control (1) */ |
396 |
s->alc = (value >> 7) & 3; /* ALCSEL */ |
397 |
break;
|
398 |
|
399 |
case WM8750_NGATE: /* Noise Gate Control */ |
400 |
case WM8750_3D: /* 3D enhance */ |
401 |
break;
|
402 |
|
403 |
case WM8750_LDAC: /* Left Channel Digital Volume */ |
404 |
s->outvol[0] = value & 0xff; /* LDACVOL */ |
405 |
break;
|
406 |
|
407 |
case WM8750_RDAC: /* Right Channel Digital Volume */ |
408 |
s->outvol[1] = value & 0xff; /* RDACVOL */ |
409 |
break;
|
410 |
|
411 |
case WM8750_BASS: /* Bass Control */ |
412 |
break;
|
413 |
|
414 |
case WM8750_LOUTM1: /* Left Mixer Control (1) */ |
415 |
s->path[0] = (value >> 8) & 1; /* LD2LO */ |
416 |
break;
|
417 |
|
418 |
case WM8750_LOUTM2: /* Left Mixer Control (2) */ |
419 |
s->path[1] = (value >> 8) & 1; /* RD2LO */ |
420 |
break;
|
421 |
|
422 |
case WM8750_ROUTM1: /* Right Mixer Control (1) */ |
423 |
s->path[2] = (value >> 8) & 1; /* LD2RO */ |
424 |
break;
|
425 |
|
426 |
case WM8750_ROUTM2: /* Right Mixer Control (2) */ |
427 |
s->path[3] = (value >> 8) & 1; /* RD2RO */ |
428 |
break;
|
429 |
|
430 |
case WM8750_MOUTM1: /* Mono Mixer Control (1) */ |
431 |
s->mpath[0] = (value >> 8) & 1; /* LD2MO */ |
432 |
break;
|
433 |
|
434 |
case WM8750_MOUTM2: /* Mono Mixer Control (2) */ |
435 |
s->mpath[1] = (value >> 8) & 1; /* RD2MO */ |
436 |
break;
|
437 |
|
438 |
case WM8750_LOUT1V: /* LOUT1 Volume */ |
439 |
s->outvol[2] = value & 0x7f; /* LOUT2VOL */ |
440 |
break;
|
441 |
|
442 |
case WM8750_LOUT2V: /* LOUT2 Volume */ |
443 |
s->outvol[4] = value & 0x7f; /* LOUT2VOL */ |
444 |
break;
|
445 |
|
446 |
case WM8750_ROUT1V: /* ROUT1 Volume */ |
447 |
s->outvol[3] = value & 0x7f; /* ROUT2VOL */ |
448 |
break;
|
449 |
|
450 |
case WM8750_ROUT2V: /* ROUT2 Volume */ |
451 |
s->outvol[5] = value & 0x7f; /* ROUT2VOL */ |
452 |
break;
|
453 |
|
454 |
case WM8750_MOUTV: /* MONOOUT Volume */ |
455 |
s->outvol[6] = value & 0x7f; /* MONOOUTVOL */ |
456 |
break;
|
457 |
|
458 |
case WM8750_ADCTL2: /* Additional Control (2) */ |
459 |
break;
|
460 |
|
461 |
case WM8750_PWR2: /* Power Management (2) */ |
462 |
s->power = value & 0x7e;
|
463 |
break;
|
464 |
|
465 |
case WM8750_IFACE: /* Digital Audio Interface Format */ |
466 |
#ifdef VERBOSE
|
467 |
if (value & 0x40) /* MS */ |
468 |
printf("%s: attempt to enable Master Mode\n", __FUNCTION__);
|
469 |
#endif
|
470 |
s->format = value; |
471 |
wm8750_set_format(s); |
472 |
break;
|
473 |
|
474 |
case WM8750_SRATE: /* Clocking and Sample Rate Control */ |
475 |
s->rate = &wm_rate_table[(value >> 1) & 0x1f]; |
476 |
wm8750_set_format(s); |
477 |
break;
|
478 |
|
479 |
case WM8750_RESET: /* Reset */ |
480 |
wm8750_reset(&s->i2c); |
481 |
break;
|
482 |
|
483 |
#ifdef VERBOSE
|
484 |
default:
|
485 |
printf("%s: unknown register %02x\n", __FUNCTION__, cmd);
|
486 |
#endif
|
487 |
} |
488 |
|
489 |
return 0; |
490 |
} |
491 |
|
492 |
static int wm8750_rx(i2c_slave *i2c) |
493 |
{ |
494 |
return 0x00; |
495 |
} |
496 |
|
497 |
static void wm8750_save(QEMUFile *f, void *opaque) |
498 |
{ |
499 |
struct wm8750_s *s = (struct wm8750_s *) opaque; |
500 |
int i;
|
501 |
qemu_put_8s(f, &s->i2c_data[0]);
|
502 |
qemu_put_8s(f, &s->i2c_data[1]);
|
503 |
qemu_put_be32(f, s->i2c_len); |
504 |
qemu_put_be32(f, s->enable); |
505 |
qemu_put_be32(f, s->idx_in); |
506 |
qemu_put_be32(f, s->req_in); |
507 |
qemu_put_be32(f, s->idx_out); |
508 |
qemu_put_be32(f, s->req_out); |
509 |
|
510 |
for (i = 0; i < 7; i ++) |
511 |
qemu_put_8s(f, &s->outvol[i]); |
512 |
for (i = 0; i < 2; i ++) |
513 |
qemu_put_8s(f, &s->outmute[i]); |
514 |
for (i = 0; i < 4; i ++) |
515 |
qemu_put_8s(f, &s->invol[i]); |
516 |
for (i = 0; i < 2; i ++) |
517 |
qemu_put_8s(f, &s->inmute[i]); |
518 |
|
519 |
for (i = 0; i < 2; i ++) |
520 |
qemu_put_8s(f, &s->diff[i]); |
521 |
qemu_put_8s(f, &s->pol); |
522 |
qemu_put_8s(f, &s->ds); |
523 |
for (i = 0; i < 2; i ++) |
524 |
qemu_put_8s(f, &s->monomix[i]); |
525 |
qemu_put_8s(f, &s->alc); |
526 |
qemu_put_8s(f, &s->mute); |
527 |
for (i = 0; i < 4; i ++) |
528 |
qemu_put_8s(f, &s->path[i]); |
529 |
for (i = 0; i < 2; i ++) |
530 |
qemu_put_8s(f, &s->mpath[i]); |
531 |
qemu_put_8s(f, &s->format); |
532 |
qemu_put_8s(f, &s->power); |
533 |
qemu_put_be32s(f, &s->inmask); |
534 |
qemu_put_be32s(f, &s->outmask); |
535 |
qemu_put_byte(f, (s->rate - wm_rate_table) / sizeof(*s->rate));
|
536 |
i2c_slave_save(f, &s->i2c); |
537 |
} |
538 |
|
539 |
static int wm8750_load(QEMUFile *f, void *opaque, int version_id) |
540 |
{ |
541 |
struct wm8750_s *s = (struct wm8750_s *) opaque; |
542 |
int i;
|
543 |
qemu_get_8s(f, &s->i2c_data[0]);
|
544 |
qemu_get_8s(f, &s->i2c_data[1]);
|
545 |
s->i2c_len = qemu_get_be32(f); |
546 |
s->enable = qemu_get_be32(f); |
547 |
s->idx_in = qemu_get_be32(f); |
548 |
s->req_in = qemu_get_be32(f); |
549 |
s->idx_out = qemu_get_be32(f); |
550 |
s->req_out = qemu_get_be32(f); |
551 |
|
552 |
for (i = 0; i < 7; i ++) |
553 |
qemu_get_8s(f, &s->outvol[i]); |
554 |
for (i = 0; i < 2; i ++) |
555 |
qemu_get_8s(f, &s->outmute[i]); |
556 |
for (i = 0; i < 4; i ++) |
557 |
qemu_get_8s(f, &s->invol[i]); |
558 |
for (i = 0; i < 2; i ++) |
559 |
qemu_get_8s(f, &s->inmute[i]); |
560 |
|
561 |
for (i = 0; i < 2; i ++) |
562 |
qemu_get_8s(f, &s->diff[i]); |
563 |
qemu_get_8s(f, &s->pol); |
564 |
qemu_get_8s(f, &s->ds); |
565 |
for (i = 0; i < 2; i ++) |
566 |
qemu_get_8s(f, &s->monomix[i]); |
567 |
qemu_get_8s(f, &s->alc); |
568 |
qemu_get_8s(f, &s->mute); |
569 |
for (i = 0; i < 4; i ++) |
570 |
qemu_get_8s(f, &s->path[i]); |
571 |
for (i = 0; i < 2; i ++) |
572 |
qemu_get_8s(f, &s->mpath[i]); |
573 |
qemu_get_8s(f, &s->format); |
574 |
qemu_get_8s(f, &s->power); |
575 |
qemu_get_be32s(f, &s->inmask); |
576 |
qemu_get_be32s(f, &s->outmask); |
577 |
s->rate = &wm_rate_table[(uint8_t) qemu_get_byte(f) & 0x1f];
|
578 |
i2c_slave_load(f, &s->i2c); |
579 |
return 0; |
580 |
} |
581 |
|
582 |
static int wm8750_iid = 0; |
583 |
|
584 |
i2c_slave *wm8750_init(i2c_bus *bus, AudioState *audio) |
585 |
{ |
586 |
struct wm8750_s *s = (struct wm8750_s *) |
587 |
i2c_slave_init(bus, 0, sizeof(struct wm8750_s)); |
588 |
s->i2c.event = wm8750_event; |
589 |
s->i2c.recv = wm8750_rx; |
590 |
s->i2c.send = wm8750_tx; |
591 |
|
592 |
AUD_register_card(audio, CODEC, &s->card); |
593 |
wm8750_reset(&s->i2c); |
594 |
|
595 |
register_savevm(CODEC, wm8750_iid ++, 0, wm8750_save, wm8750_load, s);
|
596 |
|
597 |
return &s->i2c;
|
598 |
} |
599 |
|
600 |
static void wm8750_fini(i2c_slave *i2c) |
601 |
{ |
602 |
struct wm8750_s *s = (struct wm8750_s *) i2c; |
603 |
wm8750_reset(&s->i2c); |
604 |
AUD_remove_card(&s->card); |
605 |
qemu_free(s); |
606 |
} |
607 |
|
608 |
void wm8750_data_req_set(i2c_slave *i2c,
|
609 |
void (*data_req)(void *, int, int), void *opaque) |
610 |
{ |
611 |
struct wm8750_s *s = (struct wm8750_s *) i2c; |
612 |
s->data_req = data_req; |
613 |
s->opaque = opaque; |
614 |
} |
615 |
|
616 |
void wm8750_dac_dat(void *opaque, uint32_t sample) |
617 |
{ |
618 |
struct wm8750_s *s = (struct wm8750_s *) opaque; |
619 |
uint32_t *data = (uint32_t *) &s->data_out[s->idx_out]; |
620 |
*data = sample & s->outmask; |
621 |
s->req_out -= 4;
|
622 |
s->idx_out += 4;
|
623 |
if (s->idx_out >= sizeof(s->data_out) || s->req_out <= 0) |
624 |
wm8750_out_flush(s); |
625 |
} |
626 |
|
627 |
uint32_t wm8750_adc_dat(void *opaque)
|
628 |
{ |
629 |
struct wm8750_s *s = (struct wm8750_s *) opaque; |
630 |
uint32_t *data; |
631 |
if (s->idx_in >= sizeof(s->data_in)) |
632 |
wm8750_in_load(s); |
633 |
data = (uint32_t *) &s->data_in[s->idx_in]; |
634 |
s->req_in -= 4;
|
635 |
s->idx_in += 4;
|
636 |
return *data & s->inmask;
|
637 |
} |