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

« back to all changes in this revision

Viewing changes to .pc/linaro/0026-hw-tsc2005-Add-tracing.patch/hw/input/tsc2005.c

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2014-02-04 12:13:08 UTC
  • mfrom: (10.1.45 sid)
  • Revision ID: package-import@ubuntu.com-20140204121308-1xq92lrfs75agw2g
Tags: 1.7.0+dfsg-3ubuntu1~ppa1
* Merge 1.7.0+dfsg-3 from debian.  Remaining changes:
  - debian/patches/ubuntu:
    * expose-vmx_qemu64cpu.patch
    * linaro (omap3) and arm64 patches
    * ubuntu/target-ppc-add-stubs-for-kvm-breakpoints: fix FTBFS
      on ppc
    * ubuntu/CVE-2013-4377.patch: fix denial of service via virtio
  - debian/qemu-system-x86.modprobe: set kvm_intel nested=1 options
  - debian/control:
    * add arm64 to Architectures
    * add qemu-common and qemu-system-aarch64 packages
  - debian/qemu-system-common.install: add debian/tmp/usr/lib
  - debian/qemu-system-common.preinst: add kvm group
  - debian/qemu-system-common.postinst: remove acl placed by udev,
    and add udevadm trigger.
  - qemu-system-x86.links: add eepro100.rom, remove pxe-virtio,
    pxe-e1000 and pxe-rtl8139.
  - add qemu-system-x86.qemu-kvm.upstart and .default
  - qemu-user-static.postinst-in: remove arm64 binfmt
  - debian/rules:
    * allow parallel build
    * add aarch64 to system_targets and sys_systems
    * add qemu-kvm-spice links
    * install qemu-system-x86.modprobe
  - add debian/qemu-system-common.links for OVMF.fd link
* Remove kvm-img, kvm-nbd, kvm-ifup and kvm-ifdown symlinks.

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