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