2008-05-07 18:41:37 +04:00
|
|
|
/*
|
|
|
|
* TI TSC2005 emulator.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2006 Andrzej Zaborowski <balrog@zabor.org>
|
|
|
|
* Copyright (C) 2008 Nokia Corporation
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 or
|
|
|
|
* (at your option) version 3 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
2009-01-05 01:05:52 +03:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
2009-07-17 00:47:01 +04:00
|
|
|
* with this program; if not, see <http://www.gnu.org/licenses/>.
|
2008-05-07 18:41:37 +04:00
|
|
|
*/
|
|
|
|
|
2016-01-26 21:17:28 +03:00
|
|
|
#include "qemu/osdep.h"
|
2018-06-26 19:50:40 +03:00
|
|
|
#include "qemu/log.h"
|
2013-02-04 18:40:22 +04:00
|
|
|
#include "hw/hw.h"
|
2012-12-17 21:20:00 +04:00
|
|
|
#include "qemu/timer.h"
|
2012-11-28 15:06:30 +04:00
|
|
|
#include "ui/console.h"
|
2013-04-09 18:26:55 +04:00
|
|
|
#include "hw/devices.h"
|
2018-06-21 20:12:52 +03:00
|
|
|
#include "trace.h"
|
2008-05-07 18:41:37 +04:00
|
|
|
|
|
|
|
#define TSC_CUT_RESOLUTION(value, p) ((value) >> (16 - (p ? 12 : 10)))
|
|
|
|
|
2009-05-10 04:44:56 +04:00
|
|
|
typedef struct {
|
2008-05-07 18:41:37 +04:00
|
|
|
qemu_irq pint; /* Combination of the nPENIRQ and DAV signals */
|
|
|
|
QEMUTimer *timer;
|
|
|
|
uint16_t model;
|
|
|
|
|
2016-10-04 15:28:08 +03:00
|
|
|
int32_t x, y;
|
|
|
|
bool pressure;
|
2008-05-07 18:41:37 +04:00
|
|
|
|
2016-10-04 15:28:08 +03:00
|
|
|
uint8_t reg, state;
|
|
|
|
bool irq, command;
|
2008-05-07 18:41:37 +04:00
|
|
|
uint16_t data, dav;
|
|
|
|
|
2016-10-04 15:28:08 +03:00
|
|
|
bool busy;
|
|
|
|
bool enabled;
|
|
|
|
bool host_mode;
|
|
|
|
int8_t function;
|
|
|
|
int8_t nextfunction;
|
|
|
|
bool precision;
|
|
|
|
bool nextprecision;
|
|
|
|
uint16_t filter;
|
|
|
|
uint8_t pin_func;
|
|
|
|
uint16_t timing[2];
|
|
|
|
uint8_t noise;
|
|
|
|
bool reset;
|
|
|
|
bool pdst;
|
|
|
|
bool pnd0;
|
2008-05-07 18:41:37 +04:00
|
|
|
uint16_t temp_thr[2];
|
|
|
|
uint16_t aux_thr[2];
|
|
|
|
|
2016-10-04 15:28:08 +03:00
|
|
|
int32_t tr[8];
|
2009-05-10 04:44:56 +04:00
|
|
|
} TSC2005State;
|
2008-05-07 18:41:37 +04:00
|
|
|
|
|
|
|
enum {
|
|
|
|
TSC_MODE_XYZ_SCAN = 0x0,
|
|
|
|
TSC_MODE_XY_SCAN,
|
|
|
|
TSC_MODE_X,
|
|
|
|
TSC_MODE_Y,
|
|
|
|
TSC_MODE_Z,
|
|
|
|
TSC_MODE_AUX,
|
|
|
|
TSC_MODE_TEMP1,
|
|
|
|
TSC_MODE_TEMP2,
|
|
|
|
TSC_MODE_AUX_SCAN,
|
|
|
|
TSC_MODE_X_TEST,
|
|
|
|
TSC_MODE_Y_TEST,
|
|
|
|
TSC_MODE_TS_TEST,
|
|
|
|
TSC_MODE_RESERVED,
|
|
|
|
TSC_MODE_XX_DRV,
|
|
|
|
TSC_MODE_YY_DRV,
|
|
|
|
TSC_MODE_YX_DRV,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const uint16_t mode_regs[16] = {
|
|
|
|
0xf000, /* X, Y, Z scan */
|
|
|
|
0xc000, /* X, Y scan */
|
|
|
|
0x8000, /* X */
|
|
|
|
0x4000, /* Y */
|
|
|
|
0x3000, /* Z */
|
|
|
|
0x0800, /* AUX */
|
|
|
|
0x0400, /* TEMP1 */
|
|
|
|
0x0200, /* TEMP2 */
|
|
|
|
0x0800, /* AUX scan */
|
|
|
|
0x0040, /* X test */
|
|
|
|
0x0020, /* Y test */
|
|
|
|
0x0080, /* Short-circuit test */
|
|
|
|
0x0000, /* Reserved */
|
|
|
|
0x0000, /* X+, X- drivers */
|
|
|
|
0x0000, /* Y+, Y- drivers */
|
|
|
|
0x0000, /* Y+, X- drivers */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define X_TRANSFORM(s) \
|
|
|
|
((s->y * s->tr[0] - s->x * s->tr[1]) / s->tr[2] + s->tr[3])
|
|
|
|
#define Y_TRANSFORM(s) \
|
|
|
|
((s->y * s->tr[4] - s->x * s->tr[5]) / s->tr[6] + s->tr[7])
|
|
|
|
#define Z1_TRANSFORM(s) \
|
|
|
|
((400 - ((s)->x >> 7) + ((s)->pressure << 10)) << 4)
|
|
|
|
#define Z2_TRANSFORM(s) \
|
|
|
|
((4000 + ((s)->y >> 7) - ((s)->pressure << 10)) << 4)
|
|
|
|
|
|
|
|
#define AUX_VAL (700 << 4) /* +/- 3 at 12-bit */
|
|
|
|
#define TEMP1_VAL (1264 << 4) /* +/- 5 at 12-bit */
|
|
|
|
#define TEMP2_VAL (1531 << 4) /* +/- 5 at 12-bit */
|
|
|
|
|
2009-05-10 04:44:56 +04:00
|
|
|
static uint16_t tsc2005_read(TSC2005State *s, int reg)
|
2008-05-07 18:41:37 +04:00
|
|
|
{
|
|
|
|
uint16_t ret;
|
|
|
|
|
|
|
|
switch (reg) {
|
|
|
|
case 0x0: /* X */
|
|
|
|
s->dav &= ~mode_regs[TSC_MODE_X];
|
|
|
|
return TSC_CUT_RESOLUTION(X_TRANSFORM(s), s->precision) +
|
|
|
|
(s->noise & 3);
|
|
|
|
case 0x1: /* Y */
|
|
|
|
s->dav &= ~mode_regs[TSC_MODE_Y];
|
|
|
|
s->noise ++;
|
|
|
|
return TSC_CUT_RESOLUTION(Y_TRANSFORM(s), s->precision) ^
|
|
|
|
(s->noise & 3);
|
|
|
|
case 0x2: /* Z1 */
|
|
|
|
s->dav &= 0xdfff;
|
|
|
|
return TSC_CUT_RESOLUTION(Z1_TRANSFORM(s), s->precision) -
|
|
|
|
(s->noise & 3);
|
|
|
|
case 0x3: /* Z2 */
|
|
|
|
s->dav &= 0xefff;
|
|
|
|
return TSC_CUT_RESOLUTION(Z2_TRANSFORM(s), s->precision) |
|
|
|
|
(s->noise & 3);
|
|
|
|
|
|
|
|
case 0x4: /* AUX */
|
|
|
|
s->dav &= ~mode_regs[TSC_MODE_AUX];
|
|
|
|
return TSC_CUT_RESOLUTION(AUX_VAL, s->precision);
|
|
|
|
|
|
|
|
case 0x5: /* TEMP1 */
|
|
|
|
s->dav &= ~mode_regs[TSC_MODE_TEMP1];
|
|
|
|
return TSC_CUT_RESOLUTION(TEMP1_VAL, s->precision) -
|
|
|
|
(s->noise & 5);
|
|
|
|
case 0x6: /* TEMP2 */
|
|
|
|
s->dav &= 0xdfff;
|
|
|
|
s->dav &= ~mode_regs[TSC_MODE_TEMP2];
|
|
|
|
return TSC_CUT_RESOLUTION(TEMP2_VAL, s->precision) ^
|
|
|
|
(s->noise & 3);
|
|
|
|
|
|
|
|
case 0x7: /* Status */
|
|
|
|
ret = s->dav | (s->reset << 7) | (s->pdst << 2) | 0x0;
|
|
|
|
s->dav &= ~(mode_regs[TSC_MODE_X_TEST] | mode_regs[TSC_MODE_Y_TEST] |
|
|
|
|
mode_regs[TSC_MODE_TS_TEST]);
|
2016-10-04 15:28:08 +03:00
|
|
|
s->reset = true;
|
2008-05-07 18:41:37 +04:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
case 0x8: /* AUX high treshold */
|
|
|
|
return s->aux_thr[1];
|
|
|
|
case 0x9: /* AUX low treshold */
|
|
|
|
return s->aux_thr[0];
|
|
|
|
|
|
|
|
case 0xa: /* TEMP high treshold */
|
|
|
|
return s->temp_thr[1];
|
|
|
|
case 0xb: /* TEMP low treshold */
|
|
|
|
return s->temp_thr[0];
|
|
|
|
|
|
|
|
case 0xc: /* CFR0 */
|
|
|
|
return (s->pressure << 15) | ((!s->busy) << 14) |
|
|
|
|
(s->nextprecision << 13) | s->timing[0];
|
|
|
|
case 0xd: /* CFR1 */
|
|
|
|
return s->timing[1];
|
|
|
|
case 0xe: /* CFR2 */
|
|
|
|
return (s->pin_func << 14) | s->filter;
|
|
|
|
|
|
|
|
case 0xf: /* Function select status */
|
|
|
|
return s->function >= 0 ? 1 << s->function : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Never gets here */
|
|
|
|
return 0xffff;
|
|
|
|
}
|
|
|
|
|
2009-05-10 04:44:56 +04:00
|
|
|
static void tsc2005_write(TSC2005State *s, int reg, uint16_t data)
|
2008-05-07 18:41:37 +04:00
|
|
|
{
|
|
|
|
switch (reg) {
|
|
|
|
case 0x8: /* AUX high treshold */
|
|
|
|
s->aux_thr[1] = data;
|
|
|
|
break;
|
|
|
|
case 0x9: /* AUX low treshold */
|
|
|
|
s->aux_thr[0] = data;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xa: /* TEMP high treshold */
|
|
|
|
s->temp_thr[1] = data;
|
|
|
|
break;
|
|
|
|
case 0xb: /* TEMP low treshold */
|
|
|
|
s->temp_thr[0] = data;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xc: /* CFR0 */
|
2016-10-04 15:28:08 +03:00
|
|
|
s->host_mode = (data >> 15) != 0;
|
2008-05-18 17:14:29 +04:00
|
|
|
if (s->enabled != !(data & 0x4000)) {
|
|
|
|
s->enabled = !(data & 0x4000);
|
2018-06-21 20:12:52 +03:00
|
|
|
trace_tsc2005_sense(s->enabled ? "enabled" : "disabled");
|
2008-05-18 17:14:29 +04:00
|
|
|
if (s->busy && !s->enabled)
|
2013-08-21 19:03:08 +04:00
|
|
|
timer_del(s->timer);
|
2016-10-04 15:28:08 +03:00
|
|
|
s->busy = s->busy && s->enabled;
|
2008-05-18 17:14:29 +04:00
|
|
|
}
|
2008-05-07 18:41:37 +04:00
|
|
|
s->nextprecision = (data >> 13) & 1;
|
|
|
|
s->timing[0] = data & 0x1fff;
|
2018-06-26 19:50:40 +03:00
|
|
|
if ((s->timing[0] >> 11) == 3) {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
|
|
"tsc2005_write: illegal conversion clock setting\n");
|
|
|
|
}
|
2008-05-07 18:41:37 +04:00
|
|
|
break;
|
|
|
|
case 0xd: /* CFR1 */
|
|
|
|
s->timing[1] = data & 0xf07;
|
|
|
|
break;
|
|
|
|
case 0xe: /* CFR2 */
|
|
|
|
s->pin_func = (data >> 14) & 3;
|
|
|
|
s->filter = data & 0x3fff;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-06-26 19:50:40 +03:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
|
|
"%s: write into read-only register 0x%x\n",
|
|
|
|
__func__, reg);
|
2008-05-07 18:41:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This handles most of the chip's logic. */
|
2009-05-10 04:44:56 +04:00
|
|
|
static void tsc2005_pin_update(TSC2005State *s)
|
2008-05-07 18:41:37 +04:00
|
|
|
{
|
|
|
|
int64_t expires;
|
2016-10-04 15:28:08 +03:00
|
|
|
bool pin_state;
|
2008-05-07 18:41:37 +04:00
|
|
|
|
|
|
|
switch (s->pin_func) {
|
|
|
|
case 0:
|
|
|
|
pin_state = !s->pressure && !!s->dav;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 3:
|
|
|
|
default:
|
|
|
|
pin_state = !s->dav;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
pin_state = !s->pressure;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pin_state != s->irq) {
|
|
|
|
s->irq = pin_state;
|
|
|
|
qemu_set_irq(s->pint, s->irq);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (s->nextfunction) {
|
|
|
|
case TSC_MODE_XYZ_SCAN:
|
|
|
|
case TSC_MODE_XY_SCAN:
|
2008-05-10 02:17:18 +04:00
|
|
|
if (!s->host_mode && s->dav)
|
2016-10-04 15:28:08 +03:00
|
|
|
s->enabled = false;
|
2008-05-07 18:41:37 +04:00
|
|
|
if (!s->pressure)
|
|
|
|
return;
|
|
|
|
/* Fall through */
|
|
|
|
case TSC_MODE_AUX_SCAN:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TSC_MODE_X:
|
|
|
|
case TSC_MODE_Y:
|
|
|
|
case TSC_MODE_Z:
|
|
|
|
if (!s->pressure)
|
|
|
|
return;
|
|
|
|
/* Fall through */
|
|
|
|
case TSC_MODE_AUX:
|
|
|
|
case TSC_MODE_TEMP1:
|
|
|
|
case TSC_MODE_TEMP2:
|
|
|
|
case TSC_MODE_X_TEST:
|
|
|
|
case TSC_MODE_Y_TEST:
|
|
|
|
case TSC_MODE_TS_TEST:
|
|
|
|
if (s->dav)
|
2016-10-04 15:28:08 +03:00
|
|
|
s->enabled = false;
|
2008-05-07 18:41:37 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TSC_MODE_RESERVED:
|
|
|
|
case TSC_MODE_XX_DRV:
|
|
|
|
case TSC_MODE_YY_DRV:
|
|
|
|
case TSC_MODE_YX_DRV:
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!s->enabled || s->busy)
|
|
|
|
return;
|
|
|
|
|
2016-10-04 15:28:08 +03:00
|
|
|
s->busy = true;
|
2008-05-07 18:41:37 +04:00
|
|
|
s->precision = s->nextprecision;
|
|
|
|
s->function = s->nextfunction;
|
|
|
|
s->pdst = !s->pnd0; /* Synchronised on internal clock */
|
2016-03-21 19:02:30 +03:00
|
|
|
expires = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
|
|
|
|
(NANOSECONDS_PER_SECOND >> 7);
|
2013-08-21 19:03:08 +04:00
|
|
|
timer_mod(s->timer, expires);
|
2008-05-07 18:41:37 +04:00
|
|
|
}
|
|
|
|
|
2009-05-10 04:44:56 +04:00
|
|
|
static void tsc2005_reset(TSC2005State *s)
|
2008-05-07 18:41:37 +04:00
|
|
|
{
|
|
|
|
s->state = 0;
|
|
|
|
s->pin_func = 0;
|
2016-10-04 15:28:08 +03:00
|
|
|
s->enabled = false;
|
|
|
|
s->busy = false;
|
|
|
|
s->nextprecision = false;
|
2008-05-07 18:41:37 +04:00
|
|
|
s->nextfunction = 0;
|
|
|
|
s->timing[0] = 0;
|
|
|
|
s->timing[1] = 0;
|
2016-10-04 15:28:08 +03:00
|
|
|
s->irq = false;
|
2008-05-07 18:41:37 +04:00
|
|
|
s->dav = 0;
|
2016-10-04 15:28:08 +03:00
|
|
|
s->reset = false;
|
|
|
|
s->pdst = true;
|
|
|
|
s->pnd0 = false;
|
2008-05-07 18:41:37 +04:00
|
|
|
s->function = -1;
|
|
|
|
s->temp_thr[0] = 0x000;
|
|
|
|
s->temp_thr[1] = 0xfff;
|
|
|
|
s->aux_thr[0] = 0x000;
|
|
|
|
s->aux_thr[1] = 0xfff;
|
|
|
|
|
|
|
|
tsc2005_pin_update(s);
|
|
|
|
}
|
|
|
|
|
2008-10-26 16:43:07 +03:00
|
|
|
static uint8_t tsc2005_txrx_word(void *opaque, uint8_t value)
|
2008-05-07 18:41:37 +04:00
|
|
|
{
|
2009-05-10 04:44:56 +04:00
|
|
|
TSC2005State *s = opaque;
|
2008-05-07 18:41:37 +04:00
|
|
|
uint32_t ret = 0;
|
|
|
|
|
|
|
|
switch (s->state ++) {
|
|
|
|
case 0:
|
|
|
|
if (value & 0x80) {
|
|
|
|
/* Command */
|
|
|
|
if (value & (1 << 1))
|
|
|
|
tsc2005_reset(s);
|
|
|
|
else {
|
|
|
|
s->nextfunction = (value >> 3) & 0xf;
|
|
|
|
s->nextprecision = (value >> 2) & 1;
|
|
|
|
if (s->enabled != !(value & 1)) {
|
|
|
|
s->enabled = !(value & 1);
|
2018-06-21 20:12:52 +03:00
|
|
|
trace_tsc2005_sense(s->enabled ? "enabled" : "disabled");
|
2008-05-10 02:17:18 +04:00
|
|
|
if (s->busy && !s->enabled)
|
2013-08-21 19:03:08 +04:00
|
|
|
timer_del(s->timer);
|
2016-10-04 15:28:08 +03:00
|
|
|
s->busy = s->busy && s->enabled;
|
2008-05-07 18:41:37 +04:00
|
|
|
}
|
|
|
|
tsc2005_pin_update(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
s->state = 0;
|
|
|
|
} else if (value) {
|
|
|
|
/* Data transfer */
|
|
|
|
s->reg = (value >> 3) & 0xf;
|
|
|
|
s->pnd0 = (value >> 1) & 1;
|
|
|
|
s->command = value & 1;
|
|
|
|
|
|
|
|
if (s->command) {
|
|
|
|
/* Read */
|
|
|
|
s->data = tsc2005_read(s, s->reg);
|
|
|
|
tsc2005_pin_update(s);
|
|
|
|
} else
|
|
|
|
s->data = 0;
|
|
|
|
} else
|
|
|
|
s->state = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
if (s->command)
|
|
|
|
ret = (s->data >> 8) & 0xff;
|
|
|
|
else
|
|
|
|
s->data |= value << 8;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
if (s->command)
|
|
|
|
ret = s->data & 0xff;
|
|
|
|
else {
|
|
|
|
s->data |= value;
|
|
|
|
tsc2005_write(s, s->reg, s->data);
|
|
|
|
tsc2005_pin_update(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
s->state = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t tsc2005_txrx(void *opaque, uint32_t value, int len)
|
|
|
|
{
|
|
|
|
uint32_t ret = 0;
|
|
|
|
|
|
|
|
len &= ~7;
|
|
|
|
while (len > 0) {
|
|
|
|
len -= 8;
|
|
|
|
ret |= tsc2005_txrx_word(opaque, (value >> len) & 0xff) << len;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tsc2005_timer_tick(void *opaque)
|
|
|
|
{
|
2009-05-10 04:44:56 +04:00
|
|
|
TSC2005State *s = opaque;
|
2008-05-07 18:41:37 +04:00
|
|
|
|
|
|
|
/* Timer ticked -- a set of conversions has been finished. */
|
|
|
|
|
|
|
|
if (!s->busy)
|
|
|
|
return;
|
|
|
|
|
2016-10-04 15:28:08 +03:00
|
|
|
s->busy = false;
|
2008-05-07 18:41:37 +04:00
|
|
|
s->dav |= mode_regs[s->function];
|
|
|
|
s->function = -1;
|
|
|
|
tsc2005_pin_update(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tsc2005_touchscreen_event(void *opaque,
|
|
|
|
int x, int y, int z, int buttons_state)
|
|
|
|
{
|
2009-05-10 04:44:56 +04:00
|
|
|
TSC2005State *s = opaque;
|
2008-05-07 18:41:37 +04:00
|
|
|
int p = s->pressure;
|
|
|
|
|
|
|
|
if (buttons_state) {
|
|
|
|
s->x = x;
|
|
|
|
s->y = y;
|
|
|
|
}
|
|
|
|
s->pressure = !!buttons_state;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note: We would get better responsiveness in the guest by
|
|
|
|
* signaling TS events immediately, but for now we simulate
|
|
|
|
* the first conversion delay for sake of correctness.
|
|
|
|
*/
|
|
|
|
if (p != s->pressure)
|
|
|
|
tsc2005_pin_update(s);
|
|
|
|
}
|
|
|
|
|
2016-10-04 15:28:08 +03:00
|
|
|
static int tsc2005_post_load(void *opaque, int version_id)
|
2008-05-07 18:41:37 +04:00
|
|
|
{
|
2009-05-10 04:44:56 +04:00
|
|
|
TSC2005State *s = (TSC2005State *) opaque;
|
2008-05-07 18:41:37 +04:00
|
|
|
|
2013-08-21 19:02:39 +04:00
|
|
|
s->busy = timer_pending(s->timer);
|
2008-05-07 18:41:37 +04:00
|
|
|
tsc2005_pin_update(s);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-04 15:28:08 +03:00
|
|
|
static const VMStateDescription vmstate_tsc2005 = {
|
|
|
|
.name = "tsc2005",
|
|
|
|
.version_id = 2,
|
|
|
|
.minimum_version_id = 2,
|
|
|
|
.post_load = tsc2005_post_load,
|
|
|
|
.fields = (VMStateField []) {
|
|
|
|
VMSTATE_BOOL(pressure, TSC2005State),
|
|
|
|
VMSTATE_BOOL(irq, TSC2005State),
|
|
|
|
VMSTATE_BOOL(command, TSC2005State),
|
|
|
|
VMSTATE_BOOL(enabled, TSC2005State),
|
|
|
|
VMSTATE_BOOL(host_mode, TSC2005State),
|
|
|
|
VMSTATE_BOOL(reset, TSC2005State),
|
|
|
|
VMSTATE_BOOL(pdst, TSC2005State),
|
|
|
|
VMSTATE_BOOL(pnd0, TSC2005State),
|
|
|
|
VMSTATE_BOOL(precision, TSC2005State),
|
|
|
|
VMSTATE_BOOL(nextprecision, TSC2005State),
|
|
|
|
VMSTATE_UINT8(reg, TSC2005State),
|
|
|
|
VMSTATE_UINT8(state, TSC2005State),
|
|
|
|
VMSTATE_UINT16(data, TSC2005State),
|
|
|
|
VMSTATE_UINT16(dav, TSC2005State),
|
|
|
|
VMSTATE_UINT16(filter, TSC2005State),
|
|
|
|
VMSTATE_INT8(nextfunction, TSC2005State),
|
|
|
|
VMSTATE_INT8(function, TSC2005State),
|
|
|
|
VMSTATE_INT32(x, TSC2005State),
|
|
|
|
VMSTATE_INT32(y, TSC2005State),
|
|
|
|
VMSTATE_TIMER_PTR(timer, TSC2005State),
|
|
|
|
VMSTATE_UINT8(pin_func, TSC2005State),
|
|
|
|
VMSTATE_UINT16_ARRAY(timing, TSC2005State, 2),
|
|
|
|
VMSTATE_UINT8(noise, TSC2005State),
|
|
|
|
VMSTATE_UINT16_ARRAY(temp_thr, TSC2005State, 2),
|
|
|
|
VMSTATE_UINT16_ARRAY(aux_thr, TSC2005State, 2),
|
|
|
|
VMSTATE_INT32_ARRAY(tr, TSC2005State, 8),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-05-07 18:41:37 +04:00
|
|
|
void *tsc2005_init(qemu_irq pintdav)
|
|
|
|
{
|
2009-05-10 04:44:56 +04:00
|
|
|
TSC2005State *s;
|
2008-05-07 18:41:37 +04:00
|
|
|
|
2009-05-10 04:44:56 +04:00
|
|
|
s = (TSC2005State *)
|
2011-08-21 07:09:37 +04:00
|
|
|
g_malloc0(sizeof(TSC2005State));
|
2008-05-07 18:41:37 +04:00
|
|
|
s->x = 400;
|
|
|
|
s->y = 240;
|
2016-10-04 15:28:08 +03:00
|
|
|
s->pressure = false;
|
|
|
|
s->precision = s->nextprecision = false;
|
2013-08-21 19:03:08 +04:00
|
|
|
s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, tsc2005_timer_tick, s);
|
2008-05-07 18:41:37 +04:00
|
|
|
s->pint = pintdav;
|
|
|
|
s->model = 0x2005;
|
|
|
|
|
|
|
|
s->tr[0] = 0;
|
|
|
|
s->tr[1] = 1;
|
|
|
|
s->tr[2] = 1;
|
|
|
|
s->tr[3] = 0;
|
|
|
|
s->tr[4] = 1;
|
|
|
|
s->tr[5] = 0;
|
|
|
|
s->tr[6] = 1;
|
|
|
|
s->tr[7] = 0;
|
|
|
|
|
|
|
|
tsc2005_reset(s);
|
|
|
|
|
|
|
|
qemu_add_mouse_event_handler(tsc2005_touchscreen_event, s, 1,
|
|
|
|
"QEMU TSC2005-driven Touchscreen");
|
|
|
|
|
2009-06-27 11:25:07 +04:00
|
|
|
qemu_register_reset((void *) tsc2005_reset, s);
|
2016-10-04 15:28:08 +03:00
|
|
|
vmstate_register(NULL, 0, &vmstate_tsc2005, s);
|
2008-05-07 18:41:37 +04:00
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Use tslib generated calibration data to generate ADC input values
|
|
|
|
* from the touchscreen. Assuming 12-bit precision was used during
|
|
|
|
* tslib calibration.
|
|
|
|
*/
|
2009-05-10 04:44:56 +04:00
|
|
|
void tsc2005_set_transform(void *opaque, MouseTransformInfo *info)
|
2008-05-07 18:41:37 +04:00
|
|
|
{
|
2009-05-10 04:44:56 +04:00
|
|
|
TSC2005State *s = (TSC2005State *) opaque;
|
2008-05-07 18:41:37 +04:00
|
|
|
|
|
|
|
/* This version assumes touchscreen X & Y axis are parallel or
|
|
|
|
* perpendicular to LCD's X & Y axis in some way. */
|
|
|
|
if (abs(info->a[0]) > abs(info->a[1])) {
|
|
|
|
s->tr[0] = 0;
|
|
|
|
s->tr[1] = -info->a[6] * info->x;
|
|
|
|
s->tr[2] = info->a[0];
|
|
|
|
s->tr[3] = -info->a[2] / info->a[0];
|
|
|
|
s->tr[4] = info->a[6] * info->y;
|
|
|
|
s->tr[5] = 0;
|
|
|
|
s->tr[6] = info->a[4];
|
|
|
|
s->tr[7] = -info->a[5] / info->a[4];
|
|
|
|
} else {
|
|
|
|
s->tr[0] = info->a[6] * info->y;
|
|
|
|
s->tr[1] = 0;
|
|
|
|
s->tr[2] = info->a[1];
|
|
|
|
s->tr[3] = -info->a[2] / info->a[1];
|
|
|
|
s->tr[4] = 0;
|
|
|
|
s->tr[5] = -info->a[6] * info->x;
|
|
|
|
s->tr[6] = info->a[3];
|
|
|
|
s->tr[7] = -info->a[5] / info->a[3];
|
|
|
|
}
|
|
|
|
|
|
|
|
s->tr[0] >>= 11;
|
|
|
|
s->tr[1] >>= 11;
|
|
|
|
s->tr[3] <<= 4;
|
|
|
|
s->tr[4] >>= 11;
|
|
|
|
s->tr[5] >>= 11;
|
|
|
|
s->tr[7] <<= 4;
|
|
|
|
}
|