~ubuntu-branches/ubuntu/trusty/qemu/trusty

« back to all changes in this revision

Viewing changes to .pc/linaro-patches-1.5.0/0028-tsc2005-rearrange-pin_update-timer_tick.patch/hw/input/tsc2005.c

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2013-10-22 22:47:07 UTC
  • mfrom: (1.8.3) (10.1.42 sid)
  • Revision ID: package-import@ubuntu.com-20131022224707-1lya34fw3k3f24tv
Tags: 1.6.0+dfsg-2ubuntu1
* Merge 1.6.0~rc0+dfsg-2exp from debian experimental.  Remaining changes:
  - debian/control
    * update maintainer
    * remove libiscsi, usb-redir, vde, vnc-jpeg, and libssh2-1-dev
      from build-deps
    * enable rbd
    * add qemu-system and qemu-common B/R to qemu-keymaps
    * add D:udev, R:qemu, R:qemu-common and B:qemu-common to
      qemu-system-common
    * qemu-system-arm, qemu-system-ppc, qemu-system-sparc:
      - add qemu-kvm to Provides
      - add qemu-common, qemu-kvm, kvm to B/R
      - remove openbios-sparc from qemu-system-sparc D
      - drop openbios-ppc and openhackware Depends to Suggests (for now)
    * qemu-system-x86:
      - add qemu-common to Breaks/Replaces.
      - add cpu-checker to Recommends.
    * qemu-user: add B/R:qemu-kvm
    * qemu-kvm:
      - add armhf armel powerpc sparc to Architecture
      - C/R/P: qemu-kvm-spice
    * add qemu-common package
    * drop qemu-slof which is not packaged in ubuntu
  - add qemu-system-common.links for tap ifup/down scripts and OVMF link.
  - qemu-system-x86.links:
    * remove pxe rom links which are in kvm-ipxe
    * add symlink for kvm.1 manpage
  - debian/rules
    * add kvm-spice symlink to qemu-kvm
    * call dh_installmodules for qemu-system-x86
    * update dh_installinit to install upstart script
    * run dh_installman (Closes: #709241) (cherrypicked from 1.5.0+dfsg-2)
  - Add qemu-utils.links for kvm-* symlinks.
  - Add qemu-system-x86.qemu-kvm.upstart and .default
  - Add qemu-system-x86.modprobe to set nesting=1
  - Add qemu-system-common.preinst to add kvm group
  - qemu-system-common.postinst: remove bad group acl if there, then have
    udev relabel /dev/kvm.
  - New linaro patches from qemu-linaro rebasing branch
  - Dropped patches:
    * xen-simplify-xen_enabled.patch
    * sparc-linux-user-fix-missing-symbols-in-.rel-.rela.plt-sections.patch
    * main_loop-do-not-set-nonblocking-if-xen_enabled.patch
    * xen_machine_pv-do-not-create-a-dummy-CPU-in-machine-.patch
    * virtio-rng-fix-crash
  - Kept patches:
    * expose_vms_qemu64cpu.patch - updated
    * linaro arm patches from qemu-linaro rebasing branch
  - New patches:
    * fix-pci-add: change CONFIG variable in ifdef to make sure that
      pci_add is defined.
* Add linaro patches
* Add experimental mach-virt patches for arm virtualization.
* qemu-system-common.install: add debian/tmp/usr/lib to install the
  qemu-bridge-helper

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * TI TSC2005 emulator.
3
 
 *
4
 
 * Copyright (c) 2006 Andrzej Zaborowski  <balrog@zabor.org>
5
 
 * Copyright (C) 2008 Nokia Corporation
6
 
 *
7
 
 * This program is free software; you can redistribute it and/or
8
 
 * modify it under the terms of the GNU General Public License as
9
 
 * published by the Free Software Foundation; either version 2 or
10
 
 * (at your option) version 3 of the License.
11
 
 *
12
 
 * This program is distributed in the hope that it will be useful,
13
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
 * GNU General Public License for more details.
16
 
 *
17
 
 * You should have received a copy of the GNU General Public License along
18
 
 * with this program; if not, see <http://www.gnu.org/licenses/>.
19
 
 */
20
 
 
21
 
#include "hw/hw.h"
22
 
#include "qemu/timer.h"
23
 
#include "ui/console.h"
24
 
#include "hw/devices.h"
25
 
 
26
 
//#define TSC2005_DEBUG
27
 
 
28
 
#ifdef TSC2005_DEBUG
29
 
#define TRACE(fmt, ...) fprintf(stderr, "%s@%d: " fmt "\n", \
30
 
                                __FUNCTION__, __LINE__, ##__VA_ARGS__)
31
 
#else
32
 
#define TRACE(...)
33
 
#endif
34
 
 
35
 
#define TSC_CUT_RESOLUTION(value, p)    ((value) >> (16 - (p ? 12 : 10)))
36
 
 
37
 
typedef struct {
38
 
    qemu_irq pint;      /* Combination of the nPENIRQ and DAV signals */
39
 
    QEMUTimer *timer;
40
 
    uint16_t model;
41
 
 
42
 
    int x, y;
43
 
    int pressure;
44
 
 
45
 
    int state, reg, irq, command;
46
 
    uint16_t data, dav;
47
 
 
48
 
    int busy;
49
 
    int enabled;
50
 
    int host_mode;
51
 
    int function;
52
 
    int nextfunction;
53
 
    int precision;
54
 
    int nextprecision;
55
 
    int filter;
56
 
    int pin_func;
57
 
    int timing[2];
58
 
    int noise;
59
 
    int reset;
60
 
    int pdst;
61
 
    int pnd0;
62
 
    uint16_t temp_thr[2];
63
 
    uint16_t aux_thr[2];
64
 
 
65
 
    int tr[8];
66
 
    int z1_cons, z2_cons;
67
 
} TSC2005State;
68
 
 
69
 
enum {
70
 
    TSC_MODE_XYZ_SCAN   = 0x0,
71
 
    TSC_MODE_XY_SCAN,
72
 
    TSC_MODE_X,
73
 
    TSC_MODE_Y,
74
 
    TSC_MODE_Z,
75
 
    TSC_MODE_AUX,
76
 
    TSC_MODE_TEMP1,
77
 
    TSC_MODE_TEMP2,
78
 
    TSC_MODE_AUX_SCAN,
79
 
    TSC_MODE_X_TEST,
80
 
    TSC_MODE_Y_TEST,
81
 
    TSC_MODE_TS_TEST,
82
 
    TSC_MODE_RESERVED,
83
 
    TSC_MODE_XX_DRV,
84
 
    TSC_MODE_YY_DRV,
85
 
    TSC_MODE_YX_DRV,
86
 
};
87
 
 
88
 
static const uint16_t mode_regs[16] = {
89
 
    0xf000,     /* X, Y, Z scan */
90
 
    0xc000,     /* X, Y scan */
91
 
    0x8000,     /* X */
92
 
    0x4000,     /* Y */
93
 
    0x3000,     /* Z */
94
 
    0x0800,     /* AUX */
95
 
    0x0400,     /* TEMP1 */
96
 
    0x0200,     /* TEMP2 */
97
 
    0x0800,     /* AUX scan */
98
 
    0x0040,     /* X test */
99
 
    0x0020,     /* Y test */
100
 
    0x0080,     /* Short-circuit test */
101
 
    0x0000,     /* Reserved */
102
 
    0x0000,     /* X+, X- drivers */
103
 
    0x0000,     /* Y+, Y- drivers */
104
 
    0x0000,     /* Y+, X- drivers */
105
 
};
106
 
 
107
 
#define X_TRANSFORM(s)                  \
108
 
    ((s->y * s->tr[0] - s->x * s->tr[1]) / s->tr[2] + s->tr[3])
109
 
#define Y_TRANSFORM(s)                  \
110
 
    ((s->y * s->tr[4] - s->x * s->tr[5]) / s->tr[6] + s->tr[7])
111
 
/*
112
 
#define Z1_TRANSFORM(s)                 \
113
 
    (((s)->z1_cons - ((s)->x >> 7) + ((s)->pressure << 10)) << 4)
114
 
#define Z2_TRANSFORM(s)                 \
115
 
    (((s)->z2_cons + ((s)->y >> 7) - ((s)->pressure << 10)) << 4)
116
 
 */
117
 
/* these simpler forms work much better */
118
 
#define Z1_TRANSFORM(s) (((s)->z1_cons) << 4)
119
 
#define Z2_TRANSFORM(s) (((s)->z2_cons) << 4)
120
 
 
121
 
#define AUX_VAL                         (700 << 4)      /* +/- 3 at 12-bit */
122
 
#define TEMP1_VAL                       (1264 << 4)     /* +/- 5 at 12-bit */
123
 
#define TEMP2_VAL                       (1531 << 4)     /* +/- 5 at 12-bit */
124
 
 
125
 
static uint16_t tsc2005_read(TSC2005State *s, int reg)
126
 
{
127
 
    uint16_t ret;
128
 
 
129
 
    switch (reg) {
130
 
    case 0x0:   /* X */
131
 
        s->dav &= ~mode_regs[TSC_MODE_X];
132
 
        TRACE("X = %d", TSC_CUT_RESOLUTION(X_TRANSFORM(s), s->precision) +
133
 
              (s->noise & 3));
134
 
        return TSC_CUT_RESOLUTION(X_TRANSFORM(s), s->precision) +
135
 
                (s->noise & 3);
136
 
    case 0x1:   /* Y */
137
 
        s->dav &= ~mode_regs[TSC_MODE_Y];
138
 
        s->noise ++;
139
 
        TRACE("Y = %d", TSC_CUT_RESOLUTION(Y_TRANSFORM(s), s->precision) ^
140
 
              (s->noise & 3));
141
 
        return TSC_CUT_RESOLUTION(Y_TRANSFORM(s), s->precision) ^
142
 
                (s->noise & 3);
143
 
    case 0x2:   /* Z1 */
144
 
        s->dav &= 0xdfff;
145
 
        TRACE("Z1 = %d", TSC_CUT_RESOLUTION(Z1_TRANSFORM(s), s->precision) -
146
 
              (s->noise & 3));
147
 
        return TSC_CUT_RESOLUTION(Z1_TRANSFORM(s), s->precision) -
148
 
                (s->noise & 3);
149
 
    case 0x3:   /* Z2 */
150
 
        s->dav &= 0xefff;
151
 
        TRACE("Z2 = %d", TSC_CUT_RESOLUTION(Z2_TRANSFORM(s), s->precision) |
152
 
              (s->noise & 3));
153
 
        return TSC_CUT_RESOLUTION(Z2_TRANSFORM(s), s->precision) |
154
 
                (s->noise & 3);
155
 
 
156
 
    case 0x4:   /* AUX */
157
 
        s->dav &= ~mode_regs[TSC_MODE_AUX];
158
 
        TRACE("AUX = %d", TSC_CUT_RESOLUTION(AUX_VAL, s->precision));
159
 
        return TSC_CUT_RESOLUTION(AUX_VAL, s->precision);
160
 
 
161
 
    case 0x5:   /* TEMP1 */
162
 
        s->dav &= ~mode_regs[TSC_MODE_TEMP1];
163
 
        TRACE("TEMP1 = %d", TSC_CUT_RESOLUTION(TEMP1_VAL, s->precision) -
164
 
              (s->noise & 5));
165
 
        return TSC_CUT_RESOLUTION(TEMP1_VAL, s->precision) -
166
 
                (s->noise & 5);
167
 
    case 0x6:   /* TEMP2 */
168
 
        s->dav &= 0xdfff;
169
 
        s->dav &= ~mode_regs[TSC_MODE_TEMP2];
170
 
        TRACE("TEMP2 = %d", TSC_CUT_RESOLUTION(TEMP2_VAL, s->precision) ^
171
 
              (s->noise & 3));
172
 
        return TSC_CUT_RESOLUTION(TEMP2_VAL, s->precision) ^
173
 
                (s->noise & 3);
174
 
 
175
 
    case 0x7:   /* Status */
176
 
        ret = s->dav | (s->reset << 7) | (s->pdst << 2) | 0x0;
177
 
        s->dav &= ~(mode_regs[TSC_MODE_X_TEST] | mode_regs[TSC_MODE_Y_TEST] |
178
 
                        mode_regs[TSC_MODE_TS_TEST]);
179
 
        s->reset = 1;
180
 
        TRACE("STATUS = 0x%04x", ret);
181
 
        return ret;
182
 
 
183
 
    case 0x8:   /* AUX high treshold */
184
 
        TRACE("AUX high threshold = 0x%04x", s->aux_thr[1]);
185
 
        return s->aux_thr[1];
186
 
    case 0x9:   /* AUX low treshold */
187
 
        TRACE("AUX low threshold = 0x%04x", s->aux_thr[0]);
188
 
        return s->aux_thr[0];
189
 
 
190
 
    case 0xa:   /* TEMP high treshold */
191
 
        TRACE("TEMP high threshold = 0x%04x", s->temp_thr[1]);
192
 
        return s->temp_thr[1];
193
 
    case 0xb:   /* TEMP low treshold */
194
 
        TRACE("TEMP low threshold = 0x%04x", s->temp_thr[0]);
195
 
        return s->temp_thr[0];
196
 
 
197
 
    case 0xc:   /* CFR0 */
198
 
        TRACE("CFR0 = 0x%04x", (s->pressure << 15) | ((!s->busy) << 14) |
199
 
              (s->nextprecision << 13) | s->timing[0]);
200
 
        return (s->pressure << 15) | ((!s->busy) << 14) |
201
 
                (s->nextprecision << 13) | s->timing[0]; 
202
 
    case 0xd:   /* CFR1 */
203
 
        TRACE("CFR1 = 0x%04x", s->timing[1]);
204
 
        return s->timing[1];
205
 
    case 0xe:   /* CFR2 */
206
 
        TRACE("CFR2 = 0x%04x", (s->pin_func << 14) | s->filter);
207
 
        return (s->pin_func << 14) | s->filter;
208
 
 
209
 
    case 0xf:   /* Function select status */
210
 
        TRACE("function select status = 0x%04x",
211
 
              s->function >= 0 ? 1 << s->function : 0);
212
 
        return s->function >= 0 ? 1 << s->function : 0;
213
 
    }
214
 
 
215
 
    /* Never gets here */
216
 
    TRACE("unknown register = 0xffff");
217
 
    return 0xffff;
218
 
}
219
 
 
220
 
static void tsc2005_write(TSC2005State *s, int reg, uint16_t data)
221
 
{
222
 
    switch (reg) {
223
 
    case 0x8:   /* AUX high treshold */
224
 
        TRACE("AUX high threshold = 0x%04x", data);
225
 
        s->aux_thr[1] = data;
226
 
        break;
227
 
    case 0x9:   /* AUX low treshold */
228
 
        TRACE("AUX low threshold = 0x%04x", data);
229
 
        s->aux_thr[0] = data;
230
 
        break;
231
 
 
232
 
    case 0xa:   /* TEMP high treshold */
233
 
        TRACE("TEMP high threshold = 0x%04x", data);
234
 
        s->temp_thr[1] = data;
235
 
        break;
236
 
    case 0xb:   /* TEMP low treshold */
237
 
        TRACE("TEMP low threshold = 0x%04x", data);
238
 
        s->temp_thr[0] = data;
239
 
        break;
240
 
 
241
 
    case 0xc:   /* CFR0 */
242
 
        TRACE("CFR0 = 0x%04x", data);
243
 
        s->host_mode = data >> 15;
244
 
        if (s->enabled != !(data & 0x4000)) {
245
 
            s->enabled = !(data & 0x4000);
246
 
            TRACE("touchscreen sense %sabled", s->enabled ? "en" : "dis");
247
 
            if (s->busy && !s->enabled) {
248
 
                qemu_del_timer(s->timer);
249
 
            }
250
 
            s->busy &= s->enabled;
251
 
        }
252
 
        s->nextprecision = (data >> 13) & 1;
253
 
        s->timing[0] = data & 0x1fff;
254
 
        if ((s->timing[0] >> 11) == 3) {
255
 
            TRACE("illegal conversion clock setting");
256
 
        }
257
 
        break;
258
 
    case 0xd:   /* CFR1 */
259
 
        TRACE("CFR1 = 0x%04x", data);
260
 
        s->timing[1] = data & 0xf07;
261
 
        break;
262
 
    case 0xe:   /* CFR2 */
263
 
        TRACE("CFR2 = 0x%04x", data);
264
 
        s->pin_func = (data >> 14) & 3;
265
 
        s->filter = data & 0x3fff;
266
 
        break;
267
 
 
268
 
    default:
269
 
        TRACE("write into read-only register 0x%x, value 0x%04x", reg, data);
270
 
    }
271
 
}
272
 
 
273
 
/* This handles most of the chip's logic.  */
274
 
static void tsc2005_pin_update(TSC2005State *s)
275
 
{
276
 
    int64_t expires;
277
 
    int pin_state;
278
 
 
279
 
    switch (s->pin_func) {
280
 
    case 0:
281
 
        pin_state = !s->pressure && !!s->dav;
282
 
        break;
283
 
    case 1:
284
 
    case 3:
285
 
    default:
286
 
        pin_state = !s->dav;
287
 
        break;
288
 
    case 2:
289
 
        pin_state = !s->pressure;
290
 
    }
291
 
 
292
 
    if (pin_state != s->irq) {
293
 
        s->irq = pin_state;
294
 
        qemu_set_irq(s->pint, s->irq);
295
 
    }
296
 
 
297
 
    switch (s->nextfunction) {
298
 
    case TSC_MODE_XYZ_SCAN:
299
 
    case TSC_MODE_XY_SCAN:
300
 
        if (!s->host_mode && s->dav)
301
 
            s->enabled = 0;
302
 
        if (!s->pressure)
303
 
            return;
304
 
        /* Fall through */
305
 
    case TSC_MODE_AUX_SCAN:
306
 
        break;
307
 
 
308
 
    case TSC_MODE_X:
309
 
    case TSC_MODE_Y:
310
 
    case TSC_MODE_Z:
311
 
        if (!s->pressure)
312
 
            return;
313
 
        /* Fall through */
314
 
    case TSC_MODE_AUX:
315
 
    case TSC_MODE_TEMP1:
316
 
    case TSC_MODE_TEMP2:
317
 
    case TSC_MODE_X_TEST:
318
 
    case TSC_MODE_Y_TEST:
319
 
    case TSC_MODE_TS_TEST:
320
 
        if (s->dav)
321
 
            s->enabled = 0;
322
 
        break;
323
 
 
324
 
    case TSC_MODE_RESERVED:
325
 
    case TSC_MODE_XX_DRV:
326
 
    case TSC_MODE_YY_DRV:
327
 
    case TSC_MODE_YX_DRV:
328
 
    default:
329
 
        return;
330
 
    }
331
 
 
332
 
    if (!s->enabled || s->busy)
333
 
        return;
334
 
 
335
 
    s->busy = 1;
336
 
    s->precision = s->nextprecision;
337
 
    s->function = s->nextfunction;
338
 
    s->pdst = !s->pnd0; /* Synchronised on internal clock */
339
 
    expires = qemu_get_clock_ns(vm_clock) + (get_ticks_per_sec() >> 7);
340
 
    qemu_mod_timer(s->timer, expires);
341
 
}
342
 
 
343
 
static void tsc2005_reset(TSC2005State *s)
344
 
{
345
 
    s->state = 0;
346
 
    s->pin_func = 0;
347
 
    s->enabled = 0;
348
 
    s->busy = 0;
349
 
    s->nextprecision = 0;
350
 
    s->nextfunction = 0;
351
 
    s->timing[0] = 0;
352
 
    s->timing[1] = 0;
353
 
    s->irq = 0;
354
 
    s->dav = 0;
355
 
    s->reset = 0;
356
 
    s->pdst = 1;
357
 
    s->pnd0 = 0;
358
 
    s->function = -1;
359
 
    s->temp_thr[0] = 0x000;
360
 
    s->temp_thr[1] = 0xfff;
361
 
    s->aux_thr[0] = 0x000;
362
 
    s->aux_thr[1] = 0xfff;
363
 
 
364
 
    tsc2005_pin_update(s);
365
 
}
366
 
 
367
 
static uint8_t tsc2005_txrx_word(void *opaque, uint8_t value)
368
 
{
369
 
    TSC2005State *s = opaque;
370
 
    uint32_t ret = 0;
371
 
    TRACE("value = 0x%08x, state=%d", value, s->state + 1);
372
 
    switch (s->state ++) {
373
 
    case 0:
374
 
        if (value & 0x80) {
375
 
            /* Command */
376
 
            if (value & (1 << 1))
377
 
                tsc2005_reset(s);
378
 
            else {
379
 
                s->nextfunction = (value >> 3) & 0xf;
380
 
                s->nextprecision = (value >> 2) & 1;
381
 
                if (s->enabled != !(value & 1)) {
382
 
                    s->enabled = !(value & 1);
383
 
                    TRACE("touchscreen sense %sabled",
384
 
                          s->enabled ? "en" : "dis");
385
 
                    if (s->busy && !s->enabled)
386
 
                        qemu_del_timer(s->timer);
387
 
                    s->busy &= s->enabled;
388
 
                }
389
 
                tsc2005_pin_update(s);
390
 
            }
391
 
 
392
 
            s->state = 0;
393
 
        } else if (value) {
394
 
            /* Data transfer */
395
 
            s->reg = (value >> 3) & 0xf;
396
 
            s->pnd0 = (value >> 1) & 1;
397
 
            s->command = value & 1;
398
 
 
399
 
            if (s->command) {
400
 
                /* Read */
401
 
                s->data = tsc2005_read(s, s->reg);
402
 
                tsc2005_pin_update(s);
403
 
            } else
404
 
                s->data = 0;
405
 
        } else
406
 
            s->state = 0;
407
 
        break;
408
 
 
409
 
    case 1:
410
 
        if (s->command)
411
 
            ret = (s->data >> 8) & 0xff;
412
 
        else
413
 
            s->data |= value << 8;
414
 
        break;
415
 
 
416
 
    case 2:
417
 
        if (s->command)
418
 
            ret = s->data & 0xff;
419
 
        else {
420
 
            s->data |= value;
421
 
            tsc2005_write(s, s->reg, s->data);
422
 
            tsc2005_pin_update(s);
423
 
        }
424
 
 
425
 
        s->state = 0;
426
 
        break;
427
 
    }
428
 
 
429
 
    return ret;
430
 
}
431
 
 
432
 
uint32_t tsc2005_txrx(void *opaque, uint32_t value, int len)
433
 
{
434
 
    uint32_t ret = 0;
435
 
    TRACE("value=0x%08x, len=%d", value, len);
436
 
    len &= ~7;
437
 
    while (len > 0) {
438
 
        len -= 8;
439
 
        ret |= tsc2005_txrx_word(opaque, (value >> len) & 0xff) << len;
440
 
    }
441
 
 
442
 
    return ret;
443
 
}
444
 
 
445
 
static void tsc2005_timer_tick(void *opaque)
446
 
{
447
 
    TSC2005State *s = opaque;
448
 
 
449
 
    /* Timer ticked -- a set of conversions has been finished.  */
450
 
 
451
 
    if (!s->busy) {
452
 
        TRACE("not busy -> exit");
453
 
        return;
454
 
    }
455
 
 
456
 
    s->busy = 0;
457
 
    s->dav |= mode_regs[s->function];
458
 
    s->function = -1;
459
 
    tsc2005_pin_update(s);
460
 
}
461
 
 
462
 
static void tsc2005_touchscreen_event(void *opaque,
463
 
                int x, int y, int z, int buttons_state)
464
 
{
465
 
    TSC2005State *s = opaque;
466
 
    int p = s->pressure;
467
 
 
468
 
    if (buttons_state) {
469
 
        s->x = x;
470
 
        s->y = y;
471
 
    }
472
 
    s->pressure = !!buttons_state;
473
 
 
474
 
    /*
475
 
     * Note: We would get better responsiveness in the guest by
476
 
     * signaling TS events immediately, but for now we simulate
477
 
     * the first conversion delay for sake of correctness.
478
 
     */
479
 
    if (p != s->pressure)
480
 
        tsc2005_pin_update(s);
481
 
}
482
 
 
483
 
static void tsc2005_save(QEMUFile *f, void *opaque)
484
 
{
485
 
    TSC2005State *s = (TSC2005State *) opaque;
486
 
    int i;
487
 
 
488
 
    qemu_put_be16(f, s->x);
489
 
    qemu_put_be16(f, s->y);
490
 
    qemu_put_byte(f, s->pressure);
491
 
 
492
 
    qemu_put_byte(f, s->state);
493
 
    qemu_put_byte(f, s->reg);
494
 
    qemu_put_byte(f, s->command);
495
 
 
496
 
    qemu_put_byte(f, s->irq);
497
 
    qemu_put_be16s(f, &s->dav);
498
 
    qemu_put_be16s(f, &s->data);
499
 
 
500
 
    qemu_put_timer(f, s->timer);
501
 
    qemu_put_byte(f, s->enabled);
502
 
    qemu_put_byte(f, s->host_mode);
503
 
    qemu_put_byte(f, s->function);
504
 
    qemu_put_byte(f, s->nextfunction);
505
 
    qemu_put_byte(f, s->precision);
506
 
    qemu_put_byte(f, s->nextprecision);
507
 
    qemu_put_be16(f, s->filter);
508
 
    qemu_put_byte(f, s->pin_func);
509
 
    qemu_put_be16(f, s->timing[0]);
510
 
    qemu_put_be16(f, s->timing[1]);
511
 
    qemu_put_be16s(f, &s->temp_thr[0]);
512
 
    qemu_put_be16s(f, &s->temp_thr[1]);
513
 
    qemu_put_be16s(f, &s->aux_thr[0]);
514
 
    qemu_put_be16s(f, &s->aux_thr[1]);
515
 
    qemu_put_be32(f, s->noise);
516
 
    qemu_put_byte(f, s->reset);
517
 
    qemu_put_byte(f, s->pdst);
518
 
    qemu_put_byte(f, s->pnd0);
519
 
 
520
 
    for (i = 0; i < 8; i ++)
521
 
        qemu_put_be32(f, s->tr[i]);
522
 
}
523
 
 
524
 
static int tsc2005_load(QEMUFile *f, void *opaque, int version_id)
525
 
{
526
 
    TSC2005State *s = (TSC2005State *) opaque;
527
 
    int i;
528
 
 
529
 
    s->x = qemu_get_be16(f);
530
 
    s->y = qemu_get_be16(f);
531
 
    s->pressure = qemu_get_byte(f);
532
 
 
533
 
    s->state = qemu_get_byte(f);
534
 
    s->reg = qemu_get_byte(f);
535
 
    s->command = qemu_get_byte(f);
536
 
 
537
 
    s->irq = qemu_get_byte(f);
538
 
    qemu_get_be16s(f, &s->dav);
539
 
    qemu_get_be16s(f, &s->data);
540
 
 
541
 
    qemu_get_timer(f, s->timer);
542
 
    s->enabled = qemu_get_byte(f);
543
 
    s->host_mode = qemu_get_byte(f);
544
 
    s->function = qemu_get_byte(f);
545
 
    s->nextfunction = qemu_get_byte(f);
546
 
    s->precision = qemu_get_byte(f);
547
 
    s->nextprecision = qemu_get_byte(f);
548
 
    s->filter = qemu_get_be16(f);
549
 
    s->pin_func = qemu_get_byte(f);
550
 
    s->timing[0] = qemu_get_be16(f);
551
 
    s->timing[1] = qemu_get_be16(f);
552
 
    qemu_get_be16s(f, &s->temp_thr[0]);
553
 
    qemu_get_be16s(f, &s->temp_thr[1]);
554
 
    qemu_get_be16s(f, &s->aux_thr[0]);
555
 
    qemu_get_be16s(f, &s->aux_thr[1]);
556
 
    s->noise = qemu_get_be32(f);
557
 
    s->reset = qemu_get_byte(f);
558
 
    s->pdst = qemu_get_byte(f);
559
 
    s->pnd0 = qemu_get_byte(f);
560
 
 
561
 
    for (i = 0; i < 8; i ++)
562
 
        s->tr[i] = qemu_get_be32(f);
563
 
 
564
 
    s->busy = qemu_timer_pending(s->timer);
565
 
    tsc2005_pin_update(s);
566
 
 
567
 
    return 0;
568
 
}
569
 
 
570
 
void *tsc2005_init(qemu_irq pintdav)
571
 
{
572
 
    TSC2005State *s;
573
 
 
574
 
    s = (TSC2005State *)
575
 
            g_malloc0(sizeof(TSC2005State));
576
 
    s->x = 400;
577
 
    s->y = 240;
578
 
    s->pressure = 0;
579
 
    s->precision = s->nextprecision = 0;
580
 
    s->timer = qemu_new_timer_ns(vm_clock, tsc2005_timer_tick, s);
581
 
    s->pint = pintdav;
582
 
    s->model = 0x2005;
583
 
 
584
 
    s->tr[0] = 0;
585
 
    s->tr[1] = 1;
586
 
    s->tr[2] = 1;
587
 
    s->tr[3] = 0;
588
 
    s->tr[4] = 1;
589
 
    s->tr[5] = 0;
590
 
    s->tr[6] = 1;
591
 
    s->tr[7] = 0;
592
 
 
593
 
    s->z1_cons = 400;
594
 
    s->z2_cons = 4000;
595
 
 
596
 
    tsc2005_reset(s);
597
 
 
598
 
    qemu_add_mouse_event_handler(tsc2005_touchscreen_event, s, 1,
599
 
                    "QEMU TSC2005-driven Touchscreen");
600
 
 
601
 
    qemu_register_reset((void *) tsc2005_reset, s);
602
 
    register_savevm(NULL, "tsc2005", -1, 0, tsc2005_save, tsc2005_load, s);
603
 
 
604
 
    return s;
605
 
}
606
 
 
607
 
/*
608
 
 * Use tslib generated calibration data to generate ADC input values
609
 
 * from the touchscreen.  Assuming 12-bit precision was used during
610
 
 * tslib calibration.
611
 
 */
612
 
void tsc2005_set_transform(void *opaque, MouseTransformInfo *info,
613
 
                           int z1_cons, int z2_cons)
614
 
{
615
 
    TSC2005State *s = (TSC2005State *) opaque;
616
 
 
617
 
    /* This version assumes touchscreen X & Y axis are parallel or
618
 
     * perpendicular to LCD's  X & Y axis in some way.  */
619
 
    if (abs(info->a[0]) > abs(info->a[1])) {
620
 
        s->tr[0] = 0;
621
 
        s->tr[1] = -info->a[6] * info->x;
622
 
        s->tr[2] = info->a[0];
623
 
        s->tr[3] = -info->a[2] / info->a[0];
624
 
        s->tr[4] = info->a[6] * info->y;
625
 
        s->tr[5] = 0;
626
 
        s->tr[6] = info->a[4];
627
 
        s->tr[7] = -info->a[5] / info->a[4];
628
 
    } else {
629
 
        s->tr[0] = info->a[6] * info->y;
630
 
        s->tr[1] = 0;
631
 
        s->tr[2] = info->a[1];
632
 
        s->tr[3] = -info->a[2] / info->a[1];
633
 
        s->tr[4] = 0;
634
 
        s->tr[5] = -info->a[6] * info->x;
635
 
        s->tr[6] = info->a[3];
636
 
        s->tr[7] = -info->a[5] / info->a[3];
637
 
    }
638
 
 
639
 
    s->tr[0] >>= 11;
640
 
    s->tr[1] >>= 11;
641
 
    s->tr[3] <<= 4;
642
 
    s->tr[4] >>= 11;
643
 
    s->tr[5] >>= 11;
644
 
    s->tr[7] <<= 4;
645
 
 
646
 
    s->z1_cons = z1_cons;
647
 
    s->z2_cons = z2_cons;
648
 
}