root / hw / tsc210x.c @ cda9046b
History | View | Annotate | Download (33.8 kB)
1 | 3efda49d | balrog | /*
|
---|---|---|---|
2 | 7fc42b4b | balrog | * TI TSC2102 (touchscreen/sensors/audio controller) emulator.
|
3 | a5d7eb65 | balrog | * TI TSC2301 (touchscreen/sensors/keypad).
|
4 | 3efda49d | balrog | *
|
5 | 3efda49d | balrog | * Copyright (c) 2006 Andrzej Zaborowski <balrog@zabor.org>
|
6 | a5d7eb65 | balrog | * Copyright (C) 2008 Nokia Corporation
|
7 | 3efda49d | balrog | *
|
8 | 3efda49d | balrog | * This program is free software; you can redistribute it and/or
|
9 | 3efda49d | balrog | * modify it under the terms of the GNU General Public License as
|
10 | a5d7eb65 | balrog | * published by the Free Software Foundation; either version 2 or
|
11 | a5d7eb65 | balrog | * (at your option) version 3 of the License.
|
12 | 3efda49d | balrog | *
|
13 | 3efda49d | balrog | * This program is distributed in the hope that it will be useful,
|
14 | 3efda49d | balrog | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 | 3efda49d | balrog | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 | 3efda49d | balrog | * GNU General Public License for more details.
|
17 | 3efda49d | balrog | *
|
18 | fad6cb1a | aurel32 | * You should have received a copy of the GNU General Public License along
|
19 | fad6cb1a | aurel32 | * with this program; if not, write to the Free Software Foundation, Inc.,
|
20 | fad6cb1a | aurel32 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
21 | 3efda49d | balrog | */
|
22 | 3efda49d | balrog | |
23 | 87ecb68b | pbrook | #include "hw.h" |
24 | 87ecb68b | pbrook | #include "audio/audio.h" |
25 | 87ecb68b | pbrook | #include "qemu-timer.h" |
26 | 87ecb68b | pbrook | #include "console.h" |
27 | bc24a225 | Paul Brook | #include "omap.h" /* For I2SCodec and uWireSlave */ |
28 | b1d8e52e | blueswir1 | #include "devices.h" |
29 | 3efda49d | balrog | |
30 | 3efda49d | balrog | #define TSC_DATA_REGISTERS_PAGE 0x0 |
31 | 3efda49d | balrog | #define TSC_CONTROL_REGISTERS_PAGE 0x1 |
32 | 3efda49d | balrog | #define TSC_AUDIO_REGISTERS_PAGE 0x2 |
33 | 3efda49d | balrog | |
34 | 3efda49d | balrog | #define TSC_VERBOSE
|
35 | 3efda49d | balrog | |
36 | 3efda49d | balrog | #define TSC_CUT_RESOLUTION(value, p) ((value) >> (16 - resolution[p])) |
37 | 3efda49d | balrog | |
38 | bc24a225 | Paul Brook | typedef struct { |
39 | 3efda49d | balrog | qemu_irq pint; |
40 | a5d7eb65 | balrog | qemu_irq kbint; |
41 | a5d7eb65 | balrog | qemu_irq davint; |
42 | 3efda49d | balrog | QEMUTimer *timer; |
43 | d8f699cb | balrog | QEMUSoundCard card; |
44 | bc24a225 | Paul Brook | uWireSlave chip; |
45 | bc24a225 | Paul Brook | I2SCodec codec; |
46 | d8f699cb | balrog | uint8_t in_fifo[16384];
|
47 | d8f699cb | balrog | uint8_t out_fifo[16384];
|
48 | a5d7eb65 | balrog | uint16_t model; |
49 | 3efda49d | balrog | |
50 | 3efda49d | balrog | int x, y;
|
51 | 3efda49d | balrog | int pressure;
|
52 | 3efda49d | balrog | |
53 | 3efda49d | balrog | int state, page, offset, irq;
|
54 | 3efda49d | balrog | uint16_t command, dav; |
55 | 3efda49d | balrog | |
56 | 3efda49d | balrog | int busy;
|
57 | 3efda49d | balrog | int enabled;
|
58 | 3efda49d | balrog | int host_mode;
|
59 | 3efda49d | balrog | int function;
|
60 | 3efda49d | balrog | int nextfunction;
|
61 | 3efda49d | balrog | int precision;
|
62 | 3efda49d | balrog | int nextprecision;
|
63 | 3efda49d | balrog | int filter;
|
64 | 3efda49d | balrog | int pin_func;
|
65 | 3efda49d | balrog | int ref;
|
66 | 3efda49d | balrog | int timing;
|
67 | 3efda49d | balrog | int noise;
|
68 | 3efda49d | balrog | |
69 | 3efda49d | balrog | uint16_t audio_ctrl1; |
70 | 3efda49d | balrog | uint16_t audio_ctrl2; |
71 | 3efda49d | balrog | uint16_t audio_ctrl3; |
72 | a5d7eb65 | balrog | uint16_t pll[3];
|
73 | 3efda49d | balrog | uint16_t volume; |
74 | 3efda49d | balrog | int64_t volume_change; |
75 | 3efda49d | balrog | int softstep;
|
76 | 3efda49d | balrog | uint16_t dac_power; |
77 | 3efda49d | balrog | int64_t powerdown; |
78 | 3efda49d | balrog | uint16_t filter_data[0x14];
|
79 | d8f699cb | balrog | |
80 | d8f699cb | balrog | const char *name; |
81 | d8f699cb | balrog | SWVoiceIn *adc_voice[1];
|
82 | d8f699cb | balrog | SWVoiceOut *dac_voice[1];
|
83 | d8f699cb | balrog | int i2s_rx_rate;
|
84 | d8f699cb | balrog | int i2s_tx_rate;
|
85 | a5d7eb65 | balrog | |
86 | a5d7eb65 | balrog | int tr[8]; |
87 | a5d7eb65 | balrog | |
88 | a5d7eb65 | balrog | struct {
|
89 | a5d7eb65 | balrog | uint16_t down; |
90 | a5d7eb65 | balrog | uint16_t mask; |
91 | a5d7eb65 | balrog | int scan;
|
92 | a5d7eb65 | balrog | int debounce;
|
93 | a5d7eb65 | balrog | int mode;
|
94 | a5d7eb65 | balrog | int intr;
|
95 | a5d7eb65 | balrog | } kb; |
96 | bc24a225 | Paul Brook | } TSC210xState; |
97 | 3efda49d | balrog | |
98 | 3efda49d | balrog | static const int resolution[4] = { 12, 8, 10, 12 }; |
99 | 3efda49d | balrog | |
100 | 3efda49d | balrog | #define TSC_MODE_NO_SCAN 0x0 |
101 | 3efda49d | balrog | #define TSC_MODE_XY_SCAN 0x1 |
102 | 3efda49d | balrog | #define TSC_MODE_XYZ_SCAN 0x2 |
103 | 3efda49d | balrog | #define TSC_MODE_X 0x3 |
104 | 3efda49d | balrog | #define TSC_MODE_Y 0x4 |
105 | 3efda49d | balrog | #define TSC_MODE_Z 0x5 |
106 | 3efda49d | balrog | #define TSC_MODE_BAT1 0x6 |
107 | 3efda49d | balrog | #define TSC_MODE_BAT2 0x7 |
108 | 3efda49d | balrog | #define TSC_MODE_AUX 0x8 |
109 | 3efda49d | balrog | #define TSC_MODE_AUX_SCAN 0x9 |
110 | 3efda49d | balrog | #define TSC_MODE_TEMP1 0xa |
111 | 3efda49d | balrog | #define TSC_MODE_PORT_SCAN 0xb |
112 | 3efda49d | balrog | #define TSC_MODE_TEMP2 0xc |
113 | 3efda49d | balrog | #define TSC_MODE_XX_DRV 0xd |
114 | 3efda49d | balrog | #define TSC_MODE_YY_DRV 0xe |
115 | 3efda49d | balrog | #define TSC_MODE_YX_DRV 0xf |
116 | 3efda49d | balrog | |
117 | 3efda49d | balrog | static const uint16_t mode_regs[16] = { |
118 | 3efda49d | balrog | 0x0000, /* No scan */ |
119 | 3efda49d | balrog | 0x0600, /* X, Y scan */ |
120 | 3efda49d | balrog | 0x0780, /* X, Y, Z scan */ |
121 | 3efda49d | balrog | 0x0400, /* X */ |
122 | 3efda49d | balrog | 0x0200, /* Y */ |
123 | 3efda49d | balrog | 0x0180, /* Z */ |
124 | 3efda49d | balrog | 0x0040, /* BAT1 */ |
125 | 3efda49d | balrog | 0x0030, /* BAT2 */ |
126 | 3efda49d | balrog | 0x0010, /* AUX */ |
127 | 3efda49d | balrog | 0x0010, /* AUX scan */ |
128 | 3efda49d | balrog | 0x0004, /* TEMP1 */ |
129 | 3efda49d | balrog | 0x0070, /* Port scan */ |
130 | 3efda49d | balrog | 0x0002, /* TEMP2 */ |
131 | 3efda49d | balrog | 0x0000, /* X+, X- drivers */ |
132 | 3efda49d | balrog | 0x0000, /* Y+, Y- drivers */ |
133 | 3efda49d | balrog | 0x0000, /* Y+, X- drivers */ |
134 | 3efda49d | balrog | }; |
135 | 3efda49d | balrog | |
136 | a5d7eb65 | balrog | #define X_TRANSFORM(s) \
|
137 | a5d7eb65 | balrog | ((s->y * s->tr[0] - s->x * s->tr[1]) / s->tr[2] + s->tr[3]) |
138 | a5d7eb65 | balrog | #define Y_TRANSFORM(s) \
|
139 | a5d7eb65 | balrog | ((s->y * s->tr[4] - s->x * s->tr[5]) / s->tr[6] + s->tr[7]) |
140 | 3efda49d | balrog | #define Z1_TRANSFORM(s) \
|
141 | 8ef6367e | balrog | ((400 - ((s)->x >> 7) + ((s)->pressure << 10)) << 4) |
142 | 3efda49d | balrog | #define Z2_TRANSFORM(s) \
|
143 | 8ef6367e | balrog | ((4000 + ((s)->y >> 7) - ((s)->pressure << 10)) << 4) |
144 | 8ef6367e | balrog | |
145 | 3efda49d | balrog | #define BAT1_VAL 0x8660 |
146 | 3efda49d | balrog | #define BAT2_VAL 0x0000 |
147 | 3efda49d | balrog | #define AUX1_VAL 0x35c0 |
148 | 3efda49d | balrog | #define AUX2_VAL 0xffff |
149 | 3efda49d | balrog | #define TEMP1_VAL 0x8c70 |
150 | 3efda49d | balrog | #define TEMP2_VAL 0xa5b0 |
151 | 3efda49d | balrog | |
152 | 3efda49d | balrog | #define TSC_POWEROFF_DELAY 50 |
153 | 3efda49d | balrog | #define TSC_SOFTSTEP_DELAY 50 |
154 | 3efda49d | balrog | |
155 | bc24a225 | Paul Brook | static void tsc210x_reset(TSC210xState *s) |
156 | 3efda49d | balrog | { |
157 | 3efda49d | balrog | s->state = 0;
|
158 | 3efda49d | balrog | s->pin_func = 2;
|
159 | 3efda49d | balrog | s->enabled = 0;
|
160 | 3efda49d | balrog | s->busy = 0;
|
161 | 3efda49d | balrog | s->nextfunction = 0;
|
162 | 3efda49d | balrog | s->ref = 0;
|
163 | 3efda49d | balrog | s->timing = 0;
|
164 | 3efda49d | balrog | s->irq = 0;
|
165 | 3efda49d | balrog | s->dav = 0;
|
166 | 3efda49d | balrog | |
167 | 3efda49d | balrog | s->audio_ctrl1 = 0x0000;
|
168 | 3efda49d | balrog | s->audio_ctrl2 = 0x4410;
|
169 | 3efda49d | balrog | s->audio_ctrl3 = 0x0000;
|
170 | 3efda49d | balrog | s->pll[0] = 0x1004; |
171 | 3efda49d | balrog | s->pll[1] = 0x0000; |
172 | a5d7eb65 | balrog | s->pll[2] = 0x1fff; |
173 | 3efda49d | balrog | s->volume = 0xffff;
|
174 | 3efda49d | balrog | s->dac_power = 0x8540;
|
175 | 3efda49d | balrog | s->softstep = 1;
|
176 | 3efda49d | balrog | s->volume_change = 0;
|
177 | 3efda49d | balrog | s->powerdown = 0;
|
178 | 3efda49d | balrog | s->filter_data[0x00] = 0x6be3; |
179 | 3efda49d | balrog | s->filter_data[0x01] = 0x9666; |
180 | 3efda49d | balrog | s->filter_data[0x02] = 0x675d; |
181 | 3efda49d | balrog | s->filter_data[0x03] = 0x6be3; |
182 | 3efda49d | balrog | s->filter_data[0x04] = 0x9666; |
183 | 3efda49d | balrog | s->filter_data[0x05] = 0x675d; |
184 | 3efda49d | balrog | s->filter_data[0x06] = 0x7d83; |
185 | 3efda49d | balrog | s->filter_data[0x07] = 0x84ee; |
186 | 3efda49d | balrog | s->filter_data[0x08] = 0x7d83; |
187 | 3efda49d | balrog | s->filter_data[0x09] = 0x84ee; |
188 | 3efda49d | balrog | s->filter_data[0x0a] = 0x6be3; |
189 | 3efda49d | balrog | s->filter_data[0x0b] = 0x9666; |
190 | 3efda49d | balrog | s->filter_data[0x0c] = 0x675d; |
191 | 3efda49d | balrog | s->filter_data[0x0d] = 0x6be3; |
192 | 3efda49d | balrog | s->filter_data[0x0e] = 0x9666; |
193 | 3efda49d | balrog | s->filter_data[0x0f] = 0x675d; |
194 | 3efda49d | balrog | s->filter_data[0x10] = 0x7d83; |
195 | 3efda49d | balrog | s->filter_data[0x11] = 0x84ee; |
196 | 3efda49d | balrog | s->filter_data[0x12] = 0x7d83; |
197 | 3efda49d | balrog | s->filter_data[0x13] = 0x84ee; |
198 | 3efda49d | balrog | |
199 | d8f699cb | balrog | s->i2s_tx_rate = 0;
|
200 | d8f699cb | balrog | s->i2s_rx_rate = 0;
|
201 | d8f699cb | balrog | |
202 | a5d7eb65 | balrog | s->kb.scan = 1;
|
203 | a5d7eb65 | balrog | s->kb.debounce = 0;
|
204 | a5d7eb65 | balrog | s->kb.mask = 0x0000;
|
205 | a5d7eb65 | balrog | s->kb.mode = 3;
|
206 | a5d7eb65 | balrog | s->kb.intr = 0;
|
207 | a5d7eb65 | balrog | |
208 | 7fc42b4b | balrog | qemu_set_irq(s->pint, !s->irq); |
209 | a5d7eb65 | balrog | qemu_set_irq(s->davint, !s->dav); |
210 | a5d7eb65 | balrog | qemu_irq_raise(s->kbint); |
211 | 3efda49d | balrog | } |
212 | 3efda49d | balrog | |
213 | bc24a225 | Paul Brook | typedef struct { |
214 | d8f699cb | balrog | int rate;
|
215 | d8f699cb | balrog | int dsor;
|
216 | d8f699cb | balrog | int fsref;
|
217 | bc24a225 | Paul Brook | } TSC210xRateInfo; |
218 | d8f699cb | balrog | |
219 | d8f699cb | balrog | /* { rate, dsor, fsref } */
|
220 | bc24a225 | Paul Brook | static const TSC210xRateInfo tsc2101_rates[] = { |
221 | d8f699cb | balrog | /* Fsref / 6.0 */
|
222 | d8f699cb | balrog | { 7350, 7, 1 }, |
223 | d8f699cb | balrog | { 8000, 7, 0 }, |
224 | d8f699cb | balrog | /* Fsref / 5.5 */
|
225 | d8f699cb | balrog | { 8018, 6, 1 }, |
226 | d8f699cb | balrog | { 8727, 6, 0 }, |
227 | d8f699cb | balrog | /* Fsref / 5.0 */
|
228 | d8f699cb | balrog | { 8820, 5, 1 }, |
229 | d8f699cb | balrog | { 9600, 5, 0 }, |
230 | d8f699cb | balrog | /* Fsref / 4.0 */
|
231 | d8f699cb | balrog | { 11025, 4, 1 }, |
232 | d8f699cb | balrog | { 12000, 4, 0 }, |
233 | d8f699cb | balrog | /* Fsref / 3.0 */
|
234 | d8f699cb | balrog | { 14700, 3, 1 }, |
235 | d8f699cb | balrog | { 16000, 3, 0 }, |
236 | d8f699cb | balrog | /* Fsref / 2.0 */
|
237 | d8f699cb | balrog | { 22050, 2, 1 }, |
238 | d8f699cb | balrog | { 24000, 2, 0 }, |
239 | d8f699cb | balrog | /* Fsref / 1.5 */
|
240 | d8f699cb | balrog | { 29400, 1, 1 }, |
241 | d8f699cb | balrog | { 32000, 1, 0 }, |
242 | d8f699cb | balrog | /* Fsref */
|
243 | d8f699cb | balrog | { 44100, 0, 1 }, |
244 | d8f699cb | balrog | { 48000, 0, 0 }, |
245 | d8f699cb | balrog | |
246 | d8f699cb | balrog | { 0, 0, 0 }, |
247 | d8f699cb | balrog | }; |
248 | d8f699cb | balrog | |
249 | d8f699cb | balrog | /* { rate, dsor, fsref } */
|
250 | bc24a225 | Paul Brook | static const TSC210xRateInfo tsc2102_rates[] = { |
251 | d8f699cb | balrog | /* Fsref / 6.0 */
|
252 | d8f699cb | balrog | { 7350, 63, 1 }, |
253 | d8f699cb | balrog | { 8000, 63, 0 }, |
254 | d8f699cb | balrog | /* Fsref / 6.0 */
|
255 | d8f699cb | balrog | { 7350, 54, 1 }, |
256 | d8f699cb | balrog | { 8000, 54, 0 }, |
257 | d8f699cb | balrog | /* Fsref / 5.0 */
|
258 | d8f699cb | balrog | { 8820, 45, 1 }, |
259 | d8f699cb | balrog | { 9600, 45, 0 }, |
260 | d8f699cb | balrog | /* Fsref / 4.0 */
|
261 | d8f699cb | balrog | { 11025, 36, 1 }, |
262 | d8f699cb | balrog | { 12000, 36, 0 }, |
263 | d8f699cb | balrog | /* Fsref / 3.0 */
|
264 | d8f699cb | balrog | { 14700, 27, 1 }, |
265 | d8f699cb | balrog | { 16000, 27, 0 }, |
266 | d8f699cb | balrog | /* Fsref / 2.0 */
|
267 | d8f699cb | balrog | { 22050, 18, 1 }, |
268 | d8f699cb | balrog | { 24000, 18, 0 }, |
269 | d8f699cb | balrog | /* Fsref / 1.5 */
|
270 | d8f699cb | balrog | { 29400, 9, 1 }, |
271 | d8f699cb | balrog | { 32000, 9, 0 }, |
272 | d8f699cb | balrog | /* Fsref */
|
273 | d8f699cb | balrog | { 44100, 0, 1 }, |
274 | d8f699cb | balrog | { 48000, 0, 0 }, |
275 | d8f699cb | balrog | |
276 | d8f699cb | balrog | { 0, 0, 0 }, |
277 | d8f699cb | balrog | }; |
278 | d8f699cb | balrog | |
279 | bc24a225 | Paul Brook | static inline void tsc210x_out_flush(TSC210xState *s, int len) |
280 | d8f699cb | balrog | { |
281 | d8f699cb | balrog | uint8_t *data = s->codec.out.fifo + s->codec.out.start; |
282 | d8f699cb | balrog | uint8_t *end = data + len; |
283 | d8f699cb | balrog | |
284 | d8f699cb | balrog | while (data < end)
|
285 | d8f699cb | balrog | data += AUD_write(s->dac_voice[0], data, end - data) ?: (end - data);
|
286 | d8f699cb | balrog | |
287 | d8f699cb | balrog | s->codec.out.len -= len; |
288 | d8f699cb | balrog | if (s->codec.out.len)
|
289 | d8f699cb | balrog | memmove(s->codec.out.fifo, end, s->codec.out.len); |
290 | d8f699cb | balrog | s->codec.out.start = 0;
|
291 | d8f699cb | balrog | } |
292 | d8f699cb | balrog | |
293 | bc24a225 | Paul Brook | static void tsc210x_audio_out_cb(TSC210xState *s, int free_b) |
294 | d8f699cb | balrog | { |
295 | d8f699cb | balrog | if (s->codec.out.len >= free_b) {
|
296 | d8f699cb | balrog | tsc210x_out_flush(s, free_b); |
297 | d8f699cb | balrog | return;
|
298 | d8f699cb | balrog | } |
299 | d8f699cb | balrog | |
300 | d8f699cb | balrog | s->codec.out.size = MIN(free_b, 16384);
|
301 | d8f699cb | balrog | qemu_irq_raise(s->codec.tx_start); |
302 | d8f699cb | balrog | } |
303 | d8f699cb | balrog | |
304 | bc24a225 | Paul Brook | static void tsc2102_audio_rate_update(TSC210xState *s) |
305 | d8f699cb | balrog | { |
306 | bc24a225 | Paul Brook | const TSC210xRateInfo *rate;
|
307 | 73560bc8 | balrog | |
308 | 73560bc8 | balrog | s->codec.tx_rate = 0;
|
309 | 73560bc8 | balrog | s->codec.rx_rate = 0;
|
310 | 73560bc8 | balrog | if (s->dac_power & (1 << 15)) /* PWDNC */ |
311 | 73560bc8 | balrog | return;
|
312 | 73560bc8 | balrog | |
313 | 73560bc8 | balrog | for (rate = tsc2102_rates; rate->rate; rate ++)
|
314 | 73560bc8 | balrog | if (rate->dsor == (s->audio_ctrl1 & 0x3f) && /* DACFS */ |
315 | 73560bc8 | balrog | rate->fsref == ((s->audio_ctrl3 >> 13) & 1))/* REFFS */ |
316 | 73560bc8 | balrog | break;
|
317 | 73560bc8 | balrog | if (!rate->rate) {
|
318 | 73560bc8 | balrog | printf("%s: unknown sampling rate configured\n", __FUNCTION__);
|
319 | 73560bc8 | balrog | return;
|
320 | 73560bc8 | balrog | } |
321 | 73560bc8 | balrog | |
322 | 73560bc8 | balrog | s->codec.tx_rate = rate->rate; |
323 | 73560bc8 | balrog | } |
324 | 73560bc8 | balrog | |
325 | bc24a225 | Paul Brook | static void tsc2102_audio_output_update(TSC210xState *s) |
326 | 73560bc8 | balrog | { |
327 | 73560bc8 | balrog | int enable;
|
328 | 1ea879e5 | malc | struct audsettings fmt;
|
329 | d8f699cb | balrog | |
330 | d8f699cb | balrog | if (s->dac_voice[0]) { |
331 | d8f699cb | balrog | tsc210x_out_flush(s, s->codec.out.len); |
332 | d8f699cb | balrog | s->codec.out.size = 0;
|
333 | d8f699cb | balrog | AUD_set_active_out(s->dac_voice[0], 0); |
334 | d8f699cb | balrog | AUD_close_out(&s->card, s->dac_voice[0]);
|
335 | d8f699cb | balrog | s->dac_voice[0] = 0; |
336 | d8f699cb | balrog | } |
337 | 73560bc8 | balrog | s->codec.cts = 0;
|
338 | d8f699cb | balrog | |
339 | d8f699cb | balrog | enable = |
340 | d8f699cb | balrog | (~s->dac_power & (1 << 15)) && /* PWDNC */ |
341 | d8f699cb | balrog | (~s->dac_power & (1 << 10)); /* DAPWDN */ |
342 | 73560bc8 | balrog | if (!enable || !s->codec.tx_rate)
|
343 | d8f699cb | balrog | return;
|
344 | d8f699cb | balrog | |
345 | d8f699cb | balrog | /* Force our own sampling rate even in slave DAC mode */
|
346 | d8f699cb | balrog | fmt.endianness = 0;
|
347 | d8f699cb | balrog | fmt.nchannels = 2;
|
348 | 73560bc8 | balrog | fmt.freq = s->codec.tx_rate; |
349 | d8f699cb | balrog | fmt.fmt = AUD_FMT_S16; |
350 | d8f699cb | balrog | |
351 | d8f699cb | balrog | s->dac_voice[0] = AUD_open_out(&s->card, s->dac_voice[0], |
352 | d8f699cb | balrog | "tsc2102.sink", s, (void *) tsc210x_audio_out_cb, &fmt); |
353 | 73560bc8 | balrog | if (s->dac_voice[0]) { |
354 | 73560bc8 | balrog | s->codec.cts = 1;
|
355 | d8f699cb | balrog | AUD_set_active_out(s->dac_voice[0], 1); |
356 | 73560bc8 | balrog | } |
357 | d8f699cb | balrog | } |
358 | d8f699cb | balrog | |
359 | bc24a225 | Paul Brook | static uint16_t tsc2102_data_register_read(TSC210xState *s, int reg) |
360 | 3efda49d | balrog | { |
361 | 3efda49d | balrog | switch (reg) {
|
362 | 3efda49d | balrog | case 0x00: /* X */ |
363 | 3efda49d | balrog | s->dav &= 0xfbff;
|
364 | a5d7eb65 | balrog | return TSC_CUT_RESOLUTION(X_TRANSFORM(s), s->precision) +
|
365 | 3efda49d | balrog | (s->noise & 3);
|
366 | 3efda49d | balrog | |
367 | 3efda49d | balrog | case 0x01: /* Y */ |
368 | 3efda49d | balrog | s->noise ++; |
369 | 3efda49d | balrog | s->dav &= 0xfdff;
|
370 | a5d7eb65 | balrog | return TSC_CUT_RESOLUTION(Y_TRANSFORM(s), s->precision) ^
|
371 | 3efda49d | balrog | (s->noise & 3);
|
372 | 3efda49d | balrog | |
373 | 3efda49d | balrog | case 0x02: /* Z1 */ |
374 | 3efda49d | balrog | s->dav &= 0xfeff;
|
375 | 3efda49d | balrog | return TSC_CUT_RESOLUTION(Z1_TRANSFORM(s), s->precision) -
|
376 | 3efda49d | balrog | (s->noise & 3);
|
377 | 3efda49d | balrog | |
378 | 3efda49d | balrog | case 0x03: /* Z2 */ |
379 | 3efda49d | balrog | s->dav &= 0xff7f;
|
380 | 3efda49d | balrog | return TSC_CUT_RESOLUTION(Z2_TRANSFORM(s), s->precision) |
|
381 | 3efda49d | balrog | (s->noise & 3);
|
382 | 3efda49d | balrog | |
383 | 3efda49d | balrog | case 0x04: /* KPData */ |
384 | a5d7eb65 | balrog | if ((s->model & 0xff00) == 0x2300) { |
385 | a5d7eb65 | balrog | if (s->kb.intr && (s->kb.mode & 2)) { |
386 | a5d7eb65 | balrog | s->kb.intr = 0;
|
387 | a5d7eb65 | balrog | qemu_irq_raise(s->kbint); |
388 | a5d7eb65 | balrog | } |
389 | a5d7eb65 | balrog | return s->kb.down;
|
390 | a5d7eb65 | balrog | } |
391 | a5d7eb65 | balrog | |
392 | 3efda49d | balrog | return 0xffff; |
393 | 3efda49d | balrog | |
394 | 3efda49d | balrog | case 0x05: /* BAT1 */ |
395 | 3efda49d | balrog | s->dav &= 0xffbf;
|
396 | 8ef6367e | balrog | return TSC_CUT_RESOLUTION(BAT1_VAL, s->precision) +
|
397 | 8ef6367e | balrog | (s->noise & 6);
|
398 | 3efda49d | balrog | |
399 | 3efda49d | balrog | case 0x06: /* BAT2 */ |
400 | 3efda49d | balrog | s->dav &= 0xffdf;
|
401 | 3efda49d | balrog | return TSC_CUT_RESOLUTION(BAT2_VAL, s->precision);
|
402 | 3efda49d | balrog | |
403 | 3efda49d | balrog | case 0x07: /* AUX1 */ |
404 | 3efda49d | balrog | s->dav &= 0xffef;
|
405 | 3efda49d | balrog | return TSC_CUT_RESOLUTION(AUX1_VAL, s->precision);
|
406 | 3efda49d | balrog | |
407 | 3efda49d | balrog | case 0x08: /* AUX2 */ |
408 | 3efda49d | balrog | s->dav &= 0xfff7;
|
409 | 3efda49d | balrog | return 0xffff; |
410 | 3efda49d | balrog | |
411 | 3efda49d | balrog | case 0x09: /* TEMP1 */ |
412 | 3efda49d | balrog | s->dav &= 0xfffb;
|
413 | 8ef6367e | balrog | return TSC_CUT_RESOLUTION(TEMP1_VAL, s->precision) -
|
414 | 8ef6367e | balrog | (s->noise & 5);
|
415 | 3efda49d | balrog | |
416 | 3efda49d | balrog | case 0x0a: /* TEMP2 */ |
417 | 3efda49d | balrog | s->dav &= 0xfffd;
|
418 | 8ef6367e | balrog | return TSC_CUT_RESOLUTION(TEMP2_VAL, s->precision) ^
|
419 | 8ef6367e | balrog | (s->noise & 3);
|
420 | 3efda49d | balrog | |
421 | 3efda49d | balrog | case 0x0b: /* DAC */ |
422 | 3efda49d | balrog | s->dav &= 0xfffe;
|
423 | 3efda49d | balrog | return 0xffff; |
424 | 3efda49d | balrog | |
425 | 3efda49d | balrog | default:
|
426 | 3efda49d | balrog | #ifdef TSC_VERBOSE
|
427 | 3efda49d | balrog | fprintf(stderr, "tsc2102_data_register_read: "
|
428 | 3efda49d | balrog | "no such register: 0x%02x\n", reg);
|
429 | 3efda49d | balrog | #endif
|
430 | 3efda49d | balrog | return 0xffff; |
431 | 3efda49d | balrog | } |
432 | 3efda49d | balrog | } |
433 | 3efda49d | balrog | |
434 | 3efda49d | balrog | static uint16_t tsc2102_control_register_read(
|
435 | bc24a225 | Paul Brook | TSC210xState *s, int reg)
|
436 | 3efda49d | balrog | { |
437 | 3efda49d | balrog | switch (reg) {
|
438 | 3efda49d | balrog | case 0x00: /* TSC ADC */ |
439 | 3efda49d | balrog | return (s->pressure << 15) | ((!s->busy) << 14) | |
440 | 3efda49d | balrog | (s->nextfunction << 10) | (s->nextprecision << 8) | s->filter; |
441 | 3efda49d | balrog | |
442 | a5d7eb65 | balrog | case 0x01: /* Status / Keypad Control */ |
443 | a5d7eb65 | balrog | if ((s->model & 0xff00) == 0x2100) |
444 | a5d7eb65 | balrog | return (s->pin_func << 14) | ((!s->enabled) << 13) | |
445 | a5d7eb65 | balrog | (s->host_mode << 12) | ((!!s->dav) << 11) | s->dav; |
446 | a5d7eb65 | balrog | else
|
447 | a5d7eb65 | balrog | return (s->kb.intr << 15) | ((s->kb.scan || !s->kb.down) << 14) | |
448 | a5d7eb65 | balrog | (s->kb.debounce << 11);
|
449 | a5d7eb65 | balrog | |
450 | a5d7eb65 | balrog | case 0x02: /* DAC Control */ |
451 | a5d7eb65 | balrog | if ((s->model & 0xff00) == 0x2300) |
452 | a5d7eb65 | balrog | return s->dac_power & 0x8000; |
453 | a5d7eb65 | balrog | else
|
454 | a5d7eb65 | balrog | goto bad_reg;
|
455 | 3efda49d | balrog | |
456 | 3efda49d | balrog | case 0x03: /* Reference */ |
457 | 3efda49d | balrog | return s->ref;
|
458 | 3efda49d | balrog | |
459 | 3efda49d | balrog | case 0x04: /* Reset */ |
460 | 3efda49d | balrog | return 0xffff; |
461 | 3efda49d | balrog | |
462 | 3efda49d | balrog | case 0x05: /* Configuration */ |
463 | 3efda49d | balrog | return s->timing;
|
464 | 3efda49d | balrog | |
465 | a5d7eb65 | balrog | case 0x06: /* Secondary configuration */ |
466 | a5d7eb65 | balrog | if ((s->model & 0xff00) == 0x2100) |
467 | a5d7eb65 | balrog | goto bad_reg;
|
468 | a5d7eb65 | balrog | return ((!s->dav) << 15) | ((s->kb.mode & 1) << 14) | s->pll[2]; |
469 | a5d7eb65 | balrog | |
470 | a5d7eb65 | balrog | case 0x10: /* Keypad Mask */ |
471 | a5d7eb65 | balrog | if ((s->model & 0xff00) == 0x2100) |
472 | a5d7eb65 | balrog | goto bad_reg;
|
473 | a5d7eb65 | balrog | return s->kb.mask;
|
474 | a5d7eb65 | balrog | |
475 | 3efda49d | balrog | default:
|
476 | a5d7eb65 | balrog | bad_reg:
|
477 | 3efda49d | balrog | #ifdef TSC_VERBOSE
|
478 | 3efda49d | balrog | fprintf(stderr, "tsc2102_control_register_read: "
|
479 | 3efda49d | balrog | "no such register: 0x%02x\n", reg);
|
480 | 3efda49d | balrog | #endif
|
481 | 3efda49d | balrog | return 0xffff; |
482 | 3efda49d | balrog | } |
483 | 3efda49d | balrog | } |
484 | 3efda49d | balrog | |
485 | bc24a225 | Paul Brook | static uint16_t tsc2102_audio_register_read(TSC210xState *s, int reg) |
486 | 3efda49d | balrog | { |
487 | 3efda49d | balrog | int l_ch, r_ch;
|
488 | 3efda49d | balrog | uint16_t val; |
489 | 3efda49d | balrog | |
490 | 3efda49d | balrog | switch (reg) {
|
491 | 3efda49d | balrog | case 0x00: /* Audio Control 1 */ |
492 | 3efda49d | balrog | return s->audio_ctrl1;
|
493 | 3efda49d | balrog | |
494 | 3efda49d | balrog | case 0x01: |
495 | 3efda49d | balrog | return 0xff00; |
496 | 3efda49d | balrog | |
497 | 3efda49d | balrog | case 0x02: /* DAC Volume Control */ |
498 | 3efda49d | balrog | return s->volume;
|
499 | 3efda49d | balrog | |
500 | 3efda49d | balrog | case 0x03: |
501 | 3efda49d | balrog | return 0x8b00; |
502 | 3efda49d | balrog | |
503 | 3efda49d | balrog | case 0x04: /* Audio Control 2 */ |
504 | 3efda49d | balrog | l_ch = 1;
|
505 | 3efda49d | balrog | r_ch = 1;
|
506 | 3efda49d | balrog | if (s->softstep && !(s->dac_power & (1 << 10))) { |
507 | 3efda49d | balrog | l_ch = (qemu_get_clock(vm_clock) > |
508 | 3efda49d | balrog | s->volume_change + TSC_SOFTSTEP_DELAY); |
509 | 3efda49d | balrog | r_ch = (qemu_get_clock(vm_clock) > |
510 | 3efda49d | balrog | s->volume_change + TSC_SOFTSTEP_DELAY); |
511 | 3efda49d | balrog | } |
512 | 3efda49d | balrog | |
513 | 3efda49d | balrog | return s->audio_ctrl2 | (l_ch << 3) | (r_ch << 2); |
514 | 3efda49d | balrog | |
515 | 3efda49d | balrog | case 0x05: /* Stereo DAC Power Control */ |
516 | 3efda49d | balrog | return 0x2aa0 | s->dac_power | |
517 | 3efda49d | balrog | (((s->dac_power & (1 << 10)) && |
518 | 3efda49d | balrog | (qemu_get_clock(vm_clock) > |
519 | 3efda49d | balrog | s->powerdown + TSC_POWEROFF_DELAY)) << 6);
|
520 | 3efda49d | balrog | |
521 | 3efda49d | balrog | case 0x06: /* Audio Control 3 */ |
522 | 3efda49d | balrog | val = s->audio_ctrl3 | 0x0001;
|
523 | 3efda49d | balrog | s->audio_ctrl3 &= 0xff3f;
|
524 | 3efda49d | balrog | return val;
|
525 | 3efda49d | balrog | |
526 | 3efda49d | balrog | case 0x07: /* LCH_BASS_BOOST_N0 */ |
527 | 3efda49d | balrog | case 0x08: /* LCH_BASS_BOOST_N1 */ |
528 | 3efda49d | balrog | case 0x09: /* LCH_BASS_BOOST_N2 */ |
529 | 3efda49d | balrog | case 0x0a: /* LCH_BASS_BOOST_N3 */ |
530 | 3efda49d | balrog | case 0x0b: /* LCH_BASS_BOOST_N4 */ |
531 | 3efda49d | balrog | case 0x0c: /* LCH_BASS_BOOST_N5 */ |
532 | 3efda49d | balrog | case 0x0d: /* LCH_BASS_BOOST_D1 */ |
533 | 3efda49d | balrog | case 0x0e: /* LCH_BASS_BOOST_D2 */ |
534 | 3efda49d | balrog | case 0x0f: /* LCH_BASS_BOOST_D4 */ |
535 | 3efda49d | balrog | case 0x10: /* LCH_BASS_BOOST_D5 */ |
536 | 3efda49d | balrog | case 0x11: /* RCH_BASS_BOOST_N0 */ |
537 | 3efda49d | balrog | case 0x12: /* RCH_BASS_BOOST_N1 */ |
538 | 3efda49d | balrog | case 0x13: /* RCH_BASS_BOOST_N2 */ |
539 | 3efda49d | balrog | case 0x14: /* RCH_BASS_BOOST_N3 */ |
540 | 3efda49d | balrog | case 0x15: /* RCH_BASS_BOOST_N4 */ |
541 | 3efda49d | balrog | case 0x16: /* RCH_BASS_BOOST_N5 */ |
542 | 3efda49d | balrog | case 0x17: /* RCH_BASS_BOOST_D1 */ |
543 | 3efda49d | balrog | case 0x18: /* RCH_BASS_BOOST_D2 */ |
544 | 3efda49d | balrog | case 0x19: /* RCH_BASS_BOOST_D4 */ |
545 | 3efda49d | balrog | case 0x1a: /* RCH_BASS_BOOST_D5 */ |
546 | 3efda49d | balrog | return s->filter_data[reg - 0x07]; |
547 | 3efda49d | balrog | |
548 | 3efda49d | balrog | case 0x1b: /* PLL Programmability 1 */ |
549 | 3efda49d | balrog | return s->pll[0]; |
550 | 3efda49d | balrog | |
551 | 3efda49d | balrog | case 0x1c: /* PLL Programmability 2 */ |
552 | 3efda49d | balrog | return s->pll[1]; |
553 | 3efda49d | balrog | |
554 | 3efda49d | balrog | case 0x1d: /* Audio Control 4 */ |
555 | 3efda49d | balrog | return (!s->softstep) << 14; |
556 | 3efda49d | balrog | |
557 | 3efda49d | balrog | default:
|
558 | 3efda49d | balrog | #ifdef TSC_VERBOSE
|
559 | 3efda49d | balrog | fprintf(stderr, "tsc2102_audio_register_read: "
|
560 | 3efda49d | balrog | "no such register: 0x%02x\n", reg);
|
561 | 3efda49d | balrog | #endif
|
562 | 3efda49d | balrog | return 0xffff; |
563 | 3efda49d | balrog | } |
564 | 3efda49d | balrog | } |
565 | 3efda49d | balrog | |
566 | 3efda49d | balrog | static void tsc2102_data_register_write( |
567 | bc24a225 | Paul Brook | TSC210xState *s, int reg, uint16_t value)
|
568 | 3efda49d | balrog | { |
569 | 3efda49d | balrog | switch (reg) {
|
570 | 3efda49d | balrog | case 0x00: /* X */ |
571 | 3efda49d | balrog | case 0x01: /* Y */ |
572 | 3efda49d | balrog | case 0x02: /* Z1 */ |
573 | 3efda49d | balrog | case 0x03: /* Z2 */ |
574 | 3efda49d | balrog | case 0x05: /* BAT1 */ |
575 | 3efda49d | balrog | case 0x06: /* BAT2 */ |
576 | 3efda49d | balrog | case 0x07: /* AUX1 */ |
577 | 3efda49d | balrog | case 0x08: /* AUX2 */ |
578 | 3efda49d | balrog | case 0x09: /* TEMP1 */ |
579 | 3efda49d | balrog | case 0x0a: /* TEMP2 */ |
580 | 3efda49d | balrog | return;
|
581 | 3efda49d | balrog | |
582 | 3efda49d | balrog | default:
|
583 | 3efda49d | balrog | #ifdef TSC_VERBOSE
|
584 | 3efda49d | balrog | fprintf(stderr, "tsc2102_data_register_write: "
|
585 | 3efda49d | balrog | "no such register: 0x%02x\n", reg);
|
586 | 3efda49d | balrog | #endif
|
587 | 3efda49d | balrog | } |
588 | 3efda49d | balrog | } |
589 | 3efda49d | balrog | |
590 | 3efda49d | balrog | static void tsc2102_control_register_write( |
591 | bc24a225 | Paul Brook | TSC210xState *s, int reg, uint16_t value)
|
592 | 3efda49d | balrog | { |
593 | 3efda49d | balrog | switch (reg) {
|
594 | 3efda49d | balrog | case 0x00: /* TSC ADC */ |
595 | 3efda49d | balrog | s->host_mode = value >> 15;
|
596 | 3efda49d | balrog | s->enabled = !(value & 0x4000);
|
597 | 3efda49d | balrog | if (s->busy && !s->enabled)
|
598 | 3efda49d | balrog | qemu_del_timer(s->timer); |
599 | 3efda49d | balrog | s->busy &= s->enabled; |
600 | 3efda49d | balrog | s->nextfunction = (value >> 10) & 0xf; |
601 | 3efda49d | balrog | s->nextprecision = (value >> 8) & 3; |
602 | 3efda49d | balrog | s->filter = value & 0xff;
|
603 | 3efda49d | balrog | return;
|
604 | 3efda49d | balrog | |
605 | a5d7eb65 | balrog | case 0x01: /* Status / Keypad Control */ |
606 | a5d7eb65 | balrog | if ((s->model & 0xff00) == 0x2100) |
607 | a5d7eb65 | balrog | s->pin_func = value >> 14;
|
608 | a5d7eb65 | balrog | else {
|
609 | a5d7eb65 | balrog | s->kb.scan = (value >> 14) & 1; |
610 | a5d7eb65 | balrog | s->kb.debounce = (value >> 11) & 7; |
611 | a5d7eb65 | balrog | if (s->kb.intr && s->kb.scan) {
|
612 | a5d7eb65 | balrog | s->kb.intr = 0;
|
613 | a5d7eb65 | balrog | qemu_irq_raise(s->kbint); |
614 | a5d7eb65 | balrog | } |
615 | a5d7eb65 | balrog | } |
616 | 3efda49d | balrog | return;
|
617 | 3efda49d | balrog | |
618 | a5d7eb65 | balrog | case 0x02: /* DAC Control */ |
619 | a5d7eb65 | balrog | if ((s->model & 0xff00) == 0x2300) { |
620 | a5d7eb65 | balrog | s->dac_power &= 0x7fff;
|
621 | a5d7eb65 | balrog | s->dac_power |= 0x8000 & value;
|
622 | a5d7eb65 | balrog | } else
|
623 | a5d7eb65 | balrog | goto bad_reg;
|
624 | a5d7eb65 | balrog | break;
|
625 | a5d7eb65 | balrog | |
626 | 3efda49d | balrog | case 0x03: /* Reference */ |
627 | 3efda49d | balrog | s->ref = value & 0x1f;
|
628 | 3efda49d | balrog | return;
|
629 | 3efda49d | balrog | |
630 | 3efda49d | balrog | case 0x04: /* Reset */ |
631 | 3efda49d | balrog | if (value == 0xbb00) { |
632 | 3efda49d | balrog | if (s->busy)
|
633 | 3efda49d | balrog | qemu_del_timer(s->timer); |
634 | 3efda49d | balrog | tsc210x_reset(s); |
635 | 3efda49d | balrog | #ifdef TSC_VERBOSE
|
636 | 3efda49d | balrog | } else {
|
637 | 3efda49d | balrog | fprintf(stderr, "tsc2102_control_register_write: "
|
638 | 3efda49d | balrog | "wrong value written into RESET\n");
|
639 | 3efda49d | balrog | #endif
|
640 | 3efda49d | balrog | } |
641 | 3efda49d | balrog | return;
|
642 | 3efda49d | balrog | |
643 | 3efda49d | balrog | case 0x05: /* Configuration */ |
644 | 3efda49d | balrog | s->timing = value & 0x3f;
|
645 | 3efda49d | balrog | #ifdef TSC_VERBOSE
|
646 | 3efda49d | balrog | if (value & ~0x3f) |
647 | 3efda49d | balrog | fprintf(stderr, "tsc2102_control_register_write: "
|
648 | 3efda49d | balrog | "wrong value written into CONFIG\n");
|
649 | 3efda49d | balrog | #endif
|
650 | 3efda49d | balrog | return;
|
651 | 3efda49d | balrog | |
652 | a5d7eb65 | balrog | case 0x06: /* Secondary configuration */ |
653 | a5d7eb65 | balrog | if ((s->model & 0xff00) == 0x2100) |
654 | a5d7eb65 | balrog | goto bad_reg;
|
655 | a5d7eb65 | balrog | s->kb.mode = value >> 14;
|
656 | a5d7eb65 | balrog | s->pll[2] = value & 0x3ffff; |
657 | a5d7eb65 | balrog | return;
|
658 | a5d7eb65 | balrog | |
659 | a5d7eb65 | balrog | case 0x10: /* Keypad Mask */ |
660 | a5d7eb65 | balrog | if ((s->model & 0xff00) == 0x2100) |
661 | a5d7eb65 | balrog | goto bad_reg;
|
662 | a5d7eb65 | balrog | s->kb.mask = value; |
663 | a5d7eb65 | balrog | return;
|
664 | a5d7eb65 | balrog | |
665 | 3efda49d | balrog | default:
|
666 | a5d7eb65 | balrog | bad_reg:
|
667 | 3efda49d | balrog | #ifdef TSC_VERBOSE
|
668 | 3efda49d | balrog | fprintf(stderr, "tsc2102_control_register_write: "
|
669 | 3efda49d | balrog | "no such register: 0x%02x\n", reg);
|
670 | 3efda49d | balrog | #endif
|
671 | 3efda49d | balrog | } |
672 | 3efda49d | balrog | } |
673 | 3efda49d | balrog | |
674 | 3efda49d | balrog | static void tsc2102_audio_register_write( |
675 | bc24a225 | Paul Brook | TSC210xState *s, int reg, uint16_t value)
|
676 | 3efda49d | balrog | { |
677 | 3efda49d | balrog | switch (reg) {
|
678 | 3efda49d | balrog | case 0x00: /* Audio Control 1 */ |
679 | 3efda49d | balrog | s->audio_ctrl1 = value & 0x0f3f;
|
680 | 3efda49d | balrog | #ifdef TSC_VERBOSE
|
681 | 3efda49d | balrog | if ((value & ~0x0f3f) || ((value & 7) != ((value >> 3) & 7))) |
682 | 3efda49d | balrog | fprintf(stderr, "tsc2102_audio_register_write: "
|
683 | 3efda49d | balrog | "wrong value written into Audio 1\n");
|
684 | 3efda49d | balrog | #endif
|
685 | 73560bc8 | balrog | tsc2102_audio_rate_update(s); |
686 | 22d83b14 | Paul Brook | tsc2102_audio_output_update(s); |
687 | 3efda49d | balrog | return;
|
688 | 3efda49d | balrog | |
689 | 3efda49d | balrog | case 0x01: |
690 | 3efda49d | balrog | #ifdef TSC_VERBOSE
|
691 | 3efda49d | balrog | if (value != 0xff00) |
692 | 3efda49d | balrog | fprintf(stderr, "tsc2102_audio_register_write: "
|
693 | 3efda49d | balrog | "wrong value written into reg 0x01\n");
|
694 | 3efda49d | balrog | #endif
|
695 | 3efda49d | balrog | return;
|
696 | 3efda49d | balrog | |
697 | 3efda49d | balrog | case 0x02: /* DAC Volume Control */ |
698 | 3efda49d | balrog | s->volume = value; |
699 | 3efda49d | balrog | s->volume_change = qemu_get_clock(vm_clock); |
700 | 3efda49d | balrog | return;
|
701 | 3efda49d | balrog | |
702 | 3efda49d | balrog | case 0x03: |
703 | 3efda49d | balrog | #ifdef TSC_VERBOSE
|
704 | 3efda49d | balrog | if (value != 0x8b00) |
705 | 3efda49d | balrog | fprintf(stderr, "tsc2102_audio_register_write: "
|
706 | 3efda49d | balrog | "wrong value written into reg 0x03\n");
|
707 | 3efda49d | balrog | #endif
|
708 | 3efda49d | balrog | return;
|
709 | 3efda49d | balrog | |
710 | 3efda49d | balrog | case 0x04: /* Audio Control 2 */ |
711 | 3efda49d | balrog | s->audio_ctrl2 = value & 0xf7f2;
|
712 | 3efda49d | balrog | #ifdef TSC_VERBOSE
|
713 | 3efda49d | balrog | if (value & ~0xf7fd) |
714 | 3efda49d | balrog | fprintf(stderr, "tsc2102_audio_register_write: "
|
715 | 3efda49d | balrog | "wrong value written into Audio 2\n");
|
716 | 3efda49d | balrog | #endif
|
717 | 3efda49d | balrog | return;
|
718 | 3efda49d | balrog | |
719 | 3efda49d | balrog | case 0x05: /* Stereo DAC Power Control */ |
720 | 3efda49d | balrog | if ((value & ~s->dac_power) & (1 << 10)) |
721 | 3efda49d | balrog | s->powerdown = qemu_get_clock(vm_clock); |
722 | 3efda49d | balrog | |
723 | 3efda49d | balrog | s->dac_power = value & 0x9543;
|
724 | 3efda49d | balrog | #ifdef TSC_VERBOSE
|
725 | 3efda49d | balrog | if ((value & ~0x9543) != 0x2aa0) |
726 | 3efda49d | balrog | fprintf(stderr, "tsc2102_audio_register_write: "
|
727 | 3efda49d | balrog | "wrong value written into Power\n");
|
728 | 3efda49d | balrog | #endif
|
729 | 73560bc8 | balrog | tsc2102_audio_rate_update(s); |
730 | 22d83b14 | Paul Brook | tsc2102_audio_output_update(s); |
731 | 3efda49d | balrog | return;
|
732 | 3efda49d | balrog | |
733 | 3efda49d | balrog | case 0x06: /* Audio Control 3 */ |
734 | 3efda49d | balrog | s->audio_ctrl3 &= 0x00c0;
|
735 | 3efda49d | balrog | s->audio_ctrl3 |= value & 0xf800;
|
736 | 3efda49d | balrog | #ifdef TSC_VERBOSE
|
737 | 3efda49d | balrog | if (value & ~0xf8c7) |
738 | 3efda49d | balrog | fprintf(stderr, "tsc2102_audio_register_write: "
|
739 | 3efda49d | balrog | "wrong value written into Audio 3\n");
|
740 | 3efda49d | balrog | #endif
|
741 | 22d83b14 | Paul Brook | tsc2102_audio_output_update(s); |
742 | 3efda49d | balrog | return;
|
743 | 3efda49d | balrog | |
744 | 3efda49d | balrog | case 0x07: /* LCH_BASS_BOOST_N0 */ |
745 | 3efda49d | balrog | case 0x08: /* LCH_BASS_BOOST_N1 */ |
746 | 3efda49d | balrog | case 0x09: /* LCH_BASS_BOOST_N2 */ |
747 | 3efda49d | balrog | case 0x0a: /* LCH_BASS_BOOST_N3 */ |
748 | 3efda49d | balrog | case 0x0b: /* LCH_BASS_BOOST_N4 */ |
749 | 3efda49d | balrog | case 0x0c: /* LCH_BASS_BOOST_N5 */ |
750 | 3efda49d | balrog | case 0x0d: /* LCH_BASS_BOOST_D1 */ |
751 | 3efda49d | balrog | case 0x0e: /* LCH_BASS_BOOST_D2 */ |
752 | 3efda49d | balrog | case 0x0f: /* LCH_BASS_BOOST_D4 */ |
753 | 3efda49d | balrog | case 0x10: /* LCH_BASS_BOOST_D5 */ |
754 | 3efda49d | balrog | case 0x11: /* RCH_BASS_BOOST_N0 */ |
755 | 3efda49d | balrog | case 0x12: /* RCH_BASS_BOOST_N1 */ |
756 | 3efda49d | balrog | case 0x13: /* RCH_BASS_BOOST_N2 */ |
757 | 3efda49d | balrog | case 0x14: /* RCH_BASS_BOOST_N3 */ |
758 | 3efda49d | balrog | case 0x15: /* RCH_BASS_BOOST_N4 */ |
759 | 3efda49d | balrog | case 0x16: /* RCH_BASS_BOOST_N5 */ |
760 | 3efda49d | balrog | case 0x17: /* RCH_BASS_BOOST_D1 */ |
761 | 3efda49d | balrog | case 0x18: /* RCH_BASS_BOOST_D2 */ |
762 | 3efda49d | balrog | case 0x19: /* RCH_BASS_BOOST_D4 */ |
763 | 3efda49d | balrog | case 0x1a: /* RCH_BASS_BOOST_D5 */ |
764 | 3efda49d | balrog | s->filter_data[reg - 0x07] = value;
|
765 | 3efda49d | balrog | return;
|
766 | 3efda49d | balrog | |
767 | 3efda49d | balrog | case 0x1b: /* PLL Programmability 1 */ |
768 | 3efda49d | balrog | s->pll[0] = value & 0xfffc; |
769 | 3efda49d | balrog | #ifdef TSC_VERBOSE
|
770 | 3efda49d | balrog | if (value & ~0xfffc) |
771 | 3efda49d | balrog | fprintf(stderr, "tsc2102_audio_register_write: "
|
772 | 3efda49d | balrog | "wrong value written into PLL 1\n");
|
773 | 3efda49d | balrog | #endif
|
774 | 3efda49d | balrog | return;
|
775 | 3efda49d | balrog | |
776 | 3efda49d | balrog | case 0x1c: /* PLL Programmability 2 */ |
777 | 3efda49d | balrog | s->pll[1] = value & 0xfffc; |
778 | 3efda49d | balrog | #ifdef TSC_VERBOSE
|
779 | 3efda49d | balrog | if (value & ~0xfffc) |
780 | 3efda49d | balrog | fprintf(stderr, "tsc2102_audio_register_write: "
|
781 | 3efda49d | balrog | "wrong value written into PLL 2\n");
|
782 | 3efda49d | balrog | #endif
|
783 | 3efda49d | balrog | return;
|
784 | 3efda49d | balrog | |
785 | 3efda49d | balrog | case 0x1d: /* Audio Control 4 */ |
786 | 3efda49d | balrog | s->softstep = !(value & 0x4000);
|
787 | 3efda49d | balrog | #ifdef TSC_VERBOSE
|
788 | 3efda49d | balrog | if (value & ~0x4000) |
789 | 3efda49d | balrog | fprintf(stderr, "tsc2102_audio_register_write: "
|
790 | 3efda49d | balrog | "wrong value written into Audio 4\n");
|
791 | 3efda49d | balrog | #endif
|
792 | 3efda49d | balrog | return;
|
793 | 3efda49d | balrog | |
794 | 3efda49d | balrog | default:
|
795 | 3efda49d | balrog | #ifdef TSC_VERBOSE
|
796 | 3efda49d | balrog | fprintf(stderr, "tsc2102_audio_register_write: "
|
797 | 3efda49d | balrog | "no such register: 0x%02x\n", reg);
|
798 | 3efda49d | balrog | #endif
|
799 | 3efda49d | balrog | } |
800 | 3efda49d | balrog | } |
801 | 3efda49d | balrog | |
802 | 3efda49d | balrog | /* This handles most of the chip logic. */
|
803 | bc24a225 | Paul Brook | static void tsc210x_pin_update(TSC210xState *s) |
804 | 3efda49d | balrog | { |
805 | 3efda49d | balrog | int64_t expires; |
806 | 3efda49d | balrog | int pin_state;
|
807 | 3efda49d | balrog | |
808 | 3efda49d | balrog | switch (s->pin_func) {
|
809 | 3efda49d | balrog | case 0: |
810 | 3efda49d | balrog | pin_state = s->pressure; |
811 | 3efda49d | balrog | break;
|
812 | 3efda49d | balrog | case 1: |
813 | 3efda49d | balrog | pin_state = !!s->dav; |
814 | 3efda49d | balrog | break;
|
815 | 3efda49d | balrog | case 2: |
816 | 3efda49d | balrog | default:
|
817 | 3efda49d | balrog | pin_state = s->pressure && !s->dav; |
818 | 3efda49d | balrog | } |
819 | 3efda49d | balrog | |
820 | 3efda49d | balrog | if (!s->enabled)
|
821 | 3efda49d | balrog | pin_state = 0;
|
822 | 3efda49d | balrog | |
823 | 3efda49d | balrog | if (pin_state != s->irq) {
|
824 | 3efda49d | balrog | s->irq = pin_state; |
825 | 7fc42b4b | balrog | qemu_set_irq(s->pint, !s->irq); |
826 | 3efda49d | balrog | } |
827 | 3efda49d | balrog | |
828 | 3efda49d | balrog | switch (s->nextfunction) {
|
829 | 3efda49d | balrog | case TSC_MODE_XY_SCAN:
|
830 | 3efda49d | balrog | case TSC_MODE_XYZ_SCAN:
|
831 | 3efda49d | balrog | if (!s->pressure)
|
832 | 3efda49d | balrog | return;
|
833 | 3efda49d | balrog | break;
|
834 | 3efda49d | balrog | |
835 | 3efda49d | balrog | case TSC_MODE_X:
|
836 | 3efda49d | balrog | case TSC_MODE_Y:
|
837 | 3efda49d | balrog | case TSC_MODE_Z:
|
838 | 3efda49d | balrog | if (!s->pressure)
|
839 | 3efda49d | balrog | return;
|
840 | 3efda49d | balrog | /* Fall through */
|
841 | 3efda49d | balrog | case TSC_MODE_BAT1:
|
842 | 3efda49d | balrog | case TSC_MODE_BAT2:
|
843 | 3efda49d | balrog | case TSC_MODE_AUX:
|
844 | 3efda49d | balrog | case TSC_MODE_TEMP1:
|
845 | 3efda49d | balrog | case TSC_MODE_TEMP2:
|
846 | 3efda49d | balrog | if (s->dav)
|
847 | 3efda49d | balrog | s->enabled = 0;
|
848 | 3efda49d | balrog | break;
|
849 | 3efda49d | balrog | |
850 | 3efda49d | balrog | case TSC_MODE_AUX_SCAN:
|
851 | 3efda49d | balrog | case TSC_MODE_PORT_SCAN:
|
852 | 3efda49d | balrog | break;
|
853 | 3efda49d | balrog | |
854 | 3efda49d | balrog | case TSC_MODE_NO_SCAN:
|
855 | 3efda49d | balrog | case TSC_MODE_XX_DRV:
|
856 | 3efda49d | balrog | case TSC_MODE_YY_DRV:
|
857 | 3efda49d | balrog | case TSC_MODE_YX_DRV:
|
858 | 3efda49d | balrog | default:
|
859 | 3efda49d | balrog | return;
|
860 | 3efda49d | balrog | } |
861 | 3efda49d | balrog | |
862 | a5d7eb65 | balrog | if (!s->enabled || s->busy || s->dav)
|
863 | 3efda49d | balrog | return;
|
864 | 3efda49d | balrog | |
865 | 3efda49d | balrog | s->busy = 1;
|
866 | 3efda49d | balrog | s->precision = s->nextprecision; |
867 | 3efda49d | balrog | s->function = s->nextfunction; |
868 | 3efda49d | balrog | expires = qemu_get_clock(vm_clock) + (ticks_per_sec >> 10);
|
869 | 3efda49d | balrog | qemu_mod_timer(s->timer, expires); |
870 | 3efda49d | balrog | } |
871 | 3efda49d | balrog | |
872 | bc24a225 | Paul Brook | static uint16_t tsc210x_read(TSC210xState *s)
|
873 | 3efda49d | balrog | { |
874 | 3efda49d | balrog | uint16_t ret = 0x0000;
|
875 | 3efda49d | balrog | |
876 | 3efda49d | balrog | if (!s->command)
|
877 | 3efda49d | balrog | fprintf(stderr, "tsc210x_read: SPI underrun!\n");
|
878 | 3efda49d | balrog | |
879 | 3efda49d | balrog | switch (s->page) {
|
880 | 3efda49d | balrog | case TSC_DATA_REGISTERS_PAGE:
|
881 | 3efda49d | balrog | ret = tsc2102_data_register_read(s, s->offset); |
882 | a5d7eb65 | balrog | if (!s->dav)
|
883 | a5d7eb65 | balrog | qemu_irq_raise(s->davint); |
884 | 3efda49d | balrog | break;
|
885 | 3efda49d | balrog | case TSC_CONTROL_REGISTERS_PAGE:
|
886 | 3efda49d | balrog | ret = tsc2102_control_register_read(s, s->offset); |
887 | 3efda49d | balrog | break;
|
888 | 3efda49d | balrog | case TSC_AUDIO_REGISTERS_PAGE:
|
889 | 3efda49d | balrog | ret = tsc2102_audio_register_read(s, s->offset); |
890 | 3efda49d | balrog | break;
|
891 | 3efda49d | balrog | default:
|
892 | 2ac71179 | Paul Brook | hw_error("tsc210x_read: wrong memory page\n");
|
893 | 3efda49d | balrog | } |
894 | 3efda49d | balrog | |
895 | 3efda49d | balrog | tsc210x_pin_update(s); |
896 | 3efda49d | balrog | |
897 | 3efda49d | balrog | /* Allow sequential reads. */
|
898 | 3efda49d | balrog | s->offset ++; |
899 | 3efda49d | balrog | s->state = 0;
|
900 | 3efda49d | balrog | return ret;
|
901 | 3efda49d | balrog | } |
902 | 3efda49d | balrog | |
903 | bc24a225 | Paul Brook | static void tsc210x_write(TSC210xState *s, uint16_t value) |
904 | 3efda49d | balrog | { |
905 | 3efda49d | balrog | /*
|
906 | 3efda49d | balrog | * This is a two-state state machine for reading
|
907 | 3efda49d | balrog | * command and data every second time.
|
908 | 3efda49d | balrog | */
|
909 | 3efda49d | balrog | if (!s->state) {
|
910 | 3efda49d | balrog | s->command = value >> 15;
|
911 | 3efda49d | balrog | s->page = (value >> 11) & 0x0f; |
912 | 3efda49d | balrog | s->offset = (value >> 5) & 0x3f; |
913 | 3efda49d | balrog | s->state = 1;
|
914 | 3efda49d | balrog | } else {
|
915 | 3efda49d | balrog | if (s->command)
|
916 | 3efda49d | balrog | fprintf(stderr, "tsc210x_write: SPI overrun!\n");
|
917 | 3efda49d | balrog | else
|
918 | 3efda49d | balrog | switch (s->page) {
|
919 | 3efda49d | balrog | case TSC_DATA_REGISTERS_PAGE:
|
920 | 3efda49d | balrog | tsc2102_data_register_write(s, s->offset, value); |
921 | 3efda49d | balrog | break;
|
922 | 3efda49d | balrog | case TSC_CONTROL_REGISTERS_PAGE:
|
923 | 3efda49d | balrog | tsc2102_control_register_write(s, s->offset, value); |
924 | 3efda49d | balrog | break;
|
925 | 3efda49d | balrog | case TSC_AUDIO_REGISTERS_PAGE:
|
926 | 3efda49d | balrog | tsc2102_audio_register_write(s, s->offset, value); |
927 | 3efda49d | balrog | break;
|
928 | 3efda49d | balrog | default:
|
929 | 2ac71179 | Paul Brook | hw_error("tsc210x_write: wrong memory page\n");
|
930 | 3efda49d | balrog | } |
931 | 3efda49d | balrog | |
932 | 3efda49d | balrog | tsc210x_pin_update(s); |
933 | 3efda49d | balrog | s->state = 0;
|
934 | 3efda49d | balrog | } |
935 | 3efda49d | balrog | } |
936 | 3efda49d | balrog | |
937 | e927bb00 | balrog | uint32_t tsc210x_txrx(void *opaque, uint32_t value, int len) |
938 | a5d7eb65 | balrog | { |
939 | bc24a225 | Paul Brook | TSC210xState *s = opaque; |
940 | a5d7eb65 | balrog | uint32_t ret = 0;
|
941 | a5d7eb65 | balrog | |
942 | e927bb00 | balrog | if (len != 16) |
943 | 2ac71179 | Paul Brook | hw_error("%s: FIXME: bad SPI word width %i\n", __FUNCTION__, len);
|
944 | e927bb00 | balrog | |
945 | a5d7eb65 | balrog | /* TODO: sequential reads etc - how do we make sure the host doesn't
|
946 | a5d7eb65 | balrog | * unintentionally read out a conversion result from a register while
|
947 | a5d7eb65 | balrog | * transmitting the command word of the next command? */
|
948 | a5d7eb65 | balrog | if (!value || (s->state && s->command))
|
949 | a5d7eb65 | balrog | ret = tsc210x_read(s); |
950 | a5d7eb65 | balrog | if (value || (s->state && !s->command))
|
951 | a5d7eb65 | balrog | tsc210x_write(s, value); |
952 | a5d7eb65 | balrog | |
953 | a5d7eb65 | balrog | return ret;
|
954 | a5d7eb65 | balrog | } |
955 | a5d7eb65 | balrog | |
956 | 3efda49d | balrog | static void tsc210x_timer_tick(void *opaque) |
957 | 3efda49d | balrog | { |
958 | bc24a225 | Paul Brook | TSC210xState *s = opaque; |
959 | 3efda49d | balrog | |
960 | 3efda49d | balrog | /* Timer ticked -- a set of conversions has been finished. */
|
961 | 3efda49d | balrog | |
962 | 3efda49d | balrog | if (!s->busy)
|
963 | 3efda49d | balrog | return;
|
964 | 3efda49d | balrog | |
965 | 3efda49d | balrog | s->busy = 0;
|
966 | 3efda49d | balrog | s->dav |= mode_regs[s->function]; |
967 | 3efda49d | balrog | tsc210x_pin_update(s); |
968 | a5d7eb65 | balrog | qemu_irq_lower(s->davint); |
969 | 3efda49d | balrog | } |
970 | 3efda49d | balrog | |
971 | 3efda49d | balrog | static void tsc210x_touchscreen_event(void *opaque, |
972 | 3efda49d | balrog | int x, int y, int z, int buttons_state) |
973 | 3efda49d | balrog | { |
974 | bc24a225 | Paul Brook | TSC210xState *s = opaque; |
975 | 3efda49d | balrog | int p = s->pressure;
|
976 | 3efda49d | balrog | |
977 | 3efda49d | balrog | if (buttons_state) {
|
978 | 3efda49d | balrog | s->x = x; |
979 | 3efda49d | balrog | s->y = y; |
980 | 3efda49d | balrog | } |
981 | 3efda49d | balrog | s->pressure = !!buttons_state; |
982 | 3efda49d | balrog | |
983 | 3efda49d | balrog | /*
|
984 | 3efda49d | balrog | * Note: We would get better responsiveness in the guest by
|
985 | 3efda49d | balrog | * signaling TS events immediately, but for now we simulate
|
986 | 3efda49d | balrog | * the first conversion delay for sake of correctness.
|
987 | 3efda49d | balrog | */
|
988 | 3efda49d | balrog | if (p != s->pressure)
|
989 | 3efda49d | balrog | tsc210x_pin_update(s); |
990 | 3efda49d | balrog | } |
991 | 3efda49d | balrog | |
992 | bc24a225 | Paul Brook | static void tsc210x_i2s_swallow(TSC210xState *s) |
993 | d8f699cb | balrog | { |
994 | d8f699cb | balrog | if (s->dac_voice[0]) |
995 | d8f699cb | balrog | tsc210x_out_flush(s, s->codec.out.len); |
996 | d8f699cb | balrog | else
|
997 | d8f699cb | balrog | s->codec.out.len = 0;
|
998 | d8f699cb | balrog | } |
999 | d8f699cb | balrog | |
1000 | bc24a225 | Paul Brook | static void tsc210x_i2s_set_rate(TSC210xState *s, int in, int out) |
1001 | d8f699cb | balrog | { |
1002 | d8f699cb | balrog | s->i2s_tx_rate = out; |
1003 | d8f699cb | balrog | s->i2s_rx_rate = in; |
1004 | d8f699cb | balrog | } |
1005 | d8f699cb | balrog | |
1006 | 3efda49d | balrog | static void tsc210x_save(QEMUFile *f, void *opaque) |
1007 | 3efda49d | balrog | { |
1008 | bc24a225 | Paul Brook | TSC210xState *s = (TSC210xState *) opaque; |
1009 | 3efda49d | balrog | int64_t now = qemu_get_clock(vm_clock); |
1010 | 3efda49d | balrog | int i;
|
1011 | 3efda49d | balrog | |
1012 | 3efda49d | balrog | qemu_put_be16(f, s->x); |
1013 | 3efda49d | balrog | qemu_put_be16(f, s->y); |
1014 | 3efda49d | balrog | qemu_put_byte(f, s->pressure); |
1015 | 3efda49d | balrog | |
1016 | 3efda49d | balrog | qemu_put_byte(f, s->state); |
1017 | 3efda49d | balrog | qemu_put_byte(f, s->page); |
1018 | 3efda49d | balrog | qemu_put_byte(f, s->offset); |
1019 | 3efda49d | balrog | qemu_put_byte(f, s->command); |
1020 | 3efda49d | balrog | |
1021 | 3efda49d | balrog | qemu_put_byte(f, s->irq); |
1022 | 3efda49d | balrog | qemu_put_be16s(f, &s->dav); |
1023 | 3efda49d | balrog | |
1024 | 3efda49d | balrog | qemu_put_timer(f, s->timer); |
1025 | 3efda49d | balrog | qemu_put_byte(f, s->enabled); |
1026 | 3efda49d | balrog | qemu_put_byte(f, s->host_mode); |
1027 | 3efda49d | balrog | qemu_put_byte(f, s->function); |
1028 | 3efda49d | balrog | qemu_put_byte(f, s->nextfunction); |
1029 | 3efda49d | balrog | qemu_put_byte(f, s->precision); |
1030 | 3efda49d | balrog | qemu_put_byte(f, s->nextprecision); |
1031 | 3efda49d | balrog | qemu_put_byte(f, s->filter); |
1032 | 3efda49d | balrog | qemu_put_byte(f, s->pin_func); |
1033 | 3efda49d | balrog | qemu_put_byte(f, s->ref); |
1034 | 3efda49d | balrog | qemu_put_byte(f, s->timing); |
1035 | 3efda49d | balrog | qemu_put_be32(f, s->noise); |
1036 | 3efda49d | balrog | |
1037 | 3efda49d | balrog | qemu_put_be16s(f, &s->audio_ctrl1); |
1038 | 3efda49d | balrog | qemu_put_be16s(f, &s->audio_ctrl2); |
1039 | 3efda49d | balrog | qemu_put_be16s(f, &s->audio_ctrl3); |
1040 | 3efda49d | balrog | qemu_put_be16s(f, &s->pll[0]);
|
1041 | 3efda49d | balrog | qemu_put_be16s(f, &s->pll[1]);
|
1042 | 3efda49d | balrog | qemu_put_be16s(f, &s->volume); |
1043 | b6c4f71f | blueswir1 | qemu_put_sbe64(f, (s->volume_change - now)); |
1044 | b6c4f71f | blueswir1 | qemu_put_sbe64(f, (s->powerdown - now)); |
1045 | 3efda49d | balrog | qemu_put_byte(f, s->softstep); |
1046 | 3efda49d | balrog | qemu_put_be16s(f, &s->dac_power); |
1047 | 3efda49d | balrog | |
1048 | 3efda49d | balrog | for (i = 0; i < 0x14; i ++) |
1049 | 3efda49d | balrog | qemu_put_be16s(f, &s->filter_data[i]); |
1050 | 3efda49d | balrog | } |
1051 | 3efda49d | balrog | |
1052 | 3efda49d | balrog | static int tsc210x_load(QEMUFile *f, void *opaque, int version_id) |
1053 | 3efda49d | balrog | { |
1054 | bc24a225 | Paul Brook | TSC210xState *s = (TSC210xState *) opaque; |
1055 | 3efda49d | balrog | int64_t now = qemu_get_clock(vm_clock); |
1056 | 3efda49d | balrog | int i;
|
1057 | 3efda49d | balrog | |
1058 | 3efda49d | balrog | s->x = qemu_get_be16(f); |
1059 | 3efda49d | balrog | s->y = qemu_get_be16(f); |
1060 | 3efda49d | balrog | s->pressure = qemu_get_byte(f); |
1061 | 3efda49d | balrog | |
1062 | 3efda49d | balrog | s->state = qemu_get_byte(f); |
1063 | 3efda49d | balrog | s->page = qemu_get_byte(f); |
1064 | 3efda49d | balrog | s->offset = qemu_get_byte(f); |
1065 | 3efda49d | balrog | s->command = qemu_get_byte(f); |
1066 | 3efda49d | balrog | |
1067 | 3efda49d | balrog | s->irq = qemu_get_byte(f); |
1068 | 3efda49d | balrog | qemu_get_be16s(f, &s->dav); |
1069 | 3efda49d | balrog | |
1070 | 3efda49d | balrog | qemu_get_timer(f, s->timer); |
1071 | 3efda49d | balrog | s->enabled = qemu_get_byte(f); |
1072 | 3efda49d | balrog | s->host_mode = qemu_get_byte(f); |
1073 | 3efda49d | balrog | s->function = qemu_get_byte(f); |
1074 | 3efda49d | balrog | s->nextfunction = qemu_get_byte(f); |
1075 | 3efda49d | balrog | s->precision = qemu_get_byte(f); |
1076 | 3efda49d | balrog | s->nextprecision = qemu_get_byte(f); |
1077 | 3efda49d | balrog | s->filter = qemu_get_byte(f); |
1078 | 3efda49d | balrog | s->pin_func = qemu_get_byte(f); |
1079 | 3efda49d | balrog | s->ref = qemu_get_byte(f); |
1080 | 3efda49d | balrog | s->timing = qemu_get_byte(f); |
1081 | 3efda49d | balrog | s->noise = qemu_get_be32(f); |
1082 | 3efda49d | balrog | |
1083 | 3efda49d | balrog | qemu_get_be16s(f, &s->audio_ctrl1); |
1084 | 3efda49d | balrog | qemu_get_be16s(f, &s->audio_ctrl2); |
1085 | 3efda49d | balrog | qemu_get_be16s(f, &s->audio_ctrl3); |
1086 | 3efda49d | balrog | qemu_get_be16s(f, &s->pll[0]);
|
1087 | 3efda49d | balrog | qemu_get_be16s(f, &s->pll[1]);
|
1088 | 3efda49d | balrog | qemu_get_be16s(f, &s->volume); |
1089 | b6c4f71f | blueswir1 | s->volume_change = qemu_get_sbe64(f) + now; |
1090 | b6c4f71f | blueswir1 | s->powerdown = qemu_get_sbe64(f) + now; |
1091 | 3efda49d | balrog | s->softstep = qemu_get_byte(f); |
1092 | 3efda49d | balrog | qemu_get_be16s(f, &s->dac_power); |
1093 | 3efda49d | balrog | |
1094 | 3efda49d | balrog | for (i = 0; i < 0x14; i ++) |
1095 | 3efda49d | balrog | qemu_get_be16s(f, &s->filter_data[i]); |
1096 | 3efda49d | balrog | |
1097 | 3efda49d | balrog | s->busy = qemu_timer_pending(s->timer); |
1098 | 7fc42b4b | balrog | qemu_set_irq(s->pint, !s->irq); |
1099 | a5d7eb65 | balrog | qemu_set_irq(s->davint, !s->dav); |
1100 | 3efda49d | balrog | |
1101 | 3efda49d | balrog | return 0; |
1102 | 3efda49d | balrog | } |
1103 | 3efda49d | balrog | |
1104 | 22d83b14 | Paul Brook | uWireSlave *tsc2102_init(qemu_irq pint) |
1105 | 3efda49d | balrog | { |
1106 | bc24a225 | Paul Brook | TSC210xState *s; |
1107 | 3efda49d | balrog | |
1108 | bc24a225 | Paul Brook | s = (TSC210xState *) |
1109 | bc24a225 | Paul Brook | qemu_mallocz(sizeof(TSC210xState));
|
1110 | bc24a225 | Paul Brook | memset(s, 0, sizeof(TSC210xState)); |
1111 | 3efda49d | balrog | s->x = 160;
|
1112 | 3efda49d | balrog | s->y = 160;
|
1113 | 3efda49d | balrog | s->pressure = 0;
|
1114 | 3efda49d | balrog | s->precision = s->nextprecision = 0;
|
1115 | 3efda49d | balrog | s->timer = qemu_new_timer(vm_clock, tsc210x_timer_tick, s); |
1116 | 3efda49d | balrog | s->pint = pint; |
1117 | a5d7eb65 | balrog | s->model = 0x2102;
|
1118 | d8f699cb | balrog | s->name = "tsc2102";
|
1119 | 3efda49d | balrog | |
1120 | a5d7eb65 | balrog | s->tr[0] = 0; |
1121 | a5d7eb65 | balrog | s->tr[1] = 1; |
1122 | e927bb00 | balrog | s->tr[2] = 1; |
1123 | e927bb00 | balrog | s->tr[3] = 0; |
1124 | a5d7eb65 | balrog | s->tr[4] = 1; |
1125 | a5d7eb65 | balrog | s->tr[5] = 0; |
1126 | e927bb00 | balrog | s->tr[6] = 1; |
1127 | e927bb00 | balrog | s->tr[7] = 0; |
1128 | a5d7eb65 | balrog | |
1129 | 3efda49d | balrog | s->chip.opaque = s; |
1130 | 3efda49d | balrog | s->chip.send = (void *) tsc210x_write;
|
1131 | 3efda49d | balrog | s->chip.receive = (void *) tsc210x_read;
|
1132 | 3efda49d | balrog | |
1133 | d8f699cb | balrog | s->codec.opaque = s; |
1134 | d8f699cb | balrog | s->codec.tx_swallow = (void *) tsc210x_i2s_swallow;
|
1135 | d8f699cb | balrog | s->codec.set_rate = (void *) tsc210x_i2s_set_rate;
|
1136 | d8f699cb | balrog | s->codec.in.fifo = s->in_fifo; |
1137 | d8f699cb | balrog | s->codec.out.fifo = s->out_fifo; |
1138 | d8f699cb | balrog | |
1139 | 3efda49d | balrog | tsc210x_reset(s); |
1140 | 3efda49d | balrog | |
1141 | 3efda49d | balrog | qemu_add_mouse_event_handler(tsc210x_touchscreen_event, s, 1,
|
1142 | 3efda49d | balrog | "QEMU TSC2102-driven Touchscreen");
|
1143 | 3efda49d | balrog | |
1144 | 1a7dafce | malc | AUD_register_card(s->name, &s->card); |
1145 | d8f699cb | balrog | |
1146 | 8217606e | Jan Kiszka | qemu_register_reset((void *) tsc210x_reset, 0, s); |
1147 | 18be5187 | pbrook | register_savevm(s->name, -1, 0, |
1148 | 3efda49d | balrog | tsc210x_save, tsc210x_load, s); |
1149 | 3efda49d | balrog | |
1150 | 3efda49d | balrog | return &s->chip;
|
1151 | 3efda49d | balrog | } |
1152 | d8f699cb | balrog | |
1153 | 22d83b14 | Paul Brook | uWireSlave *tsc2301_init(qemu_irq penirq, qemu_irq kbirq, qemu_irq dav) |
1154 | a5d7eb65 | balrog | { |
1155 | bc24a225 | Paul Brook | TSC210xState *s; |
1156 | a5d7eb65 | balrog | |
1157 | bc24a225 | Paul Brook | s = (TSC210xState *) |
1158 | bc24a225 | Paul Brook | qemu_mallocz(sizeof(TSC210xState));
|
1159 | bc24a225 | Paul Brook | memset(s, 0, sizeof(TSC210xState)); |
1160 | a5d7eb65 | balrog | s->x = 400;
|
1161 | a5d7eb65 | balrog | s->y = 240;
|
1162 | a5d7eb65 | balrog | s->pressure = 0;
|
1163 | a5d7eb65 | balrog | s->precision = s->nextprecision = 0;
|
1164 | a5d7eb65 | balrog | s->timer = qemu_new_timer(vm_clock, tsc210x_timer_tick, s); |
1165 | a5d7eb65 | balrog | s->pint = penirq; |
1166 | a5d7eb65 | balrog | s->kbint = kbirq; |
1167 | a5d7eb65 | balrog | s->davint = dav; |
1168 | a5d7eb65 | balrog | s->model = 0x2301;
|
1169 | a5d7eb65 | balrog | s->name = "tsc2301";
|
1170 | a5d7eb65 | balrog | |
1171 | a5d7eb65 | balrog | s->tr[0] = 0; |
1172 | a5d7eb65 | balrog | s->tr[1] = 1; |
1173 | e927bb00 | balrog | s->tr[2] = 1; |
1174 | e927bb00 | balrog | s->tr[3] = 0; |
1175 | a5d7eb65 | balrog | s->tr[4] = 1; |
1176 | a5d7eb65 | balrog | s->tr[5] = 0; |
1177 | e927bb00 | balrog | s->tr[6] = 1; |
1178 | e927bb00 | balrog | s->tr[7] = 0; |
1179 | a5d7eb65 | balrog | |
1180 | a5d7eb65 | balrog | s->chip.opaque = s; |
1181 | a5d7eb65 | balrog | s->chip.send = (void *) tsc210x_write;
|
1182 | a5d7eb65 | balrog | s->chip.receive = (void *) tsc210x_read;
|
1183 | a5d7eb65 | balrog | |
1184 | a5d7eb65 | balrog | s->codec.opaque = s; |
1185 | a5d7eb65 | balrog | s->codec.tx_swallow = (void *) tsc210x_i2s_swallow;
|
1186 | a5d7eb65 | balrog | s->codec.set_rate = (void *) tsc210x_i2s_set_rate;
|
1187 | a5d7eb65 | balrog | s->codec.in.fifo = s->in_fifo; |
1188 | a5d7eb65 | balrog | s->codec.out.fifo = s->out_fifo; |
1189 | a5d7eb65 | balrog | |
1190 | a5d7eb65 | balrog | tsc210x_reset(s); |
1191 | a5d7eb65 | balrog | |
1192 | a5d7eb65 | balrog | qemu_add_mouse_event_handler(tsc210x_touchscreen_event, s, 1,
|
1193 | a5d7eb65 | balrog | "QEMU TSC2301-driven Touchscreen");
|
1194 | a5d7eb65 | balrog | |
1195 | 1a7dafce | malc | AUD_register_card(s->name, &s->card); |
1196 | a5d7eb65 | balrog | |
1197 | 8217606e | Jan Kiszka | qemu_register_reset((void *) tsc210x_reset, 0, s); |
1198 | 18be5187 | pbrook | register_savevm(s->name, -1, 0, tsc210x_save, tsc210x_load, s); |
1199 | a5d7eb65 | balrog | |
1200 | a5d7eb65 | balrog | return &s->chip;
|
1201 | a5d7eb65 | balrog | } |
1202 | a5d7eb65 | balrog | |
1203 | bc24a225 | Paul Brook | I2SCodec *tsc210x_codec(uWireSlave *chip) |
1204 | d8f699cb | balrog | { |
1205 | bc24a225 | Paul Brook | TSC210xState *s = (TSC210xState *) chip->opaque; |
1206 | d8f699cb | balrog | |
1207 | d8f699cb | balrog | return &s->codec;
|
1208 | d8f699cb | balrog | } |
1209 | a5d7eb65 | balrog | |
1210 | a5d7eb65 | balrog | /*
|
1211 | a5d7eb65 | balrog | * Use tslib generated calibration data to generate ADC input values
|
1212 | a5d7eb65 | balrog | * from the touchscreen. Assuming 12-bit precision was used during
|
1213 | a5d7eb65 | balrog | * tslib calibration.
|
1214 | a5d7eb65 | balrog | */
|
1215 | bc24a225 | Paul Brook | void tsc210x_set_transform(uWireSlave *chip,
|
1216 | bc24a225 | Paul Brook | MouseTransformInfo *info) |
1217 | a5d7eb65 | balrog | { |
1218 | bc24a225 | Paul Brook | TSC210xState *s = (TSC210xState *) chip->opaque; |
1219 | a5d7eb65 | balrog | #if 0
|
1220 | a5d7eb65 | balrog | int64_t ltr[8];
|
1221 | a5d7eb65 | balrog | |
1222 | a5d7eb65 | balrog | ltr[0] = (int64_t) info->a[1] * info->y;
|
1223 | a5d7eb65 | balrog | ltr[1] = (int64_t) info->a[4] * info->x;
|
1224 | a5d7eb65 | balrog | ltr[2] = (int64_t) info->a[1] * info->a[3] -
|
1225 | a5d7eb65 | balrog | (int64_t) info->a[4] * info->a[0];
|
1226 | a5d7eb65 | balrog | ltr[3] = (int64_t) info->a[2] * info->a[4] -
|
1227 | a5d7eb65 | balrog | (int64_t) info->a[5] * info->a[1];
|
1228 | a5d7eb65 | balrog | ltr[4] = (int64_t) info->a[0] * info->y;
|
1229 | a5d7eb65 | balrog | ltr[5] = (int64_t) info->a[3] * info->x;
|
1230 | a5d7eb65 | balrog | ltr[6] = (int64_t) info->a[4] * info->a[0] -
|
1231 | a5d7eb65 | balrog | (int64_t) info->a[1] * info->a[3];
|
1232 | a5d7eb65 | balrog | ltr[7] = (int64_t) info->a[2] * info->a[3] -
|
1233 | a5d7eb65 | balrog | (int64_t) info->a[5] * info->a[0];
|
1234 | a5d7eb65 | balrog | |
1235 | a5d7eb65 | balrog | /* Avoid integer overflow */
|
1236 | a5d7eb65 | balrog | s->tr[0] = ltr[0] >> 11;
|
1237 | a5d7eb65 | balrog | s->tr[1] = ltr[1] >> 11;
|
1238 | a5d7eb65 | balrog | s->tr[2] = muldiv64(ltr[2], 1, info->a[6]);
|
1239 | a5d7eb65 | balrog | s->tr[3] = muldiv64(ltr[3], 1 << 4, ltr[2]);
|
1240 | a5d7eb65 | balrog | s->tr[4] = ltr[4] >> 11;
|
1241 | a5d7eb65 | balrog | s->tr[5] = ltr[5] >> 11;
|
1242 | a5d7eb65 | balrog | s->tr[6] = muldiv64(ltr[6], 1, info->a[6]);
|
1243 | a5d7eb65 | balrog | s->tr[7] = muldiv64(ltr[7], 1 << 4, ltr[6]);
|
1244 | a5d7eb65 | balrog | #else
|
1245 | a5d7eb65 | balrog | |
1246 | a5d7eb65 | balrog | /* This version assumes touchscreen X & Y axis are parallel or
|
1247 | a5d7eb65 | balrog | * perpendicular to LCD's X & Y axis in some way. */
|
1248 | a5d7eb65 | balrog | if (abs(info->a[0]) > abs(info->a[1])) { |
1249 | a5d7eb65 | balrog | s->tr[0] = 0; |
1250 | a5d7eb65 | balrog | s->tr[1] = -info->a[6] * info->x; |
1251 | a5d7eb65 | balrog | s->tr[2] = info->a[0]; |
1252 | a5d7eb65 | balrog | s->tr[3] = -info->a[2] / info->a[0]; |
1253 | a5d7eb65 | balrog | s->tr[4] = info->a[6] * info->y; |
1254 | a5d7eb65 | balrog | s->tr[5] = 0; |
1255 | a5d7eb65 | balrog | s->tr[6] = info->a[4]; |
1256 | a5d7eb65 | balrog | s->tr[7] = -info->a[5] / info->a[4]; |
1257 | a5d7eb65 | balrog | } else {
|
1258 | a5d7eb65 | balrog | s->tr[0] = info->a[6] * info->y; |
1259 | a5d7eb65 | balrog | s->tr[1] = 0; |
1260 | a5d7eb65 | balrog | s->tr[2] = info->a[1]; |
1261 | a5d7eb65 | balrog | s->tr[3] = -info->a[2] / info->a[1]; |
1262 | a5d7eb65 | balrog | s->tr[4] = 0; |
1263 | a5d7eb65 | balrog | s->tr[5] = -info->a[6] * info->x; |
1264 | a5d7eb65 | balrog | s->tr[6] = info->a[3]; |
1265 | a5d7eb65 | balrog | s->tr[7] = -info->a[5] / info->a[3]; |
1266 | a5d7eb65 | balrog | } |
1267 | a5d7eb65 | balrog | |
1268 | a5d7eb65 | balrog | s->tr[0] >>= 11; |
1269 | a5d7eb65 | balrog | s->tr[1] >>= 11; |
1270 | a5d7eb65 | balrog | s->tr[3] <<= 4; |
1271 | a5d7eb65 | balrog | s->tr[4] >>= 11; |
1272 | a5d7eb65 | balrog | s->tr[5] >>= 11; |
1273 | a5d7eb65 | balrog | s->tr[7] <<= 4; |
1274 | a5d7eb65 | balrog | #endif
|
1275 | a5d7eb65 | balrog | } |
1276 | a5d7eb65 | balrog | |
1277 | bc24a225 | Paul Brook | void tsc210x_key_event(uWireSlave *chip, int key, int down) |
1278 | a5d7eb65 | balrog | { |
1279 | bc24a225 | Paul Brook | TSC210xState *s = (TSC210xState *) chip->opaque; |
1280 | a5d7eb65 | balrog | |
1281 | a5d7eb65 | balrog | if (down)
|
1282 | a5d7eb65 | balrog | s->kb.down |= 1 << key;
|
1283 | a5d7eb65 | balrog | else
|
1284 | a5d7eb65 | balrog | s->kb.down &= ~(1 << key);
|
1285 | a5d7eb65 | balrog | |
1286 | a5d7eb65 | balrog | if (down && (s->kb.down & ~s->kb.mask) && !s->kb.intr) {
|
1287 | a5d7eb65 | balrog | s->kb.intr = 1;
|
1288 | a5d7eb65 | balrog | qemu_irq_lower(s->kbint); |
1289 | a5d7eb65 | balrog | } else if (s->kb.intr && !(s->kb.down & ~s->kb.mask) && |
1290 | a5d7eb65 | balrog | !(s->kb.mode & 1)) {
|
1291 | a5d7eb65 | balrog | s->kb.intr = 0;
|
1292 | a5d7eb65 | balrog | qemu_irq_raise(s->kbint); |
1293 | a5d7eb65 | balrog | } |
1294 | a5d7eb65 | balrog | } |