root / hw / es1370.c @ cc9f28bc
History | View | Annotate | Download (29.4 kB)
1 | 1d14ffa9 | bellard | /*
|
---|---|---|---|
2 | 1d14ffa9 | bellard | * QEMU ES1370 emulation
|
3 | 1d14ffa9 | bellard | *
|
4 | 1d14ffa9 | bellard | * Copyright (c) 2005 Vassili Karpov (malc)
|
5 | 1d14ffa9 | bellard | *
|
6 | 1d14ffa9 | bellard | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 1d14ffa9 | bellard | * of this software and associated documentation files (the "Software"), to deal
|
8 | 1d14ffa9 | bellard | * in the Software without restriction, including without limitation the rights
|
9 | 1d14ffa9 | bellard | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 1d14ffa9 | bellard | * copies of the Software, and to permit persons to whom the Software is
|
11 | 1d14ffa9 | bellard | * furnished to do so, subject to the following conditions:
|
12 | 1d14ffa9 | bellard | *
|
13 | 1d14ffa9 | bellard | * The above copyright notice and this permission notice shall be included in
|
14 | 1d14ffa9 | bellard | * all copies or substantial portions of the Software.
|
15 | 1d14ffa9 | bellard | *
|
16 | 1d14ffa9 | bellard | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 1d14ffa9 | bellard | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 1d14ffa9 | bellard | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 1d14ffa9 | bellard | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 1d14ffa9 | bellard | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 1d14ffa9 | bellard | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 1d14ffa9 | bellard | * THE SOFTWARE.
|
23 | 1d14ffa9 | bellard | */
|
24 | 1d14ffa9 | bellard | |
25 | 1d14ffa9 | bellard | /* #define DEBUG_ES1370 */
|
26 | 1d14ffa9 | bellard | /* #define VERBOSE_ES1370 */
|
27 | 1d14ffa9 | bellard | #define SILENT_ES1370
|
28 | 1d14ffa9 | bellard | |
29 | 87ecb68b | pbrook | #include "hw.h" |
30 | 87ecb68b | pbrook | #include "audiodev.h" |
31 | 87ecb68b | pbrook | #include "audio/audio.h" |
32 | 87ecb68b | pbrook | #include "pci.h" |
33 | 1d14ffa9 | bellard | |
34 | 1d14ffa9 | bellard | /* Missing stuff:
|
35 | 1d14ffa9 | bellard | SCTRL_P[12](END|ST)INC
|
36 | 1d14ffa9 | bellard | SCTRL_P1SCTRLD
|
37 | 1d14ffa9 | bellard | SCTRL_P2DACSEN
|
38 | 1d14ffa9 | bellard | CTRL_DAC_SYNC
|
39 | 1d14ffa9 | bellard | MIDI
|
40 | 1d14ffa9 | bellard | non looped mode
|
41 | 1d14ffa9 | bellard | surely more
|
42 | 1d14ffa9 | bellard | */
|
43 | 1d14ffa9 | bellard | |
44 | 1d14ffa9 | bellard | /*
|
45 | 1d14ffa9 | bellard | Following macros and samplerate array were copied verbatim from
|
46 | 1d14ffa9 | bellard | Linux kernel 2.4.30: drivers/sound/es1370.c
|
47 | 1d14ffa9 | bellard | |
48 | 1d14ffa9 | bellard | Copyright (C) 1998-2001, 2003 Thomas Sailer (t.sailer@alumni.ethz.ch)
|
49 | 1d14ffa9 | bellard | */
|
50 | 1d14ffa9 | bellard | |
51 | 1d14ffa9 | bellard | /* Start blatant GPL violation */
|
52 | 1d14ffa9 | bellard | |
53 | 1d14ffa9 | bellard | #define ES1370_REG_CONTROL 0x00 |
54 | 1d14ffa9 | bellard | #define ES1370_REG_STATUS 0x04 |
55 | 1d14ffa9 | bellard | #define ES1370_REG_UART_DATA 0x08 |
56 | 1d14ffa9 | bellard | #define ES1370_REG_UART_STATUS 0x09 |
57 | 1d14ffa9 | bellard | #define ES1370_REG_UART_CONTROL 0x09 |
58 | 1d14ffa9 | bellard | #define ES1370_REG_UART_TEST 0x0a |
59 | 1d14ffa9 | bellard | #define ES1370_REG_MEMPAGE 0x0c |
60 | 1d14ffa9 | bellard | #define ES1370_REG_CODEC 0x10 |
61 | 1d14ffa9 | bellard | #define ES1370_REG_SERIAL_CONTROL 0x20 |
62 | 1d14ffa9 | bellard | #define ES1370_REG_DAC1_SCOUNT 0x24 |
63 | 1d14ffa9 | bellard | #define ES1370_REG_DAC2_SCOUNT 0x28 |
64 | 1d14ffa9 | bellard | #define ES1370_REG_ADC_SCOUNT 0x2c |
65 | 1d14ffa9 | bellard | |
66 | 1d14ffa9 | bellard | #define ES1370_REG_DAC1_FRAMEADR 0xc30 |
67 | 1d14ffa9 | bellard | #define ES1370_REG_DAC1_FRAMECNT 0xc34 |
68 | 1d14ffa9 | bellard | #define ES1370_REG_DAC2_FRAMEADR 0xc38 |
69 | 1d14ffa9 | bellard | #define ES1370_REG_DAC2_FRAMECNT 0xc3c |
70 | 1d14ffa9 | bellard | #define ES1370_REG_ADC_FRAMEADR 0xd30 |
71 | 1d14ffa9 | bellard | #define ES1370_REG_ADC_FRAMECNT 0xd34 |
72 | 1d14ffa9 | bellard | #define ES1370_REG_PHANTOM_FRAMEADR 0xd38 |
73 | 1d14ffa9 | bellard | #define ES1370_REG_PHANTOM_FRAMECNT 0xd3c |
74 | 1d14ffa9 | bellard | |
75 | 1d14ffa9 | bellard | static const unsigned dac1_samplerate[] = { 5512, 11025, 22050, 44100 }; |
76 | 1d14ffa9 | bellard | |
77 | 1d14ffa9 | bellard | #define DAC2_SRTODIV(x) (((1411200+(x)/2)/(x))-2) |
78 | 1d14ffa9 | bellard | #define DAC2_DIVTOSR(x) (1411200/((x)+2)) |
79 | 1d14ffa9 | bellard | |
80 | 1d14ffa9 | bellard | #define CTRL_ADC_STOP 0x80000000 /* 1 = ADC stopped */ |
81 | 1d14ffa9 | bellard | #define CTRL_XCTL1 0x40000000 /* electret mic bias */ |
82 | 1d14ffa9 | bellard | #define CTRL_OPEN 0x20000000 /* no function, can be read and written */ |
83 | 1d14ffa9 | bellard | #define CTRL_PCLKDIV 0x1fff0000 /* ADC/DAC2 clock divider */ |
84 | 1d14ffa9 | bellard | #define CTRL_SH_PCLKDIV 16 |
85 | 1d14ffa9 | bellard | #define CTRL_MSFMTSEL 0x00008000 /* MPEG serial data fmt: 0 = Sony, 1 = I2S */ |
86 | 1d14ffa9 | bellard | #define CTRL_M_SBB 0x00004000 /* DAC2 clock: 0 = PCLKDIV, 1 = MPEG */ |
87 | 1d14ffa9 | bellard | #define CTRL_WTSRSEL 0x00003000 /* DAC1 clock freq: 0=5512, 1=11025, 2=22050, 3=44100 */ |
88 | 1d14ffa9 | bellard | #define CTRL_SH_WTSRSEL 12 |
89 | 1d14ffa9 | bellard | #define CTRL_DAC_SYNC 0x00000800 /* 1 = DAC2 runs off DAC1 clock */ |
90 | 1d14ffa9 | bellard | #define CTRL_CCB_INTRM 0x00000400 /* 1 = CCB "voice" ints enabled */ |
91 | 1d14ffa9 | bellard | #define CTRL_M_CB 0x00000200 /* recording source: 0 = ADC, 1 = MPEG */ |
92 | 1d14ffa9 | bellard | #define CTRL_XCTL0 0x00000100 /* 0 = Line in, 1 = Line out */ |
93 | 1d14ffa9 | bellard | #define CTRL_BREQ 0x00000080 /* 1 = test mode (internal mem test) */ |
94 | 1d14ffa9 | bellard | #define CTRL_DAC1_EN 0x00000040 /* enable DAC1 */ |
95 | 1d14ffa9 | bellard | #define CTRL_DAC2_EN 0x00000020 /* enable DAC2 */ |
96 | 1d14ffa9 | bellard | #define CTRL_ADC_EN 0x00000010 /* enable ADC */ |
97 | 1d14ffa9 | bellard | #define CTRL_UART_EN 0x00000008 /* enable MIDI uart */ |
98 | 1d14ffa9 | bellard | #define CTRL_JYSTK_EN 0x00000004 /* enable Joystick port (presumably at address 0x200) */ |
99 | 1d14ffa9 | bellard | #define CTRL_CDC_EN 0x00000002 /* enable serial (CODEC) interface */ |
100 | 1d14ffa9 | bellard | #define CTRL_SERR_DIS 0x00000001 /* 1 = disable PCI SERR signal */ |
101 | 1d14ffa9 | bellard | |
102 | 1d14ffa9 | bellard | #define STAT_INTR 0x80000000 /* wired or of all interrupt bits */ |
103 | 1d14ffa9 | bellard | #define STAT_CSTAT 0x00000400 /* 1 = codec busy or codec write in progress */ |
104 | 1d14ffa9 | bellard | #define STAT_CBUSY 0x00000200 /* 1 = codec busy */ |
105 | 1d14ffa9 | bellard | #define STAT_CWRIP 0x00000100 /* 1 = codec write in progress */ |
106 | 1d14ffa9 | bellard | #define STAT_VC 0x00000060 /* CCB int source, 0=DAC1, 1=DAC2, 2=ADC, 3=undef */ |
107 | 1d14ffa9 | bellard | #define STAT_SH_VC 5 |
108 | 1d14ffa9 | bellard | #define STAT_MCCB 0x00000010 /* CCB int pending */ |
109 | 1d14ffa9 | bellard | #define STAT_UART 0x00000008 /* UART int pending */ |
110 | 1d14ffa9 | bellard | #define STAT_DAC1 0x00000004 /* DAC1 int pending */ |
111 | 1d14ffa9 | bellard | #define STAT_DAC2 0x00000002 /* DAC2 int pending */ |
112 | 1d14ffa9 | bellard | #define STAT_ADC 0x00000001 /* ADC int pending */ |
113 | 1d14ffa9 | bellard | |
114 | 1d14ffa9 | bellard | #define USTAT_RXINT 0x80 /* UART rx int pending */ |
115 | 1d14ffa9 | bellard | #define USTAT_TXINT 0x04 /* UART tx int pending */ |
116 | 1d14ffa9 | bellard | #define USTAT_TXRDY 0x02 /* UART tx ready */ |
117 | 1d14ffa9 | bellard | #define USTAT_RXRDY 0x01 /* UART rx ready */ |
118 | 1d14ffa9 | bellard | |
119 | 1d14ffa9 | bellard | #define UCTRL_RXINTEN 0x80 /* 1 = enable RX ints */ |
120 | 1d14ffa9 | bellard | #define UCTRL_TXINTEN 0x60 /* TX int enable field mask */ |
121 | 1d14ffa9 | bellard | #define UCTRL_ENA_TXINT 0x20 /* enable TX int */ |
122 | 1d14ffa9 | bellard | #define UCTRL_CNTRL 0x03 /* control field */ |
123 | 1d14ffa9 | bellard | #define UCTRL_CNTRL_SWR 0x03 /* software reset command */ |
124 | 1d14ffa9 | bellard | |
125 | 1d14ffa9 | bellard | #define SCTRL_P2ENDINC 0x00380000 /* */ |
126 | 1d14ffa9 | bellard | #define SCTRL_SH_P2ENDINC 19 |
127 | 1d14ffa9 | bellard | #define SCTRL_P2STINC 0x00070000 /* */ |
128 | 1d14ffa9 | bellard | #define SCTRL_SH_P2STINC 16 |
129 | 1d14ffa9 | bellard | #define SCTRL_R1LOOPSEL 0x00008000 /* 0 = loop mode */ |
130 | 1d14ffa9 | bellard | #define SCTRL_P2LOOPSEL 0x00004000 /* 0 = loop mode */ |
131 | 1d14ffa9 | bellard | #define SCTRL_P1LOOPSEL 0x00002000 /* 0 = loop mode */ |
132 | 1d14ffa9 | bellard | #define SCTRL_P2PAUSE 0x00001000 /* 1 = pause mode */ |
133 | 1d14ffa9 | bellard | #define SCTRL_P1PAUSE 0x00000800 /* 1 = pause mode */ |
134 | 1d14ffa9 | bellard | #define SCTRL_R1INTEN 0x00000400 /* enable interrupt */ |
135 | 1d14ffa9 | bellard | #define SCTRL_P2INTEN 0x00000200 /* enable interrupt */ |
136 | 1d14ffa9 | bellard | #define SCTRL_P1INTEN 0x00000100 /* enable interrupt */ |
137 | 1d14ffa9 | bellard | #define SCTRL_P1SCTRLD 0x00000080 /* reload sample count register for DAC1 */ |
138 | 1d14ffa9 | bellard | #define SCTRL_P2DACSEN 0x00000040 /* 1 = DAC2 play back last sample when disabled */ |
139 | 1d14ffa9 | bellard | #define SCTRL_R1SEB 0x00000020 /* 1 = 16bit */ |
140 | 1d14ffa9 | bellard | #define SCTRL_R1SMB 0x00000010 /* 1 = stereo */ |
141 | 1d14ffa9 | bellard | #define SCTRL_R1FMT 0x00000030 /* format mask */ |
142 | 1d14ffa9 | bellard | #define SCTRL_SH_R1FMT 4 |
143 | 1d14ffa9 | bellard | #define SCTRL_P2SEB 0x00000008 /* 1 = 16bit */ |
144 | 1d14ffa9 | bellard | #define SCTRL_P2SMB 0x00000004 /* 1 = stereo */ |
145 | 1d14ffa9 | bellard | #define SCTRL_P2FMT 0x0000000c /* format mask */ |
146 | 1d14ffa9 | bellard | #define SCTRL_SH_P2FMT 2 |
147 | 1d14ffa9 | bellard | #define SCTRL_P1SEB 0x00000002 /* 1 = 16bit */ |
148 | 1d14ffa9 | bellard | #define SCTRL_P1SMB 0x00000001 /* 1 = stereo */ |
149 | 1d14ffa9 | bellard | #define SCTRL_P1FMT 0x00000003 /* format mask */ |
150 | 1d14ffa9 | bellard | #define SCTRL_SH_P1FMT 0 |
151 | 1d14ffa9 | bellard | |
152 | 1d14ffa9 | bellard | /* End blatant GPL violation */
|
153 | 1d14ffa9 | bellard | |
154 | 1d14ffa9 | bellard | #define NB_CHANNELS 3 |
155 | 1d14ffa9 | bellard | #define DAC1_CHANNEL 0 |
156 | 1d14ffa9 | bellard | #define DAC2_CHANNEL 1 |
157 | 1d14ffa9 | bellard | #define ADC_CHANNEL 2 |
158 | 1d14ffa9 | bellard | |
159 | 1d14ffa9 | bellard | #define IO_READ_PROTO(n) \
|
160 | 1d14ffa9 | bellard | static uint32_t n (void *opaque, uint32_t addr) |
161 | 1d14ffa9 | bellard | #define IO_WRITE_PROTO(n) \
|
162 | 1d14ffa9 | bellard | static void n (void *opaque, uint32_t addr, uint32_t val) |
163 | 1d14ffa9 | bellard | |
164 | 1d14ffa9 | bellard | static void es1370_dac1_callback (void *opaque, int free); |
165 | 1d14ffa9 | bellard | static void es1370_dac2_callback (void *opaque, int free); |
166 | 1d14ffa9 | bellard | static void es1370_adc_callback (void *opaque, int avail); |
167 | 1d14ffa9 | bellard | |
168 | 1d14ffa9 | bellard | #ifdef DEBUG_ES1370
|
169 | 1d14ffa9 | bellard | |
170 | 1d14ffa9 | bellard | #define ldebug(...) AUD_log ("es1370", __VA_ARGS__) |
171 | 1d14ffa9 | bellard | |
172 | 1d14ffa9 | bellard | static void print_ctl (uint32_t val) |
173 | 1d14ffa9 | bellard | { |
174 | 1d14ffa9 | bellard | char buf[1024]; |
175 | 1d14ffa9 | bellard | |
176 | 1d14ffa9 | bellard | buf[0] = '\0'; |
177 | 1d14ffa9 | bellard | #define a(n) if (val & CTRL_##n) strcat (buf, " "#n) |
178 | 1d14ffa9 | bellard | a (ADC_STOP); |
179 | 1d14ffa9 | bellard | a (XCTL1); |
180 | 1d14ffa9 | bellard | a (OPEN); |
181 | 1d14ffa9 | bellard | a (MSFMTSEL); |
182 | 1d14ffa9 | bellard | a (M_SBB); |
183 | 1d14ffa9 | bellard | a (DAC_SYNC); |
184 | 1d14ffa9 | bellard | a (CCB_INTRM); |
185 | 1d14ffa9 | bellard | a (M_CB); |
186 | 1d14ffa9 | bellard | a (XCTL0); |
187 | 1d14ffa9 | bellard | a (BREQ); |
188 | 1d14ffa9 | bellard | a (DAC1_EN); |
189 | 1d14ffa9 | bellard | a (DAC2_EN); |
190 | 1d14ffa9 | bellard | a (ADC_EN); |
191 | 1d14ffa9 | bellard | a (UART_EN); |
192 | 1d14ffa9 | bellard | a (JYSTK_EN); |
193 | 1d14ffa9 | bellard | a (CDC_EN); |
194 | 1d14ffa9 | bellard | a (SERR_DIS); |
195 | 1d14ffa9 | bellard | #undef a
|
196 | 1d14ffa9 | bellard | AUD_log ("es1370", "ctl - PCLKDIV %d(DAC2 freq %d), freq %d,%s\n", |
197 | 1d14ffa9 | bellard | (val & CTRL_PCLKDIV) >> CTRL_SH_PCLKDIV, |
198 | 1d14ffa9 | bellard | DAC2_DIVTOSR ((val & CTRL_PCLKDIV) >> CTRL_SH_PCLKDIV), |
199 | 1d14ffa9 | bellard | dac1_samplerate[(val & CTRL_WTSRSEL) >> CTRL_SH_WTSRSEL], |
200 | 1d14ffa9 | bellard | buf); |
201 | 1d14ffa9 | bellard | } |
202 | 1d14ffa9 | bellard | |
203 | 1d14ffa9 | bellard | static void print_sctl (uint32_t val) |
204 | 1d14ffa9 | bellard | { |
205 | 1d14ffa9 | bellard | static const char *fmt_names[] = {"8M", "8S", "16M", "16S"}; |
206 | 1d14ffa9 | bellard | char buf[1024]; |
207 | 1d14ffa9 | bellard | |
208 | 1d14ffa9 | bellard | buf[0] = '\0'; |
209 | 1d14ffa9 | bellard | |
210 | 1d14ffa9 | bellard | #define a(n) if (val & SCTRL_##n) strcat (buf, " "#n) |
211 | 1d14ffa9 | bellard | #define b(n) if (!(val & SCTRL_##n)) strcat (buf, " "#n) |
212 | 1d14ffa9 | bellard | b (R1LOOPSEL); |
213 | 1d14ffa9 | bellard | b (P2LOOPSEL); |
214 | 1d14ffa9 | bellard | b (P1LOOPSEL); |
215 | 1d14ffa9 | bellard | a (P2PAUSE); |
216 | 1d14ffa9 | bellard | a (P1PAUSE); |
217 | 1d14ffa9 | bellard | a (R1INTEN); |
218 | 1d14ffa9 | bellard | a (P2INTEN); |
219 | 1d14ffa9 | bellard | a (P1INTEN); |
220 | 1d14ffa9 | bellard | a (P1SCTRLD); |
221 | 1d14ffa9 | bellard | a (P2DACSEN); |
222 | 1d14ffa9 | bellard | if (buf[0]) { |
223 | 1d14ffa9 | bellard | strcat (buf, "\n ");
|
224 | 1d14ffa9 | bellard | } |
225 | 1d14ffa9 | bellard | else {
|
226 | 1d14ffa9 | bellard | buf[0] = ' '; |
227 | 1d14ffa9 | bellard | buf[1] = '\0'; |
228 | 1d14ffa9 | bellard | } |
229 | 1d14ffa9 | bellard | #undef b
|
230 | 1d14ffa9 | bellard | #undef a
|
231 | 1d14ffa9 | bellard | AUD_log ("es1370",
|
232 | 1d14ffa9 | bellard | "%s"
|
233 | 1d14ffa9 | bellard | "p2_end_inc %d, p2_st_inc %d, r1_fmt %s, p2_fmt %s, p1_fmt %s\n",
|
234 | 1d14ffa9 | bellard | buf, |
235 | 1d14ffa9 | bellard | (val & SCTRL_P2ENDINC) >> SCTRL_SH_P2ENDINC, |
236 | 1d14ffa9 | bellard | (val & SCTRL_P2STINC) >> SCTRL_SH_P2STINC, |
237 | 1d14ffa9 | bellard | fmt_names [(val >> SCTRL_SH_R1FMT) & 3],
|
238 | 1d14ffa9 | bellard | fmt_names [(val >> SCTRL_SH_P2FMT) & 3],
|
239 | 1d14ffa9 | bellard | fmt_names [(val >> SCTRL_SH_P1FMT) & 3]
|
240 | 1d14ffa9 | bellard | ); |
241 | 1d14ffa9 | bellard | } |
242 | 1d14ffa9 | bellard | #else
|
243 | 1d14ffa9 | bellard | #define ldebug(...)
|
244 | 1d14ffa9 | bellard | #define print_ctl(...)
|
245 | 1d14ffa9 | bellard | #define print_sctl(...)
|
246 | 1d14ffa9 | bellard | #endif
|
247 | 1d14ffa9 | bellard | |
248 | 1d14ffa9 | bellard | #ifdef VERBOSE_ES1370
|
249 | 1d14ffa9 | bellard | #define dolog(...) AUD_log ("es1370", __VA_ARGS__) |
250 | 1d14ffa9 | bellard | #else
|
251 | 1d14ffa9 | bellard | #define dolog(...)
|
252 | 1d14ffa9 | bellard | #endif
|
253 | 1d14ffa9 | bellard | |
254 | 1d14ffa9 | bellard | #ifndef SILENT_ES1370
|
255 | 946fc947 | bellard | #define lwarn(...) AUD_log ("es1370: warning", __VA_ARGS__) |
256 | 1d14ffa9 | bellard | #else
|
257 | 1d14ffa9 | bellard | #define lwarn(...)
|
258 | 1d14ffa9 | bellard | #endif
|
259 | 1d14ffa9 | bellard | |
260 | 1d14ffa9 | bellard | struct chan {
|
261 | 1d14ffa9 | bellard | uint32_t shift; |
262 | 1d14ffa9 | bellard | uint32_t leftover; |
263 | 1d14ffa9 | bellard | uint32_t scount; |
264 | 1d14ffa9 | bellard | uint32_t frame_addr; |
265 | 1d14ffa9 | bellard | uint32_t frame_cnt; |
266 | 1d14ffa9 | bellard | }; |
267 | 1d14ffa9 | bellard | |
268 | 1d14ffa9 | bellard | typedef struct ES1370State { |
269 | e5944641 | Juan Quintela | PCIDevice dev; |
270 | c0fe3827 | bellard | QEMUSoundCard card; |
271 | 1d14ffa9 | bellard | struct chan chan[NB_CHANNELS];
|
272 | 1d14ffa9 | bellard | SWVoiceOut *dac_voice[2];
|
273 | 1d14ffa9 | bellard | SWVoiceIn *adc_voice; |
274 | 1d14ffa9 | bellard | |
275 | 1d14ffa9 | bellard | uint32_t ctl; |
276 | 1d14ffa9 | bellard | uint32_t status; |
277 | 1d14ffa9 | bellard | uint32_t mempage; |
278 | 1d14ffa9 | bellard | uint32_t codec; |
279 | 1d14ffa9 | bellard | uint32_t sctl; |
280 | 1d14ffa9 | bellard | } ES1370State; |
281 | 1d14ffa9 | bellard | |
282 | 1d14ffa9 | bellard | struct chan_bits {
|
283 | 1d14ffa9 | bellard | uint32_t ctl_en; |
284 | 1d14ffa9 | bellard | uint32_t stat_int; |
285 | 1d14ffa9 | bellard | uint32_t sctl_pause; |
286 | 1d14ffa9 | bellard | uint32_t sctl_inten; |
287 | 1d14ffa9 | bellard | uint32_t sctl_fmt; |
288 | 1d14ffa9 | bellard | uint32_t sctl_sh_fmt; |
289 | 1d14ffa9 | bellard | uint32_t sctl_loopsel; |
290 | 1d14ffa9 | bellard | void (*calc_freq) (ES1370State *s, uint32_t ctl,
|
291 | 1d14ffa9 | bellard | uint32_t *old_freq, uint32_t *new_freq); |
292 | 1d14ffa9 | bellard | }; |
293 | 1d14ffa9 | bellard | |
294 | 1d14ffa9 | bellard | static void es1370_dac1_calc_freq (ES1370State *s, uint32_t ctl, |
295 | 1d14ffa9 | bellard | uint32_t *old_freq, uint32_t *new_freq); |
296 | 1d14ffa9 | bellard | static void es1370_dac2_and_adc_calc_freq (ES1370State *s, uint32_t ctl, |
297 | 1d14ffa9 | bellard | uint32_t *old_freq, |
298 | 1d14ffa9 | bellard | uint32_t *new_freq); |
299 | 1d14ffa9 | bellard | |
300 | 1d14ffa9 | bellard | static const struct chan_bits es1370_chan_bits[] = { |
301 | 1d14ffa9 | bellard | {CTRL_DAC1_EN, STAT_DAC1, SCTRL_P1PAUSE, SCTRL_P1INTEN, |
302 | 1d14ffa9 | bellard | SCTRL_P1FMT, SCTRL_SH_P1FMT, SCTRL_P1LOOPSEL, |
303 | 1d14ffa9 | bellard | es1370_dac1_calc_freq}, |
304 | 1d14ffa9 | bellard | |
305 | 1d14ffa9 | bellard | {CTRL_DAC2_EN, STAT_DAC2, SCTRL_P2PAUSE, SCTRL_P2INTEN, |
306 | 1d14ffa9 | bellard | SCTRL_P2FMT, SCTRL_SH_P2FMT, SCTRL_P2LOOPSEL, |
307 | 1d14ffa9 | bellard | es1370_dac2_and_adc_calc_freq}, |
308 | 1d14ffa9 | bellard | |
309 | 1d14ffa9 | bellard | {CTRL_ADC_EN, STAT_ADC, 0, SCTRL_R1INTEN,
|
310 | 1d14ffa9 | bellard | SCTRL_R1FMT, SCTRL_SH_R1FMT, SCTRL_R1LOOPSEL, |
311 | 1d14ffa9 | bellard | es1370_dac2_and_adc_calc_freq} |
312 | 1d14ffa9 | bellard | }; |
313 | 1d14ffa9 | bellard | |
314 | 1d14ffa9 | bellard | static void es1370_update_status (ES1370State *s, uint32_t new_status) |
315 | 1d14ffa9 | bellard | { |
316 | 1d14ffa9 | bellard | uint32_t level = new_status & (STAT_DAC1 | STAT_DAC2 | STAT_ADC); |
317 | 1d14ffa9 | bellard | |
318 | 1d14ffa9 | bellard | if (level) {
|
319 | 1d14ffa9 | bellard | s->status = new_status | STAT_INTR; |
320 | 1d14ffa9 | bellard | } |
321 | 1d14ffa9 | bellard | else {
|
322 | 1d14ffa9 | bellard | s->status = new_status & ~STAT_INTR; |
323 | 1d14ffa9 | bellard | } |
324 | e5944641 | Juan Quintela | qemu_set_irq (s->dev.irq[0], !!level);
|
325 | 1d14ffa9 | bellard | } |
326 | 1d14ffa9 | bellard | |
327 | 1d14ffa9 | bellard | static void es1370_reset (ES1370State *s) |
328 | 1d14ffa9 | bellard | { |
329 | 1d14ffa9 | bellard | size_t i; |
330 | 1d14ffa9 | bellard | |
331 | 1d14ffa9 | bellard | s->ctl = 1;
|
332 | 1d14ffa9 | bellard | s->status = 0x60;
|
333 | 1d14ffa9 | bellard | s->mempage = 0;
|
334 | 1d14ffa9 | bellard | s->codec = 0;
|
335 | 1d14ffa9 | bellard | s->sctl = 0;
|
336 | 1d14ffa9 | bellard | |
337 | 1d14ffa9 | bellard | for (i = 0; i < NB_CHANNELS; ++i) { |
338 | 1d14ffa9 | bellard | struct chan *d = &s->chan[i];
|
339 | 1d14ffa9 | bellard | d->scount = 0;
|
340 | 1d14ffa9 | bellard | d->leftover = 0;
|
341 | 1d14ffa9 | bellard | if (i == ADC_CHANNEL) {
|
342 | c0fe3827 | bellard | AUD_close_in (&s->card, s->adc_voice); |
343 | 1d14ffa9 | bellard | s->adc_voice = NULL;
|
344 | 1d14ffa9 | bellard | } |
345 | 1d14ffa9 | bellard | else {
|
346 | c0fe3827 | bellard | AUD_close_out (&s->card, s->dac_voice[i]); |
347 | 1d14ffa9 | bellard | s->dac_voice[i] = NULL;
|
348 | 1d14ffa9 | bellard | } |
349 | 1d14ffa9 | bellard | } |
350 | e5944641 | Juan Quintela | qemu_irq_lower (s->dev.irq[0]);
|
351 | 1d14ffa9 | bellard | } |
352 | 1d14ffa9 | bellard | |
353 | 1d14ffa9 | bellard | static void es1370_maybe_lower_irq (ES1370State *s, uint32_t sctl) |
354 | 1d14ffa9 | bellard | { |
355 | 1d14ffa9 | bellard | uint32_t new_status = s->status; |
356 | 1d14ffa9 | bellard | |
357 | 1d14ffa9 | bellard | if (!(sctl & SCTRL_P1INTEN) && (s->sctl & SCTRL_P1INTEN)) {
|
358 | 1d14ffa9 | bellard | new_status &= ~STAT_DAC1; |
359 | 1d14ffa9 | bellard | } |
360 | 1d14ffa9 | bellard | |
361 | 1d14ffa9 | bellard | if (!(sctl & SCTRL_P2INTEN) && (s->sctl & SCTRL_P2INTEN)) {
|
362 | 1d14ffa9 | bellard | new_status &= ~STAT_DAC2; |
363 | 1d14ffa9 | bellard | } |
364 | 1d14ffa9 | bellard | |
365 | 1d14ffa9 | bellard | if (!(sctl & SCTRL_R1INTEN) && (s->sctl & SCTRL_R1INTEN)) {
|
366 | 1d14ffa9 | bellard | new_status &= ~STAT_ADC; |
367 | 1d14ffa9 | bellard | } |
368 | 1d14ffa9 | bellard | |
369 | 1d14ffa9 | bellard | if (new_status != s->status) {
|
370 | 1d14ffa9 | bellard | es1370_update_status (s, new_status); |
371 | 1d14ffa9 | bellard | } |
372 | 1d14ffa9 | bellard | } |
373 | 1d14ffa9 | bellard | |
374 | 1d14ffa9 | bellard | static void es1370_dac1_calc_freq (ES1370State *s, uint32_t ctl, |
375 | 1d14ffa9 | bellard | uint32_t *old_freq, uint32_t *new_freq) |
376 | 1d14ffa9 | bellard | |
377 | 1d14ffa9 | bellard | { |
378 | 1d14ffa9 | bellard | *old_freq = dac1_samplerate[(s->ctl & CTRL_WTSRSEL) >> CTRL_SH_WTSRSEL]; |
379 | 1d14ffa9 | bellard | *new_freq = dac1_samplerate[(ctl & CTRL_WTSRSEL) >> CTRL_SH_WTSRSEL]; |
380 | 1d14ffa9 | bellard | } |
381 | 1d14ffa9 | bellard | |
382 | 1d14ffa9 | bellard | static void es1370_dac2_and_adc_calc_freq (ES1370State *s, uint32_t ctl, |
383 | 1d14ffa9 | bellard | uint32_t *old_freq, |
384 | 1d14ffa9 | bellard | uint32_t *new_freq) |
385 | 1d14ffa9 | bellard | |
386 | 1d14ffa9 | bellard | { |
387 | 1d14ffa9 | bellard | uint32_t old_pclkdiv, new_pclkdiv; |
388 | 1d14ffa9 | bellard | |
389 | 1d14ffa9 | bellard | new_pclkdiv = (ctl & CTRL_PCLKDIV) >> CTRL_SH_PCLKDIV; |
390 | 1d14ffa9 | bellard | old_pclkdiv = (s->ctl & CTRL_PCLKDIV) >> CTRL_SH_PCLKDIV; |
391 | 1d14ffa9 | bellard | *new_freq = DAC2_DIVTOSR (new_pclkdiv); |
392 | 1d14ffa9 | bellard | *old_freq = DAC2_DIVTOSR (old_pclkdiv); |
393 | 1d14ffa9 | bellard | } |
394 | 1d14ffa9 | bellard | |
395 | 1d14ffa9 | bellard | static void es1370_update_voices (ES1370State *s, uint32_t ctl, uint32_t sctl) |
396 | 1d14ffa9 | bellard | { |
397 | 1d14ffa9 | bellard | size_t i; |
398 | 1d14ffa9 | bellard | uint32_t old_freq, new_freq, old_fmt, new_fmt; |
399 | 1d14ffa9 | bellard | |
400 | 1d14ffa9 | bellard | for (i = 0; i < NB_CHANNELS; ++i) { |
401 | 1d14ffa9 | bellard | struct chan *d = &s->chan[i];
|
402 | 1d14ffa9 | bellard | const struct chan_bits *b = &es1370_chan_bits[i]; |
403 | 1d14ffa9 | bellard | |
404 | 1d14ffa9 | bellard | new_fmt = (sctl & b->sctl_fmt) >> b->sctl_sh_fmt; |
405 | 1d14ffa9 | bellard | old_fmt = (s->sctl & b->sctl_fmt) >> b->sctl_sh_fmt; |
406 | 1d14ffa9 | bellard | |
407 | 1d14ffa9 | bellard | b->calc_freq (s, ctl, &old_freq, &new_freq); |
408 | 1d14ffa9 | bellard | |
409 | 1d14ffa9 | bellard | if ((old_fmt != new_fmt) || (old_freq != new_freq)) {
|
410 | 1d14ffa9 | bellard | d->shift = (new_fmt & 1) + (new_fmt >> 1); |
411 | 1d14ffa9 | bellard | ldebug ("channel %d, freq = %d, nchannels %d, fmt %d, shift %d\n",
|
412 | 1d14ffa9 | bellard | i, |
413 | 1d14ffa9 | bellard | new_freq, |
414 | 1d14ffa9 | bellard | 1 << (new_fmt & 1), |
415 | 1d14ffa9 | bellard | (new_fmt & 2) ? AUD_FMT_S16 : AUD_FMT_U8,
|
416 | 1d14ffa9 | bellard | d->shift); |
417 | 1d14ffa9 | bellard | if (new_freq) {
|
418 | 1ea879e5 | malc | struct audsettings as;
|
419 | c0fe3827 | bellard | |
420 | c0fe3827 | bellard | as.freq = new_freq; |
421 | c0fe3827 | bellard | as.nchannels = 1 << (new_fmt & 1); |
422 | c0fe3827 | bellard | as.fmt = (new_fmt & 2) ? AUD_FMT_S16 : AUD_FMT_U8;
|
423 | d929eba5 | bellard | as.endianness = 0;
|
424 | c0fe3827 | bellard | |
425 | 1d14ffa9 | bellard | if (i == ADC_CHANNEL) {
|
426 | 1d14ffa9 | bellard | s->adc_voice = |
427 | 1d14ffa9 | bellard | AUD_open_in ( |
428 | c0fe3827 | bellard | &s->card, |
429 | 1d14ffa9 | bellard | s->adc_voice, |
430 | 1d14ffa9 | bellard | "es1370.adc",
|
431 | 1d14ffa9 | bellard | s, |
432 | 1d14ffa9 | bellard | es1370_adc_callback, |
433 | d929eba5 | bellard | &as |
434 | 1d14ffa9 | bellard | ); |
435 | 1d14ffa9 | bellard | } |
436 | 1d14ffa9 | bellard | else {
|
437 | 1d14ffa9 | bellard | s->dac_voice[i] = |
438 | 1d14ffa9 | bellard | AUD_open_out ( |
439 | c0fe3827 | bellard | &s->card, |
440 | 1d14ffa9 | bellard | s->dac_voice[i], |
441 | 1d14ffa9 | bellard | i ? "es1370.dac2" : "es1370.dac1", |
442 | 1d14ffa9 | bellard | s, |
443 | 1d14ffa9 | bellard | i ? es1370_dac2_callback : es1370_dac1_callback, |
444 | d929eba5 | bellard | &as |
445 | 1d14ffa9 | bellard | ); |
446 | 1d14ffa9 | bellard | } |
447 | 1d14ffa9 | bellard | } |
448 | 1d14ffa9 | bellard | } |
449 | 1d14ffa9 | bellard | |
450 | 1d14ffa9 | bellard | if (((ctl ^ s->ctl) & b->ctl_en)
|
451 | 1d14ffa9 | bellard | || ((sctl ^ s->sctl) & b->sctl_pause)) { |
452 | 1d14ffa9 | bellard | int on = (ctl & b->ctl_en) && !(sctl & b->sctl_pause);
|
453 | 1d14ffa9 | bellard | |
454 | 1d14ffa9 | bellard | if (i == ADC_CHANNEL) {
|
455 | 1d14ffa9 | bellard | AUD_set_active_in (s->adc_voice, on); |
456 | 1d14ffa9 | bellard | } |
457 | 1d14ffa9 | bellard | else {
|
458 | 1d14ffa9 | bellard | AUD_set_active_out (s->dac_voice[i], on); |
459 | 1d14ffa9 | bellard | } |
460 | 1d14ffa9 | bellard | } |
461 | 1d14ffa9 | bellard | } |
462 | 1d14ffa9 | bellard | |
463 | 1d14ffa9 | bellard | s->ctl = ctl; |
464 | 1d14ffa9 | bellard | s->sctl = sctl; |
465 | 1d14ffa9 | bellard | } |
466 | 1d14ffa9 | bellard | |
467 | 1d14ffa9 | bellard | static inline uint32_t es1370_fixup (ES1370State *s, uint32_t addr) |
468 | 1d14ffa9 | bellard | { |
469 | 1d14ffa9 | bellard | addr &= 0xff;
|
470 | 1d14ffa9 | bellard | if (addr >= 0x30 && addr <= 0x3f) |
471 | 1d14ffa9 | bellard | addr |= s->mempage << 8;
|
472 | 1d14ffa9 | bellard | return addr;
|
473 | 1d14ffa9 | bellard | } |
474 | 1d14ffa9 | bellard | |
475 | 1d14ffa9 | bellard | IO_WRITE_PROTO (es1370_writeb) |
476 | 1d14ffa9 | bellard | { |
477 | 1d14ffa9 | bellard | ES1370State *s = opaque; |
478 | 1d14ffa9 | bellard | uint32_t shift, mask; |
479 | 1d14ffa9 | bellard | |
480 | 8ead62cf | bellard | addr = es1370_fixup (s, addr); |
481 | 8ead62cf | bellard | |
482 | 1d14ffa9 | bellard | switch (addr) {
|
483 | 1d14ffa9 | bellard | case ES1370_REG_CONTROL:
|
484 | 1d14ffa9 | bellard | case ES1370_REG_CONTROL + 1: |
485 | 1d14ffa9 | bellard | case ES1370_REG_CONTROL + 2: |
486 | 1d14ffa9 | bellard | case ES1370_REG_CONTROL + 3: |
487 | 1d14ffa9 | bellard | shift = (addr - ES1370_REG_CONTROL) << 3;
|
488 | 1d14ffa9 | bellard | mask = 0xff << shift;
|
489 | 1d14ffa9 | bellard | val = (s->ctl & ~mask) | ((val & 0xff) << shift);
|
490 | 1d14ffa9 | bellard | es1370_update_voices (s, val, s->sctl); |
491 | 1d14ffa9 | bellard | print_ctl (val); |
492 | 1d14ffa9 | bellard | break;
|
493 | 1d14ffa9 | bellard | case ES1370_REG_MEMPAGE:
|
494 | 1d14ffa9 | bellard | s->mempage = val; |
495 | 1d14ffa9 | bellard | break;
|
496 | 1d14ffa9 | bellard | case ES1370_REG_SERIAL_CONTROL:
|
497 | 1d14ffa9 | bellard | case ES1370_REG_SERIAL_CONTROL + 1: |
498 | 1d14ffa9 | bellard | case ES1370_REG_SERIAL_CONTROL + 2: |
499 | 1d14ffa9 | bellard | case ES1370_REG_SERIAL_CONTROL + 3: |
500 | 1d14ffa9 | bellard | shift = (addr - ES1370_REG_SERIAL_CONTROL) << 3;
|
501 | 1d14ffa9 | bellard | mask = 0xff << shift;
|
502 | 1d14ffa9 | bellard | val = (s->sctl & ~mask) | ((val & 0xff) << shift);
|
503 | 1d14ffa9 | bellard | es1370_maybe_lower_irq (s, val); |
504 | 1d14ffa9 | bellard | es1370_update_voices (s, s->ctl, val); |
505 | 1d14ffa9 | bellard | print_sctl (val); |
506 | 1d14ffa9 | bellard | break;
|
507 | 1d14ffa9 | bellard | default:
|
508 | 1d14ffa9 | bellard | lwarn ("writeb %#x <- %#x\n", addr, val);
|
509 | 1d14ffa9 | bellard | break;
|
510 | 1d14ffa9 | bellard | } |
511 | 1d14ffa9 | bellard | } |
512 | 1d14ffa9 | bellard | |
513 | 1d14ffa9 | bellard | IO_WRITE_PROTO (es1370_writew) |
514 | 1d14ffa9 | bellard | { |
515 | 1d14ffa9 | bellard | ES1370State *s = opaque; |
516 | 1d14ffa9 | bellard | addr = es1370_fixup (s, addr); |
517 | 1d14ffa9 | bellard | uint32_t shift, mask; |
518 | 1d14ffa9 | bellard | struct chan *d = &s->chan[0]; |
519 | 1d14ffa9 | bellard | |
520 | 1d14ffa9 | bellard | switch (addr) {
|
521 | 1d14ffa9 | bellard | case ES1370_REG_CODEC:
|
522 | 1d14ffa9 | bellard | dolog ("ignored codec write address %#x, data %#x\n",
|
523 | 1d14ffa9 | bellard | (val >> 8) & 0xff, val & 0xff); |
524 | 1d14ffa9 | bellard | s->codec = val; |
525 | 1d14ffa9 | bellard | break;
|
526 | 1d14ffa9 | bellard | |
527 | 1d14ffa9 | bellard | case ES1370_REG_CONTROL:
|
528 | 1d14ffa9 | bellard | case ES1370_REG_CONTROL + 2: |
529 | 1d14ffa9 | bellard | shift = (addr != ES1370_REG_CONTROL) << 4;
|
530 | 1d14ffa9 | bellard | mask = 0xffff << shift;
|
531 | 1d14ffa9 | bellard | val = (s->ctl & ~mask) | ((val & 0xffff) << shift);
|
532 | 1d14ffa9 | bellard | es1370_update_voices (s, val, s->sctl); |
533 | 1d14ffa9 | bellard | print_ctl (val); |
534 | 1d14ffa9 | bellard | break;
|
535 | 1d14ffa9 | bellard | |
536 | 1d14ffa9 | bellard | case ES1370_REG_ADC_SCOUNT:
|
537 | 1d14ffa9 | bellard | d++; |
538 | 1d14ffa9 | bellard | case ES1370_REG_DAC2_SCOUNT:
|
539 | 1d14ffa9 | bellard | d++; |
540 | 1d14ffa9 | bellard | case ES1370_REG_DAC1_SCOUNT:
|
541 | 1d14ffa9 | bellard | d->scount = (d->scount & ~0xffff) | (val & 0xffff); |
542 | 1d14ffa9 | bellard | break;
|
543 | 1d14ffa9 | bellard | |
544 | 1d14ffa9 | bellard | default:
|
545 | 1d14ffa9 | bellard | lwarn ("writew %#x <- %#x\n", addr, val);
|
546 | 1d14ffa9 | bellard | break;
|
547 | 1d14ffa9 | bellard | } |
548 | 1d14ffa9 | bellard | } |
549 | 1d14ffa9 | bellard | |
550 | 1d14ffa9 | bellard | IO_WRITE_PROTO (es1370_writel) |
551 | 1d14ffa9 | bellard | { |
552 | 1d14ffa9 | bellard | ES1370State *s = opaque; |
553 | 1d14ffa9 | bellard | struct chan *d = &s->chan[0]; |
554 | 1d14ffa9 | bellard | |
555 | 1d14ffa9 | bellard | addr = es1370_fixup (s, addr); |
556 | 1d14ffa9 | bellard | |
557 | 1d14ffa9 | bellard | switch (addr) {
|
558 | 1d14ffa9 | bellard | case ES1370_REG_CONTROL:
|
559 | 1d14ffa9 | bellard | es1370_update_voices (s, val, s->sctl); |
560 | 1d14ffa9 | bellard | print_ctl (val); |
561 | 1d14ffa9 | bellard | break;
|
562 | 1d14ffa9 | bellard | |
563 | 1d14ffa9 | bellard | case ES1370_REG_MEMPAGE:
|
564 | 1d14ffa9 | bellard | s->mempage = val & 0xf;
|
565 | 1d14ffa9 | bellard | break;
|
566 | 1d14ffa9 | bellard | |
567 | 1d14ffa9 | bellard | case ES1370_REG_SERIAL_CONTROL:
|
568 | 1d14ffa9 | bellard | es1370_maybe_lower_irq (s, val); |
569 | 1d14ffa9 | bellard | es1370_update_voices (s, s->ctl, val); |
570 | 1d14ffa9 | bellard | print_sctl (val); |
571 | 1d14ffa9 | bellard | break;
|
572 | 1d14ffa9 | bellard | |
573 | 1d14ffa9 | bellard | case ES1370_REG_ADC_SCOUNT:
|
574 | 1d14ffa9 | bellard | d++; |
575 | 1d14ffa9 | bellard | case ES1370_REG_DAC2_SCOUNT:
|
576 | 1d14ffa9 | bellard | d++; |
577 | 1d14ffa9 | bellard | case ES1370_REG_DAC1_SCOUNT:
|
578 | 1d14ffa9 | bellard | d->scount = (val & 0xffff) | (d->scount & ~0xffff); |
579 | 1d14ffa9 | bellard | ldebug ("chan %d CURR_SAMP_CT %d, SAMP_CT %d\n",
|
580 | 1d14ffa9 | bellard | d - &s->chan[0], val >> 16, (val & 0xffff)); |
581 | 1d14ffa9 | bellard | break;
|
582 | 1d14ffa9 | bellard | |
583 | 1d14ffa9 | bellard | case ES1370_REG_ADC_FRAMEADR:
|
584 | 1d14ffa9 | bellard | d++; |
585 | 1d14ffa9 | bellard | case ES1370_REG_DAC2_FRAMEADR:
|
586 | 1d14ffa9 | bellard | d++; |
587 | 1d14ffa9 | bellard | case ES1370_REG_DAC1_FRAMEADR:
|
588 | 1d14ffa9 | bellard | d->frame_addr = val; |
589 | 1d14ffa9 | bellard | ldebug ("chan %d frame address %#x\n", d - &s->chan[0], val); |
590 | 1d14ffa9 | bellard | break;
|
591 | 1d14ffa9 | bellard | |
592 | 946fc947 | bellard | case ES1370_REG_PHANTOM_FRAMECNT:
|
593 | 946fc947 | bellard | lwarn ("writing to phantom frame count %#x\n", val);
|
594 | 946fc947 | bellard | break;
|
595 | 946fc947 | bellard | case ES1370_REG_PHANTOM_FRAMEADR:
|
596 | 946fc947 | bellard | lwarn ("writing to phantom frame address %#x\n", val);
|
597 | 946fc947 | bellard | break;
|
598 | 946fc947 | bellard | |
599 | 1d14ffa9 | bellard | case ES1370_REG_ADC_FRAMECNT:
|
600 | 1d14ffa9 | bellard | d++; |
601 | 1d14ffa9 | bellard | case ES1370_REG_DAC2_FRAMECNT:
|
602 | 1d14ffa9 | bellard | d++; |
603 | 1d14ffa9 | bellard | case ES1370_REG_DAC1_FRAMECNT:
|
604 | 1d14ffa9 | bellard | d->frame_cnt = val; |
605 | 1d14ffa9 | bellard | d->leftover = 0;
|
606 | 1d14ffa9 | bellard | ldebug ("chan %d frame count %d, buffer size %d\n",
|
607 | 1d14ffa9 | bellard | d - &s->chan[0], val >> 16, val & 0xffff); |
608 | 1d14ffa9 | bellard | break;
|
609 | 1d14ffa9 | bellard | |
610 | 1d14ffa9 | bellard | default:
|
611 | 1d14ffa9 | bellard | lwarn ("writel %#x <- %#x\n", addr, val);
|
612 | 1d14ffa9 | bellard | break;
|
613 | 1d14ffa9 | bellard | } |
614 | 1d14ffa9 | bellard | } |
615 | 1d14ffa9 | bellard | |
616 | 1d14ffa9 | bellard | IO_READ_PROTO (es1370_readb) |
617 | 1d14ffa9 | bellard | { |
618 | 1d14ffa9 | bellard | ES1370State *s = opaque; |
619 | 1d14ffa9 | bellard | uint32_t val; |
620 | 1d14ffa9 | bellard | |
621 | 1d14ffa9 | bellard | addr = es1370_fixup (s, addr); |
622 | 1d14ffa9 | bellard | |
623 | 1d14ffa9 | bellard | switch (addr) {
|
624 | 1d14ffa9 | bellard | case 0x1b: /* Legacy */ |
625 | 1d14ffa9 | bellard | lwarn ("Attempt to read from legacy register\n");
|
626 | 1d14ffa9 | bellard | val = 5;
|
627 | 1d14ffa9 | bellard | break;
|
628 | 1d14ffa9 | bellard | case ES1370_REG_MEMPAGE:
|
629 | 1d14ffa9 | bellard | val = s->mempage; |
630 | 1d14ffa9 | bellard | break;
|
631 | 1d14ffa9 | bellard | case ES1370_REG_CONTROL + 0: |
632 | 1d14ffa9 | bellard | case ES1370_REG_CONTROL + 1: |
633 | 1d14ffa9 | bellard | case ES1370_REG_CONTROL + 2: |
634 | 1d14ffa9 | bellard | case ES1370_REG_CONTROL + 3: |
635 | 1d14ffa9 | bellard | val = s->ctl >> ((addr - ES1370_REG_CONTROL) << 3);
|
636 | 1d14ffa9 | bellard | break;
|
637 | 1d14ffa9 | bellard | case ES1370_REG_STATUS + 0: |
638 | 1d14ffa9 | bellard | case ES1370_REG_STATUS + 1: |
639 | 1d14ffa9 | bellard | case ES1370_REG_STATUS + 2: |
640 | 1d14ffa9 | bellard | case ES1370_REG_STATUS + 3: |
641 | 1d14ffa9 | bellard | val = s->status >> ((addr - ES1370_REG_STATUS) << 3);
|
642 | 1d14ffa9 | bellard | break;
|
643 | 1d14ffa9 | bellard | default:
|
644 | 1d14ffa9 | bellard | val = ~0;
|
645 | 1d14ffa9 | bellard | lwarn ("readb %#x -> %#x\n", addr, val);
|
646 | 1d14ffa9 | bellard | break;
|
647 | 1d14ffa9 | bellard | } |
648 | 1d14ffa9 | bellard | return val;
|
649 | 1d14ffa9 | bellard | } |
650 | 1d14ffa9 | bellard | |
651 | 1d14ffa9 | bellard | IO_READ_PROTO (es1370_readw) |
652 | 1d14ffa9 | bellard | { |
653 | 1d14ffa9 | bellard | ES1370State *s = opaque; |
654 | 1d14ffa9 | bellard | struct chan *d = &s->chan[0]; |
655 | 1d14ffa9 | bellard | uint32_t val; |
656 | 1d14ffa9 | bellard | |
657 | 1d14ffa9 | bellard | addr = es1370_fixup (s, addr); |
658 | 1d14ffa9 | bellard | |
659 | 1d14ffa9 | bellard | switch (addr) {
|
660 | 1d14ffa9 | bellard | case ES1370_REG_ADC_SCOUNT + 2: |
661 | 1d14ffa9 | bellard | d++; |
662 | 1d14ffa9 | bellard | case ES1370_REG_DAC2_SCOUNT + 2: |
663 | 1d14ffa9 | bellard | d++; |
664 | 1d14ffa9 | bellard | case ES1370_REG_DAC1_SCOUNT + 2: |
665 | 1d14ffa9 | bellard | val = d->scount >> 16;
|
666 | 1d14ffa9 | bellard | break;
|
667 | 1d14ffa9 | bellard | |
668 | 946fc947 | bellard | case ES1370_REG_ADC_FRAMECNT:
|
669 | 946fc947 | bellard | d++; |
670 | 946fc947 | bellard | case ES1370_REG_DAC2_FRAMECNT:
|
671 | 946fc947 | bellard | d++; |
672 | 946fc947 | bellard | case ES1370_REG_DAC1_FRAMECNT:
|
673 | 946fc947 | bellard | val = d->frame_cnt & 0xffff;
|
674 | 946fc947 | bellard | break;
|
675 | 946fc947 | bellard | |
676 | 946fc947 | bellard | case ES1370_REG_ADC_FRAMECNT + 2: |
677 | 946fc947 | bellard | d++; |
678 | 946fc947 | bellard | case ES1370_REG_DAC2_FRAMECNT + 2: |
679 | 946fc947 | bellard | d++; |
680 | 946fc947 | bellard | case ES1370_REG_DAC1_FRAMECNT + 2: |
681 | 946fc947 | bellard | val = d->frame_cnt >> 16;
|
682 | 946fc947 | bellard | break;
|
683 | 946fc947 | bellard | |
684 | 1d14ffa9 | bellard | default:
|
685 | 1d14ffa9 | bellard | val = ~0;
|
686 | 1d14ffa9 | bellard | lwarn ("readw %#x -> %#x\n", addr, val);
|
687 | 1d14ffa9 | bellard | break;
|
688 | 1d14ffa9 | bellard | } |
689 | 1d14ffa9 | bellard | |
690 | 1d14ffa9 | bellard | return val;
|
691 | 1d14ffa9 | bellard | } |
692 | 1d14ffa9 | bellard | |
693 | 1d14ffa9 | bellard | IO_READ_PROTO (es1370_readl) |
694 | 1d14ffa9 | bellard | { |
695 | 1d14ffa9 | bellard | ES1370State *s = opaque; |
696 | 1d14ffa9 | bellard | uint32_t val; |
697 | 1d14ffa9 | bellard | struct chan *d = &s->chan[0]; |
698 | 1d14ffa9 | bellard | |
699 | 1d14ffa9 | bellard | addr = es1370_fixup (s, addr); |
700 | 1d14ffa9 | bellard | |
701 | 1d14ffa9 | bellard | switch (addr) {
|
702 | 1d14ffa9 | bellard | case ES1370_REG_CONTROL:
|
703 | 1d14ffa9 | bellard | val = s->ctl; |
704 | 1d14ffa9 | bellard | break;
|
705 | 1d14ffa9 | bellard | case ES1370_REG_STATUS:
|
706 | 1d14ffa9 | bellard | val = s->status; |
707 | 1d14ffa9 | bellard | break;
|
708 | 1d14ffa9 | bellard | case ES1370_REG_MEMPAGE:
|
709 | 1d14ffa9 | bellard | val = s->mempage; |
710 | 1d14ffa9 | bellard | break;
|
711 | 1d14ffa9 | bellard | case ES1370_REG_CODEC:
|
712 | 1d14ffa9 | bellard | val = s->codec; |
713 | 1d14ffa9 | bellard | break;
|
714 | 1d14ffa9 | bellard | case ES1370_REG_SERIAL_CONTROL:
|
715 | 1d14ffa9 | bellard | val = s->sctl; |
716 | 1d14ffa9 | bellard | break;
|
717 | 1d14ffa9 | bellard | |
718 | 1d14ffa9 | bellard | case ES1370_REG_ADC_SCOUNT:
|
719 | 1d14ffa9 | bellard | d++; |
720 | 1d14ffa9 | bellard | case ES1370_REG_DAC2_SCOUNT:
|
721 | 1d14ffa9 | bellard | d++; |
722 | 1d14ffa9 | bellard | case ES1370_REG_DAC1_SCOUNT:
|
723 | 1d14ffa9 | bellard | val = d->scount; |
724 | 1d14ffa9 | bellard | #ifdef DEBUG_ES1370
|
725 | 1d14ffa9 | bellard | { |
726 | 1d14ffa9 | bellard | uint32_t curr_count = d->scount >> 16;
|
727 | 1d14ffa9 | bellard | uint32_t count = d->scount & 0xffff;
|
728 | 1d14ffa9 | bellard | |
729 | 1d14ffa9 | bellard | curr_count <<= d->shift; |
730 | 1d14ffa9 | bellard | count <<= d->shift; |
731 | 1d14ffa9 | bellard | dolog ("read scount curr %d, total %d\n", curr_count, count);
|
732 | 1d14ffa9 | bellard | } |
733 | 1d14ffa9 | bellard | #endif
|
734 | 1d14ffa9 | bellard | break;
|
735 | 1d14ffa9 | bellard | |
736 | 1d14ffa9 | bellard | case ES1370_REG_ADC_FRAMECNT:
|
737 | 1d14ffa9 | bellard | d++; |
738 | 1d14ffa9 | bellard | case ES1370_REG_DAC2_FRAMECNT:
|
739 | 1d14ffa9 | bellard | d++; |
740 | 1d14ffa9 | bellard | case ES1370_REG_DAC1_FRAMECNT:
|
741 | 1d14ffa9 | bellard | val = d->frame_cnt; |
742 | 1d14ffa9 | bellard | #ifdef DEBUG_ES1370
|
743 | 1d14ffa9 | bellard | { |
744 | 1d14ffa9 | bellard | uint32_t size = ((d->frame_cnt & 0xffff) + 1) << 2; |
745 | 1d14ffa9 | bellard | uint32_t curr = ((d->frame_cnt >> 16) + 1) << 2; |
746 | 1d14ffa9 | bellard | if (curr > size)
|
747 | 1d14ffa9 | bellard | dolog ("read framecnt curr %d, size %d %d\n", curr, size,
|
748 | 1d14ffa9 | bellard | curr > size); |
749 | 1d14ffa9 | bellard | } |
750 | 1d14ffa9 | bellard | #endif
|
751 | 1d14ffa9 | bellard | break;
|
752 | 1d14ffa9 | bellard | |
753 | 1d14ffa9 | bellard | case ES1370_REG_ADC_FRAMEADR:
|
754 | 1d14ffa9 | bellard | d++; |
755 | 1d14ffa9 | bellard | case ES1370_REG_DAC2_FRAMEADR:
|
756 | 1d14ffa9 | bellard | d++; |
757 | 1d14ffa9 | bellard | case ES1370_REG_DAC1_FRAMEADR:
|
758 | 1d14ffa9 | bellard | val = d->frame_addr; |
759 | 1d14ffa9 | bellard | break;
|
760 | 1d14ffa9 | bellard | |
761 | 946fc947 | bellard | case ES1370_REG_PHANTOM_FRAMECNT:
|
762 | 946fc947 | bellard | val = ~0U;
|
763 | 946fc947 | bellard | lwarn ("reading from phantom frame count\n");
|
764 | 946fc947 | bellard | break;
|
765 | 946fc947 | bellard | case ES1370_REG_PHANTOM_FRAMEADR:
|
766 | 946fc947 | bellard | val = ~0U;
|
767 | 946fc947 | bellard | lwarn ("reading from phantom frame address\n");
|
768 | 946fc947 | bellard | break;
|
769 | 946fc947 | bellard | |
770 | 1d14ffa9 | bellard | default:
|
771 | 1d14ffa9 | bellard | val = ~0U;
|
772 | 1d14ffa9 | bellard | lwarn ("readl %#x -> %#x\n", addr, val);
|
773 | 1d14ffa9 | bellard | break;
|
774 | 1d14ffa9 | bellard | } |
775 | 1d14ffa9 | bellard | return val;
|
776 | 1d14ffa9 | bellard | } |
777 | 1d14ffa9 | bellard | |
778 | 1d14ffa9 | bellard | |
779 | 1d14ffa9 | bellard | static void es1370_transfer_audio (ES1370State *s, struct chan *d, int loop_sel, |
780 | 1d14ffa9 | bellard | int max, int *irq) |
781 | 1d14ffa9 | bellard | { |
782 | 1d14ffa9 | bellard | uint8_t tmpbuf[4096];
|
783 | 1d14ffa9 | bellard | uint32_t addr = d->frame_addr; |
784 | 1d14ffa9 | bellard | int sc = d->scount & 0xffff; |
785 | 1d14ffa9 | bellard | int csc = d->scount >> 16; |
786 | 1d14ffa9 | bellard | int csc_bytes = (csc + 1) << d->shift; |
787 | 1d14ffa9 | bellard | int cnt = d->frame_cnt >> 16; |
788 | 1d14ffa9 | bellard | int size = d->frame_cnt & 0xffff; |
789 | 1d14ffa9 | bellard | int left = ((size - cnt + 1) << 2) + d->leftover; |
790 | 1d14ffa9 | bellard | int transfered = 0; |
791 | 1d14ffa9 | bellard | int temp = audio_MIN (max, audio_MIN (left, csc_bytes));
|
792 | 1d14ffa9 | bellard | int index = d - &s->chan[0]; |
793 | 1d14ffa9 | bellard | |
794 | 1d14ffa9 | bellard | addr += (cnt << 2) + d->leftover;
|
795 | 1d14ffa9 | bellard | |
796 | 1d14ffa9 | bellard | if (index == ADC_CHANNEL) {
|
797 | 1d14ffa9 | bellard | while (temp) {
|
798 | 1d14ffa9 | bellard | int acquired, to_copy;
|
799 | 1d14ffa9 | bellard | |
800 | c0fe3827 | bellard | to_copy = audio_MIN ((size_t) temp, sizeof (tmpbuf));
|
801 | 1d14ffa9 | bellard | acquired = AUD_read (s->adc_voice, tmpbuf, to_copy); |
802 | 1d14ffa9 | bellard | if (!acquired)
|
803 | 1d14ffa9 | bellard | break;
|
804 | 1d14ffa9 | bellard | |
805 | 1d14ffa9 | bellard | cpu_physical_memory_write (addr, tmpbuf, acquired); |
806 | 1d14ffa9 | bellard | |
807 | 1d14ffa9 | bellard | temp -= acquired; |
808 | 1d14ffa9 | bellard | addr += acquired; |
809 | 1d14ffa9 | bellard | transfered += acquired; |
810 | 1d14ffa9 | bellard | } |
811 | 1d14ffa9 | bellard | } |
812 | 1d14ffa9 | bellard | else {
|
813 | 1d14ffa9 | bellard | SWVoiceOut *voice = s->dac_voice[index]; |
814 | 1d14ffa9 | bellard | |
815 | 1d14ffa9 | bellard | while (temp) {
|
816 | 1d14ffa9 | bellard | int copied, to_copy;
|
817 | 1d14ffa9 | bellard | |
818 | c0fe3827 | bellard | to_copy = audio_MIN ((size_t) temp, sizeof (tmpbuf));
|
819 | 1d14ffa9 | bellard | cpu_physical_memory_read (addr, tmpbuf, to_copy); |
820 | 1d14ffa9 | bellard | copied = AUD_write (voice, tmpbuf, to_copy); |
821 | 1d14ffa9 | bellard | if (!copied)
|
822 | 1d14ffa9 | bellard | break;
|
823 | 1d14ffa9 | bellard | temp -= copied; |
824 | 1d14ffa9 | bellard | addr += copied; |
825 | 1d14ffa9 | bellard | transfered += copied; |
826 | 1d14ffa9 | bellard | } |
827 | 1d14ffa9 | bellard | } |
828 | 1d14ffa9 | bellard | |
829 | 1d14ffa9 | bellard | if (csc_bytes == transfered) {
|
830 | 1d14ffa9 | bellard | *irq = 1;
|
831 | 1d14ffa9 | bellard | d->scount = sc | (sc << 16);
|
832 | 1d14ffa9 | bellard | ldebug ("sc = %d, rate = %f\n",
|
833 | 1d14ffa9 | bellard | (sc + 1) << d->shift,
|
834 | 1d14ffa9 | bellard | (sc + 1) / (double) 44100); |
835 | 1d14ffa9 | bellard | } |
836 | 1d14ffa9 | bellard | else {
|
837 | 1d14ffa9 | bellard | *irq = 0;
|
838 | 1d14ffa9 | bellard | d->scount = sc | (((csc_bytes - transfered - 1) >> d->shift) << 16); |
839 | 1d14ffa9 | bellard | } |
840 | 1d14ffa9 | bellard | |
841 | 1d14ffa9 | bellard | cnt += (transfered + d->leftover) >> 2;
|
842 | 1d14ffa9 | bellard | |
843 | 1d14ffa9 | bellard | if (s->sctl & loop_sel) {
|
844 | 1d14ffa9 | bellard | /* Bah, how stupid is that having a 0 represent true value?
|
845 | 1d14ffa9 | bellard | i just spent few hours on this shit */
|
846 | 946fc947 | bellard | AUD_log ("es1370: warning", "non looping mode\n"); |
847 | 1d14ffa9 | bellard | } |
848 | 1d14ffa9 | bellard | else {
|
849 | 1d14ffa9 | bellard | d->frame_cnt = size; |
850 | 1d14ffa9 | bellard | |
851 | c0fe3827 | bellard | if ((uint32_t) cnt <= d->frame_cnt)
|
852 | 1d14ffa9 | bellard | d->frame_cnt |= cnt << 16;
|
853 | 1d14ffa9 | bellard | } |
854 | 1d14ffa9 | bellard | |
855 | 1d14ffa9 | bellard | d->leftover = (transfered + d->leftover) & 3;
|
856 | 1d14ffa9 | bellard | } |
857 | 1d14ffa9 | bellard | |
858 | 1d14ffa9 | bellard | static void es1370_run_channel (ES1370State *s, size_t chan, int free_or_avail) |
859 | 1d14ffa9 | bellard | { |
860 | 1d14ffa9 | bellard | uint32_t new_status = s->status; |
861 | 1d14ffa9 | bellard | int max_bytes, irq;
|
862 | 1d14ffa9 | bellard | struct chan *d = &s->chan[chan];
|
863 | 1d14ffa9 | bellard | const struct chan_bits *b = &es1370_chan_bits[chan]; |
864 | 1d14ffa9 | bellard | |
865 | 1d14ffa9 | bellard | if (!(s->ctl & b->ctl_en) || (s->sctl & b->sctl_pause)) {
|
866 | 1d14ffa9 | bellard | return;
|
867 | 1d14ffa9 | bellard | } |
868 | 1d14ffa9 | bellard | |
869 | 1d14ffa9 | bellard | max_bytes = free_or_avail; |
870 | 1d14ffa9 | bellard | max_bytes &= ~((1 << d->shift) - 1); |
871 | 1d14ffa9 | bellard | if (!max_bytes) {
|
872 | 1d14ffa9 | bellard | return;
|
873 | 1d14ffa9 | bellard | } |
874 | 1d14ffa9 | bellard | |
875 | 1d14ffa9 | bellard | es1370_transfer_audio (s, d, b->sctl_loopsel, max_bytes, &irq); |
876 | 1d14ffa9 | bellard | |
877 | 1d14ffa9 | bellard | if (irq) {
|
878 | 1d14ffa9 | bellard | if (s->sctl & b->sctl_inten) {
|
879 | 1d14ffa9 | bellard | new_status |= b->stat_int; |
880 | 1d14ffa9 | bellard | } |
881 | 1d14ffa9 | bellard | } |
882 | 1d14ffa9 | bellard | |
883 | 1d14ffa9 | bellard | if (new_status != s->status) {
|
884 | 1d14ffa9 | bellard | es1370_update_status (s, new_status); |
885 | 1d14ffa9 | bellard | } |
886 | 1d14ffa9 | bellard | } |
887 | 1d14ffa9 | bellard | |
888 | 1d14ffa9 | bellard | static void es1370_dac1_callback (void *opaque, int free) |
889 | 1d14ffa9 | bellard | { |
890 | 1d14ffa9 | bellard | ES1370State *s = opaque; |
891 | 1d14ffa9 | bellard | |
892 | 1d14ffa9 | bellard | es1370_run_channel (s, DAC1_CHANNEL, free); |
893 | 1d14ffa9 | bellard | } |
894 | 1d14ffa9 | bellard | |
895 | 1d14ffa9 | bellard | static void es1370_dac2_callback (void *opaque, int free) |
896 | 1d14ffa9 | bellard | { |
897 | 1d14ffa9 | bellard | ES1370State *s = opaque; |
898 | 1d14ffa9 | bellard | |
899 | 1d14ffa9 | bellard | es1370_run_channel (s, DAC2_CHANNEL, free); |
900 | 1d14ffa9 | bellard | } |
901 | 1d14ffa9 | bellard | |
902 | 1d14ffa9 | bellard | static void es1370_adc_callback (void *opaque, int avail) |
903 | 1d14ffa9 | bellard | { |
904 | 1d14ffa9 | bellard | ES1370State *s = opaque; |
905 | 1d14ffa9 | bellard | |
906 | 1d14ffa9 | bellard | es1370_run_channel (s, ADC_CHANNEL, avail); |
907 | 1d14ffa9 | bellard | } |
908 | 1d14ffa9 | bellard | |
909 | 1d14ffa9 | bellard | static void es1370_map (PCIDevice *pci_dev, int region_num, |
910 | 6e355d90 | Isaku Yamahata | pcibus_t addr, pcibus_t size, int type)
|
911 | 1d14ffa9 | bellard | { |
912 | b6f6d0e2 | malc | ES1370State *s = DO_UPCAST (ES1370State, dev, pci_dev); |
913 | 1d14ffa9 | bellard | |
914 | c0fe3827 | bellard | (void) region_num;
|
915 | c0fe3827 | bellard | (void) size;
|
916 | c0fe3827 | bellard | (void) type;
|
917 | c0fe3827 | bellard | |
918 | 1d14ffa9 | bellard | register_ioport_write (addr, 0x40 * 4, 1, es1370_writeb, s); |
919 | 1d14ffa9 | bellard | register_ioport_write (addr, 0x40 * 2, 2, es1370_writew, s); |
920 | 1d14ffa9 | bellard | register_ioport_write (addr, 0x40, 4, es1370_writel, s); |
921 | 1d14ffa9 | bellard | |
922 | 1d14ffa9 | bellard | register_ioport_read (addr, 0x40 * 4, 1, es1370_readb, s); |
923 | 1d14ffa9 | bellard | register_ioport_read (addr, 0x40 * 2, 2, es1370_readw, s); |
924 | 1d14ffa9 | bellard | register_ioport_read (addr, 0x40, 4, es1370_readl, s); |
925 | 1d14ffa9 | bellard | } |
926 | 1d14ffa9 | bellard | |
927 | 3a14c2df | Juan Quintela | static const VMStateDescription vmstate_es1370_channel = { |
928 | 3a14c2df | Juan Quintela | .name = "es1370_channel",
|
929 | 3a14c2df | Juan Quintela | .version_id = 2,
|
930 | 3a14c2df | Juan Quintela | .minimum_version_id = 2,
|
931 | 3a14c2df | Juan Quintela | .minimum_version_id_old = 2,
|
932 | 3a14c2df | Juan Quintela | .fields = (VMStateField []) { |
933 | 3a14c2df | Juan Quintela | VMSTATE_UINT32(shift, struct chan),
|
934 | 3a14c2df | Juan Quintela | VMSTATE_UINT32(leftover, struct chan),
|
935 | 3a14c2df | Juan Quintela | VMSTATE_UINT32(scount, struct chan),
|
936 | 3a14c2df | Juan Quintela | VMSTATE_UINT32(frame_addr, struct chan),
|
937 | 3a14c2df | Juan Quintela | VMSTATE_UINT32(frame_cnt, struct chan),
|
938 | 3a14c2df | Juan Quintela | VMSTATE_END_OF_LIST() |
939 | 1d14ffa9 | bellard | } |
940 | 3a14c2df | Juan Quintela | }; |
941 | 1d14ffa9 | bellard | |
942 | 3a14c2df | Juan Quintela | static int es1370_post_load (void *opaque, int version_id) |
943 | 1d14ffa9 | bellard | { |
944 | 1d14ffa9 | bellard | uint32_t ctl, sctl; |
945 | 1d14ffa9 | bellard | ES1370State *s = opaque; |
946 | 1d14ffa9 | bellard | size_t i; |
947 | 1d14ffa9 | bellard | |
948 | 1d14ffa9 | bellard | for (i = 0; i < NB_CHANNELS; ++i) { |
949 | 1d14ffa9 | bellard | if (i == ADC_CHANNEL) {
|
950 | 1d14ffa9 | bellard | if (s->adc_voice) {
|
951 | c0fe3827 | bellard | AUD_close_in (&s->card, s->adc_voice); |
952 | 1d14ffa9 | bellard | s->adc_voice = NULL;
|
953 | 1d14ffa9 | bellard | } |
954 | 1d14ffa9 | bellard | } |
955 | 1d14ffa9 | bellard | else {
|
956 | 1d14ffa9 | bellard | if (s->dac_voice[i]) {
|
957 | c0fe3827 | bellard | AUD_close_out (&s->card, s->dac_voice[i]); |
958 | 1d14ffa9 | bellard | s->dac_voice[i] = NULL;
|
959 | 1d14ffa9 | bellard | } |
960 | 1d14ffa9 | bellard | } |
961 | 1d14ffa9 | bellard | } |
962 | 1d14ffa9 | bellard | |
963 | 3a14c2df | Juan Quintela | ctl = s->ctl; |
964 | 3a14c2df | Juan Quintela | sctl = s->sctl; |
965 | 1d14ffa9 | bellard | s->ctl = 0;
|
966 | 1d14ffa9 | bellard | s->sctl = 0;
|
967 | 1d14ffa9 | bellard | es1370_update_voices (s, ctl, sctl); |
968 | 1d14ffa9 | bellard | return 0; |
969 | 1d14ffa9 | bellard | } |
970 | 1d14ffa9 | bellard | |
971 | 3a14c2df | Juan Quintela | static const VMStateDescription vmstate_es1370 = { |
972 | 3a14c2df | Juan Quintela | .name = "es1370",
|
973 | 3a14c2df | Juan Quintela | .version_id = 2,
|
974 | 3a14c2df | Juan Quintela | .minimum_version_id = 2,
|
975 | 3a14c2df | Juan Quintela | .minimum_version_id_old = 2,
|
976 | 3a14c2df | Juan Quintela | .post_load = es1370_post_load, |
977 | 3a14c2df | Juan Quintela | .fields = (VMStateField []) { |
978 | 3a14c2df | Juan Quintela | VMSTATE_PCI_DEVICE(dev, ES1370State), |
979 | 3a14c2df | Juan Quintela | VMSTATE_STRUCT_ARRAY(chan, ES1370State, NB_CHANNELS, 2,
|
980 | 3a14c2df | Juan Quintela | vmstate_es1370_channel, struct chan),
|
981 | 3a14c2df | Juan Quintela | VMSTATE_UINT32(ctl, ES1370State), |
982 | 3a14c2df | Juan Quintela | VMSTATE_UINT32(status, ES1370State), |
983 | 3a14c2df | Juan Quintela | VMSTATE_UINT32(mempage, ES1370State), |
984 | 3a14c2df | Juan Quintela | VMSTATE_UINT32(codec, ES1370State), |
985 | 3a14c2df | Juan Quintela | VMSTATE_UINT32(sctl, ES1370State), |
986 | 3a14c2df | Juan Quintela | VMSTATE_END_OF_LIST() |
987 | 3a14c2df | Juan Quintela | } |
988 | 3a14c2df | Juan Quintela | }; |
989 | 3a14c2df | Juan Quintela | |
990 | 1d14ffa9 | bellard | static void es1370_on_reset (void *opaque) |
991 | 1d14ffa9 | bellard | { |
992 | 1d14ffa9 | bellard | ES1370State *s = opaque; |
993 | 1d14ffa9 | bellard | es1370_reset (s); |
994 | 1d14ffa9 | bellard | } |
995 | 1d14ffa9 | bellard | |
996 | 81a322d4 | Gerd Hoffmann | static int es1370_initfn (PCIDevice *dev) |
997 | 1d14ffa9 | bellard | { |
998 | b6f6d0e2 | malc | ES1370State *s = DO_UPCAST (ES1370State, dev, dev); |
999 | e5944641 | Juan Quintela | uint8_t *c = s->dev.config; |
1000 | 1d14ffa9 | bellard | |
1001 | d999f7e0 | malc | pci_config_set_vendor_id (c, PCI_VENDOR_ID_ENSONIQ); |
1002 | d999f7e0 | malc | pci_config_set_device_id (c, PCI_DEVICE_ID_ENSONIQ_ES1370); |
1003 | 1d14ffa9 | bellard | c[0x07] = 2 << 1; |
1004 | d999f7e0 | malc | pci_config_set_class (c, PCI_CLASS_MULTIMEDIA_AUDIO); |
1005 | 1d14ffa9 | bellard | |
1006 | 1d14ffa9 | bellard | #if 1 |
1007 | 1d14ffa9 | bellard | c[0x2c] = 0x42; |
1008 | 1d14ffa9 | bellard | c[0x2d] = 0x49; |
1009 | 1d14ffa9 | bellard | c[0x2e] = 0x4c; |
1010 | 1d14ffa9 | bellard | c[0x2f] = 0x4c; |
1011 | 1d14ffa9 | bellard | #else
|
1012 | 1d14ffa9 | bellard | c[0x2c] = 0x74; |
1013 | 1d14ffa9 | bellard | c[0x2d] = 0x12; |
1014 | 1d14ffa9 | bellard | c[0x2e] = 0x71; |
1015 | 1d14ffa9 | bellard | c[0x2f] = 0x13; |
1016 | 1d14ffa9 | bellard | c[0x34] = 0xdc; |
1017 | 1d14ffa9 | bellard | c[0x3c] = 10; |
1018 | 1d14ffa9 | bellard | c[0xdc] = 0x00; |
1019 | 1d14ffa9 | bellard | #endif
|
1020 | 1d14ffa9 | bellard | |
1021 | 1d14ffa9 | bellard | c[0x3d] = 1; |
1022 | 1d14ffa9 | bellard | c[0x3e] = 0x0c; |
1023 | 1d14ffa9 | bellard | c[0x3f] = 0x80; |
1024 | 1d14ffa9 | bellard | |
1025 | 0392a017 | Isaku Yamahata | pci_register_bar (&s->dev, 0, 256, PCI_BASE_ADDRESS_SPACE_IO, es1370_map); |
1026 | 3a14c2df | Juan Quintela | vmstate_register (0, &vmstate_es1370, s);
|
1027 | a08d4367 | Jan Kiszka | qemu_register_reset (es1370_on_reset, s); |
1028 | c0fe3827 | bellard | |
1029 | 1a7dafce | malc | AUD_register_card ("es1370", &s->card);
|
1030 | 1d14ffa9 | bellard | es1370_reset (s); |
1031 | 81a322d4 | Gerd Hoffmann | return 0; |
1032 | 6806e595 | Gerd Hoffmann | } |
1033 | 6806e595 | Gerd Hoffmann | |
1034 | 6806e595 | Gerd Hoffmann | int es1370_init (PCIBus *bus)
|
1035 | 6806e595 | Gerd Hoffmann | { |
1036 | b6f6d0e2 | malc | pci_create_simple (bus, -1, "ES1370"); |
1037 | 1d14ffa9 | bellard | return 0; |
1038 | 1d14ffa9 | bellard | } |
1039 | 6806e595 | Gerd Hoffmann | |
1040 | 6806e595 | Gerd Hoffmann | static PCIDeviceInfo es1370_info = {
|
1041 | 6806e595 | Gerd Hoffmann | .qdev.name = "ES1370",
|
1042 | f3519986 | Gerd Hoffmann | .qdev.desc = "ENSONIQ AudioPCI ES1370",
|
1043 | e5944641 | Juan Quintela | .qdev.size = sizeof (ES1370State),
|
1044 | 6806e595 | Gerd Hoffmann | .init = es1370_initfn, |
1045 | 6806e595 | Gerd Hoffmann | }; |
1046 | 6806e595 | Gerd Hoffmann | |
1047 | b6f6d0e2 | malc | static void es1370_register (void) |
1048 | 6806e595 | Gerd Hoffmann | { |
1049 | 0c3271c5 | Anthony Liguori | pci_qdev_register (&es1370_info); |
1050 | 6806e595 | Gerd Hoffmann | } |
1051 | 0c3271c5 | Anthony Liguori | device_init (es1370_register); |