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