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