2 * TI TSC2102 (touchscreen/sensors/audio controller) emulator.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 #include "audio/audio.h"
24 #include "qemu-timer.h"
28 #define TSC_DATA_REGISTERS_PAGE 0x0
29 #define TSC_CONTROL_REGISTERS_PAGE 0x1
30 #define TSC_AUDIO_REGISTERS_PAGE 0x2
34 #define TSC_CUT_RESOLUTION(value, p) ((value) >> (16 - resolution[p]))
36 struct tsc210x_state_s {
40 struct uwire_slave_s chip;
41 struct i2s_codec_s codec;
42 uint8_t in_fifo[16384];
43 uint8_t out_fifo[16384];
48 int state, page, offset, irq;
49 uint16_t command, dav;
69 int64_t volume_change;
73 uint16_t filter_data[0x14];
76 SWVoiceIn *adc_voice[1];
77 SWVoiceOut *dac_voice[1];
83 static const int resolution[4] = { 12, 8, 10, 12 };
85 #define TSC_MODE_NO_SCAN 0x0
86 #define TSC_MODE_XY_SCAN 0x1
87 #define TSC_MODE_XYZ_SCAN 0x2
88 #define TSC_MODE_X 0x3
89 #define TSC_MODE_Y 0x4
90 #define TSC_MODE_Z 0x5
91 #define TSC_MODE_BAT1 0x6
92 #define TSC_MODE_BAT2 0x7
93 #define TSC_MODE_AUX 0x8
94 #define TSC_MODE_AUX_SCAN 0x9
95 #define TSC_MODE_TEMP1 0xa
96 #define TSC_MODE_PORT_SCAN 0xb
97 #define TSC_MODE_TEMP2 0xc
98 #define TSC_MODE_XX_DRV 0xd
99 #define TSC_MODE_YY_DRV 0xe
100 #define TSC_MODE_YX_DRV 0xf
102 static const uint16_t mode_regs[16] = {
103 0x0000, /* No scan */
104 0x0600, /* X, Y scan */
105 0x0780, /* X, Y, Z scan */
112 0x0010, /* AUX scan */
114 0x0070, /* Port scan */
116 0x0000, /* X+, X- drivers */
117 0x0000, /* Y+, Y- drivers */
118 0x0000, /* Y+, X- drivers */
122 * Convert screen coordinates to arbitrary values that the
123 * touchscreen in my Palm Tungsten E device returns.
124 * This shouldn't really matter (because the guest system
125 * should calibrate the touchscreen anyway), but let's
126 * imitate some real hardware.
128 #define X_TRANSFORM(value) \
129 ((3850 - ((int) (value) * (3850 - 250) / 32768)) << 4)
130 #define Y_TRANSFORM(value) \
131 ((150 + ((int) (value) * (3037 - 150) / 32768)) << 4)
132 #define Z1_TRANSFORM(s) \
133 ((400 - ((s)->x >> 7) + ((s)->pressure << 10)) << 4)
134 #define Z2_TRANSFORM(s) \
135 ((4000 + ((s)->y >> 7) - ((s)->pressure << 10)) << 4)
137 #define BAT1_VAL 0x8660
138 #define BAT2_VAL 0x0000
139 #define AUX1_VAL 0x35c0
140 #define AUX2_VAL 0xffff
141 #define TEMP1_VAL 0x8c70
142 #define TEMP2_VAL 0xa5b0
144 #define TSC_POWEROFF_DELAY 50
145 #define TSC_SOFTSTEP_DELAY 50
147 static void tsc210x_reset(struct tsc210x_state_s *s)
159 s->audio_ctrl1 = 0x0000;
160 s->audio_ctrl2 = 0x4410;
161 s->audio_ctrl3 = 0x0000;
165 s->dac_power = 0x8540;
167 s->volume_change = 0;
169 s->filter_data[0x00] = 0x6be3;
170 s->filter_data[0x01] = 0x9666;
171 s->filter_data[0x02] = 0x675d;
172 s->filter_data[0x03] = 0x6be3;
173 s->filter_data[0x04] = 0x9666;
174 s->filter_data[0x05] = 0x675d;
175 s->filter_data[0x06] = 0x7d83;
176 s->filter_data[0x07] = 0x84ee;
177 s->filter_data[0x08] = 0x7d83;
178 s->filter_data[0x09] = 0x84ee;
179 s->filter_data[0x0a] = 0x6be3;
180 s->filter_data[0x0b] = 0x9666;
181 s->filter_data[0x0c] = 0x675d;
182 s->filter_data[0x0d] = 0x6be3;
183 s->filter_data[0x0e] = 0x9666;
184 s->filter_data[0x0f] = 0x675d;
185 s->filter_data[0x10] = 0x7d83;
186 s->filter_data[0x11] = 0x84ee;
187 s->filter_data[0x12] = 0x7d83;
188 s->filter_data[0x13] = 0x84ee;
193 qemu_set_irq(s->pint, !s->irq);
196 struct tsc210x_rate_info_s {
202 /* { rate, dsor, fsref } */
203 static const struct tsc210x_rate_info_s tsc2101_rates[] = {
232 /* { rate, dsor, fsref } */
233 static const struct tsc210x_rate_info_s tsc2102_rates[] = {
262 static inline void tsc210x_out_flush(struct tsc210x_state_s *s, int len)
264 uint8_t *data = s->codec.out.fifo + s->codec.out.start;
265 uint8_t *end = data + len;
268 data += AUD_write(s->dac_voice[0], data, end - data) ?: (end - data);
270 s->codec.out.len -= len;
271 if (s->codec.out.len)
272 memmove(s->codec.out.fifo, end, s->codec.out.len);
273 s->codec.out.start = 0;
276 static void tsc210x_audio_out_cb(struct tsc210x_state_s *s, int free_b)
278 if (s->codec.out.len >= free_b) {
279 tsc210x_out_flush(s, free_b);
283 s->codec.out.size = MIN(free_b, 16384);
284 qemu_irq_raise(s->codec.tx_start);
287 static void tsc2102_audio_rate_update(struct tsc210x_state_s *s)
289 const struct tsc210x_rate_info_s *rate;
291 s->codec.tx_rate = 0;
292 s->codec.rx_rate = 0;
293 if (s->dac_power & (1 << 15)) /* PWDNC */
296 for (rate = tsc2102_rates; rate->rate; rate ++)
297 if (rate->dsor == (s->audio_ctrl1 & 0x3f) && /* DACFS */
298 rate->fsref == ((s->audio_ctrl3 >> 13) & 1))/* REFFS */
301 printf("%s: unknown sampling rate configured\n", __FUNCTION__);
305 s->codec.tx_rate = rate->rate;
308 static void tsc2102_audio_output_update(struct tsc210x_state_s *s)
313 if (s->dac_voice[0]) {
314 tsc210x_out_flush(s, s->codec.out.len);
315 s->codec.out.size = 0;
316 AUD_set_active_out(s->dac_voice[0], 0);
317 AUD_close_out(&s->card, s->dac_voice[0]);
323 (~s->dac_power & (1 << 15)) && /* PWDNC */
324 (~s->dac_power & (1 << 10)); /* DAPWDN */
325 if (!enable || !s->codec.tx_rate)
328 /* Force our own sampling rate even in slave DAC mode */
331 fmt.freq = s->codec.tx_rate;
332 fmt.fmt = AUD_FMT_S16;
334 s->dac_voice[0] = AUD_open_out(&s->card, s->dac_voice[0],
335 "tsc2102.sink", s, (void *) tsc210x_audio_out_cb, &fmt);
336 if (s->dac_voice[0]) {
338 AUD_set_active_out(s->dac_voice[0], 1);
342 static uint16_t tsc2102_data_register_read(struct tsc210x_state_s *s, int reg)
347 return TSC_CUT_RESOLUTION(X_TRANSFORM(s->x), s->precision) +
353 return TSC_CUT_RESOLUTION(Y_TRANSFORM(s->y), s->precision) ^
358 return TSC_CUT_RESOLUTION(Z1_TRANSFORM(s), s->precision) -
363 return TSC_CUT_RESOLUTION(Z2_TRANSFORM(s), s->precision) |
366 case 0x04: /* KPData */
369 case 0x05: /* BAT1 */
371 return TSC_CUT_RESOLUTION(BAT1_VAL, s->precision) +
374 case 0x06: /* BAT2 */
376 return TSC_CUT_RESOLUTION(BAT2_VAL, s->precision);
378 case 0x07: /* AUX1 */
380 return TSC_CUT_RESOLUTION(AUX1_VAL, s->precision);
382 case 0x08: /* AUX2 */
386 case 0x09: /* TEMP1 */
388 return TSC_CUT_RESOLUTION(TEMP1_VAL, s->precision) -
391 case 0x0a: /* TEMP2 */
393 return TSC_CUT_RESOLUTION(TEMP2_VAL, s->precision) ^
402 fprintf(stderr, "tsc2102_data_register_read: "
403 "no such register: 0x%02x\n", reg);
409 static uint16_t tsc2102_control_register_read(
410 struct tsc210x_state_s *s, int reg)
413 case 0x00: /* TSC ADC */
414 return (s->pressure << 15) | ((!s->busy) << 14) |
415 (s->nextfunction << 10) | (s->nextprecision << 8) | s->filter;
417 case 0x01: /* Status */
418 return (s->pin_func << 14) | ((!s->enabled) << 13) |
419 (s->host_mode << 12) | ((!!s->dav) << 11) | s->dav;
421 case 0x03: /* Reference */
424 case 0x04: /* Reset */
427 case 0x05: /* Configuration */
432 fprintf(stderr, "tsc2102_control_register_read: "
433 "no such register: 0x%02x\n", reg);
439 static uint16_t tsc2102_audio_register_read(struct tsc210x_state_s *s, int reg)
445 case 0x00: /* Audio Control 1 */
446 return s->audio_ctrl1;
451 case 0x02: /* DAC Volume Control */
457 case 0x04: /* Audio Control 2 */
460 if (s->softstep && !(s->dac_power & (1 << 10))) {
461 l_ch = (qemu_get_clock(vm_clock) >
462 s->volume_change + TSC_SOFTSTEP_DELAY);
463 r_ch = (qemu_get_clock(vm_clock) >
464 s->volume_change + TSC_SOFTSTEP_DELAY);
467 return s->audio_ctrl2 | (l_ch << 3) | (r_ch << 2);
469 case 0x05: /* Stereo DAC Power Control */
470 return 0x2aa0 | s->dac_power |
471 (((s->dac_power & (1 << 10)) &&
472 (qemu_get_clock(vm_clock) >
473 s->powerdown + TSC_POWEROFF_DELAY)) << 6);
475 case 0x06: /* Audio Control 3 */
476 val = s->audio_ctrl3 | 0x0001;
477 s->audio_ctrl3 &= 0xff3f;
480 case 0x07: /* LCH_BASS_BOOST_N0 */
481 case 0x08: /* LCH_BASS_BOOST_N1 */
482 case 0x09: /* LCH_BASS_BOOST_N2 */
483 case 0x0a: /* LCH_BASS_BOOST_N3 */
484 case 0x0b: /* LCH_BASS_BOOST_N4 */
485 case 0x0c: /* LCH_BASS_BOOST_N5 */
486 case 0x0d: /* LCH_BASS_BOOST_D1 */
487 case 0x0e: /* LCH_BASS_BOOST_D2 */
488 case 0x0f: /* LCH_BASS_BOOST_D4 */
489 case 0x10: /* LCH_BASS_BOOST_D5 */
490 case 0x11: /* RCH_BASS_BOOST_N0 */
491 case 0x12: /* RCH_BASS_BOOST_N1 */
492 case 0x13: /* RCH_BASS_BOOST_N2 */
493 case 0x14: /* RCH_BASS_BOOST_N3 */
494 case 0x15: /* RCH_BASS_BOOST_N4 */
495 case 0x16: /* RCH_BASS_BOOST_N5 */
496 case 0x17: /* RCH_BASS_BOOST_D1 */
497 case 0x18: /* RCH_BASS_BOOST_D2 */
498 case 0x19: /* RCH_BASS_BOOST_D4 */
499 case 0x1a: /* RCH_BASS_BOOST_D5 */
500 return s->filter_data[reg - 0x07];
502 case 0x1b: /* PLL Programmability 1 */
505 case 0x1c: /* PLL Programmability 2 */
508 case 0x1d: /* Audio Control 4 */
509 return (!s->softstep) << 14;
513 fprintf(stderr, "tsc2102_audio_register_read: "
514 "no such register: 0x%02x\n", reg);
520 static void tsc2102_data_register_write(
521 struct tsc210x_state_s *s, int reg, uint16_t value)
528 case 0x05: /* BAT1 */
529 case 0x06: /* BAT2 */
530 case 0x07: /* AUX1 */
531 case 0x08: /* AUX2 */
532 case 0x09: /* TEMP1 */
533 case 0x0a: /* TEMP2 */
538 fprintf(stderr, "tsc2102_data_register_write: "
539 "no such register: 0x%02x\n", reg);
544 static void tsc2102_control_register_write(
545 struct tsc210x_state_s *s, int reg, uint16_t value)
548 case 0x00: /* TSC ADC */
549 s->host_mode = value >> 15;
550 s->enabled = !(value & 0x4000);
551 if (s->busy && !s->enabled)
552 qemu_del_timer(s->timer);
553 s->busy &= s->enabled;
554 s->nextfunction = (value >> 10) & 0xf;
555 s->nextprecision = (value >> 8) & 3;
556 s->filter = value & 0xff;
559 case 0x01: /* Status */
560 s->pin_func = value >> 14;
563 case 0x03: /* Reference */
564 s->ref = value & 0x1f;
567 case 0x04: /* Reset */
568 if (value == 0xbb00) {
570 qemu_del_timer(s->timer);
574 fprintf(stderr, "tsc2102_control_register_write: "
575 "wrong value written into RESET\n");
580 case 0x05: /* Configuration */
581 s->timing = value & 0x3f;
584 fprintf(stderr, "tsc2102_control_register_write: "
585 "wrong value written into CONFIG\n");
591 fprintf(stderr, "tsc2102_control_register_write: "
592 "no such register: 0x%02x\n", reg);
597 static void tsc2102_audio_register_write(
598 struct tsc210x_state_s *s, int reg, uint16_t value)
601 case 0x00: /* Audio Control 1 */
602 s->audio_ctrl1 = value & 0x0f3f;
604 if ((value & ~0x0f3f) || ((value & 7) != ((value >> 3) & 7)))
605 fprintf(stderr, "tsc2102_audio_register_write: "
606 "wrong value written into Audio 1\n");
608 tsc2102_audio_rate_update(s);
610 tsc2102_audio_output_update(s);
616 fprintf(stderr, "tsc2102_audio_register_write: "
617 "wrong value written into reg 0x01\n");
621 case 0x02: /* DAC Volume Control */
623 s->volume_change = qemu_get_clock(vm_clock);
629 fprintf(stderr, "tsc2102_audio_register_write: "
630 "wrong value written into reg 0x03\n");
634 case 0x04: /* Audio Control 2 */
635 s->audio_ctrl2 = value & 0xf7f2;
638 fprintf(stderr, "tsc2102_audio_register_write: "
639 "wrong value written into Audio 2\n");
643 case 0x05: /* Stereo DAC Power Control */
644 if ((value & ~s->dac_power) & (1 << 10))
645 s->powerdown = qemu_get_clock(vm_clock);
647 s->dac_power = value & 0x9543;
649 if ((value & ~0x9543) != 0x2aa0)
650 fprintf(stderr, "tsc2102_audio_register_write: "
651 "wrong value written into Power\n");
653 tsc2102_audio_rate_update(s);
655 tsc2102_audio_output_update(s);
658 case 0x06: /* Audio Control 3 */
659 s->audio_ctrl3 &= 0x00c0;
660 s->audio_ctrl3 |= value & 0xf800;
663 fprintf(stderr, "tsc2102_audio_register_write: "
664 "wrong value written into Audio 3\n");
667 tsc2102_audio_output_update(s);
670 case 0x07: /* LCH_BASS_BOOST_N0 */
671 case 0x08: /* LCH_BASS_BOOST_N1 */
672 case 0x09: /* LCH_BASS_BOOST_N2 */
673 case 0x0a: /* LCH_BASS_BOOST_N3 */
674 case 0x0b: /* LCH_BASS_BOOST_N4 */
675 case 0x0c: /* LCH_BASS_BOOST_N5 */
676 case 0x0d: /* LCH_BASS_BOOST_D1 */
677 case 0x0e: /* LCH_BASS_BOOST_D2 */
678 case 0x0f: /* LCH_BASS_BOOST_D4 */
679 case 0x10: /* LCH_BASS_BOOST_D5 */
680 case 0x11: /* RCH_BASS_BOOST_N0 */
681 case 0x12: /* RCH_BASS_BOOST_N1 */
682 case 0x13: /* RCH_BASS_BOOST_N2 */
683 case 0x14: /* RCH_BASS_BOOST_N3 */
684 case 0x15: /* RCH_BASS_BOOST_N4 */
685 case 0x16: /* RCH_BASS_BOOST_N5 */
686 case 0x17: /* RCH_BASS_BOOST_D1 */
687 case 0x18: /* RCH_BASS_BOOST_D2 */
688 case 0x19: /* RCH_BASS_BOOST_D4 */
689 case 0x1a: /* RCH_BASS_BOOST_D5 */
690 s->filter_data[reg - 0x07] = value;
693 case 0x1b: /* PLL Programmability 1 */
694 s->pll[0] = value & 0xfffc;
697 fprintf(stderr, "tsc2102_audio_register_write: "
698 "wrong value written into PLL 1\n");
702 case 0x1c: /* PLL Programmability 2 */
703 s->pll[1] = value & 0xfffc;
706 fprintf(stderr, "tsc2102_audio_register_write: "
707 "wrong value written into PLL 2\n");
711 case 0x1d: /* Audio Control 4 */
712 s->softstep = !(value & 0x4000);
715 fprintf(stderr, "tsc2102_audio_register_write: "
716 "wrong value written into Audio 4\n");
722 fprintf(stderr, "tsc2102_audio_register_write: "
723 "no such register: 0x%02x\n", reg);
728 /* This handles most of the chip logic. */
729 static void tsc210x_pin_update(struct tsc210x_state_s *s)
734 switch (s->pin_func) {
736 pin_state = s->pressure;
739 pin_state = !!s->dav;
743 pin_state = s->pressure && !s->dav;
749 if (pin_state != s->irq) {
751 qemu_set_irq(s->pint, !s->irq);
754 switch (s->nextfunction) {
755 case TSC_MODE_XY_SCAN:
756 case TSC_MODE_XYZ_SCAN:
776 case TSC_MODE_AUX_SCAN:
777 case TSC_MODE_PORT_SCAN:
780 case TSC_MODE_NO_SCAN:
781 case TSC_MODE_XX_DRV:
782 case TSC_MODE_YY_DRV:
783 case TSC_MODE_YX_DRV:
788 if (!s->enabled || s->busy)
792 s->precision = s->nextprecision;
793 s->function = s->nextfunction;
794 expires = qemu_get_clock(vm_clock) + (ticks_per_sec >> 10);
795 qemu_mod_timer(s->timer, expires);
798 static uint16_t tsc210x_read(struct tsc210x_state_s *s)
800 uint16_t ret = 0x0000;
803 fprintf(stderr, "tsc210x_read: SPI underrun!\n");
806 case TSC_DATA_REGISTERS_PAGE:
807 ret = tsc2102_data_register_read(s, s->offset);
809 case TSC_CONTROL_REGISTERS_PAGE:
810 ret = tsc2102_control_register_read(s, s->offset);
812 case TSC_AUDIO_REGISTERS_PAGE:
813 ret = tsc2102_audio_register_read(s, s->offset);
816 cpu_abort(cpu_single_env, "tsc210x_read: wrong memory page\n");
819 tsc210x_pin_update(s);
821 /* Allow sequential reads. */
827 static void tsc210x_write(struct tsc210x_state_s *s, uint16_t value)
830 * This is a two-state state machine for reading
831 * command and data every second time.
834 s->command = value >> 15;
835 s->page = (value >> 11) & 0x0f;
836 s->offset = (value >> 5) & 0x3f;
840 fprintf(stderr, "tsc210x_write: SPI overrun!\n");
843 case TSC_DATA_REGISTERS_PAGE:
844 tsc2102_data_register_write(s, s->offset, value);
846 case TSC_CONTROL_REGISTERS_PAGE:
847 tsc2102_control_register_write(s, s->offset, value);
849 case TSC_AUDIO_REGISTERS_PAGE:
850 tsc2102_audio_register_write(s, s->offset, value);
853 cpu_abort(cpu_single_env,
854 "tsc210x_write: wrong memory page\n");
857 tsc210x_pin_update(s);
862 static void tsc210x_timer_tick(void *opaque)
864 struct tsc210x_state_s *s = opaque;
866 /* Timer ticked -- a set of conversions has been finished. */
872 s->dav |= mode_regs[s->function];
873 tsc210x_pin_update(s);
876 static void tsc210x_touchscreen_event(void *opaque,
877 int x, int y, int z, int buttons_state)
879 struct tsc210x_state_s *s = opaque;
886 s->pressure = !!buttons_state;
889 * Note: We would get better responsiveness in the guest by
890 * signaling TS events immediately, but for now we simulate
891 * the first conversion delay for sake of correctness.
893 if (p != s->pressure)
894 tsc210x_pin_update(s);
897 static void tsc210x_i2s_swallow(struct tsc210x_state_s *s)
900 tsc210x_out_flush(s, s->codec.out.len);
902 s->codec.out.len = 0;
905 static void tsc210x_i2s_set_rate(struct tsc210x_state_s *s, int in, int out)
907 s->i2s_tx_rate = out;
911 static void tsc210x_save(QEMUFile *f, void *opaque)
913 struct tsc210x_state_s *s = (struct tsc210x_state_s *) opaque;
914 int64_t now = qemu_get_clock(vm_clock);
917 qemu_put_be16(f, s->x);
918 qemu_put_be16(f, s->y);
919 qemu_put_byte(f, s->pressure);
921 qemu_put_byte(f, s->state);
922 qemu_put_byte(f, s->page);
923 qemu_put_byte(f, s->offset);
924 qemu_put_byte(f, s->command);
926 qemu_put_byte(f, s->irq);
927 qemu_put_be16s(f, &s->dav);
929 qemu_put_timer(f, s->timer);
930 qemu_put_byte(f, s->enabled);
931 qemu_put_byte(f, s->host_mode);
932 qemu_put_byte(f, s->function);
933 qemu_put_byte(f, s->nextfunction);
934 qemu_put_byte(f, s->precision);
935 qemu_put_byte(f, s->nextprecision);
936 qemu_put_byte(f, s->filter);
937 qemu_put_byte(f, s->pin_func);
938 qemu_put_byte(f, s->ref);
939 qemu_put_byte(f, s->timing);
940 qemu_put_be32(f, s->noise);
942 qemu_put_be16s(f, &s->audio_ctrl1);
943 qemu_put_be16s(f, &s->audio_ctrl2);
944 qemu_put_be16s(f, &s->audio_ctrl3);
945 qemu_put_be16s(f, &s->pll[0]);
946 qemu_put_be16s(f, &s->pll[1]);
947 qemu_put_be16s(f, &s->volume);
948 qemu_put_be64(f, (uint64_t) (s->volume_change - now));
949 qemu_put_be64(f, (uint64_t) (s->powerdown - now));
950 qemu_put_byte(f, s->softstep);
951 qemu_put_be16s(f, &s->dac_power);
953 for (i = 0; i < 0x14; i ++)
954 qemu_put_be16s(f, &s->filter_data[i]);
957 static int tsc210x_load(QEMUFile *f, void *opaque, int version_id)
959 struct tsc210x_state_s *s = (struct tsc210x_state_s *) opaque;
960 int64_t now = qemu_get_clock(vm_clock);
963 s->x = qemu_get_be16(f);
964 s->y = qemu_get_be16(f);
965 s->pressure = qemu_get_byte(f);
967 s->state = qemu_get_byte(f);
968 s->page = qemu_get_byte(f);
969 s->offset = qemu_get_byte(f);
970 s->command = qemu_get_byte(f);
972 s->irq = qemu_get_byte(f);
973 qemu_get_be16s(f, &s->dav);
975 qemu_get_timer(f, s->timer);
976 s->enabled = qemu_get_byte(f);
977 s->host_mode = qemu_get_byte(f);
978 s->function = qemu_get_byte(f);
979 s->nextfunction = qemu_get_byte(f);
980 s->precision = qemu_get_byte(f);
981 s->nextprecision = qemu_get_byte(f);
982 s->filter = qemu_get_byte(f);
983 s->pin_func = qemu_get_byte(f);
984 s->ref = qemu_get_byte(f);
985 s->timing = qemu_get_byte(f);
986 s->noise = qemu_get_be32(f);
988 qemu_get_be16s(f, &s->audio_ctrl1);
989 qemu_get_be16s(f, &s->audio_ctrl2);
990 qemu_get_be16s(f, &s->audio_ctrl3);
991 qemu_get_be16s(f, &s->pll[0]);
992 qemu_get_be16s(f, &s->pll[1]);
993 qemu_get_be16s(f, &s->volume);
994 s->volume_change = (int64_t) qemu_get_be64(f) + now;
995 s->powerdown = (int64_t) qemu_get_be64(f) + now;
996 s->softstep = qemu_get_byte(f);
997 qemu_get_be16s(f, &s->dac_power);
999 for (i = 0; i < 0x14; i ++)
1000 qemu_get_be16s(f, &s->filter_data[i]);
1002 s->busy = qemu_timer_pending(s->timer);
1003 qemu_set_irq(s->pint, !s->irq);
1008 static int tsc2102_iid = 0;
1010 struct uwire_slave_s *tsc2102_init(qemu_irq pint, AudioState *audio)
1012 struct tsc210x_state_s *s;
1014 s = (struct tsc210x_state_s *)
1015 qemu_mallocz(sizeof(struct tsc210x_state_s));
1016 memset(s, 0, sizeof(struct tsc210x_state_s));
1020 s->precision = s->nextprecision = 0;
1021 s->timer = qemu_new_timer(vm_clock, tsc210x_timer_tick, s);
1023 s->name = "tsc2102";
1027 s->chip.send = (void *) tsc210x_write;
1028 s->chip.receive = (void *) tsc210x_read;
1030 s->codec.opaque = s;
1031 s->codec.tx_swallow = (void *) tsc210x_i2s_swallow;
1032 s->codec.set_rate = (void *) tsc210x_i2s_set_rate;
1033 s->codec.in.fifo = s->in_fifo;
1034 s->codec.out.fifo = s->out_fifo;
1038 qemu_add_mouse_event_handler(tsc210x_touchscreen_event, s, 1,
1039 "QEMU TSC2102-driven Touchscreen");
1042 AUD_register_card(s->audio, s->name, &s->card);
1044 qemu_register_reset((void *) tsc210x_reset, s);
1045 register_savevm(s->name, tsc2102_iid ++, 0,
1046 tsc210x_save, tsc210x_load, s);
1051 struct i2s_codec_s *tsc210x_codec(struct uwire_slave_s *chip)
1053 struct tsc210x_state_s *s = (struct tsc210x_state_s *) chip->opaque;