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